@zergai/ztc 0.18.2-dev.202611110225 → 0.19.0-beta.1
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/README.md +6 -3
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/agent/commands/index.js +2 -1
- package/dist/agent/commands/model.js +19 -11
- package/dist/agent/commands/models.js +21 -4
- package/dist/agent/commands/provider.d.ts +22 -0
- package/dist/agent/commands/provider.js +285 -0
- package/dist/agent/commands/provider_choices.d.ts +12 -0
- package/dist/agent/commands/provider_choices.js +15 -0
- package/dist/agent/commands/provider_selection.d.ts +18 -0
- package/dist/agent/commands/provider_selection.js +77 -13
- package/dist/agent/commands/runtime_model.d.ts +16 -1
- package/dist/agent/commands/runtime_model.js +24 -3
- package/dist/agent/commands/settings.js +39 -14
- package/dist/agent/commands/types.d.ts +25 -1
- package/dist/app/command_context.js +31 -15
- package/dist/app/model_catalog_cache.d.ts +5 -0
- package/dist/app/model_catalog_cache.js +13 -0
- package/dist/app/runtime_choices.d.ts +38 -0
- package/dist/app/runtime_choices.js +66 -0
- package/dist/app/selection_completion.d.ts +5 -0
- package/dist/app/selection_completion.js +35 -2
- package/dist/cli_ratatui.d.ts +26 -6
- package/dist/cli_ratatui.js +98 -43
- package/dist/config/provider_models.d.ts +22 -0
- package/dist/config/provider_models.js +83 -0
- package/dist/config.d.ts +22 -1
- package/dist/config.js +64 -5
- package/dist/headless.js +4 -1
- package/dist/panes/ztc_launch.js +3 -2
- package/dist/zlm-embed.mjs +69 -18
- package/package.json +24 -8
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
1
2
|
import { getDefaultModelForProvider } from '../../config/defaults.js';
|
|
2
3
|
import { isBuildableResolvedConfig } from './config.js';
|
|
3
4
|
import { canAskForCredential, promptForMissingDirectKey, providerLabel } from './direct_credential_prompt.js';
|
|
4
|
-
import { applyRuntimeModelSelection, getEffectiveModel } from './runtime_model.js';
|
|
5
|
-
import { canRouteThroughRouter, canonicalProvider, canonicalRoute, DIRECT_PROVIDER_CHOICES, describeDirectProvider, isRouterOnlyProvider, modelRouteStatus, } from './provider_choices.js';
|
|
5
|
+
import { applyRuntimeModelSelection, getEffectiveModel, paneRoute } from './runtime_model.js';
|
|
6
|
+
import { canRouteThroughRouter, canonicalProvider, canonicalRoute, DIRECT_PROVIDER_CHOICES, describeDirectProvider, isRouterOnlyProvider, modelRouteStatus, providerChoiceId, } from './provider_choices.js';
|
|
7
|
+
import { rememberedModel, rememberProviderModel } from '../../config/provider_models.js';
|
|
6
8
|
import { resolveModelAndProvider } from '../../panes/model_catalog.js';
|
|
7
9
|
import { getDefaultModel } from '../../utils/models.js';
|
|
8
10
|
import { resolveRouterModel, RouterCatalogAuthenticationError, routerModelForSwitch } from '../../utils/router_catalog.js';
|
|
@@ -10,6 +12,14 @@ import { ROUTER_MODELS_NEED_LOGIN, ZERGAI_LOGIN_BENEFITS } from '../../onboardin
|
|
|
10
12
|
import { runAuthAction } from './auth.js';
|
|
11
13
|
import { offerReasoningPicker } from './reasoning_picker.js';
|
|
12
14
|
import { isRetiredModel, isRetiredProvider, retiredModelMessage, retiredProviderMessage } from '../../config/retired_routes.js';
|
|
15
|
+
/**
|
|
16
|
+
* Where this configuration keeps its profile: the models remembered per provider live beside its config.json. A
|
|
17
|
+
* configuration without a file (a renderer's stand-in) remembers nothing.
|
|
18
|
+
*/
|
|
19
|
+
export function profileDirectory(ctx) {
|
|
20
|
+
const path = ctx.config.getConfigPath?.();
|
|
21
|
+
return path ? dirname(path) : undefined;
|
|
22
|
+
}
|
|
13
23
|
/** Local providers with their credential state, configured ones first. */
|
|
14
24
|
export function formatDirectProviders(readyProviders) {
|
|
15
25
|
const ready = new Set(readyProviders);
|
|
@@ -20,9 +30,32 @@ export function formatDirectProviders(readyProviders) {
|
|
|
20
30
|
...rows.map(row => ` ${row.id.padEnd(width)} ${describeDirectProvider(row.id, ready.has(row.id))}`),
|
|
21
31
|
'',
|
|
22
32
|
'Your Claude subscription runs in Claude Code itself: open it in a pane with /claude.',
|
|
33
|
+
'Zerg Router providers: /provider.',
|
|
23
34
|
'Use /model direct <provider> [model].',
|
|
24
35
|
].join('\n');
|
|
25
36
|
}
|
|
37
|
+
/** `/model refresh` and `/provider refresh`: Zerg Router's catalog again, without changing the selection. */
|
|
38
|
+
export async function refreshRouterModels(ctx) {
|
|
39
|
+
if (!ctx.models.catalog) {
|
|
40
|
+
ctx.addMessage({ role: 'system', content: 'Zerg Router\'s list can\'t be refreshed here.' });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const catalog = await ctx.models.catalog(undefined, { refresh: true });
|
|
45
|
+
ctx.addMessage({ role: 'system', content: `${catalog.authRequired ? 'Router authentication rejected. Run ztc auth login again. Showing cached catalog' : catalog.cached ? 'Router unavailable. Showing cached catalog' : 'Router catalog refreshed'}: ${catalog.models.length} models. Active responses continue with their current selection.` });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
ctx.addMessage({ role: 'system', content: `Could not refresh Router models: ${error.message}` });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether `model` is still one `provider` offers on your own key or login: the models discovery last listed for it
|
|
53
|
+
* include it, or none were listed yet, so nothing says it is gone.
|
|
54
|
+
*/
|
|
55
|
+
export async function stillListed(ctx, provider, model) {
|
|
56
|
+
const listed = await ctx.models.discovered?.(provider).catch(() => undefined);
|
|
57
|
+
return !listed || listed.includes(model);
|
|
58
|
+
}
|
|
26
59
|
/** `/model direct ...`: the local route, offering only providers this machine can call. */
|
|
27
60
|
async function selectDirectRoute(values, ctx, options) {
|
|
28
61
|
if (values.length === 1) {
|
|
@@ -116,12 +149,21 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
116
149
|
return;
|
|
117
150
|
}
|
|
118
151
|
const authMode = routed ? 'zrouter' : 'direct';
|
|
152
|
+
const choiceId = providerChoiceId(provider, routed ? 'zergrouter' : 'direct');
|
|
119
153
|
const defaultModel = provider === 'inception' ? getDefaultModel(provider) : getDefaultModelForProvider(provider);
|
|
120
154
|
const explicitModel = values[choice === 'zergrouter' ? 2 : 1];
|
|
155
|
+
// Another provider lands on the model last used with it; the one in use keeps its model, and a custom endpoint
|
|
156
|
+
// names its own. It must still be offered, through Zerg Router (below) or on your own key; a retired id is never
|
|
157
|
+
// used again.
|
|
158
|
+
const profile = profileDirectory(ctx);
|
|
159
|
+
const recalled = !explicitModel && provider !== current && provider !== 'openai_compatible' && profile
|
|
160
|
+
? rememberedModel(choiceId, profile) : undefined;
|
|
161
|
+
const remembered = recalled && !isRetiredModel(recalled) ? recalled : undefined;
|
|
162
|
+
const keptDirect = !routed && remembered && await stillListed(ctx, provider, remembered) ? remembered : undefined;
|
|
121
163
|
let model = explicitModel || (provider === current ? getEffectiveModel(ctx)
|
|
122
164
|
: provider === 'openai_compatible'
|
|
123
165
|
? (ctx.config.getOpenAICompatibleSettings?.().defaultModel || getDefaultModelForProvider(provider))
|
|
124
|
-
: resolveModelAndProvider(defaultModel, provider).model);
|
|
166
|
+
: keptDirect || resolveModelAndProvider(defaultModel, provider).model);
|
|
125
167
|
try {
|
|
126
168
|
if (routed && ctx.models.catalog) {
|
|
127
169
|
const catalog = await ctx.models.catalog(undefined, { refresh: !explicitModel }).catch(error => {
|
|
@@ -132,8 +174,11 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
132
174
|
if (catalog?.authRequired)
|
|
133
175
|
throw new Error('Router authentication rejected. Run /auth login and retry.');
|
|
134
176
|
if (catalog?.version === 1) {
|
|
135
|
-
|
|
136
|
-
|
|
177
|
+
const kept = remembered ? resolveRouterModel(catalog, provider, remembered) : undefined;
|
|
178
|
+
if (!explicitModel) {
|
|
179
|
+
model = (kept?.capabilities?.chat && kept.available !== false ? kept
|
|
180
|
+
: routerModelForSwitch(catalog, provider, current, model))?.id ?? '';
|
|
181
|
+
}
|
|
137
182
|
const selected = resolveRouterModel(catalog, provider, model);
|
|
138
183
|
if (!selected?.capabilities?.chat)
|
|
139
184
|
throw new Error('Model is not in the Router catalog. Run /model zergrouter to choose an available model.');
|
|
@@ -163,17 +208,36 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
163
208
|
// CLI overrides can still expose the previous provider/model until hot-swap.
|
|
164
209
|
ctx.config.set('model', model);
|
|
165
210
|
await ctx.config.save();
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
211
|
+
// A choice that sets the default is remembered for the next switch back to this provider; one for this session
|
|
212
|
+
// alone is not.
|
|
213
|
+
if (profile && ctx.config.getConfigScope?.() !== 'session') {
|
|
214
|
+
await rememberProviderModel(choiceId, model, { directory: profile }).catch(() => { });
|
|
215
|
+
}
|
|
216
|
+
// A rebuild that failed left this pane on the route it ran on; the selection is saved all the same.
|
|
217
|
+
const kept = applyRuntimeModelSelection(ctx, provider, model, authMode) ? undefined : paneRoute(ctx);
|
|
218
|
+
const applied = { provider, model, routed };
|
|
219
|
+
ctx.addMessage({ role: 'system', content: options.confirm ? options.confirm(applied, kept) : modelConfirmation(ctx, applied, kept) });
|
|
174
220
|
if (options.offerReasoning)
|
|
175
221
|
offerReasoningPicker(ctx);
|
|
176
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* /model's confirmation of a saved selection. One this pane couldn't rebuild on says the route it keeps: the
|
|
225
|
+
* selection is the default for new panes, or, chosen for this session alone, nothing changed.
|
|
226
|
+
*/
|
|
227
|
+
function modelConfirmation(ctx, applied, kept) {
|
|
228
|
+
const scope = ctx.config.getConfigScope?.() || 'global';
|
|
229
|
+
const keeps = kept && `this pane keeps ${kept.model.startsWith(`${kept.provider}/`) ? kept.model : `${kept.provider}/${kept.model}`}`
|
|
230
|
+
+ ` (route: ${kept.routed ? 'zergrouter' : 'direct'})`;
|
|
231
|
+
if (keeps && scope === 'session')
|
|
232
|
+
return `Not applied: ${keeps}.`;
|
|
233
|
+
return [
|
|
234
|
+
keeps ? `Saved for new panes; ${keeps}` : '✓ Model selected',
|
|
235
|
+
`provider: ${applied.provider}`,
|
|
236
|
+
`model: ${applied.model}`,
|
|
237
|
+
`route: ${applied.routed ? 'zergrouter' : 'direct'}`,
|
|
238
|
+
`scope: ${scope}`,
|
|
239
|
+
].join('\n');
|
|
240
|
+
}
|
|
177
241
|
/** Whether the current selection can reach a model now. */
|
|
178
242
|
export function currentRouteReady(ctx) {
|
|
179
243
|
try {
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
import type { ZTCAuthMode } from '../../config/types.js';
|
|
1
2
|
import type { CommandContext } from './types.js';
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Run the selection just saved in this process. `authMode` is the route the
|
|
5
|
+
* selection names, when it names one; it moves with the provider and model.
|
|
6
|
+
* False when this pane kept the route it ran on, because its rebuild on the
|
|
7
|
+
* selection failed (the renderer says why); the selection stays saved.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyRuntimeModelSelection(ctx: CommandContext, provider: string, model: string, authMode?: ZTCAuthMode): boolean;
|
|
10
|
+
/** What a pane runs on: the provider and model resolved for it, and whether they go through Zerg Router. */
|
|
11
|
+
export interface PaneRoute {
|
|
12
|
+
provider: string;
|
|
13
|
+
model: string;
|
|
14
|
+
routed: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** The route this pane runs on: its renderer's, where that can differ from the configuration's (getRuntimeRoute). */
|
|
17
|
+
export declare function paneRoute(ctx: CommandContext): PaneRoute;
|
|
3
18
|
export declare function getEffectiveModel(ctx: CommandContext): string;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { normalizeProviderId } from '../backends/provider_ids.js';
|
|
2
|
+
import { isRouterOnlyProvider } from './provider_choices.js';
|
|
3
|
+
/**
|
|
4
|
+
* Run the selection just saved in this process. `authMode` is the route the
|
|
5
|
+
* selection names, when it names one; it moves with the provider and model.
|
|
6
|
+
* False when this pane kept the route it ran on, because its rebuild on the
|
|
7
|
+
* selection failed (the renderer says why); the selection stays saved.
|
|
8
|
+
*/
|
|
9
|
+
export function applyRuntimeModelSelection(ctx, provider, model, authMode) {
|
|
2
10
|
if (ctx.setRuntimeModelOverride) {
|
|
3
|
-
ctx.setRuntimeModelOverride(provider, model);
|
|
4
|
-
return;
|
|
11
|
+
return ctx.setRuntimeModelOverride(provider, model, authMode) !== false;
|
|
5
12
|
}
|
|
6
13
|
ctx.reloadAgent();
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
/** The route this pane runs on: its renderer's, where that can differ from the configuration's (getRuntimeRoute). */
|
|
17
|
+
export function paneRoute(ctx) {
|
|
18
|
+
const live = ctx.getRuntimeRoute?.();
|
|
19
|
+
try {
|
|
20
|
+
const llm = ctx.config.resolveLLMBackendConfig(live ? { provider: live.provider, model: live.model } : {});
|
|
21
|
+
return { provider: llm.provider, model: llm.model, routed: llm.useProxy || isRouterOnlyProvider(llm.provider) };
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
const provider = normalizeProviderId(live?.provider ?? ctx.config.getProvider());
|
|
25
|
+
return { provider, model: live?.model ?? getEffectiveModel(ctx),
|
|
26
|
+
routed: ctx.config.getAuthMode?.() === 'zrouter' || isRouterOnlyProvider(provider) };
|
|
27
|
+
}
|
|
7
28
|
}
|
|
8
29
|
export function getEffectiveModel(ctx) {
|
|
9
30
|
return ctx.config.getModel?.() || ctx.config.get().model;
|
|
@@ -16,7 +16,7 @@ import { CODEX_REASONING_EFFORTS } from '../../config/types.js';
|
|
|
16
16
|
import { customPaneOptions, storedCustomPaneOptions, withCustomPaneOptions, } from '../../config/panes.js';
|
|
17
17
|
import { getMcpServerStatuses } from '../../mcp/registry.js';
|
|
18
18
|
import { claudeBadgesOn } from '../../panes/claude_notifications.js';
|
|
19
|
-
import { CLAUDE_SUBSCRIPTION_POLICY, isRetiredProvider, retiredProviderMessage } from '../../config/retired_routes.js';
|
|
19
|
+
import { CLAUDE_SUBSCRIPTION_POLICY, isRetiredModel, isRetiredProvider, retiredProviderMessage } from '../../config/retired_routes.js';
|
|
20
20
|
import { subsCommand } from './subs.js';
|
|
21
21
|
import { modelForProviderSwitch } from './provider_model_defaults.js';
|
|
22
22
|
import { normalizeProviderId } from '../backends/provider_ids.js';
|
|
@@ -24,8 +24,9 @@ import { applyRuntimeModelSelection, getEffectiveModel } from './runtime_model.j
|
|
|
24
24
|
import { activeReasoning } from './reasoning_settings.js';
|
|
25
25
|
import { isBuildableResolvedConfig, unbuildableSelectionMessage } from './config.js';
|
|
26
26
|
import { hasRemovableKey, manageApiKey, promptForMissingDirectKey, removeApiKey, } from './direct_credential_prompt.js';
|
|
27
|
-
import { offerKeyedProviderSwitch } from './provider_selection.js';
|
|
28
|
-
import { API_KEY_PROVIDER_CHOICES, DIRECT_PROVIDER_CHOICES, PROVIDER_CHOICES, canonicalProvider, describeKeySource, isLocalSubscription, isRouterOnlyProvider, modelRouteStatus, } from './provider_choices.js';
|
|
27
|
+
import { offerKeyedProviderSwitch, profileDirectory, stillListed } from './provider_selection.js';
|
|
28
|
+
import { API_KEY_PROVIDER_CHOICES, DIRECT_PROVIDER_CHOICES, PROVIDER_CHOICES, ROUTER_CHOICE_PREFIX, canonicalProvider, describeKeySource, isLocalSubscription, isRouterOnlyProvider, modelRouteStatus, providerChoiceId, } from './provider_choices.js';
|
|
29
|
+
import { rememberedModel, rememberProviderModel } from '../../config/provider_models.js';
|
|
29
30
|
import { describeActiveRoute, describeConnection, describeKeyRow } from './credential_status.js';
|
|
30
31
|
import { runOpenAICompatibleWizard } from './openai_compat_wizard.js';
|
|
31
32
|
import { ZERGAI_LOGIN_BENEFITS, ZERGAI_LOGIN_PITCH } from '../../onboarding/zergai_login.js';
|
|
@@ -84,8 +85,6 @@ const CATEGORY_ALIASES = {
|
|
|
84
85
|
auth: CONNECTION, zergai: CONNECTION, connect: CONNECTION,
|
|
85
86
|
accounts: PROFILE, account: PROFILE, subscriptions: PROFILE,
|
|
86
87
|
};
|
|
87
|
-
/** A Provider row choice that runs through Zerg Router: `zergrouter:<provider>`. */
|
|
88
|
-
const ROUTER_CHOICE_PREFIX = 'zergrouter:';
|
|
89
88
|
/** The ZergAI row's help: what the login offers. */
|
|
90
89
|
const ZERGAI_LOGIN_HELP = [
|
|
91
90
|
`${ZERGAI_LOGIN_PITCH}. Enter opens the login; its code shows in the transcript.`,
|
|
@@ -1228,7 +1227,7 @@ function openCustomPaneManager(ctx, reopen) {
|
|
|
1228
1227
|
};
|
|
1229
1228
|
showList();
|
|
1230
1229
|
}
|
|
1231
|
-
function applySettingChange(ctx, setting, value) {
|
|
1230
|
+
function applySettingChange(ctx, setting, value, selection) {
|
|
1232
1231
|
if (setting.startsWith('execution_')) {
|
|
1233
1232
|
const key = setting.slice('execution_'.length);
|
|
1234
1233
|
const current = resolveExecutionSettings(ctx.config.get().execution);
|
|
@@ -1245,7 +1244,8 @@ function applySettingChange(ctx, setting, value) {
|
|
|
1245
1244
|
case 'provider': {
|
|
1246
1245
|
// The route is part of the choice: a local provider never runs through
|
|
1247
1246
|
// Zerg Router because routing happened to be automatic.
|
|
1248
|
-
|
|
1247
|
+
if (!selection)
|
|
1248
|
+
throw new Error('A provider choice is planned before it is applied.');
|
|
1249
1249
|
ctx.config.setProvider(selection.provider);
|
|
1250
1250
|
ctx.config.set('model', selection.model);
|
|
1251
1251
|
if (selection.authMode)
|
|
@@ -1899,8 +1899,19 @@ function applySettingChange(ctx, setting, value) {
|
|
|
1899
1899
|
}
|
|
1900
1900
|
/** Rows that choose what the agent runs on. */
|
|
1901
1901
|
const MODEL_SELECTION_SETTINGS = new Set(['provider', 'model']);
|
|
1902
|
+
/** The route a saved selection runs on: the one it names, else the route in use. */
|
|
1903
|
+
function selectionRoute(ctx, selection) {
|
|
1904
|
+
if (selection.authMode)
|
|
1905
|
+
return selection.authMode === 'zrouter' ? 'zergrouter' : 'direct';
|
|
1906
|
+
try {
|
|
1907
|
+
return ctx.config.resolveLLMBackendConfig().useProxy ? 'zergrouter' : 'direct';
|
|
1908
|
+
}
|
|
1909
|
+
catch {
|
|
1910
|
+
return ctx.config.getAuthMode?.() === 'zrouter' ? 'zergrouter' : 'direct';
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1902
1913
|
/** The provider, model and route a provider or model row selects. */
|
|
1903
|
-
function plannedModelSelection(ctx, setting, value) {
|
|
1914
|
+
async function plannedModelSelection(ctx, setting, value) {
|
|
1904
1915
|
const current = ctx.config.getProvider();
|
|
1905
1916
|
if (setting === 'model')
|
|
1906
1917
|
return { provider: current, model: value };
|
|
@@ -1908,10 +1919,18 @@ function plannedModelSelection(ctx, setting, value) {
|
|
|
1908
1919
|
if (isRetiredProvider(choice))
|
|
1909
1920
|
throw new Error(retiredProviderMessage(choice, current));
|
|
1910
1921
|
const provider = canonicalProvider(choice) ?? choice;
|
|
1911
|
-
|
|
1922
|
+
const routed = value.startsWith(ROUTER_CHOICE_PREFIX) || isRouterOnlyProvider(provider);
|
|
1923
|
+
// Another provider lands on the model last used with it, while it is still offered.
|
|
1924
|
+
const profile = profileDirectory(ctx);
|
|
1925
|
+
const recalled = provider !== current && provider !== 'openai_compatible' && profile
|
|
1926
|
+
? rememberedModel(providerChoiceId(provider, routed ? 'zergrouter' : 'direct'), profile) : undefined;
|
|
1927
|
+
const remembered = recalled && !isRetiredModel(recalled) ? recalled : undefined;
|
|
1928
|
+
if (routed) {
|
|
1912
1929
|
const catalog = ctx.config.getRouterCatalog?.();
|
|
1913
1930
|
if (catalog?.version === 1) {
|
|
1914
|
-
const
|
|
1931
|
+
const kept = remembered ? resolveRouterModel(catalog, provider, remembered) : undefined;
|
|
1932
|
+
const selected = kept?.capabilities?.chat && kept.available !== false ? kept
|
|
1933
|
+
: routerModelForSwitch(catalog, provider, current, getEffectiveModel(ctx));
|
|
1915
1934
|
if (!selected)
|
|
1916
1935
|
throw new Error(`${providerChoiceLabel(provider)} is not in the Zerg Router catalog. Keeping the current selection.`);
|
|
1917
1936
|
return { provider, model: selected.id, authMode: 'zrouter',
|
|
@@ -1919,7 +1938,8 @@ function plannedModelSelection(ctx, setting, value) {
|
|
|
1919
1938
|
}
|
|
1920
1939
|
return { provider, model: modelForProviderSwitch(provider, current, getEffectiveModel(ctx)), authMode: 'zrouter' };
|
|
1921
1940
|
}
|
|
1922
|
-
|
|
1941
|
+
const kept = remembered && await stillListed(ctx, provider, remembered) ? remembered : undefined;
|
|
1942
|
+
return { provider, model: kept ?? modelForProviderSwitch(provider, current, getEffectiveModel(ctx)), authMode: 'direct' };
|
|
1923
1943
|
}
|
|
1924
1944
|
/**
|
|
1925
1945
|
* Check a provider or model choice before anything is saved. A direct
|
|
@@ -2123,7 +2143,7 @@ async function openSettings(ctx, open = {}) {
|
|
|
2123
2143
|
}
|
|
2124
2144
|
// Planned before anything is saved: once saved, the live selection would
|
|
2125
2145
|
// still report the previous model.
|
|
2126
|
-
const selection = MODEL_SELECTION_SETTINGS.has(setting) ? plannedModelSelection(ctx, setting, value) : undefined;
|
|
2146
|
+
const selection = MODEL_SELECTION_SETTINGS.has(setting) ? await plannedModelSelection(ctx, setting, value) : undefined;
|
|
2127
2147
|
// The panel closes for a key prompt; it comes back on this row afterwards.
|
|
2128
2148
|
const category = categories.find(entry => entry.settings.some(row => row.name === setting))?.name;
|
|
2129
2149
|
const reopen = (notice) => openSettings(ctx, { category, setting, notice });
|
|
@@ -2139,8 +2159,13 @@ async function openSettings(ctx, open = {}) {
|
|
|
2139
2159
|
if (setting === 'workflowsEnabled' && value === 'false') {
|
|
2140
2160
|
await shutdownAndClearWorkflowRegistry(5000);
|
|
2141
2161
|
}
|
|
2142
|
-
applySettingChange(ctx, setting, value);
|
|
2162
|
+
applySettingChange(ctx, setting, value, selection);
|
|
2143
2163
|
await ctx.config.save();
|
|
2164
|
+
// A provider or model the default now runs on is remembered for the next switch back to that provider.
|
|
2165
|
+
const profile = profileDirectory(ctx);
|
|
2166
|
+
if (selection && profile && ctx.config.getConfigScope?.() !== 'session') {
|
|
2167
|
+
await rememberProviderModel(providerChoiceId(selection.provider, selectionRoute(ctx, selection)), selection.model, { directory: profile }).catch(() => { });
|
|
2168
|
+
}
|
|
2144
2169
|
if (setting === 'skillsEnabled' || setting === 'skillsRoots' || setting === 'skillsDisabled') {
|
|
2145
2170
|
invalidateSkillsCache();
|
|
2146
2171
|
await preloadSkillsManifest();
|
|
@@ -2149,7 +2174,7 @@ async function openSettings(ctx, open = {}) {
|
|
|
2149
2174
|
ctx.addMessage({ role: 'system', content: selection.warning });
|
|
2150
2175
|
try {
|
|
2151
2176
|
if (selection) {
|
|
2152
|
-
applyRuntimeModelSelection(ctx, selection.provider, selection.model);
|
|
2177
|
+
applyRuntimeModelSelection(ctx, selection.provider, selection.model, selection.authMode);
|
|
2153
2178
|
}
|
|
2154
2179
|
else if (setting !== 'clearSessionConfig' && !LIVE_READ_SETTINGS.has(setting)) {
|
|
2155
2180
|
await ctx.reloadAgent();
|
|
@@ -23,8 +23,15 @@ export interface ConfigController {
|
|
|
23
23
|
getRoutedModelCatalog?: () => import('../../utils/router_catalog.js').RouterCatalog | undefined;
|
|
24
24
|
adoptRouterCatalog?(catalog: import('../../utils/router_catalog.js').RouterCatalog): Promise<void>;
|
|
25
25
|
getRouterCatalog?: () => import('../../utils/router_catalog.js').RouterCatalog | undefined;
|
|
26
|
+
/** The person's own Zerg Router sign-in, while valid: its origin hosts the dashboard where provider keys are added. */
|
|
27
|
+
getPersonalRouterCredential?: () => {
|
|
28
|
+
origin: string;
|
|
29
|
+
token: string;
|
|
30
|
+
} | undefined;
|
|
26
31
|
getModelContextWindow?: (model?: string, provider?: string) => number | null | undefined;
|
|
27
32
|
locationLabel?: string;
|
|
33
|
+
/** The profile's config.json; the models remembered per provider live beside it. */
|
|
34
|
+
getConfigPath?: () => string;
|
|
28
35
|
get: () => ZTCConfig;
|
|
29
36
|
set: <K extends keyof ZTCConfig>(key: K, value: ZTCConfig[K]) => void;
|
|
30
37
|
setGlobal?: <K extends keyof ZTCConfig>(key: K, value: ZTCConfig[K]) => void;
|
|
@@ -145,6 +152,11 @@ export interface ModelsController {
|
|
|
145
152
|
authMode?: 'direct' | 'zrouter';
|
|
146
153
|
refresh?: boolean;
|
|
147
154
|
}) => Promise<string[]>;
|
|
155
|
+
/**
|
|
156
|
+
* The models discovery last found for `provider` on your own key or login, in this process or the profile's cache,
|
|
157
|
+
* without asking the provider again; undefined when it has listed none yet.
|
|
158
|
+
*/
|
|
159
|
+
discovered?: (provider: string) => Promise<string[] | undefined>;
|
|
148
160
|
}
|
|
149
161
|
export interface SkillsController {
|
|
150
162
|
list: () => Promise<Skill[]>;
|
|
@@ -447,8 +459,20 @@ export interface CommandContext {
|
|
|
447
459
|
* Apply a provider/model selection to the currently running process. This
|
|
448
460
|
* updates any session-local runtime override before recreating the agent, so
|
|
449
461
|
* explicit CLI --provider/--model values do not keep masking user commands.
|
|
462
|
+
* `authMode`, given when the selection names its route, moves with them: a
|
|
463
|
+
* pane's launch `--auth-mode` would otherwise keep the old route. A rebuild
|
|
464
|
+
* that fails keeps the provider, model and route the process ran on, and
|
|
465
|
+
* returns false.
|
|
450
466
|
*/
|
|
451
|
-
setRuntimeModelOverride?: (provider: string, model: string) => void;
|
|
467
|
+
setRuntimeModelOverride?: (provider: string, model: string, authMode?: ZTCAuthMode) => boolean | void;
|
|
468
|
+
/**
|
|
469
|
+
* The provider and model this pane runs on, where they can differ from the configuration's: the main pane's, which
|
|
470
|
+
* the web mirror's model menu switches for that pane alone. Without it the configuration's route is the pane's.
|
|
471
|
+
*/
|
|
472
|
+
getRuntimeRoute?: () => {
|
|
473
|
+
provider: string;
|
|
474
|
+
model: string;
|
|
475
|
+
};
|
|
452
476
|
restartZtc?: () => void | Promise<void>;
|
|
453
477
|
setDebug: (debug: boolean) => void;
|
|
454
478
|
retry: () => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { discoverRouterCatalog, readRouterCatalog, routerModelIds, routerCatalogScope } from '../utils/router_catalog.js';
|
|
2
|
-
import { loadModelCatalog } from './model_catalog_cache.js';
|
|
2
|
+
import { lastDiscoveredModels, loadModelCatalog } from './model_catalog_cache.js';
|
|
3
3
|
import { getSkills } from '../skills/registry.js';
|
|
4
4
|
import { runShellCommand } from '../utils/shell.js';
|
|
5
5
|
import { configStore } from '../config.js';
|
|
@@ -146,22 +146,36 @@ export function buildModelsController(config) {
|
|
|
146
146
|
if (llm.useProxy) {
|
|
147
147
|
return listRouter(llm.provider, options);
|
|
148
148
|
}
|
|
149
|
-
return loadModelCatalog(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
codexAuthFilePath: llm.codexAuthFilePath,
|
|
161
|
-
kimiCredsFilePath: llm.kimiCredsFilePath,
|
|
162
|
-
});
|
|
149
|
+
return loadModelCatalog(directDiscovery(llm, options?.signal));
|
|
150
|
+
},
|
|
151
|
+
discovered: async (provider) => {
|
|
152
|
+
let llm;
|
|
153
|
+
try {
|
|
154
|
+
llm = config.resolveLLMBackendConfig({ provider, config: { ...config.get(), authMode: 'direct' } });
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
return llm.useProxy ? undefined : lastDiscoveredModels(directDiscovery(llm));
|
|
163
160
|
},
|
|
164
161
|
};
|
|
162
|
+
/** What discovers `llm`'s models on its own key or login, and keys its cache (see loadModelCatalog). */
|
|
163
|
+
function directDiscovery(llm, signal) {
|
|
164
|
+
return {
|
|
165
|
+
signal,
|
|
166
|
+
provider: llm.provider,
|
|
167
|
+
apiKey: llm.apiKey,
|
|
168
|
+
baseUrl: llm.provider === 'openai_compatible' ? llm.compatBaseUrl : undefined,
|
|
169
|
+
proxyUrl: llm.useProxy ? llm.proxyUrl : undefined,
|
|
170
|
+
authToken: llm.useProxy ? llm.authToken : undefined,
|
|
171
|
+
workspaceId: llm.useProxy ? config.getRouterCatalogConnection?.()?.workspaceId : undefined,
|
|
172
|
+
codexAppServerCommand: llm.codexAppServerCommand,
|
|
173
|
+
codexAppServerArgs: llm.codexAppServerArgs,
|
|
174
|
+
codexHome: llm.codexHome,
|
|
175
|
+
codexAuthFilePath: llm.codexAuthFilePath,
|
|
176
|
+
kimiCredsFilePath: llm.kimiCredsFilePath,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
165
179
|
}
|
|
166
180
|
/**
|
|
167
181
|
* Build the shared SkillsController. Delegates to the memoized `getSkills()`
|
|
@@ -294,6 +308,8 @@ const PLAN_MODE_SESSION_COMMANDS = new Set([
|
|
|
294
308
|
'models',
|
|
295
309
|
'permissions',
|
|
296
310
|
'profile',
|
|
311
|
+
// The model chip applies every choice through /provider.
|
|
312
|
+
'provider',
|
|
297
313
|
'reasoning',
|
|
298
314
|
'rewind',
|
|
299
315
|
'settings',
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { listModels } from '../utils/models.js';
|
|
2
2
|
type ListModelsOptions = Parameters<typeof listModels>[0];
|
|
3
|
+
/**
|
|
4
|
+
* What discovery last found for `options`, in this process or in the profile's cache (a day at most), without asking
|
|
5
|
+
* the provider again; undefined when it has found nothing yet.
|
|
6
|
+
*/
|
|
7
|
+
export declare function lastDiscoveredModels(options: ListModelsOptions): Promise<string[] | undefined>;
|
|
3
8
|
/** Shared discovery for all renderers. Disk rows are previews, not entitlements. */
|
|
4
9
|
export declare function loadModelCatalog(options: ListModelsOptions, onVerified?: (models: string[]) => void): Promise<string[]>;
|
|
5
10
|
export {};
|
|
@@ -54,6 +54,19 @@ function freshModels(entry) {
|
|
|
54
54
|
const age = Date.now() - entry.checkedAt;
|
|
55
55
|
return age >= 0 && age < FRESH_MS ? [...entry.models] : undefined;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* What discovery last found for `options`, in this process or in the profile's cache (a day at most), without asking
|
|
59
|
+
* the provider again; undefined when it has found nothing yet.
|
|
60
|
+
*/
|
|
61
|
+
export async function lastDiscoveredModels(options) {
|
|
62
|
+
const scope = scopeFor(options);
|
|
63
|
+
const entry = catalogs.get(scope);
|
|
64
|
+
if (entry?.models !== undefined)
|
|
65
|
+
return [...entry.models];
|
|
66
|
+
const [cached, fetchedAt] = await Promise.all([readCachedModels(scope), readCachedModelsFetchedAt(scope)]);
|
|
67
|
+
const age = fetchedAt === undefined ? Infinity : Date.now() - fetchedAt;
|
|
68
|
+
return cached.length && age >= 0 && age < OFFLINE_MAX_AGE_MS ? cached : undefined;
|
|
69
|
+
}
|
|
57
70
|
/** Shared discovery for all renderers. Disk rows are previews, not entitlements. */
|
|
58
71
|
export async function loadModelCatalog(options, onVerified) {
|
|
59
72
|
options.signal?.throwIfAborted();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RouterSessionStatus } from '../router_auth.js';
|
|
2
|
+
import type { RouterCatalog } from '../utils/router_catalog.js';
|
|
3
|
+
/** How a provider choice is reached: through Zerg Router, or a credential on this machine. */
|
|
4
|
+
export type ProviderRoute = 'zergrouter' | 'direct';
|
|
5
|
+
/** Whether a choice can run now, needs a key or login first, or has no usable model on Zerg Router. */
|
|
6
|
+
export type ProviderChoiceState = 'ready' | 'needs_setup' | 'unavailable';
|
|
7
|
+
export interface ProviderChoice {
|
|
8
|
+
/** `zergrouter:<provider>` through Zerg Router, otherwise the provider id. */
|
|
9
|
+
id: string;
|
|
10
|
+
provider: string;
|
|
11
|
+
route: ProviderRoute;
|
|
12
|
+
label: string;
|
|
13
|
+
short_label: string;
|
|
14
|
+
state: ProviderChoiceState;
|
|
15
|
+
detail: string;
|
|
16
|
+
selected: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ProviderChoicesInput {
|
|
19
|
+
/** Router's catalog as cached in the profile, whatever this pane's route. */
|
|
20
|
+
catalog?: RouterCatalog;
|
|
21
|
+
routerSession: RouterSessionStatus;
|
|
22
|
+
/** Direct providers with a credential here (see modelRouteStatus). */
|
|
23
|
+
directReady: readonly string[];
|
|
24
|
+
/** What this pane runs on: a provider only Zerg Router serves counts as routed. */
|
|
25
|
+
selected: {
|
|
26
|
+
provider: string;
|
|
27
|
+
routed: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { parseProviderChoiceId, providerChoiceId, ROUTER_CHOICE_PREFIX } from '../agent/commands/provider_choices.js';
|
|
31
|
+
/** What a Zerg Router provider says when none of its chat models is available to this account. */
|
|
32
|
+
export declare const NO_ROUTER_KEY = "No key on Zerg Router";
|
|
33
|
+
/**
|
|
34
|
+
* The provider choices to show: Zerg Router's providers from the catalog cached for this login, whatever route this
|
|
35
|
+
* pane runs on, while signed in; then the person's own keys and logins, the ones with a credential first. The
|
|
36
|
+
* provider this pane runs on is always listed, as needing setup when it would otherwise be missing.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildProviderChoices(input: ProviderChoicesInput): ProviderChoice[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { canRouteThroughRouter, DIRECT_PROVIDER_CHOICES, describeDirectProvider, describeRouterRoute, PROVIDER_CHOICES, providerChoiceId, } from '../agent/commands/provider_choices.js';
|
|
2
|
+
export { parseProviderChoiceId, providerChoiceId, ROUTER_CHOICE_PREFIX } from '../agent/commands/provider_choices.js';
|
|
3
|
+
/** Router's provider slugs and ZTC's own provider ids: what can be typed after /provider and stored. */
|
|
4
|
+
const PROVIDER_ID = /^[a-z0-9][a-z0-9._-]{0,127}$/;
|
|
5
|
+
/** What a Zerg Router provider says when none of its chat models is available to this account. */
|
|
6
|
+
export const NO_ROUTER_KEY = 'No key on Zerg Router';
|
|
7
|
+
/** The name ZTC itself gives a provider, if it knows it. */
|
|
8
|
+
function knownLabel(provider) {
|
|
9
|
+
return PROVIDER_CHOICES.find(choice => choice.id === provider)?.label;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Router's chat providers in the order Router lists them (usable ones first), each with the name Router gives it
|
|
13
|
+
* and whether any of its chat models is available to this account. A provider ZTC never sends through Router, or
|
|
14
|
+
* one whose id couldn't be typed or stored, is left out.
|
|
15
|
+
*/
|
|
16
|
+
function routerProviders(catalog) {
|
|
17
|
+
const providers = new Map();
|
|
18
|
+
for (const row of catalog?.models ?? []) {
|
|
19
|
+
if (catalog.version !== 0 && row.capabilities?.chat !== true)
|
|
20
|
+
continue;
|
|
21
|
+
if (!PROVIDER_ID.test(row.owned_by) || !canRouteThroughRouter(row.owned_by))
|
|
22
|
+
continue;
|
|
23
|
+
const known = providers.get(row.owned_by);
|
|
24
|
+
providers.set(row.owned_by, { displayName: known?.displayName ?? row.provider_display_name,
|
|
25
|
+
usable: (known?.usable ?? false) || row.available !== false });
|
|
26
|
+
}
|
|
27
|
+
return providers;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The provider choices to show: Zerg Router's providers from the catalog cached for this login, whatever route this
|
|
31
|
+
* pane runs on, while signed in; then the person's own keys and logins, the ones with a credential first. The
|
|
32
|
+
* provider this pane runs on is always listed, as needing setup when it would otherwise be missing.
|
|
33
|
+
*/
|
|
34
|
+
export function buildProviderChoices(input) {
|
|
35
|
+
const selectedRoute = input.selected.routed ? 'zergrouter' : 'direct';
|
|
36
|
+
const selectedId = providerChoiceId(input.selected.provider, selectedRoute);
|
|
37
|
+
const listed = routerProviders(input.catalog);
|
|
38
|
+
const signedIn = input.routerSession === 'signed_in';
|
|
39
|
+
const router = signedIn ? [...listed].map(([provider, { displayName, usable }]) => ({
|
|
40
|
+
id: providerChoiceId(provider, 'zergrouter'), provider, route: 'zergrouter',
|
|
41
|
+
label: displayName || knownLabel(provider) || provider, short_label: knownLabel(provider) || displayName || provider,
|
|
42
|
+
state: usable ? 'ready' : 'unavailable', detail: usable ? '' : NO_ROUTER_KEY, selected: false,
|
|
43
|
+
})) : [];
|
|
44
|
+
const ready = new Set(input.directReady);
|
|
45
|
+
const direct = [...DIRECT_PROVIDER_CHOICES]
|
|
46
|
+
.sort((a, b) => Number(ready.has(b.id)) - Number(ready.has(a.id)))
|
|
47
|
+
.map(choice => ({
|
|
48
|
+
id: choice.id, provider: choice.id, route: 'direct', label: choice.label, short_label: choice.label,
|
|
49
|
+
state: ready.has(choice.id) ? 'ready' : 'needs_setup', detail: describeDirectProvider(choice.id, ready.has(choice.id)),
|
|
50
|
+
selected: false,
|
|
51
|
+
}));
|
|
52
|
+
const section = selectedRoute === 'zergrouter' ? router : direct;
|
|
53
|
+
if (!section.some(choice => choice.id === selectedId)) {
|
|
54
|
+
const { provider } = input.selected;
|
|
55
|
+
const displayName = listed.get(provider)?.displayName;
|
|
56
|
+
section.push({
|
|
57
|
+
id: selectedId, provider, route: selectedRoute,
|
|
58
|
+
label: displayName || knownLabel(provider) || provider, short_label: knownLabel(provider) || displayName || provider,
|
|
59
|
+
state: 'needs_setup',
|
|
60
|
+
detail: selectedRoute === 'direct' ? describeDirectProvider(provider, false)
|
|
61
|
+
: signedIn ? 'Not in Zerg Router\'s list · /provider refresh' : describeRouterRoute(input.routerSession),
|
|
62
|
+
selected: false,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return [...router, ...direct].map(choice => choice.id === selectedId ? { ...choice, selected: true } : choice);
|
|
66
|
+
}
|
|
@@ -87,6 +87,11 @@ export declare class SelectionCompletion {
|
|
|
87
87
|
* otherwise it stays on the top row.
|
|
88
88
|
*/
|
|
89
89
|
private filter;
|
|
90
|
+
/**
|
|
91
|
+
* `/provider`'s rows: Zerg Router's providers from the catalog loaded for this menu, then the person's own keys.
|
|
92
|
+
* A provider on both lists is completed with its route, which a bare name would otherwise pick.
|
|
93
|
+
*/
|
|
94
|
+
private providerChoiceSelections;
|
|
90
95
|
/** Route status is known and has no current ZergAI login for Zerg Router. */
|
|
91
96
|
private routerLoginNeeded;
|
|
92
97
|
/** The one row Zerg Router choices show without a login: Enter runs /model, which asks. */
|