@xmachines/json-render-core 0.21.0-xm.5 → 0.21.0-xm.7
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 +10 -1
- package/dist/index.d.mts +152 -6
- package/dist/index.d.ts +152 -6
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{store-utils-3y6Mlk7s.d.mts → store-utils-DAaK1SsE.d.mts} +1 -1
- package/dist/{store-utils-3y6Mlk7s.d.ts → store-utils-DAaK1SsE.d.ts} +1 -1
- package/dist/store-utils.d.mts +1 -1
- package/dist/store-utils.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -240,6 +240,9 @@ Schema options:
|
|
|
240
240
|
| `resolveElementProps(props, ctx)` | Resolve all prop expressions in an element |
|
|
241
241
|
| `PropExpression<T>` | Type for prop values that may contain expressions |
|
|
242
242
|
| `ComputedFunction` | Function signature for `$computed` expressions |
|
|
243
|
+
| `OnRenderError` | The `onRenderError` handler: `(error, name, info) => void`. `name` is the element type, or the action name for `action` and `watch`. A handler with two parameters is valid too |
|
|
244
|
+
| `RenderErrorInfo` | What the handler gets about a failure: `{ kind, key?, type?, action? }`. For `props` and `visible`, `key` and `type` name the child whose expression failed |
|
|
245
|
+
| `RenderErrorKind` | `"element" \| "props" \| "visible" \| "action" \| "watch" \| "root"` |
|
|
243
246
|
| `PropResolutionContext` | Context for resolving props (includes `functions` for `$computed`) |
|
|
244
247
|
|
|
245
248
|
### Validation
|
|
@@ -368,7 +371,13 @@ The official adapter packages (`@xmachines/json-render-redux`, `@xmachines/json-
|
|
|
368
371
|
| `warnUnusedRenderErrorHandler(registry)` | Warn one time about an enumerable `onRenderError` of a registry, which is a component and no handler. A renderer calls it when a render error finds no handler |
|
|
369
372
|
| `getOwnEntry(map, key)` | The entry of a name in a registry or a map of action handlers. A name of `Object.prototype` is an entry only as an own property |
|
|
370
373
|
| `getRegistryComponent(registry, type)` | The component of a type. The error handler is no component, and a member of `Object.prototype` is one only as an own property of the registry. A string, such as an element type of React, is a component |
|
|
371
|
-
| `reportActionError(handler, error, action, source)` | Report an `on` event or a `watch` whose binding threw: to the handler, with the action name as its second argument, or to `console.error` |
|
|
374
|
+
| `reportActionError(handler, error, action, source)` | Report an `on` event or a `watch` whose binding threw: to the handler, with the action name as its second argument, or to `console.error`. `reportRenderError` with the kind `action` or `watch` replaces it |
|
|
375
|
+
| `reportRenderError(handler, error, name, info)` | Report a failure in code that the renderer runs. Calls the handler one time with `(error, name, info)`. Without a handler, writes one `console.error` line: `[json-render] <kind> error in "<action>" of <Type> "<key>":`, then the error. An error of the handler goes to `reportError` one time, and the function does not throw |
|
|
376
|
+
| `reportUncaughtError(error)` | Give an error that no caller can take to `reportError`, or to `console.error` where the platform has no `reportError` |
|
|
377
|
+
| `formatRenderError(name, info)` | The text of the console line of `reportRenderError` |
|
|
378
|
+
| `warnUnknownType(type, key?)` | One `[json-render]` warning about an element type with no component and no `fallback` |
|
|
379
|
+
| `warnMissingRoot(rootKey)` | One `[json-render]` warning about a `root` that names no element |
|
|
380
|
+
| `builtInActionDefinitions` | The prompt entries of the six built-in actions: `setState`, `pushState`, `removeState`, `push`, `pop` and `validateForm`. A renderer schema gives them to `defineSchema` as `builtInActions` |
|
|
372
381
|
| `elementSubtreeJson(spec, key, element)` | The JSON of an element and of the elements below it. A renderer resets a failed boundary when it changes |
|
|
373
382
|
| `readWatchedValues(watch, state, previous)` | The values that the `watch` of an element reads. Gives `previous` back while the paths stay the same, in the same order, and each value stays the same (`Object.is`) |
|
|
374
383
|
| `changedWatchPaths(current, previous)` | The watched paths whose value changed. A path that an element starts to watch is not a change |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,73 @@
|
|
|
1
|
-
import { S as StateModel, V as VisibilityCondition,
|
|
2
|
-
export { $ as Action, a7 as ActionBindingSchema, a0 as ActionConfirm, a9 as ActionConfirmSchema, a4 as ActionDefinition, a6 as ActionExecutionContext, a3 as ActionHandler, a2 as ActionOnError, ab as ActionOnErrorSchema, a1 as ActionOnSuccess, aa as ActionOnSuccessSchema, a8 as ActionSchema, C as ComponentSchema, f as DynamicBoolean, s as DynamicBooleanSchema, e as DynamicNumber, r as DynamicNumberSchema, d as DynamicString, q as DynamicStringSchema, p as DynamicValueSchema,
|
|
1
|
+
import { F as FlatElement, S as Spec, a as StateModel, V as VisibilityCondition, b as StateCondition, A as AndCondition, O as OrCondition, c as ActionBinding, D as DynamicValue, U as UIElement, J as JsonPatch } from './store-utils-DAaK1SsE.mjs';
|
|
2
|
+
export { $ as Action, a7 as ActionBindingSchema, a0 as ActionConfirm, a9 as ActionConfirmSchema, a4 as ActionDefinition, a6 as ActionExecutionContext, a3 as ActionHandler, a2 as ActionOnError, ab as ActionOnErrorSchema, a1 as ActionOnSuccess, aa as ActionOnSuccessSchema, a8 as ActionSchema, C as ComponentSchema, f as DynamicBoolean, s as DynamicBooleanSchema, e as DynamicNumber, r as DynamicNumberSchema, d as DynamicString, q as DynamicStringSchema, p as DynamicValueSchema, g as IndexCondition, I as ItemCondition, M as MixedStreamCallbacks, m as MixedStreamParser, P as PatchOp, R as RepeatStatePath, a5 as ResolvedAction, X as SPEC_DATA_PART, Y as SPEC_DATA_PART_TYPE, h as SingleCondition, o as SpecDataPart, l as SpecStreamCompiler, k as SpecStreamLine, i as StateStore, Z as StoreAdapterConfig, n as StreamChunk, j as ValidationMode, ai as action, ah as actionBinding, y as addByPath, H as applySpecPatch, G as applySpecStreamPatch, L as compileSpecStream, T as createJsonRenderTransform, Q as createMixedStreamParser, N as createSpecStreamCompiler, _ as createStateStore, ad as executeAction, B as findFormValue, u as getByPath, af as interpolateString, ae as isBuiltInAction, ag as mergeActionHandlers, K as nestedToFlat, E as parseSpecStreamLine, W as pipeJsonRender, z as removeByPath, ac as resolveAction, t as resolveDynamicValue, w as resolveRepeatItemStatePath, v as resolveRepeatStatePath, x as setByPath } from './store-utils-DAaK1SsE.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Pure helpers for specs that arrive in parts: a flat element list, and the
|
|
7
|
+
* parts of an AI SDK message. They read no framework, so every renderer can
|
|
8
|
+
* use them.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Convert a flat element list to a Spec.
|
|
15
|
+
* Input elements use key/parentKey to establish identity and relationships.
|
|
16
|
+
* Output spec uses the map-based format where key is the map entry key
|
|
17
|
+
* and parent-child relationships are expressed through children arrays.
|
|
18
|
+
*/
|
|
19
|
+
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
20
|
+
/**
|
|
21
|
+
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
22
|
+
* structural type so that library helpers do not depend on the AI SDK.
|
|
23
|
+
* Fields are optional because different part types carry different data:
|
|
24
|
+
* - Text parts have `text`
|
|
25
|
+
* - Data parts have `data`
|
|
26
|
+
*/
|
|
27
|
+
interface DataPart {
|
|
28
|
+
type: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a `Spec` by replaying all spec data parts from a message's
|
|
34
|
+
* parts array. Returns `null` if no spec data parts are present.
|
|
35
|
+
*
|
|
36
|
+
* This function is designed to work with the AI SDK's `UIMessage.parts` array.
|
|
37
|
+
* It picks out parts whose `type` is {@link SPEC_DATA_PART_TYPE} and processes them based
|
|
38
|
+
* on the payload's `type` discriminator:
|
|
39
|
+
*
|
|
40
|
+
* - `"patch"`: Applies the JSON Patch operation incrementally via `applySpecPatch`.
|
|
41
|
+
* - `"flat"`: Replaces the spec with the complete flat spec.
|
|
42
|
+
* - `"nested"`: Assigns the nested spec directly (future: nested-to-flat conversion).
|
|
43
|
+
*
|
|
44
|
+
* The function has no AI SDK dependency — it operates on a generic array of
|
|
45
|
+
* `{ type: string; data: unknown }` objects.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const spec = buildSpecFromParts(message.parts);
|
|
50
|
+
* if (spec) renderer.setSpec(spec);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
|
|
54
|
+
/**
|
|
55
|
+
* Extract and join all text content from a message's parts array.
|
|
56
|
+
*
|
|
57
|
+
* Filters for parts with `type === "text"`, trims each one, and joins them
|
|
58
|
+
* with double newlines so that text from separate agent steps renders as
|
|
59
|
+
* distinct paragraphs in markdown.
|
|
60
|
+
*
|
|
61
|
+
* Has no AI SDK dependency — operates on a generic `DataPart[]`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const text = getTextFromParts(message.parts);
|
|
66
|
+
* if (text) output.textContent = text;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function getTextFromParts(parts: DataPart[]): string;
|
|
70
|
+
|
|
5
71
|
/**
|
|
6
72
|
* Visibility condition schema.
|
|
7
73
|
*
|
|
@@ -942,6 +1008,78 @@ interface UserPromptOptions {
|
|
|
942
1008
|
*/
|
|
943
1009
|
declare function buildUserPrompt(options: UserPromptOptions): string;
|
|
944
1010
|
|
|
1011
|
+
/**
|
|
1012
|
+
* The error-reporting path that every renderer shares (fork module).
|
|
1013
|
+
*
|
|
1014
|
+
* Each failure in code that a renderer runs reaches the `onRenderError`
|
|
1015
|
+
* handler exactly one time, with a {@link RenderErrorInfo}. Without a
|
|
1016
|
+
* handler, the renderer writes one `[json-render]` console line in one
|
|
1017
|
+
* format. A handler that throws gives its error to `reportError`, and the
|
|
1018
|
+
* renderer fails no other element.
|
|
1019
|
+
*
|
|
1020
|
+
* The renderers call {@link reportRenderError}, {@link warnUnknownType} and
|
|
1021
|
+
* {@link warnMissingRoot}, so the console lines are the same in each one.
|
|
1022
|
+
*
|
|
1023
|
+
* @packageDocumentation
|
|
1024
|
+
*/
|
|
1025
|
+
/**
|
|
1026
|
+
* The place where a failure occurred.
|
|
1027
|
+
*
|
|
1028
|
+
* - `element`: the component threw while it rendered, in an effect or a
|
|
1029
|
+
* lifecycle hook, or in a callback that it calls in those phases.
|
|
1030
|
+
* - `props`: a prop expression of an element threw (`$computed`, a directive).
|
|
1031
|
+
* - `visible`: the `visible` condition of an element threw.
|
|
1032
|
+
* - `action`: an `on` chain failed: a handler that throws or rejects, a
|
|
1033
|
+
* built-in action, a store that refuses a write, or `validateForm`.
|
|
1034
|
+
* - `watch`: a `watch` chain failed.
|
|
1035
|
+
* - `root`: the root (its component, props or `visible`) failed, so the
|
|
1036
|
+
* renderer shows nothing.
|
|
1037
|
+
*/
|
|
1038
|
+
type RenderErrorKind = "element" | "props" | "visible" | "action" | "watch" | "root";
|
|
1039
|
+
/** What a renderer tells the handler about a failure. */
|
|
1040
|
+
interface RenderErrorInfo {
|
|
1041
|
+
/** The place where the failure occurred. */
|
|
1042
|
+
kind: RenderErrorKind;
|
|
1043
|
+
/** The key of the element whose code failed. For `props` and `visible`, the child, not the boundary. */
|
|
1044
|
+
key?: string;
|
|
1045
|
+
/** The component type of that element. */
|
|
1046
|
+
type?: string;
|
|
1047
|
+
/** The action name, for `action` and `watch`. */
|
|
1048
|
+
action?: string;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* The `onRenderError` handler of a renderer.
|
|
1052
|
+
*
|
|
1053
|
+
* The second argument stays as it was: the element type for a failure of an
|
|
1054
|
+
* element, or the action name for a failed chain. `info` tells them apart. A
|
|
1055
|
+
* handler with two parameters is still a valid handler.
|
|
1056
|
+
*/
|
|
1057
|
+
type OnRenderError = (error: unknown, name: string, info: RenderErrorInfo) => void;
|
|
1058
|
+
/**
|
|
1059
|
+
* Report an error that no caller can take, as the browser reports one: to
|
|
1060
|
+
* `reportError`, which dispatches the window `error` event. Where the
|
|
1061
|
+
* platform has no `reportError`, the error goes to `console.error`.
|
|
1062
|
+
*/
|
|
1063
|
+
declare function reportUncaughtError(error: unknown): void;
|
|
1064
|
+
/**
|
|
1065
|
+
* The single console line of a failure without a handler, before the error:
|
|
1066
|
+
* `[json-render] <kind> error in "<action>" of <Type> "<key>":`.
|
|
1067
|
+
*/
|
|
1068
|
+
declare function formatRenderError(name: string, info: RenderErrorInfo): string;
|
|
1069
|
+
/**
|
|
1070
|
+
* Report a failure in code that the renderer runs.
|
|
1071
|
+
*
|
|
1072
|
+
* With a handler, the function calls it one time with `(error, name, info)`.
|
|
1073
|
+
* When the handler throws, its error goes to {@link reportUncaughtError} one
|
|
1074
|
+
* time, and the function does not throw. Without a handler, the function
|
|
1075
|
+
* writes one `console.error` line ({@link formatRenderError}), then the error.
|
|
1076
|
+
*/
|
|
1077
|
+
declare function reportRenderError(handler: OnRenderError | undefined, error: unknown, name: string, info: RenderErrorInfo): void;
|
|
1078
|
+
/** Warn one time about an element whose type has no component and no `fallback`. */
|
|
1079
|
+
declare function warnUnknownType(type: string, key?: string): void;
|
|
1080
|
+
/** Warn one time about a `root` that names no element of the spec. */
|
|
1081
|
+
declare function warnMissingRoot(rootKey: string): void;
|
|
1082
|
+
|
|
945
1083
|
/**
|
|
946
1084
|
* Slot metadata for named-slot validation.
|
|
947
1085
|
*
|
|
@@ -997,7 +1135,7 @@ declare function warnElementSlots(registry: object, type: string, slots: Record<
|
|
|
997
1135
|
* metadata is keyed on the registry object. The registry of the caller does
|
|
998
1136
|
* not change.
|
|
999
1137
|
*/
|
|
1000
|
-
declare function withRenderErrorHandler<TRegistry extends object>(registry: TRegistry, onRenderError:
|
|
1138
|
+
declare function withRenderErrorHandler<TRegistry extends object>(registry: TRegistry, onRenderError: OnRenderError): TRegistry;
|
|
1001
1139
|
/**
|
|
1002
1140
|
* Put an `onRenderError` handler on a registry, in place. `defineRegistry`
|
|
1003
1141
|
* of each renderer calls it. The property is not enumerable, so an
|
|
@@ -1005,7 +1143,7 @@ declare function withRenderErrorHandler<TRegistry extends object>(registry: TReg
|
|
|
1005
1143
|
* place of a component of the same name, which a catalog can declare, and
|
|
1006
1144
|
* the function warns: an element of that type then renders the fallback.
|
|
1007
1145
|
*/
|
|
1008
|
-
declare function setRenderErrorHandler(registry: object, onRenderError:
|
|
1146
|
+
declare function setRenderErrorHandler(registry: object, onRenderError: OnRenderError): void;
|
|
1009
1147
|
/**
|
|
1010
1148
|
* Warn one time for each registry that holds an enumerable `onRenderError`
|
|
1011
1149
|
* function, when a render error finds no handler: the function counts as a
|
|
@@ -1051,10 +1189,18 @@ declare function getRegistryComponent<TComponent>(registry: Record<string, TComp
|
|
|
1051
1189
|
* binding threw. `onRenderError` gets the error with the action name as its
|
|
1052
1190
|
* second argument. Without a handler, the error goes to `console.error`, and
|
|
1053
1191
|
* not to an unhandled rejection, because a component discards the promise of
|
|
1054
|
-
* `emit`.
|
|
1192
|
+
* `emit`. `reportRenderError` with the kind `action` or `watch` replaces it.
|
|
1055
1193
|
*/
|
|
1056
1194
|
declare function reportActionError(onRenderError: RenderErrorHandler | undefined, error: unknown, action: string, source: "event" | "watch"): void;
|
|
1057
1195
|
|
|
1196
|
+
/**
|
|
1197
|
+
* The prompt entries of the six actions that every renderer runs itself
|
|
1198
|
+
* (fork module). A renderer schema gives them to `defineSchema` as
|
|
1199
|
+
* `builtInActions: [...builtInActionDefinitions]`, so the generated prompt
|
|
1200
|
+
* names each built-in action that the renderer runs, `push` and `pop` too.
|
|
1201
|
+
*/
|
|
1202
|
+
declare const builtInActionDefinitions: readonly BuiltInAction[];
|
|
1203
|
+
|
|
1058
1204
|
/**
|
|
1059
1205
|
* The JSON of an element and of every element below it: its children and the
|
|
1060
1206
|
* elements of its named slots.
|
|
@@ -1251,4 +1397,4 @@ interface Experimental_EvaluatorOptions {
|
|
|
1251
1397
|
*/
|
|
1252
1398
|
declare function experimental_createEvaluator(options: Experimental_EvaluatorOptions): Experimental_CompositionEvaluator;
|
|
1253
1399
|
|
|
1254
|
-
export { ActionBinding, type ActionDispatchInfo, type ActionObserver, type ActionSettleInfo, AndCondition, type BuildEditUserPromptOptions, type BuiltInAction, type Catalog, type ComponentSlotMetadata, type ComputedFunction, type DirectiveDefinition, type DirectiveRegistry, DynamicValue, type EditConfig, type EditMode, type Experimental_ChoiceQuestion, type Experimental_ComposeSpecOptions, type Experimental_CompositionCandidate, type Experimental_CompositionCatalog, type Experimental_CompositionEvaluation, type Experimental_CompositionEvaluator, type Experimental_CompositionEvent, type Experimental_CompositionStep, type Experimental_EvaluatorOptions, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, JsonPatch, type JsonSchemaOptions, OrCondition, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type RenderErrorHandler, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, Spec, type SpecIssue, type SpecIssueSeverity, type SpecValidationIssues, type SpecValidationResult, StateCondition, StateModel, UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationResult, VisibilityCondition, VisibilityConditionSchema, VisibilityConditionStrictSchema, type VisibilityContext, autoFixSpec, buildEditInstructions, buildEditUserPrompt, buildUserPrompt, builtInValidationFunctions, changedWatchPaths, check, conditionUsesItemScope, copySlotMetadata, createComponentRegistry, createDirectiveRegistry, deepMergeSpec, defineCatalog, defineDirective, defineSchema, diffToPatches, elementSubtreeJson, evaluateVisibility, experimental_composeSpec, experimental_createEvaluator, findDirective, formatSpecIssues, getComponentSlotMetadata, getOwnEntry, getRegistryComponent, getRenderErrorHandler, isDevtoolsActive, isNonEmptySpec, markDevtoolsActive, nextActionDispatchId, notifyActionDispatch, notifyActionSettle, ownMemberDescriptors, readWatchedValues, registerActionObserver, reportActionError, resolveActionParam, resolveBindingParams, resolveBindings, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, runWatchBindings, setCatalogSlotMetadata, setRenderErrorHandler, splitRepeatVisibility, subscribeDevtoolsActive, validateSpec, visibility, warnElementSlots, warnUnusedRenderErrorHandler, withRenderErrorHandler };
|
|
1400
|
+
export { ActionBinding, type ActionDispatchInfo, type ActionObserver, type ActionSettleInfo, AndCondition, type BuildEditUserPromptOptions, type BuiltInAction, type Catalog, type ComponentSlotMetadata, type ComputedFunction, type DataPart, type DirectiveDefinition, type DirectiveRegistry, DynamicValue, type EditConfig, type EditMode, type Experimental_ChoiceQuestion, type Experimental_ComposeSpecOptions, type Experimental_CompositionCandidate, type Experimental_CompositionCatalog, type Experimental_CompositionEvaluation, type Experimental_CompositionEvaluator, type Experimental_CompositionEvent, type Experimental_CompositionStep, type Experimental_EvaluatorOptions, FlatElement, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, JsonPatch, type JsonSchemaOptions, type OnRenderError, OrCondition, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type RenderErrorHandler, type RenderErrorInfo, type RenderErrorKind, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, Spec, type SpecIssue, type SpecIssueSeverity, type SpecValidationIssues, type SpecValidationResult, StateCondition, StateModel, UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationResult, VisibilityCondition, VisibilityConditionSchema, VisibilityConditionStrictSchema, type VisibilityContext, autoFixSpec, buildEditInstructions, buildEditUserPrompt, buildSpecFromParts, buildUserPrompt, builtInActionDefinitions, builtInValidationFunctions, changedWatchPaths, check, conditionUsesItemScope, copySlotMetadata, createComponentRegistry, createDirectiveRegistry, deepMergeSpec, defineCatalog, defineDirective, defineSchema, diffToPatches, elementSubtreeJson, evaluateVisibility, experimental_composeSpec, experimental_createEvaluator, findDirective, flatToTree, formatRenderError, formatSpecIssues, getComponentSlotMetadata, getOwnEntry, getRegistryComponent, getRenderErrorHandler, getTextFromParts, isDevtoolsActive, isNonEmptySpec, markDevtoolsActive, nextActionDispatchId, notifyActionDispatch, notifyActionSettle, ownMemberDescriptors, readWatchedValues, registerActionObserver, reportActionError, reportRenderError, reportUncaughtError, resolveActionParam, resolveBindingParams, resolveBindings, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, runWatchBindings, setCatalogSlotMetadata, setRenderErrorHandler, splitRepeatVisibility, subscribeDevtoolsActive, validateSpec, visibility, warnElementSlots, warnMissingRoot, warnUnknownType, warnUnusedRenderErrorHandler, withRenderErrorHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,73 @@
|
|
|
1
|
-
import { S as StateModel, V as VisibilityCondition,
|
|
2
|
-
export { $ as Action, a7 as ActionBindingSchema, a0 as ActionConfirm, a9 as ActionConfirmSchema, a4 as ActionDefinition, a6 as ActionExecutionContext, a3 as ActionHandler, a2 as ActionOnError, ab as ActionOnErrorSchema, a1 as ActionOnSuccess, aa as ActionOnSuccessSchema, a8 as ActionSchema, C as ComponentSchema, f as DynamicBoolean, s as DynamicBooleanSchema, e as DynamicNumber, r as DynamicNumberSchema, d as DynamicString, q as DynamicStringSchema, p as DynamicValueSchema,
|
|
1
|
+
import { F as FlatElement, S as Spec, a as StateModel, V as VisibilityCondition, b as StateCondition, A as AndCondition, O as OrCondition, c as ActionBinding, D as DynamicValue, U as UIElement, J as JsonPatch } from './store-utils-DAaK1SsE.js';
|
|
2
|
+
export { $ as Action, a7 as ActionBindingSchema, a0 as ActionConfirm, a9 as ActionConfirmSchema, a4 as ActionDefinition, a6 as ActionExecutionContext, a3 as ActionHandler, a2 as ActionOnError, ab as ActionOnErrorSchema, a1 as ActionOnSuccess, aa as ActionOnSuccessSchema, a8 as ActionSchema, C as ComponentSchema, f as DynamicBoolean, s as DynamicBooleanSchema, e as DynamicNumber, r as DynamicNumberSchema, d as DynamicString, q as DynamicStringSchema, p as DynamicValueSchema, g as IndexCondition, I as ItemCondition, M as MixedStreamCallbacks, m as MixedStreamParser, P as PatchOp, R as RepeatStatePath, a5 as ResolvedAction, X as SPEC_DATA_PART, Y as SPEC_DATA_PART_TYPE, h as SingleCondition, o as SpecDataPart, l as SpecStreamCompiler, k as SpecStreamLine, i as StateStore, Z as StoreAdapterConfig, n as StreamChunk, j as ValidationMode, ai as action, ah as actionBinding, y as addByPath, H as applySpecPatch, G as applySpecStreamPatch, L as compileSpecStream, T as createJsonRenderTransform, Q as createMixedStreamParser, N as createSpecStreamCompiler, _ as createStateStore, ad as executeAction, B as findFormValue, u as getByPath, af as interpolateString, ae as isBuiltInAction, ag as mergeActionHandlers, K as nestedToFlat, E as parseSpecStreamLine, W as pipeJsonRender, z as removeByPath, ac as resolveAction, t as resolveDynamicValue, w as resolveRepeatItemStatePath, v as resolveRepeatStatePath, x as setByPath } from './store-utils-DAaK1SsE.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Pure helpers for specs that arrive in parts: a flat element list, and the
|
|
7
|
+
* parts of an AI SDK message. They read no framework, so every renderer can
|
|
8
|
+
* use them.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Convert a flat element list to a Spec.
|
|
15
|
+
* Input elements use key/parentKey to establish identity and relationships.
|
|
16
|
+
* Output spec uses the map-based format where key is the map entry key
|
|
17
|
+
* and parent-child relationships are expressed through children arrays.
|
|
18
|
+
*/
|
|
19
|
+
declare function flatToTree(elements: FlatElement[]): Spec;
|
|
20
|
+
/**
|
|
21
|
+
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
22
|
+
* structural type so that library helpers do not depend on the AI SDK.
|
|
23
|
+
* Fields are optional because different part types carry different data:
|
|
24
|
+
* - Text parts have `text`
|
|
25
|
+
* - Data parts have `data`
|
|
26
|
+
*/
|
|
27
|
+
interface DataPart {
|
|
28
|
+
type: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a `Spec` by replaying all spec data parts from a message's
|
|
34
|
+
* parts array. Returns `null` if no spec data parts are present.
|
|
35
|
+
*
|
|
36
|
+
* This function is designed to work with the AI SDK's `UIMessage.parts` array.
|
|
37
|
+
* It picks out parts whose `type` is {@link SPEC_DATA_PART_TYPE} and processes them based
|
|
38
|
+
* on the payload's `type` discriminator:
|
|
39
|
+
*
|
|
40
|
+
* - `"patch"`: Applies the JSON Patch operation incrementally via `applySpecPatch`.
|
|
41
|
+
* - `"flat"`: Replaces the spec with the complete flat spec.
|
|
42
|
+
* - `"nested"`: Assigns the nested spec directly (future: nested-to-flat conversion).
|
|
43
|
+
*
|
|
44
|
+
* The function has no AI SDK dependency — it operates on a generic array of
|
|
45
|
+
* `{ type: string; data: unknown }` objects.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const spec = buildSpecFromParts(message.parts);
|
|
50
|
+
* if (spec) renderer.setSpec(spec);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function buildSpecFromParts(parts: DataPart[]): Spec | null;
|
|
54
|
+
/**
|
|
55
|
+
* Extract and join all text content from a message's parts array.
|
|
56
|
+
*
|
|
57
|
+
* Filters for parts with `type === "text"`, trims each one, and joins them
|
|
58
|
+
* with double newlines so that text from separate agent steps renders as
|
|
59
|
+
* distinct paragraphs in markdown.
|
|
60
|
+
*
|
|
61
|
+
* Has no AI SDK dependency — operates on a generic `DataPart[]`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const text = getTextFromParts(message.parts);
|
|
66
|
+
* if (text) output.textContent = text;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function getTextFromParts(parts: DataPart[]): string;
|
|
70
|
+
|
|
5
71
|
/**
|
|
6
72
|
* Visibility condition schema.
|
|
7
73
|
*
|
|
@@ -942,6 +1008,78 @@ interface UserPromptOptions {
|
|
|
942
1008
|
*/
|
|
943
1009
|
declare function buildUserPrompt(options: UserPromptOptions): string;
|
|
944
1010
|
|
|
1011
|
+
/**
|
|
1012
|
+
* The error-reporting path that every renderer shares (fork module).
|
|
1013
|
+
*
|
|
1014
|
+
* Each failure in code that a renderer runs reaches the `onRenderError`
|
|
1015
|
+
* handler exactly one time, with a {@link RenderErrorInfo}. Without a
|
|
1016
|
+
* handler, the renderer writes one `[json-render]` console line in one
|
|
1017
|
+
* format. A handler that throws gives its error to `reportError`, and the
|
|
1018
|
+
* renderer fails no other element.
|
|
1019
|
+
*
|
|
1020
|
+
* The renderers call {@link reportRenderError}, {@link warnUnknownType} and
|
|
1021
|
+
* {@link warnMissingRoot}, so the console lines are the same in each one.
|
|
1022
|
+
*
|
|
1023
|
+
* @packageDocumentation
|
|
1024
|
+
*/
|
|
1025
|
+
/**
|
|
1026
|
+
* The place where a failure occurred.
|
|
1027
|
+
*
|
|
1028
|
+
* - `element`: the component threw while it rendered, in an effect or a
|
|
1029
|
+
* lifecycle hook, or in a callback that it calls in those phases.
|
|
1030
|
+
* - `props`: a prop expression of an element threw (`$computed`, a directive).
|
|
1031
|
+
* - `visible`: the `visible` condition of an element threw.
|
|
1032
|
+
* - `action`: an `on` chain failed: a handler that throws or rejects, a
|
|
1033
|
+
* built-in action, a store that refuses a write, or `validateForm`.
|
|
1034
|
+
* - `watch`: a `watch` chain failed.
|
|
1035
|
+
* - `root`: the root (its component, props or `visible`) failed, so the
|
|
1036
|
+
* renderer shows nothing.
|
|
1037
|
+
*/
|
|
1038
|
+
type RenderErrorKind = "element" | "props" | "visible" | "action" | "watch" | "root";
|
|
1039
|
+
/** What a renderer tells the handler about a failure. */
|
|
1040
|
+
interface RenderErrorInfo {
|
|
1041
|
+
/** The place where the failure occurred. */
|
|
1042
|
+
kind: RenderErrorKind;
|
|
1043
|
+
/** The key of the element whose code failed. For `props` and `visible`, the child, not the boundary. */
|
|
1044
|
+
key?: string;
|
|
1045
|
+
/** The component type of that element. */
|
|
1046
|
+
type?: string;
|
|
1047
|
+
/** The action name, for `action` and `watch`. */
|
|
1048
|
+
action?: string;
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* The `onRenderError` handler of a renderer.
|
|
1052
|
+
*
|
|
1053
|
+
* The second argument stays as it was: the element type for a failure of an
|
|
1054
|
+
* element, or the action name for a failed chain. `info` tells them apart. A
|
|
1055
|
+
* handler with two parameters is still a valid handler.
|
|
1056
|
+
*/
|
|
1057
|
+
type OnRenderError = (error: unknown, name: string, info: RenderErrorInfo) => void;
|
|
1058
|
+
/**
|
|
1059
|
+
* Report an error that no caller can take, as the browser reports one: to
|
|
1060
|
+
* `reportError`, which dispatches the window `error` event. Where the
|
|
1061
|
+
* platform has no `reportError`, the error goes to `console.error`.
|
|
1062
|
+
*/
|
|
1063
|
+
declare function reportUncaughtError(error: unknown): void;
|
|
1064
|
+
/**
|
|
1065
|
+
* The single console line of a failure without a handler, before the error:
|
|
1066
|
+
* `[json-render] <kind> error in "<action>" of <Type> "<key>":`.
|
|
1067
|
+
*/
|
|
1068
|
+
declare function formatRenderError(name: string, info: RenderErrorInfo): string;
|
|
1069
|
+
/**
|
|
1070
|
+
* Report a failure in code that the renderer runs.
|
|
1071
|
+
*
|
|
1072
|
+
* With a handler, the function calls it one time with `(error, name, info)`.
|
|
1073
|
+
* When the handler throws, its error goes to {@link reportUncaughtError} one
|
|
1074
|
+
* time, and the function does not throw. Without a handler, the function
|
|
1075
|
+
* writes one `console.error` line ({@link formatRenderError}), then the error.
|
|
1076
|
+
*/
|
|
1077
|
+
declare function reportRenderError(handler: OnRenderError | undefined, error: unknown, name: string, info: RenderErrorInfo): void;
|
|
1078
|
+
/** Warn one time about an element whose type has no component and no `fallback`. */
|
|
1079
|
+
declare function warnUnknownType(type: string, key?: string): void;
|
|
1080
|
+
/** Warn one time about a `root` that names no element of the spec. */
|
|
1081
|
+
declare function warnMissingRoot(rootKey: string): void;
|
|
1082
|
+
|
|
945
1083
|
/**
|
|
946
1084
|
* Slot metadata for named-slot validation.
|
|
947
1085
|
*
|
|
@@ -997,7 +1135,7 @@ declare function warnElementSlots(registry: object, type: string, slots: Record<
|
|
|
997
1135
|
* metadata is keyed on the registry object. The registry of the caller does
|
|
998
1136
|
* not change.
|
|
999
1137
|
*/
|
|
1000
|
-
declare function withRenderErrorHandler<TRegistry extends object>(registry: TRegistry, onRenderError:
|
|
1138
|
+
declare function withRenderErrorHandler<TRegistry extends object>(registry: TRegistry, onRenderError: OnRenderError): TRegistry;
|
|
1001
1139
|
/**
|
|
1002
1140
|
* Put an `onRenderError` handler on a registry, in place. `defineRegistry`
|
|
1003
1141
|
* of each renderer calls it. The property is not enumerable, so an
|
|
@@ -1005,7 +1143,7 @@ declare function withRenderErrorHandler<TRegistry extends object>(registry: TReg
|
|
|
1005
1143
|
* place of a component of the same name, which a catalog can declare, and
|
|
1006
1144
|
* the function warns: an element of that type then renders the fallback.
|
|
1007
1145
|
*/
|
|
1008
|
-
declare function setRenderErrorHandler(registry: object, onRenderError:
|
|
1146
|
+
declare function setRenderErrorHandler(registry: object, onRenderError: OnRenderError): void;
|
|
1009
1147
|
/**
|
|
1010
1148
|
* Warn one time for each registry that holds an enumerable `onRenderError`
|
|
1011
1149
|
* function, when a render error finds no handler: the function counts as a
|
|
@@ -1051,10 +1189,18 @@ declare function getRegistryComponent<TComponent>(registry: Record<string, TComp
|
|
|
1051
1189
|
* binding threw. `onRenderError` gets the error with the action name as its
|
|
1052
1190
|
* second argument. Without a handler, the error goes to `console.error`, and
|
|
1053
1191
|
* not to an unhandled rejection, because a component discards the promise of
|
|
1054
|
-
* `emit`.
|
|
1192
|
+
* `emit`. `reportRenderError` with the kind `action` or `watch` replaces it.
|
|
1055
1193
|
*/
|
|
1056
1194
|
declare function reportActionError(onRenderError: RenderErrorHandler | undefined, error: unknown, action: string, source: "event" | "watch"): void;
|
|
1057
1195
|
|
|
1196
|
+
/**
|
|
1197
|
+
* The prompt entries of the six actions that every renderer runs itself
|
|
1198
|
+
* (fork module). A renderer schema gives them to `defineSchema` as
|
|
1199
|
+
* `builtInActions: [...builtInActionDefinitions]`, so the generated prompt
|
|
1200
|
+
* names each built-in action that the renderer runs, `push` and `pop` too.
|
|
1201
|
+
*/
|
|
1202
|
+
declare const builtInActionDefinitions: readonly BuiltInAction[];
|
|
1203
|
+
|
|
1058
1204
|
/**
|
|
1059
1205
|
* The JSON of an element and of every element below it: its children and the
|
|
1060
1206
|
* elements of its named slots.
|
|
@@ -1251,4 +1397,4 @@ interface Experimental_EvaluatorOptions {
|
|
|
1251
1397
|
*/
|
|
1252
1398
|
declare function experimental_createEvaluator(options: Experimental_EvaluatorOptions): Experimental_CompositionEvaluator;
|
|
1253
1399
|
|
|
1254
|
-
export { ActionBinding, type ActionDispatchInfo, type ActionObserver, type ActionSettleInfo, AndCondition, type BuildEditUserPromptOptions, type BuiltInAction, type Catalog, type ComponentSlotMetadata, type ComputedFunction, type DirectiveDefinition, type DirectiveRegistry, DynamicValue, type EditConfig, type EditMode, type Experimental_ChoiceQuestion, type Experimental_ComposeSpecOptions, type Experimental_CompositionCandidate, type Experimental_CompositionCatalog, type Experimental_CompositionEvaluation, type Experimental_CompositionEvaluator, type Experimental_CompositionEvent, type Experimental_CompositionStep, type Experimental_EvaluatorOptions, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, JsonPatch, type JsonSchemaOptions, OrCondition, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type RenderErrorHandler, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, Spec, type SpecIssue, type SpecIssueSeverity, type SpecValidationIssues, type SpecValidationResult, StateCondition, StateModel, UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationResult, VisibilityCondition, VisibilityConditionSchema, VisibilityConditionStrictSchema, type VisibilityContext, autoFixSpec, buildEditInstructions, buildEditUserPrompt, buildUserPrompt, builtInValidationFunctions, changedWatchPaths, check, conditionUsesItemScope, copySlotMetadata, createComponentRegistry, createDirectiveRegistry, deepMergeSpec, defineCatalog, defineDirective, defineSchema, diffToPatches, elementSubtreeJson, evaluateVisibility, experimental_composeSpec, experimental_createEvaluator, findDirective, formatSpecIssues, getComponentSlotMetadata, getOwnEntry, getRegistryComponent, getRenderErrorHandler, isDevtoolsActive, isNonEmptySpec, markDevtoolsActive, nextActionDispatchId, notifyActionDispatch, notifyActionSettle, ownMemberDescriptors, readWatchedValues, registerActionObserver, reportActionError, resolveActionParam, resolveBindingParams, resolveBindings, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, runWatchBindings, setCatalogSlotMetadata, setRenderErrorHandler, splitRepeatVisibility, subscribeDevtoolsActive, validateSpec, visibility, warnElementSlots, warnUnusedRenderErrorHandler, withRenderErrorHandler };
|
|
1400
|
+
export { ActionBinding, type ActionDispatchInfo, type ActionObserver, type ActionSettleInfo, AndCondition, type BuildEditUserPromptOptions, type BuiltInAction, type Catalog, type ComponentSlotMetadata, type ComputedFunction, type DataPart, type DirectiveDefinition, type DirectiveRegistry, DynamicValue, type EditConfig, type EditMode, type Experimental_ChoiceQuestion, type Experimental_ComposeSpecOptions, type Experimental_CompositionCandidate, type Experimental_CompositionCatalog, type Experimental_CompositionEvaluation, type Experimental_CompositionEvaluator, type Experimental_CompositionEvent, type Experimental_CompositionStep, type Experimental_EvaluatorOptions, FlatElement, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, JsonPatch, type JsonSchemaOptions, type OnRenderError, OrCondition, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type RenderErrorHandler, type RenderErrorInfo, type RenderErrorKind, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, Spec, type SpecIssue, type SpecIssueSeverity, type SpecValidationIssues, type SpecValidationResult, StateCondition, StateModel, UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationResult, VisibilityCondition, VisibilityConditionSchema, VisibilityConditionStrictSchema, type VisibilityContext, autoFixSpec, buildEditInstructions, buildEditUserPrompt, buildSpecFromParts, buildUserPrompt, builtInActionDefinitions, builtInValidationFunctions, changedWatchPaths, check, conditionUsesItemScope, copySlotMetadata, createComponentRegistry, createDirectiveRegistry, deepMergeSpec, defineCatalog, defineDirective, defineSchema, diffToPatches, elementSubtreeJson, evaluateVisibility, experimental_composeSpec, experimental_createEvaluator, findDirective, flatToTree, formatRenderError, formatSpecIssues, getComponentSlotMetadata, getOwnEntry, getRegistryComponent, getRenderErrorHandler, getTextFromParts, isDevtoolsActive, isNonEmptySpec, markDevtoolsActive, nextActionDispatchId, notifyActionDispatch, notifyActionSettle, ownMemberDescriptors, readWatchedValues, registerActionObserver, reportActionError, reportRenderError, reportUncaughtError, resolveActionParam, resolveBindingParams, resolveBindings, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, runWatchBindings, setCatalogSlotMetadata, setRenderErrorHandler, splitRepeatVisibility, subscribeDevtoolsActive, validateSpec, visibility, warnElementSlots, warnMissingRoot, warnUnknownType, warnUnusedRenderErrorHandler, withRenderErrorHandler };
|