@causyne/agent 1.20.7 → 1.20.9
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/package.json +1 -1
- package/src/acp/agentCatalog.js +9 -3
- package/src/acp/agentCatalog.ts +20 -4
- package/src/agentLoop.js +167 -34
- package/src/agentLoop.ts +188 -37
- package/src/commands.js +25 -10
- package/src/compiledSkills.js +7330 -319
- package/src/computerUse/types.js +8 -0
- package/src/computerUse/types.ts +121 -0
- package/src/computerUse/visionGrounding.js +87 -29
- package/src/computerUse/visionGrounding.ts +108 -36
- package/src/decisionPolicy.js +7 -9
- package/src/decisionPolicy.ts +7 -9
- package/src/documentEngine/antiSlopAuditor.js +13 -43
- package/src/documentEngine/antiSlopAuditor.ts +15 -47
- package/src/documentEngine/documentForge.js +3 -3
- package/src/documentEngine/documentForge.ts +3 -3
- package/src/dynamicCatalogue.js +568 -77
- package/src/dynamicCatalogue.ts +608 -79
- package/src/launchIntent.js +3 -3
- package/src/launchIntent.ts +3 -3
- package/src/planCache.js +4 -14
- package/src/planCache.ts +4 -14
- package/src/providers/acp.js +39 -4
- package/src/providers/acp.ts +42 -4
- package/src/providers/antigravity.d.ts +7 -1
- package/src/providers/antigravity.js +222 -34
- package/src/providers/antigravity.ts +220 -33
- package/src/providers/base.d.ts +2 -0
- package/src/providers/pi.js +3 -1
- package/src/providers/pi.ts +4 -2
- package/src/sandbox.js +7 -10
- package/src/smartToolsUse.js +203 -0
- package/src/smartToolsUse.ts +263 -0
- package/src/taskShape.js +7 -7
- package/src/taskShape.ts +7 -7
- package/src/toolPacks.js +5 -5
- package/src/tools/blenderAutomator.js +198 -11
- package/src/tools/documentForge.js +1 -1
- package/src/tools/documentForge.ts +1 -1
- package/src/tui/modelPicker.js +288 -69
- package/src/tui/modelPicker.ts +333 -72
package/src/tui/modelPicker.ts
CHANGED
|
@@ -5,11 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
// @ts-expect-error untyped local TUI dialogs
|
|
7
7
|
import { SelectLayer, InputLayer } from './dialogs.js';
|
|
8
|
+
// @ts-expect-error untyped local TUI theme
|
|
9
|
+
import { paint, bold, dim, GLYPHS } from './theme.js';
|
|
10
|
+
// @ts-expect-error untyped local TUI selectList
|
|
11
|
+
import { fuzzyFilter } from './selectList.js';
|
|
8
12
|
import { loadConfig, saveConfig } from '../config.js';
|
|
9
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
getAvailableProvidersOverview,
|
|
15
|
+
resolveAvailableProvidersOverview,
|
|
16
|
+
type ProviderOverview
|
|
17
|
+
} from '../dynamicCatalogue.js';
|
|
10
18
|
|
|
11
19
|
export interface ModelPickerItemValue {
|
|
12
|
-
type: 'acp' | 'byok';
|
|
20
|
+
type: 'acp' | 'byok' | 'toggle';
|
|
13
21
|
providerId: string;
|
|
14
22
|
modelId: string;
|
|
15
23
|
providerLabel: string;
|
|
@@ -18,6 +26,9 @@ export interface ModelPickerItemValue {
|
|
|
18
26
|
isConfigured: boolean;
|
|
19
27
|
envVar?: string | undefined;
|
|
20
28
|
setupInstruction?: string | undefined;
|
|
29
|
+
isToggle?: boolean | undefined;
|
|
30
|
+
action?: 'expand' | 'collapse' | undefined;
|
|
31
|
+
peerKey?: string | undefined;
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
export interface ModelPickerItem {
|
|
@@ -47,6 +58,12 @@ export interface InteractiveModelPickerOptions {
|
|
|
47
58
|
} | undefined;
|
|
48
59
|
}
|
|
49
60
|
|
|
61
|
+
export interface BuildModelPickerOptions {
|
|
62
|
+
tab?: 'acp' | 'byok' | 'all' | undefined;
|
|
63
|
+
expandedPeers?: Set<string> | undefined;
|
|
64
|
+
maxAcpPerPeer?: number | undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
50
67
|
async function showConfiguringAnimation(providerLabel: string): Promise<void> {
|
|
51
68
|
if (!process.stdout.isTTY) return;
|
|
52
69
|
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
@@ -61,100 +78,341 @@ async function showConfiguringAnimation(providerLabel: string): Promise<void> {
|
|
|
61
78
|
|
|
62
79
|
/**
|
|
63
80
|
* Build items for SelectLayer categorized by ACP peers and BYOK providers.
|
|
81
|
+
*
|
|
82
|
+
* Supports tab filtering ('acp' | 'byok' | 'all') and smart pagination
|
|
83
|
+
* for ACP peers exceeding maxAcpPerPeer (default 10 models).
|
|
64
84
|
*/
|
|
65
85
|
export function buildModelPickerItems(
|
|
66
86
|
config: { provider?: string; model?: string; apiKey?: string; providerKeys?: Record<string, string> },
|
|
67
|
-
overview: ProviderOverview
|
|
87
|
+
overview: ProviderOverview,
|
|
88
|
+
options: BuildModelPickerOptions = {}
|
|
68
89
|
): ModelPickerItem[] {
|
|
69
90
|
const items: ModelPickerItem[] = [];
|
|
70
91
|
const activeProvider = config.provider || '';
|
|
71
92
|
const activeModel = config.model || '';
|
|
93
|
+
const tab = options.tab || 'all';
|
|
94
|
+
const expandedPeers = options.expandedPeers || new Set<string>();
|
|
95
|
+
const maxAcp = typeof options.maxAcpPerPeer === 'number' ? options.maxAcpPerPeer : (tab === 'all' ? Infinity : 10);
|
|
72
96
|
|
|
73
97
|
// 1. ACP Peer Agents & Sovereign Local Engines
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
98
|
+
if (tab === 'all' || tab === 'acp') {
|
|
99
|
+
for (const peer of overview.acp) {
|
|
100
|
+
const isCurrentProvider = activeProvider === peer.providerKey;
|
|
101
|
+
const catTitle = peer.installed
|
|
102
|
+
? `ACP · ${peer.label} (ready)`
|
|
103
|
+
: `ACP · ${peer.label} (not installed)`;
|
|
104
|
+
|
|
105
|
+
if (peer.installed && Array.isArray(peer.models) && peer.models.length > 0) {
|
|
106
|
+
const isExpanded = expandedPeers.has(peer.providerKey) || peer.models.length <= maxAcp;
|
|
107
|
+
const visibleModels = isExpanded ? peer.models : peer.models.slice(0, maxAcp);
|
|
108
|
+
|
|
109
|
+
for (const m of visibleModels) {
|
|
110
|
+
const isCurrent = isCurrentProvider && activeModel === m;
|
|
111
|
+
items.push({
|
|
112
|
+
id: `${peer.providerKey}/${m}`,
|
|
113
|
+
label: m,
|
|
114
|
+
category: catTitle,
|
|
115
|
+
description: isCurrent ? '● active' : 'ready',
|
|
116
|
+
value: {
|
|
117
|
+
type: 'acp',
|
|
118
|
+
providerId: peer.providerKey,
|
|
119
|
+
modelId: m,
|
|
120
|
+
providerLabel: peer.label,
|
|
121
|
+
installed: true,
|
|
122
|
+
isCurrent,
|
|
123
|
+
isConfigured: true,
|
|
124
|
+
setupInstruction: peer.setupInstruction
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Toggle item: Load more / Load less for peers with > maxAcp models
|
|
130
|
+
if (peer.models.length > maxAcp) {
|
|
131
|
+
if (!isExpanded) {
|
|
132
|
+
const remaining = peer.models.length - maxAcp;
|
|
133
|
+
items.push({
|
|
134
|
+
id: `${peer.providerKey}:__load_more__`,
|
|
135
|
+
label: `▶ Load more (${remaining} more models)...`,
|
|
136
|
+
category: catTitle,
|
|
137
|
+
description: 'expand',
|
|
138
|
+
value: {
|
|
139
|
+
type: 'toggle',
|
|
140
|
+
providerId: peer.providerKey,
|
|
141
|
+
modelId: '__load_more__',
|
|
142
|
+
providerLabel: peer.label,
|
|
143
|
+
installed: true,
|
|
144
|
+
isCurrent: false,
|
|
145
|
+
isConfigured: true,
|
|
146
|
+
isToggle: true,
|
|
147
|
+
action: 'expand',
|
|
148
|
+
peerKey: peer.providerKey
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
items.push({
|
|
153
|
+
id: `${peer.providerKey}:__load_less__`,
|
|
154
|
+
label: `▲ Load less (show top ${maxAcp})...`,
|
|
155
|
+
category: catTitle,
|
|
156
|
+
description: 'collapse',
|
|
157
|
+
value: {
|
|
158
|
+
type: 'toggle',
|
|
159
|
+
providerId: peer.providerKey,
|
|
160
|
+
modelId: '__load_less__',
|
|
161
|
+
providerLabel: peer.label,
|
|
162
|
+
installed: true,
|
|
163
|
+
isCurrent: false,
|
|
164
|
+
isConfigured: true,
|
|
165
|
+
isToggle: true,
|
|
166
|
+
action: 'collapse',
|
|
167
|
+
peerKey: peer.providerKey
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
// Uninstalled ACP agent: show entry so user can see it's supported
|
|
83
174
|
items.push({
|
|
84
|
-
id: `${peer.providerKey}
|
|
85
|
-
label:
|
|
175
|
+
id: `${peer.providerKey}:uninstalled`,
|
|
176
|
+
label: peer.label,
|
|
86
177
|
category: catTitle,
|
|
87
|
-
description:
|
|
178
|
+
description: 'not installed — setup needed',
|
|
88
179
|
value: {
|
|
89
180
|
type: 'acp',
|
|
90
181
|
providerId: peer.providerKey,
|
|
91
|
-
modelId:
|
|
182
|
+
modelId: peer.models[0] || peer.id,
|
|
92
183
|
providerLabel: peer.label,
|
|
93
|
-
installed:
|
|
94
|
-
isCurrent,
|
|
95
|
-
isConfigured:
|
|
184
|
+
installed: false,
|
|
185
|
+
isCurrent: false,
|
|
186
|
+
isConfigured: false,
|
|
96
187
|
setupInstruction: peer.setupInstruction
|
|
97
188
|
}
|
|
98
189
|
});
|
|
99
190
|
}
|
|
100
|
-
} else {
|
|
101
|
-
// Uninstalled ACP agent: show entry so user can see it's supported
|
|
102
|
-
items.push({
|
|
103
|
-
id: `${peer.providerKey}:uninstalled`,
|
|
104
|
-
label: peer.label,
|
|
105
|
-
category: catTitle,
|
|
106
|
-
description: 'not installed — setup needed',
|
|
107
|
-
value: {
|
|
108
|
-
type: 'acp',
|
|
109
|
-
providerId: peer.providerKey,
|
|
110
|
-
modelId: peer.models[0] || peer.id,
|
|
111
|
-
providerLabel: peer.label,
|
|
112
|
-
installed: false,
|
|
113
|
-
isCurrent: false,
|
|
114
|
-
isConfigured: false,
|
|
115
|
-
setupInstruction: peer.setupInstruction
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
191
|
}
|
|
119
192
|
}
|
|
120
193
|
|
|
121
194
|
// 2. BYOK Providers (Cloud & Local APIs)
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
195
|
+
if (tab === 'all' || tab === 'byok') {
|
|
196
|
+
for (const p of overview.byok) {
|
|
197
|
+
const isCurrentProvider = activeProvider === p.id || (p.id === 'qwen' && activeProvider === 'dashscope-byok');
|
|
198
|
+
const catTitle = p.id === 'ollama'
|
|
199
|
+
? `BYOK · ${p.label}`
|
|
200
|
+
: `BYOK · ${p.label} ${p.isConfigured ? '(configured)' : '(needs key)'}`;
|
|
201
|
+
|
|
202
|
+
const models = Array.isArray(p.models) && p.models.length > 0 ? p.models : [p.defaultModel];
|
|
203
|
+
for (const m of models) {
|
|
204
|
+
const isCurrent = isCurrentProvider && activeModel === m;
|
|
205
|
+
const desc = isCurrent ? '● active' : (p.id === 'ollama' ? 'local' : (p.isConfigured ? 'configured' : 'needs API key'));
|
|
206
|
+
items.push({
|
|
207
|
+
id: `${p.id}/${m}`,
|
|
208
|
+
label: m,
|
|
209
|
+
category: catTitle,
|
|
210
|
+
description: desc,
|
|
211
|
+
value: {
|
|
212
|
+
type: 'byok',
|
|
213
|
+
providerId: p.id,
|
|
214
|
+
modelId: m,
|
|
215
|
+
providerLabel: p.label,
|
|
216
|
+
installed: true,
|
|
217
|
+
isCurrent,
|
|
218
|
+
isConfigured: p.isConfigured,
|
|
219
|
+
envVar: p.envVar
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
148
223
|
}
|
|
149
224
|
}
|
|
150
225
|
|
|
151
226
|
return items;
|
|
152
227
|
}
|
|
153
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Sovereign Model Picker Layer with dual-tab support (| ACP | BYOK |)
|
|
231
|
+
* and interactive 10-model pagination.
|
|
232
|
+
*/
|
|
233
|
+
export class ModelPickerLayer extends SelectLayer {
|
|
234
|
+
public activeTab: 'acp' | 'byok';
|
|
235
|
+
public config: Record<string, any>;
|
|
236
|
+
public overview: ProviderOverview;
|
|
237
|
+
public expandedPeers: Set<string>;
|
|
238
|
+
public promptHost: any;
|
|
239
|
+
public allItems: ModelPickerItem[];
|
|
240
|
+
public declare list: any;
|
|
241
|
+
public declare cursor: { x: number; y: number };
|
|
242
|
+
public declare settled: boolean;
|
|
243
|
+
public declare height: number;
|
|
244
|
+
public declare onPick: ((item: any) => any) | null;
|
|
245
|
+
|
|
246
|
+
constructor(options: {
|
|
247
|
+
config: Record<string, any>;
|
|
248
|
+
overview: ProviderOverview;
|
|
249
|
+
promptHost?: any;
|
|
250
|
+
onPick: (item: ModelPickerItem | null) => void;
|
|
251
|
+
}) {
|
|
252
|
+
const activeProvider = (options.config.provider || '').toLowerCase().trim();
|
|
253
|
+
const initialTab: 'acp' | 'byok' =
|
|
254
|
+
activeProvider === 'antigravity' ||
|
|
255
|
+
activeProvider === 'agy' ||
|
|
256
|
+
activeProvider === 'acp' ||
|
|
257
|
+
activeProvider.startsWith('acp/')
|
|
258
|
+
? 'acp'
|
|
259
|
+
: 'byok';
|
|
260
|
+
|
|
261
|
+
const expandedPeers = new Set<string>();
|
|
262
|
+
const allItems = buildModelPickerItems(options.config, options.overview, { tab: 'all', maxAcpPerPeer: Infinity });
|
|
263
|
+
|
|
264
|
+
super({
|
|
265
|
+
title: 'Select Model',
|
|
266
|
+
placeholder: 'type to filter (e.g. gemini, sonnet, opencode)…',
|
|
267
|
+
emptyText: 'No models matched your search in this tab',
|
|
268
|
+
items: allItems,
|
|
269
|
+
width: 78,
|
|
270
|
+
height: 22,
|
|
271
|
+
footer: 'tab / ← → switch tab • enter select • esc close',
|
|
272
|
+
onPick: options.onPick
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
this.config = options.config;
|
|
276
|
+
this.overview = options.overview;
|
|
277
|
+
this.promptHost = options.promptHost;
|
|
278
|
+
this.activeTab = initialTab;
|
|
279
|
+
this.expandedPeers = expandedPeers;
|
|
280
|
+
this.allItems = allItems;
|
|
281
|
+
|
|
282
|
+
// Custom refilter ensuring list renders only activeTab while keeping allItems intact
|
|
283
|
+
const self = this;
|
|
284
|
+
this.list.refilter = function() {
|
|
285
|
+
const isSearching = Boolean(this.query && this.query.trim());
|
|
286
|
+
const tabItems = buildModelPickerItems(self.config, self.overview, {
|
|
287
|
+
tab: self.activeTab,
|
|
288
|
+
expandedPeers: self.expandedPeers,
|
|
289
|
+
maxAcpPerPeer: isSearching ? Infinity : 10
|
|
290
|
+
});
|
|
291
|
+
this.filtered = fuzzyFilter(tabItems, this.query);
|
|
292
|
+
this.selected = Math.min(this.selected || 0, Math.max(0, this.filtered.length - 1));
|
|
293
|
+
this.offset = 0;
|
|
294
|
+
return this;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// Initialize list with active tab items
|
|
298
|
+
this.list.refilter();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
updateOverview(freshOverview: ProviderOverview): void {
|
|
302
|
+
this.overview = freshOverview;
|
|
303
|
+
this.allItems = buildModelPickerItems(this.config, this.overview, { tab: 'all', maxAcpPerPeer: Infinity });
|
|
304
|
+
this.list.all = this.allItems;
|
|
305
|
+
this.list.refilter();
|
|
306
|
+
if (this.promptHost && typeof this.promptHost.scheduleDraw === 'function') {
|
|
307
|
+
this.promptHost.scheduleDraw();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
switchTab(tab: 'acp' | 'byok'): void {
|
|
312
|
+
if (this.activeTab === tab) return;
|
|
313
|
+
this.activeTab = tab;
|
|
314
|
+
this.list.refilter();
|
|
315
|
+
this.list.selected = 0;
|
|
316
|
+
this.list.offset = 0;
|
|
317
|
+
if (this.promptHost && typeof this.promptHost.scheduleDraw === 'function') {
|
|
318
|
+
this.promptHost.scheduleDraw();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
togglePeerExpand(peerKey: string): void {
|
|
323
|
+
if (this.expandedPeers.has(peerKey)) {
|
|
324
|
+
this.expandedPeers.delete(peerKey);
|
|
325
|
+
} else {
|
|
326
|
+
this.expandedPeers.add(peerKey);
|
|
327
|
+
}
|
|
328
|
+
const currentId = this.list.current?.id;
|
|
329
|
+
this.list.refilter();
|
|
330
|
+
if (currentId && Array.isArray(this.list.filtered)) {
|
|
331
|
+
const idx = this.list.filtered.findIndex((entry: any) => entry?.item?.id === currentId || entry?.item?.value?.peerKey === peerKey);
|
|
332
|
+
if (idx >= 0) this.list.selected = idx;
|
|
333
|
+
}
|
|
334
|
+
if (this.promptHost && typeof this.promptHost.scheduleDraw === 'function') {
|
|
335
|
+
this.promptHost.scheduleDraw();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
preferredHeight(): number {
|
|
340
|
+
const categories = new Set(this.list.filtered.map((entry: any) => entry.item?.category).filter(Boolean));
|
|
341
|
+
return 2 + 2 + this.list.filtered.length + categories.size + 2;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
body(width: number, height: number): string[] {
|
|
345
|
+
const tabACP = this.activeTab === 'acp' ? paint('accent', bold('● ACP')) : dim('ACP');
|
|
346
|
+
const tabBYOK = this.activeTab === 'byok' ? paint('accent', bold('● BYOK')) : dim('BYOK');
|
|
347
|
+
const tabBar = ` | ${tabACP} | ${tabBYOK} | ${dim('(Tab / ← → switch tab)')}`;
|
|
348
|
+
const separator = paint('rule', GLYPHS.hLine.repeat(Math.max(4, width)));
|
|
349
|
+
|
|
350
|
+
const listHeight = Math.max(1, height - 2);
|
|
351
|
+
const { rows } = this.list.render(width, listHeight);
|
|
352
|
+
|
|
353
|
+
this.cursor = { x: this.list.cursorColumn(), y: 2 };
|
|
354
|
+
return [tabBar, separator, ...rows];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
key(event: any): string | null {
|
|
358
|
+
if (!event) return null;
|
|
359
|
+
|
|
360
|
+
// 1. Tab switching via Tab, Left/Right arrows, or PgLeft/PgRight mappings
|
|
361
|
+
if (event.name === 'tab') {
|
|
362
|
+
this.switchTab(this.activeTab === 'acp' ? 'byok' : 'acp');
|
|
363
|
+
return 'handled';
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (event.name === 'left' && this.activeTab === 'byok') {
|
|
367
|
+
if (!this.list.query || event.alt || event.ctrl || event.meta) {
|
|
368
|
+
this.switchTab('acp');
|
|
369
|
+
return 'handled';
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (event.name === 'right' && this.activeTab === 'acp') {
|
|
373
|
+
if (!this.list.query || event.alt || event.ctrl || event.meta) {
|
|
374
|
+
this.switchTab('byok');
|
|
375
|
+
return 'handled';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (event.name === '[' || (event.name === 'pageup' && (event.shift || event.alt || event.ctrl))) {
|
|
380
|
+
this.switchTab('acp');
|
|
381
|
+
return 'handled';
|
|
382
|
+
}
|
|
383
|
+
if (event.name === ']' || (event.name === 'pagedown' && (event.shift || event.alt || event.ctrl))) {
|
|
384
|
+
this.switchTab('byok');
|
|
385
|
+
return 'handled';
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 2. Delegate to SelectList for navigation / query typing
|
|
389
|
+
const visibleRows = this.list.lastItemRows || Math.max(1, this.height - 7);
|
|
390
|
+
const action = this.list.handleKey(event, visibleRows);
|
|
391
|
+
|
|
392
|
+
if (action === 'select') {
|
|
393
|
+
const item = this.list.current;
|
|
394
|
+
if (item?.value?.isToggle && item?.value?.peerKey) {
|
|
395
|
+
this.togglePeerExpand(item.value.peerKey);
|
|
396
|
+
return 'handled';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
this.settled = true;
|
|
400
|
+
const result = this.onPick ? this.onPick(item) : null;
|
|
401
|
+
if (result === 'keep') this.settled = false;
|
|
402
|
+
return result === 'keep' ? 'handled' : 'close';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (action === 'cancel') return 'close';
|
|
406
|
+
return action ? 'handled' : null;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
154
410
|
/**
|
|
155
411
|
* Run interactive model picker in the provided TUI prompt.
|
|
156
412
|
*
|
|
157
413
|
* Automatically handles:
|
|
414
|
+
* - Dual-tab navigation (| ACP | BYOK |).
|
|
415
|
+
* - Smart 10-model pagination per ACP peer with in-place Load more / Load less.
|
|
158
416
|
* - Direct selection of ACP models without prompting for an API key.
|
|
159
417
|
* - Direct selection of configured BYOK models without prompting for an API key.
|
|
160
418
|
* - InputLayer modal prompt for API key when selecting an unconfigured BYOK model,
|
|
@@ -172,19 +430,22 @@ export async function runInteractiveModelPicker(
|
|
|
172
430
|
|
|
173
431
|
const config = store.loadConfig();
|
|
174
432
|
const overview = getAvailableProvidersOverview(config);
|
|
175
|
-
const items = buildModelPickerItems(config, overview);
|
|
176
433
|
|
|
177
434
|
const picked = await new Promise<ModelPickerItem | null>((resolve) => {
|
|
178
|
-
const layer = new
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
items,
|
|
183
|
-
width: 76,
|
|
184
|
-
height: 20,
|
|
435
|
+
const layer = new ModelPickerLayer({
|
|
436
|
+
config,
|
|
437
|
+
overview,
|
|
438
|
+
promptHost: prompt,
|
|
185
439
|
onPick: resolve
|
|
186
440
|
});
|
|
187
441
|
prompt.openLayer(layer);
|
|
442
|
+
|
|
443
|
+
if (!process.env.NODE_TEST_CONTEXT) {
|
|
444
|
+
void resolveAvailableProvidersOverview(config).then((freshOverview) => {
|
|
445
|
+
if (layer.settled) return;
|
|
446
|
+
layer.updateOverview(freshOverview);
|
|
447
|
+
}).catch(() => {});
|
|
448
|
+
}
|
|
188
449
|
});
|
|
189
450
|
|
|
190
451
|
const notifyPrompt = (providerId: string, modelId: string) => {
|
|
@@ -196,7 +457,7 @@ export async function runInteractiveModelPicker(
|
|
|
196
457
|
}
|
|
197
458
|
};
|
|
198
459
|
|
|
199
|
-
if (!picked || !picked.value) {
|
|
460
|
+
if (!picked || !picked.value || picked.value.isToggle) {
|
|
200
461
|
return 'Cancelled. Model was not changed.';
|
|
201
462
|
}
|
|
202
463
|
|