UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

63 lines (62 loc) • 2.91 kB
import { w as root } from "./fs-safe-BbWvmdVn.mjs"; import { i as getGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-BmYo9Q7A.mjs"; import { Fn as object, Jn as string } from "./schemas-Cy6abvsu.mjs"; import { t as ErrorCodes } from "./gateway-error-details-B69XiHdh.mjs"; import { p as errorShape } from "./error-codes-BzF7aRQ0.mjs"; import { t as iteratePluginRootContributions } from "./plugin-root-contributions-BNGZsh9w.mjs"; import { a as readGatewayRequestMutationAuthority } from "./session-mutation-guards-Bjnk_O0z.mjs"; import { n as dispatchGatewayMethodInProcessRaw } from "./server-plugin-in-process-dispatch-B-bx4bU2.mjs"; //#region 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() }); /** Installation only publishes metadata. This endpoint requires an explicit user click. */ 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 + ".\n\n" + 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))); } } }; //#endregion export { mcpAppOnboardingHandlers };