@xmachines/json-render-core 0.20.0-xm.4 → 0.21.0-xm.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/index.d.mts +175 -3
- package/dist/index.d.ts +175 -3
- package/dist/index.js +903 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +896 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,57 @@ Core library for json-render. Define schemas, create catalogs, generate AI promp
|
|
|
8
8
|
npm install @xmachines/json-render-core zod
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Experimental decision-model composition
|
|
12
|
+
|
|
13
|
+
`experimental_composeSpec` builds a flat `Spec` by choosing among your app's atomic element candidates. `experimental_createEvaluator` connects a choice evaluation model through Vercel AI Gateway. Jev (`typesafe-ai/jev`) is the current example; the API names and explicit `model` option are model-neutral. Use your own catalog, props, state bindings, action bindings, and renderer; no playground components are required.
|
|
14
|
+
|
|
15
|
+
**Unreleased:** try a source build before the next package release. APIs prefixed with `experimental_` or `Experimental_` may change in any release. Pin exact versions and review release notes before upgrading.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// Server only
|
|
19
|
+
import { experimental_composeSpec, experimental_createEvaluator } from "@xmachines/json-render-core";
|
|
20
|
+
import { catalog } from "./catalog";
|
|
21
|
+
import { candidates } from "./candidates";
|
|
22
|
+
|
|
23
|
+
const evaluate = experimental_createEvaluator({
|
|
24
|
+
model: "typesafe-ai/jev",
|
|
25
|
+
apiKey: process.env.AI_GATEWAY_API_KEY!,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
for await (const event of experimental_composeSpec({
|
|
29
|
+
catalog,
|
|
30
|
+
candidates,
|
|
31
|
+
prompt: "Create account preferences with a name field and Save button",
|
|
32
|
+
initialState: { name: "" },
|
|
33
|
+
evaluate,
|
|
34
|
+
maxSteps: 12,
|
|
35
|
+
maxElements: 24,
|
|
36
|
+
signal: AbortSignal.timeout(30_000),
|
|
37
|
+
})) {
|
|
38
|
+
// Send snapshots to your client and render using your existing registry.
|
|
39
|
+
if (event.type === "step") console.log(event.spec);
|
|
40
|
+
else console.log(event.stopReason, event.spec);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Candidates contain `id`, `description`, and an atomic `element` (`type`, `props`, optional `on` and `visible`). `root: false` excludes a candidate from root selection; `maxUses` defaults to one; candidates sharing a `resource` are mutually exclusive. The catalog's slots determine where children can be attached. Props and action parameters are checked against initial state; expressions remain live in the output. Actions are never executed by the composer.
|
|
45
|
+
|
|
46
|
+
Candidates are configured component instances. The model constructs their tree, grouping, and order; it does not choose arbitrary prop values from the full catalog schema. Apps can build candidates per request from their records and permitted operations, or bind props to data in `initialState`. To let the model choose a different chart type or field configuration, supply those alternatives as candidates. No complete page template is required. Explicitly name required sections in the prompt; structural validation does not detect omitted content.
|
|
47
|
+
|
|
48
|
+
New compositions default to `strategy: "batch"`. One evaluation selects the root and component membership together, grouping mutually exclusive variants into one question and selecting bounded counts for reusable recipes. The first snapshot contains the selected content in catalog order under the root's default slot (or first declared slot). A second evaluation arranges parent slots and sibling order when needed. The entire resulting tree is validated before it is emitted; inconsistent placements throw and leave the first snapshot usable as partial UI. Equal sibling positions retain catalog order. Root selection takes precedence over speculative membership/count answers for the same recipe or resource. No separate finish call is needed.
|
|
49
|
+
|
|
50
|
+
`maxElements` bounds batched creation (default 32, including the root). An element/depth limit or a missing layout evaluation due to `maxSteps` produces `stopReason: "limit"`. Set `strategy: "sequential"` for one-operation-at-a-time creation or an existing custom evaluator using the `next`/`parent` protocol. Follow-up edits always use that sequential protocol, regardless of strategy.
|
|
51
|
+
|
|
52
|
+
For follow-up edits, pass the selected version as `initialSpec`. The composer can add candidates, replace an element's recipe while preserving its ID and children, remove a non-root subtree, or move/reorder a subtree among valid slots. Unchanged elements and state are retained, and the input spec is never mutated. `elementDescriptions` optionally supplies text identifying existing elements to the evaluator; otherwise matching recipes supply descriptions, with component names as the fallback. Raw props and state remain private. `initialState`, if supplied, replaces the seed's state.
|
|
53
|
+
|
|
54
|
+
Seed specs must be valid trees within the same catalog, supported expression subset, and depth limit. Existing elements that exactly match a candidate count toward its usage/resource limits. Removing or replacing them releases those limits. Replacements and moves use a second evaluation to select a valid recipe or destination; both decisions count toward `maxSteps`. A budget or cancellation can stop before an edit is applied.
|
|
55
|
+
|
|
56
|
+
The async generator emits detached `step` snapshots and a `complete` event with `stopReason: "finish" | "limit" | "unavailable"`, decision traces, timing, and nullable input usage. A batched trace represents one evaluation (`choice: "select"` or `"layout"`) and includes its independent `answers`; time and tokens are counted once per evaluation. Completion can include a partial spec or no spec, and does not guarantee that the model selected the right content. Provider errors, invalid choices, invalid combined layouts, and cancellation throw. Defaults: 32 evaluations, depth eight, and a 10-second per-call Gateway timeout.
|
|
57
|
+
|
|
58
|
+
V1 supports standard flat Spec catalogs, literals, `$state`, `$bindState`, state-based visibility, and named slots. It excludes repeat/watch, computed/custom expressions, and subtrees within candidate recipes. Bindings must resolve to valid values in the seed state or explicit `initialState`; handlers must still validate later user input. Candidate descriptions, element descriptions, and explicit `context` are sent to the evaluator; state values and raw props/bindings are not sent automatically.
|
|
59
|
+
|
|
60
|
+
See the [Jev guide](https://json-render.dev/docs/jev) for complete catalog/candidate examples, source-build installation, rendering, custom evaluators, limitations, and feedback. The [playground implementation](../../apps/web/lib/jev) uses these same APIs.
|
|
61
|
+
|
|
11
62
|
## Key Concepts
|
|
12
63
|
|
|
13
64
|
- **Schema**: Defines the structure of specs and catalogs
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StateModel, V as VisibilityCondition, a as StateCondition, A as AndCondition, O as OrCondition, D as DynamicValue, b as Spec, J as JsonPatch } from './store-utils-CGwRAVOR.mjs';
|
|
2
|
-
export { $ as Action, _ as ActionBinding, 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, e as DynamicBoolean, r as DynamicBooleanSchema, d as DynamicNumber, q as DynamicNumberSchema, c as DynamicString, p as DynamicStringSchema, o as DynamicValueSchema, F as FlatElement, f as IndexCondition, I as ItemCondition, M as MixedStreamCallbacks, l as MixedStreamParser, P as PatchOp, R as RepeatStatePath, a5 as ResolvedAction, W as SPEC_DATA_PART, X as SPEC_DATA_PART_TYPE, g as SingleCondition, n as SpecDataPart, k as SpecStreamCompiler, j as SpecStreamLine, h as StateStore, Y as StoreAdapterConfig, m as StreamChunk,
|
|
1
|
+
import { S as StateModel, V as VisibilityCondition, a as StateCondition, A as AndCondition, O as OrCondition, D as DynamicValue, b as Spec, J as JsonPatch, U as UIElement } from './store-utils-CGwRAVOR.mjs';
|
|
2
|
+
export { $ as Action, _ as ActionBinding, 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, e as DynamicBoolean, r as DynamicBooleanSchema, d as DynamicNumber, q as DynamicNumberSchema, c as DynamicString, p as DynamicStringSchema, o as DynamicValueSchema, F as FlatElement, f as IndexCondition, I as ItemCondition, M as MixedStreamCallbacks, l as MixedStreamParser, P as PatchOp, R as RepeatStatePath, a5 as ResolvedAction, W as SPEC_DATA_PART, X as SPEC_DATA_PART_TYPE, g as SingleCondition, n as SpecDataPart, k as SpecStreamCompiler, j as SpecStreamLine, h as StateStore, Y as StoreAdapterConfig, m as StreamChunk, i as ValidationMode, ag as action, af as actionBinding, x as addByPath, G as applySpecPatch, E as applySpecStreamPatch, K as compileSpecStream, Q as createJsonRenderTransform, N as createMixedStreamParser, L as createSpecStreamCompiler, Z as createStateStore, ad as executeAction, z as findFormValue, t as getByPath, ae as interpolateString, H as nestedToFlat, B as parseSpecStreamLine, T as pipeJsonRender, y as removeByPath, ac as resolveAction, s as resolveDynamicValue, v as resolveRepeatItemStatePath, u as resolveRepeatStatePath, w as setByPath } from './store-utils-CGwRAVOR.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -934,6 +934,49 @@ interface UserPromptOptions {
|
|
|
934
934
|
*/
|
|
935
935
|
declare function buildUserPrompt(options: UserPromptOptions): string;
|
|
936
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Slot metadata for named-slot validation.
|
|
939
|
+
*
|
|
940
|
+
* A renderer package records the slot names that each catalog component
|
|
941
|
+
* declares when it builds a registry from a catalog. When it renders an
|
|
942
|
+
* element with `slots`, it calls {@link warnElementSlots}, which warns about
|
|
943
|
+
* `slots.default` (spelled `children`) and about a slot name that the
|
|
944
|
+
* component does not declare.
|
|
945
|
+
*
|
|
946
|
+
* The metadata is keyed on the registry OBJECT, so a registry that a renderer
|
|
947
|
+
* clones must carry it over with {@link copySlotMetadata}. A hand-built
|
|
948
|
+
* registry carries no metadata, and its slot names are not validated.
|
|
949
|
+
*
|
|
950
|
+
* @packageDocumentation
|
|
951
|
+
*/
|
|
952
|
+
/** Slot names declared by one catalog component. */
|
|
953
|
+
interface ComponentSlotMetadata {
|
|
954
|
+
slots?: string[];
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Attach the slot declarations of a catalog to the registry that renders it.
|
|
958
|
+
* A catalog without component data attaches nothing.
|
|
959
|
+
*/
|
|
960
|
+
declare function setCatalogSlotMetadata(registry: object, catalog: unknown): void;
|
|
961
|
+
/**
|
|
962
|
+
* Carry the slot metadata of one registry over to a clone of it. A bare
|
|
963
|
+
* spread loses the metadata and silences named-slot validation.
|
|
964
|
+
*/
|
|
965
|
+
declare function copySlotMetadata(from: object, to: object): void;
|
|
966
|
+
/**
|
|
967
|
+
* Slot declarations for one component type, or `undefined` when the registry
|
|
968
|
+
* carries no catalog metadata or the type is not in the catalog.
|
|
969
|
+
*/
|
|
970
|
+
declare function getComponentSlotMetadata(registry: object, type: string): ComponentSlotMetadata | undefined;
|
|
971
|
+
/**
|
|
972
|
+
* Warn about the named slots of an element of component `type`: about
|
|
973
|
+
* `slots.default`, which is spelled `children`, and about each slot name that
|
|
974
|
+
* the catalog does not declare for the component. The renderer still renders
|
|
975
|
+
* an undeclared slot. Nothing is validated for a registry without catalog
|
|
976
|
+
* metadata, or for a component that declares no slots.
|
|
977
|
+
*/
|
|
978
|
+
declare function warnElementSlots(registry: object, type: string, slots: Record<string, string[]> | undefined): void;
|
|
979
|
+
|
|
937
980
|
/**
|
|
938
981
|
* Deep-merge `patch` into `base`, returning a new object.
|
|
939
982
|
*
|
|
@@ -958,4 +1001,133 @@ declare function deepMergeSpec(base: Record<string, unknown>, patch: Record<stri
|
|
|
958
1001
|
*/
|
|
959
1002
|
declare function diffToPatches(oldObj: Record<string, unknown>, newObj: Record<string, unknown>, basePath?: string): JsonPatch[];
|
|
960
1003
|
|
|
961
|
-
|
|
1004
|
+
/** Experimental: may change in any release. A catalog using the flat Spec format. */
|
|
1005
|
+
interface Experimental_CompositionCatalog {
|
|
1006
|
+
data: {
|
|
1007
|
+
components: Record<string, {
|
|
1008
|
+
props: z.ZodType;
|
|
1009
|
+
slots?: readonly string[];
|
|
1010
|
+
events?: readonly string[];
|
|
1011
|
+
}>;
|
|
1012
|
+
actions?: Record<string, {
|
|
1013
|
+
params?: z.ZodType;
|
|
1014
|
+
}>;
|
|
1015
|
+
};
|
|
1016
|
+
schema?: {
|
|
1017
|
+
builtInActions?: readonly {
|
|
1018
|
+
name: string;
|
|
1019
|
+
}[];
|
|
1020
|
+
};
|
|
1021
|
+
validate(spec: unknown): {
|
|
1022
|
+
success: boolean;
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
/** One app-owned element recipe. The evaluator cannot modify its props or bindings. */
|
|
1026
|
+
interface Experimental_CompositionCandidate {
|
|
1027
|
+
id: string;
|
|
1028
|
+
description: string;
|
|
1029
|
+
element: Pick<UIElement, "type" | "props" | "on" | "visible">;
|
|
1030
|
+
/** Whether this candidate can be the root. Defaults to true. */
|
|
1031
|
+
root?: boolean;
|
|
1032
|
+
/** Defaults to one. Reusable layout elements can opt into a larger count. */
|
|
1033
|
+
maxUses?: number;
|
|
1034
|
+
/** Candidates sharing a resource are mutually exclusive. */
|
|
1035
|
+
resource?: string;
|
|
1036
|
+
}
|
|
1037
|
+
interface Experimental_ChoiceQuestion {
|
|
1038
|
+
type: "choice";
|
|
1039
|
+
instructions: string;
|
|
1040
|
+
criteria: Record<string, string>;
|
|
1041
|
+
}
|
|
1042
|
+
interface Experimental_CompositionEvaluation {
|
|
1043
|
+
answers: Record<string, {
|
|
1044
|
+
choice: string;
|
|
1045
|
+
confidence?: number;
|
|
1046
|
+
}>;
|
|
1047
|
+
usage?: {
|
|
1048
|
+
inputTokens?: number;
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
/** Custom adapters must return one of each question's offered criteria keys. */
|
|
1052
|
+
type Experimental_CompositionEvaluator = (request: {
|
|
1053
|
+
state: Record<string, unknown>;
|
|
1054
|
+
questions: Record<string, Experimental_ChoiceQuestion>;
|
|
1055
|
+
signal: AbortSignal;
|
|
1056
|
+
}) => Promise<Experimental_CompositionEvaluation>;
|
|
1057
|
+
interface Experimental_CompositionStep {
|
|
1058
|
+
index: number;
|
|
1059
|
+
choice: string;
|
|
1060
|
+
description: string;
|
|
1061
|
+
parent: string | null;
|
|
1062
|
+
slot: string | null;
|
|
1063
|
+
confidence: number | null;
|
|
1064
|
+
parentConfidence: number | null;
|
|
1065
|
+
elapsedMs: number;
|
|
1066
|
+
inputTokens: number | null;
|
|
1067
|
+
/** Independent answers from a batched selection or layout evaluation. */
|
|
1068
|
+
answers?: Experimental_CompositionEvaluation["answers"];
|
|
1069
|
+
}
|
|
1070
|
+
type Experimental_CompositionEvent = {
|
|
1071
|
+
type: "step";
|
|
1072
|
+
spec: Spec;
|
|
1073
|
+
step: Experimental_CompositionStep;
|
|
1074
|
+
} | {
|
|
1075
|
+
type: "complete";
|
|
1076
|
+
spec: Spec | null;
|
|
1077
|
+
steps: Experimental_CompositionStep[];
|
|
1078
|
+
elapsedMs: number;
|
|
1079
|
+
inputTokens: number | null;
|
|
1080
|
+
stopReason: "finish" | "limit" | "unavailable";
|
|
1081
|
+
};
|
|
1082
|
+
interface Experimental_ComposeSpecOptions {
|
|
1083
|
+
catalog: Experimental_CompositionCatalog;
|
|
1084
|
+
candidates: readonly Experimental_CompositionCandidate[];
|
|
1085
|
+
prompt: string;
|
|
1086
|
+
evaluate: Experimental_CompositionEvaluator;
|
|
1087
|
+
/** New trees use batched selection/layout by default. Edits remain sequential. */
|
|
1088
|
+
strategy?: "batch" | "sequential";
|
|
1089
|
+
/** Element budget for batched creation, including the root. Default: 32. */
|
|
1090
|
+
maxElements?: number;
|
|
1091
|
+
/** Edit an existing tree. Cloned and validated before evaluation. */
|
|
1092
|
+
initialSpec?: Spec;
|
|
1093
|
+
/** Descriptions explicitly shared for existing elements, keyed by element ID. */
|
|
1094
|
+
elementDescriptions?: Record<string, string>;
|
|
1095
|
+
/** Included in the spec, never sent to the evaluator. Overrides initialSpec.state. */
|
|
1096
|
+
initialState?: Record<string, unknown>;
|
|
1097
|
+
/** Additional app context explicitly shared with the evaluator. */
|
|
1098
|
+
context?: Record<string, unknown>;
|
|
1099
|
+
signal?: AbortSignal;
|
|
1100
|
+
/** Evaluation budget, including sequential terminal decisions. Default: 32. */
|
|
1101
|
+
maxSteps?: number;
|
|
1102
|
+
/** Root has depth one. Default: 8. */
|
|
1103
|
+
maxDepth?: number;
|
|
1104
|
+
/** App-specific guidance appended to the construction instructions. */
|
|
1105
|
+
instructions?: {
|
|
1106
|
+
root?: string;
|
|
1107
|
+
next?: string;
|
|
1108
|
+
parent?: string;
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Experimental catalog-constrained composition. Streams detached Spec snapshots.
|
|
1113
|
+
* Throws on invalid configuration, evaluator output, provider errors, or abort.
|
|
1114
|
+
* Actions are copied into the spec; they are never executed by the composer.
|
|
1115
|
+
*/
|
|
1116
|
+
declare function experimental_composeSpec(options: Experimental_ComposeSpecOptions): AsyncGenerator<Experimental_CompositionEvent>;
|
|
1117
|
+
|
|
1118
|
+
interface Experimental_EvaluatorOptions {
|
|
1119
|
+
/** Server-side Vercel AI Gateway key. Never expose this in browser code. */
|
|
1120
|
+
apiKey: string;
|
|
1121
|
+
/** Gateway evaluation model identifier, for example typesafe-ai/jev. */
|
|
1122
|
+
model: string;
|
|
1123
|
+
/** Per-evaluation timeout in milliseconds. Default: 10000. */
|
|
1124
|
+
timeoutMs?: number;
|
|
1125
|
+
fetch?: typeof globalThis.fetch;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Experimental server-side choice evaluator using Vercel AI Gateway's v4 evaluation
|
|
1129
|
+
* transport. No AI SDK provider constructor or additional dependency is needed.
|
|
1130
|
+
*/
|
|
1131
|
+
declare function experimental_createEvaluator(options: Experimental_EvaluatorOptions): Experimental_CompositionEvaluator;
|
|
1132
|
+
|
|
1133
|
+
export { 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, check, conditionUsesItemScope, copySlotMetadata, createDirectiveRegistry, deepMergeSpec, defineCatalog, defineDirective, defineSchema, diffToPatches, evaluateVisibility, experimental_composeSpec, experimental_createEvaluator, findDirective, formatSpecIssues, getComponentSlotMetadata, isDevtoolsActive, isNonEmptySpec, markDevtoolsActive, nextActionDispatchId, notifyActionDispatch, notifyActionSettle, registerActionObserver, resolveActionParam, resolveBindings, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, setCatalogSlotMetadata, splitRepeatVisibility, subscribeDevtoolsActive, validateSpec, visibility, warnElementSlots };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StateModel, V as VisibilityCondition, a as StateCondition, A as AndCondition, O as OrCondition, D as DynamicValue, b as Spec, J as JsonPatch } from './store-utils-CGwRAVOR.js';
|
|
2
|
-
export { $ as Action, _ as ActionBinding, 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, e as DynamicBoolean, r as DynamicBooleanSchema, d as DynamicNumber, q as DynamicNumberSchema, c as DynamicString, p as DynamicStringSchema, o as DynamicValueSchema, F as FlatElement, f as IndexCondition, I as ItemCondition, M as MixedStreamCallbacks, l as MixedStreamParser, P as PatchOp, R as RepeatStatePath, a5 as ResolvedAction, W as SPEC_DATA_PART, X as SPEC_DATA_PART_TYPE, g as SingleCondition, n as SpecDataPart, k as SpecStreamCompiler, j as SpecStreamLine, h as StateStore, Y as StoreAdapterConfig, m as StreamChunk,
|
|
1
|
+
import { S as StateModel, V as VisibilityCondition, a as StateCondition, A as AndCondition, O as OrCondition, D as DynamicValue, b as Spec, J as JsonPatch, U as UIElement } from './store-utils-CGwRAVOR.js';
|
|
2
|
+
export { $ as Action, _ as ActionBinding, 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, e as DynamicBoolean, r as DynamicBooleanSchema, d as DynamicNumber, q as DynamicNumberSchema, c as DynamicString, p as DynamicStringSchema, o as DynamicValueSchema, F as FlatElement, f as IndexCondition, I as ItemCondition, M as MixedStreamCallbacks, l as MixedStreamParser, P as PatchOp, R as RepeatStatePath, a5 as ResolvedAction, W as SPEC_DATA_PART, X as SPEC_DATA_PART_TYPE, g as SingleCondition, n as SpecDataPart, k as SpecStreamCompiler, j as SpecStreamLine, h as StateStore, Y as StoreAdapterConfig, m as StreamChunk, i as ValidationMode, ag as action, af as actionBinding, x as addByPath, G as applySpecPatch, E as applySpecStreamPatch, K as compileSpecStream, Q as createJsonRenderTransform, N as createMixedStreamParser, L as createSpecStreamCompiler, Z as createStateStore, ad as executeAction, z as findFormValue, t as getByPath, ae as interpolateString, H as nestedToFlat, B as parseSpecStreamLine, T as pipeJsonRender, y as removeByPath, ac as resolveAction, s as resolveDynamicValue, v as resolveRepeatItemStatePath, u as resolveRepeatStatePath, w as setByPath } from './store-utils-CGwRAVOR.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -934,6 +934,49 @@ interface UserPromptOptions {
|
|
|
934
934
|
*/
|
|
935
935
|
declare function buildUserPrompt(options: UserPromptOptions): string;
|
|
936
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Slot metadata for named-slot validation.
|
|
939
|
+
*
|
|
940
|
+
* A renderer package records the slot names that each catalog component
|
|
941
|
+
* declares when it builds a registry from a catalog. When it renders an
|
|
942
|
+
* element with `slots`, it calls {@link warnElementSlots}, which warns about
|
|
943
|
+
* `slots.default` (spelled `children`) and about a slot name that the
|
|
944
|
+
* component does not declare.
|
|
945
|
+
*
|
|
946
|
+
* The metadata is keyed on the registry OBJECT, so a registry that a renderer
|
|
947
|
+
* clones must carry it over with {@link copySlotMetadata}. A hand-built
|
|
948
|
+
* registry carries no metadata, and its slot names are not validated.
|
|
949
|
+
*
|
|
950
|
+
* @packageDocumentation
|
|
951
|
+
*/
|
|
952
|
+
/** Slot names declared by one catalog component. */
|
|
953
|
+
interface ComponentSlotMetadata {
|
|
954
|
+
slots?: string[];
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Attach the slot declarations of a catalog to the registry that renders it.
|
|
958
|
+
* A catalog without component data attaches nothing.
|
|
959
|
+
*/
|
|
960
|
+
declare function setCatalogSlotMetadata(registry: object, catalog: unknown): void;
|
|
961
|
+
/**
|
|
962
|
+
* Carry the slot metadata of one registry over to a clone of it. A bare
|
|
963
|
+
* spread loses the metadata and silences named-slot validation.
|
|
964
|
+
*/
|
|
965
|
+
declare function copySlotMetadata(from: object, to: object): void;
|
|
966
|
+
/**
|
|
967
|
+
* Slot declarations for one component type, or `undefined` when the registry
|
|
968
|
+
* carries no catalog metadata or the type is not in the catalog.
|
|
969
|
+
*/
|
|
970
|
+
declare function getComponentSlotMetadata(registry: object, type: string): ComponentSlotMetadata | undefined;
|
|
971
|
+
/**
|
|
972
|
+
* Warn about the named slots of an element of component `type`: about
|
|
973
|
+
* `slots.default`, which is spelled `children`, and about each slot name that
|
|
974
|
+
* the catalog does not declare for the component. The renderer still renders
|
|
975
|
+
* an undeclared slot. Nothing is validated for a registry without catalog
|
|
976
|
+
* metadata, or for a component that declares no slots.
|
|
977
|
+
*/
|
|
978
|
+
declare function warnElementSlots(registry: object, type: string, slots: Record<string, string[]> | undefined): void;
|
|
979
|
+
|
|
937
980
|
/**
|
|
938
981
|
* Deep-merge `patch` into `base`, returning a new object.
|
|
939
982
|
*
|
|
@@ -958,4 +1001,133 @@ declare function deepMergeSpec(base: Record<string, unknown>, patch: Record<stri
|
|
|
958
1001
|
*/
|
|
959
1002
|
declare function diffToPatches(oldObj: Record<string, unknown>, newObj: Record<string, unknown>, basePath?: string): JsonPatch[];
|
|
960
1003
|
|
|
961
|
-
|
|
1004
|
+
/** Experimental: may change in any release. A catalog using the flat Spec format. */
|
|
1005
|
+
interface Experimental_CompositionCatalog {
|
|
1006
|
+
data: {
|
|
1007
|
+
components: Record<string, {
|
|
1008
|
+
props: z.ZodType;
|
|
1009
|
+
slots?: readonly string[];
|
|
1010
|
+
events?: readonly string[];
|
|
1011
|
+
}>;
|
|
1012
|
+
actions?: Record<string, {
|
|
1013
|
+
params?: z.ZodType;
|
|
1014
|
+
}>;
|
|
1015
|
+
};
|
|
1016
|
+
schema?: {
|
|
1017
|
+
builtInActions?: readonly {
|
|
1018
|
+
name: string;
|
|
1019
|
+
}[];
|
|
1020
|
+
};
|
|
1021
|
+
validate(spec: unknown): {
|
|
1022
|
+
success: boolean;
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
/** One app-owned element recipe. The evaluator cannot modify its props or bindings. */
|
|
1026
|
+
interface Experimental_CompositionCandidate {
|
|
1027
|
+
id: string;
|
|
1028
|
+
description: string;
|
|
1029
|
+
element: Pick<UIElement, "type" | "props" | "on" | "visible">;
|
|
1030
|
+
/** Whether this candidate can be the root. Defaults to true. */
|
|
1031
|
+
root?: boolean;
|
|
1032
|
+
/** Defaults to one. Reusable layout elements can opt into a larger count. */
|
|
1033
|
+
maxUses?: number;
|
|
1034
|
+
/** Candidates sharing a resource are mutually exclusive. */
|
|
1035
|
+
resource?: string;
|
|
1036
|
+
}
|
|
1037
|
+
interface Experimental_ChoiceQuestion {
|
|
1038
|
+
type: "choice";
|
|
1039
|
+
instructions: string;
|
|
1040
|
+
criteria: Record<string, string>;
|
|
1041
|
+
}
|
|
1042
|
+
interface Experimental_CompositionEvaluation {
|
|
1043
|
+
answers: Record<string, {
|
|
1044
|
+
choice: string;
|
|
1045
|
+
confidence?: number;
|
|
1046
|
+
}>;
|
|
1047
|
+
usage?: {
|
|
1048
|
+
inputTokens?: number;
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
/** Custom adapters must return one of each question's offered criteria keys. */
|
|
1052
|
+
type Experimental_CompositionEvaluator = (request: {
|
|
1053
|
+
state: Record<string, unknown>;
|
|
1054
|
+
questions: Record<string, Experimental_ChoiceQuestion>;
|
|
1055
|
+
signal: AbortSignal;
|
|
1056
|
+
}) => Promise<Experimental_CompositionEvaluation>;
|
|
1057
|
+
interface Experimental_CompositionStep {
|
|
1058
|
+
index: number;
|
|
1059
|
+
choice: string;
|
|
1060
|
+
description: string;
|
|
1061
|
+
parent: string | null;
|
|
1062
|
+
slot: string | null;
|
|
1063
|
+
confidence: number | null;
|
|
1064
|
+
parentConfidence: number | null;
|
|
1065
|
+
elapsedMs: number;
|
|
1066
|
+
inputTokens: number | null;
|
|
1067
|
+
/** Independent answers from a batched selection or layout evaluation. */
|
|
1068
|
+
answers?: Experimental_CompositionEvaluation["answers"];
|
|
1069
|
+
}
|
|
1070
|
+
type Experimental_CompositionEvent = {
|
|
1071
|
+
type: "step";
|
|
1072
|
+
spec: Spec;
|
|
1073
|
+
step: Experimental_CompositionStep;
|
|
1074
|
+
} | {
|
|
1075
|
+
type: "complete";
|
|
1076
|
+
spec: Spec | null;
|
|
1077
|
+
steps: Experimental_CompositionStep[];
|
|
1078
|
+
elapsedMs: number;
|
|
1079
|
+
inputTokens: number | null;
|
|
1080
|
+
stopReason: "finish" | "limit" | "unavailable";
|
|
1081
|
+
};
|
|
1082
|
+
interface Experimental_ComposeSpecOptions {
|
|
1083
|
+
catalog: Experimental_CompositionCatalog;
|
|
1084
|
+
candidates: readonly Experimental_CompositionCandidate[];
|
|
1085
|
+
prompt: string;
|
|
1086
|
+
evaluate: Experimental_CompositionEvaluator;
|
|
1087
|
+
/** New trees use batched selection/layout by default. Edits remain sequential. */
|
|
1088
|
+
strategy?: "batch" | "sequential";
|
|
1089
|
+
/** Element budget for batched creation, including the root. Default: 32. */
|
|
1090
|
+
maxElements?: number;
|
|
1091
|
+
/** Edit an existing tree. Cloned and validated before evaluation. */
|
|
1092
|
+
initialSpec?: Spec;
|
|
1093
|
+
/** Descriptions explicitly shared for existing elements, keyed by element ID. */
|
|
1094
|
+
elementDescriptions?: Record<string, string>;
|
|
1095
|
+
/** Included in the spec, never sent to the evaluator. Overrides initialSpec.state. */
|
|
1096
|
+
initialState?: Record<string, unknown>;
|
|
1097
|
+
/** Additional app context explicitly shared with the evaluator. */
|
|
1098
|
+
context?: Record<string, unknown>;
|
|
1099
|
+
signal?: AbortSignal;
|
|
1100
|
+
/** Evaluation budget, including sequential terminal decisions. Default: 32. */
|
|
1101
|
+
maxSteps?: number;
|
|
1102
|
+
/** Root has depth one. Default: 8. */
|
|
1103
|
+
maxDepth?: number;
|
|
1104
|
+
/** App-specific guidance appended to the construction instructions. */
|
|
1105
|
+
instructions?: {
|
|
1106
|
+
root?: string;
|
|
1107
|
+
next?: string;
|
|
1108
|
+
parent?: string;
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Experimental catalog-constrained composition. Streams detached Spec snapshots.
|
|
1113
|
+
* Throws on invalid configuration, evaluator output, provider errors, or abort.
|
|
1114
|
+
* Actions are copied into the spec; they are never executed by the composer.
|
|
1115
|
+
*/
|
|
1116
|
+
declare function experimental_composeSpec(options: Experimental_ComposeSpecOptions): AsyncGenerator<Experimental_CompositionEvent>;
|
|
1117
|
+
|
|
1118
|
+
interface Experimental_EvaluatorOptions {
|
|
1119
|
+
/** Server-side Vercel AI Gateway key. Never expose this in browser code. */
|
|
1120
|
+
apiKey: string;
|
|
1121
|
+
/** Gateway evaluation model identifier, for example typesafe-ai/jev. */
|
|
1122
|
+
model: string;
|
|
1123
|
+
/** Per-evaluation timeout in milliseconds. Default: 10000. */
|
|
1124
|
+
timeoutMs?: number;
|
|
1125
|
+
fetch?: typeof globalThis.fetch;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Experimental server-side choice evaluator using Vercel AI Gateway's v4 evaluation
|
|
1129
|
+
* transport. No AI SDK provider constructor or additional dependency is needed.
|
|
1130
|
+
*/
|
|
1131
|
+
declare function experimental_createEvaluator(options: Experimental_EvaluatorOptions): Experimental_CompositionEvaluator;
|
|
1132
|
+
|
|
1133
|
+
export { 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, check, conditionUsesItemScope, copySlotMetadata, createDirectiveRegistry, deepMergeSpec, defineCatalog, defineDirective, defineSchema, diffToPatches, evaluateVisibility, experimental_composeSpec, experimental_createEvaluator, findDirective, formatSpecIssues, getComponentSlotMetadata, isDevtoolsActive, isNonEmptySpec, markDevtoolsActive, nextActionDispatchId, notifyActionDispatch, notifyActionSettle, registerActionObserver, resolveActionParam, resolveBindings, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, setCatalogSlotMetadata, splitRepeatVisibility, subscribeDevtoolsActive, validateSpec, visibility, warnElementSlots };
|