Open History to see the last commit
1import type { ModelCapabilities, ProviderOptionSelection } from "@t3tools/contracts";
2
3/**
4 * Filter stored option selections down to those the next model also exposes.
5 * Used when switching models so a reasoning-effort choice carries over to a
6 * model that supports the same option descriptor, while options the new model
7 * does not have are dropped instead of sent blindly. Returns `undefined` when
8 * nothing survives so callers can omit the `options` field entirely.
9 */
10export function preserveCompatibleOptions(
11 currentOptions: ReadonlyArray<ProviderOptionSelection> | null | undefined,
12 nextCaps: ModelCapabilities | null | undefined,
13): ReadonlyArray<ProviderOptionSelection> | undefined {
14 if (!currentOptions || currentOptions.length === 0) return undefined;
15 const descriptorIds = new Set(
16 (nextCaps?.optionDescriptors ?? []).map((descriptor) => descriptor.id),
17 );
18 if (descriptorIds.size === 0) return undefined;
19 const preserved = currentOptions.filter((option) => descriptorIds.has(option.id));
20 return preserved.length > 0 ? preserved : undefined;
21}