oclaw/openclaw/extensions/webhooks/src/config.ts
oliver dbbe3add6a 重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
2026-04-26 08:34:33 +08:00

73 lines
2.1 KiB
TypeScript

import { z } from "zod";
import { normalizeWebhookPath } from "../runtime-api.js";
const secretRefSchema = z
.object({
source: z.enum(["env", "file", "exec"]),
provider: z.string().trim().min(1),
id: z.string().trim().min(1),
})
.strict();
const secretInputSchema = z.union([z.string().trim().min(1), secretRefSchema]);
const webhookRouteConfigSchema = z
.object({
enabled: z.boolean().optional().default(true),
path: z.string().trim().min(1).optional(),
sessionKey: z.string().trim().min(1),
secret: secretInputSchema,
controllerId: z.string().trim().min(1).optional(),
description: z.string().trim().min(1).optional(),
})
.strict();
const webhooksPluginConfigSchema = z
.object({
routes: z.record(z.string().trim().min(1), webhookRouteConfigSchema).default({}),
})
.strict();
export type WebhookSecretInput = z.infer<typeof secretInputSchema>;
export type ConfiguredWebhookRouteConfig = {
routeId: string;
path: string;
sessionKey: string;
secret: WebhookSecretInput;
controllerId: string;
description?: string;
};
export function resolveWebhooksPluginConfig(params: {
pluginConfig: unknown;
}): ConfiguredWebhookRouteConfig[] {
const parsed = webhooksPluginConfigSchema.parse(params.pluginConfig ?? {});
const configuredRoutes: ConfiguredWebhookRouteConfig[] = [];
const seenPaths = new Map<string, string>();
for (const [routeId, route] of Object.entries(parsed.routes)) {
if (!route.enabled) {
continue;
}
const path = normalizeWebhookPath(route.path ?? `/plugins/webhooks/${routeId}`);
const existingRouteId = seenPaths.get(path);
if (existingRouteId) {
throw new Error(
`webhooks.routes.${routeId}.path conflicts with routes.${existingRouteId}.path (${path}).`,
);
}
seenPaths.set(path, routeId);
configuredRoutes.push({
routeId,
path,
sessionKey: route.sessionKey,
secret: route.secret,
controllerId: route.controllerId ?? `webhooks/${routeId}`,
...(route.description ? { description: route.description } : {}),
});
}
return configuredRoutes;
}