@athenaintel/react 0.21.2 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +67 -0
  2. package/dist/chat/StatewireApprovalCard.cjs +70 -10
  3. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  4. package/dist/chat/StatewireApprovalCard.d.ts +12 -1
  5. package/dist/chat/StatewireApprovalCard.js +73 -13
  6. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  7. package/dist/chat/use-statewire-approval-request.cjs +22 -1
  8. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  9. package/dist/chat/use-statewire-approval-request.d.ts +41 -0
  10. package/dist/chat/use-statewire-approval-request.js +24 -3
  11. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  12. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.cjs +0 -1
  13. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.cjs.map +1 -1
  14. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.js +0 -1
  15. package/dist/chat-ui/mentions/suggestions/data/sources/asset-type-icons.js.map +1 -1
  16. package/dist/collab/client.cjs +4 -9
  17. package/dist/collab/client.cjs.map +1 -1
  18. package/dist/collab/client.js +2 -7
  19. package/dist/collab/client.js.map +1 -1
  20. package/dist/collab/index.cjs +23 -0
  21. package/dist/collab/index.cjs.map +1 -1
  22. package/dist/collab/index.d.ts +17 -2
  23. package/dist/collab/index.js +24 -1
  24. package/dist/collab/index.js.map +1 -1
  25. package/dist/collab/mint.cjs +18 -13
  26. package/dist/collab/mint.cjs.map +1 -1
  27. package/dist/collab/mint.d.ts +10 -0
  28. package/dist/collab/mint.js +18 -13
  29. package/dist/collab/mint.js.map +1 -1
  30. package/dist/collab/presence-client.cjs +211 -0
  31. package/dist/collab/presence-client.cjs.map +1 -0
  32. package/dist/collab/presence-client.d.ts +60 -0
  33. package/dist/collab/presence-client.js +194 -0
  34. package/dist/collab/presence-client.js.map +1 -0
  35. package/dist/collab/presence-mint.cjs +68 -0
  36. package/dist/collab/presence-mint.cjs.map +1 -0
  37. package/dist/collab/presence-mint.d.ts +87 -0
  38. package/dist/collab/presence-mint.js +68 -0
  39. package/dist/collab/presence-mint.js.map +1 -0
  40. package/dist/collab/presence-react.cjs +114 -0
  41. package/dist/collab/presence-react.cjs.map +1 -0
  42. package/dist/collab/presence-react.d.ts +47 -0
  43. package/dist/collab/presence-react.js +114 -0
  44. package/dist/collab/presence-react.js.map +1 -0
  45. package/dist/collab/presence-slots.cjs +220 -0
  46. package/dist/collab/presence-slots.cjs.map +1 -0
  47. package/dist/collab/presence-slots.d.ts +119 -0
  48. package/dist/collab/presence-slots.js +220 -0
  49. package/dist/collab/presence-slots.js.map +1 -0
  50. package/dist/collab/token-refresh.cjs +13 -0
  51. package/dist/collab/token-refresh.cjs.map +1 -0
  52. package/dist/collab/token-refresh.d.ts +20 -0
  53. package/dist/collab/token-refresh.js +13 -0
  54. package/dist/collab/token-refresh.js.map +1 -0
  55. package/dist/packages/agent-runtime/src/interrupts.cjs +40 -1
  56. package/dist/packages/agent-runtime/src/interrupts.cjs.map +1 -1
  57. package/dist/packages/agent-runtime/src/interrupts.js +40 -1
  58. package/dist/packages/agent-runtime/src/interrupts.js.map +1 -1
  59. package/dist/packages/react/package.json.cjs +1 -1
  60. package/dist/packages/react/package.json.js +1 -1
  61. package/dist/styles.css +1 -1
  62. package/package.json +7 -7
package/README.md CHANGED
@@ -234,6 +234,20 @@ Both use the same bearer / API key as session creation. The full recipe
234
234
  template skill `voice-session-guide.md`. `createAthenaVoiceSession` is also
235
235
  exported if you hold the bridge state yourself.
236
236
 
237
+ ## What's new in 0.22.1
238
+
239
+ Tailwind Typography colors now follow theme tokens inside SDK roots; `userBubbleForeground` / `assistantForeground` apply to message text, headings, bold, inline code and blockquotes.
240
+
241
+ ## What's new in 0.22.0
242
+
243
+ 0.22.0 adds a read-only **workspace presence** feed to `@athenaintel/react/collab`:
244
+ `useWorkspacePresence(workspaceId)` (and its vanilla core
245
+ `connectWorkspacePresence`) subscribes to the Keryx workspace awareness room —
246
+ the same per-recipient-filtered roster the Olympus People page renders — and
247
+ `resolveWorkspacePresence` / `useWorkspacePresenceResolver` turn the ids it
248
+ carries into titles. Admin-only. See
249
+ [Workspace presence](#workspace-presence-admin-only). No breaking changes.
250
+
237
251
  ## What's new in 0.21.0
238
252
 
239
253
  0.21.0 adds the `@athenaintel/react/voice` entry: `useAthenaVoiceSession`
@@ -682,6 +696,59 @@ text anchors, and positioned citations are also preserved by `parseAthenaCitatio
682
696
  `page_rect` may include `unit=percent` (the default) or `unit=point`; retain the unit so the region
683
697
  maps to the correct PDF coordinates.
684
698
 
699
+ ## Live Collaboration (`@athenaintel/react/collab`)
700
+
701
+ The `collab` entry hosts the Keryx-backed live surfaces: `useGenericDoc` /
702
+ `connectGenericDoc` for Generic Doc assets (yjs v14 via `@y/y` and
703
+ `@y/websocket`, auth through `POST /api/v0/assets/{id}/collab-token`), and the
704
+ workspace presence feed below. Both mint short-lived room-bound tokens with the
705
+ provider's credentials and re-mint before expiry on their own.
706
+
707
+ ### Workspace presence (admin only)
708
+
709
+ `useWorkspacePresence(workspaceId)` is a **read-only** subscriber to the
710
+ workspace awareness room — the same per-recipient-filtered roster the Olympus
711
+ People page renders. It mints a read-only token from
712
+ `POST /api/v0/workspaces/{workspaceId}/presence-token` (401 on a bad
713
+ credential; 403 unless the caller is an admin of a workspace with the roster
714
+ enabled), joins `<workspaceId>/awareness`, and keeps one entry per person (tabs
715
+ merged by the server-attested identity) plus one per agent run. The client is
716
+ a pure observer: it never publishes an awareness slot and never writes to the
717
+ room's document. Each person carries a `state` (`active` / `idle` / `away`)
718
+ re-derived every `tickMs` (default 10 s) from their last input, so the ladder
719
+ decays between events.
720
+
721
+ ```tsx
722
+ import { useWorkspacePresence, useWorkspacePresenceResolver } from '@athenaintel/react/collab';
723
+ import { useQuery } from '@tanstack/react-query';
724
+
725
+ function WhoIsHere({ workspaceId }: { workspaceId: string }) {
726
+ const { status, humans, agents } = useWorkspacePresence(workspaceId);
727
+ const resolve = useWorkspacePresenceResolver(workspaceId);
728
+ const assetIds = humans.flatMap((h) => h.contexts.filter((c) => c.type === 'asset').map((c) => c.guid));
729
+ const titles = useQuery({
730
+ queryKey: ['presence-titles', workspaceId, assetIds],
731
+ queryFn: ({ signal }) => resolve({ asset_ids: assetIds }, signal),
732
+ });
733
+ if (status !== 'connected') return <p>Presence: {status}</p>;
734
+ return (
735
+ <ul>
736
+ {humans.map((h) => <li key={h.key}>{h.name} · {h.state} · {h.contexts.length} open</li>)}
737
+ {agents.map((a) => <li key={a.key}>{a.name} (agent) for {a.agentInitiator?.name ?? '?'}</li>)}
738
+ </ul>
739
+ );
740
+ }
741
+ ```
742
+
743
+ `workspaceId === null` or `{ enabled: false }` keeps the feed closed
744
+ (`status: 'closed'`). The awareness ids are opaque; `resolveWorkspacePresence`
745
+ (`POST …/presence/resolve`) returns titles only for what the caller may open,
746
+ and the resolver hook is deliberately uncached — own the caching (TanStack
747
+ Query above). Outside React, `connectWorkspacePresence({ workspaceId, auth })`
748
+ returns the same handle the hook wraps (`status`, `humans`, `agents`,
749
+ `onChange`, `refreshNow`, `destroy`), and `mergePresenceStates` /
750
+ `derivePresenceState` are exported for tests and custom transports.
751
+
685
752
  ## Styling
686
753
 
687
754
  `styles.css` is a self-contained stylesheet compiled at package build time. One import styles every SDK component — the host app does **not** need Tailwind:
@@ -41,15 +41,56 @@ const StatewireApprovalCardInner = ({
41
41
  onResumeRejected
42
42
  }) => {
43
43
  var _a, _b, _c;
44
- const { request, requestId, hitl, actionRequests, abandonedInterrupt, pending, resume } = useStatewireApprovalRequest.useStatewireApprovalRequest({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });
44
+ const {
45
+ request,
46
+ requestId,
47
+ hitl: parkedHitl,
48
+ actionRequests: parkedActionRequests,
49
+ liveHitl,
50
+ liveActionRequests,
51
+ queuedLaneDecisions,
52
+ abandonedInterrupt,
53
+ pending,
54
+ resume,
55
+ sendLaneDecisions
56
+ } = useStatewireApprovalRequest.useStatewireApprovalRequest({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });
45
57
  const [dismissedId, setDismissedId] = react$1.useState();
46
58
  const [detailsOverride, setDetailsOverride] = react$1.useState();
47
- const prevRequestIdRef = react$1.useRef(requestId);
48
- if (prevRequestIdRef.current !== requestId) {
49
- prevRequestIdRef.current = requestId;
59
+ const [liveSentKey, setLiveSentKey] = react$1.useState();
60
+ const isLive = request === void 0 && liveHitl !== null;
61
+ const hitl = isLive ? liveHitl : parkedHitl;
62
+ const actionRequests = isLive ? liveActionRequests : parkedActionRequests;
63
+ const laneIds = interrupts.laneInterruptIds(actionRequests);
64
+ const undecidedLaneIds = (laneIds == null ? void 0 : laneIds.filter((id) => !(id in queuedLaneDecisions))) ?? null;
65
+ const liveKey = isLive ? (laneIds == null ? void 0 : laneIds.join("|")) ?? null : null;
66
+ const viewKey = requestId ?? liveKey ?? void 0;
67
+ const prevViewKeyRef = react$1.useRef(viewKey);
68
+ if (prevViewKeyRef.current !== viewKey) {
69
+ prevViewKeyRef.current = viewKey;
50
70
  if (detailsOverride !== void 0) setDetailsOverride(void 0);
71
+ if (liveSentKey !== void 0) setLiveSentKey(void 0);
51
72
  }
52
- if (!request) {
73
+ const decide = react$1.useCallback(
74
+ (value) => {
75
+ if (laneIds === null || undecidedLaneIds === null || !isLive && laneIds.length <= 1) {
76
+ resume(value);
77
+ return;
78
+ }
79
+ const lanes = interrupts.fanLaneDecision({ interruptIds: undecidedLaneIds, decision: value });
80
+ if (!isLive) {
81
+ sendLaneDecisions(lanes);
82
+ return;
83
+ }
84
+ const key = undecidedLaneIds.join("|");
85
+ setLiveSentKey(key);
86
+ Promise.resolve(sendLaneDecisions(lanes)).catch((error) => {
87
+ setLiveSentKey((current) => current === key ? void 0 : current);
88
+ onResumeRejected == null ? void 0 : onResumeRejected(error, undecidedLaneIds[0] ?? "");
89
+ });
90
+ },
91
+ [laneIds, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected]
92
+ );
93
+ if (!request && !isLive) {
53
94
  if (!abandonedInterrupt || abandonedInterrupt.id === dismissedId) return null;
54
95
  return /* @__PURE__ */ jsxRuntime.jsxs(
55
96
  "div",
@@ -76,11 +117,15 @@ const StatewireApprovalCardInner = ({
76
117
  }
77
118
  const context = { request, hitl, actionRequests };
78
119
  if (isHandledElsewhere == null ? void 0 : isHandledElsewhere(context)) return null;
79
- const message = interrupts.readInterruptMessage(request.payload, fallbackMessage);
120
+ if (isLive && laneIds === null) return null;
121
+ const message = interrupts.readInterruptMessage(request ? request.payload : liveHitl, fallbackMessage);
80
122
  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);
81
123
  const pendingCount = ((_c = hitl == null ? void 0 : hitl.context) == null ? void 0 : _c.pending_action_count) ?? 1;
82
124
  const hasDetails = hitl !== null && actionRequests.length > 0;
83
125
  const showDetails = hasDetails && (detailsOverride ?? actionRequests.length <= 1);
126
+ const sessionApprovalOffered = hitl !== null && interrupts.canApproveForSession(actionRequests);
127
+ const laneDecided = undecidedLaneIds !== null && laneIds !== null && (undecidedLaneIds.length === 0 || liveSentKey === undecidedLaneIds.join("|"));
128
+ const locked = pending || laneDecided;
84
129
  return /* @__PURE__ */ jsxRuntime.jsxs(
85
130
  "section",
86
131
  {
@@ -104,6 +149,7 @@ const StatewireApprovalCardInner = ({
104
149
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-mono", children: toolName }),
105
150
  " requires approval before it runs."
106
151
  ] }) : message }),
152
+ isLive ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "pt-1 text-amber-700 text-xs", "data-testid": "statewire-approval-live", children: laneDecided ? "Decision sent — it applies as soon as this step pauses." : "Other work keeps running while you decide." }) : null,
107
153
  hasDetails ? /* @__PURE__ */ jsxRuntime.jsxs(
108
154
  "button",
109
155
  {
@@ -130,8 +176,8 @@ const StatewireApprovalCardInner = ({
130
176
  button.Button,
131
177
  {
132
178
  size: "sm",
133
- disabled: pending,
134
- onClick: () => resume(interrupts.hitlResumeApprove()),
179
+ disabled: locked,
180
+ onClick: () => decide(interrupts.hitlResumeApprove()),
135
181
  className: "bg-green-600 text-white hover:bg-green-700",
136
182
  children: [
137
183
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckIcon, {}),
@@ -139,13 +185,27 @@ const StatewireApprovalCardInner = ({
139
185
  ]
140
186
  }
141
187
  ),
188
+ sessionApprovalOffered ? /* @__PURE__ */ jsxRuntime.jsxs(
189
+ button.Button,
190
+ {
191
+ size: "sm",
192
+ variant: "outline",
193
+ disabled: locked,
194
+ onClick: () => decide(interrupts.hitlResumeApproveForSession()),
195
+ "data-testid": "statewire-approval-approve-session",
196
+ children: [
197
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCheckIcon, {}),
198
+ "Approve all for this session"
199
+ ]
200
+ }
201
+ ) : null,
142
202
  /* @__PURE__ */ jsxRuntime.jsxs(
143
203
  button.Button,
144
204
  {
145
205
  size: "sm",
146
206
  variant: "outline",
147
- disabled: pending,
148
- onClick: () => resume(interrupts.hitlResumeReject()),
207
+ disabled: locked,
208
+ onClick: () => decide(interrupts.hitlResumeReject()),
149
209
  children: [
150
210
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, {}),
151
211
  "Reject"
@@ -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 hasStatewireThreadExtras,\n type HitlApprovalPayload,\n hitlResumeApprove,\n hitlResumeReject,\n interruptResumeDecline,\n type PendingActionRequest,\n readInterruptMessage,\n} from '@athenaintel/agent-runtime';\nimport { CheckIcon, ChevronDownIcon, TriangleAlertIcon, XIcon } from 'lucide-react';\nimport { type FC, type ReactNode, 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 * Host-specific review UIs (subagent cards, email summaries) slot in through\n * `renderDetails`; requests another surface answers (typed interrupt\n * families, per-lane subagent approvals) stand down through\n * `isHandledElsewhere`; viewers without edit rights see `readOnlyNotice`.\n */\n\n/** The pending request a host slot renders or judges. */\nexport interface StatewireApprovalRequestContext {\n request: StatewireThread.CustomInputRequest;\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\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 * 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 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 { request, requestId, hitl, actionRequests, abandonedInterrupt, pending, resume } =\n useStatewireApprovalRequest({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });\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\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 prevRequestIdRef = useRef(requestId);\n if (prevRequestIdRef.current !== requestId) {\n prevRequestIdRef.current = requestId;\n if (detailsOverride !== undefined) setDetailsOverride(undefined);\n }\n\n if (!request) {\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\n const message = readInterruptMessage(request.payload, 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\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 {hasDetails ? (\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. */}\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 <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={pending}\n onClick={() => resume(hitlResumeApprove())}\n className=\"bg-green-600 text-white hover:bg-green-700\"\n >\n <CheckIcon />\n Approve\n </Button>\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={pending}\n onClick={() => resume(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 </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","jsxs","cn","XIcon","readInterruptMessage","TriangleAlertIcon","Fragment","ChevronDownIcon","Button","hitlResumeApprove","CheckIcon","hitlResumeReject","interruptResumeDecline"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6GO,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,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB;AACF,MAAM;;AACJ,QAAM,EAAE,SAAS,WAAW,M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;AAAA,cAE9C,UAAA;AAAA,gBAAAf,2BAAAA,IAACM,YAAAA,OAAA,EAAM;AAAA,gBAAE;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAEX,EAAA,CACF,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;AAGA,MAAM,yBAAyE,CAAC;AAAA,EAC9E;AACF,MACEN,2BAAAA,IAAAS,WAAAA,UAAA,EACG,UAAA,eAAe,IAAI,CAAC,QAAQ,UAC3BL,2BAAAA;AAAAA,EAAC;AAAA,EAAA;AAAA,IAEC,WAAU;AAAA,IAET,UAAA;AAAA,MAAA,eAAe,SAAS,IACvBJ,2BAAAA,IAAC,KAAA,EAAE,WAAU,2BAA2B,UAAA,OAAO,MAAK,IAClD;AAAA,MACH,OAAO,KAAK,OAAO,IAAI,EAAE,SAAS,IACjCA,2BAAAA,IAAC,OAAA,EAAI,WAAU,+GACZ,eAAK,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 canApproveForSession,\n fanLaneDecision,\n hasStatewireThreadExtras,\n type HitlApprovalPayload,\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, 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`; requests another surface answers (typed interrupt\n * families, per-lane subagent approvals) stand down through\n * `isHandledElsewhere`; viewers without edit rights see `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\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 * 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 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({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });\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 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 (laneIds === null || undecidedLaneIds === null || (!isLive && laneIds.length <= 1)) {\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 [laneIds, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected],\n );\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 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 ? (\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. */}\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 <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 </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","jsxs","cn","XIcon","readInterruptMessage","canApproveForSession","TriangleAlertIcon","Fragment","ChevronDownIcon","Button","hitlResumeApprove","CheckIcon","hitlResumeApproveForSession","CheckCheckIcon","hitlResumeReject","interruptResumeDecline"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkIO,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,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,4BAAAA,4BAA4B,EAAE,oBAAoB,sBAAsB,kBAAkB;AAC9F,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;AAClF,QAAM,UAAU,UAAU,mCAAS,KAAK,SAAQ,OAAQ;AACxD,QAAM,UAAU,aAAa,WAAW;AAKxC,QAAM,iBAAiBC,Q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AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;AAGA,MAAM,yBAAyE,CAAC;AAAA,EAC9E;AACF,MACET,2BAAAA,IAAAa,WAAAA,UAAA,EACG,UAAA,eAAe,IAAI,CAAC,QAAQ,UAC3BN,2BAAAA;AAAAA,EAAC;AAAA,EAAA;AAAA,IAEC,WAAU;AAAA,IAET,UAAA;AAAA,MAAA,eAAe,SAAS,IACvBP,2BAAAA,IAAC,KAAA,EAAE,WAAU,2BAA2B,UAAA,OAAO,MAAK,IAClD;AAAA,MACH,OAAO,KAAK,OAAO,IAAI,EAAE,SAAS,IACjCA,2BAAAA,IAAC,OAAA,EAAI,WAAU,+GACZ,eAAK,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;;"}
@@ -15,6 +15,16 @@ import { type StatewireInterruptPredicate } from './use-statewire-approval-reque
15
15
  * run stays parked forever, so this card must be mounted on every statewire
16
16
  * chat surface. On legacy (non-statewire) threads it renders nothing.
17
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
+ *
18
28
  * Host-specific review UIs (subagent cards, email summaries) slot in through
19
29
  * `renderDetails`; requests another surface answers (typed interrupt
20
30
  * families, per-lane subagent approvals) stand down through
@@ -22,7 +32,8 @@ import { type StatewireInterruptPredicate } from './use-statewire-approval-reque
22
32
  */
23
33
  /** The pending request a host slot renders or judges. */
24
34
  export interface StatewireApprovalRequestContext {
25
- request: StatewireThread.CustomInputRequest;
35
+ /** The parked input request — `undefined` while the run still streams (a live lane approval). */
36
+ request: StatewireThread.CustomInputRequest | undefined;
26
37
  /** The payload narrowed to the Athena HITL approval shape, or `null` for a generic park. */
27
38
  hitl: HitlApprovalPayload | null;
28
39
  /** Every gated call the approval covers, in decision order (empty for non-HITL parks). */
@@ -1,12 +1,12 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useAuiState } from "@assistant-ui/react";
3
3
  import "../packages/agent-runtime/src/generated/runconfig-contract.js";
4
- import { useState, useRef } from "react";
4
+ import { useState, useRef, useCallback } from "react";
5
5
  import "@assistant-ui/tap";
6
6
  import "statewire";
7
7
  import "../packages/agent-runtime/src/statewire-suspended.js";
8
8
  import "@tanstack/react-query";
9
- import { readInterruptMessage, hitlResumeApprove, hitlResumeReject, interruptResumeDecline } from "../packages/agent-runtime/src/interrupts.js";
9
+ import { laneInterruptIds, fanLaneDecision, readInterruptMessage, canApproveForSession, hitlResumeApprove, hitlResumeApproveForSession, hitlResumeReject, interruptResumeDecline } from "../packages/agent-runtime/src/interrupts.js";
10
10
  import "../packages/agent-runtime/src/messages.js";
11
11
  import "../packages/agent-runtime/src/statewire-state.js";
12
12
  import { hasStatewireThreadExtras } from "../packages/agent-runtime/src/thread-extras.js";
@@ -17,7 +17,7 @@ import "../packages/agent-runtime/src/statewire-attach-observer.js";
17
17
  import "../packages/agent-runtime/src/thread-status.js";
18
18
  import "@assistant-ui/core";
19
19
  import "../packages/agent-runtime/src/thread-handoff.js";
20
- import { XIcon, TriangleAlertIcon, ChevronDownIcon, CheckIcon } from "lucide-react";
20
+ import { XIcon, TriangleAlertIcon, ChevronDownIcon, CheckIcon, CheckCheckIcon } from "lucide-react";
21
21
  import { Button } from "../ui/button.js";
22
22
  import { useStatewireApprovalRequest } from "./use-statewire-approval-request.js";
23
23
  import { cn } from "cnfast";
@@ -39,15 +39,56 @@ const StatewireApprovalCardInner = ({
39
39
  onResumeRejected
40
40
  }) => {
41
41
  var _a, _b, _c;
42
- const { request, requestId, hitl, actionRequests, abandonedInterrupt, pending, resume } = useStatewireApprovalRequest({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });
42
+ const {
43
+ request,
44
+ requestId,
45
+ hitl: parkedHitl,
46
+ actionRequests: parkedActionRequests,
47
+ liveHitl,
48
+ liveActionRequests,
49
+ queuedLaneDecisions,
50
+ abandonedInterrupt,
51
+ pending,
52
+ resume,
53
+ sendLaneDecisions
54
+ } = useStatewireApprovalRequest({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });
43
55
  const [dismissedId, setDismissedId] = useState();
44
56
  const [detailsOverride, setDetailsOverride] = useState();
45
- const prevRequestIdRef = useRef(requestId);
46
- if (prevRequestIdRef.current !== requestId) {
47
- prevRequestIdRef.current = requestId;
57
+ const [liveSentKey, setLiveSentKey] = useState();
58
+ const isLive = request === void 0 && liveHitl !== null;
59
+ const hitl = isLive ? liveHitl : parkedHitl;
60
+ const actionRequests = isLive ? liveActionRequests : parkedActionRequests;
61
+ const laneIds = laneInterruptIds(actionRequests);
62
+ const undecidedLaneIds = (laneIds == null ? void 0 : laneIds.filter((id) => !(id in queuedLaneDecisions))) ?? null;
63
+ const liveKey = isLive ? (laneIds == null ? void 0 : laneIds.join("|")) ?? null : null;
64
+ const viewKey = requestId ?? liveKey ?? void 0;
65
+ const prevViewKeyRef = useRef(viewKey);
66
+ if (prevViewKeyRef.current !== viewKey) {
67
+ prevViewKeyRef.current = viewKey;
48
68
  if (detailsOverride !== void 0) setDetailsOverride(void 0);
69
+ if (liveSentKey !== void 0) setLiveSentKey(void 0);
49
70
  }
50
- if (!request) {
71
+ const decide = useCallback(
72
+ (value) => {
73
+ if (laneIds === null || undecidedLaneIds === null || !isLive && laneIds.length <= 1) {
74
+ resume(value);
75
+ return;
76
+ }
77
+ const lanes = fanLaneDecision({ interruptIds: undecidedLaneIds, decision: value });
78
+ if (!isLive) {
79
+ sendLaneDecisions(lanes);
80
+ return;
81
+ }
82
+ const key = undecidedLaneIds.join("|");
83
+ setLiveSentKey(key);
84
+ Promise.resolve(sendLaneDecisions(lanes)).catch((error) => {
85
+ setLiveSentKey((current) => current === key ? void 0 : current);
86
+ onResumeRejected == null ? void 0 : onResumeRejected(error, undecidedLaneIds[0] ?? "");
87
+ });
88
+ },
89
+ [laneIds, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected]
90
+ );
91
+ if (!request && !isLive) {
51
92
  if (!abandonedInterrupt || abandonedInterrupt.id === dismissedId) return null;
52
93
  return /* @__PURE__ */ jsxs(
53
94
  "div",
@@ -74,11 +115,15 @@ const StatewireApprovalCardInner = ({
74
115
  }
75
116
  const context = { request, hitl, actionRequests };
76
117
  if (isHandledElsewhere == null ? void 0 : isHandledElsewhere(context)) return null;
77
- const message = readInterruptMessage(request.payload, fallbackMessage);
118
+ if (isLive && laneIds === null) return null;
119
+ const message = readInterruptMessage(request ? request.payload : liveHitl, fallbackMessage);
78
120
  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);
79
121
  const pendingCount = ((_c = hitl == null ? void 0 : hitl.context) == null ? void 0 : _c.pending_action_count) ?? 1;
80
122
  const hasDetails = hitl !== null && actionRequests.length > 0;
81
123
  const showDetails = hasDetails && (detailsOverride ?? actionRequests.length <= 1);
124
+ const sessionApprovalOffered = hitl !== null && canApproveForSession(actionRequests);
125
+ const laneDecided = undecidedLaneIds !== null && laneIds !== null && (undecidedLaneIds.length === 0 || liveSentKey === undecidedLaneIds.join("|"));
126
+ const locked = pending || laneDecided;
82
127
  return /* @__PURE__ */ jsxs(
83
128
  "section",
84
129
  {
@@ -102,6 +147,7 @@ const StatewireApprovalCardInner = ({
102
147
  /* @__PURE__ */ jsx("span", { className: "font-mono", children: toolName }),
103
148
  " requires approval before it runs."
104
149
  ] }) : message }),
150
+ isLive ? /* @__PURE__ */ jsx("p", { className: "pt-1 text-amber-700 text-xs", "data-testid": "statewire-approval-live", children: laneDecided ? "Decision sent — it applies as soon as this step pauses." : "Other work keeps running while you decide." }) : null,
105
151
  hasDetails ? /* @__PURE__ */ jsxs(
106
152
  "button",
107
153
  {
@@ -128,8 +174,8 @@ const StatewireApprovalCardInner = ({
128
174
  Button,
129
175
  {
130
176
  size: "sm",
131
- disabled: pending,
132
- onClick: () => resume(hitlResumeApprove()),
177
+ disabled: locked,
178
+ onClick: () => decide(hitlResumeApprove()),
133
179
  className: "bg-green-600 text-white hover:bg-green-700",
134
180
  children: [
135
181
  /* @__PURE__ */ jsx(CheckIcon, {}),
@@ -137,13 +183,27 @@ const StatewireApprovalCardInner = ({
137
183
  ]
138
184
  }
139
185
  ),
186
+ sessionApprovalOffered ? /* @__PURE__ */ jsxs(
187
+ Button,
188
+ {
189
+ size: "sm",
190
+ variant: "outline",
191
+ disabled: locked,
192
+ onClick: () => decide(hitlResumeApproveForSession()),
193
+ "data-testid": "statewire-approval-approve-session",
194
+ children: [
195
+ /* @__PURE__ */ jsx(CheckCheckIcon, {}),
196
+ "Approve all for this session"
197
+ ]
198
+ }
199
+ ) : null,
140
200
  /* @__PURE__ */ jsxs(
141
201
  Button,
142
202
  {
143
203
  size: "sm",
144
204
  variant: "outline",
145
- disabled: pending,
146
- onClick: () => resume(hitlResumeReject()),
205
+ disabled: locked,
206
+ onClick: () => decide(hitlResumeReject()),
147
207
  children: [
148
208
  /* @__PURE__ */ jsx(XIcon, {}),
149
209
  "Reject"
@@ -1 +1 @@
1
- {"version":3,"file":"StatewireApprovalCard.js","sources":["../../src/chat/StatewireApprovalCard.tsx"],"sourcesContent":["import { useAuiState } from '@assistant-ui/react';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport {\n hasStatewireThreadExtras,\n type HitlApprovalPayload,\n hitlResumeApprove,\n hitlResumeReject,\n interruptResumeDecline,\n type PendingActionRequest,\n readInterruptMessage,\n} from '@athenaintel/agent-runtime';\nimport { CheckIcon, ChevronDownIcon, TriangleAlertIcon, XIcon } from 'lucide-react';\nimport { type FC, type ReactNode, 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 * Host-specific review UIs (subagent cards, email summaries) slot in through\n * `renderDetails`; requests another surface answers (typed interrupt\n * families, per-lane subagent approvals) stand down through\n * `isHandledElsewhere`; viewers without edit rights see `readOnlyNotice`.\n */\n\n/** The pending request a host slot renders or judges. */\nexport interface StatewireApprovalRequestContext {\n request: StatewireThread.CustomInputRequest;\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\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 * 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 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 { request, requestId, hitl, actionRequests, abandonedInterrupt, pending, resume } =\n useStatewireApprovalRequest({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });\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\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 prevRequestIdRef = useRef(requestId);\n if (prevRequestIdRef.current !== requestId) {\n prevRequestIdRef.current = requestId;\n if (detailsOverride !== undefined) setDetailsOverride(undefined);\n }\n\n if (!request) {\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\n const message = readInterruptMessage(request.payload, 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\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 {hasDetails ? (\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. */}\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 <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={pending}\n onClick={() => resume(hitlResumeApprove())}\n className=\"bg-green-600 text-white hover:bg-green-700\"\n >\n <CheckIcon />\n Approve\n </Button>\n <Button\n size=\"sm\"\n variant=\"outline\"\n disabled={pending}\n onClick={() => resume(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 </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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6GO,MAAM,wBAAwD,CAAC,UAAU;AAC9E,QAAM,SAAS,YAAY,CAAC,MAAM,EAAE,OAAO,MAAM;AACjD,MAAI,CAAC,yBAAyB,MAAM,EAAG,QAAO;AAC9C,SAAO,oBAAC,4BAAA,EAA4B,GAAG,MAAA,CAAO;AAChD;AAEA,MAAM,6BAA6D,CAAC;AAAA,EAClE;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,EAAE,SAAS,WAAW,MAAM,gBAAgB,oBAAoB,SAAS,OAAA,IAC7E,4BAA4B,EAAE,oBAAoB,sBAAsB,kBAAkB;AAC5F,QAAM,CAAC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AAK,UAAU,OAAO,MAAM,MAAM,CAAC,EAAA,CACtC,IAEA,oBAAC,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.js","sources":["../../src/chat/StatewireApprovalCard.tsx"],"sourcesContent":["import { useAuiState } from '@assistant-ui/react';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport {\n canApproveForSession,\n fanLaneDecision,\n hasStatewireThreadExtras,\n type HitlApprovalPayload,\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, 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`; requests another surface answers (typed interrupt\n * families, per-lane subagent approvals) stand down through\n * `isHandledElsewhere`; viewers without edit rights see `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\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 * 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 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({ interruptPredicate, pendingResumeGraceMs, onResumeRejected });\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 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 (laneIds === null || undecidedLaneIds === null || (!isLive && laneIds.length <= 1)) {\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 [laneIds, undecidedLaneIds, isLive, resume, sendLaneDecisions, onResumeRejected],\n );\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 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 ? (\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. */}\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 <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 </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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkIO,MAAM,wBAAwD,CAAC,UAAU;AAC9E,QAAM,SAAS,YAAY,CAAC,MAAM,EAAE,OAAO,MAAM;AACjD,MAAI,CAAC,yBAAyB,MAAM,EAAG,QAAO;AAC9C,SAAO,oBAAC,4BAAA,EAA4B,GAAG,MAAA,CAAO;AAChD;AAEA,MAAM,6BAA6D,CAAC;AAAA,EAClE;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,IACE,4BAA4B,EAAE,oBAAoB,sBAAsB,kBAAkB;AAC9F,QAAM,CAAC,aAAa,cAAc,IAAI,SAAA;AAItC,QAAM,CAAC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e,IAAI,CAAC,QAAQ,UAC3B;AAAA,EAAC;AAAA,EAAA;AAAA,IAEC,WAAU;AAAA,IAET,UAAA;AAAA,MAAA,eAAe,SAAS,IACvB,oBAAC,KAAA,EAAE,WAAU,2BAA2B,UAAA,OAAO,MAAK,IAClD;AAAA,MACH,OAAO,KAAK,OAAO,IAAI,EAAE,SAAS,IACjC,oBAAC,OAAA,EAAI,WAAU,+GACZ,eAAK,UAAU,OAAO,MAAM,MAAM,CAAC,EAAA,CACtC,IAEA,oBAAC,KAAA,EAAE,WAAU,kBAAiB,UAAA,gBAAA,CAAa;AAAA,IAAA;AAAA,EAAA;AAAA,EAXxC,GAAG,OAAO,IAAI,IAAI,KAAK;AAa9B,CACD,GACH;"}
@@ -17,6 +17,7 @@ require("../packages/agent-runtime/src/thread-status.cjs");
17
17
  require("@assistant-ui/core");
18
18
  require("../packages/agent-runtime/src/thread-handoff.cjs");
19
19
  const useAthenaRunLive = require("./use-athena-run-live.cjs");
20
+ const NO_QUEUED_LANE_DECISIONS = Object.freeze({});
20
21
  function useStatewireApprovalRequest(options = {}) {
21
22
  var _a;
22
23
  const {
@@ -32,6 +33,10 @@ function useStatewireApprovalRequest(options = {}) {
32
33
  const hitl = interrupts.asHitlApproval(request == null ? void 0 : request.payload);
33
34
  const actionRequests = react.useMemo(() => interrupts.pendingActionRequests(hitl), [hitl]);
34
35
  const isRunning = useAthenaRunLive.useAthenaRunLive();
36
+ const mirror = reactStatewire.useStatewireState(interrupts.readInterruptMirror);
37
+ const liveHitl = request === void 0 && isRunning ? interrupts.asHitlApproval(interrupts.interruptMirrorPayload(mirror)) : null;
38
+ const liveActionRequests = react.useMemo(() => interrupts.pendingActionRequests(liveHitl), [liveHitl]);
39
+ const queuedLaneDecisions = reactStatewire.useStatewireState(interrupts.readQueuedLaneDecisions) ?? NO_QUEUED_LANE_DECISIONS;
35
40
  const { pending, resume } = interrupts.useApprovalResumeLock({
36
41
  requestId,
37
42
  isRunning,
@@ -45,7 +50,23 @@ function useStatewireApprovalRequest(options = {}) {
45
50
  response: { type: "resume", value }
46
51
  })
47
52
  });
48
- return { request, requestId, hitl, actionRequests, abandonedInterrupt, pending, resume };
53
+ const sendLaneDecisions = react.useCallback(
54
+ (lanes) => requestId !== void 0 ? resume({ lane_decisions: lanes }) : sendCommand({ type: "run/lane-input", laneDecisions: lanes }),
55
+ [requestId, resume, sendCommand]
56
+ );
57
+ return {
58
+ request,
59
+ requestId,
60
+ hitl,
61
+ actionRequests,
62
+ liveHitl,
63
+ liveActionRequests,
64
+ queuedLaneDecisions,
65
+ abandonedInterrupt,
66
+ pending,
67
+ resume,
68
+ sendLaneDecisions
69
+ };
49
70
  }
50
71
  exports.useStatewireApprovalRequest = useStatewireApprovalRequest;
51
72
  //# sourceMappingURL=use-statewire-approval-request.cjs.map