@syntrologie/adapt-chatbot 2.55.0 → 2.56.0

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 (76) hide show
  1. package/dist/AdaptiveChatBar.d.ts +18 -0
  2. package/dist/AdaptiveChatBar.d.ts.map +1 -1
  3. package/dist/AdaptiveChatBar.interleave.test.d.ts +9 -0
  4. package/dist/AdaptiveChatBar.interleave.test.d.ts.map +1 -0
  5. package/dist/AdaptiveChatBar.js +4 -4
  6. package/dist/AdaptiveChatBarMountable.d.ts +28 -17
  7. package/dist/AdaptiveChatBarMountable.d.ts.map +1 -1
  8. package/dist/AdaptiveChatTrail.js +3 -3
  9. package/dist/AdaptiveChipsStrip.d.ts +20 -20
  10. package/dist/AdaptiveChipsStrip.js +3 -3
  11. package/dist/ChatAssistantLit.d.ts +5 -3
  12. package/dist/ChatAssistantLit.d.ts.map +1 -1
  13. package/dist/ChatAssistantLit.js +5 -4
  14. package/dist/ChatTransport.d.ts +10 -5
  15. package/dist/ChatTransport.d.ts.map +1 -1
  16. package/dist/Turnstile.d.ts +18 -0
  17. package/dist/Turnstile.d.ts.map +1 -1
  18. package/dist/cdn.d.ts +1 -0
  19. package/dist/cdn.d.ts.map +1 -1
  20. package/dist/chunk-23E6WZOO.js +882 -0
  21. package/dist/chunk-23E6WZOO.js.map +7 -0
  22. package/dist/{chunk-57MPLQOL.js → chunk-7QXC475Y.js} +400 -935
  23. package/dist/{chunk-57MPLQOL.js.map → chunk-7QXC475Y.js.map} +4 -4
  24. package/dist/{chunk-TZA7572J.js → chunk-GN7Z5IVP.js} +2 -2
  25. package/dist/chunk-LY5AGXVD.js +21 -0
  26. package/dist/{chunk-ETDHHQS3.js → chunk-NMYFYMJI.js} +12 -12
  27. package/dist/{chunk-ETDHHQS3.js.map → chunk-NMYFYMJI.js.map} +1 -1
  28. package/dist/{chunk-LJEPZI6Y.js → chunk-WQIDXGGS.js} +2 -2
  29. package/dist/{chunk-VFWA5W56.js → chunk-XPUHW2YO.js} +44 -7
  30. package/dist/chunk-XPUHW2YO.js.map +7 -0
  31. package/dist/chunk-Z3YR4JFE.js +4702 -0
  32. package/dist/chunk-Z3YR4JFE.js.map +7 -0
  33. package/dist/editor-lit.js +1 -1
  34. package/dist/element-session.d.ts +3 -0
  35. package/dist/element-session.d.ts.map +1 -0
  36. package/dist/element-session.js +9 -0
  37. package/dist/element-session.js.map +7 -0
  38. package/dist/elements/ElementInstanceStore.d.ts +15 -1
  39. package/dist/elements/ElementInstanceStore.d.ts.map +1 -1
  40. package/dist/elements/ElementSessionController.d.ts +37 -0
  41. package/dist/elements/ElementSessionController.d.ts.map +1 -0
  42. package/dist/elements/ElementSessionController.test.d.ts +2 -0
  43. package/dist/elements/ElementSessionController.test.d.ts.map +1 -0
  44. package/dist/elements/TileHandler.d.ts.map +1 -1
  45. package/dist/elements/createElementStore.d.ts +11 -0
  46. package/dist/elements/createElementStore.d.ts.map +1 -0
  47. package/dist/elements/tileLifecycleProps.d.ts +13 -0
  48. package/dist/elements/tileLifecycleProps.d.ts.map +1 -0
  49. package/dist/elements/types.d.ts +7 -0
  50. package/dist/elements/types.d.ts.map +1 -1
  51. package/dist/hostAgentController.d.ts +65 -0
  52. package/dist/hostAgentController.d.ts.map +1 -0
  53. package/dist/hostAgentController.test.d.ts +2 -0
  54. package/dist/hostAgentController.test.d.ts.map +1 -0
  55. package/dist/observer/wire.d.ts +54 -0
  56. package/dist/observer/wire.d.ts.map +1 -0
  57. package/dist/observer/wire.test.d.ts +2 -0
  58. package/dist/observer/wire.test.d.ts.map +1 -0
  59. package/dist/runtime.d.ts +3 -0
  60. package/dist/runtime.d.ts.map +1 -1
  61. package/dist/runtime.js +832 -172
  62. package/dist/runtime.js.map +4 -4
  63. package/dist/schema.d.ts +66 -66
  64. package/dist/schema.d.ts.map +1 -1
  65. package/dist/schema.js +75 -76
  66. package/dist/schema.js.map +3 -3
  67. package/dist/types.d.ts +17 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/package.json +9 -7
  70. package/dist/chunk-NGV35N4T.js +0 -474
  71. package/dist/chunk-NGV35N4T.js.map +0 -7
  72. package/dist/chunk-UVKRO5ER.js +0 -13
  73. package/dist/chunk-VFWA5W56.js.map +0 -7
  74. /package/dist/{chunk-TZA7572J.js.map → chunk-GN7Z5IVP.js.map} +0 -0
  75. /package/dist/{chunk-UVKRO5ER.js.map → chunk-LY5AGXVD.js.map} +0 -0
  76. /package/dist/{chunk-LJEPZI6Y.js.map → chunk-WQIDXGGS.js.map} +0 -0
@@ -1,13 +1,13 @@
1
1
  import {
2
- TILE_MOUNTED_EVENT,
3
- TILE_PATCHED_EVENT,
4
- TILE_REPLAY_REQUEST_EVENT,
5
- TILE_UNMOUNTED_EVENT,
2
+ createElementSessionController
3
+ } from "./chunk-23E6WZOO.js";
4
+ import {
5
+ external_exports,
6
6
  stripMountPlumbing
7
- } from "./chunk-NGV35N4T.js";
7
+ } from "./chunk-Z3YR4JFE.js";
8
8
  import {
9
9
  __export
10
- } from "./chunk-UVKRO5ER.js";
10
+ } from "./chunk-LY5AGXVD.js";
11
11
 
12
12
  // ../../../node_modules/@ag-ui/client/node_modules/uuid/dist/esm-browser/stringify.js
13
13
  var byteToHex = [];
@@ -62,70 +62,69 @@ function v4(options, buf, offset) {
62
62
  var v4_default = v4;
63
63
 
64
64
  // ../../../node_modules/@ag-ui/core/dist/index.mjs
65
- import { z } from "zod";
66
- var FunctionCallSchema = z.object({
67
- name: z.string(),
68
- arguments: z.string()
65
+ var FunctionCallSchema = external_exports.object({
66
+ name: external_exports.string(),
67
+ arguments: external_exports.string()
69
68
  });
70
- var ToolCallSchema = z.object({
71
- id: z.string(),
72
- type: z.literal("function"),
69
+ var ToolCallSchema = external_exports.object({
70
+ id: external_exports.string(),
71
+ type: external_exports.literal("function"),
73
72
  function: FunctionCallSchema,
74
- encryptedValue: z.string().optional()
73
+ encryptedValue: external_exports.string().optional()
75
74
  });
76
- var BaseMessageSchema = z.object({
77
- id: z.string(),
78
- role: z.string(),
79
- content: z.string().optional(),
80
- name: z.string().optional(),
81
- encryptedValue: z.string().optional()
75
+ var BaseMessageSchema = external_exports.object({
76
+ id: external_exports.string(),
77
+ role: external_exports.string(),
78
+ content: external_exports.string().optional(),
79
+ name: external_exports.string().optional(),
80
+ encryptedValue: external_exports.string().optional()
82
81
  });
83
- var TextInputContentSchema = z.object({
84
- type: z.literal("text"),
85
- text: z.string()
82
+ var TextInputContentSchema = external_exports.object({
83
+ type: external_exports.literal("text"),
84
+ text: external_exports.string()
86
85
  });
87
- var InputContentDataSourceSchema = z.object({
88
- type: z.literal("data"),
89
- value: z.string(),
90
- mimeType: z.string()
86
+ var InputContentDataSourceSchema = external_exports.object({
87
+ type: external_exports.literal("data"),
88
+ value: external_exports.string(),
89
+ mimeType: external_exports.string()
91
90
  });
92
- var InputContentUrlSourceSchema = z.object({
93
- type: z.literal("url"),
94
- value: z.string(),
95
- mimeType: z.string().optional()
91
+ var InputContentUrlSourceSchema = external_exports.object({
92
+ type: external_exports.literal("url"),
93
+ value: external_exports.string(),
94
+ mimeType: external_exports.string().optional()
96
95
  });
97
- var InputContentSourceSchema = z.discriminatedUnion("type", [InputContentDataSourceSchema, InputContentUrlSourceSchema]);
98
- var ImageInputContentSchema = z.object({
99
- type: z.literal("image"),
96
+ var InputContentSourceSchema = external_exports.discriminatedUnion("type", [InputContentDataSourceSchema, InputContentUrlSourceSchema]);
97
+ var ImageInputContentSchema = external_exports.object({
98
+ type: external_exports.literal("image"),
100
99
  source: InputContentSourceSchema,
101
- metadata: z.unknown().optional()
100
+ metadata: external_exports.unknown().optional()
102
101
  });
103
- var AudioInputContentSchema = z.object({
104
- type: z.literal("audio"),
102
+ var AudioInputContentSchema = external_exports.object({
103
+ type: external_exports.literal("audio"),
105
104
  source: InputContentSourceSchema,
106
- metadata: z.unknown().optional()
105
+ metadata: external_exports.unknown().optional()
107
106
  });
108
- var VideoInputContentSchema = z.object({
109
- type: z.literal("video"),
107
+ var VideoInputContentSchema = external_exports.object({
108
+ type: external_exports.literal("video"),
110
109
  source: InputContentSourceSchema,
111
- metadata: z.unknown().optional()
110
+ metadata: external_exports.unknown().optional()
112
111
  });
113
- var DocumentInputContentSchema = z.object({
114
- type: z.literal("document"),
112
+ var DocumentInputContentSchema = external_exports.object({
113
+ type: external_exports.literal("document"),
115
114
  source: InputContentSourceSchema,
116
- metadata: z.unknown().optional()
115
+ metadata: external_exports.unknown().optional()
117
116
  });
118
- var LegacyBinaryInputContentObjectSchema = z.object({
119
- type: z.literal("binary"),
120
- mimeType: z.string(),
121
- id: z.string().optional(),
122
- url: z.string().optional(),
123
- data: z.string().optional(),
124
- filename: z.string().optional()
117
+ var LegacyBinaryInputContentObjectSchema = external_exports.object({
118
+ type: external_exports.literal("binary"),
119
+ mimeType: external_exports.string(),
120
+ id: external_exports.string().optional(),
121
+ url: external_exports.string().optional(),
122
+ data: external_exports.string().optional(),
123
+ filename: external_exports.string().optional()
125
124
  });
126
125
  var ensureBinaryPayload = (value, ctx) => {
127
126
  if (!value.id && !value.url && !value.data) ctx.addIssue({
128
- code: z.ZodIssueCode.custom,
127
+ code: external_exports.ZodIssueCode.custom,
129
128
  message: "BinaryInputContent requires at least one of id, url, or data.",
130
129
  path: ["id"]
131
130
  });
@@ -133,7 +132,7 @@ var ensureBinaryPayload = (value, ctx) => {
133
132
  var BinaryInputContentSchema = LegacyBinaryInputContentObjectSchema.superRefine((value, ctx) => {
134
133
  ensureBinaryPayload(value, ctx);
135
134
  });
136
- var InputContentBaseSchema = z.discriminatedUnion("type", [
135
+ var InputContentBaseSchema = external_exports.discriminatedUnion("type", [
137
136
  TextInputContentSchema,
138
137
  ImageInputContentSchema,
139
138
  AudioInputContentSchema,
@@ -145,43 +144,43 @@ var InputContentSchema = InputContentBaseSchema.superRefine((value, ctx) => {
145
144
  if (value.type === "binary") ensureBinaryPayload(value, ctx);
146
145
  });
147
146
  var DeveloperMessageSchema = BaseMessageSchema.extend({
148
- role: z.literal("developer"),
149
- content: z.string()
147
+ role: external_exports.literal("developer"),
148
+ content: external_exports.string()
150
149
  });
151
150
  var SystemMessageSchema = BaseMessageSchema.extend({
152
- role: z.literal("system"),
153
- content: z.string()
151
+ role: external_exports.literal("system"),
152
+ content: external_exports.string()
154
153
  });
155
154
  var AssistantMessageSchema = BaseMessageSchema.extend({
156
- role: z.literal("assistant"),
157
- content: z.string().optional(),
158
- toolCalls: z.array(ToolCallSchema).optional()
155
+ role: external_exports.literal("assistant"),
156
+ content: external_exports.string().optional(),
157
+ toolCalls: external_exports.array(ToolCallSchema).optional()
159
158
  });
160
159
  var UserMessageSchema = BaseMessageSchema.extend({
161
- role: z.literal("user"),
162
- content: z.union([z.string(), z.array(InputContentSchema)])
160
+ role: external_exports.literal("user"),
161
+ content: external_exports.union([external_exports.string(), external_exports.array(InputContentSchema)])
163
162
  });
164
- var ToolMessageSchema = z.object({
165
- id: z.string(),
166
- content: z.string(),
167
- role: z.literal("tool"),
168
- toolCallId: z.string(),
169
- error: z.string().optional(),
170
- encryptedValue: z.string().optional()
163
+ var ToolMessageSchema = external_exports.object({
164
+ id: external_exports.string(),
165
+ content: external_exports.string(),
166
+ role: external_exports.literal("tool"),
167
+ toolCallId: external_exports.string(),
168
+ error: external_exports.string().optional(),
169
+ encryptedValue: external_exports.string().optional()
171
170
  });
172
- var ActivityMessageSchema = z.object({
173
- id: z.string(),
174
- role: z.literal("activity"),
175
- activityType: z.string(),
176
- content: z.record(z.any())
171
+ var ActivityMessageSchema = external_exports.object({
172
+ id: external_exports.string(),
173
+ role: external_exports.literal("activity"),
174
+ activityType: external_exports.string(),
175
+ content: external_exports.record(external_exports.any())
177
176
  });
178
- var ReasoningMessageSchema = z.object({
179
- id: z.string(),
180
- role: z.literal("reasoning"),
181
- content: z.string(),
182
- encryptedValue: z.string().optional()
177
+ var ReasoningMessageSchema = external_exports.object({
178
+ id: external_exports.string(),
179
+ role: external_exports.literal("reasoning"),
180
+ content: external_exports.string(),
181
+ encryptedValue: external_exports.string().optional()
183
182
  });
184
- var MessageSchema = z.discriminatedUnion("role", [
183
+ var MessageSchema = external_exports.discriminatedUnion("role", [
185
184
  DeveloperMessageSchema,
186
185
  SystemMessageSchema,
187
186
  AssistantMessageSchema,
@@ -190,51 +189,51 @@ var MessageSchema = z.discriminatedUnion("role", [
190
189
  ActivityMessageSchema,
191
190
  ReasoningMessageSchema
192
191
  ]);
193
- var RoleSchema = z.union([
194
- z.literal("developer"),
195
- z.literal("system"),
196
- z.literal("assistant"),
197
- z.literal("user"),
198
- z.literal("tool"),
199
- z.literal("activity"),
200
- z.literal("reasoning")
192
+ var RoleSchema = external_exports.union([
193
+ external_exports.literal("developer"),
194
+ external_exports.literal("system"),
195
+ external_exports.literal("assistant"),
196
+ external_exports.literal("user"),
197
+ external_exports.literal("tool"),
198
+ external_exports.literal("activity"),
199
+ external_exports.literal("reasoning")
201
200
  ]);
202
- var ContextSchema = z.object({
203
- description: z.string(),
204
- value: z.string()
201
+ var ContextSchema = external_exports.object({
202
+ description: external_exports.string(),
203
+ value: external_exports.string()
205
204
  });
206
- var ToolSchema = z.object({
207
- name: z.string(),
208
- description: z.string(),
209
- parameters: z.any(),
210
- metadata: z.record(z.any()).optional()
205
+ var ToolSchema = external_exports.object({
206
+ name: external_exports.string(),
207
+ description: external_exports.string(),
208
+ parameters: external_exports.any(),
209
+ metadata: external_exports.record(external_exports.any()).optional()
211
210
  });
212
- var InterruptSchema = z.object({
213
- id: z.string(),
214
- reason: z.string(),
215
- message: z.string().optional(),
216
- toolCallId: z.string().optional(),
217
- responseSchema: z.record(z.any()).optional(),
218
- expiresAt: z.string().optional(),
219
- metadata: z.record(z.any()).optional()
211
+ var InterruptSchema = external_exports.object({
212
+ id: external_exports.string(),
213
+ reason: external_exports.string(),
214
+ message: external_exports.string().optional(),
215
+ toolCallId: external_exports.string().optional(),
216
+ responseSchema: external_exports.record(external_exports.any()).optional(),
217
+ expiresAt: external_exports.string().optional(),
218
+ metadata: external_exports.record(external_exports.any()).optional()
220
219
  });
221
- var ResumeEntrySchema = z.object({
222
- interruptId: z.string(),
223
- status: z.enum(["resolved", "cancelled"]),
224
- payload: z.any().optional()
220
+ var ResumeEntrySchema = external_exports.object({
221
+ interruptId: external_exports.string(),
222
+ status: external_exports.enum(["resolved", "cancelled"]),
223
+ payload: external_exports.any().optional()
225
224
  });
226
- var RunAgentInputSchema = z.object({
227
- threadId: z.string(),
228
- runId: z.string(),
229
- parentRunId: z.string().optional(),
230
- state: z.any(),
231
- messages: z.array(MessageSchema),
232
- tools: z.array(ToolSchema),
233
- context: z.array(ContextSchema),
234
- forwardedProps: z.any(),
235
- resume: z.array(ResumeEntrySchema).optional()
225
+ var RunAgentInputSchema = external_exports.object({
226
+ threadId: external_exports.string(),
227
+ runId: external_exports.string(),
228
+ parentRunId: external_exports.string().optional(),
229
+ state: external_exports.any(),
230
+ messages: external_exports.array(MessageSchema),
231
+ tools: external_exports.array(ToolSchema),
232
+ context: external_exports.array(ContextSchema),
233
+ forwardedProps: external_exports.any(),
234
+ resume: external_exports.array(ResumeEntrySchema).optional()
236
235
  });
237
- var StateSchema = z.any();
236
+ var StateSchema = external_exports.any();
238
237
  var AGUIError = class extends Error {
239
238
  constructor(message) {
240
239
  super(message);
@@ -245,83 +244,83 @@ var AGUIConnectNotImplementedError = class extends AGUIError {
245
244
  super("Connect not implemented. This method is not supported by the current agent.");
246
245
  }
247
246
  };
248
- var SubAgentInfoSchema = z.object({
249
- name: z.string(),
250
- description: z.string().optional()
247
+ var SubAgentInfoSchema = external_exports.object({
248
+ name: external_exports.string(),
249
+ description: external_exports.string().optional()
251
250
  });
252
- var IdentityCapabilitiesSchema = z.object({
253
- name: z.string().optional(),
254
- type: z.string().optional(),
255
- description: z.string().optional(),
256
- version: z.string().optional(),
257
- provider: z.string().optional(),
258
- documentationUrl: z.string().optional(),
259
- metadata: z.record(z.unknown()).optional()
251
+ var IdentityCapabilitiesSchema = external_exports.object({
252
+ name: external_exports.string().optional(),
253
+ type: external_exports.string().optional(),
254
+ description: external_exports.string().optional(),
255
+ version: external_exports.string().optional(),
256
+ provider: external_exports.string().optional(),
257
+ documentationUrl: external_exports.string().optional(),
258
+ metadata: external_exports.record(external_exports.unknown()).optional()
260
259
  });
261
- var TransportCapabilitiesSchema = z.object({
262
- streaming: z.boolean().optional(),
263
- websocket: z.boolean().optional(),
264
- httpBinary: z.boolean().optional(),
265
- pushNotifications: z.boolean().optional(),
266
- resumable: z.boolean().optional()
260
+ var TransportCapabilitiesSchema = external_exports.object({
261
+ streaming: external_exports.boolean().optional(),
262
+ websocket: external_exports.boolean().optional(),
263
+ httpBinary: external_exports.boolean().optional(),
264
+ pushNotifications: external_exports.boolean().optional(),
265
+ resumable: external_exports.boolean().optional()
267
266
  });
268
- var ToolsCapabilitiesSchema = z.object({
269
- supported: z.boolean().optional(),
270
- items: z.array(ToolSchema).optional(),
271
- parallelCalls: z.boolean().optional(),
272
- clientProvided: z.boolean().optional()
267
+ var ToolsCapabilitiesSchema = external_exports.object({
268
+ supported: external_exports.boolean().optional(),
269
+ items: external_exports.array(ToolSchema).optional(),
270
+ parallelCalls: external_exports.boolean().optional(),
271
+ clientProvided: external_exports.boolean().optional()
273
272
  });
274
- var OutputCapabilitiesSchema = z.object({
275
- structuredOutput: z.boolean().optional(),
276
- supportedMimeTypes: z.array(z.string()).optional()
273
+ var OutputCapabilitiesSchema = external_exports.object({
274
+ structuredOutput: external_exports.boolean().optional(),
275
+ supportedMimeTypes: external_exports.array(external_exports.string()).optional()
277
276
  });
278
- var StateCapabilitiesSchema = z.object({
279
- snapshots: z.boolean().optional(),
280
- deltas: z.boolean().optional(),
281
- memory: z.boolean().optional(),
282
- persistentState: z.boolean().optional()
277
+ var StateCapabilitiesSchema = external_exports.object({
278
+ snapshots: external_exports.boolean().optional(),
279
+ deltas: external_exports.boolean().optional(),
280
+ memory: external_exports.boolean().optional(),
281
+ persistentState: external_exports.boolean().optional()
283
282
  });
284
- var MultiAgentCapabilitiesSchema = z.object({
285
- supported: z.boolean().optional(),
286
- delegation: z.boolean().optional(),
287
- handoffs: z.boolean().optional(),
288
- subAgents: z.array(SubAgentInfoSchema).optional()
283
+ var MultiAgentCapabilitiesSchema = external_exports.object({
284
+ supported: external_exports.boolean().optional(),
285
+ delegation: external_exports.boolean().optional(),
286
+ handoffs: external_exports.boolean().optional(),
287
+ subAgents: external_exports.array(SubAgentInfoSchema).optional()
289
288
  });
290
- var ReasoningCapabilitiesSchema = z.object({
291
- supported: z.boolean().optional(),
292
- streaming: z.boolean().optional(),
293
- encrypted: z.boolean().optional()
289
+ var ReasoningCapabilitiesSchema = external_exports.object({
290
+ supported: external_exports.boolean().optional(),
291
+ streaming: external_exports.boolean().optional(),
292
+ encrypted: external_exports.boolean().optional()
294
293
  });
295
- var MultimodalInputCapabilitiesSchema = z.object({
296
- image: z.boolean().optional(),
297
- audio: z.boolean().optional(),
298
- video: z.boolean().optional(),
299
- pdf: z.boolean().optional(),
300
- file: z.boolean().optional()
294
+ var MultimodalInputCapabilitiesSchema = external_exports.object({
295
+ image: external_exports.boolean().optional(),
296
+ audio: external_exports.boolean().optional(),
297
+ video: external_exports.boolean().optional(),
298
+ pdf: external_exports.boolean().optional(),
299
+ file: external_exports.boolean().optional()
301
300
  });
302
- var MultimodalOutputCapabilitiesSchema = z.object({
303
- image: z.boolean().optional(),
304
- audio: z.boolean().optional()
301
+ var MultimodalOutputCapabilitiesSchema = external_exports.object({
302
+ image: external_exports.boolean().optional(),
303
+ audio: external_exports.boolean().optional()
305
304
  });
306
- var MultimodalCapabilitiesSchema = z.object({
305
+ var MultimodalCapabilitiesSchema = external_exports.object({
307
306
  input: MultimodalInputCapabilitiesSchema.optional(),
308
307
  output: MultimodalOutputCapabilitiesSchema.optional()
309
308
  });
310
- var ExecutionCapabilitiesSchema = z.object({
311
- codeExecution: z.boolean().optional(),
312
- sandboxed: z.boolean().optional(),
313
- maxIterations: z.number().optional(),
314
- maxExecutionTime: z.number().optional()
309
+ var ExecutionCapabilitiesSchema = external_exports.object({
310
+ codeExecution: external_exports.boolean().optional(),
311
+ sandboxed: external_exports.boolean().optional(),
312
+ maxIterations: external_exports.number().optional(),
313
+ maxExecutionTime: external_exports.number().optional()
315
314
  });
316
- var HumanInTheLoopCapabilitiesSchema = z.object({
317
- supported: z.boolean().optional(),
318
- approvals: z.boolean().optional(),
319
- interventions: z.boolean().optional(),
320
- feedback: z.boolean().optional(),
321
- interrupts: z.boolean().optional(),
322
- approveWithEdits: z.boolean().optional()
315
+ var HumanInTheLoopCapabilitiesSchema = external_exports.object({
316
+ supported: external_exports.boolean().optional(),
317
+ approvals: external_exports.boolean().optional(),
318
+ interventions: external_exports.boolean().optional(),
319
+ feedback: external_exports.boolean().optional(),
320
+ interrupts: external_exports.boolean().optional(),
321
+ approveWithEdits: external_exports.boolean().optional()
323
322
  });
324
- var AgentCapabilitiesSchema = z.object({
323
+ var AgentCapabilitiesSchema = external_exports.object({
325
324
  identity: IdentityCapabilitiesSchema.optional(),
326
325
  transport: TransportCapabilitiesSchema.optional(),
327
326
  tools: ToolsCapabilitiesSchema.optional(),
@@ -332,13 +331,13 @@ var AgentCapabilitiesSchema = z.object({
332
331
  multimodal: MultimodalCapabilitiesSchema.optional(),
333
332
  execution: ExecutionCapabilitiesSchema.optional(),
334
333
  humanInTheLoop: HumanInTheLoopCapabilitiesSchema.optional(),
335
- custom: z.record(z.unknown()).optional()
334
+ custom: external_exports.record(external_exports.unknown()).optional()
336
335
  });
337
- var TextMessageRoleSchema = z.union([
338
- z.literal("developer"),
339
- z.literal("system"),
340
- z.literal("assistant"),
341
- z.literal("user")
336
+ var TextMessageRoleSchema = external_exports.union([
337
+ external_exports.literal("developer"),
338
+ external_exports.literal("system"),
339
+ external_exports.literal("assistant"),
340
+ external_exports.literal("user")
342
341
  ]);
343
342
  var EventType = /* @__PURE__ */ (function(EventType2) {
344
343
  EventType2["TEXT_MESSAGE_START"] = "TEXT_MESSAGE_START";
@@ -376,176 +375,176 @@ var EventType = /* @__PURE__ */ (function(EventType2) {
376
375
  EventType2["REASONING_ENCRYPTED_VALUE"] = "REASONING_ENCRYPTED_VALUE";
377
376
  return EventType2;
378
377
  })({});
379
- var BaseEventSchema = z.object({
380
- type: z.nativeEnum(EventType),
381
- timestamp: z.number().optional(),
382
- rawEvent: z.any().optional()
378
+ var BaseEventSchema = external_exports.object({
379
+ type: external_exports.nativeEnum(EventType),
380
+ timestamp: external_exports.number().optional(),
381
+ rawEvent: external_exports.any().optional()
383
382
  }).passthrough();
384
383
  var TextMessageStartEventSchema = BaseEventSchema.extend({
385
- type: z.literal(EventType.TEXT_MESSAGE_START),
386
- messageId: z.string(),
384
+ type: external_exports.literal(EventType.TEXT_MESSAGE_START),
385
+ messageId: external_exports.string(),
387
386
  role: TextMessageRoleSchema.default("assistant"),
388
- name: z.string().optional()
387
+ name: external_exports.string().optional()
389
388
  });
390
389
  var TextMessageContentEventSchema = BaseEventSchema.extend({
391
- type: z.literal(EventType.TEXT_MESSAGE_CONTENT),
392
- messageId: z.string(),
393
- delta: z.string()
390
+ type: external_exports.literal(EventType.TEXT_MESSAGE_CONTENT),
391
+ messageId: external_exports.string(),
392
+ delta: external_exports.string()
394
393
  });
395
394
  var TextMessageEndEventSchema = BaseEventSchema.extend({
396
- type: z.literal(EventType.TEXT_MESSAGE_END),
397
- messageId: z.string()
395
+ type: external_exports.literal(EventType.TEXT_MESSAGE_END),
396
+ messageId: external_exports.string()
398
397
  });
399
398
  var TextMessageChunkEventSchema = BaseEventSchema.extend({
400
- type: z.literal(EventType.TEXT_MESSAGE_CHUNK),
401
- messageId: z.string().optional(),
399
+ type: external_exports.literal(EventType.TEXT_MESSAGE_CHUNK),
400
+ messageId: external_exports.string().optional(),
402
401
  role: TextMessageRoleSchema.optional(),
403
- delta: z.string().optional(),
404
- name: z.string().optional()
402
+ delta: external_exports.string().optional(),
403
+ name: external_exports.string().optional()
405
404
  });
406
- var ThinkingTextMessageStartEventSchema = BaseEventSchema.extend({ type: z.literal(EventType.THINKING_TEXT_MESSAGE_START) });
405
+ var ThinkingTextMessageStartEventSchema = BaseEventSchema.extend({ type: external_exports.literal(EventType.THINKING_TEXT_MESSAGE_START) });
407
406
  var ThinkingTextMessageContentEventSchema = TextMessageContentEventSchema.omit({
408
407
  messageId: true,
409
408
  type: true
410
- }).extend({ type: z.literal(EventType.THINKING_TEXT_MESSAGE_CONTENT) });
411
- var ThinkingTextMessageEndEventSchema = BaseEventSchema.extend({ type: z.literal(EventType.THINKING_TEXT_MESSAGE_END) });
409
+ }).extend({ type: external_exports.literal(EventType.THINKING_TEXT_MESSAGE_CONTENT) });
410
+ var ThinkingTextMessageEndEventSchema = BaseEventSchema.extend({ type: external_exports.literal(EventType.THINKING_TEXT_MESSAGE_END) });
412
411
  var ToolCallStartEventSchema = BaseEventSchema.extend({
413
- type: z.literal(EventType.TOOL_CALL_START),
414
- toolCallId: z.string(),
415
- toolCallName: z.string(),
416
- parentMessageId: z.string().optional()
412
+ type: external_exports.literal(EventType.TOOL_CALL_START),
413
+ toolCallId: external_exports.string(),
414
+ toolCallName: external_exports.string(),
415
+ parentMessageId: external_exports.string().optional()
417
416
  });
418
417
  var ToolCallArgsEventSchema = BaseEventSchema.extend({
419
- type: z.literal(EventType.TOOL_CALL_ARGS),
420
- toolCallId: z.string(),
421
- delta: z.string()
418
+ type: external_exports.literal(EventType.TOOL_CALL_ARGS),
419
+ toolCallId: external_exports.string(),
420
+ delta: external_exports.string()
422
421
  });
423
422
  var ToolCallEndEventSchema = BaseEventSchema.extend({
424
- type: z.literal(EventType.TOOL_CALL_END),
425
- toolCallId: z.string()
423
+ type: external_exports.literal(EventType.TOOL_CALL_END),
424
+ toolCallId: external_exports.string()
426
425
  });
427
426
  var ToolCallResultEventSchema = BaseEventSchema.extend({
428
- messageId: z.string(),
429
- type: z.literal(EventType.TOOL_CALL_RESULT),
430
- toolCallId: z.string(),
431
- content: z.string(),
432
- role: z.literal("tool").optional()
427
+ messageId: external_exports.string(),
428
+ type: external_exports.literal(EventType.TOOL_CALL_RESULT),
429
+ toolCallId: external_exports.string(),
430
+ content: external_exports.string(),
431
+ role: external_exports.literal("tool").optional()
433
432
  });
434
433
  var ToolCallChunkEventSchema = BaseEventSchema.extend({
435
- type: z.literal(EventType.TOOL_CALL_CHUNK),
436
- toolCallId: z.string().optional(),
437
- toolCallName: z.string().optional(),
438
- parentMessageId: z.string().optional(),
439
- delta: z.string().optional()
434
+ type: external_exports.literal(EventType.TOOL_CALL_CHUNK),
435
+ toolCallId: external_exports.string().optional(),
436
+ toolCallName: external_exports.string().optional(),
437
+ parentMessageId: external_exports.string().optional(),
438
+ delta: external_exports.string().optional()
440
439
  });
441
440
  var ThinkingStartEventSchema = BaseEventSchema.extend({
442
- type: z.literal(EventType.THINKING_START),
443
- title: z.string().optional()
441
+ type: external_exports.literal(EventType.THINKING_START),
442
+ title: external_exports.string().optional()
444
443
  });
445
- var ThinkingEndEventSchema = BaseEventSchema.extend({ type: z.literal(EventType.THINKING_END) });
444
+ var ThinkingEndEventSchema = BaseEventSchema.extend({ type: external_exports.literal(EventType.THINKING_END) });
446
445
  var StateSnapshotEventSchema = BaseEventSchema.extend({
447
- type: z.literal(EventType.STATE_SNAPSHOT),
446
+ type: external_exports.literal(EventType.STATE_SNAPSHOT),
448
447
  snapshot: StateSchema
449
448
  });
450
449
  var StateDeltaEventSchema = BaseEventSchema.extend({
451
- type: z.literal(EventType.STATE_DELTA),
452
- delta: z.array(z.any())
450
+ type: external_exports.literal(EventType.STATE_DELTA),
451
+ delta: external_exports.array(external_exports.any())
453
452
  });
454
453
  var MessagesSnapshotEventSchema = BaseEventSchema.extend({
455
- type: z.literal(EventType.MESSAGES_SNAPSHOT),
456
- messages: z.array(MessageSchema)
454
+ type: external_exports.literal(EventType.MESSAGES_SNAPSHOT),
455
+ messages: external_exports.array(MessageSchema)
457
456
  });
458
457
  var ActivitySnapshotEventSchema = BaseEventSchema.extend({
459
- type: z.literal(EventType.ACTIVITY_SNAPSHOT),
460
- messageId: z.string(),
461
- activityType: z.string(),
462
- content: z.record(z.any()),
463
- replace: z.boolean().optional().default(true)
458
+ type: external_exports.literal(EventType.ACTIVITY_SNAPSHOT),
459
+ messageId: external_exports.string(),
460
+ activityType: external_exports.string(),
461
+ content: external_exports.record(external_exports.any()),
462
+ replace: external_exports.boolean().optional().default(true)
464
463
  });
465
464
  var ActivityDeltaEventSchema = BaseEventSchema.extend({
466
- type: z.literal(EventType.ACTIVITY_DELTA),
467
- messageId: z.string(),
468
- activityType: z.string(),
469
- patch: z.array(z.any())
465
+ type: external_exports.literal(EventType.ACTIVITY_DELTA),
466
+ messageId: external_exports.string(),
467
+ activityType: external_exports.string(),
468
+ patch: external_exports.array(external_exports.any())
470
469
  });
471
470
  var RawEventSchema = BaseEventSchema.extend({
472
- type: z.literal(EventType.RAW),
473
- event: z.any(),
474
- source: z.string().optional()
471
+ type: external_exports.literal(EventType.RAW),
472
+ event: external_exports.any(),
473
+ source: external_exports.string().optional()
475
474
  });
476
475
  var CustomEventSchema = BaseEventSchema.extend({
477
- type: z.literal(EventType.CUSTOM),
478
- name: z.string(),
479
- value: z.any()
476
+ type: external_exports.literal(EventType.CUSTOM),
477
+ name: external_exports.string(),
478
+ value: external_exports.any()
480
479
  });
481
480
  var RunStartedEventSchema = BaseEventSchema.extend({
482
- type: z.literal(EventType.RUN_STARTED),
483
- threadId: z.string(),
484
- runId: z.string(),
485
- parentRunId: z.string().optional(),
481
+ type: external_exports.literal(EventType.RUN_STARTED),
482
+ threadId: external_exports.string(),
483
+ runId: external_exports.string(),
484
+ parentRunId: external_exports.string().optional(),
486
485
  input: RunAgentInputSchema.optional()
487
486
  });
488
- var RunFinishedSuccessOutcomeSchema = z.object({ type: z.literal("success") }).strict();
489
- var RunFinishedInterruptOutcomeSchema = z.object({
490
- type: z.literal("interrupt"),
491
- interrupts: z.array(InterruptSchema).min(1)
487
+ var RunFinishedSuccessOutcomeSchema = external_exports.object({ type: external_exports.literal("success") }).strict();
488
+ var RunFinishedInterruptOutcomeSchema = external_exports.object({
489
+ type: external_exports.literal("interrupt"),
490
+ interrupts: external_exports.array(InterruptSchema).min(1)
492
491
  }).strict();
493
- var RunFinishedOutcomeSchema = z.discriminatedUnion("type", [RunFinishedSuccessOutcomeSchema, RunFinishedInterruptOutcomeSchema]);
492
+ var RunFinishedOutcomeSchema = external_exports.discriminatedUnion("type", [RunFinishedSuccessOutcomeSchema, RunFinishedInterruptOutcomeSchema]);
494
493
  var RunFinishedEventSchema = BaseEventSchema.extend({
495
- type: z.literal(EventType.RUN_FINISHED),
496
- threadId: z.string(),
497
- runId: z.string(),
498
- result: z.any().optional(),
494
+ type: external_exports.literal(EventType.RUN_FINISHED),
495
+ threadId: external_exports.string(),
496
+ runId: external_exports.string(),
497
+ result: external_exports.any().optional(),
499
498
  outcome: RunFinishedOutcomeSchema.nullable().optional().transform((v) => v ?? void 0)
500
499
  });
501
500
  var RunErrorEventSchema = BaseEventSchema.extend({
502
- type: z.literal(EventType.RUN_ERROR),
503
- message: z.string(),
504
- code: z.string().optional()
501
+ type: external_exports.literal(EventType.RUN_ERROR),
502
+ message: external_exports.string(),
503
+ code: external_exports.string().optional()
505
504
  });
506
505
  var StepStartedEventSchema = BaseEventSchema.extend({
507
- type: z.literal(EventType.STEP_STARTED),
508
- stepName: z.string()
506
+ type: external_exports.literal(EventType.STEP_STARTED),
507
+ stepName: external_exports.string()
509
508
  });
510
509
  var StepFinishedEventSchema = BaseEventSchema.extend({
511
- type: z.literal(EventType.STEP_FINISHED),
512
- stepName: z.string()
510
+ type: external_exports.literal(EventType.STEP_FINISHED),
511
+ stepName: external_exports.string()
513
512
  });
514
- var ReasoningEncryptedValueSubtypeSchema = z.union([z.literal("tool-call"), z.literal("message")]);
513
+ var ReasoningEncryptedValueSubtypeSchema = external_exports.union([external_exports.literal("tool-call"), external_exports.literal("message")]);
515
514
  var ReasoningStartEventSchema = BaseEventSchema.extend({
516
- type: z.literal(EventType.REASONING_START),
517
- messageId: z.string()
515
+ type: external_exports.literal(EventType.REASONING_START),
516
+ messageId: external_exports.string()
518
517
  });
519
518
  var ReasoningMessageStartEventSchema = BaseEventSchema.extend({
520
- type: z.literal(EventType.REASONING_MESSAGE_START),
521
- messageId: z.string(),
522
- role: z.literal("reasoning")
519
+ type: external_exports.literal(EventType.REASONING_MESSAGE_START),
520
+ messageId: external_exports.string(),
521
+ role: external_exports.literal("reasoning")
523
522
  });
524
523
  var ReasoningMessageContentEventSchema = BaseEventSchema.extend({
525
- type: z.literal(EventType.REASONING_MESSAGE_CONTENT),
526
- messageId: z.string(),
527
- delta: z.string()
524
+ type: external_exports.literal(EventType.REASONING_MESSAGE_CONTENT),
525
+ messageId: external_exports.string(),
526
+ delta: external_exports.string()
528
527
  });
529
528
  var ReasoningMessageEndEventSchema = BaseEventSchema.extend({
530
- type: z.literal(EventType.REASONING_MESSAGE_END),
531
- messageId: z.string()
529
+ type: external_exports.literal(EventType.REASONING_MESSAGE_END),
530
+ messageId: external_exports.string()
532
531
  });
533
532
  var ReasoningMessageChunkEventSchema = BaseEventSchema.extend({
534
- type: z.literal(EventType.REASONING_MESSAGE_CHUNK),
535
- messageId: z.string().optional(),
536
- delta: z.string().optional()
533
+ type: external_exports.literal(EventType.REASONING_MESSAGE_CHUNK),
534
+ messageId: external_exports.string().optional(),
535
+ delta: external_exports.string().optional()
537
536
  });
538
537
  var ReasoningEndEventSchema = BaseEventSchema.extend({
539
- type: z.literal(EventType.REASONING_END),
540
- messageId: z.string()
538
+ type: external_exports.literal(EventType.REASONING_END),
539
+ messageId: external_exports.string()
541
540
  });
542
541
  var ReasoningEncryptedValueEventSchema = BaseEventSchema.extend({
543
- type: z.literal(EventType.REASONING_ENCRYPTED_VALUE),
542
+ type: external_exports.literal(EventType.REASONING_ENCRYPTED_VALUE),
544
543
  subtype: ReasoningEncryptedValueSubtypeSchema,
545
- entityId: z.string(),
546
- encryptedValue: z.string()
544
+ entityId: external_exports.string(),
545
+ encryptedValue: external_exports.string()
547
546
  });
548
- var EventSchemas = z.discriminatedUnion("type", [
547
+ var EventSchemas = external_exports.discriminatedUnion("type", [
549
548
  TextMessageStartEventSchema,
550
549
  TextMessageContentEventSchema,
551
550
  TextMessageEndEventSchema,
@@ -6205,9 +6204,6 @@ function decode(data) {
6205
6204
  }
6206
6205
  var AGUI_MEDIA_TYPE = "application/vnd.ag-ui.event+proto";
6207
6206
 
6208
- // ../../../node_modules/@ag-ui/client/dist/index.mjs
6209
- import { z as T } from "zod";
6210
-
6211
6207
  // ../../../node_modules/compare-versions/lib/esm/utils.js
6212
6208
  var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
6213
6209
  var validateAndParse = (version) => {
@@ -6694,7 +6690,7 @@ var R = (e) => defer(() => from(e())).pipe(switchMap((e2) => {
6694
6690
  });
6695
6691
  })) : throwError(() => Error(`Failed to getReader() from response`));
6696
6692
  }));
6697
- var z2 = (e, t) => {
6693
+ var z = (e, t) => {
6698
6694
  let n = M(t), r = new Subject(), i = new TextDecoder(`utf-8`, { fatal: false }), a = ``;
6699
6695
  e.subscribe({ next: (e2) => {
6700
6696
  if (e2.type !== L.HEADERS && e2.type === L.DATA && e2.data) {
@@ -6758,7 +6754,7 @@ var V = (e, t) => {
6758
6754
  if (o.next(e2), e2.type === L.HEADERS && !s) {
6759
6755
  s = true;
6760
6756
  let t2 = e2.headers.get(`content-type`);
6761
- n?.lifecycle(`HTTP`, `Stream format detected:`, { contentType: t2, parser: t2 === AGUI_MEDIA_TYPE ? `protobuf` : `sse` }), t2 === AGUI_MEDIA_TYPE ? B(o).subscribe({ next: (e3) => a.next(e3), error: (e3) => a.error(e3), complete: () => a.complete() }) : z2(o, n).subscribe({ next: (e3) => {
6757
+ n?.lifecycle(`HTTP`, `Stream format detected:`, { contentType: t2, parser: t2 === AGUI_MEDIA_TYPE ? `protobuf` : `sse` }), t2 === AGUI_MEDIA_TYPE ? B(o).subscribe({ next: (e3) => a.next(e3), error: (e3) => a.error(e3), complete: () => a.complete() }) : z(o, n).subscribe({ next: (e3) => {
6762
6758
  try {
6763
6759
  let t3 = EventSchemas.parse(e3);
6764
6760
  n?.event(`HTTP`, `Event validated:`, t3, { type: t3.type, valid: true }), a.next(t3);
@@ -6779,19 +6775,19 @@ var V = (e, t) => {
6779
6775
  o.complete();
6780
6776
  } }), a.asObservable();
6781
6777
  };
6782
- var H = T.enum([`TextMessageStart`, `TextMessageContent`, `TextMessageEnd`, `ActionExecutionStart`, `ActionExecutionArgs`, `ActionExecutionEnd`, `ActionExecutionResult`, `AgentStateMessage`, `MetaEvent`, `RunStarted`, `RunFinished`, `RunError`, `NodeStarted`, `NodeFinished`]);
6783
- var se = T.enum([`LangGraphInterruptEvent`, `PredictState`, `Exit`]);
6784
- var ce = T.object({ type: T.literal(H.enum.TextMessageStart), messageId: T.string(), parentMessageId: T.string().optional(), role: T.string().optional() });
6785
- var le = T.object({ type: T.literal(H.enum.TextMessageContent), messageId: T.string(), content: T.string() });
6786
- var ue = T.object({ type: T.literal(H.enum.TextMessageEnd), messageId: T.string() });
6787
- var de = T.object({ type: T.literal(H.enum.ActionExecutionStart), actionExecutionId: T.string(), actionName: T.string(), parentMessageId: T.string().optional() });
6788
- var fe = T.object({ type: T.literal(H.enum.ActionExecutionArgs), actionExecutionId: T.string(), args: T.string() });
6789
- var pe = T.object({ type: T.literal(H.enum.ActionExecutionEnd), actionExecutionId: T.string() });
6790
- var me = T.object({ type: T.literal(H.enum.ActionExecutionResult), actionName: T.string(), actionExecutionId: T.string(), result: T.string() });
6791
- var he = T.object({ type: T.literal(H.enum.AgentStateMessage), threadId: T.string(), agentName: T.string(), nodeName: T.string(), runId: T.string(), active: T.boolean(), role: T.string(), state: T.string(), running: T.boolean() });
6792
- var ge = T.object({ type: T.literal(H.enum.MetaEvent), name: se, value: T.any() });
6793
- var _e = T.object({ type: T.literal(H.enum.RunError), message: T.string(), code: T.string().optional() });
6794
- T.discriminatedUnion(`type`, [ce, le, ue, de, fe, pe, me, he, ge, _e]), T.object({ id: T.string(), role: T.string(), content: T.string(), parentMessageId: T.string().optional() }), T.object({ id: T.string(), name: T.string(), arguments: T.any(), parentMessageId: T.string().optional() }), T.object({ id: T.string(), result: T.any(), actionExecutionId: T.string(), actionName: T.string() });
6778
+ var H = external_exports.enum([`TextMessageStart`, `TextMessageContent`, `TextMessageEnd`, `ActionExecutionStart`, `ActionExecutionArgs`, `ActionExecutionEnd`, `ActionExecutionResult`, `AgentStateMessage`, `MetaEvent`, `RunStarted`, `RunFinished`, `RunError`, `NodeStarted`, `NodeFinished`]);
6779
+ var se = external_exports.enum([`LangGraphInterruptEvent`, `PredictState`, `Exit`]);
6780
+ var ce = external_exports.object({ type: external_exports.literal(H.enum.TextMessageStart), messageId: external_exports.string(), parentMessageId: external_exports.string().optional(), role: external_exports.string().optional() });
6781
+ var le = external_exports.object({ type: external_exports.literal(H.enum.TextMessageContent), messageId: external_exports.string(), content: external_exports.string() });
6782
+ var ue = external_exports.object({ type: external_exports.literal(H.enum.TextMessageEnd), messageId: external_exports.string() });
6783
+ var de = external_exports.object({ type: external_exports.literal(H.enum.ActionExecutionStart), actionExecutionId: external_exports.string(), actionName: external_exports.string(), parentMessageId: external_exports.string().optional() });
6784
+ var fe = external_exports.object({ type: external_exports.literal(H.enum.ActionExecutionArgs), actionExecutionId: external_exports.string(), args: external_exports.string() });
6785
+ var pe = external_exports.object({ type: external_exports.literal(H.enum.ActionExecutionEnd), actionExecutionId: external_exports.string() });
6786
+ var me = external_exports.object({ type: external_exports.literal(H.enum.ActionExecutionResult), actionName: external_exports.string(), actionExecutionId: external_exports.string(), result: external_exports.string() });
6787
+ var he = external_exports.object({ type: external_exports.literal(H.enum.AgentStateMessage), threadId: external_exports.string(), agentName: external_exports.string(), nodeName: external_exports.string(), runId: external_exports.string(), active: external_exports.boolean(), role: external_exports.string(), state: external_exports.string(), running: external_exports.boolean() });
6788
+ var ge = external_exports.object({ type: external_exports.literal(H.enum.MetaEvent), name: se, value: external_exports.any() });
6789
+ var _e = external_exports.object({ type: external_exports.literal(H.enum.RunError), message: external_exports.string(), code: external_exports.string().optional() });
6790
+ external_exports.discriminatedUnion(`type`, [ce, le, ue, de, fe, pe, me, he, ge, _e]), external_exports.object({ id: external_exports.string(), role: external_exports.string(), content: external_exports.string(), parentMessageId: external_exports.string().optional() }), external_exports.object({ id: external_exports.string(), name: external_exports.string(), arguments: external_exports.any(), parentMessageId: external_exports.string().optional() }), external_exports.object({ id: external_exports.string(), result: external_exports.any(), actionExecutionId: external_exports.string(), actionName: external_exports.string() });
6795
6791
  var ve = (e) => {
6796
6792
  if (typeof e == `string`) return e;
6797
6793
  if (!Array.isArray(e)) return;
@@ -7747,476 +7743,6 @@ var AgUiTransport = class {
7747
7743
  }
7748
7744
  };
7749
7745
 
7750
- // src/elements/ActionHandler.ts
7751
- var ActionHandler = class {
7752
- constructor() {
7753
- this.typeName = "action";
7754
- // v1: only imperative actions are wired. Stateful content-mutation
7755
- // actions arrive with Phase 7 (Portable Text renderer).
7756
- this.lifecycle = "imperative";
7757
- }
7758
- validate(instance, _ctx) {
7759
- if (instance.element_type !== "action") {
7760
- return { accepted: false, reason: "wrong_element_type" };
7761
- }
7762
- const kind = instance.content.__kind;
7763
- if (typeof kind !== "string" || kind.length === 0) {
7764
- return { accepted: false, reason: "missing_action_kind" };
7765
- }
7766
- return { accepted: true };
7767
- }
7768
- async mount(instance, ctx) {
7769
- const action = this._actionFromInstance(instance);
7770
- await ctx.actions.applyBatch([action]);
7771
- }
7772
- async patch(_instance, _ctx) {
7773
- }
7774
- async unmount(_instance, _ctx) {
7775
- }
7776
- _actionFromInstance(instance) {
7777
- const { __kind, ...params } = instance.content;
7778
- const placement = instance.placement;
7779
- const anchorOverride = placement.type === "selector" ? { anchorId: { selector: placement.selector, route: "**" } } : {};
7780
- if (typeof params.anchorId === "string") {
7781
- params.anchorId = { selector: params.anchorId, route: "**" };
7782
- }
7783
- return {
7784
- kind: __kind,
7785
- ...params,
7786
- ...anchorOverride,
7787
- label: `action:${instance.template_id}:${instance.instance_id}`
7788
- };
7789
- }
7790
- };
7791
-
7792
- // src/elements/ElementInstanceStore.ts
7793
- var COMPOSITIONAL_REPLAY_REQUEST_EVENT = "element.compositional_replay_request";
7794
- var COMPOSITIONAL_APPEND_EVENT = "element.compositional_append";
7795
- var CHAT_INLINE_SLOT = "chat-inline";
7796
- var ElementInstanceStore = class {
7797
- constructor(options) {
7798
- this._instances = /* @__PURE__ */ new Map();
7799
- /** Active TTL timeout — replaced on each call to `scheduleClientTtl`. */
7800
- this._ttlTimer = null;
7801
- /** Instance IDs the client has dismissed. Persists across canvas remounts
7802
- * so a dismissed tile never silently reappears on replay/broadcast. */
7803
- this._dismissedIds = /* @__PURE__ */ new Set();
7804
- this._actions = options.actions;
7805
- this._events = options.events;
7806
- this._resolveTileWidget = options.resolveTileWidget;
7807
- this._handlers = /* @__PURE__ */ new Map();
7808
- for (const handler of options.handlers ?? []) {
7809
- this._handlers.set(handler.typeName, handler);
7810
- }
7811
- this._logger = options.logger ?? console;
7812
- this._subscribeReplayRequests();
7813
- }
7814
- /**
7815
- * Listen for `element.compositional_replay_request` from container
7816
- * widgets and re-publish `element.compositional_append` for every
7817
- * matching item still tracked in `_instances`. This keeps LLM-authored
7818
- * items visible across SPA navigations: the store is a module-level
7819
- * singleton that survives chat-bar unmount/remount, so when a fresh
7820
- * chips-strip mounts and subscribes, asking for a replay re-populates
7821
- * its chip array.
7822
- */
7823
- _subscribeReplayRequests() {
7824
- const subscribe = this._events?.subscribe;
7825
- const publish = this._events?.publish;
7826
- if (!subscribe || !publish) return;
7827
- subscribe(
7828
- {
7829
- names: [
7830
- COMPOSITIONAL_REPLAY_REQUEST_EVENT,
7831
- TILE_REPLAY_REQUEST_EVENT,
7832
- TILE_UNMOUNTED_EVENT
7833
- ]
7834
- },
7835
- (event) => {
7836
- if (event.name === TILE_UNMOUNTED_EVENT) {
7837
- const id = String(event.props?.instance_id ?? "");
7838
- if (id) this._dismissedIds.add(id);
7839
- return;
7840
- }
7841
- if (event.name === COMPOSITIONAL_REPLAY_REQUEST_EVENT) {
7842
- const tileId = String(event.props?.tile_id ?? "");
7843
- if (!tileId) return;
7844
- this._replayItems(tileId, publish);
7845
- return;
7846
- }
7847
- if (event.name === TILE_REPLAY_REQUEST_EVENT) {
7848
- this._replayTiles(publish);
7849
- return;
7850
- }
7851
- }
7852
- );
7853
- }
7854
- _replayItems(tileId, publish) {
7855
- for (const instance of this._instances.values()) {
7856
- if (instance.element_type !== "item") continue;
7857
- if (instance.placement.type !== "parent_tile") continue;
7858
- if (instance.placement.tile_id !== tileId) continue;
7859
- if (instance.state !== "active") continue;
7860
- publish(COMPOSITIONAL_APPEND_EVENT, {
7861
- tile_id: tileId,
7862
- instance_id: instance.instance_id,
7863
- item: instance.content,
7864
- position: instance.placement.position
7865
- });
7866
- }
7867
- }
7868
- _replayTiles(publish) {
7869
- for (const instance of this._instances.values()) {
7870
- if (instance.element_type !== "tile") continue;
7871
- if (instance.placement.type !== "slot") continue;
7872
- if (instance.state !== "active") continue;
7873
- if (this._dismissedIds.has(instance.instance_id)) continue;
7874
- const props = {
7875
- slot: instance.placement.slot,
7876
- instance_id: instance.instance_id,
7877
- widget: this._resolveTileWidget?.(instance.template_id) ?? instance.template_id,
7878
- props: instance.content ?? {}
7879
- };
7880
- publish(TILE_MOUNTED_EVENT, props);
7881
- }
7882
- }
7883
- registerHandler(handler) {
7884
- this._handlers.set(handler.typeName, handler);
7885
- }
7886
- isDismissed(instanceId) {
7887
- return this._dismissedIds.has(instanceId);
7888
- }
7889
- getDismissedIds() {
7890
- return this._dismissedIds;
7891
- }
7892
- /** Store-driven receipt source for the chat trail (one per active slot-tile). */
7893
- listTileReceipts() {
7894
- const out = [];
7895
- for (const inst of this._instances.values()) {
7896
- if (inst.element_type !== "tile" || inst.placement.type !== "slot") continue;
7897
- if (inst.state !== "active") continue;
7898
- if (inst.placement.slot === CHAT_INLINE_SLOT) continue;
7899
- const content = inst.content;
7900
- const productName = content?.product?.name;
7901
- const contentTitle = content?.title;
7902
- const contentHeading = content?.heading;
7903
- const title = typeof productName === "string" && productName ? productName : typeof contentTitle === "string" && contentTitle ? contentTitle : typeof contentHeading === "string" && contentHeading ? contentHeading : (
7904
- // Never show a raw template id (kebab-case machine name) in the
7905
- // chat — prettify the last-resort fallback into Title Case.
7906
- inst.template_id.replace(/[-_]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())
7907
- );
7908
- const imgContent = inst.content;
7909
- const imageCandidate = imgContent?.product?.image?.src ?? imgContent?.items?.[0]?.image_url ?? imgContent?.products?.[0]?.image?.src;
7910
- const imageUrl = typeof imageCandidate === "string" && imageCandidate.trim() ? imageCandidate : void 0;
7911
- if (inst.placement.slot === "alert") {
7912
- out.push({
7913
- kind: "alert",
7914
- instanceId: inst.instance_id,
7915
- title,
7916
- turnId: inst.mounted_by?.turn_id,
7917
- toolCallId: inst.tool_call_id ?? void 0
7918
- });
7919
- } else {
7920
- out.push({
7921
- kind: "tile",
7922
- instanceId: inst.instance_id,
7923
- title,
7924
- dismissed: this._dismissedIds.has(inst.instance_id),
7925
- turnId: inst.mounted_by?.turn_id,
7926
- toolCallId: inst.tool_call_id ?? void 0,
7927
- ...imageUrl ? { imageUrl } : {}
7928
- });
7929
- }
7930
- }
7931
- return out;
7932
- }
7933
- /**
7934
- * Store-driven inline-widget source for the chat trail — one entry per
7935
- * active `chat-inline` slot-tile. The trail mounts each entry's widget
7936
- * element (by tag name, via `document.createElement`) inline in the
7937
- * conversation flow. Distinct from {@link listTileReceipts}: those are
7938
- * chips that recall a deck tile; these ARE the rendered widget.
7939
- */
7940
- listInlineWidgets() {
7941
- const out = [];
7942
- for (const inst of this._instances.values()) {
7943
- if (inst.element_type !== "tile" || inst.placement.type !== "slot") continue;
7944
- if (inst.placement.slot !== CHAT_INLINE_SLOT) continue;
7945
- if (inst.state !== "active") continue;
7946
- if (this._dismissedIds.has(inst.instance_id)) continue;
7947
- out.push({
7948
- instanceId: inst.instance_id,
7949
- tag: this._resolveTileWidget?.(inst.template_id) ?? inst.template_id,
7950
- props: inst.content ?? {},
7951
- turnId: inst.mounted_by?.turn_id,
7952
- toolCallId: inst.tool_call_id ?? void 0
7953
- });
7954
- }
7955
- return out;
7956
- }
7957
- /** Clear a client dismissal and re-publish the tile's mount from retained content. */
7958
- recreate(instanceId) {
7959
- const instance = this._instances.get(instanceId);
7960
- const publish = this._events?.publish;
7961
- if (!instance || instance.element_type !== "tile" || instance.placement.type !== "slot" || !publish) {
7962
- return;
7963
- }
7964
- this._dismissedIds.delete(instanceId);
7965
- const props = {
7966
- slot: instance.placement.slot,
7967
- instance_id: instance.instance_id,
7968
- widget: this._resolveTileWidget?.(instance.template_id) ?? instance.template_id,
7969
- props: instance.content ?? {}
7970
- };
7971
- publish(TILE_MOUNTED_EVENT, props);
7972
- }
7973
- /**
7974
- * Apply the server-provided boot snapshot. For each instance:
7975
- * - stateful: validated + mounted via the type handler;
7976
- * - imperative + already-applied: recorded only (no DOM action);
7977
- * - any: tracked in the in-memory map for future patches.
7978
- *
7979
- * Safe to call once on SDK init. Calling again would re-mount
7980
- * stateful instances; callers should not.
7981
- */
7982
- async hydrate(snapshot) {
7983
- for (const instance of snapshot) {
7984
- const existing = this._instances.get(instance.instance_id);
7985
- if (existing && existing.version >= instance.version) {
7986
- continue;
7987
- }
7988
- const handler = this._handlers.get(instance.element_type);
7989
- if (!handler) {
7990
- this._logger.warn("elements: hydrate skipped \u2014 unknown element_type", {
7991
- element_type: instance.element_type,
7992
- instance_id: instance.instance_id
7993
- });
7994
- continue;
7995
- }
7996
- this._instances.set(instance.instance_id, instance);
7997
- if (handler.lifecycle === "imperative" && instance.state === "applied") {
7998
- continue;
7999
- }
8000
- if (instance.state !== "active") {
8001
- continue;
8002
- }
8003
- await this._mount(handler, instance);
8004
- }
8005
- this._broadcastActive();
8006
- }
8007
- /**
8008
- * Re-publish `element.tile_mounted` / `element.compositional_append`
8009
- * for every active LLM-authored instance in the store. Idempotent —
8010
- * receivers key by `instance_id` (tiles) or by widget identity
8011
- * (items via tile_id filter).
8012
- */
8013
- _broadcastActive() {
8014
- const publish = this._events?.publish;
8015
- if (!publish) return;
8016
- this._replayTiles(publish);
8017
- const itemTileIds = /* @__PURE__ */ new Set();
8018
- for (const instance of this._instances.values()) {
8019
- if (instance.element_type !== "item") continue;
8020
- if (instance.placement.type !== "parent_tile") continue;
8021
- if (instance.state !== "active") continue;
8022
- itemTileIds.add(instance.placement.tile_id);
8023
- }
8024
- for (const tileId of itemTileIds) {
8025
- this._replayItems(tileId, publish);
8026
- }
8027
- }
8028
- /**
8029
- * Apply a batch of mutations, atomically per-batch. Each mutation is
8030
- * version-checked (mount: must not conflict with existing instance;
8031
- * patch: resulting_version must be > current; unmount: idempotent).
8032
- */
8033
- async apply(mutations) {
8034
- for (const mutation of mutations) {
8035
- try {
8036
- await this._applyOne(mutation);
8037
- } catch (err) {
8038
- this._logger.error("elements: mutation failed", { mutation, err });
8039
- }
8040
- }
8041
- }
8042
- /** Read-only snapshot of currently-known instances. */
8043
- getInstances() {
8044
- return Array.from(this._instances.values());
8045
- }
8046
- getInstance(instance_id) {
8047
- return this._instances.get(instance_id);
8048
- }
8049
- /**
8050
- * Schedule a client-side TTL that unmounts every active stateful
8051
- * instance when the server-side session expires. Replaces any
8052
- * previously-scheduled TTL.
8053
- *
8054
- * Avoids the orphan-window where session-expired tiles linger on the
8055
- * page until manual refresh — the server forgets at the 4h mark and
8056
- * the SDK tears down concurrently. Re-schedule on each boot fetch /
8057
- * mutation event that carries a refreshed `session_expires_at`.
8058
- *
8059
- * Pass `null` to clear the existing timer without scheduling a new one.
8060
- * Pass a past timestamp to trigger cleanup immediately.
8061
- */
8062
- scheduleClientTtl(session_expires_at) {
8063
- if (this._ttlTimer !== null) {
8064
- clearTimeout(this._ttlTimer);
8065
- this._ttlTimer = null;
8066
- }
8067
- if (session_expires_at === null) return;
8068
- const expiryMs = Date.parse(session_expires_at);
8069
- if (Number.isNaN(expiryMs)) {
8070
- this._logger.warn("elements: invalid session_expires_at", { session_expires_at });
8071
- return;
8072
- }
8073
- const delay = Math.max(0, expiryMs - Date.now());
8074
- this._ttlTimer = setTimeout(() => {
8075
- this._ttlTimer = null;
8076
- void this._handleSessionExpiry();
8077
- }, delay);
8078
- }
8079
- // -------------------------------------------------------------------
8080
- // Internals
8081
- // -------------------------------------------------------------------
8082
- async _handleSessionExpiry() {
8083
- const unmounts = [];
8084
- for (const instance of this._instances.values()) {
8085
- if (instance.state !== "active") continue;
8086
- const handler = this._handlers.get(instance.element_type);
8087
- if (!handler || handler.lifecycle === "imperative") continue;
8088
- unmounts.push({ op: "unmount", instance_id: instance.instance_id });
8089
- }
8090
- if (unmounts.length > 0) {
8091
- this._logger.info("elements: client TTL fired \u2014 unmounting active instances", {
8092
- count: unmounts.length
8093
- });
8094
- await this.apply(unmounts);
8095
- }
8096
- }
8097
- async _applyOne(mutation) {
8098
- if (mutation.op === "mount") {
8099
- const existing = this._instances.get(mutation.instance.instance_id);
8100
- if (existing && existing.version >= mutation.instance.version) {
8101
- return;
8102
- }
8103
- const handler = this._handlers.get(mutation.instance.element_type);
8104
- if (!handler) {
8105
- this._logger.warn("elements: mount dropped \u2014 unknown element_type", {
8106
- element_type: mutation.instance.element_type
8107
- });
8108
- return;
8109
- }
8110
- const isActiveStateful = mutation.instance.state === "active" && handler.lifecycle !== "imperative";
8111
- const isAppliedImperative = mutation.instance.state === "applied" && handler.lifecycle === "imperative";
8112
- if (isActiveStateful || isAppliedImperative) {
8113
- this._instances.set(mutation.instance.instance_id, mutation.instance);
8114
- const applied = await this._mount(handler, mutation.instance);
8115
- if (!applied) {
8116
- if (existing) {
8117
- this._instances.set(mutation.instance.instance_id, existing);
8118
- } else {
8119
- this._instances.delete(mutation.instance.instance_id);
8120
- }
8121
- }
8122
- return;
8123
- }
8124
- this._instances.set(mutation.instance.instance_id, mutation.instance);
8125
- return;
8126
- }
8127
- if (mutation.op === "patch") {
8128
- const existing = this._instances.get(mutation.instance_id);
8129
- if (!existing) {
8130
- this._logger.warn("elements: patch dropped \u2014 unknown instance", {
8131
- instance_id: mutation.instance_id
8132
- });
8133
- return;
8134
- }
8135
- if (typeof mutation.resulting_version !== "number" || mutation.resulting_content == null || typeof mutation.resulting_content !== "object") {
8136
- this._logger.warn("elements: patch dropped \u2014 malformed envelope (missing resulting_*)", {
8137
- instance_id: mutation.instance_id
8138
- });
8139
- return;
8140
- }
8141
- if (mutation.resulting_version <= existing.version) {
8142
- return;
8143
- }
8144
- const patched = {
8145
- ...existing,
8146
- content: mutation.resulting_content,
8147
- version: mutation.resulting_version
8148
- };
8149
- const handler = this._handlers.get(patched.element_type);
8150
- if (handler) {
8151
- const validation = handler.validate(patched, this._ctx());
8152
- if (!validation.accepted) {
8153
- this._logger.warn("elements: patch validation failed", {
8154
- instance_id: mutation.instance_id,
8155
- reason: validation.reason
8156
- });
8157
- return;
8158
- }
8159
- try {
8160
- await handler.patch(patched, this._ctx());
8161
- } catch (err) {
8162
- this._logger.warn("elements: handler.patch threw", {
8163
- instance_id: mutation.instance_id,
8164
- err
8165
- });
8166
- return;
8167
- }
8168
- }
8169
- this._instances.set(mutation.instance_id, patched);
8170
- return;
8171
- }
8172
- if (mutation.op === "unmount") {
8173
- const existing = this._instances.get(mutation.instance_id);
8174
- if (!existing) {
8175
- return;
8176
- }
8177
- const reverted = { ...existing, state: "reverted" };
8178
- this._instances.set(mutation.instance_id, reverted);
8179
- const handler = this._handlers.get(existing.element_type);
8180
- if (handler) {
8181
- try {
8182
- await handler.unmount(reverted, this._ctx());
8183
- } catch (err) {
8184
- this._instances.set(mutation.instance_id, existing);
8185
- this._logger.warn("elements: handler.unmount threw", {
8186
- instance_id: mutation.instance_id,
8187
- err
8188
- });
8189
- }
8190
- }
8191
- return;
8192
- }
8193
- }
8194
- async _mount(handler, instance) {
8195
- const validation = handler.validate(instance, this._ctx());
8196
- if (!validation.accepted) {
8197
- this._logger.warn("elements: mount validation failed", {
8198
- instance_id: instance.instance_id,
8199
- reason: validation.reason,
8200
- detail: validation.detail
8201
- });
8202
- return false;
8203
- }
8204
- try {
8205
- await handler.mount(instance, this._ctx());
8206
- } catch (err) {
8207
- this._logger.warn("elements: handler.mount threw", {
8208
- instance_id: instance.instance_id,
8209
- err
8210
- });
8211
- return false;
8212
- }
8213
- return true;
8214
- }
8215
- _ctx() {
8216
- return { actions: this._actions, events: this._events };
8217
- }
8218
- };
8219
-
8220
7746
  // src/elements/envelope.ts
8221
7747
  function decodeMutationEnvelope(payload) {
8222
7748
  if (!payload || typeof payload !== "object") return null;
@@ -8294,126 +7820,6 @@ function _runtimeId(method) {
8294
7820
  }
8295
7821
  }
8296
7822
 
8297
- // src/elements/ItemHandler.ts
8298
- var COMPOSITIONAL_APPEND_EVENT2 = "element.compositional_append";
8299
- var COMPOSITIONAL_PATCH_EVENT = "element.compositional_patch";
8300
- var COMPOSITIONAL_REMOVE_EVENT = "element.compositional_remove";
8301
- var ItemHandler = class {
8302
- constructor() {
8303
- this.typeName = "item";
8304
- this.lifecycle = "stateful";
8305
- }
8306
- validate(instance, _ctx) {
8307
- if (instance.element_type !== "item") {
8308
- return {
8309
- accepted: false,
8310
- reason: "wrong_element_type",
8311
- detail: instance.element_type
8312
- };
8313
- }
8314
- if (instance.placement.type !== "parent_tile") {
8315
- return {
8316
- accepted: false,
8317
- reason: "item_requires_parent_tile_placement",
8318
- detail: `got placement.type=${instance.placement.type}`
8319
- };
8320
- }
8321
- if (typeof instance.template_id !== "string" || instance.template_id.length === 0) {
8322
- return { accepted: false, reason: "missing_template_id" };
8323
- }
8324
- return { accepted: true };
8325
- }
8326
- async mount(instance, ctx) {
8327
- if (!ctx.events) return;
8328
- const placement = instance.placement;
8329
- ctx.events.publish(COMPOSITIONAL_APPEND_EVENT2, {
8330
- tile_id: placement.tile_id,
8331
- instance_id: instance.instance_id,
8332
- item: instance.content,
8333
- position: placement.position
8334
- });
8335
- }
8336
- async patch(instance, ctx) {
8337
- if (!ctx.events) return;
8338
- const placement = instance.placement;
8339
- ctx.events.publish(COMPOSITIONAL_PATCH_EVENT, {
8340
- tile_id: placement.tile_id,
8341
- instance_id: instance.instance_id,
8342
- item: instance.content
8343
- });
8344
- }
8345
- async unmount(instance, ctx) {
8346
- if (!ctx.events) return;
8347
- const placement = instance.placement;
8348
- ctx.events.publish(COMPOSITIONAL_REMOVE_EVENT, {
8349
- tile_id: placement.tile_id,
8350
- instance_id: instance.instance_id
8351
- });
8352
- }
8353
- };
8354
-
8355
- // src/elements/TileHandler.ts
8356
- var TileHandler = class {
8357
- constructor(resolveWidget) {
8358
- this.resolveWidget = resolveWidget;
8359
- this.typeName = "tile";
8360
- this.lifecycle = "stateful";
8361
- }
8362
- _widgetFor(instance) {
8363
- return this.resolveWidget?.(instance.template_id) ?? instance.template_id;
8364
- }
8365
- validate(instance, _ctx) {
8366
- if (instance.element_type !== "tile") {
8367
- return { accepted: false, reason: "wrong_element_type", detail: instance.element_type };
8368
- }
8369
- if (instance.placement.type !== "slot") {
8370
- return {
8371
- accepted: false,
8372
- reason: "tile_requires_slot_placement",
8373
- detail: `got placement.type=${instance.placement.type}`
8374
- };
8375
- }
8376
- if (typeof instance.template_id !== "string" || instance.template_id.length === 0) {
8377
- return { accepted: false, reason: "missing_template_id" };
8378
- }
8379
- if (this.resolveWidget && this.resolveWidget(instance.template_id) === void 0) {
8380
- return { accepted: false, reason: "unknown_template_id", detail: instance.template_id };
8381
- }
8382
- return { accepted: true };
8383
- }
8384
- async mount(instance, ctx) {
8385
- if (!ctx.events) return;
8386
- const placement = instance.placement;
8387
- const props = {
8388
- slot: placement.slot,
8389
- instance_id: instance.instance_id,
8390
- widget: this._widgetFor(instance),
8391
- props: instance.content ?? {}
8392
- };
8393
- ctx.events.publish(TILE_MOUNTED_EVENT, props);
8394
- }
8395
- async patch(instance, ctx) {
8396
- if (!ctx.events) return;
8397
- const placement = instance.placement;
8398
- const props = {
8399
- slot: placement.slot,
8400
- instance_id: instance.instance_id,
8401
- widget: this._widgetFor(instance),
8402
- props: instance.content ?? {}
8403
- };
8404
- ctx.events.publish(TILE_PATCHED_EVENT, props);
8405
- }
8406
- async unmount(instance, ctx) {
8407
- if (!ctx.events) return;
8408
- const placement = instance.placement;
8409
- const props = {
8410
- slot: placement.slot,
8411
- instance_id: instance.instance_id
8412
- };
8413
- ctx.events.publish(TILE_UNMOUNTED_EVENT, props);
8414
- }
8415
- };
8416
-
8417
7823
  // src/Turnstile.ts
8418
7824
  var TURNSTILE_SITEKEY = "0x4AAAAAADSzPbGWxeguF4YJ";
8419
7825
  var TURNSTILE_ACQUIRE_TIMEOUT_MS = 5e3;
@@ -8609,6 +8015,42 @@ async function acquireTokenWithChallenge(options = {}) {
8609
8015
  removePanel();
8610
8016
  }
8611
8017
  }
8018
+ var BOT_CHECK_MODE_TIMEOUT_MS = 3e3;
8019
+ var botCheckModeCache = /* @__PURE__ */ new Map();
8020
+ async function readBotCheckMode(backendUrl) {
8021
+ const controller = new AbortController();
8022
+ const timer = setTimeout(() => controller.abort(), BOT_CHECK_MODE_TIMEOUT_MS);
8023
+ try {
8024
+ const response = await fetch(`${backendUrl}/api/adaptive/bot_check`, {
8025
+ signal: controller.signal
8026
+ });
8027
+ if (!response.ok) return null;
8028
+ const body = await response.json();
8029
+ return body.mode === "off" || body.mode === "soft" || body.mode === "hard" ? body.mode : null;
8030
+ } catch {
8031
+ return null;
8032
+ } finally {
8033
+ clearTimeout(timer);
8034
+ }
8035
+ }
8036
+ function fetchBotCheckMode(backendUrl) {
8037
+ const key = backendUrl.replace(/\/$/, "");
8038
+ let pending = botCheckModeCache.get(key);
8039
+ if (!pending) {
8040
+ pending = readBotCheckMode(key);
8041
+ pending.then((mode) => {
8042
+ if (mode === null) botCheckModeCache.delete(key);
8043
+ });
8044
+ botCheckModeCache.set(key, pending);
8045
+ }
8046
+ return pending;
8047
+ }
8048
+ async function acquireBotCheckTokenForSend(backendUrl, options = {}) {
8049
+ if (!TURNSTILE_SITEKEY) return { token: null, outcome: "disabled" };
8050
+ const mode = await fetchBotCheckMode(backendUrl);
8051
+ if (mode === "off") return { token: null, outcome: "disabled" };
8052
+ return acquireTokenWithChallenge(options);
8053
+ }
8612
8054
 
8613
8055
  // src/ChatAssistantLit.ts
8614
8056
  var ERROR_DEBOUNCE_MS = 1500;
@@ -8669,6 +8111,34 @@ function renderFallbackHtml(fallback) {
8669
8111
  const ctaHtml = ctaHref && /^https?:\/\//.test(ctaHref) ? `<a href="${escapeHtml(ctaHref)}" target="_blank" rel="noopener noreferrer" style="${ctaStyle}">${escapeHtml(ctaLabel)}</a>` : "";
8670
8112
  return `<div style="${wrapperStyle}" data-adaptive-chatbot-fallback="true"><div style="${titleStyle}">${escapeHtml(title)}</div><div style="${messageStyle}">${escapeHtml(message)}</div>${ctaHtml}</div>`;
8671
8113
  }
8114
+ var BotCheckedTransport = class {
8115
+ constructor(inner, beforeUserMessage, isUnmounted) {
8116
+ this.inner = inner;
8117
+ this.beforeUserMessage = beforeUserMessage;
8118
+ this.isUnmounted = isUnmounted;
8119
+ }
8120
+ get connected() {
8121
+ return this.inner.connected;
8122
+ }
8123
+ connect(sessionId) {
8124
+ this.inner.connect(sessionId);
8125
+ }
8126
+ disconnect() {
8127
+ this.inner.disconnect();
8128
+ }
8129
+ subscribe(handler) {
8130
+ return this.inner.subscribe(handler);
8131
+ }
8132
+ send(action) {
8133
+ if (action.type !== "user-message") {
8134
+ this.inner.send(action);
8135
+ return;
8136
+ }
8137
+ void this.beforeUserMessage().then(() => {
8138
+ if (!this.isUnmounted()) this.inner.send(action);
8139
+ });
8140
+ }
8141
+ };
8672
8142
  var ChatAssistantLitMountable = {
8673
8143
  mount(container, mountConfig) {
8674
8144
  const incoming = mountConfig ?? null;
@@ -8720,17 +8190,16 @@ var ChatAssistantLitMountable = {
8720
8190
  }
8721
8191
  };
8722
8192
  debug("mount", { tileId: resolvedTileId, instanceId, baseUrl });
8723
- const elementStore = new ElementInstanceStore({
8724
- actions: runtime.actions,
8725
- handlers: [new TileHandler(), new ActionHandler()]
8193
+ const elementSession = createElementSessionController({
8194
+ ...runtime,
8195
+ legacyTemplateFallback: true
8726
8196
  });
8727
8197
  void fetchMountedElements({
8728
8198
  endpoint: `${baseUrl}/api/adaptive/mounted_elements`,
8729
8199
  token
8730
8200
  }).then((response) => {
8731
8201
  if (isUnmounted || response === null) return;
8732
- void elementStore.hydrate(response.mounted_elements);
8733
- elementStore.scheduleClientTtl(response.session_expires_at);
8202
+ void elementSession.hydrateLegacy(response.mounted_elements, response.session_expires_at);
8734
8203
  });
8735
8204
  const el = document.createElement("syntro-chat");
8736
8205
  el.greeting = chatbotConfig?.greeting;
@@ -8791,11 +8260,11 @@ var ChatAssistantLitMountable = {
8791
8260
  el.remove();
8792
8261
  container.innerHTML = renderFallbackHtml(chatbotConfig?.fallback);
8793
8262
  };
8794
- const setupTransport = (cftToken) => {
8263
+ const setupTransport = (readCftToken, beforeUserMessage) => {
8795
8264
  if (isUnmounted) return;
8796
8265
  transport = new AgUiTransport({
8797
8266
  url: streamUrl,
8798
- headers: () => buildHeaders(cftToken),
8267
+ headers: () => buildHeaders(readCftToken()),
8799
8268
  // Adaptive runtime SDK needs the `syntro_chat_session` cookie to
8800
8269
  // round-trip cross-origin so subsequent boot fetches can rehydrate
8801
8270
  // LLM-authored UI elements. Editor / action-plan chat surfaces
@@ -8805,7 +8274,12 @@ var ChatAssistantLitMountable = {
8805
8274
  onA2UIEvent: (payload) => {
8806
8275
  const mutations = decodeMutationEnvelope(payload);
8807
8276
  if (mutations !== null) {
8808
- Promise.resolve(elementStore.apply(mutations)).then(() => {
8277
+ elementSession.applyLegacyEnvelope({
8278
+ type: "syntro.element.mutation",
8279
+ schema_version: "v0",
8280
+ mutations
8281
+ }).then(() => {
8282
+ if (isUnmounted) return;
8809
8283
  runtime.events.publish("chatbot.element_mutation_applied", {
8810
8284
  tileId: resolvedTileId,
8811
8285
  count: mutations.length
@@ -8826,7 +8300,7 @@ var ChatAssistantLitMountable = {
8826
8300
  });
8827
8301
  }
8828
8302
  });
8829
- el.transport = transport;
8303
+ el.transport = new BotCheckedTransport(transport, beforeUserMessage, () => isUnmounted);
8830
8304
  unsubscribe = transport.subscribe((event) => {
8831
8305
  if (isUnmounted) return;
8832
8306
  debug("transport event", { type: event.type, hasSucceeded, fallbackRendered });
@@ -8900,32 +8374,27 @@ var ChatAssistantLitMountable = {
8900
8374
  container.appendChild(el);
8901
8375
  };
8902
8376
  const acquireAbort = new AbortController();
8903
- const acquireWithManagedChallenge = async () => {
8904
- const { token: token2, outcome } = await acquireTokenWithChallenge({
8905
- signal: acquireAbort.signal
8906
- });
8907
- if (isUnmounted) return null;
8908
- botCheckOutcome = outcome;
8909
- if (token2 === null) {
8910
- console.warn(
8911
- "[adaptive-chatbot] turnstile token acquisition failed \u2014 connecting without a bot-check token; backend may 403"
8377
+ let cftToken = null;
8378
+ let botCheck = null;
8379
+ const ensureBotCheck = () => {
8380
+ if (!botCheck) {
8381
+ botCheck = acquireBotCheckTokenForSend(baseUrl, { signal: acquireAbort.signal }).then(
8382
+ ({ token: token2, outcome }) => {
8383
+ if (isUnmounted) return;
8384
+ botCheckOutcome = outcome;
8385
+ hadTurnstileToken = outcome === "disabled" ? null : token2 !== null;
8386
+ cftToken = token2;
8387
+ if (token2 === null && outcome !== "disabled") {
8388
+ console.warn(
8389
+ "[adaptive-chatbot] turnstile token acquisition failed \u2014 sending without a bot-check token; backend may 403"
8390
+ );
8391
+ }
8392
+ }
8912
8393
  );
8913
8394
  }
8914
- return token2;
8395
+ return botCheck;
8915
8396
  };
8916
- if (TURNSTILE_SITEKEY) {
8917
- void acquireWithManagedChallenge().then((cft) => {
8918
- if (isUnmounted) return;
8919
- hadTurnstileToken = cft !== null;
8920
- if (cft === null) {
8921
- swapToFallback("connect_failed");
8922
- return;
8923
- }
8924
- setupTransport(cft);
8925
- });
8926
- } else {
8927
- setupTransport(null);
8928
- }
8397
+ setupTransport(() => cftToken, ensureBotCheck);
8929
8398
  return () => {
8930
8399
  debug("unmount", {
8931
8400
  ageMs: mountAgeMs(),
@@ -8935,7 +8404,7 @@ var ChatAssistantLitMountable = {
8935
8404
  });
8936
8405
  isUnmounted = true;
8937
8406
  clearTimers();
8938
- elementStore.scheduleClientTtl(null);
8407
+ void elementSession.dispose();
8939
8408
  acquireAbort.abort();
8940
8409
  if (unsubscribe) {
8941
8410
  unsubscribe();
@@ -8951,13 +8420,9 @@ var ChatAssistantLitMountable = {
8951
8420
 
8952
8421
  export {
8953
8422
  AgUiTransport,
8954
- ActionHandler,
8955
- ElementInstanceStore,
8956
8423
  decodeMutationEnvelope,
8957
8424
  fetchMountedElements,
8958
- ItemHandler,
8959
- TileHandler,
8960
- acquireTokenWithChallenge,
8425
+ acquireBotCheckTokenForSend,
8961
8426
  renderFallbackHtml,
8962
8427
  ChatAssistantLitMountable
8963
8428
  };
@@ -8977,4 +8442,4 @@ fast-json-patch/module/duplex.mjs:
8977
8442
  * MIT license
8978
8443
  *)
8979
8444
  */
8980
- //# sourceMappingURL=chunk-57MPLQOL.js.map
8445
+ //# sourceMappingURL=chunk-7QXC475Y.js.map