@blockrun/franklin 3.34.3 → 3.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/runner.js +9 -8
- package/dist/ui/app.js +33 -18
- package/dist/ui/model-picker.d.ts +6 -5
- package/dist/ui/model-picker.js +211 -11
- package/package.json +1 -1
package/dist/hooks/runner.js
CHANGED
|
@@ -112,14 +112,15 @@ export class HookEngine {
|
|
|
112
112
|
logger.warn(`[hooks] ${path.basename(hook.sourceFile)} ${input.hookEventName} handler failed open: ${err.message.slice(0, 160)}`);
|
|
113
113
|
resolve({ decision: 'allow' });
|
|
114
114
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
child.stdin?.on('error', err => {
|
|
116
|
+
// EPIPE from a handler that exits before reading stdin is fine; the
|
|
117
|
+
// decision still comes from exit code / stdout.
|
|
118
|
+
if (err.code !== 'EPIPE') {
|
|
119
|
+
logger.warn(`[hooks] ${path.basename(hook.sourceFile)} stdin write failed open: ${err.message.slice(0, 160)}`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
child.stdin?.write(JSON.stringify(input));
|
|
123
|
+
child.stdin?.end();
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
126
|
}
|
package/dist/ui/app.js
CHANGED
|
@@ -14,7 +14,7 @@ import Spinner from 'ink-spinner';
|
|
|
14
14
|
import TextInput from 'ink-text-input';
|
|
15
15
|
import VimInput from './vim-input.js';
|
|
16
16
|
import { renderMarkdown, renderMarkdownStreaming } from './markdown.js';
|
|
17
|
-
import { resolveModel, getPickerCategories, PICKER_CATEGORIES, PICKER_MODELS_FLAT, } from './model-picker.js';
|
|
17
|
+
import { resolveModel, getPickerCategories, getExpandedPickerCategories, PICKER_CATEGORIES, PICKER_MODELS_FLAT, } from './model-picker.js';
|
|
18
18
|
import { estimateCost } from '../pricing.js';
|
|
19
19
|
import { formatTokens, shortModelName } from '../stats/format.js';
|
|
20
20
|
import { mouse, forceDisableMouseTracking } from './mouse.js';
|
|
@@ -688,6 +688,13 @@ function formatAgentErrorForDisplay(error) {
|
|
|
688
688
|
out.push(`- Tip: ${tip}`);
|
|
689
689
|
return out.join('\n');
|
|
690
690
|
}
|
|
691
|
+
function fitPickerText(value, width) {
|
|
692
|
+
if (value.length <= width)
|
|
693
|
+
return value.padEnd(width);
|
|
694
|
+
if (width <= 1)
|
|
695
|
+
return value.slice(0, width);
|
|
696
|
+
return `${value.slice(0, width - 1)}…`;
|
|
697
|
+
}
|
|
691
698
|
function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain, initialTranscript, startWithPicker, onSubmit, onModelChange, onAbort, onExit, }) {
|
|
692
699
|
const { exit } = useApp();
|
|
693
700
|
// Track terminal rows so we can cap the dynamic-region height. Ink wipes the
|
|
@@ -721,6 +728,7 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
721
728
|
// replaced by the hydrated list once the catalog fetch lands.
|
|
722
729
|
const [pickerCats, setPickerCats] = useState(PICKER_CATEGORIES);
|
|
723
730
|
const [pickerMoreCount, setPickerMoreCount] = useState(0);
|
|
731
|
+
const [pickerExpanded, setPickerExpanded] = useState(false);
|
|
724
732
|
const pickerFlat = useMemo(() => pickerCats.flatMap(c => c.models), [pickerCats]);
|
|
725
733
|
// Track the live model without re-firing the hydration effect on every model
|
|
726
734
|
// change — the effect should run when the picker opens, not when the model
|
|
@@ -774,7 +782,7 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
774
782
|
if (mode !== 'model-picker')
|
|
775
783
|
return;
|
|
776
784
|
let cancelled = false;
|
|
777
|
-
void getPickerCategories()
|
|
785
|
+
void (pickerExpanded ? getExpandedPickerCategories() : getPickerCategories())
|
|
778
786
|
.then(({ categories, moreCount, live }) => {
|
|
779
787
|
if (cancelled || !live)
|
|
780
788
|
return;
|
|
@@ -789,7 +797,7 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
789
797
|
})
|
|
790
798
|
.catch(() => { });
|
|
791
799
|
return () => { cancelled = true; };
|
|
792
|
-
}, [mode]);
|
|
800
|
+
}, [mode, pickerExpanded]);
|
|
793
801
|
const bellPlayedRef = useRef(false);
|
|
794
802
|
useEffect(() => {
|
|
795
803
|
const dialogActive = !!permissionRequest || !!askUserRequest;
|
|
@@ -952,9 +960,10 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
952
960
|
r('always');
|
|
953
961
|
}
|
|
954
962
|
}, { isActive: !!permissionRequest });
|
|
955
|
-
// Key handler for picker +
|
|
956
|
-
|
|
957
|
-
|
|
963
|
+
// Key handler for picker + abort. Esc aborts active work or closes dialogs;
|
|
964
|
+
// it must not exit the app while idle — Ctrl+C and /exit are the exit paths.
|
|
965
|
+
const isPickerOrAbort = mode === 'model-picker' || !ready;
|
|
966
|
+
useInput((ch, key) => {
|
|
958
967
|
// Escape during generation → abort current turn (skip if permission dialog open)
|
|
959
968
|
if (key.escape && !ready && !permissionRequest) {
|
|
960
969
|
onAbort();
|
|
@@ -964,17 +973,18 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
964
973
|
setThinking(false);
|
|
965
974
|
return;
|
|
966
975
|
}
|
|
967
|
-
// Esc to quit (only when input is empty and in input mode)
|
|
968
|
-
// In Vim mode: Esc goes to normal mode (handled by VimInput), only quit on Esc in normal mode with empty input
|
|
969
|
-
if (key.escape && mode === 'input' && ready && !input) {
|
|
970
|
-
if (vimEnabled && currentVimMode === 'insert')
|
|
971
|
-
return; // Let VimInput handle Esc → normal
|
|
972
|
-
requestExit(false);
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
976
|
// Arrow key navigation for model picker
|
|
976
977
|
if (mode !== 'model-picker')
|
|
977
978
|
return;
|
|
979
|
+
if (key.ctrl && ch === 'a') {
|
|
980
|
+
const nextExpanded = !pickerExpanded;
|
|
981
|
+
setPickerExpanded(nextExpanded);
|
|
982
|
+
if (!nextExpanded)
|
|
983
|
+
setPickerCats(PICKER_CATEGORIES);
|
|
984
|
+
setPickerMoreCount(0);
|
|
985
|
+
setPickerIdx(0);
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
978
988
|
if (key.upArrow)
|
|
979
989
|
setPickerIdx(i => Math.max(0, i - 1));
|
|
980
990
|
else if (key.downArrow)
|
|
@@ -993,16 +1003,18 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
993
1003
|
// the picker closed, which is both confusing and a privacy risk.
|
|
994
1004
|
setInput('');
|
|
995
1005
|
setHistoryIdx(-1);
|
|
1006
|
+
setPickerExpanded(false);
|
|
996
1007
|
setMode('input');
|
|
997
1008
|
setReady(true);
|
|
998
1009
|
}
|
|
999
1010
|
else if (key.escape) {
|
|
1000
1011
|
setInput('');
|
|
1001
1012
|
setHistoryIdx(-1);
|
|
1013
|
+
setPickerExpanded(false);
|
|
1002
1014
|
setMode('input');
|
|
1003
1015
|
setReady(true);
|
|
1004
1016
|
}
|
|
1005
|
-
}, { isActive:
|
|
1017
|
+
}, { isActive: isPickerOrAbort });
|
|
1006
1018
|
// Tab key: toggle expand/collapse on the last completed tool
|
|
1007
1019
|
useInput((_ch, key) => {
|
|
1008
1020
|
if (key.tab && expandableTool) {
|
|
@@ -1076,6 +1088,9 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
1076
1088
|
// closing handlers clear input too, so both ends are covered.
|
|
1077
1089
|
setInput('');
|
|
1078
1090
|
setHistoryIdx(-1);
|
|
1091
|
+
setPickerExpanded(false);
|
|
1092
|
+
setPickerCats(PICKER_CATEGORIES);
|
|
1093
|
+
setPickerMoreCount(0);
|
|
1079
1094
|
setMode('model-picker');
|
|
1080
1095
|
}
|
|
1081
1096
|
return;
|
|
@@ -1502,7 +1517,7 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
1502
1517
|
cursor += cat.models.length;
|
|
1503
1518
|
return base;
|
|
1504
1519
|
});
|
|
1505
|
-
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { bold: true, children: "Select a model " }),
|
|
1520
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Box, { marginLeft: 2, children: [_jsx(Text, { bold: true, children: "Select a model " }), _jsxs(Text, { dimColor: true, children: ["(\u2191\u2193 navigate, Enter select, Ctrl+A ", pickerExpanded ? 'curated' : 'all models', ", Esc cancel)"] })] }), hiddenAbove > 0 && (_jsx(Box, { marginLeft: 2, marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["\u2191 ", hiddenAbove, " more above"] }) })), pickerCats.map((cat, catIdx) => {
|
|
1506
1521
|
const base = catBases[catIdx];
|
|
1507
1522
|
const visible = cat.models
|
|
1508
1523
|
.map((m, localIdx) => ({ m, globalIdx: base + localIdx }))
|
|
@@ -1513,9 +1528,9 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
|
|
|
1513
1528
|
const isSelected = globalIdx === pickerIdx;
|
|
1514
1529
|
const isCurrent = m.id === currentModel;
|
|
1515
1530
|
const isHighlight = m.highlight === true;
|
|
1516
|
-
return (_jsxs(Box, { marginLeft: 2, children: [_jsxs(Text, { inverse: isSelected, color: isSelected ? 'cyan' : isHighlight ? 'yellow' : undefined, bold: isSelected || isHighlight, children: [' ', m.label
|
|
1531
|
+
return (_jsxs(Box, { marginLeft: 2, children: [_jsxs(Text, { inverse: isSelected, color: isSelected ? 'cyan' : isHighlight ? 'yellow' : undefined, bold: isSelected || isHighlight, children: [' ', fitPickerText(m.label, 26), ' '] }), _jsxs(Text, { dimColor: true, children: [" ", fitPickerText(m.shortcut, 14)] }), _jsx(Text, { color: m.price === 'FREE' ? 'green' : isHighlight ? 'yellow' : undefined, dimColor: !isHighlight && m.price !== 'FREE', children: m.price }), isCurrent && _jsx(Text, { color: "green", children: " \u2190" })] }, m.id));
|
|
1517
1532
|
})] }, cat.category));
|
|
1518
|
-
}), hiddenBelow > 0 && (_jsx(Box, { marginLeft: 2, marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["\u2193 ", hiddenBelow, " more below"] }) })), pickerMoreCount > 0 && (_jsx(Box, { marginTop: 1, marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: ["+ ", pickerMoreCount, " more on gateway \u2014
|
|
1533
|
+
}), hiddenBelow > 0 && (_jsx(Box, { marginLeft: 2, marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["\u2193 ", hiddenBelow, " more below"] }) })), pickerMoreCount > 0 && (_jsx(Box, { marginTop: 1, marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: ["+ ", pickerMoreCount, " more on gateway \u2014 Ctrl+A to show all, or /model <id> to pick one"] }) })), _jsx(Box, { marginTop: 1, marginLeft: 2, children: _jsx(Text, { dimColor: true, children: "Your conversation stays above \u2014 picking a model keeps all history intact." }) })] }));
|
|
1519
1534
|
})(), !inPicker && !permissionRequest && !askUserRequest && (_jsx(InputBox, { input: input, setInput: setInput, onSubmit: handleSubmit, model: currentModel, balance: liveBalance, chain: chain, walletTail: walletAddress && walletAddress.length >= 4 && !walletAddress.startsWith('not set') ? walletAddress.slice(-4) : undefined, sessionCost: totalCost, queued: queuedInputs[0] || undefined, queuedCount: queuedInputs.length, focused: !permissionRequest && !askUserRequest, busy: !askUserRequest && (waiting || thinking || tools.size > 0), awaitingApproval: !!permissionRequest, awaitingAnswer: !!askUserRequest, contextPct: contextPct, vimMode: vimEnabled, onVimModeChange: setCurrentVimMode }))] }));
|
|
1520
1535
|
}
|
|
1521
1536
|
export function launchInkUI(opts) {
|
|
@@ -69,13 +69,12 @@ export interface HydratedPicker {
|
|
|
69
69
|
* {@link PICKER_CATEGORIES} stays the editorial layer — which models are worth
|
|
70
70
|
* featuring, in what order, under which heading, with which shortcut. The
|
|
71
71
|
* gateway is the source of truth for everything factual: whether a model still
|
|
72
|
-
* exists
|
|
73
|
-
*
|
|
74
|
-
* v3.9.3 trim), so we can't just render the catalog.
|
|
72
|
+
* exists and its price. Ctrl+A uses {@link getExpandedPickerCategories} when the
|
|
73
|
+
* user explicitly wants the full gateway chat catalog.
|
|
75
74
|
*
|
|
76
75
|
* Reconciliation rules:
|
|
77
|
-
* - Curated row present in the catalog →
|
|
78
|
-
*
|
|
76
|
+
* - Curated row present in the catalog → keep its label/shortcut/highlight and
|
|
77
|
+
* refresh its price from the gateway.
|
|
79
78
|
* - Curated row absent → drop it. This is the self-healing half: an id the
|
|
80
79
|
* gateway retired (the `claude-haiku-4.5-20251001` case) stops being
|
|
81
80
|
* offered without waiting on a Franklin release. Its MODEL_SHORTCUTS alias
|
|
@@ -95,6 +94,8 @@ export declare function getPickerCategories(): Promise<HydratedPicker>;
|
|
|
95
94
|
* rules can be tested against a synthetic catalog without touching the network.
|
|
96
95
|
*/
|
|
97
96
|
export declare function reconcilePicker(catalog: GatewayModel[]): HydratedPicker;
|
|
97
|
+
export declare function getExpandedPickerCategories(): Promise<HydratedPicker>;
|
|
98
|
+
export declare function reconcileExpandedPicker(catalog: GatewayModel[]): HydratedPicker;
|
|
98
99
|
/**
|
|
99
100
|
* Show interactive model picker. Returns the selected model ID.
|
|
100
101
|
* Falls back to text input if terminal doesn't support raw mode.
|
package/dist/ui/model-picker.js
CHANGED
|
@@ -16,12 +16,11 @@ export const MODEL_SHORTCUTS = {
|
|
|
16
16
|
smart: 'blockrun/auto',
|
|
17
17
|
eco: 'blockrun/auto',
|
|
18
18
|
premium: 'blockrun/auto',
|
|
19
|
-
// Anthropic — `
|
|
20
|
-
// Mythos-class tier above Opus.
|
|
19
|
+
// Anthropic — `claude` follows Opus; `fable` is the Mythos-class tier above it.
|
|
21
20
|
fable: 'anthropic/claude-fable-5',
|
|
22
21
|
'fable-5': 'anthropic/claude-fable-5',
|
|
23
22
|
sonnet: 'anthropic/claude-sonnet-5',
|
|
24
|
-
claude: 'anthropic/claude-
|
|
23
|
+
claude: 'anthropic/claude-opus-4.8',
|
|
25
24
|
'sonnet-5': 'anthropic/claude-sonnet-5',
|
|
26
25
|
'sonnet-4.6': 'anthropic/claude-sonnet-4.6',
|
|
27
26
|
'sonnet-4.5': 'anthropic/claude-sonnet-4.5',
|
|
@@ -198,6 +197,28 @@ export function resolveModelStrict(input) {
|
|
|
198
197
|
`or a full id like anthropic/claude-sonnet-4.6.`,
|
|
199
198
|
};
|
|
200
199
|
}
|
|
200
|
+
const PROVIDER_ORDER = [
|
|
201
|
+
'anthropic',
|
|
202
|
+
'openai',
|
|
203
|
+
'google',
|
|
204
|
+
'xai',
|
|
205
|
+
'zai',
|
|
206
|
+
'moonshot',
|
|
207
|
+
'minimax',
|
|
208
|
+
'deepseek',
|
|
209
|
+
'nvidia',
|
|
210
|
+
];
|
|
211
|
+
const PROVIDER_LABELS = {
|
|
212
|
+
anthropic: 'Anthropic / Claude',
|
|
213
|
+
openai: 'OpenAI / GPT',
|
|
214
|
+
google: 'Google / Gemini',
|
|
215
|
+
xai: 'xAI / Grok',
|
|
216
|
+
zai: 'Z.AI / GLM',
|
|
217
|
+
moonshot: 'Moonshot / Kimi',
|
|
218
|
+
minimax: 'MiniMax',
|
|
219
|
+
deepseek: 'DeepSeek',
|
|
220
|
+
nvidia: 'Free / NVIDIA',
|
|
221
|
+
};
|
|
201
222
|
/**
|
|
202
223
|
* Single source of truth for the /model picker.
|
|
203
224
|
* ~30 models across 6 categories. Every ID here is present in src/pricing.ts
|
|
@@ -306,6 +327,130 @@ export const PICKER_MODELS_FLAT = PICKER_CATEGORIES.flatMap(c => c.models);
|
|
|
306
327
|
function isSyntheticId(id) {
|
|
307
328
|
return id.startsWith('blockrun/');
|
|
308
329
|
}
|
|
330
|
+
function providerOf(id) {
|
|
331
|
+
return id.split('/', 1)[0] || 'other';
|
|
332
|
+
}
|
|
333
|
+
function providerRank(provider) {
|
|
334
|
+
const index = PROVIDER_ORDER.indexOf(provider);
|
|
335
|
+
return index >= 0 ? index : PROVIDER_ORDER.length;
|
|
336
|
+
}
|
|
337
|
+
function providerHeading(provider) {
|
|
338
|
+
return PROVIDER_LABELS[provider] || provider;
|
|
339
|
+
}
|
|
340
|
+
function modelSuffix(id) {
|
|
341
|
+
return id.includes('/') ? id.slice(id.indexOf('/') + 1) : id;
|
|
342
|
+
}
|
|
343
|
+
function versionScoreFrom(match) {
|
|
344
|
+
if (!match)
|
|
345
|
+
return 0;
|
|
346
|
+
const parts = match[1].split('.').map(part => Number.parseInt(part, 10) || 0);
|
|
347
|
+
return parts.slice(0, 3).reduce((score, part, index) => score + part * [1_000_000, 100_000, 1_000][index], 0);
|
|
348
|
+
}
|
|
349
|
+
function providerVersionScore(provider, suffix) {
|
|
350
|
+
switch (provider) {
|
|
351
|
+
case 'anthropic':
|
|
352
|
+
return versionScoreFrom(suffix.match(/claude-(?:fable|opus|sonnet|haiku)-(\d+(?:\.\d+)*)/));
|
|
353
|
+
case 'openai':
|
|
354
|
+
if (suffix.startsWith('gpt-4o'))
|
|
355
|
+
return versionScoreFrom(['', '4.0']);
|
|
356
|
+
return versionScoreFrom(suffix.match(/(?:gpt-|o)(\d+(?:\.\d+)*)/));
|
|
357
|
+
case 'google':
|
|
358
|
+
return versionScoreFrom(suffix.match(/gemini-(\d+(?:\.\d+)*)/));
|
|
359
|
+
case 'xai':
|
|
360
|
+
return versionScoreFrom(suffix.match(/grok-(\d+(?:\.\d+)*)/));
|
|
361
|
+
case 'zai':
|
|
362
|
+
return versionScoreFrom(suffix.match(/glm-(\d+(?:\.\d+)*)/));
|
|
363
|
+
case 'moonshot':
|
|
364
|
+
return versionScoreFrom(suffix.match(/kimi-k(\d+(?:\.\d+)*)/));
|
|
365
|
+
case 'minimax':
|
|
366
|
+
return versionScoreFrom(suffix.match(/minimax-m(\d+(?:\.\d+)*)/));
|
|
367
|
+
case 'deepseek':
|
|
368
|
+
return versionScoreFrom(suffix.match(/deepseek-v(\d+(?:\.\d+)*)/));
|
|
369
|
+
case 'nvidia':
|
|
370
|
+
return versionScoreFrom(suffix.match(/deepseek-v(\d+(?:\.\d+)*)/) ??
|
|
371
|
+
suffix.match(/qwen(\d+(?:\.\d+)*)/) ??
|
|
372
|
+
suffix.match(/step-(\d+(?:\.\d+)*)/) ??
|
|
373
|
+
suffix.match(/nemotron-(\d+(?:\.\d+)*)/) ??
|
|
374
|
+
suffix.match(/mistral-large-(\d+(?:\.\d+)*)/) ??
|
|
375
|
+
suffix.match(/v(\d+(?:\.\d+)*)/));
|
|
376
|
+
default:
|
|
377
|
+
return versionScoreFrom(suffix.match(/(?:^|[^\d])(\d+(?:\.\d+)*)(?:[^\d]|$)/));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function expandedModelRank(model) {
|
|
381
|
+
const suffix = modelSuffix(model.id).toLowerCase();
|
|
382
|
+
const provider = providerOf(model.id);
|
|
383
|
+
let score = providerVersionScore(provider, suffix);
|
|
384
|
+
switch (provider) {
|
|
385
|
+
case 'anthropic':
|
|
386
|
+
score += suffix.includes('fable') ? 90_000 : suffix.includes('opus') ? 80_000 : suffix.includes('sonnet') ? 70_000 : suffix.includes('haiku') ? 40_000 : 0;
|
|
387
|
+
break;
|
|
388
|
+
case 'openai':
|
|
389
|
+
score += suffix.startsWith('gpt-') ? 80_000 : suffix.startsWith('o') ? 65_000 : 0;
|
|
390
|
+
if (suffix.includes('codex'))
|
|
391
|
+
score += 8_000;
|
|
392
|
+
if (suffix.includes('pro') || suffix.includes('sol'))
|
|
393
|
+
score += 3_000;
|
|
394
|
+
if (suffix.includes('terra'))
|
|
395
|
+
score += 2_000;
|
|
396
|
+
if (suffix.includes('luna'))
|
|
397
|
+
score += 1_000;
|
|
398
|
+
if (suffix.includes('mini'))
|
|
399
|
+
score -= 8_000;
|
|
400
|
+
if (suffix.includes('nano'))
|
|
401
|
+
score -= 12_000;
|
|
402
|
+
break;
|
|
403
|
+
case 'google':
|
|
404
|
+
score += suffix.includes('gemini') ? 80_000 : 0;
|
|
405
|
+
if (suffix.includes('pro'))
|
|
406
|
+
score += 5_000;
|
|
407
|
+
if (suffix.includes('flash'))
|
|
408
|
+
score -= 5_000;
|
|
409
|
+
break;
|
|
410
|
+
case 'xai':
|
|
411
|
+
score += suffix.includes('grok') ? 80_000 : 0;
|
|
412
|
+
if (suffix.includes('fast'))
|
|
413
|
+
score -= 4_000;
|
|
414
|
+
if (suffix.includes('build'))
|
|
415
|
+
score -= 8_000;
|
|
416
|
+
break;
|
|
417
|
+
case 'zai':
|
|
418
|
+
score += suffix.includes('glm') ? 80_000 : 0;
|
|
419
|
+
if (suffix.includes('turbo'))
|
|
420
|
+
score -= 5_000;
|
|
421
|
+
break;
|
|
422
|
+
case 'moonshot':
|
|
423
|
+
score += suffix.includes('kimi') ? 80_000 : 0;
|
|
424
|
+
break;
|
|
425
|
+
case 'minimax':
|
|
426
|
+
score += suffix.includes('minimax') ? 80_000 : 0;
|
|
427
|
+
break;
|
|
428
|
+
case 'deepseek':
|
|
429
|
+
score += suffix.includes('v4-pro') ? 90_000 : suffix.includes('reasoner') ? 75_000 : suffix.includes('chat') ? 70_000 : 0;
|
|
430
|
+
break;
|
|
431
|
+
case 'nvidia':
|
|
432
|
+
score += suffix.includes('qwen3-next') ? 80_000 : suffix.includes('qwen') ? 70_000 : suffix.includes('nemotron') ? 60_000 : 0;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
return score;
|
|
436
|
+
}
|
|
437
|
+
function cleanGatewayLabel(model) {
|
|
438
|
+
return (model.name || modelSuffix(model.id))
|
|
439
|
+
.replace(/\s*\((?:free|paid)\)\s*$/i, '')
|
|
440
|
+
.trim();
|
|
441
|
+
}
|
|
442
|
+
function buildShortcutById() {
|
|
443
|
+
const preferred = new Map();
|
|
444
|
+
for (const row of PICKER_CATEGORIES.flatMap(category => category.models)) {
|
|
445
|
+
preferred.set(row.id, row.shortcut);
|
|
446
|
+
}
|
|
447
|
+
for (const [shortcut, id] of Object.entries(MODEL_SHORTCUTS)) {
|
|
448
|
+
const existing = preferred.get(id);
|
|
449
|
+
if (!existing || shortcut.length < existing.length)
|
|
450
|
+
preferred.set(id, shortcut);
|
|
451
|
+
}
|
|
452
|
+
return preferred;
|
|
453
|
+
}
|
|
309
454
|
/** Render a gateway price object into the picker's display format. */
|
|
310
455
|
function formatPrice(m) {
|
|
311
456
|
const p = m.pricing;
|
|
@@ -328,13 +473,12 @@ function formatPrice(m) {
|
|
|
328
473
|
* {@link PICKER_CATEGORIES} stays the editorial layer — which models are worth
|
|
329
474
|
* featuring, in what order, under which heading, with which shortcut. The
|
|
330
475
|
* gateway is the source of truth for everything factual: whether a model still
|
|
331
|
-
* exists
|
|
332
|
-
*
|
|
333
|
-
* v3.9.3 trim), so we can't just render the catalog.
|
|
476
|
+
* exists and its price. Ctrl+A uses {@link getExpandedPickerCategories} when the
|
|
477
|
+
* user explicitly wants the full gateway chat catalog.
|
|
334
478
|
*
|
|
335
479
|
* Reconciliation rules:
|
|
336
|
-
* - Curated row present in the catalog →
|
|
337
|
-
*
|
|
480
|
+
* - Curated row present in the catalog → keep its label/shortcut/highlight and
|
|
481
|
+
* refresh its price from the gateway.
|
|
338
482
|
* - Curated row absent → drop it. This is the self-healing half: an id the
|
|
339
483
|
* gateway retired (the `claude-haiku-4.5-20251001` case) stops being
|
|
340
484
|
* offered without waiting on a Franklin release. Its MODEL_SHORTCUTS alias
|
|
@@ -377,9 +521,7 @@ export function reconcilePicker(catalog) {
|
|
|
377
521
|
continue; // retired upstream — drop the row, keep the alias
|
|
378
522
|
// Price comes from the gateway (it's factual, it drifts, and it's the
|
|
379
523
|
// user's money). The label stays curated: gateway names are longer than
|
|
380
|
-
// the picker's tuned columns
|
|
381
|
-
// chars against a 26-wide field) and carry redundant "(Free)" suffixes
|
|
382
|
-
// that the 🆓 heading already says.
|
|
524
|
+
// the picker's tuned columns and often carry redundant suffixes.
|
|
383
525
|
models.push({ ...row, price: formatPrice(live) });
|
|
384
526
|
}
|
|
385
527
|
if (models.length > 0)
|
|
@@ -388,6 +530,64 @@ export function reconcilePicker(catalog) {
|
|
|
388
530
|
const moreCount = catalog.filter(m => m.categories?.includes('chat') && !curated.has(m.id)).length;
|
|
389
531
|
return { categories, moreCount, live: true };
|
|
390
532
|
}
|
|
533
|
+
export async function getExpandedPickerCategories() {
|
|
534
|
+
try {
|
|
535
|
+
return reconcileExpandedPicker(await getGatewayModels());
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
return { categories: PICKER_CATEGORIES, moreCount: 0, live: false };
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
export function reconcileExpandedPicker(catalog) {
|
|
542
|
+
const categories = [{ ...PICKER_CATEGORIES[0], models: [...PICKER_CATEGORIES[0].models] }];
|
|
543
|
+
const curated = new Set();
|
|
544
|
+
const curatedRows = new Map();
|
|
545
|
+
for (const cat of PICKER_CATEGORIES) {
|
|
546
|
+
for (const row of cat.models) {
|
|
547
|
+
curated.add(row.id);
|
|
548
|
+
if (!isSyntheticId(row.id))
|
|
549
|
+
curatedRows.set(row.id, row);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const shortcutById = buildShortcutById();
|
|
553
|
+
const chatModels = catalog
|
|
554
|
+
.filter(m => m.categories?.includes('chat'))
|
|
555
|
+
.sort((a, b) => {
|
|
556
|
+
const providerDelta = providerRank(providerOf(a.id)) - providerRank(providerOf(b.id));
|
|
557
|
+
if (providerDelta !== 0)
|
|
558
|
+
return providerDelta;
|
|
559
|
+
const rankDelta = expandedModelRank(b) - expandedModelRank(a);
|
|
560
|
+
if (rankDelta !== 0)
|
|
561
|
+
return rankDelta;
|
|
562
|
+
const curatedDelta = Number(!curated.has(a.id)) - Number(!curated.has(b.id));
|
|
563
|
+
if (curatedDelta !== 0)
|
|
564
|
+
return curatedDelta;
|
|
565
|
+
return modelSuffix(a.id).localeCompare(modelSuffix(b.id));
|
|
566
|
+
});
|
|
567
|
+
const byProvider = new Map();
|
|
568
|
+
for (const model of chatModels) {
|
|
569
|
+
const provider = providerOf(model.id);
|
|
570
|
+
const curatedRow = curatedRows.get(model.id);
|
|
571
|
+
const row = curatedRow
|
|
572
|
+
? { ...curatedRow, price: formatPrice(model) }
|
|
573
|
+
: {
|
|
574
|
+
id: model.id,
|
|
575
|
+
shortcut: shortcutById.get(model.id) || model.id,
|
|
576
|
+
label: cleanGatewayLabel(model),
|
|
577
|
+
price: formatPrice(model),
|
|
578
|
+
};
|
|
579
|
+
const rows = byProvider.get(provider) ?? [];
|
|
580
|
+
rows.push(row);
|
|
581
|
+
byProvider.set(provider, rows);
|
|
582
|
+
}
|
|
583
|
+
for (const [provider, models] of [...byProvider.entries()].sort((a, b) => {
|
|
584
|
+
const rankDelta = providerRank(a[0]) - providerRank(b[0]);
|
|
585
|
+
return rankDelta !== 0 ? rankDelta : a[0].localeCompare(b[0]);
|
|
586
|
+
})) {
|
|
587
|
+
categories.push({ category: providerHeading(provider), models });
|
|
588
|
+
}
|
|
589
|
+
return { categories, moreCount: 0, live: true };
|
|
590
|
+
}
|
|
391
591
|
/**
|
|
392
592
|
* Show interactive model picker. Returns the selected model ID.
|
|
393
593
|
* Falls back to text input if terminal doesn't support raw mode.
|
package/package.json
CHANGED