import { THINKING_LEVELS } from "./framework.ts"; import type { ThinkingLevel } from "./framework.ts"; /** * The level to use with a model that offers `levels`. A level the model does not offer becomes the nearest one above it * (Low on a model without it becomes Medium), or the model's highest when there is none above (Max becomes High). * Without a wish, Medium where the model has it. Undefined when the model has no level to set. */ export function resolveThinkingLevel(levels: readonly ThinkingLevel[], wanted: ThinkingLevel | undefined): ThinkingLevel | undefined { if (levels.length === 0) return undefined; if (wanted === undefined) return levels.includes("medium") ? "medium" : levels[0]; const order: readonly ThinkingLevel[] = THINKING_LEVELS; const offered = order.filter((level) => levels.includes(level)); return offered.find((level) => order.indexOf(level) >= order.indexOf(wanted)) ?? offered.at(-1); }