@copilotkit/react-core 1.84.2-canary.openbot-intel-fixes → 1.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MarkdownSurfaces-BCVdnDAk.cjs +161 -0
- package/dist/MarkdownSurfaces-BCVdnDAk.cjs.map +1 -0
- package/dist/MarkdownSurfaces-CjJduaJR.mjs +149 -0
- package/dist/MarkdownSurfaces-CjJduaJR.mjs.map +1 -0
- package/dist/{MarkdownSurfaces-3cGU5_0H.cjs → chat-BnsrQ0VS.cjs} +667 -320
- package/dist/chat-BnsrQ0VS.cjs.map +1 -0
- package/dist/{MarkdownSurfaces-D-W4f9Dy.mjs → chat-IWySXWXP.mjs} +647 -312
- package/dist/chat-IWySXWXP.mjs.map +1 -0
- package/dist/{copilotkit-UHD9sXsS.mjs → copilotkit-B1OLgEU8.mjs} +6 -354
- package/dist/copilotkit-B1OLgEU8.mjs.map +1 -0
- package/dist/{copilotkit-Dn4PbHJV.d.mts → copilotkit-C7G95NO-.d.mts} +4 -4
- package/dist/{copilotkit-Dn4PbHJV.d.mts.map → copilotkit-C7G95NO-.d.mts.map} +1 -1
- package/dist/{copilotkit-DYtl9zj0.cjs → copilotkit-Ca0IcTZU.cjs} +79 -427
- package/dist/copilotkit-Ca0IcTZU.cjs.map +1 -0
- package/dist/{copilotkit-CuTAoQF2.d.cts → copilotkit-DwD7D6jJ.d.cts} +2 -2
- package/dist/{copilotkit-CuTAoQF2.d.cts.map → copilotkit-DwD7D6jJ.d.cts.map} +1 -1
- package/dist/hooks-DMSkcNOl.d.cts +89 -0
- package/dist/hooks-DMSkcNOl.d.cts.map +1 -0
- package/dist/hooks-EwGvqYsW.d.mts +89 -0
- package/dist/hooks-EwGvqYsW.d.mts.map +1 -0
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/index.umd.js +645 -140
- package/dist/index.umd.js.map +1 -1
- package/dist/refs-DL7ITFFD.cjs +43 -0
- package/dist/refs-DL7ITFFD.cjs.map +1 -0
- package/dist/refs-DiZXJ63p.mjs +31 -0
- package/dist/refs-DiZXJ63p.mjs.map +1 -0
- package/dist/{runtime-context-Er5UIbZA.d.mts → runtime-context-B4fKyzo6.d.mts} +31 -9
- package/dist/runtime-context-B4fKyzo6.d.mts.map +1 -0
- package/dist/{runtime-context-DrVNUYLi.d.cts → runtime-context-Da7T5vy4.d.cts} +31 -9
- package/dist/runtime-context-Da7T5vy4.d.cts.map +1 -0
- package/dist/use-generative-ui-root-CaTyBFNR.cjs +390 -0
- package/dist/use-generative-ui-root-CaTyBFNR.cjs.map +1 -0
- package/dist/use-generative-ui-root-WI9ERMpo.mjs +385 -0
- package/dist/use-generative-ui-root-WI9ERMpo.mjs.map +1 -0
- package/dist/v2/generative-ui/native.cjs +66 -0
- package/dist/v2/generative-ui/native.cjs.map +1 -0
- package/dist/v2/generative-ui/native.d.cts +155 -0
- package/dist/v2/generative-ui/native.d.cts.map +1 -0
- package/dist/v2/generative-ui/native.d.mts +155 -0
- package/dist/v2/generative-ui/native.d.mts.map +1 -0
- package/dist/v2/generative-ui/native.mjs +24 -0
- package/dist/v2/generative-ui/native.mjs.map +1 -0
- package/dist/v2/generative-ui.cjs +45 -70
- package/dist/v2/generative-ui.cjs.map +1 -1
- package/dist/v2/generative-ui.d.cts +229 -308
- package/dist/v2/generative-ui.d.cts.map +1 -1
- package/dist/v2/generative-ui.d.mts +229 -308
- package/dist/v2/generative-ui.d.mts.map +1 -1
- package/dist/v2/generative-ui.mjs +4 -29
- package/dist/v2/generative-ui.mjs.map +1 -1
- package/dist/v2/headless.d.cts +185 -294
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/index.cjs +5 -5
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +645 -140
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +15 -11
- package/dist/MarkdownSurfaces-3cGU5_0H.cjs.map +0 -1
- package/dist/MarkdownSurfaces-D-W4f9Dy.mjs.map +0 -1
- package/dist/copilotkit-DYtl9zj0.cjs.map +0 -1
- package/dist/copilotkit-UHD9sXsS.mjs.map +0 -1
- package/dist/runtime-context-DrVNUYLi.d.cts.map +0 -1
- package/dist/runtime-context-Er5UIbZA.d.mts.map +0 -1
|
@@ -27,11 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let react = require("react");
|
|
29
29
|
react = __toESM(react);
|
|
30
|
-
let _copilotkit_core = require("@copilotkit/core");
|
|
31
30
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
32
31
|
let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
|
|
33
32
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
-
let streamdown = require("streamdown");
|
|
35
33
|
let zod = require("zod");
|
|
36
34
|
let _copilotkit_core_generative_ui = require("@copilotkit/core/generative-ui");
|
|
37
35
|
let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
|
|
@@ -381,25 +379,6 @@ const ControlledModalOpenScope = ({ children, open, onOpenChange }) => {
|
|
|
381
379
|
};
|
|
382
380
|
ControlledModalOpenScope.displayName = "ControlledModalOpenScope";
|
|
383
381
|
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/v2/hooks/useKatexStyles.ts
|
|
386
|
-
let injected = false;
|
|
387
|
-
/**
|
|
388
|
-
* Dynamically injects KaTeX CSS at runtime to avoid the Next.js
|
|
389
|
-
* "Global CSS cannot be imported from within node_modules" build error.
|
|
390
|
-
*
|
|
391
|
-
* Uses a singleton flag so the stylesheet is only injected once.
|
|
392
|
-
*/
|
|
393
|
-
function useKatexStyles() {
|
|
394
|
-
(0, react.useEffect)(() => {
|
|
395
|
-
if (injected || typeof document === "undefined") return;
|
|
396
|
-
injected = true;
|
|
397
|
-
import("katex/dist/katex.min.css").catch(() => {
|
|
398
|
-
console.warn("[CopilotKit] Failed to load katex styles — math content may render without formatting");
|
|
399
|
-
});
|
|
400
|
-
}, []);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
382
|
//#endregion
|
|
404
383
|
//#region src/v2/types/defineToolCallRenderer.ts
|
|
405
384
|
function defineToolCallRenderer(def) {
|
|
@@ -413,54 +392,6 @@ function defineToolCallRenderer(def) {
|
|
|
413
392
|
};
|
|
414
393
|
}
|
|
415
394
|
|
|
416
|
-
//#endregion
|
|
417
|
-
//#region src/v2/generative-ui/catalog.ts
|
|
418
|
-
/**
|
|
419
|
-
* Experimental. Declares the components the model can render, the app state
|
|
420
|
-
* they read, and the functions they call.
|
|
421
|
-
*
|
|
422
|
-
* - A prop with the name of a top-level state key is bound to that state.
|
|
423
|
-
* - `bind: { prop: (state, props) => value }` binds a prop to a selector.
|
|
424
|
-
* - An event binds to the function with its name, else to the name without
|
|
425
|
-
* `on` (`onAddToCart` calls `addToCart`).
|
|
426
|
-
* - `writable: ["value"]` gives the component a `setValue` prop. See
|
|
427
|
-
* `GenerativeUIComponentDefinition.writable`.
|
|
428
|
-
*
|
|
429
|
-
* The model does not see bound props or matched events.
|
|
430
|
-
*
|
|
431
|
-
* @param config - `id`, then optional `extends`, `state`, `functions` and
|
|
432
|
-
* `overrides`, then `components`. Put `state` before `components`, so the selectors
|
|
433
|
-
* get typed state.
|
|
434
|
-
* @throws Error when a name comes from two places, an override names no
|
|
435
|
-
* component of the bases, `props` is not an object
|
|
436
|
-
* schema with a JSON Schema, a key is reserved or used
|
|
437
|
-
* twice on a component, an event matches two functions, an unmatched event
|
|
438
|
-
* has no `parameters`, a `bind` key is not a prop, a `writable` key is not
|
|
439
|
-
* a prop or is a bound prop, or a setter name is already a key of the
|
|
440
|
-
* component. Also throws when `parameterOrder` contains duplicate or unknown
|
|
441
|
-
* keys, or an ordered component declares integer-index keys whose JSON object
|
|
442
|
-
* enumeration order cannot be controlled.
|
|
443
|
-
*
|
|
444
|
-
* @example
|
|
445
|
-
* ```ts
|
|
446
|
-
* const ui = createGenerativeUI({
|
|
447
|
-
* id: "acme/store@1",
|
|
448
|
-
* state: { cart: cartSchema },
|
|
449
|
-
* functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
|
|
450
|
-
* components: {
|
|
451
|
-
* CartSummary: {
|
|
452
|
-
* component: CartSummary,
|
|
453
|
-
* props: z.object({ count: z.number() }),
|
|
454
|
-
* bind: { count: (state) => state.cart.count },
|
|
455
|
-
* },
|
|
456
|
-
* },
|
|
457
|
-
* });
|
|
458
|
-
* ```
|
|
459
|
-
*/
|
|
460
|
-
function createGenerativeUI(config) {
|
|
461
|
-
return (0, _copilotkit_shared_generative_ui.createGenerativeUI)(config);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
395
|
//#endregion
|
|
465
396
|
//#region src/v2/generative-ui/runtime-context.ts
|
|
466
397
|
const GenerativeUIRuntimeContext = (0, react.createContext)(null);
|
|
@@ -469,7 +400,7 @@ function useGenerativeUIRuntime() {
|
|
|
469
400
|
}
|
|
470
401
|
function useRequiredGenerativeUIRuntime() {
|
|
471
402
|
const runtime = (0, react.useContext)(GenerativeUIRuntimeContext);
|
|
472
|
-
if (!runtime) throw new Error("Generative UI components must be rendered inside <CopilotKitProvider generativeUI={{ ui }}
|
|
403
|
+
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.");
|
|
473
404
|
return runtime;
|
|
474
405
|
}
|
|
475
406
|
const GenerativeUINodeContext = (0, react.createContext)(null);
|
|
@@ -562,7 +493,136 @@ function useGenerativeUIFunction(ui, name, handler) {
|
|
|
562
493
|
}
|
|
563
494
|
|
|
564
495
|
//#endregion
|
|
565
|
-
//#region src/v2/generative-ui/
|
|
496
|
+
//#region src/v2/generative-ui/activity.ts
|
|
497
|
+
/**
|
|
498
|
+
* The rejected operations of a surface (the runtime's first, then the
|
|
499
|
+
* client's) and the error that goes with them, for a wrapper: a generic
|
|
500
|
+
* message, with the same list as its `cause`. The `cause` is not enumerable,
|
|
501
|
+
* so `JSON.stringify`, a spread and error reporters leave the list out.
|
|
502
|
+
* `clientRejected` is appended to in place by the manager, so its length is
|
|
503
|
+
* part of the key.
|
|
504
|
+
*/
|
|
505
|
+
function useGenerativeUIRejected(serverRejected, clientRejected) {
|
|
506
|
+
const rejected = (0, react.useMemo)(() => [...serverRejected ?? [], ...clientRejected ?? []], [
|
|
507
|
+
serverRejected,
|
|
508
|
+
clientRejected,
|
|
509
|
+
clientRejected?.length ?? 0
|
|
510
|
+
]);
|
|
511
|
+
return {
|
|
512
|
+
rejected,
|
|
513
|
+
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])
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* What a renderer of one surface activity message shows: the surface (or the
|
|
518
|
+
* failed surface whose `createSurface` was rejected), and its rejected
|
|
519
|
+
* operations with their error (see {@link useGenerativeUIRejected}). It
|
|
520
|
+
* ingests `content` into the manager (idempotent: the root ingests the
|
|
521
|
+
* agent's messages too, and this covers an agent the root has not seen yet),
|
|
522
|
+
* and renders again on every change of the manager.
|
|
523
|
+
*
|
|
524
|
+
* `surface` is undefined when there is no runtime, thread or content, when
|
|
525
|
+
* the surface's target is not `target`, or when the surface does not exist
|
|
526
|
+
* (the agent deleted it). Both rejected lists cover only the latest
|
|
527
|
+
* `render_ui` call (see the manager's ingest).
|
|
528
|
+
*/
|
|
529
|
+
function useGenerativeUIActivitySurface({ runtime, threadId, agentId, content, target }) {
|
|
530
|
+
useManagerVersion(runtime);
|
|
531
|
+
(0, react.useLayoutEffect)(() => {
|
|
532
|
+
if (runtime && threadId && content) runtime.manager.ingest(threadId, agentId, content);
|
|
533
|
+
}, [
|
|
534
|
+
runtime,
|
|
535
|
+
threadId,
|
|
536
|
+
agentId,
|
|
537
|
+
content
|
|
538
|
+
]);
|
|
539
|
+
const surface = runtime && threadId && content && content.target === target ? runtime.manager.getSurface(threadId, content.surfaceId) ?? runtime.manager.getFailedSurface(threadId, content.surfaceId) : void 0;
|
|
540
|
+
const { rejected, error } = useGenerativeUIRejected(content?.rejected, surface?.clientRejected);
|
|
541
|
+
return {
|
|
542
|
+
surface,
|
|
543
|
+
rejected,
|
|
544
|
+
error
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/v2/generative-ui/catalog.ts
|
|
550
|
+
/**
|
|
551
|
+
* Experimental. Declares the components the model can render, the app state
|
|
552
|
+
* they read, and the functions they call.
|
|
553
|
+
*
|
|
554
|
+
* - A prop with the name of a top-level state key is bound to that state.
|
|
555
|
+
* - `bind: { prop: (state, props) => value }` binds a prop to a selector.
|
|
556
|
+
* - An event binds to the function with its name, else to the name without
|
|
557
|
+
* `on` (`onAddToCart` calls `addToCart`).
|
|
558
|
+
* - `writable: ["value"]` gives the component a `setValue` prop. See
|
|
559
|
+
* `GenerativeUIComponentDefinition.writable`.
|
|
560
|
+
*
|
|
561
|
+
* The model does not see bound props or matched events.
|
|
562
|
+
*
|
|
563
|
+
* @param config - `id`, then optional `extends`, `state`, `functions` and
|
|
564
|
+
* `overrides`, then `components`. Put `state` before `components`, so the selectors
|
|
565
|
+
* get typed state.
|
|
566
|
+
* @throws Error when a name comes from two places, an override names no
|
|
567
|
+
* component of the bases, `props` is not an object
|
|
568
|
+
* schema with a JSON Schema, a key is reserved or used
|
|
569
|
+
* twice on a component, an event matches two functions, an unmatched event
|
|
570
|
+
* has no `parameters`, a `bind` key is not a prop, a `writable` key is not
|
|
571
|
+
* a prop or is a bound prop, or a setter name is already a key of the
|
|
572
|
+
* component. Also throws when `parameterOrder` contains duplicate or unknown
|
|
573
|
+
* keys, or an ordered component declares integer-index keys whose JSON object
|
|
574
|
+
* enumeration order cannot be controlled.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```ts
|
|
578
|
+
* const ui = createGenerativeUI({
|
|
579
|
+
* id: "acme/store@1",
|
|
580
|
+
* state: { cart: cartSchema },
|
|
581
|
+
* functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
|
|
582
|
+
* components: {
|
|
583
|
+
* CartSummary: {
|
|
584
|
+
* component: CartSummary,
|
|
585
|
+
* props: z.object({ count: z.number() }),
|
|
586
|
+
* bind: { count: (state) => state.cart.count },
|
|
587
|
+
* },
|
|
588
|
+
* },
|
|
589
|
+
* });
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
function createGenerativeUI(config) {
|
|
593
|
+
return (0, _copilotkit_shared_generative_ui.createGenerativeUI)(config);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/v2/generative-ui/host.tsx
|
|
598
|
+
const DISPLAY_CONTENTS = { display: "contents" };
|
|
599
|
+
/**
|
|
600
|
+
* The root element is always there, so a theme change does not remount the
|
|
601
|
+
* surface. `display: contents` keeps it out of the layout, and the CSS
|
|
602
|
+
* variables still reach every component of the surface. The `a2ui-surface`
|
|
603
|
+
* class scopes the standard catalog's surface CSS rules. The theme is a
|
|
604
|
+
* stylesheet, not an inline style, so that its `dark` values can apply in
|
|
605
|
+
* dark mode only. The values are checked in `themeStyleSheet`, and the HTML
|
|
606
|
+
* is set as is, so the server render keeps the quotes of the rule.
|
|
607
|
+
*/
|
|
608
|
+
function DomSurfaceRoot({ surfaceId, theme, children }) {
|
|
609
|
+
const sheet = react.default.useMemo(() => (0, _copilotkit_shared_generative_ui.themeStyleSheet)(theme), [theme]);
|
|
610
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
611
|
+
className: "a2ui-surface",
|
|
612
|
+
"data-generative-ui-root": surfaceId,
|
|
613
|
+
"data-a2ui-theme": sheet?.id,
|
|
614
|
+
style: DISPLAY_CONTENTS,
|
|
615
|
+
children: [sheet ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { dangerouslySetInnerHTML: { __html: sheet.css } }) : null, children]
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
function DomAccessibilityWrapper({ attributes, children }) {
|
|
619
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
620
|
+
"data-a2ui-accessibility": "",
|
|
621
|
+
style: DISPLAY_CONTENTS,
|
|
622
|
+
...attributes,
|
|
623
|
+
children
|
|
624
|
+
});
|
|
625
|
+
}
|
|
566
626
|
function DefaultNodeFallback({ message, componentId, retry }) {
|
|
567
627
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
568
628
|
role: "alert",
|
|
@@ -590,6 +650,23 @@ function DefaultNodeFallback({ message, componentId, retry }) {
|
|
|
590
650
|
]
|
|
591
651
|
});
|
|
592
652
|
}
|
|
653
|
+
/** The DOM host: what a surface draws on the web. */
|
|
654
|
+
const domGenerativeUIHost = {
|
|
655
|
+
SurfaceRoot: DomSurfaceRoot,
|
|
656
|
+
AccessibilityWrapper: DomAccessibilityWrapper,
|
|
657
|
+
NodeFallback: DefaultNodeFallback
|
|
658
|
+
};
|
|
659
|
+
/**
|
|
660
|
+
* The host elements of the surfaces below. Defaults to the DOM host, so a
|
|
661
|
+
* web app never sets it.
|
|
662
|
+
*/
|
|
663
|
+
const GenerativeUIHostContext = (0, react.createContext)(domGenerativeUIHost);
|
|
664
|
+
function useGenerativeUIHost() {
|
|
665
|
+
return (0, react.useContext)(GenerativeUIHostContext);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/v2/generative-ui/boundaries.tsx
|
|
593
670
|
/**
|
|
594
671
|
* A child that has not streamed yet renders nothing. The prose keeps
|
|
595
672
|
* streaming above the surface, and each component appears as soon as it is
|
|
@@ -598,18 +675,188 @@ function DefaultNodeFallback({ message, componentId, retry }) {
|
|
|
598
675
|
function NodePlaceholder(_props) {
|
|
599
676
|
return null;
|
|
600
677
|
}
|
|
601
|
-
/**
|
|
602
|
-
|
|
678
|
+
/**
|
|
679
|
+
* The error that a fallback threw, told apart from the error of the
|
|
680
|
+
* component it stood in for. The fallback's own error is the `cause`.
|
|
681
|
+
*/
|
|
682
|
+
function fallbackError(error, componentId) {
|
|
683
|
+
const subject = componentId === void 0 ? "the surface" : componentId;
|
|
684
|
+
return (0, _copilotkit_shared_generative_ui.withCause)(/* @__PURE__ */ new Error(`The error fallback of ${subject} threw: ${error.message}`), error);
|
|
685
|
+
}
|
|
686
|
+
function createFailureLog() {
|
|
687
|
+
const last = /* @__PURE__ */ new Map();
|
|
688
|
+
const released = /* @__PURE__ */ new Set();
|
|
689
|
+
const releasedSinceSettle = /* @__PURE__ */ new Set();
|
|
690
|
+
const heldBack = /* @__PURE__ */ new Map();
|
|
691
|
+
return {
|
|
692
|
+
report(runtime, slot, info, context = "") {
|
|
693
|
+
released.delete(slot);
|
|
694
|
+
const signature = [
|
|
695
|
+
info.kind,
|
|
696
|
+
info.error.name,
|
|
697
|
+
info.error.message,
|
|
698
|
+
context
|
|
699
|
+
].join("\n");
|
|
700
|
+
if (last.get(slot) === signature) {
|
|
701
|
+
if (releasedSinceSettle.has(slot)) heldBack.set(slot, {
|
|
702
|
+
runtime,
|
|
703
|
+
info,
|
|
704
|
+
signature
|
|
705
|
+
});
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
heldBack.delete(slot);
|
|
709
|
+
last.set(slot, signature);
|
|
710
|
+
(0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, info);
|
|
711
|
+
},
|
|
712
|
+
clear(slot) {
|
|
713
|
+
released.delete(slot);
|
|
714
|
+
last.delete(slot);
|
|
715
|
+
heldBack.delete(slot);
|
|
716
|
+
},
|
|
717
|
+
retain(slot) {
|
|
718
|
+
released.delete(slot);
|
|
719
|
+
},
|
|
720
|
+
release(slot) {
|
|
721
|
+
heldBack.delete(slot);
|
|
722
|
+
if (!last.has(slot)) return;
|
|
723
|
+
released.add(slot);
|
|
724
|
+
releasedSinceSettle.add(slot);
|
|
725
|
+
},
|
|
726
|
+
settle(missed = false) {
|
|
727
|
+
for (const slot of missed ? releasedSinceSettle : released) last.delete(slot);
|
|
728
|
+
if (missed) for (const [slot, { runtime, info, signature }] of heldBack) {
|
|
729
|
+
if (!releasedSinceSettle.has(slot) || last.has(slot)) continue;
|
|
730
|
+
last.set(slot, signature);
|
|
731
|
+
(0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, info);
|
|
732
|
+
}
|
|
733
|
+
heldBack.clear();
|
|
734
|
+
released.clear();
|
|
735
|
+
releasedSinceSettle.clear();
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
/** Outside a surface, every failure is reported. */
|
|
740
|
+
const UNLOGGED = {
|
|
741
|
+
report: (runtime, _slot, info) => (0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, info),
|
|
742
|
+
clear: () => {},
|
|
743
|
+
retain: () => {},
|
|
744
|
+
release: () => {},
|
|
745
|
+
settle: () => {}
|
|
746
|
+
};
|
|
747
|
+
/** The failure log of the surface being rendered; set by `SurfaceView`. */
|
|
748
|
+
const GenerativeUIFailureLogContext = (0, react.createContext)(UNLOGGED);
|
|
749
|
+
function useFailureLog() {
|
|
750
|
+
return (0, react.useContext)(GenerativeUIFailureLogContext);
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* The slots of a failure log, per node place (one rendered copy of a node,
|
|
754
|
+
* see `placeOf` in SurfaceView) and surface boundary.
|
|
755
|
+
*/
|
|
756
|
+
const failureSlots = {
|
|
757
|
+
node: (place) => `node ${place}`,
|
|
758
|
+
appFallback: (place) => `app-fallback ${place}`,
|
|
759
|
+
renderFallback: (place) => `render-fallback ${place}`,
|
|
760
|
+
fallback: (place) => `fallback ${place}`,
|
|
761
|
+
cycle: (place) => `cycle ${place}`,
|
|
762
|
+
props: (place) => `props ${place}`,
|
|
763
|
+
surface: (level) => `surface ${level}`,
|
|
764
|
+
surfaceFallback: (level) => `surface-fallback ${level}`
|
|
765
|
+
};
|
|
766
|
+
function sameKeys(a, b) {
|
|
767
|
+
return a.length === b.length && a.every((value, i) => Object.is(value, b[i]));
|
|
768
|
+
}
|
|
769
|
+
var FallbackGuard = class extends react.Component {
|
|
603
770
|
constructor(..._args) {
|
|
604
771
|
super(..._args);
|
|
772
|
+
this.state = {
|
|
773
|
+
failed: false,
|
|
774
|
+
resetKeys: this.props.resetKeys
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
static getDerivedStateFromError(thrown) {
|
|
778
|
+
return {
|
|
779
|
+
failed: true,
|
|
780
|
+
error: (0, _copilotkit_shared_generative_ui.toError)(thrown)
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
static getDerivedStateFromProps(props, state) {
|
|
784
|
+
return sameKeys(props.resetKeys, state.resetKeys) ? null : {
|
|
785
|
+
failed: false,
|
|
786
|
+
error: void 0,
|
|
787
|
+
resetKeys: props.resetKeys
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
report(error) {
|
|
791
|
+
const { runtime, surfaceId, componentId, log, slot, context } = this.props;
|
|
792
|
+
log.report(runtime, slot, {
|
|
793
|
+
kind: "render",
|
|
794
|
+
surfaceId,
|
|
795
|
+
...componentId === void 0 ? {} : { componentId },
|
|
796
|
+
error: fallbackError(error, componentId)
|
|
797
|
+
}, context);
|
|
798
|
+
}
|
|
799
|
+
componentDidCatch(thrown) {
|
|
800
|
+
this.report(this.state.error ?? (0, _copilotkit_shared_generative_ui.toError)(thrown));
|
|
801
|
+
}
|
|
802
|
+
componentDidMount() {
|
|
803
|
+
if (!this.state.failed) {
|
|
804
|
+
this.props.log.clear(this.props.slot);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
if (this.state.error) this.report(this.state.error);
|
|
808
|
+
}
|
|
809
|
+
componentDidUpdate() {
|
|
810
|
+
if (!this.state.failed) this.props.log.clear(this.props.slot);
|
|
811
|
+
}
|
|
812
|
+
render() {
|
|
813
|
+
return this.state.failed ? this.props.replacement ?? null : this.props.children;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* The host's `NodeFallback`, guarded: when it throws, the node renders
|
|
818
|
+
* nothing and the error is reported, and the parent node keeps rendering.
|
|
819
|
+
* Every place that shows the host fallback goes through this.
|
|
820
|
+
*/
|
|
821
|
+
function GuardedNodeFallback({ surfaceId, componentId, runtime, message, retry, slot, revision }) {
|
|
822
|
+
const { NodeFallback } = useGenerativeUIHost();
|
|
823
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FallbackGuard, {
|
|
824
|
+
surfaceId,
|
|
825
|
+
componentId,
|
|
826
|
+
runtime,
|
|
827
|
+
log: useFailureLog(),
|
|
828
|
+
slot,
|
|
829
|
+
context: message,
|
|
830
|
+
resetKeys: [message, revision],
|
|
831
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeFallback, {
|
|
832
|
+
message,
|
|
833
|
+
componentId: componentId ?? "surface",
|
|
834
|
+
retry
|
|
835
|
+
})
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Calls the app's `errorBoundary.fallback` in a render of its own, so that
|
|
840
|
+
* the guard above it catches what it throws.
|
|
841
|
+
*/
|
|
842
|
+
function AppErrorFallback({ render, ...props }) {
|
|
843
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: render(props) });
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Per-node boundary. Resets on retry or a new agent revision, not on data
|
|
847
|
+
* ticks. A failure that stays the same across revisions is reported once.
|
|
848
|
+
*/
|
|
849
|
+
var NodeBoundary = class extends react.Component {
|
|
850
|
+
constructor(..._args2) {
|
|
851
|
+
super(..._args2);
|
|
605
852
|
this.state = {
|
|
606
853
|
error: null,
|
|
607
854
|
revision: this.props.revision
|
|
608
855
|
};
|
|
609
856
|
this.retry = () => this.setState({ error: null });
|
|
610
857
|
}
|
|
611
|
-
static getDerivedStateFromError(
|
|
612
|
-
return { error };
|
|
858
|
+
static getDerivedStateFromError(thrown) {
|
|
859
|
+
return { error: (0, _copilotkit_shared_generative_ui.toError)(thrown) };
|
|
613
860
|
}
|
|
614
861
|
static getDerivedStateFromProps(props, state) {
|
|
615
862
|
return props.revision !== state.revision ? {
|
|
@@ -617,53 +864,138 @@ var NodeBoundary = class extends react.Component {
|
|
|
617
864
|
revision: props.revision
|
|
618
865
|
} : null;
|
|
619
866
|
}
|
|
620
|
-
componentDidCatch(
|
|
621
|
-
const { runtime, surfaceId, componentId } = this.props;
|
|
622
|
-
(
|
|
867
|
+
componentDidCatch(thrown) {
|
|
868
|
+
const { runtime, surfaceId, componentId, log, place } = this.props;
|
|
869
|
+
log.clear(failureSlots.fallback(place));
|
|
870
|
+
log.report(runtime, failureSlots.node(place), {
|
|
871
|
+
kind: "render",
|
|
872
|
+
surfaceId,
|
|
873
|
+
componentId,
|
|
874
|
+
error: this.state.error ?? (0, _copilotkit_shared_generative_ui.toError)(thrown)
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
slots() {
|
|
878
|
+
const { place } = this.props;
|
|
879
|
+
return [
|
|
880
|
+
failureSlots.node(place),
|
|
881
|
+
failureSlots.appFallback(place),
|
|
882
|
+
failureSlots.renderFallback(place)
|
|
883
|
+
];
|
|
884
|
+
}
|
|
885
|
+
clearSlots() {
|
|
886
|
+
for (const slot of this.slots()) this.props.log.clear(slot);
|
|
887
|
+
}
|
|
888
|
+
componentDidMount() {
|
|
889
|
+
for (const slot of this.slots()) this.props.log.retain(slot);
|
|
890
|
+
if (!this.state.error) {
|
|
891
|
+
this.clearSlots();
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
const { runtime, surfaceId, componentId, log, place } = this.props;
|
|
895
|
+
log.report(runtime, failureSlots.node(place), {
|
|
623
896
|
kind: "render",
|
|
624
897
|
surfaceId,
|
|
625
898
|
componentId,
|
|
626
|
-
error
|
|
899
|
+
error: this.state.error
|
|
627
900
|
});
|
|
628
901
|
}
|
|
902
|
+
componentDidUpdate(prevProps) {
|
|
903
|
+
if (prevProps.place !== this.props.place) {
|
|
904
|
+
const { log } = this.props;
|
|
905
|
+
log.release(failureSlots.node(prevProps.place));
|
|
906
|
+
log.release(failureSlots.appFallback(prevProps.place));
|
|
907
|
+
log.release(failureSlots.renderFallback(prevProps.place));
|
|
908
|
+
for (const slot of this.slots()) log.retain(slot);
|
|
909
|
+
}
|
|
910
|
+
if (!this.state.error) this.clearSlots();
|
|
911
|
+
}
|
|
912
|
+
componentWillUnmount() {
|
|
913
|
+
for (const slot of this.slots()) this.props.log.release(slot);
|
|
914
|
+
}
|
|
629
915
|
render() {
|
|
630
916
|
const { error } = this.state;
|
|
631
917
|
if (!error) return this.props.children;
|
|
632
|
-
const { runtime, surfaceId, componentId } = this.props;
|
|
633
|
-
const
|
|
634
|
-
return fallback ? fallback({
|
|
635
|
-
error,
|
|
636
|
-
retry: this.retry,
|
|
918
|
+
const { runtime, surfaceId, componentId, place, log } = this.props;
|
|
919
|
+
const hostFallback = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
|
|
637
920
|
surfaceId,
|
|
638
|
-
componentId
|
|
639
|
-
|
|
921
|
+
componentId,
|
|
922
|
+
runtime,
|
|
640
923
|
message: error.message,
|
|
924
|
+
retry: this.retry,
|
|
925
|
+
slot: failureSlots.renderFallback(place)
|
|
926
|
+
});
|
|
927
|
+
const fallback = runtime.errorFallback;
|
|
928
|
+
if (!fallback) return hostFallback;
|
|
929
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FallbackGuard, {
|
|
930
|
+
surfaceId,
|
|
641
931
|
componentId,
|
|
642
|
-
|
|
932
|
+
runtime,
|
|
933
|
+
log,
|
|
934
|
+
slot: failureSlots.appFallback(place),
|
|
935
|
+
context: error.message,
|
|
936
|
+
resetKeys: [error],
|
|
937
|
+
replacement: hostFallback,
|
|
938
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppErrorFallback, {
|
|
939
|
+
render: fallback,
|
|
940
|
+
error,
|
|
941
|
+
retry: this.retry,
|
|
942
|
+
surfaceId,
|
|
943
|
+
componentId
|
|
944
|
+
})
|
|
643
945
|
});
|
|
644
946
|
}
|
|
645
947
|
};
|
|
646
|
-
/**
|
|
948
|
+
/**
|
|
949
|
+
* Surface boundary: a failure here must not reach the chat or the host page.
|
|
950
|
+
* It resets on a new revision, and on Retry when `retryable`. A failure that
|
|
951
|
+
* stays the same across revisions is reported once.
|
|
952
|
+
*/
|
|
647
953
|
var SurfaceBoundary = class extends react.Component {
|
|
648
|
-
constructor(...
|
|
649
|
-
super(...
|
|
650
|
-
this.state = {
|
|
954
|
+
constructor(..._args3) {
|
|
955
|
+
super(..._args3);
|
|
956
|
+
this.state = {
|
|
957
|
+
error: null,
|
|
958
|
+
revision: this.props.revision
|
|
959
|
+
};
|
|
960
|
+
this.retry = () => this.setState({ error: null });
|
|
651
961
|
}
|
|
652
|
-
static getDerivedStateFromError(
|
|
653
|
-
return { error };
|
|
962
|
+
static getDerivedStateFromError(thrown) {
|
|
963
|
+
return { error: (0, _copilotkit_shared_generative_ui.toError)(thrown) };
|
|
654
964
|
}
|
|
655
|
-
|
|
656
|
-
|
|
965
|
+
static getDerivedStateFromProps(props, state) {
|
|
966
|
+
return props.revision !== state.revision ? {
|
|
967
|
+
error: null,
|
|
968
|
+
revision: props.revision
|
|
969
|
+
} : null;
|
|
970
|
+
}
|
|
971
|
+
componentDidCatch(thrown) {
|
|
972
|
+
const { runtime, surfaceId, log, level } = this.props;
|
|
973
|
+
log.report(runtime, failureSlots.surface(level), {
|
|
657
974
|
kind: "render",
|
|
658
|
-
surfaceId
|
|
659
|
-
error
|
|
975
|
+
surfaceId,
|
|
976
|
+
error: this.state.error ?? (0, _copilotkit_shared_generative_ui.toError)(thrown)
|
|
660
977
|
});
|
|
661
978
|
}
|
|
979
|
+
clearSlots() {
|
|
980
|
+
const { log, level } = this.props;
|
|
981
|
+
log.clear(failureSlots.surface(level));
|
|
982
|
+
log.clear(failureSlots.surfaceFallback(level));
|
|
983
|
+
}
|
|
984
|
+
componentDidMount() {
|
|
985
|
+
if (!this.state.error) this.clearSlots();
|
|
986
|
+
}
|
|
987
|
+
componentDidUpdate() {
|
|
988
|
+
if (!this.state.error) this.clearSlots();
|
|
989
|
+
}
|
|
662
990
|
render() {
|
|
663
991
|
if (!this.state.error) return this.props.children;
|
|
664
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
992
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
|
|
993
|
+
surfaceId: this.props.surfaceId,
|
|
994
|
+
componentId: void 0,
|
|
995
|
+
runtime: this.props.runtime,
|
|
665
996
|
message: "this generated UI failed to render",
|
|
666
|
-
|
|
997
|
+
retry: this.props.retryable ? this.retry : void 0,
|
|
998
|
+
slot: failureSlots.surfaceFallback(this.props.level)
|
|
667
999
|
});
|
|
668
1000
|
}
|
|
669
1001
|
};
|
|
@@ -693,7 +1025,6 @@ function useGenerativeUIAccessibility() {
|
|
|
693
1025
|
//#endregion
|
|
694
1026
|
//#region src/v2/generative-ui/SurfaceView.tsx
|
|
695
1027
|
const NO_ANCESTORS = [];
|
|
696
|
-
const ROOT_STYLE = { display: "contents" };
|
|
697
1028
|
const undefinedSnapshot = () => void 0;
|
|
698
1029
|
const noopSubscribe = () => () => {};
|
|
699
1030
|
const zeroSnapshot = () => 0;
|
|
@@ -703,23 +1034,80 @@ function isTemplateChildren(value) {
|
|
|
703
1034
|
}
|
|
704
1035
|
function SurfaceView({ surface }) {
|
|
705
1036
|
const runtime = useRequiredGenerativeUIRuntime();
|
|
706
|
-
const {
|
|
707
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
1037
|
+
const { SurfaceRoot } = useGenerativeUIHost();
|
|
1038
|
+
const appliedCount = (0, react.useSyncExternalStore)(runtime.manager.subscribe, () => surface.operations.length, undefinedSnapshot);
|
|
1039
|
+
const revision = (0, react.useMemo)(() => ({
|
|
1040
|
+
surface,
|
|
1041
|
+
appliedCount
|
|
1042
|
+
}), [surface, appliedCount]);
|
|
1043
|
+
const [scopedLog, setScopedLog] = (0, react.useState)(() => ({
|
|
1044
|
+
key: surface.key,
|
|
1045
|
+
log: createFailureLog()
|
|
1046
|
+
}));
|
|
1047
|
+
let failureLog = scopedLog.log;
|
|
1048
|
+
if (scopedLog.key !== surface.key) {
|
|
1049
|
+
const next = {
|
|
1050
|
+
key: surface.key,
|
|
1051
|
+
log: createFailureLog()
|
|
1052
|
+
};
|
|
1053
|
+
setScopedLog(next);
|
|
1054
|
+
failureLog = next.log;
|
|
1055
|
+
}
|
|
1056
|
+
const { threadId, surfaceId } = surface;
|
|
1057
|
+
const { manager } = runtime;
|
|
1058
|
+
const seen = (0, react.useRef)(void 0);
|
|
1059
|
+
(0, react.useLayoutEffect)(() => {
|
|
1060
|
+
const contentOf = () => {
|
|
1061
|
+
const current = manager.getSurface(threadId, surfaceId);
|
|
1062
|
+
return {
|
|
1063
|
+
log: failureLog,
|
|
1064
|
+
current,
|
|
1065
|
+
applied: current?.operations.length
|
|
1066
|
+
};
|
|
1067
|
+
};
|
|
1068
|
+
const observe = (missed) => {
|
|
1069
|
+
const last = seen.current;
|
|
1070
|
+
const next = contentOf();
|
|
1071
|
+
seen.current = next;
|
|
1072
|
+
if (last?.log === failureLog && (next.current !== last.current || next.applied !== last.applied)) failureLog.settle(missed);
|
|
1073
|
+
};
|
|
1074
|
+
observe(true);
|
|
1075
|
+
return manager.subscribe(() => observe(false));
|
|
1076
|
+
}, [
|
|
1077
|
+
manager,
|
|
1078
|
+
threadId,
|
|
1079
|
+
surfaceId,
|
|
1080
|
+
failureLog
|
|
1081
|
+
]);
|
|
1082
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GenerativeUIFailureLogContext.Provider, {
|
|
1083
|
+
value: failureLog,
|
|
1084
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceBoundary, {
|
|
714
1085
|
surfaceId: surface.surfaceId,
|
|
715
1086
|
runtime,
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1087
|
+
log: failureLog,
|
|
1088
|
+
level: "outer",
|
|
1089
|
+
revision,
|
|
1090
|
+
retryable: true,
|
|
1091
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceRoot, {
|
|
1092
|
+
surfaceId: surface.surfaceId,
|
|
1093
|
+
theme: runtime.theme,
|
|
1094
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceBoundary, {
|
|
1095
|
+
surfaceId: surface.surfaceId,
|
|
1096
|
+
runtime,
|
|
1097
|
+
log: failureLog,
|
|
1098
|
+
level: "inner",
|
|
1099
|
+
revision,
|
|
1100
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
|
|
1101
|
+
surface,
|
|
1102
|
+
componentId: _copilotkit_shared.GENERATIVE_UI_ROOT_ID,
|
|
1103
|
+
basePath: void 0,
|
|
1104
|
+
ancestors: NO_ANCESTORS,
|
|
1105
|
+
parentPlace: "",
|
|
1106
|
+
via: ""
|
|
1107
|
+
})
|
|
1108
|
+
})
|
|
721
1109
|
})
|
|
722
|
-
})
|
|
1110
|
+
})
|
|
723
1111
|
});
|
|
724
1112
|
}
|
|
725
1113
|
/**
|
|
@@ -744,27 +1132,63 @@ function useComponentProperties(manager, component) {
|
|
|
744
1132
|
* repeats both.
|
|
745
1133
|
*/
|
|
746
1134
|
function scopedId(componentId, basePath) {
|
|
747
|
-
return `${basePath
|
|
1135
|
+
return `${basePath === void 0 ? "" : JSON.stringify(basePath)}#${JSON.stringify(componentId)}`;
|
|
748
1136
|
}
|
|
749
|
-
|
|
1137
|
+
/**
|
|
1138
|
+
* Where one rendered copy of a node is: the place of its parent, the slot
|
|
1139
|
+
* or child reference of the parent it renders in, and its scoped id. Names
|
|
1140
|
+
* the node's failure-log slots. A scoped id alone is not enough: the same
|
|
1141
|
+
* id can render under two parents, and a cyclic reference repeats the
|
|
1142
|
+
* scoped id of an ancestor. Each copy keeps its own memory of what it
|
|
1143
|
+
* reported, so one copy that renders, goes away or remounts does not clear
|
|
1144
|
+
* the memory of another that still fails.
|
|
1145
|
+
*/
|
|
1146
|
+
function placeOf(parentPlace, via, position) {
|
|
1147
|
+
return `${parentPlace}/${via === "" ? "" : JSON.stringify(via)}${position}`;
|
|
1148
|
+
}
|
|
1149
|
+
const NodeView = (0, react.memo)(function NodeView({ surface, componentId, basePath, ancestors, parentPlace, via }) {
|
|
750
1150
|
const runtime = useRequiredGenerativeUIRuntime();
|
|
1151
|
+
const log = useFailureLog();
|
|
751
1152
|
const component = useComponentModel(runtime.manager, surface.model, componentId);
|
|
752
1153
|
const properties = useComponentProperties(runtime.manager, component);
|
|
753
|
-
|
|
1154
|
+
const position = scopedId(componentId, basePath);
|
|
1155
|
+
const place = placeOf(parentPlace, via, position);
|
|
1156
|
+
(0, react.useEffect)(() => {
|
|
1157
|
+
const slots = [
|
|
1158
|
+
failureSlots.fallback(place),
|
|
1159
|
+
failureSlots.cycle(place),
|
|
1160
|
+
failureSlots.props(place)
|
|
1161
|
+
];
|
|
1162
|
+
for (const slot of slots) log.retain(slot);
|
|
1163
|
+
return () => {
|
|
1164
|
+
for (const slot of slots) log.release(slot);
|
|
1165
|
+
};
|
|
1166
|
+
}, [log, place]);
|
|
1167
|
+
if (ancestors.includes(position)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
|
|
1168
|
+
surfaceId: surface.surfaceId,
|
|
1169
|
+
componentId,
|
|
1170
|
+
runtime,
|
|
754
1171
|
message: `cyclic reference to ${componentId}`,
|
|
755
|
-
|
|
1172
|
+
slot: failureSlots.cycle(place),
|
|
1173
|
+
revision: properties
|
|
756
1174
|
});
|
|
757
1175
|
if (!component || !properties) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodePlaceholder, { componentId });
|
|
758
1176
|
const definition = runtime.ui.components.get(component.type);
|
|
759
|
-
if (!definition) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
1177
|
+
if (!definition) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
|
|
1178
|
+
surfaceId: surface.surfaceId,
|
|
1179
|
+
componentId,
|
|
1180
|
+
runtime,
|
|
760
1181
|
message: `unknown component "${component.type}"`,
|
|
761
|
-
|
|
1182
|
+
slot: failureSlots.fallback(place),
|
|
1183
|
+
revision: properties
|
|
762
1184
|
});
|
|
763
1185
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeBoundary, {
|
|
764
1186
|
surfaceId: surface.surfaceId,
|
|
765
1187
|
componentId,
|
|
1188
|
+
place,
|
|
766
1189
|
revision: properties,
|
|
767
1190
|
runtime,
|
|
1191
|
+
log,
|
|
768
1192
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedNode, {
|
|
769
1193
|
surface,
|
|
770
1194
|
componentId,
|
|
@@ -772,7 +1196,8 @@ const NodeView = (0, react.memo)(function NodeView({ surface, componentId, baseP
|
|
|
772
1196
|
properties,
|
|
773
1197
|
runtime,
|
|
774
1198
|
basePath,
|
|
775
|
-
ancestors
|
|
1199
|
+
ancestors,
|
|
1200
|
+
place
|
|
776
1201
|
})
|
|
777
1202
|
}, component.type);
|
|
778
1203
|
});
|
|
@@ -780,7 +1205,7 @@ const NodeView = (0, react.memo)(function NodeView({ surface, componentId, baseP
|
|
|
780
1205
|
* Renders the component of a template once for each item of the list at the
|
|
781
1206
|
* template path, keyed by index. Renders nothing when there is no list.
|
|
782
1207
|
*/
|
|
783
|
-
function TemplateChildren({ surface, template, basePath, ancestors }) {
|
|
1208
|
+
function TemplateChildren({ surface, template, basePath, ancestors, parentPlace, via }) {
|
|
784
1209
|
const dataModel = surface.model.dataModel;
|
|
785
1210
|
const listPath = (0, _copilotkit_core_generative_ui.resolvePath)(template.path, basePath);
|
|
786
1211
|
const subscribe = (0, react.useCallback)((onChange) => {
|
|
@@ -796,17 +1221,25 @@ function TemplateChildren({ surface, template, basePath, ancestors }) {
|
|
|
796
1221
|
surface,
|
|
797
1222
|
componentId: template.componentId,
|
|
798
1223
|
basePath: (0, _copilotkit_core_generative_ui.joinPath)(listPath, String(index)),
|
|
799
|
-
ancestors
|
|
1224
|
+
ancestors,
|
|
1225
|
+
parentPlace,
|
|
1226
|
+
via
|
|
800
1227
|
}, index)) });
|
|
801
1228
|
}
|
|
802
1229
|
/**
|
|
803
1230
|
* The props the model sets, with their dynamic values resolved from the
|
|
804
1231
|
* surface data model: `{"@path"}` bindings, `{"@call"}` function values and
|
|
805
|
-
* `{"@call":"@index"}` in a template, at any depth.
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
1232
|
+
* `{"@call":"@index"}` in a template, at any depth. Bound props, events and
|
|
1233
|
+
* slots are left out, and so are the keys of the A2UI component envelope;
|
|
1234
|
+
* `accessibility` is resolved the same way and given on its own.
|
|
1235
|
+
*
|
|
1236
|
+
* A writable prop that is not bound to a path and that the component set
|
|
1237
|
+
* shows the local value from `overrides`, also when the model never set the
|
|
1238
|
+
* prop. That is intended: the user's edit wins over the model's literal
|
|
1239
|
+
* value, also over a newer literal the agent sends later, until the node
|
|
1240
|
+
* remounts. A literal is not data the agent and the user share; a prop
|
|
1241
|
+
* that both must write is bound to a path, and the setter writes the data
|
|
1242
|
+
* model.
|
|
810
1243
|
*
|
|
811
1244
|
* A prop is resolved again only when its raw value or a data model value it
|
|
812
1245
|
* read has changed, so the result keeps its identity otherwise. A function
|
|
@@ -817,7 +1250,7 @@ function useModelDataProps(surface, definition, properties, basePath, overrides)
|
|
|
817
1250
|
const units = (0, react.useMemo)(() => {
|
|
818
1251
|
const list = [];
|
|
819
1252
|
for (const key of Object.keys(properties)) {
|
|
820
|
-
if (definition.events?.[key] || definition.slots?.[key] ||
|
|
1253
|
+
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;
|
|
821
1254
|
list.push({
|
|
822
1255
|
key,
|
|
823
1256
|
raw: properties[key]
|
|
@@ -918,9 +1351,10 @@ function select(definition, state, modelProps) {
|
|
|
918
1351
|
for (const [key, selector] of selectors) try {
|
|
919
1352
|
values[key] = selector(state, modelProps);
|
|
920
1353
|
} catch (error) {
|
|
1354
|
+
const { message } = (0, _copilotkit_shared_generative_ui.toError)(error);
|
|
921
1355
|
return {
|
|
922
1356
|
ok: false,
|
|
923
|
-
problem: `${key}: selector threw: ${
|
|
1357
|
+
problem: `${key}: selector threw: ${message}`
|
|
924
1358
|
};
|
|
925
1359
|
}
|
|
926
1360
|
return {
|
|
@@ -931,8 +1365,10 @@ function select(definition, state, modelProps) {
|
|
|
931
1365
|
/**
|
|
932
1366
|
* The values of the bound props of a node, read from the app state.
|
|
933
1367
|
*
|
|
934
|
-
* The selectors
|
|
935
|
-
*
|
|
1368
|
+
* The selectors get the checked model props: the resolved values that
|
|
1369
|
+
* passed the props schema (without the nulls it rejected), not the
|
|
1370
|
+
* schema's parsed output, so its defaults and transforms are not applied
|
|
1371
|
+
* 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
|
|
936
1372
|
* last snapshot is kept. So the node re-renders only when a selected value
|
|
937
1373
|
* changes. A selector that returns a new array on each call cannot cause a
|
|
938
1374
|
* render loop: with the same inputs, the cached snapshot comes back.
|
|
@@ -962,7 +1398,10 @@ function useSelection(manager, definition, modelProps) {
|
|
|
962
1398
|
* Checks the model-set props with the props schema before the selectors run.
|
|
963
1399
|
* The bound props are not set yet, so their issues do not count. Neither do
|
|
964
1400
|
* issues with no path (a check over several props), which the full check
|
|
965
|
-
* after the selectors reports.
|
|
1401
|
+
* after the selectors reports. The exception is the issue that an async
|
|
1402
|
+
* props schema gives (`isAsyncIssue`): the render checks props
|
|
1403
|
+
* synchronously only, so the full check would fail the same way, and it is
|
|
1404
|
+
* reported here.
|
|
966
1405
|
*/
|
|
967
1406
|
function checkModelProps(definition, modelData) {
|
|
968
1407
|
if (!definition.props) return {
|
|
@@ -981,7 +1420,7 @@ function checkModelProps(definition, modelData) {
|
|
|
981
1420
|
if (!result.success) {
|
|
982
1421
|
const issues = result.issues.filter((issue) => {
|
|
983
1422
|
const key = (0, _copilotkit_shared_generative_ui.issueKey)(issue);
|
|
984
|
-
return key === void 0 ? (0, _copilotkit_shared_generative_ui.isAsyncIssue)(issue) : !
|
|
1423
|
+
return key === void 0 ? (0, _copilotkit_shared_generative_ui.isAsyncIssue)(issue) : !(0, _copilotkit_shared_generative_ui.hasOwnKey)(definition.selectors, key);
|
|
985
1424
|
});
|
|
986
1425
|
if (issues.length > 0) return {
|
|
987
1426
|
ok: false,
|
|
@@ -1044,7 +1483,7 @@ function useDataProps(runtime, surface, definition, properties, basePath, overri
|
|
|
1044
1483
|
function useEventProps(runtime, surface, componentId, definition, properties, basePath) {
|
|
1045
1484
|
const latest = (0, react.useRef)(properties);
|
|
1046
1485
|
latest.current = properties;
|
|
1047
|
-
const boundNames = Object.keys(definition.events ?? {}).filter((name) =>
|
|
1486
|
+
const boundNames = Object.keys(definition.events ?? {}).filter((name) => (0, _copilotkit_shared_generative_ui.hasOwnKey)(definition.eventFunctions, name) || (0, _copilotkit_shared.isActionBinding)(properties[name])).join("|");
|
|
1048
1487
|
return (0, react.useMemo)(() => {
|
|
1049
1488
|
const handlers = {};
|
|
1050
1489
|
const names = boundNames ? boundNames.split("|") : [];
|
|
@@ -1056,7 +1495,7 @@ function useEventProps(runtime, surface, componentId, definition, properties, ba
|
|
|
1056
1495
|
name,
|
|
1057
1496
|
parameters: definition.events?.[name]?.parameters
|
|
1058
1497
|
};
|
|
1059
|
-
const functionName =
|
|
1498
|
+
const functionName = (0, _copilotkit_shared_generative_ui.hasOwnKey)(definition.eventFunctions, name) ? definition.eventFunctions[name] : void 0;
|
|
1060
1499
|
handlers[name] = functionName === void 0 ? (args) => (0, _copilotkit_core_generative_ui.invokeBoundEvent)({
|
|
1061
1500
|
...call,
|
|
1062
1501
|
binding: latest.current[name],
|
|
@@ -1082,7 +1521,9 @@ function useEventProps(runtime, surface, componentId, definition, properties, ba
|
|
|
1082
1521
|
* The setter props of a node: `setValue` for the writable prop `value`. For
|
|
1083
1522
|
* a prop the model bound to `{"@path"}`, the setter writes the data model
|
|
1084
1523
|
* and makes the path user-owned. For a literal prop, it sets `overrides`, a
|
|
1085
|
-
* local value of this mounted node
|
|
1524
|
+
* local value of this mounted node that wins over the model's value until
|
|
1525
|
+
* the node remounts (see `useModelDataProps`). The setters keep their
|
|
1526
|
+
* identity.
|
|
1086
1527
|
*/
|
|
1087
1528
|
function useSetterProps(runtime, surface, componentId, definition, properties, basePath) {
|
|
1088
1529
|
const [overrides, setOverrides] = (0, react.useState)({});
|
|
@@ -1105,7 +1546,7 @@ function useSetterProps(runtime, surface, componentId, definition, properties, b
|
|
|
1105
1546
|
try {
|
|
1106
1547
|
runtime.manager.setOwnedValue(surface.key, (0, _copilotkit_core_generative_ui.resolvePath)(binding["@path"], basePath), value);
|
|
1107
1548
|
} catch (cause) {
|
|
1108
|
-
const message =
|
|
1549
|
+
const { message } = (0, _copilotkit_shared_generative_ui.toError)(cause);
|
|
1109
1550
|
(0, _copilotkit_core_generative_ui.reportErrorSafely)(runtime, {
|
|
1110
1551
|
kind: "props",
|
|
1111
1552
|
surfaceId: surface.surfaceId,
|
|
@@ -1124,29 +1565,36 @@ function useSetterProps(runtime, surface, componentId, definition, properties, b
|
|
|
1124
1565
|
])
|
|
1125
1566
|
};
|
|
1126
1567
|
}
|
|
1127
|
-
function useSlotProps(surface, definition, properties, componentId, basePath, ancestors) {
|
|
1568
|
+
function useSlotProps(surface, definition, properties, componentId, basePath, ancestors, place) {
|
|
1128
1569
|
return (0, react.useMemo)(() => {
|
|
1129
1570
|
const childAncestors = [...ancestors, scopedId(componentId, basePath)];
|
|
1130
1571
|
const slots = {};
|
|
1131
1572
|
for (const [name, kind] of Object.entries(definition.slots ?? {})) {
|
|
1132
1573
|
const value = properties[name];
|
|
1574
|
+
const via = `${name}:`;
|
|
1133
1575
|
if (kind === "single" && typeof value === "string") slots[name] = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
|
|
1134
1576
|
surface,
|
|
1135
1577
|
componentId: value,
|
|
1136
1578
|
basePath,
|
|
1137
|
-
ancestors: childAncestors
|
|
1579
|
+
ancestors: childAncestors,
|
|
1580
|
+
parentPlace: place,
|
|
1581
|
+
via
|
|
1138
1582
|
});
|
|
1139
1583
|
else if (kind === "multiple" && isTemplateChildren(value)) slots[name] = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TemplateChildren, {
|
|
1140
1584
|
surface,
|
|
1141
1585
|
template: value,
|
|
1142
1586
|
basePath,
|
|
1143
|
-
ancestors: childAncestors
|
|
1587
|
+
ancestors: childAncestors,
|
|
1588
|
+
parentPlace: place,
|
|
1589
|
+
via
|
|
1144
1590
|
});
|
|
1145
1591
|
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, {
|
|
1146
1592
|
surface,
|
|
1147
1593
|
componentId: id,
|
|
1148
1594
|
basePath,
|
|
1149
|
-
ancestors: childAncestors
|
|
1595
|
+
ancestors: childAncestors,
|
|
1596
|
+
parentPlace: place,
|
|
1597
|
+
via
|
|
1150
1598
|
}, id));
|
|
1151
1599
|
}
|
|
1152
1600
|
return slots;
|
|
@@ -1156,7 +1604,8 @@ function useSlotProps(surface, definition, properties, componentId, basePath, an
|
|
|
1156
1604
|
properties,
|
|
1157
1605
|
componentId,
|
|
1158
1606
|
basePath,
|
|
1159
|
-
ancestors
|
|
1607
|
+
ancestors,
|
|
1608
|
+
place
|
|
1160
1609
|
]);
|
|
1161
1610
|
}
|
|
1162
1611
|
/**
|
|
@@ -1164,33 +1613,43 @@ function useSlotProps(surface, definition, properties, componentId, basePath, an
|
|
|
1164
1613
|
* `childList()`, at any depth) replaced by the rendered component. Without
|
|
1165
1614
|
* references, the parsed props come back as they are.
|
|
1166
1615
|
*/
|
|
1167
|
-
function useChildRefProps(surface, refs, props, componentId, basePath, ancestors) {
|
|
1616
|
+
function useChildRefProps(surface, refs, props, componentId, basePath, ancestors, place) {
|
|
1168
1617
|
return (0, react.useMemo)(() => {
|
|
1169
1618
|
if (props === void 0 || refs.length === 0) return props;
|
|
1170
1619
|
const childAncestors = [...ancestors, scopedId(componentId, basePath)];
|
|
1171
|
-
const render = (kind, value) => {
|
|
1620
|
+
const render = (kind, value, via) => {
|
|
1172
1621
|
if (kind === "single") return typeof value === "string" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
|
|
1173
1622
|
surface,
|
|
1174
1623
|
componentId: value,
|
|
1175
1624
|
basePath,
|
|
1176
|
-
ancestors: childAncestors
|
|
1625
|
+
ancestors: childAncestors,
|
|
1626
|
+
parentPlace: place,
|
|
1627
|
+
via
|
|
1177
1628
|
}) : void 0;
|
|
1178
1629
|
if (isTemplateChildren(value)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TemplateChildren, {
|
|
1179
1630
|
surface,
|
|
1180
1631
|
template: value,
|
|
1181
1632
|
basePath,
|
|
1182
|
-
ancestors: childAncestors
|
|
1633
|
+
ancestors: childAncestors,
|
|
1634
|
+
parentPlace: place,
|
|
1635
|
+
via
|
|
1183
1636
|
});
|
|
1184
1637
|
if (!Array.isArray(value)) return void 0;
|
|
1185
1638
|
return [...new Set(value.filter((id) => typeof id === "string"))].map((id) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NodeView, {
|
|
1186
1639
|
surface,
|
|
1187
1640
|
componentId: id,
|
|
1188
1641
|
basePath,
|
|
1189
|
-
ancestors: childAncestors
|
|
1642
|
+
ancestors: childAncestors,
|
|
1643
|
+
parentPlace: place,
|
|
1644
|
+
via
|
|
1190
1645
|
}, id));
|
|
1191
1646
|
};
|
|
1192
1647
|
let result = props;
|
|
1193
|
-
for (const ref of refs)
|
|
1648
|
+
for (const ref of refs) {
|
|
1649
|
+
let found = 0;
|
|
1650
|
+
const path = ref.path.join(".");
|
|
1651
|
+
result = (0, _copilotkit_shared.mapAtChildRef)(result, ref.path, (value) => render(ref.kind, value, `${path}[${found++}]:`));
|
|
1652
|
+
}
|
|
1194
1653
|
return result;
|
|
1195
1654
|
}, [
|
|
1196
1655
|
surface,
|
|
@@ -1198,15 +1657,17 @@ function useChildRefProps(surface, refs, props, componentId, basePath, ancestors
|
|
|
1198
1657
|
props,
|
|
1199
1658
|
componentId,
|
|
1200
1659
|
basePath,
|
|
1201
|
-
ancestors
|
|
1660
|
+
ancestors,
|
|
1661
|
+
place
|
|
1202
1662
|
]);
|
|
1203
1663
|
}
|
|
1204
|
-
function ResolvedNode({ surface, componentId, definition, properties, runtime, basePath, ancestors }) {
|
|
1664
|
+
function ResolvedNode({ surface, componentId, definition, properties, runtime, basePath, ancestors, place }) {
|
|
1665
|
+
const { AccessibilityWrapper } = useGenerativeUIHost();
|
|
1205
1666
|
const { overrides, setters } = useSetterProps(runtime, surface, componentId, definition, properties, basePath);
|
|
1206
1667
|
const dataProps = useDataProps(runtime, surface, definition, properties, basePath, overrides);
|
|
1207
1668
|
const eventProps = useEventProps(runtime, surface, componentId, definition, properties, basePath);
|
|
1208
|
-
const slotProps = useSlotProps(surface, definition, properties, componentId, basePath, ancestors);
|
|
1209
|
-
const childRefProps = useChildRefProps(surface, definition.childRefs, dataProps.ok ? dataProps.props : void 0, componentId, basePath, ancestors);
|
|
1669
|
+
const slotProps = useSlotProps(surface, definition, properties, componentId, basePath, ancestors, place);
|
|
1670
|
+
const childRefProps = useChildRefProps(surface, definition.childRefs, dataProps.ok ? dataProps.props : void 0, componentId, basePath, ancestors, place);
|
|
1210
1671
|
const accessibility = dataProps.ok ? dataProps.accessibility : void 0;
|
|
1211
1672
|
const nodeContext = (0, react.useMemo)(() => ({
|
|
1212
1673
|
surfaceKey: surface.key,
|
|
@@ -1220,8 +1681,19 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
|
|
|
1220
1681
|
accessibility
|
|
1221
1682
|
]);
|
|
1222
1683
|
const problem = dataProps.ok ? void 0 : dataProps.problem;
|
|
1684
|
+
const log = useFailureLog();
|
|
1223
1685
|
(0, react.useEffect)(() => {
|
|
1224
|
-
if (problem)
|
|
1686
|
+
if (!problem) {
|
|
1687
|
+
log.clear(failureSlots.fallback(place));
|
|
1688
|
+
log.clear(failureSlots.props(place));
|
|
1689
|
+
}
|
|
1690
|
+
}, [
|
|
1691
|
+
problem,
|
|
1692
|
+
log,
|
|
1693
|
+
place
|
|
1694
|
+
]);
|
|
1695
|
+
(0, react.useEffect)(() => {
|
|
1696
|
+
if (problem) log.report(runtime, failureSlots.props(place), {
|
|
1225
1697
|
kind: "props",
|
|
1226
1698
|
surfaceId: surface.surfaceId,
|
|
1227
1699
|
componentId,
|
|
@@ -1229,13 +1701,19 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
|
|
|
1229
1701
|
});
|
|
1230
1702
|
}, [
|
|
1231
1703
|
problem,
|
|
1704
|
+
log,
|
|
1705
|
+
place,
|
|
1232
1706
|
runtime,
|
|
1233
1707
|
surface.surfaceId,
|
|
1234
1708
|
componentId
|
|
1235
1709
|
]);
|
|
1236
|
-
if (!dataProps.ok) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
1710
|
+
if (!dataProps.ok) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GuardedNodeFallback, {
|
|
1711
|
+
surfaceId: surface.surfaceId,
|
|
1712
|
+
componentId,
|
|
1713
|
+
runtime,
|
|
1237
1714
|
message: `invalid props (${problem})`,
|
|
1238
|
-
|
|
1715
|
+
slot: failureSlots.fallback(place),
|
|
1716
|
+
revision: properties
|
|
1239
1717
|
});
|
|
1240
1718
|
const Component = definition.component;
|
|
1241
1719
|
const rendered = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
@@ -1247,10 +1725,8 @@ function ResolvedNode({ surface, componentId, definition, properties, runtime, b
|
|
|
1247
1725
|
const hasEnvelope = properties.accessibility !== void 0 && definition.accessibility !== "self";
|
|
1248
1726
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GenerativeUINodeContext.Provider, {
|
|
1249
1727
|
value: nodeContext,
|
|
1250
|
-
children: hasEnvelope ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
1251
|
-
|
|
1252
|
-
style: ROOT_STYLE,
|
|
1253
|
-
...(0, _copilotkit_core_generative_ui.wrapperAria)((0, _copilotkit_core_generative_ui.accessibilityAttributes)(accessibility)),
|
|
1728
|
+
children: hasEnvelope ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccessibilityWrapper, {
|
|
1729
|
+
attributes: (0, _copilotkit_core_generative_ui.wrapperAria)((0, _copilotkit_core_generative_ui.accessibilityAttributes)(accessibility)),
|
|
1254
1730
|
children: rendered
|
|
1255
1731
|
}) : rendered
|
|
1256
1732
|
});
|
|
@@ -1270,39 +1746,18 @@ function DefaultGenerativeUIChatCard({ surfaceId, isStreaming, error, children }
|
|
|
1270
1746
|
})]
|
|
1271
1747
|
});
|
|
1272
1748
|
}
|
|
1273
|
-
const ContentSchema = zod.z.object({
|
|
1274
|
-
surfaceId: zod.z.string(),
|
|
1275
|
-
target: zod.z.string(),
|
|
1276
|
-
catalogId: zod.z.string(),
|
|
1277
|
-
operations: zod.z.array(zod.z.any()),
|
|
1278
|
-
status: zod.z.enum([
|
|
1279
|
-
"streaming",
|
|
1280
|
-
"ready",
|
|
1281
|
-
"error"
|
|
1282
|
-
]),
|
|
1283
|
-
rejected: zod.z.array(zod.z.object({
|
|
1284
|
-
index: zod.z.number(),
|
|
1285
|
-
reason: zod.z.string()
|
|
1286
|
-
})).default([])
|
|
1287
|
-
}).passthrough();
|
|
1288
1749
|
function GenerativeUIChatActivity({ content, agent }) {
|
|
1289
1750
|
const runtime = useGenerativeUIRuntime();
|
|
1290
1751
|
const threadId = useCopilotChatConfiguration()?.threadId ?? agent?.threadId;
|
|
1291
1752
|
const Wrapper = (0, react.useContext)(GenerativeUIChatSlotContext) ?? DefaultGenerativeUIChatCard;
|
|
1292
|
-
|
|
1293
|
-
(0, react.useLayoutEffect)(() => {
|
|
1294
|
-
if (runtime && threadId) runtime.manager.ingest(threadId, agent?.agentId, content);
|
|
1295
|
-
}, [
|
|
1753
|
+
const { surface, rejected, error } = useGenerativeUIActivitySurface({
|
|
1296
1754
|
runtime,
|
|
1297
1755
|
threadId,
|
|
1298
|
-
agent?.agentId,
|
|
1299
|
-
content
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
const surface = runtime.manager.getSurface(threadId, content.surfaceId) ?? runtime.manager.getFailedSurface(threadId, content.surfaceId);
|
|
1756
|
+
agentId: agent?.agentId,
|
|
1757
|
+
content,
|
|
1758
|
+
target: _copilotkit_shared.GENERATIVE_UI_CHAT_TARGET
|
|
1759
|
+
});
|
|
1303
1760
|
if (!surface) return null;
|
|
1304
|
-
const rejected = [...content.rejected ?? [], ...surface.clientRejected];
|
|
1305
|
-
const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
|
|
1306
1761
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
|
|
1307
1762
|
surfaceId: content.surfaceId,
|
|
1308
1763
|
isStreaming: content.status === "streaming",
|
|
@@ -1314,7 +1769,7 @@ function GenerativeUIChatActivity({ content, agent }) {
|
|
|
1314
1769
|
function createGenerativeUIActivityRenderer() {
|
|
1315
1770
|
return {
|
|
1316
1771
|
activityType: _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE,
|
|
1317
|
-
content:
|
|
1772
|
+
content: _copilotkit_core_generative_ui.GenerativeUISurfaceContentSchema,
|
|
1318
1773
|
render: GenerativeUIChatActivity
|
|
1319
1774
|
};
|
|
1320
1775
|
}
|
|
@@ -1345,126 +1800,6 @@ function GenerativeUIToolCallRenderer() {
|
|
|
1345
1800
|
return null;
|
|
1346
1801
|
}
|
|
1347
1802
|
|
|
1348
|
-
//#endregion
|
|
1349
|
-
//#region src/v2/generative-ui/markdown/MarkdownSurfaces.tsx
|
|
1350
|
-
const FADE_STYLE_ID = "a2ui-markdown-fade";
|
|
1351
|
-
/**
|
|
1352
|
-
* Components fade in as they stream: each element that appears under a
|
|
1353
|
-
* markdown surface runs the keyframes once on mount. React keeps the keys
|
|
1354
|
-
* stable per component id, so an element that is already there never
|
|
1355
|
-
* animates again. SVG internals are left out: a chart library re-creates
|
|
1356
|
-
* its nodes on each render, and a fade on each of them would read as the
|
|
1357
|
-
* chart flashing whenever a sibling arrives. The fade runs under reduced
|
|
1358
|
-
* motion too, because it moves nothing.
|
|
1359
|
-
*/
|
|
1360
|
-
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");
|
|
1361
|
-
const noEffect = () => {};
|
|
1362
|
-
const useInjectEffect = typeof document === "undefined" ? noEffect : react.useInsertionEffect;
|
|
1363
|
-
function useFadeStyles() {
|
|
1364
|
-
useInjectEffect(() => {
|
|
1365
|
-
if (document.getElementById(FADE_STYLE_ID)) return;
|
|
1366
|
-
const style = document.createElement("style");
|
|
1367
|
-
style.id = FADE_STYLE_ID;
|
|
1368
|
-
style.textContent = FADE_CSS;
|
|
1369
|
-
document.head.appendChild(style);
|
|
1370
|
-
}, []);
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* The default wrapper of a chat surface in the markdown transport. It draws
|
|
1374
|
-
* no box: a surface sits in the flow of the reply like a paragraph, and a
|
|
1375
|
-
* Card draws its own box when it is interactive. Nothing shows while the
|
|
1376
|
-
* surface streams. A rejected operation gets one line.
|
|
1377
|
-
*/
|
|
1378
|
-
function DefaultMarkdownChatSurface({ surfaceId, error, children }) {
|
|
1379
|
-
useFadeStyles();
|
|
1380
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1381
|
-
"data-generative-ui-chat-surface": surfaceId,
|
|
1382
|
-
"data-a2ui-markdown-surface": surfaceId,
|
|
1383
|
-
className: "cpk:relative cpk:my-4 cpk:flex cpk:w-full cpk:min-w-0 cpk:max-w-full cpk:flex-col",
|
|
1384
|
-
children: [children, error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1385
|
-
role: "alert",
|
|
1386
|
-
className: "cpk:mt-2 cpk:text-xs cpk:text-red-600",
|
|
1387
|
-
children: "Part of this UI couldn't be shown."
|
|
1388
|
-
})]
|
|
1389
|
-
});
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* One chat surface in the chat wrapper. Nothing renders until the surface
|
|
1393
|
-
* has its root component, so a half-streamed fence shows no empty card.
|
|
1394
|
-
*/
|
|
1395
|
-
function ChatSurface({ runtime, threadId, surfaceId, Wrapper }) {
|
|
1396
|
-
const surface = runtime.manager.getSurface(threadId, surfaceId) ?? runtime.manager.getFailedSurface(threadId, surfaceId);
|
|
1397
|
-
const root = surface?.model.componentsModel.get(_copilotkit_shared.GENERATIVE_UI_ROOT_ID);
|
|
1398
|
-
if (!surface || !root && !surface.failed) return null;
|
|
1399
|
-
const rejected = [...surface.serverRejected, ...surface.clientRejected];
|
|
1400
|
-
const error = rejected.length ? new Error(`${rejected.length} UI update(s) could not be shown`, { cause: rejected }) : void 0;
|
|
1401
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
|
|
1402
|
-
surfaceId,
|
|
1403
|
-
isStreaming: surface.status === "streaming",
|
|
1404
|
-
error,
|
|
1405
|
-
rejected,
|
|
1406
|
-
children: surface.failed ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SurfaceView, { surface })
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
/** The blocks of one fence: lifted prose and chat surfaces, in order. */
|
|
1410
|
-
function FenceBlocks({ blocks, runtime, threadId, markdownProps }) {
|
|
1411
|
-
const Wrapper = (0, react.useContext)(GenerativeUIChatSlotContext) ?? DefaultMarkdownChatSurface;
|
|
1412
|
-
let surfaceCount = 0;
|
|
1413
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blocks.map((block) => {
|
|
1414
|
-
if (block.kind === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
|
|
1415
|
-
...markdownProps,
|
|
1416
|
-
children: block.markdown
|
|
1417
|
-
}, `md-${surfaceCount}`);
|
|
1418
|
-
surfaceCount++;
|
|
1419
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChatSurface, {
|
|
1420
|
-
runtime,
|
|
1421
|
-
threadId,
|
|
1422
|
-
surfaceId: block.surfaceId,
|
|
1423
|
-
Wrapper
|
|
1424
|
-
}, block.surfaceId);
|
|
1425
|
-
}) });
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Experimental. Renders an assistant message of the markdown transport.
|
|
1429
|
-
* Prose renders as markdown. In place of each ```a2ui fence:
|
|
1430
|
-
*
|
|
1431
|
-
* - the fence that created a chat surface renders that surface (and the
|
|
1432
|
-
* prose lifted out of it) in the chat wrapper;
|
|
1433
|
-
* - every other fence renders nothing: a fence that updates the surface of
|
|
1434
|
-
* an earlier fence, or a fence for a named target, which
|
|
1435
|
-
* `<GenerativeUISurface id>` renders.
|
|
1436
|
-
*
|
|
1437
|
-
* Use it inside `<CopilotKitProvider generativeUI={{ ui, transport: "markdown" }}>`.
|
|
1438
|
-
* `CopilotChatAssistantMessage` uses it there on its own.
|
|
1439
|
-
*
|
|
1440
|
-
* @example
|
|
1441
|
-
* ```tsx
|
|
1442
|
-
* <MarkdownSurfaces content={message.content} messageId={message.id} />
|
|
1443
|
-
* ```
|
|
1444
|
-
*/
|
|
1445
|
-
function MarkdownSurfaces({ content, messageId, ...markdownProps }) {
|
|
1446
|
-
const runtime = useRequiredGenerativeUIRuntime();
|
|
1447
|
-
const chatThreadId = useCopilotChatConfiguration()?.threadId;
|
|
1448
|
-
useManagerVersion(runtime);
|
|
1449
|
-
const segments = (0, react.useMemo)(() => (0, _copilotkit_core.splitA2UIMarkdown)(content), [content]);
|
|
1450
|
-
const threadId = chatThreadId ?? runtime.manager.getActiveThread();
|
|
1451
|
-
const source = (0, _copilotkit_core_generative_ui.getMarkdownSurfaceSource)(runtime);
|
|
1452
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: segments.map((segment, index) => {
|
|
1453
|
-
if (segment.type === "markdown") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
|
|
1454
|
-
...markdownProps,
|
|
1455
|
-
children: segment.text
|
|
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
|
-
markdownProps
|
|
1464
|
-
}, `a2ui-${segment.index}`);
|
|
1465
|
-
}) });
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
1803
|
//#endregion
|
|
1469
1804
|
Object.defineProperty(exports, 'ControlledModalOpenScope', {
|
|
1470
1805
|
enumerable: true,
|
|
@@ -1496,6 +1831,12 @@ Object.defineProperty(exports, 'GenerativeUIChatSlotContext', {
|
|
|
1496
1831
|
return GenerativeUIChatSlotContext;
|
|
1497
1832
|
}
|
|
1498
1833
|
});
|
|
1834
|
+
Object.defineProperty(exports, 'GenerativeUIHostContext', {
|
|
1835
|
+
enumerable: true,
|
|
1836
|
+
get: function () {
|
|
1837
|
+
return GenerativeUIHostContext;
|
|
1838
|
+
}
|
|
1839
|
+
});
|
|
1499
1840
|
Object.defineProperty(exports, 'GenerativeUINodeContext', {
|
|
1500
1841
|
enumerable: true,
|
|
1501
1842
|
get: function () {
|
|
@@ -1514,12 +1855,6 @@ Object.defineProperty(exports, 'GenerativeUIToolCallRenderer', {
|
|
|
1514
1855
|
return GenerativeUIToolCallRenderer;
|
|
1515
1856
|
}
|
|
1516
1857
|
});
|
|
1517
|
-
Object.defineProperty(exports, 'MarkdownSurfaces', {
|
|
1518
|
-
enumerable: true,
|
|
1519
|
-
get: function () {
|
|
1520
|
-
return MarkdownSurfaces;
|
|
1521
|
-
}
|
|
1522
|
-
});
|
|
1523
1858
|
Object.defineProperty(exports, 'SurfaceView', {
|
|
1524
1859
|
enumerable: true,
|
|
1525
1860
|
get: function () {
|
|
@@ -1574,28 +1909,40 @@ Object.defineProperty(exports, 'useGenerativeUIAccessibility', {
|
|
|
1574
1909
|
return useGenerativeUIAccessibility;
|
|
1575
1910
|
}
|
|
1576
1911
|
});
|
|
1912
|
+
Object.defineProperty(exports, 'useGenerativeUIActivitySurface', {
|
|
1913
|
+
enumerable: true,
|
|
1914
|
+
get: function () {
|
|
1915
|
+
return useGenerativeUIActivitySurface;
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1577
1918
|
Object.defineProperty(exports, 'useGenerativeUIFunction', {
|
|
1578
1919
|
enumerable: true,
|
|
1579
1920
|
get: function () {
|
|
1580
1921
|
return useGenerativeUIFunction;
|
|
1581
1922
|
}
|
|
1582
1923
|
});
|
|
1583
|
-
Object.defineProperty(exports, '
|
|
1924
|
+
Object.defineProperty(exports, 'useGenerativeUIHost', {
|
|
1584
1925
|
enumerable: true,
|
|
1585
1926
|
get: function () {
|
|
1586
|
-
return
|
|
1927
|
+
return useGenerativeUIHost;
|
|
1587
1928
|
}
|
|
1588
1929
|
});
|
|
1589
|
-
Object.defineProperty(exports, '
|
|
1930
|
+
Object.defineProperty(exports, 'useGenerativeUIRejected', {
|
|
1590
1931
|
enumerable: true,
|
|
1591
1932
|
get: function () {
|
|
1592
|
-
return
|
|
1933
|
+
return useGenerativeUIRejected;
|
|
1593
1934
|
}
|
|
1594
1935
|
});
|
|
1595
|
-
Object.defineProperty(exports, '
|
|
1936
|
+
Object.defineProperty(exports, 'useGenerativeUIRuntime', {
|
|
1596
1937
|
enumerable: true,
|
|
1597
1938
|
get: function () {
|
|
1598
|
-
return
|
|
1939
|
+
return useGenerativeUIRuntime;
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
Object.defineProperty(exports, 'useGenerativeUIState', {
|
|
1943
|
+
enumerable: true,
|
|
1944
|
+
get: function () {
|
|
1945
|
+
return useGenerativeUIState;
|
|
1599
1946
|
}
|
|
1600
1947
|
});
|
|
1601
1948
|
Object.defineProperty(exports, 'useManagerVersion', {
|
|
@@ -1616,4 +1963,4 @@ Object.defineProperty(exports, 'useShallowStableRef', {
|
|
|
1616
1963
|
return useShallowStableRef;
|
|
1617
1964
|
}
|
|
1618
1965
|
});
|
|
1619
|
-
//# sourceMappingURL=
|
|
1966
|
+
//# sourceMappingURL=chat-BnsrQ0VS.cjs.map
|