Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: the picked effort reaches the engine and the picker lists it

ogsamrate52e775615a4
diff --git a/apps/app/src/app/lib/opencode-v2-adapter.ts b/apps/app/src/app/lib/opencode-v2-adapter.ts
index 4ceba3cd..8a2bac2c 100644
--- a/apps/app/src/app/lib/opencode-v2-adapter.ts
+++ b/apps/app/src/app/lib/opencode-v2-adapter.ts
@@ -587,6 +587,11 @@ function mapV2Model(value: unknown): Model | null {
const outputCapabilities = stringArray(rawCapabilities?.output);
const toolcall = rawCapabilities?.tools === true;
const released = readNumber(rawTime, "released");
+ // 2.x lists a model's efforts as [{id, settings}]; the 1.x picker reads {id: settings}.
+ const variants = Object.fromEntries((Array.isArray(value.variants) ? value.variants : []).flatMap((variant) => {
+ const variantID = readString(variant, "id");
+ return variantID ? [[variantID, readRecord(variant, "settings") ?? {}]] : [];
+ }));
return {
id,
providerID,
@@ -598,7 +603,7 @@ function mapV2Model(value: unknown): Model | null {
name: readString(value, "name") ?? id,
capabilities: {
temperature: false,
- reasoning: outputCapabilities.includes("reasoning"),
+ reasoning: Object.keys(variants).length > 0 || outputCapabilities.includes("reasoning"),
attachment: inputCapabilities.some((kind) => kind !== "text"),
toolcall,
input: {
@@ -634,6 +639,7 @@ function mapV2Model(value: unknown): Model | null {
options: {},
headers: {},
release_date: released === undefined ? "" : new Date(released).toISOString(),
+ ...(Object.keys(variants).length > 0 ? { variants } : {}),
};
}
@@ -1551,9 +1557,10 @@ export function createClientV2(
return failedResult({ ...result, payload: { name: "InvalidV2SessionResponse" } });
};
- const selectModel = (sessionID: string, model: { providerID: string; modelID: string }, options?: RequestOptions) =>
+ // The picked effort rides on the model (2.x `model.variant`); without one the engine runs the model's default.
+ const selectModel = (sessionID: string, model: { providerID: string; modelID: string }, variant: string | undefined, options?: RequestOptions) =>
request("POST", `/api/session/${encodeURIComponent(sessionID)}/model`,
- { model: { providerID: model.providerID, id: model.modelID } }, options?.signal);
+ { model: { providerID: model.providerID, id: model.modelID, ...(variant ? { variant } : {}) } }, options?.signal);
// 2.x mutations answer 204 or a non-session payload; v1 callers expect the session.
const thenSession = async (result: TransportResult, sessionID: string, options?: RequestOptions) =>
@@ -1664,7 +1671,7 @@ export function createClientV2(
response: new Response(null, { status: 400 }),
};
}
- const modelResult = await selectModel(parameters.sessionID, parameters.model, options);
+ const modelResult = await selectModel(parameters.sessionID, parameters.model, parameters.variant, options);
if (!modelResult.response.ok) return failedResult(modelResult);
if (parameters.system !== undefined) {
const instructions = await request("PUT",
@@ -1785,14 +1792,14 @@ export function createClientV2(
return result.response.ok ? successfulResult(result, {}) : failedResult(result);
},
command: async (
- parameters: SessionParameters & { command: string; arguments?: string; model?: string },
+ parameters: SessionParameters & { command: string; arguments?: string; model?: string; variant?: string },
options?: RequestOptions,
): Promise<FieldsResult<Record<string, never>>> => {
// v1 passes "provider/model"; 2.x commands run on the session model.
const slash = parameters.model?.indexOf("/") ?? -1;
if (parameters.model && slash > 0) {
const modelResult = await selectModel(parameters.sessionID,
- { providerID: parameters.model.slice(0, slash), modelID: parameters.model.slice(slash + 1) }, options);
+ { providerID: parameters.model.slice(0, slash), modelID: parameters.model.slice(slash + 1) }, parameters.variant, options);
if (!modelResult.response.ok) return failedResult(modelResult);
}
const result = await request("POST", `/api/session/${encodeURIComponent(parameters.sessionID)}/command`,
diff --git a/apps/app/tests/opencode-v2-adapter.test.ts b/apps/app/tests/opencode-v2-adapter.test.ts
index 03898d28..84ce4002 100644
--- a/apps/app/tests/opencode-v2-adapter.test.ts
+++ b/apps/app/tests/opencode-v2-adapter.test.ts
@@ -1954,3 +1954,51 @@ describe("OpenCode 2.0.32 workspace reads", () => {
} finally { globalThis.fetch = originalFetch; }
});
});
+
+test("v2 models keep their efforts so the effort picker lists them", async () => {
+ const originalFetch = globalThis.fetch;
+ globalThis.fetch = async (input, init) => {
+ const request = input instanceof Request ? input : new Request(input, init);
+ if (request.url.endsWith("/api/model")) return jsonResponse({ data: [
+ { id: "gpt-6-astra", providerID: "omnirush", name: "GPT 6 Astra", capabilities: { tools: true, input: ["text"], output: ["text"] },
+ variants: [{ id: "low", settings: { reasoningEffort: "low" } }, { id: "max", settings: { reasoningEffort: "max" } }] },
+ { id: "plain", providerID: "omnirush", name: "Plain" },
+ ] });
+ if (request.url.endsWith("/api/provider")) return jsonResponse({ data: [{ id: "omnirush", name: "OmniRush" }] });
+ if (request.url.endsWith("/api/model/default")) return jsonResponse({ data: {} });
+ throw new Error(`Unexpected request: ${request.url}`);
+ };
+ try {
+ const client = createClientV2("http://opencode.test/opencode2", "/workspace", {});
+ const models = (await client.provider.list()).data?.all[0]?.models ?? {};
+ expect(models["gpt-6-astra"]?.variants).toEqual({ low: { reasoningEffort: "low" }, max: { reasoningEffort: "max" } });
+ expect(models["gpt-6-astra"]?.capabilities.reasoning).toBe(true);
+ expect(models.plain?.variants).toBeUndefined();
+ expect(models.plain?.capabilities.reasoning).toBe(false);
+ } finally {
+ globalThis.fetch = originalFetch;
+ }
+});
+
+test("a send posts the picked effort with the session model", async () => {
+ const originalFetch = globalThis.fetch;
+ const bodies: unknown[] = [];
+ globalThis.fetch = async (input, init) => {
+ const request = input instanceof Request ? input : new Request(input, init);
+ if (request.url.endsWith("/model")) { bodies.push(await request.json()); return new Response(null, { status: 204 }); }
+ if (request.url.endsWith("/prompt")) return new Response(null, { status: 204 });
+ throw new Error(`Unexpected request: ${request.method} ${request.url}`);
+ };
+ try {
+ const client = createClientV2("http://opencode.test/opencode2", "/workspace", {});
+ const model = { providerID: "omnirush", modelID: "gpt-6-astra" };
+ await client.session.promptAsync({ sessionID: "ses_e", model, variant: "max", parts: [{ type: "text", text: "a" }] });
+ await client.session.promptAsync({ sessionID: "ses_e", model, parts: [{ type: "text", text: "b" }] });
+ expect(bodies).toEqual([
+ { model: { providerID: "omnirush", id: "gpt-6-astra", variant: "max" } },
+ { model: { providerID: "omnirush", id: "gpt-6-astra" } },
+ ]);
+ } finally {
+ globalThis.fetch = originalFetch;
+ }
+});
diff --git a/apps/server/src/managed-opencode-v2.effort.test.ts b/apps/server/src/managed-opencode-v2.effort.test.ts
new file mode 100644
index 00000000..32a7f820
--- /dev/null
+++ b/apps/server/src/managed-opencode-v2.effort.test.ts
@@ -0,0 +1,34 @@
+// The catalog's efforts reach the 2.x engine (as the CLI's engine-v2.js v2Model), and a mid-chat effort change goes as
+// the request's own effort (supportsEffortUpdates false), which is what the gateway meters.
+import { expect, test } from "bun:test";
+
+import { engineModelsFromCatalog } from "./omnirush-model-catalog.js";
+import { v2ModelConfig } from "./managed-opencode-v2.js";
+
+test("a reasoning model lists the catalog efforts and turns effort updates off", () => {
+ const config = {
+ reasoning: true,
+ variants: { low: { reasoningEffort: "low" }, high: { reasoningEffort: "high" }, medium: { disabled: true }, max: { reasoningEffort: "max" } },
+ options: { reasoningEffort: "high" },
+ };
+ const entry = v2ModelConfig({ id: "gpt-6-astra", name: "GPT 6 Astra", config });
+ expect(entry.capabilities).toMatchObject({ reasoning: { supported: true, effort: ["low", "high", "max"] } });
+ expect(entry.compatibility).toEqual({ supportsEffortUpdates: false });
+ expect(entry.settings).toEqual({ reasoningEffort: "high" });
+});
+
+test("a model without reasoning gets neither", () => {
+ const entry = v2ModelConfig({ id: "plain", name: "Plain", config: { reasoning: false } });
+ expect((entry.capabilities as Record<string, unknown>).reasoning).toBeUndefined();
+ expect(entry.compatibility).toBeUndefined();
+});
+
+test("the app catalog's efforts come through in catalog order", () => {
+ const catalog = engineModelsFromCatalog([{
+ id: "gpt-6-astra", display_name: "GPT 6 Astra", reasoning_levels: ["low", "high", "xhigh", "max"],
+ capabilities: { reasoning: true, tool_call: true, web_search: false, image_input: false, file_input: false },
+ limits: { context: 400000, output: 128000 },
+ } as never]);
+ const entry = v2ModelConfig({ id: "gpt-6-astra", name: "GPT 6 Astra", config: catalog["gpt-6-astra"] });
+ expect((entry.capabilities as { reasoning: unknown }).reasoning).toEqual({ supported: true, effort: ["low", "high", "xhigh", "max"] });
+});
diff --git a/apps/server/src/managed-opencode-v2.ts b/apps/server/src/managed-opencode-v2.ts
index bff2a75f..bc3faa00 100644
--- a/apps/server/src/managed-opencode-v2.ts
+++ b/apps/server/src/managed-opencode-v2.ts
@@ -33,6 +33,35 @@ export interface OpencodeV2ProviderSpec {
models: OpencodeV2ModelSpec[];
}
+/** One app model as the 2.x engine config entry. */
+export function v2ModelConfig(model: OpencodeV2ModelSpec): Record<string, unknown> {
+ const config = model.config ?? {};
+ const modalities = isRecord(config.modalities) ? config.modalities : {};
+ // The catalog's efforts (its enabled variants), as the CLI's engine-v2.js v2Model.
+ const efforts = isRecord(config.variants)
+ ? Object.entries(config.variants).filter(([, value]) => isRecord(value) && value.disabled !== true).map(([id]) => id)
+ : [];
+ return {
+ name: model.name,
+ ...(typeof config.id === "string" ? { modelID: config.id } : {}),
+ capabilities: {
+ tools: typeof config.tool_call === "boolean" ? config.tool_call : true,
+ input: modalities.input ?? ["text"],
+ output: modalities.output ?? ["text"],
+ ...(config.reasoning ? { reasoning: { supported: true, ...(efforts.length ? { effort: efforts } : {}) } } : {}),
+ },
+ // A mid-chat effort change goes as the request's own reasoning.effort (what the gateway meters), not only
+ // as a configuration_update item the engine would add for gpt-6+ ids while keeping the chat's first effort.
+ ...(config.reasoning ? { compatibility: { supportsEffortUpdates: false } } : {}),
+ // No catalog limit: the engine's own default, as stock (an output cap of 32000 tokens).
+ ...(isRecord(config.limit) ? { limit: config.limit } : {}),
+ ...(typeof config.family === "string" ? { family: config.family } : {}),
+ ...(isRecord(config.options) ? { settings: config.options } : {}),
+ ...(isRecord(config.headers) ? { headers: config.headers } : {}),
+ ...(config.status === "deprecated" ? { disabled: true } : {}),
+ };
+}
+
export interface ManagedOpencodeV2ServerOptions {
bin: string;
rootDir: string;
@@ -274,23 +303,7 @@ export async function createManagedOpencodeV2Server(
if (!providerAllowed(provider.id)) continue;
const models: Record<string, unknown> = {};
for (const model of provider.models) {
- const config = model.config ?? {};
- const modalities = isRecord(config.modalities) ? config.modalities : {};
- models[model.id] = {
- name: model.name,
- ...(typeof config.id === "string" ? { modelID: config.id } : {}),
- capabilities: {
- tools: typeof config.tool_call === "boolean" ? config.tool_call : true,
- input: modalities.input ?? ["text"],
- output: modalities.output ?? ["text"],
- },
- // No catalog limit: the engine's own default, as stock (an output cap of 32000 tokens).
- ...(isRecord(config.limit) ? { limit: config.limit } : {}),
- ...(typeof config.family === "string" ? { family: config.family } : {}),
- ...(isRecord(config.options) ? { settings: config.options } : {}),
- ...(isRecord(config.headers) ? { headers: config.headers } : {}),
- ...(config.status === "deprecated" ? { disabled: true } : {}),
- };
+ models[model.id] = v2ModelConfig(model);
}
providerConfig[provider.id] = {
name: provider.name,