@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
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @file Structural ports for a chat pane whose host reaches its agent runtime, working directories
3
+ * and attachment staging through one injected bridge object (an Electron preload bridge, typically)
4
+ * instead of HTTP. A host's own bridge satisfies these as-is.
5
+ */
6
+ import type { ChatPaneProps, ChatPaneRuntimeAccess, ChatPaneWorkingDirectoryAccess } from '../chat-pane/types.js';
7
+ /** Writes one file's bytes into the host's staging area and answers with the staged absolute path. */
8
+ export interface AttachmentStagingPort {
9
+ /** `name` is the `File`'s original name; a host derives at most an extension from it, never a path. */
10
+ saveChatAttachment: (input: {
11
+ name: string;
12
+ data: ArrayBuffer;
13
+ }) => Promise<{
14
+ path: string;
15
+ }>;
16
+ }
17
+ /** The slice of a host bridge {@link useBridgedChatTransport} reads. */
18
+ export interface ChatBridgePort extends AttachmentStagingPort {
19
+ listAgents: ChatPaneRuntimeAccess['listAgents'];
20
+ rescanAgents: ChatPaneRuntimeAccess['rescanAgents'];
21
+ daemonOnline: ChatPaneRuntimeAccess['daemonOnline'];
22
+ normalizeWorkingDirectory: (required: {
23
+ directory: string;
24
+ }) => Promise<string | null>;
25
+ pickWorkingDirectory: (required: Record<string, never>, options?: {
26
+ currentDirectory?: string | undefined;
27
+ }) => Promise<string | null>;
28
+ recentWorkingDirectories: ChatPaneWorkingDirectoryAccess['recentDirectories'];
29
+ workingDirectoryExists: (required: {
30
+ directory: string;
31
+ }) => Promise<boolean>;
32
+ /** Resolves a dropped/picked `File` to its absolute path without a round trip. */
33
+ getPathForFile: (file: File) => string;
34
+ }
35
+ /** A run transport built on the bridge. Construction may install a listener, which `dispose` removes. */
36
+ export interface DisposableChatTransport {
37
+ dispose: () => void;
38
+ }
39
+ /** What {@link useBridgedChatTransport} hands a chat pane. Every field is `undefined` without a bridge. */
40
+ export interface BridgedChatTransport<TTransport extends DisposableChatTransport = DisposableChatTransport> {
41
+ transport: TTransport | undefined;
42
+ runtimeAccess: ChatPaneRuntimeAccess | undefined;
43
+ workingDirectoryAccess: ChatPaneWorkingDirectoryAccess | undefined;
44
+ /** `undefined` only when the bridge itself is. See {@link ChatBridgePort.getPathForFile}. */
45
+ getPathForFile: ((file: File) => string) | undefined;
46
+ /** `undefined` only when the bridge itself is. See `createStagedAttachmentUploader`. */
47
+ uploadAttachments: ChatPaneProps['uploadAttachments'];
48
+ }
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -6,7 +6,7 @@ import { agentHandleProps, agentHandleSegment } from '@jini-ai/core/agent-handle
6
6
  import { createRuntimeDropUpTipHandler, useRuntimeDropUp } from '../hooks/useRuntimeDropUp.hooks.js';
7
7
  /** The full `valueLabel` in the same white bubble `InfoTip` uses, portalled to `document.body`. */
8
8
  function RuntimeDropUpTipBubble({ tip, valueLabel }) {
9
- return createPortal(_jsx("span", { ref: tip.bubbleRef, className: tip.placement === 'below' ? 'info-tip-bubble info-tip-bubble-below' : 'info-tip-bubble', role: "presentation", "aria-hidden": "true", style: infoTipBubbleStyle(tip.coords), children: valueLabel }), document.body);
9
+ return createPortal(_jsx("span", { ref: tip.bubbleRef, className: tip.placement === 'below' ? 'jini-ui-info-tip-bubble jini-ui-info-tip-bubble-below' : 'jini-ui-info-tip-bubble', role: "presentation", "aria-hidden": "true", style: infoTipBubbleStyle(tip.coords), children: valueLabel }), document.body);
10
10
  }
11
11
  function RuntimeDropUpMenu({ base, dropUp, label, value, options, onSelect, note }) {
12
12
  if (!dropUp.open || !dropUp.position)
@@ -2,6 +2,12 @@ import type { ChatPaneProps } from './types.js';
2
2
  export interface CreateDaemonAttachmentUploaderOptions {
3
3
  /** Per-file cap checked before any request is sent. Defaults to 20 MB, matching the route pack. */
4
4
  readonly maxAttachmentBytes?: number;
5
+ /** Per-file cap chosen from the file itself (a host that lets videos exceed every other type passes one
6
+ * function backed by its single upload-limit source). Wins over {@link maxAttachmentBytes} when given. */
7
+ readonly maxAttachmentBytesFor?: (file: {
8
+ readonly name: string;
9
+ readonly type: string;
10
+ }) => number;
5
11
  /** Files per composer turn. Defaults to 10, matching the route pack. */
6
12
  readonly maxAttachmentCount?: number;
7
13
  /** Total bytes per composer turn. Defaults to 50 MB, matching the route pack. */
@@ -1,3 +1,34 @@
1
+ /**
2
+ * @module create-daemon-attachment-uploader
3
+ *
4
+ * The client half of `@jini-ai/http-kit`'s attachment capability: a ready-made
5
+ * `ChatPaneProps['uploadAttachments']` that talks to `POST`/`DELETE /api/attachments`.
6
+ *
7
+ * ```tsx
8
+ * <ChatPane transport={transport} uploadAttachments={createDaemonAttachmentUploader({ baseUrl: daemonUrl, fetch })} />
9
+ * ```
10
+ *
11
+ * That one line is the whole wire-up for composer drag-and-drop and the file picker — `ChatPane`
12
+ * gates both on `uploadAttachments` being present (see `ChatPane.tsx`'s `resolveDropTargetProps`).
13
+ *
14
+ * **Why the client enforces quotas at all**, when the daemon enforces them anyway: a user who drags
15
+ * in a 400 MB video should be told immediately, not after the browser has finished streaming it to
16
+ * localhost. These checks are a courtesy, never the security boundary — the daemon re-derives every
17
+ * one of them, and only its answer decides anything.
18
+ *
19
+ * **Bounded concurrency, preserved order.** Two workers pull from a shared index, so at most two
20
+ * requests are in flight while results still land at their input positions. The first failure aborts
21
+ * the rest and deletes whatever already landed, so a partly-uploaded turn never leaves files behind
22
+ * on the daemon waiting for their TTL.
23
+ *
24
+ * **`content-type` is always `application/octet-stream`**, deliberately not `file.type`. The daemon
25
+ * sniffs the real kind from the leading bytes and ignores this header entirely, so forwarding the
26
+ * browser's guess buys nothing — and actively breaks things: a dropped `.json` file gets
27
+ * `content-type: application/json` from the browser, which an app-wide `express.json()` on the
28
+ * daemon then claims, draining the request stream before the upload route can read a byte. A fixed
29
+ * octet-stream type is immune to every body parser.
30
+ */
31
+ import { describeUploadOverLimit } from "@jini-ai/core/text";
1
32
  const DEFAULTS = {
2
33
  maxAttachmentBytes: 20 * 1024 * 1024,
3
34
  maxAttachmentCount: 10,
@@ -45,8 +76,10 @@ async function messageForFailedUpload(response, fallback) {
45
76
  }
46
77
  /** Refuses a selection that would break a per-file, per-turn count, or per-turn byte quota. */
47
78
  function assertWithinQuota({ files, current, incomingBytes, quota }) {
48
- if (files.some((file) => file.size > quota.maxAttachmentBytes)) {
49
- throw new Error(`Each attachment must be ${formatByteLimit(quota.maxAttachmentBytes)} or smaller.`);
79
+ const capOf = (file) => quota.maxAttachmentBytesFor?.(file) ?? quota.maxAttachmentBytes;
80
+ const tooBig = files.find((file) => file.size > capOf(file));
81
+ if (tooBig) {
82
+ throw new Error(describeUploadOverLimit({ fileBytes: tooBig.size, limitBytes: capOf(tooBig) }));
50
83
  }
51
84
  if (current.count + files.length > quota.maxAttachmentCount) {
52
85
  throw new Error(`You can attach at most ${quota.maxAttachmentCount} files to one message.`);
@@ -103,6 +136,67 @@ function throwIfUploadFailed({ firstError, signal }) {
103
136
  : new Error('Attachment upload was canceled.');
104
137
  }
105
138
  }
139
+ async function uploadOneAttachment({ file, batchId, signal, send, endpoint }) {
140
+ const query = new URLSearchParams({ batch: batchId, name: file.name });
141
+ const response = await send(`${endpoint}?${query}`, {
142
+ method: 'POST',
143
+ // Fixed, not `file.type` — see this module's doc.
144
+ headers: { 'content-type': 'application/octet-stream' },
145
+ body: file,
146
+ signal,
147
+ });
148
+ if (!response.ok) {
149
+ throw new Error(await messageForFailedUpload(response, `Could not attach ${file.name}`));
150
+ }
151
+ const body = (await response.json());
152
+ if (!body.attachment) {
153
+ throw new Error(`The daemon did not return an attachment for ${file.name}`);
154
+ }
155
+ return body.attachment;
156
+ }
157
+ async function deletePartialAttachments({ batchId, attachments, send, endpoint }) {
158
+ if (attachments.length === 0)
159
+ return;
160
+ try {
161
+ // QUICK, not the upload's own composed timeout: this has no
162
+ // caller-supplied signal to compose with and no large body — it is a small best-effort JSON
163
+ // DELETE, and an unprotected `fetch` here would hang `uploadAttachments`'s rejection (the
164
+ // `await` below) on a stalled daemon instead of surfacing `firstError` promptly.
165
+ await send(endpoint, {
166
+ method: 'DELETE',
167
+ signal: AbortSignal.timeout(15_000),
168
+ headers: { 'content-type': 'application/json' },
169
+ body: JSON.stringify({ batchId, paths: attachments.map((attachment) => attachment.path) }),
170
+ });
171
+ }
172
+ catch {
173
+ // Best effort by design: the daemon expires unclaimed uploads on its own, so a failed cleanup
174
+ // costs disk until the TTL rather than leaking indefinitely. Never worth failing the turn for.
175
+ }
176
+ }
177
+ function reserveAttachmentBatch({ files, requestedBatch, quota, batchUsage, now, newBatchId }) {
178
+ pruneBatchUsage(batchUsage, now);
179
+ const batchId = requestedBatch?.batchId ?? newBatchId();
180
+ const incomingBytes = files.reduce((total, file) => total + file.size, 0);
181
+ const current = batchUsage.get(batchId) ?? { count: 0, bytes: 0, touchedAt: now };
182
+ assertWithinQuota({ files, current, incomingBytes, quota });
183
+ // Reserved up front and rolled back on failure, so two overlapping calls for the same turn
184
+ // cannot each see the same free headroom.
185
+ batchUsage.set(batchId, {
186
+ count: current.count + files.length,
187
+ bytes: current.bytes + incomingBytes,
188
+ touchedAt: now,
189
+ });
190
+ return { batchId, current };
191
+ }
192
+ function resolveUploadQuota({ options }) {
193
+ return {
194
+ maxAttachmentBytes: options.maxAttachmentBytes ?? DEFAULTS.maxAttachmentBytes,
195
+ maxAttachmentBytesFor: options.maxAttachmentBytesFor,
196
+ maxAttachmentCount: options.maxAttachmentCount ?? DEFAULTS.maxAttachmentCount,
197
+ maxBatchBytes: options.maxBatchBytes ?? DEFAULTS.maxBatchBytes,
198
+ };
199
+ }
106
200
  /**
107
201
  * Builds a `ChatPaneProps['uploadAttachments']` bound to one daemon.
108
202
  *
@@ -110,11 +204,7 @@ function throwIfUploadFailed({ firstError, signal }) {
110
204
  * when the page is served through a proxy that already forwards `/api`.
111
205
  */
112
206
  export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {}) {
113
- const quota = {
114
- maxAttachmentBytes: options.maxAttachmentBytes ?? DEFAULTS.maxAttachmentBytes,
115
- maxAttachmentCount: options.maxAttachmentCount ?? DEFAULTS.maxAttachmentCount,
116
- maxBatchBytes: options.maxBatchBytes ?? DEFAULTS.maxBatchBytes,
117
- };
207
+ const quota = resolveUploadQuota({ options });
118
208
  const timeoutMs = options.timeoutMs ?? DEFAULTS.timeoutMs;
119
209
  const concurrency = options.concurrency ?? DEFAULTS.concurrency;
120
210
  const endpoint = `${baseUrl.replace(/\/$/u, '')}/api/attachments`;
@@ -122,59 +212,11 @@ export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {})
122
212
  const send = (input, init) => (fetch ?? globalThis.fetch)(input, init);
123
213
  // Per-uploader, not module-level: two panes pointed at two daemons must not share a quota.
124
214
  const batchUsage = new Map();
125
- async function uploadOne(file, batchId, signal) {
126
- const query = new URLSearchParams({ batch: batchId, name: file.name });
127
- const response = await send(`${endpoint}?${query}`, {
128
- method: 'POST',
129
- // Fixed, not `file.type` — see this module's doc.
130
- headers: { 'content-type': 'application/octet-stream' },
131
- body: file,
132
- signal,
133
- });
134
- if (!response.ok) {
135
- throw new Error(await messageForFailedUpload(response, `Could not attach ${file.name}`));
136
- }
137
- const body = (await response.json());
138
- if (!body.attachment) {
139
- throw new Error(`The daemon did not return an attachment for ${file.name}`);
140
- }
141
- return body.attachment;
142
- }
143
- async function deletePartialUpload(batchId, attachments) {
144
- if (attachments.length === 0)
145
- return;
146
- try {
147
- // QUICK, not `uploadOne`'s own composed timeout: unlike the upload itself, this has no
148
- // caller-supplied signal to compose with and no large body — it is a small best-effort JSON
149
- // DELETE, and an unprotected `fetch` here would hang `uploadAttachments`'s rejection (the
150
- // `await` below) on a stalled daemon instead of surfacing `firstError` promptly.
151
- await send(endpoint, {
152
- method: 'DELETE',
153
- signal: AbortSignal.timeout(15_000),
154
- headers: { 'content-type': 'application/json' },
155
- body: JSON.stringify({ batchId, paths: attachments.map((attachment) => attachment.path) }),
156
- });
157
- }
158
- catch {
159
- // Best effort by design: the daemon expires unclaimed uploads on its own, so a failed cleanup
160
- // costs disk until the TTL rather than leaking indefinitely. Never worth failing the turn for.
161
- }
162
- }
163
215
  return async function uploadAttachments(files, uploadOptions) {
164
216
  if (files.length === 0)
165
217
  return [];
166
- const now = Date.now();
167
- pruneBatchUsage(batchUsage, now);
168
- const batchId = uploadOptions?.batchId ?? crypto.randomUUID();
169
- const incomingBytes = files.reduce((total, file) => total + file.size, 0);
170
- const current = batchUsage.get(batchId) ?? { count: 0, bytes: 0, touchedAt: now };
171
- assertWithinQuota({ files, current, incomingBytes, quota });
172
- // Reserved up front and rolled back on failure, so two overlapping calls for the same turn
173
- // cannot each see the same free headroom.
174
- batchUsage.set(batchId, {
175
- count: current.count + files.length,
176
- bytes: current.bytes + incomingBytes,
177
- touchedAt: now,
218
+ const { batchId, current } = reserveAttachmentBatch({
219
+ files, requestedBatch: uploadOptions, quota, batchUsage, now: Date.now(), newBatchId: () => crypto.randomUUID(),
178
220
  });
179
221
  const controller = new AbortController();
180
222
  const unlinkParentAbort = linkParentAbort({ controller, parent: uploadOptions?.signal });
@@ -192,7 +234,7 @@ export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {})
192
234
  concurrency,
193
235
  controller,
194
236
  uploaded,
195
- uploadOne: (file) => uploadOne(file, batchId, controller.signal),
237
+ uploadOne: (file) => uploadOneAttachment({ file, batchId, signal: controller.signal, send, endpoint }),
196
238
  });
197
239
  throwIfUploadFailed({ firstError, signal: controller.signal });
198
240
  succeeded = true;
@@ -208,7 +250,7 @@ export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {})
208
250
  return settled();
209
251
  // Roll the reservation back only after the daemon-side files are gone, so a retry of this turn
210
252
  // starts from a clean slate on both sides.
211
- await deletePartialUpload(batchId, settled());
253
+ await deletePartialAttachments({ batchId, attachments: settled(), send, endpoint });
212
254
  batchUsage.set(batchId, current);
213
255
  throw failure;
214
256
  };
@@ -4,12 +4,15 @@ import type { MouseEvent as ReactMouseEvent } from 'react';
4
4
  *
5
5
  * @param input.event - The click, native (React's `nativeEvent` or a DOM listener's own).
6
6
  * @param input.root - The pane root; an anchor outside it (one wrapping the whole pane) is ignored.
7
+ * @param options.origin - The origin that counts as the owner's own; defaults to the page's own.
7
8
  * @returns The anchor's resolved absolute URL to open, or `null` to leave the click to the browser.
8
9
  * @complexity O(d) for `closest` over the target's ancestor depth d.
9
10
  */
10
11
  export declare function newTabLinkHref({ event, root }: {
11
12
  event: MouseEvent;
12
13
  root: Element;
14
+ }, { origin }?: {
15
+ origin?: string;
13
16
  }): string | null;
14
17
  /**
15
18
  * The pane root's `onClickCapture` handler: opens qualifying link clicks in a new tab and cancels
@@ -1,25 +1,30 @@
1
1
  /**
2
2
  * @module useChatPaneNewTabLinks
3
3
  *
4
- * Every link inside the chat pane opens in a new tab, so following one never navigates the tab the
5
- * conversation lives in (owner 2026-10-08: "every link"). One capture-phase click guard on the
6
- * pane's root absorbs every link source at once — markdown in messages, tool cards, host-registered
7
- * ext-event cards, A2UI surfaces, the header slot — instead of each renderer setting `target` on its
8
- * own anchors and the next new card forgetting to.
4
+ * A link inside the chat pane to ANOTHER website opens in a new tab, so following it never navigates
5
+ * the tab the conversation lives in. A link to the owner's own site or admin is left alone (owner
6
+ * decision 2026-11-21, reversing 2026-10-08's "every link"): its text navigates the current tab — the
7
+ * admin's own link handler turns an admin path into an in-app navigation, so the chat dock stays —
8
+ * and the small icon `MarkdownLink` draws after it opens the new tab instead. One capture-phase click
9
+ * guard on the pane's root covers every link source at once — markdown in messages, tool cards,
10
+ * host-registered ext-event cards, A2UI surfaces, the header slot — instead of each renderer setting
11
+ * `target` on its own anchors and the next new card forgetting to.
9
12
  *
10
13
  * Capture phase, then `preventDefault()`: the guard runs before any anchor's own `onClick`, so a
11
14
  * router `<Link>` (React Router, TanStack Router — both skip their in-app navigation once
12
15
  * `defaultPrevented` is set) does not ALSO navigate the chat's tab after the new tab opens.
13
16
  *
14
- * Left to the browser: modified or non-primary clicks (the browser already opens those however the
15
- * user asked), anchors that already say `target="_blank"`, `#` same-document anchors, `download`
16
- * links, `role="button"` anchors (an action, not a link), and any scheme other than http(s) —
17
- * `mailto:`/`tel:` hand off to another app without navigating the tab anyway.
17
+ * Left to the browser: the owner's own links (see `isOwnLinkHref`), modified or non-primary clicks
18
+ * (the browser already opens those however the user asked), anchors that already say
19
+ * `target="_blank"`, `#` same-document anchors, `download` links, `role="button"` anchors (an action,
20
+ * not a link), and any scheme other than http(s) — `mailto:`/`tel:` hand off to another app without
21
+ * navigating the tab anyway.
18
22
  *
19
23
  * MCP-UI Views render inside a sandboxed iframe, out of this guard's reach; their proxy page
20
24
  * forwards link clicks as `ui/open-link` (`@jini-ai/ui/mcp-ui`'s sandbox proxy) instead.
21
25
  */
22
26
  import { useCallback } from 'react';
27
+ import { currentOrigin, isOwnLinkHref } from '../../../components/own-link.js';
23
28
  const NEW_TAB_PROTOCOLS = new Set(['http:', 'https:']);
24
29
  /** Opens `url` in a new tab with no opener or referrer — `rel="noopener noreferrer"` for `window.open`. */
25
30
  function openInNewTabDefault(url) {
@@ -38,35 +43,40 @@ function isPlainPrimaryClick({ event }) {
38
43
  return !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey);
39
44
  }
40
45
  /**
41
- * Whether an anchor is an ordinary in-tab web link the guard should redirect to a new tab — not
42
- * one already opening elsewhere, a download, an action styled as a link, or a `#` same-document jump.
46
+ * Whether an anchor is an ordinary in-tab link to ANOTHER website that the guard should redirect to
47
+ * a new tab — not the owner's own site or admin, one already opening elsewhere, a download, an
48
+ * action styled as a link, or a `#` same-document jump.
43
49
  *
44
50
  * @param input.link - An anchor matched by `a[href]`, so its `href` attribute is present.
45
- * @returns `true` when following the link would navigate the chat's own tab to an http(s) page.
51
+ * @param input.origin - The origin that counts as the owner's own.
52
+ * @returns `true` when following the link would navigate the chat's own tab away to another website.
46
53
  */
47
- function isInTabWebLink({ link }) {
54
+ function isInTabOtherWebsiteLink({ link, origin }) {
48
55
  if (link.target === '_blank' || link.hasAttribute('download') || link.getAttribute('role') === 'button')
49
56
  return false;
50
57
  if (link.getAttribute('href').startsWith('#'))
51
58
  return false;
52
- return NEW_TAB_PROTOCOLS.has(link.protocol);
59
+ if (!NEW_TAB_PROTOCOLS.has(link.protocol))
60
+ return false;
61
+ return !isOwnLinkHref({ href: link.href, origin });
53
62
  }
54
63
  /**
55
64
  * Decides whether a click inside the pane should open a link in a new tab.
56
65
  *
57
66
  * @param input.event - The click, native (React's `nativeEvent` or a DOM listener's own).
58
67
  * @param input.root - The pane root; an anchor outside it (one wrapping the whole pane) is ignored.
68
+ * @param options.origin - The origin that counts as the owner's own; defaults to the page's own.
59
69
  * @returns The anchor's resolved absolute URL to open, or `null` to leave the click to the browser.
60
70
  * @complexity O(d) for `closest` over the target's ancestor depth d.
61
71
  */
62
- export function newTabLinkHref({ event, root }) {
72
+ export function newTabLinkHref({ event, root }, { origin = currentOrigin() } = {}) {
63
73
  const target = event.target;
64
74
  if (!isPlainPrimaryClick({ event }) || !(target instanceof Element))
65
75
  return null;
66
76
  const link = target.closest('a[href]');
67
77
  if (!(link instanceof HTMLAnchorElement) || !root.contains(link))
68
78
  return null;
69
- return isInTabWebLink({ link }) ? link.href : null;
79
+ return isInTabOtherWebsiteLink({ link, origin }) ? link.href : null;
70
80
  }
71
81
  /**
72
82
  * The pane root's `onClickCapture` handler: opens qualifying link clicks in a new tab and cancels
@@ -1,6 +1,8 @@
1
1
  import type { I18nAdapter } from '../../slots.js';
2
2
  import type { ChatPaneAgent, ChatPaneAgentOption } from './types.js';
3
- export declare function isConcretePickerModel(id: string): boolean;
3
+ export declare function isConcretePickerModel({ id }: {
4
+ id: string;
5
+ }, _optional?: Record<string, never>): boolean;
4
6
  /** Aliases are selectable only as their evidence-backed concrete ID. Never render a Default row.
5
7
  * Keeps the first position per concrete ID, upgrading raw-ID labels from later human labels.
6
8
  * Legacy Default labels are rewritten to the ID before deduplication, never used as human labels.
@@ -4,7 +4,7 @@ import { codexBarVendorWords } from './codex/model-options.js';
4
4
  import { antigravityBarVendorWords } from './antigravity/model-options.js';
5
5
  // Model names and timestamps are metadata; only surrounding picker copy is translated.
6
6
  const passthrough = key => key;
7
- export function isConcretePickerModel(id) {
7
+ export function isConcretePickerModel({ id }, _optional = {}) {
8
8
  return modelIdentityKind({ id }) === 'concrete';
9
9
  }
10
10
  /** Aliases are selectable only as their evidence-backed concrete ID. Never render a Default row.
@@ -20,13 +20,13 @@ export function configuredPickerModel(agent) {
20
20
  if (agent.supportsConcreteModelSelection === false)
21
21
  return undefined;
22
22
  const resolution = agent.defaultModelResolution;
23
- return resolution?.status === 'resolved' && isConcretePickerModel(resolution.id) ? resolution.id : undefined;
23
+ return resolution?.status === 'resolved' && isConcretePickerModel({ id: resolution.id }) ? resolution.id : undefined;
24
24
  }
25
25
  export function pickerModelLabel(agent, requested, t = passthrough) {
26
26
  if (!agent)
27
27
  return t('Choose model');
28
28
  const id = !requested || requested === 'default' ? configuredPickerModel(agent) : requested;
29
- if (!id || !isConcretePickerModel(id))
29
+ if (!id || !isConcretePickerModel({ id }))
30
30
  return t('Choose model');
31
31
  return pickerModelOptions(agent).find((row) => row.id === id)?.label || id;
32
32
  }
@@ -26,7 +26,7 @@ function isSelectableAgent(agent) {
26
26
  /** A concrete custom model passes through when the agent accepts one; anything else must be on the picker list. */
27
27
  function resolveRequestedModel({ agent, requested, fallback }) {
28
28
  const acceptsCustom = agent.supportsCustomModel && agent.supportsConcreteModelSelection !== false;
29
- if (requested && acceptsCustom && isConcretePickerModel(requested))
29
+ if (requested && acceptsCustom && isConcretePickerModel({ id: requested }))
30
30
  return requested;
31
31
  return validatedOptionId(pickerModelOptions(agent), requested, fallback);
32
32
  }
@@ -95,7 +95,7 @@ function isModelUnresolved({ agent, model }) {
95
95
  const refusesConcrete = agent.supportsConcreteModelSelection === false;
96
96
  if (!agent.modelCatalog && !refusesConcrete)
97
97
  return false;
98
- return refusesConcrete || !model || !isConcretePickerModel(model);
98
+ return refusesConcrete || !model || !isConcretePickerModel({ id: model });
99
99
  }
100
100
  /** The agent/model half of {@link findChatPaneSendBlocker}: a configured API mode stands in for a missing CLI. */
101
101
  function findAgentSendBlocker(state) {
@@ -151,7 +151,8 @@ const ATTACHMENT_DETAILS_MAX = 300;
151
151
  export function describeAttachmentError({ error }) {
152
152
  const redacted = redactUserText({ text: error.message }).text.trim();
153
153
  return {
154
- summary: 'Attachment upload failed. Remove it and try again.',
154
+ // A failed file is never staged, so there is no chip to remove: the only action is to choose it again.
155
+ summary: 'Attachment upload failed. The file was not attached. Choose it again to retry.',
155
156
  details: redacted.length > ATTACHMENT_DETAILS_MAX ? `${redacted.slice(0, ATTACHMENT_DETAILS_MAX)}…` : redacted,
156
157
  };
157
158
  }