refactor: share multi-account config schema fragments

This commit is contained in:
Peter Steinberger
2026-03-08 19:43:18 +00:00
parent 52a253f18c
commit 5845b5bfba
5 changed files with 34 additions and 24 deletions

View File

@@ -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") {

View File

@@ -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";