openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines • 4.57 kB
JavaScript
import{n as normalizeAccountId,t as DEFAULT_ACCOUNT_ID}from"./account-id-3yqrEsRn.mjs";import{Fn as object,Jn as string,Lt as boolean,Nt as array,Pn as number,Un as record}from"./schemas-DuCQi-Qb.mjs";import{t as defineChannelSetupContract}from"./setup-contract-OX3vOUb4.mjs";import{i as buildChannelConfigSchema}from"./config-schema-BELT5_VZ.mjs";import{t as hasUnresolvedConfigValue}from"./gateway-config-runtime-EiUpvSz9.mjs";import{x as patchTopLevelChannelConfigSection}from"./setup-wizard-helpers-k68PnsC_.mjs";import"./setup-CylWArcc.mjs";import"./channel-setup-B5AhNmeg.mjs";import"./channel-config-schema-BMHY_2Pe.mjs";
//!extensions/a2a/src/accounts.ts
function listA2aChannelAccountIds(e){return e.channels?.a2a?[DEFAULT_ACCOUNT_ID]:[]}function resolveDefaultA2aChannelAccountId(){return DEFAULT_ACCOUNT_ID}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}}
//!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}}});
//!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]:{...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??{})}};export{resolveDefaultA2aChannelAccountId as i,listA2aChannelAccountIds as n,resolveA2aChannelAccount as r,a2aChannelSetupPlugin as t};