@copilotkit/react-core 1.85.0 → 1.87.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.
Files changed (69) hide show
  1. package/dist/MarkdownSurfaces-BCVdnDAk.cjs +161 -0
  2. package/dist/MarkdownSurfaces-BCVdnDAk.cjs.map +1 -0
  3. package/dist/MarkdownSurfaces-CjJduaJR.mjs +149 -0
  4. package/dist/MarkdownSurfaces-CjJduaJR.mjs.map +1 -0
  5. package/dist/{MarkdownSurfaces-3cGU5_0H.cjs → chat-BnsrQ0VS.cjs} +667 -320
  6. package/dist/chat-BnsrQ0VS.cjs.map +1 -0
  7. package/dist/{MarkdownSurfaces-D-W4f9Dy.mjs → chat-IWySXWXP.mjs} +647 -312
  8. package/dist/chat-IWySXWXP.mjs.map +1 -0
  9. package/dist/{copilotkit-Dn4PbHJV.d.mts → copilotkit-BNPEXnEE.d.mts} +11 -6
  10. package/dist/{copilotkit-Dn4PbHJV.d.mts.map → copilotkit-BNPEXnEE.d.mts.map} +1 -1
  11. package/dist/{copilotkit-CuTAoQF2.d.cts → copilotkit-Bop-sY6y.d.cts} +9 -4
  12. package/dist/{copilotkit-CuTAoQF2.d.cts.map → copilotkit-Bop-sY6y.d.cts.map} +1 -1
  13. package/dist/{copilotkit-BpKHgURs.cjs → copilotkit-CZ9tI_J1.cjs} +203 -452
  14. package/dist/copilotkit-CZ9tI_J1.cjs.map +1 -0
  15. package/dist/{copilotkit-D6mTCuNU.mjs → copilotkit-ChqQa52S.mjs} +131 -380
  16. package/dist/{copilotkit-BpKHgURs.cjs.map → copilotkit-ChqQa52S.mjs.map} +1 -1
  17. package/dist/hooks-CEFWIeKR.d.cts +89 -0
  18. package/dist/hooks-CEFWIeKR.d.cts.map +1 -0
  19. package/dist/hooks-DFgYRjj3.d.mts +89 -0
  20. package/dist/hooks-DFgYRjj3.d.mts.map +1 -0
  21. package/dist/index.cjs +8 -8
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +2 -2
  24. package/dist/index.d.mts +2 -2
  25. package/dist/index.mjs +2 -2
  26. package/dist/index.umd.js +769 -165
  27. package/dist/index.umd.js.map +1 -1
  28. package/dist/refs-DL7ITFFD.cjs +43 -0
  29. package/dist/refs-DL7ITFFD.cjs.map +1 -0
  30. package/dist/refs-DiZXJ63p.mjs +31 -0
  31. package/dist/refs-DiZXJ63p.mjs.map +1 -0
  32. package/dist/{runtime-context-Er5UIbZA.d.mts → runtime-context-B4fKyzo6.d.mts} +31 -9
  33. package/dist/runtime-context-B4fKyzo6.d.mts.map +1 -0
  34. package/dist/{runtime-context-DrVNUYLi.d.cts → runtime-context-Da7T5vy4.d.cts} +31 -9
  35. package/dist/runtime-context-Da7T5vy4.d.cts.map +1 -0
  36. package/dist/use-generative-ui-root-CaTyBFNR.cjs +390 -0
  37. package/dist/use-generative-ui-root-CaTyBFNR.cjs.map +1 -0
  38. package/dist/use-generative-ui-root-WI9ERMpo.mjs +385 -0
  39. package/dist/use-generative-ui-root-WI9ERMpo.mjs.map +1 -0
  40. package/dist/v2/generative-ui/native.cjs +66 -0
  41. package/dist/v2/generative-ui/native.cjs.map +1 -0
  42. package/dist/v2/generative-ui/native.d.cts +155 -0
  43. package/dist/v2/generative-ui/native.d.cts.map +1 -0
  44. package/dist/v2/generative-ui/native.d.mts +155 -0
  45. package/dist/v2/generative-ui/native.d.mts.map +1 -0
  46. package/dist/v2/generative-ui/native.mjs +24 -0
  47. package/dist/v2/generative-ui/native.mjs.map +1 -0
  48. package/dist/v2/generative-ui.cjs +45 -70
  49. package/dist/v2/generative-ui.cjs.map +1 -1
  50. package/dist/v2/generative-ui.d.cts +378 -457
  51. package/dist/v2/generative-ui.d.cts.map +1 -1
  52. package/dist/v2/generative-ui.d.mts +378 -457
  53. package/dist/v2/generative-ui.d.mts.map +1 -1
  54. package/dist/v2/generative-ui.mjs +4 -29
  55. package/dist/v2/generative-ui.mjs.map +1 -1
  56. package/dist/v2/headless.d.cts +185 -294
  57. package/dist/v2/headless.d.cts.map +1 -1
  58. package/dist/v2/index.cjs +5 -5
  59. package/dist/v2/index.d.cts +2 -2
  60. package/dist/v2/index.d.mts +2 -2
  61. package/dist/v2/index.mjs +2 -2
  62. package/dist/v2/index.umd.js +769 -165
  63. package/dist/v2/index.umd.js.map +1 -1
  64. package/package.json +14 -10
  65. package/dist/MarkdownSurfaces-3cGU5_0H.cjs.map +0 -1
  66. package/dist/MarkdownSurfaces-D-W4f9Dy.mjs.map +0 -1
  67. package/dist/copilotkit-D6mTCuNU.mjs.map +0 -1
  68. package/dist/runtime-context-DrVNUYLi.d.cts.map +0 -1
  69. package/dist/runtime-context-Er5UIbZA.d.mts.map +0 -1
@@ -0,0 +1,43 @@
1
+ const require_chat = require('./chat-BnsrQ0VS.cjs');
2
+ let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
3
+
4
+ //#region src/v2/generative-ui/refs.ts
5
+ /**
6
+ * One component id. The component receives the rendered child. Pass the
7
+ * description here, not with `.describe()`, which would replace the mark.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const tabsSchema = z.object({
12
+ * tabs: z.array(z.object({ title: z.string(), child: child() })),
13
+ * });
14
+ * // The component gets `tabs: { title: string; child: ReactNode }[]`.
15
+ * ```
16
+ */
17
+ function child(description) {
18
+ return (0, _copilotkit_shared_generative_ui.child)(description);
19
+ }
20
+ /**
21
+ * A list of component ids, or a template `{ componentId, path }` that
22
+ * repeats one component for each item of the list at `path`. The
23
+ * component receives the rendered children. Pass the description here,
24
+ * not with `.describe()`.
25
+ */
26
+ function childList(description) {
27
+ return (0, _copilotkit_shared_generative_ui.childList)(description);
28
+ }
29
+
30
+ //#endregion
31
+ Object.defineProperty(exports, 'child', {
32
+ enumerable: true,
33
+ get: function () {
34
+ return child;
35
+ }
36
+ });
37
+ Object.defineProperty(exports, 'childList', {
38
+ enumerable: true,
39
+ get: function () {
40
+ return childList;
41
+ }
42
+ });
43
+ //# sourceMappingURL=refs-DL7ITFFD.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs-DL7ITFFD.cjs","names":[],"sources":["../src/v2/generative-ui/refs.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport {\n child as sharedChild,\n childList as sharedChildList,\n} from \"@copilotkit/shared/generative-ui\";\n\n/**\n * One component id. The component receives the rendered child. Pass the\n * description here, not with `.describe()`, which would replace the mark.\n *\n * @example\n * ```ts\n * const tabsSchema = z.object({\n * tabs: z.array(z.object({ title: z.string(), child: child() })),\n * });\n * // The component gets `tabs: { title: string; child: ReactNode }[]`.\n * ```\n */\nexport function child(description?: string) {\n return sharedChild<ReactNode>(description);\n}\n\n/**\n * A list of component ids, or a template `{ componentId, path }` that\n * repeats one component for each item of the list at `path`. The\n * component receives the rendered children. Pass the description here,\n * not with `.describe()`.\n */\nexport function childList(description?: string) {\n return sharedChildList<ReactNode>(description);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,MAAM,aAAsB;AAC1C,oDAA8B,YAAY;;;;;;;;AAS5C,SAAgB,UAAU,aAAsB;AAC9C,wDAAkC,YAAY"}
@@ -0,0 +1,31 @@
1
+ import { child, childList } from "@copilotkit/shared/generative-ui";
2
+
3
+ //#region src/v2/generative-ui/refs.ts
4
+ /**
5
+ * One component id. The component receives the rendered child. Pass the
6
+ * description here, not with `.describe()`, which would replace the mark.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const tabsSchema = z.object({
11
+ * tabs: z.array(z.object({ title: z.string(), child: child() })),
12
+ * });
13
+ * // The component gets `tabs: { title: string; child: ReactNode }[]`.
14
+ * ```
15
+ */
16
+ function child$1(description) {
17
+ return child(description);
18
+ }
19
+ /**
20
+ * A list of component ids, or a template `{ componentId, path }` that
21
+ * repeats one component for each item of the list at `path`. The
22
+ * component receives the rendered children. Pass the description here,
23
+ * not with `.describe()`.
24
+ */
25
+ function childList$1(description) {
26
+ return childList(description);
27
+ }
28
+
29
+ //#endregion
30
+ export { childList$1 as n, child$1 as t };
31
+ //# sourceMappingURL=refs-DiZXJ63p.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs-DiZXJ63p.mjs","names":["child","sharedChild","childList","sharedChildList"],"sources":["../src/v2/generative-ui/refs.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport {\n child as sharedChild,\n childList as sharedChildList,\n} from \"@copilotkit/shared/generative-ui\";\n\n/**\n * One component id. The component receives the rendered child. Pass the\n * description here, not with `.describe()`, which would replace the mark.\n *\n * @example\n * ```ts\n * const tabsSchema = z.object({\n * tabs: z.array(z.object({ title: z.string(), child: child() })),\n * });\n * // The component gets `tabs: { title: string; child: ReactNode }[]`.\n * ```\n */\nexport function child(description?: string) {\n return sharedChild<ReactNode>(description);\n}\n\n/**\n * A list of component ids, or a template `{ componentId, path }` that\n * repeats one component for each item of the list at `path`. The\n * component receives the rendered children. Pass the description here,\n * not with `.describe()`.\n */\nexport function childList(description?: string) {\n return sharedChildList<ReactNode>(description);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,SAAgBA,QAAM,aAAsB;AAC1C,QAAOC,MAAuB,YAAY;;;;;;;;AAS5C,SAAgBC,YAAU,aAAsB;AAC9C,QAAOC,UAA2B,YAAY"}
@@ -1,6 +1,7 @@
1
+ import * as react from "react";
1
2
  import React$1, { ComponentType, ReactNode } from "react";
2
3
  import { AbstractAgent } from "@ag-ui/client";
3
- import { GenerativeUIRejectedOperation, GenerativeUIUserEvent, StandardSchemaV1 } from "@copilotkit/shared";
4
+ import { GenerativeUIRejectedOperation, GenerativeUISurfaceContent, GenerativeUIUserEvent, StandardSchemaV1 } from "@copilotkit/shared";
4
5
  import * as react_jsx_runtime0 from "react/jsx-runtime";
5
6
  import { ActivityMessage } from "@ag-ui/core";
6
7
  import { GenerativeUIAccessibility, GenerativeUIAriaAttributes, GenerativeUIAriaAttributes as GenerativeUIAriaAttributes$1, GenerativeUIDispatcher, GenerativeUISurfaceManager } from "@copilotkit/core/generative-ui";
@@ -50,6 +51,8 @@ declare function DefaultGenerativeUIChatCard({
50
51
  error,
51
52
  children
52
53
  }: GenerativeUIChatSurfaceProps): react_jsx_runtime0.JSX.Element;
54
+ /** Hides the raw `render_ui` tool call; the surface activity owns the UX. */
55
+ declare function GenerativeUIToolCallRenderer(): null;
53
56
  //#endregion
54
57
  //#region src/v2/generative-ui/accessibility.d.ts
55
58
  /**
@@ -138,14 +141,27 @@ declare function createGenerativeUI$1<Bases extends readonly AnyGenerativeUI[] =
138
141
  //#endregion
139
142
  //#region src/v2/generative-ui/runtime-context.d.ts
140
143
  interface GenerativeUIErrorBoundaryConfig {
141
- /** Replaces the default per-component fallback. */
144
+ /**
145
+ * Replaces the host's fallback for a component that failed to render. It
146
+ * is not used for invalid props, unknown types, cyclic references or a
147
+ * failed surface: the host's `NodeFallback` shows those. If it throws,
148
+ * the host's fallback stands in and the error is reported. `error` is
149
+ * always an Error: a component that throws something else (a string,
150
+ * `undefined`) gets an Error that describes it, with the value as its
151
+ * `cause`.
152
+ */
142
153
  fallback?: (props: {
143
154
  error: Error;
144
155
  retry: () => void;
145
156
  surfaceId: string;
146
157
  componentId: string;
147
158
  }) => ReactNode;
148
- /** Called for render, props, operation, function and event failures. */
159
+ /**
160
+ * Called for render, props, operation, function and event failures. A
161
+ * render or props failure that stays the same across new revisions of the
162
+ * node or the surface is reported once, until the node or surface renders
163
+ * again. A failed function or event is reported on every call.
164
+ */
149
165
  onError?: (info: GenerativeUIErrorInfo) => void;
150
166
  }
151
167
  interface GenerativeUIBaseConfig {
@@ -160,9 +176,10 @@ interface GenerativeUIBaseConfig {
160
176
  */
161
177
  agentIds?: string[];
162
178
  /**
163
- * Values for the `--a2ui-*` CSS variables and the map style. Top-level
164
- * values apply in both modes. `dark` changes them in dark mode, which is
165
- * on under a `.dark` class, like the CopilotKit chat.
179
+ * Web only. Values for the `--a2ui-*` CSS variables and the map style.
180
+ * Top-level values apply in both modes. `dark` changes them in dark mode,
181
+ * which is on under a `.dark` class, like the CopilotKit chat. React
182
+ * Native ignores it.
166
183
  */
167
184
  theme?: GenerativeUITheme;
168
185
  /** Fallback UI and error reporting for generated UI. */
@@ -216,13 +233,18 @@ interface GenerativeUIRuntime {
216
233
  transport: "tool" | "markdown";
217
234
  /** The latest `generativeUI` config of the provider. */
218
235
  readonly config: GenerativeUIConfig;
219
- /** The latest `theme`. Each surface root sets its CSS variables. */
236
+ /**
237
+ * The latest `theme`. The host's surface root gets it: on the web it sets
238
+ * the CSS variables; the React Native root ignores it.
239
+ */
220
240
  theme?: GenerativeUITheme;
221
241
  forwardEvent: (event: GenerativeUIUserEvent, agentId: string | undefined) => Promise<GenerativeUIInvokeResult>;
222
242
  reportError: (info: GenerativeUIErrorInfo) => void;
223
243
  readonly errorFallback?: GenerativeUIErrorBoundaryConfig["fallback"];
224
244
  }
245
+ declare const GenerativeUIRuntimeContext: react.Context<GenerativeUIRuntime | null>;
225
246
  declare function useGenerativeUIRuntime(): GenerativeUIRuntime | null;
247
+ declare function useRequiredGenerativeUIRuntime(): GenerativeUIRuntime;
226
248
  //#endregion
227
- export { useGenerativeUIAccessibility as C, ReactActivityMessageRenderer as E, GenerativeUIAriaAttributes$1 as S, GenerativeUIChatSurfaceProps as T, GenerativeUIFunctionName as _, GenerativeUIToolConfig as a, createGenerativeUI$1 as b, GenerativeUI$1 as c, GenerativeUIComponentProps$1 as d, GenerativeUIDefinitionsOf as f, GenerativeUIFunctionInput as g, GenerativeUIFunctionDefinition$1 as h, GenerativeUITheme as i, GenerativeUIComponentDefinition$1 as l, GenerativeUIFunctionArgs as m, GenerativeUIErrorBoundaryConfig as n, useGenerativeUIRuntime as o, GenerativeUIEventDefinition as p, GenerativeUIMarkdownConfig as r, CreateGenerativeUIConfig$1 as s, GenerativeUIConfig as t, GenerativeUIComponentName as u, GenerativeUISlotKind as v, DefaultGenerativeUIChatCard as w, GenerativeUIAccessibility as x, GenerativeUIStateOf as y };
228
- //# sourceMappingURL=runtime-context-Er5UIbZA.d.mts.map
249
+ export { ReactActivityMessageRenderer as A, createGenerativeUI$1 as C, DefaultGenerativeUIChatCard as D, useGenerativeUIAccessibility as E, GenerativeUIChatSurfaceProps as O, GenerativeUIStateOf as S, GenerativeUIAriaAttributes$1 as T, GenerativeUIFunctionArgs as _, GenerativeUIRuntimeContext as a, GenerativeUIFunctionName as b, useGenerativeUIRuntime as c, GenerativeUI$1 as d, GenerativeUIComponentDefinition$1 as f, GenerativeUIEventDefinition as g, GenerativeUIDefinitionsOf as h, GenerativeUIRuntime as i, GenerativeUIToolCallRenderer as k, useRequiredGenerativeUIRuntime as l, GenerativeUIComponentProps$1 as m, GenerativeUIErrorBoundaryConfig as n, GenerativeUITheme as o, GenerativeUIComponentName as p, GenerativeUIMarkdownConfig as r, GenerativeUIToolConfig as s, GenerativeUIConfig as t, CreateGenerativeUIConfig$1 as u, GenerativeUIFunctionDefinition$1 as v, GenerativeUIAccessibility as w, GenerativeUISlotKind as x, GenerativeUIFunctionInput as y };
250
+ //# sourceMappingURL=runtime-context-B4fKyzo6.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-context-B4fKyzo6.d.mts","names":[],"sources":["../src/v2/types/react-activity-message-renderer.ts","../src/v2/generative-ui/chat.tsx","../src/v2/generative-ui/accessibility.ts","../src/v2/generative-ui/catalog.ts","../src/v2/generative-ui/runtime-context.ts"],"mappings":";;;;;;;;;;UAIiB,4BAAA;;;;EAIf,YAAA;;;AAJF;EAQE,OAAA;EAR2C;;;EAY3C,OAAA,EAAS,gBAAA,MAAsB,gBAAA;EAOpB;;;EAHX,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,YAAA;IACA,OAAA,EAAS,gBAAA;IACT,OAAA,EAAS,eAAA;IACT,KAAA,EAAO,aAAA;EAAA;AAAA;;;UCCM,4BAAA;EACf,SAAA;EACA,WAAA;;;;ADvBF;EC4BE,KAAA,GAAQ,KAAA;ED5BmC;EC8B3C,QAAA,EAAU,6BAAA;EACV,QAAA,EAAU,SAAA;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,EACA,SAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,QAAA;;;UCjKW,+BAAA;EJXA;;;;;;;;;EIqBf,QAAA,IAAY,KAAA;IACV,KAAA,EAAO,KAAA;IACP,KAAA;IACA,SAAA;IACA,WAAA;EAAA,MACI,SAAA;EJdG;;;;;;EIqBT,OAAA,IAAW,IAAA,EAAM,qBAAA;AAAA;AAAA,UAGT,sBAAA;EJjBG;;;;EIsBX,EAAA,EAAI,cAAA;;;;AHpBN;EGyBE,QAAA;;;;;;;EAOA,KAAA,GAAQ,iBAAA;EH9BR;EGgCA,aAAA,GAAgB,+BAAA;AAAA;;;;;UAOD,sBAAA,SAA+B,sBAAA;EH/B3B;EGiCnB,SAAA;EAGA,WAAA;EACA,cAAA;AAAA;;;;;UAOe,0BAAA,SAAmC,sBAAA;EAClD,SAAA;EHjC6B;;;;;EGuC7B,WAAA;EHzCA;;;;EG8CA,cAAA;AAAA;;;AH8BF;;;;;;;;KGjBY,kBAAA,GACR,sBAAA,GACA,0BAAA;AAAA,UAEa,mBAAA;EACf,OAAA,EAAS,0BAAA;EACT,UAAA,EAAY,sBAAA;EF3E4D;EE6ExE,EAAA,EAAI,cAAA;;EAEJ,SAAA;EDvEU;EAAA,SCyED,MAAA,EAAQ,kBAAA;;;;AD5DnB;ECiEE,KAAA,GAAQ,iBAAA;EACR,YAAA,GACE,KAAA,EAAO,qBAAA,EACP,OAAA,yBACG,OAAA,CAAQ,wBAAA;EACb,WAAA,GAAc,IAAA,EAAM,qBAAA;EAAA,SACX,aAAA,GAAgB,+BAAA;AAAA;AAAA,cAGd,0BAAA,EAA0B,KAAA,CAAA,OAAA,CAAA,mBAAA;AAAA,iBAGvB,sBAAA,CAAA,GAA0B,mBAAA;AAAA,iBAI1B,8BAAA,CAAA,GAAkC,mBAAA"}
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import * as react from "react";
2
3
  import React$1, { ComponentType, ReactNode } from "react";
3
- import { GenerativeUIRejectedOperation, GenerativeUIUserEvent, StandardSchemaV1 } from "@copilotkit/shared";
4
+ import { GenerativeUIRejectedOperation, GenerativeUISurfaceContent, GenerativeUIUserEvent, StandardSchemaV1 } from "@copilotkit/shared";
4
5
  import { AbstractAgent } from "@ag-ui/client";
5
6
  import { ActivityMessage } from "@ag-ui/core";
6
7
  import { GenerativeUIAccessibility, GenerativeUIAriaAttributes, GenerativeUIAriaAttributes as GenerativeUIAriaAttributes$1, GenerativeUIDispatcher, GenerativeUISurfaceManager } from "@copilotkit/core/generative-ui";
@@ -50,6 +51,8 @@ declare function DefaultGenerativeUIChatCard({
50
51
  error,
51
52
  children
52
53
  }: GenerativeUIChatSurfaceProps): react_jsx_runtime0.JSX.Element;
54
+ /** Hides the raw `render_ui` tool call; the surface activity owns the UX. */
55
+ declare function GenerativeUIToolCallRenderer(): null;
53
56
  //#endregion
54
57
  //#region src/v2/generative-ui/accessibility.d.ts
55
58
  /**
@@ -138,14 +141,27 @@ declare function createGenerativeUI<Bases extends readonly AnyGenerativeUI[] = [
138
141
  //#endregion
139
142
  //#region src/v2/generative-ui/runtime-context.d.ts
140
143
  interface GenerativeUIErrorBoundaryConfig {
141
- /** Replaces the default per-component fallback. */
144
+ /**
145
+ * Replaces the host's fallback for a component that failed to render. It
146
+ * is not used for invalid props, unknown types, cyclic references or a
147
+ * failed surface: the host's `NodeFallback` shows those. If it throws,
148
+ * the host's fallback stands in and the error is reported. `error` is
149
+ * always an Error: a component that throws something else (a string,
150
+ * `undefined`) gets an Error that describes it, with the value as its
151
+ * `cause`.
152
+ */
142
153
  fallback?: (props: {
143
154
  error: Error;
144
155
  retry: () => void;
145
156
  surfaceId: string;
146
157
  componentId: string;
147
158
  }) => ReactNode;
148
- /** Called for render, props, operation, function and event failures. */
159
+ /**
160
+ * Called for render, props, operation, function and event failures. A
161
+ * render or props failure that stays the same across new revisions of the
162
+ * node or the surface is reported once, until the node or surface renders
163
+ * again. A failed function or event is reported on every call.
164
+ */
149
165
  onError?: (info: GenerativeUIErrorInfo) => void;
150
166
  }
151
167
  interface GenerativeUIBaseConfig {
@@ -160,9 +176,10 @@ interface GenerativeUIBaseConfig {
160
176
  */
161
177
  agentIds?: string[];
162
178
  /**
163
- * Values for the `--a2ui-*` CSS variables and the map style. Top-level
164
- * values apply in both modes. `dark` changes them in dark mode, which is
165
- * on under a `.dark` class, like the CopilotKit chat.
179
+ * Web only. Values for the `--a2ui-*` CSS variables and the map style.
180
+ * Top-level values apply in both modes. `dark` changes them in dark mode,
181
+ * which is on under a `.dark` class, like the CopilotKit chat. React
182
+ * Native ignores it.
166
183
  */
167
184
  theme?: GenerativeUITheme;
168
185
  /** Fallback UI and error reporting for generated UI. */
@@ -216,13 +233,18 @@ interface GenerativeUIRuntime {
216
233
  transport: "tool" | "markdown";
217
234
  /** The latest `generativeUI` config of the provider. */
218
235
  readonly config: GenerativeUIConfig;
219
- /** The latest `theme`. Each surface root sets its CSS variables. */
236
+ /**
237
+ * The latest `theme`. The host's surface root gets it: on the web it sets
238
+ * the CSS variables; the React Native root ignores it.
239
+ */
220
240
  theme?: GenerativeUITheme;
221
241
  forwardEvent: (event: GenerativeUIUserEvent, agentId: string | undefined) => Promise<GenerativeUIInvokeResult>;
222
242
  reportError: (info: GenerativeUIErrorInfo) => void;
223
243
  readonly errorFallback?: GenerativeUIErrorBoundaryConfig["fallback"];
224
244
  }
245
+ declare const GenerativeUIRuntimeContext: react.Context<GenerativeUIRuntime | null>;
225
246
  declare function useGenerativeUIRuntime(): GenerativeUIRuntime | null;
247
+ declare function useRequiredGenerativeUIRuntime(): GenerativeUIRuntime;
226
248
  //#endregion
227
- export { useGenerativeUIAccessibility as C, ReactActivityMessageRenderer as E, GenerativeUIAriaAttributes$1 as S, GenerativeUIChatSurfaceProps as T, GenerativeUIFunctionName as _, GenerativeUIToolConfig as a, createGenerativeUI as b, GenerativeUI$1 as c, GenerativeUIComponentProps$1 as d, GenerativeUIDefinitionsOf as f, GenerativeUIFunctionInput as g, GenerativeUIFunctionDefinition$1 as h, GenerativeUITheme as i, GenerativeUIComponentDefinition$1 as l, GenerativeUIFunctionArgs as m, GenerativeUIErrorBoundaryConfig as n, useGenerativeUIRuntime as o, GenerativeUIEventDefinition as p, GenerativeUIMarkdownConfig as r, CreateGenerativeUIConfig$1 as s, GenerativeUIConfig as t, GenerativeUIComponentName as u, GenerativeUISlotKind as v, DefaultGenerativeUIChatCard as w, GenerativeUIAccessibility as x, GenerativeUIStateOf as y };
228
- //# sourceMappingURL=runtime-context-DrVNUYLi.d.cts.map
249
+ export { ReactActivityMessageRenderer as A, createGenerativeUI as C, DefaultGenerativeUIChatCard as D, useGenerativeUIAccessibility as E, GenerativeUIChatSurfaceProps as O, GenerativeUIStateOf as S, GenerativeUIAriaAttributes$1 as T, GenerativeUIFunctionArgs as _, GenerativeUIRuntimeContext as a, GenerativeUIFunctionName as b, useGenerativeUIRuntime as c, GenerativeUI$1 as d, GenerativeUIComponentDefinition$1 as f, GenerativeUIEventDefinition as g, GenerativeUIDefinitionsOf as h, GenerativeUIRuntime as i, GenerativeUIToolCallRenderer as k, useRequiredGenerativeUIRuntime as l, GenerativeUIComponentProps$1 as m, GenerativeUIErrorBoundaryConfig as n, GenerativeUITheme as o, GenerativeUIComponentName as p, GenerativeUIMarkdownConfig as r, GenerativeUIToolConfig as s, GenerativeUIConfig as t, CreateGenerativeUIConfig$1 as u, GenerativeUIFunctionDefinition$1 as v, GenerativeUIAccessibility as w, GenerativeUISlotKind as x, GenerativeUIFunctionInput as y };
250
+ //# sourceMappingURL=runtime-context-Da7T5vy4.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-context-Da7T5vy4.d.cts","names":[],"sources":["../src/v2/types/react-activity-message-renderer.ts","../src/v2/generative-ui/chat.tsx","../src/v2/generative-ui/accessibility.ts","../src/v2/generative-ui/catalog.ts","../src/v2/generative-ui/runtime-context.ts"],"mappings":";;;;;;;;;;UAIiB,4BAAA;;;;EAIf,YAA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G,OAAA,CAAQ,wBAAA;EACb,WAAA,GAAc,IAAA,EAAM,qBAAA;EAAA,SACX,aAAA,GAAgB,+BAAA;AAAA;AAAA,cAGd,0BAAA,EAA0B,KAAA,CAAA,OAAA,CAAA,mBAAA;AAAA,iBAGvB,sBAAA,CAAA,GAA0B,mBAAA;AAAA,iBAI1B,8BAAA,CAAA,GAAkC,mBAAA"}
@@ -0,0 +1,390 @@
1
+ const require_chat = require('./chat-BnsrQ0VS.cjs');
2
+ let react = require("react");
3
+ let _copilotkit_shared = require("@copilotkit/shared");
4
+ let _copilotkit_core_generative_ui = require("@copilotkit/core/generative-ui");
5
+ let _copilotkit_shared_generative_ui = require("@copilotkit/shared/generative-ui");
6
+
7
+ //#region src/v2/generative-ui/markdown/context.ts
8
+ /**
9
+ * Registers the two context entries of the markdown transport: the compact
10
+ * component schema and the fence guideline. Both go only to `agentIds`.
11
+ *
12
+ * The schema is built again at each run start and when a
13
+ * `<GenerativeUISurface>` mounts, unmounts, or changes its description or
14
+ * its components, so its targets, functions, and surfaces stay current. The surfaces are those of the running thread.
15
+ *
16
+ * @param copilotkit - The CopilotKit core of the provider.
17
+ * @param runtime - The generative UI runtime parts, or null without one.
18
+ * @param options - `enabled` and `agentIds`.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * useGenerativeUIMarkdownContext(copilotkit, core, {
23
+ * enabled: config?.transport === "markdown" && config.sendContext !== false,
24
+ * agentIds: config?.agentIds,
25
+ * });
26
+ * ```
27
+ */
28
+ function useGenerativeUIMarkdownContext(copilotkit, runtime, options) {
29
+ const { enabled, agentIds } = options;
30
+ const agentIdsKey = agentIds === void 0 ? "" : JSON.stringify(agentIds);
31
+ (0, react.useEffect)(() => {
32
+ if (!runtime || !enabled) return;
33
+ const scopedAgentIds = agentIdsKey ? JSON.parse(agentIdsKey) : void 0;
34
+ const scope = scopedAgentIds ? { agentIds: scopedAgentIds } : {};
35
+ let guidelineId;
36
+ let guidelineValue;
37
+ let schemaId;
38
+ let schemaValue;
39
+ const refreshSchema = (threadId) => {
40
+ const manifest = (0, _copilotkit_core_generative_ui.buildGenerativeUIManifest)(runtime, threadId);
41
+ const guideline = (0, _copilotkit_shared.buildGenerativeUIMarkdownGuidelines)((0, _copilotkit_shared.generativeUIGuideFeatures)(manifest));
42
+ if (guideline !== guidelineValue) {
43
+ if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
44
+ guidelineValue = guideline;
45
+ guidelineId = copilotkit.addContext({
46
+ description: _copilotkit_shared.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION,
47
+ value: guideline,
48
+ ...scope
49
+ });
50
+ }
51
+ const value = (0, _copilotkit_shared.renderGenerativeUISchema)(manifest, (0, _copilotkit_shared.defaultGenerativeUIPromptSpec)().schema.markdown);
52
+ if (value === schemaValue) return;
53
+ if (schemaId !== void 0) copilotkit.removeContext(schemaId);
54
+ schemaValue = value;
55
+ schemaId = copilotkit.addContext({
56
+ description: _copilotkit_shared.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION,
57
+ value,
58
+ ...scope
59
+ });
60
+ };
61
+ refreshSchema(runtime.manager.getActiveThread());
62
+ let targetsKey = JSON.stringify(runtime.manager.getMountedTargets());
63
+ const unsubscribeManager = runtime.manager.subscribe(() => {
64
+ const nextKey = JSON.stringify(runtime.manager.getMountedTargets());
65
+ if (nextKey === targetsKey) return;
66
+ targetsKey = nextKey;
67
+ refreshSchema(runtime.manager.getActiveThread());
68
+ });
69
+ const subscription = copilotkit.subscribe({ onAgentRunStarted: ({ agent }) => refreshSchema(agent.threadId) });
70
+ return () => {
71
+ subscription.unsubscribe();
72
+ unsubscribeManager();
73
+ if (guidelineId !== void 0) copilotkit.removeContext(guidelineId);
74
+ if (schemaId !== void 0) copilotkit.removeContext(schemaId);
75
+ };
76
+ }, [
77
+ copilotkit,
78
+ runtime,
79
+ enabled,
80
+ agentIdsKey
81
+ ]);
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/v2/generative-ui/use-generative-ui-root.ts
86
+ const isDevelopment = () => process.env.NODE_ENV !== "production";
87
+ /**
88
+ * The malformed-content warnings already printed, by manager, so each
89
+ * distinct issue warns once while the manager lives.
90
+ */
91
+ const warnedMalformed = /* @__PURE__ */ new WeakMap();
92
+ /**
93
+ * Ingests the surface activity messages of `messages`. A message whose
94
+ * content is malformed (for example `null`) is skipped, in development with a
95
+ * warning once for each distinct issue, so it cannot throw inside the
96
+ * agent's run; the messages after it are still ingested.
97
+ */
98
+ function ingestMessages(manager, agent, messages) {
99
+ const { threadId } = agent;
100
+ if (!threadId) return;
101
+ for (const message of messages) {
102
+ if (message.role !== "activity" || message.activityType !== _copilotkit_shared.GENERATIVE_UI_ACTIVITY_TYPE) continue;
103
+ const parsed = (0, _copilotkit_core_generative_ui.parseGenerativeUISurfaceContent)(message.content);
104
+ if (parsed.content) {
105
+ manager.ingest(threadId, agent.agentId, parsed.content);
106
+ continue;
107
+ }
108
+ if (!isDevelopment()) continue;
109
+ const warning = `[generativeUI] skipped an activity message of thread ${JSON.stringify(threadId)}: its content is malformed: ${parsed.issues.join("; ")}.`;
110
+ let warned = warnedMalformed.get(manager);
111
+ if (!warned) {
112
+ warned = /* @__PURE__ */ new Set();
113
+ warnedMalformed.set(manager, warned);
114
+ }
115
+ if (warned.has(warning)) continue;
116
+ warned.add(warning);
117
+ console.warn(warning);
118
+ }
119
+ }
120
+ /** Provider-side wiring: manager, dispatcher, agent subscriptions, envelope. */
121
+ function useGenerativeUIRoot(copilotkit, config) {
122
+ const configRef = (0, react.useRef)(config);
123
+ configRef.current = config;
124
+ const ui = config?.ui;
125
+ const transport = config?.transport ?? "tool";
126
+ const theme = require_chat.useShallowStableRef(config?.theme);
127
+ const core = (0, react.useMemo)(() => {
128
+ if (!ui) return null;
129
+ const reportError = (info) => {
130
+ try {
131
+ configRef.current?.errorBoundary?.onError?.(info);
132
+ } catch (hostError) {
133
+ if (isDevelopment()) console.error("[generativeUI] errorBoundary.onError threw:", hostError);
134
+ }
135
+ if (isDevelopment()) console.warn(`[generativeUI] ${info.kind} error in ${info.surfaceId}${info.componentId ? `/${info.componentId}` : ""}: ${info.error?.message}`);
136
+ };
137
+ const manager = new _copilotkit_core_generative_ui.GenerativeUISurfaceManager(ui, { onOperationRejected: ({ surfaceId, index, reason }) => reportError({
138
+ kind: "operation",
139
+ surfaceId,
140
+ error: /* @__PURE__ */ new Error(`operation ${index} rejected: ${reason}`)
141
+ }) });
142
+ const dispatcher = (0, _copilotkit_core_generative_ui.createGenerativeUIDispatcher)({
143
+ getDeclared: () => ui.functions,
144
+ onError: ({ name, origin, error }) => {
145
+ if ("functionCallId" in origin) {
146
+ if (isDevelopment()) console.warn(`[generativeUI] function call ${origin.functionCallId} to "${name}" failed: ${error.message}`);
147
+ return;
148
+ }
149
+ reportError({
150
+ kind: "function",
151
+ ...origin,
152
+ error
153
+ });
154
+ }
155
+ });
156
+ const functionCalls = (0, _copilotkit_core_generative_ui.createFunctionCallRunner)({
157
+ core: copilotkit,
158
+ dispatcher,
159
+ manifest: {
160
+ catalogId: ui.id,
161
+ catalogIds: (0, _copilotkit_shared_generative_ui.catalogIdsOf)(ui),
162
+ components: ui.manifestComponents
163
+ },
164
+ settle: () => copilotkit.waitForPendingFrameworkUpdates(),
165
+ warn: (message, error) => {
166
+ if (isDevelopment()) console.warn(message, error);
167
+ }
168
+ });
169
+ const forwardingAgents = /* @__PURE__ */ new Set();
170
+ /**
171
+ * The action of a user event, as an envelope entry scoped to the agent
172
+ * the user acted on, for the run that the event starts: the structured
173
+ * form of the user message. It is set before the run starts and dropped
174
+ * when the run is over, so a suggestion request or a follow-up run
175
+ * (both read the properties with no run start) does not carry the same
176
+ * action again, and another agent never gets a click meant for this one.
177
+ * The entry comes after the shared envelope, so it wins for its agent;
178
+ * `refreshActions` keeps it last when the shared envelope is set again.
179
+ */
180
+ const actions = /* @__PURE__ */ new Map();
181
+ const dropAction = (agent) => {
182
+ const entry = actions.get(agent);
183
+ if (!entry) return;
184
+ entry.subscription.unsubscribe();
185
+ copilotkit.removeScopedProperties(entry.id);
186
+ actions.delete(agent);
187
+ };
188
+ const setAction = (agent, action) => {
189
+ const previous = actions.get(agent);
190
+ previous?.subscription.unsubscribe();
191
+ if (previous) copilotkit.removeScopedProperties(previous.id);
192
+ actions.delete(agent);
193
+ const latest = configRef.current;
194
+ if (!latest) return;
195
+ const envelope = (0, _copilotkit_core_generative_ui.buildGenerativeUIEnvelope)({
196
+ ui,
197
+ manager,
198
+ dispatcher
199
+ }, agent.threadId, {
200
+ ...(0, _copilotkit_core_generative_ui.envelopeOptionsFor)(latest),
201
+ action
202
+ });
203
+ const id = copilotkit.addScopedProperties({
204
+ properties: { [_copilotkit_shared.COPILOTKIT_FORWARDED_PROPS_KEY]: { ui: envelope } },
205
+ agentIds: agent.agentId === void 0 ? latest.agentIds : [agent.agentId]
206
+ });
207
+ const subscription = agent.subscribe({
208
+ onRunFinalized: () => dropAction(agent),
209
+ onRunFailed: () => dropAction(agent)
210
+ });
211
+ actions.set(agent, {
212
+ id,
213
+ action,
214
+ subscription
215
+ });
216
+ };
217
+ const refreshActions = () => {
218
+ for (const [agent, { action }] of [...actions]) setAction(agent, action);
219
+ };
220
+ const dropAllActions = () => {
221
+ for (const agent of [...actions.keys()]) dropAction(agent);
222
+ };
223
+ const forwardEvent = async (event, agentId) => {
224
+ const fail = (message) => {
225
+ const error = new _copilotkit_shared_generative_ui.GenerativeUIError("event_forward_failed", message);
226
+ reportError({
227
+ kind: "event",
228
+ surfaceId: event.surfaceId,
229
+ componentId: event.componentId,
230
+ error
231
+ });
232
+ return {
233
+ ok: false,
234
+ error
235
+ };
236
+ };
237
+ const agent = copilotkit.getAgent(agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID);
238
+ if (!agent) return fail(`No agent "${agentId}" to receive "${event.name}"`);
239
+ if (agent.isRunning || forwardingAgents.has(agent)) return {
240
+ ok: false,
241
+ error: new _copilotkit_shared_generative_ui.GenerativeUIError("agent_busy", `"${event.name}" was not sent: the agent is running`)
242
+ };
243
+ forwardingAgents.add(agent);
244
+ try {
245
+ const surface = agent.threadId ? manager.getSurface(agent.threadId, event.surfaceId) : void 0;
246
+ const resolveLabel = surface ? (0, _copilotkit_core_generative_ui.surfaceLabelResolver)(surface) : void 0;
247
+ agent.addMessage({
248
+ id: (0, _copilotkit_shared.randomUUID)(),
249
+ role: "user",
250
+ content: (0, _copilotkit_core_generative_ui.buildActionMessageText)(event, resolveLabel)
251
+ });
252
+ setAction(agent, (0, _copilotkit_shared.toA2UIActionMessage)(event));
253
+ await copilotkit.runAgent({ agent });
254
+ return {
255
+ ok: true,
256
+ result: void 0
257
+ };
258
+ } catch (cause) {
259
+ return fail(`Forwarding "${event.name}" failed: ${cause instanceof Error ? cause.message : String(cause)}`);
260
+ } finally {
261
+ forwardingAgents.delete(agent);
262
+ dropAction(agent);
263
+ }
264
+ };
265
+ return {
266
+ manager,
267
+ dispatcher,
268
+ ui,
269
+ forwardEvent,
270
+ reportError,
271
+ functionCalls,
272
+ refreshActions,
273
+ dropAllActions
274
+ };
275
+ }, [ui, copilotkit]);
276
+ const runtime = (0, react.useMemo)(() => {
277
+ if (!core) return null;
278
+ const { manager, dispatcher, forwardEvent, reportError } = core;
279
+ return {
280
+ manager,
281
+ dispatcher,
282
+ ui: core.ui,
283
+ forwardEvent,
284
+ reportError,
285
+ transport,
286
+ theme,
287
+ get config() {
288
+ return configRef.current ?? { ui: core.ui };
289
+ },
290
+ get errorFallback() {
291
+ return configRef.current?.errorBoundary?.fallback;
292
+ }
293
+ };
294
+ }, [
295
+ core,
296
+ transport,
297
+ theme
298
+ ]);
299
+ (0, react.useEffect)(() => {
300
+ if (!core) return;
301
+ const watched = /* @__PURE__ */ new WeakSet();
302
+ const agentSubscriptions = [];
303
+ let envelopeId;
304
+ const debug = (0, _copilotkit_core_generative_ui.createGenerativeUIDebugSource)(core, () => {
305
+ const latest = configRef.current ?? { ui: core.ui };
306
+ return {
307
+ options: (0, _copilotkit_core_generative_ui.envelopeOptionsFor)(latest),
308
+ agentIds: latest.agentIds
309
+ };
310
+ });
311
+ copilotkit.ɵsetGenerativeUIDebugSource(debug.source);
312
+ const removeEnvelope = () => {
313
+ if (envelopeId === void 0) return;
314
+ copilotkit.removeScopedProperties(envelopeId);
315
+ envelopeId = void 0;
316
+ };
317
+ /**
318
+ * Sets the shared envelope of the run. The action entries of the agents
319
+ * with a user event under way (see `forwardEvent`) are set again after
320
+ * it, so they stay the last entries and win for their agents.
321
+ */
322
+ const setEnvelope = (agent, latest) => {
323
+ removeEnvelope();
324
+ const run = (0, _copilotkit_core_generative_ui.describeGenerativeUIRun)(core, agent.threadId, (0, _copilotkit_core_generative_ui.envelopeOptionsFor)(latest));
325
+ envelopeId = copilotkit.addScopedProperties({
326
+ properties: { [_copilotkit_shared.COPILOTKIT_FORWARDED_PROPS_KEY]: { ui: run.envelope } },
327
+ agentIds: latest.agentIds
328
+ });
329
+ core.refreshActions();
330
+ if (!latest.agentIds || latest.agentIds.includes(agent.agentId ?? "")) debug.recordRun({
331
+ ...run,
332
+ agentId: agent.agentId,
333
+ threadId: agent.threadId,
334
+ startedAt: Date.now()
335
+ });
336
+ };
337
+ /**
338
+ * The tool transport reads the surface activity messages. The markdown
339
+ * transport reads the ```a2ui fences of the assistant messages, and
340
+ * builds the surfaces of the thread from them again on each change.
341
+ * Both give their function calls to the one runner.
342
+ */
343
+ const readMessages = (agent, messages, running) => {
344
+ const requests = (0, _copilotkit_core_generative_ui.activityFunctionCalls)(messages);
345
+ const { threadId } = agent;
346
+ if (configRef.current?.transport !== "markdown") ingestMessages(core.manager, agent, messages);
347
+ else if (threadId) {
348
+ core.manager.setActiveThread(threadId);
349
+ const calls = (0, _copilotkit_core_generative_ui.getMarkdownSurfaceSource)(core).sync(threadId, agent.agentId, messages, { running });
350
+ requests.push(...(0, _copilotkit_core_generative_ui.markdownFunctionCalls)(calls));
351
+ }
352
+ core.functionCalls.run(agent, requests, messages, running);
353
+ };
354
+ const subscription = copilotkit.subscribe({ onAgentRunStarted: ({ agent }) => {
355
+ core.manager.setActiveThread(agent.threadId);
356
+ const latest = configRef.current;
357
+ if (latest) setEnvelope(agent, latest);
358
+ if (!watched.has(agent)) {
359
+ watched.add(agent);
360
+ agentSubscriptions.push(agent.subscribe({
361
+ onMessagesChanged: ({ messages }) => readMessages(agent, messages, agent.isRunning),
362
+ onRunFinalized: () => readMessages(agent, agent.messages, false),
363
+ onRunFailed: () => readMessages(agent, agent.messages, false)
364
+ }));
365
+ }
366
+ readMessages(agent, agent.messages, true);
367
+ } });
368
+ return () => {
369
+ subscription.unsubscribe();
370
+ for (const s of agentSubscriptions) s.unsubscribe();
371
+ core.dropAllActions();
372
+ removeEnvelope();
373
+ if (copilotkit.ɵgenerativeUIDebugSource === debug.source) copilotkit.ɵsetGenerativeUIDebugSource(void 0);
374
+ };
375
+ }, [core, copilotkit]);
376
+ useGenerativeUIMarkdownContext(copilotkit, core, {
377
+ enabled: config?.transport === "markdown" && config.sendContext !== false,
378
+ agentIds: config?.agentIds
379
+ });
380
+ return runtime;
381
+ }
382
+
383
+ //#endregion
384
+ Object.defineProperty(exports, 'useGenerativeUIRoot', {
385
+ enumerable: true,
386
+ get: function () {
387
+ return useGenerativeUIRoot;
388
+ }
389
+ });
390
+ //# sourceMappingURL=use-generative-ui-root-CaTyBFNR.cjs.map