mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor: share channel config schema fragments
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/bluebubbles";
|
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/bluebubbles";
|
||||||
import {
|
import {
|
||||||
AllowFromEntrySchema,
|
AllowFromListSchema,
|
||||||
buildCatchallMultiAccountChannelSchema,
|
buildCatchallMultiAccountChannelSchema,
|
||||||
|
DmPolicySchema,
|
||||||
|
GroupPolicySchema,
|
||||||
} from "openclaw/plugin-sdk/compat";
|
} from "openclaw/plugin-sdk/compat";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { buildSecretInputSchema, hasConfiguredSecretInput } from "./secret-input.js";
|
import { buildSecretInputSchema, hasConfiguredSecretInput } from "./secret-input.js";
|
||||||
@@ -35,10 +37,10 @@ const bluebubblesAccountSchema = z
|
|||||||
serverUrl: z.string().optional(),
|
serverUrl: z.string().optional(),
|
||||||
password: buildSecretInputSchema().optional(),
|
password: buildSecretInputSchema().optional(),
|
||||||
webhookPath: z.string().optional(),
|
webhookPath: z.string().optional(),
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
dmPolicy: DmPolicySchema.optional(),
|
||||||
allowFrom: z.array(AllowFromEntrySchema).optional(),
|
allowFrom: AllowFromListSchema,
|
||||||
groupAllowFrom: z.array(AllowFromEntrySchema).optional(),
|
groupAllowFrom: AllowFromListSchema,
|
||||||
groupPolicy: z.enum(["open", "disabled", "allowlist"]).optional(),
|
groupPolicy: GroupPolicySchema.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(),
|
||||||
textChunkLimit: z.number().int().positive().optional(),
|
textChunkLimit: z.number().int().positive().optional(),
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
import {
|
||||||
|
AllowFromListSchema,
|
||||||
|
buildNestedDmConfigSchema,
|
||||||
|
DmPolicySchema,
|
||||||
|
GroupPolicySchema,
|
||||||
|
} from "openclaw/plugin-sdk/compat";
|
||||||
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/matrix";
|
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/matrix";
|
||||||
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 matrixActionSchema = z
|
const matrixActionSchema = z
|
||||||
.object({
|
.object({
|
||||||
reactions: z.boolean().optional(),
|
reactions: z.boolean().optional(),
|
||||||
@@ -14,14 +18,6 @@ const matrixActionSchema = z
|
|||||||
})
|
})
|
||||||
.optional();
|
.optional();
|
||||||
|
|
||||||
const matrixDmSchema = z
|
|
||||||
.object({
|
|
||||||
enabled: z.boolean().optional(),
|
|
||||||
policy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
|
||||||
allowFrom: z.array(allowFromEntry).optional(),
|
|
||||||
})
|
|
||||||
.optional();
|
|
||||||
|
|
||||||
const matrixRoomSchema = z
|
const matrixRoomSchema = z
|
||||||
.object({
|
.object({
|
||||||
enabled: z.boolean().optional(),
|
enabled: z.boolean().optional(),
|
||||||
@@ -29,7 +25,7 @@ const matrixRoomSchema = z
|
|||||||
requireMention: z.boolean().optional(),
|
requireMention: z.boolean().optional(),
|
||||||
tools: ToolPolicySchema,
|
tools: ToolPolicySchema,
|
||||||
autoReply: z.boolean().optional(),
|
autoReply: z.boolean().optional(),
|
||||||
users: z.array(allowFromEntry).optional(),
|
users: AllowFromListSchema,
|
||||||
skills: z.array(z.string()).optional(),
|
skills: z.array(z.string()).optional(),
|
||||||
systemPrompt: z.string().optional(),
|
systemPrompt: z.string().optional(),
|
||||||
})
|
})
|
||||||
@@ -49,7 +45,7 @@ export const MatrixConfigSchema = z.object({
|
|||||||
initialSyncLimit: z.number().optional(),
|
initialSyncLimit: z.number().optional(),
|
||||||
encryption: z.boolean().optional(),
|
encryption: z.boolean().optional(),
|
||||||
allowlistOnly: z.boolean().optional(),
|
allowlistOnly: z.boolean().optional(),
|
||||||
groupPolicy: z.enum(["open", "disabled", "allowlist"]).optional(),
|
groupPolicy: GroupPolicySchema.optional(),
|
||||||
replyToMode: z.enum(["off", "first", "all"]).optional(),
|
replyToMode: z.enum(["off", "first", "all"]).optional(),
|
||||||
threadReplies: z.enum(["off", "inbound", "always"]).optional(),
|
threadReplies: z.enum(["off", "inbound", "always"]).optional(),
|
||||||
textChunkLimit: z.number().optional(),
|
textChunkLimit: z.number().optional(),
|
||||||
@@ -57,9 +53,9 @@ export const MatrixConfigSchema = z.object({
|
|||||||
responsePrefix: z.string().optional(),
|
responsePrefix: z.string().optional(),
|
||||||
mediaMaxMb: z.number().optional(),
|
mediaMaxMb: z.number().optional(),
|
||||||
autoJoin: z.enum(["always", "allowlist", "off"]).optional(),
|
autoJoin: z.enum(["always", "allowlist", "off"]).optional(),
|
||||||
autoJoinAllowlist: z.array(allowFromEntry).optional(),
|
autoJoinAllowlist: AllowFromListSchema,
|
||||||
groupAllowFrom: z.array(allowFromEntry).optional(),
|
groupAllowFrom: AllowFromListSchema,
|
||||||
dm: matrixDmSchema,
|
dm: buildNestedDmConfigSchema(),
|
||||||
groups: z.object({}).catchall(matrixRoomSchema).optional(),
|
groups: z.object({}).catchall(matrixRoomSchema).optional(),
|
||||||
rooms: z.object({}).catchall(matrixRoomSchema).optional(),
|
rooms: z.object({}).catchall(matrixRoomSchema).optional(),
|
||||||
actions: matrixActionSchema,
|
actions: matrixActionSchema,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
import { AllowFromListSchema, DmPolicySchema } from "openclaw/plugin-sdk/compat";
|
||||||
import { MarkdownConfigSchema, buildChannelConfigSchema } from "openclaw/plugin-sdk/nostr";
|
import { MarkdownConfigSchema, buildChannelConfigSchema } from "openclaw/plugin-sdk/nostr";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const allowFromEntry = z.union([z.string(), z.number()]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates https:// URLs only (no javascript:, data:, file:, etc.)
|
* Validates https:// URLs only (no javascript:, data:, file:, etc.)
|
||||||
*/
|
*/
|
||||||
@@ -76,10 +75,10 @@ export const NostrConfigSchema = z.object({
|
|||||||
relays: z.array(z.string()).optional(),
|
relays: z.array(z.string()).optional(),
|
||||||
|
|
||||||
/** DM access policy: pairing, allowlist, open, or disabled */
|
/** DM access policy: pairing, allowlist, open, or disabled */
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
dmPolicy: DmPolicySchema.optional(),
|
||||||
|
|
||||||
/** Allowed sender pubkeys (npub or hex format) */
|
/** Allowed sender pubkeys (npub or hex format) */
|
||||||
allowFrom: z.array(allowFromEntry).optional(),
|
allowFrom: AllowFromListSchema,
|
||||||
|
|
||||||
/** Profile metadata (NIP-01 kind:0 content) */
|
/** Profile metadata (NIP-01 kind:0 content) */
|
||||||
profile: NostrProfileSchema.optional(),
|
profile: NostrProfileSchema.optional(),
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
AllowFromEntrySchema,
|
AllowFromListSchema,
|
||||||
buildCatchallMultiAccountChannelSchema,
|
buildCatchallMultiAccountChannelSchema,
|
||||||
|
DmPolicySchema,
|
||||||
|
GroupPolicySchema,
|
||||||
} from "openclaw/plugin-sdk/compat";
|
} from "openclaw/plugin-sdk/compat";
|
||||||
import { MarkdownConfigSchema } from "openclaw/plugin-sdk/zalo";
|
import { MarkdownConfigSchema } from "openclaw/plugin-sdk/zalo";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
@@ -15,10 +17,10 @@ const zaloAccountSchema = z.object({
|
|||||||
webhookUrl: z.string().optional(),
|
webhookUrl: z.string().optional(),
|
||||||
webhookSecret: buildSecretInputSchema().optional(),
|
webhookSecret: buildSecretInputSchema().optional(),
|
||||||
webhookPath: z.string().optional(),
|
webhookPath: z.string().optional(),
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
dmPolicy: DmPolicySchema.optional(),
|
||||||
allowFrom: z.array(AllowFromEntrySchema).optional(),
|
allowFrom: AllowFromListSchema,
|
||||||
groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(),
|
groupPolicy: GroupPolicySchema.optional(),
|
||||||
groupAllowFrom: z.array(AllowFromEntrySchema).optional(),
|
groupAllowFrom: AllowFromListSchema,
|
||||||
mediaMaxMb: z.number().optional(),
|
mediaMaxMb: z.number().optional(),
|
||||||
proxy: z.string().optional(),
|
proxy: z.string().optional(),
|
||||||
responsePrefix: z.string().optional(),
|
responsePrefix: z.string().optional(),
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
AllowFromEntrySchema,
|
AllowFromListSchema,
|
||||||
buildCatchallMultiAccountChannelSchema,
|
buildCatchallMultiAccountChannelSchema,
|
||||||
|
DmPolicySchema,
|
||||||
|
GroupPolicySchema,
|
||||||
} from "openclaw/plugin-sdk/compat";
|
} from "openclaw/plugin-sdk/compat";
|
||||||
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/zalouser";
|
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/zalouser";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
@@ -17,11 +19,11 @@ const zalouserAccountSchema = z.object({
|
|||||||
enabled: z.boolean().optional(),
|
enabled: z.boolean().optional(),
|
||||||
markdown: MarkdownConfigSchema,
|
markdown: MarkdownConfigSchema,
|
||||||
profile: z.string().optional(),
|
profile: z.string().optional(),
|
||||||
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
dmPolicy: DmPolicySchema.optional(),
|
||||||
allowFrom: z.array(AllowFromEntrySchema).optional(),
|
allowFrom: AllowFromListSchema,
|
||||||
historyLimit: z.number().int().min(0).optional(),
|
historyLimit: z.number().int().min(0).optional(),
|
||||||
groupAllowFrom: z.array(AllowFromEntrySchema).optional(),
|
groupAllowFrom: AllowFromListSchema,
|
||||||
groupPolicy: z.enum(["disabled", "allowlist", "open"]).optional(),
|
groupPolicy: GroupPolicySchema.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(),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { z, type ZodTypeAny } from "zod";
|
import { z, type ZodTypeAny } from "zod";
|
||||||
|
import { DmPolicySchema } from "../../config/zod-schema.core.js";
|
||||||
import type { ChannelConfigSchema } from "./types.plugin.js";
|
import type { ChannelConfigSchema } from "./types.plugin.js";
|
||||||
|
|
||||||
type ZodSchemaWithToJsonSchema = ZodTypeAny & {
|
type ZodSchemaWithToJsonSchema = ZodTypeAny & {
|
||||||
@@ -10,6 +11,17 @@ type ExtendableZodObject = ZodTypeAny & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AllowFromEntrySchema = z.union([z.string(), z.number()]);
|
export const AllowFromEntrySchema = z.union([z.string(), z.number()]);
|
||||||
|
export const AllowFromListSchema = z.array(AllowFromEntrySchema).optional();
|
||||||
|
|
||||||
|
export function buildNestedDmConfigSchema() {
|
||||||
|
return z
|
||||||
|
.object({
|
||||||
|
enabled: z.boolean().optional(),
|
||||||
|
policy: DmPolicySchema.optional(),
|
||||||
|
allowFrom: AllowFromListSchema,
|
||||||
|
})
|
||||||
|
.optional();
|
||||||
|
}
|
||||||
|
|
||||||
export function buildCatchallMultiAccountChannelSchema<T extends ExtendableZodObject>(
|
export function buildCatchallMultiAccountChannelSchema<T extends ExtendableZodObject>(
|
||||||
accountSchema: T,
|
accountSchema: T,
|
||||||
|
|||||||
@@ -198,6 +198,8 @@ export { createPluginRuntimeStore } from "./runtime-store.js";
|
|||||||
export { createScopedChannelConfigBase } from "./channel-config-helpers.js";
|
export { createScopedChannelConfigBase } from "./channel-config-helpers.js";
|
||||||
export {
|
export {
|
||||||
AllowFromEntrySchema,
|
AllowFromEntrySchema,
|
||||||
|
AllowFromListSchema,
|
||||||
|
buildNestedDmConfigSchema,
|
||||||
buildCatchallMultiAccountChannelSchema,
|
buildCatchallMultiAccountChannelSchema,
|
||||||
} from "../channels/plugins/config-schema.js";
|
} from "../channels/plugins/config-schema.js";
|
||||||
export type { ChannelDock } from "../channels/dock.js";
|
export type { ChannelDock } from "../channels/dock.js";
|
||||||
|
|||||||
Reference in New Issue
Block a user