@trans-ai/trans-code 0.5.0 → 0.6.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/docs/superpowers/specs/2026-11-21-key-first-model-flow-design.md +31 -0
- package/package.json +1 -1
- package/src/provider/model-list.test.ts +31 -3
- package/src/provider/provider.test.ts +32 -2
- package/src/provider/provider.ts +40 -8
- package/src/provider/routing.test.ts +1 -1
- package/src/screens/REPL.tsx +62 -5
- package/src/version.ts +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# 先输 key 再选模型 — 设计
|
|
2
|
+
|
|
3
|
+
日期:2026-11-21 · 状态:已确认(会话内)
|
|
4
|
+
|
|
5
|
+
## 意图
|
|
6
|
+
|
|
7
|
+
内置厂商的 /models 流程改为"key 优先":首次使用先输 key,再展示**线上实时**模型列表,避免首次用户只看到可能过期的 curated 兜底。对齐 custom 网关流程已有的顺序(baseurl → key → live 列表)。
|
|
8
|
+
|
|
9
|
+
## 行为
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
/models → 选厂商(非 custom)
|
|
13
|
+
├─ 已存 key → 直接进模型列表(实时拉取,现行为不变)
|
|
14
|
+
└─ 无 key → 先提示 apikey> → 用该 key 拉实时列表 → 选模型
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- 首次输入的 key 只存内存草稿,`applyModelSwitch` 验证通过才落盘(Esc 中途退出不留未验证 key)
|
|
18
|
+
- 选完模型:若 key 是本流程刚输的 → 直接验证(不重复问);老用户 → 保留现有"回车沿用"确认步(key 轮换入口不丢)
|
|
19
|
+
- 实时拉取失败/超时 → curated 兜底 + 提示行"(本地列表 · 保存 key 后显示线上实时列表)"
|
|
20
|
+
|
|
21
|
+
## 同批打磨项
|
|
22
|
+
|
|
23
|
+
- A 新者优先排序:`listEndpointModels` 按版本号降序(数值段逐位比较,同版本基础名在前)
|
|
24
|
+
- B 切换提示:verify 探测到的实际模型与所选不符时,切换行追加"(实际生效 X)";`verifyModel` 返回值新增 `served` 字段
|
|
25
|
+
- C 兜底提示:`model_pick` 显示 curated 时标注本地列表来源
|
|
26
|
+
|
|
27
|
+
## 测试
|
|
28
|
+
|
|
29
|
+
- A:model-list.test.ts 断言代表性集合的新者排序
|
|
30
|
+
- B:provider.test.ts 断言 `served` 返回与提示组合
|
|
31
|
+
- 流程重排为 REPL 状态机改动,靠 typecheck + 全套回归 + 手动验证
|
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ function stubModelsEndpoint(ids: string[]): string {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
describe('listEndpointModels', () => {
|
|
34
|
-
test('fetches the live model list from the endpoint', async () => {
|
|
34
|
+
test('fetches the live model list from the endpoint, newest generation first', async () => {
|
|
35
35
|
const baseUrl = stubModelsEndpoint(['glm-5.1', 'glm-4.6', 'glm-5.3-flash']);
|
|
36
36
|
const { saveConfig } = await import('../config.js');
|
|
37
37
|
saveConfig({
|
|
@@ -40,13 +40,41 @@ describe('listEndpointModels', () => {
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
const models = await listEndpointModels('myhub');
|
|
43
|
-
expect(models).toEqual(['glm-
|
|
43
|
+
expect(models).toEqual(['glm-5.3-flash', 'glm-5.1', 'glm-4.6']); // newest first
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('orders newest generation first: base name before variants, variants before older lines', async () => {
|
|
47
|
+
const baseUrl = stubModelsEndpoint([
|
|
48
|
+
'glm-4.5-air',
|
|
49
|
+
'glm-5.3-flashx-legal',
|
|
50
|
+
'glm-4.6',
|
|
51
|
+
'glm-5.3',
|
|
52
|
+
'glm-5.3-flashx',
|
|
53
|
+
'glm-5.3-flash',
|
|
54
|
+
'glm-5-turbo',
|
|
55
|
+
]);
|
|
56
|
+
const { saveConfig } = await import('../config.js');
|
|
57
|
+
saveConfig({
|
|
58
|
+
apiKeys: { custom: 'k' },
|
|
59
|
+
profiles: { gen: { baseUrl, model: 'glm-4.6', keyId: 'custom' } },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const models = await listEndpointModels('gen');
|
|
63
|
+
expect(models).toEqual([
|
|
64
|
+
'glm-5.3',
|
|
65
|
+
'glm-5.3-flash',
|
|
66
|
+
'glm-5.3-flashx',
|
|
67
|
+
'glm-5.3-flashx-legal',
|
|
68
|
+
'glm-5-turbo',
|
|
69
|
+
'glm-4.6',
|
|
70
|
+
'glm-4.5-air',
|
|
71
|
+
]);
|
|
44
72
|
});
|
|
45
73
|
|
|
46
74
|
test('override form queries an unsaved custom gateway with its key', async () => {
|
|
47
75
|
const baseUrl = stubModelsEndpoint(['m1', 'm2']);
|
|
48
76
|
const models = await listEndpointModels('', { baseUrl, apiKey: 'k' });
|
|
49
|
-
expect(models).toEqual(['
|
|
77
|
+
expect(models).toEqual(['m2', 'm1']); // newest-first heuristic: m2 > m1
|
|
50
78
|
});
|
|
51
79
|
|
|
52
80
|
test('returns an empty list on failure so callers can fall back', async () => {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
vendorModelSpec,
|
|
14
14
|
vendorModels,
|
|
15
15
|
verifyModel,
|
|
16
|
+
switchNote,
|
|
16
17
|
} from './provider.js';
|
|
17
18
|
|
|
18
19
|
let configDir: string;
|
|
@@ -45,7 +46,7 @@ describe('GLM Coding Plan preset', () => {
|
|
|
45
46
|
registerApiKey('glmc', 'test-key');
|
|
46
47
|
const provider = createModel('glmc');
|
|
47
48
|
expect(provider.config.baseUrl).toContain('/api/coding/');
|
|
48
|
-
expect(provider.config.model).toBe('glm-
|
|
49
|
+
expect(provider.config.model).toBe('glm-5.3');
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
test('appears in the model list for /models', () => {
|
|
@@ -64,8 +65,24 @@ describe('vendor model lists', () => {
|
|
|
64
65
|
|
|
65
66
|
test('glm lists the current model line', () => {
|
|
66
67
|
const glm = vendorModels('glm');
|
|
68
|
+
// The glm-5.x generation is what the endpoints actually serve now;
|
|
69
|
+
// glm-4.6/4.5 live on as server-side aliases. glm-4-flash is retired.
|
|
70
|
+
expect(glm).toContain('glm-5.3');
|
|
71
|
+
expect(glm).toContain('glm-5.3-flash');
|
|
67
72
|
expect(glm).toContain('glm-4.6');
|
|
68
|
-
expect(glm).toContain('glm-4
|
|
73
|
+
expect(glm).not.toContain('glm-4-flash');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('glmc lists the current model line of the coding endpoint', () => {
|
|
77
|
+
const glmc = vendorModels('glmc');
|
|
78
|
+
expect(glmc).toContain('glm-5.3');
|
|
79
|
+
expect(glmc).toContain('glm-5.3-flash');
|
|
80
|
+
expect(glmc).toContain('glm-4.6');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('registry defaults resolve to models the endpoints actually serve', () => {
|
|
84
|
+
expect(resolveModel('glm').model).toBe('glm-5.3');
|
|
85
|
+
expect(resolveModel('glmc').model).toBe('glm-5.3');
|
|
69
86
|
});
|
|
70
87
|
|
|
71
88
|
test('deepseek lists the current model line', () => {
|
|
@@ -121,3 +138,16 @@ describe('verifyModel', () => {
|
|
|
121
138
|
expect(result.message).toMatch(/key/i);
|
|
122
139
|
});
|
|
123
140
|
});
|
|
141
|
+
|
|
142
|
+
describe('switchNote', () => {
|
|
143
|
+
test('plain switch line when the endpoint serves the picked name', () => {
|
|
144
|
+
expect(switchNote('glmc/glm-5.3', 'glm-5.3', 'glm-5.3')).toBe('已切换到 glmc/glm-5.3');
|
|
145
|
+
expect(switchNote('glmc/glm-5.3', 'glm-5.3', undefined)).toBe('已切换到 glmc/glm-5.3');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('appends the effectively served model when it differs from the pick', () => {
|
|
149
|
+
expect(switchNote('glmc/glm-4.6', 'glm-4.6', 'glm-5.3-flash')).toBe(
|
|
150
|
+
'已切换到 glmc/glm-4.6(实际生效 glm-5.3-flash)',
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
});
|
package/src/provider/provider.ts
CHANGED
|
@@ -44,9 +44,9 @@ const MODEL_REGISTRY: Record<ModelId, ModelConfig> = {
|
|
|
44
44
|
envKey: 'DEEPSEEK_API_KEY',
|
|
45
45
|
},
|
|
46
46
|
glm: {
|
|
47
|
-
name: 'GLM
|
|
47
|
+
name: 'GLM',
|
|
48
48
|
provider: 'openai',
|
|
49
|
-
model: 'glm-
|
|
49
|
+
model: 'glm-5.3',
|
|
50
50
|
baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
|
|
51
51
|
envKey: 'GLM_API_KEY',
|
|
52
52
|
},
|
|
@@ -56,7 +56,7 @@ const MODEL_REGISTRY: Record<ModelId, ModelConfig> = {
|
|
|
56
56
|
// The GLM Coding Plan subscription only bills against the dedicated
|
|
57
57
|
// coding endpoint; the standard /api/paas/v4 endpoint answers 429
|
|
58
58
|
// "余额不足或无可用资源包" because the plan is not applied there.
|
|
59
|
-
model: 'glm-
|
|
59
|
+
model: 'glm-5.3',
|
|
60
60
|
baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4',
|
|
61
61
|
envKey: 'GLM_API_KEY',
|
|
62
62
|
},
|
|
@@ -88,8 +88,8 @@ const VENDOR_MODELS: Partial<Record<ModelId, string[]>> = {
|
|
|
88
88
|
opus: ['claude-opus-4-20250514', 'claude-sonnet-4-20250514'],
|
|
89
89
|
gpt: ['gpt-4o', 'gpt-4o-mini'],
|
|
90
90
|
deepseek: ['deepseek-v4-pro', 'deepseek-flash'],
|
|
91
|
-
glm: ['glm-
|
|
92
|
-
glmc: ['glm-4.6', 'glm-4.5'],
|
|
91
|
+
glm: ['glm-5.3', 'glm-5.3-flash', 'glm-5.2', 'glm-5.1', 'glm-4.6', 'glm-4.5', 'glm-4.5-air'],
|
|
92
|
+
glmc: ['glm-5.3', 'glm-5.3-flash', 'glm-5.2', 'glm-4.6', 'glm-4.5'],
|
|
93
93
|
minimax: ['MiniMax-Text-01'],
|
|
94
94
|
kimi: ['moonshot-v1-128k', 'moonshot-v1-8k'],
|
|
95
95
|
};
|
|
@@ -462,7 +462,7 @@ function buildChatModel(
|
|
|
462
462
|
export async function verifyModel(
|
|
463
463
|
spec: string,
|
|
464
464
|
apiKeyOverride?: string,
|
|
465
|
-
): Promise<{ ok: boolean; message: string }> {
|
|
465
|
+
): Promise<{ ok: boolean; message: string; served?: string }> {
|
|
466
466
|
const resolved = resolveModel(spec);
|
|
467
467
|
const apiKey = apiKeyOverride?.trim() || lookupApiKey(resolved.id);
|
|
468
468
|
if (!apiKey) {
|
|
@@ -481,6 +481,7 @@ export async function verifyModel(
|
|
|
481
481
|
const served = response?.response_metadata?.model_name;
|
|
482
482
|
return {
|
|
483
483
|
ok: true,
|
|
484
|
+
served,
|
|
484
485
|
message: `连通正常${served ? `(实际模型 ${served})` : ''}`,
|
|
485
486
|
};
|
|
486
487
|
} catch (error) {
|
|
@@ -489,6 +490,18 @@ export async function verifyModel(
|
|
|
489
490
|
}
|
|
490
491
|
}
|
|
491
492
|
|
|
493
|
+
/**
|
|
494
|
+
* Switch-line copy for applyModelSwitch: appends the effectively served
|
|
495
|
+
* model when the gateway maps the picked name onto a different one
|
|
496
|
+
* (e.g. glm-4.6 → glm-5.3-flash).
|
|
497
|
+
*/
|
|
498
|
+
export function switchNote(displayName: string, pickedModel: string, served?: string): string {
|
|
499
|
+
if (served && served !== pickedModel) {
|
|
500
|
+
return `已切换到 ${displayName}(实际生效 ${served})`;
|
|
501
|
+
}
|
|
502
|
+
return `已切换到 ${displayName}`;
|
|
503
|
+
}
|
|
504
|
+
|
|
492
505
|
/** @deprecated Use createModel instead. Kept for the existing REPL. */
|
|
493
506
|
export function createProviderWithKey(id: string, apiKey: string): TransProvider {
|
|
494
507
|
const config = MODEL_REGISTRY[id as ModelId];
|
|
@@ -581,6 +594,25 @@ export function getRouting(): Record<string, string> {
|
|
|
581
594
|
return { ...(loadConfig().routing ?? {}) };
|
|
582
595
|
}
|
|
583
596
|
|
|
597
|
+
/**
|
|
598
|
+
* Newest-generation-first ordering for a live model list: numeric runs
|
|
599
|
+
* compare pairwise, descending ('glm-5.3' > 'glm-4.6' > 'glm-4.5-air');
|
|
600
|
+
* on a version tie the shorter base name leads ('glm-5.3' before
|
|
601
|
+
* 'glm-5.3-flashx'), then alphabetical.
|
|
602
|
+
*/
|
|
603
|
+
function newestFirst(a: string, b: string): number {
|
|
604
|
+
const digits = (s: string): number[] => (s.match(/\d+/g) ?? []).map(Number);
|
|
605
|
+
const na = digits(a);
|
|
606
|
+
const nb = digits(b);
|
|
607
|
+
for (let i = 0; i < Math.max(na.length, nb.length); i++) {
|
|
608
|
+
const da = na[i] ?? -1;
|
|
609
|
+
const db = nb[i] ?? -1;
|
|
610
|
+
if (da !== db) return db - da;
|
|
611
|
+
}
|
|
612
|
+
if (a.length !== b.length) return a.length - b.length;
|
|
613
|
+
return a.localeCompare(b);
|
|
614
|
+
}
|
|
615
|
+
|
|
584
616
|
/**
|
|
585
617
|
* Live model list from an endpoint's OpenAI-compatible GET /models, so the
|
|
586
618
|
* /models picker shows what the gateway actually serves (Zhipu's coding
|
|
@@ -590,7 +622,7 @@ export function getRouting(): Record<string, string> {
|
|
|
590
622
|
*/
|
|
591
623
|
export async function listEndpointModels(
|
|
592
624
|
specOrId: string,
|
|
593
|
-
override?: { baseUrl
|
|
625
|
+
override?: { baseUrl?: string; apiKey?: string },
|
|
594
626
|
): Promise<string[]> {
|
|
595
627
|
try {
|
|
596
628
|
const baseUrl = (override?.baseUrl ?? baseUrlFor(resolveModel(specOrId)))?.replace(/\/$/, '');
|
|
@@ -609,7 +641,7 @@ export async function listEndpointModels(
|
|
|
609
641
|
const ids = (body.data ?? [])
|
|
610
642
|
.map((entry) => entry?.id)
|
|
611
643
|
.filter((id): id is string => typeof id === 'string' && id.length > 0);
|
|
612
|
-
return [...new Set(ids)].sort();
|
|
644
|
+
return [...new Set(ids)].sort(newestFirst);
|
|
613
645
|
} catch {
|
|
614
646
|
return [];
|
|
615
647
|
}
|
|
@@ -91,7 +91,7 @@ describe('role routing', () => {
|
|
|
91
91
|
test('resolveRole maps a role through to the profile model', () => {
|
|
92
92
|
setRouting('analysis', 'glmc');
|
|
93
93
|
const resolved = resolveRole('analysis');
|
|
94
|
-
expect(resolved?.model).toBe('glm-
|
|
94
|
+
expect(resolved?.model).toBe('glm-5.3');
|
|
95
95
|
expect(resolved?.baseUrl).toContain('/api/coding/');
|
|
96
96
|
});
|
|
97
97
|
|
package/src/screens/REPL.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
vendorModelSpec,
|
|
14
14
|
vendorModels,
|
|
15
15
|
verifyModel,
|
|
16
|
+
switchNote,
|
|
16
17
|
type ModelId,
|
|
17
18
|
} from '../provider/provider.js';
|
|
18
19
|
import { loadConfig } from '../config.js';
|
|
@@ -50,6 +51,7 @@ type PromptPhase =
|
|
|
50
51
|
| 'model_pick'
|
|
51
52
|
| 'model_name'
|
|
52
53
|
| 'custom_baseurl'
|
|
54
|
+
| 'vendor_apikey'
|
|
53
55
|
| 'model_apikey'
|
|
54
56
|
| 'model_check'
|
|
55
57
|
| 'permission';
|
|
@@ -101,6 +103,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
101
103
|
const [keyHint, setKeyHint] = useState<string | null>(null);
|
|
102
104
|
const [customBaseDraft, setCustomBaseDraft] = useState('');
|
|
103
105
|
const [customKeyDraft, setCustomKeyDraft] = useState('');
|
|
106
|
+
// Key typed at the vendor step (first-time setup) before any model pick.
|
|
107
|
+
const [vendorKeyDraft, setVendorKeyDraft] = useState('');
|
|
104
108
|
|
|
105
109
|
const models = getAvailableModels();
|
|
106
110
|
// Bun's scheduler can drop the render flush for updates issued from the
|
|
@@ -405,19 +409,21 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
405
409
|
);
|
|
406
410
|
|
|
407
411
|
const applyModelSwitch = useCallback(
|
|
408
|
-
(spec: string, displayName: string, apiKey: string, checkMessage: string) => {
|
|
412
|
+
(spec: string, displayName: string, apiKey: string, checkMessage: string, served?: string) => {
|
|
409
413
|
registerApiKey(spec.split(':')[0]!, apiKey);
|
|
410
414
|
ctx.setModelId(spec);
|
|
411
415
|
setPreferredModel(spec);
|
|
416
|
+
const pickedModel = spec.split(':').pop() ?? displayName;
|
|
412
417
|
addHistory({
|
|
413
418
|
input: '••••••••',
|
|
414
|
-
output: `${checkMessage} —
|
|
419
|
+
output: `${checkMessage} — ${switchNote(displayName, pickedModel, served)}`,
|
|
415
420
|
});
|
|
416
421
|
setPendingSpec(null);
|
|
417
422
|
setPendingDisplayName('');
|
|
418
423
|
setKeyHint(null);
|
|
419
424
|
setCustomBaseDraft('');
|
|
420
425
|
setCustomKeyDraft('');
|
|
426
|
+
setVendorKeyDraft('');
|
|
421
427
|
setVendor(null);
|
|
422
428
|
setPhase('idle');
|
|
423
429
|
dragFlush();
|
|
@@ -435,7 +441,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
435
441
|
setPhase('model_check');
|
|
436
442
|
const result = await verifyModel(spec, apiKey);
|
|
437
443
|
if (result.ok) {
|
|
438
|
-
applyModelSwitch(spec, displayName, apiKey, `✓ ${result.message}
|
|
444
|
+
applyModelSwitch(spec, displayName, apiKey, `✓ ${result.message}`, result.served);
|
|
439
445
|
return;
|
|
440
446
|
}
|
|
441
447
|
addHistory({
|
|
@@ -451,6 +457,35 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
451
457
|
|
|
452
458
|
const handleApiKey = useCallback(
|
|
453
459
|
async (value: string) => {
|
|
460
|
+
// Key-first vendor setup: the key unlocks the live model list before
|
|
461
|
+
// any model is picked (first-time use — no saved key yet).
|
|
462
|
+
if (phase === 'vendor_apikey') {
|
|
463
|
+
const apiKey = value.trim();
|
|
464
|
+
if (!apiKey) {
|
|
465
|
+
addHistory({ input: '••••••••', output: 'API key 不能为空。' });
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const vendor = pendingModel!;
|
|
469
|
+
setVendorKeyDraft(apiKey);
|
|
470
|
+
setPhase('model_pick');
|
|
471
|
+
setPickOptions(vendorModels(vendor));
|
|
472
|
+
setPickCursor(0);
|
|
473
|
+
setPickLive(false);
|
|
474
|
+
setPickLoading(true);
|
|
475
|
+
commitInput('');
|
|
476
|
+
const live = await listEndpointModels(vendor, { apiKey });
|
|
477
|
+
if (pendingModelRef.current === vendor) {
|
|
478
|
+
if (live.length > 0) {
|
|
479
|
+
setPickOptions(live);
|
|
480
|
+
setPickCursor(0);
|
|
481
|
+
setPickLive(true);
|
|
482
|
+
}
|
|
483
|
+
setPickLoading(false);
|
|
484
|
+
}
|
|
485
|
+
dragFlush();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
454
489
|
// Custom-gateway setup: collect the key, then pick the model from the
|
|
455
490
|
// gateway's live list instead of asking for a blind model name.
|
|
456
491
|
if (pendingSpec === null && pendingModel === null && customBaseDraft) {
|
|
@@ -486,13 +521,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
486
521
|
await finalizeSelection(spec, pendingDisplayName, apiKey);
|
|
487
522
|
},
|
|
488
523
|
[
|
|
524
|
+
phase,
|
|
489
525
|
pendingSpec,
|
|
490
526
|
pendingModel,
|
|
491
527
|
pendingDisplayName,
|
|
492
528
|
customBaseDraft,
|
|
493
529
|
addHistory,
|
|
494
530
|
finalizeSelection,
|
|
495
|
-
|
|
531
|
+
commitInput,
|
|
496
532
|
dragFlush,
|
|
497
533
|
],
|
|
498
534
|
);
|
|
@@ -503,7 +539,7 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
503
539
|
const trimmed = resolveSubmitInput(phase, raw);
|
|
504
540
|
if (trimmed === null) return;
|
|
505
541
|
|
|
506
|
-
if (phase === 'model_apikey' || phase === 'model_check') {
|
|
542
|
+
if (phase === 'vendor_apikey' || phase === 'model_apikey' || phase === 'model_check') {
|
|
507
543
|
await handleApiKey(trimmed);
|
|
508
544
|
commitInput('');
|
|
509
545
|
return;
|
|
@@ -737,6 +773,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
737
773
|
setPickOptions(vendorModels(selected.id));
|
|
738
774
|
setPickCursor(0);
|
|
739
775
|
setPickLive(false);
|
|
776
|
+
setVendorKeyDraft('');
|
|
777
|
+
// Key-first: without a saved key the live /models call would 401,
|
|
778
|
+
// so ask for the key up front and fetch the real list with it.
|
|
779
|
+
if (!lookupApiKey(selected.id)) {
|
|
780
|
+
setPhase('vendor_apikey');
|
|
781
|
+
commitInput('');
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
740
784
|
setPhase('model_pick');
|
|
741
785
|
commitInput('');
|
|
742
786
|
|
|
@@ -788,6 +832,14 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
788
832
|
// Custom gateway: model chosen from the live list.
|
|
789
833
|
setCustomModel({ baseUrl: customBaseDraft, model: modelName });
|
|
790
834
|
void finalizeSelection('custom', `custom/${modelName}`, customKeyDraft);
|
|
835
|
+
} else if (vendorKeyDraft) {
|
|
836
|
+
// Key-first flow: the key was just typed — verify without
|
|
837
|
+
// re-asking for it (applyModelSwitch persists it on success).
|
|
838
|
+
void finalizeSelection(
|
|
839
|
+
vendorModelSpec(pendingModel!, modelName),
|
|
840
|
+
`${pendingModel}/${modelName}`,
|
|
841
|
+
vendorKeyDraft,
|
|
842
|
+
);
|
|
791
843
|
} else {
|
|
792
844
|
beginKeyStep(vendorModelSpec(pendingModel!, modelName), `${pendingModel}/${modelName}`);
|
|
793
845
|
}
|
|
@@ -907,6 +959,8 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
907
959
|
? 'baseurl> '
|
|
908
960
|
: phase === 'model_apikey'
|
|
909
961
|
? keyHint ? `apikey (回车沿用 ${keyHint})> ` : 'apikey> '
|
|
962
|
+
: phase === 'vendor_apikey'
|
|
963
|
+
? 'apikey> '
|
|
910
964
|
: phase === 'permission'
|
|
911
965
|
? 'allow?> '
|
|
912
966
|
: '> ';
|
|
@@ -988,6 +1042,9 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
|
|
|
988
1042
|
</Box>
|
|
989
1043
|
{pickLoading && <Text color="gray" dimColor>… 正在从网关获取实时模型列表</Text>}
|
|
990
1044
|
{!pickLoading && pickLive && <Text color="gray" dimColor>(网关实时列表)</Text>}
|
|
1045
|
+
{!pickLoading && !pickLive && (
|
|
1046
|
+
<Text color="gray" dimColor>(本地列表 · 保存 key 后显示线上实时列表)</Text>
|
|
1047
|
+
)}
|
|
991
1048
|
<Text color="gray" dimColor>↑↓ 选择模型 · Enter 确认</Text>
|
|
992
1049
|
</Box>
|
|
993
1050
|
)}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated from package.json by scripts/sync-version.ts (npm version hook)
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.6.0';
|