diff --git a/extensions/bluebubbles/src/config-schema.ts b/extensions/bluebubbles/src/config-schema.ts index bc4ec0e3f67..94a0661afb7 100644 --- a/extensions/bluebubbles/src/config-schema.ts +++ b/extensions/bluebubbles/src/config-schema.ts @@ -1,9 +1,8 @@ +import { AllowFromEntrySchema, buildCatchallMultiAccountChannelSchema } from "openclaw/plugin-sdk"; import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/bluebubbles"; import { z } from "zod"; import { buildSecretInputSchema, hasConfiguredSecretInput } from "./secret-input.js"; -const allowFromEntry = z.union([z.string(), z.number()]); - const bluebubblesActionSchema = z .object({ reactions: z.boolean().default(true), @@ -34,8 +33,8 @@ const bluebubblesAccountSchema = z password: buildSecretInputSchema().optional(), webhookPath: z.string().optional(), dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(), - allowFrom: z.array(allowFromEntry).optional(), - groupAllowFrom: z.array(allowFromEntry).optional(), + allowFrom: z.array(AllowFromEntrySchema).optional(), + groupAllowFrom: z.array(AllowFromEntrySchema).optional(), groupPolicy: z.enum(["open", "disabled", "allowlist"]).optional(), historyLimit: z.number().int().min(0).optional(), dmHistoryLimit: z.number().int().min(0).optional(), @@ -60,8 +59,8 @@ const bluebubblesAccountSchema = z } }); -export const BlueBubblesConfigSchema = bluebubblesAccountSchema.extend({ - accounts: z.object({}).catchall(bluebubblesAccountSchema).optional(), - defaultAccount: z.string().optional(), +export const BlueBubblesConfigSchema = buildCatchallMultiAccountChannelSchema( + bluebubblesAccountSchema, +).extend({ actions: bluebubblesActionSchema, }); diff --git a/extensions/zalo/src/config-schema.ts b/extensions/zalo/src/config-schema.ts index 7f2c0f360ba..f2e5c5803e7 100644 --- a/extensions/zalo/src/config-schema.ts +++ b/extensions/zalo/src/config-schema.ts @@ -1,9 +1,8 @@ +import { AllowFromEntrySchema, buildCatchallMultiAccountChannelSchema } from "openclaw/plugin-sdk"; import { MarkdownConfigSchema } from "openclaw/plugin-sdk/zalo"; import { z } from "zod"; import { buildSecretInputSchema } from "./secret-input.js"; -const allowFromEntry = z.union([z.string(), z.number()]); - const zaloAccountSchema = z.object({ name: z.string().optional(), enabled: z.boolean().optional(), @@ -14,15 +13,12 @@ const zaloAccountSchema = z.object({ webhookSecret: buildSecretInputSchema().optional(), webhookPath: z.string().optional(), dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(), - allowFrom: z.array(allowFromEntry).optional(), + allowFrom: z.array(AllowFromEntrySchema).optional(), groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(), - groupAllowFrom: z.array(allowFromEntry).optional(), + groupAllowFrom: z.array(AllowFromEntrySchema).optional(), mediaMaxMb: z.number().optional(), proxy: z.string().optional(), responsePrefix: z.string().optional(), }); -export const ZaloConfigSchema = zaloAccountSchema.extend({ - accounts: z.object({}).catchall(zaloAccountSchema).optional(), - defaultAccount: z.string().optional(), -}); +export const ZaloConfigSchema = buildCatchallMultiAccountChannelSchema(zaloAccountSchema); diff --git a/extensions/zalouser/src/config-schema.ts b/extensions/zalouser/src/config-schema.ts index 9d6b0bcec4a..dd0f9c51fbe 100644 --- a/extensions/zalouser/src/config-schema.ts +++ b/extensions/zalouser/src/config-schema.ts @@ -1,8 +1,7 @@ +import { AllowFromEntrySchema, buildCatchallMultiAccountChannelSchema } from "openclaw/plugin-sdk"; import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/zalouser"; import { z } from "zod"; -const allowFromEntry = z.union([z.string(), z.number()]); - const groupConfigSchema = z.object({ allow: z.boolean().optional(), enabled: z.boolean().optional(), @@ -16,16 +15,13 @@ const zalouserAccountSchema = z.object({ markdown: MarkdownConfigSchema, profile: z.string().optional(), dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(), - allowFrom: z.array(allowFromEntry).optional(), + allowFrom: z.array(AllowFromEntrySchema).optional(), historyLimit: z.number().int().min(0).optional(), - groupAllowFrom: z.array(allowFromEntry).optional(), + groupAllowFrom: z.array(AllowFromEntrySchema).optional(), groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(), groups: z.object({}).catchall(groupConfigSchema).optional(), messagePrefix: z.string().optional(), responsePrefix: z.string().optional(), }); -export const ZalouserConfigSchema = zalouserAccountSchema.extend({ - accounts: z.object({}).catchall(zalouserAccountSchema).optional(), - defaultAccount: z.string().optional(), -}); +export const ZalouserConfigSchema = buildCatchallMultiAccountChannelSchema(zalouserAccountSchema); diff --git a/src/channels/plugins/config-schema.ts b/src/channels/plugins/config-schema.ts index 75074ae569d..35be4c9d388 100644 --- a/src/channels/plugins/config-schema.ts +++ b/src/channels/plugins/config-schema.ts @@ -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) => unknown; }; +type ExtendableZodObject = ZodTypeAny & { + extend: (shape: Record) => ZodTypeAny; +}; + +export const AllowFromEntrySchema = z.union([z.string(), z.number()]); + +export function buildCatchallMultiAccountChannelSchema( + 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") { diff --git a/src/plugin-sdk/index.ts b/src/plugin-sdk/index.ts index 816d644cd99..89340787e92 100644 --- a/src/plugin-sdk/index.ts +++ b/src/plugin-sdk/index.ts @@ -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";