@xmachines/json-render-solid 0.19.0-xm.1

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.
@@ -0,0 +1,611 @@
1
+ import * as solid_js from 'solid-js';
2
+ import { ParentProps, Accessor, JSX, Component } from 'solid-js';
3
+ import { StateStore, StateModel, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, ActionBinding, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams, RenderErrorHandler, UIElement, SchemaDefinition, Spec, ComputedFunction, DirectiveDefinition, FlatElement } from '@xmachines/json-render-core';
4
+ export { RenderErrorHandler, Spec, StateModel, StateStore, createStateStore } from '@xmachines/json-render-core';
5
+ export { ElementTreeSchema, ElementTreeSpec, SolidSchema, SolidSpec, elementTreeSchema, schema } from './schema.mjs';
6
+
7
+ interface StateContextValue {
8
+ state: StateModel;
9
+ get: (path: string) => unknown;
10
+ set: (path: string, value: unknown) => void;
11
+ update: (updates: Record<string, unknown>) => void;
12
+ getSnapshot: () => StateModel;
13
+ subscribeChanges: (listener: (changes: Array<{
14
+ path: string;
15
+ value: unknown;
16
+ }>) => void) => () => void;
17
+ }
18
+ interface StateProviderProps {
19
+ store?: StateStore;
20
+ initialState?: StateModel;
21
+ onStateChange?: (changes: Array<{
22
+ path: string;
23
+ value: unknown;
24
+ }>) => void;
25
+ }
26
+ declare function StateProvider(props: ParentProps<StateProviderProps>): solid_js.JSX.Element;
27
+ declare function useStateStore(): StateContextValue;
28
+ declare function useStateValue<T>(path: string): Accessor<T | undefined>;
29
+ declare function useStateBinding<T>(path: string): [Accessor<T | undefined>, (value: T) => void];
30
+
31
+ interface VisibilityContextValue {
32
+ isVisible: (condition: VisibilityCondition | undefined) => boolean;
33
+ ctx: VisibilityContext;
34
+ }
35
+ type VisibilityProviderProps = ParentProps;
36
+ declare function VisibilityProvider(props: VisibilityProviderProps): solid_js.JSX.Element;
37
+ declare function useVisibility(): VisibilityContextValue;
38
+ declare function useIsVisible(condition: VisibilityCondition | undefined): boolean;
39
+
40
+ interface PendingConfirmation {
41
+ action: ResolvedAction;
42
+ handler: ActionHandler;
43
+ resolve: () => void;
44
+ reject: () => void;
45
+ }
46
+ interface ActionContextValue {
47
+ handlers: Record<string, ActionHandler>;
48
+ loadingActions: Set<string>;
49
+ pendingConfirmation: PendingConfirmation | null;
50
+ execute: (binding: ActionBinding) => Promise<void>;
51
+ confirm: () => void;
52
+ cancel: () => void;
53
+ registerHandler: (name: string, handler: ActionHandler) => void;
54
+ }
55
+ interface ActionProviderProps {
56
+ handlers?: Record<string, ActionHandler>;
57
+ navigate?: (path: string) => void;
58
+ }
59
+ declare function ActionProvider(props: ParentProps<ActionProviderProps>): JSX.Element;
60
+ declare function useActions(): ActionContextValue;
61
+ declare function useAction(binding: ActionBinding): {
62
+ execute: () => Promise<void>;
63
+ isLoading: boolean;
64
+ };
65
+ interface ConfirmDialogProps {
66
+ confirm: ActionConfirm;
67
+ onConfirm: () => void;
68
+ onCancel: () => void;
69
+ }
70
+ declare function ConfirmDialog(props: ConfirmDialogProps): JSX.Element;
71
+
72
+ interface FieldValidationState {
73
+ touched: boolean;
74
+ validated: boolean;
75
+ result: ValidationResult | null;
76
+ }
77
+ interface ValidationContextValue {
78
+ customFunctions: Record<string, ValidationFunction>;
79
+ fieldStates: Record<string, FieldValidationState>;
80
+ validate: (path: string, config: ValidationConfig) => ValidationResult;
81
+ touch: (path: string) => void;
82
+ clear: (path: string) => void;
83
+ validateAll: () => boolean;
84
+ registerField: (path: string, config: ValidationConfig) => void;
85
+ }
86
+ interface ValidationProviderProps {
87
+ customFunctions?: Record<string, ValidationFunction>;
88
+ }
89
+ declare function ValidationProvider(props: ParentProps<ValidationProviderProps>): solid_js.JSX.Element;
90
+ declare function useValidation(): ValidationContextValue;
91
+ declare function useOptionalValidation(): ValidationContextValue | null;
92
+ declare function useFieldValidation(path: string, config?: ValidationConfig): {
93
+ state: Accessor<FieldValidationState>;
94
+ validate: () => ValidationResult;
95
+ touch: () => void;
96
+ clear: () => void;
97
+ errors: Accessor<string[]>;
98
+ isValid: Accessor<boolean>;
99
+ };
100
+
101
+ interface RepeatScopeValue {
102
+ item: unknown;
103
+ index: number;
104
+ basePath: string;
105
+ }
106
+ declare function RepeatScopeProvider(props: ParentProps<RepeatScopeValue>): solid_js.JSX.Element;
107
+ declare function useRepeatScope(): RepeatScopeValue | null;
108
+
109
+ /**
110
+ * State setter function for updating application state
111
+ */
112
+ type SetState = (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
113
+ /**
114
+ * Handle returned by the `on()` function for a specific event.
115
+ * Provides metadata about the event binding and a method to fire it.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const press = on("press");
120
+ * if (press.shouldPreventDefault) e.preventDefault();
121
+ * press.emit();
122
+ * ```
123
+ */
124
+ interface EventHandle {
125
+ /** Fire the event (resolve action bindings) */
126
+ emit: () => void;
127
+ /** Whether any binding requested preventDefault */
128
+ shouldPreventDefault: boolean;
129
+ /** Whether any handler is bound to this event */
130
+ bound: boolean;
131
+ }
132
+ /**
133
+ * Catalog-agnostic base type for component render function arguments.
134
+ * Use this when building reusable component libraries that are not tied
135
+ * to a specific catalog.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * const Card = (ctx: BaseComponentProps<{ title?: string }>) => (
140
+ * <div>{ctx.props.title}{ctx.children}</div>
141
+ * );
142
+ * ```
143
+ */
144
+ interface BaseComponentProps<P = Record<string, unknown>> {
145
+ props: P;
146
+ children?: JSX.Element;
147
+ /** Simple event emitter (shorthand). Fires the event and returns void. */
148
+ emit: (event: string) => void;
149
+ /** Get an event handle with metadata. Use when you need shouldPreventDefault or bound checks. */
150
+ on: (event: string) => EventHandle;
151
+ /**
152
+ * Two-way binding paths resolved from `$bindState` / `$bindItem` expressions.
153
+ * Maps prop name → absolute state path for write-back.
154
+ */
155
+ bindings?: Record<string, string>;
156
+ loading?: boolean;
157
+ }
158
+ /**
159
+ * Context passed to component render functions
160
+ * @example
161
+ * const Button: ComponentFn<typeof catalog, 'Button'> = (ctx) => {
162
+ * return <button onClick={() => ctx.emit("press")}>{ctx.props.label}</button>
163
+ * }
164
+ */
165
+ interface ComponentContext<C extends Catalog, K extends keyof InferCatalogComponents<C>> extends BaseComponentProps<InferComponentProps<C, K>> {
166
+ }
167
+ /**
168
+ * Component render function type for Solid
169
+ * @example
170
+ * const Button: ComponentFn<typeof catalog, 'Button'> = (ctx) => (
171
+ * <button onClick={() => ctx.emit("press")}>{ctx.props.label}</button>
172
+ * );
173
+ */
174
+ type ComponentFn<C extends Catalog, K extends keyof InferCatalogComponents<C>> = (ctx: ComponentContext<C, K>) => JSX.Element;
175
+ /**
176
+ * Registry of all component render functions for a catalog
177
+ * @example
178
+ * const components: Components<typeof myCatalog> = {
179
+ * Button: (ctx) => <button>{ctx.props.label}</button>,
180
+ * Input: (ctx) => <input placeholder={ctx.props.placeholder} />,
181
+ * };
182
+ */
183
+ type Components<C extends Catalog> = {
184
+ [K in keyof InferCatalogComponents<C>]: ComponentFn<C, K>;
185
+ };
186
+ /**
187
+ * Action handler function type
188
+ * @example
189
+ * const viewCustomers: ActionFn<typeof catalog, 'viewCustomers'> = async (params, setState) => {
190
+ * const data = await fetch('/api/customers');
191
+ * setState(prev => ({ ...prev, customers: data }));
192
+ * };
193
+ */
194
+ type ActionFn<C extends Catalog, K extends keyof InferCatalogActions<C>> = (params: InferActionParams<C, K> | undefined, setState: SetState, state: StateModel) => Promise<void>;
195
+ /**
196
+ * Registry of all action handlers for a catalog
197
+ * @example
198
+ * const actions: Actions<typeof myCatalog> = {
199
+ * viewCustomers: async (params, setState) => { ... },
200
+ * createCustomer: async (params, setState) => { ... },
201
+ * };
202
+ */
203
+ type Actions<C extends Catalog> = {
204
+ [K in keyof InferCatalogActions<C>]: ActionFn<C, K>;
205
+ };
206
+ /**
207
+ * True when the catalog declares at least one action, false otherwise.
208
+ * Used by defineRegistry to conditionally require the `actions` field.
209
+ */
210
+ type CatalogHasActions<C extends Catalog> = [
211
+ InferCatalogActions<C>
212
+ ] extends [never] ? false : [keyof InferCatalogActions<C>] extends [never] ? false : true;
213
+
214
+ /**
215
+ * Props passed to component renderers
216
+ */
217
+ interface ComponentRenderProps<P = Record<string, unknown>> {
218
+ /** The element being rendered */
219
+ element: UIElement<string, P>;
220
+ /** Rendered children */
221
+ children?: JSX.Element;
222
+ /** Emit a named event. The renderer resolves the event to action binding(s) from the element's `on` field. Always provided by the renderer. */
223
+ emit: (event: string) => void;
224
+ /** Get an event handle with metadata (shouldPreventDefault, bound). Use when you need to inspect event bindings. */
225
+ on: (event: string) => EventHandle;
226
+ /**
227
+ * Two-way binding paths resolved from `$bindState` / `$bindItem` expressions.
228
+ * Maps prop name → absolute state path for write-back.
229
+ * Only present when at least one prop uses `{ $bindState: "..." }` or `{ $bindItem: "..." }`.
230
+ */
231
+ bindings?: Record<string, string>;
232
+ /** Whether the parent is loading */
233
+ loading?: boolean;
234
+ }
235
+ /**
236
+ * Component renderer type
237
+ */
238
+ type ComponentRenderer<P = Record<string, unknown>> = Component<ComponentRenderProps<P>>;
239
+ /**
240
+ * Registry of component renderers
241
+ */
242
+ type ComponentRegistry = Record<string, ComponentRenderer<any>>;
243
+ /**
244
+ * Props for the Renderer component
245
+ */
246
+ interface RendererProps {
247
+ /** The UI spec to render */
248
+ spec: Spec | null;
249
+ /** Component registry */
250
+ registry: ComponentRegistry;
251
+ /** Whether the spec is currently loading/streaming */
252
+ loading?: boolean;
253
+ /** Fallback component for unknown types */
254
+ fallback?: ComponentRenderer;
255
+ /** Callback for element render errors caught by the inner boundary */
256
+ onRenderError?: RenderErrorHandler;
257
+ }
258
+ /**
259
+ * Main renderer component
260
+ */
261
+ declare function Renderer(props: RendererProps): JSX.Element;
262
+ /**
263
+ * Props for JSONUIProvider
264
+ */
265
+ interface JSONUIProviderProps {
266
+ /** Component registry */
267
+ registry: ComponentRegistry;
268
+ /**
269
+ * External store (controlled mode). When provided, `initialState` and
270
+ * `onStateChange` are ignored.
271
+ */
272
+ store?: StateStore;
273
+ /** Initial state model (uncontrolled mode) */
274
+ initialState?: Record<string, unknown>;
275
+ /** Action handlers */
276
+ handlers?: Record<string, (params: Record<string, unknown>) => Promise<unknown> | unknown>;
277
+ /** Navigation function */
278
+ navigate?: (path: string) => void;
279
+ /** Custom validation functions */
280
+ validationFunctions?: Record<string, (value: unknown, args?: Record<string, unknown>) => boolean>;
281
+ /** Named functions for `$computed` expressions in props */
282
+ functions?: Record<string, ComputedFunction>;
283
+ /** Custom directives for user-defined `$`-prefixed dynamic values */
284
+ directives?: DirectiveDefinition[];
285
+ /** Callback when state changes (uncontrolled mode) */
286
+ onStateChange?: (changes: Array<{
287
+ path: string;
288
+ value: unknown;
289
+ }>) => void;
290
+ children: JSX.Element;
291
+ }
292
+ /**
293
+ * Combined provider for all JSONUI contexts
294
+ */
295
+ declare function JSONUIProvider(props: JSONUIProviderProps): JSX.Element;
296
+ /**
297
+ * Result returned by defineRegistry
298
+ */
299
+ interface DefineRegistryResult {
300
+ /** Component registry for `<Renderer registry={...} />` */
301
+ registry: ComponentRegistry;
302
+ /**
303
+ * Create ActionProvider-compatible handlers.
304
+ * Accepts getter functions so handlers always read the latest state/setState
305
+ * (e.g. from refs or closures).
306
+ */
307
+ handlers: (getSetState: () => SetState | undefined, getState: () => StateModel) => Record<string, (params: Record<string, unknown>) => Promise<void>>;
308
+ /**
309
+ * Execute an action by name imperatively
310
+ * (for use outside the Solid tree, e.g. initial state loading).
311
+ */
312
+ executeAction: (actionName: string, params: Record<string, unknown> | undefined, setState: SetState, state?: StateModel) => Promise<void>;
313
+ }
314
+ /**
315
+ * Options for defineRegistry.
316
+ *
317
+ * When the catalog declares actions, the `actions` field is required.
318
+ * When the catalog has no actions (or `actions: {}`), the field is optional.
319
+ */
320
+ type DefineRegistryOptions<C extends Catalog> = {
321
+ components?: Components<C>;
322
+ onRenderError?: RenderErrorHandler;
323
+ } & (CatalogHasActions<C> extends true ? {
324
+ actions: Actions<C>;
325
+ } : {
326
+ actions?: Actions<C>;
327
+ });
328
+ /**
329
+ * Create a registry from a catalog with components and/or actions.
330
+ *
331
+ * When the catalog declares actions, the `actions` field is required.
332
+ *
333
+ * @example
334
+ * ```tsx
335
+ * // Components only (catalog has no actions)
336
+ * const { registry } = defineRegistry(catalog, {
337
+ * components: {
338
+ * Card: (ctx) => (
339
+ * <div class="card">{ctx.props.title}{ctx.children}</div>
340
+ * ),
341
+ * },
342
+ * });
343
+ *
344
+ * // Both (catalog declares actions)
345
+ * const { registry, handlers, executeAction } = defineRegistry(catalog, {
346
+ * components: { ... },
347
+ * actions: { ... },
348
+ * });
349
+ * ```
350
+ */
351
+ declare function defineRegistry<C extends Catalog>(_catalog: C, options: DefineRegistryOptions<C>): DefineRegistryResult;
352
+ /**
353
+ * Props for renderers created with createRenderer
354
+ */
355
+ interface CreateRendererProps {
356
+ /** The spec to render (AI-generated JSON) */
357
+ spec: Spec | null;
358
+ /**
359
+ * External store (controlled mode). When provided, `state` and
360
+ * `onStateChange` are ignored.
361
+ */
362
+ store?: StateStore;
363
+ /** State context for dynamic values (uncontrolled mode) */
364
+ state?: Record<string, unknown>;
365
+ /** Action handler */
366
+ onAction?: (actionName: string, params?: Record<string, unknown>) => void;
367
+ /** Callback when state changes (uncontrolled mode) */
368
+ onStateChange?: (changes: Array<{
369
+ path: string;
370
+ value: unknown;
371
+ }>) => void;
372
+ /** Named functions for `$computed` expressions in props */
373
+ functions?: Record<string, ComputedFunction>;
374
+ /** Custom directives for user-defined `$`-prefixed dynamic values */
375
+ directives?: DirectiveDefinition[];
376
+ /** Whether the spec is currently loading/streaming */
377
+ loading?: boolean;
378
+ /** Fallback component for unknown types */
379
+ fallback?: ComponentRenderer;
380
+ /** Callback for element render errors caught by the inner boundary */
381
+ onRenderError?: RenderErrorHandler;
382
+ }
383
+ /**
384
+ * Component map type - maps component names to Solid components
385
+ */
386
+ type ComponentMap<TComponents extends Record<string, {
387
+ props: unknown;
388
+ }>> = {
389
+ [K in keyof TComponents]: Component<ComponentRenderProps<TComponents[K]["props"] extends {
390
+ _output: infer O;
391
+ } ? O : Record<string, unknown>>>;
392
+ };
393
+ /**
394
+ * Create a renderer from a catalog
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * const DashboardRenderer = createRenderer(dashboardCatalog, {
399
+ * Card: (renderProps) => <div class="card">{renderProps.children}</div>,
400
+ * Metric: (renderProps) => <span>{renderProps.element.props.value}</span>,
401
+ * });
402
+ *
403
+ * // Usage
404
+ * <DashboardRenderer spec={aiGeneratedSpec} state={state} />
405
+ * ```
406
+ */
407
+ declare function createRenderer<TDef extends SchemaDefinition, TCatalog extends {
408
+ components: Record<string, {
409
+ props: unknown;
410
+ }>;
411
+ }>(catalog: Catalog<TDef, TCatalog>, components: ComponentMap<TCatalog["components"]>): Component<CreateRendererProps>;
412
+
413
+ /**
414
+ * Token usage metadata from AI generation
415
+ */
416
+ interface TokenUsage {
417
+ promptTokens: number;
418
+ completionTokens: number;
419
+ totalTokens: number;
420
+ }
421
+ /**
422
+ * Options for useUIStream
423
+ */
424
+ interface UseUIStreamOptions {
425
+ /** API endpoint */
426
+ api: string;
427
+ /** Callback when complete */
428
+ onComplete?: (spec: Spec) => void;
429
+ /** Callback on error */
430
+ onError?: (error: Error) => void;
431
+ }
432
+ /**
433
+ * Return type for useUIStream
434
+ */
435
+ interface UseUIStreamReturn {
436
+ /** Current UI spec */
437
+ readonly spec: Spec | null;
438
+ /** Whether currently streaming */
439
+ readonly isStreaming: boolean;
440
+ /** Error if any */
441
+ readonly error: Error | null;
442
+ /** Token usage from the last generation */
443
+ readonly usage: TokenUsage | null;
444
+ /** Raw JSONL lines received from the stream (JSON patch lines) */
445
+ readonly rawLines: string[];
446
+ /** Send a prompt to generate UI */
447
+ send: (prompt: string, context?: Record<string, unknown>) => Promise<void>;
448
+ /** Clear the current spec */
449
+ clear: () => void;
450
+ }
451
+ /**
452
+ * Hook for streaming UI generation
453
+ */
454
+ declare function useUIStream(options: UseUIStreamOptions): UseUIStreamReturn;
455
+ /**
456
+ * Convert a flat element list to a Spec.
457
+ * Input elements use key/parentKey to establish identity and relationships.
458
+ * Output spec uses the map-based format where key is the map entry key
459
+ * and parent-child relationships are expressed through children arrays.
460
+ */
461
+ declare function flatToTree(elements: FlatElement[]): Spec;
462
+ /**
463
+ * Hook for two-way bound props. Returns `[value, setValue]` where:
464
+ *
465
+ * - `value` is the already-resolved prop value (passed through from render props)
466
+ * - `setValue` writes back to the bound state path (no-op if not bound)
467
+ *
468
+ * Designed to work with the `bindings` map that the renderer provides when
469
+ * a prop uses `{ $bindState: "/path" }` or `{ $bindItem: "field" }`.
470
+ *
471
+ * @example
472
+ * ```tsx
473
+ * import { useBoundProp } from "@xmachines/json-render-solid";
474
+ *
475
+ * const Input: ComponentRenderer = (ctx) => {
476
+ * const [value, setValue] = useBoundProp<string>(ctx.props.value, ctx.bindings?.value);
477
+ * return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
478
+ * };
479
+ * ```
480
+ */
481
+ declare function useBoundProp<T>(propValue: T | undefined, bindingPath: string | undefined): [T | undefined, (value: T) => void];
482
+ /**
483
+ * A single part from the AI SDK's `message.parts` array. This is a minimal
484
+ * structural type so that library helpers do not depend on the AI SDK.
485
+ * Fields are optional because different part types carry different data:
486
+ * - Text parts have `text`
487
+ * - Data parts have `data`
488
+ */
489
+ interface DataPart {
490
+ type: string;
491
+ text?: string;
492
+ data?: unknown;
493
+ }
494
+ declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
495
+ /**
496
+ * Extract and join all text content from a message's parts array.
497
+ *
498
+ * Filters for parts with `type === "text"`, trims each one, and joins them
499
+ * with double newlines so that text from separate agent steps renders as
500
+ * distinct paragraphs in markdown.
501
+ *
502
+ * Has no AI SDK dependency -- operates on a generic `DataPart[]`.
503
+ *
504
+ * @example
505
+ * ```tsx
506
+ * const text = getTextFromParts(message.parts);
507
+ * if (text) {
508
+ * return <Streamdown>{text}</Streamdown>;
509
+ * }
510
+ * ```
511
+ */
512
+ declare function getTextFromParts(parts: DataPart[]): string;
513
+ /**
514
+ * Hook that extracts both the json-render spec and text content from a
515
+ * message's parts array. Combines `buildSpecFromParts` and `getTextFromParts`
516
+ * into a single call with memoized results.
517
+ *
518
+ * **Memoization behavior:** Results are recomputed only when the `parts`
519
+ * accessor returns a new array reference with a different length or last
520
+ * element. This is optimized for the typical AI SDK streaming pattern where
521
+ * parts are appended incrementally.
522
+ *
523
+ * @example
524
+ * ```tsx
525
+ * import { useJsonRenderMessage } from "@xmachines/json-render-solid";
526
+ *
527
+ * function MessageBubble(props: { parts: DataPart[] }) {
528
+ * const msg = useJsonRenderMessage(() => props.parts);
529
+ *
530
+ * return (
531
+ * <div>
532
+ * {msg.text && <Markdown>{msg.text}</Markdown>}
533
+ * {msg.hasSpec && <MyRenderer spec={msg.spec!} />}
534
+ * </div>
535
+ * );
536
+ * }
537
+ * ```
538
+ */
539
+ declare function useJsonRenderMessage(getParts: () => DataPart[]): {
540
+ readonly spec: Spec | null;
541
+ readonly text: string;
542
+ readonly hasSpec: boolean;
543
+ };
544
+ /**
545
+ * A single message in the chat, which may contain text, a rendered UI spec, or both.
546
+ */
547
+ interface ChatMessage {
548
+ /** Unique message ID */
549
+ id: string;
550
+ /** Who sent this message */
551
+ role: "user" | "assistant";
552
+ /** Text content (conversational prose) */
553
+ text: string;
554
+ /** json-render Spec built from JSONL patches (null if no UI was generated) */
555
+ spec: Spec | null;
556
+ }
557
+ /**
558
+ * Options for useChatUI
559
+ */
560
+ interface UseChatUIOptions {
561
+ /** API endpoint that accepts `{ messages: Array<{ role, content }> }` and returns a text stream */
562
+ api: string;
563
+ /** Callback when streaming completes for a message */
564
+ onComplete?: (message: ChatMessage) => void;
565
+ /** Callback on error */
566
+ onError?: (error: Error) => void;
567
+ }
568
+ /**
569
+ * Return type for useChatUI
570
+ */
571
+ interface UseChatUIReturn {
572
+ /** All messages in the conversation */
573
+ readonly messages: ChatMessage[];
574
+ /** Whether currently streaming an assistant response */
575
+ readonly isStreaming: boolean;
576
+ /** Error from the last request, if any */
577
+ readonly error: Error | null;
578
+ /** Send a user message */
579
+ send: (text: string) => Promise<void>;
580
+ /** Clear all messages and reset the conversation */
581
+ clear: () => void;
582
+ }
583
+ /**
584
+ * Hook for chat + GenUI experiences.
585
+ *
586
+ * Manages a multi-turn conversation where each assistant message can contain
587
+ * both conversational text and a json-render UI spec. The hook sends the full
588
+ * message history to the API endpoint, reads the streamed response, and
589
+ * separates text lines from JSONL patch lines using `createMixedStreamParser`.
590
+ *
591
+ * @example
592
+ * ```tsx
593
+ * const chat = useChatUI({ api: "/api/chat" });
594
+ *
595
+ * // Send a message
596
+ * await chat.send("Compare weather in NYC and Tokyo");
597
+ *
598
+ * // Render messages
599
+ * <For each={chat.messages}>
600
+ * {(msg) => (
601
+ * <div>
602
+ * {msg.text && <p>{msg.text}</p>}
603
+ * {msg.spec && <MyRenderer spec={msg.spec} />}
604
+ * </div>
605
+ * )}
606
+ * </For>
607
+ * ```
608
+ */
609
+ declare function useChatUI(options: UseChatUIOptions): UseChatUIReturn;
610
+
611
+ export { type ActionContextValue, type ActionFn, ActionProvider, type ActionProviderProps, type Actions, type BaseComponentProps, type ChatMessage, type ComponentContext, type ComponentFn, type ComponentMap, type ComponentRegistry, type ComponentRenderProps, type ComponentRenderer, type Components, ConfirmDialog, type ConfirmDialogProps, type CreateRendererProps, type DataPart, type DefineRegistryResult, type EventHandle, type FieldValidationState, JSONUIProvider, type JSONUIProviderProps, type PendingConfirmation, Renderer, type RendererProps, RepeatScopeProvider, type RepeatScopeValue, type SetState, type StateContextValue, StateProvider, type StateProviderProps, type TokenUsage, type UseChatUIOptions, type UseChatUIReturn, type UseUIStreamOptions, type UseUIStreamReturn, type ValidationContextValue, ValidationProvider, type ValidationProviderProps, type VisibilityContextValue, VisibilityProvider, type VisibilityProviderProps, buildSpecFromParts, createRenderer, defineRegistry, flatToTree, getTextFromParts, useAction, useActions, useBoundProp, useChatUI, useFieldValidation, useIsVisible, useJsonRenderMessage, useOptionalValidation, useRepeatScope, useStateBinding, useStateStore, useStateValue, useUIStream, useValidation, useVisibility };