@copilotkit/react-core 2.0.0-rc.6 → 2.0.0-rc.61
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/README.md +1 -1
- package/dist/MarkdownRendererContext-QFCldfW_.d.cts +34 -0
- package/dist/MarkdownRendererContext-QFCldfW_.d.cts.map +1 -0
- package/dist/MarkdownRendererContext-aK63ZFd-.d.mts +34 -0
- package/dist/MarkdownRendererContext-aK63ZFd-.d.mts.map +1 -0
- package/dist/MarkdownSurfaces-Do948N1P.cjs +141 -0
- package/dist/MarkdownSurfaces-Do948N1P.cjs.map +1 -0
- package/dist/MarkdownSurfaces-rtE9wRUP.mjs +135 -0
- package/dist/MarkdownSurfaces-rtE9wRUP.mjs.map +1 -0
- package/dist/ProviderMarkdown-D0eI0aPo.cjs +268 -0
- package/dist/ProviderMarkdown-D0eI0aPo.cjs.map +1 -0
- package/dist/ProviderMarkdown-epL7F3Vt.mjs +214 -0
- package/dist/ProviderMarkdown-epL7F3Vt.mjs.map +1 -0
- package/dist/accessibility-BLK-gE0R.mjs +129 -0
- package/dist/accessibility-BLK-gE0R.mjs.map +1 -0
- package/dist/accessibility-GnodqxkH.cjs +228 -0
- package/dist/accessibility-GnodqxkH.cjs.map +1 -0
- package/dist/chat-B1zczXUD.mjs +1476 -0
- package/dist/chat-B1zczXUD.mjs.map +1 -0
- package/dist/chat-BZ_bvAkg.d.mts +38 -0
- package/dist/chat-BZ_bvAkg.d.mts.map +1 -0
- package/dist/chat-CkFZMo5E.cjs +1579 -0
- package/dist/chat-CkFZMo5E.cjs.map +1 -0
- package/dist/chat-CpZVyF_t.d.cts +38 -0
- package/dist/chat-CpZVyF_t.d.cts.map +1 -0
- package/dist/context.cjs +75 -63
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +62 -107
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.mts +62 -107
- package/dist/context.d.mts.map +1 -1
- package/dist/context.mjs +76 -64
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui/map.cjs +26 -0
- package/dist/generative-ui/map.cjs.map +1 -0
- package/dist/generative-ui/map.d.cts +23 -0
- package/dist/generative-ui/map.d.cts.map +1 -0
- package/dist/generative-ui/map.d.mts +23 -0
- package/dist/generative-ui/map.d.mts.map +1 -0
- package/dist/generative-ui/map.mjs +24 -0
- package/dist/generative-ui/map.mjs.map +1 -0
- package/dist/generative-ui/native.cjs +67 -0
- package/dist/generative-ui/native.cjs.map +1 -0
- package/dist/generative-ui/native.d.cts +156 -0
- package/dist/generative-ui/native.d.cts.map +1 -0
- package/dist/generative-ui/native.d.mts +156 -0
- package/dist/generative-ui/native.d.mts.map +1 -0
- package/dist/generative-ui/native.mjs +25 -0
- package/dist/generative-ui/native.mjs.map +1 -0
- package/dist/generative-ui.cjs +33 -8088
- package/dist/generative-ui.cjs.map +1 -1
- package/dist/generative-ui.d.cts +2472 -4789
- package/dist/generative-ui.d.cts.map +1 -1
- package/dist/generative-ui.d.mts +2472 -4789
- package/dist/generative-ui.d.mts.map +1 -1
- package/dist/generative-ui.mjs +9 -8074
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/headless.cjs +289 -1054
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +149 -372
- package/dist/headless.d.cts.map +1 -1
- package/dist/headless.d.mts +123 -237
- package/dist/headless.d.mts.map +1 -1
- package/dist/headless.mjs +283 -1054
- package/dist/headless.mjs.map +1 -1
- package/dist/hooks-D2H3iL0N.d.mts +84 -0
- package/dist/hooks-D2H3iL0N.d.mts.map +1 -0
- package/dist/hooks-Dy8HeEdr.d.cts +84 -0
- package/dist/hooks-Dy8HeEdr.d.cts.map +1 -0
- package/dist/index.cjs +8702 -13238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +312 -872
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +311 -871
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1790 -7803
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +14075 -13828
- package/dist/index.umd.js.map +1 -1
- package/dist/refs-B5Dn59Pn.cjs +43 -0
- package/dist/refs-B5Dn59Pn.cjs.map +1 -0
- package/dist/refs-BW15wX_V.mjs +31 -0
- package/dist/refs-BW15wX_V.mjs.map +1 -0
- package/dist/runtime-context-B7f4M85q.d.mts +215 -0
- package/dist/runtime-context-B7f4M85q.d.mts.map +1 -0
- package/dist/runtime-context-CIkZS0ap.d.cts +215 -0
- package/dist/runtime-context-CIkZS0ap.d.cts.map +1 -0
- package/dist/standard-CSBR4FhM.mjs +5800 -0
- package/dist/standard-CSBR4FhM.mjs.map +1 -0
- package/dist/standard-DBjcBGyd.cjs +5796 -0
- package/dist/standard-DBjcBGyd.cjs.map +1 -0
- package/dist/use-generative-ui-root-CIp0ytE6.cjs +390 -0
- package/dist/use-generative-ui-root-CIp0ytE6.cjs.map +1 -0
- package/dist/use-generative-ui-root-oBqPa6uy.mjs +386 -0
- package/dist/use-generative-ui-root-oBqPa6uy.mjs.map +1 -0
- package/dist/v2/context.d.cts +28 -0
- package/dist/v2/context.d.mts +28 -0
- package/dist/v2/generative-ui/native.d.cts +112 -0
- package/dist/v2/generative-ui/native.d.mts +112 -0
- package/dist/v2/generative-ui.d.cts +96 -0
- package/dist/v2/generative-ui.d.mts +96 -0
- package/dist/v2/headless.d.cts +96 -0
- package/dist/v2/headless.d.mts +96 -0
- package/dist/v2/index.d.cts +2220 -0
- package/dist/v2/index.d.mts +2220 -0
- package/dist/v2/styles.css +5 -0
- package/package.json +116 -24
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts +0 -954
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts +0 -954
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
- package/dist/MarkdownSurfaces-Bd--93O1.mjs +0 -3676
- package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
- package/dist/MarkdownSurfaces-S4wfUl3J.cjs +0 -3991
- package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ɵshallowEqualRecord } from "@copilotkit/core";
|
|
2
|
+
import { createContext, useContext, useMemo, useRef } from "react";
|
|
3
|
+
import { accessibilityAttributes, accessibilityAttributes as accessibilityAttributes$1, controlAria, namedRole, readAccessibility, reportErrorSafely, wrapperAria } from "@copilotkit/core/generative-ui";
|
|
4
|
+
import { catalogIdsOf, createGenerativeUI, setterNameOf } from "@copilotkit/shared/generative-ui";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/shallow-stable-ref.ts
|
|
7
|
+
/**
|
|
8
|
+
* Shallow equality comparison for objects: same own keys, each holding the
|
|
9
|
+
* same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.
|
|
10
|
+
*/
|
|
11
|
+
function shallowEqual(obj1, obj2) {
|
|
12
|
+
return ɵshallowEqualRecord(obj1, obj2);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
|
|
16
|
+
* class instances, and other exotic objects that happen to have typeof "object".
|
|
17
|
+
*/
|
|
18
|
+
function isPlainObject(obj) {
|
|
19
|
+
return obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the same reference as long as the value is shallowly equal to the
|
|
23
|
+
* previous render's value.
|
|
24
|
+
*
|
|
25
|
+
* - Identical references bail out immediately (O(1)).
|
|
26
|
+
* - Plain objects ({}) are shallow-compared key-by-key.
|
|
27
|
+
* - Arrays, Dates, class instances, functions, and primitives are compared by
|
|
28
|
+
* reference only — shallowEqual is never called on non-plain objects, which
|
|
29
|
+
* avoids incorrect equality for e.g. [1,2] vs [1,2] (different arrays).
|
|
30
|
+
*
|
|
31
|
+
* Typical use: stabilize inline slot props so MemoizedSlotWrapper's shallow
|
|
32
|
+
* equality check isn't defeated by a new object reference on every render.
|
|
33
|
+
*/
|
|
34
|
+
function useShallowStableRef(value) {
|
|
35
|
+
const ref = useRef(value);
|
|
36
|
+
if (ref.current === value) return ref.current;
|
|
37
|
+
if (isPlainObject(ref.current) && isPlainObject(value)) {
|
|
38
|
+
if (shallowEqual(ref.current, value)) return ref.current;
|
|
39
|
+
}
|
|
40
|
+
ref.current = value;
|
|
41
|
+
return ref.current;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/generative-ui/runtime-context.ts
|
|
46
|
+
const GenerativeUIRuntimeContext = createContext(null);
|
|
47
|
+
function useGenerativeUIRuntime() {
|
|
48
|
+
return useContext(GenerativeUIRuntimeContext);
|
|
49
|
+
}
|
|
50
|
+
function useRequiredGenerativeUIRuntime() {
|
|
51
|
+
const runtime = useContext(GenerativeUIRuntimeContext);
|
|
52
|
+
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.");
|
|
53
|
+
return runtime;
|
|
54
|
+
}
|
|
55
|
+
const GenerativeUINodeContext = createContext(null);
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/generative-ui/catalog.ts
|
|
59
|
+
/**
|
|
60
|
+
* Experimental. Declares the components the model can render, the app state
|
|
61
|
+
* they read, and the functions they call.
|
|
62
|
+
*
|
|
63
|
+
* - A prop with the name of a top-level state key is bound to that state.
|
|
64
|
+
* - `bind: { prop: (state, props) => value }` binds a prop to a selector.
|
|
65
|
+
* - An event binds to the function with its name, else to the name without
|
|
66
|
+
* `on` (`onAddToCart` calls `addToCart`).
|
|
67
|
+
* - `writable: ["value"]` gives the component a `setValue` prop. See
|
|
68
|
+
* `GenerativeUIComponentDefinition.writable`.
|
|
69
|
+
*
|
|
70
|
+
* The model does not see bound props or matched events.
|
|
71
|
+
*
|
|
72
|
+
* @param config - `id`, then optional `extends`, `state`, `functions` and
|
|
73
|
+
* `overrides`, then `components`. Put `state` before `components`, so the selectors
|
|
74
|
+
* get typed state.
|
|
75
|
+
* @throws Error when a name comes from two places, an override names no
|
|
76
|
+
* component of the bases, `props` is not an object
|
|
77
|
+
* schema with a JSON Schema, a key is reserved or used
|
|
78
|
+
* twice on a component, an event matches two functions, an unmatched event
|
|
79
|
+
* has no `parameters`, a `bind` key is not a prop, a `writable` key is not
|
|
80
|
+
* a prop or is a bound prop, or a setter name is already a key of the
|
|
81
|
+
* component. Also throws when `parameterOrder` contains duplicate or unknown
|
|
82
|
+
* keys, or an ordered component declares integer-index keys whose JSON object
|
|
83
|
+
* enumeration order cannot be controlled.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const ui = createGenerativeUI({
|
|
88
|
+
* id: "acme/store@1",
|
|
89
|
+
* state: { cart: cartSchema },
|
|
90
|
+
* functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
|
|
91
|
+
* components: {
|
|
92
|
+
* CartSummary: {
|
|
93
|
+
* component: CartSummary,
|
|
94
|
+
* props: z.object({ count: z.number() }),
|
|
95
|
+
* bind: { count: (state) => state.cart.count },
|
|
96
|
+
* },
|
|
97
|
+
* },
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
function createGenerativeUI$1(config) {
|
|
102
|
+
return createGenerativeUI(config);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/generative-ui/accessibility.ts
|
|
107
|
+
/**
|
|
108
|
+
* Experimental. The ARIA attributes of the `accessibility` that the model
|
|
109
|
+
* gave the component being rendered, to spread on its root element. The
|
|
110
|
+
* standard components do this; a custom component does it itself:
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```tsx
|
|
114
|
+
* function Panel({ children }: { children?: ReactNode }) {
|
|
115
|
+
* const aria = useGenerativeUIAccessibility();
|
|
116
|
+
* return <section {...aria}>{children}</section>;
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* Outside of generated UI it gives `{}`.
|
|
121
|
+
*/
|
|
122
|
+
function useGenerativeUIAccessibility() {
|
|
123
|
+
const accessibility = useContext(GenerativeUINodeContext)?.accessibility;
|
|
124
|
+
return useMemo(() => accessibilityAttributes(accessibility), [accessibility]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { useGenerativeUIAccessibility as a, createGenerativeUI$1 as c, GenerativeUIRuntimeContext as d, reportErrorSafely as f, useShallowStableRef as g, shallowEqual as h, readAccessibility as i, setterNameOf as l, useRequiredGenerativeUIRuntime as m, controlAria as n, wrapperAria as o, useGenerativeUIRuntime as p, namedRole as r, catalogIdsOf as s, accessibilityAttributes$1 as t, GenerativeUINodeContext as u };
|
|
129
|
+
//# sourceMappingURL=accessibility-BLK-gE0R.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibility-BLK-gE0R.mjs","names":["createGenerativeUI","createSharedGenerativeUI"],"sources":["../src/lib/shallow-stable-ref.ts","../src/generative-ui/runtime-context.ts","../src/generative-ui/catalog.ts","../src/generative-ui/accessibility.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { ɵshallowEqualRecord } from \"@copilotkit/core\";\n\n// Reference-stability helpers, kept in their own leaf module (not in ./slots)\n// so that DOM-free consumers — e.g. CopilotChatConfigurationProvider, which is\n// re-exported from the lean `@copilotkit/react-core/headless` entry — reach\n// them without pulling in the slot rendering code (issue #4893).\n\n/**\n * Shallow equality comparison for objects: same own keys, each holding the\n * same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.\n */\nexport function shallowEqual<T extends Record<string, unknown>>(\n obj1: T,\n obj2: T,\n) {\n return ɵshallowEqualRecord(obj1, obj2);\n}\n\n/**\n * Returns true only for plain JS objects (`{}`), excluding arrays, Dates,\n * class instances, and other exotic objects that happen to have typeof \"object\".\n */\nfunction isPlainObject(obj: unknown): obj is Record<string, unknown> {\n return (\n obj !== null &&\n typeof obj === \"object\" &&\n Object.prototype.toString.call(obj) === \"[object Object]\"\n );\n}\n\n/**\n * Returns the same reference as long as the value is shallowly equal to the\n * previous render's value.\n *\n * - Identical references bail out immediately (O(1)).\n * - Plain objects ({}) are shallow-compared key-by-key.\n * - Arrays, Dates, class instances, functions, and primitives are compared by\n * reference only — shallowEqual is never called on non-plain objects, which\n * avoids incorrect equality for e.g. [1,2] vs [1,2] (different arrays).\n *\n * Typical use: stabilize inline slot props so MemoizedSlotWrapper's shallow\n * equality check isn't defeated by a new object reference on every render.\n */\nexport function useShallowStableRef<T>(value: T): T {\n const ref = useRef(value);\n\n // 1. Identical reference — bail early, no comparison needed.\n if (ref.current === value) return ref.current;\n\n // 2. Both are plain objects — shallow-compare to detect structural equality.\n if (isPlainObject(ref.current) && isPlainObject(value)) {\n if (shallowEqual(ref.current, value)) return ref.current;\n }\n\n // 3. Different values (or non-comparable types) — update the ref.\n ref.current = value;\n return ref.current;\n}\n","import { createContext, useContext } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { GenerativeUIUserEvent } from \"@copilotkit/shared\";\nimport type { GenerativeUIAccessibility } from \"./accessibility\";\nimport type { GenerativeUI } from \"./catalog\";\nimport type { GenerativeUIDispatcher } from \"@copilotkit/core/generative-ui\";\nimport type {\n GenerativeUIErrorInfo,\n GenerativeUIInvokeResult,\n} from \"@copilotkit/shared/generative-ui\";\nimport type { GenerativeUISurfaceManager } from \"@copilotkit/core/generative-ui\";\nimport type { GenerativeUITheme } from \"@copilotkit/shared/generative-ui\";\n\nexport type { GenerativeUITheme };\n\nexport interface GenerativeUIErrorBoundaryConfig {\n /**\n * Replaces the host's fallback for a component that failed to render. It\n * is not used for invalid props, unknown types, cyclic references or a\n * failed surface: the host's `NodeFallback` shows those. If it throws,\n * the host's fallback stands in and the error is reported. `error` is\n * always an Error: a component that throws something else (a string,\n * `undefined`) gets an Error that describes it, with the value as its\n * `cause`.\n */\n fallback?: (props: {\n error: Error;\n retry: () => void;\n surfaceId: string;\n componentId: string;\n }) => ReactNode;\n /**\n * Called for render, props, operation, function and event failures. A\n * render or props failure that stays the same across new revisions of the\n * node or the surface is reported once, until the node or surface renders\n * again. A failed function or event is reported on every call.\n */\n onError?: (info: GenerativeUIErrorInfo) => void;\n}\n\ninterface GenerativeUIBaseConfig {\n /**\n * The result of `createGenerativeUI`: the components the model can render,\n * the app state they read and the functions they call. Leave it out to\n * use `standardUI` when the runtime turns generative UI on; the other\n * options (such as `map` or `theme`) still apply.\n */\n ui?: GenerativeUI;\n /**\n * The agents that get the generative UI. When omitted, every agent gets\n * it. Other agents get no envelope.\n */\n agentIds?: string[];\n /**\n * Web only. Values for the `--a2ui-*` CSS variables and the map style.\n * Top-level values apply in both modes. `dark` changes them in dark mode,\n * which is on under a `.dark` class, like the CopilotKit chat. React\n * Native ignores it.\n */\n theme?: GenerativeUITheme;\n /**\n * Web only. Loads `maplibre-gl` for the standard `Map` component. Pass\n * `loadMapLibre` from `@copilotkit/react-core/generative-ui/map` and\n * install `maplibre-gl`. Without it, Map shows its markers as a list, and\n * the app builds without `maplibre-gl`. React Native ignores it.\n */\n map?: GenerativeUILibraryLoader;\n /** Fallback UI and error reporting for generated UI. */\n errorBoundary?: GenerativeUIErrorBoundaryConfig;\n}\n\n/**\n * Loads an optional library for a standard component, such as\n * `loadMapLibre` from `@copilotkit/react-core/generative-ui/map`. The\n * library stays out of apps that do not pass a loader.\n */\nexport type GenerativeUILibraryLoader = () => Promise<unknown>;\n\n/**\n * The tool transport: the model calls the `render_ui` tool, and the runtime\n * validates each operation before it streams it to the client.\n */\nexport interface GenerativeUIToolConfig extends GenerativeUIBaseConfig {\n /** Leave it out, or set \"tool\". */\n transport?: \"tool\";\n // Markdown-only options. `never` makes them a type error here, also when\n // `transport` is left out.\n sendContext?: never;\n includeCatalog?: never;\n}\n\n/**\n * The markdown transport: the model writes the operations in ```a2ui fences\n * in its reply. The client reads and validates them.\n */\nexport interface GenerativeUIMarkdownConfig extends GenerativeUIBaseConfig {\n transport: \"markdown\";\n /**\n * Send the component schema and the fence guideline as context entries.\n * Set `false` when the backend builds its own prompt from the envelope.\n * Default `true`.\n */\n sendContext?: boolean;\n /**\n * Send the component schemas in the envelope (`catalog.components`).\n * Default `true`.\n */\n includeCatalog?: boolean;\n}\n\n/**\n * Experimental. The `generativeUI` prop of `CopilotKitProvider`. Set\n * `transport: \"markdown\"` to get the markdown options.\n *\n * @example\n * ```tsx\n * <CopilotKitProvider generativeUI={{ ui }} />\n * <CopilotKitProvider generativeUI={{ ui, transport: \"markdown\", sendContext: false }} />\n * ```\n */\nexport type GenerativeUIConfig =\n | GenerativeUIToolConfig\n | GenerativeUIMarkdownConfig;\n\nexport interface GenerativeUIRuntime {\n manager: GenerativeUISurfaceManager;\n dispatcher: GenerativeUIDispatcher;\n /** The generative UI given to the provider as `generativeUI={{ ui }}`. */\n ui: GenerativeUI;\n /** How the model sends operations. \"tool\" when the config leaves it out. */\n transport: \"tool\" | \"markdown\";\n /** The latest `generativeUI` config of the provider. */\n readonly config: GenerativeUIConfig;\n /**\n * The latest `theme`. The host's surface root gets it: on the web it sets\n * the CSS variables; the React Native root ignores it.\n */\n theme?: GenerativeUITheme;\n forwardEvent: (\n event: GenerativeUIUserEvent,\n agentId: string | undefined,\n ) => Promise<GenerativeUIInvokeResult>;\n reportError: (info: GenerativeUIErrorInfo) => void;\n readonly errorFallback?: GenerativeUIErrorBoundaryConfig[\"fallback\"];\n}\n\nexport const GenerativeUIRuntimeContext =\n createContext<GenerativeUIRuntime | null>(null);\n\nexport function useGenerativeUIRuntime(): GenerativeUIRuntime | null {\n return useContext(GenerativeUIRuntimeContext);\n}\n\nexport function useRequiredGenerativeUIRuntime(): GenerativeUIRuntime {\n const runtime = useContext(GenerativeUIRuntimeContext);\n if (!runtime) {\n throw new Error(\n \"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.\",\n );\n }\n return runtime;\n}\n\nexport { reportErrorSafely } from \"@copilotkit/core/generative-ui\";\n\nexport interface GenerativeUINodeContextValue {\n surfaceKey: string;\n surfaceId: string;\n componentId: string;\n /** The resolved `accessibility` of the component envelope, if any. */\n accessibility?: GenerativeUIAccessibility;\n}\n\nexport const GenerativeUINodeContext =\n createContext<GenerativeUINodeContextValue | null>(null);\n","import type { ComponentType, ReactNode } from \"react\";\nimport { createGenerativeUI as createSharedGenerativeUI } from \"@copilotkit/shared/generative-ui\";\nimport type {\n AnyGenerativeUI,\n CreateGenerativeUIConfig as SharedCreateGenerativeUIConfig,\n GenerativeUI as SharedGenerativeUI,\n GenerativeUIBasesDefinitions,\n GenerativeUIComponentDefinition as SharedGenerativeUIComponentDefinition,\n GenerativeUIComponentProps as SharedGenerativeUIComponentProps,\n GenerativeUIDefinitions,\n GenerativeUIFunctionDefinition,\n GenerativeUIResultDefinitions,\n GenerativeUISchema,\n ResolvedGenerativeUIComponent as SharedResolvedGenerativeUIComponent,\n} from \"@copilotkit/shared/generative-ui\";\n\n// The catalog is framework-free and lives in `@copilotkit/shared/generative-ui`.\n// These types pin its component type to React components and its rendered\n// child type to `ReactNode`.\n\nexport {\n catalogIdsOf,\n componentCatalogIds,\n setterNameOf,\n} from \"@copilotkit/shared/generative-ui\";\nexport type {\n GenerativeUIComponentName,\n GenerativeUIDefinitionsOf,\n GenerativeUIEventDefinition,\n GenerativeUIEventInput,\n GenerativeUIFunctionArgs,\n GenerativeUIFunctionDefinition,\n GenerativeUIFunctionInput,\n GenerativeUIFunctionName,\n GenerativeUIFunctionsOf,\n GenerativeUISelector,\n GenerativeUISlotKind,\n GenerativeUIStateOf,\n PropsSchema,\n UnionToIntersection,\n} from \"@copilotkit/shared/generative-ui\";\n\n/** One component of a generative UI, as the renderer reads it. */\nexport type GenerativeUIComponentDefinition =\n SharedGenerativeUIComponentDefinition<ComponentType<any>>;\n\n/** A component after `createGenerativeUI` resolved its bindings. */\nexport type ResolvedGenerativeUIComponent = SharedResolvedGenerativeUIComponent<\n ComponentType<any>\n>;\n\n/**\n * Experimental. The result of `createGenerativeUI`: the components the model\n * can render, the app state they read, and the functions they call. Give it\n * to the provider (`generativeUI={{ ui }}`) and to the typed hooks.\n */\nexport type GenerativeUI<\n Definitions extends GenerativeUIDefinitions = GenerativeUIDefinitions,\n> = SharedGenerativeUI<Definitions, ComponentType<any>>;\n\n/**\n * Props that the renderer passes to a component:\n * `function CheckoutForm(props: GenerativeUIComponentProps<typeof ui, \"CheckoutForm\">)`.\n * Data props are the parsed `props` schema, bound props included. Event and\n * slot props are present only when they are bound or filled. Each writable\n * prop gets a setter (`value` gets `setValue`), which is always present.\n */\nexport type GenerativeUIComponentProps<\n UI extends AnyGenerativeUI,\n Name extends keyof NonNullable<UI[\"definitions\"]>[\"components\"] & string,\n> = SharedGenerativeUIComponentProps<UI, Name, ReactNode>;\n\n/** One new React component for each component of the bases that it names. */\ntype OverridesConfig<Bases extends readonly AnyGenerativeUI[]> = {\n [Name in keyof GenerativeUIBasesDefinitions<Bases>[\"components\"] & string]?: {\n component: ComponentType<\n GenerativeUIBasesDefinitions<Bases> extends infer Definitions extends\n GenerativeUIDefinitions\n ? GenerativeUIComponentProps<GenerativeUI<Definitions>, Name>\n : never\n >;\n };\n};\n\n/** The config of `createGenerativeUI`. */\nexport type CreateGenerativeUIConfig<\n Bases extends readonly AnyGenerativeUI[],\n State extends Record<string, GenerativeUISchema>,\n Functions extends Record<string, GenerativeUIFunctionDefinition>,\n Props extends Record<string, unknown>,\n Events extends Record<string, unknown>,\n Slots extends Record<string, unknown>,\n Writable extends Record<string, unknown>,\n> = SharedCreateGenerativeUIConfig<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable,\n OverridesConfig<Bases>\n>;\n\n/**\n * Experimental. Declares the components the model can render, the app state\n * they read, and the functions they call.\n *\n * - A prop with the name of a top-level state key is bound to that state.\n * - `bind: { prop: (state, props) => value }` binds a prop to a selector.\n * - An event binds to the function with its name, else to the name without\n * `on` (`onAddToCart` calls `addToCart`).\n * - `writable: [\"value\"]` gives the component a `setValue` prop. See\n * `GenerativeUIComponentDefinition.writable`.\n *\n * The model does not see bound props or matched events.\n *\n * @param config - `id`, then optional `extends`, `state`, `functions` and\n * `overrides`, then `components`. Put `state` before `components`, so the selectors\n * get typed state.\n * @throws Error when a name comes from two places, an override names no\n * component of the bases, `props` is not an object\n * schema with a JSON Schema, a key is reserved or used\n * twice on a component, an event matches two functions, an unmatched event\n * has no `parameters`, a `bind` key is not a prop, a `writable` key is not\n * a prop or is a bound prop, or a setter name is already a key of the\n * component. Also throws when `parameterOrder` contains duplicate or unknown\n * keys, or an ordered component declares integer-index keys whose JSON object\n * enumeration order cannot be controlled.\n *\n * @example\n * ```ts\n * const ui = createGenerativeUI({\n * id: \"acme/store@1\",\n * state: { cart: cartSchema },\n * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },\n * components: {\n * CartSummary: {\n * component: CartSummary,\n * props: z.object({ count: z.number() }),\n * bind: { count: (state) => state.cart.count },\n * },\n * },\n * });\n * ```\n */\nexport function createGenerativeUI<\n Bases extends readonly AnyGenerativeUI[] = [],\n State extends Record<string, GenerativeUISchema> = {},\n Functions extends Record<string, GenerativeUIFunctionDefinition> = {},\n Props extends Record<string, unknown> = {},\n Events extends Record<string, unknown> = {},\n Slots extends Record<string, unknown> = {},\n Writable extends Record<string, unknown> = {},\n>(\n config: CreateGenerativeUIConfig<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable\n >,\n) {\n // The React config only narrows the shared one (React component types),\n // so the shared runtime builds the same UI.\n const build = createSharedGenerativeUI as (config: unknown) => unknown;\n return build(config) as GenerativeUI<\n GenerativeUIResultDefinitions<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable\n >\n >;\n}\n","import { useContext, useMemo } from \"react\";\nimport { accessibilityAttributes } from \"@copilotkit/core/generative-ui\";\nimport type { GenerativeUIAriaAttributes } from \"@copilotkit/core/generative-ui\";\nimport { GenerativeUINodeContext } from \"./runtime-context\";\n\n// The accessibility helpers are framework-free and live in\n// `@copilotkit/core/generative-ui`. The standard components import them\n// from here.\nexport {\n accessibilityAttributes,\n controlAria,\n namedRole,\n readAccessibility,\n wrapperAria,\n} from \"@copilotkit/core/generative-ui\";\nexport type {\n GenerativeUIAccessibility,\n GenerativeUIAriaAttributes,\n} from \"@copilotkit/core/generative-ui\";\n\n/**\n * Experimental. The ARIA attributes of the `accessibility` that the model\n * gave the component being rendered, to spread on its root element. The\n * standard components do this; a custom component does it itself:\n *\n * @example\n * ```tsx\n * function Panel({ children }: { children?: ReactNode }) {\n * const aria = useGenerativeUIAccessibility();\n * return <section {...aria}>{children}</section>;\n * }\n * ```\n *\n * Outside of generated UI it gives `{}`.\n */\nexport function useGenerativeUIAccessibility(): GenerativeUIAriaAttributes {\n const node = useContext(GenerativeUINodeContext);\n const accessibility = node?.accessibility;\n return useMemo(() => accessibilityAttributes(accessibility), [accessibility]);\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,aACd,MACA,MACA;AACA,QAAO,oBAAoB,MAAM,KAAK;;;;;;AAOxC,SAAS,cAAc,KAA8C;AACnE,QACE,QAAQ,QACR,OAAO,QAAQ,YACf,OAAO,UAAU,SAAS,KAAK,IAAI,KAAK;;;;;;;;;;;;;;;AAiB5C,SAAgB,oBAAuB,OAAa;CAClD,MAAM,MAAM,OAAO,MAAM;AAGzB,KAAI,IAAI,YAAY,MAAO,QAAO,IAAI;AAGtC,KAAI,cAAc,IAAI,QAAQ,IAAI,cAAc,MAAM,EACpD;MAAI,aAAa,IAAI,SAAS,MAAM,CAAE,QAAO,IAAI;;AAInD,KAAI,UAAU;AACd,QAAO,IAAI;;;;;ACyFb,MAAa,6BACX,cAA0C,KAAK;AAEjD,SAAgB,yBAAqD;AACnE,QAAO,WAAW,2BAA2B;;AAG/C,SAAgB,iCAAsD;CACpE,MAAM,UAAU,WAAW,2BAA2B;AACtD,KAAI,CAAC,QACH,OAAM,IAAI,MACR,2NACD;AAEH,QAAO;;AAaT,MAAa,0BACX,cAAmD,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5B1D,SAAgBA,qBASd,QASA;AAIA,QADcC,mBACD,OAAO;;;;;;;;;;;;;;;;;;;;ACrItB,SAAgB,+BAA2D;CAEzE,MAAM,gBADO,WAAW,wBAAwB,EACpB;AAC5B,QAAO,cAAc,wBAAwB,cAAc,EAAE,CAAC,cAAc,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) {
|
|
11
|
+
__defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!no_symbols) {
|
|
17
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
36
|
+
value: mod,
|
|
37
|
+
enumerable: true
|
|
38
|
+
}) : target, mod));
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
let _copilotkit_core = require("@copilotkit/core");
|
|
42
|
+
let react = require("react");
|
|
43
|
+
let _copilotkit_core_generative_ui = require("@copilotkit/core/generative-ui");
|
|
44
|
+
let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
|
|
45
|
+
|
|
46
|
+
//#region src/lib/shallow-stable-ref.ts
|
|
47
|
+
/**
|
|
48
|
+
* Shallow equality comparison for objects: same own keys, each holding the
|
|
49
|
+
* same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.
|
|
50
|
+
*/
|
|
51
|
+
function shallowEqual(obj1, obj2) {
|
|
52
|
+
return (0, _copilotkit_core.ɵshallowEqualRecord)(obj1, obj2);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns true only for plain JS objects (`{}`), excluding arrays, Dates,
|
|
56
|
+
* class instances, and other exotic objects that happen to have typeof "object".
|
|
57
|
+
*/
|
|
58
|
+
function isPlainObject(obj) {
|
|
59
|
+
return obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the same reference as long as the value is shallowly equal to the
|
|
63
|
+
* previous render's value.
|
|
64
|
+
*
|
|
65
|
+
* - Identical references bail out immediately (O(1)).
|
|
66
|
+
* - Plain objects ({}) are shallow-compared key-by-key.
|
|
67
|
+
* - Arrays, Dates, class instances, functions, and primitives are compared by
|
|
68
|
+
* reference only — shallowEqual is never called on non-plain objects, which
|
|
69
|
+
* avoids incorrect equality for e.g. [1,2] vs [1,2] (different arrays).
|
|
70
|
+
*
|
|
71
|
+
* Typical use: stabilize inline slot props so MemoizedSlotWrapper's shallow
|
|
72
|
+
* equality check isn't defeated by a new object reference on every render.
|
|
73
|
+
*/
|
|
74
|
+
function useShallowStableRef(value) {
|
|
75
|
+
const ref = (0, react.useRef)(value);
|
|
76
|
+
if (ref.current === value) return ref.current;
|
|
77
|
+
if (isPlainObject(ref.current) && isPlainObject(value)) {
|
|
78
|
+
if (shallowEqual(ref.current, value)) return ref.current;
|
|
79
|
+
}
|
|
80
|
+
ref.current = value;
|
|
81
|
+
return ref.current;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/generative-ui/runtime-context.ts
|
|
86
|
+
const GenerativeUIRuntimeContext = (0, react.createContext)(null);
|
|
87
|
+
function useGenerativeUIRuntime() {
|
|
88
|
+
return (0, react.useContext)(GenerativeUIRuntimeContext);
|
|
89
|
+
}
|
|
90
|
+
function useRequiredGenerativeUIRuntime() {
|
|
91
|
+
const runtime = (0, react.useContext)(GenerativeUIRuntimeContext);
|
|
92
|
+
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.");
|
|
93
|
+
return runtime;
|
|
94
|
+
}
|
|
95
|
+
const GenerativeUINodeContext = (0, react.createContext)(null);
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/generative-ui/catalog.ts
|
|
99
|
+
/**
|
|
100
|
+
* Experimental. Declares the components the model can render, the app state
|
|
101
|
+
* they read, and the functions they call.
|
|
102
|
+
*
|
|
103
|
+
* - A prop with the name of a top-level state key is bound to that state.
|
|
104
|
+
* - `bind: { prop: (state, props) => value }` binds a prop to a selector.
|
|
105
|
+
* - An event binds to the function with its name, else to the name without
|
|
106
|
+
* `on` (`onAddToCart` calls `addToCart`).
|
|
107
|
+
* - `writable: ["value"]` gives the component a `setValue` prop. See
|
|
108
|
+
* `GenerativeUIComponentDefinition.writable`.
|
|
109
|
+
*
|
|
110
|
+
* The model does not see bound props or matched events.
|
|
111
|
+
*
|
|
112
|
+
* @param config - `id`, then optional `extends`, `state`, `functions` and
|
|
113
|
+
* `overrides`, then `components`. Put `state` before `components`, so the selectors
|
|
114
|
+
* get typed state.
|
|
115
|
+
* @throws Error when a name comes from two places, an override names no
|
|
116
|
+
* component of the bases, `props` is not an object
|
|
117
|
+
* schema with a JSON Schema, a key is reserved or used
|
|
118
|
+
* twice on a component, an event matches two functions, an unmatched event
|
|
119
|
+
* has no `parameters`, a `bind` key is not a prop, a `writable` key is not
|
|
120
|
+
* a prop or is a bound prop, or a setter name is already a key of the
|
|
121
|
+
* component. Also throws when `parameterOrder` contains duplicate or unknown
|
|
122
|
+
* keys, or an ordered component declares integer-index keys whose JSON object
|
|
123
|
+
* enumeration order cannot be controlled.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const ui = createGenerativeUI({
|
|
128
|
+
* id: "acme/store@1",
|
|
129
|
+
* state: { cart: cartSchema },
|
|
130
|
+
* functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
|
|
131
|
+
* components: {
|
|
132
|
+
* CartSummary: {
|
|
133
|
+
* component: CartSummary,
|
|
134
|
+
* props: z.object({ count: z.number() }),
|
|
135
|
+
* bind: { count: (state) => state.cart.count },
|
|
136
|
+
* },
|
|
137
|
+
* },
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
function createGenerativeUI(config) {
|
|
142
|
+
return (0, _copilotkit_shared_generative_ui.createGenerativeUI)(config);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/generative-ui/accessibility.ts
|
|
147
|
+
/**
|
|
148
|
+
* Experimental. The ARIA attributes of the `accessibility` that the model
|
|
149
|
+
* gave the component being rendered, to spread on its root element. The
|
|
150
|
+
* standard components do this; a custom component does it itself:
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* function Panel({ children }: { children?: ReactNode }) {
|
|
155
|
+
* const aria = useGenerativeUIAccessibility();
|
|
156
|
+
* return <section {...aria}>{children}</section>;
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* Outside of generated UI it gives `{}`.
|
|
161
|
+
*/
|
|
162
|
+
function useGenerativeUIAccessibility() {
|
|
163
|
+
const accessibility = (0, react.useContext)(GenerativeUINodeContext)?.accessibility;
|
|
164
|
+
return (0, react.useMemo)(() => (0, _copilotkit_core_generative_ui.accessibilityAttributes)(accessibility), [accessibility]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
Object.defineProperty(exports, 'GenerativeUINodeContext', {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function () {
|
|
171
|
+
return GenerativeUINodeContext;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, 'GenerativeUIRuntimeContext', {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function () {
|
|
177
|
+
return GenerativeUIRuntimeContext;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(exports, '__exportAll', {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function () {
|
|
183
|
+
return __exportAll;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, '__toESM', {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () {
|
|
189
|
+
return __toESM;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, 'createGenerativeUI', {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () {
|
|
195
|
+
return createGenerativeUI;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, 'shallowEqual', {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function () {
|
|
201
|
+
return shallowEqual;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(exports, 'useGenerativeUIAccessibility', {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function () {
|
|
207
|
+
return useGenerativeUIAccessibility;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(exports, 'useGenerativeUIRuntime', {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function () {
|
|
213
|
+
return useGenerativeUIRuntime;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, 'useRequiredGenerativeUIRuntime', {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () {
|
|
219
|
+
return useRequiredGenerativeUIRuntime;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, 'useShallowStableRef', {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function () {
|
|
225
|
+
return useShallowStableRef;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
//# sourceMappingURL=accessibility-GnodqxkH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibility-GnodqxkH.cjs","names":[],"sources":["../src/lib/shallow-stable-ref.ts","../src/generative-ui/runtime-context.ts","../src/generative-ui/catalog.ts","../src/generative-ui/accessibility.ts"],"sourcesContent":["import { useRef } from \"react\";\nimport { ɵshallowEqualRecord } from \"@copilotkit/core\";\n\n// Reference-stability helpers, kept in their own leaf module (not in ./slots)\n// so that DOM-free consumers — e.g. CopilotChatConfigurationProvider, which is\n// re-exported from the lean `@copilotkit/react-core/headless` entry — reach\n// them without pulling in the slot rendering code (issue #4893).\n\n/**\n * Shallow equality comparison for objects: same own keys, each holding the\n * same value (`Object.is`). Core's `ɵshallowEqualRecord` holds the rule.\n */\nexport function shallowEqual<T extends Record<string, unknown>>(\n obj1: T,\n obj2: T,\n) {\n return ɵshallowEqualRecord(obj1, obj2);\n}\n\n/**\n * Returns true only for plain JS objects (`{}`), excluding arrays, Dates,\n * class instances, and other exotic objects that happen to have typeof \"object\".\n */\nfunction isPlainObject(obj: unknown): obj is Record<string, unknown> {\n return (\n obj !== null &&\n typeof obj === \"object\" &&\n Object.prototype.toString.call(obj) === \"[object Object]\"\n );\n}\n\n/**\n * Returns the same reference as long as the value is shallowly equal to the\n * previous render's value.\n *\n * - Identical references bail out immediately (O(1)).\n * - Plain objects ({}) are shallow-compared key-by-key.\n * - Arrays, Dates, class instances, functions, and primitives are compared by\n * reference only — shallowEqual is never called on non-plain objects, which\n * avoids incorrect equality for e.g. [1,2] vs [1,2] (different arrays).\n *\n * Typical use: stabilize inline slot props so MemoizedSlotWrapper's shallow\n * equality check isn't defeated by a new object reference on every render.\n */\nexport function useShallowStableRef<T>(value: T): T {\n const ref = useRef(value);\n\n // 1. Identical reference — bail early, no comparison needed.\n if (ref.current === value) return ref.current;\n\n // 2. Both are plain objects — shallow-compare to detect structural equality.\n if (isPlainObject(ref.current) && isPlainObject(value)) {\n if (shallowEqual(ref.current, value)) return ref.current;\n }\n\n // 3. Different values (or non-comparable types) — update the ref.\n ref.current = value;\n return ref.current;\n}\n","import { createContext, useContext } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { GenerativeUIUserEvent } from \"@copilotkit/shared\";\nimport type { GenerativeUIAccessibility } from \"./accessibility\";\nimport type { GenerativeUI } from \"./catalog\";\nimport type { GenerativeUIDispatcher } from \"@copilotkit/core/generative-ui\";\nimport type {\n GenerativeUIErrorInfo,\n GenerativeUIInvokeResult,\n} from \"@copilotkit/shared/generative-ui\";\nimport type { GenerativeUISurfaceManager } from \"@copilotkit/core/generative-ui\";\nimport type { GenerativeUITheme } from \"@copilotkit/shared/generative-ui\";\n\nexport type { GenerativeUITheme };\n\nexport interface GenerativeUIErrorBoundaryConfig {\n /**\n * Replaces the host's fallback for a component that failed to render. It\n * is not used for invalid props, unknown types, cyclic references or a\n * failed surface: the host's `NodeFallback` shows those. If it throws,\n * the host's fallback stands in and the error is reported. `error` is\n * always an Error: a component that throws something else (a string,\n * `undefined`) gets an Error that describes it, with the value as its\n * `cause`.\n */\n fallback?: (props: {\n error: Error;\n retry: () => void;\n surfaceId: string;\n componentId: string;\n }) => ReactNode;\n /**\n * Called for render, props, operation, function and event failures. A\n * render or props failure that stays the same across new revisions of the\n * node or the surface is reported once, until the node or surface renders\n * again. A failed function or event is reported on every call.\n */\n onError?: (info: GenerativeUIErrorInfo) => void;\n}\n\ninterface GenerativeUIBaseConfig {\n /**\n * The result of `createGenerativeUI`: the components the model can render,\n * the app state they read and the functions they call. Leave it out to\n * use `standardUI` when the runtime turns generative UI on; the other\n * options (such as `map` or `theme`) still apply.\n */\n ui?: GenerativeUI;\n /**\n * The agents that get the generative UI. When omitted, every agent gets\n * it. Other agents get no envelope.\n */\n agentIds?: string[];\n /**\n * Web only. Values for the `--a2ui-*` CSS variables and the map style.\n * Top-level values apply in both modes. `dark` changes them in dark mode,\n * which is on under a `.dark` class, like the CopilotKit chat. React\n * Native ignores it.\n */\n theme?: GenerativeUITheme;\n /**\n * Web only. Loads `maplibre-gl` for the standard `Map` component. Pass\n * `loadMapLibre` from `@copilotkit/react-core/generative-ui/map` and\n * install `maplibre-gl`. Without it, Map shows its markers as a list, and\n * the app builds without `maplibre-gl`. React Native ignores it.\n */\n map?: GenerativeUILibraryLoader;\n /** Fallback UI and error reporting for generated UI. */\n errorBoundary?: GenerativeUIErrorBoundaryConfig;\n}\n\n/**\n * Loads an optional library for a standard component, such as\n * `loadMapLibre` from `@copilotkit/react-core/generative-ui/map`. The\n * library stays out of apps that do not pass a loader.\n */\nexport type GenerativeUILibraryLoader = () => Promise<unknown>;\n\n/**\n * The tool transport: the model calls the `render_ui` tool, and the runtime\n * validates each operation before it streams it to the client.\n */\nexport interface GenerativeUIToolConfig extends GenerativeUIBaseConfig {\n /** Leave it out, or set \"tool\". */\n transport?: \"tool\";\n // Markdown-only options. `never` makes them a type error here, also when\n // `transport` is left out.\n sendContext?: never;\n includeCatalog?: never;\n}\n\n/**\n * The markdown transport: the model writes the operations in ```a2ui fences\n * in its reply. The client reads and validates them.\n */\nexport interface GenerativeUIMarkdownConfig extends GenerativeUIBaseConfig {\n transport: \"markdown\";\n /**\n * Send the component schema and the fence guideline as context entries.\n * Set `false` when the backend builds its own prompt from the envelope.\n * Default `true`.\n */\n sendContext?: boolean;\n /**\n * Send the component schemas in the envelope (`catalog.components`).\n * Default `true`.\n */\n includeCatalog?: boolean;\n}\n\n/**\n * Experimental. The `generativeUI` prop of `CopilotKitProvider`. Set\n * `transport: \"markdown\"` to get the markdown options.\n *\n * @example\n * ```tsx\n * <CopilotKitProvider generativeUI={{ ui }} />\n * <CopilotKitProvider generativeUI={{ ui, transport: \"markdown\", sendContext: false }} />\n * ```\n */\nexport type GenerativeUIConfig =\n | GenerativeUIToolConfig\n | GenerativeUIMarkdownConfig;\n\nexport interface GenerativeUIRuntime {\n manager: GenerativeUISurfaceManager;\n dispatcher: GenerativeUIDispatcher;\n /** The generative UI given to the provider as `generativeUI={{ ui }}`. */\n ui: GenerativeUI;\n /** How the model sends operations. \"tool\" when the config leaves it out. */\n transport: \"tool\" | \"markdown\";\n /** The latest `generativeUI` config of the provider. */\n readonly config: GenerativeUIConfig;\n /**\n * The latest `theme`. The host's surface root gets it: on the web it sets\n * the CSS variables; the React Native root ignores it.\n */\n theme?: GenerativeUITheme;\n forwardEvent: (\n event: GenerativeUIUserEvent,\n agentId: string | undefined,\n ) => Promise<GenerativeUIInvokeResult>;\n reportError: (info: GenerativeUIErrorInfo) => void;\n readonly errorFallback?: GenerativeUIErrorBoundaryConfig[\"fallback\"];\n}\n\nexport const GenerativeUIRuntimeContext =\n createContext<GenerativeUIRuntime | null>(null);\n\nexport function useGenerativeUIRuntime(): GenerativeUIRuntime | null {\n return useContext(GenerativeUIRuntimeContext);\n}\n\nexport function useRequiredGenerativeUIRuntime(): GenerativeUIRuntime {\n const runtime = useContext(GenerativeUIRuntimeContext);\n if (!runtime) {\n throw new Error(\n \"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.\",\n );\n }\n return runtime;\n}\n\nexport { reportErrorSafely } from \"@copilotkit/core/generative-ui\";\n\nexport interface GenerativeUINodeContextValue {\n surfaceKey: string;\n surfaceId: string;\n componentId: string;\n /** The resolved `accessibility` of the component envelope, if any. */\n accessibility?: GenerativeUIAccessibility;\n}\n\nexport const GenerativeUINodeContext =\n createContext<GenerativeUINodeContextValue | null>(null);\n","import type { ComponentType, ReactNode } from \"react\";\nimport { createGenerativeUI as createSharedGenerativeUI } from \"@copilotkit/shared/generative-ui\";\nimport type {\n AnyGenerativeUI,\n CreateGenerativeUIConfig as SharedCreateGenerativeUIConfig,\n GenerativeUI as SharedGenerativeUI,\n GenerativeUIBasesDefinitions,\n GenerativeUIComponentDefinition as SharedGenerativeUIComponentDefinition,\n GenerativeUIComponentProps as SharedGenerativeUIComponentProps,\n GenerativeUIDefinitions,\n GenerativeUIFunctionDefinition,\n GenerativeUIResultDefinitions,\n GenerativeUISchema,\n ResolvedGenerativeUIComponent as SharedResolvedGenerativeUIComponent,\n} from \"@copilotkit/shared/generative-ui\";\n\n// The catalog is framework-free and lives in `@copilotkit/shared/generative-ui`.\n// These types pin its component type to React components and its rendered\n// child type to `ReactNode`.\n\nexport {\n catalogIdsOf,\n componentCatalogIds,\n setterNameOf,\n} from \"@copilotkit/shared/generative-ui\";\nexport type {\n GenerativeUIComponentName,\n GenerativeUIDefinitionsOf,\n GenerativeUIEventDefinition,\n GenerativeUIEventInput,\n GenerativeUIFunctionArgs,\n GenerativeUIFunctionDefinition,\n GenerativeUIFunctionInput,\n GenerativeUIFunctionName,\n GenerativeUIFunctionsOf,\n GenerativeUISelector,\n GenerativeUISlotKind,\n GenerativeUIStateOf,\n PropsSchema,\n UnionToIntersection,\n} from \"@copilotkit/shared/generative-ui\";\n\n/** One component of a generative UI, as the renderer reads it. */\nexport type GenerativeUIComponentDefinition =\n SharedGenerativeUIComponentDefinition<ComponentType<any>>;\n\n/** A component after `createGenerativeUI` resolved its bindings. */\nexport type ResolvedGenerativeUIComponent = SharedResolvedGenerativeUIComponent<\n ComponentType<any>\n>;\n\n/**\n * Experimental. The result of `createGenerativeUI`: the components the model\n * can render, the app state they read, and the functions they call. Give it\n * to the provider (`generativeUI={{ ui }}`) and to the typed hooks.\n */\nexport type GenerativeUI<\n Definitions extends GenerativeUIDefinitions = GenerativeUIDefinitions,\n> = SharedGenerativeUI<Definitions, ComponentType<any>>;\n\n/**\n * Props that the renderer passes to a component:\n * `function CheckoutForm(props: GenerativeUIComponentProps<typeof ui, \"CheckoutForm\">)`.\n * Data props are the parsed `props` schema, bound props included. Event and\n * slot props are present only when they are bound or filled. Each writable\n * prop gets a setter (`value` gets `setValue`), which is always present.\n */\nexport type GenerativeUIComponentProps<\n UI extends AnyGenerativeUI,\n Name extends keyof NonNullable<UI[\"definitions\"]>[\"components\"] & string,\n> = SharedGenerativeUIComponentProps<UI, Name, ReactNode>;\n\n/** One new React component for each component of the bases that it names. */\ntype OverridesConfig<Bases extends readonly AnyGenerativeUI[]> = {\n [Name in keyof GenerativeUIBasesDefinitions<Bases>[\"components\"] & string]?: {\n component: ComponentType<\n GenerativeUIBasesDefinitions<Bases> extends infer Definitions extends\n GenerativeUIDefinitions\n ? GenerativeUIComponentProps<GenerativeUI<Definitions>, Name>\n : never\n >;\n };\n};\n\n/** The config of `createGenerativeUI`. */\nexport type CreateGenerativeUIConfig<\n Bases extends readonly AnyGenerativeUI[],\n State extends Record<string, GenerativeUISchema>,\n Functions extends Record<string, GenerativeUIFunctionDefinition>,\n Props extends Record<string, unknown>,\n Events extends Record<string, unknown>,\n Slots extends Record<string, unknown>,\n Writable extends Record<string, unknown>,\n> = SharedCreateGenerativeUIConfig<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable,\n OverridesConfig<Bases>\n>;\n\n/**\n * Experimental. Declares the components the model can render, the app state\n * they read, and the functions they call.\n *\n * - A prop with the name of a top-level state key is bound to that state.\n * - `bind: { prop: (state, props) => value }` binds a prop to a selector.\n * - An event binds to the function with its name, else to the name without\n * `on` (`onAddToCart` calls `addToCart`).\n * - `writable: [\"value\"]` gives the component a `setValue` prop. See\n * `GenerativeUIComponentDefinition.writable`.\n *\n * The model does not see bound props or matched events.\n *\n * @param config - `id`, then optional `extends`, `state`, `functions` and\n * `overrides`, then `components`. Put `state` before `components`, so the selectors\n * get typed state.\n * @throws Error when a name comes from two places, an override names no\n * component of the bases, `props` is not an object\n * schema with a JSON Schema, a key is reserved or used\n * twice on a component, an event matches two functions, an unmatched event\n * has no `parameters`, a `bind` key is not a prop, a `writable` key is not\n * a prop or is a bound prop, or a setter name is already a key of the\n * component. Also throws when `parameterOrder` contains duplicate or unknown\n * keys, or an ordered component declares integer-index keys whose JSON object\n * enumeration order cannot be controlled.\n *\n * @example\n * ```ts\n * const ui = createGenerativeUI({\n * id: \"acme/store@1\",\n * state: { cart: cartSchema },\n * functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },\n * components: {\n * CartSummary: {\n * component: CartSummary,\n * props: z.object({ count: z.number() }),\n * bind: { count: (state) => state.cart.count },\n * },\n * },\n * });\n * ```\n */\nexport function createGenerativeUI<\n Bases extends readonly AnyGenerativeUI[] = [],\n State extends Record<string, GenerativeUISchema> = {},\n Functions extends Record<string, GenerativeUIFunctionDefinition> = {},\n Props extends Record<string, unknown> = {},\n Events extends Record<string, unknown> = {},\n Slots extends Record<string, unknown> = {},\n Writable extends Record<string, unknown> = {},\n>(\n config: CreateGenerativeUIConfig<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable\n >,\n) {\n // The React config only narrows the shared one (React component types),\n // so the shared runtime builds the same UI.\n const build = createSharedGenerativeUI as (config: unknown) => unknown;\n return build(config) as GenerativeUI<\n GenerativeUIResultDefinitions<\n Bases,\n State,\n Functions,\n Props,\n Events,\n Slots,\n Writable\n >\n >;\n}\n","import { useContext, useMemo } from \"react\";\nimport { accessibilityAttributes } from \"@copilotkit/core/generative-ui\";\nimport type { GenerativeUIAriaAttributes } from \"@copilotkit/core/generative-ui\";\nimport { GenerativeUINodeContext } from \"./runtime-context\";\n\n// The accessibility helpers are framework-free and live in\n// `@copilotkit/core/generative-ui`. The standard components import them\n// from here.\nexport {\n accessibilityAttributes,\n controlAria,\n namedRole,\n readAccessibility,\n wrapperAria,\n} from \"@copilotkit/core/generative-ui\";\nexport type {\n GenerativeUIAccessibility,\n GenerativeUIAriaAttributes,\n} from \"@copilotkit/core/generative-ui\";\n\n/**\n * Experimental. The ARIA attributes of the `accessibility` that the model\n * gave the component being rendered, to spread on its root element. The\n * standard components do this; a custom component does it itself:\n *\n * @example\n * ```tsx\n * function Panel({ children }: { children?: ReactNode }) {\n * const aria = useGenerativeUIAccessibility();\n * return <section {...aria}>{children}</section>;\n * }\n * ```\n *\n * Outside of generated UI it gives `{}`.\n */\nexport function useGenerativeUIAccessibility(): GenerativeUIAriaAttributes {\n const node = useContext(GenerativeUINodeContext);\n const accessibility = node?.accessibility;\n return useMemo(() => accessibilityAttributes(accessibility), [accessibility]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAgB,aACd,MACA,MACA;AACA,kDAA2B,MAAM,KAAK;;;;;;AAOxC,SAAS,cAAc,KAA8C;AACnE,QACE,QAAQ,QACR,OAAO,QAAQ,YACf,OAAO,UAAU,SAAS,KAAK,IAAI,KAAK;;;;;;;;;;;;;;;AAiB5C,SAAgB,oBAAuB,OAAa;CAClD,MAAM,wBAAa,MAAM;AAGzB,KAAI,IAAI,YAAY,MAAO,QAAO,IAAI;AAGtC,KAAI,cAAc,IAAI,QAAQ,IAAI,cAAc,MAAM,EACpD;MAAI,aAAa,IAAI,SAAS,MAAM,CAAE,QAAO,IAAI;;AAInD,KAAI,UAAU;AACd,QAAO,IAAI;;;;;ACyFb,MAAa,sDAC+B,KAAK;AAEjD,SAAgB,yBAAqD;AACnE,8BAAkB,2BAA2B;;AAG/C,SAAgB,iCAAsD;CACpE,MAAM,gCAAqB,2BAA2B;AACtD,KAAI,CAAC,QACH,OAAM,IAAI,MACR,2NACD;AAEH,QAAO;;AAaT,MAAa,mDACwC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5B1D,SAAgB,mBASd,QASA;AAIA,iEAAa,OAAO;;;;;;;;;;;;;;;;;;;;ACrItB,SAAgB,+BAA2D;CAEzE,MAAM,sCADkB,wBAAwB,EACpB;AAC5B,6FAA6C,cAAc,EAAE,CAAC,cAAc,CAAC"}
|