orbital-ds 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AGENTS.md +1 -1
  2. package/components.manifest.json +221 -1
  3. package/dist/hooks/use-ds-messages.d.ts +82 -0
  4. package/dist/lib/a2ui-catalog.d.ts +42 -0
  5. package/dist/lib/a2ui-catalog.js +558 -0
  6. package/dist/lib/a2ui.d.ts +289 -0
  7. package/dist/lib/a2ui.js +215 -0
  8. package/dist/lib/ai-events.d.ts +15 -0
  9. package/dist/lib/ai-events.js +202 -0
  10. package/dist/lib/auth-flow.d.ts +3 -1
  11. package/dist/lib/auth-flow.js +24 -3
  12. package/dist/lib/i18n.d.ts +82 -0
  13. package/dist/lib/i18n.js +246 -0
  14. package/dist/styles.css +23 -1
  15. package/dist/ui/a2ui-renderer.d.ts +33 -0
  16. package/dist/ui/a2ui-renderer.js +793 -0
  17. package/dist/ui/agent-events.d.ts +32 -0
  18. package/dist/ui/agent-events.js +108 -0
  19. package/dist/ui/alert.d.ts +1 -1
  20. package/dist/ui/attachment.d.ts +2 -2
  21. package/dist/ui/auth-form.d.ts +3 -1
  22. package/dist/ui/auth-form.js +34 -6
  23. package/dist/ui/badge.d.ts +1 -1
  24. package/dist/ui/banner.d.ts +1 -1
  25. package/dist/ui/bubble.d.ts +1 -1
  26. package/dist/ui/button-group.d.ts +1 -1
  27. package/dist/ui/button.d.ts +2 -2
  28. package/dist/ui/chain-of-thought.d.ts +19 -0
  29. package/dist/ui/chain-of-thought.js +90 -0
  30. package/dist/ui/chat-composer.d.ts +39 -0
  31. package/dist/ui/chat-composer.js +192 -0
  32. package/dist/ui/conversation-list.d.ts +24 -0
  33. package/dist/ui/conversation-list.js +141 -0
  34. package/dist/ui/empty.d.ts +1 -1
  35. package/dist/ui/field.d.ts +1 -1
  36. package/dist/ui/generated-image.d.ts +14 -0
  37. package/dist/ui/generated-image.js +65 -0
  38. package/dist/ui/generated-table.d.ts +11 -0
  39. package/dist/ui/generated-table.js +59 -0
  40. package/dist/ui/icon-tile.d.ts +2 -2
  41. package/dist/ui/item.d.ts +2 -2
  42. package/dist/ui/markdown.d.ts +14 -0
  43. package/dist/ui/markdown.js +123 -0
  44. package/dist/ui/marker.d.ts +1 -1
  45. package/dist/ui/message-actions.d.ts +12 -0
  46. package/dist/ui/message-actions.js +79 -0
  47. package/dist/ui/panel.d.ts +1 -1
  48. package/dist/ui/reasoning.d.ts +10 -0
  49. package/dist/ui/reasoning.js +62 -0
  50. package/dist/ui/sidebar.d.ts +1 -1
  51. package/dist/ui/sparkline.d.ts +1 -1
  52. package/dist/ui/stat.d.ts +1 -1
  53. package/dist/ui/status-badge.d.ts +3 -3
  54. package/dist/ui/suggestions.d.ts +8 -0
  55. package/dist/ui/suggestions.js +39 -0
  56. package/dist/ui/tabs.d.ts +1 -1
  57. package/dist/ui/toggle.d.ts +1 -1
  58. package/dist/ui/tool-call.d.ts +15 -0
  59. package/dist/ui/tool-call.js +74 -0
  60. package/dist/ui/workflow-run.d.ts +23 -0
  61. package/dist/ui/workflow-run.js +185 -0
  62. package/docs/designer/criterio.md +87 -87
  63. package/docs/designer/patrones.md +3 -1
  64. package/package.json +238 -228
@@ -0,0 +1,793 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import {
5
+ ActivityIcon,
6
+ ArrowLeftIcon,
7
+ ArrowRightIcon,
8
+ BellIcon,
9
+ BellOffIcon,
10
+ BotIcon,
11
+ CalendarDaysIcon,
12
+ CalendarIcon,
13
+ CameraIcon,
14
+ CheckIcon,
15
+ CircleAlertIcon,
16
+ CircleCheckIcon,
17
+ CircleHelpIcon,
18
+ CircleUserIcon,
19
+ ClockIcon,
20
+ CreditCardIcon,
21
+ DownloadIcon,
22
+ EllipsisIcon,
23
+ EllipsisVerticalIcon,
24
+ EyeIcon,
25
+ EyeOffIcon,
26
+ FileTextIcon,
27
+ FolderIcon,
28
+ HeartIcon,
29
+ HeartOffIcon,
30
+ HomeIcon,
31
+ ImageIcon,
32
+ InfoIcon,
33
+ LockIcon,
34
+ LockOpenIcon,
35
+ MailIcon,
36
+ MapPinIcon,
37
+ MenuIcon,
38
+ PaperclipIcon,
39
+ PauseIcon,
40
+ PencilIcon,
41
+ PhoneIcon,
42
+ PlayIcon,
43
+ PlusIcon,
44
+ PrinterIcon,
45
+ RefreshCwIcon,
46
+ SearchIcon,
47
+ SendIcon,
48
+ SettingsIcon,
49
+ Share2Icon,
50
+ ShieldCheckIcon,
51
+ ShoppingCartIcon,
52
+ SparklesIcon,
53
+ StarIcon,
54
+ StarOffIcon,
55
+ Trash2Icon,
56
+ TrendingUpIcon,
57
+ TriangleAlertIcon,
58
+ UploadIcon,
59
+ UserIcon,
60
+ UsersIcon,
61
+ Volume2Icon,
62
+ VolumeXIcon,
63
+ WrenchIcon,
64
+ XIcon,
65
+ ZapIcon
66
+ } from "lucide-react";
67
+ import { useDsLocale, useDsMessages } from "../hooks/use-ds-messages.js";
68
+ import {
69
+ applyUpdate,
70
+ buildFullPath,
71
+ failedChecks,
72
+ isFunctionCall,
73
+ isPathBinding,
74
+ resolveContext,
75
+ resolveDynamic
76
+ } from "../lib/a2ui.js";
77
+ import { validateA2UI } from "../lib/a2ui-catalog.js";
78
+ import { barOption, gaugeOption, lineOption, pieOption } from "../lib/echarts-presets.js";
79
+ import { cn } from "../lib/utils.js";
80
+ import { Alert, AlertDescription, AlertTitle } from "./alert.js";
81
+ import { Badge } from "./badge.js";
82
+ import { Button } from "./button.js";
83
+ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./card.js";
84
+ import { Checkbox } from "./checkbox.js";
85
+ import { Dialog, DialogContent, DialogTitle } from "./dialog.js";
86
+ import { IconTile } from "./icon-tile.js";
87
+ import { Input } from "./input.js";
88
+ import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "./item.js";
89
+ import { Label } from "./label.js";
90
+ import { Progress } from "./progress.js";
91
+ import { RadioGroup, RadioGroupItem } from "./radio-group.js";
92
+ import { Separator } from "./separator.js";
93
+ import { Slider } from "./slider.js";
94
+ import { Stat, StatDelta, StatDescription, StatHeader, StatIcon, StatLabel, StatValue } from "./stat.js";
95
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "./tabs.js";
96
+ import { Textarea } from "./textarea.js";
97
+ const DispatchContext = React.createContext({ emit: () => {
98
+ } });
99
+ const SurfaceContext = React.createContext({ sendDataModel: false });
100
+ const PlainContext = React.createContext(false);
101
+ const MAX_TEMPLATE_ITEMS = 500;
102
+ const MAX_DEPTH = 40;
103
+ const JUSTIFY = {
104
+ start: "justify-start",
105
+ center: "justify-center",
106
+ end: "justify-end",
107
+ stretch: "justify-stretch",
108
+ spaceBetween: "justify-between",
109
+ spaceAround: "justify-around",
110
+ spaceEvenly: "justify-evenly"
111
+ };
112
+ const ALIGN = {
113
+ start: "items-start",
114
+ center: "items-center",
115
+ end: "items-end",
116
+ stretch: "items-stretch"
117
+ };
118
+ function childrenOf(list, p) {
119
+ const wrap = (id, scope, key) => {
120
+ const weight = p.peek(id)?.weight;
121
+ const child = p.resolveChild(id, scope);
122
+ if (typeof weight !== "number" || !(weight > 0)) return child;
123
+ return /* @__PURE__ */ jsx("div", { "data-slot": "a2ui-weighted", className: "min-w-0", style: { flex: `${weight} 1 0%` }, children: child }, key);
124
+ };
125
+ if (Array.isArray(list)) return list.map((id) => wrap(id, p.scopePath, `${id}@${p.scopePath ?? ""}`));
126
+ if (list && typeof list === "object" && "componentId" in list) {
127
+ const items = resolveDynamic({ "@path": list.path }, p.data, p.scopePath, 0, p.locale);
128
+ if (!Array.isArray(items)) return [];
129
+ const base = buildFullPath(list.path, p.scopePath);
130
+ return items.slice(0, MAX_TEMPLATE_ITEMS).map((_, i) => wrap(list.componentId, `${base}/${i}`, `${list.componentId}@${base}/${i}`));
131
+ }
132
+ return [];
133
+ }
134
+ function useBound(raw, fallback, p) {
135
+ const initial = isPathBinding(raw) ? fallback : resolveDynamic(raw, p.data, p.scopePath, 0, p.locale) ?? fallback;
136
+ const [local, setLocal] = React.useState(initial);
137
+ if (isPathBinding(raw)) {
138
+ const value = resolveDynamic(raw, p.data, p.scopePath, 0, p.locale) ?? fallback;
139
+ return [value, (next) => p.setDataPath(buildFullPath(raw["@path"], p.scopePath), next)];
140
+ }
141
+ return [local, setLocal];
142
+ }
143
+ const str = (raw, p) => {
144
+ const v = resolveDynamic(raw, p.data, p.scopePath, 0, p.locale);
145
+ return v === void 0 || v === null ? "" : String(v);
146
+ };
147
+ function CheckMessages({ checks, p, show }) {
148
+ if (!show) return null;
149
+ const failed = failedChecks(checks, p.data, p.scopePath, p.locale);
150
+ if (failed.length === 0) return null;
151
+ return /* @__PURE__ */ jsx("ul", { "data-slot": "a2ui-checks", className: "flex flex-col gap-0.5 text-xs text-danger", children: failed.map((m) => /* @__PURE__ */ jsx("li", { children: m }, m)) });
152
+ }
153
+ function useRunAction(p) {
154
+ const { emit } = React.useContext(DispatchContext);
155
+ const { sendDataModel } = React.useContext(SurfaceContext);
156
+ return React.useCallback(
157
+ (action) => {
158
+ if ("event" in action && action.event) {
159
+ const { name, userMessage, context } = action.event;
160
+ emit({
161
+ type: "event",
162
+ surfaceId: p.surfaceId,
163
+ componentId: p.node.id,
164
+ name,
165
+ ...userMessage !== void 0 ? { userMessage } : {},
166
+ context: resolveContext(context, p.data, p.scopePath, p.locale),
167
+ ...sendDataModel ? { dataModel: structuredClone(p.data) } : {}
168
+ });
169
+ return;
170
+ }
171
+ if ("functionCall" in action && isFunctionCall(action.functionCall)) {
172
+ const call = action.functionCall["@call"];
173
+ const args = resolveContext(action.functionCall.args, p.data, p.scopePath, p.locale);
174
+ if (call === "openUrl") {
175
+ const url = typeof args.url === "string" ? args.url : "";
176
+ if (/^https?:\/\//i.test(url)) window.open(url, "_blank", "noopener,noreferrer");
177
+ return;
178
+ }
179
+ emit({ type: "functionCall", surfaceId: p.surfaceId, componentId: p.node.id, call, args });
180
+ }
181
+ },
182
+ [emit, sendDataModel, p.surfaceId, p.node.id, p.data, p.scopePath]
183
+ );
184
+ }
185
+ const ICONS = {
186
+ accountcircle: CircleUserIcon,
187
+ add: PlusIcon,
188
+ arrowback: ArrowLeftIcon,
189
+ arrowforward: ArrowRightIcon,
190
+ attachfile: PaperclipIcon,
191
+ calendartoday: CalendarIcon,
192
+ call: PhoneIcon,
193
+ camera: CameraIcon,
194
+ check: CheckIcon,
195
+ close: XIcon,
196
+ delete: Trash2Icon,
197
+ download: DownloadIcon,
198
+ edit: PencilIcon,
199
+ event: CalendarDaysIcon,
200
+ error: CircleAlertIcon,
201
+ favorite: HeartIcon,
202
+ favoriteoff: HeartOffIcon,
203
+ folder: FolderIcon,
204
+ help: CircleHelpIcon,
205
+ home: HomeIcon,
206
+ info: InfoIcon,
207
+ locationon: MapPinIcon,
208
+ lock: LockIcon,
209
+ lockopen: LockOpenIcon,
210
+ mail: MailIcon,
211
+ menu: MenuIcon,
212
+ morevert: EllipsisVerticalIcon,
213
+ morehoriz: EllipsisIcon,
214
+ notifications: BellIcon,
215
+ notificationsoff: BellOffIcon,
216
+ pause: PauseIcon,
217
+ payment: CreditCardIcon,
218
+ person: UserIcon,
219
+ phone: PhoneIcon,
220
+ photo: ImageIcon,
221
+ play: PlayIcon,
222
+ print: PrinterIcon,
223
+ refresh: RefreshCwIcon,
224
+ search: SearchIcon,
225
+ send: SendIcon,
226
+ settings: SettingsIcon,
227
+ share: Share2Icon,
228
+ shoppingcart: ShoppingCartIcon,
229
+ star: StarIcon,
230
+ staroff: StarOffIcon,
231
+ upload: UploadIcon,
232
+ visibility: EyeIcon,
233
+ visibilityoff: EyeOffIcon,
234
+ warning: TriangleAlertIcon,
235
+ volumeup: Volume2Icon,
236
+ volumeoff: VolumeXIcon,
237
+ // Extras de Orbital y alias frecuentes
238
+ file: FileTextIcon,
239
+ clock: ClockIcon,
240
+ shield: ShieldCheckIcon,
241
+ sparkles: SparklesIcon,
242
+ bolt: ZapIcon,
243
+ bot: BotIcon,
244
+ trendingup: TrendingUpIcon,
245
+ activity: ActivityIcon,
246
+ wrench: WrenchIcon,
247
+ users: UsersIcon,
248
+ success: CircleCheckIcon,
249
+ alert: TriangleAlertIcon,
250
+ bell: BellIcon,
251
+ user: UserIcon,
252
+ trash: Trash2Icon,
253
+ plus: PlusIcon
254
+ };
255
+ function iconFor(name) {
256
+ return ICONS[String(name ?? "").toLowerCase().replace(/[-_\s]/g, "")] ?? CircleHelpIcon;
257
+ }
258
+ const ALERT_ICON = { info: InfoIcon, success: CircleCheckIcon, warning: TriangleAlertIcon, danger: CircleAlertIcon };
259
+ const Row = (p) => {
260
+ const n = p.node;
261
+ return /* @__PURE__ */ jsx("div", { "data-slot": "a2ui-row", className: cn("flex min-w-0 flex-row gap-3", JUSTIFY[n.justify ?? "start"], ALIGN[n.align ?? "stretch"]), children: childrenOf(n.children, p) });
262
+ };
263
+ const Column = (p) => {
264
+ const n = p.node;
265
+ return /* @__PURE__ */ jsx("div", { "data-slot": "a2ui-column", className: cn("flex min-w-0 flex-col gap-3", JUSTIFY[n.justify ?? "start"], ALIGN[n.align ?? "stretch"]), children: childrenOf(n.children, p) });
266
+ };
267
+ const List = (p) => {
268
+ const n = p.node;
269
+ return /* @__PURE__ */ jsx(
270
+ "div",
271
+ {
272
+ "data-slot": "a2ui-list",
273
+ className: cn("flex min-w-0 gap-2", n.direction === "horizontal" ? "flex-row overflow-x-auto" : "flex-col", ALIGN[n.align ?? "stretch"]),
274
+ children: childrenOf(n.children, p)
275
+ }
276
+ );
277
+ };
278
+ const Divider = ({ node }) => /* @__PURE__ */ jsx(Separator, { orientation: node.axis ?? "horizontal" });
279
+ const CardNodeView = (p) => {
280
+ const n = p.node;
281
+ return /* @__PURE__ */ jsx(Card, { "data-slot": "a2ui-card", children: /* @__PURE__ */ jsx(CardContent, { children: p.resolveChild(n.child, p.scopePath) }) });
282
+ };
283
+ const MARKDOWN_HINT = /[*_`#>[\]]|\n|^\s*[-+]\s/;
284
+ const Text = (p) => {
285
+ const n = p.node;
286
+ const { renderMarkdown } = React.useContext(DispatchContext);
287
+ const plain = React.useContext(PlainContext);
288
+ const text = str(n.text, p);
289
+ const caption = n.variant === "caption";
290
+ const rich = !plain && renderMarkdown && MARKDOWN_HINT.test(text);
291
+ if (rich) {
292
+ return /* @__PURE__ */ jsx("div", { "data-slot": "a2ui-text", "data-variant": n.variant ?? "body", className: cn("min-w-0", caption ? "text-xs text-muted-foreground" : "text-sm"), children: renderMarkdown(text) });
293
+ }
294
+ return /* @__PURE__ */ jsx("span", { "data-slot": "a2ui-text", "data-variant": n.variant ?? "body", className: cn("min-w-0 text-pretty", caption ? "text-xs text-muted-foreground" : "text-sm"), children: text });
295
+ };
296
+ const SAFE_URL = /^(https?:|data:image\/|blob:|\/|\.{0,2}\/)/i;
297
+ const IMAGE_VARIANT = {
298
+ icon: "size-6 rounded-md",
299
+ avatar: "size-10 rounded-full",
300
+ smallFeature: "size-16 rounded-lg",
301
+ mediumFeature: "w-full max-w-48 rounded-lg",
302
+ largeFeature: "w-full rounded-lg",
303
+ header: "aspect-[3/1] w-full rounded-lg"
304
+ };
305
+ const IMAGE_FIT = {
306
+ contain: "object-contain",
307
+ cover: "object-cover",
308
+ fill: "object-fill",
309
+ none: "object-none",
310
+ scaleDown: "object-scale-down"
311
+ };
312
+ const Image = (p) => {
313
+ const n = p.node;
314
+ const url = str(n.url, p);
315
+ if (!url || !SAFE_URL.test(url)) return null;
316
+ const variant = n.variant ?? "mediumFeature";
317
+ return /* @__PURE__ */ jsx(
318
+ "img",
319
+ {
320
+ "data-slot": "a2ui-image",
321
+ "data-variant": variant,
322
+ src: url,
323
+ alt: str(n.description, p),
324
+ loading: "lazy",
325
+ className: cn("max-w-full shrink-0", IMAGE_VARIANT[variant], IMAGE_FIT[n.fit ?? (variant === "avatar" || variant === "header" ? "cover" : "contain")])
326
+ }
327
+ );
328
+ };
329
+ const Icon = ({ node, data, scopePath }) => {
330
+ const n = node;
331
+ const name = resolveDynamic(n.name, data, scopePath);
332
+ const Cmp = iconFor(name);
333
+ return /* @__PURE__ */ jsx(Cmp, { "data-slot": "a2ui-icon", "aria-hidden": true, className: "size-4 shrink-0" });
334
+ };
335
+ const Video = (p) => {
336
+ const n = p.node;
337
+ const url = str(n.url, p);
338
+ if (!url || !SAFE_URL.test(url)) return null;
339
+ const poster = str(n.posterUrl, p);
340
+ return /* @__PURE__ */ jsx("video", { "data-slot": "a2ui-video", src: url, poster: poster && SAFE_URL.test(poster) ? poster : void 0, controls: true, className: "max-w-full rounded-lg" });
341
+ };
342
+ const Audio = (p) => {
343
+ const n = p.node;
344
+ const url = str(n.url, p);
345
+ if (!url || !SAFE_URL.test(url)) return null;
346
+ const description = str(n.description, p);
347
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-audio", className: "flex w-full flex-col gap-1.5", children: [
348
+ description ? /* @__PURE__ */ jsx("span", { className: "text-sm", children: description }) : null,
349
+ /* @__PURE__ */ jsx("audio", { src: url, controls: true, className: "w-full" })
350
+ ] });
351
+ };
352
+ const BUTTON_VARIANT = { default: "outline", primary: "default", borderless: "ghost" };
353
+ const ButtonView = (p) => {
354
+ const n = p.node;
355
+ const run = useRunAction(p);
356
+ const blocked = failedChecks(n["@checks"], p.data, p.scopePath, p.locale).length > 0;
357
+ return /* @__PURE__ */ jsx(
358
+ Button,
359
+ {
360
+ type: "button",
361
+ "data-slot": "a2ui-button",
362
+ variant: BUTTON_VARIANT[n.variant ?? "default"],
363
+ disabled: blocked,
364
+ onClick: () => run(n.action),
365
+ children: /* @__PURE__ */ jsx(PlainContext.Provider, { value: true, children: p.resolveChild(n.child, p.scopePath) })
366
+ }
367
+ );
368
+ };
369
+ const TextField = (p) => {
370
+ const n = p.node;
371
+ const id = React.useId();
372
+ const label = str(n.label, p);
373
+ const [value, setValue] = useBound(n.value, "", p);
374
+ const [touched, setTouched] = React.useState(false);
375
+ const placeholder = str(n.placeholder, p) || void 0;
376
+ const common = {
377
+ id,
378
+ value: value ?? "",
379
+ placeholder,
380
+ "aria-invalid": touched && failedChecks(n["@checks"], p.data, p.scopePath, p.locale).length > 0 ? true : void 0,
381
+ onBlur: () => setTouched(true)
382
+ };
383
+ const change = (raw) => setValue(n.variant === "number" ? raw.trim() !== "" && Number.isFinite(Number(raw)) ? Number(raw) : raw : raw);
384
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-text-field", className: "flex w-full flex-col gap-1.5", children: [
385
+ label ? /* @__PURE__ */ jsx(Label, { htmlFor: id, children: label }) : null,
386
+ n.variant === "longText" ? /* @__PURE__ */ jsx(Textarea, { rows: 3, ...common, onChange: (e) => change(e.target.value) }) : /* @__PURE__ */ jsx(Input, { type: n.variant === "number" ? "number" : n.variant === "obscured" ? "password" : "text", ...common, onChange: (e) => change(e.target.value) }),
387
+ /* @__PURE__ */ jsx(CheckMessages, { checks: n["@checks"], p, show: touched })
388
+ ] });
389
+ };
390
+ const CheckBox = (p) => {
391
+ const n = p.node;
392
+ const label = str(n.label, p);
393
+ const [checked, setChecked] = useBound(n.value, false, p);
394
+ const [touched, setTouched] = React.useState(false);
395
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-checkbox", className: "flex flex-col gap-1", children: [
396
+ /* @__PURE__ */ jsxs(Label, { className: "cursor-pointer", children: [
397
+ /* @__PURE__ */ jsx(
398
+ Checkbox,
399
+ {
400
+ checked: checked === true,
401
+ onCheckedChange: (v) => {
402
+ setTouched(true);
403
+ setChecked(v === true);
404
+ }
405
+ }
406
+ ),
407
+ label ? /* @__PURE__ */ jsx("span", { children: label }) : null
408
+ ] }),
409
+ /* @__PURE__ */ jsx(CheckMessages, { checks: n["@checks"], p, show: touched })
410
+ ] });
411
+ };
412
+ const SliderView = (p) => {
413
+ const n = p.node;
414
+ const min = n.min ?? 0;
415
+ const label = str(n.label, p);
416
+ const [value, setValue] = useBound(n.value, min, p);
417
+ const step = typeof n.steps === "number" && n.steps >= 1 ? (n.max - min) / n.steps : 1;
418
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-slider", className: "flex w-full flex-col gap-2", children: [
419
+ label ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
420
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-(--ds-medium-weight)", children: label }),
421
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground tabular-nums", children: value })
422
+ ] }) : null,
423
+ /* @__PURE__ */ jsx(Slider, { "aria-label": label || void 0, value: Number(value), min, max: n.max, step, onValueChange: (v) => setValue(v) }),
424
+ /* @__PURE__ */ jsx(CheckMessages, { checks: n["@checks"], p, show: true })
425
+ ] });
426
+ };
427
+ const ChoicePicker = (p) => {
428
+ const t = useDsMessages();
429
+ const n = p.node;
430
+ const label = str(n.label, p);
431
+ const [selected, setSelected] = useBound(n.value, [], p);
432
+ const [filter, setFilter] = React.useState("");
433
+ const [touched, setTouched] = React.useState(false);
434
+ const multiple = n.variant !== "mutuallyExclusive";
435
+ const chosen = Array.isArray(selected) ? selected : [];
436
+ const options = n.options.map((o) => ({ value: o.value, label: str(o.label, p) || o.value })).filter((o) => !filter || o.label.toLowerCase().includes(filter.toLowerCase()));
437
+ const toggle = (value) => {
438
+ setTouched(true);
439
+ if (!multiple) return setSelected([value]);
440
+ setSelected(chosen.includes(value) ? chosen.filter((x) => x !== value) : [...chosen, value]);
441
+ };
442
+ return /* @__PURE__ */ jsxs("fieldset", { "data-slot": "a2ui-choice-picker", className: "flex min-w-0 flex-col gap-2", children: [
443
+ label ? /* @__PURE__ */ jsx("legend", { className: "mb-1 text-sm font-(--ds-medium-weight)", children: label }) : null,
444
+ n.filterable ? /* @__PURE__ */ jsx(Input, { type: "search", value: filter, placeholder: t.searchPlaceholder, onChange: (e) => setFilter(e.target.value) }) : null,
445
+ n.displayStyle === "chips" ? /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: options.map((o) => /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: chosen.includes(o.value) ? "default" : "outline", "aria-pressed": chosen.includes(o.value), onClick: () => toggle(o.value), children: o.label }, o.value)) }) : multiple ? options.map((o) => /* @__PURE__ */ jsxs(Label, { className: "cursor-pointer", children: [
446
+ /* @__PURE__ */ jsx(Checkbox, { checked: chosen.includes(o.value), onCheckedChange: () => toggle(o.value) }),
447
+ /* @__PURE__ */ jsx("span", { children: o.label })
448
+ ] }, o.value)) : /* @__PURE__ */ jsx(RadioGroup, { value: chosen[0] ?? "", onValueChange: (v) => toggle(String(v)), children: options.map((o) => /* @__PURE__ */ jsxs(Label, { className: "cursor-pointer", children: [
449
+ /* @__PURE__ */ jsx(RadioGroupItem, { value: o.value }),
450
+ /* @__PURE__ */ jsx("span", { children: o.label })
451
+ ] }, o.value)) }),
452
+ /* @__PURE__ */ jsx(CheckMessages, { checks: n["@checks"], p, show: touched })
453
+ ] });
454
+ };
455
+ const DateTimeInput = (p) => {
456
+ const n = p.node;
457
+ const id = React.useId();
458
+ const label = str(n.label, p);
459
+ const [value, setValue] = useBound(n.value, "", p);
460
+ const [touched, setTouched] = React.useState(false);
461
+ const date = n.enableDate !== false;
462
+ const time = n.enableTime === true;
463
+ const type = date && time ? "datetime-local" : time ? "time" : "date";
464
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-date-time", className: "flex w-full flex-col gap-1.5", children: [
465
+ label ? /* @__PURE__ */ jsx(Label, { htmlFor: id, children: label }) : null,
466
+ /* @__PURE__ */ jsx(
467
+ Input,
468
+ {
469
+ id,
470
+ type,
471
+ value: value ?? "",
472
+ min: str(n.min, p) || void 0,
473
+ max: str(n.max, p) || void 0,
474
+ onBlur: () => setTouched(true),
475
+ onChange: (e) => setValue(e.target.value)
476
+ }
477
+ ),
478
+ /* @__PURE__ */ jsx(CheckMessages, { checks: n["@checks"], p, show: touched })
479
+ ] });
480
+ };
481
+ const TabsView = (p) => {
482
+ const n = p.node;
483
+ return /* @__PURE__ */ jsxs(Tabs, { "data-slot": "a2ui-tabs", defaultValue: "0", children: [
484
+ /* @__PURE__ */ jsx(TabsList, { children: n.tabs.map((tab, i) => /* @__PURE__ */ jsx(TabsTrigger, { value: String(i), children: str(tab.title, p) }, i)) }),
485
+ n.tabs.map((tab, i) => /* @__PURE__ */ jsx(TabsContent, { value: String(i), children: p.resolveChild(tab.child, p.scopePath) }, i))
486
+ ] });
487
+ };
488
+ const Modal = (p) => {
489
+ const n = p.node;
490
+ const [open, setOpen] = React.useState(false);
491
+ const t = useDsMessages();
492
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
493
+ /* @__PURE__ */ jsx("span", { "data-slot": "a2ui-modal-trigger", className: "inline-flex", onClick: () => setOpen(true), children: p.resolveChild(n.trigger, p.scopePath) }),
494
+ /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { "data-slot": "a2ui-modal", children: [
495
+ /* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: str(n.title, p) || t.a2uiModalTitle }),
496
+ p.resolveChild(n.content, p.scopePath)
497
+ ] }) })
498
+ ] });
499
+ };
500
+ const PanelView = (p) => {
501
+ const n = p.node;
502
+ const title = str(n.title, p);
503
+ const description = str(n.description, p);
504
+ const Cmp = n.icon ? iconFor(n.icon) : null;
505
+ return /* @__PURE__ */ jsxs(Card, { "data-slot": "a2ui-panel", children: [
506
+ title || description || Cmp ? /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [
507
+ Cmp ? /* @__PURE__ */ jsx(IconTile, { tone: n.tone ?? "primary", size: "md", children: /* @__PURE__ */ jsx(Cmp, {}) }) : null,
508
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-col", children: [
509
+ title ? /* @__PURE__ */ jsx(CardTitle, { children: title }) : null,
510
+ description ? /* @__PURE__ */ jsx(CardDescription, { children: description }) : null
511
+ ] })
512
+ ] }) }) : null,
513
+ /* @__PURE__ */ jsx(CardContent, { children: p.resolveChild(n.child, p.scopePath) }),
514
+ n.footer ? /* @__PURE__ */ jsx(CardFooter, { className: "justify-end gap-2", children: p.resolveChild(n.footer, p.scopePath) }) : null
515
+ ] });
516
+ };
517
+ const HEADING = {
518
+ 1: { tag: "h2", cls: "text-xl" },
519
+ 2: { tag: "h3", cls: "text-lg" },
520
+ 3: { tag: "h4", cls: "text-base" }
521
+ };
522
+ const Heading = (p) => {
523
+ const n = p.node;
524
+ const level = HEADING[n.level ?? 2] ?? HEADING[2];
525
+ const Tag = level.tag;
526
+ const description = str(n.description, p);
527
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-heading", "data-level": n.level ?? 2, className: "flex min-w-0 flex-col gap-0.5", children: [
528
+ /* @__PURE__ */ jsx(Tag, { className: cn("text-balance font-(--ds-strong-weight) text-foreground", level.cls), children: str(n.text, p) }),
529
+ description ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: description }) : null
530
+ ] });
531
+ };
532
+ const IconTileView = ({ node }) => {
533
+ const n = node;
534
+ const Cmp = iconFor(n.name);
535
+ return /* @__PURE__ */ jsx(IconTile, { "data-slot": "a2ui-icon-tile", tone: n.tone ?? "primary", size: n.size ?? "md", children: /* @__PURE__ */ jsx(Cmp, {}) });
536
+ };
537
+ const BADGE_VARIANT = {
538
+ neutral: "neutral",
539
+ primary: "default",
540
+ info: "info",
541
+ success: "success",
542
+ warning: "warning",
543
+ danger: "danger"
544
+ };
545
+ const BadgeView = (p) => {
546
+ const n = p.node;
547
+ return /* @__PURE__ */ jsx(Badge, { "data-slot": "a2ui-badge", variant: BADGE_VARIANT[n.tone ?? "neutral"], children: str(n.text, p) });
548
+ };
549
+ const ProgressView = (p) => {
550
+ const n = p.node;
551
+ const max = typeof n.max === "number" && n.max > 0 ? n.max : 100;
552
+ const raw = Number(resolveDynamic(n.value, p.data, p.scopePath, 0, p.locale) ?? 0);
553
+ const value = Math.min(max, Math.max(0, Number.isFinite(raw) ? raw : 0));
554
+ const label = str(n.label, p);
555
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-progress", className: "flex w-full flex-col gap-1.5", children: [
556
+ /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2 text-sm", children: [
557
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 font-(--ds-medium-weight)", children: label }),
558
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground tabular-nums", children: [
559
+ Math.round(value / max * 100),
560
+ "%"
561
+ ] })
562
+ ] }),
563
+ /* @__PURE__ */ jsx(Progress, { value, max, tone: n.tone, "aria-label": label || void 0 })
564
+ ] });
565
+ };
566
+ const StatView = (p) => {
567
+ const n = p.node;
568
+ const raw = resolveDynamic(n.value, p.data, p.scopePath, 0, p.locale);
569
+ const delta = n.delta === void 0 ? void 0 : resolveDynamic(n.delta, p.data, p.scopePath, 0, p.locale);
570
+ const description = str(n.description, p);
571
+ const Cmp = n.icon ? iconFor(n.icon) : null;
572
+ return /* @__PURE__ */ jsxs(Stat, { "data-slot": "a2ui-stat", tone: n.tone ?? "neutral", children: [
573
+ /* @__PURE__ */ jsxs(StatHeader, { children: [
574
+ /* @__PURE__ */ jsx(StatLabel, { children: str(n.label, p) }),
575
+ Cmp ? /* @__PURE__ */ jsx(StatIcon, { children: /* @__PURE__ */ jsx(Cmp, {}) }) : null
576
+ ] }),
577
+ /* @__PURE__ */ jsx(StatValue, { value: raw ?? null }),
578
+ typeof delta === "number" ? /* @__PURE__ */ jsx(StatDelta, { value: delta }) : null,
579
+ description ? /* @__PURE__ */ jsx(StatDescription, { children: description }) : null
580
+ ] });
581
+ };
582
+ const AlertView = (p) => {
583
+ const n = p.node;
584
+ const tone = n.tone ?? "info";
585
+ const Cmp = ALERT_ICON[tone] ?? InfoIcon;
586
+ const title = str(n.title, p);
587
+ return /* @__PURE__ */ jsxs(Alert, { "data-slot": "a2ui-alert", variant: tone, children: [
588
+ /* @__PURE__ */ jsx(Cmp, {}),
589
+ title ? /* @__PURE__ */ jsx(AlertTitle, { children: title }) : null,
590
+ /* @__PURE__ */ jsx(AlertDescription, { children: str(n.text, p) })
591
+ ] });
592
+ };
593
+ const ListItemView = (p) => {
594
+ const n = p.node;
595
+ const description = str(n.description, p);
596
+ const badge = str(n.badge, p);
597
+ const iconName = str(n.icon, p);
598
+ const Cmp = iconName ? iconFor(iconName) : null;
599
+ const tone = str(n.tone, p) || "primary";
600
+ const badgeTone = str(n.badgeTone, p) || "neutral";
601
+ return /* @__PURE__ */ jsxs(Item, { "data-slot": "a2ui-list-item", variant: "card", children: [
602
+ Cmp ? /* @__PURE__ */ jsx(ItemMedia, { children: /* @__PURE__ */ jsx(IconTile, { tone, size: "md", children: /* @__PURE__ */ jsx(Cmp, {}) }) }) : null,
603
+ /* @__PURE__ */ jsxs(ItemContent, { children: [
604
+ /* @__PURE__ */ jsx(ItemTitle, { children: str(n.title, p) }),
605
+ description ? /* @__PURE__ */ jsx(ItemDescription, { children: description }) : null
606
+ ] }),
607
+ badge || n.action ? /* @__PURE__ */ jsxs(ItemActions, { children: [
608
+ badge ? /* @__PURE__ */ jsx(Badge, { variant: BADGE_VARIANT[badgeTone] ?? "neutral", children: badge }) : null,
609
+ n.action ? p.resolveChild(n.action, p.scopePath) : null
610
+ ] }) : null
611
+ ] });
612
+ };
613
+ const LazyChartCard = React.lazy(() => import("./chart-card.js").then((m) => ({ default: m.ChartCard })));
614
+ const MAX_SERIES = 12;
615
+ const MAX_POINTS = 500;
616
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
617
+ const arr = (raw, p) => {
618
+ const v = resolveDynamic(raw, p.data, p.scopePath, 0, p.locale);
619
+ return Array.isArray(v) ? v : [];
620
+ };
621
+ const ChartView = (p) => {
622
+ const n = p.node;
623
+ const option = React.useMemo(() => {
624
+ if (n.kind === "gauge") {
625
+ const value = num(resolveDynamic(n.value, p.data, p.scopePath, 0, p.locale));
626
+ return { option: gaugeOption({ value, min: n.min ?? 0, max: n.max ?? 100 }), empty: value === null };
627
+ }
628
+ if (n.kind === "donut" || n.kind === "pie") {
629
+ const data = arr(n.slices, p).slice(0, MAX_POINTS).flatMap((s) => {
630
+ const o = s;
631
+ const v = num(o?.value);
632
+ return v === null ? [] : [{ name: String(o?.name ?? ""), value: v }];
633
+ });
634
+ return { option: pieOption({ data, donut: n.kind === "donut" }), empty: data.length === 0 };
635
+ }
636
+ const categories = arr(n.categories, p).slice(0, MAX_POINTS).map((c) => typeof c === "number" ? c : String(c ?? ""));
637
+ const series = arr(n.series, p).slice(0, MAX_SERIES).map((s) => {
638
+ const o = s;
639
+ const data = Array.isArray(o?.data) ? o.data.slice(0, MAX_POINTS).map(num) : [];
640
+ return { name: String(o?.name ?? ""), data };
641
+ });
642
+ const empty = categories.length === 0 || series.length === 0;
643
+ if (n.kind === "bar" || n.kind === "horizontalBar") {
644
+ return { option: barOption({ categories, series, horizontal: n.kind === "horizontalBar", stack: n.stacked }), empty };
645
+ }
646
+ return { option: lineOption({ categories, series, area: n.kind === "area", stack: n.stacked }), empty };
647
+ }, [n, p.data, p.scopePath]);
648
+ const t = useDsMessages();
649
+ return /* @__PURE__ */ jsx("div", { "data-slot": "a2ui-chart", "data-kind": n.kind, className: "min-w-0", children: /* @__PURE__ */ jsx(React.Suspense, { fallback: /* @__PURE__ */ jsx("div", { role: "status", "aria-busy": "true", "aria-label": t.loading, className: "h-40 w-full animate-pulse rounded-lg bg-muted" }), children: /* @__PURE__ */ jsx(
650
+ LazyChartCard,
651
+ {
652
+ preset: n.size ?? "standard",
653
+ title: str(n.title, p) || void 0,
654
+ description: str(n.description, p) || void 0,
655
+ option: option.option,
656
+ empty: option.empty
657
+ }
658
+ ) }) });
659
+ };
660
+ const ORBITAL_CATALOG = {
661
+ Chart: ChartView,
662
+ Row,
663
+ Column,
664
+ List,
665
+ Divider,
666
+ Card: CardNodeView,
667
+ Text,
668
+ Image,
669
+ Icon,
670
+ Video,
671
+ AudioPlayer: Audio,
672
+ Button: ButtonView,
673
+ TextField,
674
+ CheckBox,
675
+ Slider: SliderView,
676
+ ChoicePicker,
677
+ DateTimeInput,
678
+ Tabs: TabsView,
679
+ Modal,
680
+ Panel: PanelView,
681
+ Heading,
682
+ IconTile: IconTileView,
683
+ Badge: BadgeView,
684
+ Progress: ProgressView,
685
+ Stat: StatView,
686
+ Alert: AlertView,
687
+ ListItem: ListItemView
688
+ };
689
+ const emptySurface = () => ({ components: /* @__PURE__ */ new Map(), data: {}, sendDataModel: false });
690
+ function reduce(prev, msg) {
691
+ const next = new Map(prev);
692
+ if ("createSurface" in msg) {
693
+ const { surfaceId, components, dataModel, sendDataModel } = msg.createSurface;
694
+ const surface = emptySurface();
695
+ if (Array.isArray(components)) for (const c of components) surface.components.set(c.id, c);
696
+ if (dataModel && typeof dataModel === "object" && !Array.isArray(dataModel)) surface.data = applyUpdate({}, void 0, dataModel);
697
+ surface.sendDataModel = sendDataModel === true;
698
+ next.set(surfaceId, surface);
699
+ } else if ("updateComponents" in msg) {
700
+ const { surfaceId, components } = msg.updateComponents;
701
+ const cur = next.get(surfaceId) ?? emptySurface();
702
+ const map = new Map(cur.components);
703
+ for (const c of components) map.set(c.id, c);
704
+ next.set(surfaceId, { ...cur, components: map });
705
+ } else if ("updateDataModel" in msg) {
706
+ const { surfaceId, path, value } = msg.updateDataModel;
707
+ const cur = next.get(surfaceId) ?? emptySurface();
708
+ next.set(surfaceId, { ...cur, data: applyUpdate(cur.data, path, value) });
709
+ } else if ("deleteSurface" in msg) {
710
+ next.delete(msg.deleteSurface.surfaceId);
711
+ }
712
+ return next;
713
+ }
714
+ function SurfaceView({
715
+ surfaceId,
716
+ surface,
717
+ catalog,
718
+ setDataPath
719
+ }) {
720
+ const t = useDsMessages();
721
+ const locale = useDsLocale();
722
+ const setPath = React.useCallback((path, value) => setDataPath(surfaceId, path, value), [setDataPath, surfaceId]);
723
+ const peek = React.useCallback((id) => surface.components.get(id), [surface.components]);
724
+ const context = React.useMemo(() => ({ sendDataModel: surface.sendDataModel }), [surface.sendDataModel]);
725
+ const resolveChild = (id, scopePath, seen = []) => {
726
+ const node = surface.components.get(id);
727
+ if (!node) return null;
728
+ if (seen.includes(id) || seen.length > MAX_DEPTH) return null;
729
+ const Renderer = catalog[node.component];
730
+ const key = scopePath ? `${id}@${scopePath}` : id;
731
+ if (!Renderer) {
732
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "a2ui-unknown", "data-component": node.component, role: "note", className: "rounded-lg border border-dashed border-border p-3 text-xs text-muted-foreground", children: [
733
+ t.a2uiUnknown,
734
+ ": ",
735
+ /* @__PURE__ */ jsx("span", { className: "font-mono", children: node.component })
736
+ ] }, key);
737
+ }
738
+ return /* @__PURE__ */ jsx(
739
+ Renderer,
740
+ {
741
+ node,
742
+ surfaceId,
743
+ data: surface.data,
744
+ scopePath,
745
+ locale,
746
+ setDataPath: setPath,
747
+ peek,
748
+ resolveChild: (childId, childScope) => resolveChild(childId, childScope ?? scopePath, [...seen, id])
749
+ },
750
+ key
751
+ );
752
+ };
753
+ return /* @__PURE__ */ jsx(SurfaceContext.Provider, { value: context, children: /* @__PURE__ */ jsx("div", { "data-slot": "a2ui-surface", "data-surface-id": surfaceId, className: "flex min-w-0 flex-col gap-3", children: resolveChild("root") }) });
754
+ }
755
+ function A2UIRenderer({
756
+ messages,
757
+ onAction,
758
+ onIssues,
759
+ catalog,
760
+ renderMarkdown,
761
+ className,
762
+ ...props
763
+ }) {
764
+ const [surfaces, setSurfaces] = React.useState(() => messages.reduce(reduce, /* @__PURE__ */ new Map()));
765
+ const applied = React.useRef(messages.length);
766
+ React.useEffect(() => {
767
+ if (messages.length < applied.current) {
768
+ setSurfaces(messages.reduce(reduce, /* @__PURE__ */ new Map()));
769
+ } else if (messages.length > applied.current) {
770
+ const fresh = messages.slice(applied.current);
771
+ setSurfaces((prev) => fresh.reduce(reduce, prev));
772
+ }
773
+ applied.current = messages.length;
774
+ }, [messages]);
775
+ React.useEffect(() => {
776
+ if (onIssues) onIssues(validateA2UI(messages));
777
+ }, [messages, onIssues]);
778
+ const setDataPath = React.useCallback((surfaceId, path, value) => {
779
+ setSurfaces((prev) => {
780
+ const cur = prev.get(surfaceId);
781
+ if (!cur) return prev;
782
+ const next = new Map(prev);
783
+ next.set(surfaceId, { ...cur, data: applyUpdate(cur.data, path, value) });
784
+ return next;
785
+ });
786
+ }, []);
787
+ const merged = React.useMemo(() => ({ ...ORBITAL_CATALOG, ...catalog }), [catalog]);
788
+ const dispatcher = React.useMemo(() => ({ emit: (event) => onAction?.(event), renderMarkdown }), [onAction, renderMarkdown]);
789
+ return /* @__PURE__ */ jsx(DispatchContext.Provider, { value: dispatcher, children: /* @__PURE__ */ jsx("div", { "data-slot": "a2ui", className: cn("flex min-w-0 flex-col gap-4", className), ...props, children: [...surfaces].map(([id, surface]) => /* @__PURE__ */ jsx(SurfaceView, { surfaceId: id, surface, catalog: merged, setDataPath }, id)) }) });
790
+ }
791
+ export {
792
+ A2UIRenderer
793
+ };