@zergai/ztc 0.20.0-beta.1 → 0.21.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/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-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/agent/commands/config.js +7 -1
- package/dist/agent/commands/model.js +9 -5
- package/dist/agent/commands/models.js +2 -4
- package/dist/agent/commands/provider.d.ts +12 -0
- package/dist/agent/commands/provider.js +38 -2
- package/dist/agent/commands/provider_selection.d.ts +24 -1
- package/dist/agent/commands/provider_selection.js +70 -36
- package/dist/agent/commands/runtime_model.d.ts +11 -2
- package/dist/agent/commands/runtime_model.js +23 -5
- package/dist/agent/commands/settings.js +12 -3
- package/dist/agent/commands/types.d.ts +24 -4
- package/dist/app/runtime_choices.d.ts +78 -1
- package/dist/app/runtime_choices.js +229 -0
- package/dist/app/runtime_choices_source.d.ts +45 -0
- package/dist/app/runtime_choices_source.js +127 -0
- package/dist/app/selection_completion.js +1 -14
- package/dist/cli_ratatui.d.ts +94 -16
- package/dist/cli_ratatui.js +510 -124
- package/dist/config/provider_models.d.ts +15 -0
- package/dist/config/provider_models.js +28 -0
- package/dist/config.d.ts +114 -4
- package/dist/config.js +306 -62
- package/dist/headless.js +13 -5
- package/dist/panes/pane_registry.d.ts +16 -1
- package/dist/panes/pane_registry.js +17 -0
- package/dist/panes/types.d.ts +14 -0
- package/dist/panes/ztc_launch.d.ts +3 -0
- package/dist/panes/ztc_launch.js +10 -7
- package/dist/simulation/toolkit/dynamic_meetings.d.ts +2 -2
- package/dist/simulation/toolkit/dynamic_story_review.d.ts +3 -3
- package/dist/ui/ratatui/pane_relay.d.ts +22 -1
- package/dist/ui/ratatui/pane_relay.js +57 -6
- package/dist/ui/ratatui/protocol.d.ts +97 -1
- package/dist/ui/ratatui/protocol.js +136 -6
- package/dist/utils/router_catalog_facts.d.ts +3 -0
- package/dist/utils/router_catalog_facts.js +14 -0
- package/dist/zlm-embed.mjs +275 -52
- package/package.json +16 -16
package/bin/zmux-darwin-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/ztc-tui-darwin-arm64
CHANGED
|
Binary file
|
package/bin/zterm-darwin-arm64
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/zterm-darwin-arm64
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 33960480 bytes
|
|
4
|
+
sha256: f6e8335bc6fe08075c793e388edf4ab3368bf6241832a1bf105b3fc1eea59c97
|
|
@@ -15,7 +15,7 @@ import { formatRate } from '../../utils/openrouter_prices.js';
|
|
|
15
15
|
import { API_KEY_PROVIDER_CHOICES, canonicalProvider, describeKeySource, isLocalSubscription, isRouterOnlyProvider, PROVIDER_CHOICES, routerOnlyModelError, } from './provider_choices.js';
|
|
16
16
|
import { canAskForCredential, manageApiKey, promptForMissingDirectKey, removeApiKey, savedKeyNotes, useApiKeyVariable, } from './direct_credential_prompt.js';
|
|
17
17
|
import { looksLikeApiKeyEnvName } from '../../config/provider_api_key_env.js';
|
|
18
|
-
import { offerKeyedProviderSwitch } from './provider_selection.js';
|
|
18
|
+
import { offerKeyedProviderSwitch, ownRouteModelSelection, selectProviderModel } from './provider_selection.js';
|
|
19
19
|
import { connectionStatusLines } from './credential_status.js';
|
|
20
20
|
import { normalizeProviderId } from '../backends/provider_ids.js';
|
|
21
21
|
import { unsupportedCodexEffort } from '../../config/defaults.js';
|
|
@@ -257,6 +257,12 @@ async function setConfigProvider(value, ctx, credentialPrompted = false) {
|
|
|
257
257
|
* for once, then the model is applied.
|
|
258
258
|
*/
|
|
259
259
|
async function setConfigModel(value, ctx, credentialPrompted = false) {
|
|
260
|
+
// A pane running a route of its own saves that provider and route with the model (see ownRouteModelSelection).
|
|
261
|
+
const own = ownRouteModelSelection(ctx, value);
|
|
262
|
+
if (own) {
|
|
263
|
+
await selectProviderModel(own, ctx, { offerReasoning: true });
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
260
266
|
// Verify the selection builds a backend BEFORE persisting so an
|
|
261
267
|
// unbuildable choice never lands in config.json nor earns a false "✓".
|
|
262
268
|
const activeProvider = ctx.config.getProvider();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { configCommand } from './config.js';
|
|
2
2
|
import { modelsCommand } from './models.js';
|
|
3
3
|
import { canRouteThroughRouter, canonicalProvider, canonicalRoute, describeDirectRoute, describeRouterRoute, isRouterOnlyProvider, modelRouteStatus, } from './provider_choices.js';
|
|
4
|
-
import { refreshRouterModels, selectProviderModel } from './provider_selection.js';
|
|
4
|
+
import { ownRouteModelSelection, refreshRouterModels, selectProviderModel } from './provider_selection.js';
|
|
5
5
|
import { switchProvider } from './provider.js';
|
|
6
6
|
import { getEffectiveModel } from './runtime_model.js';
|
|
7
7
|
import { normalizeProviderId } from '../backends/provider_ids.js';
|
|
@@ -117,15 +117,19 @@ export const modelCommand = {
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
if (args.length > 1 || (args.length === 1 && (canonicalProvider(args[0]) || canonicalRoute(args[0])))) {
|
|
120
|
-
|
|
120
|
+
await selectProviderModel(args, ctx, { offerReasoning: true });
|
|
121
|
+
return;
|
|
121
122
|
}
|
|
122
123
|
if (args.length === 1 && routerListsProvider(args[0], ctx))
|
|
123
124
|
return switchProvider(args, ctx);
|
|
124
125
|
// Another provider's model selects that provider too, so its key is the
|
|
125
126
|
// one asked for and the model is never saved under the current provider.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
// A model of the provider this pane runs on its own route is saved with that provider and route.
|
|
128
|
+
const selection = otherProvidersSelection(args[0], ctx) ?? ownRouteModelSelection(ctx, args[0]);
|
|
129
|
+
if (selection) {
|
|
130
|
+
await selectProviderModel(selection, ctx, { offerReasoning: true });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
129
133
|
return configCommand.handler(['model', ...args], ctx);
|
|
130
134
|
}
|
|
131
135
|
};
|
|
@@ -110,12 +110,10 @@ export function pickLatestModel(models, provider) {
|
|
|
110
110
|
async function setModel(value, ctx) {
|
|
111
111
|
// The main pane's route can be the web mirror's choice for it alone, not the configuration's.
|
|
112
112
|
const { provider, routed } = paneRoute(ctx);
|
|
113
|
-
if (routed)
|
|
114
|
-
return selectProviderModel(['zergrouter', provider, value], ctx);
|
|
115
113
|
// A provider /model doesn't name (Bedrock) keeps the model-only change.
|
|
116
|
-
if (!canonicalProvider(provider))
|
|
114
|
+
if (!routed && !canonicalProvider(provider))
|
|
117
115
|
return setModelOnly(value, ctx);
|
|
118
|
-
|
|
116
|
+
await selectProviderModel([routed ? 'zergrouter' : 'direct', provider, value], ctx);
|
|
119
117
|
}
|
|
120
118
|
/**
|
|
121
119
|
* The model alone, on the active provider. A missing direct key is asked for
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { type PaneRoute } from './runtime_model.js';
|
|
1
2
|
import type { Command, CommandContext } from './types.js';
|
|
3
|
+
/** What this pane runs on (see paneRoute). */
|
|
4
|
+
type Current = PaneRoute;
|
|
5
|
+
/**
|
|
6
|
+
* What a pane header's switch says in the pane: the route this pane now runs on, and, when it differs, the one new
|
|
7
|
+
* panes still start on. "✓ This pane: Morph · morph-dsv41flash-1017 (Zerg Router). New panes still start on Modal ·
|
|
8
|
+
* deepseek-v4.1-flash." On the same provider and model only the route differs, so that one is named with its route.
|
|
9
|
+
*/
|
|
10
|
+
export declare function paneSwitchConfirmation(ctx: CommandContext, applied: Current): string;
|
|
11
|
+
/** What "Use for new panes" says: "New panes start on Morph · morph-dsv41flash-1017 (Zerg Router)." */
|
|
12
|
+
export declare function newPanesConfirmation(ctx: CommandContext, applied: Current, kept?: Current): string;
|
|
2
13
|
/**
|
|
3
14
|
* `/provider [zergrouter|direct] <name> [model]`, and `/model <name>` for a provider Zerg Router lists. The model is
|
|
4
15
|
* the one named, else the one last used with that provider while it is still offered, else the provider's default.
|
|
@@ -20,3 +31,4 @@ export declare function pickProviderAndModel(ctx: CommandContext, current: {
|
|
|
20
31
|
*/
|
|
21
32
|
export declare function switchesProvider(args: readonly string[]): boolean;
|
|
22
33
|
export declare const providerCommand: Command;
|
|
34
|
+
export {};
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { buildProviderChoices } from '../../app/runtime_choices.js';
|
|
6
6
|
import { isLocalSubscriptionProvider, normalizeProviderId } from '../backends/provider_ids.js';
|
|
7
|
-
import { canonicalProvider, canonicalRoute, isRouterOnlyProvider, modelRouteStatus, routerServesProvider, } from './provider_choices.js';
|
|
7
|
+
import { canonicalProvider, canonicalRoute, isRouterOnlyProvider, modelRouteStatus, PROVIDER_CHOICES, routerServesProvider, } from './provider_choices.js';
|
|
8
8
|
import { profileDirectory, refreshRouterModels, selectProviderModel } from './provider_selection.js';
|
|
9
|
-
import { paneRoute } from './runtime_model.js';
|
|
9
|
+
import { newPaneRoute, paneRoute } from './runtime_model.js';
|
|
10
10
|
import { rememberedModel } from '../../config/provider_models.js';
|
|
11
11
|
import { defaultRouterModel, routerModelsForProvider } from '../../utils/router_catalog.js';
|
|
12
12
|
const USAGE = 'Usage: /provider [<provider> [model] | zergrouter <provider> [model] | direct <provider> [model] | refresh]';
|
|
@@ -64,6 +64,42 @@ function listing(ctx, current, choices) {
|
|
|
64
64
|
'/provider <name> switches this pane and the default for new panes. /provider refresh reloads Zerg Router\'s list.',
|
|
65
65
|
].join('\n');
|
|
66
66
|
}
|
|
67
|
+
/** How a route reads after a provider and model, in parentheses: Zerg Router, or what bills it here. */
|
|
68
|
+
function routeLabel(provider, routed) {
|
|
69
|
+
if (routed)
|
|
70
|
+
return 'Zerg Router';
|
|
71
|
+
if (isLocalSubscriptionProvider(provider))
|
|
72
|
+
return 'local login';
|
|
73
|
+
return provider === 'openai_compatible' ? 'custom endpoint' : 'your key';
|
|
74
|
+
}
|
|
75
|
+
/** A provider's name as ZTC or Zerg Router's catalog gives it. */
|
|
76
|
+
function providerName(ctx, provider) {
|
|
77
|
+
return PROVIDER_CHOICES.find(choice => choice.id === provider)?.label
|
|
78
|
+
?? ctx.config.getRouterCatalog?.()?.models.find(row => row.owned_by === provider)?.provider_display_name ?? provider;
|
|
79
|
+
}
|
|
80
|
+
/** "Morph · morph-dsv41flash-1017 (Zerg Router)": a route with its provider's short name. */
|
|
81
|
+
function routeText(ctx, route) {
|
|
82
|
+
const label = choicesFor(ctx, route).find(choice => choice.selected)?.short_label ?? route.provider;
|
|
83
|
+
return `${label} · ${modelName(route.provider, route.model)} (${routeLabel(route.provider, route.routed)})`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What a pane header's switch says in the pane: the route this pane now runs on, and, when it differs, the one new
|
|
87
|
+
* panes still start on. "✓ This pane: Morph · morph-dsv41flash-1017 (Zerg Router). New panes still start on Modal ·
|
|
88
|
+
* deepseek-v4.1-flash." On the same provider and model only the route differs, so that one is named with its route.
|
|
89
|
+
*/
|
|
90
|
+
export function paneSwitchConfirmation(ctx, applied) {
|
|
91
|
+
const configured = ctx.config.getNewPaneRoute?.();
|
|
92
|
+
const next = configured && newPaneRoute(ctx.config, configured);
|
|
93
|
+
const sameModel = next && normalizeProviderId(next.provider) === normalizeProviderId(applied.provider) && next.model === applied.model;
|
|
94
|
+
if (!next || (sameModel && next.routed === applied.routed))
|
|
95
|
+
return `✓ This pane: ${routeText(ctx, applied)}.`;
|
|
96
|
+
const named = `${providerName(ctx, next.provider)} · ${modelName(next.provider, next.model)}`;
|
|
97
|
+
return `✓ This pane: ${routeText(ctx, applied)}. New panes still start on ${sameModel ? `${named} (${routeLabel(next.provider, next.routed)})` : named}.`;
|
|
98
|
+
}
|
|
99
|
+
/** What "Use for new panes" says: "New panes start on Morph · morph-dsv41flash-1017 (Zerg Router)." */
|
|
100
|
+
export function newPanesConfirmation(ctx, applied, kept) {
|
|
101
|
+
return `New panes start on ${routeText(ctx, applied)}${kept ? `; this pane keeps ${routeText(ctx, kept)}` : ''}.`;
|
|
102
|
+
}
|
|
67
103
|
/** Bare /provider: a choice to pick where someone can pick one, otherwise the list as text. */
|
|
68
104
|
async function showProviders(ctx) {
|
|
69
105
|
const current = paneRoute(ctx);
|
|
@@ -14,6 +14,13 @@ export declare function refreshRouterModels(ctx: CommandContext): Promise<void>;
|
|
|
14
14
|
* include it, or none were listed yet, so nothing says it is gone.
|
|
15
15
|
*/
|
|
16
16
|
export declare function stillListed(ctx: CommandContext, provider: string, model: string): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* A model chosen for the provider this pane runs on, while the pane runs a route of its own (a pane header's choice,
|
|
19
|
+
* the web mirror's model menu, a default another pane chose meanwhile): the selection that saves that provider and
|
|
20
|
+
* route with the model, so the default for new panes stays a pair a provider serves. Undefined while the pane follows
|
|
21
|
+
* the configured route, or runs a provider /model can't name.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ownRouteModelSelection(ctx: CommandContext, model: string): string[] | undefined;
|
|
17
24
|
/** How a provider and model selection runs; see selectProviderModel. */
|
|
18
25
|
export interface SelectionOptions {
|
|
19
26
|
credentialPrompted?: boolean;
|
|
@@ -23,6 +30,22 @@ export interface SelectionOptions {
|
|
|
23
30
|
* running when its rebuild on the selection failed (it said why), so only new panes start on the selection.
|
|
24
31
|
*/
|
|
25
32
|
confirm?: (applied: PaneRoute, kept?: PaneRoute) => string;
|
|
33
|
+
/**
|
|
34
|
+
* 'profile' (the default) saves the selection as the default for new panes and switches this pane; 'pane'
|
|
35
|
+
* switches this pane alone and saves nothing (ctx.applyPaneRoute): a pane header's menus.
|
|
36
|
+
*/
|
|
37
|
+
scope?: 'profile' | 'pane';
|
|
38
|
+
/** With no model named, the one to land on before the profile's remembered one: this pane's last with the provider. */
|
|
39
|
+
preferredModel?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* How a selection ended: `applied`, `prompted` when it asked for a key or login and finishes once that is saved, or
|
|
43
|
+
* `refused`, with what it said. `blocked` marks a refusal because an agent turn started meanwhile.
|
|
44
|
+
*/
|
|
45
|
+
export interface SelectionOutcome {
|
|
46
|
+
kind: 'applied' | 'prompted' | 'refused';
|
|
47
|
+
message: string;
|
|
48
|
+
blocked?: boolean;
|
|
26
49
|
}
|
|
27
50
|
/**
|
|
28
51
|
* Apply a provider and optional model in one validated config transition. A
|
|
@@ -31,7 +54,7 @@ export interface SelectionOptions {
|
|
|
31
54
|
* `credentialPrompted` keeps that retry from asking twice; `offerReasoning`,
|
|
32
55
|
* set by /model, offers the model's reasoning once it is selected.
|
|
33
56
|
*/
|
|
34
|
-
export declare function selectProviderModel(args: string[], ctx: CommandContext, options?: SelectionOptions): Promise<
|
|
57
|
+
export declare function selectProviderModel(args: string[], ctx: CommandContext, options?: SelectionOptions): Promise<SelectionOutcome>;
|
|
35
58
|
/** Whether the current selection can reach a model now. */
|
|
36
59
|
export declare function currentRouteReady(ctx: CommandContext): boolean;
|
|
37
60
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { dirname } from 'node:path';
|
|
2
2
|
import { getDefaultModelForProvider } from '../../config/defaults.js';
|
|
3
|
-
import { isBuildableResolvedConfig } from './config.js';
|
|
4
|
-
import { canAskForCredential, promptForMissingDirectKey, providerLabel } from './direct_credential_prompt.js';
|
|
3
|
+
import { isBuildableResolvedConfig, unbuildableSelectionMessage } from './config.js';
|
|
4
|
+
import { canAskForCredential, promptForDirectCredential, promptForMissingDirectKey, providerLabel } from './direct_credential_prompt.js';
|
|
5
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';
|
|
6
|
+
import { canRouteThroughRouter, canonicalProvider, canonicalRoute, DIRECT_PROVIDER_CHOICES, describeDirectProvider, isLocalSubscription, isRouterOnlyProvider, modelRouteStatus, providerChoiceId, } from './provider_choices.js';
|
|
7
7
|
import { rememberedModel, rememberProviderModel } from '../../config/provider_models.js';
|
|
8
8
|
import { resolveModelAndProvider } from '../../panes/model_catalog.js';
|
|
9
9
|
import { getDefaultModel } from '../../utils/models.js';
|
|
@@ -56,24 +56,40 @@ export async function stillListed(ctx, provider, model) {
|
|
|
56
56
|
const listed = await ctx.models.discovered?.(provider).catch(() => undefined);
|
|
57
57
|
return !listed || listed.includes(model);
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* A model chosen for the provider this pane runs on, while the pane runs a route of its own (a pane header's choice,
|
|
61
|
+
* the web mirror's model menu, a default another pane chose meanwhile): the selection that saves that provider and
|
|
62
|
+
* route with the model, so the default for new panes stays a pair a provider serves. Undefined while the pane follows
|
|
63
|
+
* the configured route, or runs a provider /model can't name.
|
|
64
|
+
*/
|
|
65
|
+
export function ownRouteModelSelection(ctx, model) {
|
|
66
|
+
if (!ctx.config.getPaneRoute?.())
|
|
67
|
+
return undefined;
|
|
68
|
+
const { provider, routed } = paneRoute(ctx);
|
|
69
|
+
if (!routed && !canonicalProvider(provider))
|
|
70
|
+
return undefined;
|
|
71
|
+
return [routed ? 'zergrouter' : 'direct', provider, model];
|
|
72
|
+
}
|
|
73
|
+
/** Say `message` in the transcript and end the selection as `kind`. */
|
|
74
|
+
function ended(ctx, kind, message) {
|
|
75
|
+
ctx.addMessage({ role: 'system', content: message });
|
|
76
|
+
return { kind, message };
|
|
77
|
+
}
|
|
59
78
|
/** `/model direct ...`: the local route, offering only providers this machine can call. */
|
|
60
79
|
async function selectDirectRoute(values, ctx, options) {
|
|
61
80
|
if (values.length === 1) {
|
|
62
|
-
ctx
|
|
63
|
-
return;
|
|
81
|
+
return ended(ctx, 'refused', formatDirectProviders(modelRouteStatus(ctx.config).directProviders));
|
|
64
82
|
}
|
|
65
83
|
const provider = canonicalProvider(values[1]);
|
|
66
84
|
if (!provider) {
|
|
67
|
-
ctx
|
|
68
|
-
return;
|
|
85
|
+
return ended(ctx, 'refused', `Unknown local provider: ${values[1]}. Run /model direct to see the choices.`);
|
|
69
86
|
}
|
|
70
87
|
if (isRouterOnlyProvider(provider)) {
|
|
71
|
-
ctx
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return;
|
|
88
|
+
return ended(ctx, 'refused', provider === 'modal'
|
|
89
|
+
? 'modal runs through ZergRouter. Use /model zergrouter modal [model].'
|
|
90
|
+
: 'ZergRouter is the other route. Use /model zergrouter [provider] [model].');
|
|
75
91
|
}
|
|
76
|
-
|
|
92
|
+
return selectProviderModel([provider, ...values.slice(2)], ctx, options);
|
|
77
93
|
}
|
|
78
94
|
/**
|
|
79
95
|
* A Zerg Router selection without a current ZergAI login asks for one and,
|
|
@@ -83,8 +99,7 @@ async function selectDirectRoute(values, ctx, options) {
|
|
|
83
99
|
function askForRouterLogin(args, ctx, options) {
|
|
84
100
|
const expired = ctx.config.getRouterSessionStatus?.() === 'expired';
|
|
85
101
|
if (!canAskForCredential(ctx)) {
|
|
86
|
-
ctx
|
|
87
|
-
return;
|
|
102
|
+
return ended(ctx, 'refused', `✗ ${ROUTER_MODELS_NEED_LOGIN} with ZergAI. Run /auth login, then /model zergrouter. Keeping the current selection.`);
|
|
88
103
|
}
|
|
89
104
|
ctx.select.showSelect({
|
|
90
105
|
title: 'Log in to ZergRouter', type: 'select', defaultValue: 'login', silentCancel: true, compact: true,
|
|
@@ -102,6 +117,7 @@ function askForRouterLogin(args, ctx, options) {
|
|
|
102
117
|
if (outcome.ok && ctx.config.getRouterSessionStatus?.() === 'signed_in')
|
|
103
118
|
await selectProviderModel(args, ctx, { ...options, credentialPrompted: true });
|
|
104
119
|
});
|
|
120
|
+
return { kind: 'prompted', message: 'Finish in this pane: log in with ZergAI to use Zerg Router.' };
|
|
105
121
|
}
|
|
106
122
|
/**
|
|
107
123
|
* Apply a provider and optional model in one validated config transition. A
|
|
@@ -115,9 +131,8 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
115
131
|
const values = args.filter(Boolean);
|
|
116
132
|
const retired = values.find(value => isRetiredProvider(value) || isRetiredModel(value));
|
|
117
133
|
if (retired) {
|
|
118
|
-
ctx
|
|
119
|
-
|
|
120
|
-
return;
|
|
134
|
+
return ended(ctx, 'refused', isRetiredProvider(retired)
|
|
135
|
+
? retiredProviderMessage(retired, ctx.config.getProvider()) : retiredModelMessage(retired));
|
|
121
136
|
}
|
|
122
137
|
if (canonicalRoute(values[0]) === 'direct')
|
|
123
138
|
return selectDirectRoute(values, ctx, options);
|
|
@@ -131,22 +146,15 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
131
146
|
? (upstream ?? (canRouteThroughRouter(current) ? current : 'anthropic'))
|
|
132
147
|
: choice;
|
|
133
148
|
if (!provider || (routed && !canRouteThroughRouter(provider))) {
|
|
134
|
-
ctx
|
|
135
|
-
return;
|
|
149
|
+
return ended(ctx, 'refused', `Unknown provider or unsupported Router provider: ${values.join(' ')}. Run /model to see the choices.`);
|
|
136
150
|
}
|
|
137
151
|
if (values.length > (choice === 'zergrouter' ? 3 : 2)) {
|
|
138
|
-
ctx
|
|
139
|
-
return;
|
|
152
|
+
return ended(ctx, 'refused', 'Usage: /model [direct] <provider> [model] or /model zergrouter <upstream-provider> [model]');
|
|
140
153
|
}
|
|
141
154
|
const routerSession = ctx.config.getRouterSessionStatus?.();
|
|
142
155
|
if (routed && routerSession !== undefined && routerSession !== 'signed_in') {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
askForRouterLogin(args, ctx, options);
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
156
|
+
return credentialPrompted ? ended(ctx, 'refused', `✗ ${ROUTER_MODELS_NEED_LOGIN} with ZergAI. Keeping the current selection.`)
|
|
157
|
+
: askForRouterLogin(args, ctx, options);
|
|
150
158
|
}
|
|
151
159
|
const authMode = routed ? 'zrouter' : 'direct';
|
|
152
160
|
const choiceId = providerChoiceId(provider, routed ? 'zergrouter' : 'direct');
|
|
@@ -156,8 +164,8 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
156
164
|
// names its own. It must still be offered, through Zerg Router (below) or on your own key; a retired id is never
|
|
157
165
|
// used again.
|
|
158
166
|
const profile = profileDirectory(ctx);
|
|
159
|
-
const recalled = !explicitModel && provider !== current && provider !== 'openai_compatible'
|
|
160
|
-
? rememberedModel(choiceId, profile) : undefined;
|
|
167
|
+
const recalled = !explicitModel && provider !== current && provider !== 'openai_compatible'
|
|
168
|
+
? options.preferredModel ?? (profile ? rememberedModel(choiceId, profile) : undefined) : undefined;
|
|
161
169
|
const remembered = recalled && !isRetiredModel(recalled) ? recalled : undefined;
|
|
162
170
|
const keptDirect = !routed && remembered && await stillListed(ctx, provider, remembered) ? remembered : undefined;
|
|
163
171
|
let model = explicitModel || (provider === current ? getEffectiveModel(ctx)
|
|
@@ -191,17 +199,43 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
191
199
|
if (llm.authMode !== authMode) {
|
|
192
200
|
throw new Error('Routing is pinned by ZTC_LLM_AUTH_MODE/ZERG_LLM_AUTH_MODE. Unset it before switching routes.');
|
|
193
201
|
}
|
|
202
|
+
// A pane header's choice that isn't ready yet asks in this pane for what it needs, and the pane switches only once
|
|
203
|
+
// it is there. A local login builds a backend without one, so the login itself is its readiness, as /settings
|
|
204
|
+
// checks it: the pane says how to sign in. A custom endpoint opens its setup form, and switches once it is saved.
|
|
205
|
+
const loginMissing = isLocalSubscription(provider) && ctx.config.hasDirectCredential?.(provider) === false;
|
|
206
|
+
if (options.scope === 'pane' && (loginMissing || (provider === 'openai_compatible' && !isBuildableResolvedConfig(llm)))) {
|
|
207
|
+
if (!credentialPrompted && promptForDirectCredential(provider, ctx, async () => {
|
|
208
|
+
await selectProviderModel(args, ctx, { ...options, credentialPrompted: true });
|
|
209
|
+
})) {
|
|
210
|
+
return { kind: 'prompted', message: loginMissing
|
|
211
|
+
? `Finish in this pane: sign in to ${providerLabel(provider)}, then choose it again.`
|
|
212
|
+
: `Finish in this pane: set up your ${providerLabel(provider)} endpoint.` };
|
|
213
|
+
}
|
|
214
|
+
throw new Error(unbuildableSelectionMessage(provider).replace(/ Keeping the current selection\.$/, ''));
|
|
215
|
+
}
|
|
194
216
|
if (!isBuildableResolvedConfig(llm)) {
|
|
195
|
-
if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => selectProviderModel(args, ctx, { ...options, credentialPrompted: true })))
|
|
196
|
-
return;
|
|
217
|
+
if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, async () => { await selectProviderModel(args, ctx, { ...options, credentialPrompted: true }); })) {
|
|
218
|
+
return { kind: 'prompted', message: `Finish in this pane: add your ${providerLabel(provider)} ${provider === 'openai_compatible' ? 'endpoint' : 'API key'}.` };
|
|
219
|
+
}
|
|
197
220
|
throw new Error(provider === 'openai_compatible'
|
|
198
221
|
? 'Configure a local or custom endpoint with /config openai-compat, then select /model openai_compatible.'
|
|
199
222
|
: `No usable direct credentials for ${provider}. Add a key with /config key ${provider} or configure this provider's local login.`);
|
|
200
223
|
}
|
|
201
224
|
}
|
|
202
225
|
catch (error) {
|
|
203
|
-
ctx
|
|
204
|
-
|
|
226
|
+
return ended(ctx, 'refused', `✗ ${error instanceof Error ? error.message : String(error)} Keeping the current selection.`);
|
|
227
|
+
}
|
|
228
|
+
const applied = { provider, model, routed };
|
|
229
|
+
if (options.scope === 'pane') {
|
|
230
|
+
// This pane alone: nothing is saved or remembered for the profile, and new panes start where they did.
|
|
231
|
+
if (!ctx.applyPaneRoute)
|
|
232
|
+
return ended(ctx, 'refused', 'This pane can\'t switch on its own here; /provider sets the default and this pane.');
|
|
233
|
+
const switched = await ctx.applyPaneRoute({ provider, model, authMode });
|
|
234
|
+
if (!switched.ok) {
|
|
235
|
+
const message = switched.message ?? 'This pane keeps its model; it says why.';
|
|
236
|
+
return switched.blocked ? { kind: 'refused', message, blocked: true } : ended(ctx, 'refused', message);
|
|
237
|
+
}
|
|
238
|
+
return ended(ctx, 'applied', options.confirm ? options.confirm(applied) : `✓ This pane: ${provider} · ${model}.`);
|
|
205
239
|
}
|
|
206
240
|
ctx.config.set('authMode', authMode);
|
|
207
241
|
ctx.config.setProvider(provider);
|
|
@@ -215,10 +249,10 @@ export async function selectProviderModel(args, ctx, options = {}) {
|
|
|
215
249
|
}
|
|
216
250
|
// A rebuild that failed left this pane on the route it ran on; the selection is saved all the same.
|
|
217
251
|
const kept = applyRuntimeModelSelection(ctx, provider, model, authMode) ? undefined : paneRoute(ctx);
|
|
218
|
-
const
|
|
219
|
-
ctx.addMessage({ role: 'system', content: options.confirm ? options.confirm(applied, kept) : modelConfirmation(ctx, applied, kept) });
|
|
252
|
+
const outcome = ended(ctx, 'applied', options.confirm ? options.confirm(applied, kept) : modelConfirmation(ctx, applied, kept));
|
|
220
253
|
if (options.offerReasoning)
|
|
221
254
|
offerReasoningPicker(ctx);
|
|
255
|
+
return outcome;
|
|
222
256
|
}
|
|
223
257
|
/**
|
|
224
258
|
* /model's confirmation of a saved selection. One this pane couldn't rebuild on says the route it keeps: the
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ConfiguredRoute } from '../../config.js';
|
|
1
2
|
import type { ZTCAuthMode } from '../../config/types.js';
|
|
2
|
-
import type { CommandContext } from './types.js';
|
|
3
|
+
import type { CommandContext, ConfigController } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Run the selection just saved in this process. `authMode` is the route the
|
|
5
6
|
* selection names, when it names one; it moves with the provider and model.
|
|
@@ -13,6 +14,14 @@ export interface PaneRoute {
|
|
|
13
14
|
model: string;
|
|
14
15
|
routed: boolean;
|
|
15
16
|
}
|
|
16
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* The route this pane runs on, as the configuration resolves it: a pane's own route (ConfigStore's pane route, set by
|
|
19
|
+
* a choice made for it alone) outranks the configured one there.
|
|
20
|
+
*/
|
|
17
21
|
export declare function paneRoute(ctx: CommandContext): PaneRoute;
|
|
22
|
+
/**
|
|
23
|
+
* The route new panes start on, `route` (ConfigStore.getNewPaneRoute), with whether Zerg Router carries it, resolved
|
|
24
|
+
* as a pane launched on it resolves it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function newPaneRoute(config: ConfigController, route: ConfiguredRoute): PaneRoute;
|
|
18
27
|
export declare function getEffectiveModel(ctx: CommandContext): string;
|
|
@@ -13,19 +13,37 @@ export function applyRuntimeModelSelection(ctx, provider, model, authMode) {
|
|
|
13
13
|
ctx.reloadAgent();
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The route this pane runs on, as the configuration resolves it: a pane's own route (ConfigStore's pane route, set by
|
|
18
|
+
* a choice made for it alone) outranks the configured one there.
|
|
19
|
+
*/
|
|
17
20
|
export function paneRoute(ctx) {
|
|
18
|
-
const live = ctx.getRuntimeRoute?.();
|
|
19
21
|
try {
|
|
20
|
-
const llm = ctx.config.resolveLLMBackendConfig(
|
|
22
|
+
const llm = ctx.config.resolveLLMBackendConfig({});
|
|
21
23
|
return { provider: llm.provider, model: llm.model, routed: llm.useProxy || isRouterOnlyProvider(llm.provider) };
|
|
22
24
|
}
|
|
23
25
|
catch {
|
|
24
|
-
const provider = normalizeProviderId(
|
|
25
|
-
return { provider, model:
|
|
26
|
+
const provider = normalizeProviderId(ctx.config.getProvider());
|
|
27
|
+
return { provider, model: getEffectiveModel(ctx),
|
|
26
28
|
routed: ctx.config.getAuthMode?.() === 'zrouter' || isRouterOnlyProvider(provider) };
|
|
27
29
|
}
|
|
28
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The route new panes start on, `route` (ConfigStore.getNewPaneRoute), with whether Zerg Router carries it, resolved
|
|
33
|
+
* as a pane launched on it resolves it.
|
|
34
|
+
*/
|
|
35
|
+
export function newPaneRoute(config, route) {
|
|
36
|
+
let routed;
|
|
37
|
+
try {
|
|
38
|
+
routed = config.resolveLLMBackendConfig({ provider: route.provider, model: route.model, asChosen: true,
|
|
39
|
+
config: { ...config.get(), provider: route.provider, model: route.model, authMode: route.authMode,
|
|
40
|
+
zergProxyUrl: route.routerOrigin ?? config.get().zergProxyUrl } }).useProxy;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
routed = route.authMode === 'zrouter';
|
|
44
|
+
}
|
|
45
|
+
return { provider: route.provider, model: route.model, routed: routed || isRouterOnlyProvider(route.provider) };
|
|
46
|
+
}
|
|
29
47
|
export function getEffectiveModel(ctx) {
|
|
30
48
|
return ctx.config.getModel?.() || ctx.config.get().model;
|
|
31
49
|
}
|
|
@@ -24,7 +24,7 @@ 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, profileDirectory, stillListed } from './provider_selection.js';
|
|
27
|
+
import { offerKeyedProviderSwitch, ownRouteModelSelection, profileDirectory, stillListed } from './provider_selection.js';
|
|
28
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
29
|
import { rememberedModel, rememberProviderModel } from '../../config/provider_models.js';
|
|
30
30
|
import { describeActiveRoute, describeConnection, describeKeyRow } from './credential_status.js';
|
|
@@ -1253,6 +1253,11 @@ function applySettingChange(ctx, setting, value, selection) {
|
|
|
1253
1253
|
break;
|
|
1254
1254
|
}
|
|
1255
1255
|
case 'model':
|
|
1256
|
+
// A selection that names its route (a pane running a route of its own) saves its provider and route with it.
|
|
1257
|
+
if (selection?.authMode) {
|
|
1258
|
+
ctx.config.setProvider(selection.provider);
|
|
1259
|
+
ctx.config.set('authMode', selection.authMode);
|
|
1260
|
+
}
|
|
1256
1261
|
ctx.config.set('model', value);
|
|
1257
1262
|
break;
|
|
1258
1263
|
case 'maxTokens': {
|
|
@@ -1913,8 +1918,12 @@ function selectionRoute(ctx, selection) {
|
|
|
1913
1918
|
/** The provider, model and route a provider or model row selects. */
|
|
1914
1919
|
async function plannedModelSelection(ctx, setting, value) {
|
|
1915
1920
|
const current = ctx.config.getProvider();
|
|
1916
|
-
if (setting === 'model')
|
|
1917
|
-
|
|
1921
|
+
if (setting === 'model') {
|
|
1922
|
+
// A pane running a route of its own saves that provider and route with the model, so the default stays a pair.
|
|
1923
|
+
const own = ownRouteModelSelection(ctx, value);
|
|
1924
|
+
return own ? { provider: own[1], model: value, authMode: own[0] === 'zergrouter' ? 'zrouter' : 'direct' }
|
|
1925
|
+
: { provider: current, model: value };
|
|
1926
|
+
}
|
|
1918
1927
|
const choice = value.startsWith(ROUTER_CHOICE_PREFIX) ? value.slice(ROUTER_CHOICE_PREFIX.length) : value;
|
|
1919
1928
|
if (isRetiredProvider(choice))
|
|
1920
1929
|
throw new Error(retiredProviderMessage(choice, current));
|
|
@@ -32,6 +32,20 @@ export interface ConfigController {
|
|
|
32
32
|
locationLabel?: string;
|
|
33
33
|
/** The profile's config.json; the models remembered per provider live beside it. */
|
|
34
34
|
getConfigPath?: () => string;
|
|
35
|
+
/** The route a new pane starts on, never this pane's own (see ConfigStore.getNewPaneRoute). */
|
|
36
|
+
getNewPaneRoute?: () => {
|
|
37
|
+
provider: string;
|
|
38
|
+
model: string;
|
|
39
|
+
authMode: ZTCAuthMode;
|
|
40
|
+
routerOrigin?: string;
|
|
41
|
+
};
|
|
42
|
+
/** This pane's own route, while it runs one apart from the configured route (see ConfigStore.getPaneRoute). */
|
|
43
|
+
getPaneRoute?: () => {
|
|
44
|
+
provider: string;
|
|
45
|
+
model: string;
|
|
46
|
+
authMode: ZTCAuthMode;
|
|
47
|
+
routerOrigin?: string;
|
|
48
|
+
} | undefined;
|
|
35
49
|
get: () => ZTCConfig;
|
|
36
50
|
set: <K extends keyof ZTCConfig>(key: K, value: ZTCConfig[K]) => void;
|
|
37
51
|
setGlobal?: <K extends keyof ZTCConfig>(key: K, value: ZTCConfig[K]) => void;
|
|
@@ -466,13 +480,19 @@ export interface CommandContext {
|
|
|
466
480
|
*/
|
|
467
481
|
setRuntimeModelOverride?: (provider: string, model: string, authMode?: ZTCAuthMode) => boolean | void;
|
|
468
482
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
483
|
+
* Switch this pane alone to a route: nothing is saved, and new panes start where they did (a pane header's menus).
|
|
484
|
+
* Refused (`blocked`) when an agent turn started meanwhile; not `ok` when the pane couldn't rebuild on the route,
|
|
485
|
+
* which it then says why, keeping the route it ran on.
|
|
471
486
|
*/
|
|
472
|
-
|
|
487
|
+
applyPaneRoute?: (route: {
|
|
473
488
|
provider: string;
|
|
474
489
|
model: string;
|
|
475
|
-
|
|
490
|
+
authMode: ZTCAuthMode;
|
|
491
|
+
}) => Promise<{
|
|
492
|
+
ok: boolean;
|
|
493
|
+
blocked?: boolean;
|
|
494
|
+
message?: string;
|
|
495
|
+
}>;
|
|
476
496
|
restartZtc?: () => void | Promise<void>;
|
|
477
497
|
setDebug: (debug: boolean) => void;
|
|
478
498
|
retry: () => void;
|