@jini-ai/chat 0.7.3-next.2 → 0.7.3-next.4

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 (216) 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 +32 -0
  86. package/dist/react/chat-cleanup/ChatCleanupPanel.js +34 -0
  87. package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +174 -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 +15 -0
  91. package/dist/react/components/ChatSettingsDialog.d.ts +3 -0
  92. package/dist/react/components/ChatSettingsDialog.js +3 -3
  93. package/dist/react/components/ConversationList.d.ts +19 -5
  94. package/dist/react/components/ConversationList.hooks.d.ts +1 -0
  95. package/dist/react/components/ConversationList.hooks.js +4 -2
  96. package/dist/react/components/ConversationList.js +66 -9
  97. package/dist/react/components/Icon.d.ts +1 -1
  98. package/dist/react/components/Icon.js +7 -0
  99. package/dist/react/components/Markdown.js +6 -6
  100. package/dist/react/components/MarkdownLink.d.ts +25 -0
  101. package/dist/react/components/MarkdownLink.js +17 -0
  102. package/dist/react/components/RoutedA2uiSurfaceCard.d.ts +80 -0
  103. package/dist/react/components/RoutedA2uiSurfaceCard.js +15 -0
  104. package/dist/react/components/ToolCard.d.ts +4 -2
  105. package/dist/react/components/ToolCard.js +46 -4
  106. package/dist/react/components/ToolCard.rules.d.ts +5 -2
  107. package/dist/react/components/ToolCard.rules.js +12 -5
  108. package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
  109. package/dist/react/components/mcp-ui-surface-state.d.ts +3 -1
  110. package/dist/react/components/mcp-ui-surface-state.js +2 -2
  111. package/dist/react/components/own-link.d.ts +26 -0
  112. package/dist/react/components/own-link.js +36 -0
  113. package/dist/react/features/bridged-chat/create-staged-attachment-uploader.d.ts +7 -0
  114. package/dist/react/features/bridged-chat/create-staged-attachment-uploader.js +26 -0
  115. package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.d.ts +12 -0
  116. package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.js +60 -0
  117. package/dist/react/features/bridged-chat/index.d.ts +8 -0
  118. package/dist/react/features/bridged-chat/index.js +7 -0
  119. package/dist/react/features/bridged-chat/types.d.ts +49 -0
  120. package/dist/react/features/bridged-chat/types.js +2 -0
  121. package/dist/react/features/chat-pane/components/RuntimeDropUp.js +1 -1
  122. package/dist/react/features/chat-pane/create-daemon-attachment-uploader.d.ts +6 -0
  123. package/dist/react/features/chat-pane/create-daemon-attachment-uploader.js +101 -59
  124. package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.d.ts +3 -0
  125. package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.js +26 -16
  126. package/dist/react/features/chat-pane/model-options.d.ts +3 -1
  127. package/dist/react/features/chat-pane/model-options.js +3 -3
  128. package/dist/react/features/chat-pane/rules.js +4 -3
  129. package/dist/react/features/chat-pane/styles.d.ts +1 -1
  130. package/dist/react/features/chat-pane/styles.js +16 -0
  131. package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.d.ts +10 -0
  132. package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.js +19 -0
  133. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.d.ts +12 -0
  134. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.js +21 -0
  135. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.d.ts +13 -0
  136. package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.js +9 -0
  137. package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.d.ts +12 -0
  138. package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.js +12 -0
  139. package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.d.ts +7 -0
  140. package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.js +43 -0
  141. package/dist/react/features/conversation-chat-pane/index.d.ts +9 -0
  142. package/dist/react/features/conversation-chat-pane/index.js +8 -0
  143. package/dist/react/features/conversation-chat-pane/rules.d.ts +25 -0
  144. package/dist/react/features/conversation-chat-pane/rules.js +29 -0
  145. package/dist/react/features/conversation-chat-pane/types.d.ts +139 -0
  146. package/dist/react/features/conversation-chat-pane/types.js +2 -0
  147. package/dist/react/features/conversations/conversation-controller.d.ts +16 -0
  148. package/dist/react/features/conversations/conversation-controller.js +280 -0
  149. package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.d.ts +15 -0
  150. package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.js +33 -0
  151. package/dist/react/features/conversations/hooks/useStoredConversations.hooks.d.ts +16 -0
  152. package/dist/react/features/conversations/hooks/useStoredConversations.hooks.js +36 -0
  153. package/dist/react/features/conversations/index.d.ts +9 -0
  154. package/dist/react/features/conversations/index.js +8 -0
  155. package/dist/react/features/conversations/types.d.ts +120 -0
  156. package/dist/react/features/conversations/types.js +2 -0
  157. package/dist/react/features/voice-input/space-hold-rules.d.ts +65 -0
  158. package/dist/react/features/voice-input/space-hold-rules.js +48 -0
  159. package/dist/react/hooks/testing/fake-transport.d.ts +1 -1
  160. package/dist/react/hooks/useAnsweredCards.d.ts +2 -1
  161. package/dist/react/hooks/useConversation.js +5 -2
  162. package/dist/react/hooks/useExtEventGroups.d.ts +1 -1
  163. package/dist/react/hooks/useRunActivity.d.ts +2 -1
  164. package/dist/react/hooks/useRunStream.d.ts +1 -1
  165. package/dist/react/hooks/useRunStream.js +1 -1
  166. package/dist/react/hooks/useSurfaceRecovery.js +3 -1
  167. package/dist/react/hooks/useToolTimeline.d.ts +2 -1
  168. package/dist/react/index.d.ts +5 -2
  169. package/dist/react/index.js +4 -2
  170. package/dist/react/message-blocks.d.ts +1 -48
  171. package/dist/react/message-blocks.js +47 -0
  172. package/dist/react/styles/chat-settings.css +42 -14
  173. package/dist/server/chat-cleanup-routes.d.ts +56 -0
  174. package/dist/server/chat-cleanup-routes.js +56 -0
  175. package/dist/server/durable-runs/recover.js +193 -171
  176. package/dist/server/run-finalizer/entry.js +133 -110
  177. package/dist/store/legacy/sqlite/conversations.js +29 -17
  178. package/dist/store/pglite/index.d.ts +1 -0
  179. package/dist/store/pglite/index.js +1 -0
  180. package/dist/store/ports.d.ts +12 -0
  181. package/dist/store/postgres/index.d.ts +1 -0
  182. package/dist/store/postgres/index.js +1 -0
  183. package/dist/store/runtime/attempt-base-retention.d.ts +57 -0
  184. package/dist/store/runtime/attempt-base-retention.js +103 -0
  185. package/dist/store/runtime/chat-maintenance.d.ts +16 -0
  186. package/dist/store/runtime/chat-maintenance.js +19 -0
  187. package/dist/store/runtime/chat-principal.d.ts +63 -0
  188. package/dist/store/runtime/chat-principal.js +39 -0
  189. package/dist/store/runtime/checkpoint-delta.d.ts +1 -1
  190. package/dist/store/runtime/durable-run-queries.d.ts +124 -0
  191. package/dist/store/runtime/durable-run-queries.js +122 -0
  192. package/dist/store/runtime/durable-run-store.d.ts +1 -1
  193. package/dist/store/runtime/durable-run-store.js +291 -343
  194. package/dist/store/runtime/entry.d.ts +3 -0
  195. package/dist/store/runtime/entry.js +3 -0
  196. package/dist/store/runtime/events-json.d.ts +1 -1
  197. package/dist/store/runtime/lazy-run-ledger.d.ts +19 -0
  198. package/dist/store/runtime/lazy-run-ledger.js +28 -0
  199. package/dist/store/runtime/run-ledger.d.ts +4 -1
  200. package/dist/store/runtime/run-ledger.js +256 -204
  201. package/dist/store/sql/bulk-deletion.d.ts +36 -0
  202. package/dist/store/sql/bulk-deletion.js +103 -0
  203. package/dist/store/sql/store-queries.d.ts +170 -0
  204. package/dist/store/sql/store-queries.js +212 -0
  205. package/dist/store/sql/store-rows.d.ts +106 -0
  206. package/dist/store/sql/store-rows.js +116 -0
  207. package/dist/store/sql/store-writes.d.ts +46 -0
  208. package/dist/store/sql/store-writes.js +161 -0
  209. package/dist/store/sql/store.d.ts +3 -16
  210. package/dist/store/sql/store.js +58 -428
  211. package/dist/store/sql/tables.d.ts +1 -0
  212. package/dist/store/sqlite/index.d.ts +1 -0
  213. package/dist/store/sqlite/index.js +1 -0
  214. package/dist/store/sqlite/schema.d.ts +1 -1
  215. package/dist/store/sqlite/schema.js +5 -1
  216. package/package.json +171 -20
@@ -6,91 +6,13 @@
6
6
  * `RunAgentPayload` (the wire-level per-chunk protocol), and intentionally
7
7
  * decoupled from it: a host's transport adapter is responsible for reducing
8
8
  * wire deltas (`text_delta`, `thinking_delta`, `tool_input_delta`, ...) into
9
- * the persisted/renderable `AgentEvent` items below before handing them to
9
+ * the persisted/renderable `AgentEvent` items (declared type-only in
10
+ * `@jini-ai/core/contracts/site/chat-core`, re-exported here) before handing them to
10
11
  * chat-core's pure helpers. See archived provenance ledger for the provenance of this
11
12
  * split and why chat-core does not itself depend on `@jini-ai/protocol`.
12
13
  */
13
- /**
14
- * One tool-result content block a `tool_result` event may carry alongside its flattened `content`
15
- * string, for a renderer to display directly. Ported (not imported) from
16
- * `@jini-ai/daemon`'s `tool-result-media.ts` — this module's own doc explains why chat-core does
17
- * not depend on `@jini-ai/protocol` (or, by the same reasoning, on `@jini-ai/daemon`), the same
18
- * "translate the wire, don't import it" posture `assistant-ag-ui.ts` documents for its own port of
19
- * this package's vocabulary in the other direction. Keep in sync by hand if the daemon's shape
20
- * changes — the image arm has two required and two optional fields, so drift is easy to spot in review.
21
- */
22
- export type ToolResultMediaBlock = {
23
- readonly type: 'text';
24
- readonly text: string;
25
- } | {
26
- readonly type: 'image';
27
- readonly mimeType: string;
28
- readonly data: string;
29
- /** Optional caption and alt text (e.g. the media item's title). */
30
- readonly title?: string;
31
- /** Optional link to the full file; the renderer only links a safe (http(s) or same-site) target. */
32
- readonly href?: string;
33
- };
34
- /**
35
- * A single renderable unit of agent output. Covers every generic variant a
36
- * chat surface needs — status/text/thinking/tool lifecycle/usage/raw — plus
37
- * an `ext` escape hatch so a host can carry its own product-specific event
38
- * kinds (e.g. an OD `live_artifact` or `plugin_candidate` notification)
39
- * through the same envelope without this package knowing about them.
40
- */
41
- export type AgentEvent = {
42
- kind: 'status';
43
- label: string;
44
- detail?: string;
45
- code?: string;
46
- /** Structured fields for a coded status (e.g. `api_retry`'s attempt numbers). See `run-activity.ts`. */
47
- data?: Readonly<Record<string, string | number>>;
48
- } | {
49
- kind: 'text';
50
- text: string;
51
- } | {
52
- kind: 'thinking';
53
- text: string;
54
- } | {
55
- kind: 'tool_use';
56
- id: string;
57
- name: string;
58
- input: unknown;
59
- bridgeCall?: {
60
- name: string;
61
- input: unknown;
62
- buffered?: boolean;
63
- };
64
- toolOrigin?: 'bridge';
65
- } | {
66
- kind: 'tool_result';
67
- toolUseId: string;
68
- content: string;
69
- isError: boolean;
70
- /** Typed media (currently just images) a renderer may show directly. Absent for the
71
- * overwhelming majority of tool results, which carry none. */
72
- media?: readonly ToolResultMediaBlock[];
73
- /** Set when the call may or may not have run (its tool RPC connection broke after sending).
74
- * Such a result does not complete the call: a repeat must verify state first. */
75
- outcome?: 'unknown';
76
- } | {
77
- kind: 'usage';
78
- inputTokens?: number;
79
- outputTokens?: number;
80
- costUsd?: number;
81
- /** CLI session snapshot, persisted in events_json; reconciled across turns before display. */
82
- cumulativeCostUsd?: number;
83
- costSessionId?: string;
84
- durationMs?: number;
85
- stopReason?: string;
86
- } | {
87
- kind: 'raw';
88
- line: string;
89
- } | {
90
- kind: 'ext';
91
- name: string;
92
- data: unknown;
93
- };
14
+ import type { AgentEvent } from '@jini-ai/core/contracts/site/chat-core';
15
+ export type { AgentEvent, ToolResultMediaBlock } from '@jini-ai/core/contracts/site/chat-core';
94
16
  /** Narrows `AgentEvent` to its `tool_use` variant. */
95
17
  export type ToolUseEvent = Extract<AgentEvent, {
96
18
  kind: 'tool_use';
@@ -6,7 +6,8 @@
6
6
  * `RunAgentPayload` (the wire-level per-chunk protocol), and intentionally
7
7
  * decoupled from it: a host's transport adapter is responsible for reducing
8
8
  * wire deltas (`text_delta`, `thinking_delta`, `tool_input_delta`, ...) into
9
- * the persisted/renderable `AgentEvent` items below before handing them to
9
+ * the persisted/renderable `AgentEvent` items (declared type-only in
10
+ * `@jini-ai/core/contracts/site/chat-core`, re-exported here) before handing them to
10
11
  * chat-core's pure helpers. See archived provenance ledger for the provenance of this
11
12
  * split and why chat-core does not itself depend on `@jini-ai/protocol`.
12
13
  */
@@ -4,6 +4,8 @@
4
4
  * C2/C3). Hosts can implement the transport port without importing a browser component graph.
5
5
  */
6
6
  export * from './events.js';
7
+ /** Deprecated re-export: import these from `@jini-ai/core/contracts/site/chat-core`; removed at the next major. */
8
+ export type { AgentEvent, ToolResultMediaBlock } from "@jini-ai/core/contracts/site/chat-core";
7
9
  export * from './messages.js';
8
10
  export * from './conversation-title.js';
9
11
  export * from './partial-json.js';
@@ -18,6 +20,7 @@ export * from './util/index.js';
18
20
  export * from './transcript.js';
19
21
  export * from './run-activity.js';
20
22
  export * from './surface-expiry.js';
23
+ export { SURFACE_EXCHANGE_META } from './surface-recovery.js';
21
24
  export * from './assistant-content.js';
22
25
  export * from './compact-events.js';
23
26
  /** Chat-pane capability manifest. Generic agent-control vocabulary, markup and projections are
@@ -26,7 +29,7 @@ export * from './agentic/index.js';
26
29
  /**
27
30
  * Durable chat history — the storage-neutral `ChatHistoryStore` port and the local title
28
31
  * heuristic. Types and pure functions only, so this package stays framework-free and
29
- * `runtime: universal`; the SQLite implementation lives in `@jini-ai/sqlite-chat`'s `chat-history`
32
+ * `runtime: universal`; the SQLite implementation lives in `@jini-ai/chat/store/sqlite`'s `chat-history`
30
33
  * module, and a host binds it to its own authentication.
31
34
  */
32
35
  export * from './persistence/index.js';
@@ -18,6 +18,7 @@ export * from './util/index.js';
18
18
  export * from './transcript.js';
19
19
  export * from './run-activity.js';
20
20
  export * from './surface-expiry.js';
21
+ export { SURFACE_EXCHANGE_META } from './surface-recovery.js';
21
22
  export * from './assistant-content.js';
22
23
  export * from './compact-events.js';
23
24
  /** Chat-pane capability manifest. Generic agent-control vocabulary, markup and projections are
@@ -26,7 +27,7 @@ export * from './agentic/index.js';
26
27
  /**
27
28
  * Durable chat history — the storage-neutral `ChatHistoryStore` port and the local title
28
29
  * heuristic. Types and pure functions only, so this package stays framework-free and
29
- * `runtime: universal`; the SQLite implementation lives in `@jini-ai/sqlite-chat`'s `chat-history`
30
+ * `runtime: universal`; the SQLite implementation lives in `@jini-ai/chat/store/sqlite`'s `chat-history`
30
31
  * module, and a host binds it to its own authentication.
31
32
  */
32
33
  export * from './persistence/index.js';
@@ -1,4 +1,4 @@
1
- import type { AgentEvent } from './events.js';
1
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
2
2
  /** Who authored a `ChatMessage`. */
3
3
  export type ChatRole = 'user' | 'assistant';
4
4
  /**
@@ -2,7 +2,7 @@
2
2
  * @module persistence
3
3
  *
4
4
  * Durable chat history: the storage-neutral port plus the local title heuristic. No driver, no
5
- * DDL, no I/O — a SQLite implementation lives in `@jini-ai/sqlite-chat`'s `chat-history` module, and
5
+ * DDL, no I/O — a SQLite implementation lives in `@jini-ai/chat/store/sqlite`'s `chat-history` module, and
6
6
  * a host binds it to its own auth. See `./ports.ts` for why the owner scope is bound into the
7
7
  * store rather than passed per call.
8
8
  */
@@ -2,7 +2,7 @@
2
2
  * @module persistence
3
3
  *
4
4
  * Durable chat history: the storage-neutral port plus the local title heuristic. No driver, no
5
- * DDL, no I/O — a SQLite implementation lives in `@jini-ai/sqlite-chat`'s `chat-history` module, and
5
+ * DDL, no I/O — a SQLite implementation lives in `@jini-ai/chat/store/sqlite`'s `chat-history` module, and
6
6
  * a host binds it to its own auth. See `./ports.ts` for why the owner scope is bound into the
7
7
  * store rather than passed per call.
8
8
  */
@@ -11,11 +11,17 @@
11
11
  */
12
12
  import type { FormQuestion } from './types.js';
13
13
  /** `raw` viewed as a record of fields, or `null` when it isn't an object at all. */
14
- export declare function asRecord(raw: unknown): Record<string, unknown> | null;
14
+ export declare function asRecord({ raw }: {
15
+ raw: unknown;
16
+ }, _optional?: Record<string, never>): Record<string, unknown> | null;
15
17
  /** `raw` when it is a string, else `undefined`. */
16
- export declare function stringOrUndefined(raw: unknown): string | undefined;
18
+ export declare function stringOrUndefined({ raw }: {
19
+ raw: unknown;
20
+ }, _optional?: Record<string, never>): string | undefined;
17
21
  /** `raw` when it is a non-empty string, else `undefined`. */
18
- export declare function nonEmptyString(raw: unknown): string | undefined;
22
+ export declare function nonEmptyString({ raw }: {
23
+ raw: unknown;
24
+ }, _optional?: Record<string, never>): string | undefined;
19
25
  type OmitUndefined<T> = {
20
26
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
21
27
  } & {
@@ -1,19 +1,19 @@
1
1
  import { formOptionValueForLabel } from './format.js';
2
2
  /** `raw` viewed as a record of fields, or `null` when it isn't an object at all. */
3
- export function asRecord(raw) {
3
+ export function asRecord({ raw }, _optional = {}) {
4
4
  return raw && typeof raw === 'object' ? raw : null;
5
5
  }
6
6
  /** `raw` when it is a string, else `undefined`. */
7
- export function stringOrUndefined(raw) {
7
+ export function stringOrUndefined({ raw }, _optional = {}) {
8
8
  return typeof raw === 'string' ? raw : undefined;
9
9
  }
10
10
  /** `raw` when it is a non-empty string, else `undefined`. */
11
- export function nonEmptyString(raw) {
12
- return stringOrUndefined(raw) || undefined;
11
+ export function nonEmptyString({ raw }, _optional = {}) {
12
+ return stringOrUndefined({ raw }) || undefined;
13
13
  }
14
14
  /** `raw` trimmed when it is a string with visible content, else `undefined`. */
15
15
  function trimmedNonBlank(raw) {
16
- return nonEmptyString(stringOrUndefined(raw)?.trim());
16
+ return nonEmptyString({ raw: stringOrUndefined({ raw })?.trim() });
17
17
  }
18
18
  /** The string entries of `raw` when it is an array, else an empty list. */
19
19
  function stringsOnly(raw) {
@@ -28,7 +28,7 @@ export function omitUndefined(obj) {
28
28
  return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
29
29
  }
30
30
  export function mapRawQuestion({ q, index }) {
31
- const qo = asRecord(q);
31
+ const qo = asRecord({ raw: q });
32
32
  if (!qo)
33
33
  return null;
34
34
  const id = trimmedNonBlank(qo.id) ?? `q${index + 1}`;
@@ -37,23 +37,23 @@ export function mapRawQuestion({ q, index }) {
37
37
  const isFile = type === 'file';
38
38
  return omitUndefined({
39
39
  id,
40
- name: stringOrUndefined(qo.name),
41
- label: stringOrUndefined(qo.label) ?? id,
40
+ name: stringOrUndefined({ raw: qo.name }),
41
+ label: stringOrUndefined({ raw: qo.label }) ?? id,
42
42
  type,
43
43
  options,
44
- placeholder: nonEmptyString(qo.placeholder),
45
- help: nonEmptyString(qo.help),
44
+ placeholder: nonEmptyString({ raw: qo.placeholder }),
45
+ help: nonEmptyString({ raw: qo.help }),
46
46
  required: qo.required === true || undefined,
47
47
  defaultValue: parseDefaultValue(qo, options),
48
48
  maxSelections: type === 'checkbox' ? positiveInteger(qo.maxSelections) : undefined,
49
49
  allowCustom: parseAllowCustom(qo),
50
- customLabel: nonEmptyString(qo.customLabel),
51
- customPlaceholder: nonEmptyString(qo.customPlaceholder),
50
+ customLabel: nonEmptyString({ raw: qo.customLabel }),
51
+ customPlaceholder: nonEmptyString({ raw: qo.customPlaceholder }),
52
52
  min: parseNumberAttr(qo.min),
53
53
  max: parseNumberAttr(qo.max),
54
54
  step: parseNumberAttr(qo.step),
55
55
  multiple: (isFile && qo.multiple === true) || undefined,
56
- accept: isFile ? nonEmptyString(qo.accept) : undefined,
56
+ accept: isFile ? nonEmptyString({ raw: qo.accept }) : undefined,
57
57
  cards: parseDirectionCards(qo.cards),
58
58
  });
59
59
  }
@@ -108,7 +108,7 @@ function parseOption(raw) {
108
108
  const label = trimmedNonBlank(raw);
109
109
  return label ? { label, value: label } : null;
110
110
  }
111
- const obj = asRecord(raw) ?? {};
111
+ const obj = asRecord({ raw }) ?? {};
112
112
  const label = trimmedNonBlank(obj.label);
113
113
  if (!label)
114
114
  return null;
@@ -125,7 +125,7 @@ function parseDefaultValue(question, options) {
125
125
  function scalarString(raw) {
126
126
  if (typeof raw === 'number' || typeof raw === 'boolean')
127
127
  return String(raw);
128
- return stringOrUndefined(raw);
128
+ return stringOrUndefined({ raw });
129
129
  }
130
130
  /** `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`. */
131
131
  const HEX_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
@@ -162,22 +162,22 @@ export function isRenderableColor({ value }) {
162
162
  function parseDirectionCards(raw) {
163
163
  if (!Array.isArray(raw))
164
164
  return undefined;
165
- const out = raw.flatMap((entry) => parseDirectionCard(asRecord(entry) ?? {}) ?? []);
165
+ const out = raw.flatMap((entry) => parseDirectionCard(asRecord({ raw: entry }) ?? {}) ?? []);
166
166
  return out.length > 0 ? out : undefined;
167
167
  }
168
168
  function parseDirectionCard(e) {
169
169
  const id = trimmedNonBlank(e.id);
170
- const label = stringOrUndefined(e.label);
170
+ const label = stringOrUndefined({ raw: e.label });
171
171
  if (id === undefined || label === undefined)
172
172
  return null;
173
173
  return {
174
174
  id,
175
175
  label,
176
- mood: stringOrUndefined(e.mood) ?? '',
176
+ mood: stringOrUndefined({ raw: e.mood }) ?? '',
177
177
  references: stringsOnly(e.references).slice(0, 6),
178
178
  palette: stringsOnly(e.palette).filter((value) => isRenderableColor({ value })).slice(0, 8),
179
- displayFont: stringOrUndefined(e.displayFont) ?? 'Georgia, serif',
180
- bodyFont: stringOrUndefined(e.bodyFont) ?? '-apple-system, system-ui, sans-serif',
179
+ displayFont: stringOrUndefined({ raw: e.displayFont }) ?? 'Georgia, serif',
180
+ bodyFont: stringOrUndefined({ raw: e.bodyFont }) ?? '-apple-system, system-ui, sans-serif',
181
181
  };
182
182
  }
183
183
  //# sourceMappingURL=normalize.js.map
@@ -135,13 +135,13 @@ function tryParseForm(body, attrs) {
135
135
  catch {
136
136
  return null;
137
137
  }
138
- const obj = asRecord(data);
138
+ const obj = asRecord({ raw: data });
139
139
  if (!obj || !Array.isArray(obj.questions))
140
140
  return null;
141
141
  const questions = obj.questions.flatMap((q, index) => mapRawQuestion({ q, index }) ?? []);
142
142
  if (questions.length === 0)
143
143
  return null;
144
- return assembleForm({ attrs, top: obj, bodyId: stringOrUndefined(obj.id), bodyTitle: stringOrUndefined(obj.title), questions });
144
+ return assembleForm({ attrs, top: obj, bodyId: stringOrUndefined({ raw: obj.id }), bodyTitle: stringOrUndefined({ raw: obj.title }), questions });
145
145
  }
146
146
  // Form-level fields shared by the complete and streaming parsers: the open
147
147
  // tag's attrs win over the body's own id/title, which win over the defaults.
@@ -150,8 +150,8 @@ function assembleForm({ attrs, top, bodyId, bodyTitle, questions }) {
150
150
  id: attrs.id ?? bodyId ?? 'discovery',
151
151
  title: attrs.title ?? bodyTitle ?? 'A few quick questions',
152
152
  questions,
153
- description: nonEmptyString(top.description),
154
- submitLabel: nonEmptyString(top.submitLabel),
153
+ description: nonEmptyString({ raw: top.description }),
154
+ submitLabel: nonEmptyString({ raw: top.submitLabel }),
155
155
  });
156
156
  }
157
157
  /**
@@ -180,8 +180,8 @@ export function parsePartialQuestionForm({ input }) {
180
180
  // Derive form-level metadata from the *parsed top-level object*, not a
181
181
  // whole-body regex scan: a nested question/option `id`/`title`/`description`
182
182
  // must not masquerade as the form's own.
183
- const top = asRecord(parsePartialJson({ buf: body })) ?? {};
184
- const title = stringOrUndefined(top.title);
183
+ const top = asRecord({ raw: parsePartialJson({ buf: body }) }) ?? {};
184
+ const title = stringOrUndefined({ raw: top.title });
185
185
  // `id` keys a still-editable panel, so it must be stable for the whole
186
186
  // stream — don't adopt it until its string literal is fully terminated,
187
187
  // otherwise it would churn character-by-character and remount the panel.
@@ -285,7 +285,7 @@ function shapeStreamingQuestions(rawQuestions, closedCount) {
285
285
  return [];
286
286
  const out = [];
287
287
  rawQuestions.forEach((raw, index) => {
288
- const q = asRecord(raw);
288
+ const q = asRecord({ raw });
289
289
  if (!q)
290
290
  return;
291
291
  const label = q.label;
@@ -330,23 +330,19 @@ function balancedObjectEnd({ s, start }) {
330
330
  let depth = 0;
331
331
  let i = start;
332
332
  while (i < s.length) {
333
- const c = s[i];
334
- if (c === '"') {
335
- const end = jsonStringEnd({ s, start: i });
336
- if (end === -1)
333
+ if (s[i] === '"') {
334
+ // Quoted token: advance past the whole literal; braces inside it never reach the accounting below.
335
+ i = jsonStringEnd({ s, start: i });
336
+ if (i === -1)
337
337
  return -1;
338
- i = end;
339
338
  continue;
340
339
  }
341
- if (c === '{')
342
- depth += 1;
343
- if (c === '}') {
344
- depth -= 1;
345
- if (depth === 0)
346
- return i + 1;
347
- }
340
+ depth += BRACE_DELTA[s[i]] ?? 0;
341
+ if (s[i] === '}' && depth === 0)
342
+ return i + 1;
348
343
  i += 1;
349
344
  }
350
345
  return -1;
351
346
  }
347
+ const BRACE_DELTA = { '{': 1, '}': -1 };
352
348
  //# sourceMappingURL=scan.js.map
@@ -1,4 +1,4 @@
1
- import type { AgentEvent } from './events.js';
1
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
2
2
  /** The latest thing a running turn is doing. */
3
3
  export type RunActivity = {
4
4
  readonly kind: 'thinking';
@@ -4,40 +4,8 @@
4
4
  * event names and excluded run-ID prefixes are explicit host inputs, never product wire defaults.
5
5
  * Authenticated routing, ownership, boot repair and storage transactions remain host responsibilities. */
6
6
  import type { AgentEvent } from "../events.js";
7
- /**
8
- * @file The ONE translation from an agent-daemon run stream to chat events, shared by the browser
9
- * and the server.
10
- *
11
- * Purpose:
12
- * A daemon run streams `@jini-ai/protocol` frames (`agent`/`stdout`/`stderr`/`error`/`end`). A saved
13
- * chat row stores chat-core `AgentEvent`s plus a text `content` and a `run_status`. Until 2026-09-27
14
- * the frame-to-event translation lived only in the admin SPA (the host's `lib/assistant-transport.ts`),
15
- * so only a connected browser could turn a run into a saved answer: close the tab, or lose it to a
16
- * restart, and the row stayed `running` with no content forever (FINDING A,
17
- * `ADS-memory/reports/2026-09-27-stuck-chat-root-cause.md`).
18
- *
19
- * The server-side finalizer (`server/runtime/composition/modules/assistant-run-finalizer.ts`) now
20
- * saves the finished turn itself, and it must write exactly what the browser would have written. Two
21
- * copies of this switch would drift, so both import this file through the shared
22
- * `@jini-ai/chat/core/run-events` entry, with the host's bundler, test runner and TypeScript
23
- * resolving the same package contract.
24
- *
25
- * Architectural role:
26
- * PURE. No I/O, no DOM, no Node built-ins. The one value import is `@jini-ai/chat/core`'s content
27
- * rule, itself pure and React-free, so the saved `content` and the browser's can never differ.
28
- * `ReadableStream`/`TextDecoder` in {@link readSseFrames} are globals in both runtimes. Keep it that
29
- * way — the admin bundle imports it.
30
- */
31
- import type { ChatRunStatus } from "../messages.js";
32
- export interface RunAgentPayload {
33
- readonly type: string;
34
- readonly [key: string]: unknown;
35
- }
36
- export interface RunProtocolEventWire {
37
- readonly runId: string;
38
- readonly kind: "start" | "agent" | "stdout" | "stderr" | "error" | "end";
39
- readonly payload: unknown;
40
- }
7
+ import type { RunAgentPayload, TerminalOutcome, RunFrameOutcome, RunFrameCarry } from "@jini-ai/core/contracts/site/core-run-events";
8
+ export type { RunAgentPayload, RunProtocolEventWire, TerminalOutcome, RunFrameOutcome, RunFrameCarry, } from "@jini-ai/core/contracts/site/core-run-events";
41
9
  /** Display a wire scalar or JSON value using the existing empty-null convention. */
42
10
  export declare function asString({ value }: {
43
11
  value: unknown;
@@ -135,14 +103,6 @@ export declare function terminalReasonNotice({ reason, notice }: {
135
103
  kind: "status";
136
104
  }>;
137
105
  }, _options?: Record<string, never>): AgentEvent | null;
138
- /** A daemon `end` frame's non-successful terminal classification, as the daemon itself recorded it
139
- * in `@jini-ai/protocol`'s `RunEndPayload`. */
140
- export interface TerminalOutcome {
141
- readonly status: "failed" | "canceled";
142
- readonly code: string;
143
- readonly signal: string;
144
- readonly resumable: string;
145
- }
146
106
  /** Read non-successful daemon classification without throwing on malformed frames. */
147
107
  export declare function readTerminalOutcome({ raw }: {
148
108
  raw: string | undefined;
@@ -248,11 +208,16 @@ export declare function parseFrame({ rawFrame }: {
248
208
  * @overallScore 100
249
209
  */
250
210
  /** Decode complete named frames; cancellation always releases its reader. Inherits shared framing costs. */
251
- export declare function readSseFrames({ body }: {
211
+ export declare function readSseFrames(source: {
252
212
  body: ReadableStream<Uint8Array>;
253
- }, _options?: Record<string, never>): AsyncGenerator<{
213
+ } | {
214
+ reader: ReadableStreamDefaultReader<Uint8Array>;
215
+ }, { includeCursor }?: {
216
+ includeCursor?: boolean;
217
+ }): AsyncGenerator<{
254
218
  event: string;
255
219
  data: string;
220
+ cursor?: string | undefined;
256
221
  }>;
257
222
  /**
258
223
  * Whether the agent daemon holds this run, so its event stream can be read at
@@ -293,24 +258,6 @@ export declare function runContentFromEvents({ events }: {
293
258
  export declare function runEventsForSave({ events }: {
294
259
  events: readonly AgentEvent[];
295
260
  }, _options?: Record<string, never>): AgentEvent[];
296
- /** What one daemon stream frame means for the turn: events to append, a failure, and whether it ended. */
297
- /** Set when the frame reports a failure. Once any frame has, the turn is `failed` (the browser's
298
- * `useRunStream` keeps an `'error'` status through a later `onDone`). */
299
- /** Set only on the `end` frame: the daemon's own terminal classification. */
300
- export interface RunFrameOutcome {
301
- readonly events: AgentEvent[];
302
- readonly error?: Error;
303
- readonly terminal?: Extract<ChatRunStatus, "succeeded" | "failed" | "canceled">;
304
- }
305
- /**
306
- * Per-connection memory for {@link translateRunFrame}: which channels are mid-way through an echo
307
- * line. Only a line's first chunk carries the {@link ECHO_LINE} prefix, so without it the rest of a
308
- * split `user` echo stays as `raw` — tool-result prose that durable recovery then reads as executor
309
- * diagnostics. Pass one fresh `{}` per daemon connection (each connection replays from event 0).
310
- */
311
- export interface RunFrameCarry {
312
- openEchoChannels?: Set<string>;
313
- }
314
261
  /**
315
262
  * Translates one named daemon SSE frame (`event:` name plus raw `data:` text) into its effect on the
316
263
  * turn. The browser's `subscribeToRun` dispatches the result to `RunHandlers`; the server finalizer
@@ -327,7 +274,8 @@ export declare function translateRunFrame({ kind, raw, notices }: {
327
274
  kind: string;
328
275
  raw: string | undefined;
329
276
  notices: RunNotices;
330
- }, { carry }?: {
277
+ }, { carry, onAgentPayload }?: {
331
278
  carry?: RunFrameCarry;
279
+ onAgentPayload?: (payload: Record<string, unknown>) => void;
332
280
  }): RunFrameOutcome;
333
281
  //# sourceMappingURL=entry.d.ts.map
@@ -347,8 +347,9 @@ export function parseFrame({ rawFrame }, _options = {}) {
347
347
  * @overallScore 100
348
348
  */
349
349
  /** Decode complete named frames; cancellation always releases its reader. Inherits shared framing costs. */
350
- export async function* readSseFrames({ body }, _options = {}) {
351
- const reader = body.getReader();
350
+ export async function* readSseFrames(source, { includeCursor = false } = {}) {
351
+ const reader = 'body' in source ? source.body.getReader() : source.reader;
352
+ let cursor;
352
353
  let ended = false;
353
354
  async function* chunks() {
354
355
  for (;;) {
@@ -363,8 +364,9 @@ export async function* readSseFrames({ body }, _options = {}) {
363
364
  try {
364
365
  for await (const decoded of decodeSseFrames({ source: chunks() }, { flushFinalFrame: false })) {
365
366
  const frame = chatFrame(decoded);
367
+ cursor = decoded.id ?? cursor;
366
368
  if (frame)
367
- yield frame;
369
+ yield includeCursor ? { ...frame, cursor } : frame;
368
370
  }
369
371
  }
370
372
  finally {
@@ -552,10 +554,10 @@ function endOutcome(raw, notices) {
552
554
  * @complexity O(size of the frame).
553
555
  */
554
556
  /** Fold one named daemon frame into events, a failure and an optional terminal status. */
555
- export function translateRunFrame({ kind, raw, notices }, { carry } = {}) {
557
+ export function translateRunFrame({ kind, raw, notices }, { carry, onAgentPayload } = {}) {
556
558
  switch (kind) {
557
559
  case "agent":
558
- return { events: agentFrameEvents(raw) };
560
+ return { events: agentFrameEvents(raw, onAgentPayload) };
559
561
  // The agent CLI's own output. `stderr` is where a dying CLI says WHY it is dying.
560
562
  case "stdout":
561
563
  case "stderr":
@@ -568,10 +570,13 @@ export function translateRunFrame({ kind, raw, notices }, { carry } = {}) {
568
570
  return { events: [] };
569
571
  }
570
572
  }
571
- function agentFrameEvents(raw) {
573
+ function agentFrameEvents(raw, onAgentPayload) {
572
574
  const payload = parseWirePayload(raw);
573
575
  const translated = typeof payload?.type === "string" ? translateRunAgentPayload({ payload: payload }) : null;
574
- return translated ? [translated] : [];
576
+ if (!translated || !payload)
577
+ return [];
578
+ onAgentPayload?.(payload);
579
+ return [translated];
575
580
  }
576
581
  // Shown AND saved as a status line, not only reported: the error is live-only state, so without
577
582
  // the event the saved turn (and a reload) showed a bare "failed" with the reason lost. This is
@@ -6,8 +6,8 @@
6
6
  * derives the "latest plan state" a pinned progress card renders — no I/O,
7
7
  * no framework.
8
8
  */
9
- import type { AgentEvent } from './events.js';
10
9
  import { type ChatRunStatus } from './messages.js';
10
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
11
11
  export type TodoStatus = 'pending' | 'in_progress' | 'completed' | 'stopped';
12
12
  export interface TodoItem {
13
13
  content: string;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @module todos
3
+ *
4
+ * Pure TodoWrite-style plan-tool snapshot parsing/derivation. Reads the
5
+ * structured plan a `TodoWrite`/`update_plan`-shaped tool call carries and
6
+ * derives the "latest plan state" a pinned progress card renders — no I/O,
7
+ * no framework.
8
+ */
1
9
  import { isTerminalRunStatus } from './messages.js';
2
10
  const TODO_WRITE_TOOL_NAMES = new Set([
3
11
  'TodoWrite',
@@ -16,6 +16,13 @@ export interface ToolCallDetailOptions {
16
16
  readonly maxChars?: number;
17
17
  /** Defaults to the chat text policy, so a tool call never shows a key the rest of the chat would hide. */
18
18
  readonly redact?: RedactUserText;
19
+ /**
20
+ * `"display"` (default) shows a refused-arguments protocol error in plain words. `"copy-diagnostic"`
21
+ * keeps that protocol text for a person who chose to copy it for support, still through the same
22
+ * formatter, redactor, and cap. It must never be rendered: the protocol text is for the assistant
23
+ * to repair its call, not a user-facing explanation.
24
+ */
25
+ readonly resultPresentation?: 'display' | 'copy-diagnostic';
19
26
  }
20
27
  /**
21
28
  * Builds the readable detail for one tool call.
@@ -32,7 +39,7 @@ export declare function describeToolCallDetail({ input, result }: {
32
39
  readonly content: string;
33
40
  readonly isError?: boolean;
34
41
  } | undefined;
35
- }, { runStreaming, runSucceeded, maxChars, redact }?: ToolCallDetailOptions): ToolCallDetail;
42
+ }, { runStreaming, runSucceeded, maxChars, redact, resultPresentation }?: ToolCallDetailOptions): ToolCallDetail;
36
43
  /** Per-block cap for the text a collapsed row keeps mounted — see {@link describeCollapsedToolCall}. */
37
44
  export declare const COLLAPSED_DETAIL_MAX_CHARS = 400;
38
45
  /**