@copilotkit/shared 1.84.2-canary.1793807121 → 1.84.2-canary.openbot-intel-fixes

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 (248) hide show
  1. package/README.md +1 -1
  2. package/dist/a2ui-catalog-schema.cjs +14 -5
  3. package/dist/a2ui-catalog-schema.cjs.map +1 -1
  4. package/dist/a2ui-catalog-schema.d.cts +4 -2
  5. package/dist/a2ui-catalog-schema.d.cts.map +1 -1
  6. package/dist/a2ui-catalog-schema.d.mts +4 -2
  7. package/dist/a2ui-catalog-schema.d.mts.map +1 -1
  8. package/dist/a2ui-catalog-schema.mjs +14 -5
  9. package/dist/a2ui-catalog-schema.mjs.map +1 -1
  10. package/dist/event-transforms/open-generative-ui-middleware.cjs +7 -6
  11. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +1 -1
  12. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +1 -1
  13. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +1 -1
  14. package/dist/event-transforms/open-generative-ui-middleware.mjs +7 -6
  15. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +1 -1
  16. package/dist/generative-ui/catalog/catalog-export.cjs +329 -0
  17. package/dist/generative-ui/catalog/catalog-export.cjs.map +1 -0
  18. package/dist/generative-ui/catalog/catalog-export.d.cts +92 -0
  19. package/dist/generative-ui/catalog/catalog-export.d.cts.map +1 -0
  20. package/dist/generative-ui/catalog/catalog-export.d.mts +92 -0
  21. package/dist/generative-ui/catalog/catalog-export.d.mts.map +1 -0
  22. package/dist/generative-ui/catalog/catalog-export.mjs +328 -0
  23. package/dist/generative-ui/catalog/catalog-export.mjs.map +1 -0
  24. package/dist/generative-ui/catalog/catalog.cjs +314 -0
  25. package/dist/generative-ui/catalog/catalog.cjs.map +1 -0
  26. package/dist/generative-ui/catalog/catalog.d.cts +407 -0
  27. package/dist/generative-ui/catalog/catalog.d.cts.map +1 -0
  28. package/dist/generative-ui/catalog/catalog.d.mts +407 -0
  29. package/dist/generative-ui/catalog/catalog.d.mts.map +1 -0
  30. package/dist/generative-ui/catalog/catalog.mjs +311 -0
  31. package/dist/generative-ui/catalog/catalog.mjs.map +1 -0
  32. package/dist/generative-ui/catalog/errors.cjs +13 -0
  33. package/dist/generative-ui/catalog/errors.cjs.map +1 -0
  34. package/dist/generative-ui/catalog/errors.d.cts +46 -0
  35. package/dist/generative-ui/catalog/errors.d.cts.map +1 -0
  36. package/dist/generative-ui/catalog/errors.d.mts +46 -0
  37. package/dist/generative-ui/catalog/errors.d.mts.map +1 -0
  38. package/dist/generative-ui/catalog/errors.mjs +12 -0
  39. package/dist/generative-ui/catalog/errors.mjs.map +1 -0
  40. package/dist/generative-ui/catalog/index.d.mts +6 -0
  41. package/dist/generative-ui/catalog/json-schema.cjs +19 -0
  42. package/dist/generative-ui/catalog/json-schema.cjs.map +1 -0
  43. package/dist/generative-ui/catalog/json-schema.d.cts +13 -0
  44. package/dist/generative-ui/catalog/json-schema.d.cts.map +1 -0
  45. package/dist/generative-ui/catalog/json-schema.d.mts +13 -0
  46. package/dist/generative-ui/catalog/json-schema.d.mts.map +1 -0
  47. package/dist/generative-ui/catalog/json-schema.mjs +18 -0
  48. package/dist/generative-ui/catalog/json-schema.mjs.map +1 -0
  49. package/dist/generative-ui/catalog/refs.cjs +20 -0
  50. package/dist/generative-ui/catalog/refs.cjs.map +1 -0
  51. package/dist/generative-ui/catalog/refs.d.cts +54 -0
  52. package/dist/generative-ui/catalog/refs.d.cts.map +1 -0
  53. package/dist/generative-ui/catalog/refs.d.mts +54 -0
  54. package/dist/generative-ui/catalog/refs.d.mts.map +1 -0
  55. package/dist/generative-ui/catalog/refs.mjs +18 -0
  56. package/dist/generative-ui/catalog/refs.mjs.map +1 -0
  57. package/dist/generative-ui/catalog/schema.cjs +74 -0
  58. package/dist/generative-ui/catalog/schema.cjs.map +1 -0
  59. package/dist/generative-ui/catalog/schema.d.cts +43 -0
  60. package/dist/generative-ui/catalog/schema.d.cts.map +1 -0
  61. package/dist/generative-ui/catalog/schema.d.mts +43 -0
  62. package/dist/generative-ui/catalog/schema.d.mts.map +1 -0
  63. package/dist/generative-ui/catalog/schema.mjs +68 -0
  64. package/dist/generative-ui/catalog/schema.mjs.map +1 -0
  65. package/dist/generative-ui/index.cjs +247 -0
  66. package/dist/generative-ui/index.d.cts +33 -0
  67. package/dist/generative-ui/index.d.mts +35 -0
  68. package/dist/generative-ui/index.mjs +34 -0
  69. package/dist/generative-ui/is-record.cjs +6 -1
  70. package/dist/generative-ui/is-record.cjs.map +1 -1
  71. package/dist/generative-ui/is-record.d.cts +6 -0
  72. package/dist/generative-ui/is-record.d.cts.map +1 -0
  73. package/dist/generative-ui/is-record.d.mts +6 -0
  74. package/dist/generative-ui/is-record.d.mts.map +1 -0
  75. package/dist/generative-ui/is-record.mjs +6 -2
  76. package/dist/generative-ui/is-record.mjs.map +1 -1
  77. package/dist/generative-ui/standard/chart.cjs +56 -0
  78. package/dist/generative-ui/standard/chart.cjs.map +1 -0
  79. package/dist/generative-ui/standard/chart.d.cts +142 -0
  80. package/dist/generative-ui/standard/chart.d.cts.map +1 -0
  81. package/dist/generative-ui/standard/chart.d.mts +142 -0
  82. package/dist/generative-ui/standard/chart.d.mts.map +1 -0
  83. package/dist/generative-ui/standard/chart.mjs +54 -0
  84. package/dist/generative-ui/standard/chart.mjs.map +1 -0
  85. package/dist/generative-ui/standard/checks.cjs +74 -0
  86. package/dist/generative-ui/standard/checks.cjs.map +1 -0
  87. package/dist/generative-ui/standard/checks.d.cts +74 -0
  88. package/dist/generative-ui/standard/checks.d.cts.map +1 -0
  89. package/dist/generative-ui/standard/checks.d.mts +74 -0
  90. package/dist/generative-ui/standard/checks.d.mts.map +1 -0
  91. package/dist/generative-ui/standard/checks.mjs +71 -0
  92. package/dist/generative-ui/standard/checks.mjs.map +1 -0
  93. package/dist/generative-ui/standard/components.cjs +23 -0
  94. package/dist/generative-ui/standard/components.cjs.map +1 -0
  95. package/dist/generative-ui/standard/components.d.cts +24 -0
  96. package/dist/generative-ui/standard/components.d.cts.map +1 -0
  97. package/dist/generative-ui/standard/components.d.mts +24 -0
  98. package/dist/generative-ui/standard/components.d.mts.map +1 -0
  99. package/dist/generative-ui/standard/components.mjs +22 -0
  100. package/dist/generative-ui/standard/components.mjs.map +1 -0
  101. package/dist/generative-ui/standard/composites.cjs +143 -0
  102. package/dist/generative-ui/standard/composites.cjs.map +1 -0
  103. package/dist/generative-ui/standard/composites.d.cts +500 -0
  104. package/dist/generative-ui/standard/composites.d.cts.map +1 -0
  105. package/dist/generative-ui/standard/composites.d.mts +500 -0
  106. package/dist/generative-ui/standard/composites.d.mts.map +1 -0
  107. package/dist/generative-ui/standard/composites.mjs +132 -0
  108. package/dist/generative-ui/standard/composites.mjs.map +1 -0
  109. package/dist/generative-ui/standard/data.cjs +176 -0
  110. package/dist/generative-ui/standard/data.cjs.map +1 -0
  111. package/dist/generative-ui/standard/data.d.cts +745 -0
  112. package/dist/generative-ui/standard/data.d.cts.map +1 -0
  113. package/dist/generative-ui/standard/data.d.mts +745 -0
  114. package/dist/generative-ui/standard/data.d.mts.map +1 -0
  115. package/dist/generative-ui/standard/data.mjs +167 -0
  116. package/dist/generative-ui/standard/data.mjs.map +1 -0
  117. package/dist/generative-ui/standard/declarations.cjs +40 -0
  118. package/dist/generative-ui/standard/declarations.cjs.map +1 -0
  119. package/dist/generative-ui/standard/declarations.d.cts +4604 -0
  120. package/dist/generative-ui/standard/declarations.d.cts.map +1 -0
  121. package/dist/generative-ui/standard/declarations.d.mts +4605 -0
  122. package/dist/generative-ui/standard/declarations.d.mts.map +1 -0
  123. package/dist/generative-ui/standard/declarations.mjs +39 -0
  124. package/dist/generative-ui/standard/declarations.mjs.map +1 -0
  125. package/dist/generative-ui/standard/feedback.cjs +97 -0
  126. package/dist/generative-ui/standard/feedback.cjs.map +1 -0
  127. package/dist/generative-ui/standard/feedback.d.cts +227 -0
  128. package/dist/generative-ui/standard/feedback.d.cts.map +1 -0
  129. package/dist/generative-ui/standard/feedback.d.mts +227 -0
  130. package/dist/generative-ui/standard/feedback.d.mts.map +1 -0
  131. package/dist/generative-ui/standard/feedback.mjs +90 -0
  132. package/dist/generative-ui/standard/feedback.mjs.map +1 -0
  133. package/dist/generative-ui/standard/index.d.mts +16 -0
  134. package/dist/generative-ui/standard/inputs.cjs +333 -0
  135. package/dist/generative-ui/standard/inputs.cjs.map +1 -0
  136. package/dist/generative-ui/standard/inputs.d.cts +2658 -0
  137. package/dist/generative-ui/standard/inputs.d.cts.map +1 -0
  138. package/dist/generative-ui/standard/inputs.d.mts +2658 -0
  139. package/dist/generative-ui/standard/inputs.d.mts.map +1 -0
  140. package/dist/generative-ui/standard/inputs.mjs +318 -0
  141. package/dist/generative-ui/standard/inputs.mjs.map +1 -0
  142. package/dist/generative-ui/standard/layout.cjs +289 -0
  143. package/dist/generative-ui/standard/layout.cjs.map +1 -0
  144. package/dist/generative-ui/standard/layout.d.cts +2854 -0
  145. package/dist/generative-ui/standard/layout.d.cts.map +1 -0
  146. package/dist/generative-ui/standard/layout.d.mts +2854 -0
  147. package/dist/generative-ui/standard/layout.d.mts.map +1 -0
  148. package/dist/generative-ui/standard/layout.mjs +269 -0
  149. package/dist/generative-ui/standard/layout.mjs.map +1 -0
  150. package/dist/generative-ui/standard/map.cjs +27 -0
  151. package/dist/generative-ui/standard/map.cjs.map +1 -0
  152. package/dist/generative-ui/standard/map.d.cts +93 -0
  153. package/dist/generative-ui/standard/map.d.cts.map +1 -0
  154. package/dist/generative-ui/standard/map.d.mts +93 -0
  155. package/dist/generative-ui/standard/map.d.mts.map +1 -0
  156. package/dist/generative-ui/standard/map.mjs +25 -0
  157. package/dist/generative-ui/standard/map.mjs.map +1 -0
  158. package/dist/generative-ui/standard/media.cjs +215 -0
  159. package/dist/generative-ui/standard/media.cjs.map +1 -0
  160. package/dist/generative-ui/standard/media.d.cts +968 -0
  161. package/dist/generative-ui/standard/media.d.cts.map +1 -0
  162. package/dist/generative-ui/standard/media.d.mts +968 -0
  163. package/dist/generative-ui/standard/media.d.mts.map +1 -0
  164. package/dist/generative-ui/standard/media.mjs +205 -0
  165. package/dist/generative-ui/standard/media.mjs.map +1 -0
  166. package/dist/generative-ui/standard/parameter-order.cjs +231 -0
  167. package/dist/generative-ui/standard/parameter-order.cjs.map +1 -0
  168. package/dist/generative-ui/standard/parameter-order.d.cts +84 -0
  169. package/dist/generative-ui/standard/parameter-order.d.cts.map +1 -0
  170. package/dist/generative-ui/standard/parameter-order.d.mts +84 -0
  171. package/dist/generative-ui/standard/parameter-order.d.mts.map +1 -0
  172. package/dist/generative-ui/standard/parameter-order.mjs +230 -0
  173. package/dist/generative-ui/standard/parameter-order.mjs.map +1 -0
  174. package/dist/generative-ui/standard/styles.cjs +62 -0
  175. package/dist/generative-ui/standard/styles.cjs.map +1 -0
  176. package/dist/generative-ui/standard/styles.d.cts +17 -0
  177. package/dist/generative-ui/standard/styles.d.cts.map +1 -0
  178. package/dist/generative-ui/standard/styles.d.mts +17 -0
  179. package/dist/generative-ui/standard/styles.d.mts.map +1 -0
  180. package/dist/generative-ui/standard/styles.mjs +60 -0
  181. package/dist/generative-ui/standard/styles.mjs.map +1 -0
  182. package/dist/generative-ui/standard/text.cjs +226 -0
  183. package/dist/generative-ui/standard/text.cjs.map +1 -0
  184. package/dist/generative-ui/standard/text.d.cts +687 -0
  185. package/dist/generative-ui/standard/text.d.cts.map +1 -0
  186. package/dist/generative-ui/standard/text.d.mts +687 -0
  187. package/dist/generative-ui/standard/text.d.mts.map +1 -0
  188. package/dist/generative-ui/standard/text.mjs +209 -0
  189. package/dist/generative-ui/standard/text.mjs.map +1 -0
  190. package/dist/generative-ui/standard/theme.cjs +115 -0
  191. package/dist/generative-ui/standard/theme.cjs.map +1 -0
  192. package/dist/generative-ui/standard/theme.d.cts +60 -0
  193. package/dist/generative-ui/standard/theme.d.cts.map +1 -0
  194. package/dist/generative-ui/standard/theme.d.mts +60 -0
  195. package/dist/generative-ui/standard/theme.d.mts.map +1 -0
  196. package/dist/generative-ui/standard/theme.mjs +112 -0
  197. package/dist/generative-ui/standard/theme.mjs.map +1 -0
  198. package/dist/generative-ui/standard/tokens.cjs +336 -0
  199. package/dist/generative-ui/standard/tokens.cjs.map +1 -0
  200. package/dist/generative-ui/standard/tokens.d.cts +76 -0
  201. package/dist/generative-ui/standard/tokens.d.cts.map +1 -0
  202. package/dist/generative-ui/standard/tokens.d.mts +76 -0
  203. package/dist/generative-ui/standard/tokens.d.mts.map +1 -0
  204. package/dist/generative-ui/standard/tokens.mjs +305 -0
  205. package/dist/generative-ui/standard/tokens.mjs.map +1 -0
  206. package/dist/index.cjs.map +1 -1
  207. package/dist/index.d.cts +10 -10
  208. package/dist/index.d.mts +10 -10
  209. package/dist/index.mjs.map +1 -1
  210. package/dist/index.umd.js +16 -7
  211. package/dist/index.umd.js.map +1 -1
  212. package/dist/package.cjs +1 -1
  213. package/dist/package.mjs +1 -1
  214. package/package.json +7 -3
  215. package/src/__tests__/a2ui-catalog-schema.test.ts +26 -0
  216. package/src/a2ui-catalog-schema.ts +14 -5
  217. package/src/event-transforms/open-generative-ui-middleware.ts +19 -10
  218. package/src/generative-ui/base.ts +9 -0
  219. package/src/generative-ui/catalog/catalog-export.ts +478 -0
  220. package/src/generative-ui/catalog/catalog.ts +1166 -0
  221. package/src/generative-ui/catalog/errors.ts +102 -0
  222. package/src/generative-ui/catalog/index.ts +6 -0
  223. package/src/generative-ui/catalog/json-schema.ts +23 -0
  224. package/src/generative-ui/catalog/refs.ts +86 -0
  225. package/src/generative-ui/catalog/schema.ts +107 -0
  226. package/src/generative-ui/index.ts +7 -0
  227. package/src/generative-ui/is-record.ts +6 -1
  228. package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
  229. package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
  230. package/src/generative-ui/standard/chart.ts +79 -0
  231. package/src/generative-ui/standard/checks.ts +98 -0
  232. package/src/generative-ui/standard/components.ts +35 -0
  233. package/src/generative-ui/standard/composites.ts +158 -0
  234. package/src/generative-ui/standard/data.ts +213 -0
  235. package/src/generative-ui/standard/declarations.ts +57 -0
  236. package/src/generative-ui/standard/feedback.ts +105 -0
  237. package/src/generative-ui/standard/index.ts +19 -0
  238. package/src/generative-ui/standard/inputs.ts +423 -0
  239. package/src/generative-ui/standard/layout.ts +312 -0
  240. package/src/generative-ui/standard/map.ts +32 -0
  241. package/src/generative-ui/standard/media.ts +265 -0
  242. package/src/generative-ui/standard/parameter-order.ts +155 -0
  243. package/src/generative-ui/standard/styles.ts +79 -0
  244. package/src/generative-ui/standard/text.ts +210 -0
  245. package/src/generative-ui/standard/theme.ts +198 -0
  246. package/src/generative-ui/standard/tokens.ts +317 -0
  247. package/src/index.ts +1 -1
  248. package/tsdown.config.ts +1 -0
@@ -0,0 +1,102 @@
1
+ import type {
2
+ GenerativeUI,
3
+ GenerativeUIDefinitionsOf,
4
+ GenerativeUIEventInput,
5
+ UnionToIntersection,
6
+ } from "./catalog";
7
+
8
+ export type GenerativeUIErrorCode =
9
+ | "function_not_found"
10
+ | "function_conflict"
11
+ | "invalid_arguments"
12
+ | "handler_failed"
13
+ | "invalid_event_args"
14
+ | "event_forward_failed"
15
+ /** A function value or check could not be computed. */
16
+ | "expression_error"
17
+ /** A function the caller may not call: `openUrl` from the agent. */
18
+ | "invalid_function_call"
19
+ /** An event arrived while the agent was running: it was not sent. */
20
+ | "agent_busy";
21
+
22
+ export class GenerativeUIError extends Error {
23
+ readonly code: GenerativeUIErrorCode;
24
+ constructor(code: GenerativeUIErrorCode, message: string) {
25
+ super(message);
26
+ this.name = "GenerativeUIError";
27
+ this.code = code;
28
+ }
29
+ }
30
+
31
+ export type GenerativeUIInvokeResult =
32
+ | { ok: true; result: unknown }
33
+ | { ok: false; error: GenerativeUIError };
34
+
35
+ type Components<UI extends GenerativeUI<any>> =
36
+ GenerativeUIDefinitionsOf<UI>["components"];
37
+
38
+ type EventsOf<
39
+ UI extends GenerativeUI<any>,
40
+ Component extends keyof Components<UI>,
41
+ > =
42
+ Components<UI>[Component]["events"] extends Record<string, unknown>
43
+ ? Components<UI>[Component]["events"]
44
+ : {};
45
+
46
+ type IsUnion<T, U = T> = T extends unknown
47
+ ? [U] extends [T]
48
+ ? false
49
+ : true
50
+ : never;
51
+
52
+ /** One member of a union. Used only after IsUnion proved the members equal. */
53
+ type OneOf<U> =
54
+ UnionToIntersection<U extends unknown ? () => U : never> extends () => infer R
55
+ ? R
56
+ : never;
57
+
58
+ /** Every event name that a component of the UI declares, bases included. */
59
+ export type GenerativeUIEventName<UI extends GenerativeUI<any>> = {
60
+ [Component in keyof Components<UI>]: keyof EventsOf<UI, Component> & string;
61
+ }[keyof Components<UI>];
62
+
63
+ type EventArgs<UI extends GenerativeUI<any>, Name extends string> = {
64
+ [Component in keyof Components<UI>]: Name extends keyof EventsOf<
65
+ UI,
66
+ Component
67
+ >
68
+ ? GenerativeUIEventInput<
69
+ Name,
70
+ EventsOf<UI, Component>[Name],
71
+ GenerativeUIDefinitionsOf<UI>["functions"]
72
+ >
73
+ : never;
74
+ }[keyof Components<UI>];
75
+
76
+ /**
77
+ * Type of an event prop as seen by a component, looked up by event name in
78
+ * the generative UI that renders the component:
79
+ * `onSubmit?: GenerativeUIEventHandler<typeof ui, "onSubmit">`.
80
+ *
81
+ * The argument is the event `parameters` input. A matched event without
82
+ * `parameters` takes the input of its function.
83
+ *
84
+ * When components of the UI declare the event with different arguments, the
85
+ * result is not callable and names the conflict.
86
+ */
87
+ export type GenerativeUIEventHandler<
88
+ UI extends GenerativeUI<any>,
89
+ Name extends GenerativeUIEventName<UI>,
90
+ > =
91
+ true extends IsUnion<EventArgs<UI, Name>>
92
+ ? {
93
+ readonly error: `"${Name}" has different parameters on different components of this generative UI`;
94
+ }
95
+ : (args: OneOf<EventArgs<UI, Name>>) => Promise<GenerativeUIInvokeResult>;
96
+
97
+ export interface GenerativeUIErrorInfo {
98
+ kind: "render" | "props" | "operation" | "function" | "event";
99
+ surfaceId: string;
100
+ componentId?: string;
101
+ error: Error;
102
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./schema";
2
+ export * from "./json-schema";
3
+ export * from "./refs";
4
+ export * from "./errors";
5
+ export * from "./catalog";
6
+ export * from "./catalog-export";
@@ -0,0 +1,23 @@
1
+ import { schemaToJsonSchema } from "../../standard-schema";
2
+ import { applyChildRefMarks } from "../base";
3
+ import type { StandardSchemaV1 } from "../../standard-schema";
4
+ import type { GenerativeUIJSONSchema } from "../base";
5
+ import { zodToJsonSchema } from "zod-to-json-schema";
6
+
7
+ /**
8
+ * JSON Schema for a Standard Schema (zod v3 via zod-to-json-schema),
9
+ * inlined, no `$schema`. A prop marked by `child()` or `childList()`
10
+ * becomes an A2UI `$ref` to `ComponentId` or `ChildList`.
11
+ */
12
+ export function toJsonSchema(schema: StandardSchemaV1): GenerativeUIJSONSchema {
13
+ const json = schemaToJsonSchema(schema, {
14
+ // The cast through the parameter type keeps TypeScript from expanding
15
+ // the zod type, which is "excessively deep" in this package.
16
+ zodToJsonSchema: (s: unknown) =>
17
+ zodToJsonSchema(s as Parameters<typeof zodToJsonSchema>[0], {
18
+ $refStrategy: "none",
19
+ }) as Record<string, unknown>,
20
+ });
21
+ const { $schema: _omit, ...rest } = json as Record<string, unknown>;
22
+ return applyChildRefMarks(rest);
23
+ }
@@ -0,0 +1,86 @@
1
+ import { z } from "zod";
2
+ import { A2UI_CHILD_LIST_MARK, A2UI_COMPONENT_ID_MARK } from "../base";
3
+
4
+ /**
5
+ * Schema helpers that mark a prop as a component reference, the way A2UI
6
+ * 1.0 marks it with the `ComponentId` and `ChildList` common types. The
7
+ * engine finds every marked prop in the props schema, at any depth, renders
8
+ * the referenced components, and hands the component the rendered nodes in
9
+ * place of the ids. The model sees the prop as `componentId` or as a list
10
+ * of ids or a template.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const tabsSchema = z.object({
15
+ * tabs: z.array(z.object({ title: z.string(), child: child() })),
16
+ * });
17
+ * // A React component gets `tabs: { title: string; child: ReactNode }[]`.
18
+ * ```
19
+ *
20
+ * `TNode` is the type of a rendered child in the framework that renders the
21
+ * UI. Each framework package exports `child` and `childList` with it set.
22
+ * Without it, the output is `GenerativeUIChildNode`, which
23
+ * `GenerativeUIComponentProps` replaces with the node type of the framework.
24
+ */
25
+
26
+ declare const childNodeBrand: unique symbol;
27
+
28
+ /**
29
+ * A rendered child in a framework-free schema. `GenerativeUIComponentProps`
30
+ * replaces it with the node type that the framework passes.
31
+ */
32
+ export interface GenerativeUIChildNode {
33
+ readonly [childNodeBrand]: true;
34
+ }
35
+
36
+ type ChildSchema<TNode> = z.ZodEffects<z.ZodString, TNode, string>;
37
+ type ChildListSchema<TNode> = z.ZodEffects<
38
+ z.ZodUnion<
39
+ [
40
+ z.ZodArray<z.ZodString>,
41
+ z.ZodObject<{ componentId: z.ZodString; path: z.ZodString }>,
42
+ ]
43
+ >,
44
+ TNode
45
+ >;
46
+
47
+ // Without a type argument, `child()` gives `GenerativeUIChildNode`. A
48
+ // generic default is not enough: inside `z.object({ ... })`, TypeScript
49
+ // would infer `TNode` from the shape and give `any`.
50
+
51
+ const mark = (prefix: string, description: string | undefined) =>
52
+ description ? `${prefix} ${description}` : prefix;
53
+
54
+ /**
55
+ * One component id. The component receives the rendered child. Pass the
56
+ * description here, not with `.describe()`, which would replace the mark.
57
+ */
58
+ export function child(description?: string): ChildSchema<GenerativeUIChildNode>;
59
+ export function child<TNode>(description?: string): ChildSchema<TNode>;
60
+ export function child(description?: string): ChildSchema<unknown> {
61
+ return z
62
+ .string()
63
+ .min(1)
64
+ .describe(mark(A2UI_COMPONENT_ID_MARK, description))
65
+ .transform((value) => value as unknown);
66
+ }
67
+
68
+ /**
69
+ * A list of component ids, or a template `{ componentId, path }` that
70
+ * repeats one component for each item of the list at `path`. The
71
+ * component receives the rendered children. Pass the description here,
72
+ * not with `.describe()`.
73
+ */
74
+ export function childList(
75
+ description?: string,
76
+ ): ChildListSchema<GenerativeUIChildNode>;
77
+ export function childList<TNode>(description?: string): ChildListSchema<TNode>;
78
+ export function childList(description?: string): ChildListSchema<unknown> {
79
+ return z
80
+ .union([
81
+ z.array(z.string().min(1)),
82
+ z.object({ componentId: z.string().min(1), path: z.string().min(1) }),
83
+ ])
84
+ .describe(mark(A2UI_CHILD_LIST_MARK, description))
85
+ .transform((value) => value as unknown);
86
+ }
@@ -0,0 +1,107 @@
1
+ import type { StandardSchemaV1 } from "../../standard-schema";
2
+
3
+ /** Any Standard Schema: zod, Valibot, ArkType, and more. */
4
+ export type GenerativeUISchema = StandardSchemaV1;
5
+
6
+ /** The output type of a schema: what validation gives back. */
7
+ export type SchemaOutput<Schema> =
8
+ Schema extends StandardSchemaV1<any, infer Output> ? Output : never;
9
+
10
+ /** The input type of a schema: what validation takes. */
11
+ export type SchemaInput<Schema> =
12
+ Schema extends StandardSchemaV1<infer Input, any> ? Input : never;
13
+
14
+ export type ValidationResult =
15
+ | { success: true; data: unknown }
16
+ | { success: false; issues: readonly StandardSchemaV1.Issue[] };
17
+
18
+ const ASYNC_ISSUE: StandardSchemaV1.Issue = {
19
+ message:
20
+ "the schema validates asynchronously; component props and state need a schema that validates synchronously",
21
+ };
22
+
23
+ function toResult(result: StandardSchemaV1.Result<unknown>): ValidationResult {
24
+ return result.issues
25
+ ? { success: false, issues: result.issues }
26
+ : { success: true, data: result.value };
27
+ }
28
+
29
+ /**
30
+ * Validates `value` with `schema`. The result comes back at once when the
31
+ * schema validates synchronously, else as a promise.
32
+ */
33
+ export function validateSchema(
34
+ schema: StandardSchemaV1,
35
+ value: unknown,
36
+ ): ValidationResult | Promise<ValidationResult> {
37
+ const result = schema["~standard"].validate(value);
38
+ return result instanceof Promise ? result.then(toResult) : toResult(result);
39
+ }
40
+
41
+ /**
42
+ * Validates `value` synchronously, for code that runs during render. A
43
+ * schema that validates asynchronously fails with an issue that says so.
44
+ */
45
+ export function validateSchemaSync(
46
+ schema: StandardSchemaV1,
47
+ value: unknown,
48
+ ): ValidationResult {
49
+ const result = validateSchema(schema, value);
50
+ if (!(result instanceof Promise)) return result;
51
+ // ponytail: the async result is dropped, because render cannot wait for it.
52
+ result.catch(() => {});
53
+ return { success: false, issues: [ASYNC_ISSUE] };
54
+ }
55
+
56
+ /** True for the issue that `validateSchemaSync` gives for an async schema. */
57
+ export function isAsyncIssue(issue: StandardSchemaV1.Issue) {
58
+ return issue === ASYNC_ISSUE;
59
+ }
60
+
61
+ /** The first key of an issue path: the prop the issue is about. */
62
+ export function issueKey(issue: StandardSchemaV1.Issue) {
63
+ const first = issue.path?.[0];
64
+ const key = typeof first === "object" ? first.key : first;
65
+ return key === undefined ? undefined : String(key);
66
+ }
67
+
68
+ /**
69
+ * `props` without the top-level props whose `null` the schema rejected, or
70
+ * `undefined` when there are none. A model writes `null` for "not set" (an
71
+ * empty selection, a value it has not filled yet), and A2UI deletes a data
72
+ * model key that is set to `null`, so a rejected `null` is read as an unset
73
+ * prop. A prop whose schema accepts `null` keeps it.
74
+ */
75
+ export function withoutRejectedNulls(
76
+ props: Record<string, unknown>,
77
+ issues: readonly StandardSchemaV1.Issue[],
78
+ ): Record<string, unknown> | undefined {
79
+ const rejected = new Set<string>();
80
+ for (const issue of issues) {
81
+ const key = issueKey(issue);
82
+ if (key !== undefined && issue.path?.length === 1 && props[key] === null) {
83
+ rejected.add(key);
84
+ }
85
+ }
86
+ if (rejected.size === 0) return undefined;
87
+ return Object.fromEntries(
88
+ Object.entries(props).filter(([key]) => !rejected.has(key)),
89
+ );
90
+ }
91
+
92
+ /** `"a.b: message; c: message"`. A path-less issue gets `fallback`. */
93
+ export function formatIssues(
94
+ issues: readonly StandardSchemaV1.Issue[],
95
+ fallback = "props",
96
+ ) {
97
+ return issues
98
+ .map((issue) => {
99
+ const path = (issue.path ?? [])
100
+ .map((segment) =>
101
+ String(typeof segment === "object" ? segment.key : segment),
102
+ )
103
+ .join(".");
104
+ return `${path || fallback}: ${issue.message}`;
105
+ })
106
+ .join("; ");
107
+ }
@@ -1,3 +1,7 @@
1
+ // The `@copilotkit/shared/generative-ui` entry: the framework-free part of
2
+ // generative UI. The framework packages (`@copilotkit/react-core`,
3
+ // `@copilotkit/angular`) build their generative UI on it. The A2UI protocol
4
+ // types stay on the package root, in `./base`.
1
5
  export * from "./types";
2
6
  export * from "./validate-operation";
3
7
  export * from "./render-ui-args";
@@ -7,3 +11,6 @@ export * from "./prompt";
7
11
  export { buildCompactGenerativeUISchema } from "./compact-schema";
8
12
  export * from "./prompt-spec";
9
13
  export * from "./schema-render";
14
+ export * from "./catalog";
15
+ export * from "./standard";
16
+ export { isRecord } from "./is-record";
@@ -1,4 +1,9 @@
1
- /** True for a plain object: not null, not an array. Internal, not exported. */
1
+ /** True for a plain object: not null, not an array. */
2
2
  export function isRecord(value: unknown): value is Record<string, unknown> {
3
3
  return typeof value === "object" && value !== null && !Array.isArray(value);
4
4
  }
5
+
6
+ /** `Object.hasOwn`, which the ES2017 lib of this package does not type. */
7
+ export function hasOwnKey(value: object, key: PropertyKey): boolean {
8
+ return Object.prototype.hasOwnProperty.call(value, key);
9
+ }
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { DARK_THEME_CSS, themeStyleSheet } from "../theme";
3
+ import type { GenerativeUITheme } from "../theme";
4
+
5
+ describe("themeStyleSheet", () => {
6
+ it("gives nothing for a theme without variables", () => {
7
+ expect(themeStyleSheet(undefined)).toBeUndefined();
8
+ expect(themeStyleSheet({ mapStyle: "https://x/style" })).toBeUndefined();
9
+ });
10
+
11
+ it("puts top-level values on the themed surface and dark values in dark mode", () => {
12
+ const sheet = themeStyleSheet({
13
+ "--a2ui-color-accent": "#d97706",
14
+ dark: { "--a2ui-color-panel": "#1f2937", mapStyle: "https://x/dark" },
15
+ })!;
16
+ const self = `.a2ui-surface[data-a2ui-theme="${sheet.id}"]`;
17
+ expect(sheet.css).toBe(
18
+ `${self}{--a2ui-color-accent:#d97706}:where(.dark) ${self},${self}:where(.dark){--a2ui-color-panel:#1f2937}`,
19
+ );
20
+ });
21
+
22
+ it("gives the same id for the same theme, and another id for another theme", () => {
23
+ const theme: GenerativeUITheme = { "--a2ui-color-accent": "red" };
24
+ expect(themeStyleSheet(theme)!.id).toBe(themeStyleSheet({ ...theme })!.id);
25
+ expect(themeStyleSheet(theme)!.id).not.toBe(
26
+ themeStyleSheet({ "--a2ui-color-accent": "blue" })!.id,
27
+ );
28
+ });
29
+
30
+ it("leaves out values and names that could break out of the rule", () => {
31
+ const theme = {
32
+ "--a2ui-color-accent": "red}</style><script>alert(1)</script>",
33
+ "--a2ui-color-panel": "#fff;color:red",
34
+ "color: red; --a2ui-x": "#000",
35
+ "--a2ui-color-focus": "#3b9bff",
36
+ } as GenerativeUITheme;
37
+ const sheet = themeStyleSheet(theme)!;
38
+ expect(sheet.css).toBe(
39
+ `.a2ui-surface[data-a2ui-theme="${sheet.id}"]{--a2ui-color-focus:#3b9bff}`,
40
+ );
41
+ });
42
+ });
43
+
44
+ describe("the built-in dark values", () => {
45
+ it("apply under a .dark class, with no specificity, so any theme rule wins", () => {
46
+ expect(
47
+ DARK_THEME_CSS.startsWith(
48
+ ":where(.dark .a2ui-surface,.a2ui-surface.dark){",
49
+ ),
50
+ ).toBe(true);
51
+ expect(DARK_THEME_CSS).toContain("--a2ui-color-surface:#1f1f1f");
52
+ });
53
+ });
54
+
55
+ describe("theme rule strength", () => {
56
+ it("is stronger than an app rule on .a2ui-surface, so theme values win", () => {
57
+ const sheet = themeStyleSheet({ "--a2ui-color-accent": "red" })!;
58
+ // Two classes or attributes: one more than `.a2ui-surface` alone.
59
+ expect(sheet.css.startsWith(".a2ui-surface[data-a2ui-theme=")).toBe(true);
60
+ });
61
+ });
@@ -0,0 +1,139 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ FONT_FAMILY,
4
+ STANDARD_CATALOG_ID,
5
+ TEXT_SIZES,
6
+ TITLE_SIZES,
7
+ backgroundColor,
8
+ borderColor,
9
+ panelBackground,
10
+ radius,
11
+ spacing,
12
+ textColor,
13
+ textFont,
14
+ titleFont,
15
+ } from "../tokens";
16
+ import { STANDARD_CSS } from "../styles";
17
+
18
+ describe("standard tokens", () => {
19
+ it("maps numbers to 4px steps and passes strings through", () => {
20
+ expect(spacing(3)).toBe("calc(var(--spacing, 0.25rem) * 3)");
21
+ expect(spacing("12px")).toBe("12px");
22
+ expect(spacing(undefined)).toBeUndefined();
23
+ });
24
+
25
+ it("maps radius tokens and passes raw values through", () => {
26
+ expect(radius("lg")).toBe("var(--a2ui-radius-lg, 12px)");
27
+ expect(radius("full")).toBe("9999px");
28
+ expect(radius(6)).toBe("6px");
29
+ expect(radius("3px 4px")).toBe("3px 4px");
30
+ expect(radius(undefined)).toBeUndefined();
31
+ });
32
+
33
+ it("maps semantic colors and passes raw CSS through", () => {
34
+ expect(textColor("secondary")).toBe(
35
+ "var(--a2ui-color-text-secondary, #5d5d5d)",
36
+ );
37
+ expect(textColor("#123")).toBe("#123");
38
+ expect(textColor(undefined)).toBeUndefined();
39
+ expect(backgroundColor("surface-secondary")).toBe(
40
+ "var(--a2ui-color-surface-secondary, #f7f7f8)",
41
+ );
42
+ expect(backgroundColor("rebeccapurple")).toBe("rebeccapurple");
43
+ expect(borderColor("subtle")).toBe(
44
+ "var(--a2ui-color-border-subtle, rgba(0, 0, 0, 0.05))",
45
+ );
46
+ expect(borderColor("default")).toBe(
47
+ "var(--a2ui-color-border-default, rgba(0, 0, 0, 0.1))",
48
+ );
49
+ });
50
+
51
+ it("does not read inherited object keys as tokens", () => {
52
+ expect(textColor("constructor")).toBe("constructor");
53
+ expect(radius("toString")).toBe("toString");
54
+ });
55
+
56
+ it("maps background and text tokens to their fallback values", () => {
57
+ expect(backgroundColor("surface")).toBe("var(--a2ui-color-surface, #fff)");
58
+ expect(backgroundColor("surface-soft")).toContain("#fcfcfc");
59
+ expect(backgroundColor("surface-tertiary")).toContain("#ececec");
60
+ expect(backgroundColor("info")).toContain("rgba(0, 104, 188, 0.08)");
61
+ expect(backgroundColor("success-solid")).toContain("#00805d");
62
+ expect(textColor("default")).toContain("#0d0d0d");
63
+ expect(textColor("tertiary")).toContain("#8e8e8e");
64
+ });
65
+
66
+ it("gives a panel in a Card the inner panel fill or a lighter tint", () => {
67
+ expect(panelBackground("surface-soft")).toBe(
68
+ "var(--a2ui-color-panel, rgb(252, 252, 252))",
69
+ );
70
+ expect(panelBackground("danger")).toBe(
71
+ "var(--a2ui-color-danger-soft, rgba(193, 50, 44, 0.06))",
72
+ );
73
+ expect(panelBackground("info-solid")).toBe(
74
+ "var(--a2ui-color-info-solid, #0068bc)",
75
+ );
76
+ expect(panelBackground(undefined)).toBeUndefined();
77
+ });
78
+
79
+ it("has the size lists", () => {
80
+ expect(TITLE_SIZES).toEqual([
81
+ "sm",
82
+ "md",
83
+ "lg",
84
+ "xl",
85
+ "2xl",
86
+ "3xl",
87
+ "4xl",
88
+ "5xl",
89
+ ]);
90
+ expect(TEXT_SIZES).toEqual(["3xs", "2xs", "xs", "sm", "md", "lg"]);
91
+ });
92
+
93
+ it("uses md as the default font size", () => {
94
+ expect(titleFont()).toEqual({
95
+ fontSize: "1em",
96
+ lineHeight: 1.5,
97
+ fontWeight: 600,
98
+ });
99
+ expect(textFont()).toEqual({ fontSize: "1em", lineHeight: 1.625 });
100
+ });
101
+
102
+ it("gives the type scale in em of the host size", () => {
103
+ expect(titleFont("2xl")).toEqual({
104
+ fontSize: "1.5em",
105
+ lineHeight: 1.333,
106
+ fontWeight: 600,
107
+ });
108
+ expect(titleFont("lg").fontSize).toBe("1.125em");
109
+ expect(textFont("sm")).toEqual({ fontSize: ".875em", lineHeight: 1.429 });
110
+ expect(textFont("3xs").fontSize).toBe(".625em");
111
+ expect(textFont("2xs").fontSize).toBe(".6875em");
112
+ expect(textFont("xs").fontSize).toBe(".75em");
113
+ expect(textFont("lg").fontSize).toBe("1.125em");
114
+ expect(FONT_FAMILY).toContain("-apple-system, ui-sans-serif, system-ui");
115
+ });
116
+
117
+ it("lets the surface inherit the typography of the host", () => {
118
+ expect(STANDARD_CSS).toContain(".a2ui-surface{font:inherit;color:inherit}");
119
+ expect(STANDARD_CSS).not.toContain("font-family");
120
+ expect(STANDARD_CSS).toContain(
121
+ ":where(.a2ui-surface) :where(h2){font-size:1.5em;font-weight:600;line-height:1.3}",
122
+ );
123
+ // The list reset belongs to the List component, not to Markdown.
124
+ expect(STANDARD_CSS).not.toMatch(/\.a2ui-surface :is\(ul,ol\)/);
125
+ expect(STANDARD_CSS).toContain(
126
+ '[data-a2ui-row="spaceBetween"]>[data-a2ui-text]:last-child:not(:first-child){text-align:right',
127
+ );
128
+ });
129
+
130
+ it("gives a focusable scroll container a visible focus ring", () => {
131
+ expect(STANDARD_CSS).toContain(
132
+ "[data-a2ui-scroll]:focus-visible{outline:2px solid var(--a2ui-color-focus, #0285ff);outline-offset:2px}",
133
+ );
134
+ });
135
+
136
+ it("uses the documented catalog id", () => {
137
+ expect(STANDARD_CATALOG_ID).toBe("copilotkit/standard@1");
138
+ });
139
+ });
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+
3
+ // ---- Schema ----
4
+
5
+ export const chartSeries = z.union([
6
+ z.string(),
7
+ z.object({
8
+ key: z.string(),
9
+ label: z.string().optional(),
10
+ color: z.string().optional().describe("A text color token or a CSS color"),
11
+ }),
12
+ ]);
13
+ export type ChartSeries = z.output<typeof chartSeries>;
14
+
15
+ export const chartSchema = z.object({
16
+ chartType: z
17
+ .enum(["bar", "line", "area", "scatter", "pie", "donut"])
18
+ .optional()
19
+ .describe('Default "bar"'),
20
+ data: z.array(z.record(z.string(), z.unknown())).optional(),
21
+ xKey: z.string().optional().describe("The field of the category axis"),
22
+ series: z
23
+ .array(chartSeries)
24
+ .optional()
25
+ .describe("Default: every number field except xKey"),
26
+ stacked: z.boolean().optional(),
27
+ layout: z
28
+ .enum(["vertical", "horizontal"])
29
+ .optional()
30
+ .describe(
31
+ '"horizontal" draws the bars from left to right. Default "vertical"',
32
+ ),
33
+ yAxis: z
34
+ .object({
35
+ label: z.string().optional(),
36
+ min: z.number().optional(),
37
+ max: z.number().optional(),
38
+ width: z.number().optional().describe("Pixels"),
39
+ })
40
+ .optional()
41
+ .describe(
42
+ 'Example: {label: "Revenue (USD)", min: 0, max: 100}. In a horizontal chart it is the horizontal axis, and width sets the category axis width',
43
+ ),
44
+ showDots: z.boolean().optional().describe("Point markers on a line or area"),
45
+ barRadius: z
46
+ .number()
47
+ .optional()
48
+ .describe("The corner radius of a bar, in pixels"),
49
+ innerRadius: z
50
+ .union([z.number(), z.string()])
51
+ .optional()
52
+ .describe("Pie and donut"),
53
+ outerRadius: z
54
+ .union([z.number(), z.string()])
55
+ .optional()
56
+ .describe("Pie and donut"),
57
+ startAngle: z.number().optional().describe("Pie and donut. Default 90"),
58
+ endAngle: z.number().optional().describe("Pie and donut. Default -270"),
59
+ cornerRadius: z.number().optional().describe("The corners of a slice"),
60
+ paddingAngle: z.number().optional().describe("The gap between slices"),
61
+ showLabelLines: z
62
+ .boolean()
63
+ .optional()
64
+ .describe("Leader lines of the slice labels. Default true"),
65
+ height: z.number().optional().describe("Pixels. Default 240"),
66
+ showLegend: z.boolean().optional().describe("Default true"),
67
+ showGrid: z.boolean().optional().describe("Default true"),
68
+ showTooltip: z.boolean().optional().describe("Default true"),
69
+ showValueLabels: z.boolean().optional(),
70
+ format: z
71
+ .enum(["number", "currency", "percent"])
72
+ .optional()
73
+ .describe(
74
+ 'With "percent", data values and axis min/max are fractions: 0.4 shows as 40%; for 0% to 10%, use min: 0 and max: 0.1.',
75
+ ),
76
+ currency: z.string().optional().describe('ISO code. Default "USD"'),
77
+ title: z.string().optional(),
78
+ });
79
+ export type ChartProps = z.output<typeof chartSchema>;