@copilotkit/react-core 2.0.0-rc.6 → 2.0.0-rc.60

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