UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

158 lines (157 loc) • 6.7 kB
import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { i as resolveProviderIdForAuth } from "./provider-auth-aliases-CgGlzANu.mjs"; import { t as resolveRuntimeCliBackends } from "./cli-backends.runtime.js"; import { i as resolvePluginSetupRegistry, n as resolvePluginSetupCliBackend } from "./setup-registry-CgyZCdrJ.mjs"; import { n as mergePluginTextTransforms } from "./plugin-text-transforms-CMotGmZ0.mjs"; //#region src/agents/cli-backends.ts /** Match a profile's declared provider to a CLI binding without reading credential stores. */ function resolveCliRuntimeProfileAlias(e) { const t = normalizeProviderId(e.provider); const n = normalizeProviderId(e.profileProvider ?? ""); if (!t || !n || n === t) return; const r = { config: e.cfg, metadataSnapshot: e.metadataSnapshot }; if (resolveProviderIdForAuth(t, r) !== resolveProviderIdForAuth(n, { ...r, storedCredential: true })) return; return resolveCliRuntimeModelBackendBinding({ config: e.cfg, provider: t, runtime: n })?.runtime; } /** Exact caps require both a selectable tool surface and its declared execution adapter. */ function cliBackendSupportsExactToolAvailability(e) { return e.nativeToolMode === "selectable" && (e.toolAvailabilityEnforcement === "execution-args" && e.resolveExecutionArgs !== void 0 || e.toolAvailabilityEnforcement === "prepare-execution" && e.prepareExecution !== void 0); } function resolveCliBackendModelProvider(e) { const t = e.modelProvider?.trim(); return t ? normalizeProviderId(t) : void 0; } function addCliRuntimeModelBinding(e, t) { const n = resolveCliBackendModelProvider(t); const r = normalizeProviderId(t.id); if (!n || !r) return; e.set(`${n}:${r}`, { provider: n, runtime: r }); } function listCliRuntimeModelBackendBindings(e = {}) { const t = /* @__PURE__ */ new Map(); for (const e of resolveRuntimeCliBackends("metadata")) addCliRuntimeModelBinding(t, e); if (e.includeSetupRegistry === true) for (const n of resolvePluginSetupRegistry({ config: e.config, env: e.env }).cliBackends) addCliRuntimeModelBinding(t, n.backend); return [...t.values()].toSorted((e, t) => e.provider === t.provider ? e.runtime.localeCompare(t.runtime) : e.provider.localeCompare(t.provider)); } function listCliRuntimeProviderIds(e = {}) { return [...new Set(listCliRuntimeModelBackendBindings(e).filter((e) => e.runtime !== e.provider).map((e) => e.runtime))].toSorted(); } function resolveCliRuntimeBinding(e, t, n) { if (!e) return; const matchesProvider = (n) => t === void 0 || n === t || e === t; const r = listCliRuntimeModelBackendBindings().find((t) => t.runtime === e && matchesProvider(t.provider)); if (r) return r; const i = n(); const a = i && resolveCliBackendModelProvider(i.backend); return a && matchesProvider(a) ? { provider: a, runtime: e } : void 0; } function resolveCliRuntimeCanonicalProvider(e) { const t = normalizeProviderId(e.runtime ?? ""); return resolveCliRuntimeBinding(t, void 0, () => e.includeSetupRegistry === true && e.metadataSnapshot !== null ? resolvePluginSetupCliBackend({ backend: t, config: e.config, env: e.env, metadataSnapshot: e.metadataSnapshot }) : void 0)?.provider; } function resolveCliRuntimeModelBackendBinding(e) { const t = normalizeProviderId(e.provider ?? ""); const n = normalizeProviderId(e.runtime ?? ""); if (!t || !n) return; return resolveCliRuntimeBinding(n, t, () => e.config === void 0 ? void 0 : resolvePluginSetupCliBackend({ backend: n, config: e.config })); } function isCliRuntimeModelBackendForProvider(e) { return resolveCliRuntimeModelBackendBinding(e) !== void 0; } function resolveCliBackendLiveTest(e) { const t = normalizeProviderId(e); const n = resolvePluginSetupCliBackend({ backend: t }) ?? resolveRuntimeCliBackends().find((e) => normalizeProviderId(e.id) === t); if (!n) return null; const r = "backend" in n ? n.backend : n; return { defaultModelRef: r.liveTest?.defaultModelRef, defaultImageProbe: r.liveTest?.defaultImageProbe === true, defaultMcpProbe: r.liveTest?.defaultMcpProbe === true, dockerNpmPackage: r.liveTest?.docker?.npmPackage, dockerBinaryName: r.liveTest?.docker?.binaryName }; } /** Whether the backend can branch a native session at a recorded checkpoint. */ function cliBackendSupportsSessionFork(e, t) { const n = resolveCliBackendConfig(e, t)?.config; return Boolean(n?.forkArg && n.resumeAtArg); } function resolveCliBackendConfig(e, t, n = {}) { const r = normalizeProviderId(e); const i = { backendId: r, ...n.agentId ? { agentId: n.agentId } : {}, ...t ? { config: t } : {} }; const a = resolveRuntimeCliBackends().find((e) => normalizeProviderId(e.id) === r); const o = a ?? resolvePluginSetupCliBackend({ backend: r })?.backend; if (!o) return null; const s = a ? { ...o.config } : o.config; const c = o.normalizeConfig ? o.normalizeConfig(s, i) : s; const l = c.command?.trim(); if (!l) return null; const u = resolveCliBackendModelProvider(o); const d = o.bundleMcp === true; return { id: r, ...u ? { modelProvider: u } : {}, config: { ...c, command: l }, bundleMcp: d, bundleMcpMode: d ? o.bundleMcpMode ?? "claude-config-file" : void 0, ...a ? { pluginId: a.pluginId } : {}, transformSystemPrompt: o.transformSystemPrompt, textTransforms: mergePluginTextTransforms(o.textTransforms), defaultAuthProfileId: o.defaultAuthProfileId, authEpochMode: o.authEpochMode, autoSelectAuthProfile: o.autoSelectAuthProfile, contextEngineHostCapabilities: o.contextEngineHostCapabilities, ownsNativeCompaction: o.ownsNativeCompaction, manualCompaction: o.manualCompaction, prepareExecution: o.prepareExecution, resolveExecutionArgs: o.resolveExecutionArgs, resolveModelId: o.resolveModelId, parseJsonlEvent: o.parseJsonlEvent, classifyErrorCode: o.classifyErrorCode, parseJsonlLifecycleEvent: o.parseJsonlLifecycleEvent, toolAvailabilityEnforcement: o.toolAvailabilityEnforcement, projectNativeToolAuthority: o.projectNativeToolAuthority, resolveManagedNativeTools: o.resolveManagedNativeTools, nativeToolSearch: o.nativeToolSearch, nativeToolMode: o.nativeToolMode, hostOwnedTools: o.hostOwnedTools, sideQuestionToolMode: o.sideQuestionToolMode, runtimeArtifact: o.runtimeArtifact }; } //#endregion export { listCliRuntimeProviderIds as a, resolveCliRuntimeCanonicalProvider as c, listCliRuntimeModelBackendBindings as i, resolveCliRuntimeModelBackendBinding as l, cliBackendSupportsSessionFork as n, resolveCliBackendConfig as o, isCliRuntimeModelBackendForProvider as r, resolveCliBackendLiveTest as s, cliBackendSupportsExactToolAvailability as t, resolveCliRuntimeProfileAlias as u };