adk-ui 1.0.0

Dynamic UI generation for ADK-Rust agents - render forms, cards, tables, charts and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
import React, { createContext, useContext, useState } from 'react';
import clsx from 'clsx';
import Markdown, { type Components } from 'react-markdown';
import { AlertCircle, CheckCircle, Info, XCircle, User, Mail, Calendar } from 'lucide-react';

import type { CheckRule, FunctionRegistry } from './bindings';
import { evaluateChecks, isDataBinding, resolveDynamicString, resolveDynamicValue, resolvePath } from './bindings';
import { buildActionEvent, buildValidationFailedEvent, runLocalAction } from './events';
import type {
    A2uiActionDefinition,
    A2uiActionEventPayload,
    A2uiClientMessagePayload,
} from './events';
import type { A2uiComponent, A2uiStore } from './store';
import { isExternalNavigationUrl, sanitizeUrl } from '../security';

const IconMap: Record<string, React.ComponentType<any>> = {
    'alert-circle': AlertCircle,
    'check-circle': CheckCircle,
    'info': Info,
    'x-circle': XCircle,
    'user': User,
    'mail': Mail,
    'calendar': Calendar,
};

const markdownComponents: Components = {
    a({ node: _node, href, children, ...props }) {
        const safeHref = sanitizeUrl(href, 'anchor');
        if (!safeHref) {
            return <span>{children}</span>;
        }

        const isExternal = isExternalNavigationUrl(safeHref);
        return (
            <a
                {...props}
                href={safeHref}
                rel={isExternal ? 'noopener noreferrer nofollow' : undefined}
                target={isExternal ? '_blank' : undefined}
            >
                {children}
            </a>
        );
    },
    img({ node: _node, src, alt, ...props }) {
        const safeSrc = sanitizeUrl(src, 'image');
        if (!safeSrc) {
            return null;
        }

        return (
            <img
                {...props}
                alt={alt ?? ''}
                className="max-w-full h-auto rounded-lg"
                loading="lazy"
                referrerPolicy="no-referrer"
                src={safeSrc}
            />
        );
    },
};

function renderBlockedAsset(kind: 'image' | 'video' | 'audio') {
    return <div className="text-sm text-red-600 dark:text-red-400">Blocked unsafe {kind} URL.</div>;
}

type ChildList = string[] | { componentId: string; path: string };

interface A2uiRenderContextValue {
    store: A2uiStore;
    surfaceId: string;
    dataModel: Record<string, unknown>;
    onAction?: (payload: A2uiActionEventPayload) => void;
    onClientMessage?: (payload: A2uiClientMessagePayload) => void;
    functions?: FunctionRegistry;
    bumpVersion: () => void;
}

const A2uiRenderContext = createContext<A2uiRenderContextValue | null>(null);

export interface A2uiSurfaceRendererProps {
    store: A2uiStore;
    surfaceId: string;
    rootId?: string;
    onAction?: (payload: A2uiActionEventPayload) => void;
    onClientMessage?: (payload: A2uiClientMessagePayload) => void;
    theme?: 'light' | 'dark' | 'system';
    functions?: FunctionRegistry;
}

export const A2uiSurfaceRenderer: React.FC<A2uiSurfaceRendererProps> = ({
    store,
    surfaceId,
    rootId = 'root',
    onAction,
    onClientMessage,
    theme,
    functions,
}) => {
    const surface = store.getSurface(surfaceId);
    const [version, setVersion] = useState(0);

    const bumpVersion = React.useCallback(() => {
        setVersion((prev) => prev + 1);
    }, []);

    if (!surface) {
        return null;
    }

    const dataModel = surface.dataModel ?? {};
    const isDark = theme === 'dark';

    return (
        <A2uiRenderContext.Provider
            value={{
                store,
                surfaceId,
                dataModel,
                onAction,
                onClientMessage,
                functions,
                bumpVersion,
            }}
        >
            <div className={isDark ? 'dark' : ''} data-version={version}>
                <A2uiComponentRenderer componentId={rootId} />
            </div>
        </A2uiRenderContext.Provider>
    );
};

const A2uiComponentRenderer: React.FC<{ componentId: string; scope?: Record<string, unknown> }> = ({
    componentId,
    scope,
}) => {
    const ctx = useContext(A2uiRenderContext);
    if (!ctx) {
        return null;
    }
    const surface = ctx.store.getSurface(ctx.surfaceId);
    const component = surface?.components.get(componentId);
    if (!component) {
        return null;
    }

    return (
        <A2uiComponentView
            component={component}
            scope={scope}
        />
    );
};

const A2uiComponentView: React.FC<{ component: A2uiComponent; scope?: Record<string, unknown> }> = ({
    component,
    scope,
}) => {
    const ctx = useContext(A2uiRenderContext);
    if (!ctx) {
        return null;
    }
    const surface = ctx.store.getSurface(ctx.surfaceId);

    const resolveString = (value: unknown) =>
        resolveDynamicString(value, ctx.dataModel, scope, ctx.functions);

    const resolveValue = (value: unknown) =>
        resolveDynamicValue(value, ctx.dataModel, scope, ctx.functions);

    const renderChildList = (children: ChildList | undefined) => {
        if (!children) return null;
        if (Array.isArray(children)) {
            return children.map((childId) => (
                <A2uiComponentRenderer key={childId} componentId={childId} scope={scope} />
            ));
        }
        const items = resolvePath(ctx.dataModel, children.path, scope);
        if (!Array.isArray(items)) {
            return null;
        }
        return items.map((item, index) => {
            const itemScope = typeof item === 'object' && item !== null ? (item as Record<string, unknown>) : {};
            const key = (itemScope && 'id' in itemScope && typeof itemScope.id === 'string') ? itemScope.id : `${children.componentId}-${index}`;
            return (
                <A2uiComponentRenderer
                    key={key}
                    componentId={children.componentId}
                    scope={itemScope}
                />
            );
        });
    };

    const syncValidationState = (bindingPath: string | undefined, checks: unknown) => {
        if (!bindingPath) {
            return;
        }

        if (!Array.isArray(checks) || checks.length === 0) {
            ctx.store.clearValidationError(ctx.surfaceId, bindingPath);
            return;
        }

        const result = evaluateChecks(checks as CheckRule[], ctx.dataModel, scope, ctx.functions);
        if (result.valid) {
            ctx.store.clearValidationError(ctx.surfaceId, bindingPath);
            return;
        }

        const message = result.message ?? 'Validation failed.';
        ctx.store.setValidationError(ctx.surfaceId, bindingPath, message);
        ctx.onClientMessage?.(buildValidationFailedEvent(ctx.surfaceId, bindingPath, message));
    };

    const getValidationError = (bindingPath: string | undefined) => (
        bindingPath ? surface?.validationErrors.get(bindingPath) : undefined
    );

    const baseComponent = component.component;

    switch (baseComponent) {
        case 'Text': {
            const text = resolveString(component.text);
            const variant = component.variant as string | undefined;
            if (variant === 'body' || !variant) {
                return (
                    <div className="prose prose-sm dark:prose-invert max-w-none text-gray-700 dark:text-gray-300">
                        <Markdown components={markdownComponents} skipHtml>{text}</Markdown>
                    </div>
                );
            }
            const Tag = variant === 'h1' ? 'h1'
                : variant === 'h2' ? 'h2'
                    : variant === 'h3' ? 'h3'
                        : variant === 'h4' ? 'h4'
                            : variant === 'code' ? 'code'
                                : 'p';
            const classes = clsx({
                'text-4xl font-bold mb-4 dark:text-white': variant === 'h1',
                'text-3xl font-bold mb-3 dark:text-white': variant === 'h2',
                'text-2xl font-bold mb-2 dark:text-white': variant === 'h3',
                'text-xl font-bold mb-2 dark:text-white': variant === 'h4',
                'font-mono bg-gray-100 dark:bg-gray-800 p-1 rounded dark:text-gray-100': variant === 'code',
                'text-sm text-gray-500 dark:text-gray-400': variant === 'caption',
            });
            return <Tag className={classes}>{text}</Tag>;
        }
        case 'Image': {
            const url = resolveString(component.url);
            const alt = resolveString(component.alt ?? '');
            const fit = component.fit as string | undefined;
            const style = fit ? { objectFit: fit as React.CSSProperties['objectFit'] } : undefined;
            const safeUrl = sanitizeUrl(url, 'image');
            if (!safeUrl) {
                return renderBlockedAsset('image');
            }
            return (
                <img
                    src={safeUrl}
                    alt={alt}
                    style={style}
                    className="max-w-full h-auto"
                    loading="lazy"
                    referrerPolicy="no-referrer"
                />
            );
        }
        case 'Icon': {
            const name = String(component.name ?? 'info');
            const Icon = IconMap[name] || Info;
            const size = typeof component.size === 'number' ? component.size : 24;
            return <Icon size={size} />;
        }
        case 'Row':
        case 'Column': {
            const justify = component.justify as string | undefined;
            const align = component.align as string | undefined;
            const flexDirection = baseComponent === 'Row' ? 'row' : 'column';
            const style: React.CSSProperties = {
                display: 'flex',
                flexDirection,
                justifyContent: mapJustify(justify),
                alignItems: mapAlign(align),
                gap: 12,
            };
            return (
                <div style={style}>
                    {renderChildList(component.children as ChildList)}
                </div>
            );
        }
        case 'List': {
            const direction = component.direction as string | undefined;
            const style: React.CSSProperties = {
                display: 'flex',
                flexDirection: direction === 'horizontal' ? 'row' : 'column',
                gap: 12,
            };
            return (
                <div style={style}>
                    {renderChildList(component.children as ChildList)}
                </div>
            );
        }
        case 'Card': {
            const childId = component.child as string;
            return (
                <div className="bg-white dark:bg-gray-900 rounded-lg border dark:border-gray-700 shadow-sm overflow-hidden mb-4 p-4">
                    <A2uiComponentRenderer componentId={childId} scope={scope} />
                </div>
            );
        }
        case 'Divider': {
            const axis = component.axis as string | undefined;
            return axis === 'vertical'
                ? <div className="w-px bg-gray-200 dark:bg-gray-700 self-stretch mx-2" />
                : <div className="h-px bg-gray-200 dark:bg-gray-700 w-full my-2" />;
        }
        case 'Tabs': {
            const tabs = (component.tabs as Array<{ title: unknown; child: string }>) ?? [];
            return (
                <A2uiTabs
                    tabs={tabs}
                    scope={scope}
                />
            );
        }
        case 'Modal': {
            const triggerId = component.trigger as string;
            const contentId = component.content as string;
            return (
                <A2uiModal
                    triggerId={triggerId}
                    contentId={contentId}
                    scope={scope}
                />
            );
        }
        case 'Button': {
            const childId = component.child as string;
            const variant = component.variant as string | undefined;
            const action = component.action as A2uiActionDefinition | undefined;
            const btnClasses = clsx('px-4 py-2 rounded font-medium transition-colors', {
                'bg-blue-600 text-white hover:bg-blue-700': variant === 'primary' || !variant,
                'bg-transparent text-blue-600 hover:text-blue-700': variant === 'borderless',
            });
            return (
                <button
                    type="button"
                    className={btnClasses}
                    onClick={() => {
                        if (action?.functionCall) {
                            runLocalAction(action, {
                                dataModel: ctx.dataModel,
                                scope,
                                functions: ctx.functions,
                                openUrl: (url) => {
                                    if (typeof window !== 'undefined') {
                                        window.open(url, '_blank', 'noopener,noreferrer');
                                    }
                                },
                            });
                            return;
                        }
                        const event = buildActionEvent(action, ctx.surfaceId, component.id, {
                            dataModel: ctx.dataModel,
                            scope,
                            functions: ctx.functions,
                        });
                        if (event) {
                            ctx.onAction?.(event);
                            ctx.onClientMessage?.(event);
                        }
                    }}
                >
                    <A2uiComponentRenderer componentId={childId} scope={scope} />
                </button>
            );
        }
        case 'CheckBox': {
            const label = resolveString(component.label);
            const value = Boolean(resolveValue(component.value));
            const bindingPath = isDataBinding(component.value) ? component.value.path : undefined;
            const errorMessage = getValidationError(bindingPath);
            return (
                <div className="mb-3">
                    <label className="flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300">
                        <input
                            type="checkbox"
                            checked={value}
                            onChange={(event) => {
                                if (bindingPath) {
                                    ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, event.currentTarget.checked);
                                    syncValidationState(bindingPath, component.checks);
                                    ctx.bumpVersion();
                                }
                            }}
                            className="h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"
                        />
                        {label}
                    </label>
                    {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                </div>
            );
        }
        case 'TextField': {
            const label = resolveString(component.label);
            const variant = component.variant as string | undefined;
            const bindingPath = isDataBinding(component.value) ? component.value.path : undefined;
            const resolved = resolveValue(component.value);
            const value = typeof resolved === 'string' ? resolved : resolved ?? '';
            const errorMessage = getValidationError(bindingPath);
            if (variant === 'longText') {
                return (
                    <div className="mb-3">
                        <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{label}</label>
                        <textarea
                            value={String(value)}
                            onChange={(event) => {
                                if (bindingPath) {
                                    ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, event.currentTarget.value);
                                    syncValidationState(bindingPath, component.checks);
                                    ctx.bumpVersion();
                                }
                            }}
                            className="w-full px-3 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none bg-white dark:bg-gray-800 dark:border-gray-600 dark:text-white"
                            rows={4}
                        />
                        {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                    </div>
                );
            }
            const inputType = variant === 'obscured' ? 'password' : variant === 'number' ? 'number' : 'text';
            return (
                <div className="mb-3">
                    <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{label}</label>
                    <input
                        type={inputType}
                        value={String(value)}
                        onChange={(event) => {
                            if (bindingPath) {
                                const nextValue = inputType === 'number' ? event.currentTarget.valueAsNumber : event.currentTarget.value;
                                ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, Number.isNaN(nextValue as number) ? event.currentTarget.value : nextValue);
                                syncValidationState(bindingPath, component.checks);
                                ctx.bumpVersion();
                            }
                        }}
                        className="w-full px-3 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none bg-white dark:bg-gray-800 dark:border-gray-600 dark:text-white"
                    />
                    {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                </div>
            );
        }
        case 'ChoicePicker': {
            const label = resolveString(component.label ?? '');
            const options = (component.options as Array<{ label: unknown; value: string }>) ?? [];
            const variant = component.variant as string | undefined;
            const bindingPath = isDataBinding(component.value) ? component.value.path : undefined;
            const resolved = resolveValue(component.value);
            const values = Array.isArray(resolved) ? resolved.map(String) : [];
            const errorMessage = getValidationError(bindingPath);
            if (variant === 'mutuallyExclusive') {
                return (
                    <div className="mb-3">
                        {label && <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{label}</label>}
                        <select
                            value={values[0] ?? ''}
                            onChange={(event) => {
                                if (bindingPath) {
                                    ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, [event.currentTarget.value]);
                                    syncValidationState(bindingPath, component.checks);
                                    ctx.bumpVersion();
                                }
                            }}
                            className="w-full px-3 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none bg-white dark:bg-gray-800 dark:border-gray-600 dark:text-white"
                        >
                            <option value="">Select...</option>
                            {options.map((opt, i) => (
                                <option key={i} value={opt.value}>{resolveString(opt.label)}</option>
                            ))}
                        </select>
                        {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                    </div>
                );
            }
            return (
                <div className="mb-3">
                    {label && <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{label}</label>}
                    <select
                        multiple
                        value={values}
                        onChange={(event) => {
                            if (bindingPath) {
                                const selected = Array.from(event.currentTarget.selectedOptions).map((opt) => opt.value);
                                ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, selected);
                                syncValidationState(bindingPath, component.checks);
                                ctx.bumpVersion();
                            }
                        }}
                        className="w-full px-3 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none bg-white dark:bg-gray-800 dark:border-gray-600 dark:text-white"
                    >
                        {options.map((opt, i) => (
                            <option key={i} value={opt.value}>{resolveString(opt.label)}</option>
                        ))}
                    </select>
                    {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                </div>
            );
        }
        case 'Slider': {
            const label = resolveString(component.label ?? '');
            const bindingPath = isDataBinding(component.value) ? component.value.path : undefined;
            const resolved = resolveValue(component.value);
            const value = typeof resolved === 'number' ? resolved : Number(resolved ?? 0);
            const min = typeof component.min === 'number' ? component.min : 0;
            const max = typeof component.max === 'number' ? component.max : 100;
            const errorMessage = getValidationError(bindingPath);
            return (
                <div className="mb-3">
                    {label && <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{label}</label>}
                    <input
                        type="range"
                        min={min}
                        max={max}
                        value={Number.isNaN(value) ? min : value}
                        onChange={(event) => {
                            if (bindingPath) {
                                ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, event.currentTarget.valueAsNumber);
                                syncValidationState(bindingPath, component.checks);
                                ctx.bumpVersion();
                            }
                        }}
                        className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer"
                    />
                    {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                </div>
            );
        }
        case 'DateTimeInput': {
            const label = resolveString(component.label ?? '');
            const bindingPath = isDataBinding(component.value) ? component.value.path : undefined;
            const resolved = resolveValue(component.value);
            const value = typeof resolved === 'string' ? resolved : '';
            const enableDate = component.enableDate !== false;
            const enableTime = component.enableTime !== false;
            const inputType = enableDate && enableTime ? 'datetime-local' : enableDate ? 'date' : 'time';
            const errorMessage = getValidationError(bindingPath);
            return (
                <div className="mb-3">
                    {label && <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{label}</label>}
                    <input
                        type={inputType}
                        value={value}
                        onChange={(event) => {
                            if (bindingPath) {
                                ctx.store.applyUpdateDataModel(ctx.surfaceId, bindingPath, event.currentTarget.value);
                                syncValidationState(bindingPath, component.checks);
                                ctx.bumpVersion();
                            }
                        }}
                        className="w-full px-3 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none bg-white dark:bg-gray-800 dark:border-gray-600 dark:text-white"
                    />
                    {errorMessage && <div className="mt-1 text-sm text-red-600 dark:text-red-400">{errorMessage}</div>}
                </div>
            );
        }
        case 'Video': {
            const url = resolveString(component.url);
            const safeUrl = sanitizeUrl(url, 'media');
            if (!safeUrl) {
                return renderBlockedAsset('video');
            }
            return <video src={safeUrl} controls className="w-full rounded-md" />;
        }
        case 'AudioPlayer': {
            const url = resolveString(component.url);
            const safeUrl = sanitizeUrl(url, 'media');
            if (!safeUrl) {
                return renderBlockedAsset('audio');
            }
            return <audio src={safeUrl} controls className="w-full" />;
        }
        default:
            return null;
    }
};

const A2uiModal: React.FC<{ triggerId: string; contentId: string; scope?: Record<string, unknown> }> = ({
    triggerId,
    contentId,
    scope,
}) => {
    const [open, setOpen] = useState(false);
    return (
        <>
            <span onClick={() => setOpen(true)} className="inline-block cursor-pointer">
                <A2uiComponentRenderer componentId={triggerId} scope={scope} />
            </span>
            {open && (
                <div className="fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50">
                    <div className="bg-white dark:bg-gray-900 rounded-lg shadow-lg max-w-lg w-full">
                        <div className="p-4 flex items-center justify-between border-b dark:border-gray-700">
                            <div className="text-sm font-medium text-gray-700 dark:text-gray-200">Modal</div>
                            <button
                                onClick={() => setOpen(false)}
                                className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
                                type="button"
                            >
                                <XCircle className="w-5 h-5" />
                            </button>
                        </div>
                        <div className="p-4">
                            <A2uiComponentRenderer componentId={contentId} scope={scope} />
                        </div>
                    </div>
                </div>
            )}
        </>
    );
};

const A2uiTabs: React.FC<{ tabs: Array<{ title: unknown; child: string }>; scope?: Record<string, unknown> }> = ({
    tabs,
    scope,
}) => {
    const ctx = useContext(A2uiRenderContext);
    const [activeTab, setActiveTab] = useState(0);

    if (!ctx) {
        return null;
    }

    const resolveString = (value: unknown) =>
        resolveDynamicString(value, ctx.dataModel, scope, ctx.functions);

    return (
        <div className="mb-4">
            <div className="border-b border-gray-200">
                <nav className="flex space-x-4">
                    {tabs.map((tab, i) => (
                        <button
                            key={i}
                            onClick={() => setActiveTab(i)}
                            className={clsx('px-4 py-2 border-b-2 font-medium text-sm transition-colors', {
                                'border-blue-600 text-blue-600': activeTab === i,
                                'border-transparent text-gray-500 hover:text-gray-700': activeTab !== i,
                            })}
                        >
                            {resolveString(tab.title)}
                        </button>
                    ))}
                </nav>
            </div>
            <div className="p-4">
                {tabs[activeTab]?.child && (
                    <A2uiComponentRenderer componentId={tabs[activeTab].child} scope={scope} />
                )}
            </div>
        </div>
    );
};

function mapJustify(value: string | undefined) {
    switch (value) {
        case 'center':
            return 'center';
        case 'end':
            return 'flex-end';
        case 'spaceAround':
            return 'space-around';
        case 'spaceBetween':
            return 'space-between';
        case 'spaceEvenly':
            return 'space-evenly';
        case 'stretch':
            return 'stretch';
        case 'start':
        default:
            return 'flex-start';
    }
}

function mapAlign(value: string | undefined) {
    switch (value) {
        case 'center':
            return 'center';
        case 'end':
            return 'flex-end';
        case 'stretch':
            return 'stretch';
        case 'start':
        default:
            return 'flex-start';
    }
}