UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

193 lines (192 loc) • 5.71 kB
import { n as normalizeAccountId, t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs"; import { Fn as object, Jn as string, Lt as boolean, Nt as array, Pn as number, Un as record } from "./schemas-Cy6abvsu.mjs"; import { t as defineChannelSetupContract } from "./setup-contract-hyC_qGOR.mjs"; import { i as buildChannelConfigSchema } from "./config-schema-BxWrycwn.mjs"; import { t as hasUnresolvedConfigValue } from "./gateway-config-runtime-B8ERw-mA.mjs"; import { x as patchTopLevelChannelConfigSection } from "./setup-wizard-helpers-BVntL4dp.mjs"; import "./setup-CpdkGBHT.mjs"; import "./channel-setup-Dha6wc2W.mjs"; import "./channel-config-schema-Zup0A2Ue.mjs"; //#region extensions/a2a/src/accounts.ts function listA2aChannelAccountIds(e) { return e.channels?.a2a ? [DEFAULT_ACCOUNT_ID] : []; } function resolveDefaultA2aChannelAccountId() { return DEFAULT_ACCOUNT_ID; } /** * A `${VAR}` token reference whose variable is unset stays in config as literal * text, so it must never act as a credential: a caller could send that guessable * text as the bearer. Drop such peers (and such outbound tokens) so every consumer * sees them as unconfigured. */ function withoutUnresolvedCredentials(e, t) { const n = []; const r = []; const i = t.peers; if (!i) return { config: t, unresolvedPeers: n, unresolvedOutboundPeers: r }; const a = {}; for (const [t, o] of Object.entries(i)) { const i = [ "channels", "a2a", "peers", t ]; if (hasUnresolvedConfigValue(e, [...i, "token"])) { n.push(t); continue; } if (o.outboundToken && hasUnresolvedConfigValue(e, [...i, "outboundToken"])) { r.push(t); const { outboundToken: e, ...n } = o; a[t] = n; continue; } a[t] = o; } return { config: { ...t, peers: a }, unresolvedPeers: n, unresolvedOutboundPeers: r }; } function resolveA2aChannelAccount(e) { const { config: t, unresolvedPeers: n, unresolvedOutboundPeers: r } = withoutUnresolvedCredentials(e.cfg, e.cfg.channels?.a2a ?? {}); return { accountId: normalizeAccountId(e.accountId), enabled: t.enabled !== false, configured: Object.keys(t.peers ?? {}).length > 0, config: t, unresolvedPeers: n, unresolvedOutboundPeers: r }; } //#endregion //#region extensions/a2a/src/config-schema.ts const a2aPeerNamePattern = /^[a-z0-9][a-z0-9._-]{0,63}$/; const a2aHttpUrlSchema = string().url().and(string().regex(/^https?:\/\//, "A2A URLs must use HTTP or HTTPS")); const a2aPeerConfigSchema = object({ token: string().min(1), url: a2aHttpUrlSchema.optional(), outboundToken: string().min(1).optional() }).strict(); const a2aChannelConfigSchema = object({ enabled: boolean().optional(), configWrites: boolean().optional(), advertisedUrl: a2aHttpUrlSchema.optional(), replyTimeoutMs: number().int().min(5e3).max(6e5).optional(), rateLimitPerMinute: number().int().min(0).optional(), exposeAgents: array(string()).optional(), peers: record(string().regex(a2aPeerNamePattern), a2aPeerConfigSchema).optional() }).strict(); const a2aPluginConfigSchema = buildChannelConfigSchema(a2aChannelConfigSchema, { uiHints: { advertisedUrl: { label: "Advertised Gateway URL", help: "Public Gateway origin included in the A2A agent card." }, replyTimeoutMs: { label: "Blocking Reply Timeout (ms)", advanced: true }, rateLimitPerMinute: { label: "Requests Per Peer Per Minute", advanced: true }, exposeAgents: { label: "Exposed Agent IDs" }, "peers.*.token": { label: "Inbound Bearer Token", sensitive: true }, "peers.*.outboundToken": { label: "Outbound Bearer Token", sensitive: true } } }); //#endregion //#region extensions/a2a/src/channel-base.ts const A2A_CHANNEL_ID = "a2a"; const a2aChannelRuntimeMeta = { id: "a2a", label: "A2A", selectionLabel: "A2A (Agent-to-Agent Protocol)", docsPath: "/channels/a2a", docsLabel: "a2a", blurb: "Connect external agents through the A2A v1.0 protocol.", order: 75 }; const a2aChannelSetupPlugin = { id: "a2a", meta: a2aChannelRuntimeMeta, capabilities: { chatTypes: ["direct"] }, reload: { configPrefixes: ["channels.a2a"] }, configSchema: a2aPluginConfigSchema, setupContract: defineChannelSetupContract({ fields: { advertisedUrl: { kind: "string", cli: { flags: "--advertised-url <url>", description: "Public Gateway origin published in the A2A agent card" } }, peerName: { kind: "string", cli: { flags: "--peer-name <name>", description: "A2A peer identifier to authorize" } }, peerToken: { kind: "string", sensitive: true, cli: { flags: "--peer-token <token>", description: "Bearer token for the A2A peer" } } }, adapter: { applyAccountConfig: ({ cfg: e, input: t }) => { const n = t; const r = e.channels?.a2a?.peers; const i = n.peerName?.trim(); const a = n.peerToken?.trim(); const o = n.advertisedUrl?.trim(); return patchTopLevelChannelConfigSection({ cfg: e, channel: "a2a", enabled: true, patch: { ...o ? { advertisedUrl: o } : {}, ...i && a ? { peers: { ...r, [i]: { token: a } } } : {} } }); } } }), config: { listAccountIds: listA2aChannelAccountIds, resolveAccount: (e, t) => resolveA2aChannelAccount({ cfg: e, accountId: t }), defaultAccountId: resolveDefaultA2aChannelAccountId, isConfigured: (e) => e.configured, isEnabled: (e) => e.enabled, resolveAllowFrom: ({ cfg: e, accountId: t }) => Object.keys(resolveA2aChannelAccount({ cfg: e, accountId: t }).config.peers ?? {}) } }; //#endregion export { resolveDefaultA2aChannelAccountId as i, listA2aChannelAccountIds as n, resolveA2aChannelAccount as r, a2aChannelSetupPlugin as t };