@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,20 +1,4 @@
1
- /**
2
- * @module assistant-content
3
- *
4
- * The ONE rule for turning a turn's events into its saved text `content`.
5
- *
6
- * Why it exists: `content` used to be every `text` event glued together (`out += ev.text`). A model
7
- * that writes a short note, calls a tool, then answers produced `"Need project id. Find
8
- * list_projects.`test_table` now exists…"` — the working note fused onto the answer mid-sentence,
9
- * in the saved row, the copy button, and any transcript rebuilt from it. The live pane already
10
- * shows those as separate steps (text, tool card, text); the saved string now keeps them apart too,
11
- * with a blank line (a Markdown paragraph break) wherever a tool call or card sat between them.
12
- *
13
- * Every producer of `content` must use this: the browser (`useConversation`) and any host that
14
- * saves a finished turn server-side. `interleaveMessageBlocks` accepts both this shape and the old
15
- * glued one, so rows saved before this change still render in order.
16
- */
17
- import type { AgentEvent } from './events.js';
1
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
18
2
  /** What separates two text runs that a tool call or card sat between. */
19
3
  export declare const ASSISTANT_STEP_SEPARATOR = "\n\n";
20
4
  /** Only explicit step transitions separate text. Thinking-token heartbeats and raw diagnostics
@@ -1,3 +1,19 @@
1
+ /**
2
+ * @module assistant-content
3
+ *
4
+ * The ONE rule for turning a turn's events into its saved text `content`.
5
+ *
6
+ * Why it exists: `content` used to be every `text` event glued together (`out += ev.text`). A model
7
+ * that writes a short note, calls a tool, then answers produced `"Need project id. Find
8
+ * list_projects.`test_table` now exists…"` — the working note fused onto the answer mid-sentence,
9
+ * in the saved row, the copy button, and any transcript rebuilt from it. The live pane already
10
+ * shows those as separate steps (text, tool card, text); the saved string now keeps them apart too,
11
+ * with a blank line (a Markdown paragraph break) wherever a tool call or card sat between them.
12
+ *
13
+ * Every producer of `content` must use this: the browser (`useConversation`) and any host that
14
+ * saves a finished turn server-side. `interleaveMessageBlocks` accepts both this shape and the old
15
+ * glued one, so rows saved before this change still render in order.
16
+ */
1
17
  import { dedupeToolUsesById } from './tool-events.js';
2
18
  /** What separates two text runs that a tool call or card sat between. */
3
19
  export const ASSISTANT_STEP_SEPARATOR = '\n\n';
@@ -0,0 +1,103 @@
1
+ /** assistant registration declarations; shared placement rationale is in the host's tool-metadata aggregator. */
2
+ export declare const toolMetadata: {
3
+ readonly tool_gaps_list: {
4
+ readonly search: {
5
+ readonly keywords: "tool gaps fallback Bash shell direct file edit write missing tools audit";
6
+ };
7
+ readonly approval: {
8
+ readonly class: "read";
9
+ readonly confirmation: "direct";
10
+ };
11
+ };
12
+ readonly assistant_admin_screen_link: {
13
+ readonly approval: {
14
+ readonly class: "read";
15
+ readonly confirmation: "direct";
16
+ };
17
+ };
18
+ readonly assistant_ask_choice: {
19
+ readonly search: {
20
+ readonly keywords: string;
21
+ };
22
+ readonly approval: {
23
+ readonly class: "read";
24
+ readonly confirmation: "direct";
25
+ };
26
+ readonly mcpUi: {
27
+ readonly redeemable: true;
28
+ };
29
+ };
30
+ readonly assistant_demo_a2ui: {
31
+ readonly approval: {
32
+ readonly class: "read";
33
+ readonly confirmation: "direct";
34
+ };
35
+ };
36
+ readonly assistant_demo_choices: {
37
+ readonly approval: {
38
+ readonly class: "read";
39
+ readonly confirmation: "direct";
40
+ };
41
+ readonly mcpUi: {
42
+ readonly redeemable: true;
43
+ };
44
+ };
45
+ readonly assistant_demo_image: {
46
+ readonly approval: {
47
+ readonly class: "read";
48
+ readonly confirmation: "direct";
49
+ };
50
+ };
51
+ readonly assistant_render_ui: {
52
+ readonly search: {
53
+ readonly keywords: "render show display draw put a chart here show me a graph draw a table build a dashboard visualize view results embed inline in chat";
54
+ };
55
+ readonly approval: {
56
+ readonly class: "read";
57
+ readonly confirmation: "direct";
58
+ };
59
+ };
60
+ readonly describe_component: {
61
+ readonly search: {
62
+ readonly keywords: "component props properties schema fields interactive ui widget render rendering";
63
+ };
64
+ readonly approval: {
65
+ readonly class: "read";
66
+ readonly confirmation: "direct";
67
+ };
68
+ };
69
+ readonly search_components: {
70
+ readonly search: {
71
+ readonly keywords: "component components widget widgets chart charts graph graphs table tables button buttons checkbox card cards render rendering draw drawing display visualize visualization interactive ui shadcn recharts pie bar line";
72
+ };
73
+ readonly approval: {
74
+ readonly class: "read";
75
+ readonly confirmation: "direct";
76
+ };
77
+ };
78
+ readonly assistant_tool_failure_recovery: {
79
+ readonly mcpUi: {
80
+ readonly redeemable: true;
81
+ };
82
+ };
83
+ readonly assistant_chats_list: {
84
+ readonly search: {
85
+ readonly keywords: "previous earlier interrupted chat conversation history search resume continue what we were doing";
86
+ readonly queries: readonly ["I had to start a new chat. Can you find what we were doing?", "Find my previous conversation."];
87
+ };
88
+ readonly approval: {
89
+ readonly class: "read";
90
+ readonly confirmation: "direct";
91
+ };
92
+ };
93
+ readonly assistant_chat_read: {
94
+ readonly search: {
95
+ readonly keywords: "read previous chat transcript history tail messages resume interrupted continue conversation";
96
+ };
97
+ readonly approval: {
98
+ readonly class: "read";
99
+ readonly confirmation: "direct";
100
+ };
101
+ };
102
+ };
103
+ //# sourceMappingURL=assistant-tool-metadata.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { assistantHistoryToolMetadata } from './history-tool-metadata.js';
2
+ /** assistant registration declarations; shared placement rationale is in the host's tool-metadata aggregator. */
3
+ export const toolMetadata = {
4
+ ...assistantHistoryToolMetadata,
5
+ "tool_gaps_list": {
6
+ search: { keywords: "tool gaps fallback Bash shell direct file edit write missing tools audit" },
7
+ approval: { class: 'read', confirmation: 'direct' },
8
+ },
9
+ "assistant_admin_screen_link": {
10
+ approval: { class: 'read', confirmation: 'direct' },
11
+ },
12
+ // --- ask the administrator a question -----------------------------------------------------------------
13
+ "assistant_ask_choice": {
14
+ search: {
15
+ keywords: "ask question decide decision confirm confirmation choose choice choices options option select " +
16
+ "single multi checklist checkbox radio approve approval permission go-ahead consent which one " +
17
+ "poll survey form dialog interactive get input from user administrator before doing proceed",
18
+ },
19
+ approval: { class: 'read', confirmation: 'direct' },
20
+ mcpUi: { redeemable: true },
21
+ },
22
+ "assistant_demo_a2ui": {
23
+ approval: { class: 'read', confirmation: 'direct' },
24
+ },
25
+ // Pure form readback needs no confirmation token: submitting cannot mutate state.
26
+ "assistant_demo_choices": {
27
+ approval: { class: 'read', confirmation: 'direct' },
28
+ mcpUi: { redeemable: true },
29
+ },
30
+ "assistant_demo_image": {
31
+ approval: { class: 'read', confirmation: 'direct' },
32
+ },
33
+ "assistant_render_ui": {
34
+ search: {
35
+ keywords: "render show display draw put a chart here show me a graph draw a table build a dashboard visualize view results embed inline in chat",
36
+ },
37
+ approval: { class: 'read', confirmation: 'direct' },
38
+ },
39
+ "describe_component": {
40
+ search: {
41
+ keywords: "component props properties schema fields interactive ui widget render rendering",
42
+ },
43
+ approval: { class: 'read', confirmation: 'direct' },
44
+ },
45
+ // --- interactive-UI component catalog -----------------------------------------------------------------
46
+ "search_components": {
47
+ search: {
48
+ keywords: "component components widget widgets chart charts graph graphs table tables button buttons checkbox card cards render rendering draw drawing display visualize visualization interactive ui shadcn recharts pie bar line",
49
+ },
50
+ approval: { class: 'read', confirmation: 'direct' },
51
+ },
52
+ "assistant_tool_failure_recovery": {
53
+ mcpUi: { redeemable: true },
54
+ },
55
+ };
56
+ //# sourceMappingURL=assistant-tool-metadata.js.map
@@ -16,7 +16,7 @@ export declare function checkpointIntervalMs({ bytes }: {
16
16
  * @example checkpointProgress({ events: [{ kind: 'thinking', text: 'Working' }] });
17
17
  */
18
18
  export declare function checkpointProgress({ events }: {
19
- events: readonly import('./events.js').AgentEvent[];
19
+ events: readonly import("@jini-ai/core/contracts/site/chat-core").AgentEvent[];
20
20
  }, _options?: {}): {
21
21
  textCharacters: number;
22
22
  extensionEvents: number;
@@ -11,7 +11,7 @@
11
11
  * a card, a status or raw line — still separates them, so `assistantContentFromEvents` and the
12
12
  * pane's step layout read the same before and after.
13
13
  */
14
- import type { AgentEvent } from './events.js';
14
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
15
15
  /**
16
16
  * The events with every run of adjacent `text` (or adjacent `thinking`) events joined into one.
17
17
  * Returns a new array; the input is not changed.
@@ -1,5 +1,5 @@
1
- import type { AgentEvent } from './events.js';
2
1
  import type { ChatMessage } from './messages.js';
2
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
3
3
  /** Saved checkpoints can coalesce deltas and a completion may replay only a prefix. Keep the
4
4
  * saved projection, merge identifiable events, and append only text beyond its saved prefix. */
5
5
  export declare function mergeRunEvents({ saved, incoming }: {
@@ -1,5 +1,5 @@
1
- import type { AgentEvent } from "../index.js";
2
1
  import type { AcceptedRunRequest, DurableRun } from "./ports.js";
2
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
3
3
  export declare const CONTINUATION_DIVIDER = "\n\n---\n\nContinued\n\n";
4
4
  export declare const UNKNOWN_MUTATION_ERROR = "This operation may already be done. Its earlier outcome is unknown; verify the current state before repeating it.";
5
5
  /** Object-key order and a new tool-use id must not turn the same mutation into a new operation. */
@@ -16,6 +16,9 @@ export interface InterruptedChatTurn {
16
16
  readonly message: ChatMessage;
17
17
  }
18
18
  export interface ChatRunRecoveryOptions {
19
+ readonly admit?: (required: {
20
+ turn: InterruptedChatTurn;
21
+ }, optional?: Record<string, never>) => Promise<'recover' | 'leave-owned'>;
19
22
  /** True retains the row: a daemon run was adopted with bounded resolution of uncertainty.
20
23
  * Called outside storage transactions so a daemon request cannot hold the database lock. */
21
24
  readonly recover?: (input: InterruptedChatTurn) => Promise<boolean>;
@@ -31,7 +34,7 @@ export interface CheckpointState {
31
34
  /** SQL characters in the complete last serialized event plus closing array bracket. */
32
35
  readonly tailLength: number;
33
36
  readonly content: string;
34
- readonly events: readonly import("../events.js").AgentEvent[];
37
+ readonly events: readonly import("@jini-ai/core/contracts/site/chat-core").AgentEvent[];
35
38
  /** At most 256 UTF-16 units of the saved suffix; never the whole last tool result. */
36
39
  readonly tail: string;
37
40
  }
@@ -1,5 +1,6 @@
1
- import type { AgentEvent, ChatMessage } from "../index.js";
1
+ import type { ChatMessage } from "../index.js";
2
2
  import type { RunProgress, RunRef, RunSettlement } from "./run-contracts.js";
3
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
3
4
  export interface AcceptedRunRequest {
4
5
  readonly agentId?: string;
5
6
  readonly contextRef: string;
@@ -1,5 +1,5 @@
1
- import type { AgentEvent } from "../events.js";
2
1
  import type { ChatRunStatus } from "../messages.js";
2
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
3
3
  /** Exactly which run owns the row; the host binds authorization and storage scope. */
4
4
  export interface RunRef {
5
5
  readonly conversationId: string;
@@ -0,0 +1,145 @@
1
+ import type { AgentEvent } from "@jini-ai/core/contracts/site/chat-core";
2
+ import { checkpointProgress } from "../checkpoint-interval.js";
3
+ /**
4
+ * @file Slices of a host's run finalizer: the ports its slices receive, the checkpointer, the checkpoint
5
+ * rules, the safe reporter call and the release of an unread events body. No clock, no timer,
6
+ * no storage: the host's finalizer owns those and injects them through the ports below.
7
+ */
8
+ /** Same required keys as the supervisor scheduler's `schedule`, restated here so a slice does not
9
+ * import the scheduler's package. Returns the function that cancels the timer. */
10
+ export interface RunTimerPort {
11
+ schedule(required: {
12
+ delayMs: number;
13
+ run: () => void;
14
+ }, optional?: {}): () => void;
15
+ }
16
+ /** Where the finalizer reports a failure it has already handled. Call it through `reportSafely`:
17
+ * a host log may throw, and that must not change what happens to the run. */
18
+ export interface RunLogPort {
19
+ /** A rejected checkpoint write (it is retried) or a watch that threw (it is abandoned). */
20
+ error(required: {
21
+ operation: "checkpoint" | "watch";
22
+ runId: string;
23
+ error: unknown;
24
+ }, optional?: {}): void;
25
+ /** The release of a daemon pin or the host's attempt-ended handler failed at a watch's end. */
26
+ warn(required: {
27
+ operation: "attempt-cleanup";
28
+ runId: string;
29
+ error: unknown;
30
+ }, optional?: {}): void;
31
+ }
32
+ /** How a watch ended: the run's terminal status, `interrupted` when the watch handed the run to
33
+ * recovery or gave it up as unproven, `abandoned` when the watch itself failed. */
34
+ export type RunWatchOutcome = "succeeded" | "failed" | "canceled" | "interrupted" | "abandoned";
35
+ /** The last successfully saved progress of a watch (fields of its `Watch` record). */
36
+ export interface SavedCheckpointProgress {
37
+ readonly checkpointedTextCharacters: number;
38
+ readonly checkpointedExtensionEvents: number;
39
+ readonly checkpointedTools: Set<string>;
40
+ }
41
+ /**
42
+ * String characters in a JSON-shaped value: a cheap lower bound of its serialized size, measured
43
+ * without serializing it (the point is to avoid another multi-MB string per checkpoint).
44
+ * @complexity O(nodes) time, O(depth) stack.
45
+ */
46
+ export declare function approximateJsonBytes({ value }: {
47
+ value: unknown;
48
+ }, _optional?: {}): number;
49
+ /** Compare live progress with a successful or attempted checkpoint, including replayed tool ids.
50
+ * @returns Whether unsaved meaningful progress needs a write or trailing timer; no side effects.
51
+ * @complexity O(tool identities) time and space for the comparison. */
52
+ export declare function checkpointGrew({ previous, progress }: {
53
+ previous: ReturnType<typeof checkpointProgress>;
54
+ progress: ReturnType<typeof checkpointProgress>;
55
+ }, _options?: {}): boolean;
56
+ /** Compare with the last successful save, so replay prefixes and unchanged rows need no retry.
57
+ * @complexity O(tool identities) comparison; does not serialize or mutate progress. */
58
+ export declare function hasUnsavedCheckpointGrowth({ watch, progress }: {
59
+ watch: SavedCheckpointProgress;
60
+ progress: ReturnType<typeof checkpointProgress>;
61
+ }, _options?: {}): boolean;
62
+ /** The fields of a host watch record the checkpointer reads and writes, and nothing else. The host
63
+ * record may carry more (stream handles, ids, its own storage cursor); the checkpointer owns
64
+ * only the `checkpoint*` fields, `trailing`, and reads `terminal` and `events`. A write that
65
+ * completes late checks `terminal`; the host cancels `trailing` when it stops the watch. */
66
+ export interface CheckpointWatch {
67
+ readonly runId: string;
68
+ /** The projection source: events received so far on the current connection. */
69
+ readonly events: readonly AgentEvent[];
70
+ /** Saved payload size and start time of the latest checkpoint attempt (writes are best
71
+ * effort). The saved size picks the interval before the next one. */
72
+ checkpointedAt: number;
73
+ checkpointedBytes: number;
74
+ /** Meaningful saved progress: status chatter and replayed tool identities do not qualify. */
75
+ checkpointedTextCharacters: number;
76
+ checkpointedExtensionEvents: number;
77
+ checkpointedTools: Set<string>;
78
+ /** Only one best-effort progress write at a time; later frames are coalesced into the next one. */
79
+ checkpointPending: boolean;
80
+ /** Failed writes cannot be retried by new frames before the backed-off deadline. */
81
+ checkpointRetryAt?: number | undefined;
82
+ /** Stops progress scheduling as soon as the terminal outcome is known, before its durable write. */
83
+ terminal: boolean;
84
+ /** Cancels the trailing checkpoint armed when the interval skipped one. */
85
+ trailing?: (() => void) | undefined;
86
+ }
87
+ /** Every port is required: the checkpointer owns no clock, timer, storage or projection. */
88
+ export interface RunCheckpointerPorts<Watch extends CheckpointWatch, Saved> {
89
+ /** Turns the watch's events into what is saved: the answer text and the event list to store.
90
+ * The size of `events` selects the next interval. Pure; called once per write. */
91
+ readonly project: (required: {
92
+ events: readonly AgentEvent[];
93
+ }, optional?: {}) => {
94
+ content: string;
95
+ events: Saved;
96
+ };
97
+ /** One write on the host's own storage. Resolves `false` for a fenced or unchanged row (no retry),
98
+ * rejects for a storage failure (backed-off retry). The host binds its own cursor on the watch. */
99
+ readonly ledger: {
100
+ checkpoint(required: {
101
+ watch: Watch;
102
+ content: string;
103
+ events: Saved;
104
+ }, optional?: {}): Promise<boolean>;
105
+ };
106
+ readonly now: () => number;
107
+ /** The trailing and retry timer. It is separate from the deadline timers because the host does
108
+ * not let it keep the process alive: a quiet run must not hold an idle site open. */
109
+ readonly checkpointTimers: RunTimerPort;
110
+ readonly log: Pick<RunLogPort, "error">;
111
+ /** Override the size-based interval between in-flight checkpoints; tests pass 0. */
112
+ readonly checkpointIntervalMs: number | undefined;
113
+ }
114
+ export interface RunCheckpointer<Watch extends CheckpointWatch> {
115
+ /** Call after every frame that did not end the run. Never blocks frame consumption. */
116
+ onFrame(required: {
117
+ watch: Watch;
118
+ }, optional?: {}): void;
119
+ }
120
+ /** Instance-owned: the returned checkpointer keeps no state beyond the watches it is given.
121
+ * @complexity O(1) to build; each frame costs what `checkpoint` documents. */
122
+ export declare function createRunCheckpointer<Watch extends CheckpointWatch, Saved>({ ports }: {
123
+ ports: RunCheckpointerPorts<Watch, Saved>;
124
+ }, _optional?: {}): RunCheckpointer<Watch>;
125
+ /**
126
+ * Runs one report call and contains whatever it throws, or rejects with when the host's reporter
127
+ * turns out to be asynchronous.
128
+ *
129
+ * This is the one place the finalizer drops an error on purpose. The reporter is the only channel
130
+ * its own failure could be reported through, and the alternative is worse: a throw from the log
131
+ * call inside a checkpoint's rejection handler skips the backed-off retry and becomes an unhandled
132
+ * rejection, and a throw from the log call at a watch's end rejects the watch itself.
133
+ * @complexity O(1) beyond the reporter.
134
+ */
135
+ export declare function reportSafely({ report }: {
136
+ report: () => unknown;
137
+ }, _optional?: {}): void;
138
+ /** Releases an events response that will never be read. An unread body stays open, and a run
139
+ * reconnects up to maxReconnects times. Not awaited: a body that never finishes cancelling must
140
+ * not stall the watch. A failed cancel has nothing left to release.
141
+ * @complexity O(1); starts one cancel and returns. */
142
+ export declare function releaseUnreadBody({ response }: {
143
+ response: Response;
144
+ }, _optional?: {}): void;
145
+ //# sourceMappingURL=run-finalizer.d.ts.map
@@ -0,0 +1,171 @@
1
+ import { observed } from "@jini-ai/core/errors/idioms";
2
+ import { checkpointIntervalMs, checkpointProgress } from "../checkpoint-interval.js";
3
+ /**
4
+ * String characters in a JSON-shaped value: a cheap lower bound of its serialized size, measured
5
+ * without serializing it (the point is to avoid another multi-MB string per checkpoint).
6
+ * @complexity O(nodes) time, O(depth) stack.
7
+ */
8
+ export function approximateJsonBytes({ value }, _optional = {}) {
9
+ if (typeof value === "string")
10
+ return value.length;
11
+ if (value === null || typeof value !== "object")
12
+ return 1;
13
+ let total = 0;
14
+ for (const item of Array.isArray(value) ? value : Object.values(value))
15
+ total += approximateJsonBytes({ value: item });
16
+ return total;
17
+ }
18
+ /** Compare live progress with a successful or attempted checkpoint, including replayed tool ids.
19
+ * @returns Whether unsaved meaningful progress needs a write or trailing timer; no side effects.
20
+ * @complexity O(tool identities) time and space for the comparison. */
21
+ export function checkpointGrew({ previous, progress }, _options = {}) {
22
+ return progress.textCharacters > previous.textCharacters ||
23
+ progress.extensionEvents > previous.extensionEvents ||
24
+ [...progress.tools].some((key) => !previous.tools.has(key));
25
+ }
26
+ /** Compare with the last successful save, so replay prefixes and unchanged rows need no retry.
27
+ * @complexity O(tool identities) comparison; does not serialize or mutate progress. */
28
+ export function hasUnsavedCheckpointGrowth({ watch, progress }, _options = {}) {
29
+ return checkpointGrew({ progress, previous: {
30
+ textCharacters: watch.checkpointedTextCharacters,
31
+ extensionEvents: watch.checkpointedExtensionEvents,
32
+ tools: watch.checkpointedTools,
33
+ } });
34
+ }
35
+ function clearTrailing({ watch }, _options = {}) {
36
+ watch.trailing?.();
37
+ watch.trailing = undefined;
38
+ }
39
+ /** One cancelable timer owns skipped frames and failed-write retries. Its callback reuses the
40
+ * terminal, pending-write and unsaved-growth guards, including callbacks queued before cleanup.
41
+ * @complexity O(1) time and space; replaces at most one timer per watch. */
42
+ function scheduleCheckpoint({ ports, watch, delayMs }, _options = {}) {
43
+ clearTrailing({ watch });
44
+ watch.trailing = ports.checkpointTimers.schedule({ delayMs, run: () => {
45
+ watch.trailing = undefined;
46
+ void checkpoint({ ports, watch });
47
+ } });
48
+ }
49
+ /** Failed storage writes retry during quiet tool/approval waits, at most once per interval and
50
+ * never faster than once per second. False (fenced/unchanged) results do not retry.
51
+ * @complexity O(events + tool identities) growth comparison; one timer per watch. */
52
+ function retryCheckpoint({ ports, watch, interval }, _options = {}) {
53
+ if (watch.terminal || !hasUnsavedCheckpointGrowth({ watch, progress: checkpointProgress({ events: watch.events }) }))
54
+ return;
55
+ const delayMs = Math.max(interval, 1_000);
56
+ watch.checkpointRetryAt = ports.now() + delayMs;
57
+ scheduleCheckpoint({ ports, watch, delayMs });
58
+ }
59
+ /**
60
+ * Saves what the run has produced so far, when it has grown since the last save and the interval
61
+ * has passed. Only growth counts: a reconnect replays from event 0, and a checkpoint of the
62
+ * replay's first events would shrink the saved answer.
63
+ *
64
+ * A save the interval skips is not dropped: a trailing checkpoint is armed for the end of the
65
+ * interval. Without it, a run that goes quiet (a long tool call) right after a skipped frame kept
66
+ * its last text and tool-call start in memory only, lost on any stop — a process `exit` flush
67
+ * cannot cover a graceful stop (an `exit` listener cannot await an async write).
68
+ * At most one checkpoint is pending per run. It never blocks frame consumption: otherwise a
69
+ * slow progress write holds an already-buffered `end` behind it, leaving a finished turn running
70
+ * for startup repair to misclassify. Later progress is coalesced when the pending write finishes.
71
+ * Terminal settlement uses the ledger's terminal guard to reject any late checkpoint.
72
+ * The last saved payload selects the shared size-based interval (or an injected host override):
73
+ * a merge fallback still rewrites the projection, so large turns need fewer checkpoints.
74
+ *
75
+ * This function decides; `writeCheckpoint` writes.
76
+ * @complexity O(saved events) per write, with one pending write and one trailing timer per run.
77
+ */
78
+ async function checkpoint({ ports, watch }, _optional = {}) {
79
+ if (watch.terminal || watch.checkpointPending)
80
+ return;
81
+ // Preserve injected host/test overrides while the shared pure policy owns the default cadence.
82
+ const interval = ports.checkpointIntervalMs ?? checkpointIntervalMs({ bytes: watch.checkpointedBytes });
83
+ const wait = Math.max(watch.checkpointedAt + interval, watch.checkpointRetryAt ?? Number.NEGATIVE_INFINITY) - ports.now();
84
+ // An armed timer will consume the latest frames; avoid rescanning them on every delta.
85
+ if (wait > 0 && watch.trailing)
86
+ return;
87
+ const progress = checkpointProgress({ events: watch.events });
88
+ // Completion rechecks for coalesced frames. Do not arm a timer for an unchanged projection:
89
+ // only unsaved growth should start the trailing deadline that protects a quiet run.
90
+ if (!hasUnsavedCheckpointGrowth({ watch, progress }))
91
+ return;
92
+ if (wait > 0) {
93
+ scheduleCheckpoint({ ports, watch, delayMs: wait });
94
+ return;
95
+ }
96
+ await writeCheckpoint({ ports, watch, interval, progress });
97
+ }
98
+ /** The write `checkpoint` decided on: marks it pending, records what was saved, and on completion
99
+ * picks up progress that arrived meanwhile.
100
+ * @complexity O(saved events) for the projection and its size. */
101
+ async function writeCheckpoint({ ports, watch, interval, progress }, _optional = {}) {
102
+ const { content, events } = ports.project({ events: watch.events });
103
+ clearTrailing({ watch });
104
+ watch.checkpointedAt = ports.now();
105
+ watch.checkpointRetryAt = undefined;
106
+ watch.checkpointPending = true;
107
+ // Best effort: a failed checkpoint only loses what a restart would keep; the stream goes on.
108
+ await ports.ledger
109
+ .checkpoint({ watch, content, events })
110
+ .then((written) => {
111
+ if (!written)
112
+ return;
113
+ watch.checkpointedTextCharacters = progress.textCharacters;
114
+ watch.checkpointedExtensionEvents = progress.extensionEvents;
115
+ for (const key of progress.tools)
116
+ watch.checkpointedTools.add(key);
117
+ watch.checkpointedBytes = approximateJsonBytes({ value: events });
118
+ })
119
+ .catch((error) => {
120
+ reportSafely({ report: () => ports.log.error({ operation: "checkpoint", runId: watch.runId, error }) });
121
+ retryCheckpoint({ ports, watch, interval });
122
+ })
123
+ .finally(() => {
124
+ watch.checkpointPending = false;
125
+ // A false result (including a fenced row) or failure leaves the saved baseline behind.
126
+ // Retrying that same attempt here spins at interval 0, or rearms forever at other intervals.
127
+ // Only newer coalesced progress schedules from completion. Rejections alone also arm the
128
+ // backed-off retry above, so quiet runs are protected without resurrecting the spin.
129
+ if (!watch.terminal && checkpointGrew({ previous: progress, progress: checkpointProgress({ events: watch.events }) })) {
130
+ void checkpoint({ ports, watch });
131
+ }
132
+ });
133
+ }
134
+ /** Instance-owned: the returned checkpointer keeps no state beyond the watches it is given.
135
+ * @complexity O(1) to build; each frame costs what `checkpoint` documents. */
136
+ export function createRunCheckpointer({ ports }, _optional = {}) {
137
+ return { onFrame: ({ watch }, _options = {}) => { void checkpoint({ ports, watch }); } };
138
+ }
139
+ // ---------------------------------------------------------------------------------------------
140
+ // Calls a host reporter (a log or span port) so that its own failure cannot change what the
141
+ // run finalizer does next.
142
+ // ---------------------------------------------------------------------------------------------
143
+ /**
144
+ * Runs one report call and contains whatever it throws, or rejects with when the host's reporter
145
+ * turns out to be asynchronous.
146
+ *
147
+ * This is the one place the finalizer drops an error on purpose. The reporter is the only channel
148
+ * its own failure could be reported through, and the alternative is worse: a throw from the log
149
+ * call inside a checkpoint's rejection handler skips the backed-off retry and becomes an unhandled
150
+ * rejection, and a throw from the log call at a watch's end rejects the watch itself.
151
+ * @complexity O(1) beyond the reporter.
152
+ */
153
+ export function reportSafely({ report }, _optional = {}) {
154
+ // The executor runs `report` synchronously and turns a synchronous throw into the same rejection
155
+ // an asynchronous reporter produces, so one handler contains both.
156
+ // Nothing to do with a failure, and nowhere left to say so: see the comment above.
157
+ observed({ promise: new Promise((resolve) => { resolve(report()); }) });
158
+ }
159
+ // ---------------------------------------------------------------------------------------------
160
+ // Unread events bodies.
161
+ // ---------------------------------------------------------------------------------------------
162
+ /** Releases an events response that will never be read. An unread body stays open, and a run
163
+ * reconnects up to maxReconnects times. Not awaited: a body that never finishes cancelling must
164
+ * not stall the watch. A failed cancel has nothing left to release.
165
+ * @complexity O(1); starts one cancel and returns. */
166
+ export function releaseUnreadBody({ response }, _optional = {}) {
167
+ const cancelling = response.body?.cancel();
168
+ if (cancelling !== undefined)
169
+ observed({ promise: cancelling });
170
+ }
171
+ //# sourceMappingURL=run-finalizer.js.map