@aiwayds/dsh-opentui 0.21.1 → 0.22.0
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/CHANGELOG.md +161 -0
- package/README.md +32 -8
- package/bin/dsh-opentui.mjs +98 -7
- package/bin/lib/launcher.mjs +68 -6
- package/dist/bridge/approval-gate.js +89 -0
- package/dist/bridge/bundle-fingerprint.json +5 -0
- package/dist/bridge/cordis.patch.yml +8 -0
- package/dist/bridge/index.js +2211 -0
- package/dist/bridge/package.json +49 -0
- package/dist/client/index.js +3143 -280
- package/dist/client/index.js.map +30 -23
- package/dist/locales/en.json +29 -3
- package/dist/locales/zh-CN.json +29 -3
- package/package.json +3 -2
- package/scripts/lib/bridge-failfast-text.d.mts +12 -0
- package/scripts/lib/bridge-failfast-text.mjs +48 -0
- package/scripts/lib/host-compat.mjs +224 -0
- package/scripts/provision-inproc-profile.mjs +1229 -0
package/dist/client/index.js
CHANGED
|
@@ -3773,7 +3773,7 @@ var init_lib = __esm(() => {
|
|
|
3773
3773
|
})(Time || (Time = {}));
|
|
3774
3774
|
});
|
|
3775
3775
|
|
|
3776
|
-
// ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/cordis/lib/index.js
|
|
3776
|
+
// ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/index.js
|
|
3777
3777
|
function isConstructor(func) {
|
|
3778
3778
|
if (!func.prototype)
|
|
3779
3779
|
return false;
|
|
@@ -13751,6 +13751,7 @@ class ComposerController {
|
|
|
13751
13751
|
onPendingChange;
|
|
13752
13752
|
onQueuePaused;
|
|
13753
13753
|
isTurnAborted;
|
|
13754
|
+
disabled;
|
|
13754
13755
|
busyState = false;
|
|
13755
13756
|
pendingTurn;
|
|
13756
13757
|
queueItems = [];
|
|
@@ -13765,6 +13766,7 @@ class ComposerController {
|
|
|
13765
13766
|
this.onPendingChange = options.onPendingChange;
|
|
13766
13767
|
this.onQueuePaused = options.onQueuePaused;
|
|
13767
13768
|
this.isTurnAborted = options.isTurnAborted;
|
|
13769
|
+
this.disabled = options.disabled;
|
|
13768
13770
|
this.history = options.history ?? new ComposerHistory;
|
|
13769
13771
|
}
|
|
13770
13772
|
get busy() {
|
|
@@ -13777,6 +13779,8 @@ class ComposerController {
|
|
|
13777
13779
|
return this.queueItems.length;
|
|
13778
13780
|
}
|
|
13779
13781
|
submit(text) {
|
|
13782
|
+
if (this.disabled?.())
|
|
13783
|
+
return "ignored";
|
|
13780
13784
|
const prompt = text.trim();
|
|
13781
13785
|
if (!prompt)
|
|
13782
13786
|
return "ignored";
|
|
@@ -13789,6 +13793,8 @@ class ComposerController {
|
|
|
13789
13793
|
return "sent";
|
|
13790
13794
|
}
|
|
13791
13795
|
async submitWhileBusy(text) {
|
|
13796
|
+
if (this.disabled?.())
|
|
13797
|
+
return "ignored";
|
|
13792
13798
|
const prompt = text.trim();
|
|
13793
13799
|
if (!prompt)
|
|
13794
13800
|
return "ignored";
|
|
@@ -34177,7 +34183,7 @@ var init_config = __esm(() => {
|
|
|
34177
34183
|
description: "Prompt for permission requests or accept them automatically"
|
|
34178
34184
|
}),
|
|
34179
34185
|
activity_panel_height: optional2(Literals(["1", "5", "7", "10", "all"])).annotate({
|
|
34180
|
-
description: "
|
|
34186
|
+
description: "Think display lines in the activity panel: 1 / 5 / 7 / 10; 'all' is a legacy spelling equal to 10. The tool block is fixed and the panel never exceeds 10 lines"
|
|
34181
34187
|
})
|
|
34182
34188
|
})).annotate({
|
|
34183
34189
|
description: "Session transcript presentation settings"
|
|
@@ -42072,6 +42078,7 @@ function SessionComposer(props) {
|
|
|
42072
42078
|
onPendingChange: props.onPendingChange,
|
|
42073
42079
|
onQueuePaused: props.onQueuePaused,
|
|
42074
42080
|
isTurnAborted: props.isTurnAborted,
|
|
42081
|
+
disabled: props.disabled,
|
|
42075
42082
|
onBusyChange: (value) => {
|
|
42076
42083
|
if (disposed)
|
|
42077
42084
|
return;
|
|
@@ -42113,6 +42120,8 @@ function SessionComposer(props) {
|
|
|
42113
42120
|
const editor = textarea;
|
|
42114
42121
|
if (!editor || editor.isDestroyed)
|
|
42115
42122
|
return;
|
|
42123
|
+
if (props.disabled?.())
|
|
42124
|
+
return;
|
|
42116
42125
|
if (props.interceptSubmit?.(editor.plainText, (text) => editor.setText(text))) {
|
|
42117
42126
|
editor.setText("");
|
|
42118
42127
|
syncHeight();
|
|
@@ -42334,7 +42343,7 @@ function SessionComposer(props) {
|
|
|
42334
42343
|
footerRows: FOOTER_HEIGHT,
|
|
42335
42344
|
paletteRows: props.slashHeight?.() ?? 0,
|
|
42336
42345
|
terminalRows: dimensions().height
|
|
42337
|
-
}).height, _v$2 = composerBorderSides(dimensions().height), _v$3 = border().borderStyle, _v$4 = border().borderColor, _v$5 = dimensions().height > COMPOSER_COMPACT_TERMINAL_ROWS ? props.frameTitle?.() || (busy() ? STEER_TITLE : undefined) : undefined, _v$6 = border().borderColor, _v$7 = color.background(), _v$8 = maxLines(), _v$9 = props.placeholder ?? t("composer.placeholder"), _v$0 = color.placeholder(), _v$1 = color.unfocusedText(), _v$
|
|
42346
|
+
}).height, _v$2 = composerBorderSides(dimensions().height), _v$3 = border().borderStyle, _v$4 = border().borderColor, _v$5 = dimensions().height > COMPOSER_COMPACT_TERMINAL_ROWS ? props.frameTitle?.() || (busy() ? STEER_TITLE : undefined) : undefined, _v$6 = border().borderColor, _v$7 = color.background(), _v$8 = maxLines(), _v$9 = props.disabled?.() ? props.disabledReason?.() ?? props.placeholder ?? t("composer.placeholder") : props.placeholder ?? t("composer.placeholder"), _v$0 = color.placeholder(), _v$1 = !props.disabled?.(), _v$10 = color.unfocusedText(), _v$11 = color.text(), _v$12 = busy() ? busyColor() : color.text(), _v$13 = cursor();
|
|
42338
42347
|
_v$ !== _p$.e && (_p$.e = setProp(_el$, "height", _v$, _p$.e));
|
|
42339
42348
|
_v$2 !== _p$.t && (_p$.t = setProp(_el$, "border", _v$2, _p$.t));
|
|
42340
42349
|
_v$3 !== _p$.a && (_p$.a = setProp(_el$, "borderStyle", _v$3, _p$.a));
|
|
@@ -42345,10 +42354,11 @@ function SessionComposer(props) {
|
|
|
42345
42354
|
_v$8 !== _p$.h && (_p$.h = setProp(_el$2, "maxHeight", _v$8, _p$.h));
|
|
42346
42355
|
_v$9 !== _p$.r && (_p$.r = setProp(_el$2, "placeholder", _v$9, _p$.r));
|
|
42347
42356
|
_v$0 !== _p$.d && (_p$.d = setProp(_el$2, "placeholderColor", _v$0, _p$.d));
|
|
42348
|
-
_v$1 !== _p$.l && (_p$.l = setProp(_el$2, "
|
|
42349
|
-
_v$10 !== _p$.u && (_p$.u = setProp(_el$2, "
|
|
42350
|
-
_v$11 !== _p$.c && (_p$.c = setProp(_el$2, "
|
|
42351
|
-
_v$12 !== _p$.w && (_p$.w = setProp(_el$2, "
|
|
42357
|
+
_v$1 !== _p$.l && (_p$.l = setProp(_el$2, "showCursor", _v$1, _p$.l));
|
|
42358
|
+
_v$10 !== _p$.u && (_p$.u = setProp(_el$2, "textColor", _v$10, _p$.u));
|
|
42359
|
+
_v$11 !== _p$.c && (_p$.c = setProp(_el$2, "focusedTextColor", _v$11, _p$.c));
|
|
42360
|
+
_v$12 !== _p$.w && (_p$.w = setProp(_el$2, "cursorColor", _v$12, _p$.w));
|
|
42361
|
+
_v$13 !== _p$.m && (_p$.m = setProp(_el$2, "cursorStyle", _v$13, _p$.m));
|
|
42352
42362
|
return _p$;
|
|
42353
42363
|
}, {
|
|
42354
42364
|
e: undefined,
|
|
@@ -42364,7 +42374,8 @@ function SessionComposer(props) {
|
|
|
42364
42374
|
l: undefined,
|
|
42365
42375
|
u: undefined,
|
|
42366
42376
|
c: undefined,
|
|
42367
|
-
w: undefined
|
|
42377
|
+
w: undefined,
|
|
42378
|
+
m: undefined
|
|
42368
42379
|
});
|
|
42369
42380
|
return _el$;
|
|
42370
42381
|
})();
|
|
@@ -43609,6 +43620,18 @@ function isRecord4(value) {
|
|
|
43609
43620
|
}
|
|
43610
43621
|
|
|
43611
43622
|
// ../tui-base/src/util/error.ts
|
|
43623
|
+
function sessionLockedErrorText(error) {
|
|
43624
|
+
if (!isRecord4(error) || error.code !== "SESSION_LOCKED")
|
|
43625
|
+
return;
|
|
43626
|
+
const detail = isRecord4(error.detail) ? error.detail : undefined;
|
|
43627
|
+
const holderValue = detail?.holder;
|
|
43628
|
+
const holder = typeof holderValue === "string" && holderValue !== "" && holderValue !== "unknown" ? holderValue : undefined;
|
|
43629
|
+
if (holder === undefined)
|
|
43630
|
+
return t("error.sessionLockedNoHolder");
|
|
43631
|
+
const idValue = detail?.sessionId;
|
|
43632
|
+
const id = typeof idValue === "string" && idValue !== "" ? idValue : holder;
|
|
43633
|
+
return t("error.sessionLocked", { id, holder });
|
|
43634
|
+
}
|
|
43612
43635
|
function errorFormat(error) {
|
|
43613
43636
|
if (error instanceof Error) {
|
|
43614
43637
|
return error.stack ?? `${error.name}: ${error.message}`;
|
|
@@ -43653,7 +43676,9 @@ function errorMessage(error) {
|
|
|
43653
43676
|
return formatted;
|
|
43654
43677
|
return "unknown error";
|
|
43655
43678
|
}
|
|
43656
|
-
var init_error = () => {
|
|
43679
|
+
var init_error = __esm(() => {
|
|
43680
|
+
init_i18n();
|
|
43681
|
+
});
|
|
43657
43682
|
|
|
43658
43683
|
// ../tui-base/src/ui/toast.tsx
|
|
43659
43684
|
import { TextAttributes as TextAttributes2 } from "@opentui/core";
|
|
@@ -45667,11 +45692,16 @@ var SESSIONS_MIN_BYTES = 1024, SESSIONS_DIR_CAP = 32;
|
|
|
45667
45692
|
function parseLaunchArgs(argv) {
|
|
45668
45693
|
let newRequested = false;
|
|
45669
45694
|
let resumeLastRequested = false;
|
|
45695
|
+
let remoteRequested = false;
|
|
45670
45696
|
let sessionId;
|
|
45671
45697
|
for (let index = 0;index < argv.length; index++) {
|
|
45672
45698
|
const arg = argv[index];
|
|
45673
45699
|
if (arg === undefined)
|
|
45674
45700
|
continue;
|
|
45701
|
+
if (arg === "--remote") {
|
|
45702
|
+
remoteRequested = true;
|
|
45703
|
+
continue;
|
|
45704
|
+
}
|
|
45675
45705
|
if (arg === "--new") {
|
|
45676
45706
|
newRequested = true;
|
|
45677
45707
|
continue;
|
|
@@ -45694,7 +45724,12 @@ function parseLaunchArgs(argv) {
|
|
|
45694
45724
|
sessionId = value;
|
|
45695
45725
|
}
|
|
45696
45726
|
}
|
|
45697
|
-
return {
|
|
45727
|
+
return {
|
|
45728
|
+
newRequested,
|
|
45729
|
+
resumeLastRequested,
|
|
45730
|
+
...sessionId !== undefined ? { sessionId } : {},
|
|
45731
|
+
...remoteRequested ? { remoteRequested: true } : {}
|
|
45732
|
+
};
|
|
45698
45733
|
}
|
|
45699
45734
|
function readAutoResumeMode(config) {
|
|
45700
45735
|
return config?.autoResume === "last" ? "last" : "off";
|
|
@@ -47937,7 +47972,9 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
47937
47972
|
if (event.type === "message.updated" && details.role === "user") {
|
|
47938
47973
|
const id = typeof details.id === "string" ? details.id : `local-${++liveOrdinal}`;
|
|
47939
47974
|
const text = typeof details.text === "string" ? details.text : "";
|
|
47940
|
-
|
|
47975
|
+
const journalKey = `user:${id}`;
|
|
47976
|
+
const isWire = typeof details.sessionID === "string";
|
|
47977
|
+
if (!turnOpen && pendingTurns.length > 0 && isWire) {
|
|
47941
47978
|
const group = pendingTurns[0];
|
|
47942
47979
|
const local = rows.find((row) => row.key === group.userKey);
|
|
47943
47980
|
if (!local || local.kind !== "user" || local.text.trim() === text.trim()) {
|
|
@@ -47945,12 +47982,12 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
47945
47982
|
dropRows(new Set([group.userKey]));
|
|
47946
47983
|
}
|
|
47947
47984
|
}
|
|
47948
|
-
|
|
47949
|
-
|
|
47950
|
-
|
|
47951
|
-
|
|
47952
|
-
|
|
47953
|
-
});
|
|
47985
|
+
if (isWire && !rows.some((row) => row.key === journalKey)) {
|
|
47986
|
+
const optimistic = rows.find((row) => row.kind === "user" && row.seq === null && row.text.trim() === text.trim());
|
|
47987
|
+
if (optimistic !== undefined)
|
|
47988
|
+
dropRows(new Set([optimistic.key]));
|
|
47989
|
+
}
|
|
47990
|
+
upsert({ key: journalKey, kind: "user", text, final: true });
|
|
47954
47991
|
return;
|
|
47955
47992
|
}
|
|
47956
47993
|
if (event.type === "message.part.updated") {
|
|
@@ -47991,6 +48028,37 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
47991
48028
|
});
|
|
47992
48029
|
return;
|
|
47993
48030
|
}
|
|
48031
|
+
if (event.type === "bridge.input.acked") {
|
|
48032
|
+
if (typeof details.sessionID === "string" && details.sessionID !== sessionID())
|
|
48033
|
+
return;
|
|
48034
|
+
const text = typeof details.text === "string" ? details.text.trim() : "";
|
|
48035
|
+
setRows(produce((draft) => {
|
|
48036
|
+
for (const row of draft) {
|
|
48037
|
+
if (row.kind === "user" && row.unconfirmed === true && row.key.startsWith("user:local") && row.text.trim() === text) {
|
|
48038
|
+
row.unconfirmed = false;
|
|
48039
|
+
break;
|
|
48040
|
+
}
|
|
48041
|
+
}
|
|
48042
|
+
}));
|
|
48043
|
+
return;
|
|
48044
|
+
}
|
|
48045
|
+
if (event.type === "bridge.turn.interrupted") {
|
|
48046
|
+
if (typeof details.sessionID === "string" && details.sessionID !== sessionID())
|
|
48047
|
+
return;
|
|
48048
|
+
const turnId = typeof details.turnId === "string" ? details.turnId : "";
|
|
48049
|
+
if (turnId === "")
|
|
48050
|
+
return;
|
|
48051
|
+
const reason = typeof details.reason === "string" ? details.reason : "interrupted";
|
|
48052
|
+
upsert({
|
|
48053
|
+
key: `interrupted:local:${turnId}`,
|
|
48054
|
+
kind: "interrupted",
|
|
48055
|
+
text: reason,
|
|
48056
|
+
final: true,
|
|
48057
|
+
seq: null,
|
|
48058
|
+
turnId
|
|
48059
|
+
});
|
|
48060
|
+
return;
|
|
48061
|
+
}
|
|
47994
48062
|
if (event.type === "session.error") {
|
|
47995
48063
|
const message = typeof details.message === "string" ? details.message : "unknown error";
|
|
47996
48064
|
upsert({ key: `error:local-${++liveOrdinal}`, kind: "assistant", text: `error: ${message}`, final: true });
|
|
@@ -48004,7 +48072,7 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
48004
48072
|
if (!prompt)
|
|
48005
48073
|
return;
|
|
48006
48074
|
const userKey = `user:local-${++liveOrdinal}`;
|
|
48007
|
-
upsert({ key: userKey, kind: "user", text: prompt, final: true });
|
|
48075
|
+
upsert({ key: userKey, kind: "user", text: prompt, final: true, unconfirmed: true, seq: null });
|
|
48008
48076
|
const assistantKey = `assistant:live-${++liveOrdinal}`;
|
|
48009
48077
|
const reasoningKey = `reasoning:live-${liveOrdinal}`;
|
|
48010
48078
|
const group = { userKey, reasoningKey, assistantKey, userSuperseded: false };
|
|
@@ -48014,6 +48082,11 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
48014
48082
|
let reasoningStartedAt;
|
|
48015
48083
|
let turnErrored = false;
|
|
48016
48084
|
turnOpen = true;
|
|
48085
|
+
const reportError = (message) => {
|
|
48086
|
+
turnErrored = true;
|
|
48087
|
+
upsert({ key: assistantKey, kind: "assistant", text: `error: ${message}`, final: true });
|
|
48088
|
+
options?.onError?.(message);
|
|
48089
|
+
};
|
|
48017
48090
|
const collapseThinking = () => {
|
|
48018
48091
|
if (reasoningStartedAt === undefined)
|
|
48019
48092
|
return;
|
|
@@ -48068,11 +48141,12 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
48068
48141
|
onToolRun: (run) => {
|
|
48069
48142
|
const existing = rows.find((row) => row.key === `tool:live:${run.callId ?? run.name}`);
|
|
48070
48143
|
const startedAt = existing?.kind === "tool" ? existing.startedAt : undefined;
|
|
48144
|
+
const args = run.argsPretty || (existing?.kind === "tool" ? existing.args : undefined) || "";
|
|
48071
48145
|
upsert({
|
|
48072
48146
|
key: `tool:live:${run.callId ?? run.name}`,
|
|
48073
48147
|
kind: "tool",
|
|
48074
48148
|
name: run.name,
|
|
48075
|
-
args
|
|
48149
|
+
args,
|
|
48076
48150
|
status: run.ok ? "done" : "failed",
|
|
48077
48151
|
output: run.output,
|
|
48078
48152
|
...startedAt !== undefined ? { elapsedSec: Number(((Date.now() - startedAt) / 1000).toFixed(1)) } : {}
|
|
@@ -48081,11 +48155,12 @@ function createSeamRows(seam, sessionID, options) {
|
|
|
48081
48155
|
options?.onToolRun?.(run);
|
|
48082
48156
|
},
|
|
48083
48157
|
onApprove: options?.onApprove ?? approveThrough,
|
|
48084
|
-
onError:
|
|
48085
|
-
|
|
48086
|
-
|
|
48087
|
-
|
|
48088
|
-
|
|
48158
|
+
onError: reportError
|
|
48159
|
+
}).catch((error) => {
|
|
48160
|
+
const diagnostic = sessionLockedErrorText(error);
|
|
48161
|
+
if (diagnostic !== undefined)
|
|
48162
|
+
reportError(diagnostic);
|
|
48163
|
+
throw error;
|
|
48089
48164
|
}).finally(() => {
|
|
48090
48165
|
turnOpen = false;
|
|
48091
48166
|
(async () => {
|
|
@@ -48149,6 +48224,7 @@ var init_seam_rows = __esm(() => {
|
|
|
48149
48224
|
init_server2();
|
|
48150
48225
|
init_dock_visibility();
|
|
48151
48226
|
init_motion();
|
|
48227
|
+
init_error();
|
|
48152
48228
|
});
|
|
48153
48229
|
|
|
48154
48230
|
// ../tui-base/src/routes/session/footer-refresh.ts
|
|
@@ -48700,6 +48776,17 @@ function cacheSegment(rate, theme) {
|
|
|
48700
48776
|
priority: 40
|
|
48701
48777
|
};
|
|
48702
48778
|
}
|
|
48779
|
+
function bridgeStatusSegment(status) {
|
|
48780
|
+
if (status === undefined || status === "ready")
|
|
48781
|
+
return null;
|
|
48782
|
+
const text = status === "dead" ? "\u26A0 dead" : "\u27F3 recovering";
|
|
48783
|
+
const bg = status === "dead" ? "#a82124" : "#b58105";
|
|
48784
|
+
return {
|
|
48785
|
+
text,
|
|
48786
|
+
bg,
|
|
48787
|
+
priority: -2
|
|
48788
|
+
};
|
|
48789
|
+
}
|
|
48703
48790
|
function rollingWidth(value, decimals = 0) {
|
|
48704
48791
|
const fixed = Math.abs(value).toFixed(decimals);
|
|
48705
48792
|
return Math.max(1, (fixed.split(".")[0] ?? "0").length);
|
|
@@ -48927,6 +49014,7 @@ function sessionFooterSegments(data) {
|
|
|
48927
49014
|
add(toolSegment(data.tools ?? 0, theme));
|
|
48928
49015
|
add(elapsedSegment(data.elapsedSec ?? null, theme));
|
|
48929
49016
|
add(speedSegment(data.tps ?? null, theme));
|
|
49017
|
+
add(bridgeStatusSegment(data.bridgeStatus));
|
|
48930
49018
|
return applyPowerlineGradient(segs, theme);
|
|
48931
49019
|
}
|
|
48932
49020
|
var POWERLINE_COLORS, AUTO_FG_DARK = "#1a1a2e", AUTO_FG_LIGHT = "#ffffff", DEFAULT_EFFORT = "high", POWERLINE_MIN_SEGMENT_DISTANCE = 80, POWERLINE_RAMP_FAMILIES, POWERLINE_RAMP_DEEP_LUMINANCE = 0.02, POWERLINE_RAMP_LIGHT_LUMINANCE = 0.55, POWERLINE_RAMP_HUE_STEPS, POWERLINE_RAMP_FALLBACK_HUES, EFFORT_ICONS;
|
|
@@ -49007,15 +49095,6 @@ var init_powerline = __esm(() => {
|
|
|
49007
49095
|
});
|
|
49008
49096
|
|
|
49009
49097
|
// ../tui-base/src/routes/session/merged-dock.ts
|
|
49010
|
-
function activeTodos(todos) {
|
|
49011
|
-
const out = [];
|
|
49012
|
-
for (let i = 0;i < todos.length; i++) {
|
|
49013
|
-
const todo = todos[i];
|
|
49014
|
-
if (todo.status === "in_progress")
|
|
49015
|
-
out.push({ ...todo, index: i + 1 });
|
|
49016
|
-
}
|
|
49017
|
-
return out;
|
|
49018
|
-
}
|
|
49019
49098
|
function attributeAgents(todos, agents) {
|
|
49020
49099
|
let parent = null;
|
|
49021
49100
|
for (let i = 0;i < todos.length; i++) {
|
|
@@ -49145,28 +49224,14 @@ function latestThinkRow(rows) {
|
|
|
49145
49224
|
}
|
|
49146
49225
|
return;
|
|
49147
49226
|
}
|
|
49148
|
-
function
|
|
49149
|
-
|
|
49150
|
-
if (text === undefined)
|
|
49151
|
-
return;
|
|
49152
|
-
return {
|
|
49227
|
+
function thinkLinesFor(row, now, spin, thinkLines) {
|
|
49228
|
+
return thinkBlockLines(row, spin, thinkLines, now).map((text) => ({
|
|
49153
49229
|
kind: "think",
|
|
49154
49230
|
segments: [{ text, tone: "running", accent: "think" }],
|
|
49155
49231
|
italic: true,
|
|
49156
49232
|
id: `dock:think:${row.key}`,
|
|
49157
49233
|
fadeOutAt: row.streaming === true ? undefined : skinStopAt(row)
|
|
49158
|
-
};
|
|
49159
|
-
}
|
|
49160
|
-
function todoLine(todo) {
|
|
49161
|
-
const glyph = TODO_STATUS_GLYPHS.in_progress;
|
|
49162
|
-
return {
|
|
49163
|
-
kind: "todo",
|
|
49164
|
-
index: todo.index,
|
|
49165
|
-
segments: [
|
|
49166
|
-
{ text: `${glyph} ${todo.index} `, tone: "running" },
|
|
49167
|
-
{ text: todo.content, tone: "running" }
|
|
49168
|
-
]
|
|
49169
|
-
};
|
|
49234
|
+
}));
|
|
49170
49235
|
}
|
|
49171
49236
|
function agentLine(agent, position, count, parentIndex, now = Date.now()) {
|
|
49172
49237
|
const branch = position === count - 1 ? "\u2514\u2500 " : "\u251C\u2500 ";
|
|
@@ -49201,31 +49266,29 @@ function mergedWindowInfo(data, options) {
|
|
|
49201
49266
|
function buildMergedDock(data, options) {
|
|
49202
49267
|
const now = options.now ?? Date.now();
|
|
49203
49268
|
const spin = options.spin ?? (() => 0);
|
|
49204
|
-
const
|
|
49205
|
-
const attribution = attributeAgents(data.todos, data.agents);
|
|
49206
|
-
const agents = attribution.agents;
|
|
49207
|
-
const parent = attribution.parent;
|
|
49208
|
-
const hasLowerContent = active.length > 0 || agents.length > 0;
|
|
49269
|
+
const agents = attributeAgents(data.todos, data.agents).agents;
|
|
49209
49270
|
const thinkRow = latestThinkRow(data.think ?? []);
|
|
49210
|
-
const
|
|
49271
|
+
const thinkAtGear = thinkRow === undefined ? [] : thinkLinesFor(thinkRow, now, spin, options.thinkLines ?? 1);
|
|
49272
|
+
const scene = activityScene(agents.length > 0, thinkAtGear.length > 0);
|
|
49211
49273
|
const tools = data.tools;
|
|
49212
|
-
let
|
|
49213
|
-
|
|
49274
|
+
let upperLines;
|
|
49275
|
+
let lowerRaw;
|
|
49276
|
+
if (scene === "A") {
|
|
49277
|
+
upperLines = thinkRow === undefined ? [] : thinkLinesFor(thinkRow, now, spin, 1).slice(0, 1);
|
|
49214
49278
|
const latest = tools.length > 0 ? tools[tools.length - 1] : undefined;
|
|
49215
|
-
|
|
49279
|
+
if (latest !== undefined)
|
|
49280
|
+
upperLines.push(coexistenceToolLine(latest, now, spin));
|
|
49281
|
+
const brief = todoBriefLine(data.todos, now, data.todoStartedAt);
|
|
49282
|
+
if (brief !== "")
|
|
49283
|
+
upperLines.push({ kind: "todo", segments: [{ text: brief, tone: "running" }] });
|
|
49284
|
+
lowerRaw = agents.map((agent, i) => agentLine(agent, i, agents.length, undefined, now));
|
|
49285
|
+
} else if (scene === "B") {
|
|
49286
|
+
upperLines = thinkAtGear;
|
|
49287
|
+
lowerRaw = [];
|
|
49216
49288
|
} else {
|
|
49217
|
-
|
|
49218
|
-
|
|
49219
|
-
|
|
49220
|
-
const lowerRaw = [];
|
|
49221
|
-
for (const todo of active) {
|
|
49222
|
-
lowerRaw.push(todoLine(todo));
|
|
49223
|
-
if (parent && parent.index === todo.index) {
|
|
49224
|
-
agents.forEach((agent, i) => lowerRaw.push(agentLine(agent, i, agents.length, todo.index, now)));
|
|
49225
|
-
}
|
|
49226
|
-
}
|
|
49227
|
-
if (!parent) {
|
|
49228
|
-
agents.forEach((agent, i) => lowerRaw.push(agentLine(agent, i, agents.length, undefined, now)));
|
|
49289
|
+
upperLines = tools.slice(-MERGED_DOCK_TOOL_ONLY_MAX).map((tool) => toolOnlyLine(tool, now, spin));
|
|
49290
|
+
const summary = todosSummaryFromTodos(data.todos);
|
|
49291
|
+
lowerRaw = summary === "" ? [] : [{ kind: "todo", segments: [{ text: summary, tone: "running" }] }];
|
|
49229
49292
|
}
|
|
49230
49293
|
const assembled = assembleZones(upperLines, lowerRaw, options.totalLines ?? MERGED_DOCK_TOTAL_LINES, options.cursor);
|
|
49231
49294
|
return { lines: fitAll(assembled.lines, options.innerWidth), info: assembled.info };
|
|
@@ -49351,26 +49414,81 @@ function activityPanelCapSpec(gear, terminalRows) {
|
|
|
49351
49414
|
maxLines: dockLineCap(terminalRows)
|
|
49352
49415
|
};
|
|
49353
49416
|
}
|
|
49354
|
-
if (gear === "all")
|
|
49355
|
-
if (terminalRows === undefined)
|
|
49356
|
-
return {
|
|
49357
|
-
maxLines: PANEL_UNBOUNDED_LINES
|
|
49358
|
-
};
|
|
49359
|
-
return {
|
|
49360
|
-
maxLines: PANEL_UNBOUNDED_LINES,
|
|
49361
|
-
totalMaxLines: Math.max(1, Math.floor(terminalRows * 2 / 3) - 2)
|
|
49362
|
-
};
|
|
49363
|
-
}
|
|
49364
|
-
const cap = Number(gear);
|
|
49365
|
-
if (terminalRows === undefined)
|
|
49417
|
+
if (gear === "all")
|
|
49366
49418
|
return {
|
|
49367
|
-
maxLines:
|
|
49419
|
+
maxLines: ACTIVITY_PANEL_ALL_LINES
|
|
49368
49420
|
};
|
|
49369
|
-
const halfBudget = Math.floor(Math.max(1, Math.floor(terminalRows * 2 / 3) - 2) / 2);
|
|
49370
49421
|
return {
|
|
49371
|
-
maxLines: Math.min(
|
|
49422
|
+
maxLines: Math.min(Number(gear), MERGED_DOCK_TOTAL_LINES)
|
|
49372
49423
|
};
|
|
49373
49424
|
}
|
|
49425
|
+
function dockHeightEase(t) {
|
|
49426
|
+
const k = Math.max(0, Math.min(1, t));
|
|
49427
|
+
return k * k * (3 - 2 * k);
|
|
49428
|
+
}
|
|
49429
|
+
function dockHeightLines(from, to, elapsedMs, durationMs = DOCK_HEIGHT_ANIM_MS) {
|
|
49430
|
+
const a = Math.max(0, Math.floor(from));
|
|
49431
|
+
const b = Math.max(0, Math.floor(to));
|
|
49432
|
+
if (elapsedMs <= 0)
|
|
49433
|
+
return a;
|
|
49434
|
+
if (elapsedMs >= durationMs)
|
|
49435
|
+
return b;
|
|
49436
|
+
return Math.max(0, Math.round(a + (b - a) * dockHeightEase(elapsedMs / durationMs)));
|
|
49437
|
+
}
|
|
49438
|
+
function dockHeightContentLines(target, now = Date.now()) {
|
|
49439
|
+
if (!motionAnimationRunning())
|
|
49440
|
+
return target;
|
|
49441
|
+
const tween = dockHeightTween();
|
|
49442
|
+
if (tween === undefined)
|
|
49443
|
+
return target;
|
|
49444
|
+
return dockHeightLines(tween.from, tween.to, now - tween.startedAt);
|
|
49445
|
+
}
|
|
49446
|
+
function setDockHeightTarget(target, now = Date.now()) {
|
|
49447
|
+
dockFrameNow = now;
|
|
49448
|
+
const to = Math.max(0, Math.min(MERGED_DOCK_TOTAL_LINES, Math.floor(target)));
|
|
49449
|
+
const current = untrack(dockHeightTween);
|
|
49450
|
+
if (current !== undefined) {
|
|
49451
|
+
if (current.to === to)
|
|
49452
|
+
return;
|
|
49453
|
+
const from = Math.min(current.to, dockHeightLines(current.from, current.to, now - current.startedAt));
|
|
49454
|
+
if (from === 0 || to === 0 || !motionAnimationRunning()) {
|
|
49455
|
+
setDockHeightTween(undefined);
|
|
49456
|
+
dockHeightSettled = to;
|
|
49457
|
+
return;
|
|
49458
|
+
}
|
|
49459
|
+
setDockHeightTween({
|
|
49460
|
+
from,
|
|
49461
|
+
to,
|
|
49462
|
+
startedAt: now
|
|
49463
|
+
});
|
|
49464
|
+
} else {
|
|
49465
|
+
if (dockHeightSettled === to)
|
|
49466
|
+
return;
|
|
49467
|
+
if (dockHeightSettled === undefined || dockHeightSettled === 0 || to === 0 || !motionAnimationRunning()) {
|
|
49468
|
+
dockHeightSettled = to;
|
|
49469
|
+
return;
|
|
49470
|
+
}
|
|
49471
|
+
setDockHeightTween({
|
|
49472
|
+
from: dockHeightSettled,
|
|
49473
|
+
to,
|
|
49474
|
+
startedAt: now
|
|
49475
|
+
});
|
|
49476
|
+
}
|
|
49477
|
+
dockHeightSettled = to;
|
|
49478
|
+
}
|
|
49479
|
+
function dockHeightAnimating() {
|
|
49480
|
+
return dockHeightTween() !== undefined;
|
|
49481
|
+
}
|
|
49482
|
+
function tickDockHeight(now = Date.now()) {
|
|
49483
|
+
dockFrameNow = now;
|
|
49484
|
+
const current = untrack(dockHeightTween);
|
|
49485
|
+
if (current !== undefined && now - current.startedAt >= DOCK_HEIGHT_ANIM_MS)
|
|
49486
|
+
setDockHeightTween(undefined);
|
|
49487
|
+
}
|
|
49488
|
+
function resetDockHeight(to) {
|
|
49489
|
+
setDockHeightTween(undefined);
|
|
49490
|
+
dockHeightSettled = to === undefined ? undefined : Math.max(0, Math.min(MERGED_DOCK_TOTAL_LINES, Math.floor(to)));
|
|
49491
|
+
}
|
|
49374
49492
|
function skinNoticeFadeProgress(elapsedMs, ttlMs) {
|
|
49375
49493
|
return Math.max(0, Math.min(1, (elapsedMs - (ttlMs - SKIN_NOTICE_FADE_MS)) / SKIN_NOTICE_FADE_MS));
|
|
49376
49494
|
}
|
|
@@ -49440,7 +49558,9 @@ function latestTodos(rows) {
|
|
|
49440
49558
|
return parseTodos(todoArray(source) ?? []);
|
|
49441
49559
|
}
|
|
49442
49560
|
function todosSummaryLine(rows) {
|
|
49443
|
-
|
|
49561
|
+
return todosSummaryFromTodos(latestTodos(rows));
|
|
49562
|
+
}
|
|
49563
|
+
function todosSummaryFromTodos(todos) {
|
|
49444
49564
|
if (todos.length === 0)
|
|
49445
49565
|
return "";
|
|
49446
49566
|
const done = todos.filter((todo) => todo.status === "completed").length;
|
|
@@ -49453,6 +49573,25 @@ function todosSummaryLine(rows) {
|
|
|
49453
49573
|
});
|
|
49454
49574
|
return active ? `${head} \xB7 ${active.content}` : head;
|
|
49455
49575
|
}
|
|
49576
|
+
function todoSetStartedAt(todos, now = Date.now()) {
|
|
49577
|
+
const sig = todoSetSignature(todos);
|
|
49578
|
+
const first = todoSetFirstSeen.get(sig);
|
|
49579
|
+
if (first !== undefined)
|
|
49580
|
+
return first;
|
|
49581
|
+
todoSetFirstSeen.set(sig, now);
|
|
49582
|
+
return now;
|
|
49583
|
+
}
|
|
49584
|
+
function todoBriefLine(todos, now = Date.now(), startedAt) {
|
|
49585
|
+
if (todos.length === 0)
|
|
49586
|
+
return "";
|
|
49587
|
+
const done = todos.filter((todo) => todo.status === "completed").length;
|
|
49588
|
+
const anchor = startedAt ?? todoSetStartedAt(todos, now);
|
|
49589
|
+
const secs = Math.max(0, Math.floor((now - anchor) / 1000));
|
|
49590
|
+
return `todo ${done}/${todos.length} ${secs}s`;
|
|
49591
|
+
}
|
|
49592
|
+
function resetTodoBriefClock() {
|
|
49593
|
+
todoSetFirstSeen.clear();
|
|
49594
|
+
}
|
|
49456
49595
|
function toolMarker(status) {
|
|
49457
49596
|
return status === "running" ? "\u2699" : status === "failed" ? "\u2718" : "\u2714";
|
|
49458
49597
|
}
|
|
@@ -49489,13 +49628,20 @@ function thinkBlockLines(row, spin, maxLines = DOCK_WIDGET_MAX_LINES, now = Date
|
|
|
49489
49628
|
}
|
|
49490
49629
|
return [];
|
|
49491
49630
|
}
|
|
49631
|
+
function activityScene(hasRunningSubagent, hasVisibleThink) {
|
|
49632
|
+
if (hasRunningSubagent)
|
|
49633
|
+
return "A";
|
|
49634
|
+
return hasVisibleThink ? "B" : "C";
|
|
49635
|
+
}
|
|
49492
49636
|
function dockBlocks(rows, options = {}) {
|
|
49493
49637
|
dockSpin();
|
|
49494
49638
|
const now = options.now ?? Date.now();
|
|
49495
49639
|
const decorated = options.decorated ?? motionDecorationsEnabled();
|
|
49496
49640
|
const maxLines = Math.max(1, Math.floor(options.maxLines ?? DOCK_WIDGET_MAX_LINES));
|
|
49641
|
+
const gearThinkMaxLines = Math.max(1, Math.floor(options.thinkMaxLines ?? maxLines));
|
|
49497
49642
|
const think = [];
|
|
49498
49643
|
const toolLines = [];
|
|
49644
|
+
const hasRunningSubagent = rows.some((row) => row.kind === "subagents" && row.children.some((child) => child.status === "running"));
|
|
49499
49645
|
const reasoning = rows.filter((row) => row.kind === "reasoning");
|
|
49500
49646
|
const live = [...reasoning].reverse().find((row) => row.streaming === true);
|
|
49501
49647
|
let thinkRow = live;
|
|
@@ -49511,10 +49657,12 @@ function dockBlocks(rows, options = {}) {
|
|
|
49511
49657
|
}
|
|
49512
49658
|
}
|
|
49513
49659
|
}
|
|
49660
|
+
const scene = activityScene(hasRunningSubagent, thinkRow !== undefined);
|
|
49661
|
+
const effectiveThinkMax = scene === "A" ? 1 : gearThinkMaxLines;
|
|
49514
49662
|
if (thinkRow !== undefined) {
|
|
49515
49663
|
const stopAt = skinStopAt(thinkRow);
|
|
49516
49664
|
const fadeOutAt = thinkRow.streaming === true ? undefined : stopAt;
|
|
49517
|
-
for (const text of thinkBlockLines(thinkRow, dockSpin,
|
|
49665
|
+
for (const text of thinkBlockLines(thinkRow, dockSpin, effectiveThinkMax, now)) {
|
|
49518
49666
|
think.push({
|
|
49519
49667
|
text,
|
|
49520
49668
|
tone: "running",
|
|
@@ -49525,7 +49673,8 @@ function dockBlocks(rows, options = {}) {
|
|
|
49525
49673
|
});
|
|
49526
49674
|
}
|
|
49527
49675
|
}
|
|
49528
|
-
const
|
|
49676
|
+
const toolMax = scene === "B" ? 0 : scene === "A" ? 1 : maxLines;
|
|
49677
|
+
const tools = toolMax === 0 ? [] : rows.filter((row) => row.kind === "tool" && row.key.startsWith("tool:live:"));
|
|
49529
49678
|
const visible = tools.filter((row) => {
|
|
49530
49679
|
if (row.faded === true && row.status !== "running")
|
|
49531
49680
|
return false;
|
|
@@ -49534,7 +49683,7 @@ function dockBlocks(rows, options = {}) {
|
|
|
49534
49683
|
const stopAt = skinStopAt(row);
|
|
49535
49684
|
return stopAt === undefined || dockLineVisibility(stopAt, now, decorated).phase !== "hidden";
|
|
49536
49685
|
});
|
|
49537
|
-
for (const row of visible.slice(-
|
|
49686
|
+
for (const row of visible.slice(-toolMax)) {
|
|
49538
49687
|
toolLines.push({
|
|
49539
49688
|
text: toolLineText(row, dockSpin, now),
|
|
49540
49689
|
tone: row.status === "running" ? "running" : row.status === "failed" ? "failed" : "ok",
|
|
@@ -49799,14 +49948,24 @@ function WidgetsDock(props) {
|
|
|
49799
49948
|
decorated: motionDecorationsEnabled(),
|
|
49800
49949
|
background: bg()
|
|
49801
49950
|
});
|
|
49802
|
-
onAnimationTick(() =>
|
|
49951
|
+
onAnimationTick(() => {
|
|
49952
|
+
if (!motionAnimationRunning())
|
|
49953
|
+
return;
|
|
49954
|
+
if (untrack(dockHeightAnimating))
|
|
49955
|
+
return motionFrameRate();
|
|
49956
|
+
return dockNeedsClock(props.rows) ? motionFrameRate() : undefined;
|
|
49957
|
+
}, () => {
|
|
49958
|
+
tickDockHeight();
|
|
49959
|
+
setDockSpin((s) => s + 1);
|
|
49960
|
+
});
|
|
49803
49961
|
const width = () => Math.max(16, dimensions().width - 4);
|
|
49804
49962
|
const turnActive = () => props.turnActive?.() ?? dockTurnActive(props.rows);
|
|
49805
49963
|
createEffect(() => activityFrameLatch.push(turnActive() || mergedLowerHasContent(props.rows)));
|
|
49806
49964
|
onCleanup(activityFrameLatch.dispose);
|
|
49807
49965
|
const frame = () => activityFrameMode(dimensions().height);
|
|
49808
49966
|
const capSpec = () => activityPanelCapSpec(activityPanelGear(), dimensions().height);
|
|
49809
|
-
const
|
|
49967
|
+
const thinkCap = () => capSpec().maxLines;
|
|
49968
|
+
const toolCap = () => dockLineCap(dimensions().height);
|
|
49810
49969
|
const mergedSource = (now) => {
|
|
49811
49970
|
dockSpin();
|
|
49812
49971
|
return {
|
|
@@ -49816,19 +49975,14 @@ function WidgetsDock(props) {
|
|
|
49816
49975
|
agents: mergedRunningAgents(props.rows)
|
|
49817
49976
|
};
|
|
49818
49977
|
};
|
|
49819
|
-
const gearTotal = () => {
|
|
49820
|
-
const gear = activityPanelGear();
|
|
49821
|
-
if (gear === undefined || gear === "all")
|
|
49822
|
-
return MERGED_DOCK_TOTAL_LINES;
|
|
49823
|
-
return Number(gear);
|
|
49824
|
-
};
|
|
49825
49978
|
const mergedFrame = () => {
|
|
49826
49979
|
const now = Date.now();
|
|
49827
49980
|
const data = mergedSource(now);
|
|
49828
49981
|
const options = {
|
|
49829
49982
|
innerWidth: width(),
|
|
49830
49983
|
now,
|
|
49831
|
-
totalLines:
|
|
49984
|
+
totalLines: MERGED_DOCK_TOTAL_LINES,
|
|
49985
|
+
thinkLines: thinkCap(),
|
|
49832
49986
|
cursor: mergedDockCursor()
|
|
49833
49987
|
};
|
|
49834
49988
|
return {
|
|
@@ -49836,6 +49990,11 @@ function WidgetsDock(props) {
|
|
|
49836
49990
|
info: mergedWindowInfo(data, options)
|
|
49837
49991
|
};
|
|
49838
49992
|
};
|
|
49993
|
+
createEffect(() => setDockHeightTarget(mergedFrame().lines.length));
|
|
49994
|
+
onCleanup(() => {
|
|
49995
|
+
resetDockHeight();
|
|
49996
|
+
resetTodoBriefClock();
|
|
49997
|
+
});
|
|
49839
49998
|
const titleSlotWidth = () => dimensions().width - 4;
|
|
49840
49999
|
const mergedTitleText = () => {
|
|
49841
50000
|
const {
|
|
@@ -49890,7 +50049,15 @@ function WidgetsDock(props) {
|
|
|
49890
50049
|
bindings: ["session.dock.scroll.up", "session.dock.scroll.down"]
|
|
49891
50050
|
}));
|
|
49892
50051
|
}
|
|
49893
|
-
const
|
|
50052
|
+
const frameLines = () => {
|
|
50053
|
+
const lines = mergedFrame().lines;
|
|
50054
|
+
const target = lines.length;
|
|
50055
|
+
const tweened = Math.max(0, dockHeightContentLines(target, dockFrameNow));
|
|
50056
|
+
const animating = untrack(dockHeightAnimating);
|
|
50057
|
+
const count = !animating || tweened >= target ? target : Math.min(target, tweened);
|
|
50058
|
+
return lines.slice(0, count);
|
|
50059
|
+
};
|
|
50060
|
+
const frameHeight = () => 2 + frameLines().length;
|
|
49894
50061
|
const compactSummary = () => mergedCompactSummary(props.rows);
|
|
49895
50062
|
const compactHeight = () => 2 + (compactSummary() === "" ? 0 : 1);
|
|
49896
50063
|
const accentFg = (accent) => dockAccentColor(theme, accent);
|
|
@@ -49948,10 +50115,10 @@ function WidgetsDock(props) {
|
|
|
49948
50115
|
return skinCtx();
|
|
49949
50116
|
},
|
|
49950
50117
|
get maxLines() {
|
|
49951
|
-
return
|
|
50118
|
+
return toolCap();
|
|
49952
50119
|
},
|
|
49953
|
-
get
|
|
49954
|
-
return
|
|
50120
|
+
get thinkMaxLines() {
|
|
50121
|
+
return thinkCap();
|
|
49955
50122
|
}
|
|
49956
50123
|
});
|
|
49957
50124
|
},
|
|
@@ -50000,7 +50167,7 @@ function WidgetsDock(props) {
|
|
|
50000
50167
|
setProp(_el$4, "onMouseScroll", onMergedWheel);
|
|
50001
50168
|
insert(_el$4, createComponent2(For, {
|
|
50002
50169
|
get each() {
|
|
50003
|
-
return
|
|
50170
|
+
return frameLines();
|
|
50004
50171
|
},
|
|
50005
50172
|
children: mergedLineView
|
|
50006
50173
|
}));
|
|
@@ -50026,9 +50193,7 @@ function WidgetsDock(props) {
|
|
|
50026
50193
|
function FlatDock(props) {
|
|
50027
50194
|
const dockOptions = () => ({
|
|
50028
50195
|
maxLines: props.maxLines,
|
|
50029
|
-
|
|
50030
|
-
totalMaxLines: props.totalMaxLines
|
|
50031
|
-
} : {}
|
|
50196
|
+
thinkMaxLines: props.thinkMaxLines
|
|
50032
50197
|
});
|
|
50033
50198
|
return (() => {
|
|
50034
50199
|
var _el$7 = createElement("box");
|
|
@@ -50082,7 +50247,7 @@ function dockLineNode(line, width, ctx, fgFor, accentFg) {
|
|
|
50082
50247
|
return _el$9;
|
|
50083
50248
|
})();
|
|
50084
50249
|
}
|
|
50085
|
-
var SKIN_FADE_IN_MS = 400, SKIN_NOTICE_FADE_MS = 500, SKIN_PULSE_MS = 1200, SKIN_PULSE_CYCLES = 3, SKIN_PULSE_DIM = 0.45, SKIN_FAINT_MIX = 0.78, ACTIVITY_PANEL_GEARS,
|
|
50250
|
+
var SKIN_FADE_IN_MS = 400, SKIN_NOTICE_FADE_MS = 500, SKIN_PULSE_MS = 1200, SKIN_PULSE_CYCLES = 3, SKIN_PULSE_DIM = 0.45, SKIN_FAINT_MIX = 0.78, ACTIVITY_PANEL_GEARS, ACTIVITY_PANEL_ALL_LINES = 10, activityPanelGear, setActivityPanelGear, DOCK_HEIGHT_ANIM_MS = 200, dockHeightTween, setDockHeightTween, dockHeightSettled = undefined, dockFrameNow = 0, LINE_FIRST_SEEN_MAX = 512, lineFirstSeen, dockSpin, setDockSpin, mergedDockCursor, setMergedDockCursor, todoSetSignature = (todos) => todos.map((todo) => todo.content).sort().join("\x01"), todoSetFirstSeen, TODO_TOOL_NAMES, ACTIVITY_FRAME_BORDER_FALLBACK = "#7aa2f7", ACTIVITY_FRAME_MIN_CONTRAST = 6, ACTIVITY_BLUE_STEPS, BLUE_HUE_MIN = 190, BLUE_HUE_MAX = 250, BLUE_MIN_SATURATION = 0.25, AUTO_POLE_LIGHT = "#ffffff", AUTO_POLE_DARK = "#000000", DOCK_ACCENT_STEPS, DOCK_ACCENT_HUES, DOCK_ACCENT_FALLBACK, ACTIVITY_FRAME_DEFER_MS = 60, activityFrameLatch;
|
|
50086
50251
|
var init_widgets_dock = __esm(() => {
|
|
50087
50252
|
init_index_bun();
|
|
50088
50253
|
init_index_bun();
|
|
@@ -50108,9 +50273,11 @@ var init_widgets_dock = __esm(() => {
|
|
|
50108
50273
|
init_input_ownership();
|
|
50109
50274
|
ACTIVITY_PANEL_GEARS = ["1", "5", "7", "10", "all"];
|
|
50110
50275
|
[activityPanelGear, setActivityPanelGear] = createSignal(undefined);
|
|
50276
|
+
[dockHeightTween, setDockHeightTween] = createSignal(undefined);
|
|
50111
50277
|
lineFirstSeen = new Map;
|
|
50112
50278
|
[dockSpin, setDockSpin] = createSignal(0);
|
|
50113
50279
|
[mergedDockCursor, setMergedDockCursor] = createSignal(0);
|
|
50280
|
+
todoSetFirstSeen = new Map;
|
|
50114
50281
|
TODO_TOOL_NAMES = new Set(["todowrite", "todo_write"]);
|
|
50115
50282
|
ACTIVITY_BLUE_STEPS = [200, 100, 300, 400, 500, 600, 700];
|
|
50116
50283
|
DOCK_ACCENT_STEPS = {
|
|
@@ -50296,6 +50463,17 @@ function Transcript(props) {
|
|
|
50296
50463
|
setProp(_el$3, "paddingLeft", 2);
|
|
50297
50464
|
setProp(_el$3, "border", ["top", "bottom", "left", "right"]);
|
|
50298
50465
|
setProp(_el$3, "borderStyle", "single");
|
|
50466
|
+
insert(_el$3, createComponent2(Show, {
|
|
50467
|
+
get when() {
|
|
50468
|
+
return row.unconfirmed === true;
|
|
50469
|
+
},
|
|
50470
|
+
get children() {
|
|
50471
|
+
var _el$4 = createElement("text");
|
|
50472
|
+
insert(_el$4, () => t("recovery.input.unconfirmed"));
|
|
50473
|
+
effect((_$p) => setProp(_el$4, "fg", color.pendingQueue(), _$p));
|
|
50474
|
+
return _el$4;
|
|
50475
|
+
}
|
|
50476
|
+
}), null);
|
|
50299
50477
|
insert(_el$3, createComponent2(UserMessageFade, {
|
|
50300
50478
|
get target() {
|
|
50301
50479
|
return color.user();
|
|
@@ -50306,10 +50484,32 @@ function Transcript(props) {
|
|
|
50306
50484
|
get text() {
|
|
50307
50485
|
return row.text;
|
|
50308
50486
|
}
|
|
50309
|
-
}));
|
|
50487
|
+
}), null);
|
|
50310
50488
|
effect((_$p) => setProp(_el$3, "borderColor", unfocusedBorderColor(theme), _$p));
|
|
50311
50489
|
return _el$3;
|
|
50312
50490
|
})();
|
|
50491
|
+
case "interrupted":
|
|
50492
|
+
return (() => {
|
|
50493
|
+
var _el$5 = createElement("box"), _el$6 = createElement("text");
|
|
50494
|
+
insertNode(_el$5, _el$6);
|
|
50495
|
+
setProp(_el$5, "flexShrink", 0);
|
|
50496
|
+
setProp(_el$5, "paddingLeft", 2);
|
|
50497
|
+
setProp(_el$5, "border", ["top", "bottom", "left", "right"]);
|
|
50498
|
+
setProp(_el$5, "borderStyle", "single");
|
|
50499
|
+
insert(_el$6, () => t("recovery.turn.interrupted", {
|
|
50500
|
+
turnId: row.turnId
|
|
50501
|
+
}));
|
|
50502
|
+
effect((_p$) => {
|
|
50503
|
+
var _v$6 = color.running(), _v$7 = color.running();
|
|
50504
|
+
_v$6 !== _p$.e && (_p$.e = setProp(_el$5, "borderColor", _v$6, _p$.e));
|
|
50505
|
+
_v$7 !== _p$.t && (_p$.t = setProp(_el$6, "fg", _v$7, _p$.t));
|
|
50506
|
+
return _p$;
|
|
50507
|
+
}, {
|
|
50508
|
+
e: undefined,
|
|
50509
|
+
t: undefined
|
|
50510
|
+
});
|
|
50511
|
+
return _el$5;
|
|
50512
|
+
})();
|
|
50313
50513
|
case "assistant":
|
|
50314
50514
|
return assistantRow(row);
|
|
50315
50515
|
case "ask":
|
|
@@ -50322,68 +50522,68 @@ function Transcript(props) {
|
|
|
50322
50522
|
props.scrollRef?.(undefined);
|
|
50323
50523
|
});
|
|
50324
50524
|
return (() => {
|
|
50325
|
-
var _el$
|
|
50326
|
-
insertNode(_el$
|
|
50327
|
-
setProp(_el$
|
|
50328
|
-
setProp(_el$
|
|
50329
|
-
setProp(_el$
|
|
50330
|
-
setProp(_el$
|
|
50331
|
-
insertNode(_el$
|
|
50332
|
-
setProp(_el$
|
|
50333
|
-
setProp(_el$
|
|
50334
|
-
setProp(_el$
|
|
50335
|
-
insertNode(_el$
|
|
50336
|
-
setProp(_el$
|
|
50337
|
-
setProp(_el$
|
|
50338
|
-
setProp(_el$
|
|
50339
|
-
setProp(_el$
|
|
50525
|
+
var _el$7 = createElement("box"), _el$8 = createElement("box"), _el$9 = createElement("box"), _el$0 = createElement("scrollbox");
|
|
50526
|
+
insertNode(_el$7, _el$8);
|
|
50527
|
+
setProp(_el$7, "flexDirection", "column");
|
|
50528
|
+
setProp(_el$7, "flexGrow", 1);
|
|
50529
|
+
setProp(_el$7, "minHeight", 0);
|
|
50530
|
+
setProp(_el$7, "width", "100%");
|
|
50531
|
+
insertNode(_el$8, _el$9);
|
|
50532
|
+
setProp(_el$8, "flexDirection", "row");
|
|
50533
|
+
setProp(_el$8, "flexGrow", 1);
|
|
50534
|
+
setProp(_el$8, "minHeight", 0);
|
|
50535
|
+
insertNode(_el$9, _el$0);
|
|
50536
|
+
setProp(_el$9, "flexGrow", 1);
|
|
50537
|
+
setProp(_el$9, "minHeight", 0);
|
|
50538
|
+
setProp(_el$9, "position", "relative");
|
|
50539
|
+
setProp(_el$9, "paddingBottom", 1);
|
|
50340
50540
|
use((value) => {
|
|
50341
50541
|
props.scrollRef?.(value);
|
|
50342
|
-
}, _el$
|
|
50343
|
-
setProp(_el$
|
|
50344
|
-
setProp(_el$
|
|
50345
|
-
setProp(_el$
|
|
50346
|
-
setProp(_el$
|
|
50347
|
-
insert(_el$
|
|
50542
|
+
}, _el$0);
|
|
50543
|
+
setProp(_el$0, "flexGrow", 1);
|
|
50544
|
+
setProp(_el$0, "overflow", "hidden");
|
|
50545
|
+
setProp(_el$0, "stickyScroll", true);
|
|
50546
|
+
setProp(_el$0, "stickyStart", "bottom");
|
|
50547
|
+
insert(_el$0, createComponent2(For, {
|
|
50348
50548
|
get each() {
|
|
50349
50549
|
return visibleRows();
|
|
50350
50550
|
},
|
|
50351
50551
|
children: (row) => (() => {
|
|
50352
|
-
var _el$
|
|
50353
|
-
setProp(_el$
|
|
50354
|
-
setProp(_el$
|
|
50355
|
-
insert(_el$
|
|
50356
|
-
effect((_$p) => setProp(_el$
|
|
50357
|
-
return _el$
|
|
50552
|
+
var _el$12 = createElement("box");
|
|
50553
|
+
setProp(_el$12, "marginTop", 1);
|
|
50554
|
+
setProp(_el$12, "flexShrink", 0);
|
|
50555
|
+
insert(_el$12, () => rowView(row));
|
|
50556
|
+
effect((_$p) => setProp(_el$12, "id", `seam-row-${row.key}`, _$p));
|
|
50557
|
+
return _el$12;
|
|
50358
50558
|
})()
|
|
50359
50559
|
}), null);
|
|
50360
|
-
insert(_el$
|
|
50560
|
+
insert(_el$0, createComponent2(Show, {
|
|
50361
50561
|
get when() {
|
|
50362
50562
|
return projection.hydrated() === false;
|
|
50363
50563
|
},
|
|
50364
50564
|
get children() {
|
|
50365
|
-
var _el$
|
|
50366
|
-
insertNode(_el$
|
|
50367
|
-
setProp(_el$
|
|
50368
|
-
insert(_el$
|
|
50369
|
-
effect((_$p) => setProp(_el$
|
|
50370
|
-
return _el$
|
|
50565
|
+
var _el$1 = createElement("box"), _el$10 = createElement("text");
|
|
50566
|
+
insertNode(_el$1, _el$10);
|
|
50567
|
+
setProp(_el$1, "flexShrink", 0);
|
|
50568
|
+
insert(_el$10, () => t("transcript.loading"));
|
|
50569
|
+
effect((_$p) => setProp(_el$10, "fg", color.loading(), _$p));
|
|
50570
|
+
return _el$1;
|
|
50371
50571
|
}
|
|
50372
50572
|
}), null);
|
|
50373
|
-
insert(_el$
|
|
50573
|
+
insert(_el$0, createComponent2(For, {
|
|
50374
50574
|
get each() {
|
|
50375
50575
|
return props.pending?.() ?? [];
|
|
50376
50576
|
},
|
|
50377
50577
|
children: (row) => (() => {
|
|
50378
|
-
var _el$
|
|
50379
|
-
setProp(_el$
|
|
50380
|
-
setProp(_el$
|
|
50381
|
-
insert(_el$
|
|
50578
|
+
var _el$13 = createElement("box");
|
|
50579
|
+
setProp(_el$13, "marginTop", 1);
|
|
50580
|
+
setProp(_el$13, "flexShrink", 0);
|
|
50581
|
+
insert(_el$13, (() => {
|
|
50382
50582
|
var _c$ = memo2(() => row.kind === "queue");
|
|
50383
50583
|
return () => _c$() ? (() => {
|
|
50384
|
-
var _el$
|
|
50385
|
-
setProp(_el$
|
|
50386
|
-
insert(_el$
|
|
50584
|
+
var _el$14 = createElement("text");
|
|
50585
|
+
setProp(_el$14, "wrapMode", "word");
|
|
50586
|
+
insert(_el$14, (() => {
|
|
50387
50587
|
var _c$2 = memo2(() => row.state === "paused");
|
|
50388
50588
|
return () => _c$2() ? t("transcript.pending.queue.paused", {
|
|
50389
50589
|
order: row.order ?? 1,
|
|
@@ -50394,19 +50594,19 @@ function Transcript(props) {
|
|
|
50394
50594
|
});
|
|
50395
50595
|
})());
|
|
50396
50596
|
effect((_p$) => {
|
|
50397
|
-
var _v$
|
|
50398
|
-
_v$
|
|
50399
|
-
_v$
|
|
50597
|
+
var _v$14 = color.pendingQueue(), _v$15 = TextAttributes6.ITALIC;
|
|
50598
|
+
_v$14 !== _p$.e && (_p$.e = setProp(_el$14, "fg", _v$14, _p$.e));
|
|
50599
|
+
_v$15 !== _p$.t && (_p$.t = setProp(_el$14, "attributes", _v$15, _p$.t));
|
|
50400
50600
|
return _p$;
|
|
50401
50601
|
}, {
|
|
50402
50602
|
e: undefined,
|
|
50403
50603
|
t: undefined
|
|
50404
50604
|
});
|
|
50405
|
-
return _el$
|
|
50605
|
+
return _el$14;
|
|
50406
50606
|
})() : (() => {
|
|
50407
|
-
var _el$
|
|
50408
|
-
setProp(_el$
|
|
50409
|
-
insert(_el$
|
|
50607
|
+
var _el$15 = createElement("text");
|
|
50608
|
+
setProp(_el$15, "wrapMode", "word");
|
|
50609
|
+
insert(_el$15, (() => {
|
|
50410
50610
|
var _c$3 = memo2(() => row.state === "delivered");
|
|
50411
50611
|
return () => _c$3() ? t("transcript.pending.steer.delivered", {
|
|
50412
50612
|
text: row.text
|
|
@@ -50414,35 +50614,35 @@ function Transcript(props) {
|
|
|
50414
50614
|
text: row.text
|
|
50415
50615
|
});
|
|
50416
50616
|
})());
|
|
50417
|
-
effect((_$p) => setProp(_el$
|
|
50418
|
-
return _el$
|
|
50617
|
+
effect((_$p) => setProp(_el$15, "fg", color.pendingSteer(), _$p));
|
|
50618
|
+
return _el$15;
|
|
50419
50619
|
})();
|
|
50420
50620
|
})());
|
|
50421
|
-
effect((_$p) => setProp(_el$
|
|
50422
|
-
return _el$
|
|
50621
|
+
effect((_$p) => setProp(_el$13, "id", `pending-row-${row.id}`, _$p));
|
|
50622
|
+
return _el$13;
|
|
50423
50623
|
})()
|
|
50424
50624
|
}), null);
|
|
50425
|
-
insert(_el$
|
|
50625
|
+
insert(_el$7, createComponent2(Show, {
|
|
50426
50626
|
get when() {
|
|
50427
50627
|
return props.status || props.widgets || props.children || props.footer || props.notices;
|
|
50428
50628
|
},
|
|
50429
50629
|
get children() {
|
|
50430
|
-
var _el$
|
|
50431
|
-
setProp(_el$
|
|
50432
|
-
setProp(_el$
|
|
50433
|
-
setProp(_el$
|
|
50434
|
-
insert(_el$
|
|
50435
|
-
insert(_el$
|
|
50436
|
-
insert(_el$
|
|
50437
|
-
insert(_el$
|
|
50438
|
-
insert(_el$
|
|
50439
|
-
return _el$
|
|
50630
|
+
var _el$11 = createElement("box");
|
|
50631
|
+
setProp(_el$11, "width", "100%");
|
|
50632
|
+
setProp(_el$11, "flexShrink", 0);
|
|
50633
|
+
setProp(_el$11, "flexDirection", "column");
|
|
50634
|
+
insert(_el$11, () => props.status, null);
|
|
50635
|
+
insert(_el$11, () => props.widgets, null);
|
|
50636
|
+
insert(_el$11, () => props.children, null);
|
|
50637
|
+
insert(_el$11, () => props.footer, null);
|
|
50638
|
+
insert(_el$11, () => props.notices, null);
|
|
50639
|
+
return _el$11;
|
|
50440
50640
|
}
|
|
50441
50641
|
}), null);
|
|
50442
50642
|
effect((_p$) => {
|
|
50443
|
-
var _v$
|
|
50643
|
+
var _v$8 = color.background(), _v$9 = frame().border, _v$0 = frame().borderStyle, _v$1 = frame().borderColor, _v$10 = frame().title, _v$11 = frame().titleColor, _v$12 = {
|
|
50444
50644
|
paddingRight: props.scrollbar ? 1 : 0
|
|
50445
|
-
}, _v$
|
|
50645
|
+
}, _v$13 = {
|
|
50446
50646
|
paddingLeft: 1,
|
|
50447
50647
|
visible: props.scrollbar ?? false,
|
|
50448
50648
|
trackOptions: {
|
|
@@ -50450,14 +50650,14 @@ function Transcript(props) {
|
|
|
50450
50650
|
foregroundColor: color.reasoningBorder()
|
|
50451
50651
|
}
|
|
50452
50652
|
};
|
|
50453
|
-
_v$
|
|
50454
|
-
_v$
|
|
50455
|
-
_v$
|
|
50456
|
-
_v$
|
|
50457
|
-
_v$
|
|
50458
|
-
_v$
|
|
50459
|
-
_v$
|
|
50460
|
-
_v$
|
|
50653
|
+
_v$8 !== _p$.e && (_p$.e = setProp(_el$7, "backgroundColor", _v$8, _p$.e));
|
|
50654
|
+
_v$9 !== _p$.t && (_p$.t = setProp(_el$8, "border", _v$9, _p$.t));
|
|
50655
|
+
_v$0 !== _p$.a && (_p$.a = setProp(_el$8, "borderStyle", _v$0, _p$.a));
|
|
50656
|
+
_v$1 !== _p$.o && (_p$.o = setProp(_el$8, "borderColor", _v$1, _p$.o));
|
|
50657
|
+
_v$10 !== _p$.i && (_p$.i = setProp(_el$8, "title", _v$10, _p$.i));
|
|
50658
|
+
_v$11 !== _p$.n && (_p$.n = setProp(_el$8, "titleColor", _v$11, _p$.n));
|
|
50659
|
+
_v$12 !== _p$.s && (_p$.s = setProp(_el$0, "viewportOptions", _v$12, _p$.s));
|
|
50660
|
+
_v$13 !== _p$.h && (_p$.h = setProp(_el$0, "verticalScrollbarOptions", _v$13, _p$.h));
|
|
50461
50661
|
return _p$;
|
|
50462
50662
|
}, {
|
|
50463
50663
|
e: undefined,
|
|
@@ -50469,7 +50669,7 @@ function Transcript(props) {
|
|
|
50469
50669
|
s: undefined,
|
|
50470
50670
|
h: undefined
|
|
50471
50671
|
});
|
|
50472
|
-
return _el$
|
|
50672
|
+
return _el$7;
|
|
50473
50673
|
})();
|
|
50474
50674
|
}
|
|
50475
50675
|
function AskReplayBlock(props) {
|
|
@@ -50479,55 +50679,55 @@ function AskReplayBlock(props) {
|
|
|
50479
50679
|
const askAnswerOf = (entry) => entry.selected.map((label) => splitRecommended(label).label).join(", ") || entry.custom || t("transcript.ask.declined");
|
|
50480
50680
|
const askDeclinedOf = (entry) => entry.declined || entry.selected.length === 0 && !entry.custom;
|
|
50481
50681
|
return (() => {
|
|
50482
|
-
var _el$
|
|
50483
|
-
setProp(_el$
|
|
50484
|
-
setProp(_el$
|
|
50485
|
-
insert(_el$
|
|
50682
|
+
var _el$16 = createElement("box");
|
|
50683
|
+
setProp(_el$16, "flexDirection", "column");
|
|
50684
|
+
setProp(_el$16, "gap", 1);
|
|
50685
|
+
insert(_el$16, createComponent2(For, {
|
|
50486
50686
|
get each() {
|
|
50487
50687
|
return props.row.entries;
|
|
50488
50688
|
},
|
|
50489
50689
|
children: (entry) => (() => {
|
|
50490
|
-
var _el$
|
|
50491
|
-
insertNode(_el$
|
|
50492
|
-
insertNode(_el$
|
|
50493
|
-
setProp(_el$
|
|
50494
|
-
insert(_el$
|
|
50690
|
+
var _el$17 = createElement("box"), _el$18 = createElement("text"), _el$19 = createElement("text");
|
|
50691
|
+
insertNode(_el$17, _el$18);
|
|
50692
|
+
insertNode(_el$17, _el$19);
|
|
50693
|
+
setProp(_el$17, "flexDirection", "column");
|
|
50694
|
+
insert(_el$17, createComponent2(Show, {
|
|
50495
50695
|
get when() {
|
|
50496
50696
|
return entry.header;
|
|
50497
50697
|
},
|
|
50498
50698
|
children: (header) => (() => {
|
|
50499
|
-
var _el$
|
|
50500
|
-
insert(_el$
|
|
50501
|
-
effect((_$p) => setProp(_el$
|
|
50502
|
-
return _el$
|
|
50699
|
+
var _el$20 = createElement("text");
|
|
50700
|
+
insert(_el$20, header);
|
|
50701
|
+
effect((_$p) => setProp(_el$20, "fg", reasoning(), _$p));
|
|
50702
|
+
return _el$20;
|
|
50503
50703
|
})()
|
|
50504
|
-
}), _el$
|
|
50505
|
-
insert(_el$
|
|
50506
|
-
insert(_el$
|
|
50704
|
+
}), _el$18);
|
|
50705
|
+
insert(_el$18, () => `\u2713 ${entry.question}`);
|
|
50706
|
+
insert(_el$17, createComponent2(Show, {
|
|
50507
50707
|
get when() {
|
|
50508
50708
|
return entry.detail;
|
|
50509
50709
|
},
|
|
50510
50710
|
children: (detail) => (() => {
|
|
50511
|
-
var _el$
|
|
50512
|
-
insert(_el$
|
|
50513
|
-
effect((_$p) => setProp(_el$
|
|
50514
|
-
return _el$
|
|
50711
|
+
var _el$21 = createElement("text");
|
|
50712
|
+
insert(_el$21, detail);
|
|
50713
|
+
effect((_$p) => setProp(_el$21, "fg", reasoning(), _$p));
|
|
50714
|
+
return _el$21;
|
|
50515
50715
|
})()
|
|
50516
|
-
}), _el$
|
|
50517
|
-
insert(_el$
|
|
50716
|
+
}), _el$19);
|
|
50717
|
+
insert(_el$19, () => ` \u2192 ${askAnswerOf(entry)}`);
|
|
50518
50718
|
effect((_p$) => {
|
|
50519
|
-
var _v$
|
|
50520
|
-
_v$
|
|
50521
|
-
_v$
|
|
50719
|
+
var _v$16 = reasoning(), _v$17 = askDeclinedOf(entry) ? reasoning() : answer();
|
|
50720
|
+
_v$16 !== _p$.e && (_p$.e = setProp(_el$18, "fg", _v$16, _p$.e));
|
|
50721
|
+
_v$17 !== _p$.t && (_p$.t = setProp(_el$19, "fg", _v$17, _p$.t));
|
|
50522
50722
|
return _p$;
|
|
50523
50723
|
}, {
|
|
50524
50724
|
e: undefined,
|
|
50525
50725
|
t: undefined
|
|
50526
50726
|
});
|
|
50527
|
-
return _el$
|
|
50727
|
+
return _el$17;
|
|
50528
50728
|
})()
|
|
50529
50729
|
}));
|
|
50530
|
-
return _el$
|
|
50730
|
+
return _el$16;
|
|
50531
50731
|
})();
|
|
50532
50732
|
}
|
|
50533
50733
|
var SIDES_RULE, SIDES_FRAME, CODE_RENDER_NODE_CACHE_MAX = 256, codeRenderNodeCache;
|
|
@@ -50811,6 +51011,252 @@ var init_notices_dock = __esm(() => {
|
|
|
50811
51011
|
noticeList = notices;
|
|
50812
51012
|
});
|
|
50813
51013
|
|
|
51014
|
+
// ../tui-base/src/routes/session/recovery-banner.tsx
|
|
51015
|
+
function widthSafeBannerReason(banner) {
|
|
51016
|
+
const reason = banner?.reason ?? "";
|
|
51017
|
+
const holder = banner?.holder;
|
|
51018
|
+
if (holder === undefined || holder.length <= 8 || !reason.includes(holder))
|
|
51019
|
+
return reason;
|
|
51020
|
+
return reason.replace(holder, `${holder.slice(0, 8)}\u2026`);
|
|
51021
|
+
}
|
|
51022
|
+
function RecoveryBanner(props) {
|
|
51023
|
+
const theme = useThemeOptional();
|
|
51024
|
+
const [version, setVersion] = createSignal(0);
|
|
51025
|
+
onCleanup(props.controller.subscribe(() => setVersion((v) => v + 1)));
|
|
51026
|
+
const controller = props.controller;
|
|
51027
|
+
const banner = () => {
|
|
51028
|
+
version();
|
|
51029
|
+
return controller.banner;
|
|
51030
|
+
};
|
|
51031
|
+
const actions = () => {
|
|
51032
|
+
if (banner() === undefined)
|
|
51033
|
+
return [];
|
|
51034
|
+
return banner()?.kind === "failed" ? [{
|
|
51035
|
+
label: controller.texts.reconnect(),
|
|
51036
|
+
run: () => void controller.recover()
|
|
51037
|
+
}, {
|
|
51038
|
+
label: controller.texts.newSession(),
|
|
51039
|
+
run: () => controller.newSession()
|
|
51040
|
+
}, {
|
|
51041
|
+
label: controller.texts.quit(),
|
|
51042
|
+
run: () => controller.quit()
|
|
51043
|
+
}] : [{
|
|
51044
|
+
label: controller.texts.retry(),
|
|
51045
|
+
run: () => void controller.recover()
|
|
51046
|
+
}, {
|
|
51047
|
+
label: controller.texts.newSession(),
|
|
51048
|
+
run: () => controller.newSession()
|
|
51049
|
+
}];
|
|
51050
|
+
};
|
|
51051
|
+
const warning = () => theme?.text.feedback.warning.base ?? "#e0af68";
|
|
51052
|
+
return createComponent2(Show, {
|
|
51053
|
+
get when() {
|
|
51054
|
+
return banner() !== undefined;
|
|
51055
|
+
},
|
|
51056
|
+
fallback: null,
|
|
51057
|
+
get children() {
|
|
51058
|
+
var _el$ = createElement("box"), _el$2 = createElement("text"), _el$3 = createElement("box");
|
|
51059
|
+
insertNode(_el$, _el$2);
|
|
51060
|
+
insertNode(_el$, _el$3);
|
|
51061
|
+
setProp(_el$, "flexShrink", 0);
|
|
51062
|
+
setProp(_el$, "width", "100%");
|
|
51063
|
+
setProp(_el$, "flexDirection", "column");
|
|
51064
|
+
setProp(_el$, "border", true);
|
|
51065
|
+
setProp(_el$, "borderStyle", "single");
|
|
51066
|
+
setProp(_el$, "paddingLeft", 1);
|
|
51067
|
+
setProp(_el$, "paddingRight", 1);
|
|
51068
|
+
setProp(_el$2, "wrapMode", "none");
|
|
51069
|
+
insert(_el$2, () => widthSafeBannerReason(banner()));
|
|
51070
|
+
setProp(_el$3, "flexDirection", "row");
|
|
51071
|
+
setProp(_el$3, "gap", 2);
|
|
51072
|
+
setProp(_el$3, "height", 1);
|
|
51073
|
+
insert(_el$3, createComponent2(For, {
|
|
51074
|
+
get each() {
|
|
51075
|
+
return actions();
|
|
51076
|
+
},
|
|
51077
|
+
children: (action) => (() => {
|
|
51078
|
+
var _el$4 = createElement("text");
|
|
51079
|
+
setProp(_el$4, "wrapMode", "none");
|
|
51080
|
+
setProp(_el$4, "onMouseUp", () => action.run());
|
|
51081
|
+
insert(_el$4, () => action.label);
|
|
51082
|
+
effect((_$p) => setProp(_el$4, "fg", theme?.text.muted ?? "#9aa5ce", _$p));
|
|
51083
|
+
return _el$4;
|
|
51084
|
+
})()
|
|
51085
|
+
}));
|
|
51086
|
+
effect((_p$) => {
|
|
51087
|
+
var _v$ = warning(), _v$2 = warning();
|
|
51088
|
+
_v$ !== _p$.e && (_p$.e = setProp(_el$, "borderColor", _v$, _p$.e));
|
|
51089
|
+
_v$2 !== _p$.t && (_p$.t = setProp(_el$2, "fg", _v$2, _p$.t));
|
|
51090
|
+
return _p$;
|
|
51091
|
+
}, {
|
|
51092
|
+
e: undefined,
|
|
51093
|
+
t: undefined
|
|
51094
|
+
});
|
|
51095
|
+
return _el$;
|
|
51096
|
+
}
|
|
51097
|
+
});
|
|
51098
|
+
}
|
|
51099
|
+
var init_recovery_banner = __esm(() => {
|
|
51100
|
+
init_index_bun();
|
|
51101
|
+
init_index_bun();
|
|
51102
|
+
init_index_bun();
|
|
51103
|
+
init_index_bun();
|
|
51104
|
+
init_index_bun();
|
|
51105
|
+
init_index_bun();
|
|
51106
|
+
init_server();
|
|
51107
|
+
init_theme3();
|
|
51108
|
+
});
|
|
51109
|
+
|
|
51110
|
+
// ../tui-base/src/routes/session/recovery-ui.ts
|
|
51111
|
+
function asRecord3(value) {
|
|
51112
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
51113
|
+
}
|
|
51114
|
+
function reasonOf(details) {
|
|
51115
|
+
const error = asRecord3(details.error);
|
|
51116
|
+
for (const value of [error.message, details.message]) {
|
|
51117
|
+
if (typeof value === "string" && value.trim() !== "")
|
|
51118
|
+
return value;
|
|
51119
|
+
}
|
|
51120
|
+
return "";
|
|
51121
|
+
}
|
|
51122
|
+
|
|
51123
|
+
class RecoveryUiController {
|
|
51124
|
+
texts;
|
|
51125
|
+
#recover;
|
|
51126
|
+
#onNotice;
|
|
51127
|
+
#onNewSession;
|
|
51128
|
+
#onQuit;
|
|
51129
|
+
#phase = "ready";
|
|
51130
|
+
#banner;
|
|
51131
|
+
#listeners = new Set;
|
|
51132
|
+
constructor(options) {
|
|
51133
|
+
this.#recover = options.recover;
|
|
51134
|
+
this.texts = options.texts;
|
|
51135
|
+
this.#onNotice = options.onNotice;
|
|
51136
|
+
this.#onNewSession = options.onNewSession;
|
|
51137
|
+
this.#onQuit = options.onQuit;
|
|
51138
|
+
}
|
|
51139
|
+
get phase() {
|
|
51140
|
+
return this.#phase;
|
|
51141
|
+
}
|
|
51142
|
+
get banner() {
|
|
51143
|
+
return this.#banner;
|
|
51144
|
+
}
|
|
51145
|
+
get composerDisabled() {
|
|
51146
|
+
return this.#phase === "recovering";
|
|
51147
|
+
}
|
|
51148
|
+
get footerStatus() {
|
|
51149
|
+
if (this.#phase === "recovering")
|
|
51150
|
+
return "recovering";
|
|
51151
|
+
if (this.#phase === "ready")
|
|
51152
|
+
return "ready";
|
|
51153
|
+
return "dead";
|
|
51154
|
+
}
|
|
51155
|
+
canRecover() {
|
|
51156
|
+
return this.#phase === "dead" || this.#phase === "failed" || this.#phase === "locked";
|
|
51157
|
+
}
|
|
51158
|
+
subscribe(listener) {
|
|
51159
|
+
this.#listeners.add(listener);
|
|
51160
|
+
return () => this.#listeners.delete(listener);
|
|
51161
|
+
}
|
|
51162
|
+
#emit() {
|
|
51163
|
+
for (const listener of [...this.#listeners])
|
|
51164
|
+
listener();
|
|
51165
|
+
}
|
|
51166
|
+
#phaseTo(next) {
|
|
51167
|
+
if (this.#phase === next)
|
|
51168
|
+
return;
|
|
51169
|
+
this.#phase = next;
|
|
51170
|
+
this.#emit();
|
|
51171
|
+
}
|
|
51172
|
+
#bannerTo(next) {
|
|
51173
|
+
this.#banner = next;
|
|
51174
|
+
this.#emit();
|
|
51175
|
+
}
|
|
51176
|
+
handleEvent(event) {
|
|
51177
|
+
switch (event.type) {
|
|
51178
|
+
case "bridge.dead":
|
|
51179
|
+
this.#bannerTo(undefined);
|
|
51180
|
+
this.#phaseTo("dead");
|
|
51181
|
+
return;
|
|
51182
|
+
case "bridge.recovered": {
|
|
51183
|
+
const details = asRecord3(event.details);
|
|
51184
|
+
const count = typeof details.applied === "number" ? details.applied : 0;
|
|
51185
|
+
this.#bannerTo(undefined);
|
|
51186
|
+
this.#phaseTo("ready");
|
|
51187
|
+
this.#onNotice?.(this.texts.recovered(count), RECOVERY_NOTICE_TTL_MS);
|
|
51188
|
+
return;
|
|
51189
|
+
}
|
|
51190
|
+
case "bridge.recovery.failed": {
|
|
51191
|
+
const reason = reasonOf(asRecord3(event.details));
|
|
51192
|
+
this.#phaseTo("failed");
|
|
51193
|
+
this.#bannerTo({ kind: "failed", reason: this.texts.failedReason(reason) });
|
|
51194
|
+
return;
|
|
51195
|
+
}
|
|
51196
|
+
case "bridge.recovery.locked": {
|
|
51197
|
+
const details = asRecord3(event.details);
|
|
51198
|
+
const sessionId = typeof details.sessionId === "string" ? details.sessionId : undefined;
|
|
51199
|
+
const detailMessage = typeof details.message === "string" && details.message.trim() !== "" ? details.message : undefined;
|
|
51200
|
+
const rawReason = detailMessage ?? reasonOf(details);
|
|
51201
|
+
const errorDetail = asRecord3(asRecord3(details.error).detail);
|
|
51202
|
+
const holderValue = typeof details.holder === "string" ? details.holder : errorDetail.holder;
|
|
51203
|
+
const holder = typeof holderValue === "string" && holderValue !== "" && holderValue !== "unknown" ? holderValue : undefined;
|
|
51204
|
+
const holderSuffix = holder !== undefined && rawReason.includes(holder) ? undefined : holder;
|
|
51205
|
+
const reason = this.texts.locked(rawReason !== "" ? rawReason : undefined, holderSuffix);
|
|
51206
|
+
this.#phaseTo("locked");
|
|
51207
|
+
this.#bannerTo({ kind: "locked", reason, sessionId, holder });
|
|
51208
|
+
this.#onNotice?.(reason, RECOVERY_NOTICE_TTL_MS);
|
|
51209
|
+
return;
|
|
51210
|
+
}
|
|
51211
|
+
default:
|
|
51212
|
+
return;
|
|
51213
|
+
}
|
|
51214
|
+
}
|
|
51215
|
+
async recover() {
|
|
51216
|
+
if (!this.canRecover())
|
|
51217
|
+
return;
|
|
51218
|
+
this.#bannerTo(undefined);
|
|
51219
|
+
this.#phaseTo("recovering");
|
|
51220
|
+
this.#onNotice?.(this.texts.transient(), RECOVERY_NOTICE_TTL_MS);
|
|
51221
|
+
try {
|
|
51222
|
+
await this.#recover();
|
|
51223
|
+
} catch (err) {
|
|
51224
|
+
const code = err?.code;
|
|
51225
|
+
const detail = asRecord3(err?.detail);
|
|
51226
|
+
if (code === "BRIDGE_RECOVERY_COOLDOWN" && typeof detail.remainingMs === "number" && Number.isFinite(detail.remainingMs)) {
|
|
51227
|
+
this.#phaseTo("dead");
|
|
51228
|
+
this.#onNotice?.(this.texts.cooldown(detail.remainingMs), RECOVERY_NOTICE_TTL_MS);
|
|
51229
|
+
return;
|
|
51230
|
+
}
|
|
51231
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
51232
|
+
this.#phaseTo("failed");
|
|
51233
|
+
this.#bannerTo({ kind: "failed", reason: this.texts.failedReason(reason) });
|
|
51234
|
+
}
|
|
51235
|
+
}
|
|
51236
|
+
clearRecoveryState() {
|
|
51237
|
+
this.#bannerTo(undefined);
|
|
51238
|
+
this.#phaseTo("ready");
|
|
51239
|
+
}
|
|
51240
|
+
newSession() {
|
|
51241
|
+
this.#onNewSession?.();
|
|
51242
|
+
this.clearRecoveryState();
|
|
51243
|
+
}
|
|
51244
|
+
quit() {
|
|
51245
|
+
this.#onQuit?.();
|
|
51246
|
+
}
|
|
51247
|
+
reconnectCommand() {
|
|
51248
|
+
return {
|
|
51249
|
+
id: RECOVERY_RECONNECT_COMMAND,
|
|
51250
|
+
title: this.texts.reconnect(),
|
|
51251
|
+
group: "Session",
|
|
51252
|
+
bind: RECOVERY_RECONNECT_BIND,
|
|
51253
|
+
enabled: () => this.canRecover(),
|
|
51254
|
+
run: () => void this.recover()
|
|
51255
|
+
};
|
|
51256
|
+
}
|
|
51257
|
+
}
|
|
51258
|
+
var RECOVERY_NOTICE_TTL_MS = 4000, RECOVERY_RECONNECT_BIND = "r", RECOVERY_RECONNECT_COMMAND = "session.bridge.recover";
|
|
51259
|
+
|
|
50814
51260
|
// ../tui-base/src/routes/session/comet-track.tsx
|
|
50815
51261
|
import { parseColor as parseColor4, Renderable as Renderable7 } from "@opentui/core";
|
|
50816
51262
|
function cometHeadColor(theme) {
|
|
@@ -51180,6 +51626,7 @@ function rowSearchText(row) {
|
|
|
51180
51626
|
case "user":
|
|
51181
51627
|
case "assistant":
|
|
51182
51628
|
case "reasoning":
|
|
51629
|
+
case "interrupted":
|
|
51183
51630
|
return row.text;
|
|
51184
51631
|
case "tool":
|
|
51185
51632
|
return `${row.name}${row.args ? `(${row.args})` : ""}${row.output ? ` ${row.output}` : ""}`;
|
|
@@ -51795,6 +52242,18 @@ async function stopEverything(seam) {
|
|
|
51795
52242
|
}
|
|
51796
52243
|
|
|
51797
52244
|
// ../tui-base/src/routes/session/turn-overlay-controller.ts
|
|
52245
|
+
function askSignature(questions) {
|
|
52246
|
+
return JSON.stringify(questions.map((question) => [
|
|
52247
|
+
question.id,
|
|
52248
|
+
question.prompt,
|
|
52249
|
+
question.header,
|
|
52250
|
+
question.description,
|
|
52251
|
+
question.detail,
|
|
52252
|
+
question.multiSelect === true,
|
|
52253
|
+
question.options.map((option) => [option.label, option.description])
|
|
52254
|
+
]));
|
|
52255
|
+
}
|
|
52256
|
+
|
|
51798
52257
|
class TurnOverlayController {
|
|
51799
52258
|
#approvals = [];
|
|
51800
52259
|
#asks = [];
|
|
@@ -51802,10 +52261,94 @@ class TurnOverlayController {
|
|
|
51802
52261
|
#listeners = new Set;
|
|
51803
52262
|
#idleHandlers = new Set;
|
|
51804
52263
|
#busy = false;
|
|
52264
|
+
#pendingAsks;
|
|
51805
52265
|
subscribe(fn) {
|
|
51806
52266
|
this.#listeners.add(fn);
|
|
51807
52267
|
return () => this.#listeners.delete(fn);
|
|
51808
52268
|
}
|
|
52269
|
+
attachPendingAsks(read) {
|
|
52270
|
+
this.#pendingAsks = read;
|
|
52271
|
+
}
|
|
52272
|
+
invalidateAsk(eventId, reason) {
|
|
52273
|
+
if (eventId === "")
|
|
52274
|
+
return;
|
|
52275
|
+
if (this.#approvals.some((entry) => entry.request.invalidatedReason !== undefined && entry.request.eventId === eventId))
|
|
52276
|
+
return;
|
|
52277
|
+
this.#approvals = this.#approvals.filter((entry) => {
|
|
52278
|
+
if (entry.request.eventId !== eventId)
|
|
52279
|
+
return true;
|
|
52280
|
+
entry.resolve("rejected");
|
|
52281
|
+
return false;
|
|
52282
|
+
});
|
|
52283
|
+
this.#asks = this.#asks.filter((entry) => {
|
|
52284
|
+
if (entry.eventId !== eventId)
|
|
52285
|
+
return true;
|
|
52286
|
+
entry.resolve([]);
|
|
52287
|
+
return false;
|
|
52288
|
+
});
|
|
52289
|
+
this.#approvals.push({
|
|
52290
|
+
request: {
|
|
52291
|
+
id: ++this.#seq,
|
|
52292
|
+
name: "ask",
|
|
52293
|
+
args: {},
|
|
52294
|
+
eventId,
|
|
52295
|
+
escalation: false,
|
|
52296
|
+
invalidatedReason: reason
|
|
52297
|
+
},
|
|
52298
|
+
resolve: () => {}
|
|
52299
|
+
});
|
|
52300
|
+
this.#changed();
|
|
52301
|
+
}
|
|
52302
|
+
invalidateAll(reason) {
|
|
52303
|
+
if (reason === "")
|
|
52304
|
+
return;
|
|
52305
|
+
const open = this.#approvals.length + this.#asks.length;
|
|
52306
|
+
if (open === 0)
|
|
52307
|
+
return;
|
|
52308
|
+
const terminals = [];
|
|
52309
|
+
for (const entry of this.#approvals) {
|
|
52310
|
+
terminals.push({
|
|
52311
|
+
request: {
|
|
52312
|
+
id: ++this.#seq,
|
|
52313
|
+
name: "ask",
|
|
52314
|
+
args: {},
|
|
52315
|
+
...entry.request.eventId !== undefined ? { eventId: entry.request.eventId } : {},
|
|
52316
|
+
escalation: false,
|
|
52317
|
+
invalidatedReason: reason
|
|
52318
|
+
},
|
|
52319
|
+
resolve: () => {}
|
|
52320
|
+
});
|
|
52321
|
+
}
|
|
52322
|
+
for (const entry of this.#asks) {
|
|
52323
|
+
terminals.push({
|
|
52324
|
+
request: {
|
|
52325
|
+
id: ++this.#seq,
|
|
52326
|
+
name: "ask",
|
|
52327
|
+
args: {},
|
|
52328
|
+
...entry.eventId !== undefined ? { eventId: entry.eventId } : {},
|
|
52329
|
+
escalation: false,
|
|
52330
|
+
invalidatedReason: reason
|
|
52331
|
+
},
|
|
52332
|
+
resolve: () => {}
|
|
52333
|
+
});
|
|
52334
|
+
}
|
|
52335
|
+
for (const entry of this.#approvals)
|
|
52336
|
+
entry.resolve("rejected");
|
|
52337
|
+
for (const entry of this.#asks)
|
|
52338
|
+
entry.resolve([]);
|
|
52339
|
+
this.#approvals = terminals;
|
|
52340
|
+
this.#asks = [];
|
|
52341
|
+
this.#changed();
|
|
52342
|
+
}
|
|
52343
|
+
pendingInvalidated() {
|
|
52344
|
+
const out = new Map;
|
|
52345
|
+
for (const entry of this.#approvals) {
|
|
52346
|
+
if (entry.request.invalidatedReason !== undefined && entry.request.eventId !== undefined) {
|
|
52347
|
+
out.set(entry.request.eventId, entry.request.invalidatedReason);
|
|
52348
|
+
}
|
|
52349
|
+
}
|
|
52350
|
+
return out;
|
|
52351
|
+
}
|
|
51809
52352
|
onIdle(fn) {
|
|
51810
52353
|
this.#idleHandlers.add(fn);
|
|
51811
52354
|
return () => this.#idleHandlers.delete(fn);
|
|
@@ -51829,10 +52372,36 @@ class TurnOverlayController {
|
|
|
51829
52372
|
return this.#asks.length;
|
|
51830
52373
|
}
|
|
51831
52374
|
requestApproval(name, args) {
|
|
51832
|
-
|
|
51833
|
-
|
|
52375
|
+
const ask = this.#matchApproval(name, args);
|
|
52376
|
+
const promise = new Promise((resolve) => {
|
|
52377
|
+
this.#approvals.push({
|
|
52378
|
+
request: {
|
|
52379
|
+
id: ++this.#seq,
|
|
52380
|
+
name,
|
|
52381
|
+
args,
|
|
52382
|
+
escalation: ask?.escalation === true,
|
|
52383
|
+
...ask !== undefined ? { eventId: ask.eventId } : {}
|
|
52384
|
+
},
|
|
52385
|
+
resolve
|
|
52386
|
+
});
|
|
51834
52387
|
this.#changed();
|
|
51835
52388
|
});
|
|
52389
|
+
return promise;
|
|
52390
|
+
}
|
|
52391
|
+
#matchApproval(name, args) {
|
|
52392
|
+
const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "approval");
|
|
52393
|
+
if (asks.length === 0)
|
|
52394
|
+
return;
|
|
52395
|
+
const callId = typeof args.callId === "string" ? args.callId : undefined;
|
|
52396
|
+
if (callId !== undefined) {
|
|
52397
|
+
const byCall = asks.filter((ask) => ask.callId === callId);
|
|
52398
|
+
return byCall.length > 0 ? byCall[byCall.length - 1] : undefined;
|
|
52399
|
+
}
|
|
52400
|
+
const reason = typeof args.reason === "string" ? args.reason : undefined;
|
|
52401
|
+
const byName = asks.filter((ask) => (ask.toolName ?? "tool") === name && (reason === undefined || ask.reason === reason));
|
|
52402
|
+
if (byName.length > 0)
|
|
52403
|
+
return byName[byName.length - 1];
|
|
52404
|
+
return asks.length === 1 ? asks[0] : undefined;
|
|
51836
52405
|
}
|
|
51837
52406
|
confirmApproval() {
|
|
51838
52407
|
this.#settleApproval("allowed-once");
|
|
@@ -51840,6 +52409,17 @@ class TurnOverlayController {
|
|
|
51840
52409
|
rejectApproval() {
|
|
51841
52410
|
this.#settleApproval("rejected");
|
|
51842
52411
|
}
|
|
52412
|
+
approveAlways() {
|
|
52413
|
+
this.#settleEscalated("always");
|
|
52414
|
+
}
|
|
52415
|
+
approveSession() {
|
|
52416
|
+
this.#settleEscalated("session");
|
|
52417
|
+
}
|
|
52418
|
+
#settleEscalated(verdict) {
|
|
52419
|
+
if (this.#approvals[0]?.request.escalation !== true)
|
|
52420
|
+
return;
|
|
52421
|
+
this.#settleApproval(verdict);
|
|
52422
|
+
}
|
|
51843
52423
|
#settleApproval(verdict) {
|
|
51844
52424
|
const head = this.#approvals.shift();
|
|
51845
52425
|
if (!head)
|
|
@@ -51847,12 +52427,65 @@ class TurnOverlayController {
|
|
|
51847
52427
|
head.resolve(verdict);
|
|
51848
52428
|
this.#changed();
|
|
51849
52429
|
}
|
|
52430
|
+
syncPendingAsks() {
|
|
52431
|
+
if (this.#pendingAsks === undefined)
|
|
52432
|
+
return;
|
|
52433
|
+
const asks = this.#pendingAsks();
|
|
52434
|
+
let changed = false;
|
|
52435
|
+
const approvalsBefore = this.#approvals.length;
|
|
52436
|
+
this.#approvals = this.#approvals.filter((entry) => {
|
|
52437
|
+
if (this.#approvalStillPending(entry.request, asks))
|
|
52438
|
+
return true;
|
|
52439
|
+
entry.resolve("rejected");
|
|
52440
|
+
return false;
|
|
52441
|
+
});
|
|
52442
|
+
if (this.#approvals.length !== approvalsBefore)
|
|
52443
|
+
changed = true;
|
|
52444
|
+
const questionsBefore = this.#asks.length;
|
|
52445
|
+
this.#asks = this.#asks.filter((entry) => {
|
|
52446
|
+
if (this.#questionStillPending(entry, asks))
|
|
52447
|
+
return true;
|
|
52448
|
+
entry.resolve([]);
|
|
52449
|
+
return false;
|
|
52450
|
+
});
|
|
52451
|
+
if (this.#asks.length !== questionsBefore)
|
|
52452
|
+
changed = true;
|
|
52453
|
+
if (changed)
|
|
52454
|
+
this.#changed();
|
|
52455
|
+
}
|
|
52456
|
+
#approvalStillPending(request, asks) {
|
|
52457
|
+
if (request.eventId !== undefined)
|
|
52458
|
+
return asks.some((ask) => ask.eventId === request.eventId);
|
|
52459
|
+
return asks.some((ask) => ask.kind === "approval");
|
|
52460
|
+
}
|
|
52461
|
+
#questionStillPending(entry, asks) {
|
|
52462
|
+
if (entry.eventId !== undefined)
|
|
52463
|
+
return asks.some((ask) => ask.eventId === entry.eventId);
|
|
52464
|
+
return asks.some((ask) => ask.kind === "questions");
|
|
52465
|
+
}
|
|
52466
|
+
cancelAllApprovals() {
|
|
52467
|
+
if (this.#approvals.length === 0)
|
|
52468
|
+
return;
|
|
52469
|
+
const entries = this.#approvals.splice(0);
|
|
52470
|
+
for (const entry of entries)
|
|
52471
|
+
entry.resolve("rejected");
|
|
52472
|
+
this.#changed();
|
|
52473
|
+
}
|
|
52474
|
+
cancelAllAsks() {
|
|
52475
|
+
if (this.#asks.length === 0)
|
|
52476
|
+
return;
|
|
52477
|
+
const entries = this.#asks.splice(0);
|
|
52478
|
+
for (const entry of entries)
|
|
52479
|
+
entry.resolve([]);
|
|
52480
|
+
this.#changed();
|
|
52481
|
+
}
|
|
51850
52482
|
get pendingAsk() {
|
|
51851
52483
|
const head = this.#asks[0];
|
|
51852
52484
|
if (!head)
|
|
51853
52485
|
return;
|
|
51854
52486
|
return {
|
|
51855
52487
|
id: head.id,
|
|
52488
|
+
...head.eventId !== undefined ? { eventId: head.eventId } : {},
|
|
51856
52489
|
questions: head.questions,
|
|
51857
52490
|
index: head.index,
|
|
51858
52491
|
picks: head.picks,
|
|
@@ -51868,12 +52501,28 @@ class TurnOverlayController {
|
|
|
51868
52501
|
const head = this.#asks[0];
|
|
51869
52502
|
return head?.questions[head.index];
|
|
51870
52503
|
}
|
|
52504
|
+
#matchAsk(questions) {
|
|
52505
|
+
const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "questions");
|
|
52506
|
+
if (asks.length === 0)
|
|
52507
|
+
return;
|
|
52508
|
+
const claimed = new Set(this.#asks.map((entry) => entry.eventId));
|
|
52509
|
+
const available = asks.filter((ask) => !claimed.has(ask.eventId));
|
|
52510
|
+
if (available.length === 0)
|
|
52511
|
+
return;
|
|
52512
|
+
const signature = askSignature(questions);
|
|
52513
|
+
const exact = available.filter((ask) => askSignature(ask.questions ?? []) === signature);
|
|
52514
|
+
if (exact.length > 0)
|
|
52515
|
+
return exact[0];
|
|
52516
|
+
return available.length === 1 ? available[0] : undefined;
|
|
52517
|
+
}
|
|
51871
52518
|
answer(questions) {
|
|
51872
52519
|
if (questions.length === 0)
|
|
51873
52520
|
return Promise.resolve([]);
|
|
52521
|
+
const ask = this.#matchAsk(questions);
|
|
51874
52522
|
return new Promise((resolve) => {
|
|
51875
52523
|
this.#asks.push({
|
|
51876
52524
|
id: ++this.#seq,
|
|
52525
|
+
...ask !== undefined ? { eventId: ask.eventId } : {},
|
|
51877
52526
|
questions,
|
|
51878
52527
|
index: 0,
|
|
51879
52528
|
picks: questions.map((question) => recommendedPicks(question)),
|
|
@@ -52200,9 +52849,13 @@ function DialogConfirm(props) {
|
|
|
52200
52849
|
props.onCancel?.();
|
|
52201
52850
|
dialog.clear();
|
|
52202
52851
|
};
|
|
52852
|
+
const chooseExtra = (action) => {
|
|
52853
|
+
action.onTrigger();
|
|
52854
|
+
dialog.clear();
|
|
52855
|
+
};
|
|
52203
52856
|
Keymap2.createLayer(() => ({
|
|
52204
52857
|
mode: "modal",
|
|
52205
|
-
commands: newDesigns() ? [{
|
|
52858
|
+
commands: [...newDesigns() ? [{
|
|
52206
52859
|
bind: "return",
|
|
52207
52860
|
title: "Confirm",
|
|
52208
52861
|
group: "Dialog",
|
|
@@ -52231,7 +52884,12 @@ function DialogConfirm(props) {
|
|
|
52231
52884
|
run: () => {
|
|
52232
52885
|
setStore("active", store.active === "confirm" ? "cancel" : "confirm");
|
|
52233
52886
|
}
|
|
52234
|
-
}]
|
|
52887
|
+
}], ...(props.extraActions ?? []).map((action) => ({
|
|
52888
|
+
bind: action.bind,
|
|
52889
|
+
title: action.title ?? action.label,
|
|
52890
|
+
group: "Dialog",
|
|
52891
|
+
run: () => chooseExtra(action)
|
|
52892
|
+
}))]
|
|
52235
52893
|
}));
|
|
52236
52894
|
return createComponent2(DialogLayout, {
|
|
52237
52895
|
get header() {
|
|
@@ -52264,6 +52922,11 @@ function DialogConfirm(props) {
|
|
|
52264
52922
|
get footer() {
|
|
52265
52923
|
return {
|
|
52266
52924
|
actions: {
|
|
52925
|
+
secondary: (props.extraActions ?? []).map((action) => ({
|
|
52926
|
+
title: action.label.toLowerCase(),
|
|
52927
|
+
key: action.bind,
|
|
52928
|
+
onTrigger: () => chooseExtra(action)
|
|
52929
|
+
})),
|
|
52267
52930
|
primary: [
|
|
52268
52931
|
{
|
|
52269
52932
|
title: (props.label?.cancel ?? "cancel").toLowerCase(),
|
|
@@ -52281,28 +52944,48 @@ function DialogConfirm(props) {
|
|
|
52281
52944
|
},
|
|
52282
52945
|
get legacyFooter() {
|
|
52283
52946
|
return (() => {
|
|
52284
|
-
var _el$4 = createElement("box");
|
|
52947
|
+
var _el$4 = createElement("box"), _el$5 = createElement("box"), _el$6 = createElement("box");
|
|
52948
|
+
insertNode(_el$4, _el$5);
|
|
52949
|
+
insertNode(_el$4, _el$6);
|
|
52285
52950
|
setProp(_el$4, "flexDirection", "row");
|
|
52286
|
-
setProp(_el$4, "justifyContent", "
|
|
52287
|
-
|
|
52951
|
+
setProp(_el$4, "justifyContent", "space-between");
|
|
52952
|
+
setProp(_el$4, "gap", 1);
|
|
52953
|
+
setProp(_el$5, "flexDirection", "row");
|
|
52954
|
+
insert(_el$5, createComponent2(For, {
|
|
52955
|
+
get each() {
|
|
52956
|
+
return props.extraActions ?? [];
|
|
52957
|
+
},
|
|
52958
|
+
children: (action) => (() => {
|
|
52959
|
+
var _el$7 = createElement("box"), _el$8 = createElement("text");
|
|
52960
|
+
insertNode(_el$7, _el$8);
|
|
52961
|
+
setProp(_el$7, "paddingLeft", 1);
|
|
52962
|
+
setProp(_el$7, "paddingRight", 1);
|
|
52963
|
+
setProp(_el$7, "onMouseUp", () => chooseExtra(action));
|
|
52964
|
+
insert(_el$8, () => `${action.label} [${action.bind}]`);
|
|
52965
|
+
effect((_$p) => setProp(_el$8, "fg", theme.text.muted, _$p));
|
|
52966
|
+
return _el$7;
|
|
52967
|
+
})()
|
|
52968
|
+
}));
|
|
52969
|
+
setProp(_el$6, "flexDirection", "row");
|
|
52970
|
+
insert(_el$6, createComponent2(For, {
|
|
52288
52971
|
each: ["cancel", "confirm"],
|
|
52289
52972
|
children: (key) => (() => {
|
|
52290
|
-
var _el$
|
|
52291
|
-
insertNode(_el$
|
|
52292
|
-
setProp(_el$
|
|
52293
|
-
setProp(_el$
|
|
52294
|
-
setProp(_el$
|
|
52295
|
-
insert(_el$
|
|
52973
|
+
var _el$9 = createElement("box"), _el$0 = createElement("text");
|
|
52974
|
+
insertNode(_el$9, _el$0);
|
|
52975
|
+
setProp(_el$9, "paddingLeft", 1);
|
|
52976
|
+
setProp(_el$9, "paddingRight", 1);
|
|
52977
|
+
setProp(_el$9, "onMouseUp", () => choose(key));
|
|
52978
|
+
insert(_el$0, () => titlecase(props.label?.[key] ?? key));
|
|
52296
52979
|
effect((_p$) => {
|
|
52297
52980
|
var _v$3 = key === store.active ? row().backgroundColor : undefined, _v$4 = key === store.active ? row().textColor : theme.text.muted;
|
|
52298
|
-
_v$3 !== _p$.e && (_p$.e = setProp(_el$
|
|
52299
|
-
_v$4 !== _p$.t && (_p$.t = setProp(_el$
|
|
52981
|
+
_v$3 !== _p$.e && (_p$.e = setProp(_el$9, "backgroundColor", _v$3, _p$.e));
|
|
52982
|
+
_v$4 !== _p$.t && (_p$.t = setProp(_el$0, "fg", _v$4, _p$.t));
|
|
52300
52983
|
return _p$;
|
|
52301
52984
|
}, {
|
|
52302
52985
|
e: undefined,
|
|
52303
52986
|
t: undefined
|
|
52304
52987
|
});
|
|
52305
|
-
return _el$
|
|
52988
|
+
return _el$9;
|
|
52306
52989
|
})()
|
|
52307
52990
|
}));
|
|
52308
52991
|
return _el$4;
|
|
@@ -52323,6 +53006,7 @@ var init_dialog_confirm = __esm(() => {
|
|
|
52323
53006
|
init_index_bun();
|
|
52324
53007
|
init_index_bun();
|
|
52325
53008
|
init_index_bun();
|
|
53009
|
+
init_index_bun();
|
|
52326
53010
|
init_keymap();
|
|
52327
53011
|
init_theme3();
|
|
52328
53012
|
init_config();
|
|
@@ -53447,23 +54131,40 @@ function summarizeArgs(name, args, limit = 160) {
|
|
|
53447
54131
|
return `${name} ${body}`.trim();
|
|
53448
54132
|
}
|
|
53449
54133
|
function ApprovalCard(props) {
|
|
54134
|
+
const invalidated = () => props.invalidatedReason !== undefined;
|
|
53450
54135
|
return createComponent2(DialogConfirm, {
|
|
53451
54136
|
get title() {
|
|
53452
|
-
return t("overlay.ask.approvalTitle", {
|
|
54137
|
+
return memo2(() => !!invalidated())() ? t("overlay.ask.invalidatedTitle") : t("overlay.ask.approvalTitle", {
|
|
53453
54138
|
name: props.name
|
|
53454
54139
|
});
|
|
53455
54140
|
},
|
|
53456
54141
|
get message() {
|
|
53457
|
-
return
|
|
54142
|
+
return memo2(() => !!invalidated())() ? t("overlay.ask.invalidated", {
|
|
54143
|
+
reason: props.invalidatedReason ?? ""
|
|
54144
|
+
}) : summarizeArgs(props.name, props.args);
|
|
53458
54145
|
},
|
|
53459
54146
|
get label() {
|
|
53460
|
-
return {
|
|
54147
|
+
return memo2(() => !!invalidated())() ? {
|
|
54148
|
+
confirm: t("overlay.ask.invalidatedAck"),
|
|
54149
|
+
cancel: t("overlay.ask.invalidatedAck")
|
|
54150
|
+
} : {
|
|
53461
54151
|
confirm: t("overlay.ask.allow"),
|
|
53462
54152
|
cancel: t("overlay.ask.reject")
|
|
53463
54153
|
};
|
|
53464
54154
|
},
|
|
53465
54155
|
onConfirm: () => props.onVerdict("allowed-once"),
|
|
53466
|
-
onCancel: () => props.onVerdict("rejected")
|
|
54156
|
+
onCancel: () => props.onVerdict("rejected"),
|
|
54157
|
+
get extraActions() {
|
|
54158
|
+
return memo2(() => !!(!invalidated() && props.escalation === true))() ? [{
|
|
54159
|
+
label: t("overlay.ask.allowAlways"),
|
|
54160
|
+
bind: "a",
|
|
54161
|
+
onTrigger: () => props.onVerdict("always")
|
|
54162
|
+
}, {
|
|
54163
|
+
label: t("overlay.ask.allowSession"),
|
|
54164
|
+
bind: "s",
|
|
54165
|
+
onTrigger: () => props.onVerdict("session")
|
|
54166
|
+
}] : undefined;
|
|
54167
|
+
}
|
|
53467
54168
|
});
|
|
53468
54169
|
}
|
|
53469
54170
|
function ReminderBadge() {
|
|
@@ -53496,6 +54197,8 @@ function TurnOverlayHost(props) {
|
|
|
53496
54197
|
onMount(() => {
|
|
53497
54198
|
const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
|
|
53498
54199
|
onCleanup(unsubscribe);
|
|
54200
|
+
const timer = setInterval(() => props.controller.syncPendingAsks(), 200);
|
|
54201
|
+
onCleanup(() => clearInterval(timer));
|
|
53499
54202
|
});
|
|
53500
54203
|
props.controller.onIdle(() => {
|
|
53501
54204
|
setTimeout(() => props.reclaimFocus?.(), 3);
|
|
@@ -53520,29 +54223,55 @@ function TurnOverlayHost(props) {
|
|
|
53520
54223
|
const key = approvalWins ? `approval:${approval.id}` : askAdmitted ? `ask:${ask.id}` : "";
|
|
53521
54224
|
if (key === shown)
|
|
53522
54225
|
return;
|
|
54226
|
+
const previousKey = shown;
|
|
53523
54227
|
shown = key;
|
|
54228
|
+
if (previousKey?.startsWith("approval:") === true && dialog.stack.at(-1)?.key === previousKey) {
|
|
54229
|
+
dialog.clear();
|
|
54230
|
+
}
|
|
53524
54231
|
if (approvalWins) {
|
|
53525
54232
|
closeAsk();
|
|
53526
54233
|
const atOpen = key;
|
|
53527
|
-
|
|
53528
|
-
|
|
53529
|
-
|
|
53530
|
-
|
|
53531
|
-
|
|
53532
|
-
|
|
53533
|
-
|
|
53534
|
-
|
|
53535
|
-
|
|
53536
|
-
|
|
53537
|
-
|
|
54234
|
+
const approvalId = approval.id;
|
|
54235
|
+
try {
|
|
54236
|
+
dialog.replace(() => createComponent2(ApprovalCard, {
|
|
54237
|
+
get name() {
|
|
54238
|
+
return approval.name;
|
|
54239
|
+
},
|
|
54240
|
+
get args() {
|
|
54241
|
+
return approval.args;
|
|
54242
|
+
},
|
|
54243
|
+
get escalation() {
|
|
54244
|
+
return approval.escalation;
|
|
54245
|
+
},
|
|
54246
|
+
get invalidatedReason() {
|
|
54247
|
+
return approval.invalidatedReason;
|
|
54248
|
+
},
|
|
54249
|
+
onVerdict: (verdict) => {
|
|
54250
|
+
switch (verdict) {
|
|
54251
|
+
case "allowed-once":
|
|
54252
|
+
props.controller.confirmApproval();
|
|
54253
|
+
break;
|
|
54254
|
+
case "always":
|
|
54255
|
+
props.controller.approveAlways();
|
|
54256
|
+
break;
|
|
54257
|
+
case "session":
|
|
54258
|
+
props.controller.approveSession();
|
|
54259
|
+
break;
|
|
54260
|
+
default:
|
|
54261
|
+
props.controller.rejectApproval();
|
|
54262
|
+
}
|
|
54263
|
+
}
|
|
54264
|
+
}), () => {
|
|
54265
|
+
if (shown === atOpen && props.controller.pendingApproval?.id === approvalId) {
|
|
53538
54266
|
props.controller.rejectApproval();
|
|
53539
|
-
|
|
53540
|
-
|
|
53541
|
-
|
|
53542
|
-
|
|
53543
|
-
|
|
53544
|
-
|
|
53545
|
-
|
|
54267
|
+
}
|
|
54268
|
+
}, {
|
|
54269
|
+
key,
|
|
54270
|
+
tone: "warning"
|
|
54271
|
+
});
|
|
54272
|
+
} catch {
|
|
54273
|
+
props.controller.rejectApproval();
|
|
54274
|
+
}
|
|
53546
54275
|
return;
|
|
53547
54276
|
}
|
|
53548
54277
|
if (ask !== undefined && askAdmitted) {
|
|
@@ -53580,7 +54309,30 @@ function TurnOverlayHost(props) {
|
|
|
53580
54309
|
children: null
|
|
53581
54310
|
});
|
|
53582
54311
|
}
|
|
53583
|
-
function registerTurnOverlays(seam, controller) {
|
|
54312
|
+
function registerTurnOverlays(seam, controller, options) {
|
|
54313
|
+
if (typeof seam.pendingAsks === "function") {
|
|
54314
|
+
const read = seam.pendingAsks.bind(seam);
|
|
54315
|
+
controller.attachPendingAsks(() => read() ?? []);
|
|
54316
|
+
}
|
|
54317
|
+
if (typeof seam.onSessionEvent === "function") {
|
|
54318
|
+
seam.onSessionEvent((event) => {
|
|
54319
|
+
if (event.type === "bridge.dead") {
|
|
54320
|
+
const configured = options?.deadReason;
|
|
54321
|
+
if (configured === undefined)
|
|
54322
|
+
return;
|
|
54323
|
+
const reason = typeof configured === "function" ? configured(event.details) : configured;
|
|
54324
|
+
if (reason !== "")
|
|
54325
|
+
controller.invalidateAll(reason);
|
|
54326
|
+
return;
|
|
54327
|
+
}
|
|
54328
|
+
if (event.type !== "bridge.ask.invalidated")
|
|
54329
|
+
return;
|
|
54330
|
+
const details = event.details;
|
|
54331
|
+
if (typeof details?.eventId !== "string")
|
|
54332
|
+
return;
|
|
54333
|
+
controller.invalidateAsk(details.eventId, typeof details.reason === "string" ? details.reason : "");
|
|
54334
|
+
});
|
|
54335
|
+
}
|
|
53584
54336
|
seam.registerAskProvider((questions) => controller.answer(questions));
|
|
53585
54337
|
}
|
|
53586
54338
|
var init_turn_overlays = __esm(() => {
|
|
@@ -53590,6 +54342,7 @@ var init_turn_overlays = __esm(() => {
|
|
|
53590
54342
|
init_index_bun();
|
|
53591
54343
|
init_index_bun();
|
|
53592
54344
|
init_index_bun();
|
|
54345
|
+
init_index_bun();
|
|
53593
54346
|
init_server();
|
|
53594
54347
|
init_index_bun();
|
|
53595
54348
|
init_dialog_confirm();
|
|
@@ -53632,8 +54385,8 @@ function sessionInfoRows(info) {
|
|
|
53632
54385
|
return [
|
|
53633
54386
|
{ field: "session", value: info.sessionId ?? "\u2014" },
|
|
53634
54387
|
{ field: "model", value: info.model ?? "\u2014" },
|
|
53635
|
-
{ field: "messages", value: String(info.messageCount) },
|
|
53636
|
-
{ field: "turns", value: String(info.turnCount) },
|
|
54388
|
+
{ field: "messages", value: info.messageCount === undefined ? "\u2014" : String(info.messageCount) },
|
|
54389
|
+
{ field: "turns", value: info.turnCount === undefined ? "\u2014" : String(info.turnCount) },
|
|
53637
54390
|
{ field: "tokens in/out", value: `${info.tokensIn} / ${info.tokensOut}` },
|
|
53638
54391
|
{ field: "cache read/write", value: `${info.cacheRead} / ${info.cacheWrite}` },
|
|
53639
54392
|
{ field: "speed", value: speed }
|
|
@@ -53971,6 +54724,7 @@ function coreCommands() {
|
|
|
53971
54724
|
ctx.seam.newSession();
|
|
53972
54725
|
ctx.clear();
|
|
53973
54726
|
await ctx.reload();
|
|
54727
|
+
ctx.clearRecoveryUi?.();
|
|
53974
54728
|
ctx.say(t("command.new.created", { id: ctx.seam.currentSessionId() ?? "(unnamed)" }));
|
|
53975
54729
|
}
|
|
53976
54730
|
},
|
|
@@ -54787,7 +55541,8 @@ function buildSlashDeps(base, hooks) {
|
|
|
54787
55541
|
openSubagents: hooks.openSubagents,
|
|
54788
55542
|
refreshFooter: hooks.refreshFooter,
|
|
54789
55543
|
invalidateFooter: hooks.invalidateFooter,
|
|
54790
|
-
flushQueue: hooks.flushQueue
|
|
55544
|
+
flushQueue: hooks.flushQueue,
|
|
55545
|
+
clearRecoveryUi: hooks.clearRecoveryUi
|
|
54791
55546
|
};
|
|
54792
55547
|
}
|
|
54793
55548
|
function carrySlashHooks(deps) {
|
|
@@ -54814,7 +55569,8 @@ var init_slash_deps = __esm(() => {
|
|
|
54814
55569
|
"openSubagents",
|
|
54815
55570
|
"refreshFooter",
|
|
54816
55571
|
"invalidateFooter",
|
|
54817
|
-
"flushQueue"
|
|
55572
|
+
"flushQueue",
|
|
55573
|
+
"clearRecoveryUi"
|
|
54818
55574
|
];
|
|
54819
55575
|
});
|
|
54820
55576
|
|
|
@@ -61706,7 +62462,7 @@ var init_agents_panel = __esm(() => {
|
|
|
61706
62462
|
});
|
|
61707
62463
|
|
|
61708
62464
|
// ../tui-base/src/routes/session/history-data.ts
|
|
61709
|
-
function
|
|
62465
|
+
function asRecord4(value) {
|
|
61710
62466
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
61711
62467
|
}
|
|
61712
62468
|
function blocksText2(content) {
|
|
@@ -61714,7 +62470,7 @@ function blocksText2(content) {
|
|
|
61714
62470
|
return "";
|
|
61715
62471
|
let text = "";
|
|
61716
62472
|
for (const block of content) {
|
|
61717
|
-
const typed =
|
|
62473
|
+
const typed = asRecord4(block);
|
|
61718
62474
|
if (typeof typed.text === "string" && typed.type === "text") {
|
|
61719
62475
|
text += (text === "" ? "" : `
|
|
61720
62476
|
`) + typed.text;
|
|
@@ -61723,7 +62479,7 @@ function blocksText2(content) {
|
|
|
61723
62479
|
return text.trim();
|
|
61724
62480
|
}
|
|
61725
62481
|
function sourceKind2(data) {
|
|
61726
|
-
return
|
|
62482
|
+
return asRecord4(data.source).kind;
|
|
61727
62483
|
}
|
|
61728
62484
|
function groupHistoryTurns(entries) {
|
|
61729
62485
|
const turns = [];
|
|
@@ -61779,7 +62535,7 @@ function groupHistoryTurns(entries) {
|
|
|
61779
62535
|
break;
|
|
61780
62536
|
}
|
|
61781
62537
|
case "assistant/message": {
|
|
61782
|
-
const message =
|
|
62538
|
+
const message = asRecord4(entry.data.message);
|
|
61783
62539
|
const text = blocksText2(message.content);
|
|
61784
62540
|
if (text !== "")
|
|
61785
62541
|
open.assistantTexts.push(text);
|
|
@@ -61797,7 +62553,7 @@ function groupHistoryTurns(entries) {
|
|
|
61797
62553
|
break;
|
|
61798
62554
|
}
|
|
61799
62555
|
case "tool/result": {
|
|
61800
|
-
const message =
|
|
62556
|
+
const message = asRecord4(entry.data.message);
|
|
61801
62557
|
const callId = entry.data.callId !== undefined ? String(entry.data.callId) : message.toolCallId !== undefined ? String(message.toolCallId) : "";
|
|
61802
62558
|
const index = callId === "" ? undefined : open.callIndex.get(callId);
|
|
61803
62559
|
if (index === undefined)
|
|
@@ -61811,9 +62567,9 @@ function groupHistoryTurns(entries) {
|
|
|
61811
62567
|
case "turn/end": {
|
|
61812
62568
|
open.seqEnd = entry.seq;
|
|
61813
62569
|
open.endTime = typeof entry.time === "number" ? entry.time : undefined;
|
|
61814
|
-
const reason =
|
|
62570
|
+
const reason = asRecord4(entry.data.reason);
|
|
61815
62571
|
open.endReason = typeof reason.kind === "string" ? reason.kind : "completed";
|
|
61816
|
-
const error =
|
|
62572
|
+
const error = asRecord4(reason.error);
|
|
61817
62573
|
open.endError = typeof error.message === "string" ? error.message : undefined;
|
|
61818
62574
|
close();
|
|
61819
62575
|
break;
|
|
@@ -62904,7 +63660,7 @@ var init_subagents_viewer = __esm(() => {
|
|
|
62904
63660
|
import { TextAttributes as TextAttributes12 } from "@opentui/core";
|
|
62905
63661
|
function resolveVersion() {
|
|
62906
63662
|
try {
|
|
62907
|
-
return "0.
|
|
63663
|
+
return "0.22.0";
|
|
62908
63664
|
} catch {
|
|
62909
63665
|
return "dev";
|
|
62910
63666
|
}
|
|
@@ -65200,6 +65956,1738 @@ var init_session_seam_adapter = __esm(() => {
|
|
|
65200
65956
|
NOTICE_SOURCE_KINDS = new Set(["subagent-settled", "agent-message", "team-message", "webhook"]);
|
|
65201
65957
|
});
|
|
65202
65958
|
|
|
65959
|
+
// src/client/bridge-session-seam.ts
|
|
65960
|
+
function askTurnId(eventId) {
|
|
65961
|
+
const i = eventId.lastIndexOf(":ask-");
|
|
65962
|
+
return i === -1 ? "" : eventId.slice(0, i);
|
|
65963
|
+
}
|
|
65964
|
+
function optionalStringField(row, key) {
|
|
65965
|
+
const value = row[key];
|
|
65966
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
65967
|
+
}
|
|
65968
|
+
function parseAskRequest(value) {
|
|
65969
|
+
const row = asRecord5(value);
|
|
65970
|
+
const eventId = optionalStringField(row, "eventId");
|
|
65971
|
+
const sessionId = optionalStringField(row, "sessionId");
|
|
65972
|
+
const kind = row.kind;
|
|
65973
|
+
if (eventId === undefined || sessionId === undefined || kind !== "approval" && kind !== "questions") {
|
|
65974
|
+
return;
|
|
65975
|
+
}
|
|
65976
|
+
const out = { eventId, sessionId, kind };
|
|
65977
|
+
for (const key of ["toolName", "callId", "reason"]) {
|
|
65978
|
+
const v = optionalStringField(row, key);
|
|
65979
|
+
if (v !== undefined)
|
|
65980
|
+
out[key] = v;
|
|
65981
|
+
}
|
|
65982
|
+
for (const key of ["deadlineAt", "detachGraceMs"]) {
|
|
65983
|
+
const v = row[key];
|
|
65984
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
65985
|
+
out[key] = v;
|
|
65986
|
+
}
|
|
65987
|
+
if (row.escalation === true)
|
|
65988
|
+
out.escalation = true;
|
|
65989
|
+
if (Array.isArray(row.questions)) {
|
|
65990
|
+
const questions = [];
|
|
65991
|
+
for (const raw of row.questions) {
|
|
65992
|
+
const q = asRecord5(raw);
|
|
65993
|
+
const id = optionalStringField(q, "id");
|
|
65994
|
+
const prompt = optionalStringField(q, "prompt");
|
|
65995
|
+
if (id === undefined || prompt === undefined || !Array.isArray(q.options))
|
|
65996
|
+
continue;
|
|
65997
|
+
const options = [];
|
|
65998
|
+
for (const rawOpt of q.options) {
|
|
65999
|
+
const opt = asRecord5(rawOpt);
|
|
66000
|
+
const label = optionalStringField(opt, "label");
|
|
66001
|
+
if (label === undefined)
|
|
66002
|
+
continue;
|
|
66003
|
+
const description = optionalStringField(opt, "description");
|
|
66004
|
+
options.push({ label, ...description !== undefined ? { description } : {} });
|
|
66005
|
+
}
|
|
66006
|
+
if (options.length === 0)
|
|
66007
|
+
continue;
|
|
66008
|
+
const question = { id, prompt, options };
|
|
66009
|
+
for (const key of ["header", "description", "detail"]) {
|
|
66010
|
+
const v = optionalStringField(q, key);
|
|
66011
|
+
if (v !== undefined)
|
|
66012
|
+
question[key] = v;
|
|
66013
|
+
}
|
|
66014
|
+
if (q.multiSelect === true)
|
|
66015
|
+
question.multiSelect = true;
|
|
66016
|
+
questions.push(question);
|
|
66017
|
+
}
|
|
66018
|
+
if (questions.length > 0)
|
|
66019
|
+
out.questions = questions;
|
|
66020
|
+
}
|
|
66021
|
+
return out;
|
|
66022
|
+
}
|
|
66023
|
+
function approvalArgs(request) {
|
|
66024
|
+
return {
|
|
66025
|
+
...request.callId !== undefined ? { callId: request.callId } : {},
|
|
66026
|
+
...request.reason !== undefined ? { reason: request.reason } : {}
|
|
66027
|
+
};
|
|
66028
|
+
}
|
|
66029
|
+
function approvalQuestion(request) {
|
|
66030
|
+
const toolName = request.toolName ?? "tool";
|
|
66031
|
+
return {
|
|
66032
|
+
id: request.eventId,
|
|
66033
|
+
prompt: request.reason ?? `Allow ${toolName}?`,
|
|
66034
|
+
options: [{ label: "allow" }, { label: "deny" }],
|
|
66035
|
+
header: "Approval",
|
|
66036
|
+
...request.callId !== undefined ? { detail: `callId: ${request.callId}` } : {}
|
|
66037
|
+
};
|
|
66038
|
+
}
|
|
66039
|
+
function approvalVerdictFromPicks(request, picks) {
|
|
66040
|
+
const pick = picks.find((p) => p.questionId === request.eventId);
|
|
66041
|
+
const choice = pick?.custom ?? pick?.selections?.[0] ?? pick?.selected ?? "";
|
|
66042
|
+
return /^(allow|allowed-once|yes|approve)$/i.test(choice) ? "allowed-once" : "rejected";
|
|
66043
|
+
}
|
|
66044
|
+
function answersFor(request, picks) {
|
|
66045
|
+
const questions = request.questions ?? [];
|
|
66046
|
+
if (questions.length === 0) {
|
|
66047
|
+
return picks.map((pick) => ({
|
|
66048
|
+
id: pick.questionId,
|
|
66049
|
+
selected: pick.selections?.length ? [...pick.selections] : [pick.selected],
|
|
66050
|
+
...pick.custom !== undefined && pick.custom !== "" ? { custom: pick.custom } : {}
|
|
66051
|
+
}));
|
|
66052
|
+
}
|
|
66053
|
+
return questions.map((q) => {
|
|
66054
|
+
const pick = picks.find((p) => p.questionId === q.id);
|
|
66055
|
+
if (pick?.custom !== undefined && pick.custom !== "")
|
|
66056
|
+
return { id: q.id, selected: [], custom: pick.custom };
|
|
66057
|
+
if (pick === undefined || pick.selected === "" && (pick.custom ?? "") === "") {
|
|
66058
|
+
return { id: q.id, selected: [], custom: "declined" };
|
|
66059
|
+
}
|
|
66060
|
+
return {
|
|
66061
|
+
id: q.id,
|
|
66062
|
+
selected: pick.selections?.length ? [...pick.selections] : [pick.selected]
|
|
66063
|
+
};
|
|
66064
|
+
});
|
|
66065
|
+
}
|
|
66066
|
+
function unavailableResponse(request) {
|
|
66067
|
+
return request.kind === "questions" ? { eventId: request.eventId, kind: "questions", verdict: "unavailable", answers: answersFor(request, []) } : { eventId: request.eventId, kind: "approval", verdict: "unavailable" };
|
|
66068
|
+
}
|
|
66069
|
+
function asRecord5(value) {
|
|
66070
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
66071
|
+
}
|
|
66072
|
+
function unsupported(capability) {
|
|
66073
|
+
throw new BridgeProtocolError("UNSUPPORTED", `${capability} is not backed by the in-process bridge`, { capability });
|
|
66074
|
+
}
|
|
66075
|
+
function projectBridgeSessionList(items, limit = 12) {
|
|
66076
|
+
const rows = Array.isArray(items) ? items : [];
|
|
66077
|
+
const out = [];
|
|
66078
|
+
for (const item of rows) {
|
|
66079
|
+
const row = asRecord5(item);
|
|
66080
|
+
if (row.origin === "subagent")
|
|
66081
|
+
continue;
|
|
66082
|
+
const id = typeof row.sessionId === "string" ? row.sessionId : "";
|
|
66083
|
+
if (!id)
|
|
66084
|
+
continue;
|
|
66085
|
+
const updatedAt = typeof row.updatedAt === "number" ? String(row.updatedAt) : "";
|
|
66086
|
+
const values = asRecord5(asRecord5(row.projections).values);
|
|
66087
|
+
const title = typeof values.title === "string" ? values.title : "";
|
|
66088
|
+
out.push({
|
|
66089
|
+
id,
|
|
66090
|
+
title: title.slice(0, 40),
|
|
66091
|
+
...updatedAt ? { updatedAt } : {},
|
|
66092
|
+
...typeof row.cwd === "string" && row.cwd ? { cwd: row.cwd } : {},
|
|
66093
|
+
...typeof row.sizeBytes === "number" && Number.isFinite(row.sizeBytes) ? { sizeBytes: row.sizeBytes } : {},
|
|
66094
|
+
...typeof row.blank === "boolean" ? { blank: row.blank } : {}
|
|
66095
|
+
});
|
|
66096
|
+
}
|
|
66097
|
+
return out.sort((a, b) => String(b.updatedAt ?? "").localeCompare(String(a.updatedAt ?? ""))).slice(0, limit);
|
|
66098
|
+
}
|
|
66099
|
+
function bridgeReplayRowsToSeamTranscript(rows, skip = 0) {
|
|
66100
|
+
const entries = rows.map((row) => ({
|
|
66101
|
+
type: row.type,
|
|
66102
|
+
seq: row.seq,
|
|
66103
|
+
time: 0,
|
|
66104
|
+
data: asRecord5(row.payload)
|
|
66105
|
+
}));
|
|
66106
|
+
const durable = journalToTranscriptRows(entries, skip);
|
|
66107
|
+
return durable.map((row) => {
|
|
66108
|
+
if (row.kind === "ask") {
|
|
66109
|
+
return { kind: "ask", text: "", final: true, entries: row.entries };
|
|
66110
|
+
}
|
|
66111
|
+
if (row.kind === "tool") {
|
|
66112
|
+
return { kind: "tool", text: row.name, final: true, args: row.args, output: row.brief, ok: row.ok };
|
|
66113
|
+
}
|
|
66114
|
+
return { kind: row.kind, text: row.text, final: true };
|
|
66115
|
+
});
|
|
66116
|
+
}
|
|
66117
|
+
function seamReplayEventKey(event) {
|
|
66118
|
+
const details = asRecord5(event.details);
|
|
66119
|
+
return `${event.type}:${String(details.id ?? details.messageID ?? "")}:${String(asRecord5(details.part).id ?? "")}`;
|
|
66120
|
+
}
|
|
66121
|
+
function bridgeReplayRowsToSeamEvents(rows, sessionId) {
|
|
66122
|
+
const events = [];
|
|
66123
|
+
const seen = new Set;
|
|
66124
|
+
const push = (event) => {
|
|
66125
|
+
const key = seamReplayEventKey(event);
|
|
66126
|
+
if (seen.has(key))
|
|
66127
|
+
return;
|
|
66128
|
+
seen.add(key);
|
|
66129
|
+
events.push(event);
|
|
66130
|
+
};
|
|
66131
|
+
const toolCalls = new Map;
|
|
66132
|
+
for (const row of rows) {
|
|
66133
|
+
const entry = { type: row.type, seq: row.seq, time: 0, data: asRecord5(row.payload) };
|
|
66134
|
+
for (const event of projectJournalRecord(entry, sessionId))
|
|
66135
|
+
push(event);
|
|
66136
|
+
const data = entry.data;
|
|
66137
|
+
if (row.type === "tool/call") {
|
|
66138
|
+
const callId = data.callId === undefined ? "" : String(data.callId);
|
|
66139
|
+
if (callId) {
|
|
66140
|
+
toolCalls.set(callId, {
|
|
66141
|
+
seq: row.seq,
|
|
66142
|
+
name: typeof data.name === "string" ? data.name : "tool",
|
|
66143
|
+
args: typeof data.arguments === "string" ? data.arguments : ""
|
|
66144
|
+
});
|
|
66145
|
+
}
|
|
66146
|
+
} else if (row.type === "tool/result") {
|
|
66147
|
+
const message = asRecord5(data.message);
|
|
66148
|
+
const callId = data.callId !== undefined ? String(data.callId) : message.toolCallId !== undefined ? String(message.toolCallId) : "";
|
|
66149
|
+
const call = callId ? toolCalls.get(callId) : undefined;
|
|
66150
|
+
if (call !== undefined) {
|
|
66151
|
+
toolCalls.delete(callId);
|
|
66152
|
+
const messageID = `journal-${call.seq}`;
|
|
66153
|
+
const ok = data.isError !== true && message.isError !== true;
|
|
66154
|
+
push({
|
|
66155
|
+
type: "message.part.updated",
|
|
66156
|
+
details: {
|
|
66157
|
+
messageID,
|
|
66158
|
+
sessionID: sessionId,
|
|
66159
|
+
part: {
|
|
66160
|
+
type: "tool",
|
|
66161
|
+
id: callId,
|
|
66162
|
+
name: call.name,
|
|
66163
|
+
input: call.args,
|
|
66164
|
+
status: ok ? "done" : "failed",
|
|
66165
|
+
output: JSON.stringify(data.output ?? data).slice(0, 300)
|
|
66166
|
+
}
|
|
66167
|
+
}
|
|
66168
|
+
});
|
|
66169
|
+
}
|
|
66170
|
+
}
|
|
66171
|
+
}
|
|
66172
|
+
return events;
|
|
66173
|
+
}
|
|
66174
|
+
function bridgeAgentRunKey(runId, seq) {
|
|
66175
|
+
return `${runId}:${seq}`;
|
|
66176
|
+
}
|
|
66177
|
+
function bridgeSettledStatus(outcome) {
|
|
66178
|
+
return outcome === "failed" || outcome === "cancelled" ? outcome : "completed";
|
|
66179
|
+
}
|
|
66180
|
+
function bridgeSettleChild(existing, outcome, startedAt, now) {
|
|
66181
|
+
return {
|
|
66182
|
+
id: existing.id,
|
|
66183
|
+
label: existing.label,
|
|
66184
|
+
...existing.model !== undefined ? { model: existing.model } : {},
|
|
66185
|
+
status: bridgeSettledStatus(outcome),
|
|
66186
|
+
rounds: existing.rounds,
|
|
66187
|
+
elapsedSec: Number(((now - startedAt) / 1000).toFixed(1)),
|
|
66188
|
+
endedAt: now,
|
|
66189
|
+
...existing.injectedRound !== undefined ? { injectedRound: existing.injectedRound } : {},
|
|
66190
|
+
...existing.hardStopRound !== undefined ? { hardStopRound: existing.hardStopRound } : {},
|
|
66191
|
+
...existing.spinStopRound !== undefined ? { spinStopRound: existing.spinStopRound } : {},
|
|
66192
|
+
...existing.lastLine !== undefined ? { lastLine: existing.lastLine } : {}
|
|
66193
|
+
};
|
|
66194
|
+
}
|
|
66195
|
+
function bridgeFoldAgentRecord(children, runSeq, liveStarts, type, data, now, live) {
|
|
66196
|
+
if (type === "user/message") {
|
|
66197
|
+
const source = asRecord5(data.source);
|
|
66198
|
+
if (source.kind !== BRIDGE_SUBAGENT_SETTLED)
|
|
66199
|
+
return false;
|
|
66200
|
+
const childId = typeof source.senderSessionId === "string" ? source.senderSessionId : "";
|
|
66201
|
+
if (!childId)
|
|
66202
|
+
return false;
|
|
66203
|
+
const existing = children.get(childId);
|
|
66204
|
+
if (!existing || existing.status !== "running")
|
|
66205
|
+
return false;
|
|
66206
|
+
children.set(childId, bridgeSettleChild(existing, source.stopReason, existing.startedAt ?? now, now));
|
|
66207
|
+
return true;
|
|
66208
|
+
}
|
|
66209
|
+
if (type === BRIDGE_SUBAGENT_CATALOG) {
|
|
66210
|
+
const childId = typeof data.childId === "string" ? data.childId : "";
|
|
66211
|
+
if (!childId)
|
|
66212
|
+
return false;
|
|
66213
|
+
const label = typeof data.label === "string" && data.label ? data.label : typeof data.name === "string" ? data.name : "";
|
|
66214
|
+
const childCreatedAt = typeof data.childCreatedAt === "number" && Number.isFinite(data.childCreatedAt) ? data.childCreatedAt : undefined;
|
|
66215
|
+
const existing = children.get(childId);
|
|
66216
|
+
if (existing !== undefined && existing.status !== "running") {
|
|
66217
|
+
runSeq.set(bridgeAgentRunKey(`${BRIDGE_CATALOG_RUN_PREFIX}${childId}`, 0), childId);
|
|
66218
|
+
children.set(childId, {
|
|
66219
|
+
id: existing.id,
|
|
66220
|
+
label: label || existing.label,
|
|
66221
|
+
status: "running",
|
|
66222
|
+
rounds: 0,
|
|
66223
|
+
startedAt: childCreatedAt ?? now,
|
|
66224
|
+
...existing.model !== undefined ? { model: existing.model } : {}
|
|
66225
|
+
});
|
|
66226
|
+
if (live)
|
|
66227
|
+
liveStarts.add(childId);
|
|
66228
|
+
return true;
|
|
66229
|
+
}
|
|
66230
|
+
return bridgeFoldAgentRecord(children, runSeq, liveStarts, BRIDGE_AGENT_START, {
|
|
66231
|
+
childId,
|
|
66232
|
+
label,
|
|
66233
|
+
runId: `${BRIDGE_CATALOG_RUN_PREFIX}${childId}`,
|
|
66234
|
+
seq: 0,
|
|
66235
|
+
...childCreatedAt !== undefined ? { childCreatedAt } : {},
|
|
66236
|
+
viaCatalog: true
|
|
66237
|
+
}, now, live);
|
|
66238
|
+
}
|
|
66239
|
+
if (type === BRIDGE_AGENT_START) {
|
|
66240
|
+
const childId = typeof data.childId === "string" ? data.childId : "";
|
|
66241
|
+
if (!childId)
|
|
66242
|
+
return false;
|
|
66243
|
+
const runId = data.runId === undefined ? "" : String(data.runId);
|
|
66244
|
+
if (data.viaCatalog !== true && runId.startsWith(BRIDGE_CATALOG_RUN_PREFIX))
|
|
66245
|
+
return false;
|
|
66246
|
+
const seq = typeof data.seq === "number" ? data.seq : -1;
|
|
66247
|
+
runSeq.set(bridgeAgentRunKey(runId, seq), childId);
|
|
66248
|
+
const childCreatedAt = typeof data.childCreatedAt === "number" && Number.isFinite(data.childCreatedAt) ? data.childCreatedAt : undefined;
|
|
66249
|
+
const existing = children.get(childId);
|
|
66250
|
+
if (existing !== undefined) {
|
|
66251
|
+
const newLabel = typeof data.label === "string" ? data.label : "";
|
|
66252
|
+
const labelChanged = newLabel !== "" && newLabel !== existing.label;
|
|
66253
|
+
const upgradeStart = live && existing.status === "running" && !liveStarts.has(childId);
|
|
66254
|
+
if (!labelChanged && !upgradeStart)
|
|
66255
|
+
return false;
|
|
66256
|
+
children.set(childId, {
|
|
66257
|
+
...existing,
|
|
66258
|
+
...labelChanged ? { label: newLabel } : {},
|
|
66259
|
+
...upgradeStart ? { startedAt: childCreatedAt ?? now } : {}
|
|
66260
|
+
});
|
|
66261
|
+
if (upgradeStart)
|
|
66262
|
+
liveStarts.add(childId);
|
|
66263
|
+
return true;
|
|
66264
|
+
}
|
|
66265
|
+
const label = typeof data.label === "string" && data.label ? data.label : `subagent ${childId.slice(0, 8)}`;
|
|
66266
|
+
children.set(childId, { id: childId, label, status: "running", rounds: 0, startedAt: childCreatedAt ?? now });
|
|
66267
|
+
if (live)
|
|
66268
|
+
liveStarts.add(childId);
|
|
66269
|
+
return true;
|
|
66270
|
+
}
|
|
66271
|
+
if (type === BRIDGE_AGENT_END) {
|
|
66272
|
+
const runId = data.runId === undefined ? "" : String(data.runId);
|
|
66273
|
+
const seq = typeof data.seq === "number" ? data.seq : -1;
|
|
66274
|
+
const key = bridgeAgentRunKey(runId, seq);
|
|
66275
|
+
const childId = runSeq.get(key);
|
|
66276
|
+
if (!childId)
|
|
66277
|
+
return false;
|
|
66278
|
+
const existing = children.get(childId);
|
|
66279
|
+
if (!existing || existing.status !== "running")
|
|
66280
|
+
return false;
|
|
66281
|
+
children.set(childId, bridgeSettleChild(existing, data.outcome, existing.startedAt ?? now, now));
|
|
66282
|
+
runSeq.delete(key);
|
|
66283
|
+
return true;
|
|
66284
|
+
}
|
|
66285
|
+
return false;
|
|
66286
|
+
}
|
|
66287
|
+
function lastJournalTurnTerminal(rows, startOutsideWindow = false) {
|
|
66288
|
+
if (startOutsideWindow) {
|
|
66289
|
+
let nextStart = Infinity;
|
|
66290
|
+
const startIds = new Set;
|
|
66291
|
+
for (const row of rows) {
|
|
66292
|
+
if (row.type === "turn/start") {
|
|
66293
|
+
nextStart = Math.min(nextStart, row.seq);
|
|
66294
|
+
const id = journalTurnId(row);
|
|
66295
|
+
if (id !== undefined)
|
|
66296
|
+
startIds.add(id);
|
|
66297
|
+
}
|
|
66298
|
+
}
|
|
66299
|
+
let latest;
|
|
66300
|
+
for (const row of rows) {
|
|
66301
|
+
if (row.type !== "turn/end" && row.type !== "turn/error")
|
|
66302
|
+
continue;
|
|
66303
|
+
if (row.seq >= nextStart)
|
|
66304
|
+
continue;
|
|
66305
|
+
const id = journalTurnId(row);
|
|
66306
|
+
if (id !== undefined && startIds.has(id))
|
|
66307
|
+
continue;
|
|
66308
|
+
if (latest === undefined || row.seq > latest.seq)
|
|
66309
|
+
latest = row;
|
|
66310
|
+
}
|
|
66311
|
+
return latest;
|
|
66312
|
+
}
|
|
66313
|
+
let lastStart = -Infinity;
|
|
66314
|
+
let hasStart = false;
|
|
66315
|
+
for (const row of rows) {
|
|
66316
|
+
if (row.type === "turn/start") {
|
|
66317
|
+
lastStart = row.seq;
|
|
66318
|
+
hasStart = true;
|
|
66319
|
+
}
|
|
66320
|
+
}
|
|
66321
|
+
let latest;
|
|
66322
|
+
for (const row of rows) {
|
|
66323
|
+
if ((row.type === "turn/end" || row.type === "turn/error") && (!hasStart || row.seq > lastStart)) {
|
|
66324
|
+
if (latest === undefined || row.seq > latest.seq)
|
|
66325
|
+
latest = row;
|
|
66326
|
+
}
|
|
66327
|
+
}
|
|
66328
|
+
return latest;
|
|
66329
|
+
}
|
|
66330
|
+
function journalTurnId(row) {
|
|
66331
|
+
const payload = asRecord5(row.payload);
|
|
66332
|
+
if (typeof payload.turn === "number" && Number.isFinite(payload.turn))
|
|
66333
|
+
return payload.turn;
|
|
66334
|
+
if (typeof payload.turnId === "string" && payload.turnId !== "")
|
|
66335
|
+
return payload.turnId;
|
|
66336
|
+
return;
|
|
66337
|
+
}
|
|
66338
|
+
function projectBridgeEvent(frame, sessionId) {
|
|
66339
|
+
const payload = asRecord5(frame.payload);
|
|
66340
|
+
const turnId = typeof payload.turnId === "string" ? payload.turnId : "";
|
|
66341
|
+
if (frame.type === "turn.start") {
|
|
66342
|
+
return [{ type: "session.updated", details: { sessionID: sessionId, turnId, turn: "starting" } }];
|
|
66343
|
+
}
|
|
66344
|
+
if (frame.type === "turn.end") {
|
|
66345
|
+
return [{ type: "session.updated", details: { sessionID: sessionId, turnId, turn: "idle" } }];
|
|
66346
|
+
}
|
|
66347
|
+
if (frame.type === "turn.error") {
|
|
66348
|
+
return [{
|
|
66349
|
+
type: "session.error",
|
|
66350
|
+
details: {
|
|
66351
|
+
sessionID: sessionId,
|
|
66352
|
+
turnId,
|
|
66353
|
+
code: typeof payload.code === "string" ? payload.code : "INTERNAL",
|
|
66354
|
+
message: typeof payload.message === "string" ? payload.message : "turn failed"
|
|
66355
|
+
}
|
|
66356
|
+
}];
|
|
66357
|
+
}
|
|
66358
|
+
return [];
|
|
66359
|
+
}
|
|
66360
|
+
function parseUsage(value) {
|
|
66361
|
+
const u = asRecord5(value);
|
|
66362
|
+
const num = (...aliases) => {
|
|
66363
|
+
let present = false;
|
|
66364
|
+
let best = 0;
|
|
66365
|
+
for (const alias of aliases) {
|
|
66366
|
+
const v = u[alias];
|
|
66367
|
+
if (typeof v === "number" && Number.isFinite(v)) {
|
|
66368
|
+
present = true;
|
|
66369
|
+
best = Math.max(best, v);
|
|
66370
|
+
}
|
|
66371
|
+
}
|
|
66372
|
+
return present ? best : undefined;
|
|
66373
|
+
};
|
|
66374
|
+
const out = {};
|
|
66375
|
+
const prompt = num("prompt", "promptTokens", "inputTokens", "prompt_tokens");
|
|
66376
|
+
if (prompt !== undefined)
|
|
66377
|
+
out.prompt = prompt;
|
|
66378
|
+
const completion = num("completion", "completionTokens", "outputTokens", "completion_tokens");
|
|
66379
|
+
if (completion !== undefined)
|
|
66380
|
+
out.completion = completion;
|
|
66381
|
+
const cacheRead = num("cacheRead", "cacheReadTokens", "cache_read_tokens");
|
|
66382
|
+
if (cacheRead !== undefined)
|
|
66383
|
+
out.cacheRead = cacheRead;
|
|
66384
|
+
const cacheWrite = num("cacheWrite", "cacheWriteTokens", "cache_write_tokens");
|
|
66385
|
+
if (cacheWrite !== undefined)
|
|
66386
|
+
out.cacheWrite = cacheWrite;
|
|
66387
|
+
return out;
|
|
66388
|
+
}
|
|
66389
|
+
function journalUsage(payload) {
|
|
66390
|
+
const usage = asRecord5(asRecord5(payload).usage);
|
|
66391
|
+
const parsed = parseUsage(usage);
|
|
66392
|
+
if (Object.keys(parsed).length === 0)
|
|
66393
|
+
return;
|
|
66394
|
+
const billed = (parsed.prompt ?? 0) + (parsed.cacheRead ?? 0) + (parsed.cacheWrite ?? 0);
|
|
66395
|
+
const rawTotal = usage.totalTokens;
|
|
66396
|
+
const total = typeof rawTotal === "number" && Number.isFinite(rawTotal) && rawTotal > 0 ? rawTotal : billed + (parsed.completion ?? 0);
|
|
66397
|
+
return { ...parsed, total };
|
|
66398
|
+
}
|
|
66399
|
+
function asDeadCause(value) {
|
|
66400
|
+
const r = asRecord5(value);
|
|
66401
|
+
const stage = r.stage;
|
|
66402
|
+
const stages = ["spawn", "handshake", "runtime", "closed"];
|
|
66403
|
+
return {
|
|
66404
|
+
stage: typeof stage === "string" && stages.includes(stage) ? stage : "runtime",
|
|
66405
|
+
code: typeof r.code === "number" ? r.code : null,
|
|
66406
|
+
signal: typeof r.signal === "string" ? r.signal : null,
|
|
66407
|
+
message: typeof r.message === "string" ? r.message : "bridge connection lost",
|
|
66408
|
+
...r.recoverability === "permanent" || r.recoverability === "retriable" ? { recoverability: r.recoverability } : {},
|
|
66409
|
+
...Array.isArray(r.mismatches) && r.mismatches.every((m) => typeof m === "string") ? { mismatches: r.mismatches } : {}
|
|
66410
|
+
};
|
|
66411
|
+
}
|
|
66412
|
+
|
|
66413
|
+
class BridgeSessionSeam {
|
|
66414
|
+
#transport;
|
|
66415
|
+
#ctx;
|
|
66416
|
+
#unsubEvent;
|
|
66417
|
+
#listeners = [];
|
|
66418
|
+
#onDead;
|
|
66419
|
+
#subagentViews = new Map;
|
|
66420
|
+
#subagentRunSeq = new Map;
|
|
66421
|
+
#subagentLiveStarts = new Set;
|
|
66422
|
+
#subagentListeners = new Set;
|
|
66423
|
+
#subagentSessionId;
|
|
66424
|
+
#connection = "disconnected";
|
|
66425
|
+
#turn = "idle";
|
|
66426
|
+
#bridgeLink = "ready";
|
|
66427
|
+
#sessionAttached = false;
|
|
66428
|
+
#currentSessionId;
|
|
66429
|
+
#lastAppliedSeq;
|
|
66430
|
+
#lastAppliedSessionId;
|
|
66431
|
+
#appliedReplayKeys = new Set;
|
|
66432
|
+
#recoveryState = "idle";
|
|
66433
|
+
#pendingOpen;
|
|
66434
|
+
#inFlightTurnId;
|
|
66435
|
+
#activeCallbacks;
|
|
66436
|
+
#turnDone;
|
|
66437
|
+
#turnGeneration = 0;
|
|
66438
|
+
#inFlightGeneration = 0;
|
|
66439
|
+
#degradedOnce = new Set;
|
|
66440
|
+
#usage = { turns: 0, prompt: 0, completion: 0, cacheRead: 0, cacheWrite: 0 };
|
|
66441
|
+
#decodeWindowStart;
|
|
66442
|
+
#lastTurnDecode;
|
|
66443
|
+
#decodeTotals = { tokens: 0, ms: 0 };
|
|
66444
|
+
#sessionInfoInFlight;
|
|
66445
|
+
#sessionInfoStats;
|
|
66446
|
+
#askFrameSeen = false;
|
|
66447
|
+
#permissionNoticeShown = false;
|
|
66448
|
+
#onPermissionUnavailable;
|
|
66449
|
+
#askProvider;
|
|
66450
|
+
#pendingAsks = new Map;
|
|
66451
|
+
#bufferedPendingSnapshot;
|
|
66452
|
+
#replayDrainPending = false;
|
|
66453
|
+
#deadInFlight;
|
|
66454
|
+
#inFlightPartial = "";
|
|
66455
|
+
#invalidatedAsks = new Map;
|
|
66456
|
+
#disposed = false;
|
|
66457
|
+
constructor(options) {
|
|
66458
|
+
this.#transport = options.transport;
|
|
66459
|
+
this.#ctx = options.ctx;
|
|
66460
|
+
this.#onDead = options.onDead;
|
|
66461
|
+
this.#onPermissionUnavailable = options.onPermissionUnavailable;
|
|
66462
|
+
this.#unsubEvent = this.#transport.onEvent((frame) => this.#onBridgeEvent(frame));
|
|
66463
|
+
}
|
|
66464
|
+
async connect() {
|
|
66465
|
+
try {
|
|
66466
|
+
await this.#transport.request("bridge.ping");
|
|
66467
|
+
this.#connection = "connected";
|
|
66468
|
+
} catch (err) {
|
|
66469
|
+
this.#connection = "disconnected";
|
|
66470
|
+
this.#ctx.logger.warn("[bridge-seam] bridge.ping failed, status connection=disconnected: %s", err);
|
|
66471
|
+
}
|
|
66472
|
+
}
|
|
66473
|
+
status() {
|
|
66474
|
+
if (this.#connection === "disconnected") {
|
|
66475
|
+
this.#degradeOnce("status", "no handshake/status frame; returning disconnected/idle");
|
|
66476
|
+
}
|
|
66477
|
+
return { connection: this.#connection, turn: this.#turn, sessionAttached: this.#sessionAttached, bridge: this.#bridgeLink };
|
|
66478
|
+
}
|
|
66479
|
+
currentSessionId() {
|
|
66480
|
+
return this.#currentSessionId;
|
|
66481
|
+
}
|
|
66482
|
+
resumeSession(id) {
|
|
66483
|
+
this.#pendingOpen = { mode: "resume", id };
|
|
66484
|
+
return "ok";
|
|
66485
|
+
}
|
|
66486
|
+
newSession() {
|
|
66487
|
+
this.#currentSessionId = undefined;
|
|
66488
|
+
this.#pendingOpen = { mode: "new" };
|
|
66489
|
+
this.#settleSuspendedTurn();
|
|
66490
|
+
this.#deadInFlight = undefined;
|
|
66491
|
+
this.#inFlightPartial = "";
|
|
66492
|
+
}
|
|
66493
|
+
stagedSessionId() {
|
|
66494
|
+
return this.#pendingOpen?.mode === "resume" ? this.#pendingOpen.id : undefined;
|
|
66495
|
+
}
|
|
66496
|
+
recoveryState() {
|
|
66497
|
+
return this.#recoveryState;
|
|
66498
|
+
}
|
|
66499
|
+
async recoverSession() {
|
|
66500
|
+
const sessionId = this.#currentSessionId ?? this.stagedSessionId();
|
|
66501
|
+
const emit = (event) => {
|
|
66502
|
+
for (const listener of [...this.#listeners]) {
|
|
66503
|
+
try {
|
|
66504
|
+
listener(event);
|
|
66505
|
+
} catch {}
|
|
66506
|
+
}
|
|
66507
|
+
};
|
|
66508
|
+
const fail = (code, message) => {
|
|
66509
|
+
this.#recoveryState = "failed";
|
|
66510
|
+
this.#sessionAttached = false;
|
|
66511
|
+
this.#connection = "connected";
|
|
66512
|
+
this.#bridgeLink = "ready";
|
|
66513
|
+
this.#bufferedPendingSnapshot = undefined;
|
|
66514
|
+
this.#replayDrainPending = false;
|
|
66515
|
+
this.#settleSuspendedTurn();
|
|
66516
|
+
const result = {
|
|
66517
|
+
state: "failed",
|
|
66518
|
+
sessionId,
|
|
66519
|
+
applied: 0,
|
|
66520
|
+
from: 0,
|
|
66521
|
+
cursor: 0,
|
|
66522
|
+
rows: [],
|
|
66523
|
+
error: { code, message }
|
|
66524
|
+
};
|
|
66525
|
+
emit({ type: "bridge.recovery.failed", details: { ...result, message: `\u6062\u590D\u5931\u8D25: ${message}` } });
|
|
66526
|
+
return result;
|
|
66527
|
+
};
|
|
66528
|
+
if (this.#disposed)
|
|
66529
|
+
return fail("DISPOSED", "bridge seam is disposed");
|
|
66530
|
+
if (sessionId === undefined || sessionId === "") {
|
|
66531
|
+
return fail("NO_SESSION_TO_RESUME", "no session was open before DEAD");
|
|
66532
|
+
}
|
|
66533
|
+
this.#recoveryState = "recovering";
|
|
66534
|
+
this.#connection = "connected";
|
|
66535
|
+
this.#bridgeLink = "ready";
|
|
66536
|
+
this.#sessionAttached = false;
|
|
66537
|
+
this.#replayDrainPending = true;
|
|
66538
|
+
let opened;
|
|
66539
|
+
try {
|
|
66540
|
+
opened = asRecord5(await this.#transport.request("session.open", { mode: "resume", id: sessionId }));
|
|
66541
|
+
} catch (err) {
|
|
66542
|
+
const code = err instanceof BridgeProtocolError ? err.code : "SESSION_OPEN_FAILED";
|
|
66543
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
66544
|
+
if (code === "SESSION_LOCKED") {
|
|
66545
|
+
this.#recoveryState = "locked";
|
|
66546
|
+
this.#sessionAttached = false;
|
|
66547
|
+
this.#bufferedPendingSnapshot = undefined;
|
|
66548
|
+
this.#replayDrainPending = false;
|
|
66549
|
+
this.#settleSuspendedTurn();
|
|
66550
|
+
const errorDetail = err instanceof BridgeProtocolError ? asRecord5(err.detail) : {};
|
|
66551
|
+
const holder = typeof errorDetail.holder === "string" && errorDetail.holder.trim() !== "" ? errorDetail.holder : undefined;
|
|
66552
|
+
const result = {
|
|
66553
|
+
state: "locked",
|
|
66554
|
+
sessionId,
|
|
66555
|
+
applied: 0,
|
|
66556
|
+
from: 0,
|
|
66557
|
+
cursor: 0,
|
|
66558
|
+
rows: [],
|
|
66559
|
+
error: { code, message }
|
|
66560
|
+
};
|
|
66561
|
+
emit({
|
|
66562
|
+
type: "bridge.recovery.locked",
|
|
66563
|
+
details: {
|
|
66564
|
+
...result,
|
|
66565
|
+
message,
|
|
66566
|
+
...holder !== undefined ? { holder } : {}
|
|
66567
|
+
}
|
|
66568
|
+
});
|
|
66569
|
+
return result;
|
|
66570
|
+
}
|
|
66571
|
+
this.#ctx.logger.error("[bridge-seam] recovery session.open failed: %s", err);
|
|
66572
|
+
return fail(code, message);
|
|
66573
|
+
}
|
|
66574
|
+
const boundId = typeof opened.sessionId === "string" ? opened.sessionId : sessionId;
|
|
66575
|
+
this.#currentSessionId = boundId;
|
|
66576
|
+
if (this.#pendingOpen?.mode === "resume" && this.#pendingOpen.id === boundId)
|
|
66577
|
+
this.#pendingOpen = undefined;
|
|
66578
|
+
if (this.#lastAppliedSessionId !== boundId) {
|
|
66579
|
+
this.#lastAppliedSessionId = boundId;
|
|
66580
|
+
this.#lastAppliedSeq = undefined;
|
|
66581
|
+
this.#appliedReplayKeys.clear();
|
|
66582
|
+
}
|
|
66583
|
+
this.#sessionAttached = true;
|
|
66584
|
+
const from = this.#lastAppliedSeq === undefined ? 1 : this.#lastAppliedSeq + 1;
|
|
66585
|
+
let drained;
|
|
66586
|
+
try {
|
|
66587
|
+
drained = await this.#drainJournal(boundId, from);
|
|
66588
|
+
} catch (err) {
|
|
66589
|
+
const code = err instanceof BridgeProtocolError ? err.code : "JOURNAL_REPLAY_FAILED";
|
|
66590
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
66591
|
+
this.#ctx.logger.error("[bridge-seam] recovery journal.replay failed: %s", err);
|
|
66592
|
+
return fail(code, message);
|
|
66593
|
+
}
|
|
66594
|
+
if (drained.clamped) {
|
|
66595
|
+
this.#ctx.logger.warn("[bridge-seam] recovery replay from=%d is ahead of journal max=%d; clamped to %d", from, Math.max(0, drained.cursor - 1), drained.cursor);
|
|
66596
|
+
}
|
|
66597
|
+
this.#foldAgentReplayRows(drained.rows, boundId);
|
|
66598
|
+
const rows = bridgeReplayRowsToSeamTranscript(drained.rows);
|
|
66599
|
+
if (drained.rows.length > 0) {
|
|
66600
|
+
const maxSeq = drained.rows.reduce((m, row) => Math.max(m, row.seq), -Infinity);
|
|
66601
|
+
this.#lastAppliedSeq = Math.max(this.#lastAppliedSeq ?? 0, maxSeq);
|
|
66602
|
+
this.#lastAppliedSessionId = boundId;
|
|
66603
|
+
}
|
|
66604
|
+
const buffered = this.#bufferedPendingSnapshot;
|
|
66605
|
+
this.#bufferedPendingSnapshot = undefined;
|
|
66606
|
+
this.#replayDrainPending = false;
|
|
66607
|
+
if (buffered !== undefined)
|
|
66608
|
+
this.#applyPendingSnapshot(buffered);
|
|
66609
|
+
const dead = this.#deadInFlight;
|
|
66610
|
+
this.#deadInFlight = undefined;
|
|
66611
|
+
if (dead !== undefined) {
|
|
66612
|
+
const firstStart = drained.rows.find((r) => r.type === "turn/start")?.seq;
|
|
66613
|
+
const firstTerminal = drained.rows.find((r) => r.type === "turn/end" || r.type === "turn/error")?.seq;
|
|
66614
|
+
const startOutsideWindow = firstStart !== undefined && firstTerminal !== undefined && firstTerminal < firstStart;
|
|
66615
|
+
const terminal = lastJournalTurnTerminal(drained.rows, startOutsideWindow);
|
|
66616
|
+
if (terminal !== undefined) {
|
|
66617
|
+
emit({
|
|
66618
|
+
type: "bridge.turn.terminal",
|
|
66619
|
+
details: {
|
|
66620
|
+
sessionID: boundId,
|
|
66621
|
+
turnId: dead.turnId,
|
|
66622
|
+
seq: terminal.seq,
|
|
66623
|
+
terminalType: terminal.type,
|
|
66624
|
+
reason: asRecord5(terminal.payload).reason,
|
|
66625
|
+
payload: terminal.payload,
|
|
66626
|
+
source: "journal"
|
|
66627
|
+
}
|
|
66628
|
+
});
|
|
66629
|
+
this.#settleSuspendedTurn();
|
|
66630
|
+
} else {
|
|
66631
|
+
emit({
|
|
66632
|
+
type: "bridge.turn.interrupted",
|
|
66633
|
+
details: {
|
|
66634
|
+
sessionID: boundId,
|
|
66635
|
+
turnId: dead.turnId,
|
|
66636
|
+
partial: dead.partial,
|
|
66637
|
+
reason: "connection lost while the turn was in flight",
|
|
66638
|
+
code: "INTERRUPTED",
|
|
66639
|
+
seq: null,
|
|
66640
|
+
source: "local"
|
|
66641
|
+
}
|
|
66642
|
+
});
|
|
66643
|
+
this.#settleSuspendedTurn();
|
|
66644
|
+
}
|
|
66645
|
+
}
|
|
66646
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
66647
|
+
for (const event of bridgeReplayRowsToSeamEvents(drained.rows, boundId)) {
|
|
66648
|
+
const key = seamReplayEventKey(event);
|
|
66649
|
+
if (this.#appliedReplayKeys.has(key))
|
|
66650
|
+
continue;
|
|
66651
|
+
this.#appliedReplayKeys.add(key);
|
|
66652
|
+
emit(event);
|
|
66653
|
+
}
|
|
66654
|
+
this.#sessionAttached = true;
|
|
66655
|
+
this.#connection = "connected";
|
|
66656
|
+
this.#bridgeLink = "ready";
|
|
66657
|
+
this.#recoveryState = "attached";
|
|
66658
|
+
const result = {
|
|
66659
|
+
state: "attached",
|
|
66660
|
+
sessionId: boundId,
|
|
66661
|
+
applied: drained.rows.length,
|
|
66662
|
+
from,
|
|
66663
|
+
cursor: drained.cursor,
|
|
66664
|
+
rows
|
|
66665
|
+
};
|
|
66666
|
+
emit({ type: "bridge.recovered", details: { ...result, message: `\u5DF2\u6062\u590D\uFF0C\u8865\u9F50 ${result.applied} \u6761\u4E8B\u4EF6` } });
|
|
66667
|
+
return result;
|
|
66668
|
+
}
|
|
66669
|
+
async#drainJournal(sessionId, startFrom) {
|
|
66670
|
+
let from = startFrom;
|
|
66671
|
+
let floor = startFrom;
|
|
66672
|
+
let cursor = 0;
|
|
66673
|
+
let clamped = false;
|
|
66674
|
+
const seen = new Set;
|
|
66675
|
+
const collected = [];
|
|
66676
|
+
for (;; ) {
|
|
66677
|
+
const value = asRecord5(await this.#transport.request("journal.replay", { sessionId, from }));
|
|
66678
|
+
const rawRows = Array.isArray(value.rows) ? value.rows : [];
|
|
66679
|
+
if (typeof value.cursor === "number" && Number.isFinite(value.cursor))
|
|
66680
|
+
cursor = value.cursor;
|
|
66681
|
+
if (!clamped && cursor > 0 && from > cursor) {
|
|
66682
|
+
clamped = true;
|
|
66683
|
+
from = cursor;
|
|
66684
|
+
floor = cursor;
|
|
66685
|
+
continue;
|
|
66686
|
+
}
|
|
66687
|
+
let added = 0;
|
|
66688
|
+
let pageMax = from - 1;
|
|
66689
|
+
for (const raw of rawRows) {
|
|
66690
|
+
const row = asRecord5(raw);
|
|
66691
|
+
const seq = row.seq;
|
|
66692
|
+
if (typeof seq !== "number" || !Number.isFinite(seq) || seq < floor || seen.has(seq))
|
|
66693
|
+
continue;
|
|
66694
|
+
seen.add(seq);
|
|
66695
|
+
collected.push({ seq, type: typeof row.type === "string" ? row.type : "", payload: row.payload });
|
|
66696
|
+
added += 1;
|
|
66697
|
+
if (seq > pageMax)
|
|
66698
|
+
pageMax = seq;
|
|
66699
|
+
}
|
|
66700
|
+
if (added === 0)
|
|
66701
|
+
break;
|
|
66702
|
+
from = pageMax + 1;
|
|
66703
|
+
if (cursor > 0 && from >= cursor)
|
|
66704
|
+
break;
|
|
66705
|
+
}
|
|
66706
|
+
collected.sort((a, b) => a.seq - b.seq);
|
|
66707
|
+
return { rows: collected, cursor, clamped };
|
|
66708
|
+
}
|
|
66709
|
+
interrupt() {
|
|
66710
|
+
const turnId = this.#inFlightTurnId;
|
|
66711
|
+
if (turnId === undefined || turnId === "") {
|
|
66712
|
+
this.#degrade("interrupt", "no in-flight turnId; turn.abort skipped (no-op)");
|
|
66713
|
+
return;
|
|
66714
|
+
}
|
|
66715
|
+
const fail = (message, code) => {
|
|
66716
|
+
this.#ctx.logger.warn("[bridge-seam] %s", message);
|
|
66717
|
+
const cb = this.#activeCallbacks;
|
|
66718
|
+
if (cb !== undefined) {
|
|
66719
|
+
try {
|
|
66720
|
+
cb.onError(message);
|
|
66721
|
+
} catch {}
|
|
66722
|
+
}
|
|
66723
|
+
const [event] = projectBridgeEvent({ type: "turn.error", payload: { turnId, code, message } }, this.#currentSessionId ?? "");
|
|
66724
|
+
if (event !== undefined) {
|
|
66725
|
+
for (const listener of this.#listeners) {
|
|
66726
|
+
try {
|
|
66727
|
+
listener(event);
|
|
66728
|
+
} catch {}
|
|
66729
|
+
}
|
|
66730
|
+
}
|
|
66731
|
+
if (this.#inFlightTurnId === turnId) {
|
|
66732
|
+
this.#inFlightTurnId = undefined;
|
|
66733
|
+
this.#turn = "idle";
|
|
66734
|
+
this.#turnDone?.();
|
|
66735
|
+
}
|
|
66736
|
+
};
|
|
66737
|
+
const attempt = (remaining) => {
|
|
66738
|
+
this.#transport.request("turn.abort", { turnId }).then((result) => {
|
|
66739
|
+
if (asRecord5(result).noop === true) {
|
|
66740
|
+
fail(`turn.abort was a noop for turn ${turnId}; turn may still be running`, "TURN_ABORT_NOOP");
|
|
66741
|
+
}
|
|
66742
|
+
}).catch((err) => {
|
|
66743
|
+
if (remaining > 0) {
|
|
66744
|
+
attempt(remaining - 1);
|
|
66745
|
+
return;
|
|
66746
|
+
}
|
|
66747
|
+
const code = err instanceof BridgeProtocolError ? err.code : "TURN_ABORT_FAILED";
|
|
66748
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
66749
|
+
fail(`turn.abort failed for turn ${turnId}: ${reason}`, code);
|
|
66750
|
+
});
|
|
66751
|
+
};
|
|
66752
|
+
attempt(1);
|
|
66753
|
+
}
|
|
66754
|
+
usageSummary() {
|
|
66755
|
+
if (this.#usage.turns === 0) {
|
|
66756
|
+
this.#degradeOnce("usageSummary", "no turn.end usage captured yet; returning []");
|
|
66757
|
+
return [];
|
|
66758
|
+
}
|
|
66759
|
+
const u = this.#usage;
|
|
66760
|
+
return [
|
|
66761
|
+
`turns ${u.turns}`,
|
|
66762
|
+
`prompt ${fmtTokens(u.prompt)} tok`,
|
|
66763
|
+
`completion ${fmtTokens(u.completion)} tok`
|
|
66764
|
+
];
|
|
66765
|
+
}
|
|
66766
|
+
cacheHitRate(mode) {
|
|
66767
|
+
const stats = this.#liveStats();
|
|
66768
|
+
if (stats === undefined || stats.cacheRead + stats.cacheWrite <= 0)
|
|
66769
|
+
return null;
|
|
66770
|
+
if (mode === "session") {
|
|
66771
|
+
const billed = stats.cachePrompt + stats.cacheRead + stats.cacheWrite;
|
|
66772
|
+
return billed > 0 ? stats.cacheRead / billed * 100 : null;
|
|
66773
|
+
}
|
|
66774
|
+
return stats.lastCacheHitRate;
|
|
66775
|
+
}
|
|
66776
|
+
contextTokens() {
|
|
66777
|
+
return this.#liveStats()?.contextTokens ?? null;
|
|
66778
|
+
}
|
|
66779
|
+
contextWindow() {
|
|
66780
|
+
return this.#liveContextWindow();
|
|
66781
|
+
}
|
|
66782
|
+
#liveStats() {
|
|
66783
|
+
const stats = this.#sessionInfoStats;
|
|
66784
|
+
return stats !== undefined && stats.sessionId === this.currentSessionId() ? stats : undefined;
|
|
66785
|
+
}
|
|
66786
|
+
#liveContextWindow() {
|
|
66787
|
+
const stats = this.#liveStats();
|
|
66788
|
+
if (stats?.contextWindow === undefined)
|
|
66789
|
+
return null;
|
|
66790
|
+
if (stats.contextWindowKey !== undefined && stats.selectionKey !== undefined && stats.contextWindowKey !== stats.selectionKey)
|
|
66791
|
+
return null;
|
|
66792
|
+
return stats.contextWindow;
|
|
66793
|
+
}
|
|
66794
|
+
sessionInfo() {
|
|
66795
|
+
const existing = this.#sessionInfoInFlight;
|
|
66796
|
+
if (existing !== undefined)
|
|
66797
|
+
return existing;
|
|
66798
|
+
const run = this.#computeSessionInfo();
|
|
66799
|
+
this.#sessionInfoInFlight = run;
|
|
66800
|
+
const release = () => {
|
|
66801
|
+
if (this.#sessionInfoInFlight === run)
|
|
66802
|
+
this.#sessionInfoInFlight = undefined;
|
|
66803
|
+
};
|
|
66804
|
+
run.then(release, release);
|
|
66805
|
+
return run;
|
|
66806
|
+
}
|
|
66807
|
+
async#computeSessionInfo() {
|
|
66808
|
+
const sessionId = this.currentSessionId();
|
|
66809
|
+
if (!sessionId)
|
|
66810
|
+
return;
|
|
66811
|
+
let counts;
|
|
66812
|
+
try {
|
|
66813
|
+
let stats = this.#sessionInfoStats;
|
|
66814
|
+
if (stats === undefined || stats.sessionId !== sessionId) {
|
|
66815
|
+
stats = {
|
|
66816
|
+
sessionId,
|
|
66817
|
+
lastSeq: 0,
|
|
66818
|
+
userRows: 0,
|
|
66819
|
+
assistantRows: 0,
|
|
66820
|
+
rawAssistants: 0,
|
|
66821
|
+
cachePrompt: 0,
|
|
66822
|
+
cacheRead: 0,
|
|
66823
|
+
cacheWrite: 0,
|
|
66824
|
+
lastCacheHitRate: null,
|
|
66825
|
+
contextTokens: null,
|
|
66826
|
+
contextWindow: undefined,
|
|
66827
|
+
contextWindowKey: undefined,
|
|
66828
|
+
selectionKey: undefined
|
|
66829
|
+
};
|
|
66830
|
+
this.#sessionInfoStats = stats;
|
|
66831
|
+
}
|
|
66832
|
+
let from = stats.lastSeq + 1;
|
|
66833
|
+
let drained = await this.#drainJournal(sessionId, from);
|
|
66834
|
+
if (drained.clamped && from > 1) {
|
|
66835
|
+
stats = {
|
|
66836
|
+
sessionId,
|
|
66837
|
+
lastSeq: 0,
|
|
66838
|
+
userRows: 0,
|
|
66839
|
+
assistantRows: 0,
|
|
66840
|
+
rawAssistants: 0,
|
|
66841
|
+
cachePrompt: 0,
|
|
66842
|
+
cacheRead: 0,
|
|
66843
|
+
cacheWrite: 0,
|
|
66844
|
+
lastCacheHitRate: null,
|
|
66845
|
+
contextTokens: null,
|
|
66846
|
+
contextWindow: undefined,
|
|
66847
|
+
contextWindowKey: undefined,
|
|
66848
|
+
selectionKey: undefined
|
|
66849
|
+
};
|
|
66850
|
+
this.#sessionInfoStats = stats;
|
|
66851
|
+
from = 1;
|
|
66852
|
+
drained = await this.#drainJournal(sessionId, 1);
|
|
66853
|
+
}
|
|
66854
|
+
this.#foldAgentReplayRows(drained.rows, sessionId);
|
|
66855
|
+
for (const row of drained.rows) {
|
|
66856
|
+
if (row.type === "assistant/message") {
|
|
66857
|
+
stats.rawAssistants++;
|
|
66858
|
+
const usage = journalUsage(row.payload);
|
|
66859
|
+
if (usage !== undefined) {
|
|
66860
|
+
const prompt = usage.prompt ?? 0;
|
|
66861
|
+
const cacheRead = usage.cacheRead ?? 0;
|
|
66862
|
+
const cacheWrite = usage.cacheWrite ?? 0;
|
|
66863
|
+
if (prompt > 0)
|
|
66864
|
+
stats.cachePrompt += prompt;
|
|
66865
|
+
if (cacheRead > 0)
|
|
66866
|
+
stats.cacheRead += cacheRead;
|
|
66867
|
+
if (cacheWrite > 0)
|
|
66868
|
+
stats.cacheWrite += cacheWrite;
|
|
66869
|
+
const billed = prompt + cacheRead + cacheWrite;
|
|
66870
|
+
if (billed > 0)
|
|
66871
|
+
stats.lastCacheHitRate = cacheRead / billed * 100;
|
|
66872
|
+
stats.contextTokens = usage.total;
|
|
66873
|
+
}
|
|
66874
|
+
} else if (row.type === "request/context") {
|
|
66875
|
+
const data = asRecord5(row.payload);
|
|
66876
|
+
const window = data.contextWindow;
|
|
66877
|
+
if (typeof window === "number" && Number.isFinite(window) && window > 0) {
|
|
66878
|
+
const provider = typeof data.provider === "string" ? data.provider : "";
|
|
66879
|
+
const model = typeof data.model === "string" ? data.model : "";
|
|
66880
|
+
stats.contextWindow = window;
|
|
66881
|
+
stats.contextWindowKey = provider && model ? `${provider}/${model}` : undefined;
|
|
66882
|
+
}
|
|
66883
|
+
}
|
|
66884
|
+
}
|
|
66885
|
+
for (const row of bridgeReplayRowsToSeamTranscript(drained.rows)) {
|
|
66886
|
+
if (row.kind === "user")
|
|
66887
|
+
stats.userRows++;
|
|
66888
|
+
else if (row.kind === "assistant")
|
|
66889
|
+
stats.assistantRows++;
|
|
66890
|
+
}
|
|
66891
|
+
for (const row of drained.rows) {
|
|
66892
|
+
if (row.seq > stats.lastSeq)
|
|
66893
|
+
stats.lastSeq = row.seq;
|
|
66894
|
+
}
|
|
66895
|
+
counts = {
|
|
66896
|
+
msgCount: stats.rawAssistants,
|
|
66897
|
+
messageCount: stats.userRows + stats.assistantRows,
|
|
66898
|
+
turnCount: stats.userRows
|
|
66899
|
+
};
|
|
66900
|
+
} catch (err) {
|
|
66901
|
+
this.#ctx.logger.warn("[bridge-seam] sessionInfo journal.replay failed: %s", err);
|
|
66902
|
+
}
|
|
66903
|
+
const selection = await this.currentModelSelection().catch(() => {
|
|
66904
|
+
return;
|
|
66905
|
+
});
|
|
66906
|
+
const stats = this.#liveStats();
|
|
66907
|
+
const selectionKey = selection ? `${selection.providerID}/${selection.modelID}` : undefined;
|
|
66908
|
+
if (stats !== undefined)
|
|
66909
|
+
stats.selectionKey = selectionKey;
|
|
66910
|
+
const u = this.#usage;
|
|
66911
|
+
const last = this.#lastTurnDecode;
|
|
66912
|
+
return {
|
|
66913
|
+
sessionId,
|
|
66914
|
+
model: selectionKey ?? null,
|
|
66915
|
+
...counts !== undefined ? counts : {},
|
|
66916
|
+
tokensIn: u.prompt,
|
|
66917
|
+
tokensOut: u.completion,
|
|
66918
|
+
cacheRead: u.cacheRead,
|
|
66919
|
+
cacheWrite: u.cacheWrite,
|
|
66920
|
+
lastTurnTps: last && last.ms > 0 ? tokensPerSecond(last.tokens, last.ms) : null,
|
|
66921
|
+
sessionAvgTps: this.#decodeTotals.ms > 0 ? tokensPerSecond(this.#decodeTotals.tokens, this.#decodeTotals.ms) : null,
|
|
66922
|
+
contextTokens: stats?.contextTokens ?? null,
|
|
66923
|
+
contextWindow: this.#liveContextWindow()
|
|
66924
|
+
};
|
|
66925
|
+
}
|
|
66926
|
+
onSessionEvent(listener) {
|
|
66927
|
+
this.#degradeOnce("onSessionEvent", "only turn.* lifecycle/error events project; permission.asked / bridge.shutdown absent");
|
|
66928
|
+
this.#listeners.push(listener);
|
|
66929
|
+
return () => {
|
|
66930
|
+
const i = this.#listeners.indexOf(listener);
|
|
66931
|
+
if (i >= 0)
|
|
66932
|
+
this.#listeners.splice(i, 1);
|
|
66933
|
+
};
|
|
66934
|
+
}
|
|
66935
|
+
subagentViews() {
|
|
66936
|
+
return [...this.#subagentViews.values()].map((view) => ({ ...view }));
|
|
66937
|
+
}
|
|
66938
|
+
onSubagentViews(listener) {
|
|
66939
|
+
this.#subagentListeners.add(listener);
|
|
66940
|
+
listener(this.subagentViews());
|
|
66941
|
+
return () => {
|
|
66942
|
+
this.#subagentListeners.delete(listener);
|
|
66943
|
+
};
|
|
66944
|
+
}
|
|
66945
|
+
#emitSubagentViews() {
|
|
66946
|
+
if (this.#subagentListeners.size === 0)
|
|
66947
|
+
return;
|
|
66948
|
+
const snapshot = this.subagentViews();
|
|
66949
|
+
for (const listener of [...this.#subagentListeners]) {
|
|
66950
|
+
try {
|
|
66951
|
+
listener(snapshot);
|
|
66952
|
+
} catch {}
|
|
66953
|
+
}
|
|
66954
|
+
}
|
|
66955
|
+
#foldAgentFrame(frame) {
|
|
66956
|
+
const payload = asRecord5(frame.payload);
|
|
66957
|
+
const frameSession = typeof payload.sessionId === "string" ? payload.sessionId : "";
|
|
66958
|
+
if (this.#subagentSessionId !== undefined && frameSession !== "" && frameSession !== this.#subagentSessionId)
|
|
66959
|
+
return;
|
|
66960
|
+
const now = Date.now();
|
|
66961
|
+
let changed = false;
|
|
66962
|
+
if (frame.type === "agent.spawn") {
|
|
66963
|
+
changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, BRIDGE_AGENT_START, payload, now, true);
|
|
66964
|
+
} else if (frame.type === "agent.settle") {
|
|
66965
|
+
changed = bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, BRIDGE_AGENT_END, payload, now, true);
|
|
66966
|
+
}
|
|
66967
|
+
if (changed)
|
|
66968
|
+
this.#emitSubagentViews();
|
|
66969
|
+
}
|
|
66970
|
+
#foldAgentReplayRows(rows, sessionId) {
|
|
66971
|
+
let rosterReset = false;
|
|
66972
|
+
if (sessionId !== this.#subagentSessionId) {
|
|
66973
|
+
this.#subagentViews.clear();
|
|
66974
|
+
this.#subagentRunSeq.clear();
|
|
66975
|
+
this.#subagentLiveStarts.clear();
|
|
66976
|
+
this.#subagentSessionId = sessionId;
|
|
66977
|
+
rosterReset = true;
|
|
66978
|
+
}
|
|
66979
|
+
let changed = false;
|
|
66980
|
+
const now = Date.now();
|
|
66981
|
+
for (const row of rows) {
|
|
66982
|
+
if (bridgeFoldAgentRecord(this.#subagentViews, this.#subagentRunSeq, this.#subagentLiveStarts, row.type, asRecord5(row.payload), now, false))
|
|
66983
|
+
changed = true;
|
|
66984
|
+
}
|
|
66985
|
+
if (rosterReset || changed)
|
|
66986
|
+
this.#emitSubagentViews();
|
|
66987
|
+
}
|
|
66988
|
+
configLoad() {
|
|
66989
|
+
this.#degradeOnce("configLoad", "no config frame on the in-process bridge; returning {} (no stored override)");
|
|
66990
|
+
return {};
|
|
66991
|
+
}
|
|
66992
|
+
configRaw() {
|
|
66993
|
+
this.#degradeOnce("configRaw", "no config frame on the in-process bridge; returning {} (no profile layer)");
|
|
66994
|
+
return {};
|
|
66995
|
+
}
|
|
66996
|
+
workspaceConfig() {
|
|
66997
|
+
this.#degradeOnce("workspaceConfig", "no config frame on the in-process bridge; returning {} (no workspace overlay)");
|
|
66998
|
+
return {};
|
|
66999
|
+
}
|
|
67000
|
+
async permissionCatalog() {
|
|
67001
|
+
const answererReady = this.#askProvider !== undefined || this.#inFlightGeneration !== 0 && this.#activeCallbacks !== undefined || this.#askFrameSeen;
|
|
67002
|
+
const providerConfirmed = this.#connection === "connected" && answererReady && !this.#degradedOnce.has("ask.no-provider");
|
|
67003
|
+
if (providerConfirmed)
|
|
67004
|
+
return { options: [], defaultOptions: [], defaultPreset: "" };
|
|
67005
|
+
if (!this.#permissionNoticeShown) {
|
|
67006
|
+
this.#permissionNoticeShown = true;
|
|
67007
|
+
const reason = this.#degradedOnce.has("ask.no-provider") ? "ask-no-provider" : this.#connection === "disconnected" ? "bridge-offline" : "no-provider";
|
|
67008
|
+
this.#onPermissionUnavailable?.(reason);
|
|
67009
|
+
}
|
|
67010
|
+
return;
|
|
67011
|
+
}
|
|
67012
|
+
async listSessions(limit) {
|
|
67013
|
+
const value = await this.#transport.request("session.list");
|
|
67014
|
+
return projectBridgeSessionList(asRecord5(value).items, limit);
|
|
67015
|
+
}
|
|
67016
|
+
async storedTranscript(id, skip = 0) {
|
|
67017
|
+
const value = await this.#transport.request("journal.replay", { sessionId: id });
|
|
67018
|
+
const rows = Array.isArray(asRecord5(value).rows) ? asRecord5(value).rows : [];
|
|
67019
|
+
this.#foldAgentReplayRows(rows, id);
|
|
67020
|
+
return bridgeReplayRowsToSeamTranscript(rows, skip);
|
|
67021
|
+
}
|
|
67022
|
+
async currentModelSelection() {
|
|
67023
|
+
const selection = await this.#transport.request("model.currentSelection");
|
|
67024
|
+
if (selection === undefined || selection === null)
|
|
67025
|
+
return;
|
|
67026
|
+
const s = asRecord5(selection);
|
|
67027
|
+
const providerID = typeof s.provider === "string" ? s.provider : "";
|
|
67028
|
+
const modelID = typeof s.model === "string" ? s.model : "";
|
|
67029
|
+
if (!providerID || !modelID)
|
|
67030
|
+
return;
|
|
67031
|
+
return { providerID, modelID };
|
|
67032
|
+
}
|
|
67033
|
+
#settleSuspendedTurn() {
|
|
67034
|
+
const done = this.#turnDone;
|
|
67035
|
+
const endedTurnId = this.#inFlightTurnId;
|
|
67036
|
+
this.#turnDone = undefined;
|
|
67037
|
+
this.#activeCallbacks = undefined;
|
|
67038
|
+
this.#inFlightTurnId = undefined;
|
|
67039
|
+
this.#inFlightGeneration = 0;
|
|
67040
|
+
this.#turn = "idle";
|
|
67041
|
+
if (endedTurnId !== undefined)
|
|
67042
|
+
this.#cancelAsksForTurn(endedTurnId);
|
|
67043
|
+
done?.();
|
|
67044
|
+
}
|
|
67045
|
+
async turn(userText, cb) {
|
|
67046
|
+
if (this.#inFlightGeneration !== 0) {
|
|
67047
|
+
throw new BridgeProtocolError("TURN_REENTRANT", "turn() called while another turn is in flight; await the first turn()", { activeTurnId: this.#inFlightTurnId });
|
|
67048
|
+
}
|
|
67049
|
+
const gen = ++this.#turnGeneration;
|
|
67050
|
+
this.#inFlightGeneration = gen;
|
|
67051
|
+
this.#deadInFlight = undefined;
|
|
67052
|
+
this.#inFlightPartial = "";
|
|
67053
|
+
let sendFailed;
|
|
67054
|
+
try {
|
|
67055
|
+
if (this.#pendingOpen === undefined && !this.#sessionAttached) {
|
|
67056
|
+
this.#pendingOpen = { mode: "new" };
|
|
67057
|
+
}
|
|
67058
|
+
if (this.#pendingOpen !== undefined) {
|
|
67059
|
+
const pending = this.#pendingOpen;
|
|
67060
|
+
this.#pendingOpen = undefined;
|
|
67061
|
+
const params = pending.mode === "resume" ? { mode: "resume", id: pending.id, ...this.#sessionAttached ? { replace: true } : {} } : { mode: "new", ...this.#sessionAttached ? { replace: true } : {} };
|
|
67062
|
+
try {
|
|
67063
|
+
const opened = asRecord5(await this.#transport.request("session.open", params));
|
|
67064
|
+
if (typeof opened.sessionId === "string")
|
|
67065
|
+
this.#currentSessionId = opened.sessionId;
|
|
67066
|
+
if (this.#lastAppliedSessionId !== this.#currentSessionId) {
|
|
67067
|
+
this.#lastAppliedSessionId = this.#currentSessionId;
|
|
67068
|
+
this.#lastAppliedSeq = undefined;
|
|
67069
|
+
this.#appliedReplayKeys.clear();
|
|
67070
|
+
}
|
|
67071
|
+
this.#sessionAttached = true;
|
|
67072
|
+
} catch (err) {
|
|
67073
|
+
throw err;
|
|
67074
|
+
}
|
|
67075
|
+
}
|
|
67076
|
+
this.#activeCallbacks = cb;
|
|
67077
|
+
const done = new Promise((resolve) => {
|
|
67078
|
+
this.#turnDone = resolve;
|
|
67079
|
+
});
|
|
67080
|
+
const sent = asRecord5(await this.#transport.request("session.send", { text: userText }));
|
|
67081
|
+
if (typeof sent.turnId === "string") {
|
|
67082
|
+
this.#inFlightTurnId = sent.turnId;
|
|
67083
|
+
this.#emitEvent({
|
|
67084
|
+
type: "bridge.input.acked",
|
|
67085
|
+
details: { sessionID: this.#currentSessionId ?? "", turnId: sent.turnId, text: userText }
|
|
67086
|
+
});
|
|
67087
|
+
}
|
|
67088
|
+
await done;
|
|
67089
|
+
} catch (err) {
|
|
67090
|
+
sendFailed = err;
|
|
67091
|
+
} finally {
|
|
67092
|
+
if (this.#inFlightGeneration === gen) {
|
|
67093
|
+
const endedTurnId = this.#inFlightTurnId;
|
|
67094
|
+
this.#activeCallbacks = undefined;
|
|
67095
|
+
this.#turnDone = undefined;
|
|
67096
|
+
this.#inFlightTurnId = undefined;
|
|
67097
|
+
this.#inFlightGeneration = 0;
|
|
67098
|
+
this.#turn = "idle";
|
|
67099
|
+
if (endedTurnId !== undefined)
|
|
67100
|
+
this.#cancelAsksForTurn(endedTurnId);
|
|
67101
|
+
}
|
|
67102
|
+
}
|
|
67103
|
+
if (sendFailed !== undefined)
|
|
67104
|
+
throw sendFailed;
|
|
67105
|
+
}
|
|
67106
|
+
async dispose() {
|
|
67107
|
+
if (this.#disposed)
|
|
67108
|
+
return;
|
|
67109
|
+
this.#disposed = true;
|
|
67110
|
+
this.#unsubEvent();
|
|
67111
|
+
this.#listeners.length = 0;
|
|
67112
|
+
this.#subagentListeners.clear();
|
|
67113
|
+
this.#subagentViews.clear();
|
|
67114
|
+
this.#subagentRunSeq.clear();
|
|
67115
|
+
this.#subagentLiveStarts.clear();
|
|
67116
|
+
this.#activeCallbacks = undefined;
|
|
67117
|
+
this.#cancelAllAsks();
|
|
67118
|
+
this.#bufferedPendingSnapshot = undefined;
|
|
67119
|
+
this.#replayDrainPending = false;
|
|
67120
|
+
this.#invalidatedAsks.clear();
|
|
67121
|
+
this.#turnDone?.();
|
|
67122
|
+
this.#turnDone = undefined;
|
|
67123
|
+
this.#inFlightTurnId = undefined;
|
|
67124
|
+
this.#inFlightGeneration = 0;
|
|
67125
|
+
this.#inFlightPartial = "";
|
|
67126
|
+
this.#deadInFlight = undefined;
|
|
67127
|
+
this.#turn = "idle";
|
|
67128
|
+
try {
|
|
67129
|
+
if (this.#sessionAttached)
|
|
67130
|
+
await this.#transport.request("session.close");
|
|
67131
|
+
} catch (err) {
|
|
67132
|
+
this.#ctx.logger.warn("[bridge-seam] session.close failed during dispose: %s", err);
|
|
67133
|
+
}
|
|
67134
|
+
this.#sessionAttached = false;
|
|
67135
|
+
this.#currentSessionId = undefined;
|
|
67136
|
+
}
|
|
67137
|
+
async searchSessions(_query) {
|
|
67138
|
+
return unsupported("searchSessions");
|
|
67139
|
+
}
|
|
67140
|
+
async renameSession(_title) {
|
|
67141
|
+
return unsupported("renameSession");
|
|
67142
|
+
}
|
|
67143
|
+
steer(_text) {
|
|
67144
|
+
this.#degrade("steer", "no session.steer frame; steer is a no-op");
|
|
67145
|
+
}
|
|
67146
|
+
registerAskProvider(onAsk) {
|
|
67147
|
+
this.#askProvider = onAsk;
|
|
67148
|
+
}
|
|
67149
|
+
pendingAsks() {
|
|
67150
|
+
return [...this.#pendingAsks.values()].map((entry) => ({ ...entry.request }));
|
|
67151
|
+
}
|
|
67152
|
+
invalidatedAsks() {
|
|
67153
|
+
return new Map(this.#invalidatedAsks);
|
|
67154
|
+
}
|
|
67155
|
+
async listProviders() {
|
|
67156
|
+
return unsupported("listProviders");
|
|
67157
|
+
}
|
|
67158
|
+
async modelCatalog(_force) {
|
|
67159
|
+
return unsupported("modelCatalog");
|
|
67160
|
+
}
|
|
67161
|
+
selectModel(_providerID, _modelID) {
|
|
67162
|
+
return Promise.reject(new BridgeProtocolError("UNSUPPORTED", "selectModel is not backed by the in-process bridge", { capability: "selectModel" }));
|
|
67163
|
+
}
|
|
67164
|
+
#approvalParams(request, verdict) {
|
|
67165
|
+
const base = { eventId: request.eventId, kind: "approval" };
|
|
67166
|
+
switch (verdict) {
|
|
67167
|
+
case "allowed-once":
|
|
67168
|
+
return { ...base, verdict: "allowed-once" };
|
|
67169
|
+
case "rejected":
|
|
67170
|
+
return { ...base, verdict: "rejected" };
|
|
67171
|
+
case "always":
|
|
67172
|
+
case "session":
|
|
67173
|
+
if (request.escalation !== true) {
|
|
67174
|
+
this.#degradeOnce("ask.invalid-escalation", `behavior:${verdict} needs a granted escalation; refusing to send ask.response (ASK_INVALID_RESPONSE)`);
|
|
67175
|
+
return;
|
|
67176
|
+
}
|
|
67177
|
+
return { ...base, verdict: "allowed-once", behavior: verdict, escalation: true };
|
|
67178
|
+
default:
|
|
67179
|
+
return { ...base, verdict: "rejected" };
|
|
67180
|
+
}
|
|
67181
|
+
}
|
|
67182
|
+
#applyPendingSnapshot(asks) {
|
|
67183
|
+
this.#cancelAllAsks();
|
|
67184
|
+
for (const request of asks) {
|
|
67185
|
+
this.#invalidatedAsks.delete(request.eventId);
|
|
67186
|
+
this.#enqueueAsk(request);
|
|
67187
|
+
}
|
|
67188
|
+
}
|
|
67189
|
+
#isDeadResponseError(err) {
|
|
67190
|
+
const code = err instanceof BridgeProtocolError ? err.code : err !== null && typeof err === "object" && typeof err.code === "string" ? err.code : undefined;
|
|
67191
|
+
if (code === "ASK_NOT_FOUND" || code === "ASK_UNKNOWN_REQUEST" || code === "ASK_TURN_ENDED" || code === "BRIDGE_DEAD" || code === "BRIDGE_CLOSED") {
|
|
67192
|
+
return err instanceof Error && err.message !== "" ? `${code}: ${err.message}` : code;
|
|
67193
|
+
}
|
|
67194
|
+
return;
|
|
67195
|
+
}
|
|
67196
|
+
#enqueueAsk(request) {
|
|
67197
|
+
if (this.#disposed || this.#pendingAsks.has(request.eventId))
|
|
67198
|
+
return;
|
|
67199
|
+
this.#invalidatedAsks.delete(request.eventId);
|
|
67200
|
+
let finish;
|
|
67201
|
+
const done = new Promise((resolve) => {
|
|
67202
|
+
finish = resolve;
|
|
67203
|
+
});
|
|
67204
|
+
const entry = {
|
|
67205
|
+
request,
|
|
67206
|
+
turnId: askTurnId(request.eventId),
|
|
67207
|
+
cancelled: false,
|
|
67208
|
+
done,
|
|
67209
|
+
finish
|
|
67210
|
+
};
|
|
67211
|
+
this.#pendingAsks.set(request.eventId, entry);
|
|
67212
|
+
this.#answerAsk(entry);
|
|
67213
|
+
}
|
|
67214
|
+
async#answerAsk(entry) {
|
|
67215
|
+
const request = entry.request;
|
|
67216
|
+
let params;
|
|
67217
|
+
try {
|
|
67218
|
+
if (request.kind === "approval") {
|
|
67219
|
+
const cb = this.#inFlightGeneration !== 0 ? this.#activeCallbacks : undefined;
|
|
67220
|
+
if (cb !== undefined) {
|
|
67221
|
+
const verdict = await cb.onApprove(request.toolName ?? "tool", approvalArgs(request));
|
|
67222
|
+
params = this.#approvalParams(request, verdict);
|
|
67223
|
+
} else if (this.#askProvider !== undefined) {
|
|
67224
|
+
const picks = await this.#askProvider([approvalQuestion(request)]);
|
|
67225
|
+
params = this.#approvalParams(request, approvalVerdictFromPicks(request, picks));
|
|
67226
|
+
} else {
|
|
67227
|
+
this.#degradeOnce("ask.no-provider", "no onApprove/ask provider; answering approval unavailable (ASK_CHANNEL_UNAVAILABLE)");
|
|
67228
|
+
this.permissionCatalog();
|
|
67229
|
+
params = unavailableResponse(request);
|
|
67230
|
+
}
|
|
67231
|
+
} else if (this.#askProvider !== undefined) {
|
|
67232
|
+
const picks = await this.#askProvider(request.questions ?? []);
|
|
67233
|
+
params = { eventId: request.eventId, kind: "questions", answers: answersFor(request, picks) };
|
|
67234
|
+
} else {
|
|
67235
|
+
this.#degradeOnce("ask.no-provider", "no ask provider; answering questions unavailable (ASK_CHANNEL_UNAVAILABLE)");
|
|
67236
|
+
this.permissionCatalog();
|
|
67237
|
+
params = unavailableResponse(request);
|
|
67238
|
+
}
|
|
67239
|
+
} catch (err) {
|
|
67240
|
+
this.#degradeOnce("ask.provider-error", "ask provider threw; answering unavailable (ASK_CHANNEL_UNAVAILABLE)");
|
|
67241
|
+
this.#ctx.logger.warn("[bridge-seam] ask provider failed: %s", err);
|
|
67242
|
+
params = unavailableResponse(request);
|
|
67243
|
+
}
|
|
67244
|
+
if (entry.cancelled || this.#pendingAsks.get(request.eventId) !== entry) {
|
|
67245
|
+
entry.finish();
|
|
67246
|
+
return;
|
|
67247
|
+
}
|
|
67248
|
+
if (params !== undefined) {
|
|
67249
|
+
try {
|
|
67250
|
+
await this.#transport.request("ask.response", params);
|
|
67251
|
+
} catch (err) {
|
|
67252
|
+
this.#ctx.logger.warn("[bridge-seam] ask.response failed for %s: %s", request.eventId, err);
|
|
67253
|
+
const reason = this.#isDeadResponseError(err);
|
|
67254
|
+
if (reason !== undefined) {
|
|
67255
|
+
this.#invalidatedAsks.set(request.eventId, reason);
|
|
67256
|
+
this.#emitEvent({
|
|
67257
|
+
type: "bridge.ask.invalidated",
|
|
67258
|
+
details: { eventId: request.eventId, sessionId: request.sessionId, reason }
|
|
67259
|
+
});
|
|
67260
|
+
}
|
|
67261
|
+
}
|
|
67262
|
+
}
|
|
67263
|
+
entry.finish();
|
|
67264
|
+
if (!this.#invalidatedAsks.has(request.eventId) && this.#pendingAsks.get(request.eventId) === entry) {
|
|
67265
|
+
this.#pendingAsks.delete(request.eventId);
|
|
67266
|
+
}
|
|
67267
|
+
}
|
|
67268
|
+
#settlePendingAsk(eventId) {
|
|
67269
|
+
const entry = this.#pendingAsks.get(eventId);
|
|
67270
|
+
if (entry === undefined)
|
|
67271
|
+
return;
|
|
67272
|
+
entry.cancelled = true;
|
|
67273
|
+
this.#pendingAsks.delete(eventId);
|
|
67274
|
+
entry.finish();
|
|
67275
|
+
}
|
|
67276
|
+
#cancelAsksForTurn(turnId) {
|
|
67277
|
+
if (turnId === "")
|
|
67278
|
+
return;
|
|
67279
|
+
for (const [eventId, entry] of [...this.#pendingAsks]) {
|
|
67280
|
+
if (entry.turnId === turnId)
|
|
67281
|
+
this.#settlePendingAsk(eventId);
|
|
67282
|
+
}
|
|
67283
|
+
}
|
|
67284
|
+
#cancelAllAsks() {
|
|
67285
|
+
for (const eventId of [...this.#pendingAsks.keys()])
|
|
67286
|
+
this.#settlePendingAsk(eventId);
|
|
67287
|
+
}
|
|
67288
|
+
#onAskEvent(frame) {
|
|
67289
|
+
const payload = asRecord5(frame.payload);
|
|
67290
|
+
if (frame.type === "ask.request" || frame.type === "ask.pending")
|
|
67291
|
+
this.#askFrameSeen = true;
|
|
67292
|
+
switch (frame.type) {
|
|
67293
|
+
case "ask.request": {
|
|
67294
|
+
const request = parseAskRequest(frame.payload);
|
|
67295
|
+
if (request !== undefined)
|
|
67296
|
+
this.#enqueueAsk(request);
|
|
67297
|
+
return true;
|
|
67298
|
+
}
|
|
67299
|
+
case "ask.cancel": {
|
|
67300
|
+
const eventId = optionalStringField(payload, "eventId");
|
|
67301
|
+
if (eventId !== undefined)
|
|
67302
|
+
this.#settlePendingAsk(eventId);
|
|
67303
|
+
return true;
|
|
67304
|
+
}
|
|
67305
|
+
case "ask.settled": {
|
|
67306
|
+
const eventId = optionalStringField(payload, "eventId");
|
|
67307
|
+
if (eventId !== undefined)
|
|
67308
|
+
this.#settlePendingAsk(eventId);
|
|
67309
|
+
return true;
|
|
67310
|
+
}
|
|
67311
|
+
case "ask.pending": {
|
|
67312
|
+
const asks = [];
|
|
67313
|
+
const rawAsks = Array.isArray(payload.asks) ? payload.asks : [];
|
|
67314
|
+
for (const raw of rawAsks) {
|
|
67315
|
+
const request = parseAskRequest(raw);
|
|
67316
|
+
if (request !== undefined)
|
|
67317
|
+
asks.push(request);
|
|
67318
|
+
}
|
|
67319
|
+
if (this.#replayDrainPending) {
|
|
67320
|
+
this.#bufferedPendingSnapshot = asks;
|
|
67321
|
+
return true;
|
|
67322
|
+
}
|
|
67323
|
+
this.#applyPendingSnapshot(asks);
|
|
67324
|
+
return true;
|
|
67325
|
+
}
|
|
67326
|
+
default:
|
|
67327
|
+
return false;
|
|
67328
|
+
}
|
|
67329
|
+
}
|
|
67330
|
+
#emitEvent(event) {
|
|
67331
|
+
for (const listener of [...this.#listeners]) {
|
|
67332
|
+
try {
|
|
67333
|
+
listener(event);
|
|
67334
|
+
} catch {}
|
|
67335
|
+
}
|
|
67336
|
+
}
|
|
67337
|
+
#degrade(member, reason) {
|
|
67338
|
+
this.#ctx.logger.warn("[bridge-seam] %s degraded: %s", member, reason);
|
|
67339
|
+
}
|
|
67340
|
+
#degradeOnce(member, reason) {
|
|
67341
|
+
if (this.#degradedOnce.has(member))
|
|
67342
|
+
return;
|
|
67343
|
+
this.#degradedOnce.add(member);
|
|
67344
|
+
this.#degrade(member, reason);
|
|
67345
|
+
}
|
|
67346
|
+
#onBridgeEvent(frame) {
|
|
67347
|
+
if (this.#onAskEvent(frame))
|
|
67348
|
+
return;
|
|
67349
|
+
if (frame.type === "agent.spawn" || frame.type === "agent.settle") {
|
|
67350
|
+
this.#foldAgentFrame(frame);
|
|
67351
|
+
return;
|
|
67352
|
+
}
|
|
67353
|
+
if (frame.type === "bridge.dead") {
|
|
67354
|
+
const cause = asDeadCause(frame.payload);
|
|
67355
|
+
if (this.#inFlightGeneration !== 0 && this.#inFlightTurnId !== undefined && this.#inFlightTurnId !== "") {
|
|
67356
|
+
this.#deadInFlight = { turnId: this.#inFlightTurnId, partial: this.#inFlightPartial };
|
|
67357
|
+
}
|
|
67358
|
+
this.#bridgeLink = "dead";
|
|
67359
|
+
this.#connection = "disconnected";
|
|
67360
|
+
this.#turn = "idle";
|
|
67361
|
+
this.#onDead?.(cause);
|
|
67362
|
+
for (const listener of [...this.#listeners]) {
|
|
67363
|
+
try {
|
|
67364
|
+
listener({ type: "bridge.dead", details: cause });
|
|
67365
|
+
} catch {}
|
|
67366
|
+
}
|
|
67367
|
+
return;
|
|
67368
|
+
}
|
|
67369
|
+
const payload = asRecord5(frame.payload);
|
|
67370
|
+
if (frame.type === "turn.start") {
|
|
67371
|
+
this.#turn = "starting";
|
|
67372
|
+
this.#decodeWindowStart = undefined;
|
|
67373
|
+
}
|
|
67374
|
+
if (frame.type === "turn.token" || frame.type === "turn.tool")
|
|
67375
|
+
this.#turn = "running";
|
|
67376
|
+
if (frame.type === "turn.end" || frame.type === "turn.error") {
|
|
67377
|
+
this.#turn = "idle";
|
|
67378
|
+
const endedTurnId = typeof payload.turnId === "string" ? payload.turnId : this.#inFlightTurnId;
|
|
67379
|
+
this.#inFlightTurnId = undefined;
|
|
67380
|
+
if (endedTurnId !== undefined)
|
|
67381
|
+
this.#cancelAsksForTurn(endedTurnId);
|
|
67382
|
+
this.#turnDone?.();
|
|
67383
|
+
}
|
|
67384
|
+
if (frame.type === "turn.end") {
|
|
67385
|
+
const usage = parseUsage(payload.usage);
|
|
67386
|
+
if (Object.keys(usage).length > 0) {
|
|
67387
|
+
this.#usage.turns += 1;
|
|
67388
|
+
for (const key of ["prompt", "completion", "cacheRead", "cacheWrite"]) {
|
|
67389
|
+
this.#usage[key] += usage[key] ?? 0;
|
|
67390
|
+
}
|
|
67391
|
+
}
|
|
67392
|
+
const start = this.#decodeWindowStart;
|
|
67393
|
+
const tokens = usage.completion ?? 0;
|
|
67394
|
+
if (start !== undefined && tokens > 0) {
|
|
67395
|
+
const ms = Date.now() - start;
|
|
67396
|
+
if (ms > 0) {
|
|
67397
|
+
this.#lastTurnDecode = { tokens, ms };
|
|
67398
|
+
this.#decodeTotals.tokens += tokens;
|
|
67399
|
+
this.#decodeTotals.ms += ms;
|
|
67400
|
+
}
|
|
67401
|
+
}
|
|
67402
|
+
this.#decodeWindowStart = undefined;
|
|
67403
|
+
}
|
|
67404
|
+
if (frame.type === "turn.token" && payload.kind !== "reasoning" && typeof payload.text === "string" && payload.text) {
|
|
67405
|
+
if (this.#decodeWindowStart === undefined)
|
|
67406
|
+
this.#decodeWindowStart = Date.now();
|
|
67407
|
+
this.#inFlightPartial = (this.#inFlightPartial + payload.text).slice(-4096);
|
|
67408
|
+
}
|
|
67409
|
+
const cb = this.#activeCallbacks;
|
|
67410
|
+
if (cb !== undefined) {
|
|
67411
|
+
if (frame.type === "turn.token") {
|
|
67412
|
+
const text = typeof payload.text === "string" ? payload.text : "";
|
|
67413
|
+
if (payload.kind === "reasoning") {
|
|
67414
|
+
if (text)
|
|
67415
|
+
cb.onThinkingDelta(text);
|
|
67416
|
+
} else if (text) {
|
|
67417
|
+
cb.onContentDelta(text);
|
|
67418
|
+
}
|
|
67419
|
+
} else if (frame.type === "turn.tool") {
|
|
67420
|
+
const name = typeof payload.name === "string" ? payload.name : "tool";
|
|
67421
|
+
const callId = typeof payload.callId === "string" ? payload.callId : undefined;
|
|
67422
|
+
if (payload.input !== undefined) {
|
|
67423
|
+
cb.onToolStart?.({ ...callId !== undefined ? { callId } : {}, name, args: JSON.stringify(payload.input) });
|
|
67424
|
+
} else if (payload.output !== undefined) {
|
|
67425
|
+
cb.onToolRun?.({
|
|
67426
|
+
...callId !== undefined ? { callId } : {},
|
|
67427
|
+
name,
|
|
67428
|
+
argsPretty: "",
|
|
67429
|
+
output: typeof payload.output === "string" ? payload.output : "",
|
|
67430
|
+
ok: payload.isError !== true
|
|
67431
|
+
});
|
|
67432
|
+
}
|
|
67433
|
+
} else if (frame.type === "turn.error") {
|
|
67434
|
+
cb.onError(typeof payload.message === "string" ? payload.message : "turn failed");
|
|
67435
|
+
}
|
|
67436
|
+
}
|
|
67437
|
+
const events = projectBridgeEvent(frame, this.#currentSessionId ?? "");
|
|
67438
|
+
for (const event of events) {
|
|
67439
|
+
for (const listener of this.#listeners) {
|
|
67440
|
+
try {
|
|
67441
|
+
listener(event);
|
|
67442
|
+
} catch {}
|
|
67443
|
+
}
|
|
67444
|
+
}
|
|
67445
|
+
}
|
|
67446
|
+
}
|
|
67447
|
+
var BridgeProtocolError, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
|
|
67448
|
+
var init_bridge_session_seam = __esm(() => {
|
|
67449
|
+
init_remote_session_ops();
|
|
67450
|
+
init_session_seam_adapter();
|
|
67451
|
+
init_loop();
|
|
67452
|
+
BridgeProtocolError = class BridgeProtocolError extends Error {
|
|
67453
|
+
code;
|
|
67454
|
+
detail;
|
|
67455
|
+
constructor(code, message, detail) {
|
|
67456
|
+
super(message);
|
|
67457
|
+
this.name = "BridgeProtocolError";
|
|
67458
|
+
this.code = code;
|
|
67459
|
+
if (detail !== undefined)
|
|
67460
|
+
this.detail = detail;
|
|
67461
|
+
}
|
|
67462
|
+
};
|
|
67463
|
+
});
|
|
67464
|
+
|
|
67465
|
+
// scripts/lib/bridge-failfast-text.mjs
|
|
67466
|
+
function formatBridgeFailFastMessage(diagnosis, repairCommand = BRIDGE_REPAIR_COMMAND) {
|
|
67467
|
+
return [diagnosis, `Fix: ${repairCommand}`, BRIDGE_APPEND_PRESET_NOTICE].join(`
|
|
67468
|
+
`);
|
|
67469
|
+
}
|
|
67470
|
+
var BRIDGE_REPAIR_COMMAND = "dsh-opentui --repair-bridge", BRIDGE_APPEND_PRESET_NOTICE = "inproc bridge mode injects append-system via the bridge section; presets are standard only.", BRIDGE_REPAIR_HINT;
|
|
67471
|
+
var init_bridge_failfast_text = __esm(() => {
|
|
67472
|
+
BRIDGE_REPAIR_HINT = `Run \`${BRIDGE_REPAIR_COMMAND}\` to rebuild the bridge symlink / manifest (it fixes links, not corrupted artifact contents).`;
|
|
67473
|
+
});
|
|
67474
|
+
|
|
67475
|
+
// scripts/lib/host-compat.mjs
|
|
67476
|
+
function parseVersion(value) {
|
|
67477
|
+
if (typeof value !== "string")
|
|
67478
|
+
return null;
|
|
67479
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?$/.exec(value.trim());
|
|
67480
|
+
if (match === null)
|
|
67481
|
+
return null;
|
|
67482
|
+
const prerelease = match[4] === undefined ? [] : match[4].split(".");
|
|
67483
|
+
if (prerelease.some((id) => /^\d+$/.test(id) && id.length > 1 && id.startsWith("0")))
|
|
67484
|
+
return null;
|
|
67485
|
+
return {
|
|
67486
|
+
major: Number(match[1]),
|
|
67487
|
+
minor: Number(match[2]),
|
|
67488
|
+
patch: Number(match[3]),
|
|
67489
|
+
prerelease,
|
|
67490
|
+
build: match[5] ?? ""
|
|
67491
|
+
};
|
|
67492
|
+
}
|
|
67493
|
+
function compareIdentifier(a, b) {
|
|
67494
|
+
const aNumeric = /^\d+$/.test(a);
|
|
67495
|
+
const bNumeric = /^\d+$/.test(b);
|
|
67496
|
+
if (aNumeric && bNumeric)
|
|
67497
|
+
return Math.sign(Number(a) - Number(b));
|
|
67498
|
+
if (aNumeric)
|
|
67499
|
+
return -1;
|
|
67500
|
+
if (bNumeric)
|
|
67501
|
+
return 1;
|
|
67502
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
67503
|
+
}
|
|
67504
|
+
function compareVersions(left, right) {
|
|
67505
|
+
const a = parseVersion(left);
|
|
67506
|
+
const b = parseVersion(right);
|
|
67507
|
+
if (a === null || b === null) {
|
|
67508
|
+
throw new Error(`cannot compare non-semver values ${JSON.stringify(left)} / ${JSON.stringify(right)}`);
|
|
67509
|
+
}
|
|
67510
|
+
for (const field of ["major", "minor", "patch"]) {
|
|
67511
|
+
if (a[field] !== b[field])
|
|
67512
|
+
return a[field] < b[field] ? -1 : 1;
|
|
67513
|
+
}
|
|
67514
|
+
if (a.prerelease.length === 0 && b.prerelease.length > 0)
|
|
67515
|
+
return 1;
|
|
67516
|
+
if (a.prerelease.length > 0 && b.prerelease.length === 0)
|
|
67517
|
+
return -1;
|
|
67518
|
+
for (let i = 0;i < Math.max(a.prerelease.length, b.prerelease.length); i++) {
|
|
67519
|
+
if (i >= a.prerelease.length)
|
|
67520
|
+
return -1;
|
|
67521
|
+
if (i >= b.prerelease.length)
|
|
67522
|
+
return 1;
|
|
67523
|
+
const cmp = compareIdentifier(a.prerelease[i], b.prerelease[i]);
|
|
67524
|
+
if (cmp !== 0)
|
|
67525
|
+
return cmp;
|
|
67526
|
+
}
|
|
67527
|
+
return 0;
|
|
67528
|
+
}
|
|
67529
|
+
function isHostVersionSupported(version) {
|
|
67530
|
+
if (parseVersion(version) === null)
|
|
67531
|
+
return false;
|
|
67532
|
+
return compareVersions(version, SUPPORTED_FLOOR) >= 0 && compareVersions(version, SUPPORTED_CAP) < 0;
|
|
67533
|
+
}
|
|
67534
|
+
var HOST_PEER_RANGE = ">=0.2.2-rc.3 <0.3.0", SUPPORTED_FLOOR = "0.2.2-rc.3", SUPPORTED_CAP = "0.3.0";
|
|
67535
|
+
var init_host_compat = () => {};
|
|
67536
|
+
|
|
67537
|
+
// src/client/seam-bootstrap.ts
|
|
67538
|
+
var exports_seam_bootstrap = {};
|
|
67539
|
+
__export(exports_seam_bootstrap, {
|
|
67540
|
+
BRIDGE_APPEND_PRESET_NOTICE: () => BRIDGE_APPEND_PRESET_NOTICE,
|
|
67541
|
+
BRIDGE_PROTOCOL_VERSION: () => BRIDGE_PROTOCOL_VERSION,
|
|
67542
|
+
BRIDGE_REPAIR_COMMAND: () => BRIDGE_REPAIR_COMMAND,
|
|
67543
|
+
BRIDGE_REPAIR_HINT: () => BRIDGE_REPAIR_HINT,
|
|
67544
|
+
BridgeBootstrapError: () => BridgeBootstrapError,
|
|
67545
|
+
createBridgeSessionSeam: () => createBridgeSessionSeam,
|
|
67546
|
+
createSessionSeam: () => createSessionSeam,
|
|
67547
|
+
formatBridgeBootstrapMessage: () => formatBridgeBootstrapMessage,
|
|
67548
|
+
formatDeadNotice: () => formatDeadNotice,
|
|
67549
|
+
isInprocMode: () => isInprocMode,
|
|
67550
|
+
recoverBridgeSession: () => recoverBridgeSession,
|
|
67551
|
+
selectSeamKind: () => selectSeamKind,
|
|
67552
|
+
toBridgeBootstrapError: () => toBridgeBootstrapError,
|
|
67553
|
+
verifyBridgeFingerprint: () => verifyBridgeFingerprint,
|
|
67554
|
+
verifyRecoveryHandshake: () => verifyRecoveryHandshake
|
|
67555
|
+
});
|
|
67556
|
+
function selectSeamKind(input) {
|
|
67557
|
+
if (input.remote)
|
|
67558
|
+
return "remote";
|
|
67559
|
+
return input.inproc ? "bridge" : "remote";
|
|
67560
|
+
}
|
|
67561
|
+
function isInprocMode(env = process.env) {
|
|
67562
|
+
return env.DSH_OPENTUI_INPROC === "1";
|
|
67563
|
+
}
|
|
67564
|
+
function formatBridgeBootstrapMessage(options) {
|
|
67565
|
+
return formatBridgeFailFastMessage(`dsh-opentui inproc bridge seam failed [${options.code}]: ${options.diagnosis}`, options.repairCommand ?? BRIDGE_REPAIR_COMMAND);
|
|
67566
|
+
}
|
|
67567
|
+
function toBridgeBootstrapError(err, fallbackCode = "BRIDGE_HANDSHAKE_FAILED") {
|
|
67568
|
+
if (err instanceof BridgeBootstrapError)
|
|
67569
|
+
return err;
|
|
67570
|
+
if (err instanceof BridgeProtocolError) {
|
|
67571
|
+
const detail = err.detail === undefined ? "" : ` (detail: ${JSON.stringify(err.detail)})`;
|
|
67572
|
+
return new BridgeBootstrapError({
|
|
67573
|
+
code: err.code || fallbackCode,
|
|
67574
|
+
diagnosis: `bridge handshake rejected: ${err.message}${detail}`
|
|
67575
|
+
});
|
|
67576
|
+
}
|
|
67577
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
67578
|
+
return new BridgeBootstrapError({ code: fallbackCode, diagnosis: `bridge handshake failed: ${message}` });
|
|
67579
|
+
}
|
|
67580
|
+
function asRecord6(value) {
|
|
67581
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
67582
|
+
}
|
|
67583
|
+
function verifyBridgeFingerprint(hello, expectedProtocolVersion = BRIDGE_PROTOCOL_VERSION) {
|
|
67584
|
+
const h = asRecord6(hello);
|
|
67585
|
+
const protocolVersion = h.protocolVersion;
|
|
67586
|
+
if (protocolVersion !== expectedProtocolVersion) {
|
|
67587
|
+
throw new BridgeBootstrapError({
|
|
67588
|
+
code: "VERSION_INCOMPATIBLE",
|
|
67589
|
+
diagnosis: `protocolVersion mismatch: client=${expectedProtocolVersion}, ` + `bridge=${String(protocolVersion)}, host=${String(h.hostVersion ?? "unknown")}`
|
|
67590
|
+
});
|
|
67591
|
+
}
|
|
67592
|
+
const bridgeVersion = h.bridgeVersion;
|
|
67593
|
+
const hostVersion = h.hostVersion;
|
|
67594
|
+
if (typeof bridgeVersion !== "string" || bridgeVersion === "") {
|
|
67595
|
+
throw new BridgeBootstrapError({
|
|
67596
|
+
code: "FINGERPRINT_MISSING",
|
|
67597
|
+
diagnosis: `bridge.hello reply has no bridgeVersion (got ${String(bridgeVersion)})`
|
|
67598
|
+
});
|
|
67599
|
+
}
|
|
67600
|
+
if (typeof hostVersion !== "string" || hostVersion === "") {
|
|
67601
|
+
throw new BridgeBootstrapError({
|
|
67602
|
+
code: "FINGERPRINT_MISSING",
|
|
67603
|
+
diagnosis: `bridge.hello reply has no hostVersion (got ${String(hostVersion)})`
|
|
67604
|
+
});
|
|
67605
|
+
}
|
|
67606
|
+
return { protocolVersion, bridgeVersion, hostVersion };
|
|
67607
|
+
}
|
|
67608
|
+
function verifyRecoveryHandshake(hello, expectedProtocolVersion = BRIDGE_PROTOCOL_VERSION) {
|
|
67609
|
+
const fingerprint = verifyBridgeFingerprint(hello, expectedProtocolVersion);
|
|
67610
|
+
if (!isHostVersionSupported(fingerprint.hostVersion)) {
|
|
67611
|
+
throw new BridgeBootstrapError({
|
|
67612
|
+
code: "HOST_INCOMPATIBLE",
|
|
67613
|
+
diagnosis: `hostVersion ${fingerprint.hostVersion} is outside the supported window ${HOST_PEER_RANGE} ` + `(bridge ${fingerprint.bridgeVersion}, client protocol ${expectedProtocolVersion})`
|
|
67614
|
+
});
|
|
67615
|
+
}
|
|
67616
|
+
return fingerprint;
|
|
67617
|
+
}
|
|
67618
|
+
function formatDeadNotice(cause) {
|
|
67619
|
+
const detail = [];
|
|
67620
|
+
if (cause.code !== null)
|
|
67621
|
+
detail.push(`exit ${cause.code}`);
|
|
67622
|
+
if (cause.signal !== null)
|
|
67623
|
+
detail.push(cause.signal);
|
|
67624
|
+
detail.push(`stage ${cause.stage}`);
|
|
67625
|
+
return `\u26A0 \u8FDE\u63A5\u5DF2\u65AD\u5F00: ${cause.message} (${detail.join(", ")})`;
|
|
67626
|
+
}
|
|
67627
|
+
function deadCauseFromBootstrapError(err) {
|
|
67628
|
+
if (!(err instanceof BridgeProtocolError) || err.code !== "BRIDGE_DEAD")
|
|
67629
|
+
return;
|
|
67630
|
+
const detail = err.detail;
|
|
67631
|
+
if (detail === null || typeof detail !== "object")
|
|
67632
|
+
return;
|
|
67633
|
+
const r = detail;
|
|
67634
|
+
return {
|
|
67635
|
+
stage: "handshake",
|
|
67636
|
+
code: typeof r.code === "number" ? r.code : null,
|
|
67637
|
+
signal: typeof r.signal === "string" ? r.signal : null,
|
|
67638
|
+
message: typeof r.message === "string" ? r.message : err.message
|
|
67639
|
+
};
|
|
67640
|
+
}
|
|
67641
|
+
async function createBridgeSessionSeam(options) {
|
|
67642
|
+
const version = options.expectedProtocolVersion ?? BRIDGE_PROTOCOL_VERSION;
|
|
67643
|
+
let hello;
|
|
67644
|
+
try {
|
|
67645
|
+
hello = await options.transport.request("bridge.hello", { protocolVersion: version });
|
|
67646
|
+
} catch (err) {
|
|
67647
|
+
const cause = deadCauseFromBootstrapError(err);
|
|
67648
|
+
if (cause !== undefined)
|
|
67649
|
+
options.onDead?.(cause);
|
|
67650
|
+
throw toBridgeBootstrapError(err);
|
|
67651
|
+
}
|
|
67652
|
+
verifyBridgeFingerprint(hello, version);
|
|
67653
|
+
const seam = new BridgeSessionSeam({
|
|
67654
|
+
transport: options.transport,
|
|
67655
|
+
ctx: options.ctx,
|
|
67656
|
+
onDead: options.onDead,
|
|
67657
|
+
onPermissionUnavailable: options.onPermissionUnavailable
|
|
67658
|
+
});
|
|
67659
|
+
await seam.connect();
|
|
67660
|
+
return seam;
|
|
67661
|
+
}
|
|
67662
|
+
async function createSessionSeam(options) {
|
|
67663
|
+
if (options.kind === "remote")
|
|
67664
|
+
return options.createRemote();
|
|
67665
|
+
return options.createBridge();
|
|
67666
|
+
}
|
|
67667
|
+
async function recoverBridgeSession(options) {
|
|
67668
|
+
await options.transport.recover();
|
|
67669
|
+
return options.seam.recoverSession();
|
|
67670
|
+
}
|
|
67671
|
+
var BRIDGE_PROTOCOL_VERSION = 1, BridgeBootstrapError;
|
|
67672
|
+
var init_seam_bootstrap = __esm(() => {
|
|
67673
|
+
init_bridge_session_seam();
|
|
67674
|
+
init_bridge_failfast_text();
|
|
67675
|
+
init_host_compat();
|
|
67676
|
+
init_bridge_failfast_text();
|
|
67677
|
+
BridgeBootstrapError = class BridgeBootstrapError extends Error {
|
|
67678
|
+
code;
|
|
67679
|
+
diagnosis;
|
|
67680
|
+
repairCommand;
|
|
67681
|
+
constructor(options) {
|
|
67682
|
+
super(formatBridgeBootstrapMessage(options));
|
|
67683
|
+
this.name = "BridgeBootstrapError";
|
|
67684
|
+
this.code = options.code;
|
|
67685
|
+
this.diagnosis = options.diagnosis;
|
|
67686
|
+
this.repairCommand = options.repairCommand ?? BRIDGE_REPAIR_COMMAND;
|
|
67687
|
+
}
|
|
67688
|
+
};
|
|
67689
|
+
});
|
|
67690
|
+
|
|
65203
67691
|
// ../tui-base/examples/v2-entry.tsx
|
|
65204
67692
|
import { join as join15 } from "path";
|
|
65205
67693
|
import { existsSync as existsSync12 } from "fs";
|
|
@@ -65215,16 +67703,17 @@ function resolveWatchdogScript() {
|
|
|
65215
67703
|
return null;
|
|
65216
67704
|
}
|
|
65217
67705
|
async function loadShell() {
|
|
65218
|
-
const [shared, lifecycle, clifecycle, transport, rhs, adapter, git] = await Promise.all([
|
|
67706
|
+
const [shared, lifecycle, clifecycle, transport, rhs, adapter, git, seamBootstrap] = await Promise.all([
|
|
65219
67707
|
Promise.resolve().then(() => (init_boot_shared(), exports_boot_shared)),
|
|
65220
67708
|
Promise.resolve().then(() => (init_lifecycle(), exports_lifecycle)),
|
|
65221
67709
|
Promise.resolve().then(() => (init_client_lifecycle(), exports_client_lifecycle)),
|
|
65222
67710
|
Promise.resolve().then(() => (init_transport(), exports_transport)),
|
|
65223
67711
|
Promise.resolve().then(() => (init_remote_host_session(), exports_remote_host_session)),
|
|
65224
67712
|
Promise.resolve().then(() => (init_session_seam_adapter(), exports_session_seam_adapter)),
|
|
65225
|
-
Promise.resolve().then(() => (init_remote_git(), exports_remote_git))
|
|
67713
|
+
Promise.resolve().then(() => (init_remote_git(), exports_remote_git)),
|
|
67714
|
+
Promise.resolve().then(() => (init_seam_bootstrap(), exports_seam_bootstrap))
|
|
65226
67715
|
]);
|
|
65227
|
-
return { shared, lifecycle, clifecycle, transport, rhs, adapter, git };
|
|
67716
|
+
return { shared, lifecycle, clifecycle, transport, rhs, adapter, git, seamBootstrap };
|
|
65228
67717
|
}
|
|
65229
67718
|
function V2SessionPage(props) {
|
|
65230
67719
|
return createComponent2(DockProvider, {
|
|
@@ -65271,6 +67760,39 @@ function V2SessionPageBody(props) {
|
|
|
65271
67760
|
const [tools, setTools] = createSignal(0);
|
|
65272
67761
|
const [effort, setEffort] = createSignal();
|
|
65273
67762
|
const [remoteInfo, setRemoteInfo] = createSignal();
|
|
67763
|
+
const [bridgeStatus, setBridgeStatus] = createSignal("ready");
|
|
67764
|
+
let recoveryNewSession = () => {};
|
|
67765
|
+
const recoveryQuit = () => props.quit();
|
|
67766
|
+
const recoveryTexts = {
|
|
67767
|
+
transient: () => t("recovery.transient"),
|
|
67768
|
+
recovered: (count) => t("recovery.recovered", { count: String(count) }),
|
|
67769
|
+
failedReason: (reason) => t("recovery.failed.reason", { reason }),
|
|
67770
|
+
locked: (reason, holder) => reason === undefined ? t("recovery.locked") : holder === undefined ? t("recovery.locked.reason", { reason }) : t("recovery.locked.holder", { reason, holder }),
|
|
67771
|
+
cooldown: (remainingMs) => t("recovery.cooldown", { remainingMs: String(remainingMs) }),
|
|
67772
|
+
reconnect: () => t("recovery.action.reconnect"),
|
|
67773
|
+
retry: () => t("recovery.action.retry"),
|
|
67774
|
+
newSession: () => t("recovery.action.newSession"),
|
|
67775
|
+
quit: () => t("recovery.action.quit")
|
|
67776
|
+
};
|
|
67777
|
+
const recovery = new RecoveryUiController({
|
|
67778
|
+
recover: () => props.recoverBridge ? props.recoverBridge() : Promise.reject(new Error("no bridge transport injected")),
|
|
67779
|
+
texts: recoveryTexts,
|
|
67780
|
+
onNotice: (text, ttl, kind) => void showNotice(text, ttl, kind),
|
|
67781
|
+
onNewSession: () => recoveryNewSession(),
|
|
67782
|
+
onQuit: () => recoveryQuit()
|
|
67783
|
+
});
|
|
67784
|
+
const recoveryEvents = new Set([
|
|
67785
|
+
"bridge.dead",
|
|
67786
|
+
"bridge.recovered",
|
|
67787
|
+
"bridge.recovery.locked",
|
|
67788
|
+
"bridge.recovery.failed"
|
|
67789
|
+
]);
|
|
67790
|
+
onCleanup(seam.onSessionEvent?.((event) => {
|
|
67791
|
+
if (!recoveryEvents.has(event?.type))
|
|
67792
|
+
return;
|
|
67793
|
+
recovery.handleEvent(event);
|
|
67794
|
+
}) ?? (() => {}));
|
|
67795
|
+
onCleanup(recovery.subscribe(() => setBridgeStatus(recovery.footerStatus)));
|
|
65274
67796
|
const [now, setNow] = createSignal(new Date);
|
|
65275
67797
|
const [contextRevision, setContextRevision] = createSignal(0);
|
|
65276
67798
|
let contextFrameTitle;
|
|
@@ -65436,7 +67958,6 @@ function V2SessionPageBody(props) {
|
|
|
65436
67958
|
return;
|
|
65437
67959
|
}
|
|
65438
67960
|
setRemoteInfo({
|
|
65439
|
-
messageCount: info.messageCount,
|
|
65440
67961
|
msgCount: info.msgCount,
|
|
65441
67962
|
tps: info.lastTurnTps ?? info.sessionAvgTps
|
|
65442
67963
|
});
|
|
@@ -65467,6 +67988,7 @@ function V2SessionPageBody(props) {
|
|
|
65467
67988
|
contextWindow: ctxWindow(),
|
|
65468
67989
|
cacheHitRate: cacheRate(),
|
|
65469
67990
|
presetLabel: presetLabel(),
|
|
67991
|
+
bridgeStatus: bridgeStatus(),
|
|
65470
67992
|
theme,
|
|
65471
67993
|
mode: themeService.mode()
|
|
65472
67994
|
});
|
|
@@ -65579,6 +68101,7 @@ function V2SessionPageBody(props) {
|
|
|
65579
68101
|
};
|
|
65580
68102
|
const reloadSession = (sessionId) => {
|
|
65581
68103
|
setLastRequest(undefined);
|
|
68104
|
+
setSessionIdFromRecovery(undefined);
|
|
65582
68105
|
composerRef?.resetDeliveries();
|
|
65583
68106
|
setComposerPending([]);
|
|
65584
68107
|
setTools(0);
|
|
@@ -65634,8 +68157,10 @@ function V2SessionPageBody(props) {
|
|
|
65634
68157
|
footerRefreshSeq++;
|
|
65635
68158
|
},
|
|
65636
68159
|
themes: themeFace,
|
|
65637
|
-
flushQueue: () => composerRef?.flushQueue() ?? { kind: "empty", started: 0, remaining: 0 }
|
|
68160
|
+
flushQueue: () => composerRef?.flushQueue() ?? { kind: "empty", started: 0, remaining: 0 },
|
|
68161
|
+
clearRecoveryUi: () => recovery.clearRecoveryState()
|
|
65638
68162
|
}));
|
|
68163
|
+
recoveryNewSession = () => void slash.interceptSubmit("/new");
|
|
65639
68164
|
Keymap2.createLayer(() => ({
|
|
65640
68165
|
enabled: () => pageOwns(),
|
|
65641
68166
|
commands: [
|
|
@@ -65647,6 +68172,11 @@ function V2SessionPageBody(props) {
|
|
|
65647
68172
|
}
|
|
65648
68173
|
]
|
|
65649
68174
|
}));
|
|
68175
|
+
Keymap2.createLayer(() => ({
|
|
68176
|
+
mode: "global",
|
|
68177
|
+
enabled: () => pageOwns() || recovery.canRecover(),
|
|
68178
|
+
commands: [recovery.reconnectCommand()]
|
|
68179
|
+
}));
|
|
65650
68180
|
const overlayHost = createComponent2(TurnOverlayHost, {
|
|
65651
68181
|
controller: overlays,
|
|
65652
68182
|
reclaimFocus: () => {
|
|
@@ -65800,6 +68330,8 @@ function V2SessionPageBody(props) {
|
|
|
65800
68330
|
seam,
|
|
65801
68331
|
send,
|
|
65802
68332
|
footerHint: false,
|
|
68333
|
+
disabled: () => recovery.composerDisabled,
|
|
68334
|
+
disabledReason: () => t("recovery.composer.disabled"),
|
|
65803
68335
|
frameTitle: () => contextFrameTitle?.() ?? "",
|
|
65804
68336
|
onBusyChange: setComposerBusy,
|
|
65805
68337
|
ref: (r) => composerRef = r,
|
|
@@ -65825,6 +68357,7 @@ function V2SessionPageBody(props) {
|
|
|
65825
68357
|
}
|
|
65826
68358
|
}),
|
|
65827
68359
|
createComponent2(NoticesDock, {}),
|
|
68360
|
+
createComponent2(RecoveryBanner, { controller: recovery }),
|
|
65828
68361
|
createComponent2(SubagentsPicker, {
|
|
65829
68362
|
get seam() {
|
|
65830
68363
|
return seam;
|
|
@@ -65886,7 +68419,7 @@ function appendDiagnostic(line) {
|
|
|
65886
68419
|
} catch {}
|
|
65887
68420
|
}
|
|
65888
68421
|
async function bootClientV2(options = {}) {
|
|
65889
|
-
const { shared, lifecycle, clifecycle, transport, rhs, adapter, git } = await loadShell();
|
|
68422
|
+
const { shared, lifecycle, clifecycle, transport, rhs, adapter, git, seamBootstrap } = await loadShell();
|
|
65890
68423
|
const workspace = process.cwd();
|
|
65891
68424
|
const profile = lifecycle.DEFAULT_PROFILE;
|
|
65892
68425
|
const idleExitMs = lifecycle.resolveIdleExitMs();
|
|
@@ -65934,16 +68467,47 @@ async function bootClientV2(options = {}) {
|
|
|
65934
68467
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
65935
68468
|
}
|
|
65936
68469
|
}
|
|
65937
|
-
const seam = new adapter.RemoteSessionSeam(session);
|
|
65938
|
-
registerTurnOverlays(seam, overlays);
|
|
65939
68470
|
const launchArgs = parseLaunchArgs(options.argv ?? process.argv.slice(2));
|
|
68471
|
+
const seamKind = seamBootstrap.selectSeamKind({
|
|
68472
|
+
inproc: seamBootstrap.isInprocMode(),
|
|
68473
|
+
remote: launchArgs.remoteRequested === true
|
|
68474
|
+
});
|
|
68475
|
+
const seam = await seamBootstrap.createSessionSeam({
|
|
68476
|
+
kind: seamKind,
|
|
68477
|
+
createBridge: async () => {
|
|
68478
|
+
if (options.bridgeTransport === undefined) {
|
|
68479
|
+
throw new seamBootstrap.BridgeBootstrapError({
|
|
68480
|
+
code: "BRIDGE_TRANSPORT_MISSING",
|
|
68481
|
+
diagnosis: "inproc mode is on (DSH_OPENTUI_INPROC=1) but no bridge transport was injected at the synthetic root"
|
|
68482
|
+
});
|
|
68483
|
+
}
|
|
68484
|
+
return seamBootstrap.createBridgeSessionSeam({
|
|
68485
|
+
transport: options.bridgeTransport,
|
|
68486
|
+
ctx: options.bridgeCtx ?? { logger: console },
|
|
68487
|
+
onDead: (cause) => void showNotice(`${seamBootstrap.formatDeadNotice(cause)} \xB7 ${t("recovery.action.reconnect")}`, undefined, "error"),
|
|
68488
|
+
onPermissionUnavailable: (reason) => void showNotice(`${t("notice.permission.unavailable")} \xB7 ${t(`notice.permission.reason.${reason}`)}`, undefined, "error")
|
|
68489
|
+
});
|
|
68490
|
+
},
|
|
68491
|
+
createRemote: () => new adapter.RemoteSessionSeam(session)
|
|
68492
|
+
});
|
|
68493
|
+
const recoverBridge = seamKind === "bridge" && options.bridgeTransport !== undefined ? () => seamBootstrap.recoverBridgeSession({
|
|
68494
|
+
transport: options.bridgeTransport,
|
|
68495
|
+
seam
|
|
68496
|
+
}) : undefined;
|
|
68497
|
+
registerTurnOverlays(seam, overlays, {
|
|
68498
|
+
deadReason: (details) => {
|
|
68499
|
+
const cause = details;
|
|
68500
|
+
const detail = typeof cause?.message === "string" && cause.message.trim() !== "" ? cause.message : "";
|
|
68501
|
+
return detail === "" ? t("overlay.ask.invalidated.disconnected") : `${t("overlay.ask.invalidated.disconnected")} \xB7 ${detail}`;
|
|
68502
|
+
}
|
|
68503
|
+
});
|
|
65940
68504
|
let initialSessionId;
|
|
65941
68505
|
let resumeNotice;
|
|
65942
68506
|
if (launchArgs.sessionId !== undefined) {
|
|
65943
68507
|
seam.resumeSession(launchArgs.sessionId);
|
|
65944
68508
|
initialSessionId = launchArgs.sessionId;
|
|
65945
68509
|
} else {
|
|
65946
|
-
const autoResume = await runAutoResume({ config: seam.configLoad(), launch: launchArgs, workspace }, {
|
|
68510
|
+
const autoResume = await runAutoResume({ config: seam.configLoad?.() ?? {}, launch: launchArgs, workspace }, {
|
|
65947
68511
|
listSessions: (limit) => seam.listSessions(limit),
|
|
65948
68512
|
resumeSession: (id) => seam.resumeSession(id),
|
|
65949
68513
|
warn: (message) => console.warn(message)
|
|
@@ -65951,7 +68515,7 @@ async function bootClientV2(options = {}) {
|
|
|
65951
68515
|
initialSessionId = autoResume?.id;
|
|
65952
68516
|
resumeNotice = autoResume?.line;
|
|
65953
68517
|
}
|
|
65954
|
-
const agentsHomeConfig = seam.configLoad().agentsHome;
|
|
68518
|
+
const agentsHomeConfig = (seam.configLoad?.() ?? {}).agentsHome;
|
|
65955
68519
|
const agentsHomeForSkills = resolveAgentsHome(agentsHomeConfig);
|
|
65956
68520
|
pendingAgentsHomeNotice = agentsHomeEnvWarning(undefined, agentsHomeConfig);
|
|
65957
68521
|
const skillRows = discoverSkills({
|
|
@@ -65964,9 +68528,9 @@ async function bootClientV2(options = {}) {
|
|
|
65964
68528
|
curated: join15(host.dshHome, "skills")
|
|
65965
68529
|
};
|
|
65966
68530
|
const envTheme = process.env[shared.ENV_THEME];
|
|
65967
|
-
const workspaceConfig = seam.workspaceConfig();
|
|
68531
|
+
const workspaceConfig = seam.workspaceConfig?.() ?? {};
|
|
65968
68532
|
const migration = shared.skinMigrationPlan({
|
|
65969
|
-
profileConfig: seam.configRaw(),
|
|
68533
|
+
profileConfig: seam.configRaw?.() ?? {},
|
|
65970
68534
|
workspaceConfig,
|
|
65971
68535
|
envTheme
|
|
65972
68536
|
});
|
|
@@ -65997,6 +68561,12 @@ async function bootClientV2(options = {}) {
|
|
|
65997
68561
|
try {
|
|
65998
68562
|
await Promise.race([session.dispose(), new Promise((resolve) => setTimeout(resolve, shared.SHUTDOWN_GRACE_MS))]);
|
|
65999
68563
|
} catch {}
|
|
68564
|
+
if (seamKind === "bridge") {
|
|
68565
|
+
try {
|
|
68566
|
+
await Promise.race([seam.dispose(), new Promise((resolve) => setTimeout(resolve, shared.SHUTDOWN_GRACE_MS))]);
|
|
68567
|
+
} catch {}
|
|
68568
|
+
options.bridgeTransport?.close?.();
|
|
68569
|
+
}
|
|
66000
68570
|
if (clientHeartbeat) {
|
|
66001
68571
|
clientHeartbeat.stop();
|
|
66002
68572
|
clientHeartbeat.remove();
|
|
@@ -66040,6 +68610,7 @@ async function bootClientV2(options = {}) {
|
|
|
66040
68610
|
seam,
|
|
66041
68611
|
themeName,
|
|
66042
68612
|
quit: () => process.exit(0),
|
|
68613
|
+
recoverBridge,
|
|
66043
68614
|
workspace,
|
|
66044
68615
|
profileName: profile,
|
|
66045
68616
|
probeBranch: (cwd) => git.probeGitBranchOrSha(cwd),
|
|
@@ -66114,6 +68685,7 @@ var init_v2_entry = __esm(() => {
|
|
|
66114
68685
|
init_widgets_dock();
|
|
66115
68686
|
init_lastrequest_dock();
|
|
66116
68687
|
init_notices_dock();
|
|
68688
|
+
init_recovery_banner();
|
|
66117
68689
|
init_hints_line();
|
|
66118
68690
|
init_widgets_dock();
|
|
66119
68691
|
init_src();
|
|
@@ -66161,6 +68733,287 @@ var init_v2_entry = __esm(() => {
|
|
|
66161
68733
|
if (false) {}
|
|
66162
68734
|
});
|
|
66163
68735
|
|
|
68736
|
+
// src/client/bridge-transport.ts
|
|
68737
|
+
import { spawn as nodeSpawn2 } from "child_process";
|
|
68738
|
+
import { homedir as homedir9 } from "os";
|
|
68739
|
+
import { join as join16 } from "path";
|
|
68740
|
+
function recoveryCause(err, phase) {
|
|
68741
|
+
if (err instanceof BridgeBootstrapError) {
|
|
68742
|
+
return {
|
|
68743
|
+
stage: "handshake",
|
|
68744
|
+
code: null,
|
|
68745
|
+
signal: null,
|
|
68746
|
+
message: err.diagnosis,
|
|
68747
|
+
recoverability: "permanent",
|
|
68748
|
+
mismatches: [err.code]
|
|
68749
|
+
};
|
|
68750
|
+
}
|
|
68751
|
+
if (err instanceof BridgeProtocolError && err.code === "BRIDGE_DEAD") {
|
|
68752
|
+
const detail = asRecord7(err.detail);
|
|
68753
|
+
return {
|
|
68754
|
+
stage: phase,
|
|
68755
|
+
code: typeof detail.code === "number" ? detail.code : null,
|
|
68756
|
+
signal: typeof detail.signal === "string" ? detail.signal : null,
|
|
68757
|
+
message: err.message
|
|
68758
|
+
};
|
|
68759
|
+
}
|
|
68760
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
68761
|
+
return { stage: phase, code: null, signal: null, message };
|
|
68762
|
+
}
|
|
68763
|
+
|
|
68764
|
+
class StdioBridgeTransport {
|
|
68765
|
+
#opts;
|
|
68766
|
+
#child;
|
|
68767
|
+
#nextId = 1;
|
|
68768
|
+
#pending = new Map;
|
|
68769
|
+
#listeners = new Set;
|
|
68770
|
+
#stdoutBuffer = "";
|
|
68771
|
+
#stderrTail = [];
|
|
68772
|
+
#deadError;
|
|
68773
|
+
#deadCause;
|
|
68774
|
+
#state = "initializing";
|
|
68775
|
+
#attempts = 0;
|
|
68776
|
+
#deadAt;
|
|
68777
|
+
#connectionGeneration = 0;
|
|
68778
|
+
constructor(options = {}) {
|
|
68779
|
+
this.#opts = options;
|
|
68780
|
+
}
|
|
68781
|
+
get diagnostics() {
|
|
68782
|
+
return this.#stderrTail.slice(-12).join(`
|
|
68783
|
+
`);
|
|
68784
|
+
}
|
|
68785
|
+
get state() {
|
|
68786
|
+
return this.#state;
|
|
68787
|
+
}
|
|
68788
|
+
get attempts() {
|
|
68789
|
+
return this.#attempts;
|
|
68790
|
+
}
|
|
68791
|
+
get deadCause() {
|
|
68792
|
+
return this.#deadCause;
|
|
68793
|
+
}
|
|
68794
|
+
#setState(next) {
|
|
68795
|
+
if (this.#state === next)
|
|
68796
|
+
return;
|
|
68797
|
+
this.#state = next;
|
|
68798
|
+
this.#opts.onStateChange?.(next);
|
|
68799
|
+
}
|
|
68800
|
+
#spawn() {
|
|
68801
|
+
if (this.#child !== undefined)
|
|
68802
|
+
return this.#child;
|
|
68803
|
+
const dshHome = this.#opts.dshHome ?? process.env.DSH_HOME ?? join16(homedir9(), ".dsh");
|
|
68804
|
+
const env = {
|
|
68805
|
+
...process.env,
|
|
68806
|
+
...this.#opts.env ?? {},
|
|
68807
|
+
DSH_HOME: dshHome,
|
|
68808
|
+
DSH_OPENTUI_BRIDGE_STDIO: "1"
|
|
68809
|
+
};
|
|
68810
|
+
const spawnFn = this.#opts.spawnFn ?? ((command, args, options) => nodeSpawn2(command, [...args], options));
|
|
68811
|
+
const child = spawnFn(this.#opts.dshBin ?? "dsh", ["--profile", this.#opts.profile ?? "opentui-inproc"], {
|
|
68812
|
+
env,
|
|
68813
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
68814
|
+
});
|
|
68815
|
+
const generation = ++this.#connectionGeneration;
|
|
68816
|
+
this.#child = child;
|
|
68817
|
+
child.stdout.on("data", (chunk) => {
|
|
68818
|
+
if (generation !== this.#connectionGeneration)
|
|
68819
|
+
return;
|
|
68820
|
+
this.#onStdout(chunk);
|
|
68821
|
+
});
|
|
68822
|
+
child.stderr.on("data", (chunk) => {
|
|
68823
|
+
if (generation !== this.#connectionGeneration)
|
|
68824
|
+
return;
|
|
68825
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
68826
|
+
this.#stderrTail.push(...text.split(`
|
|
68827
|
+
`).filter(Boolean));
|
|
68828
|
+
if (this.#stderrTail.length > 64)
|
|
68829
|
+
this.#stderrTail.splice(0, this.#stderrTail.length - 64);
|
|
68830
|
+
});
|
|
68831
|
+
child.on("exit", (code, signal) => {
|
|
68832
|
+
if (generation !== this.#connectionGeneration)
|
|
68833
|
+
return;
|
|
68834
|
+
const exitCode = typeof code === "number" ? code : null;
|
|
68835
|
+
const exitSignal = typeof signal === "string" ? signal : null;
|
|
68836
|
+
const message = `bridge host exited (code ${String(code)}${exitSignal === null ? "" : `, signal ${exitSignal}`})`;
|
|
68837
|
+
this.#onDead(message, { stage: "runtime", code: exitCode, signal: exitSignal, message });
|
|
68838
|
+
});
|
|
68839
|
+
child.on("error", (err) => {
|
|
68840
|
+
if (generation !== this.#connectionGeneration)
|
|
68841
|
+
return;
|
|
68842
|
+
const message = `bridge host error: ${err instanceof Error ? err.message : String(err)}`;
|
|
68843
|
+
this.#onDead(message, { stage: "spawn", code: null, signal: null, message });
|
|
68844
|
+
});
|
|
68845
|
+
return child;
|
|
68846
|
+
}
|
|
68847
|
+
#onStdout(chunk) {
|
|
68848
|
+
this.#stdoutBuffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
68849
|
+
let newline = this.#stdoutBuffer.indexOf(`
|
|
68850
|
+
`);
|
|
68851
|
+
while (newline >= 0) {
|
|
68852
|
+
const line = this.#stdoutBuffer.slice(0, newline).trim();
|
|
68853
|
+
this.#stdoutBuffer = this.#stdoutBuffer.slice(newline + 1);
|
|
68854
|
+
if (line !== "")
|
|
68855
|
+
this.#handleFrame(line);
|
|
68856
|
+
newline = this.#stdoutBuffer.indexOf(`
|
|
68857
|
+
`);
|
|
68858
|
+
}
|
|
68859
|
+
}
|
|
68860
|
+
#handleFrame(line) {
|
|
68861
|
+
let frame;
|
|
68862
|
+
try {
|
|
68863
|
+
frame = JSON.parse(line);
|
|
68864
|
+
} catch {
|
|
68865
|
+
return;
|
|
68866
|
+
}
|
|
68867
|
+
const rec = asRecord7(frame);
|
|
68868
|
+
if (typeof rec.id === "number") {
|
|
68869
|
+
const pending = this.#pending.get(rec.id);
|
|
68870
|
+
if (pending === undefined)
|
|
68871
|
+
return;
|
|
68872
|
+
this.#pending.delete(rec.id);
|
|
68873
|
+
clearTimeout(pending.timer);
|
|
68874
|
+
if (rec.ok === true) {
|
|
68875
|
+
if (this.#state === "initializing")
|
|
68876
|
+
this.#setState("ready");
|
|
68877
|
+
pending.resolve(rec.result);
|
|
68878
|
+
} else {
|
|
68879
|
+
const error = asRecord7(rec.error);
|
|
68880
|
+
pending.reject(new BridgeProtocolError(typeof error.code === "string" ? error.code : "BRIDGE_ERROR", typeof error.message === "string" ? error.message : "bridge request failed", error.detail));
|
|
68881
|
+
}
|
|
68882
|
+
return;
|
|
68883
|
+
}
|
|
68884
|
+
if (typeof rec.type === "string") {
|
|
68885
|
+
this.#publish({ type: rec.type, payload: rec.payload });
|
|
68886
|
+
}
|
|
68887
|
+
}
|
|
68888
|
+
#publish(event) {
|
|
68889
|
+
for (const listener of [...this.#listeners]) {
|
|
68890
|
+
try {
|
|
68891
|
+
listener(event);
|
|
68892
|
+
} catch {}
|
|
68893
|
+
}
|
|
68894
|
+
}
|
|
68895
|
+
#onDead(reason, cause) {
|
|
68896
|
+
const firstDead = this.#state !== "dead" && this.#state !== "closed";
|
|
68897
|
+
if (firstDead) {
|
|
68898
|
+
this.#deadAt = (this.#opts.now ?? Date.now)();
|
|
68899
|
+
this.#attempts += 1;
|
|
68900
|
+
}
|
|
68901
|
+
if (this.#state !== "closed")
|
|
68902
|
+
this.#setState("dead");
|
|
68903
|
+
if (this.#deadError === undefined) {
|
|
68904
|
+
const tail = this.diagnostics ? ` (stderr tail: ${this.diagnostics})` : "";
|
|
68905
|
+
this.#deadError = new BridgeProtocolError("BRIDGE_DEAD", `${reason}${tail}`, cause);
|
|
68906
|
+
this.#deadCause = cause;
|
|
68907
|
+
this.#publish({ type: "bridge.dead", payload: cause });
|
|
68908
|
+
}
|
|
68909
|
+
for (const [id, pending] of [...this.#pending]) {
|
|
68910
|
+
this.#pending.delete(id);
|
|
68911
|
+
clearTimeout(pending.timer);
|
|
68912
|
+
pending.reject(this.#deadError);
|
|
68913
|
+
}
|
|
68914
|
+
}
|
|
68915
|
+
request(method, params) {
|
|
68916
|
+
if (this.#state === "closed") {
|
|
68917
|
+
return Promise.reject(new BridgeProtocolError("BRIDGE_CLOSED", "bridge transport is closed"));
|
|
68918
|
+
}
|
|
68919
|
+
if (this.#state === "recovering" || this.#state === "handshake") {
|
|
68920
|
+
return Promise.reject(new BridgeProtocolError("BRIDGE_RECOVERING", "bridge transport is recovering; request rejected", {
|
|
68921
|
+
state: this.#state
|
|
68922
|
+
}));
|
|
68923
|
+
}
|
|
68924
|
+
if (this.#deadError !== undefined)
|
|
68925
|
+
return Promise.reject(this.#deadError);
|
|
68926
|
+
return this.#sendRequest(method, params);
|
|
68927
|
+
}
|
|
68928
|
+
#sendRequest(method, params) {
|
|
68929
|
+
const child = this.#spawn();
|
|
68930
|
+
const id = this.#nextId++;
|
|
68931
|
+
return new Promise((resolve, reject) => {
|
|
68932
|
+
const timer = setTimeout(() => {
|
|
68933
|
+
this.#pending.delete(id);
|
|
68934
|
+
reject(new BridgeProtocolError("BRIDGE_TIMEOUT", `no reply for ${method} within ${this.#opts.replyTimeoutMs ?? 30000}ms`));
|
|
68935
|
+
}, this.#opts.replyTimeoutMs ?? 30000);
|
|
68936
|
+
this.#pending.set(id, { resolve, reject, timer });
|
|
68937
|
+
try {
|
|
68938
|
+
child.stdin.write(`${JSON.stringify({ id, method, ...params === undefined ? {} : { params } })}
|
|
68939
|
+
`);
|
|
68940
|
+
} catch (err) {
|
|
68941
|
+
this.#pending.delete(id);
|
|
68942
|
+
clearTimeout(timer);
|
|
68943
|
+
reject(new BridgeProtocolError("BRIDGE_WRITE_FAILED", String(err)));
|
|
68944
|
+
}
|
|
68945
|
+
});
|
|
68946
|
+
}
|
|
68947
|
+
async recover() {
|
|
68948
|
+
if (this.#state === "closed") {
|
|
68949
|
+
throw new BridgeProtocolError("BRIDGE_CLOSED", "bridge transport is closed; recover() refused");
|
|
68950
|
+
}
|
|
68951
|
+
if (this.#state !== "dead") {
|
|
68952
|
+
throw new BridgeProtocolError("BRIDGE_NOT_DEAD", `recover() requires DEAD state (current: ${this.#state})`, { state: this.#state });
|
|
68953
|
+
}
|
|
68954
|
+
const now = this.#opts.now ?? Date.now;
|
|
68955
|
+
const cooldown = this.#opts.recoverCooldownMs ?? 5000;
|
|
68956
|
+
const elapsed = this.#deadAt === undefined ? cooldown : now() - this.#deadAt;
|
|
68957
|
+
if (elapsed < cooldown) {
|
|
68958
|
+
throw new BridgeProtocolError("BRIDGE_RECOVERY_COOLDOWN", `recover() cooling down; retry in ${cooldown - elapsed}ms`, { remainingMs: cooldown - elapsed });
|
|
68959
|
+
}
|
|
68960
|
+
this.#setState("recovering");
|
|
68961
|
+
this.#deadError = undefined;
|
|
68962
|
+
this.#deadCause = undefined;
|
|
68963
|
+
this.#connectionGeneration++;
|
|
68964
|
+
for (const [id, pending] of [...this.#pending]) {
|
|
68965
|
+
this.#pending.delete(id);
|
|
68966
|
+
clearTimeout(pending.timer);
|
|
68967
|
+
pending.reject(new BridgeProtocolError("BRIDGE_RECOVERING", "bridge recovering; in-flight request dropped"));
|
|
68968
|
+
}
|
|
68969
|
+
this.#nextId = 1;
|
|
68970
|
+
this.#stdoutBuffer = "";
|
|
68971
|
+
try {
|
|
68972
|
+
try {
|
|
68973
|
+
this.#child?.kill("SIGTERM");
|
|
68974
|
+
} catch {}
|
|
68975
|
+
this.#child = undefined;
|
|
68976
|
+
this.#spawn();
|
|
68977
|
+
this.#setState("handshake");
|
|
68978
|
+
const hello = await this.#sendRequest("bridge.hello", { protocolVersion: BRIDGE_PROTOCOL_VERSION });
|
|
68979
|
+
verifyRecoveryHandshake(hello, BRIDGE_PROTOCOL_VERSION);
|
|
68980
|
+
} catch (err) {
|
|
68981
|
+
if (this.#state === "dead" || this.#state === "closed")
|
|
68982
|
+
throw err;
|
|
68983
|
+
const cause = recoveryCause(err, this.#state === "handshake" ? "handshake" : "spawn");
|
|
68984
|
+
this.#onDead(cause.message, cause);
|
|
68985
|
+
throw err;
|
|
68986
|
+
}
|
|
68987
|
+
this.#setState("ready");
|
|
68988
|
+
}
|
|
68989
|
+
onEvent(listener) {
|
|
68990
|
+
this.#listeners.add(listener);
|
|
68991
|
+
return () => {
|
|
68992
|
+
this.#listeners.delete(listener);
|
|
68993
|
+
};
|
|
68994
|
+
}
|
|
68995
|
+
close() {
|
|
68996
|
+
if (this.#state === "closed")
|
|
68997
|
+
return;
|
|
68998
|
+
this.#connectionGeneration++;
|
|
68999
|
+
this.#setState("closed");
|
|
69000
|
+
this.#onDead("bridge transport closed", {
|
|
69001
|
+
stage: "closed",
|
|
69002
|
+
code: null,
|
|
69003
|
+
signal: null,
|
|
69004
|
+
message: "bridge transport closed"
|
|
69005
|
+
});
|
|
69006
|
+
try {
|
|
69007
|
+
this.#child?.kill("SIGTERM");
|
|
69008
|
+
} catch {}
|
|
69009
|
+
}
|
|
69010
|
+
}
|
|
69011
|
+
var asRecord7 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
69012
|
+
var init_bridge_transport = __esm(() => {
|
|
69013
|
+
init_bridge_session_seam();
|
|
69014
|
+
init_seam_bootstrap();
|
|
69015
|
+
});
|
|
69016
|
+
|
|
66164
69017
|
// src/client-entry.tsx
|
|
66165
69018
|
init_client_lifecycle();
|
|
66166
69019
|
init_boot_shared();
|
|
@@ -66169,12 +69022,12 @@ init_lifecycle();
|
|
|
66169
69022
|
init_transport();
|
|
66170
69023
|
init_remote_host_session();
|
|
66171
69024
|
import { existsSync as existsSync13 } from "fs";
|
|
66172
|
-
import { join as
|
|
69025
|
+
import { join as join17 } from "path";
|
|
66173
69026
|
function resolveWatchdogScript2() {
|
|
66174
69027
|
const candidates = [
|
|
66175
|
-
|
|
66176
|
-
|
|
66177
|
-
|
|
69028
|
+
join17(import.meta.dir, "..", "watchdog.mjs"),
|
|
69029
|
+
join17(import.meta.dir, "..", "dist", "watchdog.mjs"),
|
|
69030
|
+
join17(import.meta.dir, "..", "scripts", "watchdog.mjs")
|
|
66178
69031
|
];
|
|
66179
69032
|
for (const candidate of candidates) {
|
|
66180
69033
|
if (existsSync13(candidate))
|
|
@@ -66321,7 +69174,17 @@ async function main() {
|
|
|
66321
69174
|
try {
|
|
66322
69175
|
const v2Specifier = "../../" + "tui-base/examples/v2-entry.tsx";
|
|
66323
69176
|
const mod = await Promise.resolve().then(() => (init_v2_entry(), {}));
|
|
66324
|
-
|
|
69177
|
+
const argv = process.argv.slice(2);
|
|
69178
|
+
let bootOptions = { argv };
|
|
69179
|
+
if (process.env.DSH_OPENTUI_INPROC === "1" && !argv.includes("--remote")) {
|
|
69180
|
+
const bridgeMod = await Promise.resolve().then(() => (init_bridge_transport(), {}));
|
|
69181
|
+
bootOptions = {
|
|
69182
|
+
...bootOptions,
|
|
69183
|
+
bridgeTransport: new StdioBridgeTransport,
|
|
69184
|
+
bridgeCtx: { logger: console }
|
|
69185
|
+
};
|
|
69186
|
+
}
|
|
69187
|
+
await bootClientV2(bootOptions);
|
|
66325
69188
|
} catch (error) {
|
|
66326
69189
|
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
66327
69190
|
process.stderr.write(`dsh-opentui client boot failed: ${message}
|
|
@@ -66342,5 +69205,5 @@ export {
|
|
|
66342
69205
|
themeNameFromConfig
|
|
66343
69206
|
};
|
|
66344
69207
|
|
|
66345
|
-
//# debugId=
|
|
69208
|
+
//# debugId=A1DE0F5F067B3B7E64756E2164756E21
|
|
66346
69209
|
//# sourceMappingURL=index.js.map
|