mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 16:42:19 +00:00
* feat(ai): support xhigh and max reasoning effort levels The provider-level reasoning default only offered low/medium/high, so models that document the full graded ladder could not be configured to their top tiers. DeepSeek V4/V4.1 grade `reasoning_effort` continuously up to `max`, and Anthropic exposes `max` on 4.6+ plus `xhigh` from 4.7 onward. Beyond the missing select options, three separate layers silently discarded the higher values: - REASONING_RANK stopped at `high`, so the visibility resolver treated `xhigh`/`max` as stale and fell back to `low`. - The OpenAI capability check only matched `deepseek-r1`, which left the DeepSeek V4 family unrecognised and hid the thinking chip entirely. - The pinned `@ai-sdk/openai@4.0.8` validates provider options against a zod enum capped at `xhigh`, so `max` on Chat Completions threw "invalid openai provider options" before any request was made. Add a shared PROVIDER_REASONING_EFFORT_OPTIONS list used by both the settings select and its save guard, extend the rank ladder, and teach the per-model derivation about DeepSeek V4 grading plus the Anthropic effort generations. Bump `@ai-sdk/openai` to 4.0.11, the first release whose enum accepts `max`; it keeps 4.0.8's data-URL image fix. Models whose vocabulary stops at `high` now clamp these levels onto their own ceiling instead of dropping the setting, so an explicit user choice is never silently ignored and no unsupported value reaches a provider. * fix(ai): keep extended effort for explicit custom relay aliases A custom OpenAI-compatible provider with an explicit reasoning default is the escape hatch for relay model IDs that match no capability pattern. That branch still advertised only low/medium/high, so resolveVisibleCattyThinkingLevel treated a configured `xhigh` or `max` as stale and downgraded it to `high` before the request was built. Advertise the full ladder there: the explicit provider default is already the user's assertion that the alias accepts reasoning_effort, so it should also carry the ceiling they picked. Unrecognized aliases without a default keep advertising nothing. * test(ai): verify max effort with the pinned OpenAI SDK --------- Co-authored-by: Arcadia <57169358+RayYiHang@users.noreply.github.com>
641 lines
28 KiB
TypeScript
641 lines
28 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import type { SharedV4ProviderOptions } from '@ai-sdk/provider';
|
|
|
|
import {
|
|
applyResponsesApiStatelessStoreOption,
|
|
buildCattyReasoningProviderOptions,
|
|
cattyReasoningLevelsForSelection,
|
|
estimateReasoningOutputReserve,
|
|
isProviderReasoningEffort,
|
|
openaiModelLikelySupportsReasoning,
|
|
openaiModelSupportsExtraHighReasoning,
|
|
openaiModelSupportsNoneReasoning,
|
|
PROVIDER_REASONING_EFFORT_OPTIONS,
|
|
resolveEffectiveCattyReasoningEffort,
|
|
resolveVisibleCattyThinkingLevel,
|
|
} from './cattyReasoning';
|
|
|
|
test('resolveEffectiveCattyReasoningEffort prefers the composer chip over the provider default', () => {
|
|
assert.equal(resolveEffectiveCattyReasoningEffort('low', 'high'), 'low');
|
|
assert.equal(resolveEffectiveCattyReasoningEffort('off', 'high'), 'off');
|
|
});
|
|
|
|
test('resolveEffectiveCattyReasoningEffort falls back to the provider default', () => {
|
|
assert.equal(resolveEffectiveCattyReasoningEffort(undefined, 'high'), 'high');
|
|
assert.equal(resolveEffectiveCattyReasoningEffort(null, ' high '), 'high');
|
|
assert.equal(resolveEffectiveCattyReasoningEffort('', 'HIGH'), 'high');
|
|
});
|
|
|
|
test('resolveEffectiveCattyReasoningEffort drops blank or default provider values', () => {
|
|
assert.equal(resolveEffectiveCattyReasoningEffort(undefined, undefined), undefined);
|
|
assert.equal(resolveEffectiveCattyReasoningEffort(undefined, ''), undefined);
|
|
assert.equal(resolveEffectiveCattyReasoningEffort(undefined, 'default'), undefined);
|
|
assert.equal(resolveEffectiveCattyReasoningEffort(undefined, ' '), undefined);
|
|
});
|
|
|
|
test('buildCattyReasoningProviderOptions is omitted when effort is off', () => {
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'off'),
|
|
undefined,
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, undefined),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
test('buildCattyReasoningProviderOptions maps OpenAI-compatible effort', () => {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'deepseek' }, 'high'),
|
|
{ openai: { reasoningEffort: 'high' } },
|
|
);
|
|
});
|
|
|
|
test('buildCattyReasoningProviderOptions omits reasoningEffort for non-reasoning OpenAI models', () => {
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'high', 'gpt-4o'),
|
|
undefined,
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'high', 'gpt-5.5'),
|
|
{ openai: { reasoningEffort: 'high' } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'off', 'o3-mini'),
|
|
{ openai: { reasoningEffort: 'low' } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'off', 'gpt-5'),
|
|
{ openai: { reasoningEffort: 'minimal' } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'off', 'gpt-5.5'),
|
|
{ openai: { reasoningEffort: 'none' } },
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, undefined, 'gpt-5.5'),
|
|
undefined,
|
|
);
|
|
assert.equal(openaiModelSupportsNoneReasoning('o4-mini'), false);
|
|
assert.equal(openaiModelSupportsNoneReasoning('gpt-5.1-codex'), true);
|
|
assert.equal(openaiModelSupportsNoneReasoning('gpt-5.1-chat-latest'), false);
|
|
});
|
|
|
|
test('cattyReasoningLevelsForSelection hides the chip unless the model can take effort', () => {
|
|
assert.equal(openaiModelLikelySupportsReasoning('gpt-4o'), false);
|
|
assert.equal(openaiModelLikelySupportsReasoning('gpt-5-chat-latest'), false);
|
|
assert.equal(openaiModelLikelySupportsReasoning('gpt-5.1-chat-latest'), false);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'high', 'gpt-5-chat-latest'),
|
|
undefined,
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'off', 'gpt-5.1-chat-latest'),
|
|
undefined,
|
|
);
|
|
assert.equal(openaiModelLikelySupportsReasoning('gpt-5.5'), true);
|
|
assert.deepEqual(cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'gpt-4o'), []);
|
|
assert.ok(cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'gpt-5.5').includes('high'));
|
|
assert.ok(cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'gpt-5.5').includes('off'));
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'gpt-5.5'),
|
|
['off', 'low', 'medium', 'high', 'xhigh'],
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'gpt-5'),
|
|
['minimal', 'low', 'medium', 'high'],
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'o3-mini'),
|
|
['low', 'medium', 'high'],
|
|
);
|
|
assert.deepEqual(cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-1.5-flash'), []);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3-flash'),
|
|
['minimal', 'low', 'medium', 'high'],
|
|
);
|
|
assert.ok(cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3-flash').includes('minimal'));
|
|
assert.ok(!cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3-flash').includes('off'));
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3.7-flash'),
|
|
['low', 'medium', 'high'],
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3.1-flash-lite-image'),
|
|
['minimal', 'high'],
|
|
);
|
|
assert.ok(cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, 'claude-opus-4-6').includes('high'));
|
|
assert.ok(cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, 'claude-sonnet-5').includes('high'));
|
|
// Fable 5 supports all five effort levels but is always-on, so no `off`.
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, 'claude-fable-5'),
|
|
['low', 'medium', 'high', 'xhigh', 'max'],
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, 'claude-3-haiku-20240307'),
|
|
[],
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'high', 'claude-3-haiku-20240307'),
|
|
undefined,
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3-pro'),
|
|
['low', 'high'],
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-3.1-pro-preview'),
|
|
['low', 'medium', 'high'],
|
|
);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'google' }, 'gemini-2.5-pro'),
|
|
['low', 'medium', 'high'],
|
|
);
|
|
});
|
|
|
|
test('resolveVisibleCattyThinkingLevel drops stale levels after a model switch', () => {
|
|
assert.equal(
|
|
resolveVisibleCattyThinkingLevel(['low', 'medium', 'high'], 'minimal'),
|
|
'low',
|
|
);
|
|
assert.equal(
|
|
resolveVisibleCattyThinkingLevel(['minimal', 'low', 'medium', 'high'], 'off'),
|
|
'minimal',
|
|
);
|
|
assert.equal(
|
|
resolveVisibleCattyThinkingLevel(['off', 'low', 'medium', 'high'], 'high'),
|
|
'high',
|
|
);
|
|
assert.equal(
|
|
resolveVisibleCattyThinkingLevel(['low', 'high'], 'medium'),
|
|
'high',
|
|
);
|
|
assert.equal(
|
|
resolveVisibleCattyThinkingLevel(['low', 'medium', 'high'], 'off'),
|
|
'low',
|
|
);
|
|
});
|
|
|
|
test('estimateReasoningOutputReserve folds thinking budgets into the output reserve', () => {
|
|
assert.equal(estimateReasoningOutputReserve(undefined), 0);
|
|
assert.equal(
|
|
estimateReasoningOutputReserve(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'high', 'claude-sonnet-4-5'),
|
|
),
|
|
20_000,
|
|
);
|
|
assert.equal(
|
|
estimateReasoningOutputReserve(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'medium', 'claude-3-7-sonnet-20250219'),
|
|
),
|
|
10_000,
|
|
);
|
|
assert.equal(
|
|
estimateReasoningOutputReserve(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'high', 'claude-opus-4-6'),
|
|
),
|
|
0,
|
|
);
|
|
assert.equal(
|
|
estimateReasoningOutputReserve(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'high', 'gemini-2.5-pro'),
|
|
),
|
|
16_384,
|
|
);
|
|
assert.equal(
|
|
estimateReasoningOutputReserve(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'high', 'gpt-5.5'),
|
|
),
|
|
0,
|
|
);
|
|
});
|
|
|
|
test('buildCattyReasoningProviderOptions maps Anthropic thinking budgets', () => {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'medium'),
|
|
{ anthropic: { thinking: { type: 'enabled', budgetTokens: 10_000 } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'medium', 'claude-sonnet-4-5'),
|
|
{ anthropic: { thinking: { type: 'enabled', budgetTokens: 10_000 } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'high', 'claude-opus-4-20250514'),
|
|
{ anthropic: { thinking: { type: 'enabled', budgetTokens: 20_000 } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'high', 'claude-opus-4-6'),
|
|
{ anthropic: { thinking: { type: 'adaptive' }, effort: 'high' } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'low', 'claude-sonnet-5'),
|
|
{ anthropic: { thinking: { type: 'adaptive' }, effort: 'low' } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'off', 'claude-sonnet-5'),
|
|
{ anthropic: { thinking: { type: 'disabled' } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'off', 'claude-fable-5'),
|
|
{ anthropic: { thinking: { type: 'adaptive' }, effort: 'low' } },
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'off', 'claude-sonnet-4-5'),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
test('buildCattyReasoningProviderOptions respects an explicit style override', () => {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'custom' as const, style: 'openai' }, 'low'),
|
|
{ openai: { reasoningEffort: 'low' } },
|
|
);
|
|
});
|
|
|
|
test('buildCattyReasoningProviderOptions maps Gemini thinking levels', () => {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'high', 'gemini-3-pro'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'high', includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'off', 'gemini-3-pro'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'low', includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'medium', 'gemini-3-pro'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'high', includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'medium', 'gemini-3.1-pro-preview'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'medium', includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'off', 'gemini-3-flash'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'minimal', includeThoughts: false } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'minimal', 'gemini-3.7-flash'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'low', includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'off', 'gemini-3.7-flash'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'low', includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'low', 'gemini-3.1-flash-lite-image'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'high', includeThoughts: true } } },
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, undefined, 'gemini-3-flash'),
|
|
undefined,
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'high', 'gemini-2.5-pro'),
|
|
{ google: { thinkingConfig: { thinkingBudget: 16_384, includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'off', 'gemini-2.5-pro'),
|
|
{ google: { thinkingConfig: { thinkingBudget: 1_024, includeThoughts: true } } },
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'off', 'gemini-2.5-flash'),
|
|
{ google: { thinkingConfig: { thinkingBudget: 0, includeThoughts: false } } },
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, undefined, 'gemini-2.5-flash'),
|
|
undefined,
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'high'),
|
|
undefined,
|
|
);
|
|
assert.equal(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, 'high', 'gemini-1.5-flash'),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
test('applyResponsesApiStatelessStoreOption sets store:false for OpenAI Responses providers', () => {
|
|
const responsesProvider = { providerId: 'openai' as const, openaiApi: 'responses' as const };
|
|
assert.deepEqual(
|
|
applyResponsesApiStatelessStoreOption(responsesProvider, { openai: { reasoningEffort: 'high' } }),
|
|
{ openai: { reasoningEffort: 'high', store: false, include: ['reasoning.encrypted_content'] } },
|
|
);
|
|
// Even with no reasoning options, Responses turns stay stateless
|
|
// and request replayable (encrypted) reasoning.
|
|
assert.deepEqual(
|
|
applyResponsesApiStatelessStoreOption(responsesProvider, undefined),
|
|
{ openai: { store: false, include: ['reasoning.encrypted_content'] } },
|
|
);
|
|
});
|
|
|
|
test('applyResponsesApiStatelessStoreOption is a no-op for Chat Completions and other styles', () => {
|
|
assert.deepEqual(
|
|
applyResponsesApiStatelessStoreOption({ providerId: 'openai' as const }, { openai: { reasoningEffort: 'high' } }),
|
|
{ openai: { reasoningEffort: 'high' } },
|
|
);
|
|
const chatProvider = { providerId: 'openai' as const, openaiApi: 'chat' as const };
|
|
assert.deepEqual(
|
|
applyResponsesApiStatelessStoreOption(chatProvider, { openai: { reasoningEffort: 'low' } }),
|
|
{ openai: { reasoningEffort: 'low' } },
|
|
);
|
|
const anthropicProvider = { providerId: 'openai' as const, openaiApi: 'responses' as const, style: 'anthropic' as const };
|
|
assert.deepEqual(
|
|
applyResponsesApiStatelessStoreOption(anthropicProvider, { anthropic: { thinking: { type: 'adaptive' } } }),
|
|
{ anthropic: { thinking: { type: 'adaptive' } } },
|
|
);
|
|
assert.equal(applyResponsesApiStatelessStoreOption(undefined, undefined), undefined);
|
|
});
|
|
|
|
test('applyResponsesApiStatelessStoreOption always requests encrypted reasoning on stateless Responses turns', () => {
|
|
const responsesProvider = { providerId: 'custom' as const, openaiApi: 'responses' as const };
|
|
// Every stateless Responses turn gets the include, covering known reasoner
|
|
// IDs (`deepseek-r1`, `gpt-oss-120b`, `grok-4`, `o3`, `gpt-5.1`) as before,
|
|
// always-thinking relay models whose IDs match no classifier (e.g.
|
|
// DeepSeek's default `deepseek-v4-flash`), and plain chat models — for the
|
|
// latter the include is a no-op (no reasoning items to encrypt).
|
|
assert.deepEqual(
|
|
applyResponsesApiStatelessStoreOption(responsesProvider, undefined),
|
|
{ openai: { store: false, include: ['reasoning.encrypted_content'] } },
|
|
'deepseek-v4-flash',
|
|
);
|
|
});
|
|
|
|
test('explicit provider effort exposes controls for a custom OpenAI model', () => {
|
|
const provider = { providerId: 'custom' as const, style: 'openai' as const, advancedParams: { reasoningEffort: 'low' } };
|
|
// An explicit default is the user's assertion that this unclassifiable
|
|
// alias takes reasoning_effort, so the full ladder is offered.
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection(provider, 'relay-model'),
|
|
['low', 'medium', 'high', 'xhigh', 'max'],
|
|
);
|
|
assert.deepEqual(cattyReasoningLevelsForSelection({ ...provider, advancedParams: {} }, 'relay-model'), []);
|
|
});
|
|
|
|
test('the provider default select accepts every documented effort level', () => {
|
|
assert.deepEqual(PROVIDER_REASONING_EFFORT_OPTIONS, ['low', 'medium', 'high', 'xhigh', 'max']);
|
|
for (const level of ['low', 'medium', 'high', 'xhigh', 'max']) {
|
|
assert.equal(isProviderReasoningEffort(level), true, level);
|
|
}
|
|
// Persisted values that predate the graded scale must still be honored.
|
|
for (const level of ['default', '', 'MAX', 'ultra', null, undefined]) {
|
|
assert.equal(isProviderReasoningEffort(level), false, String(level));
|
|
}
|
|
});
|
|
|
|
test('DeepSeek V4 grades reasoning effort up to max', () => {
|
|
const provider = { providerId: 'deepseek' as const };
|
|
for (const model of ['deepseek-v4.1-flash', 'deepseek-v4-flash', 'deepseek-v4-pro', 'deepseek-v4.1-pro']) {
|
|
assert.equal(openaiModelLikelySupportsReasoning(model), true, model);
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection(provider, model),
|
|
['low', 'medium', 'high', 'xhigh', 'max'],
|
|
model,
|
|
);
|
|
for (const level of ['high', 'xhigh', 'max']) {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions(provider, level, model),
|
|
{ openai: { reasoningEffort: level } },
|
|
`${model} ${level}`,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('DeepSeek keeps sending max from a provider default on a custom alias', () => {
|
|
const provider = {
|
|
providerId: 'custom' as const,
|
|
style: 'openai' as const,
|
|
advancedParams: { reasoningEffort: 'max' },
|
|
};
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions(provider, resolveEffectiveCattyReasoningEffort(undefined, 'max'), 'deepseek-v4.1-flash'),
|
|
{ openai: { reasoningEffort: 'max' } },
|
|
);
|
|
});
|
|
|
|
test('custom relay aliases keep the extended tier the provider default asserts', () => {
|
|
// `relay-model` matches no capability pattern, so the explicit provider
|
|
// default is the only signal that it accepts reasoning_effort. Advertising
|
|
// just low/medium/high would downgrade a configured xhigh/max to high.
|
|
for (const level of ['low', 'medium', 'high', 'xhigh', 'max'] as const) {
|
|
const provider = {
|
|
providerId: 'custom' as const,
|
|
style: 'openai' as const,
|
|
advancedParams: { reasoningEffort: level },
|
|
};
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection(provider, 'relay-model'),
|
|
['low', 'medium', 'high', 'xhigh', 'max'],
|
|
level,
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions(
|
|
provider,
|
|
resolveEffectiveCattyReasoningEffort(undefined, level),
|
|
'relay-model',
|
|
),
|
|
{ openai: { reasoningEffort: level } },
|
|
level,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('OpenAI models that stop at high clamp xhigh and max instead of dropping them', () => {
|
|
for (const model of ['gpt-5', 'gpt-5.1', 'o3', 'o4-mini']) {
|
|
for (const level of ['xhigh', 'max']) {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, level, model),
|
|
{ openai: { reasoningEffort: 'high' } },
|
|
`${model} ${level}`,
|
|
);
|
|
}
|
|
}
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'openai' }, 'gpt-5.1'),
|
|
['off', 'low', 'medium', 'high'],
|
|
);
|
|
});
|
|
|
|
test('GPT-5.5 and Codex Max advertise xhigh while older and chat models keep their limits', () => {
|
|
assert.equal(openaiModelSupportsExtraHighReasoning('gpt-5.1-codex-max'), true);
|
|
for (const model of ['gpt-5.5', 'gpt-5.5-2026-04-23', 'openai/gpt-5.5', ' GPT-5.5 ']) {
|
|
assert.equal(openaiModelSupportsExtraHighReasoning(model), true, model);
|
|
const levels = cattyReasoningLevelsForSelection({ providerId: 'openai' }, model);
|
|
assert.deepEqual(levels, ['off', 'low', 'medium', 'high', 'xhigh']);
|
|
for (const effort of ['xhigh', 'max']) {
|
|
assert.equal(resolveVisibleCattyThinkingLevel(levels, effort), 'xhigh');
|
|
assert.deepEqual(buildCattyReasoningProviderOptions({ providerId: 'openai' }, effort, model),
|
|
{ openai: { reasoningEffort: 'xhigh' } }, `${model} ${effort}`);
|
|
}
|
|
}
|
|
for (const model of ['gpt-5', 'gpt-5.1', 'gpt-5.5-chat-latest', 'gpt-5.5-mini', 'gpt-5.50', 'o3', 'o4-mini']) {
|
|
assert.equal(openaiModelSupportsExtraHighReasoning(model), false, model);
|
|
}
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'openai' }, 'xhigh', 'gpt-5.1-codex-max'),
|
|
{ openai: { reasoningEffort: 'xhigh' } },
|
|
);
|
|
});
|
|
|
|
test('GPT-5.5 xhigh survives SDK serialization for Chat and Responses, including max clamping', async () => {
|
|
const { createOpenAI } = await import('@ai-sdk/openai');
|
|
for (const api of ['chat', 'responses'] as const) {
|
|
for (const effort of ['xhigh', 'max']) {
|
|
let body: Record<string, unknown> | undefined;
|
|
const openai = createOpenAI({ apiKey: 'test', fetch: async (_url, init) => {
|
|
body = JSON.parse(String(init?.body));
|
|
throw new Error('captured request');
|
|
} });
|
|
const provider = { providerId: 'openai' as const, openaiApi: api, advancedParams: { reasoningEffort: effort } };
|
|
const levels = cattyReasoningLevelsForSelection(provider, 'gpt-5.5');
|
|
const chip = resolveVisibleCattyThinkingLevel(levels, effort);
|
|
const options = buildCattyReasoningProviderOptions(provider, chip, 'gpt-5.5');
|
|
await assert.rejects(async () => await openai[api]('gpt-5.5').doGenerate({
|
|
prompt: [{ role: 'user', content: [{ type: 'text', text: 'hello' }] }],
|
|
providerOptions: options as SharedV4ProviderOptions,
|
|
}), /captured request/);
|
|
assert.ok(body);
|
|
assert.equal(api === 'chat' ? body.reasoning_effort : (body.reasoning as { effort?: string } | undefined)?.effort, 'xhigh');
|
|
}
|
|
}
|
|
});
|
|
|
|
test('DeepSeek V4 and custom aliases serialize max through the installed Chat and Responses SDK', async () => {
|
|
const { createOpenAI } = await import('@ai-sdk/openai');
|
|
for (const api of ['chat', 'responses'] as const) {
|
|
for (const [providerId, model] of [['deepseek', 'deepseek-v4-flash'], ['custom', 'relay-model']] as const) {
|
|
for (const chip of ['max', undefined]) {
|
|
let body: Record<string, unknown> | undefined;
|
|
let fetchCalls = 0;
|
|
const openai = createOpenAI({ apiKey: 'test', fetch: async (_url, init) => {
|
|
fetchCalls += 1;
|
|
body = JSON.parse(String(init?.body));
|
|
throw new Error('captured max request');
|
|
} });
|
|
const provider = { providerId, openaiApi: api, advancedParams: { reasoningEffort: 'max' } };
|
|
const effort = resolveEffectiveCattyReasoningEffort(chip, provider.advancedParams.reasoningEffort);
|
|
const options = buildCattyReasoningProviderOptions(provider, effort, model);
|
|
await assert.rejects(async () => await openai[api](model).doGenerate({
|
|
prompt: [{ role: 'user', content: [{ type: 'text', text: 'hello' }] }],
|
|
providerOptions: options as SharedV4ProviderOptions,
|
|
}), /captured max request/);
|
|
assert.equal(fetchCalls, 1, `${api} ${model} ${chip ?? 'provider default'}`);
|
|
assert.ok(body);
|
|
assert.equal(api === 'chat' ? body.reasoning_effort : (body.reasoning as { effort?: string } | undefined)?.effort, 'max');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('Anthropic adaptive thinking exposes max, and xhigh from 4.7 onward', () => {
|
|
// 4.6 documents low|medium|high|max.
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, 'claude-opus-4-6'),
|
|
['off', 'low', 'medium', 'high', 'max'],
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'max', 'claude-opus-4-6'),
|
|
{ anthropic: { thinking: { type: 'adaptive' }, effort: 'max' } },
|
|
);
|
|
// 4.6 has no `xhigh`, so it lands on its ceiling rather than being dropped.
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'xhigh', 'claude-opus-4-6'),
|
|
{ anthropic: { thinking: { type: 'adaptive' }, effort: 'max' } },
|
|
);
|
|
// 4.7 and 5.x accept xhigh.
|
|
for (const model of ['claude-opus-4-7', 'claude-sonnet-5']) {
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, model),
|
|
['off', 'low', 'medium', 'high', 'xhigh', 'max'],
|
|
model,
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'xhigh', model),
|
|
{ anthropic: { thinking: { type: 'adaptive' }, effort: 'xhigh' } },
|
|
model,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('Anthropic always-on families never advertise off alongside xhigh and max', () => {
|
|
assert.deepEqual(
|
|
cattyReasoningLevelsForSelection({ providerId: 'anthropic' }, 'claude-fable-5'),
|
|
['low', 'medium', 'high', 'xhigh', 'max'],
|
|
);
|
|
// Legacy budgeted thinking has no tier above high.
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'anthropic' }, 'max', 'claude-sonnet-4-5'),
|
|
{ anthropic: { thinking: { type: 'enabled', budgetTokens: 20_000 } } },
|
|
);
|
|
});
|
|
|
|
test('Gemini clamps xhigh and max onto its highest thinking level', () => {
|
|
for (const level of ['xhigh', 'max'] as const) {
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, level, 'gemini-3-flash'),
|
|
{ google: { thinkingConfig: { thinkingLevel: 'high', includeThoughts: true } } },
|
|
`gemini-3-flash ${level}`,
|
|
);
|
|
assert.deepEqual(
|
|
buildCattyReasoningProviderOptions({ providerId: 'google' }, level, 'gemini-2.5-pro'),
|
|
{ google: { thinkingConfig: { thinkingBudget: 16_384, includeThoughts: true } } },
|
|
`gemini-2.5-pro ${level}`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('custom model requests send explicit effort for Chat and Responses and omit it by default', async () => {
|
|
const { createOpenAI } = await import('@ai-sdk/openai');
|
|
for (const api of ['chat', 'responses'] as const) {
|
|
for (const [chip, fallback, expected] of [
|
|
[undefined, 'high', 'high'],
|
|
['low', 'high', 'low'],
|
|
['', 'high', 'high'],
|
|
[undefined, undefined, undefined],
|
|
[undefined, 'default', undefined],
|
|
] as const) {
|
|
let body: Record<string, unknown> | undefined;
|
|
const openai = createOpenAI({ apiKey: 'test', fetch: async (_url, init) => {
|
|
body = JSON.parse(String(init?.body));
|
|
throw new Error('captured request');
|
|
} });
|
|
const provider = { providerId: 'custom' as const, style: 'openai' as const, openaiApi: api, advancedParams: { reasoningEffort: fallback } };
|
|
const options = buildCattyReasoningProviderOptions(provider, resolveEffectiveCattyReasoningEffort(chip, fallback), 'relay-model');
|
|
await assert.rejects(async () => await openai[api]('relay-model').doGenerate({
|
|
prompt: [{ role: 'user', content: [{ type: 'text', text: 'hello' }] }],
|
|
providerOptions: options as SharedV4ProviderOptions,
|
|
temperature: 0.4,
|
|
topP: 0.8,
|
|
}), /captured request/);
|
|
assert.ok(body);
|
|
if (api === 'chat') {
|
|
assert.equal(body.temperature, 0.4);
|
|
assert.equal(body.top_p, 0.8);
|
|
}
|
|
assert.equal(api === 'chat' ? body.reasoning_effort : (body.reasoning as { effort?: string } | undefined)?.effort, expected);
|
|
if (!expected) assert.equal(body.reasoning, undefined);
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
test('provider defaults do not enable reasoning on known unsupported OpenAI models', () => {
|
|
for (const openaiApi of ['chat', 'responses'] as const) {
|
|
const provider = { providerId: 'custom' as const, style: 'openai' as const, openaiApi, advancedParams: { reasoningEffort: 'high' } };
|
|
for (const model of ['gpt-4o', 'chatgpt-4o-latest', 'gpt-4o-mini', 'gpt-4.1', 'gpt-4-turbo', 'gpt-3.5-turbo', 'openai/gpt-4o', 'gpt-5-chat-latest']) {
|
|
assert.equal(buildCattyReasoningProviderOptions(provider, 'high', model), undefined, model);
|
|
assert.deepEqual(cattyReasoningLevelsForSelection(provider, model), [], model);
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
test('built-in providers retain capability checks when a default is configured', () => {
|
|
const provider = { providerId: 'deepseek' as const, advancedParams: { reasoningEffort: 'high' } };
|
|
assert.equal(buildCattyReasoningProviderOptions(provider, 'high', 'deepseek-chat'), undefined);
|
|
assert.deepEqual(cattyReasoningLevelsForSelection(provider, 'deepseek-chat'), []);
|
|
assert.deepEqual(buildCattyReasoningProviderOptions(provider, 'high', 'deepseek-reasoner'), { openai: { reasoningEffort: 'high' } });
|
|
});
|