@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
@@ -0,0 +1,200 @@
1
+ /** One-use, host-owned confirmation handoff. No route, authentication or run I/O lives here. */
2
+ import { EventType } from '@ag-ui/core';
3
+ import { RunAgentInputSchema } from '@ag-ui/core/schemas';
4
+ import { MCP_UI_ACTION_PLAN_META_KEY, MCP_UI_EXPIRES_AT_META_KEY } from '@jini-ai/protocol/mcp-ui';
5
+ import { SURFACE_EXCHANGE_META } from '../surface-recovery.js';
6
+ export function confirmationInterrupt({ threadId, runId, interrupt }, _optional = {}) {
7
+ return { type: EventType.RUN_FINISHED, threadId, runId,
8
+ outcome: { type: 'interrupt', interrupts: [{ ...interrupt, reason: 'confirmation' }] } };
9
+ }
10
+ function readResume(input) {
11
+ const parsed = RunAgentInputSchema.safeParse(input);
12
+ if (!parsed.success || parsed.data.resume?.length !== 1)
13
+ return undefined;
14
+ const { threadId, parentRunId, runId, resume } = parsed.data;
15
+ return { threadId, parentRunId: parentRunId ?? undefined, runId, answer: resume[0] };
16
+ }
17
+ function decisionFor(answer) {
18
+ if (answer.status === 'cancelled')
19
+ return 'cancelled';
20
+ if (answer.payload === 'allow')
21
+ return 'allow';
22
+ if (answer.payload === 'deny' || answer.payload === 'dismissed')
23
+ return 'deny';
24
+ return undefined;
25
+ }
26
+ /** Legacy readers treat dismissed and cancelled answers as denials. */
27
+ export function readConfirmationResume({ input, threadId, runId, interruptId }, _optional = {}) {
28
+ const resume = readResume(input);
29
+ if (!resume || resume.threadId !== threadId || resume.parentRunId !== runId || resume.answer.interruptId !== interruptId)
30
+ return undefined;
31
+ const decision = decisionFor(resume.answer);
32
+ return decision ? { decision: decision === 'cancelled' ? 'deny' : decision } : undefined;
33
+ }
34
+ function createPauseTable({ caps, nowMs, onExpire }) {
35
+ const records = new Map();
36
+ function take(slot) {
37
+ if (records.get(slot.entry.interruptId) !== slot)
38
+ return undefined;
39
+ records.delete(slot.entry.interruptId);
40
+ slot.cancelTimer?.();
41
+ return slot.entry;
42
+ }
43
+ function expire(slot) {
44
+ if (slot.entry.expiresAtMs <= nowMs() && take(slot))
45
+ onExpire(slot.entry);
46
+ }
47
+ return {
48
+ park(entry) {
49
+ let scoped = 0;
50
+ for (const slot of [...records.values()])
51
+ expire(slot);
52
+ for (const slot of records.values())
53
+ if (slot.entry.scopeKey === entry.scopeKey)
54
+ scoped++;
55
+ if (entry.expiresAtMs <= nowMs() || records.has(entry.interruptId))
56
+ return undefined;
57
+ if (records.size >= caps.global || scoped >= caps.perScope)
58
+ return undefined;
59
+ const slot = { entry: { ...entry } };
60
+ records.set(entry.interruptId, slot);
61
+ return slot;
62
+ },
63
+ get(id) { return records.get(id); },
64
+ live(id) {
65
+ const slot = records.get(id);
66
+ if (slot)
67
+ expire(slot);
68
+ return records.get(id);
69
+ },
70
+ all() { return [...records.values()]; },
71
+ take,
72
+ expire,
73
+ };
74
+ }
75
+ function wireId(value, max) {
76
+ return value.trim().length > 0 && value.length <= max;
77
+ }
78
+ function sameAddress(entry, claimant) {
79
+ return entry.ownerKey === claimant.ownerKey && entry.threadId === claimant.threadId && entry.parentRunId === claimant.parentRunId;
80
+ }
81
+ function claimAddress(input, ownerKey, maxWireIdChars) {
82
+ const resume = readResume(input);
83
+ if (!resume?.parentRunId || !ownerKey || resume.runId === resume.parentRunId)
84
+ return undefined;
85
+ const { threadId, parentRunId, runId, answer } = resume;
86
+ if (!wireId(runId, maxWireIdChars) || !wireId(answer.interruptId, maxWireIdChars))
87
+ return undefined;
88
+ const decision = decisionFor(answer);
89
+ return decision ? { ownerKey, threadId, parentRunId, runId, interruptId: answer.interruptId, decision } : undefined;
90
+ }
91
+ function claimResume({ input, ownerKey, maxWireIdChars, table }) {
92
+ const address = claimAddress(input, ownerKey, maxWireIdChars);
93
+ if (!address)
94
+ return undefined;
95
+ const slot = table.live(address.interruptId);
96
+ if (!slot || !sameAddress(slot.entry, address))
97
+ return undefined;
98
+ const entry = table.take(slot);
99
+ return entry ? { entry, runId: address.runId, decision: address.decision } : undefined;
100
+ }
101
+ /** Park typed host state until its verified owner claims it, or one abandonment path takes it. */
102
+ export function createAgUiResumeRegistry({ caps, nowMs, schedule, onAbandon }, { maxWireIdChars = 128 } = {}) {
103
+ const table = createPauseTable({ caps, nowMs, onExpire: entry => onAbandon({ entry, reason: 'expired' }, {}) });
104
+ let closed = false;
105
+ const abandon = (slot, reason) => {
106
+ const entry = slot && table.take(slot);
107
+ if (!entry)
108
+ return false;
109
+ onAbandon({ entry, reason }, {});
110
+ return true;
111
+ };
112
+ const registry = {
113
+ park(entry, _optional = {}) {
114
+ if (closed || !entry.ownerKey || !Number.isFinite(entry.expiresAtMs) || !wireId(entry.interruptId, maxWireIdChars))
115
+ return false;
116
+ const slot = table.park(entry);
117
+ if (!slot)
118
+ return false;
119
+ const cancelTimer = schedule({ delayMs: Math.max(0, entry.expiresAtMs - nowMs()), callback: () => table.expire(slot) }, {});
120
+ if (table.get(entry.interruptId) === slot)
121
+ slot.cancelTimer = cancelTimer;
122
+ else
123
+ cancelTimer();
124
+ return true;
125
+ },
126
+ claim({ input, ownerKey }, _optional = {}) {
127
+ return claimResume({ input, ownerKey, maxWireIdChars, table });
128
+ },
129
+ abandon({ interruptId, reason }, _optional = {}) { return abandon(table.get(interruptId), reason); },
130
+ abandonWhere({ matches, reason }, _optional = {}) {
131
+ let count = 0;
132
+ for (const slot of table.all())
133
+ if (matches(slot.entry) && abandon(slot, reason))
134
+ count++;
135
+ return count;
136
+ },
137
+ shutdown(_required, _optional = {}) {
138
+ closed = true;
139
+ registry.abandonWhere({ reason: 'shutdown', matches: () => true });
140
+ },
141
+ };
142
+ return registry;
143
+ }
144
+ /** Preserve the original untimed store interface over the same one-use pause table. */
145
+ export function createAgUiPauseStore({ caps, nowMs }, _optional = {}) {
146
+ const table = createPauseTable({
147
+ caps, nowMs, onExpire: () => { },
148
+ });
149
+ return {
150
+ park(entry, _optional = {}) {
151
+ return !!table.park({ expiresAtMs: entry.abandonAtMs, scopeKey: entry.scopeKey, interruptId: entry.interruptId, legacy: { ...entry } });
152
+ },
153
+ claim({ owner, threadId, runId, interruptId }, _optional = {}) {
154
+ const slot = table.live(interruptId);
155
+ const entry = slot?.entry.legacy;
156
+ if (!slot || !entry || entry.owner !== owner || entry.threadId !== threadId || entry.runId !== runId)
157
+ return undefined;
158
+ return table.take(slot)?.legacy;
159
+ },
160
+ remove({ interruptId }, _optional = {}) {
161
+ const slot = table.get(interruptId);
162
+ return !!slot && !!table.take(slot);
163
+ },
164
+ };
165
+ }
166
+ function record(value) {
167
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
168
+ }
169
+ function cardText(value) {
170
+ return typeof value === 'string' && value.length > 0 && value.length <= 512;
171
+ }
172
+ function hasConfirmationPair(actions) {
173
+ if (!Array.isArray(actions))
174
+ return false;
175
+ const ids = actions.map((action) => record(action)?.id);
176
+ return ids.includes('confirm') && ids.includes('cancel');
177
+ }
178
+ function cardMeta(value) {
179
+ return record(record(record(value)?.resource)?._meta);
180
+ }
181
+ function approvalFromMeta(meta, fallbackMessage) {
182
+ const exchange = record(meta[SURFACE_EXCHANGE_META]);
183
+ const plan = record(meta[MCP_UI_ACTION_PLAN_META_KEY]);
184
+ if (!exchange || !plan || !hasConfirmationPair(plan.actions))
185
+ return undefined;
186
+ const { exchangeId, toolId } = exchange;
187
+ if (!cardText(exchangeId) || !cardText(toolId))
188
+ return undefined;
189
+ const card = { exchangeId, toolId, message: cardText(plan.title) ? plan.title : fallbackMessage };
190
+ const expiresAtMs = meta[MCP_UI_EXPIRES_AT_META_KEY];
191
+ return typeof expiresAtMs === 'number' && Number.isFinite(expiresAtMs) ? { ...card, expiresAtMs } : card;
192
+ }
193
+ /** Identify only MCP-UI exchange cards with both confirmation actions. Other cards stay ordinary. */
194
+ export function readAgUiApprovalCard({ event, extensionPrefix, fallbackMessage }, _optional = {}) {
195
+ if (event.type !== EventType.CUSTOM || event.name !== `${extensionPrefix}mcp-ui`)
196
+ return undefined;
197
+ const meta = cardMeta(event.value);
198
+ return meta ? approvalFromMeta(meta, fallbackMessage) : undefined;
199
+ }
200
+ //# sourceMappingURL=resume.js.map
@@ -50,4 +50,27 @@ export declare function resolveAgUiRunInput({ body, maxHistoryMessages, ids }: {
50
50
  maxHistoryMessages: number;
51
51
  ids: AgUiRunIdPort;
52
52
  }, _optional?: Record<string, never>): AgUiRunInput | null;
53
+ declare const LAUNCH_KEYS: readonly ["attachmentIds", "pluginRefIds", "model", "reasoning", "pageContext", "folders", "agentPluginState"];
54
+ type LaunchKey = typeof LAUNCH_KEYS[number];
55
+ export interface AgUiLaunchFields<PageContext> {
56
+ readonly attachmentIds?: readonly string[];
57
+ readonly pluginRefIds?: readonly string[];
58
+ readonly model?: string;
59
+ readonly reasoning?: string;
60
+ readonly pageContext?: PageContext | undefined;
61
+ readonly folders?: unknown;
62
+ readonly agentPluginState?: unknown;
63
+ }
64
+ /** Put only portable launch fields on the durable wire, without copying authority. */
65
+ export declare function projectAgUiLaunchFields({ contextRef }: {
66
+ contextRef: Record<string, unknown>;
67
+ }, _optional?: Record<string, never>): Partial<Record<LaunchKey, unknown>>;
68
+ /** Read and bound launch fields while leaving page-context admission to the host. */
69
+ export declare function readAgUiLaunchFields<PageContext>({ durable, readPageContext }: {
70
+ durable: unknown;
71
+ readPageContext: (required: {
72
+ value: unknown;
73
+ }) => PageContext | undefined;
74
+ }, _optional?: Record<string, never>): AgUiLaunchFields<PageContext>;
75
+ export {};
53
76
  //# sourceMappingURL=run-input.d.ts.map
@@ -84,4 +84,49 @@ export function resolveAgUiRunInput({ body, maxHistoryMessages, ids }, _optional
84
84
  messages,
85
85
  };
86
86
  }
87
+ const LAUNCH_KEYS = ['attachmentIds', 'pluginRefIds', 'model', 'reasoning', 'pageContext', 'folders', 'agentPluginState'];
88
+ /** Put only portable launch fields on the durable wire, without copying authority. */
89
+ export function projectAgUiLaunchFields({ contextRef }, _optional = {}) {
90
+ const fields = {};
91
+ for (const key of LAUNCH_KEYS) {
92
+ if (Object.hasOwn(contextRef, key) && contextRef[key] !== undefined)
93
+ fields[key] = contextRef[key];
94
+ }
95
+ return fields;
96
+ }
97
+ function boundedString(value, max) {
98
+ return typeof value === 'string' && value.length > 0 && value.length <= max;
99
+ }
100
+ function readLaunchRefs(value) {
101
+ if (!Array.isArray(value))
102
+ return undefined;
103
+ const refs = [];
104
+ for (const ref of value) {
105
+ if (boundedString(ref, 512))
106
+ refs.push(ref);
107
+ if (refs.length === 32)
108
+ break;
109
+ }
110
+ return refs.length ? refs : undefined;
111
+ }
112
+ /** Read and bound launch fields while leaving page-context admission to the host. */
113
+ export function readAgUiLaunchFields({ durable, readPageContext }, _optional = {}) {
114
+ if (typeof durable !== 'object' || durable === null)
115
+ return {};
116
+ const { launch } = durable;
117
+ if (typeof launch !== 'object' || launch === null)
118
+ return {};
119
+ const raw = projectAgUiLaunchFields({ contextRef: launch });
120
+ const attachmentIds = readLaunchRefs(raw.attachmentIds);
121
+ const pluginRefIds = readLaunchRefs(raw.pluginRefIds);
122
+ return {
123
+ ...(attachmentIds ? { attachmentIds } : {}),
124
+ ...(pluginRefIds ? { pluginRefIds } : {}),
125
+ ...(boundedString(raw.model, 200) ? { model: raw.model } : {}),
126
+ ...(boundedString(raw.reasoning, 200) ? { reasoning: raw.reasoning } : {}),
127
+ pageContext: readPageContext({ value: raw.pageContext }),
128
+ folders: raw.folders,
129
+ agentPluginState: raw.agentPluginState,
130
+ };
131
+ }
87
132
  //# sourceMappingURL=run-input.js.map
@@ -0,0 +1,69 @@
1
+ /** Framework-free output ports for one AG-UI delivery segment. The host owns HTTP. */
2
+ import { type AGUIEvent, type Interrupt } from '@ag-ui/core';
3
+ import { type AgUiEvent, type CustomEventNames, type EventIdGenerator } from './event-projection.js';
4
+ export interface AgUiSseEncoder {
5
+ getContentType(): string;
6
+ encodeSSE(event: AGUIEvent): string;
7
+ }
8
+ export interface AgUiSseWriter {
9
+ readonly contentType: string;
10
+ writeEvent(required: {
11
+ event: AGUIEvent;
12
+ }, optional?: Record<string, never>): void;
13
+ }
14
+ /** Bind the official SSE encoder to an injected sink without adding named SSE events. */
15
+ export declare function createAgUiSseWriter({ encoder, write }: {
16
+ encoder: AgUiSseEncoder;
17
+ write: (required: {
18
+ chunk: string;
19
+ }, optional: Record<string, never>) => void;
20
+ }, _optional?: Record<string, never>): AgUiSseWriter;
21
+ export type AgUiSegmentOutcome = {
22
+ kind: 'ok';
23
+ reason: string;
24
+ } | {
25
+ kind: 'error';
26
+ message: string;
27
+ code?: string;
28
+ };
29
+ export interface AgUiTextSegment {
30
+ start(required: Record<string, never>, optional?: Record<string, never>): void;
31
+ text(required: {
32
+ delta: string;
33
+ }, optional?: Record<string, never>): void;
34
+ custom(required: {
35
+ name: string;
36
+ value: unknown;
37
+ }, optional?: Record<string, never>): void;
38
+ toolCall(required: {
39
+ toolCallId: string;
40
+ toolCallName: string;
41
+ args: string;
42
+ }, optional?: Record<string, never>): void;
43
+ finish(required: {
44
+ outcome: AgUiSegmentOutcome;
45
+ }, optional?: Record<string, never>): void;
46
+ interrupt(required: {
47
+ interrupt: Interrupt;
48
+ }, optional?: Record<string, never>): void;
49
+ settle(required: Record<string, never>, optional?: Record<string, never>): void;
50
+ }
51
+ interface TextSegmentInput {
52
+ threadId: string;
53
+ runId: string;
54
+ ids: EventIdGenerator;
55
+ customEventNames: CustomEventNames;
56
+ writeEvent: (required: {
57
+ event: AgUiEvent;
58
+ }, optional: Record<string, never>) => void;
59
+ copy: {
60
+ noReply: string;
61
+ interrupted: string;
62
+ };
63
+ }
64
+ /** Emit one ordered text/tool segment with at most one terminal and no whitespace-only success. */
65
+ export declare function createAgUiTextSegment(required: TextSegmentInput, { parentRunId }?: {
66
+ parentRunId?: string;
67
+ }): AgUiTextSegment;
68
+ export {};
69
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1,71 @@
1
+ /** Framework-free output ports for one AG-UI delivery segment. The host owns HTTP. */
2
+ import { EventType } from '@ag-ui/core';
3
+ import { closeAgUiRun, createAgUiTranslationState, translateAgentEventToAgUi } from './event-projection.js';
4
+ import { confirmationInterrupt } from './resume.js';
5
+ /** Bind the official SSE encoder to an injected sink without adding named SSE events. */
6
+ export function createAgUiSseWriter({ encoder, write }, _optional = {}) {
7
+ return {
8
+ contentType: encoder.getContentType(),
9
+ writeEvent({ event }, _optional = {}) { write({ chunk: encoder.encodeSSE(event) }, {}); },
10
+ };
11
+ }
12
+ function finishEvent({ outcome, visible, required }) {
13
+ if (outcome.kind === 'error') {
14
+ return { type: EventType.RUN_ERROR, message: outcome.message, ...(outcome.code ? { code: outcome.code } : {}) };
15
+ }
16
+ if (!visible)
17
+ return { type: EventType.RUN_ERROR, message: required.copy.noReply, code: 'NO_REPLY' };
18
+ return { type: EventType.RUN_FINISHED, threadId: required.threadId, runId: required.runId, result: { reason: outcome.reason } };
19
+ }
20
+ /** Emit one ordered text/tool segment with at most one terminal and no whitespace-only success. */
21
+ export function createAgUiTextSegment(required, { parentRunId } = {}) {
22
+ const { threadId, runId, ids, customEventNames, writeEvent, copy } = required;
23
+ const state = createAgUiTranslationState({ ids, customEventNames });
24
+ let terminal = false;
25
+ let started = false;
26
+ let visible = false;
27
+ let leading = '';
28
+ const emit = (events) => { for (const event of events)
29
+ writeEvent({ event }, {}); };
30
+ const terminate = (event) => {
31
+ if (terminal)
32
+ return;
33
+ terminal = true;
34
+ emit([...closeAgUiRun({ state }), event]);
35
+ };
36
+ return {
37
+ start(_required, _optional = {}) {
38
+ if (started || terminal)
39
+ return;
40
+ started = true;
41
+ writeEvent({ event: { type: EventType.RUN_STARTED, threadId, runId, ...(parentRunId === undefined ? {} : { parentRunId }) } }, {});
42
+ },
43
+ text({ delta }, _optional = {}) {
44
+ if (terminal)
45
+ return;
46
+ if (!visible && !delta.trim()) {
47
+ leading += delta;
48
+ return;
49
+ }
50
+ const text = leading + delta;
51
+ leading = '';
52
+ visible = true;
53
+ emit(translateAgentEventToAgUi({ event: { kind: 'text', text }, state }));
54
+ },
55
+ custom({ name, value }, _optional = {}) {
56
+ if (!terminal)
57
+ writeEvent({ event: { type: EventType.CUSTOM, name, value } }, {});
58
+ },
59
+ toolCall({ toolCallId, toolCallName, args }, _optional = {}) {
60
+ if (terminal)
61
+ return;
62
+ const parentMessageId = state.openTextMessageId;
63
+ emit([{ type: EventType.TOOL_CALL_START, toolCallId, toolCallName, ...(parentMessageId ? { parentMessageId } : {}) },
64
+ { type: EventType.TOOL_CALL_ARGS, toolCallId, delta: args }, { type: EventType.TOOL_CALL_END, toolCallId }]);
65
+ },
66
+ finish({ outcome }, _optional = {}) { terminate(finishEvent({ outcome, visible, required })); },
67
+ interrupt({ interrupt }, _optional = {}) { terminate(confirmationInterrupt({ threadId, runId, interrupt })); },
68
+ settle(_required, _optional = {}) { terminate({ type: EventType.RUN_ERROR, message: copy.interrupted, code: 'INTERRUPTED' }); },
69
+ };
70
+ }
71
+ //# sourceMappingURL=server.js.map
@@ -1,3 +1,4 @@
1
+ import { orFallbackSync } from '@jini-ai/core/errors/idioms';
1
2
  export const AGENT_PLUGIN_STATE_CHANGED = 'jini:agent-plugin-state';
2
3
  const key = (conversationId) => `jini:chat-agent-plugins:${conversationId}`;
3
4
  function browserStorage() {
@@ -19,22 +20,23 @@ function usableChatState({ value }) {
19
20
  }
20
21
  /** Corrupt/blocked storage permits a fresh question, as clearing localStorage does. */
21
22
  export function readAgentPluginChatState({ conversationId }, { storage = browserStorage() } = {}) {
22
- try {
23
- const state = usableChatState({ value: JSON.parse(storage?.getItem(key(conversationId)) ?? 'null') });
24
- if (state)
25
- return state;
26
- }
27
- catch { /* Private browsing/corrupt rows behave as a new chat decision. */ }
28
- return { decision: null, excluded: [] };
23
+ /* Private browsing/corrupt rows behave as a new chat decision. */
24
+ return orFallbackSync({
25
+ work: () => usableChatState({ value: JSON.parse(storage?.getItem(key(conversationId)) ?? 'null') }),
26
+ fallback: null,
27
+ step: 'Read stored chat plugin state',
28
+ }) ?? { decision: null, excluded: [] };
29
29
  }
30
30
  /** Persist only decision/exclusions. Existing exclusions win over an in-flight server response. */
31
31
  export function writeAgentPluginChatState({ conversationId, state }, { storage = browserStorage() } = {}) {
32
32
  const current = readAgentPluginChatState({ conversationId }, { storage });
33
33
  const next = { decision: state.decision, excluded: [...new Set([...current.excluded, ...state.excluded])] };
34
- try {
35
- storage?.setItem(key(conversationId), JSON.stringify(next));
36
- }
37
- catch { /* Session can continue without persistence. */ }
34
+ /* Session can continue without persistence. */
35
+ orFallbackSync({
36
+ work: () => storage?.setItem(key(conversationId), JSON.stringify(next)),
37
+ fallback: undefined,
38
+ step: 'Save chat plugin state',
39
+ });
38
40
  if (typeof window !== 'undefined')
39
41
  window.dispatchEvent(new CustomEvent(AGENT_PLUGIN_STATE_CHANGED, { detail: { conversationId, state: next } }));
40
42
  }
@@ -0,0 +1,113 @@
1
+ /** Live-only confirmation correlation for one logical turn across AG-UI delivery segments. */
2
+ import { type RunAgentInput } from "@ag-ui/core";
3
+ import type { RunHandlers } from "../transport.js";
4
+ import type { AgUiRunClient } from "./ag-ui-transport.js";
5
+ import type { McpUiToolCallHandler } from "@jini-ai/protocol/mcp-ui";
6
+ type Empty = Record<string, never>;
7
+ export interface AgUiApprovalPoster {
8
+ answersExchange(required: {
9
+ exchangeId: string;
10
+ }, optional?: Empty): boolean;
11
+ answer(required: {
12
+ exchangeId: string;
13
+ allow: boolean;
14
+ }, optional?: Empty): Promise<boolean>;
15
+ }
16
+ export interface AgUiApprovalRelay extends AgUiApprovalPoster {
17
+ beginTurn(required: {
18
+ threadId: string;
19
+ handlers: RunHandlers;
20
+ signal: AbortSignal;
21
+ }, optional?: {
22
+ segmentRunId?: string;
23
+ onStop?: () => void;
24
+ cancelSignal?: AbortSignal;
25
+ stopResume?: (runId: string) => void;
26
+ }): RunHandlers;
27
+ observe(required: {
28
+ threadId: string;
29
+ event: unknown;
30
+ input: RunAgentInput;
31
+ }, optional?: Empty): void;
32
+ bindRun(required: {
33
+ threadId: string;
34
+ runId: string;
35
+ }, optional?: Empty): void;
36
+ /** Revoke live answer rights and return the resume segment that also needs to stop. */
37
+ release(required: {
38
+ runId: string;
39
+ }, optional?: Empty): string | undefined;
40
+ }
41
+ interface ApprovalRelayLifecycle extends AgUiApprovalRelay {
42
+ /** Bind the start ID that the underlying client actually acknowledged. */
43
+ confirmStart(required: {
44
+ segmentRunId: string;
45
+ runId: string;
46
+ }, optional?: Empty): void;
47
+ /** Bind a resume before subscribing, so Stop can reach a segment waiting for its first frame. */
48
+ bindResume(required: {
49
+ input: RunAgentInput;
50
+ }, optional?: Empty): void;
51
+ /** Clear a rejected start without delivering a transcript or replacing a newer turn. */
52
+ discard(required: {
53
+ runId: string;
54
+ }, optional?: Empty): void;
55
+ }
56
+ export interface AgUiApprovalRelayPorts {
57
+ resume: AgUiRunClient["resumeAgUiRun"];
58
+ copy: {
59
+ expired: string;
60
+ unsent: string;
61
+ };
62
+ isAccepted(required: {
63
+ runId: string;
64
+ }, optional: Empty): boolean;
65
+ }
66
+ export interface AgUiConfirmationInterrupt {
67
+ threadId: string;
68
+ parentRunId: string;
69
+ interruptId: string;
70
+ message?: string;
71
+ exchangeId?: string;
72
+ }
73
+ /** Read a validated confirmation from an AG-UI terminal, optionally requiring exchange metadata. */
74
+ export declare function readAgUiConfirmationInterrupt({ event }: {
75
+ event: unknown;
76
+ }, { requireExchange }?: {
77
+ requireExchange?: boolean;
78
+ }): AgUiConfirmationInterrupt | undefined;
79
+ type ResumeDecision = "allow" | "deny" | "cancelled";
80
+ /** Address one paused run with a fresh segment ID and no history or tool registrations. */
81
+ export declare function createAgUiResumeInput({ threadId, runId, parentRunId, interruptId, decision }: {
82
+ threadId: string;
83
+ runId: string;
84
+ parentRunId: string;
85
+ interruptId: string;
86
+ decision: ResumeDecision;
87
+ }, _optional?: Empty): RunAgentInput;
88
+ interface AnswerOnce<Choice, Result> {
89
+ answer(required: {
90
+ choice: Choice;
91
+ }, optional?: Empty): Promise<Result>;
92
+ }
93
+ /** Record the first choice before invoking I/O and give every caller the same promise. */
94
+ export declare function createAgUiAnswerOnce<Choice, Result>({ submit }: {
95
+ submit: (required: {
96
+ choice: Choice;
97
+ }, optional: Empty) => Promise<Result>;
98
+ }, _optional?: Empty): AnswerOnce<Choice, Result>;
99
+ /** Correlate live approval cards without storing them in the conversation transcript. */
100
+ export declare function createAgUiApprovalRelay({ ports }: {
101
+ ports: AgUiApprovalRelayPorts;
102
+ }, _optional?: Empty): ApprovalRelayLifecycle;
103
+ /** Keep ordinary MCP-UI calls on their original route. Only a live exchange can resume AG-UI. */
104
+ export declare function routeApprovalToolCall({ approvals, fallback, copy }: {
105
+ approvals: AgUiApprovalPoster;
106
+ fallback: McpUiToolCallHandler;
107
+ copy: {
108
+ sent: string;
109
+ notSent: string;
110
+ };
111
+ }, _optional?: Empty): McpUiToolCallHandler;
112
+ export {};
113
+ //# sourceMappingURL=ag-ui-approval-relay.d.ts.map