@athenaintel/react 0.26.3 → 0.26.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +18 -0
  2. package/dist/auth/AthenaAuthProvider.d.ts +1 -1
  3. package/dist/auth/AthenaSSOProvider.d.ts +1 -1
  4. package/dist/chat/StatewireApprovalCard.cjs +68 -9
  5. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  6. package/dist/chat/StatewireApprovalCard.d.ts +0 -31
  7. package/dist/chat/StatewireApprovalCard.js +70 -11
  8. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  9. package/dist/chat/super-grouping/CollapsibleGroup.d.ts +1 -1
  10. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +2 -2
  11. package/dist/chat/super-grouping/ToolTimeline.d.ts +1 -1
  12. package/dist/chat/use-statewire-approval-request.cjs +6 -1
  13. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  14. package/dist/chat/use-statewire-approval-request.d.ts +20 -0
  15. package/dist/chat/use-statewire-approval-request.js +6 -1
  16. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  17. package/dist/chat-ui/header/chat-header.cjs +4 -4
  18. package/dist/chat-ui/header/chat-header.cjs.map +1 -1
  19. package/dist/chat-ui/header/chat-header.d.ts +3 -3
  20. package/dist/chat-ui/header/chat-header.js +1 -1
  21. package/dist/chat-ui/header/chat-header.js.map +1 -1
  22. package/dist/chat-ui/header/conversation-history-panel.d.ts +1 -1
  23. package/dist/chat-ui/index.cjs +8 -7
  24. package/dist/chat-ui/index.cjs.map +1 -1
  25. package/dist/chat-ui/index.d.ts +2 -1
  26. package/dist/chat-ui/index.js +2 -1
  27. package/dist/chat-ui/index.js.map +1 -1
  28. package/dist/chat-ui/markdown-storage.cjs +2 -1
  29. package/dist/chat-ui/markdown-storage.cjs.map +1 -1
  30. package/dist/chat-ui/markdown-storage.d.ts +3 -0
  31. package/dist/chat-ui/markdown-storage.js +2 -1
  32. package/dist/chat-ui/markdown-storage.js.map +1 -1
  33. package/dist/chat-ui/mentions/suggestions/components/mention-icon.d.ts +1 -1
  34. package/dist/chat-ui/mentions/suggestions/components/menu-breadcrumbs.d.ts +1 -1
  35. package/dist/chat-ui/mentions/suggestions/components/menu-item.d.ts +1 -1
  36. package/dist/chat-ui/mentions/suggestions/components/menu-list.d.ts +1 -1
  37. package/dist/chat-ui/mentions/suggestions/components/menu-skeleton.d.ts +1 -1
  38. package/dist/chat-ui/mentions/suggestions/components/menu-summary.d.ts +1 -1
  39. package/dist/chat-ui/mentions/suggestions/shims.d.ts +1 -1
  40. package/dist/chat-ui/messages/message-components.cjs +13 -59
  41. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  42. package/dist/chat-ui/messages/message-components.d.ts +2 -14
  43. package/dist/chat-ui/messages/message-components.js +2 -47
  44. package/dist/chat-ui/messages/message-components.js.map +1 -1
  45. package/dist/chat-ui/messages/runtime-message.cjs +1 -1
  46. package/dist/chat-ui/messages/runtime-message.cjs.map +1 -1
  47. package/dist/chat-ui/messages/runtime-message.js +1 -1
  48. package/dist/chat-ui/messages/runtime-message.js.map +1 -1
  49. package/dist/chat-ui/messages/thread-chrome.cjs +59 -0
  50. package/dist/chat-ui/messages/thread-chrome.cjs.map +1 -0
  51. package/dist/chat-ui/messages/thread-chrome.d.ts +14 -0
  52. package/dist/chat-ui/messages/thread-chrome.js +59 -0
  53. package/dist/chat-ui/messages/thread-chrome.js.map +1 -0
  54. package/dist/chat-ui/messages/wake-marker.cjs +1 -1
  55. package/dist/chat-ui/messages/wake-marker.cjs.map +1 -1
  56. package/dist/chat-ui/messages/wake-marker.js +1 -1
  57. package/dist/chat-ui/messages/wake-marker.js.map +1 -1
  58. package/dist/chat-ui/rich-text/chat-link.d.ts +2 -2
  59. package/dist/chat-ui/rich-text/chat-message-body.d.ts +1 -1
  60. package/dist/chat-ui/rich-text/chat-node-views.d.ts +5 -5
  61. package/dist/chat-ui/rich-text/chat-text-schema.cjs +9 -1
  62. package/dist/chat-ui/rich-text/chat-text-schema.cjs.map +1 -1
  63. package/dist/chat-ui/rich-text/chat-text-schema.d.ts +7 -0
  64. package/dist/chat-ui/rich-text/chat-text-schema.js +9 -1
  65. package/dist/chat-ui/rich-text/chat-text-schema.js.map +1 -1
  66. package/dist/chat-ui/thread/chat-composer-dock.d.ts +1 -1
  67. package/dist/chat-ui/thread/chat-thread-shell.cjs +4 -3
  68. package/dist/chat-ui/thread/chat-thread-shell.cjs.map +1 -1
  69. package/dist/chat-ui/thread/chat-thread-shell.d.ts +1 -1
  70. package/dist/chat-ui/thread/chat-thread-shell.js +2 -1
  71. package/dist/chat-ui/thread/chat-thread-shell.js.map +1 -1
  72. package/dist/composer/AttachmentContext.d.ts +1 -1
  73. package/dist/composer/QuoteContext.d.ts +1 -1
  74. package/dist/lib/posthog/before-send.cjs +12 -0
  75. package/dist/lib/posthog/before-send.cjs.map +1 -1
  76. package/dist/lib/posthog/before-send.js +12 -0
  77. package/dist/lib/posthog/before-send.js.map +1 -1
  78. package/dist/packages/agent-runtime/src/generated/runconfig-contract.cjs +2 -0
  79. package/dist/packages/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  80. package/dist/packages/agent-runtime/src/generated/runconfig-contract.js +2 -0
  81. package/dist/packages/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  82. package/dist/packages/agent-runtime/src/messages.cjs +15 -1
  83. package/dist/packages/agent-runtime/src/messages.cjs.map +1 -1
  84. package/dist/packages/agent-runtime/src/messages.js +15 -1
  85. package/dist/packages/agent-runtime/src/messages.js.map +1 -1
  86. package/dist/packages/react/package.json.cjs +1 -1
  87. package/dist/packages/react/package.json.js +1 -1
  88. package/dist/packages/tiptap-markdown-table/src/markdown-table-serializer.cjs +114 -0
  89. package/dist/packages/tiptap-markdown-table/src/markdown-table-serializer.cjs.map +1 -0
  90. package/dist/packages/tiptap-markdown-table/src/markdown-table-serializer.js +114 -0
  91. package/dist/packages/tiptap-markdown-table/src/markdown-table-serializer.js.map +1 -0
  92. package/dist/provider/AthenaProvider.d.ts +1 -1
  93. package/dist/provider/PostHogProvider.d.ts +1 -1
  94. package/dist/threads/SessionList.d.ts +1 -1
  95. package/dist/threads/ThreadList.d.ts +1 -1
  96. package/dist/threads/statewire-thread-list.d.ts +1 -1
  97. package/dist/tools/primitives.d.ts +3 -3
  98. package/dist/tools/tool-fallback.d.ts +8 -8
  99. package/dist/ui/button.d.ts +1 -1
  100. package/dist/ui/collapsible.d.ts +3 -3
  101. package/dist/ui/popover.d.ts +3 -3
  102. package/dist/ui/tooltip.d.ts +4 -4
  103. package/dist/voice/use-athena-voice-session.cjs.map +1 -1
  104. package/dist/voice/use-athena-voice-session.d.ts +5 -0
  105. package/dist/voice/use-athena-voice-session.js.map +1 -1
  106. package/package.json +3 -2
package/README.md CHANGED
@@ -429,6 +429,14 @@ mobile tools) are not part of the hook's contract. Omit the field for the
429
429
  server's default set; pass `[]` for pure conversation. The server refuses
430
430
  unknown names with a 422.
431
431
 
432
+ **Silent start.** By default the agent opens the call with a greeting. Pass
433
+ `silent_start: true` and it stays quiet — no greeting audio, no greeting
434
+ transcript turn — until a participant speaks (a deposition witness, a
435
+ customer waiting to be addressed). Replies after that are unchanged.
436
+ Silence is enforced by not asking the model to speak; with the full-duplex
437
+ `gpt-live-1` model the first reply still follows whatever the model hears, so
438
+ verify on a real call if a pre-speech greeting would matter.
439
+
432
440
  **Authentication.** Served from a Marathon computer-asset URL, the hook is
433
441
  zero-config: it takes the viewer bearer from `useParentBridge()` and creates
434
442
  the session **as the person using the app**, so it shows up under their
@@ -462,6 +470,16 @@ Both use the same bearer / API key as session creation. The full recipe
462
470
  template skill `voice-session-guide.md`. `createAthenaVoiceSession` is also
463
471
  exported if you hold the bridge state yourself.
464
472
 
473
+ ## What's new in 0.26.5
474
+
475
+ - `useAthenaVoiceSession({ session: { silent_start: true } })` starts the voice agent without its opening greeting; it waits for the first participant to speak. Forwarded to agora's `POST /api/orpheus/create-session`, which needs an agora that accepts `silent_start` (staging from 2026-10-05).
476
+
477
+ ## What's new in 0.26.4
478
+
479
+ **A `|` inside a table cell stays in its cell when a draft is sent.** The composer wrote a pipe inside a table cell bare, so the sent message (and a draft restored into the composer) read it as a cell boundary: `a | b` became two cells, a code span holding `x|y` was split, and the cells after it moved over or were dropped. A pipe inside a cell, code spans and link targets included, is now written as `\|`, which reads back as a literal pipe. Tables without pipes, tables written as HTML and everything outside tables are written as before.
480
+
481
+ No host code changes are needed.
482
+
465
483
  ## What's new in 0.26.3
466
484
 
467
485
  **A thread opens on its newest prompt, not halfway through a long agent run.** When the newest turn is longer than the first page of history, the thread keeps loading until the message that started it shows, along with what came right before it.
@@ -61,4 +61,4 @@ export interface AthenaAuthProviderProps {
61
61
  * }
62
62
  * ```
63
63
  */
64
- export declare function AthenaAuthProvider({ children, authUrl, postLoginRedirectUrl, displayWhileLoading, }: AthenaAuthProviderProps): import("react/jsx-runtime").JSX.Element;
64
+ export declare function AthenaAuthProvider({ children, authUrl, postLoginRedirectUrl, displayWhileLoading, }: AthenaAuthProviderProps): import("react").JSX.Element;
@@ -88,4 +88,4 @@ export interface AthenaSSOProviderProps {
88
88
  * }
89
89
  * ```
90
90
  */
91
- export declare function AthenaSSOProvider({ children, ssoBaseUrl, ssoUserInfoUrl, ssoLoginUrl, ssoLogoutUrl, displayWhileLoading, displayOnError, revalidateOnWindowFocus, }: AthenaSSOProviderProps): import("react/jsx-runtime").JSX.Element | null;
91
+ export declare function AthenaSSOProvider({ children, ssoBaseUrl, ssoUserInfoUrl, ssoLoginUrl, ssoLogoutUrl, displayWhileLoading, displayOnError, revalidateOnWindowFocus, }: AthenaSSOProviderProps): import("react").JSX.Element | null;
@@ -9,6 +9,7 @@ const useStatewireApprovalRequest = require("./use-statewire-approval-request.cj
9
9
  const threadExtras = require("../packages/agent-runtime/src/thread-extras.cjs");
10
10
  const interrupts = require("../packages/agent-runtime/src/interrupts.cjs");
11
11
  const cnfast = require("cnfast");
12
+ const NO_HOST_QUEUED_LANE_DECISIONS = Object.freeze({});
12
13
  const StatewireApprovalCard = (props) => {
13
14
  const extras = react.useAuiState((s) => s.thread.extras);
14
15
  if (!threadExtras.hasStatewireThreadExtras(extras)) return null;
@@ -39,7 +40,8 @@ const StatewireApprovalCardInner = ({
39
40
  abandonedInterrupt,
40
41
  pending,
41
42
  resume,
42
- sendLaneDecisions
43
+ sendLaneDecisions,
44
+ replayQueuedLanes
43
45
  } = useStatewireApprovalRequest.useStatewireApprovalRequest({
44
46
  interruptPredicate,
45
47
  pendingResumeGraceMs,
@@ -48,11 +50,16 @@ const StatewireApprovalCardInner = ({
48
50
  const [dismissedId, setDismissedId] = react$1.useState();
49
51
  const [detailsOverride, setDetailsOverride] = react$1.useState();
50
52
  const [liveSentKey, setLiveSentKey] = react$1.useState();
53
+ const [staleQueuedRequestId, setStaleQueuedRequestId] = react$1.useState();
54
+ const [replayingRequestId, setReplayingRequestId] = react$1.useState();
55
+ const sentLaneIdsRef = react$1.useRef(/* @__PURE__ */ new Set());
56
+ const replayedRequestIdRef = react$1.useRef(void 0);
51
57
  const isLive = request === void 0 && liveHitl !== null;
52
58
  const hitl = isLive ? liveHitl : parkedHitl;
53
59
  const actionRequests = isLive ? liveActionRequests : parkedActionRequests;
54
60
  const laneIds = interrupts.laneInterruptIds(actionRequests);
55
- const undecidedLaneIds = (laneIds == null ? void 0 : laneIds.filter((id) => !(id in queuedLaneDecisions))) ?? null;
61
+ const hostQueuedLaneDecisions = requestId !== void 0 && staleQueuedRequestId === requestId ? NO_HOST_QUEUED_LANE_DECISIONS : queuedLaneDecisions;
62
+ const undecidedLaneIds = (laneIds == null ? void 0 : laneIds.filter((id) => !(id in hostQueuedLaneDecisions))) ?? null;
56
63
  const positional = laneIds === null || !isLive && laneIds.length <= 1;
57
64
  const liveKey = isLive ? (laneIds == null ? void 0 : laneIds.join("|")) ?? null : null;
58
65
  const viewKey = requestId ?? liveKey ?? void 0;
@@ -61,7 +68,55 @@ const StatewireApprovalCardInner = ({
61
68
  prevViewKeyRef.current = viewKey;
62
69
  if (detailsOverride !== void 0) setDetailsOverride(void 0);
63
70
  if (liveSentKey !== void 0) setLiveSentKey(void 0);
71
+ if (laneIds !== null) {
72
+ for (const id of sentLaneIdsRef.current) {
73
+ if (!laneIds.includes(id)) sentLaneIdsRef.current.delete(id);
74
+ }
75
+ }
76
+ }
77
+ if (requestId !== void 0 && staleQueuedRequestId !== void 0 && requestId !== staleQueuedRequestId) {
78
+ setStaleQueuedRequestId(void 0);
79
+ }
80
+ if (requestId !== void 0 && replayingRequestId !== void 0 && requestId !== replayingRequestId) {
81
+ setReplayingRequestId(void 0);
82
+ }
83
+ if (requestId !== void 0 && replayedRequestIdRef.current !== void 0 && requestId !== replayedRequestIdRef.current) {
84
+ replayedRequestIdRef.current = void 0;
64
85
  }
86
+ const context = { request, hitl, actionRequests };
87
+ const handledElsewhere = (isHandledElsewhere == null ? void 0 : isHandledElsewhere(context)) ?? false;
88
+ const replaying = replayingRequestId !== void 0 && replayingRequestId === requestId;
89
+ const queuedLanesAwaitingHost = !isLive && !readOnly && !handledElsewhere && requestId !== void 0 && undecidedLaneIds !== null && undecidedLaneIds.length === 0 && !pending && !replaying;
90
+ const queuedLaneGraceMs = pendingResumeGraceMs ?? interrupts.HITL_PENDING_RESUME_GRACE_MS;
91
+ const laneKey = laneIds == null ? void 0 : laneIds.join("|");
92
+ const onResumeRejectedRef = react$1.useRef(onResumeRejected);
93
+ onResumeRejectedRef.current = onResumeRejected;
94
+ react$1.useEffect(() => {
95
+ if (!queuedLanesAwaitingHost || requestId === void 0 || laneKey === void 0) {
96
+ return void 0;
97
+ }
98
+ const timer = setTimeout(() => {
99
+ const ownQueue = laneKey.split("|").every((id) => sentLaneIdsRef.current.has(id)) && replayedRequestIdRef.current !== requestId;
100
+ if (!ownQueue) {
101
+ setStaleQueuedRequestId(requestId);
102
+ return;
103
+ }
104
+ replayedRequestIdRef.current = requestId;
105
+ setReplayingRequestId(requestId);
106
+ replayQueuedLanes(requestId).then(
107
+ () => {
108
+ setReplayingRequestId((current) => current === requestId ? void 0 : current);
109
+ },
110
+ (error) => {
111
+ var _a2;
112
+ setReplayingRequestId((current) => current === requestId ? void 0 : current);
113
+ setStaleQueuedRequestId(requestId);
114
+ (_a2 = onResumeRejectedRef.current) == null ? void 0 : _a2.call(onResumeRejectedRef, error, requestId);
115
+ }
116
+ );
117
+ }, queuedLaneGraceMs);
118
+ return () => clearTimeout(timer);
119
+ }, [queuedLanesAwaitingHost, requestId, laneKey, queuedLaneGraceMs, replayQueuedLanes]);
65
120
  const decide = react$1.useCallback(
66
121
  (value) => {
67
122
  if (positional || undecidedLaneIds === null) {
@@ -75,10 +130,15 @@ const StatewireApprovalCardInner = ({
75
130
  }
76
131
  const key = undecidedLaneIds.join("|");
77
132
  setLiveSentKey(key);
78
- Promise.resolve(sendLaneDecisions(lanes)).catch((error) => {
79
- setLiveSentKey((current) => current === key ? void 0 : current);
80
- onResumeRejected == null ? void 0 : onResumeRejected(error, undecidedLaneIds[0] ?? "");
81
- });
133
+ Promise.resolve(sendLaneDecisions(lanes)).then(
134
+ () => {
135
+ for (const id of undecidedLaneIds) sentLaneIdsRef.current.add(id);
136
+ },
137
+ (error) => {
138
+ setLiveSentKey((current) => current === key ? void 0 : current);
139
+ onResumeRejected == null ? void 0 : onResumeRejected(error, undecidedLaneIds[0] ?? "");
140
+ }
141
+ );
82
142
  },
83
143
  [positional, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected]
84
144
  );
@@ -117,8 +177,7 @@ const StatewireApprovalCardInner = ({
117
177
  }
118
178
  );
119
179
  }
120
- const context = { request, hitl, actionRequests };
121
- if (isHandledElsewhere == null ? void 0 : isHandledElsewhere(context)) return null;
180
+ if (handledElsewhere) return null;
122
181
  if (isLive && laneIds === null) return null;
123
182
  const message = interrupts.readInterruptMessage(request ? request.payload : liveHitl, fallbackMessage);
124
183
  const toolName = ((_a = hitl == null ? void 0 : hitl.context) == null ? void 0 : _a.tool_name) ?? ((_b = hitl == null ? void 0 : hitl.context) == null ? void 0 : _b.tool_id);
@@ -127,7 +186,7 @@ const StatewireApprovalCardInner = ({
127
186
  const showDetails = hasDetails && (detailsOverride ?? actionRequests.length <= 1);
128
187
  const sessionApprovalOffered = hitl !== null && interrupts.canApproveForSession(actionRequests);
129
188
  const laneDecided = undecidedLaneIds !== null && laneIds !== null && (undecidedLaneIds.length === 0 || liveSentKey === undecidedLaneIds.join("|"));
130
- const locked = pending || laneDecided;
189
+ const locked = pending || laneDecided || replaying;
131
190
  const editor = !readOnly && hitl !== null && renderEditor ? renderEditor({
132
191
  ...context,
133
192
  locked,
@@ -1 +1 @@
1
- {"version":3,"file":"StatewireApprovalCard.cjs","sources":["../../src/chat/StatewireApprovalCard.tsx"],"sourcesContent":["import { useAuiState } from '@assistant-ui/react';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport {\n actionRequestToolCallIds,\n canApproveForSession,\n fanLaneDecision,\n hasStatewireThreadExtras,\n type HitlActionDecision,\n type HitlApprovalPayload,\n hitlResumeActionDecisions,\n hitlResumeApprove,\n hitlResumeApproveForSession,\n hitlResumeReject,\n interruptResumeDecline,\n laneInterruptIds,\n type PendingActionRequest,\n readInterruptMessage,\n} from '@athenaintel/agent-runtime';\nimport {\n CheckCheckIcon,\n CheckIcon,\n ChevronDownIcon,\n TriangleAlertIcon,\n XIcon,\n} from 'lucide-react';\nimport { type FC, type ReactNode, useCallback, useMemo, useRef, useState } from 'react';\nimport { cn } from '../lib/utils';\nimport { Button } from '../ui/button';\nimport {\n type StatewireInterruptPredicate,\n useStatewireApprovalRequest,\n} from './use-statewire-approval-request';\n\n/**\n * Human-in-the-loop approval card for the statewire transport — the one\n * approval UI every Athena chat surface mounts (the SDK's `AthenaChat`, the\n * Chrome side panel, the Office task pane, Olympus).\n *\n * When the deep-agent runtime hits an approval-gated tool call, the backend\n * parks the run on an `interrupt` input request. This card reads that request\n * through `useStatewireApprovalRequest` and answers it with\n * `{ type: 'run/input', requestId, response: { type: 'resume', value } }` —\n * the exact command the backend's resume path consumes. Without an answer the\n * run stays parked forever, so this card must be mounted on every statewire\n * chat surface. On legacy (non-statewire) threads it renders nothing.\n *\n * A gated call raised inside a delegated subagent parks only its lane: the\n * host mirrors that interrupt while the sibling lanes keep streaming, before\n * any input request exists. The card renders the mirrored payload the same\n * way and answers it with `run/lane-input` keyed by the lane's langgraph\n * interrupt id (`laneInterruptIds`); the host queues the decision and applies\n * it the moment the run parks, so the approver never waits on the siblings.\n * Once parked, a payload whose calls all carry interrupt ids resumes as a\n * `lane_decisions` map too — one positional `run/input` can only answer the\n * first of several parked lanes.\n *\n * Host-specific review UIs (subagent cards, email summaries) slot in through\n * `renderDetails`; a host composer that must also OWN the decision (an\n * editable email whose edits have to reach the backend) takes over the\n * details and the decision row through `renderEditor`; requests another\n * surface answers (typed interrupt families, per-lane subagent approvals)\n * stand down through `isHandledElsewhere`; viewers without edit rights see\n * `readOnlyNotice`.\n */\n\n/** The pending request a host slot renders or judges. */\nexport interface StatewireApprovalRequestContext {\n /** The parked input request — `undefined` while the run still streams (a live lane approval). */\n request: StatewireThread.CustomInputRequest | undefined;\n /** The payload narrowed to the Athena HITL approval shape, or `null` for a generic park. */\n hitl: HitlApprovalPayload | null;\n /** Every gated call the approval covers, in decision order (empty for non-HITL parks). */\n actionRequests: PendingActionRequest[];\n}\n\n/** The request a host editor renders, plus the decisions it may send for it. */\nexport interface StatewireApprovalEditorContext extends StatewireApprovalRequestContext {\n /** A decision is in flight (or a live lane already answered); the editor must not send another. */\n locked: boolean;\n /** Whether \"approve all for this session\" may be offered for this batch. */\n sessionApprovalOffered: boolean;\n approve: () => void;\n approveForSession: () => void;\n reject: (reason?: string) => void;\n /**\n * Answer each gated call on its own — the only way an EDITED call reaches\n * the backend. `decision` is asked once per call, in order, so the answer\n * always names exactly the parked calls (a partial map is refused\n * server-side and nothing runs). `null` when the batch cannot take\n * per-action answers: a call without a `tool_call_id`, or a live / multi-\n * lane approval, which resumes per lane and carries no edit.\n */\n decideEach: ((decision: (request: PendingActionRequest) => HitlActionDecision) => void) | null;\n}\n\nexport interface StatewireApprovalCardProps {\n /** Surface-styling overrides merged onto the default classes. */\n classNames?: {\n /** The approval card container. */\n root?: string;\n /** The \"approval was cancelled\" notice container. */\n abandoned?: string;\n /** The disclosed details block. */\n details?: string;\n /** The decision row. */\n actions?: string;\n };\n /** Copy shown when an interrupt payload carries no message. */\n fallbackMessage?: string;\n /**\n * Which pending interrupt this card answers. Defaults to\n * `isApprovalCardInterrupt` (client-tool parks excluded — keep it that way\n * unless the surface handles those itself).\n */\n interruptPredicate?: StatewireInterruptPredicate;\n /**\n * How long a clicked decision keeps the buttons locked when no resume run\n * ever starts (a `run/input` the host rejected before any run began).\n * Defaults to `HITL_PENDING_RESUME_GRACE_MS`.\n */\n pendingResumeGraceMs?: number;\n /**\n * Return true when another surface answers this request (a typed Athena\n * interrupt family, per-lane subagent approval cards). The card renders\n * nothing for it — two surfaces must never answer the same input request.\n */\n isHandledElsewhere?: (context: StatewireApprovalRequestContext) => boolean;\n /**\n * Replace the default argument disclosure (one JSON block per gated call)\n * with a host-specific review UI. Rendered inside the collapsible details\n * region; the decision buttons stay with the card.\n */\n renderDetails?: (context: StatewireApprovalRequestContext) => ReactNode;\n /**\n * Replace BOTH the details region and the decision row with a host\n * composer that decides the request itself through the context's\n * callbacks (an editable email whose edits must be what runs). Return\n * `null`/`undefined` to keep the default card for this request. Not\n * consulted for read-only viewers or non-HITL parks.\n */\n renderEditor?: (context: StatewireApprovalEditorContext) => ReactNode;\n /**\n * The viewer may see the request (it explains why the run is parked) but\n * cannot decide it — answering steers the shared run. Renders\n * `readOnlyNotice` in place of the buttons.\n */\n readOnly?: boolean;\n readOnlyNotice?: ReactNode;\n /**\n * Copy for a park that is not a HITL approval — a typed Athena interrupt\n * this surface has no card for. The only honest action is to decline it\n * (`{ action: 'reject' }`, which every typed raiser treats as a clean user\n * decline); a generic \"Continue\" would be rejected by the raiser's resume\n * schema and surface as a tool error.\n */\n nonHitlNotice?: ReactNode;\n /**\n * The host refused a decision (or the transport lost it). The optimistic\n * fold has rolled back and the request is on screen again with its actions\n * re-enabled; this is where a host tells the user why (a toast, a log line).\n */\n onResumeRejected?: (error: unknown, requestId: string) => void;\n}\n\nexport const StatewireApprovalCard: FC<StatewireApprovalCardProps> = (props) => {\n const extras = useAuiState((s) => s.thread.extras);\n if (!hasStatewireThreadExtras(extras)) return null;\n return <StatewireApprovalCardInner {...props} />;\n};\n\nconst StatewireApprovalCardInner: FC<StatewireApprovalCardProps> = ({\n classNames,\n fallbackMessage,\n interruptPredicate,\n pendingResumeGraceMs,\n isHandledElsewhere,\n renderDetails,\n renderEditor,\n readOnly = false,\n readOnlyNotice = 'Waiting for someone with edit access to respond.',\n nonHitlNotice = 'This request needs an answer this surface cannot collect.',\n onResumeRejected,\n}) => {\n const {\n request,\n requestId,\n hitl: parkedHitl,\n actionRequests: parkedActionRequests,\n liveHitl,\n liveActionRequests,\n queuedLaneDecisions,\n abandonedInterrupt,\n pending,\n resume,\n sendLaneDecisions,\n } = useStatewireApprovalRequest<StatewireThread.InputResponse>({\n interruptPredicate,\n pendingResumeGraceMs,\n onResumeRejected,\n });\n const [dismissedId, setDismissedId] = useState<string>();\n // The card shares the chat column with the thread. A lone gated call is\n // small enough to show inline, but a fan-out of a dozen calls would swallow\n // the conversation, so a batch starts collapsed until someone opens it.\n const [detailsOverride, setDetailsOverride] = useState<boolean>();\n // The live lanes a decision was sent for (joined ids); the buttons stay\n // locked until the host echoes them in `queuedLaneDecisions` or refuses.\n const [liveSentKey, setLiveSentKey] = useState<string>();\n\n const isLive = request === undefined && liveHitl !== null;\n const hitl = isLive ? liveHitl : parkedHitl;\n const actionRequests = isLive ? liveActionRequests : parkedActionRequests;\n const laneIds = laneInterruptIds(actionRequests);\n const undecidedLaneIds = laneIds?.filter((id) => !(id in queuedLaneDecisions)) ?? null;\n // A lone parked lane (or an unstamped batch) answers with one positional\n // `run/input`; that is the only resume the backend binds per-action answers\n // to, so it is the only place an edited call can go.\n const positional = laneIds === null || (!isLive && laneIds.length <= 1);\n const liveKey = isLive ? (laneIds?.join('|') ?? null) : null;\n const viewKey = requestId ?? liveKey ?? undefined;\n\n // A fresh approval gets the default for ITS batch size, not the disclosure\n // the previous one was left in. Reset during render via React's \"previous\n // value\" pattern.\n const prevViewKeyRef = useRef(viewKey);\n if (prevViewKeyRef.current !== viewKey) {\n prevViewKeyRef.current = viewKey;\n if (detailsOverride !== undefined) setDetailsOverride(undefined);\n if (liveSentKey !== undefined) setLiveSentKey(undefined);\n }\n\n const decide = useCallback(\n (value: Record<string, string>) => {\n // Several parked lanes (or a live one) answer by interrupt id: a\n // positional `run/input` would resume only the first and re-park the\n // rest. A lone parked lane keeps the positional resume every host\n // already speaks.\n if (positional || undecidedLaneIds === null) {\n resume(value);\n return;\n }\n const lanes = fanLaneDecision({ interruptIds: undecidedLaneIds, decision: value });\n if (!isLive) {\n sendLaneDecisions(lanes);\n return;\n }\n const key = undecidedLaneIds.join('|');\n setLiveSentKey(key);\n Promise.resolve(sendLaneDecisions(lanes)).catch((error: unknown) => {\n setLiveSentKey((current) => (current === key ? undefined : current));\n onResumeRejected?.(error, undecidedLaneIds[0] ?? '');\n });\n },\n [positional, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected],\n );\n\n const decideEach = useMemo<StatewireApprovalEditorContext['decideEach']>(() => {\n if (actionRequestToolCallIds(actionRequests) === null || !positional) return null;\n return (decision) => {\n const decisions: Record<string, HitlActionDecision> = {};\n for (const request of actionRequests) {\n if (request.toolCallId !== undefined) decisions[request.toolCallId] = decision(request);\n }\n // The edited argument set comes from the wire as JSON; the resume value\n // is that JSON going back.\n resume(hitlResumeActionDecisions(decisions) as StatewireThread.InputResponse);\n };\n }, [actionRequests, positional, resume]);\n\n if (!request && !isLive) {\n if (!abandonedInterrupt || abandonedInterrupt.id === dismissedId) return null;\n return (\n <div\n className={cn(\n 'aui-approval-abandoned flex w-full items-center justify-between gap-3 rounded-xl border border-amber-300 bg-amber-50 px-3 py-2 text-amber-800 text-xs',\n classNames?.abandoned,\n )}\n >\n <p>Approval was cancelled — the run moved on.</p>\n <button\n type=\"button\"\n aria-label=\"Dismiss cancelled approval\"\n onClick={() => setDismissedId(abandonedInterrupt.id)}\n className=\"shrink-0 rounded-md p-1 hover:bg-amber-100\"\n >\n <XIcon className=\"size-3.5\" />\n </button>\n </div>\n );\n }\n\n const context: StatewireApprovalRequestContext = { request, hitl, actionRequests };\n if (isHandledElsewhere?.(context)) return null;\n // A live mirror without lane stamps cannot be answered before the run\n // parks; the parked request renders it then.\n if (isLive && laneIds === null) return null;\n\n const message = readInterruptMessage(request ? request.payload : liveHitl, fallbackMessage);\n const toolName = hitl?.context?.tool_name ?? hitl?.context?.tool_id;\n const pendingCount = hitl?.context?.pending_action_count ?? 1;\n const hasDetails = hitl !== null && actionRequests.length > 0;\n const showDetails = hasDetails && (detailsOverride ?? actionRequests.length <= 1);\n const sessionApprovalOffered = hitl !== null && canApproveForSession(actionRequests);\n const laneDecided =\n undecidedLaneIds !== null &&\n laneIds !== null &&\n (undecidedLaneIds.length === 0 || liveSentKey === undecidedLaneIds.join('|'));\n const locked = pending || laneDecided;\n\n const editor =\n !readOnly && hitl !== null && renderEditor\n ? renderEditor({\n ...context,\n locked,\n sessionApprovalOffered,\n approve: () => decide(hitlResumeApprove()),\n approveForSession: () => decide(hitlResumeApproveForSession()),\n reject: (reason) => decide(hitlResumeReject(reason)),\n decideEach,\n })\n : undefined;\n\n return (\n <section\n aria-label={hitl ? 'Approval required' : 'Input required'}\n className={cn(\n 'aui-approval-card w-full rounded-2xl border border-amber-300 bg-amber-50 px-4 py-3 text-amber-900',\n classNames?.root,\n )}\n >\n <div className=\"flex items-start gap-3\">\n <TriangleAlertIcon className=\"mt-0.5 size-4 shrink-0\" />\n <div className=\"min-w-0 flex-1\">\n <p className=\"flex items-center gap-2 font-semibold text-sm\">\n <span>{hitl ? 'Approval required' : 'Waiting for input'}</span>\n {hitl && pendingCount > 1 ? (\n <span className=\"shrink-0 font-normal text-amber-800 text-xs\">\n {pendingCount} tool calls\n </span>\n ) : null}\n </p>\n <p className=\"pt-1 text-amber-800 text-sm leading-snug\">\n {hitl && pendingCount === 1 && toolName ? (\n <>\n <span className=\"font-mono\">{toolName}</span> requires approval before it runs.\n </>\n ) : (\n message\n )}\n </p>\n {isLive ? (\n <p className=\"pt-1 text-amber-700 text-xs\" data-testid=\"statewire-approval-live\">\n {laneDecided\n ? 'Decision sent — it applies as soon as this step pauses.'\n : 'Other work keeps running while you decide.'}\n </p>\n ) : null}\n {hasDetails && editor == null ? (\n <button\n type=\"button\"\n onClick={() => setDetailsOverride(!showDetails)}\n aria-expanded={showDetails}\n className=\"mt-2 flex items-center gap-1 rounded px-1 py-0.5 text-amber-800 text-xs transition-colors hover:text-amber-950\"\n >\n <ChevronDownIcon\n className={cn('size-3 transition-transform', showDetails && 'rotate-180')}\n />\n {showDetails ? 'Hide details' : 'Review details'}\n </button>\n ) : null}\n {/* EVERY pending gated call renders, in order — one decision\n authorizes the whole batch, so nothing may hide behind a host's\n richer cards. All read-only: this runtime resumes through\n `hitl_response_to_decisions`, which has no `tool_args` channel —\n an editable composer would let someone rewrite an email and then\n watch the original go out — unless the host takes over the\n decision too (`renderEditor`), which sends the edit per call. */}\n {editor != null ? (\n <div className={cn('mt-3 flex flex-col gap-2', classNames?.details)}>{editor}</div>\n ) : showDetails ? (\n <div className={cn('mt-2 flex flex-col gap-2', classNames?.details)}>\n {renderDetails ? (\n renderDetails(context)\n ) : (\n <DefaultApprovalDetails actionRequests={actionRequests} />\n )}\n </div>\n ) : null}\n </div>\n </div>\n {editor != null ? null : (\n <div className={cn('flex flex-wrap items-center gap-2 pt-3', classNames?.actions)}>\n {readOnly ? (\n <p className=\"text-amber-800 text-sm\" data-testid=\"statewire-approval-read-only\">\n {readOnlyNotice}\n </p>\n ) : hitl ? (\n <>\n <Button\n size=\"sm\"\n disabled={locked}\n onClick={() => decide(hitlResumeApprove())}\n className=\"bg-green-600 text-white hover:bg-green-700\"\n >\n <CheckIcon />\n Approve\n </Button>\n {sessionApprovalOffered ? (\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={locked}\n onClick={() => decide(hitlResumeApproveForSession())}\n data-testid=\"statewire-approval-approve-session\"\n >\n <CheckCheckIcon />\n Approve all for this session\n </Button>\n ) : null}\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={locked}\n onClick={() => decide(hitlResumeReject())}\n >\n <XIcon />\n Reject\n </Button>\n </>\n ) : (\n <>\n <p className=\"text-amber-800 text-sm\" data-testid=\"statewire-approval-non-hitl\">\n {nonHitlNotice}\n </p>\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={pending}\n onClick={() => resume(interruptResumeDecline())}\n >\n <XIcon />\n Decline\n </Button>\n </>\n )}\n </div>\n )}\n </section>\n );\n};\n\n/** One block per gated call: its name (when the batch has several) and its arguments as JSON. */\nconst DefaultApprovalDetails: FC<{ actionRequests: PendingActionRequest[] }> = ({\n actionRequests,\n}) => (\n <>\n {actionRequests.map((action, index) => (\n <div\n key={`${action.name}-${index}`}\n className=\"rounded-lg bg-amber-100 p-2 text-amber-900 text-xs leading-relaxed\"\n >\n {actionRequests.length > 1 ? (\n <p className=\"font-mono font-semibold\">{action.name}</p>\n ) : null}\n {Object.keys(action.args).length > 0 ? (\n <pre className=\"mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-words rounded bg-white/60 p-1.5 font-mono text-[11px]\">\n {JSON.stringify(action.args, null, 2)}\n </pre>\n ) : (\n <p className=\"text-amber-800\">No arguments.</p>\n )}\n </div>\n ))}\n </>\n);\n"],"names":["useAuiState","hasStatewireThreadExtras","jsx","useStatewireApprovalRequest","useState","laneInterruptIds","useRef","useCallback","fanLaneDecision","useMemo","actionRequestToolCallIds","request","hitlResumeActionDecisions","jsxs","cn","XIcon","readInterruptMessage","canApproveForSession","hitlResumeApprove","hitlResumeApproveForSession","hitlResumeReject","TriangleAlertIcon","Fragment","ChevronDownIcon","Button","CheckIcon","CheckCheckIcon","interruptResumeDecline"],"mappings":";;;;;;;;;;;AAoKO,MAAM,wBAAwD,CAAC,UAAU;AAC9E,QAAM,SAASA,MAAAA,YAAY,CAAC,MAAM,EAAE,OAAO,MAAM;AACjD,MAAI,CAACC,aAAAA,yBAAyB,MAAM,EAAG,QAAO;AAC9C,SAAOC,+BAAC,4BAAA,EAA4B,GAAG,MAAA,CAAO;AAChD;AAEA,MAAM,6BAA6D,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB;AACF,MAAM;;AACJ,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACEC,wDAA2D;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACD,QAAM,CAAC,aAAa,cAAc,IAAIC,iBAAA;AAItC,QAAM,CAAC,iBAAiB,kBAAkB,IAAIA,iBAAA;AAG9C,QAAM,CAAC,aAAa,cAAc,IAAIA,iBAAA;AAEtC,QAAM,SAAS,YAAY,UAAa,aAAa;AACrD,QAAM,OAAO,SAAS,WAAW;AACjC,QAAM,iBAAiB,SAAS,qBAAqB;AACrD,QAAM,UAAUC,WAAAA,iBAAiB,cAAc;AAC/C,QAAM,oBAAmB,mCAAS,OAAO,CAAC,OAAO,EAAE,MAAM,0BAAyB;AAIlF,QAAM,aAAa,YAAY,QAAS,CAAC,UAAU,QAAQ,UAAU;AACrE,QAAM,UAAU,UAAU,mCAAS,KAAK,SAAQ,OAAQ;AACxD,QAAM,UAAU,aAAa,WAAW;AAKxC,QAAM,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AAK,UAAU,OAAO,MAAM,MAAM,CAAC,EAAA,CACtC,IAEAA,+BAAC,KAAA,EAAE,WAAU,kBAAiB,UAAA,gBAAA,CAAa;AAAA,IAAA;AAAA,EAAA;AAAA,EAXxC,GAAG,OAAO,IAAI,IAAI,KAAK;AAa9B,CACD,GACH;;"}
1
+ {"version":3,"file":"StatewireApprovalCard.cjs","sources":["../../src/chat/StatewireApprovalCard.tsx"],"sourcesContent":["import { useAuiState } from '@assistant-ui/react';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport {\n actionRequestToolCallIds,\n canApproveForSession,\n fanLaneDecision,\n HITL_PENDING_RESUME_GRACE_MS,\n hasStatewireThreadExtras,\n type HitlActionDecision,\n type HitlApprovalPayload,\n hitlResumeActionDecisions,\n hitlResumeApprove,\n hitlResumeApproveForSession,\n hitlResumeReject,\n interruptResumeDecline,\n laneInterruptIds,\n type PendingActionRequest,\n readInterruptMessage,\n} from '@athenaintel/agent-runtime';\nimport {\n CheckCheckIcon,\n CheckIcon,\n ChevronDownIcon,\n TriangleAlertIcon,\n XIcon,\n} from 'lucide-react';\nimport {\n type FC,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { cn } from '../lib/utils';\nimport { Button } from '../ui/button';\nimport {\n type StatewireInterruptPredicate,\n useStatewireApprovalRequest,\n} from './use-statewire-approval-request';\n\n/**\n * Human-in-the-loop approval card for the statewire transport — the one\n * approval UI every Athena chat surface mounts (the SDK's `AthenaChat`, the\n * Chrome side panel, the Office task pane, Olympus).\n *\n * When the deep-agent runtime hits an approval-gated tool call, the backend\n * parks the run on an `interrupt` input request. This card reads that request\n * through `useStatewireApprovalRequest` and answers it with\n * `{ type: 'run/input', requestId, response: { type: 'resume', value } }` —\n * the exact command the backend's resume path consumes. Without an answer the\n * run stays parked forever, so this card must be mounted on every statewire\n * chat surface. On legacy (non-statewire) threads it renders nothing.\n *\n * A gated call raised inside a delegated subagent parks only its lane: the\n * host mirrors that interrupt while the sibling lanes keep streaming, before\n * any input request exists. The card renders the mirrored payload the same\n * way and answers it with `run/lane-input` keyed by the lane's langgraph\n * interrupt id (`laneInterruptIds`); the host queues the decision and applies\n * it the moment the run parks, so the approver never waits on the siblings.\n * Once parked, a payload whose calls all carry interrupt ids resumes as a\n * `lane_decisions` map too — one positional `run/input` can only answer the\n * first of several parked lanes.\n *\n * Recovery of a queued decision the host never applies is ordered host\n * first: the host's answerer resumes the park or drops (and flushes) the\n * queue within `QUEUED_LANE_ANSWER_BUDGET_SECONDS` of the park, and this\n * card's grace (`HITL_PENDING_RESUME_GRACE_MS`, longer than that budget)\n * fires only when the host stayed silent. When it fires, the card that sent\n * the queued decision asks the host to replay it (`run/lane-replay` — the\n * host resumes as the approver, under the meta it recorded, and refuses any\n * other caller); every other card, and a replay the host refuses, hands the\n * decision back to a person by unlocking the actions. A queued decision is\n * never re-sent as a `run/input` of the viewing client's own: that would run\n * the approver's decision under the viewer's identity and configuration.\n *\n * Host-specific review UIs (subagent cards, email summaries) slot in through\n * `renderDetails`; a host composer that must also OWN the decision (an\n * editable email whose edits have to reach the backend) takes over the\n * details and the decision row through `renderEditor`; requests another\n * surface answers (typed interrupt families, per-lane subagent approvals)\n * stand down through `isHandledElsewhere`; viewers without edit rights see\n * `readOnlyNotice`.\n */\n\n/** What the card reads in place of the host's queued lanes once it has given up on them. */\nconst NO_HOST_QUEUED_LANE_DECISIONS: Readonly<Record<string, unknown>> = Object.freeze({});\n\n/** The pending request a host slot renders or judges. */\nexport interface StatewireApprovalRequestContext {\n /** The parked input request — `undefined` while the run still streams (a live lane approval). */\n request: StatewireThread.CustomInputRequest | undefined;\n /** The payload narrowed to the Athena HITL approval shape, or `null` for a generic park. */\n hitl: HitlApprovalPayload | null;\n /** Every gated call the approval covers, in decision order (empty for non-HITL parks). */\n actionRequests: PendingActionRequest[];\n}\n\n/** The request a host editor renders, plus the decisions it may send for it. */\nexport interface StatewireApprovalEditorContext extends StatewireApprovalRequestContext {\n /** A decision is in flight (or a live lane already answered); the editor must not send another. */\n locked: boolean;\n /** Whether \"approve all for this session\" may be offered for this batch. */\n sessionApprovalOffered: boolean;\n approve: () => void;\n approveForSession: () => void;\n reject: (reason?: string) => void;\n /**\n * Answer each gated call on its own — the only way an EDITED call reaches\n * the backend. `decision` is asked once per call, in order, so the answer\n * always names exactly the parked calls (a partial map is refused\n * server-side and nothing runs). `null` when the batch cannot take\n * per-action answers: a call without a `tool_call_id`, or a live / multi-\n * lane approval, which resumes per lane and carries no edit.\n */\n decideEach: ((decision: (request: PendingActionRequest) => HitlActionDecision) => void) | null;\n}\n\nexport interface StatewireApprovalCardProps {\n /** Surface-styling overrides merged onto the default classes. */\n classNames?: {\n /** The approval card container. */\n root?: string;\n /** The \"approval was cancelled\" notice container. */\n abandoned?: string;\n /** The disclosed details block. */\n details?: string;\n /** The decision row. */\n actions?: string;\n };\n /** Copy shown when an interrupt payload carries no message. */\n fallbackMessage?: string;\n /**\n * Which pending interrupt this card answers. Defaults to\n * `isApprovalCardInterrupt` (client-tool parks excluded — keep it that way\n * unless the surface handles those itself).\n */\n interruptPredicate?: StatewireInterruptPredicate;\n /**\n * How long a clicked decision keeps the buttons locked when no resume run\n * ever starts (a `run/input` the host rejected before any run began).\n * Defaults to `HITL_PENDING_RESUME_GRACE_MS`.\n */\n pendingResumeGraceMs?: number;\n /**\n * Return true when another surface answers this request (a typed Athena\n * interrupt family, per-lane subagent approval cards). The card renders\n * nothing for it — two surfaces must never answer the same input request.\n */\n isHandledElsewhere?: (context: StatewireApprovalRequestContext) => boolean;\n /**\n * Replace the default argument disclosure (one JSON block per gated call)\n * with a host-specific review UI. Rendered inside the collapsible details\n * region; the decision buttons stay with the card.\n */\n renderDetails?: (context: StatewireApprovalRequestContext) => ReactNode;\n /**\n * Replace BOTH the details region and the decision row with a host\n * composer that decides the request itself through the context's\n * callbacks (an editable email whose edits must be what runs). Return\n * `null`/`undefined` to keep the default card for this request. Not\n * consulted for read-only viewers or non-HITL parks.\n */\n renderEditor?: (context: StatewireApprovalEditorContext) => ReactNode;\n /**\n * The viewer may see the request (it explains why the run is parked) but\n * cannot decide it — answering steers the shared run. Renders\n * `readOnlyNotice` in place of the buttons.\n */\n readOnly?: boolean;\n readOnlyNotice?: ReactNode;\n /**\n * Copy for a park that is not a HITL approval — a typed Athena interrupt\n * this surface has no card for. The only honest action is to decline it\n * (`{ action: 'reject' }`, which every typed raiser treats as a clean user\n * decline); a generic \"Continue\" would be rejected by the raiser's resume\n * schema and surface as a tool error.\n */\n nonHitlNotice?: ReactNode;\n /**\n * The host refused a decision (or the transport lost it). The optimistic\n * fold has rolled back and the request is on screen again with its actions\n * re-enabled; this is where a host tells the user why (a toast, a log line).\n */\n onResumeRejected?: (error: unknown, requestId: string) => void;\n}\n\nexport const StatewireApprovalCard: FC<StatewireApprovalCardProps> = (props) => {\n const extras = useAuiState((s) => s.thread.extras);\n if (!hasStatewireThreadExtras(extras)) return null;\n return <StatewireApprovalCardInner {...props} />;\n};\n\nconst StatewireApprovalCardInner: FC<StatewireApprovalCardProps> = ({\n classNames,\n fallbackMessage,\n interruptPredicate,\n pendingResumeGraceMs,\n isHandledElsewhere,\n renderDetails,\n renderEditor,\n readOnly = false,\n readOnlyNotice = 'Waiting for someone with edit access to respond.',\n nonHitlNotice = 'This request needs an answer this surface cannot collect.',\n onResumeRejected,\n}) => {\n const {\n request,\n requestId,\n hitl: parkedHitl,\n actionRequests: parkedActionRequests,\n liveHitl,\n liveActionRequests,\n queuedLaneDecisions,\n abandonedInterrupt,\n pending,\n resume,\n sendLaneDecisions,\n replayQueuedLanes,\n } = useStatewireApprovalRequest<StatewireThread.InputResponse>({\n interruptPredicate,\n pendingResumeGraceMs,\n onResumeRejected,\n });\n const [dismissedId, setDismissedId] = useState<string>();\n // The card shares the chat column with the thread. A lone gated call is\n // small enough to show inline, but a fan-out of a dozen calls would swallow\n // the conversation, so a batch starts collapsed until someone opens it.\n const [detailsOverride, setDetailsOverride] = useState<boolean>();\n // The live lanes a decision was sent for (joined ids); the buttons stay\n // locked until the host echoes them in `queuedLaneDecisions` or refuses.\n const [liveSentKey, setLiveSentKey] = useState<string>();\n // The parked request whose host-queued lanes outlived the grace window\n // (see `queuedLanesAwaitingHost` below): its queue is read as stale.\n const [staleQueuedRequestId, setStaleQueuedRequestId] = useState<string>();\n // The parked request whose queued lanes this card has asked the host to\n // replay (`run/lane-replay` in flight): locked until the host answers.\n const [replayingRequestId, setReplayingRequestId] = useState<string>();\n // The lanes THIS card decided live (its own `run/lane-input` the host\n // accepted). Only a queue this card recorded is replayed from here — the\n // host refuses any other caller, and a second editor's card must not even\n // ask. Pruned to the lanes on screen whenever a different view arrives, so\n // the record survives the live → parked transition of the same lanes (and\n // a fold that briefly shows nothing) and dies with a new request.\n const sentLaneIdsRef = useRef<Set<string>>(new Set());\n // The parked request already replayed once from here: a request is\n // replayed at most once, then the grace hands the decision back.\n const replayedRequestIdRef = useRef<string>(undefined);\n\n const isLive = request === undefined && liveHitl !== null;\n const hitl = isLive ? liveHitl : parkedHitl;\n const actionRequests = isLive ? liveActionRequests : parkedActionRequests;\n const laneIds = laneInterruptIds(actionRequests);\n // The host answers the lanes it queued from its own settle path, within its\n // published budget of the park (`QUEUED_LANE_ANSWER_BUDGET_SECONDS`). A\n // parked request whose queued lanes are still unanswered past the grace\n // window has a silent answerer, and either this card asked the host to\n // replay them and was refused, or the queue is not this card's to replay —\n // so the queue no longer counts as a decision here: the actions re-enable\n // and the next click answers the parked request itself (a resume the host\n // accepts, and whose dispatch drops the stale queue).\n const hostQueuedLaneDecisions =\n requestId !== undefined && staleQueuedRequestId === requestId\n ? NO_HOST_QUEUED_LANE_DECISIONS\n : queuedLaneDecisions;\n const undecidedLaneIds =\n laneIds?.filter((id) => !(id in hostQueuedLaneDecisions)) ?? null;\n // A lone parked lane (or an unstamped batch) answers with one positional\n // `run/input`; that is the only resume the backend binds per-action answers\n // to, so it is the only place an edited call can go.\n const positional = laneIds === null || (!isLive && laneIds.length <= 1);\n const liveKey = isLive ? (laneIds?.join('|') ?? null) : null;\n const viewKey = requestId ?? liveKey ?? undefined;\n\n // A fresh approval gets the default for ITS batch size, not the disclosure\n // the previous one was left in. Reset during render via React's \"previous\n // value\" pattern.\n const prevViewKeyRef = useRef(viewKey);\n if (prevViewKeyRef.current !== viewKey) {\n prevViewKeyRef.current = viewKey;\n if (detailsOverride !== undefined) setDetailsOverride(undefined);\n if (liveSentKey !== undefined) setLiveSentKey(undefined);\n if (laneIds !== null) {\n for (const id of sentLaneIdsRef.current) {\n if (!laneIds.includes(id)) sentLaneIdsRef.current.delete(id);\n }\n }\n }\n // The per-request marks (stale queue, replayed once, replay in flight)\n // outlive the optimistic fold of a click's own `run/input`: the request\n // leaves and comes back under the SAME id when the host refuses it, and a\n // card that forgot its stale mark then would relock over the standing\n // queue for another grace, and could replay it a second time. They are\n // forgotten only for a genuinely different parked request.\n if (\n requestId !== undefined &&\n staleQueuedRequestId !== undefined &&\n requestId !== staleQueuedRequestId\n ) {\n setStaleQueuedRequestId(undefined);\n }\n if (\n requestId !== undefined &&\n replayingRequestId !== undefined &&\n requestId !== replayingRequestId\n ) {\n setReplayingRequestId(undefined);\n }\n if (\n requestId !== undefined &&\n replayedRequestIdRef.current !== undefined &&\n requestId !== replayedRequestIdRef.current\n ) {\n replayedRequestIdRef.current = undefined;\n }\n\n const context: StatewireApprovalRequestContext = { request, hitl, actionRequests };\n const handledElsewhere = isHandledElsewhere?.(context) ?? false;\n const replaying = replayingRequestId !== undefined && replayingRequestId === requestId;\n\n // Parked, every lane the request covers already queued on the host, no\n // resume of our own in flight, and this card is the one that would decide\n // (not a viewer, not a request another surface owns): the host's answerer\n // is expected to resume the run within its budget. Start the clock on it,\n // longer than that budget. When it runs out the host has stayed silent: if\n // this card queued those lanes itself, it asks the host to replay them as\n // their approver (`run/lane-replay`); otherwise — and when the host refuses\n // the replay — the queue no longer counts as a decision here and the actions\n // re-enable, so a person decides. Never a `run/input` of this client's own\n // carrying someone else's recorded decision.\n const queuedLanesAwaitingHost =\n !isLive &&\n !readOnly &&\n !handledElsewhere &&\n requestId !== undefined &&\n undecidedLaneIds !== null &&\n undecidedLaneIds.length === 0 &&\n !pending &&\n !replaying;\n const queuedLaneGraceMs = pendingResumeGraceMs ?? HITL_PENDING_RESUME_GRACE_MS;\n const laneKey = laneIds?.join('|');\n const onResumeRejectedRef = useRef(onResumeRejected);\n onResumeRejectedRef.current = onResumeRejected;\n useEffect(() => {\n if (!queuedLanesAwaitingHost || requestId === undefined || laneKey === undefined) {\n return undefined;\n }\n const timer = setTimeout(() => {\n const ownQueue =\n laneKey.split('|').every((id) => sentLaneIdsRef.current.has(id)) &&\n replayedRequestIdRef.current !== requestId;\n if (!ownQueue) {\n setStaleQueuedRequestId(requestId);\n return;\n }\n replayedRequestIdRef.current = requestId;\n setReplayingRequestId(requestId);\n replayQueuedLanes(requestId).then(\n () => {\n setReplayingRequestId((current) => (current === requestId ? undefined : current));\n },\n (error: unknown) => {\n setReplayingRequestId((current) => (current === requestId ? undefined : current));\n setStaleQueuedRequestId(requestId);\n onResumeRejectedRef.current?.(error, requestId);\n },\n );\n }, queuedLaneGraceMs);\n return () => clearTimeout(timer);\n }, [queuedLanesAwaitingHost, requestId, laneKey, queuedLaneGraceMs, replayQueuedLanes]);\n\n const decide = useCallback(\n (value: Record<string, string>) => {\n // Several parked lanes (or a live one) answer by interrupt id: a\n // positional `run/input` would resume only the first and re-park the\n // rest. A lone parked lane keeps the positional resume every host\n // already speaks.\n if (positional || undecidedLaneIds === null) {\n resume(value);\n return;\n }\n const lanes = fanLaneDecision({ interruptIds: undecidedLaneIds, decision: value });\n if (!isLive) {\n sendLaneDecisions(lanes);\n return;\n }\n const key = undecidedLaneIds.join('|');\n setLiveSentKey(key);\n Promise.resolve(sendLaneDecisions(lanes)).then(\n () => {\n // The host holds these decisions for this card's caller: they are\n // the only queue this card may ask it to replay.\n for (const id of undecidedLaneIds) sentLaneIdsRef.current.add(id);\n },\n (error: unknown) => {\n setLiveSentKey((current) => (current === key ? undefined : current));\n onResumeRejected?.(error, undecidedLaneIds[0] ?? '');\n },\n );\n },\n [positional, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected],\n );\n\n const decideEach = useMemo<StatewireApprovalEditorContext['decideEach']>(() => {\n if (actionRequestToolCallIds(actionRequests) === null || !positional) return null;\n return (decision) => {\n const decisions: Record<string, HitlActionDecision> = {};\n for (const request of actionRequests) {\n if (request.toolCallId !== undefined) decisions[request.toolCallId] = decision(request);\n }\n // The edited argument set comes from the wire as JSON; the resume value\n // is that JSON going back.\n resume(hitlResumeActionDecisions(decisions) as StatewireThread.InputResponse);\n };\n }, [actionRequests, positional, resume]);\n\n if (!request && !isLive) {\n if (!abandonedInterrupt || abandonedInterrupt.id === dismissedId) return null;\n return (\n <div\n className={cn(\n 'aui-approval-abandoned flex w-full items-center justify-between gap-3 rounded-xl border border-amber-300 bg-amber-50 px-3 py-2 text-amber-800 text-xs',\n classNames?.abandoned,\n )}\n >\n <p>Approval was cancelled — the run moved on.</p>\n <button\n type=\"button\"\n aria-label=\"Dismiss cancelled approval\"\n onClick={() => setDismissedId(abandonedInterrupt.id)}\n className=\"shrink-0 rounded-md p-1 hover:bg-amber-100\"\n >\n <XIcon className=\"size-3.5\" />\n </button>\n </div>\n );\n }\n\n if (handledElsewhere) return null;\n // A live mirror without lane stamps cannot be answered before the run\n // parks; the parked request renders it then.\n if (isLive && laneIds === null) return null;\n\n const message = readInterruptMessage(request ? request.payload : liveHitl, fallbackMessage);\n const toolName = hitl?.context?.tool_name ?? hitl?.context?.tool_id;\n const pendingCount = hitl?.context?.pending_action_count ?? 1;\n const hasDetails = hitl !== null && actionRequests.length > 0;\n const showDetails = hasDetails && (detailsOverride ?? actionRequests.length <= 1);\n const sessionApprovalOffered = hitl !== null && canApproveForSession(actionRequests);\n const laneDecided =\n undecidedLaneIds !== null &&\n laneIds !== null &&\n (undecidedLaneIds.length === 0 || liveSentKey === undecidedLaneIds.join('|'));\n const locked = pending || laneDecided || replaying;\n\n const editor =\n !readOnly && hitl !== null && renderEditor\n ? renderEditor({\n ...context,\n locked,\n sessionApprovalOffered,\n approve: () => decide(hitlResumeApprove()),\n approveForSession: () => decide(hitlResumeApproveForSession()),\n reject: (reason) => decide(hitlResumeReject(reason)),\n decideEach,\n })\n : undefined;\n\n return (\n <section\n aria-label={hitl ? 'Approval required' : 'Input required'}\n className={cn(\n 'aui-approval-card w-full rounded-2xl border border-amber-300 bg-amber-50 px-4 py-3 text-amber-900',\n classNames?.root,\n )}\n >\n <div className=\"flex items-start gap-3\">\n <TriangleAlertIcon className=\"mt-0.5 size-4 shrink-0\" />\n <div className=\"min-w-0 flex-1\">\n <p className=\"flex items-center gap-2 font-semibold text-sm\">\n <span>{hitl ? 'Approval required' : 'Waiting for input'}</span>\n {hitl && pendingCount > 1 ? (\n <span className=\"shrink-0 font-normal text-amber-800 text-xs\">\n {pendingCount} tool calls\n </span>\n ) : null}\n </p>\n <p className=\"pt-1 text-amber-800 text-sm leading-snug\">\n {hitl && pendingCount === 1 && toolName ? (\n <>\n <span className=\"font-mono\">{toolName}</span> requires approval before it runs.\n </>\n ) : (\n message\n )}\n </p>\n {isLive ? (\n <p className=\"pt-1 text-amber-700 text-xs\" data-testid=\"statewire-approval-live\">\n {laneDecided\n ? 'Decision sent — it applies as soon as this step pauses.'\n : 'Other work keeps running while you decide.'}\n </p>\n ) : null}\n {hasDetails && editor == null ? (\n <button\n type=\"button\"\n onClick={() => setDetailsOverride(!showDetails)}\n aria-expanded={showDetails}\n className=\"mt-2 flex items-center gap-1 rounded px-1 py-0.5 text-amber-800 text-xs transition-colors hover:text-amber-950\"\n >\n <ChevronDownIcon\n className={cn('size-3 transition-transform', showDetails && 'rotate-180')}\n />\n {showDetails ? 'Hide details' : 'Review details'}\n </button>\n ) : null}\n {/* EVERY pending gated call renders, in order — one decision\n authorizes the whole batch, so nothing may hide behind a host's\n richer cards. All read-only: this runtime resumes through\n `hitl_response_to_decisions`, which has no `tool_args` channel —\n an editable composer would let someone rewrite an email and then\n watch the original go out — unless the host takes over the\n decision too (`renderEditor`), which sends the edit per call. */}\n {editor != null ? (\n <div className={cn('mt-3 flex flex-col gap-2', classNames?.details)}>{editor}</div>\n ) : showDetails ? (\n <div className={cn('mt-2 flex flex-col gap-2', classNames?.details)}>\n {renderDetails ? (\n renderDetails(context)\n ) : (\n <DefaultApprovalDetails actionRequests={actionRequests} />\n )}\n </div>\n ) : null}\n </div>\n </div>\n {editor != null ? null : (\n <div className={cn('flex flex-wrap items-center gap-2 pt-3', classNames?.actions)}>\n {readOnly ? (\n <p className=\"text-amber-800 text-sm\" data-testid=\"statewire-approval-read-only\">\n {readOnlyNotice}\n </p>\n ) : hitl ? (\n <>\n <Button\n size=\"sm\"\n disabled={locked}\n onClick={() => decide(hitlResumeApprove())}\n className=\"bg-green-600 text-white hover:bg-green-700\"\n >\n <CheckIcon />\n Approve\n </Button>\n {sessionApprovalOffered ? (\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={locked}\n onClick={() => decide(hitlResumeApproveForSession())}\n data-testid=\"statewire-approval-approve-session\"\n >\n <CheckCheckIcon />\n Approve all for this session\n </Button>\n ) : null}\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={locked}\n onClick={() => decide(hitlResumeReject())}\n >\n <XIcon />\n Reject\n </Button>\n </>\n ) : (\n <>\n <p className=\"text-amber-800 text-sm\" data-testid=\"statewire-approval-non-hitl\">\n {nonHitlNotice}\n </p>\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={pending}\n onClick={() => resume(interruptResumeDecline())}\n >\n <XIcon />\n Decline\n </Button>\n </>\n )}\n </div>\n )}\n </section>\n );\n};\n\n/** One block per gated call: its name (when the batch has several) and its arguments as JSON. */\nconst DefaultApprovalDetails: FC<{ actionRequests: PendingActionRequest[] }> = ({\n actionRequests,\n}) => (\n <>\n {actionRequests.map((action, index) => (\n <div\n key={`${action.name}-${index}`}\n className=\"rounded-lg bg-amber-100 p-2 text-amber-900 text-xs leading-relaxed\"\n >\n {actionRequests.length > 1 ? (\n <p className=\"font-mono font-semibold\">{action.name}</p>\n ) : null}\n {Object.keys(action.args).length > 0 ? (\n <pre className=\"mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-words rounded bg-white/60 p-1.5 font-mono text-[11px]\">\n {JSON.stringify(action.args, null, 2)}\n </pre>\n ) : (\n <p className=\"text-amber-800\">No arguments.</p>\n )}\n </div>\n ))}\n </>\n);\n"],"names":["useAuiState","hasStatewireThreadExtras","jsx","useStatewireApprovalRequest","useState","useRef","laneInterruptIds","HITL_PENDING_RESUME_GRACE_MS","useEffect","_a","useCallback","fanLaneDecision","useMemo","actionRequestToolCallIds","request","hitlResumeActionDecisions","jsxs","cn","XIcon","readInterruptMessage","canApproveForSession","hitlResumeApprove","hitlResumeApproveForSession","hitlResumeReject","TriangleAlertIcon","Fragment","ChevronDownIcon","Button","CheckIcon","CheckCheckIcon","interruptResumeDecline"],"mappings":";;;;;;;;;;;AAuFA,MAAM,gCAAmE,OAAO,OAAO,EAAE;AAqGlF,MAAM,wBAAwD,CAAC,UAAU;AAC9E,QAAM,SAASA,MAAAA,YAAY,CAAC,MAAM,EAAE,OAAO,MAAM;AACjD,MAAI,CAACC,aAAAA,yBAAyB,MAAM,EAAG,QAAO;AAC9C,SAAOC,+BAAC,4BAAA,EAA4B,GAAG,MAAA,CAAO;AAChD;AAEA,MAAM,6BAA6D,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB;AACF,MAAM;;AACJ,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE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A,EAAE,WAAU,kBAAiB,UAAA,gBAAA,CAAa;AAAA,IAAA;AAAA,EAAA;AAAA,EAXxC,GAAG,OAAO,IAAI,IAAI,KAAK;AAa9B,CACD,GACH;;"}
@@ -2,37 +2,6 @@ import type { StatewireThread } from '@assistant-ui/react-statewire';
2
2
  import { type HitlActionDecision, type HitlApprovalPayload, type PendingActionRequest } from '@athenaintel/agent-runtime';
3
3
  import { type FC, type ReactNode } from 'react';
4
4
  import { type StatewireInterruptPredicate } from './use-statewire-approval-request';
5
- /**
6
- * Human-in-the-loop approval card for the statewire transport — the one
7
- * approval UI every Athena chat surface mounts (the SDK's `AthenaChat`, the
8
- * Chrome side panel, the Office task pane, Olympus).
9
- *
10
- * When the deep-agent runtime hits an approval-gated tool call, the backend
11
- * parks the run on an `interrupt` input request. This card reads that request
12
- * through `useStatewireApprovalRequest` and answers it with
13
- * `{ type: 'run/input', requestId, response: { type: 'resume', value } }` —
14
- * the exact command the backend's resume path consumes. Without an answer the
15
- * run stays parked forever, so this card must be mounted on every statewire
16
- * chat surface. On legacy (non-statewire) threads it renders nothing.
17
- *
18
- * A gated call raised inside a delegated subagent parks only its lane: the
19
- * host mirrors that interrupt while the sibling lanes keep streaming, before
20
- * any input request exists. The card renders the mirrored payload the same
21
- * way and answers it with `run/lane-input` keyed by the lane's langgraph
22
- * interrupt id (`laneInterruptIds`); the host queues the decision and applies
23
- * it the moment the run parks, so the approver never waits on the siblings.
24
- * Once parked, a payload whose calls all carry interrupt ids resumes as a
25
- * `lane_decisions` map too — one positional `run/input` can only answer the
26
- * first of several parked lanes.
27
- *
28
- * Host-specific review UIs (subagent cards, email summaries) slot in through
29
- * `renderDetails`; a host composer that must also OWN the decision (an
30
- * editable email whose edits have to reach the backend) takes over the
31
- * details and the decision row through `renderEditor`; requests another
32
- * surface answers (typed interrupt families, per-lane subagent approvals)
33
- * stand down through `isHandledElsewhere`; viewers without edit rights see
34
- * `readOnlyNotice`.
35
- */
36
5
  /** The pending request a host slot renders or judges. */
37
6
  export interface StatewireApprovalRequestContext {
38
7
  /** The parked input request — `undefined` while the run still streams (a live lane approval). */
@@ -1,12 +1,13 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useAuiState } from "@assistant-ui/react";
3
3
  import { XIcon, TriangleAlertIcon, ChevronDownIcon, CheckIcon, CheckCheckIcon } from "lucide-react";
4
- import { useState, useRef, useCallback, useMemo } from "react";
4
+ import { useState, useRef, useEffect, useCallback, useMemo } from "react";
5
5
  import { Button } from "../ui/button.js";
6
6
  import { useStatewireApprovalRequest } from "./use-statewire-approval-request.js";
7
7
  import { hasStatewireThreadExtras } from "../packages/agent-runtime/src/thread-extras.js";
8
- import { laneInterruptIds, fanLaneDecision, actionRequestToolCallIds, hitlResumeActionDecisions, readInterruptMessage, canApproveForSession, hitlResumeReject, hitlResumeApproveForSession, hitlResumeApprove, interruptResumeDecline } from "../packages/agent-runtime/src/interrupts.js";
8
+ import { laneInterruptIds, HITL_PENDING_RESUME_GRACE_MS, fanLaneDecision, actionRequestToolCallIds, hitlResumeActionDecisions, readInterruptMessage, canApproveForSession, hitlResumeReject, hitlResumeApproveForSession, hitlResumeApprove, interruptResumeDecline } from "../packages/agent-runtime/src/interrupts.js";
9
9
  import { cn } from "cnfast";
10
+ const NO_HOST_QUEUED_LANE_DECISIONS = Object.freeze({});
10
11
  const StatewireApprovalCard = (props) => {
11
12
  const extras = useAuiState((s) => s.thread.extras);
12
13
  if (!hasStatewireThreadExtras(extras)) return null;
@@ -37,7 +38,8 @@ const StatewireApprovalCardInner = ({
37
38
  abandonedInterrupt,
38
39
  pending,
39
40
  resume,
40
- sendLaneDecisions
41
+ sendLaneDecisions,
42
+ replayQueuedLanes
41
43
  } = useStatewireApprovalRequest({
42
44
  interruptPredicate,
43
45
  pendingResumeGraceMs,
@@ -46,11 +48,16 @@ const StatewireApprovalCardInner = ({
46
48
  const [dismissedId, setDismissedId] = useState();
47
49
  const [detailsOverride, setDetailsOverride] = useState();
48
50
  const [liveSentKey, setLiveSentKey] = useState();
51
+ const [staleQueuedRequestId, setStaleQueuedRequestId] = useState();
52
+ const [replayingRequestId, setReplayingRequestId] = useState();
53
+ const sentLaneIdsRef = useRef(/* @__PURE__ */ new Set());
54
+ const replayedRequestIdRef = useRef(void 0);
49
55
  const isLive = request === void 0 && liveHitl !== null;
50
56
  const hitl = isLive ? liveHitl : parkedHitl;
51
57
  const actionRequests = isLive ? liveActionRequests : parkedActionRequests;
52
58
  const laneIds = laneInterruptIds(actionRequests);
53
- const undecidedLaneIds = (laneIds == null ? void 0 : laneIds.filter((id) => !(id in queuedLaneDecisions))) ?? null;
59
+ const hostQueuedLaneDecisions = requestId !== void 0 && staleQueuedRequestId === requestId ? NO_HOST_QUEUED_LANE_DECISIONS : queuedLaneDecisions;
60
+ const undecidedLaneIds = (laneIds == null ? void 0 : laneIds.filter((id) => !(id in hostQueuedLaneDecisions))) ?? null;
54
61
  const positional = laneIds === null || !isLive && laneIds.length <= 1;
55
62
  const liveKey = isLive ? (laneIds == null ? void 0 : laneIds.join("|")) ?? null : null;
56
63
  const viewKey = requestId ?? liveKey ?? void 0;
@@ -59,7 +66,55 @@ const StatewireApprovalCardInner = ({
59
66
  prevViewKeyRef.current = viewKey;
60
67
  if (detailsOverride !== void 0) setDetailsOverride(void 0);
61
68
  if (liveSentKey !== void 0) setLiveSentKey(void 0);
69
+ if (laneIds !== null) {
70
+ for (const id of sentLaneIdsRef.current) {
71
+ if (!laneIds.includes(id)) sentLaneIdsRef.current.delete(id);
72
+ }
73
+ }
74
+ }
75
+ if (requestId !== void 0 && staleQueuedRequestId !== void 0 && requestId !== staleQueuedRequestId) {
76
+ setStaleQueuedRequestId(void 0);
77
+ }
78
+ if (requestId !== void 0 && replayingRequestId !== void 0 && requestId !== replayingRequestId) {
79
+ setReplayingRequestId(void 0);
80
+ }
81
+ if (requestId !== void 0 && replayedRequestIdRef.current !== void 0 && requestId !== replayedRequestIdRef.current) {
82
+ replayedRequestIdRef.current = void 0;
62
83
  }
84
+ const context = { request, hitl, actionRequests };
85
+ const handledElsewhere = (isHandledElsewhere == null ? void 0 : isHandledElsewhere(context)) ?? false;
86
+ const replaying = replayingRequestId !== void 0 && replayingRequestId === requestId;
87
+ const queuedLanesAwaitingHost = !isLive && !readOnly && !handledElsewhere && requestId !== void 0 && undecidedLaneIds !== null && undecidedLaneIds.length === 0 && !pending && !replaying;
88
+ const queuedLaneGraceMs = pendingResumeGraceMs ?? HITL_PENDING_RESUME_GRACE_MS;
89
+ const laneKey = laneIds == null ? void 0 : laneIds.join("|");
90
+ const onResumeRejectedRef = useRef(onResumeRejected);
91
+ onResumeRejectedRef.current = onResumeRejected;
92
+ useEffect(() => {
93
+ if (!queuedLanesAwaitingHost || requestId === void 0 || laneKey === void 0) {
94
+ return void 0;
95
+ }
96
+ const timer = setTimeout(() => {
97
+ const ownQueue = laneKey.split("|").every((id) => sentLaneIdsRef.current.has(id)) && replayedRequestIdRef.current !== requestId;
98
+ if (!ownQueue) {
99
+ setStaleQueuedRequestId(requestId);
100
+ return;
101
+ }
102
+ replayedRequestIdRef.current = requestId;
103
+ setReplayingRequestId(requestId);
104
+ replayQueuedLanes(requestId).then(
105
+ () => {
106
+ setReplayingRequestId((current) => current === requestId ? void 0 : current);
107
+ },
108
+ (error) => {
109
+ var _a2;
110
+ setReplayingRequestId((current) => current === requestId ? void 0 : current);
111
+ setStaleQueuedRequestId(requestId);
112
+ (_a2 = onResumeRejectedRef.current) == null ? void 0 : _a2.call(onResumeRejectedRef, error, requestId);
113
+ }
114
+ );
115
+ }, queuedLaneGraceMs);
116
+ return () => clearTimeout(timer);
117
+ }, [queuedLanesAwaitingHost, requestId, laneKey, queuedLaneGraceMs, replayQueuedLanes]);
63
118
  const decide = useCallback(
64
119
  (value) => {
65
120
  if (positional || undecidedLaneIds === null) {
@@ -73,10 +128,15 @@ const StatewireApprovalCardInner = ({
73
128
  }
74
129
  const key = undecidedLaneIds.join("|");
75
130
  setLiveSentKey(key);
76
- Promise.resolve(sendLaneDecisions(lanes)).catch((error) => {
77
- setLiveSentKey((current) => current === key ? void 0 : current);
78
- onResumeRejected == null ? void 0 : onResumeRejected(error, undecidedLaneIds[0] ?? "");
79
- });
131
+ Promise.resolve(sendLaneDecisions(lanes)).then(
132
+ () => {
133
+ for (const id of undecidedLaneIds) sentLaneIdsRef.current.add(id);
134
+ },
135
+ (error) => {
136
+ setLiveSentKey((current) => current === key ? void 0 : current);
137
+ onResumeRejected == null ? void 0 : onResumeRejected(error, undecidedLaneIds[0] ?? "");
138
+ }
139
+ );
80
140
  },
81
141
  [positional, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected]
82
142
  );
@@ -115,8 +175,7 @@ const StatewireApprovalCardInner = ({
115
175
  }
116
176
  );
117
177
  }
118
- const context = { request, hitl, actionRequests };
119
- if (isHandledElsewhere == null ? void 0 : isHandledElsewhere(context)) return null;
178
+ if (handledElsewhere) return null;
120
179
  if (isLive && laneIds === null) return null;
121
180
  const message = readInterruptMessage(request ? request.payload : liveHitl, fallbackMessage);
122
181
  const toolName = ((_a = hitl == null ? void 0 : hitl.context) == null ? void 0 : _a.tool_name) ?? ((_b = hitl == null ? void 0 : hitl.context) == null ? void 0 : _b.tool_id);
@@ -125,7 +184,7 @@ const StatewireApprovalCardInner = ({
125
184
  const showDetails = hasDetails && (detailsOverride ?? actionRequests.length <= 1);
126
185
  const sessionApprovalOffered = hitl !== null && canApproveForSession(actionRequests);
127
186
  const laneDecided = undecidedLaneIds !== null && laneIds !== null && (undecidedLaneIds.length === 0 || liveSentKey === undecidedLaneIds.join("|"));
128
- const locked = pending || laneDecided;
187
+ const locked = pending || laneDecided || replaying;
129
188
  const editor = !readOnly && hitl !== null && renderEditor ? renderEditor({
130
189
  ...context,
131
190
  locked,