@copilotkit/shared 2.0.0-rc.31 → 2.0.0-rc.32

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 (231) hide show
  1. package/README.md +1 -1
  2. package/dist/generative-ui/catalog/catalog-export.cjs +329 -0
  3. package/dist/generative-ui/catalog/catalog-export.cjs.map +1 -0
  4. package/dist/generative-ui/catalog/catalog-export.d.cts +92 -0
  5. package/dist/generative-ui/catalog/catalog-export.d.cts.map +1 -0
  6. package/dist/generative-ui/catalog/catalog-export.d.mts +92 -0
  7. package/dist/generative-ui/catalog/catalog-export.d.mts.map +1 -0
  8. package/dist/generative-ui/catalog/catalog-export.mjs +328 -0
  9. package/dist/generative-ui/catalog/catalog-export.mjs.map +1 -0
  10. package/dist/generative-ui/catalog/catalog.cjs +315 -0
  11. package/dist/generative-ui/catalog/catalog.cjs.map +1 -0
  12. package/dist/generative-ui/catalog/catalog.d.cts +407 -0
  13. package/dist/generative-ui/catalog/catalog.d.cts.map +1 -0
  14. package/dist/generative-ui/catalog/catalog.d.mts +407 -0
  15. package/dist/generative-ui/catalog/catalog.d.mts.map +1 -0
  16. package/dist/generative-ui/catalog/catalog.mjs +312 -0
  17. package/dist/generative-ui/catalog/catalog.mjs.map +1 -0
  18. package/dist/generative-ui/catalog/errors.cjs +13 -0
  19. package/dist/generative-ui/catalog/errors.cjs.map +1 -0
  20. package/dist/generative-ui/catalog/errors.d.cts +46 -0
  21. package/dist/generative-ui/catalog/errors.d.cts.map +1 -0
  22. package/dist/generative-ui/catalog/errors.d.mts +46 -0
  23. package/dist/generative-ui/catalog/errors.d.mts.map +1 -0
  24. package/dist/generative-ui/catalog/errors.mjs +12 -0
  25. package/dist/generative-ui/catalog/errors.mjs.map +1 -0
  26. package/dist/generative-ui/catalog/index.d.mts +6 -0
  27. package/dist/generative-ui/catalog/json-schema.cjs +16 -0
  28. package/dist/generative-ui/catalog/json-schema.cjs.map +1 -0
  29. package/dist/generative-ui/catalog/json-schema.d.cts +12 -0
  30. package/dist/generative-ui/catalog/json-schema.d.cts.map +1 -0
  31. package/dist/generative-ui/catalog/json-schema.d.mts +12 -0
  32. package/dist/generative-ui/catalog/json-schema.d.mts.map +1 -0
  33. package/dist/generative-ui/catalog/json-schema.mjs +16 -0
  34. package/dist/generative-ui/catalog/json-schema.mjs.map +1 -0
  35. package/dist/generative-ui/catalog/refs.cjs +21 -0
  36. package/dist/generative-ui/catalog/refs.cjs.map +1 -0
  37. package/dist/generative-ui/catalog/refs.d.cts +55 -0
  38. package/dist/generative-ui/catalog/refs.d.cts.map +1 -0
  39. package/dist/generative-ui/catalog/refs.d.mts +55 -0
  40. package/dist/generative-ui/catalog/refs.d.mts.map +1 -0
  41. package/dist/generative-ui/catalog/refs.mjs +18 -0
  42. package/dist/generative-ui/catalog/refs.mjs.map +1 -0
  43. package/dist/generative-ui/catalog/schema.cjs +74 -0
  44. package/dist/generative-ui/catalog/schema.cjs.map +1 -0
  45. package/dist/generative-ui/catalog/schema.d.cts +43 -0
  46. package/dist/generative-ui/catalog/schema.d.cts.map +1 -0
  47. package/dist/generative-ui/catalog/schema.d.mts +43 -0
  48. package/dist/generative-ui/catalog/schema.d.mts.map +1 -0
  49. package/dist/generative-ui/catalog/schema.mjs +68 -0
  50. package/dist/generative-ui/catalog/schema.mjs.map +1 -0
  51. package/dist/generative-ui/index.cjs +247 -0
  52. package/dist/generative-ui/index.d.cts +33 -0
  53. package/dist/generative-ui/index.d.mts +35 -0
  54. package/dist/generative-ui/index.mjs +34 -0
  55. package/dist/generative-ui/is-record.cjs +6 -1
  56. package/dist/generative-ui/is-record.cjs.map +1 -1
  57. package/dist/generative-ui/is-record.d.cts +6 -0
  58. package/dist/generative-ui/is-record.d.cts.map +1 -0
  59. package/dist/generative-ui/is-record.d.mts +6 -0
  60. package/dist/generative-ui/is-record.d.mts.map +1 -0
  61. package/dist/generative-ui/is-record.mjs +6 -2
  62. package/dist/generative-ui/is-record.mjs.map +1 -1
  63. package/dist/generative-ui/standard/chart.cjs +56 -0
  64. package/dist/generative-ui/standard/chart.cjs.map +1 -0
  65. package/dist/generative-ui/standard/chart.d.cts +62 -0
  66. package/dist/generative-ui/standard/chart.d.cts.map +1 -0
  67. package/dist/generative-ui/standard/chart.d.mts +62 -0
  68. package/dist/generative-ui/standard/chart.d.mts.map +1 -0
  69. package/dist/generative-ui/standard/chart.mjs +54 -0
  70. package/dist/generative-ui/standard/chart.mjs.map +1 -0
  71. package/dist/generative-ui/standard/checks.cjs +74 -0
  72. package/dist/generative-ui/standard/checks.cjs.map +1 -0
  73. package/dist/generative-ui/standard/checks.d.cts +56 -0
  74. package/dist/generative-ui/standard/checks.d.cts.map +1 -0
  75. package/dist/generative-ui/standard/checks.d.mts +56 -0
  76. package/dist/generative-ui/standard/checks.d.mts.map +1 -0
  77. package/dist/generative-ui/standard/checks.mjs +71 -0
  78. package/dist/generative-ui/standard/checks.mjs.map +1 -0
  79. package/dist/generative-ui/standard/components.cjs +23 -0
  80. package/dist/generative-ui/standard/components.cjs.map +1 -0
  81. package/dist/generative-ui/standard/components.d.cts +24 -0
  82. package/dist/generative-ui/standard/components.d.cts.map +1 -0
  83. package/dist/generative-ui/standard/components.d.mts +24 -0
  84. package/dist/generative-ui/standard/components.d.mts.map +1 -0
  85. package/dist/generative-ui/standard/components.mjs +22 -0
  86. package/dist/generative-ui/standard/components.mjs.map +1 -0
  87. package/dist/generative-ui/standard/composites.cjs +143 -0
  88. package/dist/generative-ui/standard/composites.cjs.map +1 -0
  89. package/dist/generative-ui/standard/composites.d.cts +233 -0
  90. package/dist/generative-ui/standard/composites.d.cts.map +1 -0
  91. package/dist/generative-ui/standard/composites.d.mts +233 -0
  92. package/dist/generative-ui/standard/composites.d.mts.map +1 -0
  93. package/dist/generative-ui/standard/composites.mjs +132 -0
  94. package/dist/generative-ui/standard/composites.mjs.map +1 -0
  95. package/dist/generative-ui/standard/data.cjs +176 -0
  96. package/dist/generative-ui/standard/data.cjs.map +1 -0
  97. package/dist/generative-ui/standard/data.d.cts +365 -0
  98. package/dist/generative-ui/standard/data.d.cts.map +1 -0
  99. package/dist/generative-ui/standard/data.d.mts +365 -0
  100. package/dist/generative-ui/standard/data.d.mts.map +1 -0
  101. package/dist/generative-ui/standard/data.mjs +167 -0
  102. package/dist/generative-ui/standard/data.mjs.map +1 -0
  103. package/dist/generative-ui/standard/declarations.cjs +40 -0
  104. package/dist/generative-ui/standard/declarations.cjs.map +1 -0
  105. package/dist/generative-ui/standard/declarations.d.cts +2570 -0
  106. package/dist/generative-ui/standard/declarations.d.cts.map +1 -0
  107. package/dist/generative-ui/standard/declarations.d.mts +2571 -0
  108. package/dist/generative-ui/standard/declarations.d.mts.map +1 -0
  109. package/dist/generative-ui/standard/declarations.mjs +39 -0
  110. package/dist/generative-ui/standard/declarations.mjs.map +1 -0
  111. package/dist/generative-ui/standard/feedback.cjs +97 -0
  112. package/dist/generative-ui/standard/feedback.cjs.map +1 -0
  113. package/dist/generative-ui/standard/feedback.d.cts +133 -0
  114. package/dist/generative-ui/standard/feedback.d.cts.map +1 -0
  115. package/dist/generative-ui/standard/feedback.d.mts +133 -0
  116. package/dist/generative-ui/standard/feedback.d.mts.map +1 -0
  117. package/dist/generative-ui/standard/feedback.mjs +90 -0
  118. package/dist/generative-ui/standard/feedback.mjs.map +1 -0
  119. package/dist/generative-ui/standard/index.d.mts +16 -0
  120. package/dist/generative-ui/standard/inputs.cjs +333 -0
  121. package/dist/generative-ui/standard/inputs.cjs.map +1 -0
  122. package/dist/generative-ui/standard/inputs.d.cts +1128 -0
  123. package/dist/generative-ui/standard/inputs.d.cts.map +1 -0
  124. package/dist/generative-ui/standard/inputs.d.mts +1128 -0
  125. package/dist/generative-ui/standard/inputs.d.mts.map +1 -0
  126. package/dist/generative-ui/standard/inputs.mjs +318 -0
  127. package/dist/generative-ui/standard/inputs.mjs.map +1 -0
  128. package/dist/generative-ui/standard/layout.cjs +289 -0
  129. package/dist/generative-ui/standard/layout.cjs.map +1 -0
  130. package/dist/generative-ui/standard/layout.d.cts +1974 -0
  131. package/dist/generative-ui/standard/layout.d.cts.map +1 -0
  132. package/dist/generative-ui/standard/layout.d.mts +1975 -0
  133. package/dist/generative-ui/standard/layout.d.mts.map +1 -0
  134. package/dist/generative-ui/standard/layout.mjs +269 -0
  135. package/dist/generative-ui/standard/layout.mjs.map +1 -0
  136. package/dist/generative-ui/standard/map.cjs +27 -0
  137. package/dist/generative-ui/standard/map.cjs.map +1 -0
  138. package/dist/generative-ui/standard/map.d.cts +31 -0
  139. package/dist/generative-ui/standard/map.d.cts.map +1 -0
  140. package/dist/generative-ui/standard/map.d.mts +31 -0
  141. package/dist/generative-ui/standard/map.d.mts.map +1 -0
  142. package/dist/generative-ui/standard/map.mjs +25 -0
  143. package/dist/generative-ui/standard/map.mjs.map +1 -0
  144. package/dist/generative-ui/standard/media.cjs +215 -0
  145. package/dist/generative-ui/standard/media.cjs.map +1 -0
  146. package/dist/generative-ui/standard/media.d.cts +396 -0
  147. package/dist/generative-ui/standard/media.d.cts.map +1 -0
  148. package/dist/generative-ui/standard/media.d.mts +396 -0
  149. package/dist/generative-ui/standard/media.d.mts.map +1 -0
  150. package/dist/generative-ui/standard/media.mjs +205 -0
  151. package/dist/generative-ui/standard/media.mjs.map +1 -0
  152. package/dist/generative-ui/standard/parameter-order.cjs +231 -0
  153. package/dist/generative-ui/standard/parameter-order.cjs.map +1 -0
  154. package/dist/generative-ui/standard/parameter-order.d.cts +84 -0
  155. package/dist/generative-ui/standard/parameter-order.d.cts.map +1 -0
  156. package/dist/generative-ui/standard/parameter-order.d.mts +84 -0
  157. package/dist/generative-ui/standard/parameter-order.d.mts.map +1 -0
  158. package/dist/generative-ui/standard/parameter-order.mjs +230 -0
  159. package/dist/generative-ui/standard/parameter-order.mjs.map +1 -0
  160. package/dist/generative-ui/standard/styles.cjs +62 -0
  161. package/dist/generative-ui/standard/styles.cjs.map +1 -0
  162. package/dist/generative-ui/standard/styles.d.cts +17 -0
  163. package/dist/generative-ui/standard/styles.d.cts.map +1 -0
  164. package/dist/generative-ui/standard/styles.d.mts +17 -0
  165. package/dist/generative-ui/standard/styles.d.mts.map +1 -0
  166. package/dist/generative-ui/standard/styles.mjs +60 -0
  167. package/dist/generative-ui/standard/styles.mjs.map +1 -0
  168. package/dist/generative-ui/standard/text.cjs +226 -0
  169. package/dist/generative-ui/standard/text.cjs.map +1 -0
  170. package/dist/generative-ui/standard/text.d.cts +522 -0
  171. package/dist/generative-ui/standard/text.d.cts.map +1 -0
  172. package/dist/generative-ui/standard/text.d.mts +522 -0
  173. package/dist/generative-ui/standard/text.d.mts.map +1 -0
  174. package/dist/generative-ui/standard/text.mjs +209 -0
  175. package/dist/generative-ui/standard/text.mjs.map +1 -0
  176. package/dist/generative-ui/standard/theme.cjs +115 -0
  177. package/dist/generative-ui/standard/theme.cjs.map +1 -0
  178. package/dist/generative-ui/standard/theme.d.cts +60 -0
  179. package/dist/generative-ui/standard/theme.d.cts.map +1 -0
  180. package/dist/generative-ui/standard/theme.d.mts +60 -0
  181. package/dist/generative-ui/standard/theme.d.mts.map +1 -0
  182. package/dist/generative-ui/standard/theme.mjs +112 -0
  183. package/dist/generative-ui/standard/theme.mjs.map +1 -0
  184. package/dist/generative-ui/standard/tokens.cjs +336 -0
  185. package/dist/generative-ui/standard/tokens.cjs.map +1 -0
  186. package/dist/generative-ui/standard/tokens.d.cts +76 -0
  187. package/dist/generative-ui/standard/tokens.d.cts.map +1 -0
  188. package/dist/generative-ui/standard/tokens.d.mts +76 -0
  189. package/dist/generative-ui/standard/tokens.d.mts.map +1 -0
  190. package/dist/generative-ui/standard/tokens.mjs +305 -0
  191. package/dist/generative-ui/standard/tokens.mjs.map +1 -0
  192. package/dist/index.cjs.map +1 -1
  193. package/dist/index.d.cts +10 -10
  194. package/dist/index.d.mts +10 -10
  195. package/dist/index.mjs.map +1 -1
  196. package/dist/index.umd.js +2 -2
  197. package/dist/index.umd.js.map +1 -1
  198. package/dist/package.cjs +1 -1
  199. package/dist/package.mjs +1 -1
  200. package/package.json +7 -3
  201. package/src/generative-ui/base.ts +9 -0
  202. package/src/generative-ui/catalog/catalog-export.ts +478 -0
  203. package/src/generative-ui/catalog/catalog.ts +1167 -0
  204. package/src/generative-ui/catalog/errors.ts +102 -0
  205. package/src/generative-ui/catalog/index.ts +6 -0
  206. package/src/generative-ui/catalog/json-schema.ts +14 -0
  207. package/src/generative-ui/catalog/refs.ts +87 -0
  208. package/src/generative-ui/catalog/schema.ts +107 -0
  209. package/src/generative-ui/index.ts +7 -0
  210. package/src/generative-ui/is-record.ts +6 -1
  211. package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
  212. package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
  213. package/src/generative-ui/standard/chart.ts +79 -0
  214. package/src/generative-ui/standard/checks.ts +98 -0
  215. package/src/generative-ui/standard/components.ts +35 -0
  216. package/src/generative-ui/standard/composites.ts +158 -0
  217. package/src/generative-ui/standard/data.ts +213 -0
  218. package/src/generative-ui/standard/declarations.ts +57 -0
  219. package/src/generative-ui/standard/feedback.ts +105 -0
  220. package/src/generative-ui/standard/index.ts +19 -0
  221. package/src/generative-ui/standard/inputs.ts +423 -0
  222. package/src/generative-ui/standard/layout.ts +312 -0
  223. package/src/generative-ui/standard/map.ts +32 -0
  224. package/src/generative-ui/standard/media.ts +265 -0
  225. package/src/generative-ui/standard/parameter-order.ts +155 -0
  226. package/src/generative-ui/standard/styles.ts +79 -0
  227. package/src/generative-ui/standard/text.ts +210 -0
  228. package/src/generative-ui/standard/theme.ts +198 -0
  229. package/src/generative-ui/standard/tokens.ts +317 -0
  230. package/src/index.ts +1 -1
  231. package/tsdown.config.ts +1 -1
@@ -0,0 +1,98 @@
1
+ import { z } from "zod";
2
+ import { textColor, textFont } from "./tokens";
3
+
4
+ /**
5
+ * The `checks` of the A2UI 1.0 `Checkable` components. The model writes
6
+ * each condition as a validator call or a boolean binding:
7
+ * `{ "condition": { "@call": "email", "args": { "value": { "@path": "/form/email" } } }, "message": "..." }`.
8
+ * The engine resolves the condition before the component renders, so a
9
+ * component sees a boolean or a `ValidationResult`.
10
+ */
11
+
12
+ const severity = z.enum(["error", "warning", "info"]);
13
+
14
+ const validationResult = z
15
+ .object({
16
+ valid: z.boolean(),
17
+ message: z.string().optional(),
18
+ code: z.string().optional(),
19
+ severity: severity.optional(),
20
+ })
21
+ .loose();
22
+
23
+ /** The first failed check of a control, as the control shows it. */
24
+ export interface FailedCheck {
25
+ message: string;
26
+ /** `"error"` when the result named none. Only an error blocks. */
27
+ severity: z.output<typeof severity>;
28
+ /** The `code` of the validation result, when it had one. */
29
+ code?: string;
30
+ }
31
+
32
+ export const checksProp = z
33
+ .array(
34
+ z.object({
35
+ condition: z
36
+ .union([z.boolean(), validationResult])
37
+ .optional()
38
+ .describe(
39
+ 'A validator call, for example {"@call":"required","args":{"value":{"@path":"/x"}}}, or a boolean binding',
40
+ ),
41
+ message: z
42
+ .string()
43
+ .optional()
44
+ .describe("Shown when the check fails, instead of the default message"),
45
+ }),
46
+ )
47
+ .optional()
48
+ .describe("Validation rules. The control shows the first failed one");
49
+
50
+ export type ResolvedChecks = z.output<typeof checksProp>;
51
+
52
+ /**
53
+ * The failed check to show, or `undefined` when every check passes: the
54
+ * first error, or the first warning or info when no check is an error, so
55
+ * a warning never hides an error that comes after it. A condition that is
56
+ * not known yet (undefined) passes. A `false` condition is an error with
57
+ * the check's message. The check's message also wins over the message of
58
+ * a validator result: the built-in validators always have one, and the
59
+ * check is where the model puts its own wording.
60
+ */
61
+ export function firstFailedCheck(
62
+ checks: ResolvedChecks,
63
+ ): FailedCheck | undefined {
64
+ let first: FailedCheck | undefined;
65
+ for (const check of checks ?? []) {
66
+ const { condition } = check;
67
+ if (condition === undefined || condition === null) continue;
68
+ let failed: FailedCheck;
69
+ if (typeof condition === "boolean") {
70
+ if (condition) continue;
71
+ failed = { message: check.message ?? "Invalid value", severity: "error" };
72
+ } else {
73
+ if (condition.valid) continue;
74
+ failed = {
75
+ message: check.message ?? condition.message ?? "Invalid value",
76
+ severity: condition.severity ?? "error",
77
+ ...(condition.code === undefined ? {} : { code: condition.code }),
78
+ };
79
+ }
80
+ if (failed.severity === "error") return failed;
81
+ first ??= failed;
82
+ }
83
+ return first;
84
+ }
85
+
86
+ /** The style of a check message, by its severity. */
87
+ export function checkMessageStyle(severity: FailedCheck["severity"]) {
88
+ return {
89
+ ...textFont("sm"),
90
+ color: textColor(
91
+ severity === "error"
92
+ ? "danger"
93
+ : severity === "warning"
94
+ ? "warning"
95
+ : "secondary",
96
+ ),
97
+ };
98
+ }
@@ -0,0 +1,35 @@
1
+ import type { GenerativeUIComponentDefinition } from "../catalog/catalog";
2
+
3
+ /**
4
+ * A standard component without its framework component: what the model
5
+ * sees (description, props, events, slots) and how the engine treats it.
6
+ * Each framework adds its own component with `withComponents`.
7
+ */
8
+ export type GenerativeUIComponentDeclaration = Omit<
9
+ GenerativeUIComponentDefinition,
10
+ "component"
11
+ >;
12
+
13
+ /**
14
+ * The definitions of `createGenerativeUI`: each declaration with the
15
+ * component of the same name.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const layoutComponents = withComponents(layoutDeclarations, { Box, Column });
20
+ * ```
21
+ */
22
+ export function withComponents<
23
+ Declarations extends Record<string, GenerativeUIComponentDeclaration>,
24
+ Components extends { [Name in keyof Declarations]: unknown },
25
+ >(declarations: Declarations, components: Components) {
26
+ const definitions: Record<string, unknown> = {};
27
+ for (const name of Object.keys(declarations)) {
28
+ definitions[name] = { ...declarations[name], component: components[name] };
29
+ }
30
+ return definitions as {
31
+ [Name in keyof Declarations]: Declarations[Name] & {
32
+ component: Components[Name];
33
+ };
34
+ };
35
+ }
@@ -0,0 +1,158 @@
1
+ import { z } from "zod";
2
+ import { NO_ARGS, sizeValue } from "./layout";
3
+
4
+ // ---- Schemas ----
5
+
6
+ const text = (description: string) =>
7
+ z.string().optional().describe(description);
8
+
9
+ export const linkCardSchema = z.object({
10
+ href: z.string().describe("The URL (http, https)"),
11
+ title: z.string().describe("The page title"),
12
+ description: text("One or two lines"),
13
+ image: text("A thumbnail URL"),
14
+ domain: text("Shown next to the favicon. Default: the host of href"),
15
+ favicon: z.boolean().optional().describe("Default true"),
16
+ });
17
+ export const citationSchema = z.object({
18
+ index: z.number().optional().describe("The marker number. Default 1"),
19
+ label: text("Marker text instead of the number, for example a domain"),
20
+ title: text("The source title"),
21
+ url: text("The source URL (http, https)"),
22
+ snippet: text("The quoted passage, one or two lines"),
23
+ source: text("The publisher or domain. Default: the host of url"),
24
+ });
25
+ export const followUpItem = z.union([
26
+ z.string(),
27
+ z.object({
28
+ label: z.string(),
29
+ message: text("The text sent when the user clicks. Default: label"),
30
+ }),
31
+ ]);
32
+ export const followUpSchema = z.object({
33
+ items: z.array(followUpItem).optional(),
34
+ title: text("A caption above the pills"),
35
+ });
36
+ export const followUpArgs = z.object({
37
+ message: z.string().describe("The message of the clicked pill"),
38
+ });
39
+ const BADGE_COLORS = [
40
+ "secondary",
41
+ "success",
42
+ "danger",
43
+ "warning",
44
+ "info",
45
+ "discovery",
46
+ ] as const;
47
+ export const cardAction = z.object({
48
+ label: z.string(),
49
+ href: text("Opens this URL in a new tab"),
50
+ variant: z.enum(["solid", "soft", "outline", "ghost"]).optional(),
51
+ });
52
+ export const entityCardSchema = z.object({
53
+ title: z.string().describe("The name"),
54
+ subtitle: text("A second line, for example the brand or category"),
55
+ description: text("Up to three lines"),
56
+ image: text("An image URL"),
57
+ imageAspectRatio: z.string().optional().describe('Default "4 / 3"'),
58
+ meta: text(
59
+ 'A short fact line, for example "$29 / month" or "Open until 22:00"',
60
+ ),
61
+ badge: z
62
+ .object({ label: z.string(), color: z.enum(BADGE_COLORS).optional() })
63
+ .optional(),
64
+ rating: z.number().optional().describe("0 to 5, shown as stars"),
65
+ ratingCount: z.number().optional().describe("The number of ratings"),
66
+ href: text("Opens this URL in a new tab when the user clicks the card"),
67
+ actions: z
68
+ .array(cardAction)
69
+ .max(3)
70
+ .optional()
71
+ .describe(
72
+ "Up to three buttons. A button without href sends onAction with its label",
73
+ ),
74
+ layout: z
75
+ .enum(["vertical", "horizontal"])
76
+ .optional()
77
+ .describe('Default "vertical". "horizontal" puts the image on the left'),
78
+ width: sizeValue.optional(),
79
+ });
80
+ export const entityActionArgs = z.object({
81
+ label: z.string().describe("The label of the clicked button"),
82
+ });
83
+ export const gridImage = z.object({
84
+ url: z.string(),
85
+ description: z.string().optional().describe("What the image shows"),
86
+ caption: z.string().optional(),
87
+ href: text("Opens this URL instead of the full-screen view"),
88
+ });
89
+ export const imageGridSchema = z.object({
90
+ images: z.array(gridImage).optional(),
91
+ columns: z.number().optional().describe("Default 3"),
92
+ aspectRatio: z.string().optional().describe('Default "1 / 1"'),
93
+ gap: sizeValue.optional().describe("Default 2"),
94
+ layout: z
95
+ .enum(["grid", "bento"])
96
+ .optional()
97
+ .describe('Default "grid". "bento" makes the first image twice as large'),
98
+ });
99
+
100
+ /**
101
+ * The standard composite components, without their framework components.
102
+ *
103
+ * - LinkCard and EntityCard open `href`, or send `onClick` when it is bound.
104
+ * - FollowUp sends `onFollowUp` with the message of the pill. Unbound, the
105
+ * engine turns it into a visible user message with that text.
106
+ * - EntityCard buttons without href send `onAction` with their label.
107
+ */
108
+ export const compositeDeclarations = {
109
+ LinkCard: {
110
+ description:
111
+ "A preview of a URL: favicon and domain, title, description, thumbnail. A click opens it in a new tab, or sends onClick when bound. For sources, articles and products with a page.",
112
+ props: linkCardSchema,
113
+ events: {
114
+ onClick: {
115
+ description: "Sent when the user clicks the card, instead of the link.",
116
+ parameters: NO_ARGS,
117
+ },
118
+ },
119
+ },
120
+ Citation: {
121
+ description:
122
+ "An inline source marker ([1]) showing title, snippet and link on hover or click. Put it right after the sentence it supports, as a child of a Text or in a Row.",
123
+ props: citationSchema,
124
+ },
125
+ FollowUp: {
126
+ description:
127
+ "Suggested next prompts as pills; a click sends the pill's message as the user's next turn, no event needed. At the end of a surface, two to four short items.",
128
+ props: followUpSchema,
129
+ events: {
130
+ onFollowUp: {
131
+ description:
132
+ "Sent when the user clicks a pill. The args carry the message of the pill.",
133
+ parameters: followUpArgs,
134
+ },
135
+ },
136
+ },
137
+ EntityCard: {
138
+ description:
139
+ "A card for one product, place, person or listing: image, title, subtitle, description, a price or meta line, badge, rating and up to three buttons. href opens a page; onClick is sent when bound. Use a Grid of them for several things.",
140
+ props: entityCardSchema,
141
+ events: {
142
+ onClick: {
143
+ description: "Sent when the user clicks the card and it has no href.",
144
+ parameters: NO_ARGS,
145
+ },
146
+ onAction: {
147
+ description:
148
+ "Sent when the user clicks a button without href. The args carry the label of the button.",
149
+ parameters: entityActionArgs,
150
+ },
151
+ },
152
+ },
153
+ ImageGrid: {
154
+ description:
155
+ 'A gallery of images in a grid. A click opens the image full-screen, with arrows to the other images. layout "bento" makes the first image twice as large.',
156
+ props: imageGridSchema,
157
+ },
158
+ };
@@ -0,0 +1,213 @@
1
+ import { z } from "zod";
2
+ import { chartSchema } from "./chart";
3
+ import { CHILDREN_SLOT, sizeValue, weightProp } from "./layout";
4
+ import { mapSchema } from "./map";
5
+
6
+ // ---- Schemas ----
7
+
8
+ const cellAlign = z.enum(["start", "center", "end"]).optional();
9
+
10
+ /**
11
+ * A table cell or column header that shows another component. `id` is an
12
+ * alias of `componentId`.
13
+ */
14
+ const tableComponentCell = z.union([
15
+ z.object({ componentId: z.string() }),
16
+ z.object({ id: z.string() }),
17
+ ]);
18
+
19
+ const tableColumn = z.union([
20
+ z.string(),
21
+ z.object({
22
+ label: z.string(),
23
+ align: cellAlign,
24
+ width: sizeValue.optional(),
25
+ componentId: z.string().optional(),
26
+ }),
27
+ tableComponentCell,
28
+ ]);
29
+ export type TableColumn = z.output<typeof tableColumn>;
30
+
31
+ export const tableSchema = z.object({
32
+ caption: z
33
+ .string()
34
+ .optional()
35
+ .describe("A short name of the table for screen readers. It is not shown"),
36
+ columns: z.array(tableColumn).optional().describe("Default []"),
37
+ // A cell is `unknown`, so booleans and null from bound data are valid too.
38
+ rows: z
39
+ .array(z.array(z.unknown()))
40
+ .optional()
41
+ .describe(
42
+ 'A list of row lists. A cell is a string, a number, or { "componentId": "<id>" } to show a component. Default []',
43
+ ),
44
+ columnSizing: z.enum(["auto", "equal"]).optional().describe('Default "auto"'),
45
+ dividers: z.boolean().optional().describe("Default true"),
46
+ stickyHeader: z.boolean().optional().describe("Default false"),
47
+ emptyLabel: z.string().optional().describe('Default "No rows"'),
48
+ });
49
+ export const tableSectionSchema = z.object({
50
+ header: z.boolean().optional().describe("Renders the rows as the header"),
51
+ rowDivider: z.boolean().optional(),
52
+ });
53
+ export const tableRowSchema = z.object({
54
+ header: z.boolean().optional(),
55
+ label: z
56
+ .string()
57
+ .optional()
58
+ .describe("The text of a header cell at the start of the row"),
59
+ labelColSpan: z.number().optional().describe("Columns the label cell spans"),
60
+ });
61
+ export const tableCellSchema = z.object({
62
+ text: z.union([z.string(), z.number()]).optional(),
63
+ header: z.boolean().optional(),
64
+ align: cellAlign,
65
+ vAlign: cellAlign.describe('Default "start"'),
66
+ colSpan: z.number().optional(),
67
+ rowSpan: z.number().optional(),
68
+ width: sizeValue.optional(),
69
+ padding: sizeValue.optional(),
70
+ });
71
+
72
+ const listItemValue = z.union([
73
+ z.string(),
74
+ z.object({
75
+ label: z.string(),
76
+ description: z.string().optional(),
77
+ icon: z.string().optional().describe("Lucide icon name"),
78
+ value: z
79
+ .union([z.string(), z.number()])
80
+ .optional()
81
+ .describe(
82
+ "Without an action: shown on the right of the label, for a key and value fact. With an action: the payload of the pick, not shown",
83
+ ),
84
+ }),
85
+ ]);
86
+ export type ListItemValue = z.output<typeof listItemValue>;
87
+
88
+ export const LIST_MARKERS = ["bullet", "number", "rich", "none"] as const;
89
+ export type ListMarker = (typeof LIST_MARKERS)[number];
90
+
91
+ export const listSchema = z.object({
92
+ items: z.array(listItemValue).optional(),
93
+ direction: z
94
+ .enum(["vertical", "horizontal"])
95
+ .optional()
96
+ .describe('Default "vertical". "horizontal" scrolls sideways'),
97
+ align: z.enum(["start", "center", "end", "stretch"]).optional(),
98
+ weight: weightProp,
99
+ marker: z.enum(LIST_MARKERS).optional().describe('Default "bullet"'),
100
+ connector: z.enum(["none", "solid"]).optional().describe('Default "none"'),
101
+ gap: sizeValue.optional(),
102
+ start: z.number().optional().describe('The first number of marker "number"'),
103
+ maxMarkerSize: z
104
+ .number()
105
+ .optional()
106
+ .describe("The width of the marker column in pixels"),
107
+ });
108
+ export const listItemSchema = z.object({
109
+ label: z.string().optional(),
110
+ value: z
111
+ .union([z.string(), z.number()])
112
+ .optional()
113
+ .describe(
114
+ "Without an action: shown on the right of the label, for a key and value fact",
115
+ ),
116
+ description: z.string().optional(),
117
+ icon: z.string().optional().describe("Lucide icon name"),
118
+ marker: z.string().optional().describe("Shows this text as the marker"),
119
+ markerSize: z
120
+ .number()
121
+ .optional()
122
+ .describe("The width of the marker column in pixels"),
123
+ disabled: z
124
+ .boolean()
125
+ .optional()
126
+ .describe("Greys the item out and ignores its action"),
127
+ });
128
+
129
+ export const listSelection = z.object({
130
+ index: z.number(),
131
+ label: z.string(),
132
+ value: z.string().optional(),
133
+ });
134
+
135
+ export type ListSelection = z.output<typeof listSelection>;
136
+
137
+ /**
138
+ * The standard data components, without their framework components:
139
+ * tables, lists, a chart and a map. Each framework adds its components
140
+ * with `withComponents`.
141
+ *
142
+ * - Table: `children` (TableSection or TableRow ids, or a template) and
143
+ * `cellComponents` (the components that `{ componentId }` cells show).
144
+ * - List and ListItem: an `action` event. The List event gets the index,
145
+ * label and value of the picked item.
146
+ * - Map: `selected` is writable, so a `{ "@path" }` binding gets the choice of
147
+ * the user.
148
+ */
149
+ export const dataDeclarations = {
150
+ Table: {
151
+ description:
152
+ 'A data table, in a plain Column, not a Card. Give "columns" and "rows", or "children": TableSection or TableRow ids, or a template { "componentId", "path" } repeating a TableRow per item. A component in a cell or header (Badge, Button, Icon, Text): { "componentId": "<id>" }, with the id in "cellComponents".',
153
+ props: tableSchema,
154
+ slots: { children: "multiple", cellComponents: "multiple" } as const,
155
+ },
156
+ TableSection: {
157
+ accessibility: "self" as const,
158
+ description:
159
+ "A group of TableRow children in a Table. With header true, it is the header of the table.",
160
+ props: tableSectionSchema,
161
+ slots: CHILDREN_SLOT,
162
+ },
163
+ TableRow: {
164
+ accessibility: "self" as const,
165
+ description:
166
+ "A row of a Table. Its children are TableCell ids, or a template. With label, a header cell with that text starts the row.",
167
+ props: tableRowSchema,
168
+ slots: CHILDREN_SLOT,
169
+ },
170
+ TableCell: {
171
+ accessibility: "self" as const,
172
+ description:
173
+ 'A cell of a TableRow. It shows "text", or its children. With header true, it is a header cell.',
174
+ props: tableCellSchema,
175
+ slots: CHILDREN_SLOT,
176
+ },
177
+ List: {
178
+ description:
179
+ 'A list in a Card or next to another component; a plain list of text is markdown. Give "items": an item with a value and no action is a key-value row (Price: $1,599). Or give "children": ListItem ids or a template. With "action" the user picks an item; the event context gets its index, label and value.',
180
+ props: listSchema,
181
+ events: {
182
+ action: {
183
+ description:
184
+ "Runs when the user picks an item. The args are the index, label and value of the item.",
185
+ parameters: listSelection,
186
+ },
187
+ },
188
+ slots: CHILDREN_SLOT,
189
+ },
190
+ ListItem: {
191
+ description:
192
+ 'An item of a List, with a label, a value on the right, a description, an icon and children. With an "action", the user can pick it.',
193
+ props: listItemSchema,
194
+ events: {
195
+ action: {
196
+ description: "Runs when the user picks the item.",
197
+ parameters: z.object({}),
198
+ },
199
+ },
200
+ slots: CHILDREN_SLOT,
201
+ },
202
+ Chart: {
203
+ description:
204
+ 'A bar, line, area, scatter, pie or donut chart. "data" is a list of objects. "xKey" is the field of the category. "series" are the value fields.',
205
+ props: chartSchema,
206
+ },
207
+ Map: {
208
+ description:
209
+ 'A map with markers; with "route" a line connects them in order. Bind "selected" to get the label of the marker the user picks. Without maps it shows a list of the places.',
210
+ props: mapSchema,
211
+ writable: ["selected"] as const,
212
+ },
213
+ };
@@ -0,0 +1,57 @@
1
+ import type { GenerativeUIComponentDeclaration } from "./components";
2
+ import { compositeDeclarations } from "./composites";
3
+ import { dataDeclarations } from "./data";
4
+ import { feedbackDeclarations } from "./feedback";
5
+ import { inputDeclarations } from "./inputs";
6
+ import { layoutDeclarations } from "./layout";
7
+ import { mediaDeclarations } from "./media";
8
+ import {
9
+ standardParameterOrder,
10
+ STANDARD_ARGUMENT_PREFIXES,
11
+ } from "./parameter-order";
12
+ import { textDeclarations } from "./text";
13
+
14
+ /** Every standard component, without its framework component. */
15
+ export const standardDeclarations = {
16
+ ...layoutDeclarations,
17
+ ...textDeclarations,
18
+ ...inputDeclarations,
19
+ ...feedbackDeclarations,
20
+ ...dataDeclarations,
21
+ ...mediaDeclarations,
22
+ ...compositeDeclarations,
23
+ };
24
+
25
+ /** The name of a standard component. */
26
+ export type StandardComponentName = keyof typeof standardDeclarations;
27
+
28
+ // Every standard component needs an intentional positional calling convention.
29
+ STANDARD_ARGUMENT_PREFIXES satisfies Record<
30
+ StandardComponentName,
31
+ readonly string[]
32
+ >;
33
+
34
+ /**
35
+ * The standard components of a framework, each with its positional
36
+ * parameter order. Give the result to `createGenerativeUI`.
37
+ */
38
+ export function withStandardParameterOrder<
39
+ Definitions extends Record<
40
+ StandardComponentName,
41
+ GenerativeUIComponentDeclaration
42
+ >,
43
+ >(definitions: Definitions) {
44
+ const ordered: Record<string, unknown> = {};
45
+ for (const name of Object.keys(definitions) as StandardComponentName[]) {
46
+ const definition = definitions[name];
47
+ ordered[name] = {
48
+ ...definition,
49
+ parameterOrder: standardParameterOrder(name, definition),
50
+ };
51
+ }
52
+ return ordered as {
53
+ [Name in keyof Definitions]: Definitions[Name] & {
54
+ parameterOrder: string[];
55
+ };
56
+ };
57
+ }
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import { CHILDREN_SLOT, sizeValue, weightProp } from "./layout";
3
+
4
+ export const pulseIndicatorSchema = z.object({
5
+ label: z
6
+ .string()
7
+ .optional()
8
+ .describe(
9
+ "What the dot means, for screen readers. Leave it unset when text next to the dot says the same",
10
+ ),
11
+ color: z.string().optional().describe('Text color token. Default "success"'),
12
+ size: z.number().optional().describe("Pixels. Default 12"),
13
+ pulseColor: z.string().optional(),
14
+ duration: z.number().optional().describe("Milliseconds. Default 1500"),
15
+ endScale: z.number().optional().describe("Default 2.4"),
16
+ startOpacity: z.number().optional().describe("Default 0.6"),
17
+ });
18
+ export const flashcardSchema = z.object({
19
+ front: z.string().optional().describe("The text on the front"),
20
+ back: z.string().optional().describe("The text on the back"),
21
+ hint: z
22
+ .string()
23
+ .optional()
24
+ .describe('A small line under the front, for example "Click to flip"'),
25
+ });
26
+ export const popoverSchema = z.object({
27
+ open: z.boolean().optional().describe("Default false"),
28
+ showOnHover: z.boolean().optional(),
29
+ hoverOpenDelay: z
30
+ .number()
31
+ .optional()
32
+ .describe("Milliseconds before a hover opens it. Default 0"),
33
+ });
34
+ export const popoverTriggerSchema = z.object({
35
+ block: z.boolean().optional().describe("Full width"),
36
+ });
37
+ export const popoverContentSchema = z.object({
38
+ side: z
39
+ .enum(["top", "bottom", "left", "right"])
40
+ .optional()
41
+ .describe('Default "bottom"'),
42
+ sideOffset: z
43
+ .number()
44
+ .optional()
45
+ .describe("Pixels between the trigger and the content. Default 6"),
46
+ align: z
47
+ .enum(["start", "center", "end"])
48
+ .optional()
49
+ .describe('Default "center"'),
50
+ width: sizeValue.optional().describe("4px steps when a number"),
51
+ });
52
+ export const modalSchema = z.object({
53
+ title: z.string().optional().describe("The heading of the dialog"),
54
+ open: z
55
+ .boolean()
56
+ .optional()
57
+ .describe('Default false. Bind it with { "@path": "/x" } to read it'),
58
+ maxWidth: sizeValue.optional().describe("Default 480"),
59
+ weight: weightProp,
60
+ });
61
+
62
+ /**
63
+ * The standard feedback components, without their framework components: a
64
+ * pulse dot, a flashcard, a popover and a modal. Popover, PopoverTrigger and
65
+ * PopoverContent have a "multiple" `children` slot. Popover and Modal `open`
66
+ * is writable, so the component gets a `setOpen` prop.
67
+ */
68
+ export const feedbackDeclarations = {
69
+ PulseIndicator: {
70
+ description:
71
+ 'A small dot that pulses, for example next to the text "Live". Set label when no text next to the dot says what it means.',
72
+ props: pulseIndicatorSchema,
73
+ },
74
+ FlashcardFlip: {
75
+ description:
76
+ "A card that shows the front text. A click or the Enter key flips it to the back text, and again to the front.",
77
+ props: flashcardSchema,
78
+ },
79
+ Popover: {
80
+ description:
81
+ "A small overlay: exactly two children, one PopoverTrigger then one PopoverContent. A click on the trigger toggles it; Escape or a click outside closes it.",
82
+ props: popoverSchema,
83
+ slots: CHILDREN_SLOT,
84
+ writable: ["open"] as const,
85
+ },
86
+ PopoverTrigger: {
87
+ description:
88
+ "The trigger of a Popover. Its children are the label of the trigger: a Text or an Icon. Do not put a Button in it, because the trigger is already a button.",
89
+ props: popoverTriggerSchema,
90
+ slots: CHILDREN_SLOT,
91
+ },
92
+ PopoverContent: {
93
+ description:
94
+ "The body of a Popover. It shows only when the Popover is open.",
95
+ props: popoverContentSchema,
96
+ slots: CHILDREN_SLOT,
97
+ },
98
+ Modal: {
99
+ description:
100
+ "A dialog over the page. A click on the trigger (a Button or a Text) opens the content in the dialog. Escape, the close button or a click on the backdrop closes it.",
101
+ props: modalSchema,
102
+ slots: { trigger: "single", content: "single" } as const,
103
+ writable: ["open"] as const,
104
+ },
105
+ };
@@ -0,0 +1,19 @@
1
+ // The framework-free part of the standard catalog: tokens, theme,
2
+ // stylesheet, schemas and declarations. Each framework adds its components
3
+ // with `withComponents`.
4
+ export * from "./tokens";
5
+ export * from "./theme";
6
+ export * from "./styles";
7
+ export * from "./checks";
8
+ export * from "./components";
9
+ export * from "./parameter-order";
10
+ export * from "./layout";
11
+ export * from "./text";
12
+ export * from "./inputs";
13
+ export * from "./feedback";
14
+ export * from "./data";
15
+ export * from "./chart";
16
+ export * from "./map";
17
+ export * from "./media";
18
+ export * from "./composites";
19
+ export * from "./declarations";