@copilotkit/react-core 2.0.0-rc.31 → 2.0.0-rc.33

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 (34) hide show
  1. package/README.md +1 -1
  2. package/dist/MarkdownRendererContext-CPfNVyde.d.mts +241 -0
  3. package/dist/MarkdownRendererContext-CPfNVyde.d.mts.map +1 -0
  4. package/dist/MarkdownRendererContext-iOl2pj9l.d.cts +241 -0
  5. package/dist/MarkdownRendererContext-iOl2pj9l.d.cts.map +1 -0
  6. package/dist/MarkdownSurfaces-BFoO6wSB.cjs +1650 -0
  7. package/dist/MarkdownSurfaces-BFoO6wSB.cjs.map +1 -0
  8. package/dist/MarkdownSurfaces-BQ1HGCzB.mjs +1442 -0
  9. package/dist/MarkdownSurfaces-BQ1HGCzB.mjs.map +1 -0
  10. package/dist/generative-ui.cjs +687 -2964
  11. package/dist/generative-ui.cjs.map +1 -1
  12. package/dist/generative-ui.d.cts +2478 -2683
  13. package/dist/generative-ui.d.cts.map +1 -1
  14. package/dist/generative-ui.d.mts +2477 -2682
  15. package/dist/generative-ui.d.mts.map +1 -1
  16. package/dist/generative-ui.mjs +299 -2585
  17. package/dist/generative-ui.mjs.map +1 -1
  18. package/dist/index.cjs +26 -1367
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +1 -1
  21. package/dist/index.d.mts +1 -1
  22. package/dist/index.mjs +11 -1352
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/index.umd.js +124 -3358
  25. package/dist/index.umd.js.map +1 -1
  26. package/package.json +9 -9
  27. package/dist/MarkdownRendererContext-BX26QLwl.d.cts +0 -937
  28. package/dist/MarkdownRendererContext-BX26QLwl.d.cts.map +0 -1
  29. package/dist/MarkdownRendererContext-DAOMewji.d.mts +0 -937
  30. package/dist/MarkdownRendererContext-DAOMewji.d.mts.map +0 -1
  31. package/dist/MarkdownSurfaces-BbrHcSHN.cjs +0 -3903
  32. package/dist/MarkdownSurfaces-BbrHcSHN.cjs.map +0 -1
  33. package/dist/MarkdownSurfaces-DQbRS91-.mjs +0 -3587
  34. package/dist/MarkdownSurfaces-DQbRS91-.mjs.map +0 -1
@@ -1,20 +1,16 @@
1
1
  "use client";
2
2
 
3
- import { F as toJsonSchema, K as IconSvg, O as isRecord, P as createGenerativeUI, _ as GenerativeUINodeContext, b as useRequiredGenerativeUIRuntime, c as SurfaceView, d as namedRole, f as useGenerativeUIAccessibility, g as useManagerVersion, h as useGenerativeUIState, j as GenerativeUIError, l as DARK_THEME_CSS, m as useGenerativeUIFunction, n as ProviderMarkdown, p as wrapperAria, r as DefaultGenerativeUIChatCard, t as MarkdownSurfaces, u as controlAria, y as useGenerativeUIRuntime } from "./MarkdownSurfaces-DQbRS91-.mjs";
3
+ import { M as IconSvg, c as SurfaceView, d as useGenerativeUIAccessibility, f as wrapperAria, g as GenerativeUINodeContext, h as useManagerVersion, l as controlAria, m as useGenerativeUIState, n as ProviderMarkdown, p as useGenerativeUIFunction, r as DefaultGenerativeUIChatCard, t as MarkdownSurfaces, u as namedRole, v as useGenerativeUIRuntime, x as createGenerativeUI, y as useRequiredGenerativeUIRuntime } from "./MarkdownSurfaces-BQ1HGCzB.mjs";
4
4
  import React, { Suspense, createContext, isValidElement, memo, useCallback, useContext, useEffect, useId, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
5
5
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
- import { A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF, GENERATIVE_UI_FUNCTIONS, GENERATIVE_UI_MAX_TARGET_COMPONENTS, childRefKind, functionCallers } from "@copilotkit/shared";
7
- import * as z from "zod";
6
+ import { allowedComponents, scrollToSurface } from "@copilotkit/core/generative-ui";
7
+ import { ACCENT, BACKDROP, CHART_CURSOR, CHART_PALETTE, FONT_WEIGHT, GenerativeUIError, INNER_PANEL_BG, ON_ACCENT, SHADOW_MD, SHADOW_SM, SHADOW_SOFT, SHADOW_XS, STANDARD_CATALOG_ID, STANDARD_CSS, STANDARD_STYLE_ID, backgroundColor, borderColor, checkMessageStyle, child as child$1, childList as childList$1, compositeDeclarations, dataDeclarations, exportA2UICatalog, feedbackDeclarations, firstFailedCheck, inputDeclarations, layoutDeclarations, mediaDeclarations, panelBackground, radius, spacing, textColor, textDeclarations, textFont, withComponents, withStandardParameterOrder } from "@copilotkit/shared/generative-ui";
8
8
  import { createPortal } from "react-dom";
9
9
 
10
10
  //#region src/generative-ui/refs.ts
11
11
  /**
12
- * Schema helpers that mark a prop as a component reference, the way A2UI
13
- * 1.0 marks it with the `ComponentId` and `ChildList` common types. The
14
- * engine finds every marked prop in the props schema, at any depth, renders
15
- * the referenced components, and hands the component the rendered nodes in
16
- * place of the ids. The model sees the prop as `componentId` or as a list
17
- * of ids or a template.
12
+ * One component id. The component receives the rendered child. Pass the
13
+ * description here, not with `.describe()`, which would replace the mark.
18
14
  *
19
15
  * @example
20
16
  * ```ts
@@ -24,14 +20,8 @@ import { createPortal } from "react-dom";
24
20
  * // The component gets `tabs: { title: string; child: ReactNode }[]`.
25
21
  * ```
26
22
  */
27
- const toNode = (value) => value;
28
- const mark = (prefix, description) => description ? `${prefix} ${description}` : prefix;
29
- /**
30
- * One component id. The component receives the rendered child. Pass the
31
- * description here, not with `.describe()`, which would replace the mark.
32
- */
33
23
  function child(description) {
34
- return z.string().min(1).describe(mark(A2UI_COMPONENT_ID_MARK, description)).transform(toNode);
24
+ return child$1(description);
35
25
  }
36
26
  /**
37
27
  * A list of component ids, or a template `{ componentId, path }` that
@@ -40,364 +30,13 @@ function child(description) {
40
30
  * not with `.describe()`.
41
31
  */
42
32
  function childList(description) {
43
- return z.union([z.array(z.string().min(1)), z.object({
44
- componentId: z.string().min(1),
45
- path: z.string().min(1)
46
- })]).describe(mark(A2UI_CHILD_LIST_MARK, description)).transform(toNode);
47
- }
48
-
49
- //#endregion
50
- //#region src/generative-ui/catalog-export.ts
51
- const COMMON = "common_types.json#/$defs/";
52
- const DATA_BINDING_REF = `${COMMON}DataBinding`;
53
- const FUNCTION_CALL_REF = `${COMMON}FunctionCall`;
54
- const ACTION_REF = `${COMMON}Action`;
55
- const DYNAMIC_REFS = {
56
- string: `${COMMON}DynamicString`,
57
- number: `${COMMON}DynamicNumber`,
58
- boolean: `${COMMON}DynamicBoolean`,
59
- "string[]": `${COMMON}DynamicStringList`,
60
- unknown: `${COMMON}DynamicValue`
61
- };
62
- /**
63
- * The A2UI 1.0 catalog definition of a generative UI, as a JSON value that
64
- * follows `catalog_definition.json`: one `components` entry per component,
65
- * with `component` as a `const`, `functions` for the built-ins and the
66
- * declared functions, and `$defs.anyComponent` / `$defs.anyFunction`. Other
67
- * A2UI tools (a validator, another renderer, a prompt builder) read it.
68
- *
69
- * - A prop that `child()` or `childList()` marks is a `ComponentId` or a
70
- * `ChildList` reference; so is a slot. An event prop is an `Action`.
71
- * - Every other value, at any depth of a prop or of the args of a declared
72
- * function, takes its literal schema, a `DataBinding` or a `FunctionCall`,
73
- * because the renderer resolves dynamic values at any depth.
74
- * - Every function states `returnType` and `allowedCallers`: the built-ins
75
- * are `rendererOnly`, and so is a declared function without
76
- * `allowedCallers`, as in A2UI 1.0.
77
- *
78
- * @param ui - The generative UI to describe.
79
- * @param options - The title, description and instructions of the catalog.
80
- *
81
- * @example
82
- * ```ts
83
- * const catalog = exportA2UICatalog(shopUI, { title: "Acme shop" });
84
- * fs.writeFileSync("shop-catalog.json", JSON.stringify(catalog, null, 2));
85
- * ```
86
- */
87
- function exportA2UICatalog(ui, options = {}) {
88
- const components = Object.fromEntries(Object.entries(ui.manifestComponents).map(([name, manifest]) => [name, toDraft2020(rebaseRefs(componentDefinition(name, manifest), `#/components/${pointerSegment(name)}`))]));
89
- const functions = {};
90
- for (const [name, info] of Object.entries(GENERATIVE_UI_FUNCTIONS)) {
91
- if (ui.functions.has(name)) continue;
92
- functions[name] = functionEntry(name, info, {
93
- description: info.description,
94
- returnType: info.returnType,
95
- args: argsSchemaFromSignature(info.parameters)
96
- });
97
- }
98
- for (const [name, fn] of ui.functions) functions[name] = functionEntry(name, fn, {
99
- description: fn.description,
100
- returnType: fn.returnType ?? "any",
101
- args: toDraft2020(rebaseRefs(dynamicArgs(toJsonSchema(fn.parameters)), `#/functions/${pointerSegment(name)}/properties/args`))
102
- });
103
- const { title, description, instructions } = options;
104
- return {
105
- $schema: "https://json-schema.org/draft/2020-12/schema",
106
- protocolVersion: "1.0",
107
- catalogId: ui.id,
108
- ...title === void 0 ? {} : { title },
109
- ...description === void 0 ? {} : { description },
110
- ...instructions === void 0 ? {} : { instructions },
111
- components,
112
- functions,
113
- $defs: {
114
- anyComponent: {
115
- ...oneOfRefs("components", Object.keys(components)),
116
- discriminator: { propertyName: "component" }
117
- },
118
- anyFunction: oneOfRefs("functions", Object.keys(functions))
119
- }
120
- };
121
- }
122
- /**
123
- * `oneOf` over the entries of a section. JSON Schema wants at least one
124
- * variant, so an empty section (a UI with no components) matches nothing.
125
- */
126
- function oneOfRefs(section, names) {
127
- if (names.length === 0) return { not: {} };
128
- return { oneOf: names.map((name) => ({ $ref: `#/${section}/${pointerSegment(name)}` })) };
129
- }
130
- /** A name as a JSON Pointer segment in a URI fragment: `acme/Card` is `acme~1Card`. */
131
- function pointerSegment(name) {
132
- return encodeURIComponent(name.replace(/~/g, "~0").replace(/\//g, "~1"));
133
- }
134
- /** Keywords whose value is data, not a schema. */
135
- const LITERAL_KEYWORDS = new Set([
136
- "default",
137
- "const",
138
- "enum",
139
- "examples"
140
- ]);
141
- /**
142
- * A schema in the draft 2020-12 dialect that the catalog declares. The
143
- * converter writes draft-07, where a tuple is `items: [...]` with
144
- * `additionalItems`; 2020-12 spells that `prefixItems` and `items`.
145
- */
146
- function toDraft2020(schema) {
147
- return mapSchema$1(schema, (node) => {
148
- const { items, additionalItems, ...rest } = node;
149
- if (!Array.isArray(items)) return node;
150
- return {
151
- ...rest,
152
- prefixItems: items,
153
- ...additionalItems === void 0 ? {} : { items: additionalItems }
154
- };
155
- });
156
- }
157
- /** One `components` entry: the props as the model sets them, with the A2UI common types. */
158
- function componentDefinition(name, manifest) {
159
- const { properties, required, description, $defs, definitions } = manifest.props;
160
- const props = Object.fromEntries(Object.entries(isRecord(properties) ? properties : {}).map(([key, schema]) => [key, dynamicProp(schema)]));
161
- const events = Object.fromEntries(Object.entries(manifest.events ?? {}).map(([key, event]) => [key, {
162
- $ref: ACTION_REF,
163
- ...event.description ? { description: event.description } : {}
164
- }]));
165
- const slots = Object.fromEntries(Object.entries(manifest.slots ?? {}).map(([key, kind]) => [key, { $ref: kind === "single" ? A2UI_COMPONENT_ID_REF : A2UI_CHILD_LIST_REF }]));
166
- const fields = {
167
- ...props,
168
- ...events,
169
- ...slots
170
- };
171
- const orderedFields = manifest.parameterOrder === void 0 ? fields : Object.fromEntries([...new Set([...manifest.parameterOrder, ...Object.keys(fields)])].filter((key) => Object.hasOwn(fields, key)).map((key) => [key, fields[key]]));
172
- const text = manifest.description ?? description;
173
- return {
174
- type: "object",
175
- ...typeof text === "string" ? { description: text } : {},
176
- properties: {
177
- component: { const: name },
178
- ...orderedFields
179
- },
180
- required: ["component", ...Array.isArray(required) ? required.filter(isString) : []],
181
- ...withDynamicChildren({
182
- ...isRecord($defs) ? { $defs } : {},
183
- ...isRecord(definitions) ? { definitions } : {}
184
- })
185
- };
186
- }
187
- /**
188
- * The schema with its local references (`#/...`) pointing into the place
189
- * it is embedded at. A converter that writes `$defs` refers to them from
190
- * the root of its own document; inside the catalog, that root is `base`.
191
- */
192
- function rebaseRefs(schema, base) {
193
- return mapSchema$1(schema, (node) => {
194
- const ref = node.$ref;
195
- if (ref === "#") return {
196
- ...node,
197
- $ref: base
198
- };
199
- if (typeof ref === "string" && ref.startsWith("#/")) return {
200
- ...node,
201
- $ref: `${base}${ref.slice(1)}`
202
- };
203
- return node;
204
- });
205
- }
206
- /** Keywords whose value is a map from a name to a schema. */
207
- const SCHEMA_MAP_KEYWORDS = new Set([
208
- "properties",
209
- "patternProperties",
210
- "$defs",
211
- "definitions",
212
- "dependentSchemas"
213
- ]);
214
- /**
215
- * Walks a JSON Schema and rebuilds each schema node with `transform`, the
216
- * children first. The names in `properties` and the definition maps are
217
- * names, not keywords: a prop called `default` is a schema, while the
218
- * `default` of a schema is data and stays as it is.
219
- */
220
- function mapSchema$1(schema, transform) {
221
- const visitValue = (value) => {
222
- if (Array.isArray(value)) return value.map(visitValue);
223
- return isRecord(value) ? visitNode(value) : value;
224
- };
225
- const visitNode = (node) => {
226
- const result = {};
227
- for (const [key, value] of Object.entries(node)) if (LITERAL_KEYWORDS.has(key)) result[key] = value;
228
- else if (SCHEMA_MAP_KEYWORDS.has(key) && isRecord(value)) result[key] = Object.fromEntries(Object.entries(value).map(([name, entry]) => [name, isRecord(entry) ? visitNode(entry) : entry]));
229
- else result[key] = visitValue(value);
230
- return transform(result);
231
- };
232
- return visitNode(schema);
233
- }
234
- const isString = (value) => typeof value === "string";
235
- /**
236
- * A prop as the catalog states it. A component reference stays one. Any
237
- * other value takes its literal schema, a data binding or a function call,
238
- * and so does every value inside it: the properties of an object, the
239
- * values of a record and the items of a list, because the renderer
240
- * resolves dynamic values at any depth. The variants of a union are
241
- * transformed in place.
242
- */
243
- function dynamicProp(schema) {
244
- if (!isRecord(schema)) return { $ref: DYNAMIC_REFS.unknown };
245
- if (childRefKind(schema)) return schema;
246
- const { description, ...literal } = withDynamicChildren(schema);
247
- return {
248
- ...typeof description === "string" ? { description } : {},
249
- anyOf: [
250
- literal,
251
- { $ref: DATA_BINDING_REF },
252
- { $ref: FUNCTION_CALL_REF }
253
- ]
254
- };
255
- }
256
- /** The schema with its nested values made dynamic, itself unchanged. */
257
- function withDynamicChildren(schema) {
258
- const result = { ...schema };
259
- if (isRecord(schema.properties)) result.properties = Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => [key, dynamicProp(value)]));
260
- if (isRecord(schema.items)) result.items = dynamicProp(schema.items);
261
- if (Array.isArray(schema.items)) result.items = schema.items.map((item) => isRecord(item) ? dynamicProp(item) : item);
262
- if (isRecord(schema.additionalItems)) result.additionalItems = dynamicProp(schema.additionalItems);
263
- for (const key of ["$defs", "definitions"]) {
264
- const defs = schema[key];
265
- if (isRecord(defs)) result[key] = Object.fromEntries(Object.entries(defs).map(([name, def]) => [name, isRecord(def) ? withDynamicChildren(def) : def]));
266
- }
267
- if (Array.isArray(schema.allOf)) result.allOf = schema.allOf.map((part) => isRecord(part) ? withDynamicChildren(part) : part);
268
- if (isRecord(schema.additionalProperties)) result.additionalProperties = dynamicProp(schema.additionalProperties);
269
- if (isRecord(schema.patternProperties)) result.patternProperties = Object.fromEntries(Object.entries(schema.patternProperties).map(([pattern, value]) => [pattern, dynamicProp(value)]));
270
- for (const key of ["anyOf", "oneOf"]) {
271
- const variants = schema[key];
272
- if (Array.isArray(variants)) result[key] = variants.map((variant) => isRecord(variant) && !childRefKind(variant) ? withDynamicChildren(variant) : variant);
273
- }
274
- return result;
275
- }
276
- /**
277
- * The args of a declared function as the catalog states them: the object
278
- * stays an object, each arg takes a value, a binding or a function call.
279
- */
280
- function dynamicArgs(schema) {
281
- return withDynamicChildren(schema);
282
- }
283
- /** One `functions` entry, in the A2UI `FunctionDefinition` shape. */
284
- function functionEntry(name, permissions, parts) {
285
- const callers = functionCallers(permissions);
286
- const allowedCallers = callers.renderer && callers.agent ? "rendererOrAgent" : callers.agent ? "agentOnly" : "rendererOnly";
287
- const argsRequired = hasRequiredArgs(parts.args);
288
- return {
289
- type: "object",
290
- ...parts.description ? { description: parts.description } : {},
291
- returnType: parts.returnType,
292
- allowedCallers,
293
- requiresUserActivation: permissions.requiresUserActivation === true,
294
- properties: {
295
- "@call": { const: name },
296
- args: parts.args
297
- },
298
- required: argsRequired ? ["@call", "args"] : ["@call"]
299
- };
300
- }
301
- /**
302
- * True when an empty args object fails the schema: a key is required at
303
- * its top, in an `allOf` part, or in every variant of an `anyOf` / `oneOf`.
304
- */
305
- function hasRequiredArgs(schema) {
306
- if (!isRecord(schema)) return false;
307
- if (Array.isArray(schema.required) && schema.required.length > 0) return true;
308
- if (Array.isArray(schema.allOf) && schema.allOf.some(hasRequiredArgs)) return true;
309
- for (const key of ["anyOf", "oneOf"]) {
310
- const variants = schema[key];
311
- if (Array.isArray(variants) && variants.length > 0) {
312
- if (variants.every(hasRequiredArgs)) return true;
313
- }
314
- }
315
- return false;
316
- }
317
- /**
318
- * The JSON Schema of the args of a built-in function, from its short
319
- * TypeScript-like signature (`{ value: number; decimals?: number }`). Each
320
- * arg takes a literal, a binding or a function call, so a type maps to the
321
- * A2UI dynamic type; `[name: string]: T` becomes `additionalProperties`.
322
- *
323
- * @example
324
- * ```ts
325
- * argsSchemaFromSignature("{ value: string; min?: number }");
326
- * // { type: "object", properties: { value: { $ref: ".../DynamicString" }, min: { $ref: ".../DynamicNumber" } }, required: ["value"], additionalProperties: false }
327
- * ```
328
- */
329
- function argsSchemaFromSignature(signature) {
330
- const body = signature.trim().replace(/^\{/, "").replace(/\}$/, "");
331
- const properties = {};
332
- const required = [];
333
- let additionalProperties = false;
334
- for (const part of body.split(";")) {
335
- const field = part.trim();
336
- if (field === "") continue;
337
- const index = field.match(/^\[\w+: string\]:\s*(.+)$/);
338
- if (index) {
339
- additionalProperties = typeSchema(index[1]);
340
- continue;
341
- }
342
- const named = field.match(/^(\w+)(\?)?:\s*(.+)$/);
343
- if (!named) continue;
344
- properties[named[1]] = typeSchema(named[3]);
345
- if (!named[2]) required.push(named[1]);
346
- }
347
- return {
348
- type: "object",
349
- properties,
350
- ...required.length > 0 ? { required } : {},
351
- additionalProperties
352
- };
353
- }
354
- function typeSchema(type) {
355
- const trimmed = type.trim();
356
- const alternatives = trimmed.split("|").map((part) => part.trim());
357
- if (alternatives.length > 1) return { anyOf: alternatives.map(typeSchema) };
358
- if (trimmed in DYNAMIC_REFS) return { $ref: DYNAMIC_REFS[trimmed] };
359
- if (trimmed.endsWith("[]")) return { anyOf: [
360
- {
361
- type: "array",
362
- items: typeSchema(trimmed.slice(0, -2))
363
- },
364
- { $ref: DATA_BINDING_REF },
365
- { $ref: FUNCTION_CALL_REF }
366
- ] };
367
- return { $ref: DYNAMIC_REFS.unknown };
33
+ return childList$1(description);
368
34
  }
369
35
 
370
36
  //#endregion
371
37
  //#region src/generative-ui/GenerativeUISurface.tsx
372
- /** Scrolls `element` into view, unless it is already fully on screen. */
373
- function scrollToSurface(element) {
374
- const { top, bottom } = element.getBoundingClientRect();
375
- if (top >= 0 && bottom <= window.innerHeight) return;
376
- const reduceMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
377
- element.scrollIntoView?.({
378
- behavior: reduceMotion ? "auto" : "smooth",
379
- block: "start"
380
- });
381
- }
382
38
  const isDevelopment = () => process.env.NODE_ENV !== "production";
383
39
  /**
384
- * The names of `requested` that `ui` has, without repeats, at most the
385
- * number that the envelope takes. `warning` tells what was dropped.
386
- */
387
- function allowedComponents(requested, ui) {
388
- const unique = [...new Set(requested)];
389
- const unknown = unique.filter((name) => !ui.components.has(name));
390
- const known = unique.filter((name) => ui.components.has(name));
391
- const names = known.slice(0, GENERATIVE_UI_MAX_TARGET_COMPONENTS);
392
- const problems = [];
393
- if (unknown.length > 0) problems.push(`these components are not in the UI and are ignored: ${unknown.join(", ")}`);
394
- if (known.length > names.length) problems.push(`only the first ${GENERATIVE_UI_MAX_TARGET_COMPONENTS} components are used`);
395
- return {
396
- names,
397
- warning: problems.join("; ")
398
- };
399
- }
400
- /**
401
40
  * Experimental. A named place on the page where the agent can render UI.
402
41
  *
403
42
  * @example
@@ -492,255 +131,6 @@ function useOverlayEscape(isOpen, close) {
492
131
  }, [isOpen, close]);
493
132
  }
494
133
 
495
- //#endregion
496
- //#region src/generative-ui/standard/tokens.ts
497
- /**
498
- * Design tokens of the standard components. Each token is a CSS variable
499
- * with a literal fallback, so a host can restyle a surface with the
500
- * `--a2ui-*` variables. A value that is not a token passes through as raw
501
- * CSS.
502
- */
503
- /** Id of `standardUI`, the catalog id the model writes in createSurface. */
504
- const STANDARD_CATALOG_ID = "copilotkit/standard@1";
505
- const TITLE_SIZES = [
506
- "sm",
507
- "md",
508
- "lg",
509
- "xl",
510
- "2xl",
511
- "3xl",
512
- "4xl",
513
- "5xl"
514
- ];
515
- const TEXT_SIZES = [
516
- "3xs",
517
- "2xs",
518
- "xs",
519
- "sm",
520
- "md",
521
- "lg"
522
- ];
523
- const WEIGHTS = [
524
- "normal",
525
- "medium",
526
- "semibold",
527
- "bold"
528
- ];
529
- const ALIGN = [
530
- "start",
531
- "center",
532
- "end",
533
- "baseline",
534
- "stretch"
535
- ];
536
- const JUSTIFY = [
537
- "start",
538
- "center",
539
- "end",
540
- "spaceBetween",
541
- "spaceAround",
542
- "spaceEvenly",
543
- "stretch"
544
- ];
545
- const WRAP = [
546
- "nowrap",
547
- "wrap",
548
- "wrap-reverse"
549
- ];
550
- const RADII = [
551
- "2xs",
552
- "xs",
553
- "sm",
554
- "md",
555
- "lg",
556
- "xl",
557
- "2xl",
558
- "3xl",
559
- "4xl",
560
- "full"
561
- ];
562
- const TEXT_COLORS = [
563
- "default",
564
- "prose",
565
- "primary",
566
- "emphasis",
567
- "secondary",
568
- "tertiary",
569
- "success",
570
- "info",
571
- "warning",
572
- "caution",
573
- "danger",
574
- "discovery"
575
- ];
576
- const BORDER_COLORS = [
577
- "default",
578
- "subtle",
579
- "strong",
580
- "info",
581
- "warning",
582
- "caution",
583
- "success",
584
- "danger",
585
- "discovery"
586
- ];
587
- const RADIUS_PX = {
588
- "2xs": "2px",
589
- xs: "4px",
590
- sm: "6px",
591
- md: "8px",
592
- lg: "12px",
593
- xl: "16px",
594
- "2xl": "20px",
595
- "3xl": "24px",
596
- "4xl": "32px",
597
- full: "9999px"
598
- };
599
- const TEXT_COLOR_FALLBACK = {
600
- default: "#0d0d0d",
601
- prose: "#0d0d0d",
602
- primary: "#0d0d0d",
603
- emphasis: "#000",
604
- secondary: "#5d5d5d",
605
- tertiary: "#8e8e8e",
606
- success: "#00805d",
607
- info: "#0068bc",
608
- warning: "#946200",
609
- caution: "#946200",
610
- danger: "#c1322c",
611
- discovery: "#7040c1"
612
- };
613
- const BG_FALLBACK = {
614
- surface: "#fff",
615
- "surface-secondary": "#f7f7f8",
616
- "surface-tertiary": "#ececec",
617
- "surface-elevated": "#fff",
618
- "surface-elevated-secondary": "#f7f7f8",
619
- "surface-inverted": "#0d0d0d",
620
- "surface-soft": "#fcfcfc",
621
- info: "rgba(0, 104, 188, 0.08)",
622
- warning: "rgba(148, 98, 0, 0.08)",
623
- caution: "rgba(148, 98, 0, 0.08)",
624
- success: "rgba(0, 128, 93, 0.08)",
625
- danger: "rgba(193, 50, 44, 0.08)",
626
- discovery: "rgba(112, 64, 193, 0.08)",
627
- "info-solid": "#0068bc",
628
- "warning-solid": "#946200",
629
- "caution-solid": "#946200",
630
- "success-solid": "#00805d",
631
- "danger-solid": "#c1322c",
632
- "discovery-solid": "#7040c1"
633
- };
634
- const BORDER_FALLBACK = {
635
- default: "rgba(0, 0, 0, 0.1)",
636
- subtle: "rgba(0, 0, 0, 0.05)",
637
- strong: "#cdcdcd",
638
- info: "#9cc4ea",
639
- warning: "#e6c98a",
640
- caution: "#e6c98a",
641
- success: "#9ad9c3",
642
- danger: "#eeaaa6",
643
- discovery: "#c8b4ea"
644
- };
645
- function hasToken(table, key) {
646
- return Object.hasOwn(table, key);
647
- }
648
- /** A number is a count of 4px steps. A string passes through as CSS. */
649
- function spacing(value) {
650
- if (value === void 0) return void 0;
651
- return typeof value === "number" ? `calc(var(--spacing, 0.25rem) * ${value})` : value;
652
- }
653
- /** A radius token, a number of pixels, or raw CSS. */
654
- function radius(value) {
655
- if (value === void 0) return void 0;
656
- if (typeof value === "number") return `${value}px`;
657
- if (value === "full") return "9999px";
658
- return hasToken(RADIUS_PX, value) ? `var(--a2ui-radius-${value}, ${RADIUS_PX[value]})` : value;
659
- }
660
- /** A text color token, or a raw CSS color. */
661
- function textColor(value) {
662
- if (!value) return void 0;
663
- return hasToken(TEXT_COLOR_FALLBACK, value) ? `var(--a2ui-color-text-${value}, ${TEXT_COLOR_FALLBACK[value]})` : value;
664
- }
665
- /** A background token, or a raw CSS color. */
666
- function backgroundColor(value) {
667
- if (!value) return void 0;
668
- return hasToken(BG_FALLBACK, value) ? `var(--a2ui-color-${value}, ${BG_FALLBACK[value]})` : value;
669
- }
670
- /** The one inner panel of a Card: near-white fill. */
671
- const INNER_PANEL_BG = "var(--a2ui-color-panel, rgb(252, 252, 252))";
672
- const SOFT_TINT = {
673
- info: "rgba(0, 104, 188, 0.06)",
674
- warning: "rgba(148, 98, 0, 0.06)",
675
- caution: "rgba(148, 98, 0, 0.06)",
676
- success: "rgba(0, 128, 93, 0.06)",
677
- danger: "rgba(193, 50, 44, 0.06)",
678
- discovery: "rgba(112, 64, 193, 0.06)"
679
- };
680
- /**
681
- * The background of a panel inside a Card. A neutral surface becomes the
682
- * near-white inner panel. A semantic tint gets lighter (about 6% alpha).
683
- * Solid and raw values go through `backgroundColor`.
684
- */
685
- function panelBackground(value) {
686
- if (!value) return void 0;
687
- if (value === "surface-secondary" || value === "surface-soft" || value === "surface-elevated-secondary") return INNER_PANEL_BG;
688
- return hasToken(SOFT_TINT, value) ? `var(--a2ui-color-${value}-soft, ${SOFT_TINT[value]})` : backgroundColor(value);
689
- }
690
- /** A border color token, or a raw CSS color. */
691
- function borderColor(value) {
692
- if (!value) return void 0;
693
- return hasToken(BORDER_FALLBACK, value) ? `var(--a2ui-color-border-${value}, ${BORDER_FALLBACK[value]})` : value;
694
- }
695
- const TEXT_SCALE = {
696
- "3xs": [".625em", 1.2],
697
- "2xs": [".6875em", 1.273],
698
- xs: [".75em", 1.333],
699
- sm: [".875em", 1.429],
700
- md: ["1em", 1.625],
701
- lg: ["1.125em", 1.556]
702
- };
703
- /** Text on an accent fill (solid buttons and badges, selected segments). */
704
- const ON_ACCENT = "var(--a2ui-color-on-accent, #fff)";
705
- /** The fill of a control (checkbox, radio, slider thumb, selected segment). */
706
- const CONTROL_BG = "var(--a2ui-color-control, #fff)";
707
- const SHADOW_XS = "var(--a2ui-shadow-xs, 0 1px 2px rgba(0,0,0,.12))";
708
- const SHADOW_SM = "var(--a2ui-shadow-sm, 0 1px 3px rgba(0,0,0,.12))";
709
- const SHADOW_SOFT = "var(--a2ui-shadow-soft, 0 1px 3px rgba(0,0,0,.06))";
710
- const SHADOW_MD = "var(--a2ui-shadow-md, 0 4px 12px rgba(0,0,0,.08))";
711
- /** The scrim behind a lightbox or modal. */
712
- const BACKDROP = "var(--a2ui-color-backdrop, rgba(0,0,0,.8))";
713
- /** The hover band behind a chart column. */
714
- const CHART_CURSOR = "var(--a2ui-color-chart-cursor, rgba(0,0,0,.04))";
715
- /**
716
- * Chart series colors: a soft blue family first, then muted companions, so
717
- * a chart with many series stays easy to read. A host can change each one
718
- * with `--a2ui-chart-1`, `--a2ui-chart-2`, and so on.
719
- */
720
- const CHART_PALETTE_FALLBACK = [
721
- "#7fb0f2",
722
- "#2f6fd1",
723
- "#b7cff7",
724
- "#8bb5a8",
725
- "#d9b36b",
726
- "#c08bb0"
727
- ];
728
- const CHART_PALETTE = CHART_PALETTE_FALLBACK.map((hex, index) => `var(--a2ui-chart-${index + 1}, ${hex})`);
729
- /** The body text size, in em of the text around it. */
730
- function textFont(size = "md") {
731
- const [fontSize, lineHeight] = TEXT_SCALE[size];
732
- return {
733
- fontSize,
734
- lineHeight
735
- };
736
- }
737
- const FONT_WEIGHT = {
738
- normal: 400,
739
- medium: 500,
740
- semibold: 600,
741
- bold: 700
742
- };
743
-
744
134
  //#endregion
745
135
  //#region src/generative-ui/standard/lightbox.tsx
746
136
  const LIGHTBOX_BUTTON = {
@@ -876,58 +266,6 @@ function openUrl(href) {
876
266
 
877
267
  //#endregion
878
268
  //#region src/generative-ui/standard/styles.ts
879
- /**
880
- * The stylesheet for what inline styles cannot do: pseudo-elements (slider
881
- * track and thumb, placeholder), `:checked` and `:first-child` states,
882
- * heading fallbacks, and resets for host prose styles. It is added once per
883
- * document.
884
- *
885
- * Typography is inherited: a surface takes the font, size, line height and
886
- * color of the text around it (the chat prose). Headings take the heading
887
- * styles of the host.
888
- */
889
- const STANDARD_STYLE_ID = "a2ui-standard-catalog";
890
- const ACCENT = "var(--a2ui-color-accent, #0d0d0d)";
891
- const FOCUS_RING$1 = "2px solid var(--a2ui-color-focus, #0285ff)";
892
- const CHECK_SVG = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E\")";
893
- const SLIDER_TRACK = "var(--a2ui-color-slider-track, rgba(0, 0, 0, 0.04))";
894
- const THUMB = `width:20px;height:20px;box-sizing:border-box;border-radius:9999px;background:${CONTROL_BG};border:1px solid ${borderColor("default")};box-shadow:${SHADOW_XS};cursor:pointer`;
895
- const STANDARD_CSS = [
896
- DARK_THEME_CSS,
897
- ".a2ui-surface{min-width:0;max-width:100%;box-sizing:border-box}",
898
- ".a2ui-surface{font:inherit;color:inherit}",
899
- ":where(.a2ui-surface) :where(h2){font-size:1.5em;font-weight:600;line-height:1.3}",
900
- ":where(.a2ui-surface) :where(h3){font-size:1.25em;font-weight:600;line-height:1.3}",
901
- ":where(.a2ui-surface) :where(h4){font-size:1em;font-weight:600;line-height:1.4}",
902
- "[data-a2ui-std] :is(button,input,select,textarea),[data-a2ui-input]{font:inherit;color:inherit}",
903
- "[data-a2ui-row=\"spaceBetween\"]>[data-a2ui-text]:last-child:not(:first-child){text-align:right;margin-inline-start:auto}",
904
- `[data-a2ui-input]:focus-visible{outline:${FOCUS_RING$1};outline-offset:1px}`,
905
- `[data-a2ui-scroll]:focus-visible{outline:${FOCUS_RING$1};outline-offset:2px}`,
906
- `[data-a2ui-input]::placeholder{color:${textColor("tertiary")};opacity:1}`,
907
- `.a2ui-std-range{-webkit-appearance:none;appearance:none;display:block;width:100%;height:24px;margin:0;padding:0 2px;box-sizing:border-box;border-radius:9999px;background:${SLIDER_TRACK};cursor:pointer}`,
908
- ".a2ui-std-range:disabled{cursor:not-allowed;opacity:.5}",
909
- ".a2ui-std-range::-webkit-slider-runnable-track{height:24px;background:transparent;border:0}",
910
- `.a2ui-std-range::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;margin-top:2px;${THUMB}}`,
911
- ".a2ui-std-range::-moz-range-track{height:24px;background:transparent;border:0}",
912
- `.a2ui-std-range::-moz-range-thumb{${THUMB}}`,
913
- `.a2ui-std-check{-webkit-appearance:none;appearance:none;flex-shrink:0;width:20px;height:20px;margin:0;box-sizing:border-box;border:1px solid ${borderColor("strong")};border-radius:9999px;background:${CONTROL_BG} center/14px 14px no-repeat;cursor:pointer}`,
914
- ".a2ui-std-check[data-shape=\"square\"]{border-radius:6px}",
915
- `.a2ui-std-check:checked{background-color:${ACCENT};border-color:${ACCENT};background-image:${CHECK_SVG}}`,
916
- `.a2ui-std-check[type="radio"]:checked{background-image:none;background-color:${CONTROL_BG};border:6px solid ${ACCENT}}`,
917
- ".a2ui-std-check:disabled{cursor:not-allowed}",
918
- ".a2ui-surface :is(h1,h2,h3,h4,h5,h6):not(.a2ui-markdown *){margin:var(--a2ui-heading-margin,0)}",
919
- ".a2ui-surface :is(p,table,figure,figcaption,blockquote,pre):not(.a2ui-markdown *){margin:var(--a2ui-block-margin,0)}",
920
- ".a2ui-markdown>:first-child{margin-top:0}",
921
- ".a2ui-markdown>:last-child{margin-bottom:0}",
922
- ".a2ui-surface :is(.a2ui-std-list,.a2ui-std-list>li){margin:0}",
923
- ".a2ui-surface .a2ui-std-table{font-size:inherit;line-height:inherit}",
924
- ".a2ui-std-table-wrap{width:100%;max-width:100%;min-width:0;overflow-x:auto}",
925
- ".a2ui-std-cell{padding:8px}",
926
- ".a2ui-std-cell:first-child{padding-inline-start:0}",
927
- ".a2ui-std-cell:last-child{padding-inline-end:0}",
928
- `.a2ui-std-cell[data-divider]{border-bottom:1px solid ${borderColor("subtle")}}`,
929
- ".a2ui-std-table>tbody:last-child>tr:last-child>.a2ui-std-cell{border-bottom:0}"
930
- ].join("\n");
931
269
  const noEffect$2 = () => {};
932
270
  const useInjectEffect$2 = typeof document === "undefined" ? noEffect$2 : React.useInsertionEffect;
933
271
  /**
@@ -945,170 +283,164 @@ function useStandardStyles() {
945
283
  }
946
284
 
947
285
  //#endregion
948
- //#region src/generative-ui/standard/layout.tsx
949
- /** A number is a count of 4px steps. A string is raw CSS. */
950
- const sizeValue = z.union([z.number(), z.string()]);
951
- /** The A2UI `weight`: how much of the free space of a Row or Column to take. */
952
- const weightProp = z.number().optional().describe("flex-grow in a Row or Column");
953
- const radiusValue = z.union([
954
- z.enum(RADII),
955
- z.number(),
956
- z.string(),
957
- z.object({
958
- topLeft: z.string().optional(),
959
- topRight: z.string().optional(),
960
- bottomLeft: z.string().optional(),
961
- bottomRight: z.string().optional()
962
- })
963
- ]);
964
- /**
965
- * The layout props of every container. Spread them into a props schema:
966
- * `z.object({ ...layoutProps, variant: ... })`. The children of a container
967
- * are a slot, not a prop.
968
- */
969
- const layoutProps = {
970
- align: z.enum(ALIGN).optional(),
971
- justify: z.enum(JUSTIFY).optional(),
972
- wrap: z.enum(WRAP).optional(),
973
- gap: sizeValue.optional().describe("4px steps when a number"),
974
- rowGap: sizeValue.optional(),
975
- columnGap: sizeValue.optional(),
976
- padding: sizeValue.optional().describe("4px steps when a number"),
977
- background: z.string().optional().describe("Leave it unset. A surface token such as surface, surface-secondary, info, success, warning, danger, discovery, or one with -solid, or a CSS color. Only one summary panel in a Card uses \"surface-secondary\""),
978
- border: z.boolean().optional(),
979
- borderColor: z.enum(BORDER_COLORS).optional(),
980
- radius: radiusValue.optional(),
981
- width: sizeValue.optional(),
982
- height: sizeValue.optional(),
983
- minWidth: sizeValue.optional(),
984
- maxWidth: sizeValue.optional(),
985
- minHeight: sizeValue.optional(),
986
- maxHeight: sizeValue.optional(),
987
- flex: z.number().optional(),
988
- weight: weightProp,
989
- aspectRatio: z.string().optional(),
990
- scrollable: z.boolean().optional(),
991
- clip: z.boolean().optional(),
992
- shadow: z.boolean().optional(),
993
- inline: z.boolean().optional(),
994
- role: z.string().optional().describe("ARIA role"),
995
- flush: z.boolean().optional().describe("No padding"),
996
- minSize: sizeValue.optional().describe("Minimum width and height"),
997
- maxSize: sizeValue.optional().describe("Maximum width and height"),
998
- disableAutoSpacing: z.boolean().optional().describe("No default gap between children")
286
+ //#region src/generative-ui/standard/markdown.tsx
287
+ const SAFE_URL = /^(https?:|mailto:)/i;
288
+ /** The trimmed URL when it is http, https or mailto. Else `undefined`. */
289
+ function safeHref(url) {
290
+ const trimmed = url.trim();
291
+ return SAFE_URL.test(trimmed) ? trimmed : void 0;
292
+ }
293
+ /** Hides text on screen but keeps it for screen readers. */
294
+ const VISUALLY_HIDDEN$1 = {
295
+ position: "absolute",
296
+ width: 1,
297
+ height: 1,
298
+ padding: 0,
299
+ margin: -1,
300
+ overflow: "hidden",
301
+ clipPath: "inset(50%)",
302
+ whiteSpace: "nowrap",
303
+ border: 0
999
304
  };
1000
- const layoutSchema = z.object(layoutProps);
1001
- /** The arguments of a click or visibility event: none. */
1002
- const NO_ARGS$3 = z.object({});
1003
305
  /**
1004
- * The `onVisible` event of every container: sent once, the first time the
1005
- * container scrolls into view.
306
+ * A link that opens in a new tab. Screen readers also hear that it opens a
307
+ * new tab.
1006
308
  */
1007
- const VISIBLE_EVENT = { onVisible: {
1008
- description: "Sent once, the first time the container scrolls into view. Use it to load more content lazily.",
1009
- parameters: NO_ARGS$3
1010
- } };
1011
- /** The slot of every container: a list of children or a template. */
1012
- const CHILDREN_SLOT = { children: "multiple" };
1013
- const boxSchema = z.object({
1014
- ...layoutProps,
1015
- direction: z.enum(["col", "row"]).optional().describe("Default \"col\"")
1016
- });
1017
- const gridSchema = z.object({
1018
- ...layoutProps,
1019
- columns: z.union([z.number(), z.string()]).optional().describe("Column count or CSS template. Default 2"),
1020
- minChildWidth: sizeValue.optional(),
1021
- rows: z.union([z.number(), z.string()]).optional()
1022
- });
1023
- const gridItemSchema = z.object({
1024
- ...layoutProps,
1025
- span: z.number().optional(),
1026
- rowSpan: z.number().optional()
1027
- });
1028
- const cardSchema = z.object({
1029
- ...layoutProps,
1030
- variant: z.enum([
1031
- "default",
1032
- "outline",
1033
- "section",
1034
- "soft",
1035
- "elevated",
1036
- "transparent"
1037
- ]).optional(),
1038
- shadowStyle: z.enum([
1039
- "none",
1040
- "sm",
1041
- "md"
1042
- ]).optional().describe("Overrides the shadow of the variant"),
1043
- size: z.enum([
1044
- "sm",
1045
- "md",
1046
- "lg"
1047
- ]).optional().describe("The padding preset: 8, 16 or 24px. Default \"md\"")
1048
- });
1049
- const flowSchema = z.object({
1050
- ...layoutProps,
1051
- columns: z.number().optional(),
1052
- rows: z.number().optional(),
1053
- layout: z.enum(["pack", "fixed"]).optional().describe("Default \"pack\"")
1054
- });
1055
- const flowItemSchema = z.object({
1056
- ...layoutProps,
1057
- span: z.number().optional(),
1058
- rowSpan: z.number().optional(),
1059
- aspectRatio: z.string().optional().describe("Default \"1 / 1\""),
1060
- aspectMode: z.enum(["soft", "fixed"]).optional()
1061
- });
1062
- const carouselSchema = z.object({
1063
- ...layoutProps,
1064
- label: z.string().optional().describe("A short name of the carousel for screen readers"),
1065
- visibleItems: z.number().optional(),
1066
- showArrows: z.boolean().optional().describe("Default true"),
1067
- activeIndex: z.number().optional().describe("The index of the slide in view. Bind it with { \"@path\": \"/x\" } to read or set it"),
1068
- previousLabel: z.string().optional().describe("Default \"Previous\""),
1069
- nextLabel: z.string().optional().describe("Default \"Next\""),
1070
- snap: z.enum([
1071
- "none",
1072
- "proximity",
1073
- "mandatory"
1074
- ]).optional(),
1075
- snapAlign: z.enum([
1076
- "start",
1077
- "center",
1078
- "end"
1079
- ]).optional()
1080
- });
1081
- const CAROUSEL_MEDIA_SIZES = [
1082
- "sm",
1083
- "md",
1084
- "lg"
309
+ function ExternalLink({ href, title, style, children }) {
310
+ return /* @__PURE__ */ jsxs("a", {
311
+ href,
312
+ title,
313
+ target: "_blank",
314
+ rel: "noopener noreferrer",
315
+ style,
316
+ children: [children, /* @__PURE__ */ jsx("span", {
317
+ style: VISUALLY_HIDDEN$1,
318
+ children: " (opens in a new tab)"
319
+ })]
320
+ });
321
+ }
322
+ const DELIMITERS = [
323
+ {
324
+ open: "**",
325
+ tag: "strong"
326
+ },
327
+ {
328
+ open: "~~",
329
+ tag: "s"
330
+ },
331
+ {
332
+ open: "++",
333
+ tag: "u"
334
+ },
335
+ {
336
+ open: "`",
337
+ tag: "code"
338
+ },
339
+ {
340
+ open: "*",
341
+ tag: "em"
342
+ },
343
+ {
344
+ open: "_",
345
+ tag: "em"
346
+ }
1085
347
  ];
1086
- const carouselMediaItemSchema = z.object({
1087
- ...layoutProps,
1088
- url: z.string().describe("Image URL"),
1089
- description: z.string().optional().describe("What the image shows, for screen readers"),
1090
- size: z.enum(CAROUSEL_MEDIA_SIZES).optional().describe("The width: \"sm\" 160px, \"md\" 240px, \"lg\" 320px. Default \"md\""),
1091
- aspectRatio: z.string().optional().describe("Default \"4 / 3\""),
1092
- href: z.string().optional().describe("Opens this URL in a new tab"),
1093
- lightbox: z.boolean().optional().describe("Default true: a click opens all slides full-screen")
1094
- });
1095
- const spacerSchema = z.object({ minSize: sizeValue.optional() });
1096
- const tabsSchema = z.object({
1097
- tabs: z.array(z.object({
1098
- title: z.string().describe("The tab title"),
1099
- child: child("The id of the panel component")
1100
- })).describe("One entry per tab"),
1101
- selectedIndex: z.number().optional().describe("The open tab. Default 0. Bind it with { \"@path\": \"/x\" } to read it"),
1102
- weight: weightProp
1103
- });
1104
- const dividerSchema = z.object({
1105
- axis: z.enum(["horizontal", "vertical"]).optional().describe("Default \"horizontal\""),
1106
- weight: weightProp,
1107
- color: z.enum(BORDER_COLORS).optional(),
1108
- size: z.number().optional(),
1109
- spacing: sizeValue.optional(),
1110
- flush: z.boolean().optional()
1111
- });
348
+ /** The link that starts at `start` (`[label](url)`), or `null`. */
349
+ function matchLink(text, start) {
350
+ if (text[start] !== "[") return null;
351
+ const close = text.indexOf("](", start + 1);
352
+ if (close < 0) return null;
353
+ const end = text.indexOf(")", close + 2);
354
+ if (end < 0) return null;
355
+ let urlEnd = end;
356
+ if (text.slice(close + 2, end).includes("(")) {
357
+ const next = text.indexOf(")", end + 1);
358
+ if (next < 0) return null;
359
+ urlEnd = next;
360
+ }
361
+ return {
362
+ label: text.slice(start + 1, close),
363
+ url: text.slice(close + 2, urlEnd),
364
+ next: urlEnd + 1
365
+ };
366
+ }
367
+ /**
368
+ * Renders a small set of inline markdown: `**bold**`, `*italic*` and
369
+ * `_italic_`, `~~strike~~`, `++underline++`, `` `code` `` and
370
+ * `[label](url)`.
371
+ *
372
+ * - A marker without a closing partner stays literal text.
373
+ * - A link is a link only for http, https and mailto URLs. For other URLs,
374
+ * only the label shows.
375
+ * - Marks do not nest.
376
+ *
377
+ * @param text - The source text.
378
+ */
379
+ function renderInlineMarkdown(text) {
380
+ if (!text) return text;
381
+ const out = [];
382
+ let buffer = "";
383
+ let key = 0;
384
+ const flush = () => {
385
+ if (buffer) out.push(buffer);
386
+ buffer = "";
387
+ };
388
+ let index = 0;
389
+ while (index < text.length) {
390
+ const link = matchLink(text, index);
391
+ if (link) {
392
+ flush();
393
+ const href = safeHref(link.url);
394
+ out.push(href ? /* @__PURE__ */ jsx(ExternalLink, {
395
+ href,
396
+ children: link.label
397
+ }, key++) : /* @__PURE__ */ jsx(React.Fragment, { children: link.label }, key++));
398
+ index = link.next;
399
+ continue;
400
+ }
401
+ const delimiter = DELIMITERS.find((d) => text.startsWith(d.open, index));
402
+ const isIntraWordUnderscore = delimiter?.open === "_" && /\w/.test(text[index - 1] ?? "");
403
+ if (delimiter && !isIntraWordUnderscore) {
404
+ const start = index + delimiter.open.length;
405
+ const end = text.indexOf(delimiter.open, start);
406
+ const inner = end > start ? text.slice(start, end) : "";
407
+ if (inner !== "" && (delimiter.tag === "code" || inner.trim() === inner)) {
408
+ flush();
409
+ const Tag = delimiter.tag;
410
+ out.push(/* @__PURE__ */ jsx(Tag, { children: inner }, key++));
411
+ index = end + delimiter.open.length;
412
+ continue;
413
+ }
414
+ buffer += delimiter.open;
415
+ index = start;
416
+ continue;
417
+ }
418
+ buffer += text[index];
419
+ index += 1;
420
+ }
421
+ flush();
422
+ return out.length === 1 && typeof out[0] === "string" ? out[0] : out;
423
+ }
424
+ /**
425
+ * Full GitHub-flavored markdown, rendered with the same markdown renderer
426
+ * as the chat messages. It has no typography of its own, so it reads like
427
+ * the chat text around the surface. While `streaming` is true, the renderer
428
+ * handles markdown that is not complete yet.
429
+ */
430
+ function Markdown({ text, streaming = false }) {
431
+ useStandardStyles();
432
+ return /* @__PURE__ */ jsx("div", {
433
+ className: "a2ui-markdown",
434
+ "data-a2ui-std": "",
435
+ children: /* @__PURE__ */ jsx(ProviderMarkdown, {
436
+ content: text,
437
+ isStreaming: streaming
438
+ })
439
+ });
440
+ }
441
+
442
+ //#endregion
443
+ //#region src/generative-ui/standard/layout.tsx
1112
444
  const ALIGN_CSS$1 = {
1113
445
  start: "flex-start",
1114
446
  end: "flex-end",
@@ -1768,487 +1100,83 @@ function Tabs(props) {
1768
1100
  background: "transparent",
1769
1101
  color: isSelected ? textColor("default") : textColor("secondary"),
1770
1102
  font: "inherit",
1771
- fontWeight: 500,
1772
- cursor: "pointer"
1773
- },
1774
- children: tab.title
1775
- }, `${tab.title}-${index}`);
1776
- })
1777
- }), tabs.map((tab, index) => index === selected ? /* @__PURE__ */ jsx("div", {
1778
- role: "tabpanel",
1779
- id: `${id}-panel-${index}`,
1780
- "aria-labelledby": `${id}-tab-${index}`,
1781
- style: {
1782
- display: "flex",
1783
- flexDirection: "column",
1784
- gap: spacing(3)
1785
- },
1786
- children: tab.child
1787
- }, index) : null)]
1788
- });
1789
- }
1790
- function Spacer(props) {
1791
- return /* @__PURE__ */ jsx("div", {
1792
- "aria-hidden": "true",
1793
- style: {
1794
- flex: 1,
1795
- minWidth: spacing(props.minSize ?? 2),
1796
- minHeight: spacing(props.minSize ?? 2)
1797
- }
1798
- });
1799
- }
1800
- function Divider(props) {
1801
- const line = `${props.size ?? 1}px solid ${borderColor(props.color ?? "subtle")}`;
1802
- const margin = props.flush ? 0 : spacing(props.spacing ?? 2);
1803
- const isVertical = props.axis === "vertical";
1804
- return /* @__PURE__ */ jsx("hr", {
1805
- "aria-orientation": isVertical ? "vertical" : void 0,
1806
- style: {
1807
- border: 0,
1808
- ...isVertical ? {
1809
- borderLeft: line,
1810
- margin: `0 ${margin}`,
1811
- height: "auto"
1812
- } : {
1813
- borderTop: line,
1814
- margin: `${margin} 0`,
1815
- width: "100%"
1816
- },
1817
- flexShrink: 0,
1818
- flexGrow: props.weight,
1819
- alignSelf: "stretch"
1820
- }
1821
- });
1822
- }
1823
- /**
1824
- * The standard layout components: containers, Spacer and Divider. Give
1825
- * them to `createGenerativeUI({ components: { ...layoutComponents } })`.
1826
- * Every container has a "multiple" `children` slot, so it takes a list of
1827
- * child ids or a template `{ componentId, path }`.
1828
- */
1829
- const layoutComponents = {
1830
- Box: {
1831
- component: Box,
1832
- description: "A flex container. It stacks its children in a column (direction \"row\" puts them in a row). Use it to group children with gap, padding, border, radius or background.",
1833
- props: boxSchema,
1834
- events: VISIBLE_EVENT,
1835
- slots: CHILDREN_SLOT
1836
- },
1837
- Column: {
1838
- component: Column,
1839
- description: "A vertical flex container. Its default gap already separates sections, so do not add padding, background or a Spacer for space.",
1840
- props: layoutSchema,
1841
- events: VISIBLE_EVENT,
1842
- slots: CHILDREN_SLOT
1843
- },
1844
- Row: {
1845
- component: Row,
1846
- description: "A horizontal flex container. Label and value pair: justify \"spaceBetween\", a Caption left and a Text with fontWeight \"medium\" right. Buttons go in a Row at the bottom of a Card: one variant \"primary\", the others default or \"borderless\".",
1847
- props: layoutSchema,
1848
- events: VISIBLE_EVENT,
1849
- slots: CHILDREN_SLOT
1850
- },
1851
- Grid: {
1852
- component: Grid,
1853
- description: "A CSS grid container. On a narrow screen, its columns collapse towards one column.",
1854
- props: gridSchema,
1855
- events: VISIBLE_EVENT,
1856
- slots: CHILDREN_SLOT
1857
- },
1858
- GridItem: {
1859
- component: GridItem,
1860
- description: "A cell of a Grid, with an optional span. A span that covers all rendered columns fills the row.",
1861
- props: gridItemSchema,
1862
- events: VISIBLE_EVENT,
1863
- slots: CHILDREN_SLOT
1864
- },
1865
- Card: {
1866
- component: Card,
1867
- description: "A bordered panel, only for an interactive panel (controls, a form, a configurator); tables, charts and text need none. Give it a Title and a Caption. Separate groups with a Divider or the gap, never a nested Card or bordered Box. Variant \"section\": no box; \"outline\": always a box. In markdown mode, without controls it renders as \"section\" unless variant or border is set.",
1868
- props: cardSchema,
1869
- events: VISIBLE_EVENT,
1870
- slots: {
1871
- child: "single",
1872
- children: "multiple"
1873
- }
1874
- },
1875
- Flow: {
1876
- component: Flow,
1877
- description: "A masonry-like grid that packs cells of different sizes. Put FlowItem children in it.",
1878
- props: flowSchema,
1879
- events: VISIBLE_EVENT,
1880
- slots: CHILDREN_SLOT
1881
- },
1882
- FlowItem: {
1883
- component: FlowItem,
1884
- description: "A cell of a Flow, with an optional span.",
1885
- props: flowItemSchema,
1886
- events: VISIBLE_EVENT,
1887
- slots: CHILDREN_SLOT
1888
- },
1889
- Carousel: {
1890
- component: Carousel,
1891
- description: "A horizontally scrolling row that snaps to its CarouselItem or CarouselMediaItem children, with arrows. Bind activeIndex to read or set the slide in view.",
1892
- props: carouselSchema,
1893
- events: VISIBLE_EVENT,
1894
- slots: CHILDREN_SLOT,
1895
- writable: ["activeIndex"]
1896
- },
1897
- CarouselItem: {
1898
- component: CarouselItem,
1899
- description: "A slide of a Carousel.",
1900
- props: layoutSchema,
1901
- events: VISIBLE_EVENT,
1902
- slots: CHILDREN_SLOT
1903
- },
1904
- CarouselMediaItem: {
1905
- component: CarouselMediaItem,
1906
- description: "A Carousel slide: an image with its children (a Caption, a Text) under it. size \"sm\" 160px, \"md\" 240px (default), \"lg\" 320px wide. A click opens all slides full-screen, unless href or onClick is set.",
1907
- props: carouselMediaItemSchema,
1908
- events: {
1909
- ...VISIBLE_EVENT,
1910
- onClick: {
1911
- description: "Sent when the user clicks the image. It replaces the full-screen view.",
1912
- parameters: NO_ARGS$3
1913
- }
1914
- },
1915
- slots: CHILDREN_SLOT
1916
- },
1917
- Spacer: {
1918
- component: Spacer,
1919
- description: "Flexible empty space. You almost never need it: use the default gap.",
1920
- props: spacerSchema
1921
- },
1922
- Divider: {
1923
- component: Divider,
1924
- description: "A line between two groups: horizontal, or vertical with axis \"vertical\" in a Row.",
1925
- props: dividerSchema
1926
- },
1927
- Tabs: {
1928
- component: Tabs,
1929
- description: "Tabs that show one panel at a time. Each tab has a title and the id of its panel component: \"tabs\":[{\"title\":\"Specs\",\"child\":\"specs\"}].",
1930
- props: tabsSchema,
1931
- writable: ["selectedIndex"]
1932
- }
1933
- };
1934
-
1935
- //#endregion
1936
- //#region src/generative-ui/standard/markdown.tsx
1937
- const SAFE_URL = /^(https?:|mailto:)/i;
1938
- /** The trimmed URL when it is http, https or mailto. Else `undefined`. */
1939
- function safeHref(url) {
1940
- const trimmed = url.trim();
1941
- return SAFE_URL.test(trimmed) ? trimmed : void 0;
1942
- }
1943
- /** Hides text on screen but keeps it for screen readers. */
1944
- const VISUALLY_HIDDEN$1 = {
1945
- position: "absolute",
1946
- width: 1,
1947
- height: 1,
1948
- padding: 0,
1949
- margin: -1,
1950
- overflow: "hidden",
1951
- clipPath: "inset(50%)",
1952
- whiteSpace: "nowrap",
1953
- border: 0
1954
- };
1955
- /**
1956
- * A link that opens in a new tab. Screen readers also hear that it opens a
1957
- * new tab.
1958
- */
1959
- function ExternalLink({ href, title, style, children }) {
1960
- return /* @__PURE__ */ jsxs("a", {
1961
- href,
1962
- title,
1963
- target: "_blank",
1964
- rel: "noopener noreferrer",
1965
- style,
1966
- children: [children, /* @__PURE__ */ jsx("span", {
1967
- style: VISUALLY_HIDDEN$1,
1968
- children: " (opens in a new tab)"
1969
- })]
1970
- });
1971
- }
1972
- const DELIMITERS = [
1973
- {
1974
- open: "**",
1975
- tag: "strong"
1976
- },
1977
- {
1978
- open: "~~",
1979
- tag: "s"
1980
- },
1981
- {
1982
- open: "++",
1983
- tag: "u"
1984
- },
1985
- {
1986
- open: "`",
1987
- tag: "code"
1988
- },
1989
- {
1990
- open: "*",
1991
- tag: "em"
1992
- },
1993
- {
1994
- open: "_",
1995
- tag: "em"
1996
- }
1997
- ];
1998
- /** The link that starts at `start` (`[label](url)`), or `null`. */
1999
- function matchLink(text, start) {
2000
- if (text[start] !== "[") return null;
2001
- const close = text.indexOf("](", start + 1);
2002
- if (close < 0) return null;
2003
- const end = text.indexOf(")", close + 2);
2004
- if (end < 0) return null;
2005
- let urlEnd = end;
2006
- if (text.slice(close + 2, end).includes("(")) {
2007
- const next = text.indexOf(")", end + 1);
2008
- if (next < 0) return null;
2009
- urlEnd = next;
2010
- }
2011
- return {
2012
- label: text.slice(start + 1, close),
2013
- url: text.slice(close + 2, urlEnd),
2014
- next: urlEnd + 1
2015
- };
2016
- }
2017
- /**
2018
- * Renders a small set of inline markdown: `**bold**`, `*italic*` and
2019
- * `_italic_`, `~~strike~~`, `++underline++`, `` `code` `` and
2020
- * `[label](url)`.
2021
- *
2022
- * - A marker without a closing partner stays literal text.
2023
- * - A link is a link only for http, https and mailto URLs. For other URLs,
2024
- * only the label shows.
2025
- * - Marks do not nest.
2026
- *
2027
- * @param text - The source text.
2028
- */
2029
- function renderInlineMarkdown(text) {
2030
- if (!text) return text;
2031
- const out = [];
2032
- let buffer = "";
2033
- let key = 0;
2034
- const flush = () => {
2035
- if (buffer) out.push(buffer);
2036
- buffer = "";
2037
- };
2038
- let index = 0;
2039
- while (index < text.length) {
2040
- const link = matchLink(text, index);
2041
- if (link) {
2042
- flush();
2043
- const href = safeHref(link.url);
2044
- out.push(href ? /* @__PURE__ */ jsx(ExternalLink, {
2045
- href,
2046
- children: link.label
2047
- }, key++) : /* @__PURE__ */ jsx(React.Fragment, { children: link.label }, key++));
2048
- index = link.next;
2049
- continue;
1103
+ fontWeight: 500,
1104
+ cursor: "pointer"
1105
+ },
1106
+ children: tab.title
1107
+ }, `${tab.title}-${index}`);
1108
+ })
1109
+ }), tabs.map((tab, index) => index === selected ? /* @__PURE__ */ jsx("div", {
1110
+ role: "tabpanel",
1111
+ id: `${id}-panel-${index}`,
1112
+ "aria-labelledby": `${id}-tab-${index}`,
1113
+ style: {
1114
+ display: "flex",
1115
+ flexDirection: "column",
1116
+ gap: spacing(3)
1117
+ },
1118
+ children: tab.child
1119
+ }, index) : null)]
1120
+ });
1121
+ }
1122
+ function Spacer(props) {
1123
+ return /* @__PURE__ */ jsx("div", {
1124
+ "aria-hidden": "true",
1125
+ style: {
1126
+ flex: 1,
1127
+ minWidth: spacing(props.minSize ?? 2),
1128
+ minHeight: spacing(props.minSize ?? 2)
2050
1129
  }
2051
- const delimiter = DELIMITERS.find((d) => text.startsWith(d.open, index));
2052
- const isIntraWordUnderscore = delimiter?.open === "_" && /\w/.test(text[index - 1] ?? "");
2053
- if (delimiter && !isIntraWordUnderscore) {
2054
- const start = index + delimiter.open.length;
2055
- const end = text.indexOf(delimiter.open, start);
2056
- const inner = end > start ? text.slice(start, end) : "";
2057
- if (inner !== "" && (delimiter.tag === "code" || inner.trim() === inner)) {
2058
- flush();
2059
- const Tag = delimiter.tag;
2060
- out.push(/* @__PURE__ */ jsx(Tag, { children: inner }, key++));
2061
- index = end + delimiter.open.length;
2062
- continue;
2063
- }
2064
- buffer += delimiter.open;
2065
- index = start;
2066
- continue;
1130
+ });
1131
+ }
1132
+ function Divider(props) {
1133
+ const line = `${props.size ?? 1}px solid ${borderColor(props.color ?? "subtle")}`;
1134
+ const margin = props.flush ? 0 : spacing(props.spacing ?? 2);
1135
+ const isVertical = props.axis === "vertical";
1136
+ return /* @__PURE__ */ jsx("hr", {
1137
+ "aria-orientation": isVertical ? "vertical" : void 0,
1138
+ style: {
1139
+ border: 0,
1140
+ ...isVertical ? {
1141
+ borderLeft: line,
1142
+ margin: `0 ${margin}`,
1143
+ height: "auto"
1144
+ } : {
1145
+ borderTop: line,
1146
+ margin: `${margin} 0`,
1147
+ width: "100%"
1148
+ },
1149
+ flexShrink: 0,
1150
+ flexGrow: props.weight,
1151
+ alignSelf: "stretch"
2067
1152
  }
2068
- buffer += text[index];
2069
- index += 1;
2070
- }
2071
- flush();
2072
- return out.length === 1 && typeof out[0] === "string" ? out[0] : out;
1153
+ });
2073
1154
  }
2074
1155
  /**
2075
- * Full GitHub-flavored markdown, rendered with the same markdown renderer
2076
- * as the chat messages. It has no typography of its own, so it reads like
2077
- * the chat text around the surface. While `streaming` is true, the renderer
2078
- * handles markdown that is not complete yet.
1156
+ * The standard layout components: containers, Spacer and Divider. Give
1157
+ * them to `createGenerativeUI({ components: { ...layoutComponents } })`.
1158
+ * Every container has a "multiple" `children` slot, so it takes a list of
1159
+ * child ids or a template `{ componentId, path }`.
2079
1160
  */
2080
- function Markdown({ text, streaming = false }) {
2081
- useStandardStyles();
2082
- return /* @__PURE__ */ jsx("div", {
2083
- className: "a2ui-markdown",
2084
- "data-a2ui-std": "",
2085
- children: /* @__PURE__ */ jsx(ProviderMarkdown, {
2086
- content: text,
2087
- isStreaming: streaming
2088
- })
2089
- });
2090
- }
1161
+ const layoutComponents = withComponents(layoutDeclarations, {
1162
+ Box,
1163
+ Column,
1164
+ Row,
1165
+ Grid,
1166
+ GridItem,
1167
+ Card,
1168
+ Flow,
1169
+ FlowItem,
1170
+ Carousel,
1171
+ CarouselItem,
1172
+ CarouselMediaItem,
1173
+ Spacer,
1174
+ Divider,
1175
+ Tabs
1176
+ });
2091
1177
 
2092
1178
  //#endregion
2093
1179
  //#region src/generative-ui/standard/media.tsx
2094
- const NO_ARGS$2 = z.object({});
2095
- const colorProp$1 = z.string().optional();
2096
- const ICON_SIZES = [
2097
- "sm",
2098
- "md",
2099
- "lg",
2100
- "xl"
2101
- ];
2102
- const imageSchema = z.object({
2103
- url: z.string().describe("Image URL"),
2104
- description: z.string().optional().describe("What the image shows, for screen readers. Leave it unset only for a decorative image"),
2105
- variant: z.enum([
2106
- "icon",
2107
- "avatar",
2108
- "smallFeature",
2109
- "mediumFeature",
2110
- "largeFeature",
2111
- "header"
2112
- ]).optional().describe("The size: \"icon\" 24px, \"avatar\" 40px round, \"smallFeature\" 160px wide, \"largeFeature\" and \"header\" full width. Default \"mediumFeature\": the natural size"),
2113
- weight: weightProp,
2114
- aspectRatio: z.string().optional(),
2115
- fit: z.enum([
2116
- "cover",
2117
- "contain",
2118
- "fill",
2119
- "none",
2120
- "scaleDown"
2121
- ]).optional().describe("CSS object-fit. Default \"cover\""),
2122
- radius: radiusValue.optional(),
2123
- width: sizeValue.optional(),
2124
- height: sizeValue.optional(),
2125
- maxWidth: sizeValue.optional(),
2126
- maxHeight: sizeValue.optional(),
2127
- minWidth: sizeValue.optional(),
2128
- minHeight: sizeValue.optional(),
2129
- background: z.string().optional(),
2130
- frame: z.boolean().optional(),
2131
- position: z.string().optional().describe("CSS object-position, for example \"top\" or \"50% 20%\""),
2132
- hideOnFailure: z.boolean().optional().describe("Default false"),
2133
- fallback: z.string().optional().describe("Text shown in place of the image when it does not load"),
2134
- hoverZoom: z.boolean().optional().describe("A slight zoom on hover"),
2135
- lightbox: z.boolean().optional().describe("Default true: a click opens the image full-screen"),
2136
- actionOverlay: z.object({
2137
- label: z.string(),
2138
- icon: z.string().optional().describe("Lucide icon name"),
2139
- href: z.string().optional().describe("Opens this URL in a new tab")
2140
- }).optional().describe("A button over the bottom-right corner of the image. Without href, it sends onOverlayClick")
2141
- });
2142
- const iconSchema = z.object({
2143
- name: z.union([z.string(), z.object({ svgPath: z.string() })]).describe("A Lucide icon name in kebab-case (\"arrow-right\"), an A2UI icon name (\"arrowBack\"), or { \"svgPath\" } on a 24px grid"),
2144
- label: z.string().optional().describe("What the icon means, for screen readers. Leave it unset when text next to the icon says the same"),
2145
- size: z.union([z.enum(ICON_SIZES), z.number()]).optional().describe("Default \"md\""),
2146
- color: colorProp$1,
2147
- inline: z.boolean().optional().describe("Default false"),
2148
- strokeWeight: z.enum(WEIGHTS).optional().describe("The stroke width"),
2149
- weight: weightProp
2150
- });
2151
- const faviconSchema = z.object({
2152
- url: z.string(),
2153
- alt: z.string().optional(),
2154
- size: z.number().optional().describe("Pixels. Default 16"),
2155
- inline: z.boolean().optional().describe("Default false"),
2156
- frame: z.boolean().optional().describe("Default false")
2157
- });
2158
- const svgSchema = z.object({
2159
- viewBox: z.string().optional(),
2160
- label: z.string().optional().describe("What the drawing shows, for screen readers. Leave it unset for a decorative drawing"),
2161
- width: sizeValue.optional(),
2162
- height: sizeValue.optional(),
2163
- size: sizeValue.optional(),
2164
- color: colorProp$1.describe("Default \"prose\""),
2165
- fill: colorProp$1.describe("Default \"currentColor\""),
2166
- stroke: colorProp$1,
2167
- strokeWidth: z.number().optional(),
2168
- strokeLinecap: z.enum([
2169
- "butt",
2170
- "round",
2171
- "square"
2172
- ]).optional(),
2173
- strokeLinejoin: z.enum([
2174
- "miter",
2175
- "round",
2176
- "bevel"
2177
- ]).optional(),
2178
- preserveAspectRatio: z.string().optional(),
2179
- paths: z.array(z.object({
2180
- d: z.string(),
2181
- fill: colorProp$1,
2182
- stroke: colorProp$1,
2183
- strokeWidth: z.number().optional()
2184
- })).optional(),
2185
- circles: z.array(z.object({
2186
- cx: z.number(),
2187
- cy: z.number(),
2188
- r: z.number(),
2189
- fill: colorProp$1,
2190
- stroke: colorProp$1
2191
- })).optional(),
2192
- rects: z.array(z.object({
2193
- x: z.number(),
2194
- y: z.number(),
2195
- width: z.number(),
2196
- height: z.number(),
2197
- rx: z.number().optional(),
2198
- fill: colorProp$1,
2199
- stroke: colorProp$1
2200
- })).optional(),
2201
- lines: z.array(z.object({
2202
- x1: z.number(),
2203
- y1: z.number(),
2204
- x2: z.number(),
2205
- y2: z.number(),
2206
- stroke: colorProp$1
2207
- })).optional(),
2208
- texts: z.array(z.object({
2209
- x: z.number(),
2210
- y: z.number(),
2211
- text: z.string(),
2212
- size: z.number().optional(),
2213
- fill: colorProp$1,
2214
- anchor: z.enum([
2215
- "start",
2216
- "middle",
2217
- "end"
2218
- ]).optional()
2219
- })).optional()
2220
- });
2221
- const captionTrack = z.object({
2222
- url: z.string().describe("The URL of a WebVTT file"),
2223
- language: z.string().optional().describe("BCP 47, for example \"en\""),
2224
- label: z.string().optional().describe("Shown in the captions menu"),
2225
- kind: z.enum([
2226
- "subtitles",
2227
- "captions",
2228
- "descriptions"
2229
- ]).optional()
2230
- });
2231
- const videoSchema = z.object({
2232
- url: z.string().describe("The URL of a video file, or of a YouTube video or short. A page on another video site shows as a link"),
2233
- posterUrl: z.string().optional().describe("The image shown before the video plays"),
2234
- title: z.string().optional().describe("Names the video for screen readers"),
2235
- captions: z.array(captionTrack).optional().describe("Caption tracks of a video file"),
2236
- aspectRatio: z.string().optional().describe("Default \"16 / 9\""),
2237
- width: sizeValue.optional().describe("Default \"100%\""),
2238
- maxWidth: sizeValue.optional().describe("Default \"100%\""),
2239
- weight: weightProp
2240
- });
2241
- const audioPlayerSchema = z.object({
2242
- url: z.string().describe("The URL of the audio file"),
2243
- description: z.string().optional().describe("A title or summary of the audio, shown above the player"),
2244
- weight: weightProp
2245
- });
2246
- const htmlViewSchema = z.object({
2247
- html: z.string(),
2248
- height: sizeValue.optional().describe("Pixels when a number. Default 360"),
2249
- width: sizeValue.optional().describe("Default \"100%\""),
2250
- title: z.string().optional()
2251
- });
2252
1180
  /** Pixels when a number, raw CSS when a string. */
2253
1181
  function px$1(value) {
2254
1182
  if (value === void 0) return void 0;
@@ -2971,133 +1899,18 @@ function HtmlView(props) {
2971
1899
  * The standard media components. Give them to
2972
1900
  * `createGenerativeUI({ components: { ...mediaComponents } })`.
2973
1901
  */
2974
- const mediaComponents = {
2975
- Image: {
2976
- component: Image,
2977
- description: "An image from a URL. A click opens it full-screen. Set description to say what the image shows, unless it is only decoration.",
2978
- props: imageSchema,
2979
- events: { onOverlayClick: {
2980
- description: "Sent when the user clicks the actionOverlay button and it has no href.",
2981
- parameters: NO_ARGS$2
2982
- } }
2983
- },
2984
- Icon: {
2985
- component: Icon,
2986
- description: "A Lucide icon by kebab-case name (for example \"arrow-right\"), or an A2UI icon name (for example \"arrowBack\"). Set label when no text next to the icon says what it means.",
2987
- props: iconSchema
2988
- },
2989
- Favicon: {
2990
- component: Favicon,
2991
- description: "The favicon of the site at a URL.",
2992
- props: faviconSchema
2993
- },
2994
- Svg: {
2995
- component: Svg,
2996
- description: "A vector drawing from primitive shapes (paths, circles, rects, lines, texts). Colors take text color tokens or CSS colors.",
2997
- props: svgSchema
2998
- },
2999
- Video: {
3000
- component: Video,
3001
- description: "A video file URL (optional captions) or a YouTube link, privacy-enhanced: the poster shows until play. Other video sites show as a link. Set title.",
3002
- props: videoSchema
3003
- },
3004
- AudioPlayer: {
3005
- component: AudioPlayer,
3006
- description: "An audio player for an audio file URL, with the description above it.",
3007
- props: audioPlayerSchema
3008
- },
3009
- HtmlView: {
3010
- component: HtmlView,
3011
- description: "Raw HTML in a fully sandboxed iframe: no scripts, no same-origin access. Set title to name the content.",
3012
- props: htmlViewSchema
3013
- }
3014
- };
1902
+ const mediaComponents = withComponents(mediaDeclarations, {
1903
+ Image,
1904
+ Icon,
1905
+ Favicon,
1906
+ Svg,
1907
+ Video,
1908
+ AudioPlayer,
1909
+ HtmlView
1910
+ });
3015
1911
 
3016
1912
  //#endregion
3017
1913
  //#region src/generative-ui/standard/composites.tsx
3018
- /**
3019
- * The composite components: the prebuilt widgets that sit next to
3020
- * its primitives (LinkCard, Citation, FollowUp pills, entity cards, image
3021
- * grids). Each one is a single component, so the model places it with one
3022
- * object instead of eight primitives.
3023
- */
3024
- const NO_ARGS$1 = z.object({});
3025
- const text = (description) => z.string().optional().describe(description);
3026
- const linkCardSchema = z.object({
3027
- href: z.string().describe("The URL (http, https)"),
3028
- title: z.string().describe("The page title"),
3029
- description: text("One or two lines"),
3030
- image: text("A thumbnail URL"),
3031
- domain: text("Shown next to the favicon. Default: the host of href"),
3032
- favicon: z.boolean().optional().describe("Default true")
3033
- });
3034
- const citationSchema = z.object({
3035
- index: z.number().optional().describe("The marker number. Default 1"),
3036
- label: text("Marker text instead of the number, for example a domain"),
3037
- title: text("The source title"),
3038
- url: text("The source URL (http, https)"),
3039
- snippet: text("The quoted passage, one or two lines"),
3040
- source: text("The publisher or domain. Default: the host of url")
3041
- });
3042
- const followUpItem = z.union([z.string(), z.object({
3043
- label: z.string(),
3044
- message: text("The text sent when the user clicks. Default: label")
3045
- })]);
3046
- const followUpSchema = z.object({
3047
- items: z.array(followUpItem).optional(),
3048
- title: text("A caption above the pills")
3049
- });
3050
- const followUpArgs = z.object({ message: z.string().describe("The message of the clicked pill") });
3051
- const BADGE_COLORS = [
3052
- "secondary",
3053
- "success",
3054
- "danger",
3055
- "warning",
3056
- "info",
3057
- "discovery"
3058
- ];
3059
- const cardAction = z.object({
3060
- label: z.string(),
3061
- href: text("Opens this URL in a new tab"),
3062
- variant: z.enum([
3063
- "solid",
3064
- "soft",
3065
- "outline",
3066
- "ghost"
3067
- ]).optional()
3068
- });
3069
- const entityCardSchema = z.object({
3070
- title: z.string().describe("The name"),
3071
- subtitle: text("A second line, for example the brand or category"),
3072
- description: text("Up to three lines"),
3073
- image: text("An image URL"),
3074
- imageAspectRatio: z.string().optional().describe("Default \"4 / 3\""),
3075
- meta: text("A short fact line, for example \"$29 / month\" or \"Open until 22:00\""),
3076
- badge: z.object({
3077
- label: z.string(),
3078
- color: z.enum(BADGE_COLORS).optional()
3079
- }).optional(),
3080
- rating: z.number().optional().describe("0 to 5, shown as stars"),
3081
- ratingCount: z.number().optional().describe("The number of ratings"),
3082
- href: text("Opens this URL in a new tab when the user clicks the card"),
3083
- actions: z.array(cardAction).max(3).optional().describe("Up to three buttons. A button without href sends onAction with its label"),
3084
- layout: z.enum(["vertical", "horizontal"]).optional().describe("Default \"vertical\". \"horizontal\" puts the image on the left"),
3085
- width: sizeValue.optional()
3086
- });
3087
- const entityActionArgs = z.object({ label: z.string().describe("The label of the clicked button") });
3088
- const gridImage = z.object({
3089
- url: z.string(),
3090
- description: z.string().optional().describe("What the image shows"),
3091
- caption: z.string().optional(),
3092
- href: text("Opens this URL instead of the full-screen view")
3093
- });
3094
- const imageGridSchema = z.object({
3095
- images: z.array(gridImage).optional(),
3096
- columns: z.number().optional().describe("Default 3"),
3097
- aspectRatio: z.string().optional().describe("Default \"1 / 1\""),
3098
- gap: sizeValue.optional().describe("Default 2"),
3099
- layout: z.enum(["grid", "bento"]).optional().describe("Default \"grid\". \"bento\" makes the first image twice as large")
3100
- });
3101
1914
  function FaviconImage({ host, size = 16 }) {
3102
1915
  return /* @__PURE__ */ jsx("img", {
3103
1916
  src: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(host)}&sz=64`,
@@ -3669,101 +2482,16 @@ function ImageGrid(props) {
3669
2482
  * engine turns it into a visible user message with that text.
3670
2483
  * - EntityCard buttons without href send `onAction` with their label.
3671
2484
  */
3672
- const compositeComponents = {
3673
- LinkCard: {
3674
- component: LinkCard,
3675
- description: "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.",
3676
- props: linkCardSchema,
3677
- events: { onClick: {
3678
- description: "Sent when the user clicks the card, instead of the link.",
3679
- parameters: NO_ARGS$1
3680
- } }
3681
- },
3682
- Citation: {
3683
- component: Citation,
3684
- description: "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.",
3685
- props: citationSchema
3686
- },
3687
- FollowUp: {
3688
- component: FollowUp,
3689
- description: "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.",
3690
- props: followUpSchema,
3691
- events: { onFollowUp: {
3692
- description: "Sent when the user clicks a pill. The args carry the message of the pill.",
3693
- parameters: followUpArgs
3694
- } }
3695
- },
3696
- EntityCard: {
3697
- component: EntityCard,
3698
- description: "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.",
3699
- props: entityCardSchema,
3700
- events: {
3701
- onClick: {
3702
- description: "Sent when the user clicks the card and it has no href.",
3703
- parameters: NO_ARGS$1
3704
- },
3705
- onAction: {
3706
- description: "Sent when the user clicks a button without href. The args carry the label of the button.",
3707
- parameters: entityActionArgs
3708
- }
3709
- }
3710
- },
3711
- ImageGrid: {
3712
- component: ImageGrid,
3713
- description: "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.",
3714
- props: imageGridSchema
3715
- }
3716
- };
2485
+ const compositeComponents = withComponents(compositeDeclarations, {
2486
+ LinkCard,
2487
+ Citation,
2488
+ FollowUp,
2489
+ EntityCard,
2490
+ ImageGrid
2491
+ });
3717
2492
 
3718
2493
  //#endregion
3719
2494
  //#region src/generative-ui/standard/Chart.tsx
3720
- const chartSeries = z.union([z.string(), z.object({
3721
- key: z.string(),
3722
- label: z.string().optional(),
3723
- color: z.string().optional().describe("A text color token or a CSS color")
3724
- })]);
3725
- const chartSchema = z.object({
3726
- chartType: z.enum([
3727
- "bar",
3728
- "line",
3729
- "area",
3730
- "scatter",
3731
- "pie",
3732
- "donut"
3733
- ]).optional().describe("Default \"bar\""),
3734
- data: z.array(z.record(z.string(), z.unknown())).optional(),
3735
- xKey: z.string().optional().describe("The field of the category axis"),
3736
- series: z.array(chartSeries).optional().describe("Default: every number field except xKey"),
3737
- stacked: z.boolean().optional(),
3738
- layout: z.enum(["vertical", "horizontal"]).optional().describe("\"horizontal\" draws the bars from left to right. Default \"vertical\""),
3739
- yAxis: z.object({
3740
- label: z.string().optional(),
3741
- min: z.number().optional(),
3742
- max: z.number().optional(),
3743
- width: z.number().optional().describe("Pixels")
3744
- }).optional().describe("Example: {label: \"Revenue (USD)\", min: 0, max: 100}. In a horizontal chart it is the horizontal axis, and width sets the category axis width"),
3745
- showDots: z.boolean().optional().describe("Point markers on a line or area"),
3746
- barRadius: z.number().optional().describe("The corner radius of a bar, in pixels"),
3747
- innerRadius: z.union([z.number(), z.string()]).optional().describe("Pie and donut"),
3748
- outerRadius: z.union([z.number(), z.string()]).optional().describe("Pie and donut"),
3749
- startAngle: z.number().optional().describe("Pie and donut. Default 90"),
3750
- endAngle: z.number().optional().describe("Pie and donut. Default -270"),
3751
- cornerRadius: z.number().optional().describe("The corners of a slice"),
3752
- paddingAngle: z.number().optional().describe("The gap between slices"),
3753
- showLabelLines: z.boolean().optional().describe("Leader lines of the slice labels. Default true"),
3754
- height: z.number().optional().describe("Pixels. Default 240"),
3755
- showLegend: z.boolean().optional().describe("Default true"),
3756
- showGrid: z.boolean().optional().describe("Default true"),
3757
- showTooltip: z.boolean().optional().describe("Default true"),
3758
- showValueLabels: z.boolean().optional(),
3759
- format: z.enum([
3760
- "number",
3761
- "currency",
3762
- "percent"
3763
- ]).optional().describe("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."),
3764
- currency: z.string().optional().describe("ISO code. Default \"USD\""),
3765
- title: z.string().optional()
3766
- });
3767
2495
  const DEFAULT_HEIGHT = 240;
3768
2496
  /** Hides an element on screen. Screen readers still read it. */
3769
2497
  const VISUALLY_HIDDEN = {
@@ -4166,24 +2894,6 @@ function Chart(props) {
4166
2894
 
4167
2895
  //#endregion
4168
2896
  //#region src/generative-ui/standard/Map.tsx
4169
- const mapMarker = z.object({
4170
- label: z.string(),
4171
- lat: z.number(),
4172
- lng: z.number(),
4173
- category: z.string().optional(),
4174
- icon: z.string().optional()
4175
- });
4176
- const mapSchema = z.object({
4177
- markers: z.array(mapMarker).optional(),
4178
- route: z.boolean().optional().describe("Draws a line through the markers in order"),
4179
- selected: z.string().optional().describe("The label of the selected marker. Bind it with { \"@path\": \"/x\" } to read the choice of the user"),
4180
- height: z.number().optional().describe("Pixels. Default 240"),
4181
- zoom: z.number().optional().describe("With two or more markers, only the highest zoom of the fit"),
4182
- center: z.object({
4183
- lat: z.number(),
4184
- lng: z.number()
4185
- }).optional()
4186
- });
4187
2897
  /**
4188
2898
  * The default basemap: the Positron style of OpenFreeMap. It is a keyless
4189
2899
  * OpenStreetMap vector style with streets and labels at city zoom. A host
@@ -4480,95 +3190,6 @@ function MapView(props) {
4480
3190
 
4481
3191
  //#endregion
4482
3192
  //#region src/generative-ui/standard/data.tsx
4483
- const cellAlign = z.enum([
4484
- "start",
4485
- "center",
4486
- "end"
4487
- ]).optional();
4488
- /**
4489
- * A table cell or column header that shows another component. `id` is an
4490
- * alias of `componentId`.
4491
- */
4492
- const tableComponentCell = z.union([z.object({ componentId: z.string() }), z.object({ id: z.string() })]);
4493
- const tableColumn = z.union([
4494
- z.string(),
4495
- z.object({
4496
- label: z.string(),
4497
- align: cellAlign,
4498
- width: sizeValue.optional(),
4499
- componentId: z.string().optional()
4500
- }),
4501
- tableComponentCell
4502
- ]);
4503
- const tableSchema = z.object({
4504
- caption: z.string().optional().describe("A short name of the table for screen readers. It is not shown"),
4505
- columns: z.array(tableColumn).optional().describe("Default []"),
4506
- rows: z.array(z.array(z.unknown())).optional().describe("A list of row lists. A cell is a string, a number, or { \"componentId\": \"<id>\" } to show a component. Default []"),
4507
- columnSizing: z.enum(["auto", "equal"]).optional().describe("Default \"auto\""),
4508
- dividers: z.boolean().optional().describe("Default true"),
4509
- stickyHeader: z.boolean().optional().describe("Default false"),
4510
- emptyLabel: z.string().optional().describe("Default \"No rows\"")
4511
- });
4512
- const tableSectionSchema = z.object({
4513
- header: z.boolean().optional().describe("Renders the rows as the header"),
4514
- rowDivider: z.boolean().optional()
4515
- });
4516
- const tableRowSchema = z.object({
4517
- header: z.boolean().optional(),
4518
- label: z.string().optional().describe("The text of a header cell at the start of the row"),
4519
- labelColSpan: z.number().optional().describe("Columns the label cell spans")
4520
- });
4521
- const tableCellSchema = z.object({
4522
- text: z.union([z.string(), z.number()]).optional(),
4523
- header: z.boolean().optional(),
4524
- align: cellAlign,
4525
- vAlign: cellAlign.describe("Default \"start\""),
4526
- colSpan: z.number().optional(),
4527
- rowSpan: z.number().optional(),
4528
- width: sizeValue.optional(),
4529
- padding: sizeValue.optional()
4530
- });
4531
- const listItemValue = z.union([z.string(), z.object({
4532
- label: z.string(),
4533
- description: z.string().optional(),
4534
- icon: z.string().optional().describe("Lucide icon name"),
4535
- value: z.union([z.string(), z.number()]).optional().describe("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")
4536
- })]);
4537
- const listSchema = z.object({
4538
- items: z.array(listItemValue).optional(),
4539
- direction: z.enum(["vertical", "horizontal"]).optional().describe("Default \"vertical\". \"horizontal\" scrolls sideways"),
4540
- align: z.enum([
4541
- "start",
4542
- "center",
4543
- "end",
4544
- "stretch"
4545
- ]).optional(),
4546
- weight: weightProp,
4547
- marker: z.enum([
4548
- "bullet",
4549
- "number",
4550
- "rich",
4551
- "none"
4552
- ]).optional().describe("Default \"bullet\""),
4553
- connector: z.enum(["none", "solid"]).optional().describe("Default \"none\""),
4554
- gap: sizeValue.optional(),
4555
- start: z.number().optional().describe("The first number of marker \"number\""),
4556
- maxMarkerSize: z.number().optional().describe("The width of the marker column in pixels")
4557
- });
4558
- const listItemSchema = z.object({
4559
- label: z.string().optional(),
4560
- value: z.union([z.string(), z.number()]).optional().describe("Without an action: shown on the right of the label, for a key and value fact"),
4561
- description: z.string().optional(),
4562
- icon: z.string().optional().describe("Lucide icon name"),
4563
- marker: z.string().optional().describe("Shows this text as the marker"),
4564
- markerSize: z.number().optional().describe("The width of the marker column in pixels"),
4565
- disabled: z.boolean().optional().describe("Greys the item out and ignores its action")
4566
- });
4567
- const listSelection = z.object({
4568
- index: z.number(),
4569
- label: z.string(),
4570
- value: z.string().optional()
4571
- });
4572
3193
  const TableContext = createContext(null);
4573
3194
  const V_ALIGN = {
4574
3195
  start: "top",
@@ -4986,69 +3607,16 @@ function ListItem(props) {
4986
3607
  * - Map: `selected` is writable, so a `{ "@path" }` binding gets the choice of
4987
3608
  * the user.
4988
3609
  */
4989
- const dataComponents = {
4990
- Table: {
4991
- component: Table,
4992
- description: "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\".",
4993
- props: tableSchema,
4994
- slots: {
4995
- children: "multiple",
4996
- cellComponents: "multiple"
4997
- }
4998
- },
4999
- TableSection: {
5000
- component: TableSection,
5001
- accessibility: "self",
5002
- description: "A group of TableRow children in a Table. With header true, it is the header of the table.",
5003
- props: tableSectionSchema,
5004
- slots: CHILDREN_SLOT
5005
- },
5006
- TableRow: {
5007
- component: TableRow,
5008
- accessibility: "self",
5009
- description: "A row of a Table. Its children are TableCell ids, or a template. With label, a header cell with that text starts the row.",
5010
- props: tableRowSchema,
5011
- slots: CHILDREN_SLOT
5012
- },
5013
- TableCell: {
5014
- component: TableCell,
5015
- accessibility: "self",
5016
- description: "A cell of a TableRow. It shows \"text\", or its children. With header true, it is a header cell.",
5017
- props: tableCellSchema,
5018
- slots: CHILDREN_SLOT
5019
- },
5020
- List: {
5021
- component: List,
5022
- description: "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.",
5023
- props: listSchema,
5024
- events: { action: {
5025
- description: "Runs when the user picks an item. The args are the index, label and value of the item.",
5026
- parameters: listSelection
5027
- } },
5028
- slots: CHILDREN_SLOT
5029
- },
5030
- ListItem: {
5031
- component: ListItem,
5032
- description: "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.",
5033
- props: listItemSchema,
5034
- events: { action: {
5035
- description: "Runs when the user picks the item.",
5036
- parameters: z.object({})
5037
- } },
5038
- slots: CHILDREN_SLOT
5039
- },
5040
- Chart: {
5041
- component: Chart,
5042
- description: "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.",
5043
- props: chartSchema
5044
- },
5045
- Map: {
5046
- component: MapView,
5047
- description: "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.",
5048
- props: mapSchema,
5049
- writable: ["selected"]
5050
- }
5051
- };
3610
+ const dataComponents = withComponents(dataDeclarations, {
3611
+ Table,
3612
+ TableSection,
3613
+ TableRow,
3614
+ TableCell,
3615
+ List,
3616
+ ListItem,
3617
+ Chart,
3618
+ Map: MapView
3619
+ });
5052
3620
 
5053
3621
  //#endregion
5054
3622
  //#region src/generative-ui/standard/feedback.tsx
@@ -5090,41 +3658,6 @@ const BUTTON_RESET = {
5090
3658
  textAlign: "inherit",
5091
3659
  cursor: "pointer"
5092
3660
  };
5093
- const pulseIndicatorSchema = z.object({
5094
- label: z.string().optional().describe("What the dot means, for screen readers. Leave it unset when text next to the dot says the same"),
5095
- color: z.string().optional().describe("Text color token. Default \"success\""),
5096
- size: z.number().optional().describe("Pixels. Default 12"),
5097
- pulseColor: z.string().optional(),
5098
- duration: z.number().optional().describe("Milliseconds. Default 1500"),
5099
- endScale: z.number().optional().describe("Default 2.4"),
5100
- startOpacity: z.number().optional().describe("Default 0.6")
5101
- });
5102
- const flashcardSchema = z.object({
5103
- front: z.string().optional().describe("The text on the front"),
5104
- back: z.string().optional().describe("The text on the back"),
5105
- hint: z.string().optional().describe("A small line under the front, for example \"Click to flip\"")
5106
- });
5107
- const popoverSchema = z.object({
5108
- open: z.boolean().optional().describe("Default false"),
5109
- showOnHover: z.boolean().optional(),
5110
- hoverOpenDelay: z.number().optional().describe("Milliseconds before a hover opens it. Default 0")
5111
- });
5112
- const popoverTriggerSchema = z.object({ block: z.boolean().optional().describe("Full width") });
5113
- const popoverContentSchema = z.object({
5114
- side: z.enum([
5115
- "top",
5116
- "bottom",
5117
- "left",
5118
- "right"
5119
- ]).optional().describe("Default \"bottom\""),
5120
- sideOffset: z.number().optional().describe("Pixels between the trigger and the content. Default 6"),
5121
- align: z.enum([
5122
- "start",
5123
- "center",
5124
- "end"
5125
- ]).optional().describe("Default \"center\""),
5126
- width: sizeValue.optional().describe("4px steps when a number")
5127
- });
5128
3661
  /** A spinning ring. It is decoration: the caller names the status. */
5129
3662
  function PulseIndicator(props) {
5130
3663
  useFeedbackStyles();
@@ -5382,12 +3915,6 @@ function PopoverContent(props) {
5382
3915
  children: props.children
5383
3916
  });
5384
3917
  }
5385
- const modalSchema = z.object({
5386
- title: z.string().optional().describe("The heading of the dialog"),
5387
- open: z.boolean().optional().describe("Default false. Bind it with { \"@path\": \"/x\" } to read it"),
5388
- maxWidth: sizeValue.optional().describe("Default 480"),
5389
- weight: weightProp
5390
- });
5391
3918
  const FOCUSABLE = "a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),iframe,video[controls],audio[controls],[tabindex]:not([tabindex=\"-1\"])";
5392
3919
  /**
5393
3920
  * A control, enabled or not: a disabled Button, or a Pressable (a div with
@@ -5587,107 +4114,18 @@ function Modal(props) {
5587
4114
  * "multiple" `children` slot. Popover `open` is writable, so the component
5588
4115
  * gets a `setOpen` prop.
5589
4116
  */
5590
- const feedbackComponents = {
5591
- PulseIndicator: {
5592
- component: PulseIndicator,
5593
- description: "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.",
5594
- props: pulseIndicatorSchema
5595
- },
5596
- FlashcardFlip: {
5597
- component: FlashcardFlip,
5598
- description: "A card that shows the front text. A click or the Enter key flips it to the back text, and again to the front.",
5599
- props: flashcardSchema
5600
- },
5601
- Popover: {
5602
- component: Popover,
5603
- description: "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.",
5604
- props: popoverSchema,
5605
- slots: CHILDREN_SLOT,
5606
- writable: ["open"]
5607
- },
5608
- PopoverTrigger: {
5609
- component: PopoverTrigger,
5610
- description: "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.",
5611
- props: popoverTriggerSchema,
5612
- slots: CHILDREN_SLOT
5613
- },
5614
- PopoverContent: {
5615
- component: PopoverContent,
5616
- description: "The body of a Popover. It shows only when the Popover is open.",
5617
- props: popoverContentSchema,
5618
- slots: CHILDREN_SLOT
5619
- },
5620
- Modal: {
5621
- component: Modal,
5622
- description: "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.",
5623
- props: modalSchema,
5624
- slots: {
5625
- trigger: "single",
5626
- content: "single"
5627
- },
5628
- writable: ["open"]
5629
- }
5630
- };
4117
+ const feedbackComponents = withComponents(feedbackDeclarations, {
4118
+ PulseIndicator,
4119
+ FlashcardFlip,
4120
+ Popover,
4121
+ PopoverTrigger,
4122
+ PopoverContent,
4123
+ Modal
4124
+ });
5631
4125
 
5632
4126
  //#endregion
5633
4127
  //#region src/generative-ui/standard/checks.ts
5634
4128
  /**
5635
- * The `checks` of the A2UI 1.0 `Checkable` components. The model writes
5636
- * each condition as a validator call or a boolean binding:
5637
- * `{ "condition": { "@call": "email", "args": { "value": { "@path": "/form/email" } } }, "message": "..." }`.
5638
- * The engine resolves the condition before the component renders, so a
5639
- * component sees a boolean or a `ValidationResult`.
5640
- */
5641
- const severity = z.enum([
5642
- "error",
5643
- "warning",
5644
- "info"
5645
- ]);
5646
- const validationResult = z.object({
5647
- valid: z.boolean(),
5648
- message: z.string().optional(),
5649
- code: z.string().optional(),
5650
- severity: severity.optional()
5651
- }).loose();
5652
- const checksProp = z.array(z.object({
5653
- condition: z.union([z.boolean(), validationResult]).optional().describe("A validator call, for example {\"@call\":\"required\",\"args\":{\"value\":{\"@path\":\"/x\"}}}, or a boolean binding"),
5654
- message: z.string().optional().describe("Shown when the check fails, instead of the default message")
5655
- })).optional().describe("Validation rules. The control shows the first failed one");
5656
- /**
5657
- * The failed check to show, or `undefined` when every check passes: the
5658
- * first error, or the first warning or info when no check is an error, so
5659
- * a warning never hides an error that comes after it. A condition that is
5660
- * not known yet (undefined) passes. A `false` condition is an error with
5661
- * the check's message. The check's message also wins over the message of
5662
- * a validator result: the built-in validators always have one, and the
5663
- * check is where the model puts its own wording.
5664
- */
5665
- function firstFailedCheck(checks) {
5666
- let first;
5667
- for (const check of checks ?? []) {
5668
- const { condition } = check;
5669
- if (condition === void 0 || condition === null) continue;
5670
- let failed;
5671
- if (typeof condition === "boolean") {
5672
- if (condition) continue;
5673
- failed = {
5674
- message: check.message ?? "Invalid value",
5675
- severity: "error"
5676
- };
5677
- } else {
5678
- if (condition.valid) continue;
5679
- failed = {
5680
- message: check.message ?? condition.message ?? "Invalid value",
5681
- severity: condition.severity ?? "error",
5682
- ...condition.code === void 0 ? {} : { code: condition.code }
5683
- };
5684
- }
5685
- if (failed.severity === "error") return failed;
5686
- first ??= failed;
5687
- }
5688
- return first;
5689
- }
5690
- /**
5691
4129
  * The check state of a control: the failed check to show, whether the
5692
4130
  * control is invalid, and the blur handler that marks it as touched. The
5693
4131
  * message shows only once the user has been in the control, or when it has
@@ -5705,13 +4143,6 @@ function useChecks(checks, value) {
5705
4143
  onBlur: () => setTouched(true)
5706
4144
  };
5707
4145
  }
5708
- /** The style of a check message, by its severity. */
5709
- function checkMessageStyle(severity) {
5710
- return {
5711
- ...textFont("sm"),
5712
- color: textColor(severity === "error" ? "danger" : severity === "warning" ? "warning" : "secondary")
5713
- };
5714
- }
5715
4146
 
5716
4147
  //#endregion
5717
4148
  //#region src/generative-ui/standard/inputs.tsx
@@ -5724,223 +4155,6 @@ async function copyText(text) {
5724
4155
  return false;
5725
4156
  }
5726
4157
  }
5727
- /**
5728
- * The arguments of a click or submit event: none. The model adds values
5729
- * with the `context` of its `{ "event": ... }` binding.
5730
- */
5731
- const NO_ARGS = z.object({});
5732
- /** A list of choices: plain strings or `{ value, label, description? }`. */
5733
- const optionList = z.array(z.union([z.string(), z.object({
5734
- value: z.string(),
5735
- label: z.string().optional(),
5736
- description: z.string().optional()
5737
- })])).optional();
5738
- const SIZES = [
5739
- "sm",
5740
- "md",
5741
- "lg",
5742
- "xl"
5743
- ];
5744
- const size = (fallback) => z.enum(SIZES).optional().describe(`Default "${fallback}"`);
5745
- const pill = z.boolean().optional().describe("Default true");
5746
- const fieldLabel = z.string().optional().describe("The visible label of the field. Always set it");
5747
- const boundValue = z.string().optional().describe("Bind it with { \"@path\": \"/x\" } to read what the user entered");
5748
- const buttonSchema = z.object({
5749
- label: z.string().optional().describe("The button text"),
5750
- checks: checksProp,
5751
- text: z.string().optional().describe("Same as label. Used when label is not set"),
5752
- variant: z.enum([
5753
- "default",
5754
- "primary",
5755
- "soft",
5756
- "borderless"
5757
- ]).optional().describe("Default \"default\": outlined. \"primary\" is filled, for the one main action. \"borderless\" has no box, like a link"),
5758
- color: z.enum([
5759
- "primary",
5760
- "secondary",
5761
- "danger"
5762
- ]).optional().describe("Default \"primary\""),
5763
- size: z.enum([
5764
- "sm",
5765
- "md",
5766
- "lg"
5767
- ]).optional().describe("Default \"lg\""),
5768
- block: z.boolean().optional().describe("Full width"),
5769
- weight: weightProp,
5770
- pill,
5771
- disabled: z.boolean().optional(),
5772
- loading: z.boolean().optional(),
5773
- submit: z.boolean().optional().describe("Submits the Form around it. The Form sends its onSubmit event"),
5774
- icon: z.string().optional().describe("Lucide icon name"),
5775
- uniform: z.boolean().optional().describe("A square button, for an icon"),
5776
- href: z.string().optional().describe("Opens this URL in a new tab on click, instead of onClick"),
5777
- copy: z.string().optional().describe("Copies this text to the clipboard on click and shows a check mark, instead of onClick")
5778
- });
5779
- const pressableSchema = z.object({
5780
- ...layoutProps,
5781
- disabled: z.boolean().optional(),
5782
- hoverBackground: z.string().optional(),
5783
- href: z.string().optional().describe("Opens this URL in a new tab on click, instead of onClick"),
5784
- tooltip: z.string().optional().describe("Shown on hover"),
5785
- ariaPressed: z.boolean().optional().describe("For a toggle"),
5786
- insetBorder: z.boolean().optional().describe("A 1px border inside the box")
5787
- });
5788
- const formSchema = z.object({
5789
- ...layoutProps,
5790
- label: z.string().optional().describe("A short name of the form for screen readers")
5791
- });
5792
- const textFieldSchema = z.object({
5793
- checks: checksProp,
5794
- value: z.union([z.string(), z.number()]).optional().describe("Bind it with { \"@path\": \"/x\" } to read what the user typed"),
5795
- placeholder: z.string().optional(),
5796
- label: fieldLabel,
5797
- variant: z.enum([
5798
- "shortText",
5799
- "longText",
5800
- "number",
5801
- "obscured",
5802
- "email",
5803
- "url",
5804
- "tel"
5805
- ]).optional().describe("Default \"shortText\". \"longText\" is a multi-line field, \"obscured\" a password"),
5806
- weight: weightProp,
5807
- name: z.string().optional(),
5808
- required: z.boolean().optional(),
5809
- disabled: z.boolean().optional(),
5810
- invalid: z.boolean().optional(),
5811
- size: size("xl"),
5812
- pill,
5813
- autoSelect: z.boolean().optional(),
5814
- mask: z.string().optional()
5815
- });
5816
- const textAreaSchema = z.object({
5817
- checks: checksProp,
5818
- value: boundValue,
5819
- placeholder: z.string().optional(),
5820
- label: fieldLabel,
5821
- weight: weightProp,
5822
- rows: z.number().optional().describe("Default 3"),
5823
- maxRows: z.number().optional(),
5824
- autoResize: z.boolean().optional(),
5825
- name: z.string().optional(),
5826
- required: z.boolean().optional(),
5827
- disabled: z.boolean().optional(),
5828
- invalid: z.boolean().optional(),
5829
- size: size("xl")
5830
- });
5831
- const selectSchema = z.object({
5832
- checks: checksProp,
5833
- value: boundValue,
5834
- options: optionList,
5835
- placeholder: z.string().optional(),
5836
- label: fieldLabel,
5837
- name: z.string().optional(),
5838
- required: z.boolean().optional(),
5839
- disabled: z.boolean().optional(),
5840
- clearable: z.boolean().optional(),
5841
- clearLabel: z.string().optional().describe("The label of the empty option"),
5842
- searchable: z.boolean().optional(),
5843
- icon: z.string().optional().describe("Lucide icon shown before the value"),
5844
- block: z.boolean().optional().describe("Full width"),
5845
- size: size("xl"),
5846
- pill
5847
- });
5848
- const checkBoxSchema = z.object({
5849
- checks: checksProp,
5850
- value: z.boolean().optional().describe("True when checked. Bind it with { \"@path\": \"/x\" } to read the state of the box"),
5851
- label: z.string().optional().describe("The label text. Always set it"),
5852
- name: z.string().optional(),
5853
- weight: weightProp,
5854
- disabled: z.boolean().optional(),
5855
- required: z.boolean().optional(),
5856
- lineThrough: z.boolean().optional().describe("Default false. Strikes the label when the box is checked"),
5857
- shape: z.enum(["round", "square"]).optional().describe("Default \"round\"")
5858
- });
5859
- const radioSchema = z.object({
5860
- value: z.string().optional(),
5861
- label: z.string().optional(),
5862
- disabled: z.boolean().optional(),
5863
- required: z.boolean().optional()
5864
- });
5865
- const radioGroupSchema = z.object({
5866
- checks: checksProp,
5867
- value: boundValue,
5868
- options: optionList,
5869
- label: fieldLabel,
5870
- name: z.string().optional(),
5871
- direction: z.enum(["row", "col"]).optional().describe("Default \"row\""),
5872
- variant: z.enum([
5873
- "list",
5874
- "pills",
5875
- "cards"
5876
- ]).optional(),
5877
- disabled: z.boolean().optional(),
5878
- required: z.boolean().optional()
5879
- });
5880
- const sliderSchema = z.object({
5881
- checks: checksProp,
5882
- value: z.number().optional().describe("Bind it with { \"@path\": \"/x\" } to read the number"),
5883
- min: z.number().optional().describe("Default 0"),
5884
- max: z.number().optional().describe("Default 100"),
5885
- step: z.number().optional().describe("Default 1"),
5886
- steps: z.number().int().min(1).optional().describe("The number of equal divisions between min and max, instead of step"),
5887
- label: fieldLabel,
5888
- weight: weightProp,
5889
- unit: z.string().optional().describe("Unit after the value, for example \"%\""),
5890
- marks: z.array(z.object({
5891
- value: z.number(),
5892
- label: z.string().optional()
5893
- })).optional(),
5894
- sliderStyle: z.enum(["continuous", "discrete"]).optional().describe("Default \"continuous\""),
5895
- disabled: z.boolean().optional(),
5896
- name: z.string().optional()
5897
- });
5898
- const segmentedControlSchema = z.object({
5899
- checks: checksProp,
5900
- value: boundValue,
5901
- options: optionList,
5902
- label: fieldLabel,
5903
- block: z.boolean().optional().describe("Full width"),
5904
- size: size("lg"),
5905
- pill,
5906
- variant: z.enum([
5907
- "solid",
5908
- "soft",
5909
- "outline",
5910
- "ghost"
5911
- ]).optional().describe("Default \"ghost\""),
5912
- disabled: z.boolean().optional()
5913
- });
5914
- const choicePickerSchema = z.object({
5915
- checks: checksProp,
5916
- value: z.array(z.string()).optional().describe("The chosen option values. Bind it with { \"@path\": \"/x\" } to a string list"),
5917
- options: optionList,
5918
- label: fieldLabel,
5919
- variant: z.enum(["multipleSelection", "mutuallyExclusive"]).optional().describe("Default \"mutuallyExclusive\": the user picks one option"),
5920
- displayStyle: z.enum(["checkbox", "chips"]).optional().describe("Default \"checkbox\". \"chips\" shows the options as pills"),
5921
- filterable: z.boolean().optional().describe("Default false. Shows a field that filters the options"),
5922
- weight: weightProp,
5923
- disabled: z.boolean().optional(),
5924
- required: z.boolean().optional()
5925
- });
5926
- const dateTimeInputSchema = z.object({
5927
- checks: checksProp,
5928
- value: z.string().optional().describe("ISO 8601: \"YYYY-MM-DD\", \"HH:MM\" or \"YYYY-MM-DDTHH:MM\". Bind it with { \"@path\": \"/x\" }"),
5929
- label: fieldLabel,
5930
- enableDate: z.boolean().optional().describe("The user picks a date. Default true unless only enableTime is set"),
5931
- enableTime: z.boolean().optional().describe("The user picks a time"),
5932
- timeStep: z.number().int().min(1).max(720).optional().describe("Minutes between the times the user can pick, e.g. 15 or 30. Shows the time as a list"),
5933
- weight: weightProp,
5934
- min: z.string().optional().describe("The earliest value, ISO 8601"),
5935
- max: z.string().optional().describe("The latest value, ISO 8601"),
5936
- placeholder: z.string().optional(),
5937
- disabled: z.boolean().optional(),
5938
- required: z.boolean().optional(),
5939
- clearable: z.boolean().optional(),
5940
- block: z.boolean().optional().describe("Full width")
5941
- });
5942
- /** The writable list of a control that keeps its state in `value`. */
5943
- const VALUE_WRITABLE = ["value"];
5944
4158
  const HEIGHT = {
5945
4159
  sm: 28,
5946
4160
  md: 32,
@@ -7185,226 +5399,24 @@ function Slider(props) {
7185
5399
  * When the model binds it to `{ "@path": "/x" }`, what the user enters goes
7186
5400
  * into the data model at that path, and the agent can no longer change it.
7187
5401
  */
7188
- const inputComponents = {
7189
- Button: {
7190
- component: Button,
7191
- description: "Sends its onClick event; with href it opens the URL, with copy it copies the text. Variant \"primary\" for the one main Button in a Row. submit true submits the Form around it. Its children render instead of the label. With checks it is disabled while a check fails.",
7192
- props: buttonSchema,
7193
- events: { onClick: {
7194
- description: "Sent when the user clicks the button.",
7195
- parameters: NO_ARGS
7196
- } },
7197
- slots: {
7198
- child: "single",
7199
- children: "multiple"
7200
- }
7201
- },
7202
- Pressable: {
7203
- component: Pressable,
7204
- description: "A layout container that the user can click or press with Enter or Space. It sends its onClick event, or opens href. A control inside it sends only its own event.",
7205
- props: pressableSchema,
7206
- events: {
7207
- ...VISIBLE_EVENT,
7208
- onClick: {
7209
- description: "Sent when the user clicks or presses the container.",
7210
- parameters: NO_ARGS
7211
- }
7212
- },
7213
- slots: CHILDREN_SLOT
7214
- },
7215
- Form: {
7216
- component: Form,
7217
- description: "A layout container that is a form. It sends onSubmit when the user submits (a Button with submit true, or Enter in a field). Put its field values in the event context with { \"@path\": \"/x\" }.",
7218
- props: formSchema,
7219
- events: { onSubmit: {
7220
- description: "Sent when the user submits the form.",
7221
- parameters: NO_ARGS
7222
- } },
7223
- slots: CHILDREN_SLOT
7224
- },
7225
- TextField: {
7226
- component: TextField,
7227
- description: "A text input, single-line unless variant is \"longText\". Bind value with { \"@path\": \"/x\" } to read what the user typed. Give it a label.",
7228
- props: textFieldSchema,
7229
- writable: VALUE_WRITABLE
7230
- },
7231
- TextArea: {
7232
- component: TextArea,
7233
- description: "A multi-line text input. Bind value with { \"@path\": \"/x\" } to read what the user typed. Give it a label.",
7234
- props: textAreaSchema,
7235
- writable: VALUE_WRITABLE
7236
- },
7237
- Select: {
7238
- component: Select,
7239
- description: "A dropdown list of options. Bind value with { \"@path\": \"/x\" } to read the chosen option. Give it a label.",
7240
- props: selectSchema,
7241
- writable: VALUE_WRITABLE
7242
- },
7243
- CheckBox: {
7244
- component: CheckBox,
7245
- description: "A checkbox with a label. Bind value with { \"@path\": \"/x\" } to read its state, true or false.",
7246
- props: checkBoxSchema,
7247
- writable: VALUE_WRITABLE
7248
- },
7249
- Radio: {
7250
- component: Radio,
7251
- description: "One radio button. Use RadioGroup instead, because it keeps the chosen value.",
7252
- props: radioSchema
7253
- },
7254
- RadioGroup: {
7255
- component: RadioGroup,
7256
- description: "A group of radio buttons. The user chooses one option. Bind value with { \"@path\": \"/x\" } to read it. Give it a label.",
7257
- props: radioGroupSchema,
7258
- writable: VALUE_WRITABLE
7259
- },
7260
- Slider: {
7261
- component: Slider,
7262
- description: "A range slider for a number between min and max. Bind value with { \"@path\": \"/x\" } to read the number. Give it a label.",
7263
- props: sliderSchema,
7264
- writable: VALUE_WRITABLE
7265
- },
7266
- SegmentedControl: {
7267
- component: SegmentedControl,
7268
- description: "A row of segments. The user chooses one option. Use it for 2 to 5 short options. Bind value with { \"@path\": \"/x\" } to read it.",
7269
- props: segmentedControlSchema,
7270
- writable: VALUE_WRITABLE
7271
- },
7272
- ChoicePicker: {
7273
- component: ChoicePicker,
7274
- description: "Options as checkboxes or chips: pick one, or several with variant \"multipleSelection\". Its value is the list of chosen values. Give it a label.",
7275
- props: choicePickerSchema,
7276
- writable: VALUE_WRITABLE
7277
- },
7278
- DateTimeInput: {
7279
- component: DateTimeInput,
7280
- description: "A date picker, a time picker with enableTime, or both. timeStep (minutes) offers fixed times, e.g. 30 for a booking. The value is ISO 8601. Give it a label.",
7281
- props: dateTimeInputSchema,
7282
- writable: VALUE_WRITABLE
7283
- }
7284
- };
5402
+ const inputComponents = withComponents(inputDeclarations, {
5403
+ Button,
5404
+ Pressable,
5405
+ Form,
5406
+ TextField,
5407
+ TextArea,
5408
+ Select,
5409
+ CheckBox,
5410
+ Radio,
5411
+ RadioGroup,
5412
+ Slider,
5413
+ SegmentedControl,
5414
+ ChoicePicker,
5415
+ DateTimeInput
5416
+ });
7285
5417
 
7286
5418
  //#endregion
7287
5419
  //#region src/generative-ui/standard/text.tsx
7288
- const colorProp = z.string().optional().describe(`One of ${TEXT_COLORS.join("|")} or a CSS color`);
7289
- const fontWeight = z.enum(WEIGHTS).optional();
7290
- const textAlign = z.enum([
7291
- "start",
7292
- "center",
7293
- "end"
7294
- ]).optional();
7295
- const typographyProps = {
7296
- color: colorProp,
7297
- fontWeight,
7298
- textAlign,
7299
- italic: z.boolean().optional(),
7300
- truncate: z.boolean().optional(),
7301
- maxLines: z.number().optional(),
7302
- tabularNums: z.boolean().optional(),
7303
- width: sizeValue.optional()
7304
- };
7305
- z.object(typographyProps);
7306
- const titleSchema = z.object({
7307
- ...typographyProps,
7308
- text: z.string().describe("Heading text"),
7309
- size: z.enum(TITLE_SIZES).optional().describe("Default \"md\""),
7310
- strong: z.boolean().optional().describe("Default true")
7311
- });
7312
- const textSchema = z.object({
7313
- ...typographyProps,
7314
- weight: weightProp,
7315
- text: z.union([z.string(), z.number()]).optional().describe("Text with inline markdown. A bound number shows as text"),
7316
- size: z.enum(TEXT_SIZES).optional().describe("Default \"md\""),
7317
- fontSize: sizeValue.optional().describe("Pixels when a number. Wins over size"),
7318
- lineHeight: z.union([z.number(), z.string()]).optional().describe("A unitless ratio, or CSS"),
7319
- minLines: z.number().optional().describe("Reserves the height of this many lines"),
7320
- strong: z.boolean().optional().describe("Default false"),
7321
- underline: z.boolean().optional(),
7322
- lineThrough: z.boolean().optional(),
7323
- inline: z.boolean().optional(),
7324
- preserveWhitespace: z.boolean().optional(),
7325
- highlight: z.union([z.enum([
7326
- "green",
7327
- "orange",
7328
- "pink"
7329
- ]), z.boolean()]).optional()
7330
- });
7331
- const captionSchema = z.object({
7332
- text: z.union([z.string(), z.number()]).describe("Caption text"),
7333
- color: colorProp,
7334
- size: z.enum([
7335
- "sm",
7336
- "md",
7337
- "lg"
7338
- ]).optional().describe("Default \"lg\""),
7339
- fontWeight: fontWeight.describe("Default \"normal\""),
7340
- textAlign,
7341
- truncate: z.boolean().optional(),
7342
- maxLines: z.number().optional()
7343
- });
7344
- const labelSchema = z.object({
7345
- text: z.union([z.string(), z.number()]).describe("Label text"),
7346
- htmlFor: z.string().optional(),
7347
- color: colorProp,
7348
- size: z.enum(TEXT_SIZES).optional().describe("Default \"sm\""),
7349
- fontWeight: fontWeight.describe("Default \"medium\""),
7350
- textAlign,
7351
- truncate: z.boolean().optional(),
7352
- width: sizeValue.optional()
7353
- });
7354
- const boldSchema = z.object({
7355
- text: z.string(),
7356
- fontWeight
7357
- });
7358
- const inlineTextSchema = z.object({ text: z.string() });
7359
- const blockquoteSchema = z.object({ text: z.string().describe("The quoted text, with inline markdown") });
7360
- const badgeSchema = z.object({
7361
- label: z.string().describe("Badge text"),
7362
- color: z.enum([
7363
- "secondary",
7364
- "success",
7365
- "danger",
7366
- "warning",
7367
- "info",
7368
- "discovery"
7369
- ]).optional().describe("Default \"secondary\""),
7370
- size: z.enum([
7371
- "sm",
7372
- "md",
7373
- "lg"
7374
- ]).optional().describe("Default \"md\""),
7375
- pill: z.boolean().optional().describe("Default true"),
7376
- variant: z.enum([
7377
- "soft",
7378
- "solid",
7379
- "outline"
7380
- ]).optional().describe("Default \"soft\""),
7381
- fontWeight: fontWeight.describe("Default \"medium\""),
7382
- maxWidth: sizeValue.optional(),
7383
- padding: sizeValue.optional()
7384
- });
7385
- const codeSchema = z.object({
7386
- text: z.string().describe("Source code"),
7387
- language: z.string().optional()
7388
- });
7389
- const markdownSchema = z.object({
7390
- text: z.string().describe("Markdown source"),
7391
- streaming: z.boolean().optional().describe("Default false")
7392
- });
7393
- const mathSchema = z.object({
7394
- value: z.string().describe("TeX source"),
7395
- block: z.boolean().optional().describe("Default false")
7396
- });
7397
- const shimmerSchema = z.object({
7398
- ...typographyProps,
7399
- text: z.string(),
7400
- size: z.enum(TEXT_SIZES).optional().describe("Default \"md\""),
7401
- lineThrough: z.boolean().optional()
7402
- });
7403
- const linkSchema = z.object({
7404
- text: z.string().describe("Link text"),
7405
- href: z.string().describe("URL"),
7406
- title: z.string().optional()
7407
- });
7408
5420
  const FOCUS_RING = "2px solid var(--a2ui-color-focus, #0285ff)";
7409
5421
  const TEXT_STYLE_ID = "a2ui-standard-text";
7410
5422
  const TEXT_CSS = [
@@ -7777,322 +5789,28 @@ function Tooltip({ trigger, content }) {
7777
5789
  * - Tooltip has two "single" slots: `trigger` and `content`.
7778
5790
  * - Link is a plain link. It opens http, https and mailto URLs only.
7779
5791
  */
7780
- const textComponents = {
7781
- Title: {
7782
- component: Title,
7783
- description: "A heading in a Card or next to another component; a heading alone is markdown. Size \"2xl\" at most once per surface, \"lg\" for sections. \"sm\" is an h4, \"md\"/\"lg\" an h3 (default \"md\"), \"xl\" and up an h2. Bold unless strong is false.",
7784
- props: titleSchema
7785
- },
7786
- Text: {
7787
- component: Text,
7788
- description: "Body text in a Card or next to another component; a paragraph alone is markdown outside the fence. Color \"default\" or \"secondary\". `text` takes inline markdown (**bold**, *italic*, ~~strike~~, ++underline++, `code`, [link](url)). `children` ids render inline after it, e.g. a Badge.",
7789
- props: textSchema,
7790
- slots: CHILDREN_SLOT
7791
- },
7792
- Caption: {
7793
- component: Caption,
7794
- description: "Small secondary text: a hint under a control, or a label in a Row. `text` can have inline markdown.",
7795
- props: captionSchema
7796
- },
7797
- Label: {
7798
- component: Label,
7799
- description: "The label of a form field.",
7800
- props: labelSchema
7801
- },
7802
- Bold: {
7803
- component: Bold,
7804
- description: "Bold inline text.",
7805
- props: boldSchema
7806
- },
7807
- Italic: {
7808
- component: Italic,
7809
- description: "Italic inline text.",
7810
- props: inlineTextSchema
7811
- },
7812
- Underline: {
7813
- component: Underline,
7814
- description: "Underlined inline text.",
7815
- props: inlineTextSchema
7816
- },
7817
- Strikethrough: {
7818
- component: Strikethrough,
7819
- description: "Struck-through inline text.",
7820
- props: inlineTextSchema
7821
- },
7822
- Badge: {
7823
- component: Badge,
7824
- description: "A small status pill. Use the colors success, danger and warning only to show a status, not for decoration.",
7825
- props: badgeSchema
7826
- },
7827
- Blockquote: {
7828
- component: Blockquote,
7829
- description: "A block quotation with a line on the left. `text` can have inline markdown.",
7830
- props: blockquoteSchema
7831
- },
7832
- Code: {
7833
- component: Code,
7834
- description: "A block of code in a monospace font.",
7835
- props: codeSchema
7836
- },
7837
- Markdown: {
7838
- component: Markdown,
7839
- description: "A block of GitHub-flavored markdown. Use it only next to other components, for example in a table cell or next to a chart. Markdown alone goes outside the fence.",
7840
- props: markdownSchema
7841
- },
7842
- Math: {
7843
- component: MathFormula,
7844
- description: "A TeX math formula, typeset with KaTeX. Set block to true for a centered formula on its own line.",
7845
- props: mathSchema
7846
- },
7847
- ShimmerText: {
7848
- component: ShimmerText,
7849
- description: "Text with a moving shimmer. It shows that something is loading or pending.",
7850
- props: shimmerSchema
7851
- },
7852
- Link: {
7853
- component: Link,
7854
- description: "A link. Only http, https and mailto URLs work. It opens in a new tab.",
7855
- props: linkSchema
7856
- },
7857
- Tooltip: {
7858
- component: Tooltip,
7859
- description: "Shows `content` when the user points at or focuses `trigger`. `trigger`: one child id, a Text, Icon or Badge (not a Button or Link). `content`: one child id of short text, no links or buttons.",
7860
- slots: {
7861
- trigger: "single",
7862
- content: "single"
7863
- }
7864
- }
7865
- };
7866
-
7867
- //#endregion
7868
- //#region src/generative-ui/standard/parameter-order.ts
7869
- /** CopilotKit catalog design, not an A2UI-mandated list of signatures.
7870
- * Express maps positional arguments using the exported JSON Schema property order:
7871
- * https://a2ui.org/specification/proposals/express/a2ui_express/#schema-driven-key-mapping
7872
- * Keep these prefixes stable. Optional styling is best passed by name.
7873
- */
7874
- const STANDARD_ARGUMENT_PREFIXES = {
7875
- Box: ["children"],
7876
- Column: ["children"],
7877
- Row: ["children"],
7878
- Grid: ["children", "columns"],
7879
- GridItem: ["children"],
7880
- Card: ["children", "child"],
7881
- Flow: ["children"],
7882
- FlowItem: ["children"],
7883
- Carousel: ["children", "activeIndex"],
7884
- CarouselItem: ["children"],
7885
- CarouselMediaItem: [
7886
- "url",
7887
- "children",
7888
- "onClick"
7889
- ],
7890
- Spacer: ["minSize"],
7891
- Divider: ["axis"],
7892
- Tabs: ["tabs", "selectedIndex"],
7893
- Title: ["text"],
7894
- Text: ["text", "children"],
7895
- Caption: ["text"],
7896
- Label: ["text", "htmlFor"],
7897
- Bold: ["text"],
7898
- Italic: ["text"],
7899
- Underline: ["text"],
7900
- Strikethrough: ["text"],
7901
- Badge: ["label"],
7902
- Blockquote: ["text"],
7903
- Code: ["text", "language"],
7904
- Markdown: ["text"],
7905
- Math: ["value"],
7906
- ShimmerText: ["text"],
7907
- Link: ["text", "href"],
7908
- Tooltip: ["trigger", "content"],
7909
- Button: ["label", "onClick"],
7910
- Pressable: [
7911
- "children",
7912
- "onClick",
7913
- "href"
7914
- ],
7915
- Form: ["children", "onSubmit"],
7916
- TextField: ["label", "value"],
7917
- TextArea: ["label", "value"],
7918
- Select: [
7919
- "label",
7920
- "options",
7921
- "value"
7922
- ],
7923
- CheckBox: ["label", "value"],
7924
- Radio: ["label", "value"],
7925
- RadioGroup: [
7926
- "label",
7927
- "options",
7928
- "value"
7929
- ],
7930
- Slider: [
7931
- "label",
7932
- "value",
7933
- "min",
7934
- "max"
7935
- ],
7936
- SegmentedControl: [
7937
- "label",
7938
- "options",
7939
- "value"
7940
- ],
7941
- ChoicePicker: [
7942
- "label",
7943
- "options",
7944
- "value"
7945
- ],
7946
- DateTimeInput: ["label", "value"],
7947
- PulseIndicator: ["label"],
7948
- FlashcardFlip: ["front", "back"],
7949
- Popover: ["children", "open"],
7950
- PopoverTrigger: ["children"],
7951
- PopoverContent: ["children"],
7952
- Modal: [
7953
- "trigger",
7954
- "content",
7955
- "title"
7956
- ],
7957
- Table: [
7958
- "columns",
7959
- "rows",
7960
- "children"
7961
- ],
7962
- TableSection: ["children"],
7963
- TableRow: ["children", "label"],
7964
- TableCell: ["text", "children"],
7965
- List: [
7966
- "items",
7967
- "children",
7968
- "action"
7969
- ],
7970
- ListItem: [
7971
- "label",
7972
- "value",
7973
- "action",
7974
- "children"
7975
- ],
7976
- Chart: [
7977
- "data",
7978
- "xKey",
7979
- "series",
7980
- "chartType"
7981
- ],
7982
- Map: [
7983
- "markers",
7984
- "selected",
7985
- "route"
7986
- ],
7987
- Image: [
7988
- "url",
7989
- "description",
7990
- "onOverlayClick"
7991
- ],
7992
- Icon: ["name", "label"],
7993
- Favicon: ["url", "alt"],
7994
- Svg: ["paths", "viewBox"],
7995
- Video: [
7996
- "url",
7997
- "title",
7998
- "captions"
7999
- ],
8000
- AudioPlayer: ["url", "description"],
8001
- HtmlView: ["html", "title"],
8002
- LinkCard: [
8003
- "href",
8004
- "title",
8005
- "onClick"
8006
- ],
8007
- Citation: [
8008
- "index",
8009
- "title",
8010
- "url"
8011
- ],
8012
- FollowUp: [
8013
- "items",
8014
- "onFollowUp",
8015
- "title"
8016
- ],
8017
- EntityCard: [
8018
- "title",
8019
- "actions",
8020
- "onAction",
8021
- "onClick"
8022
- ],
8023
- ImageGrid: ["images"]
8024
- };
8025
- const PRESENTATION_PARAMETERS = new Set([
8026
- "align",
8027
- "aspectRatio",
8028
- "background",
8029
- "border",
8030
- "borderColor",
8031
- "clip",
8032
- "color",
8033
- "columnGap",
8034
- "disableAutoSpacing",
8035
- "flex",
8036
- "flush",
8037
- "fontSize",
8038
- "fontWeight",
8039
- "gap",
8040
- "height",
8041
- "highlight",
8042
- "hoverBackground",
8043
- "inline",
8044
- "insetBorder",
8045
- "italic",
8046
- "justify",
8047
- "lineHeight",
8048
- "lineThrough",
8049
- "maxHeight",
8050
- "maxLines",
8051
- "maxSize",
8052
- "maxWidth",
8053
- "minHeight",
8054
- "minLines",
8055
- "minSize",
8056
- "minWidth",
8057
- "padding",
8058
- "pill",
8059
- "preserveWhitespace",
8060
- "radius",
8061
- "role",
8062
- "rowGap",
8063
- "scrollable",
8064
- "shadow",
8065
- "shadowStyle",
8066
- "size",
8067
- "strokeWeight",
8068
- "strong",
8069
- "tabularNums",
8070
- "textAlign",
8071
- "truncate",
8072
- "underline",
8073
- "weight",
8074
- "width",
8075
- "wrap"
8076
- ]);
8077
- /** Put content/actions before presentation, across props, slots and events. */
8078
- function standardParameterOrder(name, definition) {
8079
- const keys = [
8080
- ...Object.keys(definition.props ? toJsonSchema(definition.props).properties ?? {} : {}),
8081
- ...Object.keys(definition.slots ?? {}),
8082
- ...Object.keys(definition.events ?? {})
8083
- ];
8084
- const prefix = STANDARD_ARGUMENT_PREFIXES[name];
8085
- const remainder = keys.filter((key) => !prefix.includes(key));
8086
- return [
8087
- ...prefix,
8088
- ...remainder.filter((key) => !PRESENTATION_PARAMETERS.has(key)),
8089
- ...remainder.filter((key) => PRESENTATION_PARAMETERS.has(key))
8090
- ];
8091
- }
5792
+ const textComponents = withComponents(textDeclarations, {
5793
+ Title,
5794
+ Text,
5795
+ Caption,
5796
+ Label,
5797
+ Bold,
5798
+ Italic,
5799
+ Underline,
5800
+ Strikethrough,
5801
+ Badge,
5802
+ Blockquote,
5803
+ Code,
5804
+ Markdown,
5805
+ Math: MathFormula,
5806
+ ShimmerText,
5807
+ Link,
5808
+ Tooltip
5809
+ });
8092
5810
 
8093
5811
  //#endregion
8094
5812
  //#region src/generative-ui/standard/index.ts
8095
- const components = {
5813
+ const orderedComponents = withStandardParameterOrder({
8096
5814
  ...layoutComponents,
8097
5815
  ...textComponents,
8098
5816
  ...inputComponents,
@@ -8100,11 +5818,7 @@ const components = {
8100
5818
  ...dataComponents,
8101
5819
  ...mediaComponents,
8102
5820
  ...compositeComponents
8103
- };
8104
- const orderedComponents = Object.fromEntries(Object.entries(components).map(([name, definition]) => [name, {
8105
- ...definition,
8106
- parameterOrder: standardParameterOrder(name, definition)
8107
- }]));
5821
+ });
8108
5822
  /**
8109
5823
  * Experimental. The standard components: layout, text, inputs, feedback,
8110
5824
  * data, media and composites. Give it to the provider as it is, or add your