@jini-ai/chat 0.7.3-next.1 → 0.7.3-next.3

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 (220) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +49 -0
  3. package/dist/core/accepted-input.d.ts +1 -1
  4. package/dist/core/ag-ui/event-projection.d.ts +14 -69
  5. package/dist/core/ag-ui/event-projection.js +58 -133
  6. package/dist/core/ag-ui/event-reduction.d.ts +12 -2
  7. package/dist/core/ag-ui/event-reduction.js +35 -10
  8. package/dist/core/ag-ui/resume.d.ts +110 -0
  9. package/dist/core/ag-ui/resume.js +200 -0
  10. package/dist/core/ag-ui/run-input.d.ts +23 -0
  11. package/dist/core/ag-ui/run-input.js +45 -0
  12. package/dist/core/ag-ui/server.d.ts +69 -0
  13. package/dist/core/ag-ui/server.js +71 -0
  14. package/dist/core/agent-plugin-chat-state.js +13 -11
  15. package/dist/core/assistant-client/ag-ui-approval-relay.d.ts +113 -0
  16. package/dist/core/assistant-client/ag-ui-approval-relay.js +287 -0
  17. package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +25 -10
  18. package/dist/core/assistant-client/ag-ui-fetch-agent.js +25 -6
  19. package/dist/core/assistant-client/ag-ui-transport.d.ts +86 -3
  20. package/dist/core/assistant-client/ag-ui-transport.js +310 -80
  21. package/dist/core/assistant-client/browser-durable-subscription.d.ts +25 -0
  22. package/dist/core/assistant-client/browser-durable-subscription.js +78 -0
  23. package/dist/core/assistant-client/durable-run-subscription.js +141 -130
  24. package/dist/core/assistant-client/entry.d.ts +2 -1
  25. package/dist/core/assistant-client/entry.js +1 -0
  26. package/dist/core/assistant-client/transport-prompt.d.ts +94 -0
  27. package/dist/core/assistant-client/transport-prompt.js +180 -0
  28. package/dist/core/assistant-client/transport-run.d.ts +49 -0
  29. package/dist/core/assistant-client/transport-run.js +432 -0
  30. package/dist/core/assistant-client/transport-stream.d.ts +73 -0
  31. package/dist/core/assistant-client/transport-stream.js +128 -0
  32. package/dist/core/assistant-client/transport.d.ts +1 -1
  33. package/dist/core/assistant-client/transport.js +129 -835
  34. package/dist/core/assistant-content.d.ts +1 -17
  35. package/dist/core/assistant-content.js +16 -0
  36. package/dist/core/assistant-tool-metadata.d.ts +103 -0
  37. package/dist/core/assistant-tool-metadata.js +56 -0
  38. package/dist/core/checkpoint-interval.d.ts +1 -1
  39. package/dist/core/compact-events.d.ts +1 -1
  40. package/dist/core/durable-projection.d.ts +1 -1
  41. package/dist/core/durable-runs/continuation.d.ts +1 -1
  42. package/dist/core/durable-runs/ledger-contracts.d.ts +4 -1
  43. package/dist/core/durable-runs/ports.d.ts +2 -1
  44. package/dist/core/durable-runs/run-contracts.d.ts +1 -1
  45. package/dist/core/durable-runs/run-finalizer.d.ts +145 -0
  46. package/dist/core/durable-runs/run-finalizer.js +171 -0
  47. package/dist/core/events.d.ts +4 -82
  48. package/dist/core/events.js +2 -1
  49. package/dist/core/index.d.ts +4 -1
  50. package/dist/core/index.js +2 -1
  51. package/dist/core/messages.d.ts +1 -1
  52. package/dist/core/persistence/index.d.ts +1 -1
  53. package/dist/core/persistence/index.js +1 -1
  54. package/dist/core/question-form/normalize.d.ts +9 -3
  55. package/dist/core/question-form/normalize.js +20 -20
  56. package/dist/core/question-form/scan.js +15 -19
  57. package/dist/core/run-activity.d.ts +1 -1
  58. package/dist/core/run-events/entry.d.ts +11 -63
  59. package/dist/core/run-events/entry.js +12 -7
  60. package/dist/core/todos.d.ts +1 -1
  61. package/dist/core/todos.js +8 -0
  62. package/dist/core/tool-call-detail.d.ts +8 -1
  63. package/dist/core/tool-call-detail.js +35 -12
  64. package/dist/core/tool-events.d.ts +1 -1
  65. package/dist/core/tool-output.js +2 -6
  66. package/dist/core/tools.d.ts +2 -1
  67. package/dist/core/transport.d.ts +1 -1
  68. package/dist/core/turn-usage.d.ts +1 -1
  69. package/dist/core/util/parser.js +70 -69
  70. package/dist/embed-widget/browser/embed-send-bridge.d.ts +44 -0
  71. package/dist/embed-widget/browser/embed-send-bridge.js +60 -0
  72. package/dist/embed-widget/browser/frontend-invocation-handler.d.ts +39 -0
  73. package/dist/embed-widget/browser/frontend-invocation-handler.js +151 -0
  74. package/dist/embed-widget/browser/frontend-session-bridge.d.ts +28 -0
  75. package/dist/embed-widget/browser/frontend-session-bridge.js +201 -257
  76. package/dist/embed-widget/browser/lazy-loader.js +16 -12
  77. package/dist/embed-widget/browser/session-store.d.ts +19 -1
  78. package/dist/embed-widget/browser/session-store.js +48 -17
  79. package/dist/embed-widget/transports/fetch-sse.d.ts +1 -1
  80. package/dist/embed-widget/vanilla/index.js +131 -67
  81. package/dist/embed-widget/vanilla/state.js +53 -38
  82. package/dist/react/admin-execution/ai-agent-presentation.d.ts +35 -0
  83. package/dist/react/admin-execution/ai-agent-presentation.js +39 -0
  84. package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.d.ts +22 -0
  85. package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.js +25 -0
  86. package/dist/react/chat-cleanup/ChatCleanupPanel.d.ts +15 -0
  87. package/dist/react/chat-cleanup/ChatCleanupPanel.js +17 -0
  88. package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +168 -0
  89. package/dist/react/chat-cleanup/chat-cleanup.hooks.js +83 -0
  90. package/dist/react/components/ChatCleanupDialog.d.ts +38 -0
  91. package/dist/react/components/ChatCleanupDialog.js +12 -0
  92. package/dist/react/components/ConversationList.d.ts +14 -5
  93. package/dist/react/components/ConversationList.hooks.d.ts +1 -0
  94. package/dist/react/components/ConversationList.hooks.js +4 -2
  95. package/dist/react/components/ConversationList.js +41 -5
  96. package/dist/react/components/Icon.d.ts +1 -1
  97. package/dist/react/components/Icon.js +2 -0
  98. package/dist/react/components/Markdown.js +6 -6
  99. package/dist/react/components/MarkdownLink.d.ts +25 -0
  100. package/dist/react/components/MarkdownLink.js +17 -0
  101. package/dist/react/components/MessageList.hooks.d.ts +4 -0
  102. package/dist/react/components/MessageList.hooks.js +16 -2
  103. package/dist/react/components/MessageList.js +14 -7
  104. package/dist/react/components/MessageList.rules.d.ts +5 -0
  105. package/dist/react/components/MessageList.rules.js +4 -0
  106. package/dist/react/components/RoutedA2uiSurfaceCard.d.ts +80 -0
  107. package/dist/react/components/RoutedA2uiSurfaceCard.js +15 -0
  108. package/dist/react/components/ToolCard.d.ts +4 -2
  109. package/dist/react/components/ToolCard.js +46 -4
  110. package/dist/react/components/ToolCard.rules.d.ts +5 -2
  111. package/dist/react/components/ToolCard.rules.js +12 -5
  112. package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
  113. package/dist/react/components/mcp-ui-surface-state.d.ts +3 -1
  114. package/dist/react/components/mcp-ui-surface-state.js +2 -2
  115. package/dist/react/components/own-link.d.ts +26 -0
  116. package/dist/react/components/own-link.js +36 -0
  117. package/dist/react/features/bridged-chat/create-staged-attachment-uploader.d.ts +7 -0
  118. package/dist/react/features/bridged-chat/create-staged-attachment-uploader.js +26 -0
  119. package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.d.ts +12 -0
  120. package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.js +60 -0
  121. package/dist/react/features/bridged-chat/index.d.ts +8 -0
  122. package/dist/react/features/bridged-chat/index.js +7 -0
  123. package/dist/react/features/bridged-chat/types.d.ts +49 -0
  124. package/dist/react/features/bridged-chat/types.js +2 -0
  125. package/dist/react/features/chat-pane/components/RuntimeDropUp.js +1 -1
  126. package/dist/react/features/chat-pane/create-daemon-attachment-uploader.d.ts +6 -0
  127. package/dist/react/features/chat-pane/create-daemon-attachment-uploader.js +101 -59
  128. package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.d.ts +3 -0
  129. package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.js +26 -16
  130. package/dist/react/features/chat-pane/model-options.d.ts +3 -1
  131. package/dist/react/features/chat-pane/model-options.js +3 -3
  132. package/dist/react/features/chat-pane/rules.js +4 -3
  133. package/dist/react/features/chat-pane/styles.d.ts +1 -1
  134. package/dist/react/features/chat-pane/styles.js +43 -11
  135. package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.d.ts +10 -0
  136. package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.js +19 -0
  137. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.d.ts +12 -0
  138. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.js +21 -0
  139. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.d.ts +13 -0
  140. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.js +9 -0
  141. package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.d.ts +12 -0
  142. package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.js +12 -0
  143. package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.d.ts +7 -0
  144. package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.js +43 -0
  145. package/dist/react/features/conversation-chat-pane/index.d.ts +9 -0
  146. package/dist/react/features/conversation-chat-pane/index.js +8 -0
  147. package/dist/react/features/conversation-chat-pane/rules.d.ts +25 -0
  148. package/dist/react/features/conversation-chat-pane/rules.js +29 -0
  149. package/dist/react/features/conversation-chat-pane/types.d.ts +139 -0
  150. package/dist/react/features/conversation-chat-pane/types.js +2 -0
  151. package/dist/react/features/conversations/conversation-controller.d.ts +16 -0
  152. package/dist/react/features/conversations/conversation-controller.js +280 -0
  153. package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.d.ts +15 -0
  154. package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.js +33 -0
  155. package/dist/react/features/conversations/hooks/useStoredConversations.hooks.d.ts +16 -0
  156. package/dist/react/features/conversations/hooks/useStoredConversations.hooks.js +36 -0
  157. package/dist/react/features/conversations/index.d.ts +9 -0
  158. package/dist/react/features/conversations/index.js +8 -0
  159. package/dist/react/features/conversations/types.d.ts +120 -0
  160. package/dist/react/features/conversations/types.js +2 -0
  161. package/dist/react/features/voice-input/space-hold-rules.d.ts +65 -0
  162. package/dist/react/features/voice-input/space-hold-rules.js +48 -0
  163. package/dist/react/hooks/testing/fake-transport.d.ts +1 -1
  164. package/dist/react/hooks/useAnsweredCards.d.ts +2 -1
  165. package/dist/react/hooks/useConversation.js +5 -2
  166. package/dist/react/hooks/useExtEventGroups.d.ts +1 -1
  167. package/dist/react/hooks/useRunActivity.d.ts +2 -1
  168. package/dist/react/hooks/useRunStream.d.ts +1 -1
  169. package/dist/react/hooks/useRunStream.js +1 -1
  170. package/dist/react/hooks/useSurfaceRecovery.js +3 -1
  171. package/dist/react/hooks/useToolTimeline.d.ts +2 -1
  172. package/dist/react/index.d.ts +5 -2
  173. package/dist/react/index.js +4 -2
  174. package/dist/react/message-blocks.d.ts +1 -48
  175. package/dist/react/message-blocks.js +47 -0
  176. package/dist/react/styles/chat-settings.css +14 -14
  177. package/dist/server/chat-cleanup-routes.d.ts +56 -0
  178. package/dist/server/chat-cleanup-routes.js +56 -0
  179. package/dist/server/durable-runs/recover.js +193 -171
  180. package/dist/server/run-finalizer/entry.js +133 -110
  181. package/dist/store/legacy/sqlite/conversations.js +29 -17
  182. package/dist/store/pglite/index.d.ts +1 -0
  183. package/dist/store/pglite/index.js +1 -0
  184. package/dist/store/ports.d.ts +12 -0
  185. package/dist/store/postgres/index.d.ts +1 -0
  186. package/dist/store/postgres/index.js +1 -0
  187. package/dist/store/runtime/attempt-base-retention.d.ts +57 -0
  188. package/dist/store/runtime/attempt-base-retention.js +103 -0
  189. package/dist/store/runtime/chat-maintenance.d.ts +16 -0
  190. package/dist/store/runtime/chat-maintenance.js +19 -0
  191. package/dist/store/runtime/chat-principal.d.ts +63 -0
  192. package/dist/store/runtime/chat-principal.js +39 -0
  193. package/dist/store/runtime/checkpoint-delta.d.ts +1 -1
  194. package/dist/store/runtime/durable-run-queries.d.ts +124 -0
  195. package/dist/store/runtime/durable-run-queries.js +122 -0
  196. package/dist/store/runtime/durable-run-store.d.ts +1 -1
  197. package/dist/store/runtime/durable-run-store.js +291 -343
  198. package/dist/store/runtime/entry.d.ts +3 -0
  199. package/dist/store/runtime/entry.js +3 -0
  200. package/dist/store/runtime/events-json.d.ts +1 -1
  201. package/dist/store/runtime/lazy-run-ledger.d.ts +19 -0
  202. package/dist/store/runtime/lazy-run-ledger.js +28 -0
  203. package/dist/store/runtime/run-ledger.d.ts +4 -1
  204. package/dist/store/runtime/run-ledger.js +256 -204
  205. package/dist/store/sql/bulk-deletion.d.ts +36 -0
  206. package/dist/store/sql/bulk-deletion.js +103 -0
  207. package/dist/store/sql/store-queries.d.ts +170 -0
  208. package/dist/store/sql/store-queries.js +212 -0
  209. package/dist/store/sql/store-rows.d.ts +106 -0
  210. package/dist/store/sql/store-rows.js +116 -0
  211. package/dist/store/sql/store-writes.d.ts +46 -0
  212. package/dist/store/sql/store-writes.js +161 -0
  213. package/dist/store/sql/store.d.ts +3 -16
  214. package/dist/store/sql/store.js +58 -428
  215. package/dist/store/sql/tables.d.ts +1 -0
  216. package/dist/store/sqlite/index.d.ts +1 -0
  217. package/dist/store/sqlite/index.js +1 -0
  218. package/dist/store/sqlite/schema.d.ts +1 -1
  219. package/dist/store/sqlite/schema.js +5 -1
  220. package/package.json +174 -23
@@ -7,7 +7,7 @@
7
7
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
8
  import { conversationUsage } from '../../core/turn-usage.js';
9
9
  import { projectAcceptedInputEvents } from '../../core/accepted-input.js';
10
- import { nextStickToBottom, startsNewTurn } from './MessageList.rules.js';
10
+ import { hasOverflow, nextStickToBottom, startsNewTurn } from './MessageList.rules.js';
11
11
  const prefersReducedMotion = () => typeof window !== 'undefined' && (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false);
12
12
  /** Recompute costs once per immutable transcript snapshot, including saved history on reload. */
13
13
  export function useConversationUsage({ messages }, _optional = {}) {
@@ -45,6 +45,8 @@ export function useMessageListAutoScroll({ messages, scrollIntent }, { onScrolle
45
45
  // State mirror of `!stickToBottomRef.current` for the "Jump to latest" button; the ref stays the
46
46
  // source of truth for the scroll effects, which must not wait for a render.
47
47
  const [awayFromLatest, setAwayFromLatest] = useState(false);
48
+ // Whether there is history above to jump up to; refreshed on scroll and whenever rows change size.
49
+ const [scrollable, setScrollable] = useState(false);
48
50
  // Runs BEFORE the scroll effect below (effects run in declaration order), so a send re-sticks in
49
51
  // time for that same commit's scroll. The user's own send (or retry) is an explicit "take me to
50
52
  // the latest turn": without this, a user who had scrolled up to read history and then sent stayed
@@ -91,6 +93,7 @@ export function useMessageListAutoScroll({ messages, scrollIntent }, { onScrolle
91
93
  if (!el || typeof ResizeObserver !== 'function')
92
94
  return undefined;
93
95
  const observer = new ResizeObserver(() => {
96
+ setScrollable(hasOverflow(el));
94
97
  if (!stickToBottomRef.current)
95
98
  return;
96
99
  el.scrollTop = el.scrollHeight;
@@ -104,6 +107,7 @@ export function useMessageListAutoScroll({ messages, scrollIntent }, { onScrolle
104
107
  stickToBottomRef.current = nextStickToBottom(el, { wasSticking: stickToBottomRef.current, previousScrollTop: lastScrollTopRef.current });
105
108
  lastScrollTopRef.current = el.scrollTop;
106
109
  setAwayFromLatest(!stickToBottomRef.current);
110
+ setScrollable(hasOverflow(el));
107
111
  };
108
112
  const jumpToLatest = useCallback(() => {
109
113
  const el = containerRef.current;
@@ -115,6 +119,16 @@ export function useMessageListAutoScroll({ messages, scrollIntent }, { onScrolle
115
119
  setAwayFromLatest(false);
116
120
  el.scrollTo({ top: el.scrollHeight, behavior: reducedMotion() ? 'auto' : 'smooth' });
117
121
  }, [reducedMotion]);
118
- return { containerRef, onScroll, awayFromLatest, jumpToLatest };
122
+ const jumpToTop = useCallback(() => {
123
+ const el = containerRef.current;
124
+ if (!el)
125
+ return;
126
+ // Unstick first, mirroring jumpToLatest: otherwise output streaming in during the smooth scroll
127
+ // re-sticks via the ResizeObserver and yanks the reader straight back down.
128
+ stickToBottomRef.current = false;
129
+ setAwayFromLatest(true);
130
+ el.scrollTo({ top: 0, behavior: reducedMotion() ? 'auto' : 'smooth' });
131
+ }, [reducedMotion]);
132
+ return { containerRef, onScroll, awayFromLatest, jumpToLatest, scrollable, jumpToTop };
119
133
  }
120
134
  //# sourceMappingURL=MessageList.hooks.js.map
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
3
  * @module MessageList
4
4
  *
@@ -38,7 +38,7 @@ export const MessageList = memo(function MessageList({ messages: sourceMessages,
38
38
  // Derive from the conversation's saved events, so replay/remount does not repeat the notice.
39
39
  const accessNoticeId = useMemo(() => messages.find(message => message.role === 'assistant'
40
40
  && message.events?.some(event => event.kind === 'status' && event.label === 'full_cli_access' && event.detail))?.id, [messages]);
41
- const { containerRef, onScroll, awayFromLatest, jumpToLatest } = hooks.useMessageListAutoScroll({ messages, scrollIntent }, onScrolled !== undefined ? { onScrolled } : {});
41
+ const { containerRef, onScroll, awayFromLatest, jumpToLatest, scrollable, jumpToTop } = hooks.useMessageListAutoScroll({ messages, scrollIntent }, onScrolled !== undefined ? { onScrolled } : {});
42
42
  return (_jsxs("div", { className: "jini-message-list", ref: containerRef, onScroll: onScroll, "data-agent-element": "chat-transcript", "data-agent-role": "list", "data-agent-label": "The conversation transcript, oldest message first", children: [messages.map((message, index) => renderMessageRow({
43
43
  message,
44
44
  showAccessNotice: message.id === accessNoticeId,
@@ -48,15 +48,22 @@ export const MessageList = memo(function MessageList({ messages: sourceMessages,
48
48
  sending: message.runId === undefined && messages[index - 1]?.inputPending === true,
49
49
  isStreaming,
50
50
  usageSummary: usageByMessage.get(message.id),
51
- }, rowProps)), (pendingPrompts ?? (pendingPrompt ? [pendingPrompt] : [])).map((prompt, index) => (_jsx(QueuedMessage, { prompt: prompt, renderAttachment: rowProps.renderAttachment }, prompt.id ?? index))), awayFromLatest && _jsx(JumpToLatest, { onJump: jumpToLatest })] }));
51
+ }, rowProps)), (pendingPrompts ?? (pendingPrompt ? [pendingPrompt] : [])).map((prompt, index) => (_jsx(QueuedMessage, { prompt: prompt, renderAttachment: rowProps.renderAttachment }, prompt.id ?? index))), awayFromLatest ? _jsx(JumpArrow, { direction: "down", onJump: jumpToLatest })
52
+ : scrollable ? _jsx(JumpArrow, { direction: "up", onJump: jumpToTop }) : null] }));
52
53
  });
53
54
  /**
54
- * Sticky, zero-height last child of the scroll container, so the button floats centred just above
55
- * the composer without a wrapper element changing the pane's flex layout.
55
+ * Sticky, zero-height last child of the scroll container, so the button floats at the list's
56
+ * bottom-right just above the composer without a wrapper element changing the pane's flex layout.
57
+ * Owner 2026-11-13: the centred "↓ Jump to latest" pill covered a message; it is an icon-only arrow
58
+ * now — down to the latest when scrolled away, up to the top when already there. The label lives in
59
+ * aria-label/title only, so screen readers and hover still name it.
56
60
  */
57
- function JumpToLatest({ onJump, useTHook = useT }) {
61
+ function JumpArrow({ direction, onJump, useTHook = useT }) {
58
62
  const t = useTHook();
59
- return (_jsx("div", { className: "jini-message-list__jump", children: _jsxs("button", { type: "button", className: "jini-message-list__jump-btn", onClick: onJump, children: [_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M12 5v14" }), _jsx("path", { d: "m19 12-7 7-7-7" })] }), t('Jump to latest')] }) }));
63
+ const label = direction === 'down' ? t('Jump to latest') : t('Jump to top');
64
+ return (_jsx("div", { className: "jini-message-list__jump", children: _jsx("button", { type: "button", className: "jini-message-list__jump-btn", onClick: onJump, "aria-label": label, title: label, children: _jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: direction === 'down'
65
+ ? _jsxs(_Fragment, { children: [_jsx("path", { d: "M12 5v14" }), _jsx("path", { d: "m19 12-7 7-7-7" })] })
66
+ : _jsxs(_Fragment, { children: [_jsx("path", { d: "M12 19V5" }), _jsx("path", { d: "m5 12 7-7 7 7" })] }) }) }) }));
60
67
  }
61
68
  /** Hooks QueuedMessage calls; defaults to the real ones, a test hands in fakes. */
62
69
  const defaultQueuedMessageHooks = { useT, useAttachmentGallery };
@@ -11,6 +11,11 @@ export declare function isScrolledToBottom(el: {
11
11
  scrollTop: number;
12
12
  clientHeight: number;
13
13
  }): boolean;
14
+ /** Whether the transcript is taller than its box, i.e. there is anywhere to scroll at all. */
15
+ export declare function hasOverflow(el: {
16
+ scrollHeight: number;
17
+ clientHeight: number;
18
+ }): boolean;
14
19
  /**
15
20
  * The sticky-follow flag after a `scroll` event.
16
21
  *
@@ -4,6 +4,10 @@ export const AT_BOTTOM_THRESHOLD_PX = 4;
4
4
  export function isScrolledToBottom(el) {
5
5
  return el.scrollHeight - el.scrollTop - el.clientHeight <= AT_BOTTOM_THRESHOLD_PX;
6
6
  }
7
+ /** Whether the transcript is taller than its box, i.e. there is anywhere to scroll at all. */
8
+ export function hasOverflow(el) {
9
+ return el.scrollHeight - el.clientHeight > AT_BOTTOM_THRESHOLD_PX;
10
+ }
7
11
  /**
8
12
  * The sticky-follow flag after a `scroll` event.
9
13
  *
@@ -0,0 +1,80 @@
1
+ import type { ComponentType } from "react";
2
+ import type { AdminChartProviderSnapshot } from "@jini-ai/core/contracts/headless/chart-providers";
3
+ import type { A2uiSurfaceCardProps } from "./A2uiSurfaceCard.js";
4
+ /**
5
+ * @file Makes `A2uiSurfaceCard` page-aware without touching the card itself, Jini's ext-event
6
+ * registry, or the daemon/tool that emits the a2ui events in the first place (`render-ui-tool.ts`
7
+ * already sends everything needed — this is purely about where the browser puts it).
8
+ *
9
+ * `hooks/use-dock-renderer-registry.hooks.ts` registers this component (not `A2uiSurfaceCard`
10
+ * directly) under `a2ui` in the dock's owned registry. `@jini-ai/chat/react`'s `MessageRow` calls the
11
+ * registered renderer as `renderer(props)` and treats the return value as a `ReactNode` — but the
12
+ * registration itself returns a React element via `createElement`, so
13
+ * React evaluates this component as a real element during its own reconciliation, not as a plain
14
+ * function call. That is what makes hooks safe to use from here — both `useRoutedA2uiSurfaceCard`
15
+ * below and, transitively, everything it calls — the same way it is already safe inside
16
+ * `A2uiSurfaceCard` itself.
17
+ *
18
+ * Routing target, dismiss state, and per-surfaceId error tracking live in
19
+ * `hooks/use-routed-a2ui-surface-card.hooks.ts`, split out the same way `SeeMore`/`SeeMore.hooks.tsx`
20
+ * does: that file owns the state, this one stays props-and-JSX only. (It sits in a `hooks/`
21
+ * subfolder rather than a sibling file — see that file's own doc for why, and for why it has no
22
+ * `*Port`/`useWiredX` pair despite that being this workspace's dominant hook shape elsewhere.)
23
+ *
24
+ * ## The routing decision
25
+ *
26
+ * `useRoutedA2uiSurfaceCard` reads `playground-render-target-bus.ts`'s registered node (set only by
27
+ * `features/playground/Playground.tsx`, on mount/unmount) as `target`:
28
+ *
29
+ * - **No target registered** (Playground is not the active page, or hasn't mounted its canvas
30
+ * yet): falls back to the exact pre-existing behavior — `<A2uiSurfaceCard>` renders inline,
31
+ * wherever this ext-event group lands in the transcript.
32
+ * - **Target registered**: `ReactDOM.createPortal`s the exact same `<A2uiSurfaceCard>` element
33
+ * into Playground's own DOM container instead. The card's own internals (interpreter, local
34
+ * action handling, `onAgentAction` wiring) are unchanged either way — only the DOM location
35
+ * differs. Multiple asks stack in that container in mount order (oldest first, matching normal
36
+ * reading order) — see `playground.css`'s `.playground-render-target` for the flex/gap layout
37
+ * that makes that look intentional rather than accidental.
38
+ *
39
+ * ## Dismissing a drawn surface
40
+ *
41
+ * Portaled surfaces get a small "×" so the canvas doesn't just accumulate forever. Only offered
42
+ * when portaled: the chat transcript is a history, not a scratch surface, so inline cards (no
43
+ * target registered) never get a dismiss control. (See the hooks file for why `dismissed` is local
44
+ * state rather than written back to the render-target bus.)
45
+ *
46
+ * ## A refusal never portals, even with a target registered — but only for AS LONG AS it's live
47
+ *
48
+ * A catalog-validation refusal is diagnostic chat output ("this failed, here's why"), not a real
49
+ * drawn artifact — putting it on Playground's canvas would make the whiteboard look broken instead
50
+ * of the request that actually failed. `hasError`, computed by the hook, tracks the CURRENT surface
51
+ * only, not "has this card ever seen an error" — see `hooks/use-routed-a2ui-surface-card.hooks.ts`
52
+ * for the full reasoning and the regression a sticky flag caused (a genuinely successful retry never
53
+ * reaching the canvas), which is why this file just reads `hasError` rather than deriving it itself.
54
+ */
55
+ export interface RoutedA2uiSurfaceCardProps extends A2uiSurfaceCardProps {
56
+ SurfaceCard: ComponentType<A2uiSurfaceCardProps>;
57
+ useTHook: () => (key: string) => string;
58
+ /** `generation` is the server's chart-provider generation (core's {@link AdminChartProviderSnapshot}); it keys the card so a new catalog remounts the interpreter. */
59
+ useChartRegistryHook: () => {
60
+ registry: NonNullable<A2uiSurfaceCardProps["registry"]>;
61
+ generation: AdminChartProviderSnapshot["generation"];
62
+ stylesheets: readonly string[];
63
+ };
64
+ /** Required seam for the routing/dismiss/error-tracking hook (the host binds its real
65
+ * `useRoutedA2uiSurfaceCard`); a test can pass a fake here to exercise this component's
66
+ * rendering (inline vs. portal, the dismiss control, refusal handling) without driving the real
67
+ * `playground-render-target-bus` subscription or the hook's own local state. Destructured off
68
+ * separately from `...props` below so it is never spread through to the real `A2uiSurfaceCard`. */
69
+ useRoutedA2uiSurfaceCardHook: (props: A2uiSurfaceCardProps) => {
70
+ target: HTMLElement | null;
71
+ dismissed: boolean;
72
+ setDismissed: (required: {
73
+ value: boolean;
74
+ }) => void;
75
+ hasError: boolean;
76
+ handleAgentAction: NonNullable<A2uiSurfaceCardProps["onAgentAction"]>;
77
+ };
78
+ }
79
+ export declare function RoutedA2uiSurfaceCard({ useRoutedA2uiSurfaceCardHook, useTHook, SurfaceCard, useChartRegistryHook, ...props }: RoutedA2uiSurfaceCardProps): import("react").JSX.Element | null;
80
+ //# sourceMappingURL=RoutedA2uiSurfaceCard.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { createPortal } from "react-dom";
4
+ export function RoutedA2uiSurfaceCard({ useRoutedA2uiSurfaceCardHook, useTHook, SurfaceCard, useChartRegistryHook, ...props }) {
5
+ const t = useTHook();
6
+ const { registry, generation, stylesheets } = useChartRegistryHook();
7
+ const { target, dismissed, setDismissed, hasError, handleAgentAction } = useRoutedA2uiSurfaceCardHook(props);
8
+ if (target && !hasError) {
9
+ if (dismissed)
10
+ return null;
11
+ return createPortal(_jsxs("div", { className: "playground-drawn-surface", children: [_jsx("button", { type: "button", className: "playground-drawn-surface-dismiss", onClick: () => setDismissed({ value: true }), "aria-label": t("Remove from canvas"), children: "\u00D7" }), stylesheets.map((href) => _jsx("link", { rel: "stylesheet", href: href }, href)), _createElement(SurfaceCard, { ...props, key: generation, registry: registry, onAgentAction: handleAgentAction })] }), target);
12
+ }
13
+ return _jsxs(_Fragment, { children: [stylesheets.map((href) => _jsx("link", { rel: "stylesheet", href: href }, href)), _createElement(SurfaceCard, { ...props, key: generation, registry: registry, onAgentAction: handleAgentAction })] });
14
+ }
15
+ //# sourceMappingURL=RoutedA2uiSurfaceCard.js.map
@@ -1,6 +1,7 @@
1
1
  import { type Logger } from '@jini-ai/core/primitives';
2
- import type { AgentEvent } from '../../core/index.js';
2
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
3
3
  import { useToolRendererRegistry } from '../hooks/context.js';
4
+ import { useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
4
5
  type ToolUseEvent = Extract<AgentEvent, {
5
6
  kind: 'tool_use';
6
7
  }>;
@@ -22,8 +23,9 @@ export interface ToolCardProps {
22
23
  /** A later call of the same tool in this turn succeeded (`retriedToolRowIds`): a failure shows a neutral "Retried" badge, not red. */
23
24
  retried?: boolean;
24
25
  }
25
- export declare function ToolCard({ use, result, runStreaming, runSucceeded, projectFileNames, onRequestOpenFile, retried, report, useToolRendererRegistryHook }: ToolCardProps & {
26
+ export declare function ToolCard({ use, result, runStreaming, runSucceeded, projectFileNames, onRequestOpenFile, retried, report, useToolRendererRegistryHook, useCopyToClipboardHook }: ToolCardProps & {
26
27
  useToolRendererRegistryHook?: typeof useToolRendererRegistry;
28
+ useCopyToClipboardHook?: typeof useCopyToClipboard;
27
29
  }): import("react").JSX.Element | null;
28
30
  export {};
29
31
  //# sourceMappingURL=ToolCard.d.ts.map
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { createConsoleLogger } from '@jini-ai/core/primitives';
3
3
  const RUNNING_TITLE_CLASS = ' shimmer-text';
4
4
  /**
@@ -25,6 +25,7 @@ const RUNNING_TITLE_CLASS = ' shimmer-text';
25
25
  import { createContext, useContext, useId, useMemo, useState } from 'react';
26
26
  import { COLLAPSED_DETAIL_MAX_CHARS, describeCollapsedToolCall, describeToolCallDetail, humanizeToolName, isDelegatedWrapperToolName, isTodoWriteToolName, parseTodoWriteInput, redactUserText, toRenderProps } from '../../core/index.js';
27
27
  import { useT, useToolRendererRegistry } from '../hooks/context.js';
28
+ import { useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
28
29
  import { Icon } from './Icon.js';
29
30
  import { SAFE_LINK_HREF } from './Markdown.js';
30
31
  import { TodoCard } from './TodoCard.js';
@@ -37,14 +38,18 @@ import { toolPresentation } from '../../core/tool-presentation.js';
37
38
  const RetriedContext = createContext(false);
38
39
  /** A Jini registry tool id: dotted, lowercase, snake_case segments — `page.fill`, `daemon.db.vacuum`, `chat.send_message`. Never matches an agent-vendor tool name (`Bash`, `Write`, `mcp__jini__execute_delegated_tool`), which is the point — this is how a canonical delegated-tool event is told apart from everything else. */
39
40
  const JINI_TOOL_ID_PATTERN = /^[a-z][a-z_]*(\.[a-z][a-z_]*)+$/;
40
- export function ToolCard({ use, result, runStreaming, runSucceeded, projectFileNames, onRequestOpenFile, retried = false, report, useToolRendererRegistryHook = useToolRendererRegistry }) {
41
+ export function ToolCard({ use, result, runStreaming, runSucceeded, projectFileNames, onRequestOpenFile, retried = false, report, useToolRendererRegistryHook = useToolRendererRegistry, useCopyToClipboardHook = useCopyToClipboard }) {
41
42
  const registry = useToolRendererRegistryHook();
42
43
  // Resolve vendor dialects for rendering only; tool ids and stored events stay intact.
43
44
  const presentation = toolPresentation(use);
44
45
  use = { ...use, ...presentation };
45
46
  const name = use.name;
46
47
  const card = { input: use.input, result: result, runStreaming: runStreaming ?? false, runSucceeded: runSucceeded ?? false };
47
- const content = renderToolCardBody({ use, card, wrapper: presentation.wrapper, fileCtx: { projectFileNames, onRequestOpenFile }, registry, report });
48
+ // Classified on the normalized name and ahead of every registered or family renderer: a failed
49
+ // choice's protocol text must not reach any renderer, including one a host registers later.
50
+ const content = result?.isError === true && isChoiceToolName({ name: name })
51
+ ? _jsx(FailedChoiceCard, { result: result, useTHook: useT, useCopyToClipboardHook: useCopyToClipboardHook })
52
+ : renderToolCardBody({ use, card, wrapper: presentation.wrapper, fileCtx: { projectFileNames, onRequestOpenFile }, registry, report });
48
53
  if (content === null)
49
54
  return null;
50
55
  // Tagged once here, at the single dispatch point every branch below funnels through, rather than
@@ -54,6 +59,43 @@ export function ToolCard({ use, result, runStreaming, runSucceeded, projectFileN
54
59
  // ambiguous the way a repeated literal handle would be.
55
60
  return (_jsx("div", { "data-agent-element": `tool-call-${use.id}`, "data-agent-role": "region", "data-agent-label": `A ${humanizeToolName({ name: name })} tool call the AI made`, children: _jsx(RetriedContext.Provider, { value: retried, children: content }) }));
56
61
  }
62
+ const CHOICE_TOOL_NAME = 'assistant_ask_choice';
63
+ /** Bare `assistant_ask_choice`, or `mcp__<server>__assistant_ask_choice` whose exact tool segment is it — never a suffix match (`my_assistant_ask_choice`). O(n) in the name. */
64
+ function isChoiceToolName({ name }, _optional = {}) {
65
+ if (name === CHOICE_TOOL_NAME)
66
+ return true;
67
+ if (!name.startsWith('mcp__'))
68
+ return false;
69
+ // The server segment is at least one character, so its closing `__` starts at index 6 or later.
70
+ const separator = name.indexOf('__', 6);
71
+ return separator !== -1 && name.slice(separator + 2) === CHOICE_TOOL_NAME;
72
+ }
73
+ /** A host translation, or the English default when the adapter has none (it echoes the key or returns ''). */
74
+ function translated({ t, key, fallback }, _optional = {}) {
75
+ const text = t(key);
76
+ return text === '' || text === key ? fallback : text;
77
+ }
78
+ /**
79
+ * A failed `assistant_ask_choice`. Failed tool protocol text (the choice schema, the assistant's own
80
+ * inputs) is for the assistant to repair its call, not a user-facing explanation, so the row,
81
+ * badge, collapsed reader and panel only ever get a safe projection carrying the plain sentence.
82
+ * The redacted diagnostic is built on click and handed straight to the clipboard hook — never
83
+ * rendered, logged, or stored in an attribute. The two representations stay separate so a new
84
+ * renderer cannot accidentally publish the diagnostic.
85
+ */
86
+ function FailedChoiceCard({ result, useTHook, useCopyToClipboardHook }, _optional = {}) {
87
+ const t = useTHook();
88
+ const { copied, copy } = useCopyToClipboardHook();
89
+ const sentence = translated({ t, key: 'chat.toolCard.choiceFailed', fallback: "The assistant couldn't open the choice form. Ask it to try again." });
90
+ const copyLabel = translated({ t, key: 'chat.toolCard.copyDetails', fallback: 'Copy details' });
91
+ const safeResult = { kind: 'tool_result', toolUseId: result.toolUseId, content: sentence, isError: true };
92
+ const safeCall = { input: undefined, result: safeResult, runStreaming: false, runSucceeded: false };
93
+ const copyDetails = () => {
94
+ const diagnostic = describeToolCallDetail({ input: undefined, result }, { resultPresentation: 'copy-diagnostic' }).outputText;
95
+ void copy(diagnostic ?? sentence);
96
+ };
97
+ return (_jsx(ExpandableCard, { className: "jini-op-generic jini-op-choice-failed", call: safeCall, head: _jsxs(_Fragment, { children: [_jsx(ResultBadge, { result: safeResult, runStreaming: false, runSucceeded: false }), _jsx("span", { className: "jini-op-sr-prefix", children: `${t('Tool call')} · ` }), _jsx("span", { className: "op-title", children: sentence })] }), children: _jsxs("div", { className: "jini-op-card-detail", children: [_jsx("p", { className: "jini-op-detail-note", children: sentence }), _jsx("button", { type: "button", className: "jini-op-copy-details", onClick: copyDetails, children: copied ? t('Copied') : copyLabel }), _jsx("span", { className: "jini-message-copy-status", "aria-live": "polite", children: copied ? t('Copied to clipboard') : '' })] }) }));
98
+ }
57
99
  // Hardcoded family cards for tools shipped with this package, keyed by every name each tool goes
58
100
  // by. A `Map`, not an object literal, so a tool named `constructor`/`toString` can never resolve
59
101
  // to an inherited `Object.prototype` member.
@@ -219,7 +261,7 @@ function FileReadCard({ input, result, runStreaming, runSucceeded, ctx, useTHook
219
261
  const obj = (input ?? {});
220
262
  const file = obj.file_path ?? obj.filePath ?? obj.path ?? '(unnamed)';
221
263
  // See OpenInTabButton's baseName comment: `.split('/').pop()` is never undefined.
222
- const baseName = targetAtOffset({ target: file.split('/').pop(), offset: obj.offset });
264
+ const baseName = targetAtOffset({ target: file.split('/').pop(), offset: obj.offset, limit: obj.limit });
223
265
  const call = { input, result, runStreaming, runSucceeded };
224
266
  return (_jsx(FamilyCard, { call: call, className: "jini-op-file", shimmer: true, title: t('Read'), meta: _jsx("span", { className: "jini-op-meta", children: baseName }), after: _jsx(FileErrorDetail, { result: result }), children: _jsxs("div", { className: "jini-op-card-detail jini-op-card-file-detail", children: [_jsx("code", { className: "jini-op-path", children: file }), _jsx(OpenInTabButton, { filePath: file, ctx: ctx })] }) }));
225
267
  }
@@ -17,9 +17,12 @@ export declare function toolRowTarget({ input, resultContent }: {
17
17
  input: unknown;
18
18
  resultContent?: string | undefined;
19
19
  }): string | undefined;
20
- /** Preserve absent/invalid offsets; explicit zero still distinguishes a first-page read. */
21
- export declare function targetAtOffset({ target, offset }: {
20
+ /** Preserve absent/invalid offsets; explicit zero still distinguishes a first-page read. Limits follow the same rule.
21
+ * The read window (offset and/or limit) is appended so two reads of one file stay distinguishable.
22
+ */
23
+ export declare function targetAtOffset({ target, offset, limit }: {
22
24
  target: string | undefined;
23
25
  offset: unknown;
26
+ limit?: unknown;
24
27
  }, _options?: {}): string | undefined;
25
28
  //# sourceMappingURL=ToolCard.rules.d.ts.map
@@ -89,12 +89,19 @@ export function toolRowTarget({ input, resultContent }) {
89
89
  const args = (input ?? {});
90
90
  const named = firstReadable(args, SUMMARY_KEYS) ?? resultName(resultContent);
91
91
  const target = named ?? batchTarget(args) ?? firstReadable(args, KIND_KEYS) ?? Object.values(args).find(readable);
92
- return targetAtOffset({ target, offset: args.offset });
92
+ return targetAtOffset({ target, offset: args.offset, limit: args.limit });
93
93
  }
94
- /** Preserve absent/invalid offsets; explicit zero still distinguishes a first-page read. */
95
- export function targetAtOffset({ target, offset }, _options = {}) {
96
- if (!target || typeof offset !== 'number')
94
+ /** A valid window bound is a safe non-negative integer; anything else is ignored rather than shown. */
95
+ function windowBound({ label, value }) {
96
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? `${label} ${value}` : undefined;
97
+ }
98
+ /** Preserve absent/invalid offsets; explicit zero still distinguishes a first-page read. Limits follow the same rule.
99
+ * The read window (offset and/or limit) is appended so two reads of one file stay distinguishable.
100
+ */
101
+ export function targetAtOffset({ target, offset, limit }, _options = {}) {
102
+ if (!target)
97
103
  return target;
98
- return Number.isSafeInteger(offset) && offset >= 0 ? `${target} (offset ${offset})` : target;
104
+ const window = [windowBound({ label: 'offset', value: offset }), windowBound({ label: 'limit', value: limit })].filter(Boolean);
105
+ return window.length > 0 ? `${target} (${window.join(', ')})` : target;
99
106
  }
100
107
  //# sourceMappingURL=ToolCard.rules.js.map
@@ -1,7 +1,7 @@
1
1
  /** Read display context from a standalone form; its host may not have emitted a tool call. */
2
2
  import { type UIResource } from '@jini-ai/protocol/mcp-ui';
3
- import type { AgentEvent } from '../../core/events.js';
4
3
  import type { AcceptedInputProjectionOptions } from '../../core/accepted-input.js';
4
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
5
5
  /** Feed recovered form context into the existing receipt projection, including after history reload.
6
6
  * Grouping owns tool/surface association; this hook only supplies missing presentation context.
7
7
  * @complexity O(e + h + c) for events, parsed HTML and controls; no mutation or I/O.
@@ -25,7 +25,9 @@ export declare function closedSurfaceLabel({ t, call, runStreaming, documentsFor
25
25
  *
26
26
  * @complexity O(1).
27
27
  */
28
- export declare function isDeliveredAnswer(result: unknown): boolean;
28
+ export declare function isDeliveredAnswer({ result }: {
29
+ result: unknown;
30
+ }, _optional?: Record<string, never>): boolean;
29
31
  /**
30
32
  * Wraps a card's tool executor so a delivered answer is reported once it resolves. The result is
31
33
  * passed through unchanged; onAnswerText receives readable choice text when available. A rejected call
@@ -60,7 +60,7 @@ export function closedSurfaceLabel({ t, call, runStreaming, documentsForUri, exp
60
60
  *
61
61
  * @complexity O(1).
62
62
  */
63
- export function isDeliveredAnswer(result) {
63
+ export function isDeliveredAnswer({ result }, _optional = {}) {
64
64
  return typeof result === 'object' && result !== null && result.delivered === true;
65
65
  }
66
66
  /**
@@ -73,7 +73,7 @@ export function isDeliveredAnswer(result) {
73
73
  export function reportDeliveredAnswer({ onToolCall, onAnswered, onAnswerText, input }) {
74
74
  return async (call) => {
75
75
  const result = await onToolCall(call);
76
- if (isDeliveredAnswer(result)) {
76
+ if (isDeliveredAnswer({ result })) {
77
77
  const text = questionAnswerText({ answer: call.arguments, input });
78
78
  if (text !== undefined)
79
79
  onAnswerText?.(text);
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file Which chat links count as "the owner's own site or admin".
3
+ *
4
+ * Owner decision 2026-11-21 (reverses 2026-10-08, when every chat link opened a new tab): a link to
5
+ * the owner's own site or admin navigates the current tab from its text, with a small icon right
6
+ * after it for a new tab. Links to any other website keep opening a new tab. This is the one place
7
+ * that decides which is which, so the markdown renderer (which draws the icon) and the pane's click
8
+ * guard (which leaves own links to the browser or the host's router) cannot disagree.
9
+ */
10
+ /** The page's own origin, or `''` where there is no `window` (server render), which matches nothing. */
11
+ export declare function currentOrigin(_required?: Record<string, never>, _options?: {}): string;
12
+ /**
13
+ * Whether `href` points at `origin`'s own site: an in-app path, or an absolute URL on exactly that
14
+ * origin (scheme, host and port). A same-document `#anchor`, `mailto:`, a protocol-relative `//host`
15
+ * and anything unparseable are not own links, so each keeps the behaviour it had.
16
+ *
17
+ * @param input.href - The link target as written (a path) or resolved (absolute).
18
+ * @param input.origin - The origin that counts as own; usually {@link currentOrigin}.
19
+ * @returns `true` when the link text should navigate this tab.
20
+ * @complexity O(n) in the href length (one URL parse); no I/O.
21
+ */
22
+ export declare function isOwnLinkHref({ href, origin }: {
23
+ href: string;
24
+ origin: string;
25
+ }, _options?: {}): boolean;
26
+ //# sourceMappingURL=own-link.d.ts.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file Which chat links count as "the owner's own site or admin".
3
+ *
4
+ * Owner decision 2026-11-21 (reverses 2026-10-08, when every chat link opened a new tab): a link to
5
+ * the owner's own site or admin navigates the current tab from its text, with a small icon right
6
+ * after it for a new tab. Links to any other website keep opening a new tab. This is the one place
7
+ * that decides which is which, so the markdown renderer (which draws the icon) and the pane's click
8
+ * guard (which leaves own links to the browser or the host's router) cannot disagree.
9
+ */
10
+ /** The page's own origin, or `''` where there is no `window` (server render), which matches nothing. */
11
+ export function currentOrigin(_required = {}, _options = {}) {
12
+ return typeof window === 'undefined' ? '' : window.location.origin;
13
+ }
14
+ /**
15
+ * Whether `href` points at `origin`'s own site: an in-app path, or an absolute URL on exactly that
16
+ * origin (scheme, host and port). A same-document `#anchor`, `mailto:`, a protocol-relative `//host`
17
+ * and anything unparseable are not own links, so each keeps the behaviour it had.
18
+ *
19
+ * @param input.href - The link target as written (a path) or resolved (absolute).
20
+ * @param input.origin - The origin that counts as own; usually {@link currentOrigin}.
21
+ * @returns `true` when the link text should navigate this tab.
22
+ * @complexity O(n) in the href length (one URL parse); no I/O.
23
+ */
24
+ export function isOwnLinkHref({ href, origin }, _options = {}) {
25
+ if (href.startsWith('//'))
26
+ return false;
27
+ if (href.startsWith('/'))
28
+ return true;
29
+ try {
30
+ return origin !== '' && new URL(href).origin === origin;
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ }
36
+ //# sourceMappingURL=own-link.js.map
@@ -0,0 +1,7 @@
1
+ import type { ChatPaneProps } from '../chat-pane/types.js';
2
+ import type { AttachmentStagingPort } from './types.js';
3
+ /** Builds the uploader over the host's staging bridge. */
4
+ export declare function createStagedAttachmentUploader({ bridge }: {
5
+ bridge: AttachmentStagingPort;
6
+ }, _options?: Record<string, never>): NonNullable<ChatPaneProps['uploadAttachments']>;
7
+ //# sourceMappingURL=create-staged-attachment-uploader.d.ts.map
@@ -0,0 +1,26 @@
1
+ /** `File.type` is the browser's own MIME sniff off the dropped/picked file — good enough to tell
2
+ * `ChatPane` how to render the attachment chip; not a security boundary either way. */
3
+ function attachmentKind({ file }, _options = {}) {
4
+ return file.type.startsWith('image/') ? 'image' : 'file';
5
+ }
6
+ async function stageOne({ bridge, file, order }, _options = {}) {
7
+ const data = await file.arrayBuffer();
8
+ const { path } = await bridge.saveChatAttachment({ name: file.name, data });
9
+ return { path, name: file.name, kind: attachmentKind({ file }), size: file.size, order };
10
+ }
11
+ /** Builds the uploader over the host's staging bridge. */
12
+ export function createStagedAttachmentUploader({ bridge }, _options = {}) {
13
+ return async function uploadAttachments(files, options) {
14
+ if (files.length === 0)
15
+ return [];
16
+ // `options?.signal` covers a composer reset/unmount mid-upload; there is nothing partial to
17
+ // clean up on the host's side (its staging directory is wiped at every boot, not accumulated
18
+ // across a session's worth of abandoned drafts), so an abort simply drops the result on the
19
+ // floor rather than rolling anything back.
20
+ const staged = await Promise.all(files.map((file, order) => stageOne({ bridge, file, order })));
21
+ if (options?.signal.aborted === true)
22
+ return [];
23
+ return staged;
24
+ };
25
+ }
26
+ //# sourceMappingURL=create-staged-attachment-uploader.js.map
@@ -0,0 +1,12 @@
1
+ import type { BridgedChatTransport, ChatBridgePort, DisposableChatTransport } from '../types.js';
2
+ /**
3
+ * @param getBridge the host's bridge lookup; called once per identity, never per render.
4
+ * @param createTransport builds the host's run transport on the bridge. Its construction may
5
+ * install a listener; the hook disposes it when the bridge changes or the pane unmounts. Must
6
+ * be referentially stable.
7
+ */
8
+ export declare function useBridgedChatTransport<B extends ChatBridgePort, TTransport extends DisposableChatTransport>({ getBridge, createTransport }: {
9
+ getBridge: () => B | undefined;
10
+ createTransport: (bridge: B) => TTransport;
11
+ }, _options?: Record<string, never>): BridgedChatTransport<TTransport>;
12
+ //# sourceMappingURL=useBridgedChatTransport.hooks.d.ts.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @file A chat pane's bridge-backed surfaces: the run transport built on the host bridge, plus the
3
+ * runtime-access, working-directory, file-path and attachment surfaces `ChatPane` needs. All of them
4
+ * come from one bridge lookup, so they live in one hook rather than one per concern.
5
+ */
6
+ import { useEffect, useMemo, useState } from 'react';
7
+ import { createStagedAttachmentUploader } from '../create-staged-attachment-uploader.js';
8
+ /**
9
+ * @param getBridge the host's bridge lookup; called once per identity, never per render.
10
+ * @param createTransport builds the host's run transport on the bridge. Its construction may
11
+ * install a listener; the hook disposes it when the bridge changes or the pane unmounts. Must
12
+ * be referentially stable.
13
+ */
14
+ export function useBridgedChatTransport({ getBridge, createTransport }, _options = {}) {
15
+ const bridge = useMemo(() => getBridge(), [getBridge]);
16
+ const runtimeAccess = useMemo(() => {
17
+ if (bridge === undefined)
18
+ return undefined;
19
+ return {
20
+ listAgents: bridge.listAgents,
21
+ rescanAgents: bridge.rescanAgents,
22
+ daemonOnline: bridge.daemonOnline,
23
+ };
24
+ }, [bridge]);
25
+ const workingDirectoryAccess = useMemo(() => {
26
+ if (bridge === undefined)
27
+ return undefined;
28
+ return {
29
+ normalizeWorkingDirectory: (directory) => bridge.normalizeWorkingDirectory({ directory }),
30
+ pickWorkingDirectory: (currentDirectory) => bridge.pickWorkingDirectory({}, { currentDirectory }),
31
+ recentDirectories: bridge.recentWorkingDirectories,
32
+ directoryExists: (directory) => bridge.workingDirectoryExists({ directory }),
33
+ };
34
+ }, [bridge]);
35
+ const [binding, setBinding] = useState();
36
+ // Construction installs a listener, so setup and disposal must share an effect lifetime.
37
+ // StrictMode can discard a render and replay setup/cleanup without rebuilding memoized values.
38
+ // A new `createTransport` identity rebuilds the transport, so a host passes a module-level factory.
39
+ useEffect(() => {
40
+ if (bridge === undefined) {
41
+ setBinding(undefined);
42
+ return;
43
+ }
44
+ const transport = createTransport(bridge);
45
+ setBinding({ bridge, transport });
46
+ return () => transport.dispose();
47
+ }, [bridge, createTransport]);
48
+ const transport = binding?.bridge === bridge ? binding?.transport : undefined;
49
+ // A bridge host has no HTTP server, so this is the staging uploader
50
+ // (`create-staged-attachment-uploader.ts`), not the daemon-backed one — see that module's doc.
51
+ const uploadAttachments = useMemo(() => (bridge === undefined ? undefined : createStagedAttachmentUploader({ bridge })), [bridge]);
52
+ return {
53
+ transport,
54
+ runtimeAccess,
55
+ workingDirectoryAccess,
56
+ getPathForFile: bridge?.getPathForFile,
57
+ uploadAttachments,
58
+ };
59
+ }
60
+ //# sourceMappingURL=useBridgedChatTransport.hooks.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@jini-ai/chat/react/bridged-chat` — `ChatPane` surfaces for a host that reaches its runtime,
3
+ * working directories and attachment staging through one injected bridge instead of HTTP.
4
+ */
5
+ export { createStagedAttachmentUploader } from './create-staged-attachment-uploader.js';
6
+ export { useBridgedChatTransport } from './hooks/useBridgedChatTransport.hooks.js';
7
+ export type { AttachmentStagingPort, BridgedChatTransport, ChatBridgePort, DisposableChatTransport, } from './types.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `@jini-ai/chat/react/bridged-chat` — `ChatPane` surfaces for a host that reaches its runtime,
3
+ * working directories and attachment staging through one injected bridge instead of HTTP.
4
+ */
5
+ export { createStagedAttachmentUploader } from './create-staged-attachment-uploader.js';
6
+ export { useBridgedChatTransport } from './hooks/useBridgedChatTransport.hooks.js';
7
+ //# sourceMappingURL=index.js.map