GeezerVison is showing github.com — fix(zcode): export reasoning configuration for thought-capable models · agentHits/opencodex@7267df1
File treeExpand file treeCollapse file tree Open diff view settings src/clients/config-export
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/clients/config-export/zcode.ts +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // ZCode config export. | 2 | 2 | import type { ExportContext, ManagedContribution } from "./contracts"; | 3 | 3 | import { normalizeExportModels, inputModalitiesForClient, exportModelLabel, authoritativeContextWindow, singleFragment } from "./model-metadata"; | | 4 | +import { sanitizeCodexReasoningEfforts } from "../../reasoning-effort"; | 4 | 5 | import { OPENCODE_PROVIDER_ID, LOOPBACK_API_KEY_PLACEHOLDER } from "./constants"; | 5 | 6 |
| 6 | 7 |
| @@ -15,6 +16,16 @@ export interface ZcodeModelEntry { | 15 | 16 | name?: string; | 16 | 17 | limit?: { context: number; output?: number }; | 17 | 18 | modalities: { input: string[]; output: string[] }; | | 19 | + /** | | 20 | + * On-disk Thought Level block. ZCode 3.x persists `variants`/`defaultVariant` | | 21 | + * and parses them into in-memory `levels`/`defaultLevel`. Omit the field when | | 22 | + * the catalog has no selectable ladder, so the picker stays hidden. | | 23 | + */ | | 24 | + reasoning?: { | | 25 | + enabled: boolean; | | 26 | + variants: string[]; | | 27 | + defaultVariant?: string; | | 28 | + }; | 18 | 29 | } | 19 | 30 |
| 20 | 31 | export interface ZcodeProviderBlock { | @@ -61,6 +72,19 @@ export function buildZcodeClientConfig(ctx: ExportContext): ZcodeGeneratedConfig | 61 | 72 | if (context !== undefined) { | 62 | 73 | entry.limit = { context }; | 63 | 74 | } | | 75 | + // `none` is a Codex omit-sentinel, not a ZCode picker option. Keep catalog | | 76 | + // `ultra` when present: ZCode forwards the selected variant as | | 77 | + // `reasoning_effort`. Set `defaultVariant` only when it survives that filter. | | 78 | + const efforts = sanitizeCodexReasoningEfforts(model.reasoningEfforts) | | 79 | + ?.filter(effort => effort !== "none"); | | 80 | + if (efforts && efforts.length > 0) { | | 81 | + const defaultVariant = model.defaultReasoningEffort?.trim().toLowerCase(); | | 82 | + entry.reasoning = { | | 83 | + enabled: true, | | 84 | + variants: efforts, | | 85 | + ...(defaultVariant && efforts.includes(defaultVariant) ? { defaultVariant } : {}), | | 86 | + }; | | 87 | + } | 64 | 88 | models[model.namespaced] = entry; | 65 | 89 | } | 66 | 90 | return { | |
Collapse file Copy file name to clipboardExpand all lines: tests/config/client-config-export.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -120,7 +120,7 @@ describe("split config-export public facade", () => { | 120 | 120 | ["omp", ["providers", "opencodex"], '{"providers":{"opencodex":{"baseUrl":"http://127.0.0.1:10100/v1","api":"openai-completions","apiKey":"opencodex-loopback","models":[{"id":"test/known","name":"known (test)","input":["text","image"],"contextWindow":8192,"maxTokens":8192,"reasoning":true,"thinking":{"mode":"effort","efforts":["high"]}}]}}}'], | 121 | 121 | ["dsh", ["llm-pi-ai", "providers", "opencodex"], '{"llm-pi-ai":{"providers":{"opencodex":{"displayName":"OpenCodex","api":"openai-responses","baseURL":"http://127.0.0.1:10100/v1","headers":{"Authorization":"Bearer ocx_data_dsh"},"models":[{"id":"test/known","name":"known (test)","input":["text","image"],"contextWindow":8192,"reasoningEfforts":{"high":"high"}}]}}}}'], | 122 | 122 | ["mcode", ["custom_provider", "opencodex"], '{"custom_provider":{"opencodex":{"name":"OpenCodex","kind":"custom","enabled":true,"api":"anthropic-messages","options":{"apiKey":"opencodex-loopback","baseURL":"http://127.0.0.1:10100","authMode":"api-key"},"models":{"test/known":{"limit":{"context":8192},"thinking":{"effortOptions":["high"]}}}}}}'], | 123 | | - ["zcode", ["provider", "opencodex"], '{"provider":{"opencodex":{"name":"OpenCodex","kind":"openai-compatible","enabled":true,"source":"custom","options":{"apiKey":"opencodex-loopback","baseURL":"http://127.0.0.1:10100/v1","apiKeyRequired":true},"models":{"test/known":{"name":"known (test)","modalities":{"input":["text","image"],"output":["text"]},"limit":{"context":8192}}}}}}'], | | 123 | + ["zcode", ["provider", "opencodex"], '{"provider":{"opencodex":{"name":"OpenCodex","kind":"openai-compatible","enabled":true,"source":"custom","options":{"apiKey":"opencodex-loopback","baseURL":"http://127.0.0.1:10100/v1","apiKeyRequired":true},"models":{"test/known":{"name":"known (test)","modalities":{"input":["text","image"],"output":["text"]},"limit":{"context":8192},"reasoning":{"enabled":true,"variants":["high"]}}}}}}'], | 124 | 124 | ] as const; | 125 | 125 | for (const [id, path, expectedBytes] of cases) { | 126 | 126 | const built = buildClientConfigText(id, context); | |
Collapse file Copy file name to clipboardExpand all lines: tests/providers/zcode-client.test.ts +58-1Lines changed: 58 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,6 +93,64 @@ describe("ZCode client config", () => { | 93 | 93 | }); | 94 | 94 | }); | 95 | 95 |
| | 96 | +describe("ZCode reasoning export", () => { | | 97 | + test("emits on-disk variants for thought-capable models and omits them otherwise", () => { | | 98 | + const document = buildClientConfig("zcode", { | | 99 | + ...context(), | | 100 | + models: [ | | 101 | + { | | 102 | + namespaced: "google-antigravity/gemini-3.8-flash", | | 103 | + provider: "google-antigravity", | | 104 | + id: "gemini-3.8-flash", | | 105 | + contextWindow: 1_048_576, | | 106 | + inputModalities: ["text", "image"], | | 107 | + reasoningEfforts: ["low", "medium", "high", "max"], | | 108 | + defaultReasoningEffort: "medium", | | 109 | + }, | | 110 | + { | | 111 | + namespaced: "CommandCode/meituan-LongCat-2.0:free", | | 112 | + provider: "CommandCode", | | 113 | + id: "meituan-LongCat-2.0:free", | | 114 | + contextWindow: 128_000, | | 115 | + }, | | 116 | + ], | | 117 | + }) as ZcodeGeneratedConfig; | | 118 | + const models = document.provider[OPENCODE_PROVIDER_ID]!.models; | | 119 | + expect(models["google-antigravity/gemini-3.8-flash"]).toEqual({ | | 120 | + name: "gemini-3.8-flash (google-antigravity)", | | 121 | + modalities: { input: ["text", "image"], output: ["text"] }, | | 122 | + limit: { context: 1_048_576 }, | | 123 | + reasoning: { enabled: true, variants: ["low", "medium", "high", "max"], defaultVariant: "medium" }, | | 124 | + }); | | 125 | + expect(models["CommandCode/meituan-LongCat-2.0:free"]).not.toHaveProperty("reasoning"); | | 126 | + }); | | 127 | + | | 128 | + test("drops none, keeps ultra, and omits defaultVariant when it is not in the emitted ladder", () => { | | 129 | + const document = buildClientConfig("zcode", { | | 130 | + ...context(), | | 131 | + models: [ | | 132 | + { | | 133 | + namespaced: "opencode-go/muse-spark-1.3-contributor", | | 134 | + provider: "opencode-go", | | 135 | + id: "muse-spark-1.3-contributor", | | 136 | + reasoningEfforts: ["none", "high", "ultra", "turbo"], | | 137 | + defaultReasoningEffort: "none", | | 138 | + }, | | 139 | + { namespaced: "a/none-only", provider: "a", id: "none-only", reasoningEfforts: ["none"] }, | | 140 | + { namespaced: "a/empty", provider: "a", id: "empty", reasoningEfforts: [] }, | | 141 | + ], | | 142 | + }) as ZcodeGeneratedConfig; | | 143 | + const models = document.provider[OPENCODE_PROVIDER_ID]!.models; | | 144 | + expect(models["opencode-go/muse-spark-1.3-contributor"]).toEqual({ | | 145 | + name: "muse-spark-1.3-contributor (opencode-go)", | | 146 | + modalities: { input: ["text"], output: ["text"] }, | | 147 | + reasoning: { enabled: true, variants: ["high", "ultra"] }, | | 148 | + }); | | 149 | + expect(models["a/none-only"]).not.toHaveProperty("reasoning"); | | 150 | + expect(models["a/empty"]).not.toHaveProperty("reasoning"); | | 151 | + }); | | 152 | +}); | | 153 | + | 96 | 154 | describe("ocx zcode CLI alias", () => { | 97 | 155 | /** Captures the client-integration requests the alias forwards. */ | 98 | 156 | function fakeRuntime(): { deps: { baseUrl: string; fetchImpl: typeof fetch }; requests: Array<{ path: string; method: string; body: unknown }> } { | @@ -149,4 +207,3 @@ describe("ocx zcode CLI alias", () => { | 149 | 207 | expect(requests.some(r => r.path === "/api/client-integrations/restore" && r.method === "POST" && (r.body as { opId?: string }).opId === "op-1")).toBe(true); | 150 | 208 | }); | 151 | 209 | }); | 152 | | - | |
|