@zergai/ztc 0.18.0-beta.1 → 0.18.2-dev.202611110225

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.
Files changed (37) hide show
  1. package/bin/zmux-darwin-arm64 +0 -0
  2. package/bin/ztc-audio-darwin-arm64 +0 -0
  3. package/bin/ztc-capture-darwin-arm64 +0 -0
  4. package/bin/ztc-computer-darwin-arm64 +0 -0
  5. package/bin/ztc-llm-darwin-arm64 +0 -0
  6. package/bin/ztc-tts-darwin-arm64 +0 -0
  7. package/bin/ztc-tui-darwin-arm64 +0 -0
  8. package/bin/zterm-darwin-arm64 +1 -1
  9. package/dist/App.js +3 -1
  10. package/dist/agent/backends/index.js +14 -5
  11. package/dist/agent/backends/provider_ids.d.ts +13 -0
  12. package/dist/agent/backends/provider_ids.js +19 -0
  13. package/dist/agent/commands/config.d.ts +8 -3
  14. package/dist/agent/commands/config.js +72 -23
  15. package/dist/agent/commands/credential_status.js +23 -12
  16. package/dist/agent/commands/model.js +7 -2
  17. package/dist/agent/commands/models.js +4 -3
  18. package/dist/agent/commands/provider_choices.d.ts +62 -1
  19. package/dist/agent/commands/provider_choices.js +90 -6
  20. package/dist/agent/commands/reasoning_settings.d.ts +1 -1
  21. package/dist/agent/commands/reasoning_settings.js +5 -5
  22. package/dist/agent/commands/settings.js +4 -6
  23. package/dist/agent/factory.js +9 -5
  24. package/dist/app/agent_runner.js +8 -3
  25. package/dist/cli_ratatui.js +28 -11
  26. package/dist/config/defaults.d.ts +5 -2
  27. package/dist/config/defaults.js +8 -4
  28. package/dist/config.d.ts +17 -5
  29. package/dist/config.js +26 -9
  30. package/dist/headless.js +6 -2
  31. package/dist/headless_cli.js +21 -2
  32. package/dist/headless_cli_args.js +2 -10
  33. package/dist/onboarding/setup_agent_health.js +4 -0
  34. package/dist/utils/reasoning.d.ts +5 -0
  35. package/dist/utils/reasoning.js +7 -3
  36. package/dist/zlm-embed.mjs +86 -21
  37. package/package.json +9 -14
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/zterm-darwin-arm64
3
3
  size: 33730352 bytes
4
- sha256: 598ea3aa4997631a8e4df6deabd3cd3e32c3a4bcad0dd6e3b6f160c3dc2a4299
4
+ sha256: d9b491a5c2e99773b153ebd23b926f3e9d5bd1663641fa65ca0586d20cb5d6c9
package/dist/App.js CHANGED
@@ -62,6 +62,7 @@ import { compactMessages, localSummarizer } from './utils/compaction.js';
62
62
  import { speak, optionsFromConfig, isProviderAvailable } from './utils/tts.js';
63
63
  import { applyAgentEventToState, buildActivityDisplayState, formatApiRetryNotice, getAgentActivityPlaceholder } from './app/activity.js';
64
64
  import { buildCredentialSetupMessage, buildNoCredentialsWelcome, buildReadyWelcome, createFirstRunLaunchMessage, isFirstRunWelcomeMessage, } from './onboarding/first_run.js';
65
+ import { currentRouterOnlyModelError } from './agent/commands/provider_choices.js';
65
66
  // --- Utilities ---
66
67
  const generateId = () => Math.random().toString(36).slice(2, 11);
67
68
  const ESCAPE_CONFIRMATION_HINT = 'Esc again to stop';
@@ -1796,7 +1797,8 @@ export const App = () => {
1796
1797
  addMessage({ role: 'user', content: text });
1797
1798
  addMessage({
1798
1799
  role: 'system',
1799
- content: buildCredentialSetupMessage(),
1800
+ // A model only Zerg Router serves needs no key here: it names itself and the step that reaches it.
1801
+ content: currentRouterOnlyModelError(configStore)?.message ?? buildCredentialSetupMessage(),
1800
1802
  });
1801
1803
  return;
1802
1804
  }
@@ -27,7 +27,7 @@ import { CodexAuthManager, CodexAuthBackend } from './codex_auth.js';
27
27
  import { ClarifaiBackend } from './clarifai.js';
28
28
  import { KimiCodeAuthBackend, KimiCodeAuthManager } from './kimi_code_auth.js';
29
29
  import { ZRouterStreamBackend } from './zrouter_stream.js';
30
- import { CODEX_APP_SERVER_PROVIDER, CODEX_LEGACY_PROVIDER, normalizeProviderId } from './provider_ids.js';
30
+ import { CODEX_APP_SERVER_PROVIDER, CODEX_LEGACY_PROVIDER, isDirectBackendProvider, normalizeProviderId } from './provider_ids.js';
31
31
  import { writeBackendTrace } from './trace.js';
32
32
  import { assertProviderNotRetired } from '../../config/retired_routes.js';
33
33
  export class TracedBackend {
@@ -128,10 +128,17 @@ export function createBackendForProvider(provider, opts) {
128
128
  // sign-in for Claude Code itself. Say where to go instead of "unknown provider".
129
129
  assertProviderNotRetired(provider);
130
130
  const resolvedProvider = normalizeProviderId(provider);
131
+ if (resolvedProvider === 'modal') {
132
+ throw new Error('Modal requires a Zerg Router backend. Run ztc auth login and use the routed agent factory.');
133
+ }
134
+ if (!isDirectBackendProvider(resolvedProvider)) {
135
+ throw new Error(`Unknown provider: ${provider}. Select a Router integration or a supported direct provider.`);
136
+ }
137
+ // Typed against DIRECT_BACKEND_PROVIDERS: a case missing from the list, or a
138
+ // listed provider with no case, does not compile, so hasDirectBackend and
139
+ // this switch cannot disagree.
131
140
  switch (resolvedProvider) {
132
141
  case 'bedrock': return traced(provider, new BedrockBackend(opts.bedrock));
133
- case 'modal':
134
- throw new Error('Modal requires a Zerg Router backend. Run ztc auth login and use the routed agent factory.');
135
142
  case 'openai':
136
143
  return traced(provider, new OpenAIBackend({ apiKey: opts.apiKey, apiEndpoint: opts.apiEndpoint }));
137
144
  case 'gemini':
@@ -194,7 +201,9 @@ export function createBackendForProvider(provider, opts) {
194
201
  case 'anthropic':
195
202
  case 'claude':
196
203
  return traced(provider, new AnthropicBackend({ apiKey: opts.apiKey, apiEndpoint: opts.apiEndpoint }));
197
- default:
198
- throw new Error(`Unknown provider: ${provider}. Select a Router integration or a supported direct provider.`);
204
+ default: {
205
+ const unbuilt = resolvedProvider;
206
+ throw new Error(`Unknown provider: ${String(unbuilt)}. Select a Router integration or a supported direct provider.`);
207
+ }
199
208
  }
200
209
  }
@@ -13,3 +13,16 @@ export declare function getProviderDisplayName(provider: string): string;
13
13
  * route direct, never through Zerg Router, and switch accounts in /accounts.
14
14
  */
15
15
  export declare function isLocalSubscriptionProvider(provider: string): boolean;
16
+ /**
17
+ * Every provider id createBackendForProvider builds a backend for, in each
18
+ * spelling it accepts (after normalizeProviderId). Its switch is typed against
19
+ * this list, so the compiler keeps the two the same. Modal is not here: its
20
+ * endpoints run only through Zerg Router, like every provider Router serves
21
+ * that ZTC has no backend of its own for.
22
+ */
23
+ export declare const DIRECT_BACKEND_PROVIDERS: readonly ["bedrock", "openai", "gemini", "inception", "openai_compatible", "kimi", "moonshot", "deepseek", "fireworks", "clarifai", "codex_app_server", "codex_legacy", "kimi_code", "kimi-code", "anthropic", "claude"];
24
+ export type DirectBackendProvider = (typeof DIRECT_BACKEND_PROVIDERS)[number];
25
+ /** True when `id`, already normalized, names a provider ZTC builds a backend for itself. */
26
+ export declare function isDirectBackendProvider(id: string): id is DirectBackendProvider;
27
+ /** True when ZTC can reach `provider` without Zerg Router, with a key, an endpoint or a local login. */
28
+ export declare function hasDirectBackend(provider: string): boolean;
@@ -46,3 +46,22 @@ export function isLocalSubscriptionProvider(provider) {
46
46
  return ['codex_app_server', 'codex_legacy', 'kimi_code', 'kimi-code']
47
47
  .includes(normalizeProviderId(provider));
48
48
  }
49
+ /**
50
+ * Every provider id createBackendForProvider builds a backend for, in each
51
+ * spelling it accepts (after normalizeProviderId). Its switch is typed against
52
+ * this list, so the compiler keeps the two the same. Modal is not here: its
53
+ * endpoints run only through Zerg Router, like every provider Router serves
54
+ * that ZTC has no backend of its own for.
55
+ */
56
+ export const DIRECT_BACKEND_PROVIDERS = [
57
+ 'bedrock', 'openai', 'gemini', 'inception', 'openai_compatible', 'kimi', 'moonshot', 'deepseek', 'fireworks',
58
+ 'clarifai', CODEX_APP_SERVER_PROVIDER, CODEX_LEGACY_PROVIDER, 'kimi_code', 'kimi-code', 'anthropic', 'claude',
59
+ ];
60
+ /** True when `id`, already normalized, names a provider ZTC builds a backend for itself. */
61
+ export function isDirectBackendProvider(id) {
62
+ return DIRECT_BACKEND_PROVIDERS.includes(id);
63
+ }
64
+ /** True when ZTC can reach `provider` without Zerg Router, with a key, an endpoint or a local login. */
65
+ export function hasDirectBackend(provider) {
66
+ return isDirectBackendProvider(normalizeProviderId(provider));
67
+ }
@@ -1,4 +1,4 @@
1
- import { Command } from './types.js';
1
+ import { Command, type ConfigController } from './types.js';
2
2
  import { type ZTCAuthMode } from '../../config/types.js';
3
3
  import type { ResolvedLLMConfig } from '../../config/resolved.js';
4
4
  /**
@@ -11,8 +11,13 @@ import type { ResolvedLLMConfig } from '../../config/resolved.js';
11
11
  * dishonest "✓".
12
12
  */
13
13
  export declare function isBuildableResolvedConfig(resolved: ResolvedLLMConfig): boolean;
14
- /** Actionable error shown when a provider/model switch can't build a backend. */
15
- export declare function unbuildableSelectionMessage(provider: string): string;
14
+ /**
15
+ * Actionable error shown when a provider/model switch can't build a backend.
16
+ * `route` is the switch as it resolved: for a provider only Zerg Router serves,
17
+ * its routing mode says which step reaches it, and `config` reads Router's
18
+ * cached catalog, which can say Router serves it.
19
+ */
20
+ export declare function unbuildableSelectionMessage(provider: string, route?: Pick<ResolvedLLMConfig, 'model' | 'authMode'>, config?: Pick<ConfigController, 'getRouterCatalog'>): string;
16
21
  export declare function parseConfigKeyArgs(args: string[], currentProvider: string): {
17
22
  provider: string;
18
23
  apiKey: string;
@@ -6,20 +6,21 @@ import { openFactoryResetConfirmation, settingsCommand } from './settings.js';
6
6
  import { contextProgressBarConfig, normalizeBarColor, publishContextProgressBar, withBarColor, } from './context_progress_bar.js';
7
7
  import { compatEndpoint, DEFAULT_CONTEXT_PROGRESS_BAR, maskApiKey } from '../../config.js';
8
8
  import { parseGoalTurnCap } from './goal.js';
9
- import { getSupportedCodexReasoningEfforts, isCodexReasoningEffortSupported, unsupportedEffortMessage, } from '../../utils/models.js';
9
+ import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage, } from '../../utils/models.js';
10
10
  import { modelForProviderSwitch } from './provider_model_defaults.js';
11
11
  import { CLAUDE_CODE_TOKEN_MESSAGE, isClaudeCodeToken, isRetiredProvider, retiredProviderMessage } from '../../config/retired_routes.js';
12
12
  import { applyRuntimeModelSelection, getEffectiveModel } from './runtime_model.js';
13
13
  import { shutdownAndClearWorkflowRegistry } from '../../workflows/registry_handle.js';
14
14
  import { formatRate } from '../../utils/openrouter_prices.js';
15
- import { API_KEY_PROVIDER_CHOICES, canonicalProvider, describeKeySource, isLocalSubscription, PROVIDER_CHOICES, } from './provider_choices.js';
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
18
  import { offerKeyedProviderSwitch } from './provider_selection.js';
19
19
  import { connectionStatusLines } from './credential_status.js';
20
20
  import { normalizeProviderId } from '../backends/provider_ids.js';
21
- import { resolveCodexEffort } from '../../config/defaults.js';
22
- import { formatReasoningEffort } from '../../utils/reasoning.js';
21
+ import { unsupportedCodexEffort } from '../../config/defaults.js';
22
+ import { activeReasoning } from './reasoning_settings.js';
23
+ import { formatReasoningEffort, reasoningContractChoices } from '../../utils/reasoning.js';
23
24
  import { DEFAULT_MESSAGE_DISPLAY, MIN_TOOL_OUTPUT_LINES, parseToolOutputLines, resolveMessageDisplaySettings, } from '../../config/message_display.js';
24
25
  import { DEFAULT_STATUS_LINE_SETTINGS, STATUS_LINE_ITEMS, STATUS_LINE_ITEM_DESCRIPTIONS, STATUS_LINE_VARIANTS, compactStatusLineVariants, formatStatusLineSettings, normalizeStatusLineSeparator, parseStatusLineItems, parseStatusLineVariant, resolveStatusLineSettings, resolveStatusLineVariants, statusLineSettingsForStorage, } from '../../ui/status_line_config.js';
25
26
  import { offerReasoningPicker } from './reasoning_picker.js';
@@ -33,7 +34,10 @@ import { offerReasoningPicker } from './reasoning_picker.js';
33
34
  * dishonest "✓".
34
35
  */
35
36
  export function isBuildableResolvedConfig(resolved) {
36
- if (resolved.provider === 'modal')
37
+ // Modal, and any provider ZTC has no backend of its own for, runs only through
38
+ // Zerg Router, whatever key is set here (one lent from another provider's
39
+ // variable included): the factory refuses any other route.
40
+ if (isRouterOnlyProvider(resolved.provider))
37
41
  return resolved.useProxy;
38
42
  const directKeyAvailable = Boolean(resolved.apiKey && resolved.apiKey.length > 0)
39
43
  || (resolved.provider === 'openai_compatible' && Boolean(resolved.compatBaseUrl));
@@ -44,11 +48,42 @@ export function isBuildableResolvedConfig(resolved) {
44
48
  // Platform-authenticated ZergAPI fallback — only when routing isn't forced direct.
45
49
  return resolved.authMode !== 'direct' && Boolean(resolved.authToken);
46
50
  }
47
- /** Actionable error shown when a provider/model switch can't build a backend. */
48
- export function unbuildableSelectionMessage(provider) {
49
- if (provider === 'modal' || provider === 'zergrouter') {
50
- return `Can't switch to ${provider}: it runs through Zerg Router. Log in with ZergAI (/auth login). Keeping the current selection.`;
51
- }
51
+ /**
52
+ * A Router model's reasoning levels, for its own `/config effort model`
53
+ * setting: its catalog row's, read through the contract of the route it runs
54
+ * on (getReasoningContract), whatever model is active. A provider only Zerg
55
+ * Router serves has no other route, so its row's levels hold while its route
56
+ * isn't Router too (the session expired, or routing is set to direct).
57
+ * Undefined for a model with no Router row, or one of a provider with a route
58
+ * of its own that isn't Zerg Router now.
59
+ */
60
+ function routerModelChoices(ctx, model) {
61
+ const catalog = ctx.config.getRouterCatalog?.();
62
+ const rows = catalog?.version === 1 ? catalog.models.filter(row => row.id === model) : [];
63
+ const owners = [...new Set(rows.map(row => row.owned_by))];
64
+ if (owners.length !== 1)
65
+ return undefined;
66
+ if (isRouterOnlyProvider(owners[0]))
67
+ return rows[0].capabilities?.reasoning?.choices ?? [];
68
+ const contract = ctx.config.getReasoningContract?.(owners[0], model);
69
+ return contract === undefined || typeof contract === 'string' ? undefined : reasoningContractChoices(owners[0], model, contract);
70
+ }
71
+ /** The levels any of `provider`'s rows in Router's cached catalog takes, as Router spells them. */
72
+ function routerProviderChoices(ctx, provider) {
73
+ const catalog = ctx.config.getRouterCatalog?.();
74
+ return catalog?.version === 1
75
+ ? catalog.models.filter(row => row.owned_by === provider).flatMap(row => row.capabilities?.reasoning?.choices ?? []) : [];
76
+ }
77
+ /**
78
+ * Actionable error shown when a provider/model switch can't build a backend.
79
+ * `route` is the switch as it resolved: for a provider only Zerg Router serves,
80
+ * its routing mode says which step reaches it, and `config` reads Router's
81
+ * cached catalog, which can say Router serves it.
82
+ */
83
+ export function unbuildableSelectionMessage(provider, route, config) {
84
+ const routerOnly = routerOnlyModelError({ provider, model: route?.model ?? '', useProxy: false, authMode: route?.authMode ?? 'auto' }, config);
85
+ if (routerOnly)
86
+ return `Can't switch to ${provider}: it ${routerOnly.reason}. ${routerOnly.step}. Keeping the current selection.`;
52
87
  if (isLocalSubscription(provider)) {
53
88
  return `Can't switch to ${provider}: sign in through /accounts. Keeping the current selection.`;
54
89
  }
@@ -193,7 +228,7 @@ async function setConfigProvider(value, ctx, credentialPrompted = false) {
193
228
  if (!isBuildableResolvedConfig(llm)) {
194
229
  if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => setConfigProvider(provider, ctx, true)))
195
230
  return;
196
- ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(provider) });
231
+ ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(provider, llm, ctx.config) });
197
232
  return;
198
233
  }
199
234
  }
@@ -229,7 +264,7 @@ async function setConfigModel(value, ctx, credentialPrompted = false) {
229
264
  if (!isBuildableResolvedConfig(llm)) {
230
265
  if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => setConfigModel(value, ctx, true)))
231
266
  return;
232
- ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(activeProvider) });
267
+ ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(activeProvider, llm, ctx.config) });
233
268
  return;
234
269
  }
235
270
  ctx.config.set('model', value);
@@ -1046,15 +1081,24 @@ Usage: /config context-progress-bar <enabled|accent|warning|critical|track|reset
1046
1081
  : CODEX_REASONING_EFFORTS;
1047
1082
  const CLEAR_WORDS = ['clear', 'default', 'unset', 'reset'];
1048
1083
  const config = ctx.config.get();
1049
- const activeEffort = () => `Active (${config.provider} · ${config.model}): ${formatReasoningEffort(resolveCodexEffort(ctx.config.get(), config.provider, config.model))}`;
1084
+ // The active model's effort as its route applies it, as the status line reads it: a saved
1085
+ // level its Router row lacks is not applied, and says so.
1086
+ const activeEffort = () => {
1087
+ const { provider, model, current, contract } = activeReasoning(ctx);
1088
+ const notApplied = unsupportedCodexEffort(ctx.config.get(), provider, model, contract);
1089
+ return `Active (${provider} · ${model}): ${formatReasoningEffort(current)}`
1090
+ + (notApplied ? ` (${notApplied} not applied: this model doesn't take it)` : '');
1091
+ };
1050
1092
  const [scope, ...scopeRest] = rest;
1051
1093
  const scopeKey = (scope ?? '').toLowerCase();
1052
- const parseLevel = (raw) => {
1094
+ const parseLevel = (raw, levels = EFFORT_LEVELS) => {
1053
1095
  const v = raw.toLowerCase();
1054
1096
  if (CLEAR_WORDS.includes(v))
1055
1097
  return null; // explicit clear
1056
- if (EFFORT_LEVELS.includes(v))
1057
- return v;
1098
+ // A Router row may spell a level its own way; it is saved as the row spells it.
1099
+ const level = levels.find(choice => choice.toLowerCase() === v);
1100
+ if (level !== undefined)
1101
+ return level;
1058
1102
  return undefined; // invalid
1059
1103
  };
1060
1104
  // `/config effort` with no args → show current global + per-provider/model.
@@ -1095,19 +1139,24 @@ Usage: /config context-progress-bar <enabled|accent|warning|critical|track|reset
1095
1139
  // Per-model / per-provider form.
1096
1140
  if (scopeKey === 'model' || scopeKey === 'provider') {
1097
1141
  const [target, levelArg] = scopeRest;
1142
+ // A model's own setting takes that model's levels, never the active
1143
+ // model's: a Router model's are its catalog row's. A provider's takes
1144
+ // any level one of its models may, as Router spells its rows' too.
1145
+ const rowChoices = scopeKey === 'model' && target ? routerModelChoices(ctx, target) : undefined;
1146
+ const levels = scopeKey === 'model' ? rowChoices ?? CODEX_REASONING_EFFORTS
1147
+ : [...new Set([...CODEX_REASONING_EFFORTS, ...(target ? routerProviderChoices(ctx, target) : [])])];
1098
1148
  if (!target || !levelArg) {
1099
- ctx.addMessage({ role: 'system', content: `Usage: /config effort ${scopeKey} <${scopeKey}> <${EFFORT_LEVELS.join('|')}|clear>` });
1149
+ ctx.addMessage({ role: 'system', content: `Usage: /config effort ${scopeKey} <${scopeKey}> <${levels.join('|')}|clear>` });
1100
1150
  return;
1101
1151
  }
1102
- const level = parseLevel(levelArg);
1152
+ const level = parseLevel(levelArg, scopeKey === 'model' ? [...levels, ...CODEX_REASONING_EFFORTS] : levels);
1103
1153
  if (level === undefined) {
1104
- ctx.addMessage({ role: 'system', content: `Invalid effort "${levelArg}". Choose: ${EFFORT_LEVELS.join(', ')} (or clear).` });
1154
+ ctx.addMessage({ role: 'system', content: `Invalid effort "${levelArg}". Choose: ${levels.join(', ')} (or clear).` });
1105
1155
  return;
1106
1156
  }
1107
- if (scopeKey === 'model'
1108
- && level !== null
1109
- && !isCodexReasoningEffortSupported(undefined, target, level)) {
1110
- const supported = getSupportedCodexReasoningEfforts(target) ?? [];
1157
+ // Any other model keeps the reviewed tables, which know it under every provider it runs on.
1158
+ const supported = scopeKey === 'model' ? rowChoices ?? getSupportedCodexReasoningEfforts(target) : undefined;
1159
+ if (level !== null && supported !== undefined && !supported.includes(level)) {
1111
1160
  ctx.addMessage({
1112
1161
  role: 'system',
1113
1162
  content: unsupportedEffortMessage(target, level, supported),
@@ -30,13 +30,16 @@ export function describeActiveRoute(config) {
30
30
  const provider = config.getProvider();
31
31
  try {
32
32
  const llm = config.resolveLLMBackendConfig();
33
+ // A provider only Zerg Router serves reaches no model on any other route, whatever key is set here.
34
+ const offRouter = !llm.useProxy && isRouterOnlyProvider(llm.provider);
33
35
  const ready = isBuildableResolvedConfig(llm);
34
36
  // A custom endpoint may carry a key, but the endpoint is what it connects to.
35
37
  const kind = isLocalSubscription(provider) ? 'local-login'
36
38
  : llm.useProxy ? 'router'
37
- : provider === 'openai_compatible' && llm.compatBaseUrl ? 'endpoint'
38
- : llm.apiKey ? 'api-key'
39
- : ready ? 'platform' : 'none';
39
+ : offRouter ? 'none'
40
+ : provider === 'openai_compatible' && llm.compatBaseUrl ? 'endpoint'
41
+ : llm.apiKey ? 'api-key'
42
+ : ready ? 'platform' : 'none';
40
43
  return { kind, route: ROUTE_NAMES[kind], ready };
41
44
  }
42
45
  catch (error) {
@@ -60,17 +63,25 @@ export function readinessLine(config, route = describeActiveRoute(config)) {
60
63
  const provider = config.getProvider();
61
64
  const session = config.getRouterSessionStatus?.() ?? 'signed_out';
62
65
  const mode = routingMode(config);
63
- const needsRouter = session !== 'signed_in' && (mode === 'zrouter' || isRouterOnlyProvider(provider));
64
- const reason = needsRouter
65
- ? `${mode === 'zrouter' ? 'routing is Zerg Router only' : `${provider} runs through Zerg Router`} and ${session === 'expired' ? 'your ZergAI session expired' : 'you are not logged in with ZergAI'}`
66
- : isLocalSubscription(provider) ? `${provider} is not signed in on this machine`
67
- : provider === 'openai_compatible' ? 'the custom endpoint is not set up'
68
- : `${provider} has no API key here`;
66
+ const routerOnly = isRouterOnlyProvider(provider);
67
+ // Routing set to direct keeps a provider only Zerg Router serves off Router
68
+ // whether or not ZTC is logged in: no login, and no key here, reaches it.
69
+ const routingDirect = routerOnly && mode === 'direct';
70
+ const needsRouter = !routingDirect && session !== 'signed_in' && (mode === 'zrouter' || routerOnly);
71
+ const reason = routingDirect ? `${provider} runs through Zerg Router and routing is set to direct (local keys only)`
72
+ : needsRouter
73
+ ? `${mode === 'zrouter' ? 'routing is Zerg Router only' : `${provider} runs through Zerg Router`} and ${session === 'expired' ? 'your ZergAI session expired' : 'you are not logged in with ZergAI'}`
74
+ : isLocalSubscription(provider) ? `${provider} is not signed in on this machine`
75
+ : provider === 'openai_compatible' ? 'the custom endpoint is not set up'
76
+ : `${provider} has no API key here`;
77
+ const step = routingDirect ? 'set Routing to auto in /config' : needsRouter ? 'log in with /auth login' : 'add a key in /keys';
69
78
  // When routing is the block, the selected provider's own key counts too.
70
- const ready = modelRouteStatus(config).directProviders.filter(id => needsRouter || id !== provider);
79
+ const ready = modelRouteStatus(config).directProviders.filter(id => routingDirect || needsRouter || id !== provider);
71
80
  const next = ready.length > 0
72
- ? `Ready on this machine: ${ready.join(', ')}. Switch with /model direct ${ready[0]}, or ${needsRouter ? 'log in with /auth login' : 'add a key in /keys'}.`
73
- : needsRouter ? 'Log in with /auth login, or add an API key in /keys.' : 'Add a key in /keys, or log in with ZergAI (/auth login).';
81
+ ? `Ready on this machine: ${ready.join(', ')}. Switch with /model direct ${ready[0]}, or ${step}.`
82
+ // Neither a login nor a key here reaches it, only routing set back to auto.
83
+ : routingDirect ? 'Set Routing to auto in /config, or choose another model with /model.'
84
+ : needsRouter ? 'Log in with /auth login, or add an API key in /keys.' : 'Add a key in /keys, or log in with ZergAI (/auth login).';
74
85
  return `No - ${reason}. ${next}`;
75
86
  }
76
87
  /**
@@ -27,15 +27,20 @@ async function showModelRoutes(ctx) {
27
27
  // Router model ids already carry their provider (modal/deepseek-…).
28
28
  const selection = model.startsWith(`${provider}/`) ? model : `${provider}/${model}`;
29
29
  const routerOnly = isRouterOnlyProvider(provider);
30
+ // Routing set to direct keeps it off Zerg Router whether or not ZTC is logged
31
+ // in; otherwise it waits for a ZergAI login.
32
+ const routingDirect = ctx.config.getAuthMode?.() === 'direct';
30
33
  const lines = [
31
- `Current: ${selection} · ${routed ? 'ZergRouter' : routerOnly ? 'ZergRouter (log in with ZergAI)' : 'Local API key'}`,
34
+ `Current: ${selection} · ${routed ? 'ZergRouter' : routerOnly
35
+ ? `ZergRouter (${routingDirect ? 'routing is set to direct' : 'log in with ZergAI'})` : 'Local API key'}`,
32
36
  '',
33
37
  'Routes:',
34
38
  ...routes.map(([label, usage, detail]) => ` ${label.padEnd(width)} ${usage} · ${detail}`),
35
39
  ];
36
40
  lines.push('', `Models (${provider}):`);
37
41
  if (routerOnly && !routed) {
38
- lines.push(' Log in with ZergAI (/auth login) to list ZergRouter models.');
42
+ lines.push(routingDirect ? ' Set Routing to auto in /config to list ZergRouter models.'
43
+ : ' Log in with ZergAI (/auth login) to list ZergRouter models.');
39
44
  }
40
45
  else {
41
46
  try {
@@ -113,7 +113,7 @@ async function setModel(value, ctx, credentialPrompted = false) {
113
113
  if (!isBuildableResolvedConfig(llm)) {
114
114
  if (!credentialPrompted && promptForMissingDirectKey(llm, ctx, () => setModel(value, ctx, true)))
115
115
  return;
116
- ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(provider) });
116
+ ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(provider, llm, ctx.config) });
117
117
  return;
118
118
  }
119
119
  ctx.config.set('model', value);
@@ -153,8 +153,9 @@ async function listModels(subCmd, provider, ctx, credentialPrompted = false) {
153
153
  // ctx.config.getProvider() — so we don't persist a kimi id under
154
154
  // provider=openai and hot-swap into a 400-ing mismatch. Verify buildable
155
155
  // BEFORE persisting.
156
- if (!isBuildableResolvedConfig(ctx.config.resolveLLMBackendConfig({ provider, model: latest, asChosen: true }))) {
157
- ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(provider) });
156
+ const route = ctx.config.resolveLLMBackendConfig({ provider, model: latest, asChosen: true });
157
+ if (!isBuildableResolvedConfig(route)) {
158
+ ctx.addMessage({ role: 'system', content: unbuildableSelectionMessage(provider, route, ctx.config) });
158
159
  return;
159
160
  }
160
161
  const providerChanged = normalizeProviderId(provider) !== normalizeProviderId(ctx.config.getProvider());
@@ -1,6 +1,8 @@
1
+ import type { ZTCAuthMode } from '../../config/types.js';
1
2
  import type { RouterSessionStatus } from '../../router_auth.js';
2
3
  import type { ConfigController } from './types.js';
3
4
  import type { ApiKeySource } from '../../config/provider_api_key_env.js';
5
+ import type { RouterCatalog } from '../../utils/router_catalog.js';
4
6
  export declare const PROVIDER_CHOICES: ({
5
7
  id: string;
6
8
  label: string;
@@ -47,6 +49,14 @@ export interface ModelRouteStatus {
47
49
  /** Local providers that can build a backend now, in DIRECT_PROVIDER_CHOICES order. */
48
50
  directProviders?: readonly string[];
49
51
  }
52
+ /**
53
+ * Providers ZTC reaches only through Zerg Router: Router itself, and every
54
+ * provider Router may serve that ZTC has no backend of its own for (Modal,
55
+ * OpenRouter, and any provider Router adds, such as a bring-your-own-key one).
56
+ * Every other choice runs locally. A name ZTC accepts for a provider (`google`,
57
+ * `fireworks-ai`) counts as that provider.
58
+ */
59
+ export declare function isRouterOnlyProvider(provider: string): boolean;
50
60
  export declare const DIRECT_PROVIDER_CHOICES: ({
51
61
  id: string;
52
62
  label: string;
@@ -72,7 +82,58 @@ export declare const API_KEY_PROVIDER_CHOICES: ({
72
82
  })[];
73
83
  /** A provider's key state for a picker row. Names a variable, never a value. */
74
84
  export declare function describeKeySource(source: ApiKeySource): string;
75
- export declare function isRouterOnlyProvider(provider: string): boolean;
85
+ /**
86
+ * Whether anything here says Zerg Router serves `provider`: it is one ZTC
87
+ * knows, Router's catalog cached here lists it, or `model` is an id of the
88
+ * shape Router gives that provider's rows (`morph/morph-kimik31`). Otherwise,
89
+ * as for a mistyped name while signed out, it may be a provider Router serves
90
+ * or a name nobody serves.
91
+ */
92
+ export declare function routerServesProvider(provider: string, model: string | undefined, catalog: RouterCatalog | undefined): boolean;
93
+ /**
94
+ * A model of a provider ZTC reaches only through Zerg Router, on a route that
95
+ * is not Zerg Router: ZTC isn't logged in to Router, or routing is set to
96
+ * direct. The message names the model with its provider and the one step that
97
+ * fixes it. A provider nothing says Router serves (`served` false) is an
98
+ * unknown provider, as it was before Router could serve providers ZTC doesn't
99
+ * know, possibly a mistyped name.
100
+ */
101
+ export declare class RouterOnlyModelError extends Error {
102
+ readonly provider: string;
103
+ readonly model: string;
104
+ readonly authMode: ZTCAuthMode;
105
+ readonly served: boolean;
106
+ /** Why the model can't run here, after its subject: "runs through Zerg Router, and …". */
107
+ readonly reason: string;
108
+ /** The step that reaches it, as a sentence. */
109
+ readonly step: string;
110
+ constructor(provider: string, model: string, authMode: ZTCAuthMode, served?: boolean);
111
+ }
112
+ /**
113
+ * Why a resolved route can't run its model: the provider runs only through
114
+ * Zerg Router and the route isn't Zerg Router. Undefined when it can. `config`
115
+ * reads Router's cached catalog, which can say Router serves the provider.
116
+ */
117
+ export declare function routerOnlyModelError(route: {
118
+ provider: string;
119
+ model: string;
120
+ useProxy: boolean;
121
+ authMode: ZTCAuthMode;
122
+ }, config?: Pick<ConfigController, 'getRouterCatalog'>): RouterOnlyModelError | undefined;
123
+ /**
124
+ * The RouterOnlyModelError the agent factory raises for the current route (or
125
+ * `route`), for a place that has no agent to ask: a gate before one is built
126
+ * (a missing key, say), or a profile switch that built none. Undefined when the
127
+ * route can run its model or doesn't resolve, and for Modal: a new profile's
128
+ * default route, it waits for a ZergAI login as a missing key waits for a key,
129
+ * so those places show every way to connect.
130
+ */
131
+ export declare function currentRouterOnlyModelError(config: Pick<ConfigController, 'resolveLLMBackendConfig' | 'getRouterCatalog'>, route?: {
132
+ provider: string;
133
+ model: string;
134
+ useProxy: boolean;
135
+ authMode: ZTCAuthMode;
136
+ }): RouterOnlyModelError | undefined;
76
137
  export declare function canonicalRoute(value: string): ModelRoute | undefined;
77
138
  export declare function describeRouterRoute(session: RouterSessionStatus): string;
78
139
  export declare function describeDirectRoute(readyProviders: readonly string[]): string;
@@ -1,4 +1,4 @@
1
- import { isLocalSubscriptionProvider, normalizeProviderId } from '../backends/provider_ids.js';
1
+ import { hasDirectBackend, isLocalSubscriptionProvider, normalizeProviderId } from '../backends/provider_ids.js';
2
2
  import { RETIRED_PROVIDER_IDS } from '../../config/retired_ids.js';
3
3
  import { ZERGAI_LOGIN_PITCH } from '../../onboarding/zergai_login.js';
4
4
  export const PROVIDER_CHOICES = [
@@ -61,9 +61,18 @@ export const MODEL_ROUTE_CHOICES = [
61
61
  { id: 'zergrouter', label: 'ZergRouter', aliases: ['zrouter', 'router'] },
62
62
  { id: 'direct', label: 'Local API key', aliases: ['own', 'byok', 'apikey', 'api-key', 'keys', 'local-key'] },
63
63
  ];
64
- /** Providers served only through Zerg Router; every other choice runs locally. */
65
- const ROUTER_ONLY_PROVIDERS = new Set(['zergrouter', 'modal', 'openrouter']);
66
- export const DIRECT_PROVIDER_CHOICES = PROVIDER_CHOICES.filter(choice => !ROUTER_ONLY_PROVIDERS.has(choice.id));
64
+ /**
65
+ * Providers ZTC reaches only through Zerg Router: Router itself, and every
66
+ * provider Router may serve that ZTC has no backend of its own for (Modal,
67
+ * OpenRouter, and any provider Router adds, such as a bring-your-own-key one).
68
+ * Every other choice runs locally. A name ZTC accepts for a provider (`google`,
69
+ * `fireworks-ai`) counts as that provider.
70
+ */
71
+ export function isRouterOnlyProvider(provider) {
72
+ const id = canonicalProvider(provider) ?? normalizeProviderId(provider);
73
+ return id === 'zergrouter' || (canRouteThroughRouter(id) && !hasDirectBackend(id));
74
+ }
75
+ export const DIRECT_PROVIDER_CHOICES = PROVIDER_CHOICES.filter(choice => !isRouterOnlyProvider(choice.id));
67
76
  /** Providers reached with an API key alone: no local login, endpoint or Router. */
68
77
  export const API_KEY_PROVIDER_CHOICES = DIRECT_PROVIDER_CHOICES
69
78
  .filter(choice => !isLocalSubscription(choice.id) && choice.id !== 'openai_compatible');
@@ -79,8 +88,83 @@ export function describeKeySource(source) {
79
88
  case 'none': return 'No key';
80
89
  }
81
90
  }
82
- export function isRouterOnlyProvider(provider) {
83
- return ROUTER_ONLY_PROVIDERS.has(provider);
91
+ /** Providers ZTC itself knows only Zerg Router serves: Router, Modal's shared endpoints and OpenRouter. */
92
+ const KNOWN_ROUTER_PROVIDERS = new Set(['zergrouter', 'modal', 'openrouter']);
93
+ /**
94
+ * Whether anything here says Zerg Router serves `provider`: it is one ZTC
95
+ * knows, Router's catalog cached here lists it, or `model` is an id of the
96
+ * shape Router gives that provider's rows (`morph/morph-kimik31`). Otherwise,
97
+ * as for a mistyped name while signed out, it may be a provider Router serves
98
+ * or a name nobody serves.
99
+ */
100
+ export function routerServesProvider(provider, model, catalog) {
101
+ const id = canonicalProvider(provider) ?? normalizeProviderId(provider);
102
+ return KNOWN_ROUTER_PROVIDERS.has(id) || Boolean(model?.startsWith(`${id}/`))
103
+ || Boolean(catalog?.models.some(row => row.owned_by === id));
104
+ }
105
+ /**
106
+ * A model of a provider ZTC reaches only through Zerg Router, on a route that
107
+ * is not Zerg Router: ZTC isn't logged in to Router, or routing is set to
108
+ * direct. The message names the model with its provider and the one step that
109
+ * fixes it. A provider nothing says Router serves (`served` false) is an
110
+ * unknown provider, as it was before Router could serve providers ZTC doesn't
111
+ * know, possibly a mistyped name.
112
+ */
113
+ export class RouterOnlyModelError extends Error {
114
+ provider;
115
+ model;
116
+ authMode;
117
+ served;
118
+ /** Why the model can't run here, after its subject: "runs through Zerg Router, and …". */
119
+ reason;
120
+ /** The step that reaches it, as a sentence. */
121
+ step;
122
+ constructor(provider, model, authMode, served = true) {
123
+ const step = authMode === 'direct' ? 'set Routing to auto in /config' : 'log in with /auth login';
124
+ const reason = !served ? "isn't a provider ZTC reaches directly"
125
+ : authMode === 'direct' ? 'runs through Zerg Router, and routing is set to direct (local keys only)'
126
+ : "runs through Zerg Router, and ZTC isn't logged in to it";
127
+ const fix = served ? `${step[0].toUpperCase()}${step.slice(1)}` : `If Zerg Router serves it, ${step}; otherwise check the name`;
128
+ // Router model ids may carry their provider already (morph/morph-kimik31), as /model shows them.
129
+ const subject = model.startsWith(`${provider}/`) ? model : `${provider}/${model}`;
130
+ super(served ? `${subject} ${reason}. ${fix}, or choose another model with /model.`
131
+ : `Unknown provider: ${provider}. ${fix}, or choose another model with /model.`);
132
+ this.provider = provider;
133
+ this.model = model;
134
+ this.authMode = authMode;
135
+ this.served = served;
136
+ this.name = 'RouterOnlyModelError';
137
+ this.reason = reason;
138
+ this.step = fix;
139
+ }
140
+ }
141
+ /**
142
+ * Why a resolved route can't run its model: the provider runs only through
143
+ * Zerg Router and the route isn't Zerg Router. Undefined when it can. `config`
144
+ * reads Router's cached catalog, which can say Router serves the provider.
145
+ */
146
+ export function routerOnlyModelError(route, config) {
147
+ if (route.useProxy || !isRouterOnlyProvider(route.provider))
148
+ return undefined;
149
+ const served = routerServesProvider(route.provider, route.model, config?.getRouterCatalog?.());
150
+ return new RouterOnlyModelError(route.provider, route.model, route.authMode, served);
151
+ }
152
+ /**
153
+ * The RouterOnlyModelError the agent factory raises for the current route (or
154
+ * `route`), for a place that has no agent to ask: a gate before one is built
155
+ * (a missing key, say), or a profile switch that built none. Undefined when the
156
+ * route can run its model or doesn't resolve, and for Modal: a new profile's
157
+ * default route, it waits for a ZergAI login as a missing key waits for a key,
158
+ * so those places show every way to connect.
159
+ */
160
+ export function currentRouterOnlyModelError(config, route) {
161
+ try {
162
+ const resolved = route ?? config.resolveLLMBackendConfig();
163
+ return normalizeProviderId(resolved.provider) === 'modal' ? undefined : routerOnlyModelError(resolved, config);
164
+ }
165
+ catch {
166
+ return undefined;
167
+ }
84
168
  }
85
169
  export function canonicalRoute(value) {
86
170
  const normalized = value.trim().toLowerCase();
@@ -9,7 +9,7 @@ export declare function activeReasoning(ctx: CommandContext): {
9
9
  /** Effort and thinking are checked against this: Router's catalog for a Router model, else the reviewed contract. */
10
10
  contract: ReasoningContract;
11
11
  /** The model's levels; undefined when nothing says which it takes. */
12
- supported: string[] | readonly ("none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra")[] | undefined;
12
+ supported: readonly string[] | undefined;
13
13
  /** The saved effort this model runs with, if any. */
14
14
  current: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "ultra" | undefined;
15
15
  status: () => string;