@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.
@@ -36697,6 +36697,14 @@ var init_dock_visibility = __esm(() => {
36697
36697
 
36698
36698
  // ../tui-base/src/routes/session/seam-rows.ts
36699
36699
  function toStoredRow(stored, index) {
36700
+ if (stored.kind === "notice") {
36701
+ return {
36702
+ key: `notice:${stored.id ?? "ask-outcome:unknown"}`,
36703
+ kind: "assistant",
36704
+ text: stored.text,
36705
+ final: true
36706
+ };
36707
+ }
36700
36708
  const kind = stored.kind === "user" || stored.kind === "tool" || stored.kind === "ask" ? stored.kind : "assistant";
36701
36709
  const key = `stored:${kind}:${index}`;
36702
36710
  if (kind === "tool") {
@@ -55041,7 +55049,7 @@ var init_subagents_viewer = __esm(() => {
55041
55049
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
55042
55050
  function resolveVersion() {
55043
55051
  try {
55044
- return "0.28.1";
55052
+ return "0.28.2";
55045
55053
  } catch {
55046
55054
  return "dev";
55047
55055
  }
@@ -56624,7 +56632,7 @@ function createBtwSnapshotBuilder(seam) {
56624
56632
  return [];
56625
56633
  try {
56626
56634
  const rows = await seam.storedTranscript(id);
56627
- return rows.slice(-BTW_SNAPSHOT_ROWS).map((row) => `${row.kind}: ${row.text}`.slice(0, BTW_SNAPSHOT_ROW_CHARS));
56635
+ return rows.filter((row) => row.kind !== "notice").slice(-BTW_SNAPSHOT_ROWS).map((row) => `${row.kind}: ${row.text}`.slice(0, BTW_SNAPSHOT_ROW_CHARS));
56628
56636
  } catch {
56629
56637
  return [];
56630
56638
  }
@@ -57708,6 +57716,85 @@ var init_journal_projection = __esm(() => {
57708
57716
  NOTICE_SOURCE_KINDS = new Set(["subagent-settled", "agent-message", "team-message", "webhook"]);
57709
57717
  });
57710
57718
 
57719
+ // src/client/ask-outcome.ts
57720
+ function legacyReason(input) {
57721
+ if (input.journalKind === "ask.responded") {
57722
+ if (input.outcome === "denied")
57723
+ return "rejected";
57724
+ if (input.outcome === "approved" && input.source === "answer")
57725
+ return "answered";
57726
+ if (input.outcome === "unavailable" && input.source === "fail-closed")
57727
+ return "no-channel";
57728
+ return "unrecorded";
57729
+ }
57730
+ if (input.journalKind === "ask.cancelled") {
57731
+ if (input.cancelReason === "deadline")
57732
+ return "timeout";
57733
+ if (input.cancelReason === "host-abort")
57734
+ return "ended";
57735
+ return "unrecorded";
57736
+ }
57737
+ if (input.outcome === "approved")
57738
+ return "answered";
57739
+ if (input.outcome === "denied")
57740
+ return "rejected";
57741
+ if (input.outcome === "unavailable")
57742
+ return "no-channel";
57743
+ return "unrecorded";
57744
+ }
57745
+ function reasonText(reason) {
57746
+ if (reason === "ended")
57747
+ return LEGACY_ENDED_TEXT;
57748
+ if (reason === "unrecorded")
57749
+ return LEGACY_UNRECORDED_TEXT;
57750
+ return SETTLE_TEXT[reason] ?? LEGACY_UNRECORDED_TEXT;
57751
+ }
57752
+ function deriveAskOutcomeNotice(input) {
57753
+ if (input.eventId === "" || input.sessionId === "" || input.sessionId === "unknown")
57754
+ return;
57755
+ if (input.source === "summary")
57756
+ return;
57757
+ if (!input.orphan && input.askKind === "questions" && input.outcome === "approved" && input.childSessionId === undefined) {
57758
+ return;
57759
+ }
57760
+ const text = input.orphan ? LEGACY_ORPHAN_TEXT : reasonText(input.settleReason !== undefined && CLOSED_SETTLE_REASONS.has(input.settleReason) ? input.settleReason : legacyReason(input));
57761
+ return {
57762
+ id: `ask-outcome:${input.eventId}`,
57763
+ text,
57764
+ anchorSeq: input.anchorSeq,
57765
+ sessionId: input.sessionId
57766
+ };
57767
+ }
57768
+ var CLOSED_SETTLE_REASONS, SETTLE_TEXT, LEGACY_ENDED_TEXT = "\u8BE5\u8BF7\u6C42\u5DF2\u7ED3\u675F\uFF08\u65E7\u65E5\u5FD7\u672A\u7EC6\u5206\uFF09", LEGACY_UNRECORDED_TEXT = "\u8BE5\u8BF7\u6C42\u7ED3\u5C40\u672A\u8BB0\u5F55\uFF08\u65E7\u65E5\u5FD7\u672A\u7EC6\u5206\uFF09", LEGACY_ORPHAN_TEXT = "\u672A\u6536\u5230\u8BE5\u8BF7\u6C42\u7684\u56DE\u7B54\u7ED3\u679C";
57769
+ var init_ask_outcome = __esm(() => {
57770
+ CLOSED_SETTLE_REASONS = new Set([
57771
+ "answered",
57772
+ "rejected",
57773
+ "unavailable",
57774
+ "timeout",
57775
+ "aborted",
57776
+ "turn-ended",
57777
+ "session-closed",
57778
+ "detached",
57779
+ "connection-closed",
57780
+ "no-channel",
57781
+ "auto-approved"
57782
+ ]);
57783
+ SETTLE_TEXT = {
57784
+ answered: "\u5DF2\u6536\u5230\u8BE5\u8BF7\u6C42\u7684\u56DE\u7B54",
57785
+ rejected: "\u8BE5\u8BF7\u6C42\u5DF2\u88AB\u62D2\u7EDD",
57786
+ unavailable: "\u8BE5\u8BF7\u6C42\u65E0\u53EF\u7528\u56DE\u7B54\u6E20\u9053",
57787
+ timeout: "\u7B49\u5F85\u8BE5\u8BF7\u6C42\u7684\u56DE\u7B54\u8D85\u65F6",
57788
+ aborted: "\u8BE5\u8BF7\u6C42\u88AB\u4E2D\u6B62",
57789
+ "turn-ended": "\u56DE\u5408\u7ED3\u675F\u65F6\u8BE5\u8BF7\u6C42\u5DF2\u53D6\u6D88",
57790
+ "session-closed": "\u4F1A\u8BDD\u5173\u95ED\u65F6\u8BE5\u8BF7\u6C42\u5DF2\u53D6\u6D88",
57791
+ detached: "\u8BE5\u8BF7\u6C42\u5DF2\u8131\u79BB\u5F53\u524D\u4F1A\u8BDD",
57792
+ "connection-closed": "\u8FDE\u63A5\u5173\u95ED\u65F6\u8BE5\u8BF7\u6C42\u5DF2\u53D6\u6D88",
57793
+ "no-channel": "\u6CA1\u6709\u53EF\u7528\u6295\u9012\u6E20\u9053\uFF0C\u8BE5\u8BF7\u6C42\u672A\u5B8C\u6210",
57794
+ "auto-approved": "\u8BE5\u8BF7\u6C42\u5DF2\u81EA\u52A8\u6279\u51C6"
57795
+ };
57796
+ });
57797
+
57711
57798
  // src/client/bridge-side-session.ts
57712
57799
  import { randomUUID as randomUUID2 } from "crypto";
57713
57800
  function classify(err, stage) {
@@ -59550,7 +59637,7 @@ function foldModelRouteCache(cache, rows) {
59550
59637
  function liveModelRoute(fold) {
59551
59638
  return fold.pending ?? fold.lastUsed;
59552
59639
  }
59553
- function bridgeReplayRowsToSeamTranscript(rows, skip = 0) {
59640
+ function bridgeReplayRowsToSeamTranscript(rows, skip = 0, sessionId) {
59554
59641
  const entries = rows.map((row) => ({
59555
59642
  type: row.type,
59556
59643
  seq: row.seq,
@@ -59558,7 +59645,7 @@ function bridgeReplayRowsToSeamTranscript(rows, skip = 0) {
59558
59645
  data: asRecord12(row.payload)
59559
59646
  }));
59560
59647
  const durable = journalToTranscriptRows(entries, skip);
59561
- return durable.map((row) => {
59648
+ const stored = durable.map((row) => {
59562
59649
  if (row.kind === "ask") {
59563
59650
  return { kind: "ask", text: "", final: true, entries: row.entries };
59564
59651
  }
@@ -59567,11 +59654,177 @@ function bridgeReplayRowsToSeamTranscript(rows, skip = 0) {
59567
59654
  }
59568
59655
  return { kind: row.kind, text: row.text, final: true };
59569
59656
  });
59657
+ if (sessionId === undefined || sessionId === "" || sessionId === "unknown")
59658
+ return stored;
59659
+ const notices = deriveAskOutcomeNoticeViews(rows, sessionId);
59660
+ if (notices.length === 0)
59661
+ return stored;
59662
+ const prefixCounts = new Map;
59663
+ const byInsert = new Map;
59664
+ for (const notice of notices) {
59665
+ let count = prefixCounts.get(notice.anchorSeq);
59666
+ if (count === undefined) {
59667
+ count = journalToTranscriptRows(entries.filter((e) => e.seq <= notice.anchorSeq), 0).length;
59668
+ prefixCounts.set(notice.anchorSeq, count);
59669
+ }
59670
+ const insertAt = Math.max(0, Math.min(stored.length, count - skip));
59671
+ const bucket = byInsert.get(insertAt);
59672
+ if (bucket === undefined)
59673
+ byInsert.set(insertAt, [notice]);
59674
+ else
59675
+ bucket.push(notice);
59676
+ }
59677
+ const merged = [];
59678
+ for (let i = 0;i <= stored.length; i++) {
59679
+ for (const notice of byInsert.get(i) ?? []) {
59680
+ merged.push({ kind: "notice", id: notice.id, text: notice.text, final: true });
59681
+ }
59682
+ if (i < stored.length)
59683
+ merged.push(stored[i]);
59684
+ }
59685
+ return merged;
59570
59686
  }
59571
59687
  function seamReplayEventKey(event) {
59572
59688
  const details = asRecord12(event.details);
59573
59689
  return `${event.type}:${String(details.id ?? details.messageID ?? "")}:${String(asRecord12(details.part).id ?? "")}`;
59574
59690
  }
59691
+ function askJournalKind(row, data) {
59692
+ if (typeof data.kind === "string" && data.kind !== "")
59693
+ return data.kind;
59694
+ const prefix = "plugin:opentui/ask/";
59695
+ if (row.type.startsWith(prefix))
59696
+ return `ask.${row.type.slice(prefix.length)}`;
59697
+ return;
59698
+ }
59699
+ function deriveAskOutcomeNoticeViews(rows, sessionId) {
59700
+ const out = [];
59701
+ const terminals = new Map;
59702
+ for (const row of rows) {
59703
+ const data = asRecord12(row.payload);
59704
+ const kind = askJournalKind(row, data);
59705
+ if (kind !== "ask.responded" && kind !== "ask.cancelled")
59706
+ continue;
59707
+ const eventId = optionalStringField(data, "eventId");
59708
+ if (eventId === undefined || optionalStringField(data, "sessionId") !== sessionId)
59709
+ continue;
59710
+ const group = terminals.get(eventId);
59711
+ if (group === undefined)
59712
+ terminals.set(eventId, [row]);
59713
+ else
59714
+ group.push(row);
59715
+ }
59716
+ for (const [eventId, group] of terminals) {
59717
+ const ordered = [...group].sort((a, b) => a.seq - b.seq);
59718
+ const canonical = ordered[ordered.length - 1];
59719
+ const noticeOf = (row) => {
59720
+ const data = asRecord12(row.payload);
59721
+ return deriveAskOutcomeNotice({
59722
+ eventId,
59723
+ sessionId,
59724
+ anchorSeq: row.seq,
59725
+ settleReason: optionalStringField(data, "settleReason"),
59726
+ journalKind: askJournalKind(row, data),
59727
+ askKind: optionalStringField(data, "askKind"),
59728
+ outcome: optionalStringField(data, "outcome"),
59729
+ source: optionalStringField(data, "source"),
59730
+ cancelReason: optionalStringField(data, "reason"),
59731
+ childSessionId: optionalStringField(data, "childSessionId")
59732
+ });
59733
+ };
59734
+ const canonicalNotice = noticeOf(canonical);
59735
+ if (canonicalNotice === undefined)
59736
+ continue;
59737
+ const canonicalChild = optionalStringField(asRecord12(canonical.payload), "childSessionId");
59738
+ out.push({
59739
+ id: canonicalNotice.id,
59740
+ text: canonicalNotice.text,
59741
+ anchorSeq: canonicalNotice.anchorSeq,
59742
+ sessionId,
59743
+ ...canonicalChild !== undefined ? { childSessionId: canonicalChild } : {}
59744
+ });
59745
+ const seenText = new Set([canonicalNotice.text]);
59746
+ for (const row of ordered) {
59747
+ if (row === canonical)
59748
+ continue;
59749
+ const other = noticeOf(row);
59750
+ if (other === undefined || seenText.has(other.text))
59751
+ continue;
59752
+ seenText.add(other.text);
59753
+ const childSessionId = optionalStringField(asRecord12(row.payload), "childSessionId");
59754
+ out.push({
59755
+ id: `${other.id}:seq-${row.seq}`,
59756
+ text: `\u3010\u65E5\u5FD7\u7ED3\u5C40\u51B2\u7A81\u3011${other.text}`,
59757
+ anchorSeq: other.anchorSeq,
59758
+ sessionId,
59759
+ ...childSessionId !== undefined ? { childSessionId } : {}
59760
+ });
59761
+ }
59762
+ }
59763
+ const terminalIds = new Set(terminals.keys());
59764
+ const turnEnds = new Map;
59765
+ for (const row of rows) {
59766
+ if (row.type !== "turn/end")
59767
+ continue;
59768
+ const data = asRecord12(row.payload);
59769
+ const keys = [optionalStringField(data, "turnId")];
59770
+ if (typeof data.turn === "number" && Number.isFinite(data.turn))
59771
+ keys.push(String(data.turn));
59772
+ for (const key of keys) {
59773
+ if (key === undefined)
59774
+ continue;
59775
+ const prior = turnEnds.get(key);
59776
+ if (prior === undefined || row.seq > prior.seq)
59777
+ turnEnds.set(key, row);
59778
+ }
59779
+ }
59780
+ for (const row of rows) {
59781
+ const data = asRecord12(row.payload);
59782
+ if (askJournalKind(row, data) !== "ask.requested")
59783
+ continue;
59784
+ const eventId = optionalStringField(data, "eventId");
59785
+ if (eventId === undefined || terminalIds.has(eventId))
59786
+ continue;
59787
+ if (optionalStringField(data, "sessionId") !== sessionId)
59788
+ continue;
59789
+ const turnKey = optionalStringField(data, "turnId") ?? askTurnId(eventId);
59790
+ if (turnKey === undefined || turnKey === "")
59791
+ continue;
59792
+ const turnEnd = turnEnds.get(turnKey);
59793
+ if (turnEnd === undefined)
59794
+ continue;
59795
+ const notice = deriveAskOutcomeNotice({
59796
+ eventId,
59797
+ sessionId,
59798
+ anchorSeq: turnEnd.seq,
59799
+ orphan: true,
59800
+ askKind: optionalStringField(data, "askKind"),
59801
+ childSessionId: optionalStringField(data, "childSessionId")
59802
+ });
59803
+ if (notice !== undefined) {
59804
+ const childSessionId = optionalStringField(data, "childSessionId");
59805
+ out.push({
59806
+ id: notice.id,
59807
+ text: notice.text,
59808
+ anchorSeq: notice.anchorSeq,
59809
+ sessionId,
59810
+ ...childSessionId !== undefined ? { childSessionId } : {}
59811
+ });
59812
+ }
59813
+ }
59814
+ return out;
59815
+ }
59816
+ function askOutcomeEvent(view) {
59817
+ return {
59818
+ type: "message.updated",
59819
+ details: {
59820
+ id: view.id,
59821
+ role: "notice",
59822
+ text: view.text,
59823
+ sessionID: view.sessionId,
59824
+ ...view.childSessionId !== undefined ? { childSessionId: view.childSessionId } : {}
59825
+ }
59826
+ };
59827
+ }
59575
59828
  function bridgeReplayRowsToSeamEvents(rows, sessionId) {
59576
59829
  const events = [];
59577
59830
  const seen = new Set;
@@ -59582,6 +59835,14 @@ function bridgeReplayRowsToSeamEvents(rows, sessionId) {
59582
59835
  seen.add(key);
59583
59836
  events.push(event);
59584
59837
  };
59838
+ const noticeViews = [...deriveAskOutcomeNoticeViews(rows, sessionId)].sort((a, b) => a.anchorSeq - b.anchorSeq);
59839
+ let nextNotice = 0;
59840
+ const flushNoticesThrough = (seq) => {
59841
+ while (nextNotice < noticeViews.length && noticeViews[nextNotice].anchorSeq <= seq) {
59842
+ push(askOutcomeEvent(noticeViews[nextNotice]));
59843
+ nextNotice++;
59844
+ }
59845
+ };
59585
59846
  const toolCalls = new Map;
59586
59847
  for (const row of rows) {
59587
59848
  const entry = { type: row.type, seq: row.seq, time: 0, data: asRecord12(row.payload) };
@@ -59622,7 +59883,9 @@ function bridgeReplayRowsToSeamEvents(rows, sessionId) {
59622
59883
  });
59623
59884
  }
59624
59885
  }
59886
+ flushNoticesThrough(row.seq);
59625
59887
  }
59888
+ flushNoticesThrough(Number.POSITIVE_INFINITY);
59626
59889
  return events;
59627
59890
  }
59628
59891
  function bridgeAgentRunKey(runId, seq) {
@@ -59843,7 +60106,7 @@ function bridgeChildJournalMeta(rows) {
59843
60106
  };
59844
60107
  }
59845
60108
  function bridgeReplayRowsToChildLog(rows) {
59846
- return bridgeReplayRowsToSeamTranscript(rows).map((row) => {
60109
+ return bridgeReplayRowsToSeamTranscript(rows).filter((row) => row.kind !== "notice").map((row) => {
59847
60110
  if (row.kind === "tool") {
59848
60111
  return row.output ? `\u25B6 ${row.text}
59849
60112
  \u23BF ${row.output}` : `\u25B6 ${row.text}`;
@@ -60412,6 +60675,7 @@ class BridgeSessionSeam {
60412
60675
  #deadInFlight;
60413
60676
  #inFlightPartial = "";
60414
60677
  #invalidatedAsks = new Map;
60678
+ #emittedAskOutcomes = new Set;
60415
60679
  #disposed = false;
60416
60680
  constructor(options) {
60417
60681
  this.#transport = options.transport;
@@ -60609,7 +60873,7 @@ class BridgeSessionSeam {
60609
60873
  this.#foldAgentReplayRows(drained.rows, boundId);
60610
60874
  this.#foldModelRouteFromDrain(boundId, drained.rows, from);
60611
60875
  await this.#sweepSubagents(boundId);
60612
- const rows = bridgeReplayRowsToSeamTranscript(drained.rows);
60876
+ const rows = bridgeReplayRowsToSeamTranscript(drained.rows, 0, boundId);
60613
60877
  if (drained.rows.length > 0) {
60614
60878
  const maxSeq = drained.rows.reduce((m, row) => Math.max(m, row.seq), -Infinity);
60615
60879
  this.#lastAppliedSeq = Math.max(this.#lastAppliedSeq ?? 0, maxSeq);
@@ -61432,7 +61696,7 @@ class BridgeSessionSeam {
61432
61696
  const rows = Array.isArray(asRecord12(value).rows) ? asRecord12(value).rows : [];
61433
61697
  this.#foldAgentReplayRows(rows, id);
61434
61698
  this.#sweepSubagents(id);
61435
- return bridgeReplayRowsToSeamTranscript(rows, skip);
61699
+ return bridgeReplayRowsToSeamTranscript(rows, skip, id);
61436
61700
  }
61437
61701
  async sessionJournal(id) {
61438
61702
  const value = await this.#transport.request("journal.replay", { sessionId: id });
@@ -61941,6 +62205,33 @@ class BridgeSessionSeam {
61941
62205
  const eventId = optionalStringField(payload, "eventId");
61942
62206
  if (eventId !== undefined)
61943
62207
  this.#settlePendingAsk(eventId);
62208
+ const bound = this.currentSessionId();
62209
+ const sid = optionalStringField(payload, "sessionId");
62210
+ const childSessionId = optionalStringField(payload, "childSessionId");
62211
+ if (eventId !== undefined && bound !== undefined && sid === bound && !this.#emittedAskOutcomes.has(eventId)) {
62212
+ const notice = deriveAskOutcomeNotice({
62213
+ eventId,
62214
+ sessionId: sid,
62215
+ anchorSeq: 0,
62216
+ settleReason: optionalStringField(payload, "reason"),
62217
+ askKind: optionalStringField(payload, "kind"),
62218
+ outcome: optionalStringField(payload, "outcome"),
62219
+ childSessionId
62220
+ });
62221
+ if (notice !== undefined) {
62222
+ this.#emittedAskOutcomes.add(eventId);
62223
+ this.#emitEvent({
62224
+ type: "message.updated",
62225
+ details: {
62226
+ id: notice.id,
62227
+ role: "notice",
62228
+ text: notice.text,
62229
+ sessionID: notice.sessionId,
62230
+ ...childSessionId !== undefined ? { childSessionId } : {}
62231
+ }
62232
+ });
62233
+ }
62234
+ }
61944
62235
  return true;
61945
62236
  }
61946
62237
  case "ask.pending": {
@@ -62144,6 +62435,7 @@ var CONFIRM_REQUIRED = (method) => new BridgeProtocolError("CONFIRM_REQUIRED", `
62144
62435
  var init_bridge_session_seam = __esm(() => {
62145
62436
  init_remote_session_ops();
62146
62437
  init_journal_projection();
62438
+ init_ask_outcome();
62147
62439
  init_bridge_side_session();
62148
62440
  init_loop();
62149
62441
  init_local_config_faces();
@@ -63685,5 +63977,5 @@ if (import.meta.main) {
63685
63977
  main();
63686
63978
  }
63687
63979
 
63688
- //# debugId=9C3AA1DB8B7B933364756E2164756E21
63980
+ //# debugId=DAD2522A36CE287C64756E2164756E21
63689
63981
  //# sourceMappingURL=index.js.map