UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

65 lines (64 loc) 2.86 kB
import { t as resolveModelRuntimePolicy } from "./model-runtime-policy-CTIBeOo2.js"; import { s as parseModelRefProvider } from "./openai-routing-DXJmS9CT.js"; import { t as createRuntimePluginModelSelectionHelpers } from "./runtime-plugin-install-S6_BRVub.js"; //#region src/agents/copilot-routing.ts const GITHUB_COPILOT_PROVIDER_ID = "github-copilot"; /** * Canonical id of the Copilot agent runtime plugin. */ const COPILOT_RUNTIME_ID = "copilot"; function parseModelRefId(model) { if (typeof model !== "string") return; const trimmed = model.trim(); const slash = trimmed.indexOf("/"); if (slash <= 0 || slash === trimmed.length - 1) return; return trimmed.slice(slash + 1); } /** * Returns true when the selected model should trigger the external * `@openclaw/copilot` runtime plugin install. * * Gating contract (review #2, P1): * - Model ref must use the `github-copilot/*` provider prefix. * - The user's config must explicitly opt in by setting * `agentRuntime.id: "copilot"` at the provider, model, or agent scope * (resolved via `resolveModelRuntimePolicy`). * * Without the explicit opt-in we fall through to the built-in GitHub * Copilot provider, which has shipped support for `github-copilot/*` * models for a long time and must not install the runtime plugin for * users who never asked for it. */ function modelSelectionShouldEnsureCopilotRuntimePlugin(params) { if (parseModelRefProvider(params.model) !== "github-copilot") return false; const modelId = parseModelRefId(params.model); return resolveModelRuntimePolicy({ config: params.config, provider: GITHUB_COPILOT_PROVIDER_ID, modelId }).policy?.id?.trim().toLowerCase() === COPILOT_RUNTIME_ID; } //#endregion //#region src/commands/copilot-runtime-plugin-install.ts const COPILOT_RUNTIME_PLUGIN_ID = "copilot"; const COPILOT_RUNTIME_PLUGIN_DESCRIPTOR = { pluginId: COPILOT_RUNTIME_PLUGIN_ID, label: "GitHub Copilot agent runtime", npmSpec: "@openclaw/copilot", warningLabel: "GitHub Copilot" }; /** Return true when a selected model requires the Copilot runtime plugin to be installed. */ function selectedModelShouldEnsureCopilotRuntimePlugin(params) { return modelSelectionShouldEnsureCopilotRuntimePlugin({ config: params.cfg, model: params.model }); } const copilotRuntimePluginInstall = createRuntimePluginModelSelectionHelpers({ descriptor: COPILOT_RUNTIME_PLUGIN_DESCRIPTOR, shouldEnsure: selectedModelShouldEnsureCopilotRuntimePlugin }); const ensureCopilotRuntimePluginForModelSelection = copilotRuntimePluginInstall.ensure; const repairCopilotRuntimePluginInstallForModelSelection = copilotRuntimePluginInstall.repair; //#endregion export { selectedModelShouldEnsureCopilotRuntimePlugin as i, ensureCopilotRuntimePluginForModelSelection as n, repairCopilotRuntimePluginInstallForModelSelection as r, COPILOT_RUNTIME_PLUGIN_ID as t };