Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
320
extensions/github-copilot/models.ts
Normal file
320
extensions/github-copilot/models.ts
Normal file
@@ -0,0 +1,320 @@
|
||||
// Github Copilot plugin module implements models behavior.
|
||||
import type {
|
||||
ProviderResolveDynamicModelContext,
|
||||
ProviderRuntimeModel,
|
||||
} from "openclaw/plugin-sdk/core";
|
||||
import { buildCopilotIdeHeaders, COPILOT_INTEGRATION_ID } from "openclaw/plugin-sdk/provider-auth";
|
||||
import { readProviderJsonArrayFieldResponse } from "openclaw/plugin-sdk/provider-http";
|
||||
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import {
|
||||
normalizeModelCompat,
|
||||
supportsClaudeAdaptiveThinking,
|
||||
} from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import {
|
||||
asPositiveSafeInteger,
|
||||
normalizeOptionalLowercaseString,
|
||||
} from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import {
|
||||
resolveCopilotModelCompat,
|
||||
resolveCopilotTransportApi,
|
||||
resolveStaticCopilotModelOverride,
|
||||
} from "./model-metadata.js";
|
||||
|
||||
export const PROVIDER_ID = "github-copilot";
|
||||
const CODEX_FORWARD_COMPAT_TARGET_IDS = new Set(["gpt-5.4", "gpt-5.3-codex"]);
|
||||
// gpt-5.3-codex is only a useful template when gpt-5.4 is the target; it is
|
||||
// always a registry miss (and therefore skipped) when it is the target itself.
|
||||
const CODEX_TEMPLATE_MODEL_IDS = ["gpt-5.3-codex"] as const;
|
||||
|
||||
const DEFAULT_CONTEXT_WINDOW = 128_000;
|
||||
const DEFAULT_MAX_TOKENS = 8192;
|
||||
|
||||
function isCopilotCodexModelId(modelId: string): boolean {
|
||||
return /(?:^|[-_.])codex(?:$|[-_.])/.test(modelId);
|
||||
}
|
||||
|
||||
export function resolveCopilotForwardCompatModel(
|
||||
ctx: ProviderResolveDynamicModelContext,
|
||||
): ProviderRuntimeModel | undefined {
|
||||
const trimmedModelId = ctx.modelId.trim();
|
||||
if (!trimmedModelId) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// If the model is already in the registry, let the normal path handle it.
|
||||
const lowerModelId = normalizeOptionalLowercaseString(trimmedModelId) ?? "";
|
||||
const existing = ctx.modelRegistry.find(PROVIDER_ID, lowerModelId);
|
||||
if (existing) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// For gpt-5.4 and gpt-5.3-codex, clone from a registered codex template
|
||||
// to inherit the correct reasoning and capability flags.
|
||||
if (CODEX_FORWARD_COMPAT_TARGET_IDS.has(lowerModelId)) {
|
||||
for (const templateId of CODEX_TEMPLATE_MODEL_IDS) {
|
||||
const template = ctx.modelRegistry.find(
|
||||
PROVIDER_ID,
|
||||
templateId,
|
||||
) as ProviderRuntimeModel | null;
|
||||
if (!template) {
|
||||
continue;
|
||||
}
|
||||
return normalizeModelCompat({
|
||||
...template,
|
||||
id: trimmedModelId,
|
||||
name: trimmedModelId,
|
||||
} as ProviderRuntimeModel);
|
||||
}
|
||||
// Template not found — fall through to synthetic catch-all below.
|
||||
}
|
||||
|
||||
const staticOverride = resolveStaticCopilotModelOverride(lowerModelId);
|
||||
if (staticOverride) {
|
||||
const compat = staticOverride.compat ?? resolveCopilotModelCompat(trimmedModelId);
|
||||
return normalizeModelCompat({
|
||||
id: trimmedModelId,
|
||||
name: staticOverride.name ?? trimmedModelId,
|
||||
provider: PROVIDER_ID,
|
||||
api: staticOverride.api ?? resolveCopilotTransportApi(trimmedModelId),
|
||||
reasoning: staticOverride.reasoning ?? false,
|
||||
input: staticOverride.input ?? ["text", "image"],
|
||||
cost: staticOverride.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: staticOverride.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: staticOverride.maxTokens ?? DEFAULT_MAX_TOKENS,
|
||||
...(staticOverride.thinkingLevelMap
|
||||
? { thinkingLevelMap: staticOverride.thinkingLevelMap }
|
||||
: {}),
|
||||
...(compat ? { compat } : {}),
|
||||
} as ProviderRuntimeModel);
|
||||
}
|
||||
|
||||
// Catch-all: create a synthetic model definition for any unknown model ID.
|
||||
// The Copilot API is OpenAI-compatible and will return its own error if the
|
||||
// model isn't available on the user's plan. This lets new models be used
|
||||
// by simply adding them to agents.defaults.models in openclaw.json — no
|
||||
// code change required.
|
||||
const reasoning = /^o[13](\b|$)/.test(lowerModelId) || isCopilotCodexModelId(lowerModelId);
|
||||
const compat = resolveCopilotModelCompat(trimmedModelId);
|
||||
return normalizeModelCompat({
|
||||
id: trimmedModelId,
|
||||
name: trimmedModelId,
|
||||
provider: PROVIDER_ID,
|
||||
api: resolveCopilotTransportApi(trimmedModelId),
|
||||
reasoning,
|
||||
// Optimistic: most Copilot models support images, and the API rejects
|
||||
// image payloads for text-only models rather than failing silently.
|
||||
input: ["text", "image"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: DEFAULT_MAX_TOKENS,
|
||||
...(compat ? { compat } : {}),
|
||||
} as ProviderRuntimeModel);
|
||||
}
|
||||
|
||||
// Subset of the Copilot /models response shape that we depend on. We only read
|
||||
// fields we need; everything else is preserved as `unknown` so upstream changes
|
||||
// don't break parsing.
|
||||
type CopilotApiModelEntry = {
|
||||
id?: string;
|
||||
name?: string;
|
||||
object?: string;
|
||||
vendor?: string;
|
||||
preview?: boolean;
|
||||
model_picker_enabled?: boolean;
|
||||
capabilities?: {
|
||||
type?: string;
|
||||
family?: string;
|
||||
limits?: {
|
||||
max_context_window_tokens?: number;
|
||||
max_output_tokens?: number;
|
||||
max_prompt_tokens?: number;
|
||||
};
|
||||
supports?: {
|
||||
vision?: boolean;
|
||||
tool_calls?: boolean;
|
||||
streaming?: boolean;
|
||||
structured_outputs?: boolean;
|
||||
reasoning_effort?: string[] | null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const COPILOT_MODELS_LIST_DEFAULT_TIMEOUT_MS = 10_000;
|
||||
const COPILOT_ROUTER_ID_PREFIX = "accounts/";
|
||||
|
||||
function resolveCopilotApiForVendor(
|
||||
vendor: string | undefined,
|
||||
modelId: string,
|
||||
): "anthropic-messages" | "openai-completions" | "openai-responses" {
|
||||
if (vendor && vendor.toLowerCase() === "anthropic") {
|
||||
return "anthropic-messages";
|
||||
}
|
||||
return resolveCopilotTransportApi(modelId);
|
||||
}
|
||||
|
||||
function mergeCopilotCompat(
|
||||
base: ModelDefinitionConfig["compat"] | undefined,
|
||||
reasoningEfforts: string[] | null | undefined,
|
||||
): ModelDefinitionConfig["compat"] | undefined {
|
||||
const supportedReasoningEfforts = Array.isArray(reasoningEfforts)
|
||||
? [
|
||||
...new Set(
|
||||
reasoningEfforts
|
||||
.map((effort) => normalizeOptionalLowercaseString(effort))
|
||||
.filter((effort): effort is string => Boolean(effort)),
|
||||
),
|
||||
]
|
||||
: [];
|
||||
if (supportedReasoningEfforts.length === 0) {
|
||||
return base;
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
supportedReasoningEfforts,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveCopilotThinkingLevelMap(
|
||||
api: ModelDefinitionConfig["api"],
|
||||
modelId: string,
|
||||
compat: ModelDefinitionConfig["compat"] | undefined,
|
||||
): ModelDefinitionConfig["thinkingLevelMap"] | undefined {
|
||||
const efforts = compat?.supportedReasoningEfforts;
|
||||
if (api !== "anthropic-messages" || !Array.isArray(efforts)) {
|
||||
return undefined;
|
||||
}
|
||||
const supportsAdaptiveEffort = supportsClaudeAdaptiveThinking({ id: modelId });
|
||||
return {
|
||||
xhigh: supportsAdaptiveEffort && efforts.includes("xhigh") ? "xhigh" : null,
|
||||
max: supportsAdaptiveEffort && efforts.includes("max") ? "max" : null,
|
||||
};
|
||||
}
|
||||
|
||||
function mapCopilotApiModelToDefinition(
|
||||
entry: CopilotApiModelEntry,
|
||||
): ModelDefinitionConfig | undefined {
|
||||
const id = entry.id?.trim();
|
||||
if (!id) {
|
||||
return undefined;
|
||||
}
|
||||
// Skip non-chat objects (embeddings, routers, etc.) and internal router ids.
|
||||
if (entry.object && entry.object !== "model") {
|
||||
return undefined;
|
||||
}
|
||||
if (entry.capabilities?.type && entry.capabilities.type !== "chat") {
|
||||
return undefined;
|
||||
}
|
||||
if (id.startsWith(COPILOT_ROUTER_ID_PREFIX)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const limits = entry.capabilities?.limits;
|
||||
const supports = entry.capabilities?.supports;
|
||||
const reasoning = Array.isArray(supports?.reasoning_effort)
|
||||
? supports.reasoning_effort.length > 0
|
||||
: false;
|
||||
const supportsVision = supports?.vision === true;
|
||||
const input: ModelDefinitionConfig["input"] = supportsVision ? ["text", "image"] : ["text"];
|
||||
|
||||
const contextWindow =
|
||||
asPositiveSafeInteger(limits?.max_context_window_tokens) ?? DEFAULT_CONTEXT_WINDOW;
|
||||
const maxTokens = asPositiveSafeInteger(limits?.max_output_tokens) ?? DEFAULT_MAX_TOKENS;
|
||||
const compat = mergeCopilotCompat(resolveCopilotModelCompat(id), supports?.reasoning_effort);
|
||||
const api = resolveCopilotApiForVendor(entry.vendor, id);
|
||||
const thinkingLevelMap = resolveCopilotThinkingLevelMap(api, id, compat);
|
||||
|
||||
const definition: ModelDefinitionConfig = {
|
||||
id,
|
||||
name: entry.name?.trim() || id,
|
||||
api,
|
||||
reasoning,
|
||||
input,
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow,
|
||||
maxTokens,
|
||||
...(thinkingLevelMap ? { thinkingLevelMap } : {}),
|
||||
...(compat ? { compat } : {}),
|
||||
};
|
||||
return definition;
|
||||
}
|
||||
|
||||
function asCopilotApiModelEntry(value: unknown): CopilotApiModelEntry {
|
||||
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
||||
throw new Error("Copilot /models: malformed JSON response");
|
||||
}
|
||||
return value as CopilotApiModelEntry;
|
||||
}
|
||||
|
||||
export type FetchCopilotModelCatalogParams = {
|
||||
/** Short-lived Copilot API token (from `resolveCopilotApiToken`). */
|
||||
copilotApiToken: string;
|
||||
/** Resolved baseUrl from the same token-exchange response. */
|
||||
baseUrl: string;
|
||||
/** Optional fetch override for testing. */
|
||||
fetchImpl?: typeof fetch;
|
||||
/** Optional AbortSignal; defaults to a 10s timeout. */
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch the live Copilot model catalog from `${baseUrl}/models` and project it
|
||||
* into `ModelDefinitionConfig[]`. Used by the plugin's discovery hook so the
|
||||
* runtime catalog tracks per-account entitlements + accurate context windows
|
||||
* without manifest churn.
|
||||
*
|
||||
* Filters out non-chat objects (embeddings, routers) and internal router ids.
|
||||
* On any HTTP/parse failure the caller should fall back to the static manifest
|
||||
* catalog; this function throws so the caller decides the recovery shape.
|
||||
*/
|
||||
export async function fetchCopilotModelCatalog(
|
||||
params: FetchCopilotModelCatalogParams,
|
||||
): Promise<ModelDefinitionConfig[]> {
|
||||
const fetchImpl = params.fetchImpl ?? fetch;
|
||||
const trimmedBase = params.baseUrl.replace(/\/+$/, "");
|
||||
if (!trimmedBase) {
|
||||
throw new Error("fetchCopilotModelCatalog: baseUrl required");
|
||||
}
|
||||
if (!params.copilotApiToken.trim()) {
|
||||
throw new Error("fetchCopilotModelCatalog: copilotApiToken required");
|
||||
}
|
||||
const url = `${trimmedBase}/models`;
|
||||
const controller = params.signal ? undefined : new AbortController();
|
||||
const timeoutId = controller
|
||||
? setTimeout(() => controller.abort(), COPILOT_MODELS_LIST_DEFAULT_TIMEOUT_MS)
|
||||
: undefined;
|
||||
try {
|
||||
const res = await fetchImpl(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${params.copilotApiToken}`,
|
||||
...buildCopilotIdeHeaders(),
|
||||
"Copilot-Integration-Id": COPILOT_INTEGRATION_ID,
|
||||
},
|
||||
signal: params.signal ?? controller?.signal,
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`Copilot /models fetch failed: HTTP ${res.status}`);
|
||||
}
|
||||
const data = await readProviderJsonArrayFieldResponse(res, "Copilot /models", "data");
|
||||
const seen = new Set<string>();
|
||||
const out: ModelDefinitionConfig[] = [];
|
||||
for (const rawEntry of data) {
|
||||
const entry = asCopilotApiModelEntry(rawEntry);
|
||||
const def = mapCopilotApiModelToDefinition(entry);
|
||||
if (!def) {
|
||||
continue;
|
||||
}
|
||||
if (seen.has(def.id)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(def.id);
|
||||
out.push(def);
|
||||
}
|
||||
return out;
|
||||
} finally {
|
||||
if (timeoutId !== undefined) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user