@copilotkit/react-core 2.0.0-rc.4 → 2.0.0-rc.41

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 (80) hide show
  1. package/README.md +1 -1
  2. package/dist/MarkdownRendererContext-BL8ct_3U.d.mts +34 -0
  3. package/dist/MarkdownRendererContext-BL8ct_3U.d.mts.map +1 -0
  4. package/dist/MarkdownRendererContext-C2J_lgqF.d.cts +34 -0
  5. package/dist/MarkdownRendererContext-C2J_lgqF.d.cts.map +1 -0
  6. package/dist/MarkdownSurfaces-Byz821bg.mjs +324 -0
  7. package/dist/MarkdownSurfaces-Byz821bg.mjs.map +1 -0
  8. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs +378 -0
  9. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs.map +1 -0
  10. package/dist/chat-Bf0vVdo7.mjs +1600 -0
  11. package/dist/chat-Bf0vVdo7.mjs.map +1 -0
  12. package/dist/chat-D3fxo6Ah.cjs +1784 -0
  13. package/dist/chat-D3fxo6Ah.cjs.map +1 -0
  14. package/dist/chat-DgP2N7bD.d.mts +233 -0
  15. package/dist/chat-DgP2N7bD.d.mts.map +1 -0
  16. package/dist/chat-DtHs4alO.d.cts +233 -0
  17. package/dist/chat-DtHs4alO.d.cts.map +1 -0
  18. package/dist/context.cjs +75 -63
  19. package/dist/context.cjs.map +1 -1
  20. package/dist/context.d.cts +62 -107
  21. package/dist/context.d.cts.map +1 -1
  22. package/dist/context.d.mts +62 -107
  23. package/dist/context.d.mts.map +1 -1
  24. package/dist/context.mjs +76 -64
  25. package/dist/context.mjs.map +1 -1
  26. package/dist/generative-ui/native.cjs +66 -0
  27. package/dist/generative-ui/native.cjs.map +1 -0
  28. package/dist/generative-ui/native.d.cts +155 -0
  29. package/dist/generative-ui/native.d.cts.map +1 -0
  30. package/dist/generative-ui/native.d.mts +155 -0
  31. package/dist/generative-ui/native.d.mts.map +1 -0
  32. package/dist/generative-ui/native.mjs +24 -0
  33. package/dist/generative-ui/native.mjs.map +1 -0
  34. package/dist/generative-ui.cjs +757 -3056
  35. package/dist/generative-ui.cjs.map +1 -1
  36. package/dist/generative-ui.d.cts +2470 -4788
  37. package/dist/generative-ui.d.cts.map +1 -1
  38. package/dist/generative-ui.d.mts +2470 -4788
  39. package/dist/generative-ui.d.mts.map +1 -1
  40. package/dist/generative-ui.mjs +327 -2636
  41. package/dist/generative-ui.mjs.map +1 -1
  42. package/dist/headless.cjs +289 -1054
  43. package/dist/headless.cjs.map +1 -1
  44. package/dist/headless.d.cts +146 -371
  45. package/dist/headless.d.cts.map +1 -1
  46. package/dist/headless.d.mts +120 -236
  47. package/dist/headless.d.mts.map +1 -1
  48. package/dist/headless.mjs +283 -1054
  49. package/dist/headless.mjs.map +1 -1
  50. package/dist/hooks-2Ur8NQhj.d.cts +84 -0
  51. package/dist/hooks-2Ur8NQhj.d.cts.map +1 -0
  52. package/dist/hooks-BRYonCVu.d.mts +84 -0
  53. package/dist/hooks-BRYonCVu.d.mts.map +1 -0
  54. package/dist/index.cjs +9003 -13047
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +352 -834
  57. package/dist/index.d.cts.map +1 -1
  58. package/dist/index.d.mts +349 -831
  59. package/dist/index.d.mts.map +1 -1
  60. package/dist/index.mjs +1904 -7583
  61. package/dist/index.mjs.map +1 -1
  62. package/dist/index.umd.js +10629 -15765
  63. package/dist/index.umd.js.map +1 -1
  64. package/dist/refs-BIUfn1wb.cjs +43 -0
  65. package/dist/refs-BIUfn1wb.cjs.map +1 -0
  66. package/dist/refs-CMrRm3ta.mjs +31 -0
  67. package/dist/refs-CMrRm3ta.mjs.map +1 -0
  68. package/dist/use-generative-ui-root-C12htqbK.cjs +390 -0
  69. package/dist/use-generative-ui-root-C12htqbK.cjs.map +1 -0
  70. package/dist/use-generative-ui-root-CVgsDy1f.mjs +385 -0
  71. package/dist/use-generative-ui-root-CVgsDy1f.mjs.map +1 -0
  72. package/package.json +45 -23
  73. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts +0 -954
  74. package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
  75. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts +0 -954
  76. package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
  77. package/dist/MarkdownSurfaces-Bd--93O1.mjs +0 -3676
  78. package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
  79. package/dist/MarkdownSurfaces-S4wfUl3J.cjs +0 -3991
  80. package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
@@ -0,0 +1,1600 @@
1
+ import { CopilotChatDefaultLabels, ɵChatConfigurationStore, ɵshallowEqualRecord } from "@copilotkit/core";
2
+ import React, { Component, createContext, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
3
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
+ import { CopilotKitContext, useCopilotKit, useDefaultAgentId } from "@copilotkit/react-core/context";
5
+ import { A2UI_COMPONENT_ENVELOPE_KEYS, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE, GENERATIVE_UI_RENDER_TOOL, GENERATIVE_UI_ROOT_ID, isActionBinding, isPathBinding, mapAtChildRef, ɵanySchema } from "@copilotkit/shared";
6
+ import * as z from "zod";
7
+ import { GenerativeUISurfaceContentSchema, accessibilityAttributes, accessibilityAttributes as accessibilityAttributes$1, controlAria, invokeBoundEvent, invokeMatchedEvent, joinPath, namedRole, parseGenerativeUISurfaceContent, readAccessibility, reportErrorSafely, resolvePath, tryResolveDynamicValue, wrapperAria } from "@copilotkit/core/generative-ui";
8
+ import { catalogIdsOf, createGenerativeUI, formatIssues, hasOwnKey, isAsyncIssue, issueKey, setterNameOf, themeStyleSheet, toError, validateSchema, validateSchemaSync, withCause, withCause as withCause$1, withoutRejectedNulls } from "@copilotkit/shared/generative-ui";
9
+
10
+ //#region src/lib/shallow-stable-ref.ts
11
+ /**
12
+ * Shallow equality comparison for objects: same own keys, each holding the
13
+ * same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.
14
+ */
15
+ function shallowEqual(obj1, obj2) {
16
+ return ɵshallowEqualRecord(obj1, obj2);
17
+ }
18
+ /**
19
+ * Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
20
+ * class instances, and other exotic objects that happen to have typeof "object".
21
+ */
22
+ function isPlainObject(obj) {
23
+ return obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
24
+ }
25
+ /**
26
+ * Returns the same reference as long as the value is shallowly equal to the
27
+ * previous render's value.
28
+ *
29
+ * - Identical references bail out immediately (O(1)).
30
+ * - Plain objects ({}) are shallow-compared key-by-key.
31
+ * - Arrays, Dates, class instances, functions, and primitives are compared by
32
+ * reference only — shallowEqual is never called on non-plain objects, which
33
+ * avoids incorrect equality for e.g. [1,2] vs [1,2] (different arrays).
34
+ *
35
+ * Typical use: stabilize inline slot props so MemoizedSlotWrapper's shallow
36
+ * equality check isn't defeated by a new object reference on every render.
37
+ */
38
+ function useShallowStableRef(value) {
39
+ const ref = useRef(value);
40
+ if (ref.current === value) return ref.current;
41
+ if (isPlainObject(ref.current) && isPlainObject(value)) {
42
+ if (shallowEqual(ref.current, value)) return ref.current;
43
+ }
44
+ ref.current = value;
45
+ return ref.current;
46
+ }
47
+
48
+ //#endregion
49
+ //#region src/providers/CopilotChatConfigurationProvider.tsx
50
+ const CopilotChatConfiguration = createContext(null);
51
+ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId, hasExplicitThreadId, isModalDefaultOpen }) => {
52
+ const parentConfig = useContext(CopilotChatConfiguration);
53
+ const stableLabels = useShallowStableRef(labels);
54
+ const mergedLabels = useMemo(() => ({
55
+ ...CopilotChatDefaultLabels,
56
+ ...parentConfig?.labels,
57
+ ...stableLabels
58
+ }), [stableLabels, parentConfig?.labels]);
59
+ const providerAgentId = useDefaultAgentId();
60
+ const options = {
61
+ agentId,
62
+ threadId,
63
+ hasExplicitThreadId,
64
+ isModalDefaultOpen,
65
+ providerAgentId
66
+ };
67
+ const parentStore = parentConfig?.ɵstore ?? null;
68
+ const [store] = useState(() => new ɵChatConfigurationStore(options, parentStore));
69
+ store.ɵsetOptions(options);
70
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
71
+ useEffect(() => {
72
+ store.update({
73
+ agentId,
74
+ threadId,
75
+ hasExplicitThreadId,
76
+ isModalDefaultOpen,
77
+ providerAgentId
78
+ });
79
+ }, [
80
+ store,
81
+ agentId,
82
+ threadId,
83
+ hasExplicitThreadId,
84
+ isModalDefaultOpen,
85
+ providerAgentId
86
+ ]);
87
+ const copilotkit = useContext(CopilotKitContext)?.copilotkit;
88
+ useEffect(() => {
89
+ if (copilotkit === void 0) return;
90
+ return store.bindOpenThread(copilotkit);
91
+ }, [copilotkit, store]);
92
+ const ownsModal = isModalDefaultOpen !== void 0;
93
+ const isModalOpen = ownsModal || !parentConfig ? snapshot.isModalOpen : parentConfig.isModalOpen;
94
+ const setModalOpen = ownsModal || !parentConfig ? store.setModalOpen : parentConfig.setModalOpen;
95
+ const { agentId: resolvedAgentId, threadId: resolvedThreadId, hasExplicitThreadId: resolvedHasExplicitThreadId, drawerOpen, drawerRegistered } = snapshot;
96
+ const configurationValue = useMemo(() => ({
97
+ labels: mergedLabels,
98
+ agentId: resolvedAgentId,
99
+ threadId: resolvedThreadId,
100
+ hasExplicitThreadId: resolvedHasExplicitThreadId,
101
+ isModalOpen,
102
+ setModalOpen,
103
+ drawerOpen,
104
+ setDrawerOpen: store.setDrawerOpen,
105
+ drawerRegistered,
106
+ registerDrawer: store.registerDrawer,
107
+ ɵregisterModalCloser: store.registerModalCloser,
108
+ setActiveThreadId: store.setActiveThreadId,
109
+ startNewThread: store.startNewThread,
110
+ ɵstore: store
111
+ }), [
112
+ mergedLabels,
113
+ resolvedAgentId,
114
+ resolvedThreadId,
115
+ resolvedHasExplicitThreadId,
116
+ isModalOpen,
117
+ setModalOpen,
118
+ drawerOpen,
119
+ drawerRegistered,
120
+ store
121
+ ]);
122
+ return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, {
123
+ value: configurationValue,
124
+ children
125
+ });
126
+ };
127
+ const useCopilotChatConfiguration = () => {
128
+ return useContext(CopilotChatConfiguration);
129
+ };
130
+ /**
131
+ * Reports modal open/close requests to the host, and — when `open` is
132
+ * supplied — makes the modal state of an already-established chat
133
+ * configuration **controlled** for the subtree it wraps.
134
+ *
135
+ * This is deliberately a scope component rather than another mode inside
136
+ * {@link CopilotChatConfigurationProvider}. The provider resolves modal state
137
+ * across a nested chain (own state, parent sync, drawer mutual-exclusion, the
138
+ * modal-closer registry); a controlled branch inside that resolution would add
139
+ * a fourth interacting mode. Overriding the context for the subtree instead
140
+ * leaves every one of those paths untouched:
141
+ *
142
+ * - `isModalOpen` is replaced with the host's `open`, so the rendered surface
143
+ * follows the prop from the very first frame (no open-then-close flash).
144
+ * - `setModalOpen` still calls the underlying setter, so the existing
145
+ * parent-sync and drawer mutual-exclusion side effects continue to run, and
146
+ * *then* reports the request through `onOpenChange`.
147
+ * - The wrapped setter is registered as the modal closer, so the drawer's
148
+ * mobile mutual-exclusion reaches the host instead of silently flipping
149
+ * state that nothing displays.
150
+ *
151
+ * A host that supplies `open` and ignores `onOpenChange` gets a modal pinned
152
+ * to `open`, which is the standard controlled-component contract. A host that
153
+ * supplies only `onOpenChange` is notified while the modal keeps managing
154
+ * itself.
155
+ *
156
+ * Renders `children` unchanged when no chat configuration is in scope.
157
+ */
158
+ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
159
+ const parentConfig = useContext(CopilotChatConfiguration);
160
+ const parentSetModalOpen = parentConfig?.setModalOpen;
161
+ const registerModalCloser = parentConfig?.ɵregisterModalCloser;
162
+ const setModalOpen = useCallback((next) => {
163
+ parentSetModalOpen?.(next);
164
+ onOpenChange?.(next);
165
+ }, [parentSetModalOpen, onOpenChange]);
166
+ useEffect(() => {
167
+ if (!registerModalCloser) return;
168
+ return registerModalCloser(setModalOpen);
169
+ }, [registerModalCloser, setModalOpen]);
170
+ const configurationValue = useMemo(() => parentConfig ? {
171
+ ...parentConfig,
172
+ isModalOpen: open ?? parentConfig.isModalOpen,
173
+ setModalOpen
174
+ } : null, [
175
+ parentConfig,
176
+ open,
177
+ setModalOpen
178
+ ]);
179
+ if (!configurationValue) return /* @__PURE__ */ jsx(Fragment$1, { children });
180
+ return /* @__PURE__ */ jsx(CopilotChatConfiguration.Provider, {
181
+ value: configurationValue,
182
+ children
183
+ });
184
+ };
185
+ ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
186
+
187
+ //#endregion
188
+ //#region src/types/defineToolCallRenderer.ts
189
+ function defineToolCallRenderer(def) {
190
+ const argsSchema = def.name === "*" && !def.args ? ɵanySchema : def.args;
191
+ return {
192
+ name: def.name,
193
+ args: argsSchema,
194
+ render: def.render,
195
+ ...def.agentId ? { agentId: def.agentId } : {},
196
+ ...def.group ? { group: true } : {}
197
+ };
198
+ }
199
+
200
+ //#endregion
201
+ //#region src/generative-ui/runtime-context.ts
202
+ const GenerativeUIRuntimeContext = createContext(null);
203
+ function useGenerativeUIRuntime() {
204
+ return useContext(GenerativeUIRuntimeContext);
205
+ }
206
+ function useRequiredGenerativeUIRuntime() {
207
+ const runtime = useContext(GenerativeUIRuntimeContext);
208
+ if (!runtime) throw new Error("Generative UI components must be rendered inside a generative UI provider: <CopilotKitProvider generativeUI={{ ui }}> on the web, or <GenerativeUIProvider> from @copilotkit/react-native/generative-ui on React Native.");
209
+ return runtime;
210
+ }
211
+ const GenerativeUINodeContext = createContext(null);
212
+
213
+ //#endregion
214
+ //#region src/generative-ui/hooks.ts
215
+ const noopSubscribe$1 = () => () => {};
216
+ const zero = () => 0;
217
+ /** Re-renders on any surface-manager change. */
218
+ function useManagerVersion(runtime) {
219
+ return useSyncExternalStore(runtime?.manager.subscribe ?? noopSubscribe$1, runtime?.manager.getVersion ?? zero, zero);
220
+ }
221
+ /**
222
+ * Experimental. Gives one key of the app state declared in
223
+ * `createGenerativeUI({ state })` its value. Bound props of generated
224
+ * components read it. The model does not see it.
225
+ *
226
+ * The key is set on mount and when the value changes (compared as JSON). It
227
+ * is removed on unmount.
228
+ *
229
+ * @param ui - The object from `createGenerativeUI`. It gives the key and the
230
+ * value their types.
231
+ * @param key - A top-level key of `state`.
232
+ * @param value - The value of that key. It must fit the key's schema.
233
+ *
234
+ * @example
235
+ * ```tsx
236
+ * useGenerativeUIState(storeUI, "cart", { count, total, coupon, items });
237
+ * ```
238
+ */
239
+ function useGenerativeUIState(ui, key, value) {
240
+ const runtime = useRequiredGenerativeUIRuntime();
241
+ const serialized = JSON.stringify(value);
242
+ useEffect(() => {
243
+ const raw = JSON.parse(serialized ?? "null");
244
+ let current = true;
245
+ const apply = (parsed) => {
246
+ if (!current) return;
247
+ if (parsed.success) {
248
+ runtime.manager.setState(key, parsed.data);
249
+ return;
250
+ }
251
+ runtime.manager.removeState(key);
252
+ if (process.env.NODE_ENV !== "production") console.error(`[generativeUI] useGenerativeUIState: invalid value for "${key}": ${formatIssues(parsed.issues, "value")}`);
253
+ };
254
+ const schema = runtime.ui.state.get(key);
255
+ const parsed = schema ? validateSchema(schema, raw) : {
256
+ success: true,
257
+ data: raw
258
+ };
259
+ if (parsed instanceof Promise) parsed.then(apply);
260
+ else apply(parsed);
261
+ return () => {
262
+ current = false;
263
+ };
264
+ }, [
265
+ runtime,
266
+ key,
267
+ serialized
268
+ ]);
269
+ useEffect(() => () => runtime.manager.removeState(key), [runtime, key]);
270
+ }
271
+ /**
272
+ * Experimental. Mounts the handler of a function declared in
273
+ * `createGenerativeUI({ functions })`. Generated UI can call the function
274
+ * only while exactly one handler for it is mounted.
275
+ *
276
+ * The handler gets the parsed arguments: schema defaults are set. It can
277
+ * change on each render. The latest handler always runs, and the hook does
278
+ * not register again.
279
+ *
280
+ * @param ui - The object from `createGenerativeUI`. It gives the name and the
281
+ * handler arguments their types.
282
+ * @param name - A key of `functions`.
283
+ * @param handler - Runs when generated UI calls the function. Its return
284
+ * value goes back to the caller as `{ ok: true, result }`.
285
+ *
286
+ * @example
287
+ * ```tsx
288
+ * useGenerativeUIFunction(storeUI, "addToCart", ({ productId, quantity }) =>
289
+ * cart.addItem(productId, quantity),
290
+ * );
291
+ * ```
292
+ */
293
+ function useGenerativeUIFunction(ui, name, handler) {
294
+ const runtime = useRequiredGenerativeUIRuntime();
295
+ const latest = useRef(handler);
296
+ latest.current = handler;
297
+ useEffect(() => runtime.dispatcher.register(name, latest), [runtime, name]);
298
+ }
299
+
300
+ //#endregion
301
+ //#region src/generative-ui/activity.ts
302
+ /**
303
+ * The rejected operations of a surface (the runtime's first, then the
304
+ * client's) and the error that goes with them, for a wrapper: a generic
305
+ * message, with the same list as its `cause`. The `cause` is not enumerable,
306
+ * so `JSON.stringify`, a spread and error reporters leave the list out.
307
+ * `clientRejected` is appended to in place by the manager, so its length is
308
+ * part of the key.
309
+ */
310
+ function useGenerativeUIRejected(serverRejected, clientRejected) {
311
+ const rejected = useMemo(() => [...serverRejected ?? [], ...clientRejected ?? []], [
312
+ serverRejected,
313
+ clientRejected,
314
+ clientRejected?.length ?? 0
315
+ ]);
316
+ return {
317
+ rejected,
318
+ error: useMemo(() => rejected.length ? withCause(/* @__PURE__ */ new Error(`${rejected.length} UI update(s) could not be shown`), rejected) : void 0, [rejected])
319
+ };
320
+ }
321
+ /**
322
+ * What a renderer of one surface activity message shows: the surface (or the
323
+ * failed surface whose `createSurface` was rejected), and its rejected
324
+ * operations with their error (see {@link useGenerativeUIRejected}). It
325
+ * ingests `content` into the manager (idempotent: the root ingests the
326
+ * agent's messages too, and this covers an agent the root has not seen yet),
327
+ * and renders again on every change of the manager.
328
+ *
329
+ * `surface` is undefined when there is no runtime, thread or content, when
330
+ * the surface's target is not `target`, or when the surface does not exist
331
+ * (the agent deleted it). Both rejected lists cover only the latest
332
+ * `render_ui` call (see the manager's ingest).
333
+ */
334
+ function useGenerativeUIActivitySurface({ runtime, threadId, agentId, content, target }) {
335
+ useManagerVersion(runtime);
336
+ useLayoutEffect(() => {
337
+ if (runtime && threadId && content) runtime.manager.ingest(threadId, agentId, content);
338
+ }, [
339
+ runtime,
340
+ threadId,
341
+ agentId,
342
+ content
343
+ ]);
344
+ const surface = runtime && threadId && content && content.target === target ? runtime.manager.getSurface(threadId, content.surfaceId) ?? runtime.manager.getFailedSurface(threadId, content.surfaceId) : void 0;
345
+ const { rejected, error } = useGenerativeUIRejected(content?.rejected, surface?.clientRejected);
346
+ return {
347
+ surface,
348
+ rejected,
349
+ error
350
+ };
351
+ }
352
+
353
+ //#endregion
354
+ //#region src/generative-ui/catalog.ts
355
+ /**
356
+ * Experimental. Declares the components the model can render, the app state
357
+ * they read, and the functions they call.
358
+ *
359
+ * - A prop with the name of a top-level state key is bound to that state.
360
+ * - `bind: { prop: (state, props) => value }` binds a prop to a selector.
361
+ * - An event binds to the function with its name, else to the name without
362
+ * `on` (`onAddToCart` calls `addToCart`).
363
+ * - `writable: ["value"]` gives the component a `setValue` prop. See
364
+ * `GenerativeUIComponentDefinition.writable`.
365
+ *
366
+ * The model does not see bound props or matched events.
367
+ *
368
+ * @param config - `id`, then optional `extends`, `state`, `functions` and
369
+ * `overrides`, then `components`. Put `state` before `components`, so the selectors
370
+ * get typed state.
371
+ * @throws Error when a name comes from two places, an override names no
372
+ * component of the bases, `props` is not an object
373
+ * schema with a JSON Schema, a key is reserved or used
374
+ * twice on a component, an event matches two functions, an unmatched event
375
+ * has no `parameters`, a `bind` key is not a prop, a `writable` key is not
376
+ * a prop or is a bound prop, or a setter name is already a key of the
377
+ * component. Also throws when `parameterOrder` contains duplicate or unknown
378
+ * keys, or an ordered component declares integer-index keys whose JSON object
379
+ * enumeration order cannot be controlled.
380
+ *
381
+ * @example
382
+ * ```ts
383
+ * const ui = createGenerativeUI({
384
+ * id: "acme/store@1",
385
+ * state: { cart: cartSchema },
386
+ * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
387
+ * components: {
388
+ * CartSummary: {
389
+ * component: CartSummary,
390
+ * props: z.object({ count: z.number() }),
391
+ * bind: { count: (state) => state.cart.count },
392
+ * },
393
+ * },
394
+ * });
395
+ * ```
396
+ */
397
+ function createGenerativeUI$1(config) {
398
+ return createGenerativeUI(config);
399
+ }
400
+
401
+ //#endregion
402
+ //#region src/generative-ui/host.tsx
403
+ const DISPLAY_CONTENTS = { display: "contents" };
404
+ /**
405
+ * The root element is always there, so a theme change does not remount the
406
+ * surface. `display: contents` keeps it out of the layout, and the CSS
407
+ * variables still reach every component of the surface. The `a2ui-surface`
408
+ * class scopes the standard catalog's surface CSS rules. The theme is a
409
+ * stylesheet, not an inline style, so that its `dark` values can apply in
410
+ * dark mode only. The values are checked in `themeStyleSheet`, and the HTML
411
+ * is set as is, so the server render keeps the quotes of the rule.
412
+ */
413
+ function DomSurfaceRoot({ surfaceId, theme, children }) {
414
+ const sheet = React.useMemo(() => themeStyleSheet(theme), [theme]);
415
+ return /* @__PURE__ */ jsxs("div", {
416
+ className: "a2ui-surface",
417
+ "data-generative-ui-root": surfaceId,
418
+ "data-a2ui-theme": sheet?.id,
419
+ style: DISPLAY_CONTENTS,
420
+ children: [sheet ? /* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: sheet.css } }) : null, children]
421
+ });
422
+ }
423
+ function DomAccessibilityWrapper({ attributes, children }) {
424
+ return /* @__PURE__ */ jsx("span", {
425
+ "data-a2ui-accessibility": "",
426
+ style: DISPLAY_CONTENTS,
427
+ ...attributes,
428
+ children
429
+ });
430
+ }
431
+ function DefaultNodeFallback({ message, componentId, retry }) {
432
+ return /* @__PURE__ */ jsxs("div", {
433
+ role: "alert",
434
+ "data-generative-ui-error": componentId,
435
+ style: {
436
+ border: "1px solid #fca5a5",
437
+ background: "#fef2f2",
438
+ color: "#991b1b",
439
+ borderRadius: 8,
440
+ padding: "8px 12px",
441
+ fontSize: 13
442
+ },
443
+ children: [
444
+ "Couldn’t display this part: ",
445
+ message,
446
+ retry && /* @__PURE__ */ jsx("button", {
447
+ type: "button",
448
+ onClick: retry,
449
+ style: {
450
+ marginLeft: 8,
451
+ textDecoration: "underline"
452
+ },
453
+ children: "Retry"
454
+ })
455
+ ]
456
+ });
457
+ }
458
+ /** The DOM host: what a surface draws on the web. */
459
+ const domGenerativeUIHost = {
460
+ SurfaceRoot: DomSurfaceRoot,
461
+ AccessibilityWrapper: DomAccessibilityWrapper,
462
+ NodeFallback: DefaultNodeFallback
463
+ };
464
+ /**
465
+ * The host elements of the surfaces below. Defaults to the DOM host, so a
466
+ * web app never sets it.
467
+ */
468
+ const GenerativeUIHostContext = createContext(domGenerativeUIHost);
469
+ function useGenerativeUIHost() {
470
+ return useContext(GenerativeUIHostContext);
471
+ }
472
+
473
+ //#endregion
474
+ //#region src/generative-ui/boundaries.tsx
475
+ /**
476
+ * A child that has not streamed yet renders nothing. The prose keeps
477
+ * streaming above the surface, and each component appears as soon as it is
478
+ * complete. A grey block in its place would read as a broken layout.
479
+ */
480
+ function NodePlaceholder(_props) {
481
+ return null;
482
+ }
483
+ /**
484
+ * The error that a fallback threw, told apart from the error of the
485
+ * component it stood in for. The fallback's own error is the `cause`.
486
+ */
487
+ function fallbackError(error, componentId) {
488
+ const subject = componentId === void 0 ? "the surface" : componentId;
489
+ return withCause$1(/* @__PURE__ */ new Error(`The error fallback of ${subject} threw: ${error.message}`), error);
490
+ }
491
+ function createFailureLog() {
492
+ const last = /* @__PURE__ */ new Map();
493
+ const released = /* @__PURE__ */ new Set();
494
+ const releasedSinceSettle = /* @__PURE__ */ new Set();
495
+ const heldBack = /* @__PURE__ */ new Map();
496
+ return {
497
+ report(runtime, slot, info, context = "") {
498
+ released.delete(slot);
499
+ const signature = [
500
+ info.kind,
501
+ info.error.name,
502
+ info.error.message,
503
+ context
504
+ ].join("\n");
505
+ if (last.get(slot) === signature) {
506
+ if (releasedSinceSettle.has(slot)) heldBack.set(slot, {
507
+ runtime,
508
+ info,
509
+ signature
510
+ });
511
+ return;
512
+ }
513
+ heldBack.delete(slot);
514
+ last.set(slot, signature);
515
+ reportErrorSafely(runtime, info);
516
+ },
517
+ clear(slot) {
518
+ released.delete(slot);
519
+ last.delete(slot);
520
+ heldBack.delete(slot);
521
+ },
522
+ retain(slot) {
523
+ released.delete(slot);
524
+ },
525
+ release(slot) {
526
+ heldBack.delete(slot);
527
+ if (!last.has(slot)) return;
528
+ released.add(slot);
529
+ releasedSinceSettle.add(slot);
530
+ },
531
+ settle(missed = false) {
532
+ for (const slot of missed ? releasedSinceSettle : released) last.delete(slot);
533
+ if (missed) for (const [slot, { runtime, info, signature }] of heldBack) {
534
+ if (!releasedSinceSettle.has(slot) || last.has(slot)) continue;
535
+ last.set(slot, signature);
536
+ reportErrorSafely(runtime, info);
537
+ }
538
+ heldBack.clear();
539
+ released.clear();
540
+ releasedSinceSettle.clear();
541
+ }
542
+ };
543
+ }
544
+ /** Outside a surface, every failure is reported. */
545
+ const UNLOGGED = {
546
+ report: (runtime, _slot, info) => reportErrorSafely(runtime, info),
547
+ clear: () => {},
548
+ retain: () => {},
549
+ release: () => {},
550
+ settle: () => {}
551
+ };
552
+ /** The failure log of the surface being rendered; set by `SurfaceView`. */
553
+ const GenerativeUIFailureLogContext = createContext(UNLOGGED);
554
+ function useFailureLog() {
555
+ return useContext(GenerativeUIFailureLogContext);
556
+ }
557
+ /**
558
+ * The slots of a failure log, per node place (one rendered copy of a node,
559
+ * see `placeOf` in SurfaceView) and surface boundary.
560
+ */
561
+ const failureSlots = {
562
+ node: (place) => `node ${place}`,
563
+ appFallback: (place) => `app-fallback ${place}`,
564
+ renderFallback: (place) => `render-fallback ${place}`,
565
+ fallback: (place) => `fallback ${place}`,
566
+ cycle: (place) => `cycle ${place}`,
567
+ props: (place) => `props ${place}`,
568
+ surface: (level) => `surface ${level}`,
569
+ surfaceFallback: (level) => `surface-fallback ${level}`
570
+ };
571
+ function sameKeys(a, b) {
572
+ return a.length === b.length && a.every((value, i) => Object.is(value, b[i]));
573
+ }
574
+ var FallbackGuard = class extends Component {
575
+ state = {
576
+ failed: false,
577
+ resetKeys: this.props.resetKeys
578
+ };
579
+ static getDerivedStateFromError(thrown) {
580
+ return {
581
+ failed: true,
582
+ error: toError(thrown)
583
+ };
584
+ }
585
+ static getDerivedStateFromProps(props, state) {
586
+ return sameKeys(props.resetKeys, state.resetKeys) ? null : {
587
+ failed: false,
588
+ error: void 0,
589
+ resetKeys: props.resetKeys
590
+ };
591
+ }
592
+ report(error) {
593
+ const { runtime, surfaceId, componentId, log, slot, context } = this.props;
594
+ log.report(runtime, slot, {
595
+ kind: "render",
596
+ surfaceId,
597
+ ...componentId === void 0 ? {} : { componentId },
598
+ error: fallbackError(error, componentId)
599
+ }, context);
600
+ }
601
+ componentDidCatch(thrown) {
602
+ this.report(this.state.error ?? toError(thrown));
603
+ }
604
+ componentDidMount() {
605
+ if (!this.state.failed) {
606
+ this.props.log.clear(this.props.slot);
607
+ return;
608
+ }
609
+ if (this.state.error) this.report(this.state.error);
610
+ }
611
+ componentDidUpdate() {
612
+ if (!this.state.failed) this.props.log.clear(this.props.slot);
613
+ }
614
+ render() {
615
+ return this.state.failed ? this.props.replacement ?? null : this.props.children;
616
+ }
617
+ };
618
+ /**
619
+ * The host's `NodeFallback`, guarded: when it throws, the node renders
620
+ * nothing and the error is reported, and the parent node keeps rendering.
621
+ * Every place that shows the host fallback goes through this.
622
+ */
623
+ function GuardedNodeFallback({ surfaceId, componentId, runtime, message, retry, slot, revision }) {
624
+ const { NodeFallback } = useGenerativeUIHost();
625
+ return /* @__PURE__ */ jsx(FallbackGuard, {
626
+ surfaceId,
627
+ componentId,
628
+ runtime,
629
+ log: useFailureLog(),
630
+ slot,
631
+ context: message,
632
+ resetKeys: [message, revision],
633
+ children: /* @__PURE__ */ jsx(NodeFallback, {
634
+ message,
635
+ componentId: componentId ?? "surface",
636
+ retry
637
+ })
638
+ });
639
+ }
640
+ /**
641
+ * Calls the app's `errorBoundary.fallback` in a render of its own, so that
642
+ * the guard above it catches what it throws.
643
+ */
644
+ function AppErrorFallback({ render, ...props }) {
645
+ return /* @__PURE__ */ jsx(Fragment$1, { children: render(props) });
646
+ }
647
+ /**
648
+ * Per-node boundary. Resets on retry or a new agent revision, not on data
649
+ * ticks. A failure that stays the same across revisions is reported once.
650
+ */
651
+ var NodeBoundary = class extends Component {
652
+ state = {
653
+ error: null,
654
+ revision: this.props.revision
655
+ };
656
+ static getDerivedStateFromError(thrown) {
657
+ return { error: toError(thrown) };
658
+ }
659
+ static getDerivedStateFromProps(props, state) {
660
+ return props.revision !== state.revision ? {
661
+ error: null,
662
+ revision: props.revision
663
+ } : null;
664
+ }
665
+ componentDidCatch(thrown) {
666
+ const { runtime, surfaceId, componentId, log, place } = this.props;
667
+ log.clear(failureSlots.fallback(place));
668
+ log.report(runtime, failureSlots.node(place), {
669
+ kind: "render",
670
+ surfaceId,
671
+ componentId,
672
+ error: this.state.error ?? toError(thrown)
673
+ });
674
+ }
675
+ slots() {
676
+ const { place } = this.props;
677
+ return [
678
+ failureSlots.node(place),
679
+ failureSlots.appFallback(place),
680
+ failureSlots.renderFallback(place)
681
+ ];
682
+ }
683
+ clearSlots() {
684
+ for (const slot of this.slots()) this.props.log.clear(slot);
685
+ }
686
+ componentDidMount() {
687
+ for (const slot of this.slots()) this.props.log.retain(slot);
688
+ if (!this.state.error) {
689
+ this.clearSlots();
690
+ return;
691
+ }
692
+ const { runtime, surfaceId, componentId, log, place } = this.props;
693
+ log.report(runtime, failureSlots.node(place), {
694
+ kind: "render",
695
+ surfaceId,
696
+ componentId,
697
+ error: this.state.error
698
+ });
699
+ }
700
+ componentDidUpdate(prevProps) {
701
+ if (prevProps.place !== this.props.place) {
702
+ const { log } = this.props;
703
+ log.release(failureSlots.node(prevProps.place));
704
+ log.release(failureSlots.appFallback(prevProps.place));
705
+ log.release(failureSlots.renderFallback(prevProps.place));
706
+ for (const slot of this.slots()) log.retain(slot);
707
+ }
708
+ if (!this.state.error) this.clearSlots();
709
+ }
710
+ componentWillUnmount() {
711
+ for (const slot of this.slots()) this.props.log.release(slot);
712
+ }
713
+ retry = () => this.setState({ error: null });
714
+ render() {
715
+ const { error } = this.state;
716
+ if (!error) return this.props.children;
717
+ const { runtime, surfaceId, componentId, place, log } = this.props;
718
+ const hostFallback = /* @__PURE__ */ jsx(GuardedNodeFallback, {
719
+ surfaceId,
720
+ componentId,
721
+ runtime,
722
+ message: error.message,
723
+ retry: this.retry,
724
+ slot: failureSlots.renderFallback(place)
725
+ });
726
+ const fallback = runtime.errorFallback;
727
+ if (!fallback) return hostFallback;
728
+ return /* @__PURE__ */ jsx(FallbackGuard, {
729
+ surfaceId,
730
+ componentId,
731
+ runtime,
732
+ log,
733
+ slot: failureSlots.appFallback(place),
734
+ context: error.message,
735
+ resetKeys: [error],
736
+ replacement: hostFallback,
737
+ children: /* @__PURE__ */ jsx(AppErrorFallback, {
738
+ render: fallback,
739
+ error,
740
+ retry: this.retry,
741
+ surfaceId,
742
+ componentId
743
+ })
744
+ });
745
+ }
746
+ };
747
+ /**
748
+ * Surface boundary: a failure here must not reach the chat or the host page.
749
+ * It resets on a new revision, and on Retry when `retryable`. A failure that
750
+ * stays the same across revisions is reported once.
751
+ */
752
+ var SurfaceBoundary = class extends Component {
753
+ state = {
754
+ error: null,
755
+ revision: this.props.revision
756
+ };
757
+ static getDerivedStateFromError(thrown) {
758
+ return { error: toError(thrown) };
759
+ }
760
+ static getDerivedStateFromProps(props, state) {
761
+ return props.revision !== state.revision ? {
762
+ error: null,
763
+ revision: props.revision
764
+ } : null;
765
+ }
766
+ componentDidCatch(thrown) {
767
+ const { runtime, surfaceId, log, level } = this.props;
768
+ log.report(runtime, failureSlots.surface(level), {
769
+ kind: "render",
770
+ surfaceId,
771
+ error: this.state.error ?? toError(thrown)
772
+ });
773
+ }
774
+ clearSlots() {
775
+ const { log, level } = this.props;
776
+ log.clear(failureSlots.surface(level));
777
+ log.clear(failureSlots.surfaceFallback(level));
778
+ }
779
+ componentDidMount() {
780
+ if (!this.state.error) this.clearSlots();
781
+ }
782
+ componentDidUpdate() {
783
+ if (!this.state.error) this.clearSlots();
784
+ }
785
+ retry = () => this.setState({ error: null });
786
+ render() {
787
+ if (!this.state.error) return this.props.children;
788
+ return /* @__PURE__ */ jsx(GuardedNodeFallback, {
789
+ surfaceId: this.props.surfaceId,
790
+ componentId: void 0,
791
+ runtime: this.props.runtime,
792
+ message: "this generated UI failed to render",
793
+ retry: this.props.retryable ? this.retry : void 0,
794
+ slot: failureSlots.surfaceFallback(this.props.level)
795
+ });
796
+ }
797
+ };
798
+
799
+ //#endregion
800
+ //#region src/generative-ui/accessibility.ts
801
+ /**
802
+ * Experimental. The ARIA attributes of the `accessibility` that the model
803
+ * gave the component being rendered, to spread on its root element. The
804
+ * standard components do this; a custom component does it itself:
805
+ *
806
+ * @example
807
+ * ```tsx
808
+ * function Panel({ children }: { children?: ReactNode }) {
809
+ * const aria = useGenerativeUIAccessibility();
810
+ * return <section {...aria}>{children}</section>;
811
+ * }
812
+ * ```
813
+ *
814
+ * Outside of generated UI it gives `{}`.
815
+ */
816
+ function useGenerativeUIAccessibility() {
817
+ const accessibility = useContext(GenerativeUINodeContext)?.accessibility;
818
+ return useMemo(() => accessibilityAttributes(accessibility), [accessibility]);
819
+ }
820
+
821
+ //#endregion
822
+ //#region src/generative-ui/SurfaceView.tsx
823
+ const NO_ANCESTORS = [];
824
+ const undefinedSnapshot = () => void 0;
825
+ const noopSubscribe = () => () => {};
826
+ const zeroSnapshot = () => 0;
827
+ /** A "multiple" slot value that repeats a component for each list item. */
828
+ function isTemplateChildren(value) {
829
+ return typeof value === "object" && value !== null && "componentId" in value && typeof value.componentId === "string" && "path" in value && typeof value.path === "string";
830
+ }
831
+ function SurfaceView({ surface }) {
832
+ const runtime = useRequiredGenerativeUIRuntime();
833
+ const { SurfaceRoot } = useGenerativeUIHost();
834
+ const appliedCount = useSyncExternalStore(runtime.manager.subscribe, () => surface.operations.length, undefinedSnapshot);
835
+ const revision = useMemo(() => ({
836
+ surface,
837
+ appliedCount
838
+ }), [surface, appliedCount]);
839
+ const [scopedLog, setScopedLog] = useState(() => ({
840
+ key: surface.key,
841
+ log: createFailureLog()
842
+ }));
843
+ let failureLog = scopedLog.log;
844
+ if (scopedLog.key !== surface.key) {
845
+ const next = {
846
+ key: surface.key,
847
+ log: createFailureLog()
848
+ };
849
+ setScopedLog(next);
850
+ failureLog = next.log;
851
+ }
852
+ const { threadId, surfaceId } = surface;
853
+ const { manager } = runtime;
854
+ const seen = useRef(void 0);
855
+ useLayoutEffect(() => {
856
+ const contentOf = () => {
857
+ const current = manager.getSurface(threadId, surfaceId);
858
+ return {
859
+ log: failureLog,
860
+ current,
861
+ applied: current?.operations.length
862
+ };
863
+ };
864
+ const observe = (missed) => {
865
+ const last = seen.current;
866
+ const next = contentOf();
867
+ seen.current = next;
868
+ if (last?.log === failureLog && (next.current !== last.current || next.applied !== last.applied)) failureLog.settle(missed);
869
+ };
870
+ observe(true);
871
+ return manager.subscribe(() => observe(false));
872
+ }, [
873
+ manager,
874
+ threadId,
875
+ surfaceId,
876
+ failureLog
877
+ ]);
878
+ return /* @__PURE__ */ jsx(GenerativeUIFailureLogContext.Provider, {
879
+ value: failureLog,
880
+ children: /* @__PURE__ */ jsx(SurfaceBoundary, {
881
+ surfaceId: surface.surfaceId,
882
+ runtime,
883
+ log: failureLog,
884
+ level: "outer",
885
+ revision,
886
+ retryable: true,
887
+ children: /* @__PURE__ */ jsx(SurfaceRoot, {
888
+ surfaceId: surface.surfaceId,
889
+ theme: runtime.theme,
890
+ children: /* @__PURE__ */ jsx(SurfaceBoundary, {
891
+ surfaceId: surface.surfaceId,
892
+ runtime,
893
+ log: failureLog,
894
+ level: "inner",
895
+ revision,
896
+ children: /* @__PURE__ */ jsx(NodeView, {
897
+ surface,
898
+ componentId: GENERATIVE_UI_ROOT_ID,
899
+ basePath: void 0,
900
+ ancestors: NO_ANCESTORS,
901
+ parentPlace: "",
902
+ via: ""
903
+ })
904
+ })
905
+ })
906
+ })
907
+ });
908
+ }
909
+ /**
910
+ * Resolves a component by id. Subscribes to the manager rather than web_core's
911
+ * `onCreated`/`onDeleted`: web_core's EventEmitter awaits each listener in turn,
912
+ * so with several subscribers (one per slotted child, or one per mount of the
913
+ * same surface) all but the first are notified a microtask late. That is only
914
+ * visible inside synchronous flushes such as `act()` / `flushSync`, where the
915
+ * old tree would still be on screen, but it makes updates order-dependent.
916
+ * The manager notifies synchronously once an ingest has been fully applied.
917
+ */
918
+ function useComponentModel(manager, model, id) {
919
+ return useSyncExternalStore(manager.subscribe, () => model.componentsModel.get(id), undefinedSnapshot);
920
+ }
921
+ /** Same reasoning as `useComponentModel`: never rely on web_core's emitters. */
922
+ function useComponentProperties(manager, component) {
923
+ return useSyncExternalStore(manager.subscribe, () => component?.properties, undefinedSnapshot);
924
+ }
925
+ /**
926
+ * The id of a node in the ancestor list. A template renders the same
927
+ * component once per item, so the item path is part of the id. A real cycle
928
+ * repeats both.
929
+ */
930
+ function scopedId(componentId, basePath) {
931
+ return `${basePath === void 0 ? "" : JSON.stringify(basePath)}#${JSON.stringify(componentId)}`;
932
+ }
933
+ /**
934
+ * Where one rendered copy of a node is: the place of its parent, the slot
935
+ * or child reference of the parent it renders in, and its scoped id. Names
936
+ * the node's failure-log slots. A scoped id alone is not enough: the same
937
+ * id can render under two parents, and a cyclic reference repeats the
938
+ * scoped id of an ancestor. Each copy keeps its own memory of what it
939
+ * reported, so one copy that renders, goes away or remounts does not clear
940
+ * the memory of another that still fails.
941
+ */
942
+ function placeOf(parentPlace, via, position) {
943
+ return `${parentPlace}/${via === "" ? "" : JSON.stringify(via)}${position}`;
944
+ }
945
+ const NodeView = memo(function NodeView({ surface, componentId, basePath, ancestors, parentPlace, via }) {
946
+ const runtime = useRequiredGenerativeUIRuntime();
947
+ const log = useFailureLog();
948
+ const component = useComponentModel(runtime.manager, surface.model, componentId);
949
+ const properties = useComponentProperties(runtime.manager, component);
950
+ const position = scopedId(componentId, basePath);
951
+ const place = placeOf(parentPlace, via, position);
952
+ useEffect(() => {
953
+ const slots = [
954
+ failureSlots.fallback(place),
955
+ failureSlots.cycle(place),
956
+ failureSlots.props(place)
957
+ ];
958
+ for (const slot of slots) log.retain(slot);
959
+ return () => {
960
+ for (const slot of slots) log.release(slot);
961
+ };
962
+ }, [log, place]);
963
+ if (ancestors.includes(position)) return /* @__PURE__ */ jsx(GuardedNodeFallback, {
964
+ surfaceId: surface.surfaceId,
965
+ componentId,
966
+ runtime,
967
+ message: `cyclic reference to ${componentId}`,
968
+ slot: failureSlots.cycle(place),
969
+ revision: properties
970
+ });
971
+ if (!component || !properties) return /* @__PURE__ */ jsx(NodePlaceholder, { componentId });
972
+ const definition = runtime.ui.components.get(component.type);
973
+ if (!definition) return /* @__PURE__ */ jsx(GuardedNodeFallback, {
974
+ surfaceId: surface.surfaceId,
975
+ componentId,
976
+ runtime,
977
+ message: `unknown component "${component.type}"`,
978
+ slot: failureSlots.fallback(place),
979
+ revision: properties
980
+ });
981
+ return /* @__PURE__ */ jsx(NodeBoundary, {
982
+ surfaceId: surface.surfaceId,
983
+ componentId,
984
+ place,
985
+ revision: properties,
986
+ runtime,
987
+ log,
988
+ children: /* @__PURE__ */ jsx(ResolvedNode, {
989
+ surface,
990
+ componentId,
991
+ definition,
992
+ properties,
993
+ runtime,
994
+ basePath,
995
+ ancestors,
996
+ place
997
+ })
998
+ }, component.type);
999
+ });
1000
+ /**
1001
+ * Renders the component of a template once for each item of the list at the
1002
+ * template path, keyed by index. Renders nothing when there is no list.
1003
+ */
1004
+ function TemplateChildren({ surface, template, basePath, ancestors, parentPlace, via }) {
1005
+ const dataModel = surface.model.dataModel;
1006
+ const listPath = resolvePath(template.path, basePath);
1007
+ const subscribe = useCallback((onChange) => {
1008
+ const subscription = dataModel.subscribe(listPath, onChange);
1009
+ return () => subscription.unsubscribe();
1010
+ }, [dataModel, listPath]);
1011
+ const getCount = () => {
1012
+ const list = dataModel.get(listPath);
1013
+ return Array.isArray(list) ? list.length : 0;
1014
+ };
1015
+ const count = useSyncExternalStore(subscribe, getCount, zeroSnapshot);
1016
+ return /* @__PURE__ */ jsx(Fragment$1, { children: Array.from({ length: count }, (_, index) => index).map((index) => /* @__PURE__ */ jsx(NodeView, {
1017
+ surface,
1018
+ componentId: template.componentId,
1019
+ basePath: joinPath(listPath, String(index)),
1020
+ ancestors,
1021
+ parentPlace,
1022
+ via
1023
+ }, index)) });
1024
+ }
1025
+ /**
1026
+ * The props the model sets, with their dynamic values resolved from the
1027
+ * surface data model: `{"@path"}` bindings, `{"@call"}` function values and
1028
+ * `{"@call":"@index"}` in a template, at any depth. Bound props, events and
1029
+ * slots are left out, and so are the keys of the A2UI component envelope;
1030
+ * `accessibility` is resolved the same way and given on its own.
1031
+ *
1032
+ * A writable prop that is not bound to a path and that the component set
1033
+ * shows the local value from `overrides`, also when the model never set the
1034
+ * prop. That is intended: the user's edit wins over the model's literal
1035
+ * value, also over a newer literal the agent sends later, until the node
1036
+ * remounts. A literal is not data the agent and the user share; a prop
1037
+ * that both must write is bound to a path, and the setter writes the data
1038
+ * model.
1039
+ *
1040
+ * A prop is resolved again only when its raw value or a data model value it
1041
+ * read has changed, so the result keeps its identity otherwise. A function
1042
+ * value that cannot be computed gives a problem instead of values.
1043
+ */
1044
+ function useModelDataProps(surface, definition, properties, basePath, overrides) {
1045
+ const dataModel = surface.model.dataModel;
1046
+ const units = useMemo(() => {
1047
+ const list = [];
1048
+ for (const key of Object.keys(properties)) {
1049
+ if (definition.events?.[key] || definition.slots?.[key] || hasOwnKey(definition.selectors, key) || A2UI_COMPONENT_ENVELOPE_KEYS.has(key)) continue;
1050
+ list.push({
1051
+ key,
1052
+ raw: properties[key]
1053
+ });
1054
+ }
1055
+ const a11y = properties.accessibility;
1056
+ if (typeof a11y === "object" && a11y !== null && !Array.isArray(a11y)) for (const [field, raw] of Object.entries(a11y)) list.push({
1057
+ key: `accessibility/${field}`,
1058
+ raw,
1059
+ field
1060
+ });
1061
+ return list;
1062
+ }, [properties, definition]);
1063
+ const [, rerender] = useReducer((n) => n + 1, 0);
1064
+ const cache = useRef(/* @__PURE__ */ new Map());
1065
+ const values = {};
1066
+ const a11yValues = {};
1067
+ const paths = /* @__PURE__ */ new Set();
1068
+ let problem;
1069
+ const next = /* @__PURE__ */ new Map();
1070
+ for (const { key, raw, field } of units) {
1071
+ const cached = cache.current.get(key);
1072
+ const isFresh = cached !== void 0 && cached.raw === raw && cached.basePath === basePath && [...cached.reads].every(([path, value]) => Object.is(dataModel.get(path), value));
1073
+ const resolve = () => {
1074
+ const resolved = tryResolveDynamicValue(raw, {
1075
+ data: dataModel,
1076
+ basePath
1077
+ }, { isChecks: key === "checks" });
1078
+ const reads = /* @__PURE__ */ new Map();
1079
+ for (const path of resolved.paths) reads.set(path, dataModel.get(path));
1080
+ return {
1081
+ raw,
1082
+ basePath,
1083
+ reads,
1084
+ outcome: resolved.ok ? {
1085
+ ok: true,
1086
+ value: resolved.value
1087
+ } : {
1088
+ ok: false,
1089
+ message: resolved.error.message
1090
+ }
1091
+ };
1092
+ };
1093
+ const entry = isFresh && cached ? cached : resolve();
1094
+ next.set(key, entry);
1095
+ if (field !== void 0) {
1096
+ if (entry.outcome.ok) a11yValues[field] = entry.outcome.value;
1097
+ } else if (entry.outcome.ok) values[key] = entry.outcome.value;
1098
+ else problem ??= `${key}: ${entry.outcome.message}`;
1099
+ for (const path of entry.reads.keys()) paths.add(path);
1100
+ }
1101
+ cache.current = next;
1102
+ const accessibility = readAccessibility(a11yValues);
1103
+ for (const [key, value] of Object.entries(overrides)) if (!isPathBinding(properties[key])) values[key] = value;
1104
+ const rendered = useRef(next);
1105
+ rendered.current = next;
1106
+ const pathKey = [...paths].sort().join("\n");
1107
+ useEffect(() => {
1108
+ const list = pathKey === "" ? [] : pathKey.split("\n");
1109
+ const onChange = () => {
1110
+ cache.current = /* @__PURE__ */ new Map();
1111
+ rerender();
1112
+ };
1113
+ const subscriptions = list.map((path) => dataModel.subscribe(path, onChange));
1114
+ if ([...rendered.current.values()].some((entry) => [...entry.reads].some(([path, value]) => !Object.is(dataModel.get(path), value)))) rerender();
1115
+ return () => subscriptions.forEach((s) => s.unsubscribe());
1116
+ }, [dataModel, pathKey]);
1117
+ const stable = useRef({
1118
+ ok: true,
1119
+ values: {},
1120
+ accessibility: void 0
1121
+ });
1122
+ const result = problem === void 0 ? {
1123
+ ok: true,
1124
+ values,
1125
+ accessibility
1126
+ } : {
1127
+ ok: false,
1128
+ problem
1129
+ };
1130
+ const last = stable.current;
1131
+ if (!(result.ok && last.ok ? shallowEqual(last.values, result.values) && shallowEqual(last.accessibility ?? {}, result.accessibility ?? {}) : !result.ok && !last.ok && last.problem === result.problem)) stable.current = result;
1132
+ return stable.current;
1133
+ }
1134
+ const NO_SELECTION = {
1135
+ ok: true,
1136
+ values: {}
1137
+ };
1138
+ function isSameSelection(a, b) {
1139
+ if (a.ok && b.ok) return shallowEqual(a.values, b.values);
1140
+ if (!a.ok && !b.ok) return a.problem === b.problem;
1141
+ return false;
1142
+ }
1143
+ /** Runs every selector of a node. A selector that throws gives a problem. */
1144
+ function select(definition, state, modelProps) {
1145
+ const values = {};
1146
+ const selectors = Object.entries(definition.selectors);
1147
+ for (const [key, selector] of selectors) try {
1148
+ values[key] = selector(state, modelProps);
1149
+ } catch (error) {
1150
+ const { message } = toError(error);
1151
+ return {
1152
+ ok: false,
1153
+ problem: `${key}: selector threw: ${message}`
1154
+ };
1155
+ }
1156
+ return {
1157
+ ok: true,
1158
+ values
1159
+ };
1160
+ }
1161
+ /**
1162
+ * The values of the bound props of a node, read from the app state.
1163
+ *
1164
+ * The selectors get the checked model props: the resolved values that
1165
+ * passed the props schema (without the nulls it rejected), not the
1166
+ * schema's parsed output, so its defaults and transforms are not applied
1167
+ * yet. They run again only when the state object or those props change. When the new values are shallow-equal to the last ones, the
1168
+ * last snapshot is kept. So the node re-renders only when a selected value
1169
+ * changes. A selector that returns a new array on each call cannot cause a
1170
+ * render loop: with the same inputs, the cached snapshot comes back.
1171
+ *
1172
+ * A node without bound props does not subscribe to the state.
1173
+ */
1174
+ function useSelection(manager, definition, modelProps) {
1175
+ const hasSelectors = Object.keys(definition.selectors).length > 0;
1176
+ const cache = useRef(void 0);
1177
+ const getSnapshot = () => {
1178
+ if (!hasSelectors || modelProps === void 0) return NO_SELECTION;
1179
+ const state = manager.getState();
1180
+ const cached = cache.current;
1181
+ if (cached !== void 0 && cached.state === state && cached.modelProps === modelProps) return cached.selection;
1182
+ const next = select(definition, state, modelProps);
1183
+ const selection = cached !== void 0 && isSameSelection(cached.selection, next) ? cached.selection : next;
1184
+ cache.current = {
1185
+ state,
1186
+ modelProps,
1187
+ selection
1188
+ };
1189
+ return selection;
1190
+ };
1191
+ return useSyncExternalStore(hasSelectors ? manager.subscribe : noopSubscribe, getSnapshot, getSnapshot);
1192
+ }
1193
+ /**
1194
+ * Checks the model-set props with the props schema before the selectors run.
1195
+ * The bound props are not set yet, so their issues do not count. Neither do
1196
+ * issues with no path (a check over several props), which the full check
1197
+ * after the selectors reports. The exception is the issue that an async
1198
+ * props schema gives (`isAsyncIssue`): the render checks props
1199
+ * synchronously only, so the full check would fail the same way, and it is
1200
+ * reported here.
1201
+ */
1202
+ function checkModelProps(definition, modelData) {
1203
+ if (!definition.props) return {
1204
+ ok: true,
1205
+ values: {}
1206
+ };
1207
+ let values = modelData;
1208
+ let result = validateSchemaSync(definition.props, values);
1209
+ if (!result.success) {
1210
+ const unset = withoutRejectedNulls(values, result.issues);
1211
+ if (unset) {
1212
+ values = unset;
1213
+ result = validateSchemaSync(definition.props, values);
1214
+ }
1215
+ }
1216
+ if (!result.success) {
1217
+ const issues = result.issues.filter((issue) => {
1218
+ const key = issueKey(issue);
1219
+ return key === void 0 ? isAsyncIssue(issue) : !hasOwnKey(definition.selectors, key);
1220
+ });
1221
+ if (issues.length > 0) return {
1222
+ ok: false,
1223
+ problem: formatIssues(issues)
1224
+ };
1225
+ }
1226
+ return {
1227
+ ok: true,
1228
+ values
1229
+ };
1230
+ }
1231
+ /**
1232
+ * The data props of a node, in three steps: check the model-set props with
1233
+ * the props schema, run the selectors with them, then parse all props with
1234
+ * the props schema. Gives the reason when a step fails.
1235
+ */
1236
+ function useDataProps(runtime, surface, definition, properties, basePath, overrides) {
1237
+ const modelData = useModelDataProps(surface, definition, properties, basePath, overrides);
1238
+ const modelCheck = useMemo(() => modelData.ok ? checkModelProps(definition, modelData.values) : modelData, [definition, modelData]);
1239
+ const selection = useSelection(runtime.manager, definition, modelCheck.ok ? modelCheck.values : void 0);
1240
+ const accessibility = modelData.ok ? modelData.accessibility : void 0;
1241
+ return useMemo(() => {
1242
+ if (!modelCheck.ok) return modelCheck;
1243
+ if (!selection.ok) return selection;
1244
+ if (!definition.props) return {
1245
+ ok: true,
1246
+ props: {},
1247
+ accessibility
1248
+ };
1249
+ const input = {
1250
+ ...modelCheck.values,
1251
+ ...selection.values
1252
+ };
1253
+ let parsed = validateSchemaSync(definition.props, input);
1254
+ if (!parsed.success) {
1255
+ const unset = withoutRejectedNulls(input, parsed.issues);
1256
+ if (unset) parsed = validateSchemaSync(definition.props, unset);
1257
+ }
1258
+ if (!parsed.success) return {
1259
+ ok: false,
1260
+ problem: formatIssues(parsed.issues)
1261
+ };
1262
+ return {
1263
+ ok: true,
1264
+ props: parsed.data,
1265
+ accessibility
1266
+ };
1267
+ }, [
1268
+ definition,
1269
+ modelCheck,
1270
+ selection,
1271
+ accessibility
1272
+ ]);
1273
+ }
1274
+ /**
1275
+ * The event props of a node. A matched event (one that matches a declared
1276
+ * function) is always bound. An unmatched event is bound only when the model
1277
+ * bound it.
1278
+ */
1279
+ function useEventProps(runtime, surface, componentId, definition, properties, basePath) {
1280
+ const latest = useRef(properties);
1281
+ latest.current = properties;
1282
+ const boundNames = Object.keys(definition.events ?? {}).filter((name) => hasOwnKey(definition.eventFunctions, name) || isActionBinding(properties[name])).join("|");
1283
+ return useMemo(() => {
1284
+ const handlers = {};
1285
+ const names = boundNames ? boundNames.split("|") : [];
1286
+ for (const name of names) {
1287
+ const call = {
1288
+ runtime,
1289
+ surface,
1290
+ componentId,
1291
+ name,
1292
+ parameters: definition.events?.[name]?.parameters
1293
+ };
1294
+ const functionName = hasOwnKey(definition.eventFunctions, name) ? definition.eventFunctions[name] : void 0;
1295
+ handlers[name] = functionName === void 0 ? (args) => invokeBoundEvent({
1296
+ ...call,
1297
+ binding: latest.current[name],
1298
+ basePath,
1299
+ args
1300
+ }) : (args) => invokeMatchedEvent({
1301
+ ...call,
1302
+ functionName,
1303
+ args
1304
+ });
1305
+ }
1306
+ return handlers;
1307
+ }, [
1308
+ boundNames,
1309
+ runtime,
1310
+ surface,
1311
+ componentId,
1312
+ definition,
1313
+ basePath
1314
+ ]);
1315
+ }
1316
+ /**
1317
+ * The setter props of a node: `setValue` for the writable prop `value`. For
1318
+ * a prop the model bound to `{"@path"}`, the setter writes the data model
1319
+ * and makes the path user-owned. For a literal prop, it sets `overrides`, a
1320
+ * local value of this mounted node that wins over the model's value until
1321
+ * the node remounts (see `useModelDataProps`). The setters keep their
1322
+ * identity.
1323
+ */
1324
+ function useSetterProps(runtime, surface, componentId, definition, properties, basePath) {
1325
+ const [overrides, setOverrides] = useState({});
1326
+ const latest = useRef(properties);
1327
+ latest.current = properties;
1328
+ return {
1329
+ overrides,
1330
+ setters: useMemo(() => {
1331
+ const result = {};
1332
+ const writable = definition.writable ?? [];
1333
+ for (const key of writable) result[setterNameOf(key)] = (value) => {
1334
+ const binding = latest.current[key];
1335
+ if (!isPathBinding(binding)) {
1336
+ setOverrides((current) => ({
1337
+ ...current,
1338
+ [key]: value
1339
+ }));
1340
+ return;
1341
+ }
1342
+ try {
1343
+ runtime.manager.setOwnedValue(surface.key, resolvePath(binding["@path"], basePath), value);
1344
+ } catch (cause) {
1345
+ const { message } = toError(cause);
1346
+ reportErrorSafely(runtime, {
1347
+ kind: "props",
1348
+ surfaceId: surface.surfaceId,
1349
+ componentId,
1350
+ error: /* @__PURE__ */ new Error(`${setterNameOf(key)}: ${message}`)
1351
+ });
1352
+ }
1353
+ };
1354
+ return result;
1355
+ }, [
1356
+ runtime,
1357
+ surface,
1358
+ componentId,
1359
+ definition,
1360
+ basePath
1361
+ ])
1362
+ };
1363
+ }
1364
+ function useSlotProps(surface, definition, properties, componentId, basePath, ancestors, place) {
1365
+ return useMemo(() => {
1366
+ const childAncestors = [...ancestors, scopedId(componentId, basePath)];
1367
+ const slots = {};
1368
+ for (const [name, kind] of Object.entries(definition.slots ?? {})) {
1369
+ const value = properties[name];
1370
+ const via = `${name}:`;
1371
+ if (kind === "single" && typeof value === "string") slots[name] = /* @__PURE__ */ jsx(NodeView, {
1372
+ surface,
1373
+ componentId: value,
1374
+ basePath,
1375
+ ancestors: childAncestors,
1376
+ parentPlace: place,
1377
+ via
1378
+ });
1379
+ else if (kind === "multiple" && isTemplateChildren(value)) slots[name] = /* @__PURE__ */ jsx(TemplateChildren, {
1380
+ surface,
1381
+ template: value,
1382
+ basePath,
1383
+ ancestors: childAncestors,
1384
+ parentPlace: place,
1385
+ via
1386
+ });
1387
+ else if (kind === "multiple" && Array.isArray(value)) slots[name] = [...new Set(value.filter((id) => typeof id === "string"))].map((id) => /* @__PURE__ */ jsx(NodeView, {
1388
+ surface,
1389
+ componentId: id,
1390
+ basePath,
1391
+ ancestors: childAncestors,
1392
+ parentPlace: place,
1393
+ via
1394
+ }, id));
1395
+ }
1396
+ return slots;
1397
+ }, [
1398
+ surface,
1399
+ definition,
1400
+ properties,
1401
+ componentId,
1402
+ basePath,
1403
+ ancestors,
1404
+ place
1405
+ ]);
1406
+ }
1407
+ /**
1408
+ * The parsed data props with every typed child reference (`child()`,
1409
+ * `childList()`, at any depth) replaced by the rendered component. Without
1410
+ * references, the parsed props come back as they are.
1411
+ */
1412
+ function useChildRefProps(surface, refs, props, componentId, basePath, ancestors, place) {
1413
+ return useMemo(() => {
1414
+ if (props === void 0 || refs.length === 0) return props;
1415
+ const childAncestors = [...ancestors, scopedId(componentId, basePath)];
1416
+ const render = (kind, value, via) => {
1417
+ if (kind === "single") return typeof value === "string" ? /* @__PURE__ */ jsx(NodeView, {
1418
+ surface,
1419
+ componentId: value,
1420
+ basePath,
1421
+ ancestors: childAncestors,
1422
+ parentPlace: place,
1423
+ via
1424
+ }) : void 0;
1425
+ if (isTemplateChildren(value)) return /* @__PURE__ */ jsx(TemplateChildren, {
1426
+ surface,
1427
+ template: value,
1428
+ basePath,
1429
+ ancestors: childAncestors,
1430
+ parentPlace: place,
1431
+ via
1432
+ });
1433
+ if (!Array.isArray(value)) return void 0;
1434
+ return [...new Set(value.filter((id) => typeof id === "string"))].map((id) => /* @__PURE__ */ jsx(NodeView, {
1435
+ surface,
1436
+ componentId: id,
1437
+ basePath,
1438
+ ancestors: childAncestors,
1439
+ parentPlace: place,
1440
+ via
1441
+ }, id));
1442
+ };
1443
+ let result = props;
1444
+ for (const ref of refs) {
1445
+ let found = 0;
1446
+ const path = ref.path.join(".");
1447
+ result = mapAtChildRef(result, ref.path, (value) => render(ref.kind, value, `${path}[${found++}]:`));
1448
+ }
1449
+ return result;
1450
+ }, [
1451
+ surface,
1452
+ refs,
1453
+ props,
1454
+ componentId,
1455
+ basePath,
1456
+ ancestors,
1457
+ place
1458
+ ]);
1459
+ }
1460
+ function ResolvedNode({ surface, componentId, definition, properties, runtime, basePath, ancestors, place }) {
1461
+ const { AccessibilityWrapper } = useGenerativeUIHost();
1462
+ const { overrides, setters } = useSetterProps(runtime, surface, componentId, definition, properties, basePath);
1463
+ const dataProps = useDataProps(runtime, surface, definition, properties, basePath, overrides);
1464
+ const eventProps = useEventProps(runtime, surface, componentId, definition, properties, basePath);
1465
+ const slotProps = useSlotProps(surface, definition, properties, componentId, basePath, ancestors, place);
1466
+ const childRefProps = useChildRefProps(surface, definition.childRefs, dataProps.ok ? dataProps.props : void 0, componentId, basePath, ancestors, place);
1467
+ const accessibility = dataProps.ok ? dataProps.accessibility : void 0;
1468
+ const nodeContext = useMemo(() => ({
1469
+ surfaceKey: surface.key,
1470
+ surfaceId: surface.surfaceId,
1471
+ componentId,
1472
+ accessibility
1473
+ }), [
1474
+ surface.key,
1475
+ surface.surfaceId,
1476
+ componentId,
1477
+ accessibility
1478
+ ]);
1479
+ const problem = dataProps.ok ? void 0 : dataProps.problem;
1480
+ const log = useFailureLog();
1481
+ useEffect(() => {
1482
+ if (!problem) {
1483
+ log.clear(failureSlots.fallback(place));
1484
+ log.clear(failureSlots.props(place));
1485
+ }
1486
+ }, [
1487
+ problem,
1488
+ log,
1489
+ place
1490
+ ]);
1491
+ useEffect(() => {
1492
+ if (problem) log.report(runtime, failureSlots.props(place), {
1493
+ kind: "props",
1494
+ surfaceId: surface.surfaceId,
1495
+ componentId,
1496
+ error: /* @__PURE__ */ new Error(`Invalid props: ${problem}`)
1497
+ });
1498
+ }, [
1499
+ problem,
1500
+ log,
1501
+ place,
1502
+ runtime,
1503
+ surface.surfaceId,
1504
+ componentId
1505
+ ]);
1506
+ if (!dataProps.ok) return /* @__PURE__ */ jsx(GuardedNodeFallback, {
1507
+ surfaceId: surface.surfaceId,
1508
+ componentId,
1509
+ runtime,
1510
+ message: `invalid props (${problem})`,
1511
+ slot: failureSlots.fallback(place),
1512
+ revision: properties
1513
+ });
1514
+ const Component = definition.component;
1515
+ const rendered = /* @__PURE__ */ jsx(Component, {
1516
+ ...childRefProps,
1517
+ ...eventProps,
1518
+ ...slotProps,
1519
+ ...setters
1520
+ });
1521
+ const hasEnvelope = properties.accessibility !== void 0 && definition.accessibility !== "self";
1522
+ return /* @__PURE__ */ jsx(GenerativeUINodeContext.Provider, {
1523
+ value: nodeContext,
1524
+ children: hasEnvelope ? /* @__PURE__ */ jsx(AccessibilityWrapper, {
1525
+ attributes: wrapperAria(accessibilityAttributes$1(accessibility)),
1526
+ children: rendered
1527
+ }) : rendered
1528
+ });
1529
+ }
1530
+
1531
+ //#endregion
1532
+ //#region src/generative-ui/chat.tsx
1533
+ const GenerativeUIChatSlotContext = createContext(void 0);
1534
+ function DefaultGenerativeUIChatCard({ surfaceId, error, children }) {
1535
+ return /* @__PURE__ */ jsxs("div", {
1536
+ "data-generative-ui-chat-surface": surfaceId,
1537
+ className: "cpk-generative-ui-chat-card",
1538
+ children: [children, error && /* @__PURE__ */ jsx("div", {
1539
+ role: "alert",
1540
+ className: "cpk-generative-ui-chat-card-error",
1541
+ children: "Part of this UI couldn't be shown."
1542
+ })]
1543
+ });
1544
+ }
1545
+ function GenerativeUIChatActivity({ content, agent }) {
1546
+ const runtime = useGenerativeUIRuntime();
1547
+ const threadId = useCopilotChatConfiguration()?.threadId ?? agent?.threadId;
1548
+ const Wrapper = useContext(GenerativeUIChatSlotContext) ?? DefaultGenerativeUIChatCard;
1549
+ const { surface, rejected, error } = useGenerativeUIActivitySurface({
1550
+ runtime,
1551
+ threadId,
1552
+ agentId: agent?.agentId,
1553
+ content,
1554
+ target: GENERATIVE_UI_CHAT_TARGET
1555
+ });
1556
+ if (!surface) return null;
1557
+ return /* @__PURE__ */ jsx(Wrapper, {
1558
+ surfaceId: content.surfaceId,
1559
+ isStreaming: content.status === "streaming",
1560
+ error,
1561
+ rejected,
1562
+ children: surface.failed ? null : /* @__PURE__ */ jsx(SurfaceView, { surface })
1563
+ });
1564
+ }
1565
+ function createGenerativeUIActivityRenderer() {
1566
+ return {
1567
+ activityType: GENERATIVE_UI_ACTIVITY_TYPE,
1568
+ content: GenerativeUISurfaceContentSchema,
1569
+ render: GenerativeUIChatActivity
1570
+ };
1571
+ }
1572
+ /**
1573
+ * Shows nothing in the chat for an agent-called function. The root reads the
1574
+ * function-call activities from the messages and runs them. This renderer
1575
+ * only keeps a wildcard ("*") activity renderer from showing them.
1576
+ */
1577
+ function createGenerativeUIFunctionCallActivityRenderer() {
1578
+ return {
1579
+ activityType: GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE,
1580
+ content: z.unknown(),
1581
+ render: () => null
1582
+ };
1583
+ }
1584
+ /** Hides the raw `render_ui` tool call; the surface activity owns the UX. */
1585
+ function GenerativeUIToolCallRenderer() {
1586
+ const { copilotkit } = useCopilotKit();
1587
+ useEffect(() => {
1588
+ const renderer = defineToolCallRenderer({
1589
+ name: GENERATIVE_UI_RENDER_TOOL,
1590
+ args: z.any(),
1591
+ render: () => /* @__PURE__ */ jsx(Fragment$1, {})
1592
+ });
1593
+ return copilotkit.ɵaddBuiltInRenderToolCall(renderer);
1594
+ }, [copilotkit]);
1595
+ return null;
1596
+ }
1597
+
1598
+ //#endregion
1599
+ export { shallowEqual as A, GenerativeUIRuntimeContext as C, ControlledModalOpenScope as D, defineToolCallRenderer as E, CopilotChatConfigurationProvider as O, GenerativeUINodeContext as S, useRequiredGenerativeUIRuntime as T, useGenerativeUIActivitySurface as _, createGenerativeUIFunctionCallActivityRenderer as a, useGenerativeUIState as b, namedRole as c, GenerativeUIHostContext as d, useGenerativeUIHost as f, parseGenerativeUISurfaceContent as g, GenerativeUISurfaceContentSchema as h, createGenerativeUIActivityRenderer as i, useShallowStableRef as j, useCopilotChatConfiguration as k, useGenerativeUIAccessibility as l, createGenerativeUI$1 as m, GenerativeUIChatSlotContext as n, SurfaceView as o, catalogIdsOf as p, GenerativeUIToolCallRenderer as r, controlAria as s, DefaultGenerativeUIChatCard as t, wrapperAria as u, useGenerativeUIRejected as v, useGenerativeUIRuntime as w, useManagerVersion as x, useGenerativeUIFunction as y };
1600
+ //# sourceMappingURL=chat-Bf0vVdo7.mjs.map