Skip to content

Commit ea9b1b1

Browse files
fix(clients): format subagent effort from stated values
1 parent 1832271 commit ea9b1b1

3 files changed

Lines changed: 22 additions & 23 deletions

File tree

‎packages/client-runtime/src/state/threadExecution.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ describe("formatModelSelectionEffort", () => {
477477
reported,
478478
),
479479
).toBe("Medium");
480+
expect(
481+
formatModelSelectionEffort(
482+
selection([{ id: "effort", value: "retired-effort" }]),
483+
catalog({ currentValue: "medium" }),
484+
reported,
485+
),
486+
).toBeNull();
480487
});
481488

482489
it("shows nothing when neither the selection nor the provider states an effort", () => {

‎packages/client-runtime/src/state/threadExecution.ts‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ import {
2222
backgroundWorkHoldsCompletion,
2323
derivePendingBackgroundWork,
2424
} from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
25-
import {
26-
getProviderOptionCurrentLabel,
27-
getProviderOptionCurrentValue,
28-
getProviderOptionDescriptors,
29-
isProviderOptionValueStated,
30-
} from "@t3tools/shared/model";
25+
import { getProviderOptionCurrentLabel, getProviderOptionStatedValue } from "@t3tools/shared/model";
3126
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
3227
import * as DateTime from "effect/DateTime";
3328

@@ -165,20 +160,18 @@ export function formatModelSelectionEffort(
165160
): string | null {
166161
const caps = models.find((model) => model.slug === selection.model)?.capabilities;
167162
if (!caps) return null;
168-
const descriptors = getProviderOptionDescriptors({ caps, selections: selection.options });
169163
for (const id of REASONING_EFFORT_OPTION_IDS) {
170-
const descriptor = descriptors.find((candidate) => candidate.id === id);
164+
const descriptor = caps.optionDescriptors?.find((candidate) => candidate.id === id);
171165
if (descriptor?.type !== "select") continue;
172-
// The adapter writes a subagent's selection from what the provider reported,
173-
// so a missing option is unknown; the catalog's pick is not its effort. A
174-
// resolver with no value at all yields "Unknown", which may still be named.
175-
if (
176-
!isProviderOptionValueStated(id, selection, reportedSelection) &&
177-
getProviderOptionCurrentValue(descriptor, selection, reportedSelection) !== undefined
178-
) {
179-
continue;
180-
}
181-
const label = getProviderOptionCurrentLabel(descriptor, selection, reportedSelection);
166+
const value = getProviderOptionStatedValue(id, selection, reportedSelection);
167+
if (value === undefined && id !== "variant") continue;
168+
if (typeof value === "boolean") continue;
169+
// Bypass picker normalization so an obsolete choice cannot become a catalog default.
170+
const label = getProviderOptionCurrentLabel(
171+
{ ...descriptor, currentValue: value },
172+
selection,
173+
reportedSelection,
174+
);
182175
if (label) return label;
183176
}
184177
return null;

‎packages/shared/src/model.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,14 @@ function getReportedOptionValue(
213213
return getRawSelectionValueById(reportedSelection.options, id);
214214
}
215215

216-
/** A catalog default or current value is a guess, so it does not count as stated. */
217-
export function isProviderOptionValueStated(
216+
export function getProviderOptionStatedValue(
218217
id: string,
219218
selection?: ModelSelection | null,
220219
reportedSelection?: ModelSelection | null,
221-
): boolean {
220+
) {
222221
return (
223-
selection?.options?.some((option) => option.id === id) === true ||
224-
getReportedOptionValue(id, selection, reportedSelection) !== undefined
222+
getRawSelectionValueById(selection?.options, id) ??
223+
getReportedOptionValue(id, selection, reportedSelection)
225224
);
226225
}
227226

0 commit comments

Comments
 (0)