@jini-ai/chat 0.7.2 → 0.7.3-next.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 (205) hide show
  1. package/CHANGELOG.md +2 -12
  2. package/README.md +3 -3
  3. package/dist/contracts/chat-bubble-style.d.ts +1 -1
  4. package/dist/contracts/chat-bubble-style.js +1 -1
  5. package/dist/core/ag-ui/event-projection.d.ts +125 -0
  6. package/dist/core/ag-ui/event-projection.js +275 -0
  7. package/dist/core/ag-ui/event-reduction.d.ts +39 -0
  8. package/dist/core/ag-ui/event-reduction.js +99 -0
  9. package/dist/core/ag-ui/run-input.d.ts +53 -0
  10. package/dist/core/ag-ui/run-input.js +87 -0
  11. package/dist/core/agentic/chat-capabilities.d.ts +1 -1
  12. package/dist/core/agentic/index.d.ts +2 -4
  13. package/dist/core/agentic/index.js +2 -3
  14. package/dist/core/agents-port.d.ts +50 -0
  15. package/dist/core/agents-port.js +2 -0
  16. package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +16 -0
  17. package/dist/core/assistant-client/ag-ui-fetch-agent.js +24 -0
  18. package/dist/core/assistant-client/ag-ui-transport.d.ts +15 -1
  19. package/dist/core/assistant-client/ag-ui-transport.js +167 -145
  20. package/dist/core/assistant-client/attachment-liveness.js +13 -11
  21. package/dist/core/assistant-client/durable-run-subscription.d.ts +3 -2
  22. package/dist/core/assistant-client/durable-run-subscription.js +6 -5
  23. package/dist/core/assistant-client/messages.d.ts +7 -4
  24. package/dist/core/assistant-client/messages.js +5 -4
  25. package/dist/core/assistant-client/transport.d.ts +1 -1
  26. package/dist/core/assistant-client/transport.js +4 -4
  27. package/dist/core/index.d.ts +2 -0
  28. package/dist/core/index.js +1 -0
  29. package/dist/core/page-port.d.ts +15 -0
  30. package/dist/core/page-port.js +2 -0
  31. package/dist/core/run-activity.js +1 -1
  32. package/dist/core/run-events/entry.js +1 -0
  33. package/dist/core/user-text-redaction.d.ts +1 -3
  34. package/dist/core/user-text-redaction.js +3 -61
  35. package/dist/embed-widget/browser/agent-inventory.d.ts +37 -0
  36. package/dist/embed-widget/browser/agent-inventory.js +36 -0
  37. package/dist/embed-widget/browser/frontend-session-bridge.d.ts +2 -2
  38. package/dist/embed-widget/browser/frontend-session-bridge.js +17 -14
  39. package/dist/embed-widget/react/dialog.hooks.d.ts +16 -0
  40. package/dist/embed-widget/react/dialog.hooks.js +15 -0
  41. package/dist/embed-widget/react/embed.d.ts +7 -2
  42. package/dist/embed-widget/react/embed.js +6 -16
  43. package/dist/embed-widget/react/header.d.ts +4 -1
  44. package/dist/embed-widget/react/header.js +2 -2
  45. package/dist/embed-widget/vanilla/state.js +2 -2
  46. package/dist/embed-widget/vanilla/style.css +4 -4
  47. package/dist/react/components/A2uiSurfaceCard.d.ts +18 -4
  48. package/dist/react/components/A2uiSurfaceCard.hooks.d.ts +36 -0
  49. package/dist/react/components/A2uiSurfaceCard.hooks.js +174 -0
  50. package/dist/react/components/A2uiSurfaceCard.js +14 -227
  51. package/dist/react/components/A2uiSurfaceCard.rules.d.ts +14 -0
  52. package/dist/react/components/A2uiSurfaceCard.rules.js +24 -0
  53. package/dist/react/components/AttachmentPreviewModal.d.ts +21 -1
  54. package/dist/react/components/AttachmentPreviewModal.hooks.js +1 -3
  55. package/dist/react/components/AttachmentPreviewModal.js +11 -9
  56. package/dist/react/components/AttachmentTray.d.ts +11 -1
  57. package/dist/react/components/AttachmentTray.js +12 -8
  58. package/dist/react/components/ChatFab.d.ts +10 -1
  59. package/dist/react/components/ChatFab.js +2 -2
  60. package/dist/react/components/ChatSettingsDialog.d.ts +4 -3
  61. package/dist/react/components/ChatSettingsDialog.js +9 -6
  62. package/dist/react/components/ChatSettingsSegmented.d.ts +1 -1
  63. package/dist/react/components/ChatSettingsSegmented.js +1 -1
  64. package/dist/react/components/Composer.d.ts +9 -1
  65. package/dist/react/components/Composer.hooks.d.ts +79 -0
  66. package/dist/react/components/Composer.hooks.js +336 -0
  67. package/dist/react/components/Composer.js +40 -341
  68. package/dist/react/components/ComposerDiscovery.js +1 -1
  69. package/dist/react/components/ConversationList.d.ts +34 -1
  70. package/dist/react/components/ConversationList.hooks.d.ts +37 -0
  71. package/dist/react/components/ConversationList.hooks.js +177 -1
  72. package/dist/react/components/ConversationList.js +7 -174
  73. package/dist/react/components/ConversationTitleEditor.d.ts +17 -2
  74. package/dist/react/components/ConversationTitleEditor.hooks.d.ts +15 -0
  75. package/dist/react/components/ConversationTitleEditor.hooks.js +36 -0
  76. package/dist/react/components/ConversationTitleEditor.js +11 -34
  77. package/dist/react/components/CopyMessageButton.d.ts +6 -1
  78. package/dist/react/components/CopyMessageButton.js +4 -4
  79. package/dist/react/components/ExtEventErrorBoundary.d.ts +2 -0
  80. package/dist/react/components/ExtEventErrorBoundary.js +5 -3
  81. package/dist/react/components/FolderChips.d.ts +11 -1
  82. package/dist/react/components/FolderChips.hooks.d.ts +12 -0
  83. package/dist/react/components/FolderChips.hooks.js +10 -0
  84. package/dist/react/components/FolderChips.js +9 -9
  85. package/dist/react/components/Markdown.js +7 -5
  86. package/dist/react/components/McpUiSurfaceCard.d.ts +29 -5
  87. package/dist/react/components/McpUiSurfaceCard.js +29 -16
  88. package/dist/react/components/MessageList.d.ts +10 -1
  89. package/dist/react/components/MessageList.hooks.d.ts +0 -4
  90. package/dist/react/components/MessageList.hooks.js +6 -18
  91. package/dist/react/components/MessageList.js +17 -20
  92. package/dist/react/components/MessageList.rules.d.ts +0 -5
  93. package/dist/react/components/MessageList.rules.js +0 -4
  94. package/dist/react/components/MessageRow.d.ts +46 -2
  95. package/dist/react/components/MessageRow.hooks.d.ts +60 -0
  96. package/dist/react/components/MessageRow.hooks.js +94 -0
  97. package/dist/react/components/MessageRow.js +53 -113
  98. package/dist/react/components/MidRunUserMessage.d.ts +6 -1
  99. package/dist/react/components/MidRunUserMessage.js +5 -5
  100. package/dist/react/components/NextStepActions.d.ts +3 -1
  101. package/dist/react/components/NextStepActions.js +3 -3
  102. package/dist/react/components/QuestionForm.answers.hooks.d.ts +26 -0
  103. package/dist/react/components/QuestionForm.answers.hooks.js +89 -0
  104. package/dist/react/components/QuestionForm.d.ts +6 -0
  105. package/dist/react/components/QuestionForm.js +23 -261
  106. package/dist/react/components/QuestionForm.values.d.ts +22 -0
  107. package/dist/react/components/QuestionForm.values.js +58 -0
  108. package/dist/react/components/QuestionFormField.d.ts +17 -0
  109. package/dist/react/components/QuestionFormField.js +114 -0
  110. package/dist/react/components/QuestionsPanel.d.ts +3 -1
  111. package/dist/react/components/QuestionsPanel.js +7 -3
  112. package/dist/react/components/SentAttachment.d.ts +11 -2
  113. package/dist/react/components/SentAttachment.hooks.d.ts +1 -1
  114. package/dist/react/components/SentAttachment.hooks.js +6 -5
  115. package/dist/react/components/SentAttachment.js +5 -3
  116. package/dist/react/components/TodoCard.d.ts +3 -1
  117. package/dist/react/components/TodoCard.js +9 -4
  118. package/dist/react/components/ToolCallGroup.d.ts +11 -1
  119. package/dist/react/components/ToolCallGroup.js +10 -4
  120. package/dist/react/components/ToolCard.d.ts +6 -1
  121. package/dist/react/components/ToolCard.js +79 -69
  122. package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
  123. package/dist/react/components/mcp-ui-question-input.js +3 -3
  124. package/dist/react/components/mcp-ui-surface-state.d.ts +1 -1
  125. package/dist/react/features/chat-pane/agent-tools.d.ts +1 -1
  126. package/dist/react/features/chat-pane/antigravity/model-options.d.ts +2 -0
  127. package/dist/react/features/chat-pane/antigravity/model-options.js +2 -0
  128. package/dist/react/features/chat-pane/claude/model-options.d.ts +2 -0
  129. package/dist/react/features/chat-pane/claude/model-options.js +2 -0
  130. package/dist/react/features/chat-pane/codex/model-options.d.ts +2 -0
  131. package/dist/react/features/chat-pane/codex/model-options.js +2 -0
  132. package/dist/react/features/chat-pane/components/AgentPluginUsage.d.ts +4 -1
  133. package/dist/react/features/chat-pane/components/AgentPluginUsage.js +2 -2
  134. package/dist/react/features/chat-pane/components/AgentRuntimePicker.d.ts +10 -6
  135. package/dist/react/features/chat-pane/components/AgentRuntimePicker.js +18 -132
  136. package/dist/react/features/chat-pane/components/ChatPane.d.ts +24 -2
  137. package/dist/react/features/chat-pane/components/ChatPane.js +45 -297
  138. package/dist/react/features/chat-pane/components/ChatPaneComposerArea.d.ts +33 -0
  139. package/dist/react/features/chat-pane/components/ChatPaneComposerArea.js +119 -0
  140. package/dist/react/features/chat-pane/components/ChatPaneLayout.d.ts +42 -0
  141. package/dist/react/features/chat-pane/components/ChatPaneLayout.js +54 -0
  142. package/dist/react/features/chat-pane/components/ChatPaneStatus.d.ts +27 -0
  143. package/dist/react/features/chat-pane/components/ChatPaneStatus.js +91 -0
  144. package/dist/react/features/chat-pane/components/RuntimeDropUp.d.ts +6 -1
  145. package/dist/react/features/chat-pane/components/RuntimeDropUp.js +20 -19
  146. package/dist/react/features/chat-pane/components/RuntimePickerSections.d.ts +62 -0
  147. package/dist/react/features/chat-pane/components/RuntimePickerSections.js +122 -0
  148. package/dist/react/features/chat-pane/create-mcp-ui-tool-caller.d.ts +1 -1
  149. package/dist/react/features/chat-pane/hooks/useChatPane.hooks.d.ts +5 -3
  150. package/dist/react/features/chat-pane/hooks/useChatPane.hooks.js +78 -26
  151. package/dist/react/features/chat-pane/hooks/useChatPaneAgentControl.hooks.js +6 -6
  152. package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.d.ts +5 -1
  153. package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.js +7 -7
  154. package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.d.ts +7 -0
  155. package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.js +5 -0
  156. package/dist/react/features/chat-pane/model-options.js +7 -4
  157. package/dist/react/features/chat-pane/styles.d.ts +1 -1
  158. package/dist/react/features/chat-pane/styles.js +25 -41
  159. package/dist/react/features/chat-pane/types.d.ts +29 -1
  160. package/dist/react/hooks/assistant-chats-contracts.d.ts +1 -1
  161. package/dist/react/hooks/attachment-preview-cache.d.ts +1 -1
  162. package/dist/react/hooks/attachment-preview-cache.js +1 -1
  163. package/dist/react/hooks/fab-position.js +16 -18
  164. package/dist/react/hooks/useConversation.d.ts +6 -1
  165. package/dist/react/hooks/useConversation.js +11 -10
  166. package/dist/react/hooks/useRunStream.d.ts +3 -0
  167. package/dist/react/hooks/useRunStream.js +12 -12
  168. package/dist/react/hooks/useSurfaceRecovery.d.ts +1 -1
  169. package/dist/react/hooks/useSurfaceRecovery.js +2 -2
  170. package/dist/react/index.d.ts +6 -3
  171. package/dist/react/index.js +5 -3
  172. package/dist/react/styles/chat-settings.css +9 -9
  173. package/dist/react/surfaces.d.ts +91 -0
  174. package/dist/react/surfaces.js +28 -0
  175. package/dist/server/durable-runs/recover.d.ts +4 -3
  176. package/dist/server/durable-runs/recover.js +4 -3
  177. package/dist/store/legacy/sqlite/conversations.d.ts +1 -2
  178. package/dist/store/legacy/sqlite/conversations.js +1 -1
  179. package/dist/store/legacy/sqlite/messages.d.ts +2 -3
  180. package/dist/store/legacy/sqlite/messages.js +6 -6
  181. package/dist/store/pglite/index.d.ts +7 -7
  182. package/dist/store/pglite/index.js +1 -1
  183. package/dist/store/ports.d.ts +5 -2
  184. package/dist/store/postgres/index.d.ts +7 -7
  185. package/dist/store/postgres/index.js +1 -1
  186. package/dist/store/runtime/chat-expiry-sweep.js +2 -4
  187. package/dist/store/runtime/chat-history-store.js +2 -3
  188. package/dist/store/runtime/durable-run-store.js +16 -2
  189. package/dist/store/runtime/history-tools.js +33 -11
  190. package/dist/store/runtime/kernel.d.ts +3 -2
  191. package/dist/store/runtime/run-ledger.js +2 -2
  192. package/dist/store/sql/boundary.d.ts +5 -5
  193. package/dist/store/sql/maintenance.d.ts +3 -2
  194. package/dist/store/sql/store.d.ts +16 -8
  195. package/dist/store/sql/store.js +31 -14
  196. package/dist/store/sqlite/index.d.ts +11 -12
  197. package/dist/store/sqlite/index.js +5 -5
  198. package/dist/store/sqlite/schema.d.ts +1 -1
  199. package/package.json +46 -24
  200. package/dist/core/ag-ui/entry.d.ts +0 -84
  201. package/dist/core/ag-ui/entry.js +0 -225
  202. package/dist/core/browser/page-actions.d.ts +0 -121
  203. package/dist/core/browser/page-actions.js +0 -113
  204. package/dist/embed-widget/browser/page-actions.d.ts +0 -2
  205. package/dist/embed-widget/browser/page-actions.js +0 -3
@@ -0,0 +1,174 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { createA2uiInterpreter, createLabCatalog, } from '@jini-ai/protocol/a2ui';
3
+ import { useChatSurfaces } from '../surfaces.js';
4
+ /** Every agent→renderer message shape carries `surfaceId` under exactly one of these keys. */
5
+ const SURFACE_ID_KEYS = ['createSurface', 'updateComponents', 'updateDataModel', 'deleteSurface'];
6
+ function extractSurfaceId(message) {
7
+ if (typeof message !== 'object' || message === null)
8
+ return undefined;
9
+ for (const key of SURFACE_ID_KEYS) {
10
+ const body = message[key];
11
+ if (body && typeof body === 'object' && typeof body.surfaceId === 'string') {
12
+ return body.surfaceId;
13
+ }
14
+ }
15
+ return undefined;
16
+ }
17
+ /**
18
+ * Duck-types `value` as a thenable rather than checking `instanceof Promise`. `onAgentAction`'s
19
+ * declared return type is `void | Promise<A2uiAgentActionOutcome>`, and TypeScript's structural
20
+ * typing means anything with a spec-shaped `then` — a hand-built thenable, a non-native promise
21
+ * library, a promise crossing a realm boundary (e.g. constructed inside an iframe) — satisfies
22
+ * `Promise<T>` at the call site without being `instanceof Promise` in *this* realm. An `instanceof`
23
+ * check would silently skip the await branch for any of those, dropping the delivery outcome on the
24
+ * floor — reintroducing, inside the fix for it, the exact silent-failure class this feature exists
25
+ * to remove. Do not "simplify" this back to `instanceof`.
26
+ *
27
+ * @complexity O(1).
28
+ * @overallScore 100
29
+ */
30
+ function isThenable(value) {
31
+ return typeof value === 'object' && value !== null && typeof value.then === 'function';
32
+ }
33
+ /** Apply streamed surface events and report local or agent action outcomes. */
34
+ export function useA2uiSurfaceCard({ events, runId, onAgentAction, registry, t, clock }, _options = {}) {
35
+ const surfaces = useChatSurfaces();
36
+ // Merges the host registry (shadcn/recharts by default) into the lab catalog, keyed under
37
+ // the SAME `catalogId` the lab catalog already uses — so a tool built against
38
+ // `createLabCatalog({}).catalogId` (e.g. `demo-a2ui-tool.ts`) still validates unchanged, and now
39
+ // ALSO gains every registry component as a real, addable/removable catalog entry.
40
+ const catalog = useMemo(() => {
41
+ const base = createLabCatalog({});
42
+ return surfaces.a2ui.catalogFromRegistry({ registry, catalogId: base.catalogId }, { base });
43
+ }, [registry, surfaces]);
44
+ const interpreterRef = useRef(null);
45
+ const actionIdCounterRef = useRef(0); // per-card sequence; the clock suffix keeps the wire format
46
+ if (!interpreterRef.current) {
47
+ interpreterRef.current = createA2uiInterpreter({
48
+ catalog,
49
+ clock,
50
+ ids: {
51
+ next: (_required) => `a2ui-action-${(actionIdCounterRef.current += 1)}-${clock.nowMs().toString(36)}`,
52
+ },
53
+ });
54
+ }
55
+ const interpreter = interpreterRef.current;
56
+ const [, forceRender] = useState(0);
57
+ const appliedCountRef = useRef(0);
58
+ const surfaceIdRef = useRef(undefined);
59
+ /** Monotonic ticket for `handleAction`'s agent-delivery attempts — see its use for why a host's
60
+ * promises settling out of order would otherwise repaint a superseded failure. */
61
+ const agentActionAttemptRef = useRef(0);
62
+ const [refusalNotice, setRefusalNotice] = useState(null);
63
+ const [pendingAgentAction, setPendingAgentAction] = useState(null);
64
+ const [localActionResult, setLocalActionResult] = useState(null);
65
+ const [deliveryFailureNotice, setDeliveryFailureNotice] = useState(null);
66
+ useEffect(() => {
67
+ const unsubscribe = interpreter.subscribe({ listener: () => forceRender((n) => n + 1) });
68
+ // React invokes cleanup with no arguments; the interpreter's port takes a required bag.
69
+ return () => unsubscribe({});
70
+ }, [interpreter]);
71
+ useEffect(() => {
72
+ while (appliedCountRef.current < events.length) {
73
+ const message = events[appliedCountRef.current];
74
+ appliedCountRef.current += 1;
75
+ const surfaceId = extractSurfaceId(message);
76
+ if (surfaceId)
77
+ surfaceIdRef.current = surfaceId;
78
+ const result = interpreter.applyAgentMessage({ raw: message });
79
+ if (result.unattributedViolation) {
80
+ setRefusalNotice(result.unattributedViolation);
81
+ }
82
+ else {
83
+ // A catalog-validation refusal (e.g. an unrecognized component type, or a known type with a
84
+ // missing/invalid required prop) surfaces as an `error`-shaped entry in `rendererMessages`,
85
+ // not `unattributedViolation`. Shown locally AND relayed through the exact same
86
+ // `onAgentAction` pipe a button click already uses: `errorMessage` is a real
87
+ // `RendererToAgentMessage` carrying `error.surfaceId`, which is all `onAgentAction`'s host
88
+ // implementation needs to address it — no second callback prop, no new wire shape. Without
89
+ // this relay a tool call that opened the surface has no way to learn its render was REFUSED
90
+ // and returns success anyway, which is worse than the silent-"waiting" bug this comment used
91
+ // to describe: it actively tells the agent (and, downstream, the human) that a chart is on
92
+ // screen when it never rendered at all.
93
+ const errorMessage = result.rendererMessages.find((m) => 'error' in m);
94
+ if (errorMessage) {
95
+ setRefusalNotice(errorMessage.error.message);
96
+ void onAgentAction?.(runId, errorMessage);
97
+ }
98
+ else {
99
+ // A message that applies cleanly clears any earlier refusal. `refusalNotice` describes
100
+ // whether the CURRENT surface is broken, not a permanent scar from an earlier mistake this
101
+ // same conversation already recovered from — e.g. a retry that fixed a missing prop, or an
102
+ // unrelated later `updateDataModel`. Without this, a stale "Action refused" banner from an
103
+ // early failed attempt sits underneath a chart that went on to render successfully.
104
+ setRefusalNotice(null);
105
+ }
106
+ }
107
+ }
108
+ // `onAgentAction`/`runId` included: the loop above now calls `onAgentAction` directly (relaying
109
+ // a validation error), not just on a later user click — the effect must see a fresh reference,
110
+ // the same way `handleAction`'s own (non-effect) call site already gets one on every render.
111
+ }, [events, interpreter, onAgentAction, runId]);
112
+ const surfaceId = surfaceIdRef.current;
113
+ const root = surfaceId ? interpreter.getRoot({ surfaceId }) : undefined;
114
+ function handleAction(componentId) {
115
+ // `surfaceId` is non-null here by construction, not by luck: this callback is only ever reached
116
+ // from a `Button` inside the rendered tree, and nothing renders until `root` resolves — which
117
+ // the `!root` early return below only permits when `surfaceId` was already truthy. Asserted
118
+ // rather than re-checked, exactly as the `RenderComponent` call site below already does.
119
+ const built = interpreter.buildAction({ surfaceId: surfaceId, componentId });
120
+ if (!built.ok) {
121
+ setRefusalNotice(built.reason);
122
+ return;
123
+ }
124
+ setRefusalNotice(null);
125
+ if (built.kind === 'local') {
126
+ // `buildAction`'s local branch is a pure computation (`resolveDynamicValue` over a
127
+ // registered catalog function's `impl`) — it never touches interpreter state, so there is
128
+ // nothing for `interpreter.subscribe` to notify and no re-render to "reflect" it. The only
129
+ // honest thing this component can do with the resolved value is show it.
130
+ setPendingAgentAction(null);
131
+ setLocalActionResult({ componentId, value: built.result });
132
+ return;
133
+ }
134
+ setLocalActionResult(null);
135
+ if (onAgentAction) {
136
+ // Clearing here, not just at the top of `handleAction`: a *previous* click's delivery failure
137
+ // must not linger next to a new attempt that has not resolved yet — same "stale notice beside
138
+ // a working control" concern `refusalNotice`'s own clearing already guards against.
139
+ setPendingAgentAction(null);
140
+ setDeliveryFailureNotice(null);
141
+ // Clearing the notice is not enough on its own: `onAgentAction` is host-supplied and its
142
+ // promises are not guaranteed to settle in call order, so an OLDER click's rejection could
143
+ // land after a newer one had already cleared the notice — repainting a failure the human has
144
+ // since superseded, next to a control that just worked. Only the latest attempt may write.
145
+ const attempt = (agentActionAttemptRef.current += 1);
146
+ const isLatestAttempt = () => agentActionAttemptRef.current === attempt;
147
+ const outcome = onAgentAction(runId, built.message);
148
+ // `isThenable`, not `instanceof Promise` — see that helper's own doc for why.
149
+ if (isThenable(outcome)) {
150
+ void outcome.then((result) => {
151
+ if (!result.ok && isLatestAttempt())
152
+ setDeliveryFailureNotice(result.reason);
153
+ }, (error) => {
154
+ // A rejection is the host's transport breaking, not a message the host chose to report —
155
+ // still surfaced, so the human sees *something* rather than a click that silently did
156
+ // nothing.
157
+ if (!isLatestAttempt())
158
+ return;
159
+ setDeliveryFailureNotice(error instanceof Error ? error.message : String(error));
160
+ });
161
+ }
162
+ }
163
+ else {
164
+ setPendingAgentAction(JSON.stringify(built.message));
165
+ }
166
+ }
167
+ function formatLocalActionValue(value) {
168
+ if (value === undefined)
169
+ return t('(no return value)');
170
+ return typeof value === 'string' ? value : JSON.stringify(value);
171
+ }
172
+ return { interpreter, surfaceId, root, refusalNotice, pendingAgentAction, localActionResult, deliveryFailureNotice, handleAction, formatLocalActionValue };
173
+ }
174
+ //# sourceMappingURL=A2uiSurfaceCard.hooks.js.map
@@ -1,58 +1,8 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * @module A2uiSurfaceCard
4
- *
5
- * Renders a live A2UI (a2ui-project/a2ui v1.0) surface inline in the chat transcript, fed by a
6
- * message's `kind: 'ext', name: 'a2ui'` events (see `ext-event-renderer-registry.ts`). A host
7
- * registers this against `'a2ui'` once, at module scope — mirroring how `McpUiLab.tsx` registers
8
- * `show_mcpui_widget` via `registerToolRenderer` — and every `ChatPane` that surfaces an `a2ui`
9
- * event thereafter renders through it.
10
- *
11
- * Ported from `examples/reference-web/src/A2uiLab.tsx`'s `RenderComponent` (the same tree-walking
12
- * approach: degrade sanely — a visible, inert placeholder, never a crash — for a missing child id
13
- * or a circular reference), generalized to consume a growing `events` array instead of a live SSE
14
- * callback. `@jini-ai/agentic/a2ui`'s catalog validates all 18 of the real basic catalog's
15
- * components; this renderer has React cases for 5 of them — `Text`/`Column`/`Row`/`Card`/`Button`
16
- * — plus, since the catalog this card builds is the lab catalog MERGED with
17
- * `DEFAULT_INTERACTIVE_UI_REGISTRY` (`buildA2uiCatalogFromRegistry`, `@jini-ai/ui/a2ui`), any
18
- * registry-sourced component (`shadcn.*`, `recharts.*`) resolves through that registry the same
19
- * way `@jini-ai/ui`'s own `A2uiSurfaceRenderer` does — see this file's `default` case. The
20
- * remaining basic types (Image/Icon/Video/AudioPlayer/List/Tabs/Modal/Divider and the input
21
- * family) still have no case here; a catalog type the interpreter accepts but this switch has no
22
- * case for, and that the registry does not resolve either, degrades to the same visible
23
- * placeholder as a genuinely unrenderable one — see the `default` branch's own comment.
24
- *
25
- * **Known gap, by design, not oversight:** a `Button`'s click only completes the round trip when
26
- * `interpreter.buildAction` resolves it as a `local` (client-side) function call. A `message`-shaped
27
- * action (meant for the agent) has nowhere real to go yet — the only existing relay
28
- * (`examples/reference-web/src/daemon.ts`'s `/a2ui-action`) is hardwired to that app's fixed,
29
- * scripted `a2ui-demo` agent, not a real conversational run; sending to it here would silently
30
- * misrepresent whether a live agent turn can actually receive the action. `onAgentAction` is the
31
- * seam a host wires up once that backend capability exists — until then, a `message`-shaped action
32
- * surfaces as a visible, honest notice instead of vanishing or hitting the wrong endpoint.
33
- */
34
- import { useEffect, useMemo, useRef, useState } from 'react';
35
- import { createA2uiInterpreter, createLabCatalog, DynamicValueSchema } from '@jini-ai/agentic/a2ui';
36
- import { createSystemClock } from '@jini-ai/core/primitives';
37
- import { buildA2uiCatalogFromRegistry } from '@jini-ai/ui/a2ui';
38
- import { DEFAULT_INTERACTIVE_UI_REGISTRY } from '@jini-ai/ui/interactive-ui';
2
+ import { useChatSurfaces } from '../surfaces.js';
39
3
  import { useT } from '../hooks/context.js';
40
- /** Every agent→renderer message shape carries `surfaceId` under exactly one of these keys. */
41
- const SURFACE_ID_KEYS = ['createSurface', 'updateComponents', 'updateDataModel', 'deleteSurface'];
42
- // Preserve the interpreter's former module-wide sequence so separate cards cannot reuse an
43
- // action ID in the same millisecond; the wall-clock suffix keeps the existing wire format.
44
- let actionIdCounter = 0;
45
- function extractSurfaceId(message) {
46
- if (typeof message !== 'object' || message === null)
47
- return undefined;
48
- for (const key of SURFACE_ID_KEYS) {
49
- const body = message[key];
50
- if (body && typeof body === 'object' && typeof body.surfaceId === 'string') {
51
- return body.surfaceId;
52
- }
53
- }
54
- return undefined;
55
- }
4
+ import { useA2uiSurfaceCard } from './A2uiSurfaceCard.hooks.js';
5
+ import { createA2uiCardNodeHelpers } from './A2uiSurfaceCard.rules.js';
56
6
  /** Renders one component and its children by walking the surface's component map from `componentId` — identical degrade-sanely behavior to `A2uiLab.tsx`'s `RenderComponent`. */
57
7
  function RenderComponent({ interpreter, surfaceId, componentId, ancestors, onAction, registry, }) {
58
8
  if (ancestors.has(componentId)) {
@@ -66,20 +16,7 @@ function RenderComponent({ interpreter, surfaceId, componentId, ancestors, onAct
66
16
  const nextAncestors = new Set(ancestors);
67
17
  nextAncestors.add(componentId);
68
18
  const childProps = { interpreter, surfaceId, ancestors: nextAncestors, onAction, registry };
69
- function resolveText(value) {
70
- // Text props already passed the catalog schema. Parsing preserves that wire type at this
71
- // Record<string, unknown> boundary without asserting a shape the compiler cannot verify.
72
- const result = interpreter.resolve({ surfaceId, value: DynamicValueSchema.parse(value) });
73
- if (!result.ok)
74
- return `⚠ unresolved (${result.reason})`;
75
- return typeof result.value === 'string' ? result.value : JSON.stringify(result.value);
76
- }
77
- function renderChildList(children) {
78
- if (Array.isArray(children)) {
79
- return children.map((childId) => _jsx(RenderComponent, { componentId: String(childId), ...childProps }, String(childId)));
80
- }
81
- return (_jsx("span", { className: "a2ui-placeholder", "data-a2ui-status": "unimplemented-template-list", children: "\u26A0 dynamic (template) child lists are not implemented by this port" }));
82
- }
19
+ const { resolveText, renderChildList } = createA2uiCardNodeHelpers({ interpreter, surfaceId, childProps, renderNode: RenderComponent });
83
20
  switch (component.component) {
84
21
  case 'Text':
85
22
  return (
@@ -122,172 +59,22 @@ function RenderComponent({ interpreter, surfaceId, componentId, ancestors, onAct
122
59
  }
123
60
  }
124
61
  }
125
- /**
126
- * Duck-types `value` as a thenable rather than checking `instanceof Promise`. `onAgentAction`'s
127
- * declared return type is `void | Promise<A2uiAgentActionOutcome>`, and TypeScript's structural
128
- * typing means anything with a spec-shaped `then` — a hand-built thenable, a non-native promise
129
- * library, a promise crossing a realm boundary (e.g. constructed inside an iframe) — satisfies
130
- * `Promise<T>` at the call site without being `instanceof Promise` in *this* realm. An `instanceof`
131
- * check would silently skip the await branch for any of those, dropping the delivery outcome on the
132
- * floor — reintroducing, inside the fix for it, the exact silent-failure class this feature exists
133
- * to remove. Do not "simplify" this back to `instanceof`.
134
- *
135
- * @complexity O(1).
136
- * @overallScore 100
137
- */
138
- function isThenable(value) {
139
- return typeof value === 'object' && value !== null && typeof value.then === 'function';
140
- }
62
+ /** Hooks A2uiSurfaceCard calls; defaults to the real ones, a test hands in fakes. */
63
+ export const defaultA2uiSurfaceCardHooks = { useT, useChatSurfaces, useA2uiSurfaceCard };
141
64
  /** Registered against `ext-event-renderer-registry.ts`'s `'a2ui'` name — see module doc. */
142
- export function A2uiSurfaceCard({ events, runId, onAgentAction, registry = DEFAULT_INTERACTIVE_UI_REGISTRY }) {
143
- const t = useT();
144
- // Merges the host registry (shadcn/recharts by default) into the lab catalog, keyed under
145
- // the SAME `catalogId` the lab catalog already uses — so a tool built against
146
- // `createLabCatalog({}).catalogId` (e.g. `demo-a2ui-tool.ts`) still validates unchanged, and now
147
- // ALSO gains every registry component as a real, addable/removable catalog entry.
148
- const catalog = useMemo(() => {
149
- const base = createLabCatalog({});
150
- return buildA2uiCatalogFromRegistry({ registry, catalogId: base.catalogId }, { base });
151
- }, [registry]);
152
- const interpreterRef = useRef(null);
153
- if (!interpreterRef.current) {
154
- const clock = createSystemClock();
155
- interpreterRef.current = createA2uiInterpreter({
156
- catalog,
157
- clock,
158
- ids: {
159
- next: (_required) => {
160
- actionIdCounter += 1;
161
- return `a2ui-action-${actionIdCounter}-${clock.nowMs().toString(36)}`;
162
- },
163
- },
164
- });
165
- }
166
- const interpreter = interpreterRef.current;
167
- const [, forceRender] = useState(0);
168
- const appliedCountRef = useRef(0);
169
- const surfaceIdRef = useRef(undefined);
170
- /** Monotonic ticket for `handleAction`'s agent-delivery attempts — see its use for why a host's
171
- * promises settling out of order would otherwise repaint a superseded failure. */
172
- const agentActionAttemptRef = useRef(0);
173
- const [refusalNotice, setRefusalNotice] = useState(null);
174
- const [pendingAgentAction, setPendingAgentAction] = useState(null);
175
- const [localActionResult, setLocalActionResult] = useState(null);
176
- const [deliveryFailureNotice, setDeliveryFailureNotice] = useState(null);
177
- useEffect(() => {
178
- const unsubscribe = interpreter.subscribe({ listener: () => forceRender((n) => n + 1) });
179
- // React invokes cleanup with no arguments; the interpreter's port takes a required bag.
180
- return () => unsubscribe({});
181
- }, [interpreter]);
182
- useEffect(() => {
183
- while (appliedCountRef.current < events.length) {
184
- const message = events[appliedCountRef.current];
185
- appliedCountRef.current += 1;
186
- const surfaceId = extractSurfaceId(message);
187
- if (surfaceId)
188
- surfaceIdRef.current = surfaceId;
189
- const result = interpreter.applyAgentMessage({ raw: message });
190
- if (result.unattributedViolation) {
191
- setRefusalNotice(result.unattributedViolation);
192
- }
193
- else {
194
- // A catalog-validation refusal (e.g. an unrecognized component type, or a known type with a
195
- // missing/invalid required prop) surfaces as an `error`-shaped entry in `rendererMessages`,
196
- // not `unattributedViolation`. Shown locally AND relayed through the exact same
197
- // `onAgentAction` pipe a button click already uses: `errorMessage` is a real
198
- // `RendererToAgentMessage` carrying `error.surfaceId`, which is all `onAgentAction`'s host
199
- // implementation needs to address it — no second callback prop, no new wire shape. Without
200
- // this relay a tool call that opened the surface has no way to learn its render was REFUSED
201
- // and returns success anyway, which is worse than the silent-"waiting" bug this comment used
202
- // to describe: it actively tells the agent (and, downstream, the human) that a chart is on
203
- // screen when it never rendered at all.
204
- const errorMessage = result.rendererMessages.find((m) => 'error' in m);
205
- if (errorMessage) {
206
- setRefusalNotice(errorMessage.error.message);
207
- void onAgentAction?.(runId, errorMessage);
208
- }
209
- else {
210
- // A message that applies cleanly clears any earlier refusal. `refusalNotice` describes
211
- // whether the CURRENT surface is broken, not a permanent scar from an earlier mistake this
212
- // same conversation already recovered from — e.g. a retry that fixed a missing prop, or an
213
- // unrelated later `updateDataModel`. Without this, a stale "Action refused" banner from an
214
- // early failed attempt sits underneath a chart that went on to render successfully.
215
- setRefusalNotice(null);
216
- }
217
- }
218
- }
219
- // `onAgentAction`/`runId` included: the loop above now calls `onAgentAction` directly (relaying
220
- // a validation error), not just on a later user click — the effect must see a fresh reference,
221
- // the same way `handleAction`'s own (non-effect) call site already gets one on every render.
222
- }, [events, interpreter, onAgentAction, runId]);
223
- const surfaceId = surfaceIdRef.current;
224
- const root = surfaceId ? interpreter.getRoot({ surfaceId }) : undefined;
225
- function handleAction(componentId) {
226
- // `surfaceId` is non-null here by construction, not by luck: this callback is only ever reached
227
- // from a `Button` inside the rendered tree, and nothing renders until `root` resolves — which
228
- // the `!root` early return below only permits when `surfaceId` was already truthy. Asserted
229
- // rather than re-checked, exactly as the `RenderComponent` call site below already does.
230
- const built = interpreter.buildAction({ surfaceId: surfaceId, componentId });
231
- if (!built.ok) {
232
- setRefusalNotice(built.reason);
233
- return;
234
- }
235
- setRefusalNotice(null);
236
- if (built.kind === 'local') {
237
- // `buildAction`'s local branch is a pure computation (`resolveDynamicValue` over a
238
- // registered catalog function's `impl`) — it never touches interpreter state, so there is
239
- // nothing for `interpreter.subscribe` to notify and no re-render to "reflect" it. The only
240
- // honest thing this component can do with the resolved value is show it.
241
- setPendingAgentAction(null);
242
- setLocalActionResult({ componentId, value: built.result });
243
- return;
244
- }
245
- setLocalActionResult(null);
246
- if (onAgentAction) {
247
- // Clearing here, not just at the top of `handleAction`: a *previous* click's delivery failure
248
- // must not linger next to a new attempt that has not resolved yet — same "stale notice beside
249
- // a working control" concern `refusalNotice`'s own clearing already guards against.
250
- setPendingAgentAction(null);
251
- setDeliveryFailureNotice(null);
252
- // Clearing the notice is not enough on its own: `onAgentAction` is host-supplied and its
253
- // promises are not guaranteed to settle in call order, so an OLDER click's rejection could
254
- // land after a newer one had already cleared the notice — repainting a failure the human has
255
- // since superseded, next to a control that just worked. Only the latest attempt may write.
256
- const attempt = (agentActionAttemptRef.current += 1);
257
- const isLatestAttempt = () => agentActionAttemptRef.current === attempt;
258
- const outcome = onAgentAction(runId, built.message);
259
- // `isThenable`, not `instanceof Promise` — see that helper's own doc for why.
260
- if (isThenable(outcome)) {
261
- void outcome.then((result) => {
262
- if (!result.ok && isLatestAttempt())
263
- setDeliveryFailureNotice(result.reason);
264
- }, (error) => {
265
- // A rejection is the host's transport breaking, not a message the host chose to report —
266
- // still surfaced, so the human sees *something* rather than a click that silently did
267
- // nothing.
268
- if (!isLatestAttempt())
269
- return;
270
- setDeliveryFailureNotice(error instanceof Error ? error.message : String(error));
271
- });
272
- }
273
- }
274
- else {
275
- setPendingAgentAction(JSON.stringify(built.message));
276
- }
277
- }
278
- function formatLocalActionValue(value) {
279
- if (value === undefined)
280
- return t('(no return value)');
281
- return typeof value === 'string' ? value : JSON.stringify(value);
282
- }
65
+ export function A2uiSurfaceCard({ events, runId, onAgentAction, clock, registry: registryProp, hooks = defaultA2uiSurfaceCardHooks }) {
66
+ const t = hooks.useT();
67
+ const surfaces = hooks.useChatSurfaces();
68
+ const registry = registryProp ?? surfaces.interactiveUi.defaultRegistry;
69
+ const { interpreter, surfaceId, root, refusalNotice, pendingAgentAction, localActionResult, deliveryFailureNotice, handleAction, formatLocalActionValue } = hooks.useA2uiSurfaceCard({ events, runId, onAgentAction, registry, t, clock });
283
70
  if (!root) {
284
- return refusalNotice ? (_jsx("div", { className: "a2ui-surface-card a2ui-surface-refused", role: "status", children: t('A2UI surface refused: {reason}', { reason: refusalNotice }) })) : (_jsx("div", { className: "a2ui-surface-card a2ui-surface-waiting", role: "status", children: t('Waiting for the agent to send a root component…') }));
71
+ return refusalNotice ? (_jsx("div", { className: "a2ui-surface-card a2ui-surface-refused", role: "status", children: t('A2UI surface refused: {reason}', { reason: refusalNotice }) })) : (_jsx("div", { className: "a2ui-surface-card jini-a2ui-surface-waiting", role: "status", children: t('Waiting for the agent to send a root component…') }));
285
72
  }
286
- return (_jsxs("div", { className: "a2ui-surface-card", "data-a2ui-surface-id": surfaceId, children: [_jsx(RenderComponent, { interpreter: interpreter, surfaceId: surfaceId, componentId: "root", ancestors: new Set(), onAction: handleAction, registry: registry }), refusalNotice ? (_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-refused", role: "status", children: t('Action refused: {reason}', { reason: refusalNotice }) })) : null, pendingAgentAction ? (_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-unwired", role: "status", children: t('This action is meant for the agent, but this host has not wired up a live agent-action relay yet.') })) : null, deliveryFailureNotice ? (
73
+ return (_jsxs("div", { className: "a2ui-surface-card", "data-a2ui-surface-id": surfaceId, children: [_jsx(RenderComponent, { interpreter: interpreter, surfaceId: surfaceId, componentId: "root", ancestors: new Set(), onAction: handleAction, registry: registry }), refusalNotice ? (_jsx("div", { className: "jini-a2ui-surface-notice a2ui-surface-notice-refused", role: "status", children: t('Action refused: {reason}', { reason: refusalNotice }) })) : null, pendingAgentAction ? (_jsx("div", { className: "jini-a2ui-surface-notice jini-a2ui-surface-notice-unwired", role: "status", children: t('This action is meant for the agent, but this host has not wired up a live agent-action relay yet.') })) : null, deliveryFailureNotice ? (
287
74
  // Deliberately its own notice, not folded into `refusalNotice` above: that one fires
288
75
  // *before* anything is sent (the interpreter said no); this one fires *after* — the message
289
76
  // left this component but the host reports it never arrived. Conflating them would tell the
290
77
  // human the wrong half of the story.
291
- _jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-delivery-failed", role: "status", children: t('This action could not be delivered: {reason}', { reason: deliveryFailureNotice }) })) : null, localActionResult ? (_jsx("div", { className: "a2ui-surface-notice a2ui-surface-notice-local-action", role: "status", "data-a2ui-component-id": localActionResult.componentId, children: t('Local action resolved: {value}', { value: formatLocalActionValue(localActionResult.value) }) })) : null] }));
78
+ _jsx("div", { className: "jini-a2ui-surface-notice a2ui-surface-notice-delivery-failed", role: "status", children: t('This action could not be delivered: {reason}', { reason: deliveryFailureNotice }) })) : null, localActionResult ? (_jsx("div", { className: "jini-a2ui-surface-notice jini-a2ui-surface-notice-local-action", role: "status", "data-a2ui-component-id": localActionResult.componentId, children: t('Local action resolved: {value}', { value: formatLocalActionValue(localActionResult.value) }) })) : null] }));
292
79
  }
293
80
  //# sourceMappingURL=A2uiSurfaceCard.js.map
@@ -0,0 +1,14 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ import { type A2uiInterpreter } from '@jini-ai/protocol/a2ui';
3
+ import type { RenderComponentProps } from './A2uiSurfaceCard.hooks.js';
4
+ /** Resolve dynamic text and explicit child IDs for the card's renderer. */
5
+ export declare function createA2uiCardNodeHelpers({ interpreter, surfaceId, childProps, renderNode: Node }: {
6
+ interpreter: A2uiInterpreter;
7
+ surfaceId: string;
8
+ childProps: Omit<RenderComponentProps, 'componentId'>;
9
+ renderNode: ComponentType<RenderComponentProps>;
10
+ }, _options?: {}): {
11
+ resolveText: (value: unknown) => string;
12
+ renderChildList: (children: unknown) => ReactNode;
13
+ };
14
+ //# sourceMappingURL=A2uiSurfaceCard.rules.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { createElement } from 'react';
2
+ import { parseDynamicValue } from '@jini-ai/protocol/a2ui';
3
+ /** Resolve dynamic text and explicit child IDs for the card's renderer. */
4
+ export function createA2uiCardNodeHelpers({ interpreter, surfaceId, childProps, renderNode: Node }, _options = {}) {
5
+ function resolveText(value) {
6
+ // Text props already passed the catalog schema. Parsing preserves that wire type at this
7
+ // Record<string, unknown> boundary without asserting a shape the compiler cannot verify.
8
+ const parsed = parseDynamicValue({ value });
9
+ if (!parsed.ok)
10
+ throw new Error(parsed.error);
11
+ const result = interpreter.resolve({ surfaceId, value: parsed.value });
12
+ if (!result.ok)
13
+ return `⚠ unresolved (${result.reason})`;
14
+ return typeof result.value === 'string' ? result.value : JSON.stringify(result.value);
15
+ }
16
+ function renderChildList(children) {
17
+ if (Array.isArray(children)) {
18
+ return children.map((childId) => createElement(Node, { key: String(childId), componentId: String(childId), ...childProps }));
19
+ }
20
+ return createElement('span', { className: 'a2ui-placeholder', 'data-a2ui-status': 'unimplemented-template-list' }, '⚠ dynamic (template) child lists are not implemented by this port');
21
+ }
22
+ return { resolveText, renderChildList };
23
+ }
24
+ //# sourceMappingURL=A2uiSurfaceCard.rules.js.map
@@ -1,4 +1,16 @@
1
+ /**
2
+ * @module AttachmentPreviewModal
3
+ *
4
+ * The "can we see it again" modal `MessageRow.tsx`'s attachment chip opens: an image scaled to fit,
5
+ * a scrollable monospace pane for a text-ish file, or - honestly, never a faked preview - the
6
+ * filename/type/size for anything else. All state/effects live in `useAttachmentPreviewModal`; this
7
+ * is the presentational shell, native-`<dialog>`-based like `Markdown.tsx`'s `TableBlock` pop-out.
8
+ * With `navigation` (more than one image in the message or the composer's staged set) a footer adds
9
+ * previous/next side by side in the bottom-right corner, plus ←/→ on the dialog.
10
+ */
11
+ import { useT } from '../hooks/context.js';
1
12
  import type { ChatAttachment } from '../../core/index.js';
13
+ import { useAttachmentPreviewModal } from './AttachmentPreviewModal.hooks.js';
2
14
  import type { AttachmentPreviewNavigation } from './AttachmentGallery.hooks.js';
3
15
  export interface AttachmentPreviewModalProps {
4
16
  attachment: ChatAttachment;
@@ -6,5 +18,13 @@ export interface AttachmentPreviewModalProps {
6
18
  /** Previous/next over the surrounding images; omitted for a lone attachment. */
7
19
  navigation?: AttachmentPreviewNavigation | undefined;
8
20
  }
9
- export declare function AttachmentPreviewModal({ attachment, onClose, navigation }: AttachmentPreviewModalProps): import("react").JSX.Element;
21
+ /** Hooks AttachmentPreviewModal calls; defaults to the real ones, a test hands in fakes. */
22
+ export declare const defaultAttachmentPreviewModalHooks: {
23
+ useT: typeof useT;
24
+ useAttachmentPreviewModal: typeof useAttachmentPreviewModal;
25
+ };
26
+ export type AttachmentPreviewModalHooks = typeof defaultAttachmentPreviewModalHooks;
27
+ export declare function AttachmentPreviewModal({ attachment, onClose, navigation, hooks }: AttachmentPreviewModalProps & {
28
+ hooks?: AttachmentPreviewModalHooks | undefined;
29
+ }): import("react").JSX.Element;
10
30
  //# sourceMappingURL=AttachmentPreviewModal.d.ts.map
@@ -167,7 +167,6 @@ export function useAttachmentPreviewModal({ attachment, onClose, navigation }, {
167
167
  const url = URL.createObjectURL(cachedFile);
168
168
  setImageUrl(url);
169
169
  return () => URL.revokeObjectURL(url);
170
- // eslint-disable-next-line react-hooks/exhaustive-deps
171
170
  }, [attemptImage, cachedFile]);
172
171
  useEffect(() => {
173
172
  if (!attemptText || !cachedFile) {
@@ -196,8 +195,7 @@ export function useAttachmentPreviewModal({ attachment, onClose, navigation }, {
196
195
  return () => {
197
196
  canceled = true;
198
197
  };
199
- // eslint-disable-next-line react-hooks/exhaustive-deps
200
- }, [attemptText, cachedFile]);
198
+ }, [attemptText, cachedFile, readText]);
201
199
  function handleNativeCancel(event) {
202
200
  // Always prevented, same reasoning as `ConfirmDialog.hooks.tsx`: the effect above is the single
203
201
  // source of truth for open/closed, so Escape still closes — it just does so through `onClose`
@@ -12,9 +12,11 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
12
12
  import { useT } from '../hooks/context.js';
13
13
  import { Icon } from './Icon.js';
14
14
  import { looksLikeImageAttachment, useAttachmentPreviewModal } from './AttachmentPreviewModal.hooks.js';
15
- export function AttachmentPreviewModal({ attachment, onClose, navigation }) {
16
- const t = useT();
17
- const c = useAttachmentPreviewModal({ attachment: attachment, onClose: onClose, navigation });
15
+ /** Hooks AttachmentPreviewModal calls; defaults to the real ones, a test hands in fakes. */
16
+ export const defaultAttachmentPreviewModalHooks = { useT, useAttachmentPreviewModal };
17
+ export function AttachmentPreviewModal({ attachment, onClose, navigation, hooks = defaultAttachmentPreviewModalHooks }) {
18
+ const t = hooks.useT();
19
+ const c = hooks.useAttachmentPreviewModal({ attachment: attachment, onClose: onClose, navigation });
18
20
  return (_jsxs("dialog", { ref: c.dialogRef, className: `jini-attachment-preview-dialog${navigation ? ' has-nav' : ''}`, role: "dialog", "aria-modal": "true", "aria-label": t('{name} preview', { name: attachment.name }), onCancel: c.handleNativeCancel, onClick: c.handleBackdropClick, onKeyDown: c.handleKeyDown, children: [_jsxs("div", { className: "jini-attachment-preview-header", children: [_jsx("span", { className: "jini-attachment-preview-name", title: attachment.name, children: attachment.name }), _jsx("button", { type: "button", className: "jini-attachment-preview-close", onClick: onClose, title: t('Close'), "aria-label": t('Close'), children: _jsx(Icon, { name: "close", size: 16 }) })] }), _jsx("div", { className: "jini-attachment-preview-body", children: _jsx(AttachmentPreviewBody, { attachment: attachment, preview: c }) }), navigation ? _jsx(AttachmentPreviewNav, { navigation: navigation }) : null] }));
19
21
  }
20
22
  /** The image, the text pane, or - for anything else - the filename/type/size card. */
@@ -26,19 +28,19 @@ function AttachmentPreviewBody({ attachment, preview }) {
26
28
  return _jsx(AttachmentTextPane, { preview: preview });
27
29
  return _jsx(AttachmentMetaCard, { attachment: attachment, sizeLabel: preview.sizeLabel });
28
30
  }
29
- function AttachmentTextPane({ preview }) {
30
- const t = useT();
31
+ function AttachmentTextPane({ preview, useTHook = useT }) {
32
+ const t = useTHook();
31
33
  if (preview.textLoading)
32
34
  return _jsx("div", { className: "jini-attachment-preview-loading", children: t('Loading…') });
33
35
  return (_jsxs(_Fragment, { children: [_jsx("pre", { className: "jini-attachment-preview-text", children: preview.text?.content ?? '' }), preview.text?.truncated ? (_jsx("div", { className: "jini-attachment-preview-truncated", children: t('Preview truncated — this file is larger than the preview limit.') })) : null] }));
34
36
  }
35
- function AttachmentMetaCard({ attachment, sizeLabel }) {
36
- const t = useT();
37
+ function AttachmentMetaCard({ attachment, sizeLabel, useTHook = useT }) {
38
+ const t = useTHook();
37
39
  return (_jsxs("div", { className: "jini-attachment-preview-meta", children: [_jsxs("div", { className: "jini-attachment-preview-meta-row", children: [_jsx("span", { className: "jini-attachment-preview-meta-label", children: t('Name') }), _jsx("span", { children: attachment.name })] }), _jsxs("div", { className: "jini-attachment-preview-meta-row", children: [_jsx("span", { className: "jini-attachment-preview-meta-label", children: t('Type') }), _jsx("span", { children: looksLikeImageAttachment({ attachment: attachment }) ? t('Image') : t('File') })] }), sizeLabel ? (_jsxs("div", { className: "jini-attachment-preview-meta-row", children: [_jsx("span", { className: "jini-attachment-preview-meta-label", children: t('Size') }), _jsx("span", { children: sizeLabel })] })) : null, _jsx("div", { className: "jini-attachment-preview-meta-note", children: t('A preview is not available for this file.') })] }));
38
40
  }
39
41
  /** Previous/next side by side in the bottom-right corner, with the "2 / 5" position before them. */
40
- function AttachmentPreviewNav({ navigation }) {
41
- const t = useT();
42
+ function AttachmentPreviewNav({ navigation, useTHook = useT }) {
43
+ const t = useTHook();
42
44
  return (_jsxs("div", { className: "jini-attachment-preview-nav", children: [_jsx("span", { className: "jini-attachment-preview-count", "aria-live": "polite", children: t('{index} / {count}', { index: navigation.index + 1, count: navigation.count }) }), _jsx("button", { type: "button", className: "jini-attachment-preview-step", onClick: navigation.onPrevious, title: t('Previous image'), "aria-label": t('Previous image'), children: _jsx(Icon, { name: "chevron-left", size: 18 }) }), _jsx("button", { type: "button", className: "jini-attachment-preview-step", onClick: navigation.onNext, title: t('Next image'), "aria-label": t('Next image'), children: _jsx(Icon, { name: "chevron-right", size: 18 }) })] }));
43
45
  }
44
46
  //# sourceMappingURL=AttachmentPreviewModal.js.map
@@ -1,4 +1,6 @@
1
+ import { useT } from '../hooks/context.js';
1
2
  import type { AttachmentTraySlot } from '../slots.js';
3
+ import { useAttachmentGallery } from './AttachmentGallery.hooks.js';
2
4
  import { type ObjectUrlPort } from './SentAttachment.hooks.js';
3
5
  import { formatAttachmentSize } from './attachment-size.js';
4
6
  export { formatAttachmentSize };
@@ -9,5 +11,13 @@ export type AttachmentTrayProps = AttachmentTraySlot & {
9
11
  /** An upload is still running: shows a spinning placeholder chip after the staged ones. */
10
12
  uploading?: boolean | undefined;
11
13
  };
12
- export declare function AttachmentTray({ agentHandle, attachments, onRemove, renderItem, objectUrls, uploading }: AttachmentTrayProps): import("react").JSX.Element | null;
14
+ /** Hooks AttachmentTray calls; defaults to the real ones, a test hands in fakes. */
15
+ export declare const defaultAttachmentTrayHooks: {
16
+ useT: typeof useT;
17
+ useAttachmentGallery: typeof useAttachmentGallery;
18
+ };
19
+ export type AttachmentTrayHooks = typeof defaultAttachmentTrayHooks;
20
+ export declare function AttachmentTray({ agentHandle, attachments, onRemove, renderItem, objectUrls, uploading, hooks }: AttachmentTrayProps & {
21
+ hooks?: AttachmentTrayHooks | undefined;
22
+ }): import("react").JSX.Element | null;
13
23
  //# sourceMappingURL=AttachmentTray.d.ts.map