mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 10:53:56 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50cfe8412e | ||
|
|
f193940839 | ||
|
|
9b82876e8c | ||
|
|
7c5e6b129e | ||
|
|
3075b594b0 |
No files matched your search
@@ -29,6 +29,9 @@ for (const codexRuntime of ['sdk', 'app-server'] as const) {
|
||||
const config = { ...agent, codexRuntime };
|
||||
await act(async () => { root = TestRenderer.create(React.createElement(Harness, { config })); });
|
||||
assert.equal(result.model, null);
|
||||
// The unresolved probe must be distinguishable from "no locked model"
|
||||
// so consumers can hide manual entry until it resolves (#3535).
|
||||
assert.equal(result.isPending, true);
|
||||
let sent = false;
|
||||
const sending = result.loadModel().then(model => { sent = true; return model; });
|
||||
await Promise.resolve();
|
||||
@@ -38,9 +41,11 @@ for (const codexRuntime of ['sdk', 'app-server'] as const) {
|
||||
await act(async () => { resolve({ customConfig: { model: 'glm-5' } }); await sending; });
|
||||
assert.equal(await sending, 'glm-5');
|
||||
assert.equal(result.model, 'glm-5');
|
||||
assert.equal(result.isPending, false);
|
||||
// A different agent must not inherit the previous home/model or promise.
|
||||
await act(async () => { root.update(React.createElement(Harness, { config: { ...config, env: { CODEX_HOME: '/fixture/other' } } })); });
|
||||
assert.equal(result.model, null);
|
||||
assert.equal(result.isPending, true);
|
||||
assert.equal(calls.length, 2);
|
||||
await act(async () => { resolve({ customConfig: null }); await result.loadModel(); });
|
||||
assert.equal(result.model, null);
|
||||
|
||||
@@ -29,5 +29,11 @@ export function useCodexConfigModel(agent: ExternalAgentConfig | undefined, isVi
|
||||
});
|
||||
return () => { cancelled = true; };
|
||||
}, [isVisible, loadModel]);
|
||||
return { model: result?.loadModel === loadModel ? result.model : null, loadModel };
|
||||
return {
|
||||
model: result?.loadModel === loadModel ? result.model : null,
|
||||
loadModel,
|
||||
// `model` is null both while the probe is pending and when no locked model
|
||||
// exists; this flag lets consumers distinguish the unresolved state.
|
||||
isPending: result?.loadModel !== loadModel,
|
||||
};
|
||||
}
|
||||
@@ -67,6 +67,8 @@ interface AIChatPanelContentProps {
|
||||
modelDisplayName?: string;
|
||||
modelCatalogWarning?: string;
|
||||
agentModelPresets: AgentModelPreset[];
|
||||
/** Suppress the composer picker's "use custom model" action (locked model). */
|
||||
allowCustomModelEntry?: boolean;
|
||||
selectedAgentModel: string;
|
||||
handleAgentModelSelect: (modelId: string) => void;
|
||||
cattyConfiguredProviders: ProviderConfig[];
|
||||
@@ -138,6 +140,7 @@ export const AIChatPanelContent: React.FC<AIChatPanelContentProps> = ({
|
||||
modelDisplayName,
|
||||
modelCatalogWarning,
|
||||
agentModelPresets,
|
||||
allowCustomModelEntry = true,
|
||||
selectedAgentModel,
|
||||
handleAgentModelSelect,
|
||||
cattyConfiguredProviders,
|
||||
@@ -354,6 +357,7 @@ export const AIChatPanelContent: React.FC<AIChatPanelContentProps> = ({
|
||||
modelName={modelDisplayName}
|
||||
agentName={currentAgentId === 'catty' ? 'Catty Agent' : externalAgents.find(a => a.id === currentAgentId)?.name}
|
||||
modelPresets={agentModelPresets}
|
||||
allowCustomModelEntry={allowCustomModelEntry}
|
||||
selectedModelId={selectedAgentModel}
|
||||
onModelSelect={handleAgentModelSelect}
|
||||
providerSwitcher={providerSwitcher}
|
||||
|
||||
@@ -22,6 +22,14 @@ import {
|
||||
resolveAgentModelSelection,
|
||||
} from '../infrastructure/ai/types';
|
||||
import { getExternalAgentSdkBackend, getManualAgentCommand, matchesManagedAgentConfig } from '../infrastructure/ai/managedAgents';
|
||||
import {
|
||||
appendComposerCustomModelPresets,
|
||||
resolveComposerCustomModelIds,
|
||||
} from '../infrastructure/ai/composerPicker';
|
||||
import {
|
||||
readComposerModelPrefs,
|
||||
subscribeComposerModelPrefs,
|
||||
} from '../infrastructure/ai/composerModelPrefs';
|
||||
import { toast } from './ui/toast';
|
||||
import { useAgentDiscovery } from '../application/state/useAgentDiscovery';
|
||||
import {
|
||||
@@ -843,13 +851,34 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
[currentAgentConfig],
|
||||
);
|
||||
|
||||
const { model: codexConfigModel, loadModel: loadCodexConfigModel } = useCodexConfigModel(
|
||||
const {
|
||||
model: codexConfigModel,
|
||||
loadModel: loadCodexConfigModel,
|
||||
isPending: isCodexConfigModelPending,
|
||||
} = useCodexConfigModel(
|
||||
currentAgentConfig, isVisible,
|
||||
);
|
||||
|
||||
const agentModelMapRef = useRef(agentModelMap);
|
||||
agentModelMapRef.current = agentModelMap;
|
||||
|
||||
// Manual model ids typed in the composer picker are recorded in composer
|
||||
// prefs (per agent scope). Re-render when they change so custom picks stay
|
||||
// visible and accepted as stored selections (#3534).
|
||||
const [composerCustomModelsVersion, setComposerCustomModelsVersion] = useState(0);
|
||||
useEffect(() => subscribeComposerModelPrefs(() => {
|
||||
setComposerCustomModelsVersion((version) => version + 1);
|
||||
}), []);
|
||||
const collectCustomModelIds = useCallback((agentId: string, presets: AgentModelPreset[]) => {
|
||||
// Touch the version so pref writes recreate this callback and invalidate
|
||||
// memos that read custom ids.
|
||||
void composerCustomModelsVersion;
|
||||
return resolveComposerCustomModelIds({
|
||||
prefs: readComposerModelPrefs(agentId),
|
||||
presets,
|
||||
});
|
||||
}, [composerCustomModelsVersion]);
|
||||
|
||||
const buildExternalAgentRuntimeModelTarget = useCallback((agent: ExternalAgentConfig | undefined): SdkRuntimeModelTarget | null => {
|
||||
if (!agent) return null;
|
||||
const sdkBackend = getExternalAgentSdkBackend(agent);
|
||||
@@ -881,10 +910,14 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
const agent = externalAgentsRef.current.find((item) => item.id === target.agentId);
|
||||
if (buildExternalAgentRuntimeModelTarget(agent)?.cacheKey !== target.cacheKey) return;
|
||||
const agentId = target.agentId;
|
||||
const runtimePresets = mergeFallbackThinkingLevels(
|
||||
const catalogPresets = mergeFallbackThinkingLevels(
|
||||
normalizeSdkRuntimeModelPresets(catalog.models, catalog.currentModelId),
|
||||
getAgentModelPresets(agent?.command, getExternalAgentSdkBackend(agent)),
|
||||
);
|
||||
const runtimePresets = appendComposerCustomModelPresets(
|
||||
catalogPresets,
|
||||
collectCustomModelIds(agentId, catalogPresets),
|
||||
);
|
||||
const storedModelId = agentModelMapRef.current[agentId];
|
||||
if (runtimePresets.length === 0) {
|
||||
setRuntimeAgentModelPresets((prev) => {
|
||||
@@ -917,7 +950,7 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
) {
|
||||
setAgentModel(agentId, catalog.currentModelId);
|
||||
}
|
||||
}, [setAgentModel, buildExternalAgentRuntimeModelTarget]);
|
||||
}, [setAgentModel, buildExternalAgentRuntimeModelTarget, collectCustomModelIds]);
|
||||
|
||||
const loadSdkRuntimeModelCatalog = useCallback((
|
||||
target: SdkRuntimeModelTarget,
|
||||
@@ -1020,6 +1053,12 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
const isCodexAppServer = isCodexManagedAgent && currentAgentConfig?.codexRuntime === 'app-server';
|
||||
const canSteerCurrentTurn = Boolean(activeSessionId && isStreaming && isCodexAppServer);
|
||||
const hasCodexCustomConfig = Boolean(codexConfigModel) && isCodexManagedAgent;
|
||||
// `codexConfigModel` is null both while the config probe is pending and when
|
||||
// the managed Codex config has no locked model. Keep the manual-entry action
|
||||
// hidden until the probe resolves so a pick made in the interim can't be
|
||||
// silently overridden by the config model on send (#3535).
|
||||
const allowCustomModelEntry = !isCodexManagedAgent
|
||||
|| (!isCodexConfigModelPending && !hasCodexCustomConfig);
|
||||
|
||||
const agentModelPresets = useMemo(() => {
|
||||
const target = buildExternalAgentRuntimeModelTarget(currentAgentConfig);
|
||||
@@ -1030,14 +1069,25 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
if (hasCodexCustomConfig && codexConfigModel) {
|
||||
return [{ id: codexConfigModel, name: codexConfigModel }];
|
||||
}
|
||||
if (runtimePresets) return runtimePresets;
|
||||
if (runtimePresets) {
|
||||
return appendComposerCustomModelPresets(
|
||||
runtimePresets,
|
||||
collectCustomModelIds(currentAgentId, runtimePresets),
|
||||
);
|
||||
}
|
||||
const presets = getAgentModelPresets(
|
||||
currentAgentConfig?.command,
|
||||
getExternalAgentSdkBackend(currentAgentConfig),
|
||||
);
|
||||
// BYO Codex CLI: hide GPT-5.6 when CLI < 0.144.0 (stored probe or discovery).
|
||||
const cliVersion = resolveAgentCliVersion(currentAgentConfig, discoveredAgents);
|
||||
return filterAgentModelPresetsForCliVersion(presets, cliVersion);
|
||||
const filteredPresets = filterAgentModelPresetsForCliVersion(presets, cliVersion);
|
||||
// Manual model ids typed in the composer (#3534) stay selectable even when
|
||||
// the CLI catalog does not list them yet.
|
||||
return appendComposerCustomModelPresets(
|
||||
filteredPresets,
|
||||
collectCustomModelIds(currentAgentId, filteredPresets),
|
||||
);
|
||||
}, [
|
||||
currentAgentConfig,
|
||||
currentAgentId,
|
||||
@@ -1046,6 +1096,7 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
hasCodexCustomConfig,
|
||||
codexConfigModel,
|
||||
discoveredAgents,
|
||||
collectCustomModelIds,
|
||||
]);
|
||||
|
||||
const selectedAgentModel = useMemo(() => {
|
||||
@@ -1229,13 +1280,17 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
const catalog = await loadSdkRuntimeModelCatalog(runtimeTarget);
|
||||
if (catalog) {
|
||||
applySdkRuntimeModelCatalog(runtimeTarget, catalog, { adoptCurrentModel: true });
|
||||
const runtimePresets = mergeFallbackThinkingLevels(
|
||||
const catalogPresets = mergeFallbackThinkingLevels(
|
||||
normalizeSdkRuntimeModelPresets(catalog.models, catalog.currentModelId),
|
||||
getAgentModelPresets(
|
||||
currentAgentConfig.command,
|
||||
getExternalAgentSdkBackend(currentAgentConfig),
|
||||
),
|
||||
);
|
||||
const runtimePresets = appendComposerCustomModelPresets(
|
||||
catalogPresets,
|
||||
collectCustomModelIds(sendAgentId, catalogPresets),
|
||||
);
|
||||
const storedModelId = agentModelMapRef.current[sendAgentId];
|
||||
if (
|
||||
catalog.currentModelId
|
||||
@@ -1418,7 +1473,7 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
toolIntegrationMode,
|
||||
clearScopeDraft, showScopeSessionView, setActiveSessionId,
|
||||
flushDraftText, currentAgentConfig, buildExternalAgentRuntimeModelTarget,
|
||||
loadSdkRuntimeModelCatalog, applySdkRuntimeModelCatalog,
|
||||
loadSdkRuntimeModelCatalog, applySdkRuntimeModelCatalog, collectCustomModelIds,
|
||||
]);
|
||||
|
||||
const handleCompact = useCallback(async () => {
|
||||
@@ -1740,6 +1795,9 @@ const AIChatSidePanelActive: React.FC<AIChatSidePanelProps> = ({
|
||||
? runtimeModelWarnings[currentAgentId].message
|
||||
: undefined}
|
||||
agentModelPresets={agentModelPresets}
|
||||
// A managed Codex config's `model` field overrides every selection on
|
||||
// send, so the manual-entry action would be a silent no-op.
|
||||
allowCustomModelEntry={allowCustomModelEntry}
|
||||
selectedAgentModel={selectedAgentModel}
|
||||
handleAgentModelSelect={handleAgentModelSelect}
|
||||
cattyConfiguredProviders={cattyConfiguredProviders}
|
||||
|
||||
@@ -4,11 +4,19 @@ import {
|
||||
type ExternalAgentConfig,
|
||||
} from '../infrastructure/ai/types';
|
||||
import { getExternalAgentSdkBackend } from '../infrastructure/ai/managedAgents';
|
||||
import { canonicalizeEffortEncodedModelId } from '../infrastructure/ai/composerPicker';
|
||||
import {
|
||||
canonicalizeEffortEncodedModelId,
|
||||
modelPresetMatchesId,
|
||||
modelPresetsContainId,
|
||||
} from '../infrastructure/ai/composerPicker';
|
||||
import { sha256 } from '@noble/hashes/sha2.js';
|
||||
import { bytesToHex } from '@noble/hashes/utils.js';
|
||||
|
||||
export { canonicalizeEffortEncodedModelId };
|
||||
export {
|
||||
canonicalizeEffortEncodedModelId,
|
||||
modelPresetMatchesId,
|
||||
modelPresetsContainId,
|
||||
};
|
||||
|
||||
export type SdkRuntimeModelCatalog = {
|
||||
currentModelId: string | null;
|
||||
@@ -234,19 +242,6 @@ export function agentModelPresetsShallowEqual(
|
||||
});
|
||||
}
|
||||
|
||||
export function modelPresetMatchesId(preset: AgentModelPreset, modelId: string): boolean {
|
||||
const canonical = canonicalizeEffortEncodedModelId(modelId);
|
||||
if (preset.thinkingLevels?.length) {
|
||||
return preset.id === canonical
|
||||
|| preset.thinkingLevels.some((level) => `${preset.id}/${level}` === canonical);
|
||||
}
|
||||
return preset.id === canonical;
|
||||
}
|
||||
|
||||
export function modelPresetsContainId(presets: AgentModelPreset[], modelId: string): boolean {
|
||||
return presets.some((preset) => modelPresetMatchesId(preset, modelId));
|
||||
}
|
||||
|
||||
export function normalizeStoredAgentModelSelection(
|
||||
storedModelId: string | null | undefined,
|
||||
presets: AgentModelPreset[],
|
||||
|
||||
@@ -206,6 +206,12 @@ interface ChatInputProps {
|
||||
placeholder?: string;
|
||||
/** Available model presets for the current agent */
|
||||
modelPresets?: AgentModelPreset[];
|
||||
/**
|
||||
* Offer the picker's "use custom model" action. Disable when the current
|
||||
* agent locks the model (e.g. managed Codex `model` config overrides the
|
||||
* selection on every send).
|
||||
*/
|
||||
allowCustomModelEntry?: boolean;
|
||||
/** Currently selected model ID */
|
||||
selectedModelId?: string;
|
||||
/** Callback when user selects a model */
|
||||
@@ -271,6 +277,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
|
||||
agentName,
|
||||
placeholder,
|
||||
modelPresets = [],
|
||||
allowCustomModelEntry = true,
|
||||
selectedModelId,
|
||||
onModelSelect,
|
||||
files = [],
|
||||
@@ -1526,7 +1533,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
|
||||
) : (
|
||||
<Cpu size={11} className="text-muted-foreground/64" />
|
||||
)}
|
||||
<span className={`truncate min-w-0 ${modelChipMaxWidth}`}>{modelLabel}</span>
|
||||
<span className={`truncate min-w-0 ${modelChipMaxWidth}`} title={modelLabel}>{modelLabel}</span>
|
||||
{hasModelPicker && <ChevronDown size={9} className="text-muted-foreground/50" />}
|
||||
</button>
|
||||
{contextUsage && (
|
||||
@@ -1585,19 +1592,22 @@ const ChatInput: React.FC<ChatInputProps> = ({
|
||||
selectedProviderId={providerSwitcher?.selectedProviderId}
|
||||
selectedModelId={hasProviderSwitcher ? providerSwitcher?.selectedModelId : selectedBaseModelId}
|
||||
modelPresets={hasProviderSwitcher ? undefined : modelPresets}
|
||||
allowCustomEntry={allowCustomModelEntry}
|
||||
prefs={modelPrefs}
|
||||
onSelectProviderModel={(providerId, modelId, contextWindow) => {
|
||||
providerSwitcher?.onSelect(providerId, modelId, contextWindow);
|
||||
setModelPrefs(rememberComposerRecentModel(pickerScope, { providerId, modelId }));
|
||||
closeAllMenus();
|
||||
}}
|
||||
onSelectModel={(modelId) => {
|
||||
onSelectModel={(modelId, options) => {
|
||||
const preset = modelPresets.find((item) => item.id === modelId);
|
||||
const nextId = preset
|
||||
? resolveModelSelectionWithThinking(preset, selectedPresetThinking)
|
||||
: modelId;
|
||||
onModelSelect?.(nextId);
|
||||
setModelPrefs(rememberComposerRecentModel(pickerScope, { modelId }));
|
||||
setModelPrefs(rememberComposerRecentModel(pickerScope, options?.custom
|
||||
? { modelId, custom: true }
|
||||
: { modelId }));
|
||||
closeAllMenus();
|
||||
}}
|
||||
onTogglePinned={(entry) => {
|
||||
@@ -1795,6 +1805,7 @@ function chatInputPropsAreEqual(prev: ChatInputProps, next: ChatInputProps): boo
|
||||
&& prev.agentName === next.agentName
|
||||
&& prev.placeholder === next.placeholder
|
||||
&& prev.modelPresets === next.modelPresets
|
||||
&& prev.allowCustomModelEntry === next.allowCustomModelEntry
|
||||
&& prev.selectedModelId === next.selectedModelId
|
||||
&& prev.onModelSelect === next.onModelSelect
|
||||
&& prev.files === next.files
|
||||
|
||||
@@ -61,8 +61,51 @@ test('external agent picker lists presets without a provider column', () => {
|
||||
assert.doesNotMatch(html, /ai\.chat\.providers/);
|
||||
});
|
||||
|
||||
test('custom model action is only offered in Catty provider-switcher mode', () => {
|
||||
test('custom model action is offered in provider-switcher and preset modes', () => {
|
||||
const source = readFileSync(new URL('./ComposerModelPicker.tsx', import.meta.url), 'utf8');
|
||||
assert.match(source, /const showCustom = Boolean\(\s*hasProviders/s);
|
||||
// Custom ids are accepted regardless of mode (provider catalog or CLI
|
||||
// presets) — #3534 wants manual model entry for external agents too.
|
||||
assert.match(source, /const showCustom = Boolean\(\s*allowCustomEntry\s*&&\s*trimmedQuery/s);
|
||||
assert.match(source, /resolveComposerEnterModelId/);
|
||||
});
|
||||
|
||||
test('custom model action can be suppressed when the host locks the model', () => {
|
||||
const source = readFileSync(new URL('./ComposerModelPicker.tsx', import.meta.url), 'utf8');
|
||||
// Codex config-locked models override every selection on send; the host
|
||||
// turns the action off so it never becomes a silent no-op.
|
||||
assert.match(source, /allowCustomEntry = true/);
|
||||
const html = renderToStaticMarkup(
|
||||
<ComposerModelPicker
|
||||
modelPresets={[{ id: 'gpt-5.5', name: 'GPT-5.5' }]}
|
||||
selectedModelId="gpt-5.5"
|
||||
prefs={{ recent: [], pinned: [] }}
|
||||
allowCustomEntry={false}
|
||||
onSelectModel={() => {}}
|
||||
onTogglePinned={() => {}}
|
||||
/>,
|
||||
);
|
||||
assert.doesNotMatch(html, /ai\.chat\.useCustomModel/);
|
||||
});
|
||||
|
||||
test('reselecting a saved custom model preserves its custom provenance', () => {
|
||||
const source = readFileSync(new URL('./ComposerModelPicker.tsx', import.meta.url), 'utf8');
|
||||
// A saved custom id is appended to the preset list, so picking it from
|
||||
// Recent has showCustom === false. The callback must keep the custom flag
|
||||
// anyway, or the host overwrites the pref entry without it and
|
||||
// resolveComposerCustomModelIds drops the model from the presets.
|
||||
assert.match(source, /customPrefIds\.has\(modelId\.toLowerCase\(\)\)/);
|
||||
});
|
||||
|
||||
test('external agent picker keeps preset rows truncation-friendly with a full-name tooltip', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<ComposerModelPicker
|
||||
modelPresets={[{ id: 'gpt-5.6-sol-very-long-preview-id', name: 'GPT-5.6 Sol (preview)' }]}
|
||||
selectedModelId="gpt-5.6-sol-very-long-preview-id"
|
||||
prefs={{ recent: [], pinned: [] }}
|
||||
onSelectModel={() => {}}
|
||||
onTogglePinned={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
assert.match(html, /title="GPT-5\.6 Sol \(preview\)"/);
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { Check, ChevronLeft, ChevronRight, Loader2, Pin, Search, Star } from 'lu
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { useI18n } from '../../application/i18n/I18nProvider';
|
||||
import {
|
||||
canonicalizeEffortEncodedModelId,
|
||||
filterComposerModels,
|
||||
resolveComposerEnterModelId,
|
||||
resolvePinnedAndRecentModels,
|
||||
@@ -22,8 +23,14 @@ export interface ComposerModelPickerProps {
|
||||
selectedModelId?: string;
|
||||
modelPresets?: AgentModelPreset[];
|
||||
prefs: ComposerModelPrefs;
|
||||
/**
|
||||
* Offer the "use custom model" action. Disable when the host locks the
|
||||
* model (e.g. a managed Codex config's `model` field overrides every
|
||||
* selection), so the action never becomes a silent no-op.
|
||||
*/
|
||||
allowCustomEntry?: boolean;
|
||||
onSelectProviderModel?: (providerId: string, modelId: string, contextWindow?: number) => void;
|
||||
onSelectModel?: (modelId: string) => void;
|
||||
onSelectModel?: (modelId: string, options?: { custom?: boolean }) => void;
|
||||
onTogglePinned: (entry: ComposerModelPrefEntry) => void;
|
||||
}
|
||||
|
||||
@@ -56,7 +63,7 @@ const ModelRow: React.FC<{
|
||||
{selected
|
||||
? <Check size={11} className="text-primary shrink-0" />
|
||||
: <span className="w-[11px] shrink-0" />}
|
||||
<span className="min-w-0 flex-1 truncate text-foreground/88">{model.name}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-foreground/88" title={model.name}>{model.name}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@@ -83,6 +90,7 @@ export const ComposerModelPicker: React.FC<ComposerModelPickerProps> = ({
|
||||
selectedModelId,
|
||||
modelPresets = [],
|
||||
prefs,
|
||||
allowCustomEntry = true,
|
||||
onSelectProviderModel,
|
||||
onSelectModel,
|
||||
onTogglePinned,
|
||||
@@ -133,23 +141,51 @@ export const ComposerModelPicker: React.FC<ComposerModelPickerProps> = ({
|
||||
);
|
||||
|
||||
const trimmedQuery = query.trim();
|
||||
// Manual model ids are accepted in both modes: provider-bound catalogs and
|
||||
// preset lists from external CLI agents whose catalogs lag new models.
|
||||
const showCustom = Boolean(
|
||||
hasProviders
|
||||
allowCustomEntry
|
||||
&& trimmedQuery
|
||||
&& !models.some((model) => model.id.toLowerCase() === trimmedQuery.toLowerCase()),
|
||||
);
|
||||
|
||||
// Ids the prefs already mark as custom. A saved custom model that was
|
||||
// appended to the preset list is selectable from Recent/Pinned while
|
||||
// showCustom is false (query empty, id present in the list); the callback
|
||||
// must keep the custom provenance or the host overwrites the pref entry
|
||||
// without it and resolveComposerCustomModelIds drops the model (#3534).
|
||||
const customPrefIds = useMemo(() => {
|
||||
const ids = new Set<string>();
|
||||
for (const entry of [...prefs.pinned, ...prefs.recent]) {
|
||||
if (entry.providerId || entry.custom !== true) continue;
|
||||
ids.add(canonicalizeEffortEncodedModelId(entry.modelId).trim().toLowerCase());
|
||||
}
|
||||
return ids;
|
||||
}, [prefs]);
|
||||
|
||||
const selectModel = (modelId: string) => {
|
||||
const contextWindow = models.find((model) => model.id === modelId)?.contextWindow;
|
||||
if (hasProviders && previewProvider) {
|
||||
onSelectProviderModel?.(previewProvider.id, modelId, contextWindow);
|
||||
return;
|
||||
}
|
||||
onSelectModel?.(modelId);
|
||||
// showCustom is only true when no catalog id matches the query, so a
|
||||
// matching pick here came from the manual-entry action (row or Enter).
|
||||
// Otherwise preserve provenance already recorded in the prefs.
|
||||
const custom = Boolean(
|
||||
(showCustom && modelId.toLowerCase() === trimmedQuery.toLowerCase())
|
||||
|| customPrefIds.has(modelId.toLowerCase()),
|
||||
);
|
||||
onSelectModel?.(modelId, custom ? { custom: true } : undefined);
|
||||
};
|
||||
|
||||
const prefEntryFor = (modelId: string): ComposerModelPrefEntry => (
|
||||
previewProvider ? { providerId: previewProvider.id, modelId } : { modelId }
|
||||
previewProvider
|
||||
? { providerId: previewProvider.id, modelId }
|
||||
// Preserve custom provenance on pin/unpin: a manual model pinned while
|
||||
// other selections evict its unmarked recent twin would otherwise lose
|
||||
// the custom marker and fall back to a catalog model (#3534).
|
||||
: { modelId, ...(customPrefIds.has(modelId.toLowerCase()) ? { custom: true as const } : {}) }
|
||||
);
|
||||
|
||||
if (hasProviders && view === 'providers') {
|
||||
|
||||
@@ -3,11 +3,14 @@ import assert from 'node:assert/strict';
|
||||
|
||||
import type { ProviderConfig } from './types';
|
||||
import {
|
||||
appendComposerCustomModelPresets,
|
||||
buildProviderSeedModels,
|
||||
filterComposerModels,
|
||||
mergeComposerModels,
|
||||
modelPresetsContainId,
|
||||
normalizeCattyReasoningLevel,
|
||||
parseComposerModelPrefs,
|
||||
resolveComposerCustomModelIds,
|
||||
resolveComposerEnterModelId,
|
||||
resolveModelSelectionWithThinking,
|
||||
resolvePinnedAndRecentModels,
|
||||
@@ -210,3 +213,54 @@ test('parseComposerModelPrefs drops empty and duplicate entries', () => {
|
||||
]);
|
||||
assert.deepEqual(parsed.pinned, [{ modelId: 'c' }]);
|
||||
});
|
||||
|
||||
test('resolveComposerCustomModelIds collects explicitly custom ids outside the catalog', () => {
|
||||
const presets = [
|
||||
{ id: 'gpt-5.6-sol', name: 'GPT-5.6 Sol', thinkingLevels: ['high', 'medium'] },
|
||||
{ id: 'gpt-5.5', name: 'GPT-5.5' },
|
||||
];
|
||||
const prefs = parseComposerModelPrefs({
|
||||
recent: [
|
||||
{ modelId: 'gpt-6-astra', custom: true },
|
||||
{ modelId: 'gpt-5.6-sol' },
|
||||
{ modelId: 'gpt-5.5/high' },
|
||||
{ providerId: 'p1', modelId: 'provider-only', custom: true },
|
||||
{ modelId: 'gpt-6-astra', custom: true },
|
||||
],
|
||||
pinned: [{ modelId: 'my-fork-model', custom: true }],
|
||||
});
|
||||
const ids = resolveComposerCustomModelIds({ prefs, presets });
|
||||
assert.deepEqual(ids, ['my-fork-model', 'gpt-6-astra']);
|
||||
});
|
||||
|
||||
test('resolveComposerCustomModelIds ignores unmarked entries missing from the catalog', () => {
|
||||
// Stale catalog entries (removed or version-gated models) must not be
|
||||
// resurrected as custom presets after a CLI downgrade.
|
||||
const prefs = parseComposerModelPrefs({
|
||||
recent: [{ modelId: 'gpt-5.6-sol' }, { modelId: 'my-fork-model' }],
|
||||
pinned: [{ modelId: 'gpt-5.6-sol/medium' }],
|
||||
});
|
||||
const ids = resolveComposerCustomModelIds({ prefs, presets: [{ id: 'gpt-5.5', name: 'GPT-5.5' }] });
|
||||
assert.deepEqual(ids, []);
|
||||
});
|
||||
|
||||
test('appendComposerCustomModelPresets appends unknown ids and stays idempotent', () => {
|
||||
const presets = [{ id: 'gpt-5.5', name: 'GPT-5.5' }];
|
||||
const augmented = appendComposerCustomModelPresets(presets, ['gpt-6-astra', '']);
|
||||
assert.deepEqual(augmented, [
|
||||
{ id: 'gpt-5.5', name: 'GPT-5.5' },
|
||||
{ id: 'gpt-6-astra', name: 'gpt-6-astra' },
|
||||
]);
|
||||
assert.equal(appendComposerCustomModelPresets(augmented, ['gpt-6-astra']), augmented);
|
||||
assert.equal(appendComposerCustomModelPresets(presets, []), presets);
|
||||
});
|
||||
|
||||
test('modelPresetsContainId matches plain and effort-encoded ids', () => {
|
||||
const presets = [
|
||||
{ id: 'gpt-5.6-sol', name: 'GPT-5.6 Sol', thinkingLevels: ['high'] },
|
||||
{ id: 'gpt-5.5', name: 'GPT-5.5' },
|
||||
];
|
||||
assert.equal(modelPresetsContainId(presets, 'gpt-5.5'), true);
|
||||
assert.equal(modelPresetsContainId(presets, 'gpt-5.6-sol?effort=high'), true);
|
||||
assert.equal(modelPresetsContainId(presets, 'gpt-5.5/high'), false);
|
||||
});
|
||||
@@ -19,6 +19,12 @@ export interface ComposerPickerModel {
|
||||
export interface ComposerModelPrefEntry {
|
||||
providerId?: string;
|
||||
modelId: string;
|
||||
/**
|
||||
* True when the id was typed manually in the composer picker ("use custom
|
||||
* model"). Explicit provenance keeps stale catalog entries (removed or
|
||||
* version-gated models) from being resurrected as custom presets.
|
||||
*/
|
||||
custom?: boolean;
|
||||
}
|
||||
|
||||
export interface ComposerModelPrefs {
|
||||
@@ -92,6 +98,7 @@ function parsePrefEntries(value: unknown): ComposerModelPrefEntry[] {
|
||||
? (item as { providerId: string }).providerId.trim()
|
||||
: undefined;
|
||||
const entry: ComposerModelPrefEntry = providerId ? { providerId, modelId } : { modelId };
|
||||
if ((item as { custom?: unknown }).custom === true) entry.custom = true;
|
||||
const key = composerModelPrefKey(entry);
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
@@ -231,6 +238,60 @@ export function formatComposerThinkingLabel(level: string): string {
|
||||
return formatThinkingLabel(level);
|
||||
}
|
||||
|
||||
export function modelPresetMatchesId(preset: AgentModelPreset, modelId: string): boolean {
|
||||
const canonical = canonicalizeEffortEncodedModelId(modelId);
|
||||
if (preset.thinkingLevels?.length) {
|
||||
return preset.id === canonical
|
||||
|| preset.thinkingLevels.some((level) => `${preset.id}/${level}` === canonical);
|
||||
}
|
||||
return preset.id === canonical;
|
||||
}
|
||||
|
||||
export function modelPresetsContainId(presets: AgentModelPreset[], modelId: string): boolean {
|
||||
return presets.some((preset) => modelPresetMatchesId(preset, modelId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Model IDs the user typed manually in the composer picker. Only pref entries
|
||||
* explicitly marked as custom (recorded when the user picked "use custom
|
||||
* model") count, so entries that merely dropped out of the current catalog —
|
||||
* removed or version-gated models, e.g. after a CLI downgrade — are never
|
||||
* resurrected as custom presets.
|
||||
*/
|
||||
export function resolveComposerCustomModelIds(input: {
|
||||
prefs: ComposerModelPrefs;
|
||||
presets: AgentModelPreset[];
|
||||
}): string[] {
|
||||
const seen = new Set<string>();
|
||||
const ids: string[] = [];
|
||||
for (const entry of [...input.prefs.pinned, ...input.prefs.recent]) {
|
||||
if (entry.providerId || entry.custom !== true) continue;
|
||||
const id = canonicalizeEffortEncodedModelId(entry.modelId).trim();
|
||||
if (!id || seen.has(id)) continue;
|
||||
if (modelPresetsContainId(input.presets, id)) continue;
|
||||
seen.add(id);
|
||||
ids.push(id);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append manual model ids as presets after the catalog so a custom pick stays
|
||||
* visible, selectable, and accepted as a stored selection. Idempotent: ids the
|
||||
* presets already cover are ignored.
|
||||
*/
|
||||
export function appendComposerCustomModelPresets(
|
||||
presets: AgentModelPreset[],
|
||||
customIds: readonly string[],
|
||||
): AgentModelPreset[] {
|
||||
if (customIds.length === 0) return presets;
|
||||
const known = new Set(presets.map((preset) => canonicalizeEffortEncodedModelId(preset.id)));
|
||||
const extra = customIds
|
||||
.filter((id) => id && !known.has(id))
|
||||
.map((id) => ({ id, name: id }));
|
||||
return extra.length > 0 ? [...presets, ...extra] : presets;
|
||||
}
|
||||
|
||||
export function resolvePinnedAndRecentModels(input: {
|
||||
models: ComposerPickerModel[];
|
||||
prefs: ComposerModelPrefs;
|
||||
|
||||
Reference in new issue
Block a user