openclaw/extensions/github-copilot/starter-model.ts
Finn763 53c0ca9754
fix(github-copilot): honor configured identity across model requests (#127965)
* fix(github-copilot): honor configured request identity

Honor existing provider request headers consistently across model discovery, setup, inference, and embeddings. Preserve the default identity and partition the live catalog by the configured identity.

Co-authored-by: Finn763 <165816600+Finn763@users.noreply.github.com>

* test(github-copilot): real-behavior wire-trace proof for #127965

* fix(github-copilot proof): print on-disk wire-trace.json sha256

* chore(github-copilot proof): drop pr-body.md from PR diff

* fix(github-copilot): finish identity checks and consolidate proof

Complete the typed provider fixture and keep the identity constant private. Retain canonical owner tests and real provider evidence; remove parallel copied mock implementations and generated PR-only traces while preserving the diagnostic commits in ancestry.

Co-authored-by: Finn763 <165816600+Finn763@users.noreply.github.com>

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: Finn763 <Finn763@users.noreply.github.com>
2026-08-27 01:29:28 -07:00

39 lines
1.6 KiB
TypeScript

// Resolves a safe setup default from the authenticated Copilot model catalog.
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
import { DEFAULT_COPILOT_MODEL } from "./model-metadata.js";
import { fetchCopilotModelCatalog, PROVIDER_ID, selectCopilotStarterModel } from "./models.js";
import { resolveCopilotRuntimeAuth } from "./runtime-auth.js";
import { buildCopilotRuntimeHeaders } from "./runtime-identity.js";
function preferredCopilotStarterModelId(): string {
const prefix = `${PROVIDER_ID}/`;
return DEFAULT_COPILOT_MODEL.startsWith(prefix)
? DEFAULT_COPILOT_MODEL.slice(prefix.length)
: DEFAULT_COPILOT_MODEL;
}
export async function resolveCopilotStarterModel(params: {
githubToken: string;
env?: NodeJS.ProcessEnv;
githubDomain?: string;
config?: OpenClawConfig;
}): Promise<string> {
const auth = await resolveCopilotRuntimeAuth({
githubToken: params.githubToken,
...(params.env ? { env: params.env } : {}),
...(params.githubDomain ? { githubDomain: params.githubDomain } : {}),
...(params.config ? { config: params.config } : {}),
});
const models = await fetchCopilotModelCatalog({
copilotApiToken: auth.apiKey,
baseUrl: auth.baseUrl,
headers: buildCopilotRuntimeHeaders({ config: params.config }),
});
const selected = selectCopilotStarterModel(models, preferredCopilotStarterModelId());
if (!selected) {
throw new Error(
"GitHub Copilot did not return an enabled, picker-visible chat model with streaming and tool-call support.",
);
}
return `${PROVIDER_ID}/${selected.id}`;
}