@copilotkit/react-core 2.0.0-rc.37 → 2.0.0-rc.39

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 (61) hide show
  1. package/dist/MarkdownRendererContext-BL8ct_3U.d.mts +34 -0
  2. package/dist/MarkdownRendererContext-BL8ct_3U.d.mts.map +1 -0
  3. package/dist/MarkdownRendererContext-C2J_lgqF.d.cts +34 -0
  4. package/dist/MarkdownRendererContext-C2J_lgqF.d.cts.map +1 -0
  5. package/dist/MarkdownSurfaces-Byz821bg.mjs +324 -0
  6. package/dist/MarkdownSurfaces-Byz821bg.mjs.map +1 -0
  7. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs +378 -0
  8. package/dist/MarkdownSurfaces-D2Ck-cbb.cjs.map +1 -0
  9. package/dist/{MarkdownSurfaces-BQ1HGCzB.mjs → chat-Bf0vVdo7.mjs} +642 -484
  10. package/dist/chat-Bf0vVdo7.mjs.map +1 -0
  11. package/dist/{MarkdownSurfaces-BFoO6wSB.cjs → chat-D3fxo6Ah.cjs} +663 -529
  12. package/dist/chat-D3fxo6Ah.cjs.map +1 -0
  13. package/dist/{MarkdownRendererContext-CPfNVyde.d.mts → chat-DgP2N7bD.d.mts} +31 -39
  14. package/dist/chat-DgP2N7bD.d.mts.map +1 -0
  15. package/dist/{MarkdownRendererContext-iOl2pj9l.d.cts → chat-DtHs4alO.d.cts} +31 -39
  16. package/dist/chat-DtHs4alO.d.cts.map +1 -0
  17. package/dist/generative-ui/native.cjs +66 -0
  18. package/dist/generative-ui/native.cjs.map +1 -0
  19. package/dist/generative-ui/native.d.cts +155 -0
  20. package/dist/generative-ui/native.d.cts.map +1 -0
  21. package/dist/generative-ui/native.d.mts +155 -0
  22. package/dist/generative-ui/native.d.mts.map +1 -0
  23. package/dist/generative-ui/native.mjs +24 -0
  24. package/dist/generative-ui/native.mjs.map +1 -0
  25. package/dist/generative-ui.cjs +45 -70
  26. package/dist/generative-ui.cjs.map +1 -1
  27. package/dist/generative-ui.d.cts +72 -144
  28. package/dist/generative-ui.d.cts.map +1 -1
  29. package/dist/generative-ui.d.mts +72 -144
  30. package/dist/generative-ui.d.mts.map +1 -1
  31. package/dist/generative-ui.mjs +4 -29
  32. package/dist/generative-ui.mjs.map +1 -1
  33. package/dist/headless.d.cts +58 -153
  34. package/dist/headless.d.cts.map +1 -1
  35. package/dist/hooks-2Ur8NQhj.d.cts +84 -0
  36. package/dist/hooks-2Ur8NQhj.d.cts.map +1 -0
  37. package/dist/hooks-BRYonCVu.d.mts +84 -0
  38. package/dist/hooks-BRYonCVu.d.mts.map +1 -0
  39. package/dist/index.cjs +82 -430
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +3 -2
  42. package/dist/index.d.cts.map +1 -1
  43. package/dist/index.d.mts +4 -3
  44. package/dist/index.d.mts.map +1 -1
  45. package/dist/index.mjs +5 -353
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/index.umd.js +645 -140
  48. package/dist/index.umd.js.map +1 -1
  49. package/dist/refs-BIUfn1wb.cjs +43 -0
  50. package/dist/refs-BIUfn1wb.cjs.map +1 -0
  51. package/dist/refs-CMrRm3ta.mjs +31 -0
  52. package/dist/refs-CMrRm3ta.mjs.map +1 -0
  53. package/dist/use-generative-ui-root-C12htqbK.cjs +390 -0
  54. package/dist/use-generative-ui-root-C12htqbK.cjs.map +1 -0
  55. package/dist/use-generative-ui-root-CVgsDy1f.mjs +385 -0
  56. package/dist/use-generative-ui-root-CVgsDy1f.mjs.map +1 -0
  57. package/package.json +14 -10
  58. package/dist/MarkdownRendererContext-CPfNVyde.d.mts.map +0 -1
  59. package/dist/MarkdownRendererContext-iOl2pj9l.d.cts.map +0 -1
  60. package/dist/MarkdownSurfaces-BFoO6wSB.cjs.map +0 -1
  61. package/dist/MarkdownSurfaces-BQ1HGCzB.mjs.map +0 -1
@@ -28,8 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  let _copilotkit_core = require("@copilotkit/core");
29
29
  let react = require("react");
30
30
  react = __toESM(react);
31
- let _copilotkit_markdown_react = require("@copilotkit/markdown/react");
32
- let _copilotkit_markdown = require("@copilotkit/markdown");
33
31
  let react_jsx_runtime = require("react/jsx-runtime");
34
32
  let _copilotkit_react_core_context = require("@copilotkit/react-core/context");
35
33
  let _copilotkit_shared = require("@copilotkit/shared");
@@ -38,94 +36,6 @@ zod = __toESM(zod);
38
36
  let _copilotkit_core_generative_ui = require("@copilotkit/core/generative-ui");
39
37
  let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
40
38
 
41
- //#region src/components/chat/StreamingMarkdownDefaultRenderer.tsx
42
- /**
43
- * react-core's built-in default markdown renderer — a thin adapter over
44
- * `@copilotkit/markdown`'s streaming renderer. Maps the pluggable
45
- * renderer contract (`{ content, isStreaming, className }`) onto the streaming
46
- * renderer for streaming-safe incremental rendering + per-token animation.
47
- * Still overridable via the slot/provider pluggable interface.
48
- */
49
- function StreamingMarkdownDefaultRenderer({ content, isStreaming, className, nodeRenderers, caret, options, onLinkClick, onCitationClick }) {
50
- if (!content) return null;
51
- (0, _copilotkit_markdown.warnUnsupportedRichSyntaxOnce)(content);
52
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_markdown_react.StreamingMarkdownRenderer, {
53
- className,
54
- isComplete: !isStreaming,
55
- caret: caret ?? !!isStreaming,
56
- nodeRenderers,
57
- nodeClassNames: _copilotkit_markdown.CHAT_MARKDOWN_NODE_CLASS_NAMES,
58
- options,
59
- onLinkClick,
60
- onCitationClick,
61
- children: content
62
- });
63
- }
64
- StreamingMarkdownDefaultRenderer.displayName = "StreamingMarkdownDefaultRenderer";
65
-
66
- //#endregion
67
- //#region src/components/icons/CopilotIcon.tsx
68
- /** Turns SVG attribute names such as `stroke-width` into React's `strokeWidth`. */
69
- function toReactAttributes(attributes) {
70
- return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase()), value]));
71
- }
72
- const svgDefaults = toReactAttributes(_copilotkit_core.ɵcopilotIconSvgAttributes);
73
- /** True when the props give the icon an accessible name or role. */
74
- function hasAccessibleProp(props) {
75
- return Object.keys(props).some((key) => key.startsWith("aria-") || key === "role" || key === "title");
76
- }
77
- /**
78
- * Internal. Draws a Lucide icon from its node data, the way Lucide's React package
79
- * does: Lucide's default SVG attributes, the `lucide lucide-<name>` classes,
80
- * and `aria-hidden="true"` when no `aria-*`, `role` or `title` prop names it.
81
- */
82
- const IconSvg = (0, react.forwardRef)(function IconSvg({ lucideName, nodes, size = 24, color = "currentColor", strokeWidth = 2, className, children, ...props }, ref) {
83
- const isDecorative = !children && !hasAccessibleProp(props);
84
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
85
- ref,
86
- ...svgDefaults,
87
- width: size,
88
- height: size,
89
- stroke: color,
90
- strokeWidth,
91
- className: (0, _copilotkit_core.ɵcn)("lucide", `lucide-${lucideName}`, className),
92
- "aria-hidden": isDecorative || void 0,
93
- ...props,
94
- children: [nodes.map((node, index) => (0, react.createElement)(node.tag, {
95
- key: index,
96
- ...node.attributes
97
- })), children]
98
- });
99
- });
100
- /**
101
- * Draws one of the chat icons as an inline `<svg>`.
102
- *
103
- * The `<svg>` has the classes `lucide lucide-<icon name>`, so CSS that selects
104
- * them (for example `svg.lucide-arrow-up`) keeps working. The icon is hidden
105
- * from screen readers unless you give it an `aria-label`, `role` or `title`.
106
- *
107
- * @param props.name - The chat icon, for example `"ArrowUp"` or `"X"`.
108
- * @param props.size - Width and height. Defaults to `24`.
109
- * @param props.strokeWidth - Line width. Defaults to `2`.
110
- * @param props.color - Line color. Defaults to `currentColor`.
111
- *
112
- * @example
113
- * ```tsx
114
- * <CopilotIcon name="ArrowUp" className="cpk-chat-input-send-icon" />
115
- * <CopilotIcon name="X" aria-label="Close" />
116
- * ```
117
- */
118
- const CopilotIcon = (0, react.forwardRef)(function CopilotIcon({ name, ...props }, ref) {
119
- const icon = _copilotkit_core.ɵcopilotIcons[name];
120
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconSvg, {
121
- ref,
122
- lucideName: icon.name,
123
- nodes: icon.nodes,
124
- ...props
125
- });
126
- });
127
-
128
- //#endregion
129
39
  //#region src/lib/shallow-stable-ref.ts
130
40
  /**
131
41
  * Shallow equality comparison for objects: same own keys, each holding the
@@ -303,84 +213,6 @@ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
303
213
  };
304
214
  ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
305
215
 
306
- //#endregion
307
- //#region src/lib/slots.tsx
308
- /**
309
- * Check if a value is a React component type (function, class, forwardRef, memo, etc.)
310
- */
311
- function isReactComponentType(value) {
312
- if (typeof value === "function") return true;
313
- if (value && typeof value === "object" && "$$typeof" in value && !react.default.isValidElement(value)) return true;
314
- return false;
315
- }
316
- /**
317
- * Internal function to render a slot value as a React element (non-memoized).
318
- */
319
- function renderSlotElement(slot, DefaultComponent, props) {
320
- if (typeof slot === "string") {
321
- const existingClassName = props.className;
322
- return react.default.createElement(DefaultComponent, {
323
- ...props,
324
- className: (0, _copilotkit_core.ɵcn)(existingClassName, slot)
325
- });
326
- }
327
- if (isReactComponentType(slot)) return react.default.createElement(slot, props);
328
- if (slot && typeof slot === "object" && !react.default.isValidElement(slot)) return react.default.createElement(DefaultComponent, {
329
- ...props,
330
- ...slot
331
- });
332
- return react.default.createElement(DefaultComponent, props);
333
- }
334
- /**
335
- * Internal memoized wrapper component for renderSlot.
336
- * Uses forwardRef to support ref forwarding.
337
- */
338
- const MemoizedSlotWrapper = react.default.memo(react.default.forwardRef(function MemoizedSlotWrapper(props, ref) {
339
- const { $slot, $component, ...rest } = props;
340
- return renderSlotElement($slot, $component, ref !== null ? {
341
- ...rest,
342
- ref
343
- } : rest);
344
- }), (prev, next) => {
345
- if (prev.$slot !== next.$slot) return false;
346
- if (prev.$component !== next.$component) return false;
347
- const { $slot: _ps, $component: _pc, ...prevRest } = prev;
348
- const { $slot: _ns, $component: _nc, ...nextRest } = next;
349
- return shallowEqual(prevRest, nextRest);
350
- });
351
- /**
352
- * Renders a slot value as a memoized React element.
353
- * Automatically prevents unnecessary re-renders using shallow prop comparison.
354
- * Supports ref forwarding.
355
- *
356
- * @example
357
- * renderSlot(customInput, CopilotChatInput, { onSubmit: handleSubmit })
358
- */
359
- function renderSlot(slot, DefaultComponent, props) {
360
- return react.default.createElement(MemoizedSlotWrapper, {
361
- ...props,
362
- $slot: slot,
363
- $component: DefaultComponent
364
- });
365
- }
366
-
367
- //#endregion
368
- //#region src/providers/MarkdownRendererContext.tsx
369
- const MarkdownRendererContext = (0, react.createContext)(void 0);
370
- const MarkdownRendererProvider = ({ renderer, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MarkdownRendererContext.Provider, {
371
- value: renderer,
372
- children
373
- });
374
- /**
375
- * The markdown renderer set at the provider level, or `undefined` when none was
376
- * supplied. Message components fall back to the built-in
377
- * `StreamingMarkdownDefaultRenderer` (via `CopilotChatAssistantMessage.MarkdownRenderer`)
378
- * when this is `undefined`.
379
- */
380
- function useMarkdownRenderer() {
381
- return (0, react.useContext)(MarkdownRendererContext);
382
- }
383
-
384
216
  //#endregion
385
217
  //#region src/types/defineToolCallRenderer.ts
386
218
  function defineToolCallRenderer(def) {
@@ -394,54 +226,6 @@ function defineToolCallRenderer(def) {
394
226
  };
395
227
  }
396
228
 
397
- //#endregion
398
- //#region src/generative-ui/catalog.ts
399
- /**
400
- * Experimental. Declares the components the model can render, the app state
401
- * they read, and the functions they call.
402
- *
403
- * - A prop with the name of a top-level state key is bound to that state.
404
- * - `bind: { prop: (state, props) => value }` binds a prop to a selector.
405
- * - An event binds to the function with its name, else to the name without
406
- * `on` (`onAddToCart` calls `addToCart`).
407
- * - `writable: ["value"]` gives the component a `setValue` prop. See
408
- * `GenerativeUIComponentDefinition.writable`.
409
- *
410
- * The model does not see bound props or matched events.
411
- *
412
- * @param config - `id`, then optional `extends`, `state`, `functions` and
413
- * `overrides`, then `components`. Put `state` before `components`, so the selectors
414
- * get typed state.
415
- * @throws Error when a name comes from two places, an override names no
416
- * component of the bases, `props` is not an object
417
- * schema with a JSON Schema, a key is reserved or used
418
- * twice on a component, an event matches two functions, an unmatched event
419
- * has no `parameters`, a `bind` key is not a prop, a `writable` key is not
420
- * a prop or is a bound prop, or a setter name is already a key of the
421
- * component. Also throws when `parameterOrder` contains duplicate or unknown
422
- * keys, or an ordered component declares integer-index keys whose JSON object
423
- * enumeration order cannot be controlled.
424
- *
425
- * @example
426
- * ```ts
427
- * const ui = createGenerativeUI({
428
- * id: "acme/store@1",
429
- * state: { cart: cartSchema },
430
- * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
431
- * components: {
432
- * CartSummary: {
433
- * component: CartSummary,
434
- * props: z.object({ count: z.number() }),
435
- * bind: { count: (state) => state.cart.count },
436
- * },
437
- * },
438
- * });
439
- * ```
440
- */
441
- function createGenerativeUI(config) {
442
- return (0, _copilotkit_shared_generative_ui.createGenerativeUI)(config);
443
- }
444
-
445
229
  //#endregion
446
230
  //#region src/generative-ui/runtime-context.ts
447
231
  const GenerativeUIRuntimeContext = (0, react.createContext)(null);
@@ -450,7 +234,7 @@ function useGenerativeUIRuntime() {
450
234
  }
451
235
  function useRequiredGenerativeUIRuntime() {
452
236
  const runtime = (0, react.useContext)(GenerativeUIRuntimeContext);
453
- if (!runtime) throw new Error("Generative UI components must be rendered inside <CopilotKitProvider generativeUI={{ ui }}>.");
237
+ 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.");
454
238
  return runtime;
455
239
  }
456
240
  const GenerativeUINodeContext = (0, react.createContext)(null);
@@ -543,7 +327,136 @@ function useGenerativeUIFunction(ui, name, handler) {
543
327
  }
544
328
 
545
329
  //#endregion
546
- //#region src/generative-ui/boundaries.tsx
330
+ //#region src/generative-ui/activity.ts
331
+ /**
332
+ * The rejected operations of a surface (the runtime's first, then the
333
+ * client's) and the error that goes with them, for a wrapper: a generic
334
+ * message, with the same list as its `cause`. The `cause` is not enumerable,
335
+ * so `JSON.stringify`, a spread and error reporters leave the list out.
336
+ * `clientRejected` is appended to in place by the manager, so its length is
337
+ * part of the key.
338
+ */
339
+ function useGenerativeUIRejected(serverRejected, clientRejected) {
340
+ const rejected = (0, react.useMemo)(() => [...serverRejected ?? [], ...clientRejected ?? []], [
341
+ serverRejected,
342
+ clientRejected,
343
+ clientRejected?.length ?? 0
344
+ ]);
345
+ return {
346
+ rejected,
347
+ 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])
348
+ };
349
+ }
350
+ /**
351
+ * What a renderer of one surface activity message shows: the surface (or the
352
+ * failed surface whose `createSurface` was rejected), and its rejected
353
+ * operations with their error (see {@link useGenerativeUIRejected}). It
354
+ * ingests `content` into the manager (idempotent: the root ingests the
355
+ * agent's messages too, and this covers an agent the root has not seen yet),
356
+ * and renders again on every change of the manager.
357
+ *
358
+ * `surface` is undefined when there is no runtime, thread or content, when
359
+ * the surface's target is not `target`, or when the surface does not exist
360
+ * (the agent deleted it). Both rejected lists cover only the latest
361
+ * `render_ui` call (see the manager's ingest).
362
+ */
363
+ function useGenerativeUIActivitySurface({ runtime, threadId, agentId, content, target }) {
364
+ useManagerVersion(runtime);
365
+ (0, react.useLayoutEffect)(() => {
366
+ if (runtime && threadId && content) runtime.manager.ingest(threadId, agentId, content);
367
+ }, [
368
+ runtime,
369
+ threadId,
370
+ agentId,
371
+ content
372
+ ]);
373
+ const surface = runtime && threadId && content && content.target === target ? runtime.manager.getSurface(threadId, content.surfaceId) ?? runtime.manager.getFailedSurface(threadId, content.surfaceId) : void 0;
374
+ const { rejected, error } = useGenerativeUIRejected(content?.rejected, surface?.clientRejected);
375
+ return {
376
+ surface,
377
+ rejected,
378
+ error
379
+ };
380
+ }
381
+
382
+ //#endregion
383
+ //#region src/generative-ui/catalog.ts
384
+ /**
385
+ * Experimental. Declares the components the model can render, the app state
386
+ * they read, and the functions they call.
387
+ *
388
+ * - A prop with the name of a top-level state key is bound to that state.
389
+ * - `bind: { prop: (state, props) => value }` binds a prop to a selector.
390
+ * - An event binds to the function with its name, else to the name without
391
+ * `on` (`onAddToCart` calls `addToCart`).
392
+ * - `writable: ["value"]` gives the component a `setValue` prop. See
393
+ * `GenerativeUIComponentDefinition.writable`.
394
+ *
395
+ * The model does not see bound props or matched events.
396
+ *
397
+ * @param config - `id`, then optional `extends`, `state`, `functions` and
398
+ * `overrides`, then `components`. Put `state` before `components`, so the selectors
399
+ * get typed state.
400
+ * @throws Error when a name comes from two places, an override names no
401
+ * component of the bases, `props` is not an object
402
+ * schema with a JSON Schema, a key is reserved or used
403
+ * twice on a component, an event matches two functions, an unmatched event
404
+ * has no `parameters`, a `bind` key is not a prop, a `writable` key is not
405
+ * a prop or is a bound prop, or a setter name is already a key of the
406
+ * component. Also throws when `parameterOrder` contains duplicate or unknown
407
+ * keys, or an ordered component declares integer-index keys whose JSON object
408
+ * enumeration order cannot be controlled.
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * const ui = createGenerativeUI({
413
+ * id: "acme/store@1",
414
+ * state: { cart: cartSchema },
415
+ * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
416
+ * components: {
417
+ * CartSummary: {
418
+ * component: CartSummary,
419
+ * props: z.object({ count: z.number() }),
420
+ * bind: { count: (state) => state.cart.count },
421
+ * },
422
+ * },
423
+ * });
424
+ * ```
425
+ */
426
+ function createGenerativeUI(config) {
427
+ return (0, _copilotkit_shared_generative_ui.createGenerativeUI)(config);
428
+ }
429
+
430
+ //#endregion
431
+ //#region src/generative-ui/host.tsx
432
+ const DISPLAY_CONTENTS = { display: "contents" };
433
+ /**
434
+ * The root element is always there, so a theme change does not remount the
435
+ * surface. `display: contents` keeps it out of the layout, and the CSS
436
+ * variables still reach every component of the surface. The `a2ui-surface`
437
+ * class scopes the standard catalog's surface CSS rules. The theme is a
438
+ * stylesheet, not an inline style, so that its `dark` values can apply in
439
+ * dark mode only. The values are checked in `themeStyleSheet`, and the HTML
440
+ * is set as is, so the server render keeps the quotes of the rule.
441
+ */
442
+ function DomSurfaceRoot({ surfaceId, theme, children }) {
443
+ const sheet = react.default.useMemo(() => (0, _copilotkit_shared_generative_ui.themeStyleSheet)(theme), [theme]);
444
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
445
+ className: "a2ui-surface",
446
+ "data-generative-ui-root": surfaceId,
447
+ "data-a2ui-theme": sheet?.id,
448
+ style: DISPLAY_CONTENTS,
449
+ children: [sheet ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { dangerouslySetInnerHTML: { __html: sheet.css } }) : null, children]
450
+ });
451
+ }
452
+ function DomAccessibilityWrapper({ attributes, children }) {
453
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
454
+ "data-a2ui-accessibility": "",
455
+ style: DISPLAY_CONTENTS,
456
+ ...attributes,
457
+ children
458
+ });
459
+ }
547
460
  function DefaultNodeFallback({ message, componentId, retry }) {
548
461
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
549
462
  role: "alert",
@@ -571,6 +484,23 @@ function DefaultNodeFallback({ message, componentId, retry }) {
571
484
  ]
572
485
  });
573
486
  }
487
+ /** The DOM host: what a surface draws on the web. */
488
+ const domGenerativeUIHost = {
489
+ SurfaceRoot: DomSurfaceRoot,
490
+ AccessibilityWrapper: DomAccessibilityWrapper,
491
+ NodeFallback: DefaultNodeFallback
492
+ };
493
+ /**
494
+ * The host elements of the surfaces below. Defaults to the DOM host, so a
495
+ * web app never sets it.
496
+ */
497
+ const GenerativeUIHostContext = (0, react.createContext)(domGenerativeUIHost);
498
+ function useGenerativeUIHost() {
499
+ return (0, react.useContext)(GenerativeUIHostContext);
500
+ }
501
+
502
+ //#endregion
503
+ //#region src/generative-ui/boundaries.tsx
574
504
  /**
575
505
  * A child that has not streamed yet renders nothing. The prose keeps
576
506
  * streaming above the surface, and each component appears as soon as it is
@@ -579,14 +509,181 @@ function DefaultNodeFallback({ message, componentId, retry }) {
579
509
  function NodePlaceholder(_props) {
580
510
  return null;
581
511
  }
582
- /** Per-node boundary. Resets on retry or a new agent revision, not on data ticks. */
512
+ /**
513
+ * The error that a fallback threw, told apart from the error of the
514
+ * component it stood in for. The fallback's own error is the `cause`.
515
+ */
516
+ function fallbackError(error, componentId) {
517
+ const subject = componentId === void 0 ? "the surface" : componentId;
518
+ return (0, _copilotkit_shared_generative_ui.withCause)(/* @__PURE__ */ new Error(`The error fallback of ${subject} threw: ${error.message}`), error);
519
+ }
520
+ function createFailureLog() {
521
+ const last = /* @__PURE__ */ new Map();
522
+ const released = /* @__PURE__ */ new Set();
523
+ const releasedSinceSettle = /* @__PURE__ */ new Set();
524
+ const heldBack = /* @__PURE__ */ new Map();
525
+ return {
526
+ report(runtime, slot, info, context = "") {
527
+ released.delete(slot);
528
+ const signature = [
529
+ info.kind,
530
+ info.error.name,
531
+ info.error.message,
532
+ context
533
+ ].join("\n");
534
+ if (last.get(slot) === signature) {
535
+ if (releasedSinceSettle.has(slot)) heldBack.set(slot, {
536
+ runtime,
537
+ info,
538
+ signature
539
+ });
540
+ return;
541
+ }
542
+ heldBack.delete(slot);
543
+ last.set(slot, signature);
544
+ (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, info);
545
+ },
546
+ clear(slot) {
547
+ released.delete(slot);
548
+ last.delete(slot);
549
+ heldBack.delete(slot);
550
+ },
551
+ retain(slot) {
552
+ released.delete(slot);
553
+ },
554
+ release(slot) {
555
+ heldBack.delete(slot);
556
+ if (!last.has(slot)) return;
557
+ released.add(slot);
558
+ releasedSinceSettle.add(slot);
559
+ },
560
+ settle(missed = false) {
561
+ for (const slot of missed ? releasedSinceSettle : released) last.delete(slot);
562
+ if (missed) for (const [slot, { runtime, info, signature }] of heldBack) {
563
+ if (!releasedSinceSettle.has(slot) || last.has(slot)) continue;
564
+ last.set(slot, signature);
565
+ (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, info);
566
+ }
567
+ heldBack.clear();
568
+ released.clear();
569
+ releasedSinceSettle.clear();
570
+ }
571
+ };
572
+ }
573
+ /** Outside a surface, every failure is reported. */
574
+ const UNLOGGED = {
575
+ report: (runtime, _slot, info) => (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, info),
576
+ clear: () => {},
577
+ retain: () => {},
578
+ release: () => {},
579
+ settle: () => {}
580
+ };
581
+ /** The failure log of the surface being rendered; set by `SurfaceView`. */
582
+ const GenerativeUIFailureLogContext = (0, react.createContext)(UNLOGGED);
583
+ function useFailureLog() {
584
+ return (0, react.useContext)(GenerativeUIFailureLogContext);
585
+ }
586
+ /**
587
+ * The slots of a failure log, per node place (one rendered copy of a node,
588
+ * see `placeOf` in SurfaceView) and surface boundary.
589
+ */
590
+ const failureSlots = {
591
+ node: (place) => `node ${place}`,
592
+ appFallback: (place) => `app-fallback ${place}`,
593
+ renderFallback: (place) => `render-fallback ${place}`,
594
+ fallback: (place) => `fallback ${place}`,
595
+ cycle: (place) => `cycle ${place}`,
596
+ props: (place) => `props ${place}`,
597
+ surface: (level) => `surface ${level}`,
598
+ surfaceFallback: (level) => `surface-fallback ${level}`
599
+ };
600
+ function sameKeys(a, b) {
601
+ return a.length === b.length && a.every((value, i) => Object.is(value, b[i]));
602
+ }
603
+ var FallbackGuard = class extends react.Component {
604
+ state = {
605
+ failed: false,
606
+ resetKeys: this.props.resetKeys
607
+ };
608
+ static getDerivedStateFromError(thrown) {
609
+ return {
610
+ failed: true,
611
+ error: (0, _copilotkit_shared_generative_ui.toError)(thrown)
612
+ };
613
+ }
614
+ static getDerivedStateFromProps(props, state) {
615
+ return sameKeys(props.resetKeys, state.resetKeys) ? null : {
616
+ failed: false,
617
+ error: void 0,
618
+ resetKeys: props.resetKeys
619
+ };
620
+ }
621
+ report(error) {
622
+ const { runtime, surfaceId, componentId, log, slot, context } = this.props;
623
+ log.report(runtime, slot, {
624
+ kind: "render",
625
+ surfaceId,
626
+ ...componentId === void 0 ? {} : { componentId },
627
+ error: fallbackError(error, componentId)
628
+ }, context);
629
+ }
630
+ componentDidCatch(thrown) {
631
+ this.report(this.state.error ?? (0, _copilotkit_shared_generative_ui.toError)(thrown));
632
+ }
633
+ componentDidMount() {
634
+ if (!this.state.failed) {
635
+ this.props.log.clear(this.props.slot);
636
+ return;
637
+ }
638
+ if (this.state.error) this.report(this.state.error);
639
+ }
640
+ componentDidUpdate() {
641
+ if (!this.state.failed) this.props.log.clear(this.props.slot);
642
+ }
643
+ render() {
644
+ return this.state.failed ? this.props.replacement ?? null : this.props.children;
645
+ }
646
+ };
647
+ /**
648
+ * The host's `NodeFallback`, guarded: when it throws, the node renders
649
+ * nothing and the error is reported, and the parent node keeps rendering.
650
+ * Every place that shows the host fallback goes through this.
651
+ */
652
+ function GuardedNodeFallback({ surfaceId, componentId, runtime, message, retry, slot, revision }) {
653
+ const { NodeFallback } = useGenerativeUIHost();
654
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FallbackGuard, {
655
+ surfaceId,
656
+ componentId,
657
+ runtime,
658
+ log: useFailureLog(),
659
+ slot,
660
+ context: message,
661
+ resetKeys: [message, revision],
662
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeFallback, {
663
+ message,
664
+ componentId: componentId ?? "surface",
665
+ retry
666
+ })
667
+ });
668
+ }
669
+ /**
670
+ * Calls the app's `errorBoundary.fallback` in a render of its own, so that
671
+ * the guard above it catches what it throws.
672
+ */
673
+ function AppErrorFallback({ render, ...props }) {
674
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: render(props) });
675
+ }
676
+ /**
677
+ * Per-node boundary. Resets on retry or a new agent revision, not on data
678
+ * ticks. A failure that stays the same across revisions is reported once.
679
+ */
583
680
  var NodeBoundary = class extends react.Component {
584
681
  state = {
585
682
  error: null,
586
683
  revision: this.props.revision
587
684
  };
588
- static getDerivedStateFromError(error) {
589
- return { error };
685
+ static getDerivedStateFromError(thrown) {
686
+ return { error: (0, _copilotkit_shared_generative_ui.toError)(thrown) };
590
687
  }
591
688
  static getDerivedStateFromProps(props, state) {
592
689
  return props.revision !== state.revision ? {
@@ -594,51 +691,136 @@ var NodeBoundary = class extends react.Component {
594
691
  revision: props.revision
595
692
  } : null;
596
693
  }
597
- componentDidCatch(error) {
598
- const { runtime, surfaceId, componentId } = this.props;
599
- (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, {
694
+ componentDidCatch(thrown) {
695
+ const { runtime, surfaceId, componentId, log, place } = this.props;
696
+ log.clear(failureSlots.fallback(place));
697
+ log.report(runtime, failureSlots.node(place), {
698
+ kind: "render",
699
+ surfaceId,
700
+ componentId,
701
+ error: this.state.error ?? (0, _copilotkit_shared_generative_ui.toError)(thrown)
702
+ });
703
+ }
704
+ slots() {
705
+ const { place } = this.props;
706
+ return [
707
+ failureSlots.node(place),
708
+ failureSlots.appFallback(place),
709
+ failureSlots.renderFallback(place)
710
+ ];
711
+ }
712
+ clearSlots() {
713
+ for (const slot of this.slots()) this.props.log.clear(slot);
714
+ }
715
+ componentDidMount() {
716
+ for (const slot of this.slots()) this.props.log.retain(slot);
717
+ if (!this.state.error) {
718
+ this.clearSlots();
719
+ return;
720
+ }
721
+ const { runtime, surfaceId, componentId, log, place } = this.props;
722
+ log.report(runtime, failureSlots.node(place), {
600
723
  kind: "render",
601
724
  surfaceId,
602
725
  componentId,
603
- error
726
+ error: this.state.error
604
727
  });
605
728
  }
729
+ componentDidUpdate(prevProps) {
730
+ if (prevProps.place !== this.props.place) {
731
+ const { log } = this.props;
732
+ log.release(failureSlots.node(prevProps.place));
733
+ log.release(failureSlots.appFallback(prevProps.place));
734
+ log.release(failureSlots.renderFallback(prevProps.place));
735
+ for (const slot of this.slots()) log.retain(slot);
736
+ }
737
+ if (!this.state.error) this.clearSlots();
738
+ }
739
+ componentWillUnmount() {
740
+ for (const slot of this.slots()) this.props.log.release(slot);
741
+ }
606
742
  retry = () => this.setState({ error: null });
607
743
  render() {
608
744
  const { error } = this.state;
609
745
  if (!error) return this.props.children;
610
- const { runtime, surfaceId, componentId } = this.props;
611
- const fallback = runtime.errorFallback;
612
- return fallback ? fallback({
613
- error,
614
- retry: this.retry,
746
+ const { runtime, surfaceId, componentId, place, log } = this.props;
747
+ const hostFallback = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
615
748
  surfaceId,
616
- componentId
617
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultNodeFallback, {
749
+ componentId,
750
+ runtime,
618
751
  message: error.message,
752
+ retry: this.retry,
753
+ slot: failureSlots.renderFallback(place)
754
+ });
755
+ const fallback = runtime.errorFallback;
756
+ if (!fallback) return hostFallback;
757
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FallbackGuard, {
758
+ surfaceId,
619
759
  componentId,
620
- retry: this.retry
760
+ runtime,
761
+ log,
762
+ slot: failureSlots.appFallback(place),
763
+ context: error.message,
764
+ resetKeys: [error],
765
+ replacement: hostFallback,
766
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppErrorFallback, {
767
+ render: fallback,
768
+ error,
769
+ retry: this.retry,
770
+ surfaceId,
771
+ componentId
772
+ })
621
773
  });
622
774
  }
623
775
  };
624
- /** Outer boundary: a failure here must not reach the chat or the host page. */
776
+ /**
777
+ * Surface boundary: a failure here must not reach the chat or the host page.
778
+ * It resets on a new revision, and on Retry when `retryable`. A failure that
779
+ * stays the same across revisions is reported once.
780
+ */
625
781
  var SurfaceBoundary = class extends react.Component {
626
- state = { error: null };
627
- static getDerivedStateFromError(error) {
628
- return { error };
782
+ state = {
783
+ error: null,
784
+ revision: this.props.revision
785
+ };
786
+ static getDerivedStateFromError(thrown) {
787
+ return { error: (0, _copilotkit_shared_generative_ui.toError)(thrown) };
788
+ }
789
+ static getDerivedStateFromProps(props, state) {
790
+ return props.revision !== state.revision ? {
791
+ error: null,
792
+ revision: props.revision
793
+ } : null;
629
794
  }
630
- componentDidCatch(error) {
631
- (0, _copilotkit_core_generative_ui.reportErrorSafely)(this.props.runtime, {
795
+ componentDidCatch(thrown) {
796
+ const { runtime, surfaceId, log, level } = this.props;
797
+ log.report(runtime, failureSlots.surface(level), {
632
798
  kind: "render",
633
- surfaceId: this.props.surfaceId,
634
- error
799
+ surfaceId,
800
+ error: this.state.error ?? (0, _copilotkit_shared_generative_ui.toError)(thrown)
635
801
  });
636
802
  }
803
+ clearSlots() {
804
+ const { log, level } = this.props;
805
+ log.clear(failureSlots.surface(level));
806
+ log.clear(failureSlots.surfaceFallback(level));
807
+ }
808
+ componentDidMount() {
809
+ if (!this.state.error) this.clearSlots();
810
+ }
811
+ componentDidUpdate() {
812
+ if (!this.state.error) this.clearSlots();
813
+ }
814
+ retry = () => this.setState({ error: null });
637
815
  render() {
638
816
  if (!this.state.error) return this.props.children;
639
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultNodeFallback, {
817
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
818
+ surfaceId: this.props.surfaceId,
819
+ componentId: void 0,
820
+ runtime: this.props.runtime,
640
821
  message: "this generated UI failed to render",
641
- componentId: "surface"
822
+ retry: this.props.retryable ? this.retry : void 0,
823
+ slot: failureSlots.surfaceFallback(this.props.level)
642
824
  });
643
825
  }
644
826
  };
@@ -668,7 +850,6 @@ function useGenerativeUIAccessibility() {
668
850
  //#endregion
669
851
  //#region src/generative-ui/SurfaceView.tsx
670
852
  const NO_ANCESTORS = [];
671
- const ROOT_STYLE = { display: "contents" };
672
853
  const undefinedSnapshot = () => void 0;
673
854
  const noopSubscribe = () => () => {};
674
855
  const zeroSnapshot = () => 0;
@@ -678,23 +859,80 @@ function isTemplateChildren(value) {
678
859
  }
679
860
  function SurfaceView({ surface }) {
680
861
  const runtime = useRequiredGenerativeUIRuntime();
681
- const { theme } = runtime;
682
- const sheet = (0, react.useMemo)(() => (0, _copilotkit_shared_generative_ui.themeStyleSheet)(theme), [theme]);
683
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
684
- className: "a2ui-surface",
685
- "data-generative-ui-root": surface.surfaceId,
686
- "data-a2ui-theme": sheet?.id,
687
- style: ROOT_STYLE,
688
- children: [sheet ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { dangerouslySetInnerHTML: { __html: sheet.css } }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceBoundary, {
862
+ const { SurfaceRoot } = useGenerativeUIHost();
863
+ const appliedCount = (0, react.useSyncExternalStore)(runtime.manager.subscribe, () => surface.operations.length, undefinedSnapshot);
864
+ const revision = (0, react.useMemo)(() => ({
865
+ surface,
866
+ appliedCount
867
+ }), [surface, appliedCount]);
868
+ const [scopedLog, setScopedLog] = (0, react.useState)(() => ({
869
+ key: surface.key,
870
+ log: createFailureLog()
871
+ }));
872
+ let failureLog = scopedLog.log;
873
+ if (scopedLog.key !== surface.key) {
874
+ const next = {
875
+ key: surface.key,
876
+ log: createFailureLog()
877
+ };
878
+ setScopedLog(next);
879
+ failureLog = next.log;
880
+ }
881
+ const { threadId, surfaceId } = surface;
882
+ const { manager } = runtime;
883
+ const seen = (0, react.useRef)(void 0);
884
+ (0, react.useLayoutEffect)(() => {
885
+ const contentOf = () => {
886
+ const current = manager.getSurface(threadId, surfaceId);
887
+ return {
888
+ log: failureLog,
889
+ current,
890
+ applied: current?.operations.length
891
+ };
892
+ };
893
+ const observe = (missed) => {
894
+ const last = seen.current;
895
+ const next = contentOf();
896
+ seen.current = next;
897
+ if (last?.log === failureLog && (next.current !== last.current || next.applied !== last.applied)) failureLog.settle(missed);
898
+ };
899
+ observe(true);
900
+ return manager.subscribe(() => observe(false));
901
+ }, [
902
+ manager,
903
+ threadId,
904
+ surfaceId,
905
+ failureLog
906
+ ]);
907
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GenerativeUIFailureLogContext.Provider, {
908
+ value: failureLog,
909
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceBoundary, {
689
910
  surfaceId: surface.surfaceId,
690
911
  runtime,
691
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
692
- surface,
693
- componentId: _copilotkit_shared.GENERATIVE_UI_ROOT_ID,
694
- basePath: void 0,
695
- ancestors: NO_ANCESTORS
912
+ log: failureLog,
913
+ level: "outer",
914
+ revision,
915
+ retryable: true,
916
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceRoot, {
917
+ surfaceId: surface.surfaceId,
918
+ theme: runtime.theme,
919
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceBoundary, {
920
+ surfaceId: surface.surfaceId,
921
+ runtime,
922
+ log: failureLog,
923
+ level: "inner",
924
+ revision,
925
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
926
+ surface,
927
+ componentId: _copilotkit_shared.GENERATIVE_UI_ROOT_ID,
928
+ basePath: void 0,
929
+ ancestors: NO_ANCESTORS,
930
+ parentPlace: "",
931
+ via: ""
932
+ })
933
+ })
696
934
  })
697
- })]
935
+ })
698
936
  });
699
937
  }
700
938
  /**
@@ -719,27 +957,63 @@ function useComponentProperties(manager, component) {
719
957
  * repeats both.
720
958
  */
721
959
  function scopedId(componentId, basePath) {
722
- return `${basePath ?? ""}#${componentId}`;
960
+ return `${basePath === void 0 ? "" : JSON.stringify(basePath)}#${JSON.stringify(componentId)}`;
961
+ }
962
+ /**
963
+ * Where one rendered copy of a node is: the place of its parent, the slot
964
+ * or child reference of the parent it renders in, and its scoped id. Names
965
+ * the node's failure-log slots. A scoped id alone is not enough: the same
966
+ * id can render under two parents, and a cyclic reference repeats the
967
+ * scoped id of an ancestor. Each copy keeps its own memory of what it
968
+ * reported, so one copy that renders, goes away or remounts does not clear
969
+ * the memory of another that still fails.
970
+ */
971
+ function placeOf(parentPlace, via, position) {
972
+ return `${parentPlace}/${via === "" ? "" : JSON.stringify(via)}${position}`;
723
973
  }
724
- const NodeView = (0, react.memo)(function NodeView({ surface, componentId, basePath, ancestors }) {
974
+ const NodeView = (0, react.memo)(function NodeView({ surface, componentId, basePath, ancestors, parentPlace, via }) {
725
975
  const runtime = useRequiredGenerativeUIRuntime();
976
+ const log = useFailureLog();
726
977
  const component = useComponentModel(runtime.manager, surface.model, componentId);
727
978
  const properties = useComponentProperties(runtime.manager, component);
728
- if (ancestors.includes(scopedId(componentId, basePath))) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultNodeFallback, {
979
+ const position = scopedId(componentId, basePath);
980
+ const place = placeOf(parentPlace, via, position);
981
+ (0, react.useEffect)(() => {
982
+ const slots = [
983
+ failureSlots.fallback(place),
984
+ failureSlots.cycle(place),
985
+ failureSlots.props(place)
986
+ ];
987
+ for (const slot of slots) log.retain(slot);
988
+ return () => {
989
+ for (const slot of slots) log.release(slot);
990
+ };
991
+ }, [log, place]);
992
+ if (ancestors.includes(position)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
993
+ surfaceId: surface.surfaceId,
994
+ componentId,
995
+ runtime,
729
996
  message: `cyclic reference to ${componentId}`,
730
- componentId
997
+ slot: failureSlots.cycle(place),
998
+ revision: properties
731
999
  });
732
1000
  if (!component || !properties) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodePlaceholder, { componentId });
733
1001
  const definition = runtime.ui.components.get(component.type);
734
- if (!definition) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultNodeFallback, {
1002
+ if (!definition) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
1003
+ surfaceId: surface.surfaceId,
1004
+ componentId,
1005
+ runtime,
735
1006
  message: `unknown component "${component.type}"`,
736
- componentId
1007
+ slot: failureSlots.fallback(place),
1008
+ revision: properties
737
1009
  });
738
1010
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeBoundary, {
739
1011
  surfaceId: surface.surfaceId,
740
1012
  componentId,
1013
+ place,
741
1014
  revision: properties,
742
1015
  runtime,
1016
+ log,
743
1017
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedNode, {
744
1018
  surface,
745
1019
  componentId,
@@ -747,7 +1021,8 @@ const NodeView = (0, react.memo)(function NodeView({ surface, componentId, baseP
747
1021
  properties,
748
1022
  runtime,
749
1023
  basePath,
750
- ancestors
1024
+ ancestors,
1025
+ place
751
1026
  })
752
1027
  }, component.type);
753
1028
  });
@@ -755,7 +1030,7 @@ const NodeView = (0, react.memo)(function NodeView({ surface, componentId, baseP
755
1030
  * Renders the component of a template once for each item of the list at the
756
1031
  * template path, keyed by index. Renders nothing when there is no list.
757
1032
  */
758
- function TemplateChildren({ surface, template, basePath, ancestors }) {
1033
+ function TemplateChildren({ surface, template, basePath, ancestors, parentPlace, via }) {
759
1034
  const dataModel = surface.model.dataModel;
760
1035
  const listPath = (0, _copilotkit_core_generative_ui.resolvePath)(template.path, basePath);
761
1036
  const subscribe = (0, react.useCallback)((onChange) => {
@@ -771,17 +1046,25 @@ function TemplateChildren({ surface, template, basePath, ancestors }) {
771
1046
  surface,
772
1047
  componentId: template.componentId,
773
1048
  basePath: (0, _copilotkit_core_generative_ui.joinPath)(listPath, String(index)),
774
- ancestors
1049
+ ancestors,
1050
+ parentPlace,
1051
+ via
775
1052
  }, index)) });
776
1053
  }
777
1054
  /**
778
1055
  * The props the model sets, with their dynamic values resolved from the
779
1056
  * surface data model: `{"@path"}` bindings, `{"@call"}` function values and
780
- * `{"@call":"@index"}` in a template, at any depth. A literal writable prop
781
- * that the component set shows the local value from `overrides`. Bound
782
- * props, events and slots are left out, and so are the keys of the A2UI
783
- * component envelope; `accessibility` is resolved the same way and given
784
- * on its own.
1057
+ * `{"@call":"@index"}` in a template, at any depth. Bound props, events and
1058
+ * slots are left out, and so are the keys of the A2UI component envelope;
1059
+ * `accessibility` is resolved the same way and given on its own.
1060
+ *
1061
+ * A writable prop that is not bound to a path and that the component set
1062
+ * shows the local value from `overrides`, also when the model never set the
1063
+ * prop. That is intended: the user's edit wins over the model's literal
1064
+ * value, also over a newer literal the agent sends later, until the node
1065
+ * remounts. A literal is not data the agent and the user share; a prop
1066
+ * that both must write is bound to a path, and the setter writes the data
1067
+ * model.
785
1068
  *
786
1069
  * A prop is resolved again only when its raw value or a data model value it
787
1070
  * read has changed, so the result keeps its identity otherwise. A function
@@ -792,7 +1075,7 @@ function useModelDataProps(surface, definition, properties, basePath, overrides)
792
1075
  const units = (0, react.useMemo)(() => {
793
1076
  const list = [];
794
1077
  for (const key of Object.keys(properties)) {
795
- if (definition.events?.[key] || definition.slots?.[key] || Object.hasOwn(definition.selectors, key) || _copilotkit_shared.A2UI_COMPONENT_ENVELOPE_KEYS.has(key)) continue;
1078
+ 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;
796
1079
  list.push({
797
1080
  key,
798
1081
  raw: properties[key]
@@ -893,9 +1176,10 @@ function select(definition, state, modelProps) {
893
1176
  for (const [key, selector] of selectors) try {
894
1177
  values[key] = selector(state, modelProps);
895
1178
  } catch (error) {
1179
+ const { message } = (0, _copilotkit_shared_generative_ui.toError)(error);
896
1180
  return {
897
1181
  ok: false,
898
- problem: `${key}: selector threw: ${error instanceof Error ? error.message : String(error)}`
1182
+ problem: `${key}: selector threw: ${message}`
899
1183
  };
900
1184
  }
901
1185
  return {
@@ -906,8 +1190,10 @@ function select(definition, state, modelProps) {
906
1190
  /**
907
1191
  * The values of the bound props of a node, read from the app state.
908
1192
  *
909
- * The selectors run again only when the state object or the parsed model
910
- * props change. When the new values are shallow-equal to the last ones, the
1193
+ * The selectors get the checked model props: the resolved values that
1194
+ * passed the props schema (without the nulls it rejected), not the
1195
+ * schema's parsed output, so its defaults and transforms are not applied
1196
+ * 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
911
1197
  * last snapshot is kept. So the node re-renders only when a selected value
912
1198
  * changes. A selector that returns a new array on each call cannot cause a
913
1199
  * render loop: with the same inputs, the cached snapshot comes back.
@@ -937,7 +1223,10 @@ function useSelection(manager, definition, modelProps) {
937
1223
  * Checks the model-set props with the props schema before the selectors run.
938
1224
  * The bound props are not set yet, so their issues do not count. Neither do
939
1225
  * issues with no path (a check over several props), which the full check
940
- * after the selectors reports.
1226
+ * after the selectors reports. The exception is the issue that an async
1227
+ * props schema gives (`isAsyncIssue`): the render checks props
1228
+ * synchronously only, so the full check would fail the same way, and it is
1229
+ * reported here.
941
1230
  */
942
1231
  function checkModelProps(definition, modelData) {
943
1232
  if (!definition.props) return {
@@ -956,7 +1245,7 @@ function checkModelProps(definition, modelData) {
956
1245
  if (!result.success) {
957
1246
  const issues = result.issues.filter((issue) => {
958
1247
  const key = (0, _copilotkit_shared_generative_ui.issueKey)(issue);
959
- return key === void 0 ? (0, _copilotkit_shared_generative_ui.isAsyncIssue)(issue) : !Object.hasOwn(definition.selectors, key);
1248
+ return key === void 0 ? (0, _copilotkit_shared_generative_ui.isAsyncIssue)(issue) : !(0, _copilotkit_shared_generative_ui.hasOwnKey)(definition.selectors, key);
960
1249
  });
961
1250
  if (issues.length > 0) return {
962
1251
  ok: false,
@@ -1019,7 +1308,7 @@ function useDataProps(runtime, surface, definition, properties, basePath, overri
1019
1308
  function useEventProps(runtime, surface, componentId, definition, properties, basePath) {
1020
1309
  const latest = (0, react.useRef)(properties);
1021
1310
  latest.current = properties;
1022
- const boundNames = Object.keys(definition.events ?? {}).filter((name) => Object.hasOwn(definition.eventFunctions, name) || (0, _copilotkit_shared.isActionBinding)(properties[name])).join("|");
1311
+ const boundNames = Object.keys(definition.events ?? {}).filter((name) => (0, _copilotkit_shared_generative_ui.hasOwnKey)(definition.eventFunctions, name) || (0, _copilotkit_shared.isActionBinding)(properties[name])).join("|");
1023
1312
  return (0, react.useMemo)(() => {
1024
1313
  const handlers = {};
1025
1314
  const names = boundNames ? boundNames.split("|") : [];
@@ -1031,7 +1320,7 @@ function useEventProps(runtime, surface, componentId, definition, properties, ba
1031
1320
  name,
1032
1321
  parameters: definition.events?.[name]?.parameters
1033
1322
  };
1034
- const functionName = Object.hasOwn(definition.eventFunctions, name) ? definition.eventFunctions[name] : void 0;
1323
+ const functionName = (0, _copilotkit_shared_generative_ui.hasOwnKey)(definition.eventFunctions, name) ? definition.eventFunctions[name] : void 0;
1035
1324
  handlers[name] = functionName === void 0 ? (args) => (0, _copilotkit_core_generative_ui.invokeBoundEvent)({
1036
1325
  ...call,
1037
1326
  binding: latest.current[name],
@@ -1057,7 +1346,9 @@ function useEventProps(runtime, surface, componentId, definition, properties, ba
1057
1346
  * The setter props of a node: `setValue` for the writable prop `value`. For
1058
1347
  * a prop the model bound to `{"@path"}`, the setter writes the data model
1059
1348
  * and makes the path user-owned. For a literal prop, it sets `overrides`, a
1060
- * local value of this mounted node. The setters keep their identity.
1349
+ * local value of this mounted node that wins over the model's value until
1350
+ * the node remounts (see `useModelDataProps`). The setters keep their
1351
+ * identity.
1061
1352
  */
1062
1353
  function useSetterProps(runtime, surface, componentId, definition, properties, basePath) {
1063
1354
  const [overrides, setOverrides] = (0, react.useState)({});
@@ -1080,7 +1371,7 @@ function useSetterProps(runtime, surface, componentId, definition, properties, b
1080
1371
  try {
1081
1372
  runtime.manager.setOwnedValue(surface.key, (0, _copilotkit_core_generative_ui.resolvePath)(binding["@path"], basePath), value);
1082
1373
  } catch (cause) {
1083
- const message = cause instanceof Error ? cause.message : String(cause);
1374
+ const { message } = (0, _copilotkit_shared_generative_ui.toError)(cause);
1084
1375
  (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, {
1085
1376
  kind: "props",
1086
1377
  surfaceId: surface.surfaceId,
@@ -1099,29 +1390,36 @@ function useSetterProps(runtime, surface, componentId, definition, properties, b
1099
1390
  ])
1100
1391
  };
1101
1392
  }
1102
- function useSlotProps(surface, definition, properties, componentId, basePath, ancestors) {
1393
+ function useSlotProps(surface, definition, properties, componentId, basePath, ancestors, place) {
1103
1394
  return (0, react.useMemo)(() => {
1104
1395
  const childAncestors = [...ancestors, scopedId(componentId, basePath)];
1105
1396
  const slots = {};
1106
1397
  for (const [name, kind] of Object.entries(definition.slots ?? {})) {
1107
1398
  const value = properties[name];
1399
+ const via = `${name}:`;
1108
1400
  if (kind === "single" && typeof value === "string") slots[name] = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
1109
1401
  surface,
1110
1402
  componentId: value,
1111
1403
  basePath,
1112
- ancestors: childAncestors
1404
+ ancestors: childAncestors,
1405
+ parentPlace: place,
1406
+ via
1113
1407
  });
1114
1408
  else if (kind === "multiple" && isTemplateChildren(value)) slots[name] = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TemplateChildren, {
1115
1409
  surface,
1116
1410
  template: value,
1117
1411
  basePath,
1118
- ancestors: childAncestors
1412
+ ancestors: childAncestors,
1413
+ parentPlace: place,
1414
+ via
1119
1415
  });
1120
1416
  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, {
1121
1417
  surface,
1122
1418
  componentId: id,
1123
1419
  basePath,
1124
- ancestors: childAncestors
1420
+ ancestors: childAncestors,
1421
+ parentPlace: place,
1422
+ via
1125
1423
  }, id));
1126
1424
  }
1127
1425
  return slots;
@@ -1131,7 +1429,8 @@ function useSlotProps(surface, definition, properties, componentId, basePath, an
1131
1429
  properties,
1132
1430
  componentId,
1133
1431
  basePath,
1134
- ancestors
1432
+ ancestors,
1433
+ place
1135
1434
  ]);
1136
1435
  }
1137
1436
  /**
@@ -1139,33 +1438,43 @@ function useSlotProps(surface, definition, properties, componentId, basePath, an
1139
1438
  * `childList()`, at any depth) replaced by the rendered component. Without
1140
1439
  * references, the parsed props come back as they are.
1141
1440
  */
1142
- function useChildRefProps(surface, refs, props, componentId, basePath, ancestors) {
1441
+ function useChildRefProps(surface, refs, props, componentId, basePath, ancestors, place) {
1143
1442
  return (0, react.useMemo)(() => {
1144
1443
  if (props === void 0 || refs.length === 0) return props;
1145
1444
  const childAncestors = [...ancestors, scopedId(componentId, basePath)];
1146
- const render = (kind, value) => {
1445
+ const render = (kind, value, via) => {
1147
1446
  if (kind === "single") return typeof value === "string" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
1148
1447
  surface,
1149
1448
  componentId: value,
1150
1449
  basePath,
1151
- ancestors: childAncestors
1450
+ ancestors: childAncestors,
1451
+ parentPlace: place,
1452
+ via
1152
1453
  }) : void 0;
1153
1454
  if (isTemplateChildren(value)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TemplateChildren, {
1154
1455
  surface,
1155
1456
  template: value,
1156
1457
  basePath,
1157
- ancestors: childAncestors
1458
+ ancestors: childAncestors,
1459
+ parentPlace: place,
1460
+ via
1158
1461
  });
1159
1462
  if (!Array.isArray(value)) return void 0;
1160
1463
  return [...new Set(value.filter((id) => typeof id === "string"))].map((id) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
1161
1464
  surface,
1162
1465
  componentId: id,
1163
1466
  basePath,
1164
- ancestors: childAncestors
1467
+ ancestors: childAncestors,
1468
+ parentPlace: place,
1469
+ via
1165
1470
  }, id));
1166
1471
  };
1167
1472
  let result = props;
1168
- for (const ref of refs) result = (0, _copilotkit_shared.mapAtChildRef)(result, ref.path, (found) => render(ref.kind, found));
1473
+ for (const ref of refs) {
1474
+ let found = 0;
1475
+ const path = ref.path.join(".");
1476
+ result = (0, _copilotkit_shared.mapAtChildRef)(result, ref.path, (value) => render(ref.kind, value, `${path}[${found++}]:`));
1477
+ }
1169
1478
  return result;
1170
1479
  }, [
1171
1480
  surface,
@@ -1173,15 +1482,17 @@ function useChildRefProps(surface, refs, props, componentId, basePath, ancestors
1173
1482
  props,
1174
1483
  componentId,
1175
1484
  basePath,
1176
- ancestors
1485
+ ancestors,
1486
+ place
1177
1487
  ]);
1178
1488
  }
1179
- function ResolvedNode({ surface, componentId, definition, properties, runtime, basePath, ancestors }) {
1489
+ function ResolvedNode({ surface, componentId, definition, properties, runtime, basePath, ancestors, place }) {
1490
+ const { AccessibilityWrapper } = useGenerativeUIHost();
1180
1491
  const { overrides, setters } = useSetterProps(runtime, surface, componentId, definition, properties, basePath);
1181
1492
  const dataProps = useDataProps(runtime, surface, definition, properties, basePath, overrides);
1182
1493
  const eventProps = useEventProps(runtime, surface, componentId, definition, properties, basePath);
1183
- const slotProps = useSlotProps(surface, definition, properties, componentId, basePath, ancestors);
1184
- const childRefProps = useChildRefProps(surface, definition.childRefs, dataProps.ok ? dataProps.props : void 0, componentId, basePath, ancestors);
1494
+ const slotProps = useSlotProps(surface, definition, properties, componentId, basePath, ancestors, place);
1495
+ const childRefProps = useChildRefProps(surface, definition.childRefs, dataProps.ok ? dataProps.props : void 0, componentId, basePath, ancestors, place);
1185
1496
  const accessibility = dataProps.ok ? dataProps.accessibility : void 0;
1186
1497
  const nodeContext = (0, react.useMemo)(() => ({
1187
1498
  surfaceKey: surface.key,
@@ -1195,8 +1506,19 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
1195
1506
  accessibility
1196
1507
  ]);
1197
1508
  const problem = dataProps.ok ? void 0 : dataProps.problem;
1509
+ const log = useFailureLog();
1198
1510
  (0, react.useEffect)(() => {
1199
- if (problem) (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, {
1511
+ if (!problem) {
1512
+ log.clear(failureSlots.fallback(place));
1513
+ log.clear(failureSlots.props(place));
1514
+ }
1515
+ }, [
1516
+ problem,
1517
+ log,
1518
+ place
1519
+ ]);
1520
+ (0, react.useEffect)(() => {
1521
+ if (problem) log.report(runtime, failureSlots.props(place), {
1200
1522
  kind: "props",
1201
1523
  surfaceId: surface.surfaceId,
1202
1524
  componentId,
@@ -1204,13 +1526,19 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
1204
1526
  });
1205
1527
  }, [
1206
1528
  problem,
1529
+ log,
1530
+ place,
1207
1531
  runtime,
1208
1532
  surface.surfaceId,
1209
1533
  componentId
1210
1534
  ]);
1211
- if (!dataProps.ok) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultNodeFallback, {
1535
+ if (!dataProps.ok) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
1536
+ surfaceId: surface.surfaceId,
1537
+ componentId,
1538
+ runtime,
1212
1539
  message: `invalid props (${problem})`,
1213
- componentId
1540
+ slot: failureSlots.fallback(place),
1541
+ revision: properties
1214
1542
  });
1215
1543
  const Component = definition.component;
1216
1544
  const rendered = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
@@ -1222,10 +1550,8 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
1222
1550
  const hasEnvelope = properties.accessibility !== void 0 && definition.accessibility !== "self";
1223
1551
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GenerativeUINodeContext.Provider, {
1224
1552
  value: nodeContext,
1225
- children: hasEnvelope ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1226
- "data-a2ui-accessibility": "",
1227
- style: ROOT_STYLE,
1228
- ...(0, _copilotkit_core_generative_ui.wrapperAria)((0, _copilotkit_core_generative_ui.accessibilityAttributes)(accessibility)),
1553
+ children: hasEnvelope ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccessibilityWrapper, {
1554
+ attributes: (0, _copilotkit_core_generative_ui.wrapperAria)((0, _copilotkit_core_generative_ui.accessibilityAttributes)(accessibility)),
1229
1555
  children: rendered
1230
1556
  }) : rendered
1231
1557
  });
@@ -1245,39 +1571,18 @@ function DefaultGenerativeUIChatCard({ surfaceId, error, children }) {
1245
1571
  })]
1246
1572
  });
1247
1573
  }
1248
- const ContentSchema = zod.object({
1249
- surfaceId: zod.string(),
1250
- target: zod.string(),
1251
- catalogId: zod.string(),
1252
- operations: zod.array(zod.any()),
1253
- status: zod.enum([
1254
- "streaming",
1255
- "ready",
1256
- "error"
1257
- ]),
1258
- rejected: zod.array(zod.object({
1259
- index: zod.number(),
1260
- reason: zod.string()
1261
- })).default([])
1262
- }).loose();
1263
1574
  function GenerativeUIChatActivity({ content, agent }) {
1264
1575
  const runtime = useGenerativeUIRuntime();
1265
1576
  const threadId = useCopilotChatConfiguration()?.threadId ?? agent?.threadId;
1266
1577
  const Wrapper = (0, react.useContext)(GenerativeUIChatSlotContext) ?? DefaultGenerativeUIChatCard;
1267
- useManagerVersion(runtime);
1268
- (0, react.useLayoutEffect)(() => {
1269
- if (runtime && threadId) runtime.manager.ingest(threadId, agent?.agentId, content);
1270
- }, [
1578
+ const { surface, rejected, error } = useGenerativeUIActivitySurface({
1271
1579
  runtime,
1272
1580
  threadId,
1273
- agent?.agentId,
1274
- content
1275
- ]);
1276
- if (!runtime || !threadId || content.target !== _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET) return null;
1277
- const surface = runtime.manager.getSurface(threadId, content.surfaceId) ?? runtime.manager.getFailedSurface(threadId, content.surfaceId);
1581
+ agentId: agent?.agentId,
1582
+ content,
1583
+ target: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET
1584
+ });
1278
1585
  if (!surface) return null;
1279
- const rejected = [...content.rejected ?? [], ...surface.clientRejected];
1280
- const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
1281
1586
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
1282
1587
  surfaceId: content.surfaceId,
1283
1588
  isStreaming: content.status === "streaming",
@@ -1289,7 +1594,7 @@ function GenerativeUIChatActivity({ content, agent }) {
1289
1594
  function createGenerativeUIActivityRenderer() {
1290
1595
  return {
1291
1596
  activityType: _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE,
1292
- content: ContentSchema,
1597
+ content: _copilotkit_core_generative_ui.GenerativeUISurfaceContentSchema,
1293
1598
  render: GenerativeUIChatActivity
1294
1599
  };
1295
1600
  }
@@ -1319,153 +1624,6 @@ function GenerativeUIToolCallRenderer() {
1319
1624
  return null;
1320
1625
  }
1321
1626
 
1322
- //#endregion
1323
- //#region src/generative-ui/markdown/ProviderMarkdown.tsx
1324
- /**
1325
- * Markdown prose inside generative UI, rendered like the chat text around
1326
- * it: the renderer set on the provider when there is one, else the built-in
1327
- * streaming renderer. Config passed here wins over provider config.
1328
- */
1329
- function ProviderMarkdown({ content, isStreaming, className, ...config }) {
1330
- const renderer = useMarkdownRenderer();
1331
- if (renderer && isReactComponentType(renderer)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(renderer, {
1332
- content,
1333
- isStreaming,
1334
- className
1335
- });
1336
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamingMarkdownDefaultRenderer, {
1337
- ...renderer,
1338
- ...config,
1339
- content,
1340
- isStreaming,
1341
- className
1342
- });
1343
- }
1344
-
1345
- //#endregion
1346
- //#region src/generative-ui/markdown/MarkdownSurfaces.tsx
1347
- const FADE_STYLE_ID = "a2ui-markdown-fade";
1348
- /**
1349
- * Components fade in as they stream: each element that appears under a
1350
- * markdown surface runs the keyframes once on mount. React keeps the keys
1351
- * stable per component id, so an element that is already there never
1352
- * animates again. SVG internals are left out: a chart library re-creates
1353
- * its nodes on each render, and a fade on each of them would read as the
1354
- * chart flashing whenever a sibling arrives. The fade runs under reduced
1355
- * motion too, because it moves nothing.
1356
- */
1357
- const FADE_CSS = ["@keyframes a2ui-fade-in{from{opacity:0}}", "[data-a2ui-markdown-surface] .a2ui-surface *:not(svg):not(svg *){animation:a2ui-fade-in .35s ease-out backwards}"].join("\n");
1358
- const noEffect = () => {};
1359
- const useInjectEffect = typeof document === "undefined" ? noEffect : react.useInsertionEffect;
1360
- function useFadeStyles() {
1361
- useInjectEffect(() => {
1362
- if (document.getElementById(FADE_STYLE_ID)) return;
1363
- const style = document.createElement("style");
1364
- style.id = FADE_STYLE_ID;
1365
- style.textContent = FADE_CSS;
1366
- document.head.appendChild(style);
1367
- }, []);
1368
- }
1369
- /**
1370
- * The default wrapper of a chat surface in the markdown transport. It draws
1371
- * no box: a surface sits in the flow of the reply like a paragraph, and a
1372
- * Card draws its own box when it is interactive. Nothing shows while the
1373
- * surface streams. A rejected operation gets one line.
1374
- */
1375
- function DefaultMarkdownChatSurface({ surfaceId, error, children }) {
1376
- useFadeStyles();
1377
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1378
- "data-generative-ui-chat-surface": surfaceId,
1379
- "data-a2ui-markdown-surface": surfaceId,
1380
- className: "cpk-markdown-chat-surface",
1381
- children: [children, error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1382
- role: "alert",
1383
- className: "cpk-markdown-chat-surface-error",
1384
- children: "Part of this UI couldn't be shown."
1385
- })]
1386
- });
1387
- }
1388
- /**
1389
- * One chat surface in the chat wrapper. Nothing renders until the surface
1390
- * has its root component, so a half-streamed fence shows no empty card.
1391
- */
1392
- function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
1393
- const surface = runtime.manager.getSurface(threadId, surfaceId) ?? runtime.manager.getFailedSurface(threadId, surfaceId);
1394
- const root = surface?.model.componentsModel.get(_copilotkit_shared.GENERATIVE_UI_ROOT_ID);
1395
- if (!surface || !root && !surface.failed) return null;
1396
- const rejected = [...surface.serverRejected, ...surface.clientRejected];
1397
- const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
1398
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
1399
- surfaceId,
1400
- isStreaming: surface.status === "streaming",
1401
- error,
1402
- rejected,
1403
- children: surface.failed ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceView, { surface })
1404
- });
1405
- }
1406
- /** The blocks of one fence: lifted prose and chat surfaces, in order. */
1407
- function FenceBlocks({ blocks, runtime, threadId, isStreaming, markdownProps }) {
1408
- const Wrapper = (0, react.useContext)(GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
1409
- let surfaceCount = 0;
1410
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blocks.map((block, index) => {
1411
- if (block.kind === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderMarkdown, {
1412
- ...markdownProps,
1413
- content: block.markdown,
1414
- isStreaming: isStreaming && index === blocks.length - 1
1415
- }, `md-${surfaceCount}`);
1416
- surfaceCount++;
1417
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChatSurface, {
1418
- runtime,
1419
- threadId,
1420
- surfaceId: block.surfaceId,
1421
- Wrapper
1422
- }, block.surfaceId);
1423
- }) });
1424
- }
1425
- /**
1426
- * Experimental. Renders an assistant message of the markdown transport.
1427
- * Prose renders as markdown. In place of each ```a2ui fence:
1428
- *
1429
- * - the fence that created a chat surface renders that surface (and the
1430
- * prose lifted out of it) in the chat wrapper;
1431
- * - every other fence renders nothing: a fence that updates the surface of
1432
- * an earlier fence, or a fence for a named target, which
1433
- * `<GenerativeUISurface id>` renders.
1434
- *
1435
- * Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: "markdown" }}>`.
1436
- * `CopilotChatAssistantMessage` uses it there on its own.
1437
- *
1438
- * @example
1439
- * ```tsx
1440
- * <MarkdownSurfaces content={message.content} messageId={message.id} />
1441
- * ```
1442
- */
1443
- function MarkdownSurfaces({ content, messageId, isStreaming = false, ...markdownProps }) {
1444
- const runtime = useRequiredGenerativeUIRuntime();
1445
- const chatThreadId = useCopilotChatConfiguration()?.threadId;
1446
- useManagerVersion(runtime);
1447
- const segments = (0, react.useMemo)(() => (0, _copilotkit_core.splitA2UIMarkdown)(content), [content]);
1448
- const threadId = chatThreadId ?? runtime.manager.getActiveThread();
1449
- const source = (0, _copilotkit_core_generative_ui.getMarkdownSurfaceSource)(runtime);
1450
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: segments.map((segment, index) => {
1451
- const isLast = index === segments.length - 1;
1452
- if (segment.type === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderMarkdown, {
1453
- ...markdownProps,
1454
- content: segment.text,
1455
- isStreaming: isStreaming && isLast
1456
- }, `md-${index}`);
1457
- const blocks = threadId ? source.getFenceBlocks(threadId, messageId, segment.index) : void 0;
1458
- if (!threadId || !blocks) return null;
1459
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FenceBlocks, {
1460
- blocks,
1461
- runtime,
1462
- threadId,
1463
- isStreaming: isStreaming && isLast,
1464
- markdownProps
1465
- }, `a2ui-${segment.index}`);
1466
- }) });
1467
- }
1468
-
1469
1627
  //#endregion
1470
1628
  Object.defineProperty(exports, 'ControlledModalOpenScope', {
1471
1629
  enumerable: true,
@@ -1479,12 +1637,6 @@ Object.defineProperty(exports, 'CopilotChatConfigurationProvider', {
1479
1637
  return CopilotChatConfigurationProvider;
1480
1638
  }
1481
1639
  });
1482
- Object.defineProperty(exports, 'CopilotIcon', {
1483
- enumerable: true,
1484
- get: function () {
1485
- return CopilotIcon;
1486
- }
1487
- });
1488
1640
  Object.defineProperty(exports, 'DefaultGenerativeUIChatCard', {
1489
1641
  enumerable: true,
1490
1642
  get: function () {
@@ -1497,6 +1649,12 @@ Object.defineProperty(exports, 'GenerativeUIChatSlotContext', {
1497
1649
  return GenerativeUIChatSlotContext;
1498
1650
  }
1499
1651
  });
1652
+ Object.defineProperty(exports, 'GenerativeUIHostContext', {
1653
+ enumerable: true,
1654
+ get: function () {
1655
+ return GenerativeUIHostContext;
1656
+ }
1657
+ });
1500
1658
  Object.defineProperty(exports, 'GenerativeUINodeContext', {
1501
1659
  enumerable: true,
1502
1660
  get: function () {
@@ -1515,36 +1673,6 @@ Object.defineProperty(exports, 'GenerativeUIToolCallRenderer', {
1515
1673
  return GenerativeUIToolCallRenderer;
1516
1674
  }
1517
1675
  });
1518
- Object.defineProperty(exports, 'IconSvg', {
1519
- enumerable: true,
1520
- get: function () {
1521
- return IconSvg;
1522
- }
1523
- });
1524
- Object.defineProperty(exports, 'MarkdownRendererProvider', {
1525
- enumerable: true,
1526
- get: function () {
1527
- return MarkdownRendererProvider;
1528
- }
1529
- });
1530
- Object.defineProperty(exports, 'MarkdownSurfaces', {
1531
- enumerable: true,
1532
- get: function () {
1533
- return MarkdownSurfaces;
1534
- }
1535
- });
1536
- Object.defineProperty(exports, 'ProviderMarkdown', {
1537
- enumerable: true,
1538
- get: function () {
1539
- return ProviderMarkdown;
1540
- }
1541
- });
1542
- Object.defineProperty(exports, 'StreamingMarkdownDefaultRenderer', {
1543
- enumerable: true,
1544
- get: function () {
1545
- return StreamingMarkdownDefaultRenderer;
1546
- }
1547
- });
1548
1676
  Object.defineProperty(exports, 'SurfaceView', {
1549
1677
  enumerable: true,
1550
1678
  get: function () {
@@ -1581,16 +1709,10 @@ Object.defineProperty(exports, 'defineToolCallRenderer', {
1581
1709
  return defineToolCallRenderer;
1582
1710
  }
1583
1711
  });
1584
- Object.defineProperty(exports, 'isReactComponentType', {
1712
+ Object.defineProperty(exports, 'shallowEqual', {
1585
1713
  enumerable: true,
1586
1714
  get: function () {
1587
- return isReactComponentType;
1588
- }
1589
- });
1590
- Object.defineProperty(exports, 'renderSlot', {
1591
- enumerable: true,
1592
- get: function () {
1593
- return renderSlot;
1715
+ return shallowEqual;
1594
1716
  }
1595
1717
  });
1596
1718
  Object.defineProperty(exports, 'useCopilotChatConfiguration', {
@@ -1605,12 +1727,30 @@ Object.defineProperty(exports, 'useGenerativeUIAccessibility', {
1605
1727
  return useGenerativeUIAccessibility;
1606
1728
  }
1607
1729
  });
1730
+ Object.defineProperty(exports, 'useGenerativeUIActivitySurface', {
1731
+ enumerable: true,
1732
+ get: function () {
1733
+ return useGenerativeUIActivitySurface;
1734
+ }
1735
+ });
1608
1736
  Object.defineProperty(exports, 'useGenerativeUIFunction', {
1609
1737
  enumerable: true,
1610
1738
  get: function () {
1611
1739
  return useGenerativeUIFunction;
1612
1740
  }
1613
1741
  });
1742
+ Object.defineProperty(exports, 'useGenerativeUIHost', {
1743
+ enumerable: true,
1744
+ get: function () {
1745
+ return useGenerativeUIHost;
1746
+ }
1747
+ });
1748
+ Object.defineProperty(exports, 'useGenerativeUIRejected', {
1749
+ enumerable: true,
1750
+ get: function () {
1751
+ return useGenerativeUIRejected;
1752
+ }
1753
+ });
1614
1754
  Object.defineProperty(exports, 'useGenerativeUIRuntime', {
1615
1755
  enumerable: true,
1616
1756
  get: function () {
@@ -1629,12 +1769,6 @@ Object.defineProperty(exports, 'useManagerVersion', {
1629
1769
  return useManagerVersion;
1630
1770
  }
1631
1771
  });
1632
- Object.defineProperty(exports, 'useMarkdownRenderer', {
1633
- enumerable: true,
1634
- get: function () {
1635
- return useMarkdownRenderer;
1636
- }
1637
- });
1638
1772
  Object.defineProperty(exports, 'useRequiredGenerativeUIRuntime', {
1639
1773
  enumerable: true,
1640
1774
  get: function () {
@@ -1647,4 +1781,4 @@ Object.defineProperty(exports, 'useShallowStableRef', {
1647
1781
  return useShallowStableRef;
1648
1782
  }
1649
1783
  });
1650
- //# sourceMappingURL=MarkdownSurfaces-BFoO6wSB.cjs.map
1784
+ //# sourceMappingURL=chat-D3fxo6Ah.cjs.map