@ng-render/angular 0.1.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.
- package/README.md +87 -0
- package/fesm2022/ng-render-angular.mjs +1527 -0
- package/fesm2022/ng-render-angular.mjs.map +1 -0
- package/package.json +43 -0
- package/types/ng-render-angular.d.ts +537 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import * as _json_render_core from '@json-render/core';
|
|
2
|
+
import { Catalog, InferCatalogActions, InferActionParams, StateModel, InferCatalogComponents, InferComponentProps, UIElement, ActionHandler, VisibilityContext, VisibilityCondition, ResolvedAction, ActionBinding, ValidationResult, ValidationFunction, ValidationConfig, Spec, JsonPatch, FlatElement } from '@json-render/core';
|
|
3
|
+
export { ActionBinding, Catalog, FlatElement, JsonPatch, Spec, StateModel, UIElement, VisibilityCondition, defineCatalog } from '@json-render/core';
|
|
4
|
+
import * as i0 from '@angular/core';
|
|
5
|
+
import { Type, InjectionToken, EnvironmentProviders, OnDestroy, ViewContainerRef, Signal } from '@angular/core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The schema for @ng-render/angular.
|
|
9
|
+
*
|
|
10
|
+
* Identical to the React schema — the schema is framework-agnostic.
|
|
11
|
+
*/
|
|
12
|
+
declare const schema: _json_render_core.Schema<{
|
|
13
|
+
spec: _json_render_core.SchemaType<"object", {
|
|
14
|
+
root: _json_render_core.SchemaType<"string", unknown>;
|
|
15
|
+
elements: _json_render_core.SchemaType<"record", _json_render_core.SchemaType<"object", {
|
|
16
|
+
type: _json_render_core.SchemaType<"ref", string>;
|
|
17
|
+
props: _json_render_core.SchemaType<"propsOf", string>;
|
|
18
|
+
children: _json_render_core.SchemaType<"array", _json_render_core.SchemaType<"string", unknown>>;
|
|
19
|
+
visible: _json_render_core.SchemaType<"any", unknown>;
|
|
20
|
+
}>>;
|
|
21
|
+
}>;
|
|
22
|
+
catalog: _json_render_core.SchemaType<"object", {
|
|
23
|
+
components: _json_render_core.SchemaType<"map", {
|
|
24
|
+
props: _json_render_core.SchemaType<"zod", unknown>;
|
|
25
|
+
slots: _json_render_core.SchemaType<"array", _json_render_core.SchemaType<"string", unknown>>;
|
|
26
|
+
description: _json_render_core.SchemaType<"string", unknown>;
|
|
27
|
+
example: _json_render_core.SchemaType<"any", unknown>;
|
|
28
|
+
}>;
|
|
29
|
+
actions: _json_render_core.SchemaType<"map", {
|
|
30
|
+
params: _json_render_core.SchemaType<"zod", unknown>;
|
|
31
|
+
description: _json_render_core.SchemaType<"string", unknown>;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
}>;
|
|
35
|
+
type AngularSchema = typeof schema;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* State setter function for updating application state.
|
|
39
|
+
*/
|
|
40
|
+
type SetState = (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Handle returned by the `on()` function for a specific event.
|
|
43
|
+
*/
|
|
44
|
+
interface EventHandle {
|
|
45
|
+
emit: () => void;
|
|
46
|
+
shouldPreventDefault: boolean;
|
|
47
|
+
bound: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Context passed to Angular component render functions via defineRegistry.
|
|
51
|
+
*/
|
|
52
|
+
interface ComponentRenderContext<P = Record<string, unknown>> {
|
|
53
|
+
props: P;
|
|
54
|
+
emit: (event: string) => void;
|
|
55
|
+
on: (event: string) => EventHandle;
|
|
56
|
+
bindings?: Record<string, string>;
|
|
57
|
+
loading?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Type-safe component render context for a specific catalog component.
|
|
61
|
+
*/
|
|
62
|
+
interface CatalogComponentContext<C extends Catalog, K extends keyof InferCatalogComponents<C>> extends ComponentRenderContext<InferComponentProps<C, K>> {
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Action handler function type.
|
|
66
|
+
*/
|
|
67
|
+
type ActionFn<C extends Catalog, K extends keyof InferCatalogActions<C>> = (params: InferActionParams<C, K> | undefined, setState: SetState, state: StateModel) => Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Registry of all action handlers for a catalog.
|
|
70
|
+
*/
|
|
71
|
+
type Actions<C extends Catalog> = {
|
|
72
|
+
[K in keyof InferCatalogActions<C>]: ActionFn<C, K>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* True when the catalog declares at least one action.
|
|
76
|
+
*/
|
|
77
|
+
type CatalogHasActions<C extends Catalog> = [
|
|
78
|
+
InferCatalogActions<C>
|
|
79
|
+
] extends [never] ? false : [keyof InferCatalogActions<C>] extends [never] ? false : true;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Maps element type names to Angular component classes.
|
|
83
|
+
*/
|
|
84
|
+
type ComponentRegistry = Record<string, Type<any>>;
|
|
85
|
+
/**
|
|
86
|
+
* Interface that renderable Angular components should implement.
|
|
87
|
+
* All inputs are set via ComponentRef.setInput().
|
|
88
|
+
*/
|
|
89
|
+
interface JsonRenderComponent<P = Record<string, unknown>> {
|
|
90
|
+
element: UIElement<string, P>;
|
|
91
|
+
emit: (event: string) => void;
|
|
92
|
+
on: (event: string) => EventHandle;
|
|
93
|
+
bindings?: Record<string, string>;
|
|
94
|
+
loading?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare const NG_RENDER_REGISTRY: InjectionToken<ComponentRegistry>;
|
|
98
|
+
declare const NG_RENDER_ACTION_HANDLERS: InjectionToken<Record<string, ActionHandler>>;
|
|
99
|
+
declare const NG_RENDER_NAVIGATE: InjectionToken<(path: string) => void>;
|
|
100
|
+
declare const NG_RENDER_FALLBACK: InjectionToken<Type<any>>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Result from defineRegistry.
|
|
104
|
+
*/
|
|
105
|
+
interface DefineRegistryResult {
|
|
106
|
+
registry: ComponentRegistry;
|
|
107
|
+
handlers: (getSetState: () => SetState | undefined, getState: () => StateModel) => Record<string, (params: Record<string, unknown>) => Promise<void>>;
|
|
108
|
+
executeAction: (actionName: string, params: Record<string, unknown> | undefined, setState: SetState, state?: StateModel) => Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Options for defineRegistry. Actions are required when the catalog declares them.
|
|
112
|
+
*/
|
|
113
|
+
type DefineRegistryOptions<C extends Catalog> = {
|
|
114
|
+
components?: Record<string, Type<any>>;
|
|
115
|
+
} & (CatalogHasActions<C> extends true ? {
|
|
116
|
+
actions: Actions<C>;
|
|
117
|
+
} : {
|
|
118
|
+
actions?: Actions<C>;
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Create a type-safe registry from a catalog.
|
|
122
|
+
* Maps component names to Angular component classes.
|
|
123
|
+
*/
|
|
124
|
+
declare function defineRegistry<C extends Catalog>(_catalog: C, options: DefineRegistryOptions<C>): DefineRegistryResult;
|
|
125
|
+
/**
|
|
126
|
+
* Options for provideNgRender.
|
|
127
|
+
*/
|
|
128
|
+
interface ProvideNgRenderOptions {
|
|
129
|
+
registry: ComponentRegistry;
|
|
130
|
+
handlers?: Record<string, ActionHandler>;
|
|
131
|
+
navigate?: (path: string) => void;
|
|
132
|
+
fallback?: Type<any>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Provide ng-render configuration at the environment level.
|
|
136
|
+
* Replaces React's <JSONUIProvider>.
|
|
137
|
+
*/
|
|
138
|
+
declare function provideNgRender(options: ProvideNgRenderOptions): EnvironmentProviders;
|
|
139
|
+
|
|
140
|
+
declare class SpecStateService {
|
|
141
|
+
private readonly _state;
|
|
142
|
+
readonly state: i0.Signal<StateModel>;
|
|
143
|
+
get(path: string): unknown;
|
|
144
|
+
set(path: string, value: unknown): void;
|
|
145
|
+
update(updates: Record<string, unknown>): void;
|
|
146
|
+
initialize(initialState: StateModel): void;
|
|
147
|
+
mergeInitialState(state: StateModel): void;
|
|
148
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SpecStateService, never>;
|
|
149
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SpecStateService>;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
declare class VisibilityService {
|
|
153
|
+
private readonly stateService;
|
|
154
|
+
readonly ctx: i0.Signal<VisibilityContext>;
|
|
155
|
+
isVisible(condition: VisibilityCondition | undefined): boolean;
|
|
156
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<VisibilityService, never>;
|
|
157
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<VisibilityService>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface PendingConfirmation {
|
|
161
|
+
action: ResolvedAction;
|
|
162
|
+
handler: ActionHandler;
|
|
163
|
+
resolve: () => void;
|
|
164
|
+
reject: () => void;
|
|
165
|
+
}
|
|
166
|
+
declare class ActionDispatcherService {
|
|
167
|
+
private readonly stateService;
|
|
168
|
+
private readonly handlers;
|
|
169
|
+
private readonly navigate;
|
|
170
|
+
readonly loadingActions: i0.WritableSignal<Set<string>>;
|
|
171
|
+
readonly pendingConfirmation: i0.WritableSignal<PendingConfirmation | null>;
|
|
172
|
+
execute(binding: ActionBinding): Promise<void>;
|
|
173
|
+
confirm(): void;
|
|
174
|
+
cancel(): void;
|
|
175
|
+
private executeHandler;
|
|
176
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ActionDispatcherService, never>;
|
|
177
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ActionDispatcherService>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface FieldValidationState {
|
|
181
|
+
touched: boolean;
|
|
182
|
+
validated: boolean;
|
|
183
|
+
result: ValidationResult | null;
|
|
184
|
+
}
|
|
185
|
+
declare class ValidationService {
|
|
186
|
+
private readonly stateService;
|
|
187
|
+
private customFunctions;
|
|
188
|
+
private fieldConfigs;
|
|
189
|
+
readonly fieldStates: i0.WritableSignal<Record<string, FieldValidationState>>;
|
|
190
|
+
setCustomFunctions(fns: Record<string, ValidationFunction>): void;
|
|
191
|
+
registerField(path: string, config: ValidationConfig): void;
|
|
192
|
+
validate(path: string, config: ValidationConfig): ValidationResult;
|
|
193
|
+
touch(path: string): void;
|
|
194
|
+
clear(path: string): void;
|
|
195
|
+
validateAll(): boolean;
|
|
196
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ValidationService, never>;
|
|
197
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ValidationService>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare class RepeatScopeService {
|
|
201
|
+
item: unknown;
|
|
202
|
+
index: number;
|
|
203
|
+
basePath: string;
|
|
204
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RepeatScopeService, never>;
|
|
205
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<RepeatScopeService>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
declare class JsonRendererComponent {
|
|
209
|
+
readonly spec: i0.InputSignal<Spec | null>;
|
|
210
|
+
readonly loading: i0.InputSignal<boolean>;
|
|
211
|
+
readonly initialState: i0.InputSignal<StateModel>;
|
|
212
|
+
readonly onStateChange: i0.InputSignal<((path: string, value: unknown) => void) | undefined>;
|
|
213
|
+
private readonly stateService;
|
|
214
|
+
private previousSpecState;
|
|
215
|
+
private previousInitialState;
|
|
216
|
+
readonly rootElement: i0.Signal<_json_render_core.UIElement<string, Record<string, unknown>> | null>;
|
|
217
|
+
constructor();
|
|
218
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<JsonRendererComponent, never>;
|
|
219
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<JsonRendererComponent, "json-renderer", never, { "spec": { "alias": "spec"; "required": false; "isSignal": true; }; "loading": { "alias": "loading"; "required": false; "isSignal": true; }; "initialState": { "alias": "initialState"; "required": false; "isSignal": true; }; "onStateChange": { "alias": "onStateChange"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare class ElementRendererComponent implements OnDestroy {
|
|
223
|
+
readonly element: i0.InputSignal<UIElement<string, Record<string, unknown>>>;
|
|
224
|
+
readonly spec: i0.InputSignal<Spec>;
|
|
225
|
+
readonly loading: i0.InputSignal<boolean>;
|
|
226
|
+
private readonly vcr;
|
|
227
|
+
private readonly injector;
|
|
228
|
+
private readonly envInjector;
|
|
229
|
+
private readonly stateService;
|
|
230
|
+
private readonly visibilityService;
|
|
231
|
+
private readonly actionDispatcher;
|
|
232
|
+
private readonly repeatScope;
|
|
233
|
+
private readonly registry;
|
|
234
|
+
private readonly fallbackComponent;
|
|
235
|
+
private componentRef;
|
|
236
|
+
private childRenderers;
|
|
237
|
+
private repeatInjectors;
|
|
238
|
+
constructor();
|
|
239
|
+
private render;
|
|
240
|
+
private renderRepeat;
|
|
241
|
+
private renderChildren;
|
|
242
|
+
private cleanup;
|
|
243
|
+
ngOnDestroy(): void;
|
|
244
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ElementRendererComponent, never>;
|
|
245
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<ElementRendererComponent, "jr-element-renderer", never, { "element": { "alias": "element"; "required": true; "isSignal": true; }; "spec": { "alias": "spec"; "required": true; "isSignal": true; }; "loading": { "alias": "loading"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Directive that marks where children should be rendered inside a
|
|
250
|
+
* registered component.
|
|
251
|
+
*
|
|
252
|
+
* Usage in component templates:
|
|
253
|
+
* ```html
|
|
254
|
+
* <div class="card">
|
|
255
|
+
* <ng-template jrChildren></ng-template>
|
|
256
|
+
* </div>
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare class ChildrenOutletDirective {
|
|
260
|
+
readonly vcr: ViewContainerRef;
|
|
261
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ChildrenOutletDirective, never>;
|
|
262
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<ChildrenOutletDirective, "[jrChildren]", ["jrChildren"], {}, {}, never, never, true, never>;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Default confirmation dialog component.
|
|
267
|
+
* Renders when an action has a `confirm` field.
|
|
268
|
+
*
|
|
269
|
+
* Place inside or near the `<json-renderer>` in your template:
|
|
270
|
+
* ```html
|
|
271
|
+
* <json-renderer [spec]="spec">
|
|
272
|
+
* <jr-confirm-dialog />
|
|
273
|
+
* </json-renderer>
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* Or use it standalone anywhere the ActionDispatcherService is available.
|
|
277
|
+
*/
|
|
278
|
+
declare class ConfirmDialogComponent {
|
|
279
|
+
private readonly dispatcher;
|
|
280
|
+
readonly confirm: i0.Signal<_json_render_core.ActionConfirm | null>;
|
|
281
|
+
onConfirm(): void;
|
|
282
|
+
onCancel(): void;
|
|
283
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ConfirmDialogComponent, never>;
|
|
284
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<ConfirmDialogComponent, "jr-confirm-dialog", never, {}, {}, never, never, true, never>;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Default fallback component for unknown element types.
|
|
289
|
+
* Displays a warning in development.
|
|
290
|
+
*
|
|
291
|
+
* Register via provideNgRender:
|
|
292
|
+
* ```ts
|
|
293
|
+
* provideNgRender({
|
|
294
|
+
* registry: myRegistry,
|
|
295
|
+
* fallback: FallbackComponent,
|
|
296
|
+
* })
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
declare class FallbackComponent {
|
|
300
|
+
readonly element: i0.InputSignal<UIElement<string, Record<string, unknown>>>;
|
|
301
|
+
readonly emit: i0.InputSignal<(event: string) => void>;
|
|
302
|
+
readonly on: i0.InputSignal<(event: string) => EventHandle>;
|
|
303
|
+
readonly bindings: i0.InputSignal<Record<string, string> | undefined>;
|
|
304
|
+
readonly loading: i0.InputSignal<boolean>;
|
|
305
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FallbackComponent, never>;
|
|
306
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<FallbackComponent, "jr-fallback", never, { "element": { "alias": "element"; "required": true; "isSignal": true; }; "emit": { "alias": "emit"; "required": true; "isSignal": true; }; "on": { "alias": "on"; "required": true; "isSignal": true; }; "bindings": { "alias": "bindings"; "required": false; "isSignal": true; }; "loading": { "alias": "loading"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Token usage metadata from AI generation.
|
|
311
|
+
*/
|
|
312
|
+
interface TokenUsage {
|
|
313
|
+
promptTokens: number;
|
|
314
|
+
completionTokens: number;
|
|
315
|
+
totalTokens: number;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Apply an RFC 6902 JSON patch to a Spec.
|
|
319
|
+
* Returns a new shallow-copied Spec (immutable pattern for signal updates).
|
|
320
|
+
*/
|
|
321
|
+
declare function applyPatch(spec: Spec, patch: JsonPatch): Spec;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Options for createUIStream.
|
|
325
|
+
*/
|
|
326
|
+
interface UIStreamOptions {
|
|
327
|
+
api: string;
|
|
328
|
+
onComplete?: (spec: Spec) => void;
|
|
329
|
+
onError?: (error: Error) => void;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Return type for createUIStream.
|
|
333
|
+
*/
|
|
334
|
+
interface UIStreamState {
|
|
335
|
+
spec: Signal<Spec | null>;
|
|
336
|
+
isStreaming: Signal<boolean>;
|
|
337
|
+
error: Signal<Error | null>;
|
|
338
|
+
usage: Signal<TokenUsage | null>;
|
|
339
|
+
rawLines: Signal<string[]>;
|
|
340
|
+
send: (prompt: string, context?: Record<string, unknown>) => Promise<void>;
|
|
341
|
+
clear: () => void;
|
|
342
|
+
destroy: () => void;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Create a streaming UI generator.
|
|
346
|
+
* Angular equivalent of React's `useUIStream` hook.
|
|
347
|
+
*
|
|
348
|
+
* Returns signal-based reactive state + imperative send/clear functions.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* // In a component
|
|
353
|
+
* private stream = createUIStream({ api: '/api/generate' });
|
|
354
|
+
* spec = this.stream.spec;
|
|
355
|
+
* isStreaming = this.stream.isStreaming;
|
|
356
|
+
*
|
|
357
|
+
* async generate() {
|
|
358
|
+
* await this.stream.send('Create a dashboard');
|
|
359
|
+
* }
|
|
360
|
+
*
|
|
361
|
+
* ngOnDestroy() {
|
|
362
|
+
* this.stream.destroy();
|
|
363
|
+
* }
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
declare function createUIStream(options: UIStreamOptions): UIStreamState;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* A single message in the chat.
|
|
370
|
+
*/
|
|
371
|
+
interface ChatMessage {
|
|
372
|
+
id: string;
|
|
373
|
+
role: 'user' | 'assistant';
|
|
374
|
+
text: string;
|
|
375
|
+
spec: Spec | null;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Options for createChatUI.
|
|
379
|
+
*/
|
|
380
|
+
interface ChatUIOptions {
|
|
381
|
+
api: string;
|
|
382
|
+
onComplete?: (message: ChatMessage) => void;
|
|
383
|
+
onError?: (error: Error) => void;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Return type for createChatUI.
|
|
387
|
+
*/
|
|
388
|
+
interface ChatUIState {
|
|
389
|
+
messages: Signal<ChatMessage[]>;
|
|
390
|
+
isStreaming: Signal<boolean>;
|
|
391
|
+
error: Signal<Error | null>;
|
|
392
|
+
send: (text: string) => Promise<void>;
|
|
393
|
+
clear: () => void;
|
|
394
|
+
destroy: () => void;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Create a chat + GenUI interface.
|
|
398
|
+
* Angular equivalent of React's `useChatUI` hook.
|
|
399
|
+
*
|
|
400
|
+
* Manages a multi-turn conversation where each assistant message can contain
|
|
401
|
+
* both conversational text and a json-render UI spec.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts
|
|
405
|
+
* private chat = createChatUI({ api: '/api/chat' });
|
|
406
|
+
* messages = this.chat.messages;
|
|
407
|
+
* isStreaming = this.chat.isStreaming;
|
|
408
|
+
*
|
|
409
|
+
* async send(text: string) {
|
|
410
|
+
* await this.chat.send(text);
|
|
411
|
+
* }
|
|
412
|
+
*
|
|
413
|
+
* ngOnDestroy() {
|
|
414
|
+
* this.chat.destroy();
|
|
415
|
+
* }
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
declare function createChatUI(options: ChatUIOptions): ChatUIState;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Return type for createBoundProp.
|
|
422
|
+
*/
|
|
423
|
+
interface BoundProp<T> {
|
|
424
|
+
value: T | undefined;
|
|
425
|
+
setValue: (value: T) => void;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Create a two-way bound prop helper.
|
|
429
|
+
* Angular equivalent of React's `useBoundProp` hook.
|
|
430
|
+
*
|
|
431
|
+
* Must be called within an injection context (constructor, factory, etc.)
|
|
432
|
+
* where SpecStateService is available.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* // In a component that receives bindings
|
|
437
|
+
* private stateService = inject(SpecStateService);
|
|
438
|
+
*
|
|
439
|
+
* // Create bound prop for a form input
|
|
440
|
+
* get emailBinding(): BoundProp<string> {
|
|
441
|
+
* return boundProp(
|
|
442
|
+
* this.element().props['value'] as string,
|
|
443
|
+
* this.bindings()?.['value'],
|
|
444
|
+
* this.stateService,
|
|
445
|
+
* );
|
|
446
|
+
* }
|
|
447
|
+
*
|
|
448
|
+
* onInput(event: Event) {
|
|
449
|
+
* this.emailBinding.setValue((event.target as HTMLInputElement).value);
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function boundProp<T>(propValue: T | undefined, bindingPath: string | undefined, stateService: SpecStateService): BoundProp<T>;
|
|
454
|
+
/**
|
|
455
|
+
* Create a two-way bound prop helper using dependency injection.
|
|
456
|
+
* Convenience wrapper that injects SpecStateService automatically.
|
|
457
|
+
*
|
|
458
|
+
* Must be called within an injection context.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* // In a component constructor or field initializer
|
|
463
|
+
* private createBound = injectBoundProp();
|
|
464
|
+
*
|
|
465
|
+
* get emailBinding() {
|
|
466
|
+
* return this.createBound(
|
|
467
|
+
* this.element().props['value'] as string,
|
|
468
|
+
* this.bindings()?.['value'],
|
|
469
|
+
* );
|
|
470
|
+
* }
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
declare function injectBoundProp(): <T>(propValue: T | undefined, bindingPath: string | undefined) => BoundProp<T>;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* A single part from the AI SDK's `message.parts` array.
|
|
477
|
+
* Minimal structural type so the library doesn't depend on the AI SDK.
|
|
478
|
+
*/
|
|
479
|
+
interface DataPart {
|
|
480
|
+
type: string;
|
|
481
|
+
text?: string;
|
|
482
|
+
data?: unknown;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Build a Spec by replaying all spec data parts from a message's parts array.
|
|
486
|
+
* Returns null if no spec data parts are present.
|
|
487
|
+
*
|
|
488
|
+
* Works with the AI SDK's UIMessage.parts array.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* const spec = buildSpecFromParts(message.parts);
|
|
493
|
+
* if (spec) {
|
|
494
|
+
* // render with <json-renderer [spec]="spec" />
|
|
495
|
+
* }
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
|
|
499
|
+
/**
|
|
500
|
+
* Extract and join all text content from a message's parts array.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```ts
|
|
504
|
+
* const text = getTextFromParts(message.parts);
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
declare function getTextFromParts(parts: DataPart[]): string;
|
|
508
|
+
/**
|
|
509
|
+
* Convert a flat element list to a Spec.
|
|
510
|
+
* Input elements use key/parentKey to establish identity and relationships.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```ts
|
|
514
|
+
* const spec = flatToTree([
|
|
515
|
+
* { key: 'root', type: 'Stack', props: {}, children: [] },
|
|
516
|
+
* { key: 'text', parentKey: 'root', type: 'Text', props: { content: 'Hello' } },
|
|
517
|
+
* ]);
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
521
|
+
/**
|
|
522
|
+
* Extract both spec and text from message parts.
|
|
523
|
+
* Combines buildSpecFromParts and getTextFromParts.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* const { spec, text, hasSpec } = extractFromParts(message.parts);
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
declare function extractFromParts(parts: DataPart[]): {
|
|
531
|
+
spec: Spec | null;
|
|
532
|
+
text: string;
|
|
533
|
+
hasSpec: boolean;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
export { ActionDispatcherService, ChildrenOutletDirective, ConfirmDialogComponent, ElementRendererComponent, FallbackComponent, JsonRendererComponent, NG_RENDER_ACTION_HANDLERS, NG_RENDER_FALLBACK, NG_RENDER_NAVIGATE, NG_RENDER_REGISTRY, RepeatScopeService, SpecStateService, ValidationService, VisibilityService, applyPatch, boundProp, buildSpecFromParts, createChatUI, createUIStream, defineRegistry, extractFromParts, flatToTree, getTextFromParts, injectBoundProp, provideNgRender, schema };
|
|
537
|
+
export type { ActionFn, Actions, AngularSchema, BoundProp, CatalogComponentContext, CatalogHasActions, ChatMessage, ChatUIOptions, ChatUIState, ComponentRegistry, ComponentRenderContext, DataPart, DefineRegistryResult, EventHandle, FieldValidationState, JsonRenderComponent, PendingConfirmation, ProvideNgRenderOptions, SetState, TokenUsage, UIStreamOptions, UIStreamState };
|