@zergai/ztc 0.23.0-beta.1 → 0.24.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 +299 -13
- 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/agent.js +57 -14
- package/dist/agent/backends/http_error.d.ts +2 -0
- package/dist/agent/backends/http_error.js +2 -0
- package/dist/agent/backends/router_gate.d.ts +3 -2
- package/dist/agent/backends/router_gate.js +5 -4
- package/dist/agent/backends/router_keys.d.ts +14 -0
- package/dist/agent/backends/router_keys.js +19 -0
- package/dist/agent/backends/router_refusal.d.ts +5 -3
- package/dist/agent/backends/router_refusal.js +28 -6
- package/dist/agent/backends/types.d.ts +1 -1
- package/dist/agent/backends/zrouter_stream.js +10 -6
- package/dist/agent/commands/agent_cli.d.ts +11 -1
- package/dist/agent/commands/agent_cli.js +295 -38
- package/dist/agent/commands/diff.js +4 -1
- package/dist/agent/commands/help.js +4 -1
- package/dist/agent/commands/plan.js +3 -1
- package/dist/agent/commands/session_redaction.d.ts +16 -0
- package/dist/agent/commands/session_redaction.js +77 -0
- package/dist/agent/commands/settings.js +144 -0
- package/dist/agent/commands/types.d.ts +5 -0
- package/dist/agent/commands/usage_spec.d.ts +4 -0
- package/dist/agent/commands/usage_spec.js +10 -4
- package/dist/agent/runtime/policy.d.ts +25 -0
- package/dist/agent/runtime/policy.js +154 -26
- package/dist/agent/runtime/source_verification.js +6 -2
- package/dist/agent/runtime/tool_runtime.js +81 -3
- package/dist/agent/tools/apply_patch.js +678 -131
- package/dist/agent/tools/bus_message.d.ts +26 -1
- package/dist/agent/tools/bus_message.js +126 -10
- package/dist/agent/tools/file.d.ts +16 -1
- package/dist/agent/tools/file.js +43 -5
- package/dist/agent/tools/index.d.ts +1 -1
- package/dist/agent/tools/index.js +1 -1
- package/dist/agent/tools/pane.js +5 -0
- package/dist/agent/tools/search.js +5 -1
- package/dist/agent/tools/supervision.js +16 -2
- package/dist/agent/tools/types.d.ts +22 -0
- package/dist/app/mirror_startup.d.ts +7 -5
- package/dist/app/mirror_startup.js +7 -5
- package/dist/app/navigator_mirrors.d.ts +20 -0
- package/dist/app/navigator_mirrors.js +36 -0
- package/dist/app/workspace_layout_controller.d.ts +11 -2
- package/dist/app/workspace_layout_controller.js +13 -2
- package/dist/batch/worktree.js +9 -1
- package/dist/cli_ratatui.d.ts +264 -12
- package/dist/cli_ratatui.js +1198 -103
- package/dist/config/types.d.ts +29 -0
- package/dist/desktop/daily/source_baseline.js +3 -1
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +229 -26
- package/dist/emulation/tool_adapters.js +42 -5
- package/dist/headless.js +24 -5
- package/dist/instance_registry.d.ts +7 -0
- package/dist/mcp/workspace_server.d.ts +12 -1
- package/dist/mcp/workspace_server.js +75 -8
- package/dist/panes/agent_cli.d.ts +60 -3
- package/dist/panes/agent_cli.js +169 -16
- package/dist/panes/agent_pane_sessions.d.ts +22 -0
- package/dist/panes/agent_pane_sessions.js +111 -0
- package/dist/panes/agent_panes.d.ts +77 -3
- package/dist/panes/agent_panes.js +199 -10
- package/dist/panes/agent_profiles.d.ts +5 -0
- package/dist/panes/agent_profiles.js +7 -0
- package/dist/panes/agent_resume.d.ts +134 -0
- package/dist/panes/agent_resume.js +155 -0
- package/dist/panes/agent_sessions/claude_head.d.ts +32 -0
- package/dist/panes/agent_sessions/claude_head.js +122 -0
- package/dist/panes/agent_sessions/claude_store.d.ts +59 -0
- package/dist/panes/agent_sessions/claude_store.js +223 -0
- package/dist/panes/agent_sessions/codex_head.d.ts +55 -0
- package/dist/panes/agent_sessions/codex_head.js +161 -0
- package/dist/panes/agent_sessions/codex_store.d.ts +43 -0
- package/dist/panes/agent_sessions/codex_store.js +187 -0
- package/dist/panes/agent_sessions/controller.d.ts +74 -0
- package/dist/panes/agent_sessions/controller.js +110 -0
- package/dist/panes/agent_sessions/cut_json.d.ts +14 -0
- package/dist/panes/agent_sessions/cut_json.js +109 -0
- package/dist/panes/agent_sessions/limits.d.ts +48 -0
- package/dist/panes/agent_sessions/limits.js +48 -0
- package/dist/panes/agent_sessions/scan.d.ts +49 -0
- package/dist/panes/agent_sessions/scan.js +86 -0
- package/dist/panes/agent_sessions/store_fs.d.ts +51 -0
- package/dist/panes/agent_sessions/store_fs.js +128 -0
- package/dist/panes/agent_sessions/stores.d.ts +36 -0
- package/dist/panes/agent_sessions/stores.js +89 -0
- package/dist/panes/agent_sessions/title.d.ts +9 -0
- package/dist/panes/agent_sessions/title.js +51 -0
- package/dist/panes/agent_sessions/types.d.ts +48 -0
- package/dist/panes/agent_sessions/types.js +2 -0
- package/dist/panes/reply_arbitrator.d.ts +39 -0
- package/dist/panes/reply_arbitrator.js +185 -0
- package/dist/panes/reply_modes.d.ts +291 -0
- package/dist/panes/reply_modes.js +598 -0
- package/dist/runtime_info.js +11 -2
- package/dist/session.js +4 -2
- package/dist/simulation/living/context.d.ts +8 -8
- package/dist/simulation/living/types.d.ts +5 -5
- package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
- package/dist/ui/ratatui/ipc_path.d.ts +5 -0
- package/dist/ui/ratatui/ipc_path.js +23 -3
- package/dist/ui/ratatui/pane_credential_broker.d.ts +23 -8
- package/dist/ui/ratatui/pane_credential_broker.js +49 -14
- package/dist/ui/ratatui/pane_relay.d.ts +5 -2
- package/dist/ui/ratatui/pane_relay.js +86 -19
- package/dist/ui/ratatui/process.js +3 -0
- package/dist/ui/ratatui/protocol.d.ts +50 -1
- package/dist/ui/ratatui/protocol.js +56 -0
- package/dist/ui/ratatui/relay_policy.d.ts +39 -0
- package/dist/ui/ratatui/relay_policy.js +94 -0
- package/dist/ui/ratatui/screen_privacy.d.ts +15 -0
- package/dist/ui/ratatui/screen_privacy.js +24 -0
- package/dist/ui/scrollback.js +8 -0
- package/dist/ui/widgets/agent_sessions_panel.d.ts +139 -0
- package/dist/ui/widgets/agent_sessions_panel.js +542 -0
- package/dist/ui/widgets/log_view.d.ts +5 -1
- package/dist/ui/widgets/log_view.js +40 -4
- package/dist/utils/atomic_write.js +9 -11
- package/dist/utils/canonical_path.d.ts +19 -0
- package/dist/utils/canonical_path.js +44 -0
- package/dist/utils/compaction.d.ts +2 -1
- package/dist/utils/compaction.js +3 -1
- package/dist/utils/git_directory_names.d.ts +51 -0
- package/dist/utils/git_directory_names.js +429 -0
- package/dist/utils/temporary_write_root.d.ts +6 -1
- package/dist/utils/temporary_write_root.js +32 -2
- package/dist/utils/tool_result_message.d.ts +4 -1
- package/dist/utils/tool_result_message.js +6 -2
- package/dist/web/bus_hold.d.ts +70 -0
- package/dist/web/bus_hold.js +118 -0
- package/dist/web/mirror_client.d.ts +7 -3
- package/dist/web/mirror_client.js +61 -23
- package/dist/web/mirror_route_gate.d.ts +40 -0
- package/dist/web/mirror_route_gate.js +71 -0
- package/dist/web/mirror_stream.d.ts +147 -22
- package/dist/web/mirror_stream.js +350 -83
- package/dist/web/pane_credentials.d.ts +32 -1
- package/dist/web/pane_credentials.js +62 -2
- package/dist/workspace_collision.js +11 -2
- package/dist/zlm-embed.mjs +940 -273
- package/package.json +34 -12
|
@@ -54,8 +54,9 @@ export declare class RouterRefusalGate {
|
|
|
54
54
|
/** Router answered: whatever held this route and model is over. */
|
|
55
55
|
succeed(target: RouterGateTarget): void;
|
|
56
56
|
/**
|
|
57
|
-
* Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of
|
|
58
|
-
*
|
|
57
|
+
* Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of a usable
|
|
58
|
+
* key of its provider waited on (provider_key_unavailable, or a key stored broken or refused: provider_key_malformed,
|
|
59
|
+
* provider_key_rejected): the key has been added or replaced, so that hold is over and the next
|
|
59
60
|
* request for it reaches Router, a relayed one included. A model the catalog doesn't describe counts once any model
|
|
60
61
|
* of its provider can run. Every other hold stays. Only a catalog Router has just sent says so, never a cached one.
|
|
61
62
|
*/
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { createHash } from 'node:crypto';
|
|
23
23
|
import { resolveRouterModel } from '../../utils/router_catalog.js';
|
|
24
|
-
import {
|
|
24
|
+
import { PROVIDER_KEY_REFUSALS } from './router_keys.js';
|
|
25
25
|
import { RouterRefusalError } from './router_refusal.js';
|
|
26
26
|
/** At most one real attempt per held route and model in this long. */
|
|
27
27
|
export const ROUTER_REFUSAL_RETRY_MS = 5 * 60_000;
|
|
@@ -100,8 +100,9 @@ export class RouterRefusalGate {
|
|
|
100
100
|
this.store?.released(hold);
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
* Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of
|
|
104
|
-
*
|
|
103
|
+
* Router's catalog, just sent for this route and account, lists as one it can run a model a hold for want of a usable
|
|
104
|
+
* key of its provider waited on (provider_key_unavailable, or a key stored broken or refused: provider_key_malformed,
|
|
105
|
+
* provider_key_rejected): the key has been added or replaced, so that hold is over and the next
|
|
105
106
|
* request for it reaches Router, a relayed one included. A model the catalog doesn't describe counts once any model
|
|
106
107
|
* of its provider can run. Every other hold stays. Only a catalog Router has just sent says so, never a cached one.
|
|
107
108
|
*/
|
|
@@ -109,7 +110,7 @@ export class RouterRefusalGate {
|
|
|
109
110
|
if (catalog.version !== 1)
|
|
110
111
|
return;
|
|
111
112
|
for (const [key, hold] of this.holds) {
|
|
112
|
-
if (hold.refusal.code
|
|
113
|
+
if (!PROVIDER_KEY_REFUSALS.has(hold.refusal.code) || hold.route !== routerRoute(filter.route) || hold.account !== filter.account)
|
|
113
114
|
continue;
|
|
114
115
|
const row = resolveRouterModel(catalog, hold.provider, hold.model);
|
|
115
116
|
const runs = row ? row.available !== false
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
import type { RouterCatalog } from '../../utils/router_catalog.js';
|
|
14
14
|
/** Router's code for a provider it has no usable key for, so nothing was sent to it. */
|
|
15
15
|
export declare const PROVIDER_KEY_UNAVAILABLE = "provider_key_unavailable";
|
|
16
|
+
/**
|
|
17
|
+
* Router's codes for an account key it holds but can't use, so nothing was sent: one stored with a defect (an export
|
|
18
|
+
* line, a masked copy), or one its provider refused and that is cooling (zapps/zergrouter server/lib/missing-provider-key.ts).
|
|
19
|
+
*/
|
|
20
|
+
export declare const PROVIDER_KEY_MALFORMED = "provider_key_malformed";
|
|
21
|
+
export declare const PROVIDER_KEY_REJECTED = "provider_key_rejected";
|
|
22
|
+
/** Refusals the person ends by adding or replacing the provider's key: a list Router sends that runs it again ends them. */
|
|
23
|
+
export declare const PROVIDER_KEY_REFUSALS: ReadonlySet<string>;
|
|
16
24
|
/** Router's Credentials page on ORIGIN, where a person adds a provider's API key. */
|
|
17
25
|
export declare function routerCredentialsUrl(origin: string): string;
|
|
18
26
|
/** The name Router's catalog gives PROVIDER ("Morph"), if it lists one. */
|
|
@@ -40,6 +48,12 @@ export declare function routerKeyAdvice(target: RouterKeyTarget, addIt: string,
|
|
|
40
48
|
}): string;
|
|
41
49
|
/** What ZTC says when Router refused a request because it has no key for the provider: nothing reached it. */
|
|
42
50
|
export declare function missingRouterKeyMessage(target: RouterKeyTarget): string;
|
|
51
|
+
/**
|
|
52
|
+
* What ZTC says when Router holds the account's key for the provider but can't use it (PROVIDER_KEY_MALFORMED,
|
|
53
|
+
* PROVIDER_KEY_REJECTED): Router's own sentence, which says what is wrong and to replace the key, then where the new
|
|
54
|
+
* key goes. Router's words alone when ZTC can't tell the provider is the request's, or it runs only on Zerg's key.
|
|
55
|
+
*/
|
|
56
|
+
export declare function unusableRouterKeyMessage(said: string, target: RouterKeyTarget): string;
|
|
43
57
|
/**
|
|
44
58
|
* What ZTC says when the provider turned away the key Zerg Router holds for it: its 401, which Router passes on from
|
|
45
59
|
* inside a turn it started, so Router took this ZTC's sign-in. The key to check is the provider's, on Router.
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/** Router's code for a provider it has no usable key for, so nothing was sent to it. */
|
|
2
2
|
export const PROVIDER_KEY_UNAVAILABLE = 'provider_key_unavailable';
|
|
3
|
+
/**
|
|
4
|
+
* Router's codes for an account key it holds but can't use, so nothing was sent: one stored with a defect (an export
|
|
5
|
+
* line, a masked copy), or one its provider refused and that is cooling (zapps/zergrouter server/lib/missing-provider-key.ts).
|
|
6
|
+
*/
|
|
7
|
+
export const PROVIDER_KEY_MALFORMED = 'provider_key_malformed';
|
|
8
|
+
export const PROVIDER_KEY_REJECTED = 'provider_key_rejected';
|
|
9
|
+
/** Refusals the person ends by adding or replacing the provider's key: a list Router sends that runs it again ends them. */
|
|
10
|
+
export const PROVIDER_KEY_REFUSALS = new Set([PROVIDER_KEY_UNAVAILABLE, PROVIDER_KEY_MALFORMED, PROVIDER_KEY_REJECTED]);
|
|
3
11
|
/** Router's Credentials page on ORIGIN, where a person adds a provider's API key. */
|
|
4
12
|
export function routerCredentialsUrl(origin) {
|
|
5
13
|
return `${origin.replace(/\/+$/, '')}/dashboard?tab=credentials`;
|
|
@@ -62,6 +70,17 @@ export function missingRouterKeyMessage(target) {
|
|
|
62
70
|
return `Zerg Router has no key for ${name}, so it cannot run this model. Choose another model with /model.`;
|
|
63
71
|
return `Zerg Router has no ${name} key for your account, so nothing was sent to ${name}. ${routerKeyAdvice(target, `your ${name} API key`)}`;
|
|
64
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* What ZTC says when Router holds the account's key for the provider but can't use it (PROVIDER_KEY_MALFORMED,
|
|
75
|
+
* PROVIDER_KEY_REJECTED): Router's own sentence, which says what is wrong and to replace the key, then where the new
|
|
76
|
+
* key goes. Router's words alone when ZTC can't tell the provider is the request's, or it runs only on Zerg's key.
|
|
77
|
+
*/
|
|
78
|
+
export function unusableRouterKeyMessage(said, target) {
|
|
79
|
+
const name = nameOf(target);
|
|
80
|
+
if (!name || zergKeyOnly(target.provider))
|
|
81
|
+
return said;
|
|
82
|
+
return `${said} ${routerKeyAdvice(target, `your new ${name} API key`)}`;
|
|
83
|
+
}
|
|
65
84
|
/**
|
|
66
85
|
* What ZTC says when the provider turned away the key Zerg Router holds for it: its 401, which Router passes on from
|
|
67
86
|
* inside a turn it started, so Router took this ZTC's sign-in. The key to check is the provider's, on Router.
|
|
@@ -92,9 +92,11 @@ export declare function cleanRouterText(text: string, max?: number): string;
|
|
|
92
92
|
export declare function routerHelpUrl(value: unknown): string | undefined;
|
|
93
93
|
/** A moment in the person's own time zone, named: "Sun, Nov 8, 4:00 PM PST". */
|
|
94
94
|
export declare function localRouterTime(at: number): string;
|
|
95
|
+
export declare function withHttpStatus(label: string, status: number, provider?: string): string;
|
|
95
96
|
/**
|
|
96
|
-
* What ZTC shows for a refusal: Router's words, then the reset in the person's local
|
|
97
|
-
* nothing about waiting when waiting will not help), then the help link unless Router's
|
|
98
|
-
*
|
|
97
|
+
* What ZTC shows for a refusal: its class and HTTP status, then Router's words, then the reset in the person's local
|
|
98
|
+
* time when Router gives one (and nothing about waiting when waiting will not help), then the help link unless Router's
|
|
99
|
+
* words already hold it. A refusal for want of a usable provider key (PROVIDER_KEY_REFUSALS) is worded whole, what is
|
|
100
|
+
* wrong and where the key goes, so it has no class before it. `retryAt` is when a cooldown that ended the turn clears.
|
|
99
101
|
*/
|
|
100
102
|
export declare function formatRouterRefusal(refusal: RouterRefusal, now?: number, retryAt?: number): string;
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
* and body through but drops its headers, so retry timing is read from the body; its own workspace quota and request
|
|
12
12
|
* throttles answer in their own shapes. A provider Router has no usable key for is `provider_key_unavailable`, read by
|
|
13
13
|
* its code whatever the provider (or, from an older Router that sent no code, by its exact sentence) and worded by ZTC
|
|
14
|
-
* (router_keys.ts), since Router's sentence names no way on.
|
|
14
|
+
* (router_keys.ts), since Router's sentence names no way on. An account key Router holds but can't use, stored with a
|
|
15
|
+
* defect (`provider_key_malformed`) or refused by its provider and cooling (`provider_key_rejected`), keeps Router's
|
|
16
|
+
* sentence, which says to replace it, and ZTC adds where the new key goes.
|
|
15
17
|
*/
|
|
16
|
-
import { missingRouterKeyMessage, PROVIDER_KEY_UNAVAILABLE } from './router_keys.js';
|
|
18
|
+
import { missingRouterKeyMessage, PROVIDER_KEY_MALFORMED, PROVIDER_KEY_REFUSALS, PROVIDER_KEY_REJECTED, PROVIDER_KEY_UNAVAILABLE, unusableRouterKeyMessage, } from './router_keys.js';
|
|
17
19
|
import { RequestRefusedError } from './types.js';
|
|
18
20
|
/**
|
|
19
21
|
* The longest provider cooldown a turn waits out. Router cools a rate-limited key for 60 seconds unless the provider
|
|
@@ -167,6 +169,18 @@ export function readRouterRefusal(status, body, request) {
|
|
|
167
169
|
fallback = missingRouterKeyMessage({ provider: named?.provider, label: named?.providerLabel, credentialsUrl: request?.credentialsUrl });
|
|
168
170
|
ownWords = true;
|
|
169
171
|
}
|
|
172
|
+
else if ((code === PROVIDER_KEY_MALFORMED || code === PROVIDER_KEY_REJECTED) && dispatched === false) {
|
|
173
|
+
// Lasts until the key is replaced: the person's own next message still gets a real attempt (router_gate.ts).
|
|
174
|
+
kind = 'lasting';
|
|
175
|
+
const words = sentence(said || (code === PROVIDER_KEY_MALFORMED
|
|
176
|
+
? 'The key Zerg Router holds for this provider was saved with a defect, so nothing was sent to it'
|
|
177
|
+
: 'The provider refused the key Zerg Router holds for it, so nothing was sent to it'));
|
|
178
|
+
const named = request && providerNamed(fields, said) === request.provider ? request : undefined;
|
|
179
|
+
fallback = named
|
|
180
|
+
? unusableRouterKeyMessage(words, { provider: named.provider, label: named.providerLabel, credentialsUrl: named.credentialsUrl })
|
|
181
|
+
: words;
|
|
182
|
+
ownWords = true;
|
|
183
|
+
}
|
|
170
184
|
else if (code && Object.hasOwn(ROUTER_USAGE_DENIALS, code) && dispatched !== true) {
|
|
171
185
|
kind = code === CONCURRENCY ? 'concurrency' : 'lasting';
|
|
172
186
|
fallback = ROUTER_USAGE_DENIALS[code];
|
|
@@ -266,10 +280,15 @@ export function localRouterTime(at) {
|
|
|
266
280
|
function sentence(text) {
|
|
267
281
|
return /[.!?…]$/.test(text) ? text : `${text}.`;
|
|
268
282
|
}
|
|
283
|
+
export function withHttpStatus(label, status, provider = '') {
|
|
284
|
+
const at = Number.isInteger(status) && status >= 400 && status <= 599 ? ` (HTTP ${status})` : '';
|
|
285
|
+
return `${label}${at}${provider ? ` from ${provider}` : ''}`;
|
|
286
|
+
}
|
|
269
287
|
/**
|
|
270
|
-
* What ZTC shows for a refusal: Router's words, then the reset in the person's local
|
|
271
|
-
* nothing about waiting when waiting will not help), then the help link unless Router's
|
|
272
|
-
*
|
|
288
|
+
* What ZTC shows for a refusal: its class and HTTP status, then Router's words, then the reset in the person's local
|
|
289
|
+
* time when Router gives one (and nothing about waiting when waiting will not help), then the help link unless Router's
|
|
290
|
+
* words already hold it. A refusal for want of a usable provider key (PROVIDER_KEY_REFUSALS) is worded whole, what is
|
|
291
|
+
* wrong and where the key goes, so it has no class before it. `retryAt` is when a cooldown that ended the turn clears.
|
|
273
292
|
*/
|
|
274
293
|
export function formatRouterRefusal(refusal, now = Date.now(), retryAt) {
|
|
275
294
|
let text = sentence(refusal.message);
|
|
@@ -282,5 +301,8 @@ export function formatRouterRefusal(refusal, now = Date.now(), retryAt) {
|
|
|
282
301
|
text += ` ${WAIT_GUIDANCE}`;
|
|
283
302
|
if (refusal.helpUrl && !text.includes(refusal.helpUrl))
|
|
284
303
|
text += ` See ${refusal.helpUrl}.`;
|
|
285
|
-
|
|
304
|
+
if (PROVIDER_KEY_REFUSALS.has(refusal.code))
|
|
305
|
+
return text;
|
|
306
|
+
const label = refusal.kind !== 'lasting' ? 'Rate limit' : refusal.status === 429 ? 'Plan limit' : 'Router refused';
|
|
307
|
+
return `${withHttpStatus(label, refusal.status)}: ${text}`;
|
|
286
308
|
}
|
|
@@ -193,7 +193,7 @@ export interface BackendRequest {
|
|
|
193
193
|
allow_fallbacks: boolean;
|
|
194
194
|
};
|
|
195
195
|
/** Stable id for one logical LLM turn across transport reconnects. */
|
|
196
|
-
transportTurnId?: string;
|
|
196
|
+
transportTurnId?: string | null;
|
|
197
197
|
/**
|
|
198
198
|
* The first request of a turn the person's own new message started. It gets one real attempt even while Zerg
|
|
199
199
|
* Router's refusal holds the route: they may have just raised the limit.
|
|
@@ -529,7 +529,7 @@ export class ZRouterStreamBackend {
|
|
|
529
529
|
if (!response.ok) {
|
|
530
530
|
const failure = await readHttpErrorBody(response, request.signal);
|
|
531
531
|
throw routerFailure(response.status, failure.body, { headers, response, bodyReadState: failure.bodyReadState, request: this.refusalRequest(),
|
|
532
|
-
ownSignIn: this.signInTarget() });
|
|
532
|
+
ownSignIn: this.signInTarget(), provider: this.provider });
|
|
533
533
|
}
|
|
534
534
|
const data = await response.json();
|
|
535
535
|
const parsed = this.parseOpenAIResponse(data);
|
|
@@ -636,16 +636,18 @@ export class ZRouterStreamBackend {
|
|
|
636
636
|
const headers = await this.buildHeaders(request);
|
|
637
637
|
if (resumeAfter)
|
|
638
638
|
headers['X-Zerg-Resume-After'] = resumeAfter;
|
|
639
|
+
// Router answers a request without a turn id only once the provider's first bytes arrive, and that request
|
|
640
|
+
// is never sent again, so it has no reconnect budget to share.
|
|
639
641
|
const response = await fetchWithHeadersTimeout(fetcher, this.endpointFor(), {
|
|
640
642
|
method: 'POST',
|
|
641
643
|
headers,
|
|
642
644
|
body,
|
|
643
645
|
signal: request.signal,
|
|
644
|
-
}, Math.min(ZROUTER_HEADERS_TIMEOUT_MS, Math.max(1, remaining())));
|
|
646
|
+
}, request.transportTurnId ? Math.min(ZROUTER_HEADERS_TIMEOUT_MS, Math.max(1, remaining())) : ZROUTER_HEADERS_TIMEOUT_MS);
|
|
645
647
|
if (!response.ok) {
|
|
646
648
|
const failure = await readHttpErrorBody(response, request.signal);
|
|
647
649
|
throw routerFailure(response.status, routerErrorFrameBody(failure.body), { headers, response, bodyReadState: failure.bodyReadState,
|
|
648
|
-
request: this.refusalRequest(), ownSignIn: this.signInTarget() });
|
|
650
|
+
request: this.refusalRequest(), ownSignIn: this.signInTarget(), provider: this.provider });
|
|
649
651
|
}
|
|
650
652
|
if (!response.body) {
|
|
651
653
|
throw new Error('ZRouter API error: no response body for streaming request');
|
|
@@ -675,7 +677,7 @@ export class ZRouterStreamBackend {
|
|
|
675
677
|
: 502;
|
|
676
678
|
routerTurnEnded = true;
|
|
677
679
|
throw routerFailure(status, JSON.stringify(ev.body ?? {}), { headers, turnEnded: true, request: this.refusalRequest(),
|
|
678
|
-
ownSignIn: this.signInTarget() });
|
|
680
|
+
ownSignIn: this.signInTarget(), provider: this.provider });
|
|
679
681
|
}
|
|
680
682
|
const mapped = mapEvent(ev);
|
|
681
683
|
if (this.getModelCapabilities(request.model)?.tools === false && mapped.some(event => event.type.startsWith('tool_use'))) {
|
|
@@ -711,6 +713,8 @@ export class ZRouterStreamBackend {
|
|
|
711
713
|
: isTransportError(error));
|
|
712
714
|
if (request.signal?.aborted
|
|
713
715
|
|| !retryable
|
|
716
|
+
// Router tells a reconnect from a new request by its turn id: without one, sending again dispatches again.
|
|
717
|
+
|| !request.transportTurnId
|
|
714
718
|
|| (emittedMappedEvent && (!resumeSupported || !resumeAfter))) {
|
|
715
719
|
// The last clause keeps the no-duplicate guarantee: once visible output
|
|
716
720
|
// has been delivered, a retry is only safe when the Router can replay
|
|
@@ -740,7 +744,7 @@ export class ZRouterStreamBackend {
|
|
|
740
744
|
}
|
|
741
745
|
}
|
|
742
746
|
function withTransportTurn(request) {
|
|
743
|
-
return request.transportTurnId
|
|
747
|
+
return request.transportTurnId === undefined ? { ...request, transportTurnId: randomUUID() } : request;
|
|
744
748
|
}
|
|
745
749
|
async function fetchWithHeadersTimeout(fetcher, input, init, timeoutMs) {
|
|
746
750
|
const timeoutController = new AbortController();
|
|
@@ -868,7 +872,7 @@ function routerFailure(status, body, options) {
|
|
|
868
872
|
const header = options.response?.headers.get('retry-after') ?? null;
|
|
869
873
|
const httpError = (retryAfter) => {
|
|
870
874
|
const error = new BackendHttpError(status, body, { prefix: 'ZRouter API', headers: options.headers, bodyReadState: options.bodyReadState,
|
|
871
|
-
retryAfter, rateLimitReset: options.response?.headers.get('x-ratelimit-reset'), turnEnded: options.turnEnded });
|
|
875
|
+
retryAfter, rateLimitReset: options.response?.headers.get('x-ratelimit-reset'), turnEnded: options.turnEnded, provider: options.provider });
|
|
872
876
|
if (options.response)
|
|
873
877
|
error.message += failureHeaderSuffix(options.response);
|
|
874
878
|
return error;
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/claude` and `/codex` — open the user's own Claude Code or Codex in a new
|
|
3
|
-
* pane, in this pane's directory.
|
|
3
|
+
* pane, in this pane's directory, or resume one of their own sessions.
|
|
4
4
|
*
|
|
5
5
|
* The CLI signs in with the user's own account through its own flow; ZTC only
|
|
6
6
|
* runs it, unmodified, and attaches its workspace MCP server so the agent can
|
|
7
7
|
* open, read, type into and message other panes. Plain text after the command
|
|
8
8
|
* is the opening prompt; text starting with a flag is the CLI's arguments.
|
|
9
|
+
*
|
|
10
|
+
* `resume`, `continue`, `fork`, `sessions` and `show-resumable` resume the
|
|
11
|
+
* person's sessions (panes/agent_cli.ts's parseAgentCommand): one by id opens
|
|
12
|
+
* in its own folder, on the sign-in whose store holds it (panes/agent_resume.ts).
|
|
13
|
+
* They are the person's alone: an agent's or relayed input's are refused before
|
|
14
|
+
* anything is read, and only Main, which has the sessions controller, reads the
|
|
15
|
+
* stores. What is said about a session is shown in this terminal only
|
|
16
|
+
* (localOnly) and never saved (ephemeral); with panes, which may read Main's
|
|
17
|
+
* screen, it names no session, folder or prompt (openedSessionLine), and only
|
|
18
|
+
* the command printed to run elsewhere, where there are none, names them.
|
|
9
19
|
*/
|
|
10
20
|
import { type AgentCliId, type PaneProgram } from '../../panes/agent_cli.js';
|
|
11
21
|
import type { PaneCommandTransport } from '../../ui/ratatui/pane_relay.js';
|