glchat-a2ui-react-renderer 0.0.2

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 (75) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +141 -0
  3. package/dist/index.d.ts +19 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +17 -0
  6. package/dist/src/components/Button.d.ts +12 -0
  7. package/dist/src/components/Button.d.ts.map +1 -0
  8. package/dist/src/components/Button.js +38 -0
  9. package/dist/src/components/Card.d.ts +9 -0
  10. package/dist/src/components/Card.d.ts.map +1 -0
  11. package/dist/src/components/Card.js +16 -0
  12. package/dist/src/components/Checkbox.d.ts +5 -0
  13. package/dist/src/components/Checkbox.d.ts.map +1 -0
  14. package/dist/src/components/Checkbox.js +9 -0
  15. package/dist/src/components/Column.d.ts +17 -0
  16. package/dist/src/components/Column.d.ts.map +1 -0
  17. package/dist/src/components/Column.js +20 -0
  18. package/dist/src/components/Image.d.ts +9 -0
  19. package/dist/src/components/Image.d.ts.map +1 -0
  20. package/dist/src/components/Image.js +25 -0
  21. package/dist/src/components/Input.d.ts +8 -0
  22. package/dist/src/components/Input.d.ts.map +1 -0
  23. package/dist/src/components/Input.js +9 -0
  24. package/dist/src/components/Label.d.ts +6 -0
  25. package/dist/src/components/Label.d.ts.map +1 -0
  26. package/dist/src/components/Label.js +10 -0
  27. package/dist/src/components/Row.d.ts +17 -0
  28. package/dist/src/components/Row.d.ts.map +1 -0
  29. package/dist/src/components/Row.js +20 -0
  30. package/dist/src/components/Separator.d.ts +5 -0
  31. package/dist/src/components/Separator.d.ts.map +1 -0
  32. package/dist/src/components/Separator.js +26 -0
  33. package/dist/src/components/Text.d.ts +8 -0
  34. package/dist/src/components/Text.d.ts.map +1 -0
  35. package/dist/src/components/Text.js +22 -0
  36. package/dist/src/components/TextField.d.ts +16 -0
  37. package/dist/src/components/TextField.d.ts.map +1 -0
  38. package/dist/src/components/TextField.js +31 -0
  39. package/dist/src/components/Timeout.d.ts +14 -0
  40. package/dist/src/components/Timeout.d.ts.map +1 -0
  41. package/dist/src/components/Timeout.js +40 -0
  42. package/dist/src/helpers/css.d.ts +11 -0
  43. package/dist/src/helpers/css.d.ts.map +1 -0
  44. package/dist/src/helpers/css.js +13 -0
  45. package/dist/src/helpers/messageParser.d.ts +10 -0
  46. package/dist/src/helpers/messageParser.d.ts.map +1 -0
  47. package/dist/src/helpers/messageParser.js +40 -0
  48. package/dist/src/hooks/useA2UIProcessor.d.ts +17 -0
  49. package/dist/src/hooks/useA2UIProcessor.d.ts.map +1 -0
  50. package/dist/src/hooks/useA2UIProcessor.js +16 -0
  51. package/dist/src/rendering/Surface.d.ts +28 -0
  52. package/dist/src/rendering/Surface.d.ts.map +1 -0
  53. package/dist/src/rendering/Surface.js +55 -0
  54. package/dist/src/rendering/catalog.d.ts +42 -0
  55. package/dist/src/rendering/catalog.d.ts.map +1 -0
  56. package/dist/src/rendering/catalog.js +139 -0
  57. package/dist/src/rendering/componentRegistry.d.ts +9 -0
  58. package/dist/src/rendering/componentRegistry.d.ts.map +1 -0
  59. package/dist/src/rendering/componentRegistry.js +10 -0
  60. package/dist/src/runtime/bindingResolver.d.ts +29 -0
  61. package/dist/src/runtime/bindingResolver.d.ts.map +1 -0
  62. package/dist/src/runtime/bindingResolver.js +143 -0
  63. package/dist/src/runtime/dispatcher.d.ts +15 -0
  64. package/dist/src/runtime/dispatcher.d.ts.map +1 -0
  65. package/dist/src/runtime/dispatcher.js +29 -0
  66. package/dist/src/runtime/messageProcessor.d.ts +54 -0
  67. package/dist/src/runtime/messageProcessor.d.ts.map +1 -0
  68. package/dist/src/runtime/messageProcessor.js +85 -0
  69. package/dist/src/runtime/surfaceManager.d.ts +48 -0
  70. package/dist/src/runtime/surfaceManager.d.ts.map +1 -0
  71. package/dist/src/runtime/surfaceManager.js +90 -0
  72. package/dist/src/types.d.ts +285 -0
  73. package/dist/src/types.d.ts.map +1 -0
  74. package/dist/src/types.js +4 -0
  75. package/package.json +75 -0
@@ -0,0 +1,14 @@
1
+ export type TimeoutUsageHint = 'body' | 'caption' | 'h3' | 'h4' | 'h5';
2
+ export interface A2UITimeoutProps {
3
+ /** Target time in UTC (ISO 8601 string, e.g. '2025-02-11T15:30:00.000Z'). Countdown shows time until this moment. */
4
+ targetTimeUtc: string;
5
+ /** Text style hint */
6
+ usageHint?: TimeoutUsageHint;
7
+ className?: string;
8
+ }
9
+ /**
10
+ * A2UI Timeout component: displays a countdown to a target UTC time.
11
+ * Recomputes remaining time from the target each second to stay in sync.
12
+ */
13
+ export declare function A2UITimeout({ targetTimeUtc, usageHint, className, }: A2UITimeoutProps): import("react/jsx-runtime").JSX.Element;
14
+ //# sourceMappingURL=Timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Timeout.d.ts","sourceRoot":"","sources":["../../../src/components/Timeout.tsx"],"names":[],"mappings":"AAQA,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC/B,qHAAqH;IACrH,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB;IACtB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiBD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAC1B,aAAa,EACb,SAAkB,EAClB,SAAS,GACV,EAAE,gBAAgB,2CAyBlB"}
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useState } from 'react';
4
+ import { A2UIText } from './Text.js';
5
+ import { cn } from '../helpers/css.js';
6
+ function getRemainingSeconds(targetTimeUtc) {
7
+ const targetMs = Date.parse(targetTimeUtc);
8
+ if (Number.isNaN(targetMs))
9
+ return 0;
10
+ return Math.max(0, Math.floor((targetMs - Date.now()) / 1000));
11
+ }
12
+ function formatAsHhMmSs(seconds) {
13
+ const s = Math.max(0, Math.floor(seconds));
14
+ const m = Math.floor(s / 60);
15
+ const h = Math.floor(m / 60);
16
+ const mm = m % 60;
17
+ const ss = s % 60;
18
+ return `${String(h).padStart(2, '0')}:${String(mm).padStart(2, '0')}:${String(ss).padStart(2, '0')}`;
19
+ }
20
+ /**
21
+ * A2UI Timeout component: displays a countdown to a target UTC time.
22
+ * Recomputes remaining time from the target each second to stay in sync.
23
+ */
24
+ export function A2UITimeout({ targetTimeUtc, usageHint = 'body', className, }) {
25
+ const [remaining, setRemaining] = useState(() => getRemainingSeconds(targetTimeUtc));
26
+ useEffect(() => {
27
+ setRemaining(getRemainingSeconds(targetTimeUtc));
28
+ }, [targetTimeUtc]);
29
+ useEffect(() => {
30
+ const t = setInterval(() => {
31
+ const next = getRemainingSeconds(targetTimeUtc);
32
+ setRemaining(next);
33
+ if (next <= 0)
34
+ clearInterval(t);
35
+ }, 1000);
36
+ return () => clearInterval(t);
37
+ }, [targetTimeUtc]);
38
+ const display = formatAsHhMmSs(remaining);
39
+ return (_jsx("div", { className: cn('tabular-nums', className), children: _jsx(A2UIText, { text: display, usageHint: usageHint }) }));
40
+ }
@@ -0,0 +1,11 @@
1
+ import { ClassValue } from 'clsx';
2
+ /**
3
+ * Conditionally joins class names and resolves Tailwind CSS class conflicts.
4
+ * @param {ClassValue[]} inputs A variadic list of class values. Each item can be:
5
+ * - a string (e.g., 'text-sm')
6
+ * - an object with conditional classes (e.g., { 'text-red-500': isError })
7
+ * - an array of class values
8
+ * @returns {string} A single string of class names with conflicts resolved according to Tailwind’s rules.
9
+ */
10
+ export declare function cn(...inputs: ClassValue[]): string;
11
+ //# sourceMappingURL=css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../src/helpers/css.ts"],"names":[],"mappings":"AAAA,OAAa,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAExC;;;;;;;GAOG;AACH,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAElD"}
@@ -0,0 +1,13 @@
1
+ import clsx from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+ /**
4
+ * Conditionally joins class names and resolves Tailwind CSS class conflicts.
5
+ * @param {ClassValue[]} inputs A variadic list of class values. Each item can be:
6
+ * - a string (e.g., 'text-sm')
7
+ * - an object with conditional classes (e.g., { 'text-red-500': isError })
8
+ * - an array of class values
9
+ * @returns {string} A single string of class names with conflicts resolved according to Tailwind’s rules.
10
+ */
11
+ export function cn(...inputs) {
12
+ return twMerge(clsx(inputs));
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { A2UIMessage } from '../types.js';
2
+ /**
3
+ * Parses a JSONL stream (newline-delimited JSON)
4
+ */
5
+ export declare function parseJSONLStream(jsonl: string): A2UIMessage[];
6
+ /**
7
+ * Checks if a message is a valid A2UI message
8
+ */
9
+ export declare function isValidMessage(message: any): message is A2UIMessage;
10
+ //# sourceMappingURL=messageParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageParser.d.ts","sourceRoot":"","sources":["../../../src/helpers/messageParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAY7D;AAeD;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,WAAW,CASnE"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Parses a JSONL stream (newline-delimited JSON)
3
+ */
4
+ export function parseJSONLStream(jsonl) {
5
+ const lines = jsonl.split('\n').filter((line) => line.trim());
6
+ const messages = [];
7
+ for (const line of lines) {
8
+ const message = parseMessage(line);
9
+ if (message) {
10
+ messages.push(message);
11
+ }
12
+ }
13
+ return messages;
14
+ }
15
+ /**
16
+ * Parses a single JSON line into an A2UI message
17
+ */
18
+ function parseMessage(line) {
19
+ try {
20
+ const parsed = JSON.parse(line);
21
+ return parsed;
22
+ }
23
+ catch (error) {
24
+ console.error('Failed to parse A2UI message:', error, line);
25
+ return null;
26
+ }
27
+ }
28
+ /**
29
+ * Checks if a message is a valid A2UI message
30
+ */
31
+ export function isValidMessage(message) {
32
+ if (!message || typeof message !== 'object')
33
+ return false;
34
+ return [
35
+ 'beginRendering',
36
+ 'surfaceUpdate',
37
+ 'dataModelUpdate',
38
+ 'deleteSurface',
39
+ ].some((key) => key in message);
40
+ }
@@ -0,0 +1,17 @@
1
+ import { MessageProcessor } from '../runtime/messageProcessor.js';
2
+ import type { SurfaceState } from '../types.js';
3
+ export interface UseA2UIProcessorResult {
4
+ /** Processor with getSurfaces(), processMessages(), clearSurfaces(). Same API as Lit/Angular. */
5
+ processor: MessageProcessor;
6
+ /** Current surfaces (reactive). Update by calling refreshSurfaces() after processMessages() or client data model updates. */
7
+ surfaces: Map<string, SurfaceState>;
8
+ /** Call after processMessages() or after updating data model from client to re-render. */
9
+ refreshSurfaces: () => void;
10
+ }
11
+ /**
12
+ * Hook that provides a MessageProcessor and reactive surfaces state.
13
+ * Aligns with how Lit/Angular apps own the processor and read getSurfaces().
14
+ * After calling processor.processMessages(messages), call refreshSurfaces() so surfaces state updates and the UI re-renders.
15
+ */
16
+ export declare function useA2UIProcessor(): UseA2UIProcessorResult;
17
+ //# sourceMappingURL=useA2UIProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useA2UIProcessor.d.ts","sourceRoot":"","sources":["../../../src/hooks/useA2UIProcessor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,sBAAsB;IACrC,iGAAiG;IACjG,SAAS,EAAE,gBAAgB,CAAC;IAC5B,6HAA6H;IAC7H,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACpC,0FAA0F;IAC1F,eAAe,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,sBAAsB,CAWzD"}
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+ import { useCallback, useState } from 'react';
3
+ import { MessageProcessor } from '../runtime/messageProcessor.js';
4
+ /**
5
+ * Hook that provides a MessageProcessor and reactive surfaces state.
6
+ * Aligns with how Lit/Angular apps own the processor and read getSurfaces().
7
+ * After calling processor.processMessages(messages), call refreshSurfaces() so surfaces state updates and the UI re-renders.
8
+ */
9
+ export function useA2UIProcessor() {
10
+ const [processor] = useState(() => new MessageProcessor());
11
+ const [surfaces, setSurfaces] = useState(() => new Map());
12
+ const refreshSurfaces = useCallback(() => {
13
+ setSurfaces(new Map(processor.getSurfaces()));
14
+ }, [processor]);
15
+ return { processor, surfaces, refreshSurfaces };
16
+ }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import type { MessageProcessor } from '../runtime/messageProcessor.js';
3
+ import type { SurfaceState, Theme } from '../types.js';
4
+ import { type ComponentCatalog } from './catalog.js';
5
+ export interface A2UISurfaceProps {
6
+ /** Surface identifier (from processor.getSurfaces()) */
7
+ surfaceId: string;
8
+ /** Surface state (from processor.getSurfaces()) */
9
+ surface: SurfaceState;
10
+ /**
11
+ * Optional: pass with refreshSurfaces so TextField/CheckBox update the data model
12
+ * via processor.setData() and refresh. Same as Lit/Angular; required for two-way binding.
13
+ */
14
+ processor?: MessageProcessor;
15
+ /** Call after processor.setData() so the UI re-renders. Pass with processor. */
16
+ refreshSurfaces?: () => void;
17
+ /** Optional: custom catalog. Defaults to DEFAULT_CATALOG. */
18
+ catalog?: ComponentCatalog;
19
+ /** Optional: theme for styling built-in components (className strings per component/part). */
20
+ theme?: Theme;
21
+ }
22
+ /**
23
+ * Renders a single A2UI surface. Aligned with official Lit/Angular Surface:
24
+ * app passes surfaceId and surface from processor.getSurfaces(), and renders
25
+ * one A2UISurface per surface.
26
+ */
27
+ export declare function A2UISurface({ surfaceId, surface, processor, refreshSurfaces, catalog, theme, }: A2UISurfaceProps): React.ReactNode;
28
+ //# sourceMappingURL=Surface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Surface.d.ts","sourceRoot":"","sources":["../../../src/rendering/Surface.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAGV,YAAY,EACZ,KAAK,EAEN,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,KAAK,gBAAgB,EAItB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,OAAO,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,gFAAgF;IAChF,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,8FAA8F;IAC9F,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,OAAO,EACP,SAAS,EACT,eAAe,EACf,OAAyB,EACzB,KAAK,GACN,EAAE,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAqEpC"}
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useCallback, useRef } from 'react';
4
+ import { resolveActionContext } from '../runtime/bindingResolver.js';
5
+ import { DEFAULT_CATALOG, renderComponentFromCatalog, } from './catalog.js';
6
+ /**
7
+ * Renders a single A2UI surface. Aligned with official Lit/Angular Surface:
8
+ * app passes surfaceId and surface from processor.getSurfaces(), and renders
9
+ * one A2UISurface per surface.
10
+ */
11
+ export function A2UISurface({ surfaceId, surface, processor, refreshSurfaces, catalog = DEFAULT_CATALOG, theme, }) {
12
+ const surfaceRef = useRef(null);
13
+ const handleAction = useCallback((action, sourceComponentId) => {
14
+ const resolvedContext = action.context != null
15
+ ? resolveActionContext(action.context, surface.dataModel)
16
+ : undefined;
17
+ const userAction = {
18
+ name: action.name,
19
+ surfaceId,
20
+ sourceComponentId,
21
+ context: resolvedContext,
22
+ timestamp: new Date().toISOString(),
23
+ };
24
+ const message = { userAction };
25
+ if (processor) {
26
+ processor.dispatch(message);
27
+ }
28
+ if (surfaceRef.current) {
29
+ surfaceRef.current.dispatchEvent(new CustomEvent('a2uiaction', { detail: message, bubbles: true }));
30
+ }
31
+ }, [processor, surfaceId, surface.dataModel]);
32
+ const renderComponentById = useCallback((componentId) => {
33
+ const componentDef = surface.componentBuffer.get(componentId);
34
+ if (!componentDef) {
35
+ console.warn(`Component not found: ${componentId}`);
36
+ return null;
37
+ }
38
+ const props = {
39
+ component: componentDef.component,
40
+ dataModel: surface.dataModel,
41
+ sourceComponentId: componentId,
42
+ onAction: handleAction,
43
+ renderChild: (childId) => renderComponentById(childId),
44
+ processor,
45
+ surfaceId,
46
+ refreshSurfaces,
47
+ theme,
48
+ };
49
+ return renderComponentFromCatalog(catalog, componentDef.component, props);
50
+ }, [surface.componentBuffer, surface.dataModel, handleAction, catalog, processor, surfaceId, refreshSurfaces, theme]);
51
+ if (!surface.ready || !surface.rootId) {
52
+ return null;
53
+ }
54
+ return (_jsx("div", { ref: surfaceRef, className: "a2ui-surface", "data-surface-id": surfaceId, children: renderComponentById(surface.rootId) }));
55
+ }
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import type { MessageProcessor } from '../runtime/messageProcessor.js';
3
+ import type { ActionDefinition, Component, Theme } from '../types.js';
4
+ /**
5
+ * Props passed to each catalog renderer when rendering a component.
6
+ * Same contract as Lit/Angular: dataModel, callbacks, and renderChild for recursion.
7
+ * When processor + surfaceId + refreshSurfaces are provided, TextField/CheckBox
8
+ * call processor.setData() and refreshSurfaces() on value change (no app callback).
9
+ */
10
+ export interface ComponentRenderProps {
11
+ component: Component;
12
+ dataModel: Record<string, unknown>;
13
+ sourceComponentId?: string;
14
+ onAction?: (action: ActionDefinition, sourceComponentId: string) => void;
15
+ renderChild?: (componentId: string) => React.ReactNode;
16
+ /** When set, TextField/CheckBox use processor.setData() + refreshSurfaces() on change. */
17
+ processor?: MessageProcessor;
18
+ surfaceId?: string;
19
+ refreshSurfaces?: () => void;
20
+ /** Optional theme for styling (className strings per component/part). */
21
+ theme?: Theme;
22
+ }
23
+ /**
24
+ * A catalog entry: given component data and render props, returns React node.
25
+ * Aligns with Lit componentRegistry / Angular Catalog pattern.
26
+ */
27
+ export type ComponentRenderer = (data: Record<string, unknown>, props: ComponentRenderProps) => React.ReactNode;
28
+ /**
29
+ * Catalog map: component type string → renderer.
30
+ * Same structure as official renderers; keep small for simplicity.
31
+ */
32
+ export type ComponentCatalog = Record<string, ComponentRenderer>;
33
+ /**
34
+ * Default catalog: type → renderer. Same pattern as Lit componentRegistry / Angular Catalog.
35
+ */
36
+ export declare const DEFAULT_CATALOG: ComponentCatalog;
37
+ /**
38
+ * Renders one A2UI component using the given catalog (no recursion).
39
+ * The caller supplies renderChild for children. Used by the tree renderer inside A2UISurface.
40
+ */
41
+ export declare function renderComponentFromCatalog(catalog: ComponentCatalog, component: Component, props: ComponentRenderProps): React.ReactNode;
42
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/rendering/catalog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAkBxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAc,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIlF;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,KAAK,IAAI,CAAC;IACzE,WAAW,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IACvD,0FAA0F;IAC1F,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,yEAAyE;IACzE,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,oBAAoB,KACxB,KAAK,CAAC,SAAS,CAAC;AAErB;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAiOjE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,gBAW7B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,oBAAoB,GAC1B,KAAK,CAAC,SAAS,CAUjB"}
@@ -0,0 +1,139 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Fragment } from 'react';
4
+ import { A2UIColumn } from '../components/Column.js';
5
+ import { A2UIImage } from '../components/Image.js';
6
+ import { A2UIRow } from '../components/Row.js';
7
+ import { A2UIText } from '../components/Text.js';
8
+ import { A2UITextField } from '../components/TextField.js';
9
+ import { A2UITimeout } from '../components/Timeout.js';
10
+ import { Button } from '../components/Button.js';
11
+ import { Card, CardContent } from '../components/Card.js';
12
+ import { Checkbox } from '../components/Checkbox.js';
13
+ import { Label } from '../components/Label.js';
14
+ import { Separator } from '../components/Separator.js';
15
+ import { getPathFromBoundValue, resolveBoundValue, } from '../runtime/bindingResolver.js';
16
+ import { cn } from '../helpers/css.js';
17
+ function renderText(data, props) {
18
+ const usageHint = data.usageHint ?? 'body';
19
+ const textTheme = props.theme?.components?.Text;
20
+ const className = textTheme
21
+ ? (textTheme[usageHint] ?? textTheme.className)
22
+ : undefined;
23
+ return (_jsx(A2UIText, { text: String(resolveBoundValue(data.text, props.dataModel) ?? ''), usageHint: usageHint, className: className }));
24
+ }
25
+ function renderButton(data, props) {
26
+ const variant = data.destructive
27
+ ? 'destructive'
28
+ : data.primary
29
+ ? 'primary'
30
+ : 'outline';
31
+ const buttonClassName = props.theme?.components?.Button;
32
+ return (_jsx(Button, { variant: variant, className: buttonClassName, onClick: () => {
33
+ if (!data.action) {
34
+ return;
35
+ }
36
+ if (!props.sourceComponentId) {
37
+ console.warn('renderButton: sourceComponentId is required for interactive components; action dispatch skipped.', { action: data.action });
38
+ return;
39
+ }
40
+ props.onAction?.(data.action, props.sourceComponentId);
41
+ }, children: data.child ? props.renderChild?.(data.child) : null }));
42
+ }
43
+ function renderCard(data, props) {
44
+ const cardClassName = props.theme?.components?.Card;
45
+ return (_jsx(Card, { className: cardClassName, children: _jsx(CardContent, { className: "p-6", children: props.renderChild?.(data.child) }) }));
46
+ }
47
+ function renderRow(data, props) {
48
+ const children = data.children ?? [];
49
+ const className = props.theme?.components?.Row;
50
+ return (_jsx(A2UIRow, { distribution: data.distribution, alignment: data.alignment, className: className, children: children.map((childId) => (_jsx(Fragment, { children: props.renderChild?.(childId) }, childId))) }));
51
+ }
52
+ function renderColumn(data, props) {
53
+ const children = data.children ?? [];
54
+ const className = props.theme?.components?.Column;
55
+ return (_jsx(A2UIColumn, { distribution: data.distribution, alignment: data.alignment, className: className, children: children.map((childId) => (_jsx(Fragment, { children: props.renderChild?.(childId) }, childId))) }));
56
+ }
57
+ function renderTextField(data, props) {
58
+ const label = data.label != null
59
+ ? resolveBoundValue(data.label, props.dataModel)
60
+ : undefined;
61
+ const textPath = getPathFromBoundValue(data.text);
62
+ const handleChange = (value) => {
63
+ if (!textPath)
64
+ return;
65
+ if (props.processor && props.surfaceId != null && props.refreshSurfaces) {
66
+ props.processor.setData(props.surfaceId, textPath, value);
67
+ props.refreshSurfaces();
68
+ }
69
+ };
70
+ const tfTheme = props.theme?.components?.TextField;
71
+ return (_jsx(A2UITextField, { label: label != null ? String(label) : undefined, value: resolveBoundValue(data.text, props.dataModel) ?? '', textFieldType: data.textFieldType, validationRegexp: data.validationRegexp, onChange: handleChange, className: tfTheme?.container, labelClassName: tfTheme?.label, elementClassName: tfTheme?.element }));
72
+ }
73
+ function renderCheckBox(data, props) {
74
+ const label = data.label != null
75
+ ? resolveBoundValue(data.label, props.dataModel)
76
+ : undefined;
77
+ const checked = resolveBoundValue(data.checked, props.dataModel);
78
+ const checkedPath = getPathFromBoundValue(data.checked);
79
+ const handleChange = (checkedValue) => {
80
+ if (!checkedPath)
81
+ return;
82
+ const normalizedChecked = checkedValue === 'indeterminate' ? false : checkedValue;
83
+ if (props.processor && props.surfaceId != null && props.refreshSurfaces) {
84
+ props.processor.setData(props.surfaceId, checkedPath, normalizedChecked);
85
+ props.refreshSurfaces();
86
+ }
87
+ };
88
+ const checkboxId = props.sourceComponentId ? `${props.sourceComponentId}-checkbox` : undefined;
89
+ const cbTheme = props.theme?.components?.CheckBox;
90
+ return (_jsxs("div", { className: cn('flex items-center gap-2 text-sm text-foreground', cbTheme?.container), children: [_jsx(Checkbox, { id: checkboxId, checked: Boolean(checked), onCheckedChange: handleChange, className: cbTheme?.element }), label != null && (_jsx(Label, { htmlFor: checkboxId, className: cn('font-normal', cbTheme?.label), children: String(label) }))] }));
91
+ }
92
+ function renderImage(data, props) {
93
+ const imageClassName = props.theme?.components?.Image;
94
+ return (_jsx(A2UIImage, { url: String(resolveBoundValue(data.url, props.dataModel) ?? ''), fit: data.fit, usageHint: data.usageHint, className: imageClassName }));
95
+ }
96
+ function renderDivider(data, props) {
97
+ const axis = data.axis ?? 'horizontal';
98
+ const dividerTheme = props.theme?.components?.Divider;
99
+ return (_jsx(Separator, { orientation: axis, className: cn({
100
+ 'h-px w-full': axis === 'horizontal',
101
+ 'h-full w-px': axis === 'vertical',
102
+ }, dividerTheme) }));
103
+ }
104
+ function renderTimeout(data, props) {
105
+ const targetTimeUtc = resolveBoundValue(data.targetTimeUtc, props.dataModel);
106
+ const target = typeof targetTimeUtc === 'string' ? targetTimeUtc : '';
107
+ const timeoutTheme = props.theme?.components?.Timeout;
108
+ return (_jsx(A2UITimeout, { targetTimeUtc: target, usageHint: data.usageHint ?? 'body', className: timeoutTheme }));
109
+ }
110
+ /**
111
+ * Default catalog: type → renderer. Same pattern as Lit componentRegistry / Angular Catalog.
112
+ */
113
+ export const DEFAULT_CATALOG = {
114
+ Text: renderText,
115
+ Button: renderButton,
116
+ Card: renderCard,
117
+ Row: renderRow,
118
+ Column: renderColumn,
119
+ TextField: renderTextField,
120
+ CheckBox: renderCheckBox,
121
+ Image: renderImage,
122
+ Divider: renderDivider,
123
+ Timeout: renderTimeout,
124
+ };
125
+ /**
126
+ * Renders one A2UI component using the given catalog (no recursion).
127
+ * The caller supplies renderChild for children. Used by the tree renderer inside A2UISurface.
128
+ */
129
+ export function renderComponentFromCatalog(catalog, component, props) {
130
+ const componentType = Object.keys(component)[0];
131
+ const componentRecord = component;
132
+ const data = componentRecord[componentType];
133
+ const renderer = catalog[componentType];
134
+ if (renderer) {
135
+ return renderer(data, props);
136
+ }
137
+ console.warn('Unsupported component type:', componentType);
138
+ return _jsxs("div", { children: ["Unsupported component: ", componentType] });
139
+ }
@@ -0,0 +1,9 @@
1
+ import { type ComponentRenderProps } from './catalog.js';
2
+ /**
3
+ * Renders an A2UI component based on its type using the default catalog.
4
+ * For custom types, use renderComponentFromCatalog with a custom catalog.
5
+ */
6
+ export declare function renderComponent(props: ComponentRenderProps): React.ReactNode;
7
+ export type { ComponentRenderProps, ComponentCatalog, ComponentRenderer } from './catalog.js';
8
+ export { DEFAULT_CATALOG, renderComponentFromCatalog } from './catalog.js';
9
+ //# sourceMappingURL=componentRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"componentRegistry.d.ts","sourceRoot":"","sources":["../../../src/rendering/componentRegistry.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,KAAK,CAAC,SAAS,CAE5E;AAED,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,10 @@
1
+ 'use client';
2
+ import { DEFAULT_CATALOG, renderComponentFromCatalog, } from './catalog.js';
3
+ /**
4
+ * Renders an A2UI component based on its type using the default catalog.
5
+ * For custom types, use renderComponentFromCatalog with a custom catalog.
6
+ */
7
+ export function renderComponent(props) {
8
+ return renderComponentFromCatalog(DEFAULT_CATALOG, props.component, props);
9
+ }
10
+ export { DEFAULT_CATALOG, renderComponentFromCatalog } from './catalog.js';
@@ -0,0 +1,29 @@
1
+ import type { ActionContextInput, BoundValue, DataModelContent } from '../types.js';
2
+ /**
3
+ * Returns the binding path from a BoundValue if it has one (writable binding).
4
+ * Literal-only bindings have no path and cannot be updated from the UI.
5
+ */
6
+ export declare function getPathFromBoundValue(boundValue: BoundValue): string | undefined;
7
+ /**
8
+ * Sets a value at a path in the data model (immutable update).
9
+ * Path format: slash-separated only (e.g. "user/name" or "/user/name").
10
+ * Creates nested objects as needed.
11
+ */
12
+ export declare function setPathValue(dataModel: Record<string, any>, path: string, value: unknown): Record<string, any>;
13
+ /**
14
+ * Resolves action context against the data model for user action payload.
15
+ * Accepts context as Record<string, BoundValue> or Array<{ key, value: BoundValue }>.
16
+ * Returns a plain object with resolved values (used when sending UserAction).
17
+ */
18
+ export declare function resolveActionContext(context: ActionContextInput | undefined, dataModel: Record<string, any>): Record<string, any>;
19
+ /**
20
+ * Resolves a BoundValue against a data model.
21
+ * Returns the resolved value (string, number, boolean, or undefined).
22
+ * Safe against malformed input: returns undefined if boundValue is not a non-null object.
23
+ */
24
+ export declare function resolveBoundValue(boundValue: BoundValue, dataModel: Record<string, any>): any;
25
+ /**
26
+ * Updates the data model with new content
27
+ */
28
+ export declare function updateDataModel(currentModel: Record<string, any>, contents: DataModelContent[]): Record<string, any>;
29
+ //# sourceMappingURL=bindingResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindingResolver.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindingResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,GACrB,MAAM,GAAG,SAAS,CAKpB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAyBrB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,kBAAkB,GAAG,SAAS,EACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAerB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,GAAG,CAsBL;AA8BD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,QAAQ,EAAE,gBAAgB,EAAE,GAC3B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAWrB"}