Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions components/generation/generation-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import type { SettingsSection } from '@/lib/types/settings';
import { MediaPopover } from '@/components/generation/media-popover';
import { getAcceptStringForProviders, isMimeSupportedByProviders } from '@/lib/document/mime';
import { findModelById, modelIdsMatch } from '@/lib/ai/model-aliases';

// ─── Constants ───────────────────────────────────────────────
const MAX_COURSE_MATERIAL_SIZE_MB = 50;
Expand Down Expand Up @@ -103,13 +104,21 @@ export function GenerationToolbar({
isServerConfigured: config.isServerConfigured,
models:
config.isServerConfigured && !config.apiKey && config.serverModels?.length
? config.models.filter((m) => new Set(config.serverModels).has(m.id))
? config.models.filter((model) =>
config.serverModels?.some((serverModelId) =>
modelIdsMatch(id, model.id, serverModelId),
),
)
: config.models,
}))
: [];

const currentProviderConfig = providersConfig?.[currentProviderId];
const currentModel = currentProviderConfig?.models.find((model) => model.id === currentModelId);
const currentModel = findModelById(
currentProviderId,
currentProviderConfig?.models,
currentModelId,
);
const currentThinkingConfig =
thinkingConfigs[getThinkingConfigKey(currentProviderId, currentModelId)];

Expand Down
3 changes: 2 additions & 1 deletion components/scene-renderers/pbl/v2/submission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
} from 'lucide-react';

import { addSubmission, listSubmissionsForMicrotask } from '@/lib/pbl/v2/operations/submission';
import { findModelById } from '@/lib/ai/model-aliases';
import {
TEXT_PDF_IMAGE_ACCEPT,
isImageFile,
Expand Down Expand Up @@ -920,7 +921,7 @@ function SubmissionModal({
// Whether the currently-selected model can read images. Reactive so that
// switching models (in Settings) updates the image-caption gating live.
const hasVision = useSettingsStore((s) => {
const model = s.providersConfig[s.providerId]?.models.find((m) => m.id === s.modelId);
const model = findModelById(s.providerId, s.providersConfig[s.providerId]?.models, s.modelId);
return !!model?.capabilities?.vision;
});
const [mode, setMode] = useState<'paste' | 'file'>('paste');
Expand Down
9 changes: 6 additions & 3 deletions lib/ai/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createLogger } from '@/lib/logger';
import { PROVIDERS } from './providers';
import { thinkingContext } from './thinking-context';
import { getModelMetadataKey } from './model-metadata';
import { getCanonicalModelId } from './model-aliases';
import type { ThinkingCapability, ThinkingConfig } from '@/lib/types/provider';
import {
getThinkingMode,
Expand Down Expand Up @@ -140,9 +141,10 @@ function buildThinkingProviderOptions(
modelId: string,
config: ThinkingConfig,
): ProviderOptions | undefined {
const lookupModelId = providerId ? getCanonicalModelId(providerId, modelId) : modelId;
const info = providerId
? MODEL_THINKING_MAP.get(getModelMetadataKey(providerId, modelId))
: UNIQUE_MODEL_THINKING_MAP.get(modelId);
? MODEL_THINKING_MAP.get(getModelMetadataKey(providerId, lookupModelId))
: UNIQUE_MODEL_THINKING_MAP.get(lookupModelId);
if (!info?.thinking) return undefined; // model has no thinking capability
const thinking = info.thinking;
if (thinking.control === 'none') return undefined;
Expand Down Expand Up @@ -278,8 +280,9 @@ const DEFAULT_VALIDATE = (text: string) => text.trim().length > 0;
// ---------------------------------------------------------------------------

function buildUsageMeta(params: GenerateTextParams | StreamTextParams, source: string) {
const modelId = getModelId(params);
const rawModelId = getModelId(params);
const providerId = getModelProviderId(params) ?? 'unknown';
const modelId = getCanonicalModelId(providerId, rawModelId);
return { source, providerId, modelId, modelString: `${providerId}:${modelId}` };
}

Expand Down
23 changes: 23 additions & 0 deletions lib/ai/model-aliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const MODEL_ID_ALIASES: ReadonlyMap<string, string> = new Map([['openai:gpt-5.6-sol', 'gpt-5.6']]);

/** Resolve aliases used for local catalog, settings, capability, and usage lookups. */
export function getCanonicalModelId(providerId: string, modelId: string): string {
return MODEL_ID_ALIASES.get(`${providerId}:${modelId}`) ?? modelId;
}

export function modelIdsMatch(providerId: string, left: string, right: string): boolean {
return getCanonicalModelId(providerId, left) === getCanonicalModelId(providerId, right);
}

/** Find a model using canonical IDs without changing the model ID sent on the wire. */
export function findModelById<T extends { id: string }>(
providerId: string,
models: readonly T[] | undefined,
modelId: string,
): T | undefined {
const canonicalModelId = getCanonicalModelId(providerId, modelId);
return (
models?.find((model) => model.id === canonicalModelId) ??
models?.find((model) => modelIdsMatch(providerId, model.id, modelId))
);
}
18 changes: 17 additions & 1 deletion lib/ai/model-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ThinkingLevel,
ThinkingRequestAdapter,
} from '@/lib/types/provider';
import { getCanonicalModelId } from './model-aliases';

export function getModelMetadataKey(providerId: string, modelId: string): string {
return `${providerId}:${modelId}`;
Expand Down Expand Up @@ -227,7 +228,21 @@ const doubaoSeed20Effort: ThinkingCapability = {

const minimaxM3Thinking = toggleCapability('anthropic', false);

const openaiGpt56Effort: ThinkingCapability = {
control: 'effort',
requestAdapter: 'openai',
effortValues: ['none', 'low', 'medium', 'high', 'xhigh', 'max'],
defaultEffort: 'medium',
defaultMode: 'enabled',
toggleable: true,
budgetAdjustable: true,
defaultEnabled: true,
};

const THINKING_CAPABILITIES: Record<string, ThinkingCapability> = {
[getModelMetadataKey('openai', 'gpt-5.6')]: openaiGpt56Effort,
[getModelMetadataKey('openai', 'gpt-5.6-terra')]: openaiGpt56Effort,
[getModelMetadataKey('openai', 'gpt-5.6-luna')]: openaiGpt56Effort,
[getModelMetadataKey('openai', 'gpt-5.5')]: effortCapability(
'openai',
['low', 'medium', 'high', 'xhigh'],
Expand Down Expand Up @@ -403,7 +418,8 @@ export function getCatalogThinkingCapability(
providerId: string,
modelId: string,
): ThinkingCapability | undefined {
const exact = THINKING_CAPABILITIES[getModelMetadataKey(providerId, modelId)];
const canonicalModelId = getCanonicalModelId(providerId, modelId);
const exact = THINKING_CAPABILITIES[getModelMetadataKey(providerId, canonicalModelId)];
if (exact) return exact;

if (providerId === 'lemonade') {
Expand Down
54 changes: 52 additions & 2 deletions lib/ai/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type {
ThinkingConfig,
} from '@/lib/types/provider';
import { applyModelMetadata, getCatalogThinkingCapability } from './model-metadata';
import { findModelById } from './model-aliases';
import { getDefaultThinkingConfig, getThinkingMode, pickThinkingBudget } from './thinking-config';
import { createLogger } from '@/lib/logger';
// NOTE: Do NOT import thinking-context.ts here — it uses node:async_hooks
Expand Down Expand Up @@ -66,6 +67,54 @@ export const PROVIDERS: Record<ProviderId, ProviderConfig> = {
requiresApiKey: true,
icon: '/logos/openai.svg',
models: [
{
id: 'gpt-5.6',
name: 'GPT-5.6 Sol',
contextWindow: 1050000,
outputWindow: 128000,
capabilities: {
streaming: true,
tools: true,
vision: true,
thinking: {
toggleable: true,
budgetAdjustable: true,
defaultEnabled: true,
},
},
},
{
id: 'gpt-5.6-terra',
name: 'GPT-5.6 Terra',
contextWindow: 1050000,
outputWindow: 128000,
capabilities: {
streaming: true,
tools: true,
vision: true,
thinking: {
toggleable: true,
budgetAdjustable: true,
defaultEnabled: true,
},
},
},
{
id: 'gpt-5.6-luna',
name: 'GPT-5.6 Luna',
contextWindow: 1050000,
outputWindow: 128000,
capabilities: {
streaming: true,
tools: true,
vision: true,
thinking: {
toggleable: true,
budgetAdjustable: true,
defaultEnabled: true,
},
},
},
{
id: 'gpt-5.5',
name: 'GPT-5.5',
Expand Down Expand Up @@ -1421,6 +1470,7 @@ function shouldUseOpenAIResponsesApi(providerId: ProviderId, modelId: string): b

return (
/^gpt-5\.\d+-pro(?:-|$)/.test(modelId) ||
/^gpt-5\.6(?:-|$)/.test(modelId) ||
/^gpt-5\.5(?:-|$)/.test(modelId) ||
/^gpt-5\.[3-9]-codex(?:-|$)/.test(modelId)
);
Expand Down Expand Up @@ -1659,7 +1709,7 @@ export function getModel(config: ModelConfig): ModelWithInfo {
}

// Look up model info from the provider registry
const modelInfo = provider?.models.find((m) => m.id === config.modelId) || null;
const modelInfo = findModelById(config.providerId, provider?.models, config.modelId) ?? null;

return { model, modelInfo };
}
Expand Down Expand Up @@ -1713,5 +1763,5 @@ export function getProvider(providerId: ProviderId): ProviderConfig | undefined
*/
export function getModelInfo(providerId: ProviderId, modelId: string): ModelInfo | undefined {
const provider = PROVIDERS[providerId];
return provider?.models.find((m) => m.id === modelId);
return findModelById(providerId, provider?.models, modelId);
}
3 changes: 2 additions & 1 deletion lib/ai/thinking-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import type {
ThinkingLevel,
ThinkingMode,
} from '@/lib/types/provider';
import { getCanonicalModelId } from './model-aliases';

export function getThinkingConfigKey(providerId: string, modelId: string): string {
return `${providerId}:${modelId}`;
return `${providerId}:${getCanonicalModelId(providerId, modelId)}`;
}

export function supportsConfigurableThinking(
Expand Down
7 changes: 6 additions & 1 deletion lib/config/apply-token-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
import { MODALITY_ORDER } from './token-plan-presets';
import { getCatalogThinkingCapability } from '@/lib/ai/model-metadata';
import { PROVIDERS } from '@/lib/ai/providers';
import { findModelById } from '@/lib/ai/model-aliases';
import type { ModelInfo } from '@/lib/types/provider';

/**
Expand Down Expand Up @@ -104,7 +105,11 @@ export function applyTokenPlan(
}

function catalogModelFor(target: TokenPlanModalityTarget, id: string): ModelInfo | undefined {
const direct = PROVIDERS[target.providerId as ProviderId]?.models.find((m) => m.id === id);
const direct = findModelById(
target.providerId,
PROVIDERS[target.providerId as ProviderId]?.models,
id,
);
if (direct) return direct;

const allModels = Object.values(PROVIDERS).flatMap((provider) => provider.models);
Expand Down
44 changes: 40 additions & 4 deletions lib/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { persist } from 'zustand/middleware';
import type { ProviderId } from '@/lib/ai/providers';
import type { ProvidersConfig } from '@/lib/types/settings';
import { PROVIDERS } from '@/lib/ai/providers';
import { findModelById, getCanonicalModelId } from '@/lib/ai/model-aliases';
import type { ThinkingConfig } from '@/lib/types/provider';
import { getThinkingConfigKey, supportsConfigurableThinking } from '@/lib/ai/thinking-config';
import type { TTSProviderId, ASRProviderId, BuiltInTTSProviderId } from '@/lib/audio/types';
Expand Down Expand Up @@ -393,11 +394,28 @@ function resolveLLMSelection(
? currentProviderId
: ((Object.keys(config) as ProviderId[]).find(isUsable) ?? ('' as ProviderId));
const modelId = providerId
? resolveSelectedModel(currentModelId, config[providerId]?.models ?? [])
? resolveSelectedLLMModel(providerId, currentModelId, config[providerId]?.models ?? [])
: '';
return { providerId, modelId };
}

/** Keep the caller's wire model ID when it resolves to a known catalog alias. */
function resolveSelectedLLMModel(
providerId: ProviderId,
currentModelId: string,
availableModels: Array<{ id: string }>,
): string {
if (availableModels.some((model) => model.id === currentModelId)) return currentModelId;
const canonicalModelId = getCanonicalModelId(providerId, currentModelId);
if (
canonicalModelId !== currentModelId &&
availableModels.some((model) => model.id === canonicalModelId)
) {
return currentModelId;
}
return availableModels[0]?.id ?? '';
}

function resolveMediaModels<T extends { id: string; name: string }>(
builtInModels: T[],
config?: { customModels?: T[]; replaceBuiltInModels?: boolean },
Expand Down Expand Up @@ -1376,9 +1394,27 @@ export const useSettingsStore = create<SettingsState>()(
const currentModels = newProvidersConfig[key].models;
// When server specifies allowed models, filter the models list
// while preserving custom IDs from env/YAML in server order.
const currentModelMap = new Map(currentModels.map((m) => [m.id, m]));
const filteredModels = info.models?.length
? info.models.map((id) => currentModelMap.get(id) ?? { id, name: id })
? info.models.map((id) => {
const currentModel = findModelById(key, currentModels, id);
const builtInModel = findModelById(key, PROVIDERS[key]?.models, id);
const model =
currentModel && builtInModel
? {
...builtInModel,
...currentModel,
name:
currentModel.name === currentModel.id
? builtInModel.name
: currentModel.name,
capabilities: {
...builtInModel.capabilities,
...currentModel.capabilities,
},
}
: (currentModel ?? builtInModel);
return model ? { ...model, id, name: model.name || id } : { id, name: id };
})
: currentModels;
newProvidersConfig[key] = {
...newProvidersConfig[key],
Expand Down Expand Up @@ -1606,7 +1642,7 @@ export const useSettingsStore = create<SettingsState>()(
? (newProvidersConfig[validLLMProvider as ProviderId]?.models ?? [])
: [];
const validLLMModel = validLLMProvider
? resolveSelectedModel(state.modelId, llmModels)
? resolveSelectedLLMModel(validLLMProvider as ProviderId, state.modelId, llmModels)
: '';
const imageModels = validImageProvider
? resolveMediaModels(
Expand Down
7 changes: 5 additions & 2 deletions lib/utils/model-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
normalizeThinkingConfig,
supportsConfigurableThinking,
} from '@/lib/ai/thinking-config';
import { findModelById } from '@/lib/ai/model-aliases';
import { getCatalogThinkingCapability } from '@/lib/ai/model-metadata';

/**
* Get current model configuration from settings store
Expand All @@ -14,8 +16,9 @@ export function getCurrentModelConfig() {

// Get current provider's config
const providerConfig = providersConfig[providerId];
const modelInfo = providerConfig?.models.find((model) => model.id === modelId);
const thinking = modelInfo?.capabilities?.thinking;
const modelInfo = findModelById(providerId, providerConfig?.models, modelId);
const thinking =
modelInfo?.capabilities?.thinking ?? getCatalogThinkingCapability(providerId, modelId);
const thinkingConfig = supportsConfigurableThinking(thinking)
? normalizeThinkingConfig(thinking, thinkingConfigs[getThinkingConfigKey(providerId, modelId)])
: undefined;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@ai-sdk/anthropic": "^3.0.71",
"@ai-sdk/google": "^3.0.64",
"@ai-sdk/openai": "^3.0.53",
"@ai-sdk/openai": "^3.0.84",
"@ai-sdk/react": "^3.0.170",
"@assistant-ui/react": "^0.14.18",
"@assistant-ui/react-markdown": "^0.14.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/docs/content/docs/supported-models.ar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: قوائم النماذج والموفرين المدمجة في إ

| الموفر | Provider ID | النماذج المدمجة |
| --------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OpenAI | `openai` | GPT-5.5 (`gpt-5.5`)<br />GPT-5.4 Pro (`gpt-5.4-pro`)<br />GPT-5.4 (`gpt-5.4`)<br />GPT-5.4 Mini (`gpt-5.4-mini`)<br />GPT-5.4 Nano (`gpt-5.4-nano`) |
| OpenAI | `openai` | GPT-5.6 Sol (`gpt-5.6`)<br />GPT-5.6 Terra (`gpt-5.6-terra`)<br />GPT-5.6 Luna (`gpt-5.6-luna`)<br />GPT-5.5 (`gpt-5.5`)<br />GPT-5.4 Pro (`gpt-5.4-pro`)<br />GPT-5.4 (`gpt-5.4`)<br />GPT-5.4 Mini (`gpt-5.4-mini`)<br />GPT-5.4 Nano (`gpt-5.4-nano`) |
| Claude | `anthropic` | Claude Opus 4.7 (`claude-opus-4-7`)<br />Claude Opus 4.6 (`claude-opus-4-6`)<br />Claude Sonnet 4.6 (`claude-sonnet-4-6`)<br />Claude Sonnet 4.5 (`claude-sonnet-4-5`)<br />Claude Haiku 4.5 (`claude-haiku-4-5`) |
| Gemini | `google` | Gemini 3.1 Pro Preview (`gemini-3.1-pro-preview`)<br />Gemini 3 Flash Preview (`gemini-3-flash-preview`)<br />Gemini 2.5 Flash (`gemini-2.5-flash`)<br />Gemini 2.5 Flash Lite (`gemini-2.5-flash-lite`)<br />Gemini 2.5 Pro (`gemini-2.5-pro`) |
| GLM | `glm` | GLM-5.1 (`glm-5.1`)<br />GLM-5V-Turbo (`glm-5v-turbo`)<br />GLM-5 (`glm-5`)<br />GLM-4.7 (`glm-4.7`)<br />GLM-4.7-FlashX (`glm-4.7-flashx`)<br />GLM-4.7-Flash (`glm-4.7-flash`)<br />GLM-4.6 (`glm-4.6`)<br />GLM-4.6V (`glm-4.6v`)<br />GLM-4.6V-Flash (`glm-4.6v-flash`) |
Expand Down Expand Up @@ -84,4 +84,3 @@ description: قوائم النماذج والموفرين المدمجة في إ
| unpdf | `unpdf` | نصوص، صور، metadata |
| MinerU | `mineru` | نصوص، صور، جداول، صيغ رياضية، layout analysis |
| MinerU Cloud | `mineru-cloud` | نصوص، صور، جداول، صيغ رياضية، layout analysis |

Loading
Loading