UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

48 lines (47 loc) • 2.53 kB
import { t as AgentsApiClient } from "./agentsapi-client-BkGGOio6.mjs"; import { i as resolveAgentsApiSessionAccessError } from "./agentsapi-errors-ByxEsPsd.mjs"; import { t as buildAgentsApiMcpTools } from "./agentsapi-mcp-CLo_Gpkq.mjs"; import { i as resolveAgentsApiNativeToolPolicy, n as requireAgentsApiSessionFingerprint, r as resolveAgentsApiEnvironment, t as agentsApiConfigSchema } from "./config-ClWEtS9v.mjs"; import { createHash } from "node:crypto"; //#region extensions/agentsapi/agentsapi-binding-migration.ts /** The binding owner calls this once, under its lease, before admitting legacy state. */ async function migrateAgentsApiBinding(e, t, n, r) { const assertMigrationCurrent = () => { r(); t.abortSignal?.throwIfAborted(); }; assertMigrationCurrent(); const i = agentsApiConfigSchema.parse(n() ?? {}); if (!i.forwarding.gatewayTools || !i.forwarding.mcpServers) throw new Error("Agents API legacy binding cannot adopt forwarding restrictions; restore the original configuration and API key and retry, or reset the OpenClaw session to settle the saved native session with a currently authorized key. The saved binding has been retained."); const a = resolveAgentsApiEnvironment(i, t.workspaceDir); const { webSearchEnabled: o } = resolveAgentsApiNativeToolPolicy(t, i); const s = await buildAgentsApiMcpTools(t); assertMigrationCurrent(); const c = [ t.model.id, t.resolvedApiKey, ...a.type === "self_hosted" || a.network != null ? [a] : [], ...s.length ? [s] : [] ]; const l = createHash("sha256").update(JSON.stringify(c)).digest("hex"); if (e.authFingerprint !== l || !o) throw new Error("Agents API legacy binding cannot verify the original model, API key, environment, MCP, or web-search policy; restore the original configuration and API key and retry, or reset the OpenClaw session to settle the saved native session with a currently authorized key. The saved binding has been retained."); try { const n = t.abortSignal ? AbortSignal.any([t.abortSignal, AbortSignal.timeout(3e4)]) : AbortSignal.timeout(3e4); await new AgentsApiClient(t.resolvedApiKey, assertMigrationCurrent).session(e.sessionId, n); assertMigrationCurrent(); } catch (t) { throw resolveAgentsApiSessionAccessError(t, e.sessionId); } return { sessionId: e.sessionId, configFingerprint: requireAgentsApiSessionFingerprint({ model: t.model.id, environment: a, mcpTools: s, webSearchEnabled: o, forwarding: i.forwarding }) }; } //#endregion export { migrateAgentsApiBinding as t };