@aiwayds/dsh-opentui 0.28.1 → 0.28.2
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 +29 -0
- package/dist/bridge/bundle-fingerprint.json +1 -1
- package/dist/bridge/index.js +248 -47
- package/dist/client/index.js +300 -8
- package/dist/client/index.js.map +8 -7
- package/package.json +1 -1
- package/scripts/lib/inproc-companions.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.28.2] - 2026-11-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Ask outcomes now enter the session transcript.** When an `ask` settles
|
|
13
|
+
(answered, rejected, unavailable, cancelled or timed out), the bridge writes
|
|
14
|
+
a terminal journal row and emits a frame carrying a closed settle reason. The
|
|
15
|
+
shell projects that outcome into a single `ask-outcome:<eventId>` notice row,
|
|
16
|
+
so live frames, bridge reconnect and `/resume` of a stored transcript all
|
|
17
|
+
show the same result in the transcript.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **Expired approval windows no longer leave zombie cards.** The bridge arms a
|
|
22
|
+
gate for each pending ask: when the approval window expires without a verdict
|
|
23
|
+
the ask is settled with reason `timeout` and the default outcome, even if the
|
|
24
|
+
provider never answers.
|
|
25
|
+
- **Older ask frames and journals still read.** The settle reason is optional on
|
|
26
|
+
read paths, so journals written before it existed still replay, and frames
|
|
27
|
+
without the new reason field stay valid for consumers. New writes always
|
|
28
|
+
carry a closed settle reason.
|
|
29
|
+
- **The companion model-sync guard now tracks `^0.11.0`.** The in-process profile
|
|
30
|
+
previously declared `^0.10.0`, so npm `latest` = 0.11.0 was skipped as a 0.x
|
|
31
|
+
cross-minor break and the fresh-home verifier saw only 10 of 11 companions.
|
|
32
|
+
The guard now admits 0.11.0 while still rejecting 0.12.0. The 0.11.0 manifest
|
|
33
|
+
keeps the same peers, engine and entry points as 0.10.0. The interaction
|
|
34
|
+
between 0.11.0's migrate-go/one-shot paths and provision patch ownership is
|
|
35
|
+
**NOT VERIFIED** and is not claimed as validated by this change.
|
|
36
|
+
|
|
8
37
|
## [0.28.1] - 2026-11-25
|
|
9
38
|
|
|
10
39
|
### Added
|
package/dist/bridge/index.js
CHANGED
|
@@ -25,6 +25,19 @@ var ASK_ERROR_CODE_SET = new Set(Object.values(ASK_ERROR_CODES));
|
|
|
25
25
|
function isAskErrorCode(value) {
|
|
26
26
|
return typeof value === "string" && ASK_ERROR_CODE_SET.has(value);
|
|
27
27
|
}
|
|
28
|
+
var SETTLE_REASONS = [
|
|
29
|
+
"answered",
|
|
30
|
+
"rejected",
|
|
31
|
+
"unavailable",
|
|
32
|
+
"timeout",
|
|
33
|
+
"aborted",
|
|
34
|
+
"turn-ended",
|
|
35
|
+
"session-closed",
|
|
36
|
+
"detached",
|
|
37
|
+
"connection-closed",
|
|
38
|
+
"no-channel",
|
|
39
|
+
"auto-approved"
|
|
40
|
+
];
|
|
28
41
|
function isRecord(value) {
|
|
29
42
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
30
43
|
}
|
|
@@ -245,7 +258,45 @@ function validateAskSettled(value) {
|
|
|
245
258
|
const outcome = oneOf(value.outcome, OUTCOMES, "outcome", code);
|
|
246
259
|
if (typeof outcome !== "string")
|
|
247
260
|
return outcome;
|
|
248
|
-
|
|
261
|
+
let reason;
|
|
262
|
+
if (value.reason !== undefined) {
|
|
263
|
+
const parsed = oneOf(value.reason, SETTLE_REASONS, "reason", code);
|
|
264
|
+
if (typeof parsed !== "string")
|
|
265
|
+
return parsed;
|
|
266
|
+
reason = parsed;
|
|
267
|
+
}
|
|
268
|
+
const sessionId = optionalString(value.sessionId, "sessionId", code);
|
|
269
|
+
if (typeof sessionId === "object")
|
|
270
|
+
return sessionId;
|
|
271
|
+
let kind;
|
|
272
|
+
if (value.kind !== undefined) {
|
|
273
|
+
const parsed = oneOf(value.kind, KINDS, "kind", code);
|
|
274
|
+
if (typeof parsed !== "string")
|
|
275
|
+
return parsed;
|
|
276
|
+
kind = parsed;
|
|
277
|
+
}
|
|
278
|
+
const toolName = optionalString(value.toolName, "toolName", code);
|
|
279
|
+
if (typeof toolName === "object")
|
|
280
|
+
return toolName;
|
|
281
|
+
const callId = optionalString(value.callId, "callId", code);
|
|
282
|
+
if (typeof callId === "object")
|
|
283
|
+
return callId;
|
|
284
|
+
const childSessionId = optionalString(value.childSessionId, "childSessionId", code);
|
|
285
|
+
if (typeof childSessionId === "object")
|
|
286
|
+
return childSessionId;
|
|
287
|
+
return {
|
|
288
|
+
ok: true,
|
|
289
|
+
value: {
|
|
290
|
+
eventId,
|
|
291
|
+
outcome,
|
|
292
|
+
...reason !== undefined ? { reason } : {},
|
|
293
|
+
...sessionId !== undefined ? { sessionId } : {},
|
|
294
|
+
...kind !== undefined ? { kind } : {},
|
|
295
|
+
...toolName !== undefined ? { toolName } : {},
|
|
296
|
+
...callId !== undefined ? { callId } : {},
|
|
297
|
+
...childSessionId !== undefined ? { childSessionId } : {}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
249
300
|
}
|
|
250
301
|
function validateAskResponse(value) {
|
|
251
302
|
const code = ASK_ERROR_CODES.INVALID_RESPONSE;
|
|
@@ -408,6 +459,11 @@ var WRITE_TOOL_POLICY = Object.freeze({
|
|
|
408
459
|
|
|
409
460
|
// ../bridge/src/ask-registry.ts
|
|
410
461
|
var DEFAULT_RECORD_LIMIT = 256;
|
|
462
|
+
var ANSWER_SETTLE_REASON = {
|
|
463
|
+
approved: "answered",
|
|
464
|
+
denied: "rejected",
|
|
465
|
+
unavailable: "unavailable"
|
|
466
|
+
};
|
|
411
467
|
var DEFAULT_MAX_ASK_WAIT_MS = 3600000;
|
|
412
468
|
function remember(ids, id, limit) {
|
|
413
469
|
ids.add(id);
|
|
@@ -482,9 +538,11 @@ class AskRegistry {
|
|
|
482
538
|
sessionId: redactIdentifier(input.sessionId) ?? input.sessionId,
|
|
483
539
|
turnId: redactIdentifier(turnId) ?? turnId,
|
|
484
540
|
...redactIdentifier(input.toolName) !== undefined ? { toolName: redactIdentifier(input.toolName) } : {},
|
|
541
|
+
...redactIdentifier(input.childSessionId) !== undefined ? { childSessionId: redactIdentifier(input.childSessionId) } : {},
|
|
485
542
|
verdict: "allowed-once",
|
|
486
543
|
outcome: "approved",
|
|
487
544
|
behavior: "always",
|
|
545
|
+
settleReason: "auto-approved",
|
|
488
546
|
source: "summary",
|
|
489
547
|
at: this.#now()
|
|
490
548
|
});
|
|
@@ -520,6 +578,13 @@ class AskRegistry {
|
|
|
520
578
|
#emit(frame) {
|
|
521
579
|
this.#sink(frame);
|
|
522
580
|
}
|
|
581
|
+
#emitTerminal(frame) {
|
|
582
|
+
try {
|
|
583
|
+
this.#emit(frame);
|
|
584
|
+
} catch (err) {
|
|
585
|
+
this.#logger?.warn?.("[ask-registry] terminal frame emit failed (decision unchanged): %s", err);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
523
588
|
create(turnId, input) {
|
|
524
589
|
const eventId = this.nextEventId(turnId);
|
|
525
590
|
const request = { ...input, eventId };
|
|
@@ -531,6 +596,7 @@ class AskRegistry {
|
|
|
531
596
|
if (deadlineAt !== undefined) {
|
|
532
597
|
entry.deadlineTimer = this.#arm(() => {
|
|
533
598
|
this.#settle(entry, this.#deadlineOutcome(entry.request.kind), {
|
|
599
|
+
settleReason: "timeout",
|
|
534
600
|
code: ASK_ERROR_CODES.DEADLINE_EXCEEDED,
|
|
535
601
|
cancelReason: "deadline",
|
|
536
602
|
message: "ask deadline exceeded",
|
|
@@ -540,29 +606,43 @@ class AskRegistry {
|
|
|
540
606
|
}
|
|
541
607
|
entry.hardCapTimer = this.#arm(() => {
|
|
542
608
|
this.#settle(entry, "unavailable", {
|
|
609
|
+
settleReason: "timeout",
|
|
543
610
|
code: ASK_ERROR_CODES.DEADLINE_EXCEEDED,
|
|
544
611
|
cancelReason: "deadline",
|
|
545
612
|
message: "maxAskWaitMs hard cap exceeded",
|
|
546
613
|
source: "timeout"
|
|
547
614
|
});
|
|
548
615
|
}, this.#maxAskWaitMs);
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
616
|
+
try {
|
|
617
|
+
this.#writeJournal({
|
|
618
|
+
eventId,
|
|
619
|
+
kind: ASK_JOURNAL_KINDS.REQUESTED,
|
|
620
|
+
askKind: request.kind,
|
|
621
|
+
sessionId: redactIdentifier(request.sessionId) ?? request.sessionId,
|
|
622
|
+
turnId: redactIdentifier(turnId) ?? turnId,
|
|
623
|
+
...redactIdentifier(request.toolName) !== undefined ? { toolName: redactIdentifier(request.toolName) } : {},
|
|
624
|
+
...redactIdentifier(request.childSessionId) !== undefined ? { childSessionId: redactIdentifier(request.childSessionId) } : {},
|
|
625
|
+
source: "request",
|
|
626
|
+
at: createdAt
|
|
627
|
+
});
|
|
628
|
+
this.#emit({ type: ASK_FRAME_TYPES.REQUEST, payload: request });
|
|
629
|
+
} catch (err) {
|
|
630
|
+
this.#disarm(entry.deadlineTimer);
|
|
631
|
+
this.#disarm(entry.graceTimer);
|
|
632
|
+
this.#disarm(entry.hardCapTimer);
|
|
633
|
+
entry.deadlineTimer = undefined;
|
|
634
|
+
entry.graceTimer = undefined;
|
|
635
|
+
entry.hardCapTimer = undefined;
|
|
636
|
+
this.#pending.delete(eventId);
|
|
637
|
+
this.#logger?.warn?.("[ask-registry] ask.request emit failed; rolled back %s: %s", eventId, err);
|
|
638
|
+
throw err;
|
|
639
|
+
}
|
|
560
640
|
return request;
|
|
561
641
|
}
|
|
562
642
|
#deadlineOutcome(kind) {
|
|
563
643
|
return kind === "approval" ? "denied" : "cancelled";
|
|
564
644
|
}
|
|
565
|
-
#settle(entry, outcome, options
|
|
645
|
+
#settle(entry, outcome, options) {
|
|
566
646
|
const eventId = entry.request.eventId;
|
|
567
647
|
this.#disarm(entry.deadlineTimer);
|
|
568
648
|
this.#disarm(entry.graceTimer);
|
|
@@ -576,7 +656,7 @@ class AskRegistry {
|
|
|
576
656
|
else
|
|
577
657
|
remember(this.#settledIds, eventId, this.#recordLimit);
|
|
578
658
|
if (options.cancelReason !== undefined) {
|
|
579
|
-
this.#
|
|
659
|
+
this.#emitTerminal({ type: ASK_FRAME_TYPES.CANCEL, payload: { eventId, reason: options.cancelReason } });
|
|
580
660
|
}
|
|
581
661
|
const settlement = {
|
|
582
662
|
eventId,
|
|
@@ -596,6 +676,8 @@ class AskRegistry {
|
|
|
596
676
|
sessionId: redactIdentifier(entry.request.sessionId) ?? entry.request.sessionId,
|
|
597
677
|
turnId: redactIdentifier(entry.turnId) ?? entry.turnId,
|
|
598
678
|
...redactIdentifier(entry.request.toolName) !== undefined ? { toolName: redactIdentifier(entry.request.toolName) } : {},
|
|
679
|
+
...redactIdentifier(entry.request.childSessionId) !== undefined ? { childSessionId: redactIdentifier(entry.request.childSessionId) } : {},
|
|
680
|
+
settleReason: options.settleReason,
|
|
599
681
|
...options.verdict !== undefined ? { verdict: options.verdict } : {},
|
|
600
682
|
outcome,
|
|
601
683
|
...options.behavior !== undefined ? { behavior: options.behavior } : {},
|
|
@@ -605,9 +687,42 @@ class AskRegistry {
|
|
|
605
687
|
source: options.source ?? (cancelled ? "teardown" : "answer"),
|
|
606
688
|
at: settlement.at
|
|
607
689
|
});
|
|
608
|
-
this.#
|
|
690
|
+
this.#emitTerminal({
|
|
691
|
+
type: ASK_FRAME_TYPES.SETTLED,
|
|
692
|
+
payload: {
|
|
693
|
+
eventId,
|
|
694
|
+
outcome,
|
|
695
|
+
reason: options.settleReason,
|
|
696
|
+
sessionId: entry.request.sessionId,
|
|
697
|
+
kind: entry.request.kind,
|
|
698
|
+
...entry.request.toolName !== undefined ? { toolName: entry.request.toolName } : {},
|
|
699
|
+
...entry.request.callId !== undefined ? { callId: entry.request.callId } : {},
|
|
700
|
+
...entry.request.childSessionId !== undefined ? { childSessionId: entry.request.childSessionId } : {}
|
|
701
|
+
}
|
|
702
|
+
});
|
|
609
703
|
return settlement;
|
|
610
704
|
}
|
|
705
|
+
settleExternal(eventId, input) {
|
|
706
|
+
const entry = this.#pending.get(eventId);
|
|
707
|
+
if (entry === undefined)
|
|
708
|
+
return;
|
|
709
|
+
let outcome;
|
|
710
|
+
if (input.outcome !== undefined) {
|
|
711
|
+
outcome = input.outcome;
|
|
712
|
+
} else if (input.settleReason === "timeout") {
|
|
713
|
+
outcome = input.defaultOutcome === "rejected" ? "denied" : input.defaultOutcome === "unavailable" ? "unavailable" : this.#deadlineOutcome(entry.request.kind);
|
|
714
|
+
} else {
|
|
715
|
+
outcome = "cancelled";
|
|
716
|
+
}
|
|
717
|
+
return this.#settle(entry, outcome, {
|
|
718
|
+
settleReason: input.settleReason,
|
|
719
|
+
...input.code !== undefined ? { code: input.code } : input.settleReason === "timeout" ? { code: ASK_ERROR_CODES.DEADLINE_EXCEEDED } : {},
|
|
720
|
+
...input.message !== undefined ? { message: input.message } : {},
|
|
721
|
+
...input.cancelReason !== undefined ? { cancelReason: input.cancelReason } : {},
|
|
722
|
+
...input.settleReason !== "timeout" ? { ended: true } : {},
|
|
723
|
+
source: input.source ?? (input.settleReason === "timeout" ? "timeout" : "teardown")
|
|
724
|
+
});
|
|
725
|
+
}
|
|
611
726
|
answer(sessionId, rawParams) {
|
|
612
727
|
const parsed = validateAskResponse(rawParams);
|
|
613
728
|
if (!parsed.ok) {
|
|
@@ -670,9 +785,11 @@ class AskRegistry {
|
|
|
670
785
|
askKind: entry.request.kind,
|
|
671
786
|
sessionId: sourceSession,
|
|
672
787
|
turnId: sourceTurn,
|
|
788
|
+
...redactIdentifier(entry.request.childSessionId) !== undefined ? { childSessionId: redactIdentifier(entry.request.childSessionId) } : {},
|
|
673
789
|
toolName: tool,
|
|
674
790
|
verdict: "allowed-once",
|
|
675
791
|
outcome: "approved",
|
|
792
|
+
settleReason: "answered",
|
|
676
793
|
behavior: "always",
|
|
677
794
|
source: "answer",
|
|
678
795
|
at: this.#now()
|
|
@@ -680,6 +797,7 @@ class AskRegistry {
|
|
|
680
797
|
}
|
|
681
798
|
}
|
|
682
799
|
const settlement = this.#settle(entry, outcome, {
|
|
800
|
+
settleReason: ANSWER_SETTLE_REASON[outcome],
|
|
683
801
|
...params.verdict !== undefined ? { verdict: params.verdict } : {},
|
|
684
802
|
...params.behavior !== undefined ? { behavior: params.behavior } : {},
|
|
685
803
|
...params.answers !== undefined ? { answers: params.answers } : {},
|
|
@@ -704,13 +822,28 @@ class AskRegistry {
|
|
|
704
822
|
askKind: input.kind,
|
|
705
823
|
sessionId: redactIdentifier(input.sessionId) ?? input.sessionId,
|
|
706
824
|
turnId: redactIdentifier(input.turnId) ?? input.turnId,
|
|
825
|
+
...redactIdentifier(input.toolName) !== undefined ? { toolName: redactIdentifier(input.toolName) } : {},
|
|
826
|
+
...redactIdentifier(input.childSessionId) !== undefined ? { childSessionId: redactIdentifier(input.childSessionId) } : {},
|
|
707
827
|
verdict: "unavailable",
|
|
708
828
|
outcome: "unavailable",
|
|
829
|
+
settleReason: "no-channel",
|
|
709
830
|
code: ASK_ERROR_CODES.CHANNEL_UNAVAILABLE,
|
|
710
831
|
source: "fail-closed",
|
|
711
832
|
at: settlement.at
|
|
712
833
|
});
|
|
713
|
-
this.#
|
|
834
|
+
this.#emitTerminal({
|
|
835
|
+
type: ASK_FRAME_TYPES.SETTLED,
|
|
836
|
+
payload: {
|
|
837
|
+
eventId,
|
|
838
|
+
outcome: "unavailable",
|
|
839
|
+
reason: "no-channel",
|
|
840
|
+
sessionId: input.sessionId,
|
|
841
|
+
kind: input.kind,
|
|
842
|
+
...input.toolName !== undefined ? { toolName: input.toolName } : {},
|
|
843
|
+
...input.callId !== undefined ? { callId: input.callId } : {},
|
|
844
|
+
...input.childSessionId !== undefined ? { childSessionId: input.childSessionId } : {}
|
|
845
|
+
}
|
|
846
|
+
});
|
|
714
847
|
return { settlement, code: ASK_ERROR_CODES.CHANNEL_UNAVAILABLE };
|
|
715
848
|
}
|
|
716
849
|
markDetached(sessionId) {
|
|
@@ -719,6 +852,7 @@ class AskRegistry {
|
|
|
719
852
|
continue;
|
|
720
853
|
entry.graceTimer = this.#arm(() => {
|
|
721
854
|
this.#settle(entry, "cancelled", {
|
|
855
|
+
settleReason: "detached",
|
|
722
856
|
cancelReason: "host-abort",
|
|
723
857
|
code: ASK_ERROR_CODES.TURN_ENDED,
|
|
724
858
|
message: "client detached past the grace window",
|
|
@@ -740,7 +874,7 @@ class AskRegistry {
|
|
|
740
874
|
for (const entry of [...this.#pending.values()]) {
|
|
741
875
|
if (entry.turnId !== turnId)
|
|
742
876
|
continue;
|
|
743
|
-
out.push(this.#settle(entry, "cancelled", { cancelReason: reason, ended: true, message: "turn ended" }));
|
|
877
|
+
out.push(this.#settle(entry, "cancelled", { settleReason: "turn-ended", cancelReason: reason, ended: true, message: "turn ended" }));
|
|
744
878
|
}
|
|
745
879
|
return out;
|
|
746
880
|
}
|
|
@@ -749,7 +883,7 @@ class AskRegistry {
|
|
|
749
883
|
for (const entry of [...this.#pending.values()]) {
|
|
750
884
|
if (entry.deliveredTo !== sessionId)
|
|
751
885
|
continue;
|
|
752
|
-
out.push(this.#settle(entry, "cancelled", { cancelReason: reason, ended: true, message: "session ended" }));
|
|
886
|
+
out.push(this.#settle(entry, "cancelled", { settleReason: "session-closed", cancelReason: reason, ended: true, message: "session ended" }));
|
|
753
887
|
}
|
|
754
888
|
return out;
|
|
755
889
|
}
|
|
@@ -767,7 +901,6 @@ class AskRegistry {
|
|
|
767
901
|
this.#seqByTurn.clear();
|
|
768
902
|
this.#settledIds.clear();
|
|
769
903
|
this.#endedIds.clear();
|
|
770
|
-
this.#settlementLog.length = 0;
|
|
771
904
|
this.#summary.clear();
|
|
772
905
|
this.#logger?.debug?.("[ask-registry] disposed: all timers released");
|
|
773
906
|
}
|
|
@@ -8481,6 +8614,16 @@ function apply(ctx, config) {
|
|
|
8481
8614
|
return last.slice(0, 80);
|
|
8482
8615
|
}
|
|
8483
8616
|
const pendingAnswerers = new Map;
|
|
8617
|
+
const approvalGateListeners = new Map;
|
|
8618
|
+
function clearApprovalGate(eventId) {
|
|
8619
|
+
const dispose = approvalGateListeners.get(eventId);
|
|
8620
|
+
if (dispose === undefined)
|
|
8621
|
+
return;
|
|
8622
|
+
approvalGateListeners.delete(eventId);
|
|
8623
|
+
try {
|
|
8624
|
+
dispose();
|
|
8625
|
+
} catch {}
|
|
8626
|
+
}
|
|
8484
8627
|
function settleAnswerer(eventId, settlement) {
|
|
8485
8628
|
const pending = pendingAnswerers.get(eventId);
|
|
8486
8629
|
if (pending === undefined)
|
|
@@ -8492,18 +8635,24 @@ function apply(ctx, config) {
|
|
|
8492
8635
|
return new Promise((resolve) => {
|
|
8493
8636
|
const pending = { resolve };
|
|
8494
8637
|
pendingAnswerers.set(eventId, pending);
|
|
8638
|
+
const original = pending.resolve;
|
|
8639
|
+
let onAbort;
|
|
8640
|
+
pending.resolve = (settlement) => {
|
|
8641
|
+
if (signal !== undefined && onAbort !== undefined) {
|
|
8642
|
+
signal.removeEventListener("abort", onAbort);
|
|
8643
|
+
}
|
|
8644
|
+
clearApprovalGate(eventId);
|
|
8645
|
+
original(settlement);
|
|
8646
|
+
};
|
|
8495
8647
|
if (signal !== undefined) {
|
|
8496
|
-
|
|
8648
|
+
onAbort = () => {
|
|
8649
|
+
ask.settleExternal(eventId, { settleReason: "aborted" });
|
|
8497
8650
|
settleAnswerer(eventId, { outcome: "cancelled" });
|
|
8498
|
-
}
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
signal.removeEventListener("abort", onAbort);
|
|
8503
|
-
original(settlement);
|
|
8504
|
-
};
|
|
8651
|
+
};
|
|
8652
|
+
if (signal.aborted)
|
|
8653
|
+
onAbort();
|
|
8654
|
+
else
|
|
8505
8655
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
8506
|
-
}
|
|
8507
8656
|
}
|
|
8508
8657
|
});
|
|
8509
8658
|
}
|
|
@@ -8532,14 +8681,17 @@ function apply(ctx, config) {
|
|
|
8532
8681
|
logger,
|
|
8533
8682
|
journal: writeAskJournal,
|
|
8534
8683
|
sink: (frame) => {
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8684
|
+
try {
|
|
8685
|
+
emitEvent(frame.type, frame.payload);
|
|
8686
|
+
} finally {
|
|
8687
|
+
if (frame.type === ASK_FRAME_TYPES.SETTLED) {
|
|
8688
|
+
const settled = frame.payload;
|
|
8689
|
+
const pending = pendingAnswerers.get(settled.eventId);
|
|
8690
|
+
settleAnswerer(settled.eventId, {
|
|
8691
|
+
outcome: settled.outcome,
|
|
8692
|
+
...pending?.params !== undefined ? { params: pending.params } : {}
|
|
8693
|
+
});
|
|
8694
|
+
}
|
|
8543
8695
|
}
|
|
8544
8696
|
}
|
|
8545
8697
|
});
|
|
@@ -8961,28 +9113,57 @@ function apply(ctx, config) {
|
|
|
8961
9113
|
return { turn: state, sessionId: binding.sessionId, childSessionId: agentSessionId };
|
|
8962
9114
|
}
|
|
8963
9115
|
const FAIL_CLOSED_UNKNOWN_SESSION = "unknown";
|
|
8964
|
-
function failClosedAsk(kind, turnId, sessionId, reason) {
|
|
8965
|
-
const result = ask.failClosed({
|
|
9116
|
+
function failClosedAsk(kind, turnId, sessionId, reason, meta = {}) {
|
|
9117
|
+
const result = ask.failClosed({
|
|
9118
|
+
turnId,
|
|
9119
|
+
sessionId,
|
|
9120
|
+
kind,
|
|
9121
|
+
reason,
|
|
9122
|
+
...meta.toolName !== undefined ? { toolName: meta.toolName } : {},
|
|
9123
|
+
...meta.callId !== undefined ? { callId: meta.callId } : {},
|
|
9124
|
+
...meta.childSessionId !== undefined ? { childSessionId: meta.childSessionId } : {}
|
|
9125
|
+
});
|
|
8966
9126
|
logger.warn("[dsh-opentui-bridge] ask fail-closed kind=%s session=%s eventId=%s code=%s reason=%s", kind, sessionId, result.settlement.eventId, result.code, reason);
|
|
8967
9127
|
}
|
|
9128
|
+
function armApprovalGate(eventId, expiry) {
|
|
9129
|
+
if (expiry === undefined || !pendingAnswerers.has(eventId))
|
|
9130
|
+
return;
|
|
9131
|
+
const signal = expiry.signal;
|
|
9132
|
+
if (signal === undefined || typeof signal.addEventListener !== "function")
|
|
9133
|
+
return;
|
|
9134
|
+
const defaultOutcome = expiry.defaultOutcome === "unavailable" ? "unavailable" : "rejected";
|
|
9135
|
+
const onGateAbort = () => {
|
|
9136
|
+
ask.settleExternal(eventId, { settleReason: "timeout", defaultOutcome });
|
|
9137
|
+
};
|
|
9138
|
+
if (signal.aborted) {
|
|
9139
|
+
onGateAbort();
|
|
9140
|
+
return;
|
|
9141
|
+
}
|
|
9142
|
+
signal.addEventListener("abort", onGateAbort, { once: true });
|
|
9143
|
+
approvalGateListeners.set(eventId, () => signal.removeEventListener("abort", onGateAbort));
|
|
9144
|
+
}
|
|
8968
9145
|
async function onApprovalRequest(raw, _next) {
|
|
8969
9146
|
const req = raw !== null && typeof raw === "object" ? raw : {};
|
|
9147
|
+
const toolName = typeof req.toolName === "string" && req.toolName !== "" ? req.toolName : undefined;
|
|
9148
|
+
const callId = req.callId === undefined ? undefined : idString(req.callId);
|
|
8970
9149
|
const target = askTarget(req.agent);
|
|
8971
9150
|
if (target === undefined) {
|
|
8972
|
-
failClosedAsk("approval", "no-turn", binding?.sessionId ?? FAIL_CLOSED_UNKNOWN_SESSION, "no open in-flight turn to deliver an approval ask"
|
|
9151
|
+
failClosedAsk("approval", "no-turn", binding?.sessionId ?? FAIL_CLOSED_UNKNOWN_SESSION, "no open in-flight turn to deliver an approval ask", {
|
|
9152
|
+
...toolName !== undefined ? { toolName } : {},
|
|
9153
|
+
...callId !== undefined ? { callId } : {}
|
|
9154
|
+
});
|
|
8973
9155
|
return "unavailable";
|
|
8974
9156
|
}
|
|
8975
|
-
const toolName = typeof req.toolName === "string" && req.toolName !== "" ? req.toolName : undefined;
|
|
8976
9157
|
if (toolName !== undefined && ask.hasGrant(target.sessionId, toolName)) {
|
|
8977
9158
|
const grantedEventId = ask.recordSummaryDecision(target.turn.turnId, {
|
|
8978
9159
|
sessionId: target.sessionId,
|
|
8979
9160
|
askKind: "approval",
|
|
8980
|
-
toolName
|
|
9161
|
+
toolName,
|
|
9162
|
+
...target.childSessionId !== undefined ? { childSessionId: target.childSessionId } : {}
|
|
8981
9163
|
});
|
|
8982
9164
|
logger.info("[dsh-opentui-bridge] ask always-grant from session summary: session=%s tool=%s eventId=%s (no card)", target.sessionId, toolName, grantedEventId);
|
|
8983
9165
|
return "allowed-once";
|
|
8984
9166
|
}
|
|
8985
|
-
const callId = req.callId === undefined ? undefined : idString(req.callId);
|
|
8986
9167
|
const reason = typeof req.reason === "string" && req.reason !== "" ? req.reason : undefined;
|
|
8987
9168
|
let request;
|
|
8988
9169
|
try {
|
|
@@ -8997,10 +9178,16 @@ function apply(ctx, config) {
|
|
|
8997
9178
|
});
|
|
8998
9179
|
} catch (err) {
|
|
8999
9180
|
logger.error("[dsh-opentui-bridge] ask.create(approval) failed: %s", err);
|
|
9000
|
-
failClosedAsk("approval", target.turn.turnId, target.sessionId, "ask.create(approval) threw"
|
|
9181
|
+
failClosedAsk("approval", target.turn.turnId, target.sessionId, "ask.create(approval) threw", {
|
|
9182
|
+
...toolName !== undefined ? { toolName } : {},
|
|
9183
|
+
...callId !== undefined ? { callId } : {},
|
|
9184
|
+
...target.childSessionId !== undefined ? { childSessionId: target.childSessionId } : {}
|
|
9185
|
+
});
|
|
9001
9186
|
return "unavailable";
|
|
9002
9187
|
}
|
|
9003
|
-
const
|
|
9188
|
+
const answer = waitForAnswerer(request.eventId, req.signal);
|
|
9189
|
+
armApprovalGate(request.eventId, req.approvalGateExpiry);
|
|
9190
|
+
const settled = await answer;
|
|
9004
9191
|
switch (settled.outcome) {
|
|
9005
9192
|
case "approved":
|
|
9006
9193
|
return "allowed-once";
|
|
@@ -9014,9 +9201,12 @@ function apply(ctx, config) {
|
|
|
9014
9201
|
}
|
|
9015
9202
|
async function onUserQuestionsRequest(raw, _next) {
|
|
9016
9203
|
const req = raw !== null && typeof raw === "object" ? raw : {};
|
|
9204
|
+
const callId = req.wait?.callId === undefined ? undefined : idString(req.wait.callId);
|
|
9017
9205
|
const target = askTarget(req.agent);
|
|
9018
9206
|
if (target === undefined) {
|
|
9019
|
-
failClosedAsk("questions", "no-turn", binding?.sessionId ?? FAIL_CLOSED_UNKNOWN_SESSION, "no open in-flight turn to deliver a questions ask"
|
|
9207
|
+
failClosedAsk("questions", "no-turn", binding?.sessionId ?? FAIL_CLOSED_UNKNOWN_SESSION, "no open in-flight turn to deliver a questions ask", {
|
|
9208
|
+
...callId !== undefined ? { callId } : {}
|
|
9209
|
+
});
|
|
9020
9210
|
throw new Error("ASK_CHANNEL_UNAVAILABLE: no in-flight turn to deliver user questions");
|
|
9021
9211
|
}
|
|
9022
9212
|
const questions = (req.questions ?? []).map((q) => {
|
|
@@ -9035,7 +9225,6 @@ function apply(ctx, config) {
|
|
|
9035
9225
|
...q.multiSelect === true ? { multiSelect: true } : {}
|
|
9036
9226
|
};
|
|
9037
9227
|
});
|
|
9038
|
-
const callId = req.wait?.callId === undefined ? undefined : idString(req.wait.callId);
|
|
9039
9228
|
let request;
|
|
9040
9229
|
try {
|
|
9041
9230
|
request = ask.create(target.turn.turnId, {
|
|
@@ -9047,7 +9236,10 @@ function apply(ctx, config) {
|
|
|
9047
9236
|
});
|
|
9048
9237
|
} catch (err) {
|
|
9049
9238
|
logger.error("[dsh-opentui-bridge] ask.create(questions) failed: %s", err);
|
|
9050
|
-
failClosedAsk("questions", target.turn.turnId, target.sessionId, "ask.create(questions) threw"
|
|
9239
|
+
failClosedAsk("questions", target.turn.turnId, target.sessionId, "ask.create(questions) threw", {
|
|
9240
|
+
...callId !== undefined ? { callId } : {},
|
|
9241
|
+
...target.childSessionId !== undefined ? { childSessionId: target.childSessionId } : {}
|
|
9242
|
+
});
|
|
9051
9243
|
throw new Error("ASK_CHANNEL_UNAVAILABLE: ask.create(questions) failed");
|
|
9052
9244
|
}
|
|
9053
9245
|
const settled = await waitForAnswerer(request.eventId, req.signal);
|
|
@@ -9866,9 +10058,18 @@ function apply(ctx, config) {
|
|
|
9866
10058
|
clearTurnSubscriptions();
|
|
9867
10059
|
pushRelay.stopAll();
|
|
9868
10060
|
accountRelay.stopAll();
|
|
10061
|
+
for (const eventId of ask.pendingIds()) {
|
|
10062
|
+
ask.settleExternal(eventId, { settleReason: "connection-closed" });
|
|
10063
|
+
}
|
|
9869
10064
|
for (const eventId of [...pendingAnswerers.keys()]) {
|
|
9870
10065
|
settleAnswerer(eventId, { outcome: "cancelled" });
|
|
9871
10066
|
}
|
|
10067
|
+
for (const dispose of [...approvalGateListeners.values()]) {
|
|
10068
|
+
try {
|
|
10069
|
+
dispose();
|
|
10070
|
+
} catch {}
|
|
10071
|
+
}
|
|
10072
|
+
approvalGateListeners.clear();
|
|
9872
10073
|
try {
|
|
9873
10074
|
unsubApprovalAnswerer?.();
|
|
9874
10075
|
} catch {}
|