A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
use the prime inference catalog thinking metadata for reasoning controls + team-scoped catalog fetches (#2519)
kta8cca493d5e0
diff --git a/packages/ai/.changes/prime-inference-catalog-reasoning-controls.md b/packages/ai/.changes/prime-inference-catalog-reasoning-controls.mdnew file mode 100644index 0000000000..26ef5dcb7d--- /dev/null+++ b/packages/ai/.changes/prime-inference-catalog-reasoning-controls.md@@ -0,0 +1 @@+- Changed Prime Inference models to take their reasoning controls from the live catalog's `supported_parameters` and `reasoning` metadata: effort routes send only their declared `reasoning_effort` values, toggle-only routes switch reasoning through the declared `reasoning` object, and mandatory routes hide the off level instead of sending disables the gateway rejects.diff --git a/packages/ai/src/prime-inference-model-catalog.ts b/packages/ai/src/prime-inference-model-catalog.tsindex f1dc3101c3..5f119118d8 100644--- a/packages/ai/src/prime-inference-model-catalog.ts+++ b/packages/ai/src/prime-inference-model-catalog.ts@@ -1,3 +1,5 @@+import type { ThinkingLevel, ThinkingLevelMap } from "./types.js";+export interface PrimeInferenceCatalogEntry {id: string;name?: string;@@ -9,6 +11,26 @@ export interface PrimeInferenceCatalogEntry {maxTokens?: number;vision?: boolean;reasoning?: boolean;+ /** Request parameter names the live route declares; absent when the route reports none. */+ supportedParameters?: string[];+ /** Reasoning effort values the live route declares; absent when the route has no effort selector. */+ reasoningEfforts?: string[];+ /** Whether the live route rejects requests that disable reasoning. */+ reasoningMandatory?: boolean;+}++/**+ * Reasoning request controls derived from a live Prime Inference catalog entry.+ * The gateway validates reasoning values per route and rejects undeclared+ * efforts, so only declared values are ever sent.+ */+export interface PrimeInferenceReasoningControls {+ /** Whether the route accepts a top-level `reasoning_effort` parameter. */+ supportsReasoningEffort: boolean;+ /** Thinking format required to address the route's declared reasoning parameters. */+ thinkingFormat?: "zai" | "openrouter";+ /** Local-to-route effort map; absent when the route exposes no reasoning parameter. */+ thinkingLevelMap?: ThinkingLevelMap;}function isRecord(value: unknown): value is Record<string, unknown> {@@ -23,6 +45,76 @@ function positiveInteger(value: unknown): number | undefined {return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;}+function parseStringArray(value: unknown): string[] | undefined {+ if (!Array.isArray(value)) return undefined;+ const entries = value.filter((entry): entry is string => typeof entry === "string" && entry.length > 0);+ return entries.length > 0 ? [...new Set(entries)] : undefined;+}++const REASONING_EFFORT_LEVELS: readonly ThinkingLevel[] = ["minimal", "low", "medium", "high", "xhigh", "max"];++/**+ * Derives reasoning request controls from the parameters a live route declares.+ * Returns undefined when the route does not report parameter support; callers+ * then keep their bundled template compat instead of guessing.+ */+export function getPrimeInferenceReasoningControls(+ entry: Pick<PrimeInferenceCatalogEntry, "supportedParameters" | "reasoningEfforts" | "reasoningMandatory">,+): PrimeInferenceReasoningControls | undefined {+ const supported = entry.supportedParameters;+ if (!supported) return undefined;+ const includes = new Set(supported);+ const supportsReasoningEffort = includes.has("reasoning_effort");+ const mandatory = entry.reasoningMandatory === true;+ let thinkingLevelMap: ThinkingLevelMap | undefined;+ if (supportsReasoningEffort && entry.reasoningEfforts) {+ // Efforts are only addressable through reasoning_effort; without that+ // parameter the route falls through to the reasoning-object toggle.+ thinkingLevelMap = {+ // Mandatory routes cannot disable reasoning; non-mandatory effort+ // routes accept "none" as the disable value even when they do not list it.+ off: mandatory ? null : "none",+ };+ for (const level of REASONING_EFFORT_LEVELS) {+ thinkingLevelMap[level] = entry.reasoningEfforts.includes(level) ? level : null;+ }+ } else if (includes.has("reasoning") && !supportsReasoningEffort) {+ // The route can only toggle reasoning on or off; expose a single generic+ // level. A route that declares reasoning_effort but no supported efforts+ // deliberately gets no map here: the values are unknown, so callers fall+ // back to their bounded bundled template map instead of a guessed toggle.+ thinkingLevelMap = {+ ...(mandatory ? { off: null } : {}),+ minimal: null,+ low: null,+ medium: null,+ high: "high",+ xhigh: null,+ max: null,+ };+ } else if (includes.has("enable_thinking")) {+ // The ZAI toggle serializes every non-off level as enable_thinking: true,+ // so a mandatory route must hide off — selecting it would emit+ // enable_thinking: false, which the catalog declares unsupported.+ thinkingLevelMap = mandatory ? { off: null } : undefined;+ }+ // An effort route takes the default arm so the selected level is sent as+ // reasoning_effort; enable_thinking only claims the ZAI toggle when the+ // route declares no effort selector.+ const thinkingFormat = supportsReasoningEffort+ ? undefined+ : includes.has("enable_thinking")+ ? "zai"+ : includes.has("reasoning")+ ? "openrouter"+ : undefined;+ return {+ supportsReasoningEffort,+ ...(thinkingFormat ? { thinkingFormat } : {}),+ ...(thinkingLevelMap ? { thinkingLevelMap } : {}),+ };+}+export function isPrivatePrimeInferenceModelId(modelId: string): boolean {const normalizedId = modelId.toLowerCase();return normalizedId.startsWith("internal/") || normalizedId.startsWith("dev/") || normalizedId.includes(":");@@ -69,6 +161,10 @@ export function parsePrimeInferenceModelCatalog(outputModalities !== undefined;const cacheRead = nonNegativeNumber(pricing.cache_read_usd_per_mtok);const cacheWrite = nonNegativeNumber(pricing.cache_write_usd_per_mtok);+ const supportedParameters = parseStringArray(item.supported_parameters);+ const reasoningSpec = isRecord(item.reasoning) ? item.reasoning : undefined;+ const reasoningEfforts = parseStringArray(reasoningSpec?.supported_efforts);+ const reasoningMandatory = reasoningSpec?.mandatory === true ? true : undefined;seen.add(item.id);models.push({@@ -78,6 +174,9 @@ export function parsePrimeInferenceModelCatalog(output,...(cacheRead !== undefined ? { cacheRead } : {}),...(cacheWrite !== undefined ? { cacheWrite } : {}),+ ...(supportedParameters ? { supportedParameters } : {}),+ ...(reasoningEfforts ? { reasoningEfforts } : {}),+ ...(reasoningMandatory !== undefined ? { reasoningMandatory } : {}),...(hasSpecs? {contextWindow,diff --git a/packages/ai/test/fixture-models.ts b/packages/ai/test/fixture-models.tsindex 22f5ad62ef..95b9e9da47 100644--- a/packages/ai/test/fixture-models.ts+++ b/packages/ai/test/fixture-models.ts@@ -1081,6 +1081,64 @@ const fixtureModels = {contextWindow: 1000000,maxTokens: 131072,},+ // Prime Inference fixtures carry the reasoning controls the client derives+ // from the live catalog's supported_parameters/reasoning metadata+ // (getPrimeInferenceReasoningControls applied over the bundled templates by+ // buildPrimeInferenceModels; the derivation is covered by the catalog+ // tests). Gateway-verified 2026-09-21: z-ai/glm-5.3 declares reasoning_effort+ // with efforts low/high/max and mandatory reasoning; z-ai/glm-4.7 declares+ // only the optional reasoning toggle (no effort selector).+ "prime-inference/z-ai/glm-5.3": {+ id: "z-ai/glm-5.3",+ name: "GLM 5.3",+ api: "openai-completions",+ provider: "prime-inference",+ baseUrl: "https://api.pinference.ai/api/v1",+ compat: {+ supportsStore: false,+ supportsDeveloperRole: false,+ supportsReasoningEffort: true,+ maxTokensField: "max_tokens",+ supportsStrictMode: false,+ },+ reasoning: true,+ thinkingLevelMap: { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: null, max: "max" },+ input: ["text"],+ cost: {+ input: 1.4,+ output: 4.4,+ cacheRead: 0.26,+ cacheWrite: 1.4,+ },+ contextWindow: 1048576,+ maxTokens: 131072,+ },+ "prime-inference/z-ai/glm-4.7": {+ id: "z-ai/glm-4.7",+ name: "GLM 4.7",+ api: "openai-completions",+ provider: "prime-inference",+ baseUrl: "https://api.pinference.ai/api/v1",+ compat: {+ supportsStore: false,+ supportsDeveloperRole: false,+ supportsReasoningEffort: false,+ maxTokensField: "max_tokens",+ supportsStrictMode: false,+ thinkingFormat: "openrouter",+ },+ reasoning: true,+ thinkingLevelMap: { minimal: null, low: null, medium: null, high: "high", xhigh: null, max: null },+ input: ["text"],+ cost: {+ input: 0.6,+ output: 2.2,+ cacheRead: 0,+ cacheWrite: 0,+ },+ contextWindow: 204800,+ maxTokens: 131072,+ },"cloudflare-ai-gateway/claude-sonnet-4.6": {id: "claude-sonnet-4.6",name: "Claude Sonnet 4.6",diff --git a/packages/ai/test/openai-completions-tool-choice.test.ts b/packages/ai/test/openai-completions-tool-choice.test.tsindex 627545df46..789e159602 100644--- a/packages/ai/test/openai-completions-tool-choice.test.ts+++ b/packages/ai/test/openai-completions-tool-choice.test.ts@@ -1150,26 +1150,50 @@ describe("openai-completions tool_choice", () => {expect((payload as { reasoning_effort?: unknown }).reasoning_effort).toBe("none");});- it("sends no thinking parameter to Prime Inference GLM routes but keeps the z.ai toggle", async () => {+ // Gateway-verified (2026-09-21): glm-5.3 declares reasoning_effort, glm-4.7 only the reasoning object.+ it("sends only the declared reasoning parameters to Prime Inference GLM routes", async () => {const context = { messages: [{ role: "user" as const, content: "Hi", timestamp: Date.now() }] };const payloads = new Map<string, Record<string, unknown>>();- for (const model of [- getModel("prime-inference", "z-ai/glm-5.3")!,- getFixtureModel<"openai-completions">("zai", "glm-5.3")!,- ]) {- await streamSimple(model, context, {+ for (const [id, level] of [+ ["z-ai/glm-5.3", "high"],+ ["z-ai/glm-5.3", "medium"],+ ["z-ai/glm-4.7", "high"],+ ["z-ai/glm-4.7", "off"],+ ] as const) {+ await streamSimple(getFixtureModel<"openai-completions">("prime-inference", id)!, context, {apiKey: "test",- reasoning: "high",+ reasoning: level,onPayload: (params: unknown) => {- payloads.set(model.id, params as Record<string, unknown>);+ payloads.set(`${id}:${level}`, params as Record<string, unknown>);},}).result();}- const prime = payloads.get("z-ai/glm-5.3");- expect(prime?.enable_thinking).toBeUndefined();- expect(prime?.reasoning_effort).toBeUndefined();- expect(prime?.reasoning).toBeUndefined();- expect(payloads.get("glm-5.3")?.enable_thinking).toBe(true);+ const effort = payloads.get("z-ai/glm-5.3:high")!;+ expect(effort).toMatchObject({ reasoning_effort: "high" });+ expect(effort).not.toHaveProperty("enable_thinking");+ expect(effort).not.toHaveProperty("reasoning");+ expect(payloads.get("z-ai/glm-5.3:medium")).toMatchObject({ reasoning_effort: "high" });+ const toggle = payloads.get("z-ai/glm-4.7:high")!;+ expect(toggle).toMatchObject({ reasoning: { enabled: true } });+ expect(toggle).not.toHaveProperty("enable_thinking");+ expect(toggle).not.toHaveProperty("reasoning_effort");+ expect(payloads.get("z-ai/glm-4.7:off")).toMatchObject({ reasoning: { enabled: false } });+ });++ it("keeps the z.ai coding-plan toggle on enable_thinking", async () => {+ let payload: Record<string, unknown> | undefined;+ await streamSimple(+ getFixtureModel<"openai-completions">("zai", "glm-5.3")!,+ { messages: [{ role: "user" as const, content: "Hi", timestamp: Date.now() }] },+ {+ apiKey: "test",+ reasoning: "high",+ onPayload: (params: unknown) => {+ payload = params as Record<string, unknown>;+ },+ },+ ).result();+ expect(payload?.enable_thinking).toBe(true);});it("serializes explicit off only for models that allow disabling reasoning", async () => {diff --git a/packages/ai/test/prime-inference-model-catalog.test.ts b/packages/ai/test/prime-inference-model-catalog.test.tsindex 831c1f28e2..f1cbbd7667 100644--- a/packages/ai/test/prime-inference-model-catalog.test.ts+++ b/packages/ai/test/prime-inference-model-catalog.test.ts@@ -1,6 +1,9 @@import { afterEach, describe, expect, test } from "vitest";import { findEnvKeys, getEnvApiKey } from "../src/env-api-keys.js";-import { parsePrimeInferenceModelCatalog } from "../src/prime-inference-model-catalog.js";+import {+ getPrimeInferenceReasoningControls,+ parsePrimeInferenceModelCatalog,+} from "../src/prime-inference-model-catalog.js";function response(...data: unknown[]) {return { object: "list", data };@@ -99,6 +102,20 @@ describe("Prime Inference model catalog", () => {const model = { id: "duplicate", pricing: { input_usd_per_mtok: 1, output_usd_per_mtok: 2 } };expect(() => parsePrimeInferenceModelCatalog(response(model, model))).toThrow(/duplicate/i);});++ test("parses and sanitizes live reasoning declarations", () => {+ const [model] = parsePrimeInferenceModelCatalog(+ response({+ id: "z-ai/glm-5.3",+ pricing: { input_usd_per_mtok: 1.4, output_usd_per_mtok: 4.4 },+ supported_parameters: ["max_tokens", "reasoning", "reasoning_effort", 42, null],+ reasoning: { supported_efforts: ["low", "high", "max", "high", null], mandatory: true },+ }),+ );+ expect(model.supportedParameters).toEqual(["max_tokens", "reasoning", "reasoning_effort"]);+ expect(model.reasoningEfforts).toEqual(["low", "high", "max"]);+ expect(model.reasoningMandatory).toBe(true);+ });});// Folded in from prime-inference-models.test.ts: the catalog/config assertions there churned on@@ -128,3 +145,75 @@ describe("Prime Inference API key resolution", () => {expect(getEnvApiKey("prime-inference")).toBeUndefined();});});++// Maps live /models reasoning metadata onto request controls; the gateway+// rejects undeclared efforts, and "none" disables non-mandatory effort routes.+describe("getPrimeInferenceReasoningControls", () => {+ const mandatoryMap = { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: null, max: "max" };+ const optionalMap = { off: "none", minimal: null, low: null, medium: null, high: "high", xhigh: "xhigh", max: null };++ test("maps declared route shapes onto reasoning controls", () => {+ const effortRoute = { supportedParameters: ["reasoning", "reasoning_effort"] };+ expect(+ getPrimeInferenceReasoningControls({+ ...effortRoute,+ reasoningEfforts: ["low", "high", "max"],+ reasoningMandatory: true,+ }),+ ).toEqual({ supportsReasoningEffort: true, thinkingLevelMap: mandatoryMap });+ expect(getPrimeInferenceReasoningControls({ ...effortRoute, reasoningEfforts: ["xhigh", "high"] })).toEqual({+ supportsReasoningEffort: true,+ thinkingLevelMap: optionalMap,+ });+ const toggleControls = {+ supportsReasoningEffort: false,+ thinkingFormat: "openrouter",+ thinkingLevelMap: { minimal: null, low: null, medium: null, high: "high", xhigh: null, max: null },+ };+ expect(getPrimeInferenceReasoningControls({ supportedParameters: ["reasoning"] })).toEqual(toggleControls);+ expect(+ getPrimeInferenceReasoningControls({ supportedParameters: ["reasoning"], reasoningEfforts: ["high"] }),+ ).toEqual(toggleControls);+ // An effort route that declares reasoning_effort but no supported efforts+ // gets no map (and no format): the values are unknown, so callers fall+ // back to their bounded bundled template map instead of a guessed toggle.+ expect(getPrimeInferenceReasoningControls({ supportedParameters: ["reasoning", "reasoning_effort"] })).toEqual({+ supportsReasoningEffort: true,+ });+ // enable_thinking routes take the ZAI toggle: mandatory routes must hide+ // off (the serializer would otherwise disable reasoning), and a route that+ // also declares reasoning_effort must keep the effort arm so the selected+ // level is actually sent.+ expect(+ getPrimeInferenceReasoningControls({ supportedParameters: ["enable_thinking"], reasoningMandatory: true }),+ ).toEqual({ supportsReasoningEffort: false, thinkingFormat: "zai", thinkingLevelMap: { off: null } });+ expect(getPrimeInferenceReasoningControls({ supportedParameters: ["enable_thinking"] })).toEqual({+ supportsReasoningEffort: false,+ thinkingFormat: "zai",+ });+ expect(+ getPrimeInferenceReasoningControls({+ supportedParameters: ["enable_thinking", "reasoning_effort"],+ reasoningEfforts: ["high"],+ }),+ ).toEqual({+ supportsReasoningEffort: true,+ thinkingLevelMap: {+ off: "none",+ minimal: null,+ low: null,+ medium: null,+ high: "high",+ xhigh: null,+ max: null,+ },+ });+ expect(+ getPrimeInferenceReasoningControls({ supportedParameters: ["enable_thinking", "reasoning_effort"] }),+ ).toEqual({ supportsReasoningEffort: true });+ expect(getPrimeInferenceReasoningControls({ supportedParameters: ["max_tokens"] })).toEqual({+ supportsReasoningEffort: false,+ });+ expect(getPrimeInferenceReasoningControls({})).toBeUndefined();+ });+});diff --git a/packages/coding-agent/.changes/prime-inference-catalog-reasoning-controls.md b/packages/coding-agent/.changes/prime-inference-catalog-reasoning-controls.mdnew file mode 100644index 0000000000..c3bfbb954c--- /dev/null+++ b/packages/coding-agent/.changes/prime-inference-catalog-reasoning-controls.md@@ -0,0 +1 @@+- Changed live Prime Inference catalog refreshes to rebuild each model's thinking levels and reasoning compat from the route's declared parameters, so stale bundled templates no longer override what the gateway actually accepts.diff --git a/packages/coding-agent/.changes/prime-inference-team-source.md b/packages/coding-agent/.changes/prime-inference-team-source.mdnew file mode 100644index 0000000000..4bd87a98bb--- /dev/null+++ b/packages/coding-agent/.changes/prime-inference-team-source.md@@ -0,0 +1 @@+- Fixed the stored Prime team selection being hidden whenever the API key came from a runtime or environment override: an ambient PRIME_API_KEY supplies the key, never the team, so the stored login's team still scopes the credentialed catalog and private-model fetches and team-private internal routes keep appearing in the model picker.diff --git a/packages/coding-agent/src/core/auth-storage.ts b/packages/coding-agent/src/core/auth-storage.tsindex ae169760b1..631c5423c4 100644--- a/packages/coding-agent/src/core/auth-storage.ts+++ b/packages/coding-agent/src/core/auth-storage.ts@@ -1243,8 +1243,13 @@ export class AuthStorage {getPrimeInferenceTeamSelection(): PrimeTeamCredential | null | undefined {if (process.env.PRIME_TEAM_ID?.trim()) return undefined;- const authSource = this.getAuthStatus(PRIME_INFERENCE_PROVIDER_ID).source;- if (authSource === "runtime" || authSource === "environment") return undefined;+ // The stored primeTeam survives runtime and environment API-key+ // overrides: an ambient PRIME_API_KEY supplies the key, never the team,+ // so the stored login's team still scopes the credentialed catalog and+ // private-model fetches (fleet parity with the Rust port's auth+ // team-source change). Without this, boxes running with an ambient+ // PRIME_API_KEY never send X-Prime-Team-ID, and the team-private+ // internal/* routes disappear from /model.const credential = this.data[PRIME_INFERENCE_PROVIDER_ID];return credential?.type === "api_key" ? credential.primeTeam : undefined;}diff --git a/packages/coding-agent/src/core/prime-inference-model-catalog.ts b/packages/coding-agent/src/core/prime-inference-model-catalog.tsindex 992df7d058..66823bd677 100644--- a/packages/coding-agent/src/core/prime-inference-model-catalog.ts+++ b/packages/coding-agent/src/core/prime-inference-model-catalog.ts@@ -3,6 +3,7 @@ import { existsSync, mkdirSync, readFileSync } from "node:fs";import { basename, dirname, join } from "node:path";import {type Api,+ getPrimeInferenceReasoningControls,isPrivatePrimeInferenceModelId,type Model,type OpenAICompletionsCompat,@@ -21,8 +22,8 @@ const pendingRefreshes = new Map<string, Promise<Model<"openai-completions">[] |const DEFAULT_COMPAT: OpenAICompletionsCompat = {supportsStore: false,supportsDeveloperRole: false,- // The endpoint does not yet describe reasoning controls. Do not send an- // unconfirmed reasoning_effort parameter for models without a bundled template.+ // Routes that do not describe their reasoning controls get no unconfirmed+ // reasoning_effort parameter; live supported_parameters drive the override.supportsReasoningEffort: false,maxTokensField: "max_tokens",supportsStrictMode: false,@@ -50,6 +51,24 @@ export function buildPrimeInferenceModels(const contextWindow = entry.contextWindow ?? template?.contextWindow ?? 0;const maxTokens = Math.min(entry.maxTokens ?? template?.maxTokens ?? 0, contextWindow);const compat = structuredClone(template?.compat ?? DEFAULT_COMPAT);+ const controls = getPrimeInferenceReasoningControls(entry);+ if (controls) {+ // The live catalog is authoritative for which reasoning parameters the+ // route accepts; never emit one it does not declare.+ compat.supportsReasoningEffort = controls.supportsReasoningEffort;+ if (controls.thinkingFormat) compat.thinkingFormat = controls.thinkingFormat;+ else delete compat.thinkingFormat;+ }+ // The live map is authoritative when present; no reported parameter+ // support keeps the whole stale template. A route that declares+ // reasoning_effort but no supported efforts keeps the template's map:+ // the param is accepted but its values are unknown, and the template+ // bounds the selection better than the raw default levels. A route that+ // declares supported parameters but no reasoning controls drops the+ // template map entirely.+ const thinkingLevelMap = !controls+ ? template?.thinkingLevelMap+ : (controls.thinkingLevelMap ?? (controls.supportsReasoningEffort ? template?.thinkingLevelMap : undefined));// Anthropic models cache with explicit breakpoints, not automatic// server-side prefix caching; cacheControlFormat makes the provider add// anthropic-style cache_control markers for these entries. The catalog@@ -65,7 +84,7 @@ export function buildPrimeInferenceModels(provider: "prime-inference",baseUrl: PRIME_INFERENCE_BASE_URL,reasoning: entry.reasoning ?? template?.reasoning ?? false,- ...(template?.thinkingLevelMap ? { thinkingLevelMap: { ...template.thinkingLevelMap } } : {}),+ ...(thinkingLevelMap ? { thinkingLevelMap: { ...thinkingLevelMap } } : {}),input: (entry.vision ?? template?.input.includes("image")) ? ["text", "image"] : ["text"],cost: { input: entry.input, output: entry.output, ...cacheCosts(entry, template) },contextWindow,diff --git a/packages/coding-agent/test/auth-storage.test.ts b/packages/coding-agent/test/auth-storage.test.tsindex 193f309b26..7c7717d808 100644--- a/packages/coding-agent/test/auth-storage.test.ts+++ b/packages/coding-agent/test/auth-storage.test.ts@@ -254,8 +254,14 @@ describe("AuthStorage", () => {await expect(authStorage.getApiKey("prime-inference")).resolves.toBe("runtime-key");expect(authStorage.getAuthStatus("prime-inference").source).toBe("runtime");- expect(authStorage.getPrimeInferenceTeamSelection()).toBeUndefined();- expect(authStorage.getProviderHeaders("prime-inference")).toBeUndefined();+ // The stored primeTeam survives runtime and environment API-key+ // overrides: the key comes from the override, the team from the+ // stored login, so the credentialed catalog and private-model+ // fetches stay team-scoped and internal/* routes remain visible.+ expect(authStorage.getPrimeInferenceTeamSelection()).toEqual(team);+ expect(authStorage.getProviderHeaders("prime-inference")).toEqual({+ "X-Prime-Team-ID": team.teamId,+ });authStorage.removeRuntimeApiKey("prime-inference");await expect(authStorage.getApiKey("prime-inference")).resolves.toBe("env-key");expect(authStorage.getAuthStatus("prime-inference")).toEqual({@@ -263,8 +269,10 @@ describe("AuthStorage", () => {source: "environment",label: "PRIME_API_KEY",});- expect(authStorage.getPrimeInferenceTeamSelection()).toBeUndefined();- expect(authStorage.getProviderHeaders("prime-inference")).toBeUndefined();+ expect(authStorage.getPrimeInferenceTeamSelection()).toEqual(team);+ expect(authStorage.getProviderHeaders("prime-inference")).toEqual({+ "X-Prime-Team-ID": team.teamId,+ });vi.stubEnv("PRIME_API_KEY", undefined);await expect(authStorage.getApiKey("prime-inference")).resolves.toBe("agent-key");expect(authStorage.getAuthStatus("prime-inference").source).toBe("stored");diff --git a/packages/coding-agent/test/prime-inference-model-catalog.test.ts b/packages/coding-agent/test/prime-inference-model-catalog.test.tsindex e46bdeeeee..a023f3861a 100644--- a/packages/coding-agent/test/prime-inference-model-catalog.test.ts+++ b/packages/coding-agent/test/prime-inference-model-catalog.test.ts@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "nodimport { tmpdir } from "node:os";import { join } from "node:path";import type { Model } from "@earendil-works/pi-ai";-import { afterEach, describe, expect, test, vi } from "vitest";+import { afterEach, describe, expect, it, test, vi } from "vitest";import {buildPrimeInferenceModels,PRIME_INFERENCE_BASE_URL,@@ -41,6 +41,20 @@ const entry = (id: string) => ({reasoning: false,});+const effortEntry = (id: string) => ({+ ...entry(id),+ reasoning: true,+ supportedParameters: ["max_tokens", "reasoning", "reasoning_effort"],+ reasoningEfforts: ["low", "high", "max"],+ reasoningMandatory: true,+});++const toggleEntry = (id: string) => ({+ ...entry(id),+ reasoning: true,+ supportedParameters: ["max_tokens", "reasoning", "include_reasoning"],+});+const payloadEntry = (id: string,specs: unknown = {@@ -89,6 +103,64 @@ describe("Prime Inference model catalog", () => {).toBeUndefined();});+ it.each([+ {+ name: "effort route",+ entry: () => effortEntry("z-ai/glm-5.3"),+ thinkingFormat: undefined,+ supportsReasoningEffort: true,+ map: { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: null, max: "max" },+ },+ {+ name: "toggle route",+ entry: () => toggleEntry("z-ai/glm-4.7"),+ thinkingFormat: "openrouter",+ supportsReasoningEffort: false,+ map: { minimal: null, low: null, medium: null, high: "high", xhigh: null, max: null },+ },+ {+ name: "effort route without declared efforts keeps the template map",+ entry: () => ({+ ...entry("z-ai/glm-5.3"),+ reasoning: true,+ supportedParameters: ["max_tokens", "reasoning", "reasoning_effort"],+ reasoningMandatory: false,+ }),+ thinkingFormat: undefined,+ supportsReasoningEffort: true,+ map: { high: "high" },+ },+ {+ name: "no-parameter route keeps the stale template",+ entry: () => entry("z-ai/glm-5.3"),+ thinkingFormat: "zai",+ supportsReasoningEffort: undefined,+ map: { high: "high" },+ },+ {+ name: "reasoning-free route drops the stale template",+ entry: () => ({ ...entry("qwen/qwen3-coder"), supportedParameters: ["max_tokens"] }),+ thinkingFormat: undefined,+ supportsReasoningEffort: false,+ map: undefined,+ },+ ])("$name", ({ entry: makeEntry, ...expected }) => {+ const liveEntry = makeEntry();+ const template = model(liveEntry.id);+ const stale = { ...template, compat: { ...template.compat, thinkingFormat: "zai" as const } };+ const [live] = buildPrimeInferenceModels([stale], [liveEntry], { minimumModels: 0 }) ?? [];+ expect(live?.compat?.thinkingFormat).toBe(expected.thinkingFormat);+ expect(live?.compat?.supportsReasoningEffort).toBe(expected.supportsReasoningEffort);+ if (expected.map) expect(live?.thinkingLevelMap).toEqual(expected.map);+ else expect(live?.thinkingLevelMap).toBeUndefined();+ });++ test("gives new live models the conservative default compat plus declared controls", () => {+ const models =+ buildPrimeInferenceModels([], [effortEntry("vendor/new"), entry("vendor/plain")], { minimumModels: 0 }) ?? [];+ expect(models.map((m) => m.compat?.supportsReasoningEffort)).toEqual([true, false]);+ });+test("caches valid responses and falls back to the cache when the fetch fails", async () => {const directory = mkdtempSync(join(tmpdir(), "prime-models-"));directories.push(directory);