mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
refactor: share multi-account config schema fragments
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
import type { ZodTypeAny } from "zod";
|
||||
import { z, type ZodTypeAny } from "zod";
|
||||
import type { ChannelConfigSchema } from "./types.plugin.js";
|
||||
|
||||
type ZodSchemaWithToJsonSchema = ZodTypeAny & {
|
||||
toJSONSchema?: (params?: Record<string, unknown>) => unknown;
|
||||
};
|
||||
|
||||
type ExtendableZodObject = ZodTypeAny & {
|
||||
extend: (shape: Record<string, ZodTypeAny>) => ZodTypeAny;
|
||||
};
|
||||
|
||||
export const AllowFromEntrySchema = z.union([z.string(), z.number()]);
|
||||
|
||||
export function buildCatchallMultiAccountChannelSchema<T extends ExtendableZodObject>(
|
||||
accountSchema: T,
|
||||
): T {
|
||||
return accountSchema.extend({
|
||||
accounts: z.object({}).catchall(accountSchema).optional(),
|
||||
defaultAccount: z.string().optional(),
|
||||
}) as T;
|
||||
}
|
||||
|
||||
export function buildChannelConfigSchema(schema: ZodTypeAny): ChannelConfigSchema {
|
||||
const schemaWithJson = schema as ZodSchemaWithToJsonSchema;
|
||||
if (typeof schemaWithJson.toJSONSchema === "function") {
|
||||
|
||||
@@ -195,6 +195,10 @@ export { formatResolvedUnresolvedNote } from "./resolution-notes.js";
|
||||
export { buildChannelSendResult } from "./channel-send-result.js";
|
||||
export type { ChannelSendRawResult } from "./channel-send-result.js";
|
||||
export { createPluginRuntimeStore } from "./runtime-store.js";
|
||||
export {
|
||||
AllowFromEntrySchema,
|
||||
buildCatchallMultiAccountChannelSchema,
|
||||
} from "../channels/plugins/config-schema.js";
|
||||
export type { ChannelDock } from "../channels/dock.js";
|
||||
export { getChatChannelMeta } from "../channels/registry.js";
|
||||
export { resolveAllowlistMatchByCandidates } from "../channels/allowlist-match.js";
|
||||
|
||||
Reference in New Issue
Block a user