Skip to content

Commit 97a62c9

Browse files
committed
fix(command-code): guard model alias lookups
1 parent 2468502 commit 97a62c9

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎src/adapters/command-code.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ const COMMAND_CODE_MODEL_ALIASES: Readonly<Record<string, string>> = {
2121
"glm-5.2": "zai-org/GLM-5.2",
2222
};
2323

24+
function canonicalCommandCodeModelId(modelId: string): string {
25+
return Object.hasOwn(COMMAND_CODE_MODEL_ALIASES, modelId) ? COMMAND_CODE_MODEL_ALIASES[modelId]! : modelId;
26+
}
27+
2428
/** Flatten tool-result content for the text-only wire output, keeping an `[image]` marker per image part in content order. */
2529
function toolResultText(content: string | OcxContentPart[]): string {
2630
if (typeof content === "string") return content;
@@ -318,7 +322,7 @@ function supportedCommandCodeEffort(provider: OcxProviderConfig, modelId: string
318322
// Compatibility ids (deepseek-v4-flash / glm-5.2) must resolve to their canonical
319323
// Command Code id before the effort lookup, or legacy requests silently lose the
320324
// reasoning effort because the official table is keyed by the canonical ids.
321-
const canonicalId = COMMAND_CODE_MODEL_ALIASES[modelId] ?? modelId;
325+
const canonicalId = canonicalCommandCodeModelId(modelId);
322326
const supported = commandCodeReasoningEfforts(canonicalId) ?? configuredReasoningEfforts(provider, canonicalId);
323327
if (!supported) return undefined;
324328
// Command Code's official profiles describe xhigh and ultra as the CLI labels that map to
@@ -347,7 +351,7 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
347351
config: await commandCodeConfig(cwd), memory: "", taste: null, skills: null,
348352
permissionMode: "standard", mode: "agent",
349353
params: {
350-
model: COMMAND_CODE_MODEL_ALIASES[parsed.modelId] ?? parsed.modelId,
354+
model: canonicalCommandCodeModelId(parsed.modelId),
351355
messages: wireMessages(parsed.context.messages),
352356
tools: wireTools(tools),
353357
system,

‎src/providers/command-code-efforts.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function keyFor(modelId: string): string {
3131

3232
export function commandCodeReasoningEfforts(modelId: string): readonly string[] | undefined {
3333
const key = keyFor(modelId);
34-
return refreshedEfforts.get(key) ?? COMMAND_CODE_MODEL_REASONING_EFFORTS[key];
34+
return refreshedEfforts.get(key)
35+
?? (Object.hasOwn(COMMAND_CODE_MODEL_REASONING_EFFORTS, key) ? COMMAND_CODE_MODEL_REASONING_EFFORTS[key] : undefined);
3536
}
3637

3738
function parsedProfileEfforts(page: string): string[] | undefined {
@@ -59,7 +60,9 @@ export async function refreshCommandCodeReasoningEfforts(
5960
fetchFn: typeof globalThis.fetch = globalThis.fetch,
6061
): Promise<readonly string[] | undefined> {
6162
const key = keyFor(modelId);
62-
const profile = COMMAND_CODE_MODEL_EFFORTS[key as keyof typeof COMMAND_CODE_MODEL_EFFORTS];
63+
const profile = Object.hasOwn(COMMAND_CODE_MODEL_EFFORTS, key)
64+
? COMMAND_CODE_MODEL_EFFORTS[key as keyof typeof COMMAND_CODE_MODEL_EFFORTS]
65+
: undefined;
6366
if (!profile) return undefined;
6467
try {
6568
const response = await fetchFn(profile.profileUrl, {

‎tests/command-code-provider.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ describe("Command Code provider", () => {
214214
expect(JSON.parse(legacy.body).params.reasoning_effort).toBe("high");
215215
});
216216

217+
test("treats prototype property names as literal model ids", async () => {
218+
for (const modelId of ["__proto__", "constructor", "toString"]) {
219+
const built = await builtRequest(parsed(modelId));
220+
const params = JSON.parse(built.body).params;
221+
expect(params.model).toBe(modelId);
222+
expect(params).not.toHaveProperty("reasoning_effort");
223+
}
224+
});
225+
217226
test("filters tool declarations when tool_choice disables tools", async () => {
218227
const built = await builtRequest({ ...parsed(), options: { toolChoice: "none" } });
219228
expect(JSON.parse(built.body).params.tools).toEqual([]);

0 commit comments

Comments
 (0)