Skip to content

Commit fd09ac2

Browse files
committed
fix(opencode): require a matching report for Default fallback
1 parent 20be6a8 commit fd09ac2

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎packages/shared/src/model.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,21 @@ describe("provider-reported option display", () => {
335335
expect(descriptor.options.map((option) => option.id)).toEqual(["none", "thinking"]);
336336
expect(buildProviderOptionSelectionsFromDescriptors([descriptor])).toBeUndefined();
337337
expect(getProviderOptionCurrentLabel(descriptor, selection)).toBe("Unknown");
338+
const effortDescriptor = { ...descriptor, id: "effort", currentValue: "default" };
339+
expect(getProviderOptionCurrentLabel(effortDescriptor, selection)).toBeUndefined();
340+
expect(
341+
getProviderOptionCurrentLabel(effortDescriptor, selection, {
342+
...reported,
343+
model: "other",
344+
options: [{ id: "effort", value: "default" }],
345+
}),
346+
).toBeUndefined();
347+
expect(
348+
getProviderOptionCurrentLabel(effortDescriptor, selection, {
349+
...reported,
350+
options: [{ id: "effort", value: "default" }],
351+
}),
352+
).toBe("Default");
338353
expect(
339354
getProviderOptionCurrentLabel({ ...descriptor, currentValue: "thinking" }, selection),
340355
).toBe("Unknown");

‎packages/shared/src/model.ts‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,22 @@ export function getProviderOptionDescriptors(input: {
202202
);
203203
}
204204

205+
function getReportedOptionValue(
206+
id: string,
207+
selection?: ModelSelection | null,
208+
reportedSelection?: ModelSelection | null,
209+
) {
210+
if (
211+
!selection ||
212+
!reportedSelection ||
213+
selection.instanceId !== reportedSelection.instanceId ||
214+
selection.model !== reportedSelection.model ||
215+
selection.options?.some((option) => option.id === id)
216+
)
217+
return undefined;
218+
return getRawSelectionValueById(reportedSelection.options, id);
219+
}
220+
205221
export function getProviderOptionCurrentValue(
206222
descriptor: ProviderOptionDescriptor | null | undefined,
207223
selection?: ModelSelection | null,
@@ -212,16 +228,8 @@ export function getProviderOptionCurrentValue(
212228
}
213229
const hasExplicitOption = selection?.options?.some((option) => option.id === descriptor.id);
214230
// Reported values are display-only; callers that build dispatch options omit this context.
215-
if (
216-
selection &&
217-
reportedSelection &&
218-
selection.instanceId === reportedSelection.instanceId &&
219-
selection.model === reportedSelection.model &&
220-
!hasExplicitOption
221-
) {
222-
const reportedValue = getRawSelectionValueById(reportedSelection.options, descriptor.id);
223-
if (reportedValue !== undefined) return reportedValue;
224-
}
231+
const reportedValue = getReportedOptionValue(descriptor.id, selection, reportedSelection);
232+
if (reportedValue !== undefined) return reportedValue;
225233
if (descriptor.id === "variant" && selection && !hasExplicitOption) return undefined;
226234
if (descriptor.type === "boolean") {
227235
return descriptor.currentValue;
@@ -250,7 +258,11 @@ export function getProviderOptionCurrentLabel(
250258
const currentValue = getProviderOptionCurrentValue(descriptor, selection, reportedSelection);
251259
return (
252260
descriptor.options.find((option) => option.id === currentValue)?.label ??
253-
(currentValue === "default" ? "Default" : descriptor.id === "variant" ? "Unknown" : undefined)
261+
(getReportedOptionValue(descriptor.id, selection, reportedSelection) === "default"
262+
? "Default"
263+
: descriptor.id === "variant"
264+
? "Unknown"
265+
: undefined)
254266
);
255267
}
256268

0 commit comments

Comments
 (0)