UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines (4 loc) • 2.48 kB
import{x as root}from"./fs-safe-Bxzu1j4h.mjs";import{o as getGatewayPluginMetadataSnapshot}from"./plugin-metadata-lifecycle-Bdt91XXL.mjs";import{Fn as object,Jn as string}from"./schemas-DuCQi-Qb.mjs";import{i as ErrorCodes}from"./missing-scope-error-CkgBgh6d.mjs";import{p as errorShape}from"./error-codes-CQNGhXT-.mjs";import{t as iteratePluginRootContributions}from"./plugin-root-contributions-CmNJYoLA.mjs";import{a as readGatewayRequestMutationAuthority}from"./session-mutation-guards-Bqnc5JYL.mjs";import{n as dispatchGatewayMethodInProcessRaw}from"./server-plugin-in-process-dispatch-bWayi_W3.mjs"; //!src/gateway/server-methods/mcp-app-onboarding.ts const schema=object({sessionKey:string().min(1),agentId:string().optional(),pluginId:string().min(1),idempotencyKey:string().min(1),expectedLeafEntryId:string().nullable().optional()});const mcpAppOnboardingHandlers={"mcp.app.onboard":async e=>{try{const t=schema.parse(e.params);const n=e.sessionAccessAuthority;if(!n)throw new Error(`Plugin onboarding session authority is unavailable`);n.assertCurrent();const r=readGatewayRequestMutationAuthority(e);const i=getGatewayPluginMetadataSnapshot();if(!i)throw new Error(`Plugin metadata is not ready`);const find=()=>[...iteratePluginRootContributions({metadataSnapshot:i,config:e.context.getRuntimeConfig(),contribution:`skills`})].find(({record:e})=>e.id===t.pluginId)?.record;const a=find();if(!a?.onboardingSkill)throw new Error(`This plugin has no packaged onboarding skill`);const o=await(await root(a.rootDir)).read(a.onboardingSkill,{maxBytes:262144,hardlinks:`reject`,symlinks:`reject`});n.assertCurrent();if(getGatewayPluginMetadataSnapshot()!==i||find()!==a)throw new Error(`Plugin onboarding availability changed`);const s=await dispatchGatewayMethodInProcessRaw(`chat.send`,{sessionKey:n.target.sessionKey,agentId:n.target.agentId,message:`Run the setup skill for plugin `+a.id+`. `+o.buffer.toString(`utf8`),idempotencyKey:t.idempotencyKey,...t.expectedLeafEntryId!==void 0?{expectedLeafEntryId:t.expectedLeafEntryId}:{},suppressCommandInterpretation:true},{disableSyntheticClient:true,requireScopedClient:true,signal:e.signal,hasCurrentClientAuthority:e.hasCurrentClientAuthority,prepareDispatchCurrent:async()=>n.assertCurrent(),sessionMutationCommitGuard:r.assertCurrent});e.respond(s.ok,s.payload,s.error)}catch(t){e.respond(false,void 0,errorShape(ErrorCodes.INVALID_REQUEST,t instanceof Error?t.message:String(t)))}}};export{mcpAppOnboardingHandlers};