mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 20:35:39 -06:00
59 lines
2.0 KiB
TypeScript
Executable File
59 lines
2.0 KiB
TypeScript
Executable File
/**
|
|
* Decides when a GitHub Copilot model selection should install the Copilot
|
|
* runtime plugin instead of using the built-in provider path.
|
|
*/
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { resolveModelRuntimePolicy } from "./model-runtime-policy.js";
|
|
import { parseModelRefProvider } from "./openai-routing.js";
|
|
|
|
const GITHUB_COPILOT_PROVIDER_ID = "github-copilot";
|
|
|
|
/**
|
|
* Canonical id of the Copilot agent runtime plugin.
|
|
*/
|
|
const COPILOT_RUNTIME_ID = "copilot";
|
|
|
|
function parseModelRefId(model: string | undefined): string | undefined {
|
|
if (typeof model !== "string") {
|
|
return undefined;
|
|
}
|
|
const trimmed = model.trim();
|
|
const slash = trimmed.indexOf("/");
|
|
if (slash <= 0 || slash === trimmed.length - 1) {
|
|
return undefined;
|
|
}
|
|
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.
|
|
*/
|
|
export function modelSelectionShouldEnsureCopilotRuntimePlugin(params: {
|
|
model?: string;
|
|
config?: OpenClawConfig;
|
|
}): boolean {
|
|
if (parseModelRefProvider(params.model) !== GITHUB_COPILOT_PROVIDER_ID) {
|
|
return false;
|
|
}
|
|
const modelId = parseModelRefId(params.model);
|
|
const resolved = resolveModelRuntimePolicy({
|
|
config: params.config,
|
|
provider: GITHUB_COPILOT_PROVIDER_ID,
|
|
modelId,
|
|
});
|
|
const runtimeId = resolved.policy?.id?.trim().toLowerCase();
|
|
return runtimeId === COPILOT_RUNTIME_ID;
|
|
}
|