mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor: share multi-account config schema fragments
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
|
import { AllowFromEntrySchema, buildCatchallMultiAccountChannelSchema } from "openclaw/plugin-sdk";
|
||||||
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/bluebubbles";
|
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/bluebubbles";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { buildSecretInputSchema, hasConfiguredSecretInput } from "./secret-input.js";
|
import { buildSecretInputSchema, hasConfiguredSecretInput } from "./secret-input.js";
|
||||||
|
|
||||||
const allowFromEntry = z.union([z.string(), z.number()]);
|
|
||||||
|
|
||||||
const bluebubblesActionSchema = z
|
const bluebubblesActionSchema = z
|
||||||
.object({
|
.object({
|
||||||
reactions: z.boolean().default(true),
|
reactions: z.boolean().default(true),
|
||||||
@@ -34,8 +33,8 @@ const bluebubblesAccountSchema = z
|
|||||||
password: buildSecretInputSchema().optional(),
|
password: buildSecretInputSchema().optional(),
|
||||||
webhookPath: z.string().optional(),
|
webhookPath: z.string().optional(),
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
||||||
allowFrom: z.array(allowFromEntry).optional(),
|
allowFrom: z.array(AllowFromEntrySchema).optional(),
|
||||||
groupAllowFrom: z.array(allowFromEntry).optional(),
|
groupAllowFrom: z.array(AllowFromEntrySchema).optional(),
|
||||||
groupPolicy: z.enum(["open", "disabled", "allowlist"]).optional(),
|
groupPolicy: z.enum(["open", "disabled", "allowlist"]).optional(),
|
||||||
historyLimit: z.number().int().min(0).optional(),
|
historyLimit: z.number().int().min(0).optional(),
|
||||||
dmHistoryLimit: 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({
|
export const BlueBubblesConfigSchema = buildCatchallMultiAccountChannelSchema(
|
||||||
accounts: z.object({}).catchall(bluebubblesAccountSchema).optional(),
|
bluebubblesAccountSchema,
|
||||||
defaultAccount: z.string().optional(),
|
).extend({
|
||||||
actions: bluebubblesActionSchema,
|
actions: bluebubblesActionSchema,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
|
import { AllowFromEntrySchema, buildCatchallMultiAccountChannelSchema } from "openclaw/plugin-sdk";
|
||||||
import { MarkdownConfigSchema } from "openclaw/plugin-sdk/zalo";
|
import { MarkdownConfigSchema } from "openclaw/plugin-sdk/zalo";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { buildSecretInputSchema } from "./secret-input.js";
|
import { buildSecretInputSchema } from "./secret-input.js";
|
||||||
|
|
||||||
const allowFromEntry = z.union([z.string(), z.number()]);
|
|
||||||
|
|
||||||
const zaloAccountSchema = z.object({
|
const zaloAccountSchema = z.object({
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
enabled: z.boolean().optional(),
|
enabled: z.boolean().optional(),
|
||||||
@@ -14,15 +13,12 @@ const zaloAccountSchema = z.object({
|
|||||||
webhookSecret: buildSecretInputSchema().optional(),
|
webhookSecret: buildSecretInputSchema().optional(),
|
||||||
webhookPath: z.string().optional(),
|
webhookPath: z.string().optional(),
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).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(),
|
groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(),
|
||||||
groupAllowFrom: z.array(allowFromEntry).optional(),
|
groupAllowFrom: z.array(AllowFromEntrySchema).optional(),
|
||||||
mediaMaxMb: z.number().optional(),
|
mediaMaxMb: z.number().optional(),
|
||||||
proxy: z.string().optional(),
|
proxy: z.string().optional(),
|
||||||
responsePrefix: z.string().optional(),
|
responsePrefix: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZaloConfigSchema = zaloAccountSchema.extend({
|
export const ZaloConfigSchema = buildCatchallMultiAccountChannelSchema(zaloAccountSchema);
|
||||||
accounts: z.object({}).catchall(zaloAccountSchema).optional(),
|
|
||||||
defaultAccount: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
import { AllowFromEntrySchema, buildCatchallMultiAccountChannelSchema } from "openclaw/plugin-sdk";
|
||||||
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/zalouser";
|
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/zalouser";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const allowFromEntry = z.union([z.string(), z.number()]);
|
|
||||||
|
|
||||||
const groupConfigSchema = z.object({
|
const groupConfigSchema = z.object({
|
||||||
allow: z.boolean().optional(),
|
allow: z.boolean().optional(),
|
||||||
enabled: z.boolean().optional(),
|
enabled: z.boolean().optional(),
|
||||||
@@ -16,16 +15,13 @@ const zalouserAccountSchema = z.object({
|
|||||||
markdown: MarkdownConfigSchema,
|
markdown: MarkdownConfigSchema,
|
||||||
profile: z.string().optional(),
|
profile: z.string().optional(),
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).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(),
|
historyLimit: z.number().int().min(0).optional(),
|
||||||
groupAllowFrom: z.array(allowFromEntry).optional(),
|
groupAllowFrom: z.array(AllowFromEntrySchema).optional(),
|
||||||
groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(),
|
groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(),
|
||||||
groups: z.object({}).catchall(groupConfigSchema).optional(),
|
groups: z.object({}).catchall(groupConfigSchema).optional(),
|
||||||
messagePrefix: z.string().optional(),
|
messagePrefix: z.string().optional(),
|
||||||
responsePrefix: z.string().optional(),
|
responsePrefix: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZalouserConfigSchema = zalouserAccountSchema.extend({
|
export const ZalouserConfigSchema = buildCatchallMultiAccountChannelSchema(zalouserAccountSchema);
|
||||||
accounts: z.object({}).catchall(zalouserAccountSchema).optional(),
|
|
||||||
defaultAccount: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
import type { ZodTypeAny } from "zod";
|
import { z, type ZodTypeAny } from "zod";
|
||||||
import type { ChannelConfigSchema } from "./types.plugin.js";
|
import type { ChannelConfigSchema } from "./types.plugin.js";
|
||||||
|
|
||||||
type ZodSchemaWithToJsonSchema = ZodTypeAny & {
|
type ZodSchemaWithToJsonSchema = ZodTypeAny & {
|
||||||
toJSONSchema?: (params?: Record<string, unknown>) => unknown;
|
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 {
|
export function buildChannelConfigSchema(schema: ZodTypeAny): ChannelConfigSchema {
|
||||||
const schemaWithJson = schema as ZodSchemaWithToJsonSchema;
|
const schemaWithJson = schema as ZodSchemaWithToJsonSchema;
|
||||||
if (typeof schemaWithJson.toJSONSchema === "function") {
|
if (typeof schemaWithJson.toJSONSchema === "function") {
|
||||||
|
|||||||
@@ -195,6 +195,10 @@ export { formatResolvedUnresolvedNote } from "./resolution-notes.js";
|
|||||||
export { buildChannelSendResult } from "./channel-send-result.js";
|
export { buildChannelSendResult } from "./channel-send-result.js";
|
||||||
export type { ChannelSendRawResult } from "./channel-send-result.js";
|
export type { ChannelSendRawResult } from "./channel-send-result.js";
|
||||||
export { createPluginRuntimeStore } from "./runtime-store.js";
|
export { createPluginRuntimeStore } from "./runtime-store.js";
|
||||||
|
export {
|
||||||
|
AllowFromEntrySchema,
|
||||||
|
buildCatchallMultiAccountChannelSchema,
|
||||||
|
} from "../channels/plugins/config-schema.js";
|
||||||
export type { ChannelDock } from "../channels/dock.js";
|
export type { ChannelDock } from "../channels/dock.js";
|
||||||
export { getChatChannelMeta } from "../channels/registry.js";
|
export { getChatChannelMeta } from "../channels/registry.js";
|
||||||
export { resolveAllowlistMatchByCandidates } from "../channels/allowlist-match.js";
|
export { resolveAllowlistMatchByCandidates } from "../channels/allowlist-match.js";
|
||||||
|
|||||||
Reference in New Issue
Block a user