@jini-ai/chat 0.7.3-next.2 → 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 (214) hide show
  1. package/README.md +49 -0
  2. package/dist/core/accepted-input.d.ts +1 -1
  3. package/dist/core/ag-ui/event-projection.d.ts +14 -69
  4. package/dist/core/ag-ui/event-projection.js +58 -133
  5. package/dist/core/ag-ui/event-reduction.d.ts +12 -2
  6. package/dist/core/ag-ui/event-reduction.js +35 -10
  7. package/dist/core/ag-ui/resume.d.ts +110 -0
  8. package/dist/core/ag-ui/resume.js +200 -0
  9. package/dist/core/ag-ui/run-input.d.ts +23 -0
  10. package/dist/core/ag-ui/run-input.js +45 -0
  11. package/dist/core/ag-ui/server.d.ts +69 -0
  12. package/dist/core/ag-ui/server.js +71 -0
  13. package/dist/core/agent-plugin-chat-state.js +13 -11
  14. package/dist/core/assistant-client/ag-ui-approval-relay.d.ts +113 -0
  15. package/dist/core/assistant-client/ag-ui-approval-relay.js +287 -0
  16. package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +25 -10
  17. package/dist/core/assistant-client/ag-ui-fetch-agent.js +25 -6
  18. package/dist/core/assistant-client/ag-ui-transport.d.ts +86 -3
  19. package/dist/core/assistant-client/ag-ui-transport.js +310 -80
  20. package/dist/core/assistant-client/browser-durable-subscription.d.ts +25 -0
  21. package/dist/core/assistant-client/browser-durable-subscription.js +78 -0
  22. package/dist/core/assistant-client/durable-run-subscription.js +141 -130
  23. package/dist/core/assistant-client/entry.d.ts +2 -1
  24. package/dist/core/assistant-client/entry.js +1 -0
  25. package/dist/core/assistant-client/transport-prompt.d.ts +94 -0
  26. package/dist/core/assistant-client/transport-prompt.js +180 -0
  27. package/dist/core/assistant-client/transport-run.d.ts +49 -0
  28. package/dist/core/assistant-client/transport-run.js +432 -0
  29. package/dist/core/assistant-client/transport-stream.d.ts +73 -0
  30. package/dist/core/assistant-client/transport-stream.js +128 -0
  31. package/dist/core/assistant-client/transport.d.ts +1 -1
  32. package/dist/core/assistant-client/transport.js +129 -835
  33. package/dist/core/assistant-content.d.ts +1 -17
  34. package/dist/core/assistant-content.js +16 -0
  35. package/dist/core/assistant-tool-metadata.d.ts +103 -0
  36. package/dist/core/assistant-tool-metadata.js +56 -0
  37. package/dist/core/checkpoint-interval.d.ts +1 -1
  38. package/dist/core/compact-events.d.ts +1 -1
  39. package/dist/core/durable-projection.d.ts +1 -1
  40. package/dist/core/durable-runs/continuation.d.ts +1 -1
  41. package/dist/core/durable-runs/ledger-contracts.d.ts +4 -1
  42. package/dist/core/durable-runs/ports.d.ts +2 -1
  43. package/dist/core/durable-runs/run-contracts.d.ts +1 -1
  44. package/dist/core/durable-runs/run-finalizer.d.ts +145 -0
  45. package/dist/core/durable-runs/run-finalizer.js +171 -0
  46. package/dist/core/events.d.ts +4 -82
  47. package/dist/core/events.js +2 -1
  48. package/dist/core/index.d.ts +4 -1
  49. package/dist/core/index.js +2 -1
  50. package/dist/core/messages.d.ts +1 -1
  51. package/dist/core/persistence/index.d.ts +1 -1
  52. package/dist/core/persistence/index.js +1 -1
  53. package/dist/core/question-form/normalize.d.ts +9 -3
  54. package/dist/core/question-form/normalize.js +20 -20
  55. package/dist/core/question-form/scan.js +15 -19
  56. package/dist/core/run-activity.d.ts +1 -1
  57. package/dist/core/run-events/entry.d.ts +11 -63
  58. package/dist/core/run-events/entry.js +12 -7
  59. package/dist/core/todos.d.ts +1 -1
  60. package/dist/core/todos.js +8 -0
  61. package/dist/core/tool-call-detail.d.ts +8 -1
  62. package/dist/core/tool-call-detail.js +35 -12
  63. package/dist/core/tool-events.d.ts +1 -1
  64. package/dist/core/tool-output.js +2 -6
  65. package/dist/core/tools.d.ts +2 -1
  66. package/dist/core/transport.d.ts +1 -1
  67. package/dist/core/turn-usage.d.ts +1 -1
  68. package/dist/core/util/parser.js +70 -69
  69. package/dist/embed-widget/browser/embed-send-bridge.d.ts +44 -0
  70. package/dist/embed-widget/browser/embed-send-bridge.js +60 -0
  71. package/dist/embed-widget/browser/frontend-invocation-handler.d.ts +39 -0
  72. package/dist/embed-widget/browser/frontend-invocation-handler.js +151 -0
  73. package/dist/embed-widget/browser/frontend-session-bridge.d.ts +28 -0
  74. package/dist/embed-widget/browser/frontend-session-bridge.js +201 -257
  75. package/dist/embed-widget/browser/lazy-loader.js +16 -12
  76. package/dist/embed-widget/browser/session-store.d.ts +19 -1
  77. package/dist/embed-widget/browser/session-store.js +48 -17
  78. package/dist/embed-widget/transports/fetch-sse.d.ts +1 -1
  79. package/dist/embed-widget/vanilla/index.js +131 -67
  80. package/dist/embed-widget/vanilla/state.js +53 -38
  81. package/dist/react/admin-execution/ai-agent-presentation.d.ts +35 -0
  82. package/dist/react/admin-execution/ai-agent-presentation.js +39 -0
  83. package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.d.ts +22 -0
  84. package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.js +25 -0
  85. package/dist/react/chat-cleanup/ChatCleanupPanel.d.ts +15 -0
  86. package/dist/react/chat-cleanup/ChatCleanupPanel.js +17 -0
  87. package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +168 -0
  88. package/dist/react/chat-cleanup/chat-cleanup.hooks.js +83 -0
  89. package/dist/react/components/ChatCleanupDialog.d.ts +38 -0
  90. package/dist/react/components/ChatCleanupDialog.js +12 -0
  91. package/dist/react/components/ConversationList.d.ts +14 -5
  92. package/dist/react/components/ConversationList.hooks.d.ts +1 -0
  93. package/dist/react/components/ConversationList.hooks.js +4 -2
  94. package/dist/react/components/ConversationList.js +41 -5
  95. package/dist/react/components/Icon.d.ts +1 -1
  96. package/dist/react/components/Icon.js +2 -0
  97. package/dist/react/components/Markdown.js +6 -6
  98. package/dist/react/components/MarkdownLink.d.ts +25 -0
  99. package/dist/react/components/MarkdownLink.js +17 -0
  100. package/dist/react/components/RoutedA2uiSurfaceCard.d.ts +80 -0
  101. package/dist/react/components/RoutedA2uiSurfaceCard.js +15 -0
  102. package/dist/react/components/ToolCard.d.ts +4 -2
  103. package/dist/react/components/ToolCard.js +46 -4
  104. package/dist/react/components/ToolCard.rules.d.ts +5 -2
  105. package/dist/react/components/ToolCard.rules.js +12 -5
  106. package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
  107. package/dist/react/components/mcp-ui-surface-state.d.ts +3 -1
  108. package/dist/react/components/mcp-ui-surface-state.js +2 -2
  109. package/dist/react/components/own-link.d.ts +26 -0
  110. package/dist/react/components/own-link.js +36 -0
  111. package/dist/react/features/bridged-chat/create-staged-attachment-uploader.d.ts +7 -0
  112. package/dist/react/features/bridged-chat/create-staged-attachment-uploader.js +26 -0
  113. package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.d.ts +12 -0
  114. package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.js +60 -0
  115. package/dist/react/features/bridged-chat/index.d.ts +8 -0
  116. package/dist/react/features/bridged-chat/index.js +7 -0
  117. package/dist/react/features/bridged-chat/types.d.ts +49 -0
  118. package/dist/react/features/bridged-chat/types.js +2 -0
  119. package/dist/react/features/chat-pane/components/RuntimeDropUp.js +1 -1
  120. package/dist/react/features/chat-pane/create-daemon-attachment-uploader.d.ts +6 -0
  121. package/dist/react/features/chat-pane/create-daemon-attachment-uploader.js +101 -59
  122. package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.d.ts +3 -0
  123. package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.js +26 -16
  124. package/dist/react/features/chat-pane/model-options.d.ts +3 -1
  125. package/dist/react/features/chat-pane/model-options.js +3 -3
  126. package/dist/react/features/chat-pane/rules.js +4 -3
  127. package/dist/react/features/chat-pane/styles.d.ts +1 -1
  128. package/dist/react/features/chat-pane/styles.js +16 -0
  129. package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.d.ts +10 -0
  130. package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.js +19 -0
  131. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.d.ts +12 -0
  132. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.js +21 -0
  133. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.d.ts +13 -0
  134. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.js +9 -0
  135. package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.d.ts +12 -0
  136. package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.js +12 -0
  137. package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.d.ts +7 -0
  138. package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.js +43 -0
  139. package/dist/react/features/conversation-chat-pane/index.d.ts +9 -0
  140. package/dist/react/features/conversation-chat-pane/index.js +8 -0
  141. package/dist/react/features/conversation-chat-pane/rules.d.ts +25 -0
  142. package/dist/react/features/conversation-chat-pane/rules.js +29 -0
  143. package/dist/react/features/conversation-chat-pane/types.d.ts +139 -0
  144. package/dist/react/features/conversation-chat-pane/types.js +2 -0
  145. package/dist/react/features/conversations/conversation-controller.d.ts +16 -0
  146. package/dist/react/features/conversations/conversation-controller.js +280 -0
  147. package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.d.ts +15 -0
  148. package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.js +33 -0
  149. package/dist/react/features/conversations/hooks/useStoredConversations.hooks.d.ts +16 -0
  150. package/dist/react/features/conversations/hooks/useStoredConversations.hooks.js +36 -0
  151. package/dist/react/features/conversations/index.d.ts +9 -0
  152. package/dist/react/features/conversations/index.js +8 -0
  153. package/dist/react/features/conversations/types.d.ts +120 -0
  154. package/dist/react/features/conversations/types.js +2 -0
  155. package/dist/react/features/voice-input/space-hold-rules.d.ts +65 -0
  156. package/dist/react/features/voice-input/space-hold-rules.js +48 -0
  157. package/dist/react/hooks/testing/fake-transport.d.ts +1 -1
  158. package/dist/react/hooks/useAnsweredCards.d.ts +2 -1
  159. package/dist/react/hooks/useConversation.js +5 -2
  160. package/dist/react/hooks/useExtEventGroups.d.ts +1 -1
  161. package/dist/react/hooks/useRunActivity.d.ts +2 -1
  162. package/dist/react/hooks/useRunStream.d.ts +1 -1
  163. package/dist/react/hooks/useRunStream.js +1 -1
  164. package/dist/react/hooks/useSurfaceRecovery.js +3 -1
  165. package/dist/react/hooks/useToolTimeline.d.ts +2 -1
  166. package/dist/react/index.d.ts +5 -2
  167. package/dist/react/index.js +4 -2
  168. package/dist/react/message-blocks.d.ts +1 -48
  169. package/dist/react/message-blocks.js +47 -0
  170. package/dist/react/styles/chat-settings.css +14 -14
  171. package/dist/server/chat-cleanup-routes.d.ts +56 -0
  172. package/dist/server/chat-cleanup-routes.js +56 -0
  173. package/dist/server/durable-runs/recover.js +193 -171
  174. package/dist/server/run-finalizer/entry.js +133 -110
  175. package/dist/store/legacy/sqlite/conversations.js +29 -17
  176. package/dist/store/pglite/index.d.ts +1 -0
  177. package/dist/store/pglite/index.js +1 -0
  178. package/dist/store/ports.d.ts +12 -0
  179. package/dist/store/postgres/index.d.ts +1 -0
  180. package/dist/store/postgres/index.js +1 -0
  181. package/dist/store/runtime/attempt-base-retention.d.ts +57 -0
  182. package/dist/store/runtime/attempt-base-retention.js +103 -0
  183. package/dist/store/runtime/chat-maintenance.d.ts +16 -0
  184. package/dist/store/runtime/chat-maintenance.js +19 -0
  185. package/dist/store/runtime/chat-principal.d.ts +63 -0
  186. package/dist/store/runtime/chat-principal.js +39 -0
  187. package/dist/store/runtime/checkpoint-delta.d.ts +1 -1
  188. package/dist/store/runtime/durable-run-queries.d.ts +124 -0
  189. package/dist/store/runtime/durable-run-queries.js +122 -0
  190. package/dist/store/runtime/durable-run-store.d.ts +1 -1
  191. package/dist/store/runtime/durable-run-store.js +291 -343
  192. package/dist/store/runtime/entry.d.ts +3 -0
  193. package/dist/store/runtime/entry.js +3 -0
  194. package/dist/store/runtime/events-json.d.ts +1 -1
  195. package/dist/store/runtime/lazy-run-ledger.d.ts +19 -0
  196. package/dist/store/runtime/lazy-run-ledger.js +28 -0
  197. package/dist/store/runtime/run-ledger.d.ts +4 -1
  198. package/dist/store/runtime/run-ledger.js +256 -204
  199. package/dist/store/sql/bulk-deletion.d.ts +36 -0
  200. package/dist/store/sql/bulk-deletion.js +103 -0
  201. package/dist/store/sql/store-queries.d.ts +170 -0
  202. package/dist/store/sql/store-queries.js +212 -0
  203. package/dist/store/sql/store-rows.d.ts +106 -0
  204. package/dist/store/sql/store-rows.js +116 -0
  205. package/dist/store/sql/store-writes.d.ts +46 -0
  206. package/dist/store/sql/store-writes.js +161 -0
  207. package/dist/store/sql/store.d.ts +3 -16
  208. package/dist/store/sql/store.js +58 -428
  209. package/dist/store/sql/tables.d.ts +1 -0
  210. package/dist/store/sqlite/index.d.ts +1 -0
  211. package/dist/store/sqlite/index.js +1 -0
  212. package/dist/store/sqlite/schema.d.ts +1 -1
  213. package/dist/store/sqlite/schema.js +5 -1
  214. package/package.json +171 -20
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Creates bounded, fail-soft transcript storage.
3
- * Corrupt transcripts are cleared as a whole. Serialization/storage failures never escape.
3
+ * Corrupt transcripts are cleared as a whole. Serialization/storage failures never escape unless
4
+ * the host's `onFailure` rethrows; by default they are swallowed silently.
4
5
  * Reject oversized stored envelopes before parsing, validate the whole message batch, then trim
5
6
  * oldest messages first. Circular serialization is fail-soft. Keys, limits, validator and Storage
6
7
  * are injected so separate controllers never accidentally share a product-selected namespace.
@@ -9,6 +10,8 @@
9
10
  */
10
11
  export function createBrowserSessionStore(args) {
11
12
  const { storage, transcriptKey, maxMessages, maxBytes, validateMessage } = args;
13
+ const capReads = args.overCapReads !== 'read';
14
+ const report = args.onFailure ?? (() => undefined);
12
15
  if (!transcriptKey) {
13
16
  throw new Error('Transcript key must be nonempty');
14
17
  }
@@ -22,7 +25,9 @@ export function createBrowserSessionStore(args) {
22
25
  try {
23
26
  storage.removeItem(transcriptKey);
24
27
  }
25
- catch { /* unavailable storage */ }
28
+ catch (error) {
29
+ report({ operation: 'clear', error });
30
+ } // unavailable storage
26
31
  };
27
32
  return {
28
33
  load(_args) {
@@ -30,51 +35,77 @@ export function createBrowserSessionStore(args) {
30
35
  try {
31
36
  raw = storage.getItem(transcriptKey);
32
37
  }
33
- catch {
38
+ catch (error) {
39
+ report({ operation: 'load', error });
34
40
  return empty();
35
41
  }
36
42
  if (raw === null)
37
43
  return empty();
38
44
  try {
39
- return parseTranscript({ raw, maxBytes, maxMessages, validateMessage });
45
+ return parseTranscript({ raw, maxBytes, maxMessages, validateMessage, capReads });
40
46
  }
41
- catch {
47
+ catch (error) {
42
48
  clear({});
49
+ report({ operation: 'decode', error });
43
50
  return empty();
44
51
  }
45
52
  },
46
53
  save({ state }) {
54
+ // The live conversation continues even when serialization or storage fails.
55
+ let serialized;
56
+ try {
57
+ serialized = serializeCapped({ state, maxBytes, maxMessages });
58
+ }
59
+ catch (error) {
60
+ report({ operation: 'serialize', error });
61
+ return;
62
+ }
47
63
  try {
48
- let messages = maxMessages === 0 ? [] : state.messages.slice(-maxMessages);
49
- let serialized = JSON.stringify({ open: state.open, messages });
50
- while (messages.length > 0 && utf8Bytes(serialized) > maxBytes) {
51
- messages = messages.slice(1);
52
- serialized = JSON.stringify({ open: state.open, messages });
53
- }
54
64
  storage.setItem(transcriptKey, serialized);
55
65
  }
56
- catch { /* The live conversation continues even when serialization or storage fails. */ }
66
+ catch (error) {
67
+ report({ operation: 'save', error });
68
+ }
57
69
  },
58
70
  clear,
59
71
  };
60
72
  }
61
73
  const utf8Bytes = (value) => new TextEncoder().encode(value).length;
74
+ /** Drops the oldest messages first until both the count cap and the UTF-8 byte cap hold. */
75
+ function serializeCapped(args) {
76
+ const { state, maxBytes, maxMessages } = args;
77
+ let messages = maxMessages === 0 ? [] : state.messages.slice(-maxMessages);
78
+ let serialized = JSON.stringify({ open: state.open, messages });
79
+ while (messages.length > 0 && utf8Bytes(serialized) > maxBytes) {
80
+ messages = messages.slice(1);
81
+ serialized = JSON.stringify({ open: state.open, messages });
82
+ }
83
+ return serialized;
84
+ }
62
85
  /**
63
86
  * Parses and validates one stored transcript envelope. Throws on any defect so the caller can
64
- * clear the whole entry (no partial recovery). Oversized envelopes are rejected before parsing.
87
+ * clear the whole entry (no partial recovery). Oversized envelopes are rejected before parsing
88
+ * unless the host opted into reading legacy over-cap envelopes.
65
89
  */
66
90
  function parseTranscript(args) {
67
- const { raw, maxBytes, maxMessages, validateMessage } = args;
68
- if (utf8Bytes(raw) > maxBytes)
91
+ const { raw, maxBytes, maxMessages, validateMessage, capReads } = args;
92
+ if (capReads && utf8Bytes(raw) > maxBytes)
69
93
  throw new Error('Transcript exceeds byte limit');
94
+ const state = parseEnvelopeShape(raw);
95
+ if (capReads && state.messages.length > maxMessages)
96
+ throw new Error('Transcript exceeds message limit');
97
+ if (!state.messages.every(value => validateMessage({ value })))
98
+ throw new Error('Invalid transcript');
99
+ return { open: state.open, messages: state.messages };
100
+ }
101
+ /** JSON-parses the envelope and checks only its `{ open: boolean, messages: unknown[] }` shape; throws on any defect. */
102
+ function parseEnvelopeShape(raw) {
70
103
  const value = JSON.parse(raw);
71
104
  if (typeof value !== 'object' || value === null || Array.isArray(value))
72
105
  throw new Error('Invalid envelope');
73
106
  const state = value;
74
107
  if (typeof state.open !== 'boolean' || !Array.isArray(state.messages))
75
108
  throw new Error('Invalid transcript');
76
- if (state.messages.length > maxMessages || !state.messages.every(value => validateMessage({ value })))
77
- throw new Error('Invalid transcript');
78
109
  return { open: state.open, messages: state.messages };
79
110
  }
80
111
  //# sourceMappingURL=session-store.js.map
@@ -1,6 +1,6 @@
1
- import type { AgentEvent } from '../../core/events.js';
2
1
  import type { ChatMessage } from '../../core/messages.js';
3
2
  import type { ChatTransport, StartRunInput } from '../../core/transport.js';
3
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
4
4
  export interface DecodedSseFrame {
5
5
  readonly event: string | null;
6
6
  readonly data: string;
@@ -14,15 +14,7 @@ function svgIcon({ document, path }) {
14
14
  svg.append(shape);
15
15
  return svg;
16
16
  }
17
- /**
18
- * Mounts a DOM-only chat panel. Native buttons/forms supply keyboard semantics;
19
- * explicitly opened dialogs trap focus, restore the bubble on close and announce settled replies.
20
- * Restored panels leave page focus alone. Streaming markdown is rendered at most once per frame.
21
- * All listeners, scheduled page effects and runs belong to this mount and are disposed.
22
- * Markdown is an injected host capability; no framework or icon font enters this graph.
23
- */
24
- export function mountVanillaChat(args, options = {}) {
25
- const { document, element, copy } = args;
17
+ function createChatElementFactory({ document }) {
26
18
  const node = (tag, className, text = '') => {
27
19
  const result = document.createElement(tag);
28
20
  result.className = className;
@@ -34,6 +26,10 @@ export function mountVanillaChat(args, options = {}) {
34
26
  result.type = 'button';
35
27
  return result;
36
28
  };
29
+ return { node, button };
30
+ }
31
+ function createChatDialog({ args, document, copy, dom }) {
32
+ const { node, button } = dom;
37
33
  const shell = node('div', 'jini-chat-vanilla');
38
34
  const fab = button('');
39
35
  fab.className = 'jini-chat-bubble';
@@ -59,6 +55,10 @@ export function mountVanillaChat(args, options = {}) {
59
55
  const keep = button(copy.keep);
60
56
  confirmation.append(node('span', '', copy.resetQuestion), confirm, keep);
61
57
  confirmation.hidden = true;
58
+ return { shell, fab, panel, header, reset, close, confirmation, confirm, keep };
59
+ }
60
+ function createChatRegions({ dom, copy }) {
61
+ const { node, button } = dom;
62
62
  const log = node('div', 'jini-chat-vanilla__messages');
63
63
  log.setAttribute('role', 'log');
64
64
  log.setAttribute('aria-live', 'off');
@@ -80,6 +80,10 @@ export function mountVanillaChat(args, options = {}) {
80
80
  const proposalText = node('span', '');
81
81
  const go = button('Allow');
82
82
  proposal.append(proposalText, go);
83
+ return { log, status, announcements, error, proposal };
84
+ }
85
+ function createChatComposer({ dom, document, copy }) {
86
+ const { node, button } = dom;
83
87
  const form = node('form', 'jini-chat-vanilla__composer');
84
88
  const input = node('textarea', 'jini-chat-vanilla__input');
85
89
  input.placeholder = copy.placeholder;
@@ -93,6 +97,16 @@ export function mountVanillaChat(args, options = {}) {
93
97
  send.replaceChildren(svgIcon({ document, path: 'M5 4l15 8-15 8v-6l9-2-9-2V4z' }));
94
98
  const stop = button(copy.stop);
95
99
  form.append(input, send, stop);
100
+ return { form, input, send, stop };
101
+ }
102
+ function mountChatElements({ args, document, element, copy, dom }) {
103
+ const { node, button } = dom;
104
+ const dialog = createChatDialog({ args, document, copy, dom });
105
+ const regions = createChatRegions({ dom, copy });
106
+ const composer = createChatComposer({ dom, document, copy });
107
+ const { shell, fab, panel, header, confirmation } = dialog;
108
+ const { log, status, announcements, error, proposal } = regions;
109
+ const { form } = composer;
96
110
  const greeting = node('p', 'jini-chat-vanilla__greeting', copy.greeting);
97
111
  const suggestions = node('div', 'jini-chat-vanilla__suggestions');
98
112
  if (copy.suggestionsLabel)
@@ -105,25 +119,29 @@ export function mountVanillaChat(args, options = {}) {
105
119
  const bubbleStyle = node('style', '', CHAT_BUBBLE_STYLE);
106
120
  shell.append(bubbleStyle, fab, panel);
107
121
  element.replaceChildren(shell);
122
+ return { ...dialog, ...regions, ...composer, greeting, suggestions, suggestionEntries, suggestionButtons };
123
+ }
124
+ function renderChatChrome({ view, copy, state }) {
125
+ const { panel, fab, greeting, suggestions, suggestionButtons, error, status, send, input, stop } = view;
126
+ panel.hidden = !state.open;
127
+ panel.setAttribute('aria-modal', String(state.open));
128
+ fab.setAttribute('aria-expanded', String(state.open));
129
+ fab.querySelector('path')?.setAttribute('d', state.open ? 'M6 6l12 12M18 6L6 18' : 'M4 4h16v12H9l-5 4V4z');
130
+ greeting.hidden = !copy.greeting || state.messages.length > 0;
131
+ suggestions.hidden = suggestionButtons.length === 0 || state.messages.length > 0;
132
+ suggestionButtons.forEach(button => { button.disabled = state.busy; });
133
+ error.textContent = state.error ?? '';
134
+ error.hidden = !state.error;
135
+ status.textContent = state.busy ? copy.thinking : '';
136
+ send.disabled = state.busy || !input.value.trim();
137
+ input.disabled = state.busy;
138
+ stop.hidden = !state.busy;
139
+ }
140
+ function createChatTranscript({ view, dom, args }) {
141
+ const { log, announcements } = view;
142
+ const { node } = dom;
108
143
  const rows = new Map();
109
- let wasOpen = false;
110
- let initialized = false;
111
144
  const liveReplies = new Set();
112
- const renderChrome = ({ state }) => {
113
- panel.hidden = !state.open;
114
- panel.setAttribute('aria-modal', String(state.open));
115
- fab.setAttribute('aria-expanded', String(state.open));
116
- fab.querySelector('path')?.setAttribute('d', state.open ? 'M6 6l12 12M18 6L6 18' : 'M4 4h16v12H9l-5 4V4z');
117
- greeting.hidden = !copy.greeting || state.messages.length > 0;
118
- suggestions.hidden = suggestionButtons.length === 0 || state.messages.length > 0;
119
- suggestionButtons.forEach(button => { button.disabled = state.busy; });
120
- error.textContent = state.error ?? '';
121
- error.hidden = !state.error;
122
- status.textContent = state.busy ? copy.thinking : '';
123
- send.disabled = state.busy || !input.value.trim();
124
- input.disabled = state.busy;
125
- stop.hidden = !state.busy;
126
- };
127
145
  const createRow = ({ message }) => {
128
146
  const row = { element: node('div', `jini-chat-vanilla__message jini-chat-vanilla__message--${message.role}`), content: '\0' };
129
147
  rows.set(message.id, row);
@@ -173,11 +191,21 @@ export function mountVanillaChat(args, options = {}) {
173
191
  if (pinned)
174
192
  log.scrollTop = log.scrollHeight;
175
193
  };
194
+ function trackLiveReplies({ messages }) {
195
+ for (const message of messages)
196
+ if (message.role === 'assistant' && message.runStatus === 'running')
197
+ liveReplies.add(message.id);
198
+ }
199
+ return { renderRows, trackLiveReplies };
200
+ }
201
+ function createChatFocus({ view }) {
202
+ const { close, input, stop, confirmation, fab } = view;
203
+ let wasOpen = false;
176
204
  const focusEntry = ({ busy }) => { if (busy)
177
205
  close.focus();
178
206
  else
179
207
  input.focus(); };
180
- const moveFocus = ({ state, composerHadFocus, stopHadFocus }) => {
208
+ const moveFocus = ({ state, composerHadFocus, stopHadFocus, initialized }) => {
181
209
  if (!state.open)
182
210
  return;
183
211
  if (!wasOpen && initialized) {
@@ -191,9 +219,9 @@ export function mountVanillaChat(args, options = {}) {
191
219
  if (!state.busy && stopHadFocus)
192
220
  input.focus();
193
221
  };
194
- const renderFocus = ({ state, composerHadFocus, stopHadFocus, panelHadFocus }) => {
195
- moveFocus({ state, composerHadFocus, stopHadFocus });
196
- // renderChrome (which always runs first) already ended modal semantics for a closed panel.
222
+ const renderFocus = ({ state, composerHadFocus, stopHadFocus, panelHadFocus, initialized }) => {
223
+ moveFocus({ state, composerHadFocus, stopHadFocus, initialized });
224
+ // renderChatChrome (which always runs first) already ended modal semantics for a closed panel.
197
225
  if (!state.open && wasOpen) {
198
226
  confirmation.hidden = true;
199
227
  if (panelHadFocus)
@@ -201,6 +229,11 @@ export function mountVanillaChat(args, options = {}) {
201
229
  }
202
230
  wasOpen = state.open;
203
231
  };
232
+ return { renderFocus, focusEntry };
233
+ }
234
+ function createChatRenderer({ view, document, copy, focus, transcript, args }) {
235
+ const { panel, input, stop } = view;
236
+ let initialized = false;
204
237
  let latestState;
205
238
  let framePending = false;
206
239
  let cancelRenderFrame = () => { };
@@ -209,53 +242,31 @@ export function mountVanillaChat(args, options = {}) {
209
242
  const panelHadFocus = panel.contains(document.activeElement);
210
243
  const composerHadFocus = document.activeElement === input;
211
244
  const stopHadFocus = document.activeElement === stop;
212
- renderChrome({ state });
213
- renderFocus({ state, composerHadFocus, stopHadFocus, panelHadFocus });
245
+ renderChatChrome({ view, copy, state });
246
+ focus.renderFocus({ state, composerHadFocus, stopHadFocus, panelHadFocus, initialized });
214
247
  if (initialized && state.busy) {
215
- for (const message of state.messages)
216
- if (message.role === 'assistant' && message.runStatus === 'running')
217
- liveReplies.add(message.id);
248
+ transcript.trackLiveReplies({ messages: state.messages });
218
249
  if (framePending)
219
250
  return;
220
251
  framePending = true;
221
252
  cancelRenderFrame = args.scheduleFrame({ callback: () => {
222
253
  framePending = false;
223
- renderRows({ state: latestState });
254
+ transcript.renderRows({ state: latestState });
224
255
  } });
225
256
  return;
226
257
  }
227
258
  cancelRenderFrame();
228
259
  framePending = false;
229
- renderRows({ state });
260
+ transcript.renderRows({ state });
230
261
  };
231
- const controller = createVanillaChatController({ ...args, onChange: render });
232
- const listeners = [];
233
- const listen = (target, type, handler) => {
234
- target.addEventListener(type, handler);
235
- listeners.push(() => target.removeEventListener(type, handler));
262
+ return {
263
+ render,
264
+ initialize: () => { initialized = true; },
265
+ cancelFrame: () => cancelRenderFrame(),
236
266
  };
237
- suggestionEntries.forEach(({ text, button }) => listen(button, 'click', () => {
238
- input.value = text;
239
- renderChrome({ state: controller.getState({}) });
240
- input.focus();
241
- }));
242
- listen(input, 'input', () => renderChrome({ state: controller.getState({}) }));
243
- listen(fab, 'click', () => controller.setOpen({ open: !controller.getState({}).open }));
244
- listen(close, 'click', () => controller.setOpen({ open: false }));
245
- listen(reset, 'click', () => {
246
- if (controller.getState({}).messages.length === 0 && input.value.length === 0) {
247
- controller.reset({});
248
- input.focus();
249
- return;
250
- }
251
- confirm.textContent = controller.getState({}).messages.length === 0 ? copy.confirmDraft ?? copy.confirm : copy.confirm;
252
- confirmation.hidden = false;
253
- keep.focus();
254
- });
255
- const dismissConfirmation = () => { confirmation.hidden = true; reset.focus(); };
256
- listen(keep, 'click', dismissConfirmation);
257
- listen(confirm, 'click', () => { confirmation.hidden = true; input.value = ''; controller.reset({}); input.focus(); });
258
- listen(stop, 'click', () => controller.cancel({}));
267
+ }
268
+ function listenForComposerInput({ document, view, controller, listen }) {
269
+ const { input, panel, form } = view;
259
270
  listen(form, 'submit', event => {
260
271
  event.preventDefault();
261
272
  const text = input.value;
@@ -275,6 +286,9 @@ export function mountVanillaChat(args, options = {}) {
275
286
  form.requestSubmit();
276
287
  }
277
288
  });
289
+ }
290
+ function listenForChatKeyboard({ document, view, controller, listen, dismissConfirmation }) {
291
+ const { confirmation, panel } = view;
278
292
  const onEscape = ({ key }) => {
279
293
  key.preventDefault();
280
294
  if (!confirmation.hidden)
@@ -305,22 +319,72 @@ export function mountVanillaChat(args, options = {}) {
305
319
  if (key.key === 'Tab')
306
320
  trapTab({ key });
307
321
  });
322
+ }
323
+ function installChatListeners({ view, document, element, copy, controller, focusEntry }) {
324
+ const { suggestionEntries, input, fab, close, reset, confirm, confirmation, keep, stop } = view;
325
+ const listeners = [];
326
+ const listen = (target, type, handler) => {
327
+ target.addEventListener(type, handler);
328
+ listeners.push(() => target.removeEventListener(type, handler));
329
+ };
330
+ suggestionEntries.forEach(({ text, button }) => listen(button, 'click', () => {
331
+ input.value = text;
332
+ renderChatChrome({ view, copy, state: controller.getState({}) });
333
+ input.focus();
334
+ }));
335
+ listen(input, 'input', () => renderChatChrome({ view, copy, state: controller.getState({}) }));
336
+ listen(fab, 'click', () => controller.setOpen({ open: !controller.getState({}).open }));
337
+ listen(close, 'click', () => controller.setOpen({ open: false }));
338
+ listen(reset, 'click', () => {
339
+ if (controller.getState({}).messages.length === 0 && input.value.length === 0) {
340
+ controller.reset({});
341
+ input.focus();
342
+ return;
343
+ }
344
+ confirm.textContent = controller.getState({}).messages.length === 0 ? copy.confirmDraft ?? copy.confirm : copy.confirm;
345
+ confirmation.hidden = false;
346
+ keep.focus();
347
+ });
348
+ const dismissConfirmation = () => { confirmation.hidden = true; reset.focus(); };
349
+ listen(keep, 'click', dismissConfirmation);
350
+ listen(confirm, 'click', () => { confirmation.hidden = true; input.value = ''; controller.reset({}); input.focus(); });
351
+ listen(stop, 'click', () => controller.cancel({}));
352
+ listenForComposerInput({ document, view, controller, listen });
353
+ listenForChatKeyboard({ document, view, controller, listen, dismissConfirmation });
308
354
  listen(element, 'jini-chat-open', () => {
309
355
  controller.setOpen({ open: true });
310
356
  focusEntry({ busy: controller.getState({}).busy });
311
357
  });
358
+ return listeners;
359
+ }
360
+ /**
361
+ * Mounts a DOM-only chat panel. Native buttons/forms supply keyboard semantics;
362
+ * explicitly opened dialogs trap focus, restore the bubble on close and announce settled replies.
363
+ * Restored panels leave page focus alone. Streaming markdown is rendered at most once per frame.
364
+ * All listeners, scheduled page effects and runs belong to this mount and are disposed.
365
+ * Markdown is an injected host capability; no framework or icon font enters this graph.
366
+ */
367
+ export function mountVanillaChat(args, options = {}) {
368
+ const { document, element, copy } = args;
369
+ const dom = createChatElementFactory({ document });
370
+ const view = mountChatElements({ args, document, element, copy, dom });
371
+ const transcript = createChatTranscript({ view, dom, args });
372
+ const focus = createChatFocus({ view });
373
+ const renderer = createChatRenderer({ view, document, copy, focus, transcript, args });
374
+ const controller = createVanillaChatController({ ...args, onChange: renderer.render });
375
+ const listeners = installChatListeners({ view, document, element, copy, controller, focusEntry: focus.focusEntry });
312
376
  controller.setOpen({ open: options.initialOpen ?? controller.getState({}).open });
313
- initialized = true;
377
+ renderer.initialize();
314
378
  element.dataset.chatMounted = 'true';
315
379
  element.dispatchEvent(new (document.defaultView?.Event ?? Event)('jini-chat-mounted'));
316
380
  return {
317
381
  controller,
318
382
  unmount(_input = {}, _opts = {}) {
319
383
  listeners.forEach(dispose => dispose());
320
- cancelRenderFrame();
384
+ renderer.cancelFrame();
321
385
  delete element.dataset.chatMounted;
322
386
  controller.dispose({});
323
- shell.remove();
387
+ view.shell.remove();
324
388
  },
325
389
  };
326
390
  }
@@ -1,4 +1,51 @@
1
1
  import { assistantContentFromEvents } from '../../core/assistant-content.js';
2
+ function createReplyHandlers({ reply, abort, isCurrent, clearActive, getState, setState, publish }) {
3
+ let events = [];
4
+ let failed = false;
5
+ let settled = false;
6
+ const current = () => isCurrent() && !settled;
7
+ const updateReply = (next, { persist = false } = {}) => {
8
+ const state = getState();
9
+ setState({ state: { ...state, messages: state.messages.map(message => message.id === reply.id ? next : message) } });
10
+ publish({ persist });
11
+ };
12
+ const fail = (_error) => {
13
+ if (!current())
14
+ return;
15
+ failed = true;
16
+ const state = { ...getState(), error: 'The message could not be sent to the agent; send it again.' };
17
+ setState({ state });
18
+ updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events], runStatus: 'failed' });
19
+ };
20
+ const done = (final) => {
21
+ if (!current())
22
+ return;
23
+ settled = true;
24
+ clearActive();
25
+ events = final;
26
+ setState({ state: { ...getState(), busy: false } });
27
+ const completedStatus = abort.signal.aborted ? 'canceled' : 'succeeded';
28
+ updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events],
29
+ runStatus: failed ? 'failed' : completedStatus }, { persist: true });
30
+ };
31
+ const handlers = {
32
+ onEvent(event) {
33
+ if (!current())
34
+ return;
35
+ events = [...events, event];
36
+ updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events], runStatus: failed ? 'failed' : 'running' });
37
+ },
38
+ onError: fail,
39
+ onDone: done,
40
+ };
41
+ return {
42
+ handlers,
43
+ transportFailed(error) {
44
+ fail(error instanceof Error ? error : new Error(String(error)));
45
+ done(events);
46
+ },
47
+ };
48
+ }
2
49
  /**
3
50
  * Framework-free visitor state over the existing transport/session owners.
4
51
  * Restored messages never replay effects; page control belongs to the shared frontend bridge.
@@ -32,47 +79,15 @@ export function createVanillaChatController(args, _options = {}) {
32
79
  const reply = { id: args.ids({}), role: 'assistant', content: '', events: [], runStatus: 'running' };
33
80
  state = { ...state, messages: [...history, reply], busy: true, error: null };
34
81
  publish({ persist: false });
35
- let events = [];
36
- let failed = false;
37
- let settled = false;
38
- const current = () => token === generation && !settled;
39
- const updateReply = (next, { persist = false } = {}) => {
40
- state = { ...state, messages: state.messages.map(message => message.id === reply.id ? next : message) };
41
- publish({ persist });
42
- };
43
- const fail = (_error) => {
44
- if (!current())
45
- return;
46
- failed = true;
47
- state = { ...state, error: 'The message could not be sent to the agent; send it again.' };
48
- updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events], runStatus: 'failed' });
49
- };
50
- const done = (final) => {
51
- if (!current())
52
- return;
53
- settled = true;
54
- active = null;
55
- events = final;
56
- state = { ...state, busy: false };
57
- const completedStatus = abort.signal.aborted ? 'canceled' : 'succeeded';
58
- updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events],
59
- runStatus: failed ? 'failed' : completedStatus }, { persist: true });
60
- };
82
+ const { handlers, transportFailed } = createReplyHandlers({
83
+ reply, abort, isCurrent: () => token === generation, clearActive: () => { active = null; },
84
+ getState: () => state, setState: ({ state: next }) => { state = next; }, publish,
85
+ });
61
86
  try {
62
- await args.transport.startRun({ history, agentId: args.agentId, assistantMessageId: reply.id, signal: abort.signal }, {
63
- onEvent(event) {
64
- if (!current())
65
- return;
66
- events = [...events, event];
67
- updateReply({ ...reply, content: assistantContentFromEvents({ events }), events: [...events], runStatus: failed ? 'failed' : 'running' });
68
- },
69
- onError: fail,
70
- onDone: done,
71
- });
87
+ await args.transport.startRun({ history, agentId: args.agentId, assistantMessageId: reply.id, signal: abort.signal }, handlers);
72
88
  }
73
89
  catch (error) {
74
- fail(error instanceof Error ? error : new Error(String(error)));
75
- done(events);
90
+ transportFailed(error);
76
91
  }
77
92
  return true;
78
93
  },
@@ -0,0 +1,35 @@
1
+ import type { ExecutionPort, ExecutionCardAgent } from '@jini-ai/core/contracts/execution';
2
+ /** Detection runs on the server; preload bridge presence identifies when that server is local.
3
+ * Returns the dictionary KEY: the server-scope one carries `{productName}`, filled at each render site
4
+ * from `SETTINGS_EXECUTION_PRODUCT_VARS` (`integrations/jini-admin/settings-execution-copy.ts`).
5
+ * Do not infer desktop from screen size, localhost URLs, or the site-switcher flag. */
6
+ export declare function localCliScopeCopy({ desktop, desktopKey, serverKey }: {
7
+ desktop: boolean;
8
+ desktopKey: string;
9
+ serverKey: string;
10
+ }, _optional?: {}): string;
11
+ /** Unknown authentication is not a refusal. Warn only about a confirmed missing sign-in. */
12
+ export declare function selectedAgentWarning({ mode, agentId, agents, locale, translate }: {
13
+ mode: string;
14
+ agentId: string | null;
15
+ agents: readonly ExecutionCardAgent[];
16
+ locale: string;
17
+ translate: (required: {
18
+ locale: string;
19
+ key: string;
20
+ }) => string;
21
+ }, _optional?: {}): string | null;
22
+ /** Empty strings suppress the shared card's divider; trim whitespace without inventing vendor copy.
23
+ * Undefined preserves Jini's existing vendor-description fallback. */
24
+ export declare function normalizeAgentDescription({ agent }: {
25
+ agent: ExecutionCardAgent;
26
+ }, _optional?: {}): ExecutionCardAgent;
27
+ /** Share the component's scan with the warning instead of spawning another inventory sweep.
28
+ * Rescan results replace previous auth status; rejected scans remain failures, never empty lists. */
29
+ export declare function createAgentPresentationPort({ port, onAgents }: {
30
+ port: ExecutionPort;
31
+ onAgents: (input: {
32
+ agents: readonly ExecutionCardAgent[];
33
+ }, options?: Record<string, never>) => void;
34
+ }, _optional?: {}): ExecutionPort;
35
+ //# sourceMappingURL=ai-agent-presentation.d.ts.map
@@ -0,0 +1,39 @@
1
+ /** Detection runs on the server; preload bridge presence identifies when that server is local.
2
+ * Returns the dictionary KEY: the server-scope one carries `{productName}`, filled at each render site
3
+ * from `SETTINGS_EXECUTION_PRODUCT_VARS` (`integrations/jini-admin/settings-execution-copy.ts`).
4
+ * Do not infer desktop from screen size, localhost URLs, or the site-switcher flag. */
5
+ export function localCliScopeCopy({ desktop, desktopKey, serverKey }, _optional = {}) {
6
+ return desktop ? desktopKey : serverKey;
7
+ }
8
+ /** Unknown authentication is not a refusal. Warn only about a confirmed missing sign-in. */
9
+ export function selectedAgentWarning({ mode, agentId, agents, locale, translate }, _optional = {}) {
10
+ const agent = agents.find((candidate) => candidate.id === agentId);
11
+ return mode === 'local-cli' && agent?.installed && agent.authStatus === 'missing'
12
+ ? `${agent.label}: ${translate({ locale: locale, key: 'Authentication required. Sign in before sending.' })}` : null;
13
+ }
14
+ /** Empty strings suppress the shared card's divider; trim whitespace without inventing vendor copy.
15
+ * Undefined preserves Jini's existing vendor-description fallback. */
16
+ export function normalizeAgentDescription({ agent }, _optional = {}) {
17
+ return agent.description === undefined ? agent : { ...agent, description: agent.description.trim() };
18
+ }
19
+ /** Share the component's scan with the warning instead of spawning another inventory sweep.
20
+ * Rescan results replace previous auth status; rejected scans remain failures, never empty lists. */
21
+ export function createAgentPresentationPort({ port, onAgents }, _optional = {}) {
22
+ let latestScan = 0;
23
+ const project = async ({ request }, _options = {}) => {
24
+ latestScan += 1;
25
+ const scan = latestScan;
26
+ const agents = (await request()).map((agent) => normalizeAgentDescription({ agent }));
27
+ // A slow initial scan must not overwrite a newer rescan's authentication result.
28
+ if (scan === latestScan)
29
+ onAgents({ agents });
30
+ return agents;
31
+ };
32
+ const rescanLocalAgents = port.rescanLocalAgents;
33
+ return {
34
+ ...port,
35
+ detectLocalAgents: () => project({ request: () => port.detectLocalAgents() }),
36
+ ...(rescanLocalAgents ? { rescanLocalAgents: () => project({ request: () => rescanLocalAgents.call(port) }) } : {}),
37
+ };
38
+ }
39
+ //# sourceMappingURL=ai-agent-presentation.js.map
@@ -0,0 +1,22 @@
1
+ import type { ExecutionConfig, ExecutionPort } from '@jini-ai/core/contracts/execution';
2
+ /** Observe the same detection that renders Settings cards, including rescans and selection changes. */
3
+ export declare function useAiAgentPresentation({ port, config, locale, desktop, defaultLocalAgentId, translate, scopeKeys }: {
4
+ port: ExecutionPort;
5
+ config: ExecutionConfig | null;
6
+ locale: string;
7
+ desktop: boolean;
8
+ defaultLocalAgentId: string;
9
+ translate: (required: {
10
+ locale: string;
11
+ key: string;
12
+ }) => string;
13
+ scopeKeys: {
14
+ desktopKey: string;
15
+ serverKey: string;
16
+ };
17
+ }, _optional?: Record<string, never>): {
18
+ port: ExecutionPort;
19
+ scopeCopy: string;
20
+ warning: string | null;
21
+ };
22
+ //# sourceMappingURL=use-ai-agent-presentation.hooks.d.ts.map