@json-render/core 0.6.1 → 0.8.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 +26 -0
- package/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +54 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,6 +157,14 @@ const spec = compileSpecStream<MySpec>(jsonlString);
|
|
|
157
157
|
| `defineSchema(builder, options?)` | Create a schema with spec/catalog structure |
|
|
158
158
|
| `SchemaBuilder` | Builder with `s.object()`, `s.array()`, `s.map()`, etc. |
|
|
159
159
|
|
|
160
|
+
Schema options:
|
|
161
|
+
|
|
162
|
+
| Option | Purpose |
|
|
163
|
+
|--------|---------|
|
|
164
|
+
| `promptTemplate` | Custom AI prompt generator |
|
|
165
|
+
| `defaultRules` | Default rules injected before custom rules in prompts |
|
|
166
|
+
| `builtInActions` | Actions always available at runtime, auto-injected into prompts (e.g. `setState`) |
|
|
167
|
+
|
|
160
168
|
### Catalog
|
|
161
169
|
|
|
162
170
|
| Export | Purpose |
|
|
@@ -196,12 +204,30 @@ const spec = compileSpecStream<MySpec>(jsonlString);
|
|
|
196
204
|
| `autoFixSpec(spec)` | Auto-fix common spec issues (returns corrected copy) |
|
|
197
205
|
| `formatSpecIssues(issues)` | Format validation issues as readable strings |
|
|
198
206
|
|
|
207
|
+
### Actions
|
|
208
|
+
|
|
209
|
+
| Export | Purpose |
|
|
210
|
+
|--------|---------|
|
|
211
|
+
| `ActionBinding` | Action binding with `action`, `params`, `confirm`, `preventDefault`, etc. |
|
|
212
|
+
| `BuiltInAction` | Built-in action definition with `name` and `description` |
|
|
213
|
+
|
|
214
|
+
### Chat Mode (Mixed Streams)
|
|
215
|
+
|
|
216
|
+
| Export | Purpose |
|
|
217
|
+
|--------|---------|
|
|
218
|
+
| `createJsonRenderTransform()` | TransformStream that separates text from JSONL patches in a mixed stream |
|
|
219
|
+
| `pipeJsonRender()` | Server-side helper to pipe a mixed stream through the transform |
|
|
220
|
+
| `SPEC_DATA_PART` / `SPEC_DATA_PART_TYPE` | Constants for filtering spec data parts |
|
|
221
|
+
|
|
222
|
+
The transform splits text blocks around spec data by emitting `text-end`/`text-start` pairs, ensuring the AI SDK creates separate text parts and preserving correct interleaving of prose and UI in `message.parts`.
|
|
223
|
+
|
|
199
224
|
### Types
|
|
200
225
|
|
|
201
226
|
| Export | Purpose |
|
|
202
227
|
|--------|---------|
|
|
203
228
|
| `Spec` | Base spec type |
|
|
204
229
|
| `Catalog` | Catalog type |
|
|
230
|
+
| `BuiltInAction` | Built-in action type (`name` + `description`) |
|
|
205
231
|
| `VisibilityCondition` | Visibility condition type (used by `$cond`) |
|
|
206
232
|
| `VisibilityContext` | Context for evaluating visibility and prop expressions |
|
|
207
233
|
| `SpecStreamLine` | Single patch operation |
|
package/dist/index.d.mts
CHANGED
|
@@ -47,6 +47,8 @@ interface ActionBinding {
|
|
|
47
47
|
onSuccess?: ActionOnSuccess;
|
|
48
48
|
/** Handler after failed execution */
|
|
49
49
|
onError?: ActionOnError;
|
|
50
|
+
/** Whether to prevent default browser behavior (e.g. navigation on links) */
|
|
51
|
+
preventDefault?: boolean;
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* @deprecated Use ActionBinding instead
|
|
@@ -113,6 +115,7 @@ declare const ActionBindingSchema: z.ZodObject<{
|
|
|
113
115
|
}, z.core.$strip>, z.ZodObject<{
|
|
114
116
|
action: z.ZodString;
|
|
115
117
|
}, z.core.$strip>]>>;
|
|
118
|
+
preventDefault: z.ZodOptional<z.ZodBoolean>;
|
|
116
119
|
}, z.core.$strip>;
|
|
117
120
|
/**
|
|
118
121
|
* @deprecated Use ActionBindingSchema instead
|
|
@@ -144,6 +147,7 @@ declare const ActionSchema: z.ZodObject<{
|
|
|
144
147
|
}, z.core.$strip>, z.ZodObject<{
|
|
145
148
|
action: z.ZodString;
|
|
146
149
|
}, z.core.$strip>]>>;
|
|
150
|
+
preventDefault: z.ZodOptional<z.ZodBoolean>;
|
|
147
151
|
}, z.core.$strip>;
|
|
148
152
|
/**
|
|
149
153
|
* Action handler function signature
|
|
@@ -1129,6 +1133,8 @@ interface Schema<TDef extends SchemaDefinition = SchemaDefinition> {
|
|
|
1129
1133
|
readonly promptTemplate?: PromptTemplate;
|
|
1130
1134
|
/** Default rules baked into the schema (injected before customRules) */
|
|
1131
1135
|
readonly defaultRules?: string[];
|
|
1136
|
+
/** Built-in actions always available at runtime (injected into prompts automatically) */
|
|
1137
|
+
readonly builtInActions?: BuiltInAction[];
|
|
1132
1138
|
/** Create a catalog from this schema */
|
|
1133
1139
|
createCatalog<TCatalog extends InferCatalogInput<TDef["catalog"]>>(catalog: TCatalog): Catalog<TDef, TCatalog>;
|
|
1134
1140
|
}
|
|
@@ -1191,6 +1197,17 @@ interface PromptContext<TCatalog = unknown> {
|
|
|
1191
1197
|
* Prompt template function type
|
|
1192
1198
|
*/
|
|
1193
1199
|
type PromptTemplate<TCatalog = unknown> = (context: PromptContext<TCatalog>) => string;
|
|
1200
|
+
/**
|
|
1201
|
+
* A built-in action that is always available regardless of catalog configuration.
|
|
1202
|
+
* These are handled by the runtime (e.g. ActionProvider) and injected into prompts
|
|
1203
|
+
* automatically so the LLM knows about them.
|
|
1204
|
+
*/
|
|
1205
|
+
interface BuiltInAction {
|
|
1206
|
+
/** Action name (e.g. "setState") */
|
|
1207
|
+
name: string;
|
|
1208
|
+
/** Human-readable description for the LLM */
|
|
1209
|
+
description: string;
|
|
1210
|
+
}
|
|
1194
1211
|
/**
|
|
1195
1212
|
* Schema options
|
|
1196
1213
|
*/
|
|
@@ -1199,6 +1216,13 @@ interface SchemaOptions<TCatalog = unknown> {
|
|
|
1199
1216
|
promptTemplate?: PromptTemplate<TCatalog>;
|
|
1200
1217
|
/** Default rules baked into the schema (injected before customRules in prompts) */
|
|
1201
1218
|
defaultRules?: string[];
|
|
1219
|
+
/**
|
|
1220
|
+
* Built-in actions that are always available regardless of catalog configuration.
|
|
1221
|
+
* These are injected into prompts automatically so the LLM knows about them,
|
|
1222
|
+
* but they don't require handlers in defineRegistry because the runtime
|
|
1223
|
+
* (e.g. ActionProvider) handles them directly.
|
|
1224
|
+
*/
|
|
1225
|
+
builtInActions?: BuiltInAction[];
|
|
1202
1226
|
}
|
|
1203
1227
|
/**
|
|
1204
1228
|
* Spec validation result
|
|
@@ -1312,4 +1336,4 @@ interface UserPromptOptions {
|
|
|
1312
1336
|
*/
|
|
1313
1337
|
declare function buildUserPrompt(options: UserPromptOptions): string;
|
|
1314
1338
|
|
|
1315
|
-
export { type Action, type ActionBinding, ActionBindingSchema, type ActionConfirm, ActionConfirmSchema, type ActionDefinition, type ActionExecutionContext, type ActionHandler, type ActionOnError, ActionOnErrorSchema, type ActionOnSuccess, ActionOnSuccessSchema, ActionSchema, type AndCondition, type Catalog, type ComponentSchema, type DynamicBoolean, DynamicBooleanSchema, type DynamicNumber, DynamicNumberSchema, type DynamicString, DynamicStringSchema, type DynamicValue, DynamicValueSchema, type FlatElement, type IndexCondition, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, type ItemCondition, type JsonPatch, type MixedStreamCallbacks, type MixedStreamParser, type OrCondition, type PatchOp, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type ResolvedAction, SPEC_DATA_PART, SPEC_DATA_PART_TYPE, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, type SingleCondition, type Spec, type SpecDataPart, type SpecIssue, type SpecIssueSeverity, type SpecStreamCompiler, type SpecStreamLine, type SpecValidationIssues, type SpecValidationResult, type StateCondition, type StateModel, type StreamChunk, type UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationMode, type ValidationResult, type VisibilityCondition, VisibilityConditionSchema, type VisibilityContext, action, actionBinding, addByPath, applySpecPatch, applySpecStreamPatch, autoFixSpec, buildUserPrompt, builtInValidationFunctions, check, compileSpecStream, createJsonRenderTransform, createMixedStreamParser, createSpecStreamCompiler, defineCatalog, defineSchema, evaluateVisibility, executeAction, findFormValue, formatSpecIssues, getByPath, interpolateString, nestedToFlat, parseSpecStreamLine, pipeJsonRender, removeByPath, resolveAction, resolveActionParam, resolveBindings, resolveDynamicValue, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, setByPath, validateSpec, visibility };
|
|
1339
|
+
export { type Action, type ActionBinding, ActionBindingSchema, type ActionConfirm, ActionConfirmSchema, type ActionDefinition, type ActionExecutionContext, type ActionHandler, type ActionOnError, ActionOnErrorSchema, type ActionOnSuccess, ActionOnSuccessSchema, ActionSchema, type AndCondition, type BuiltInAction, type Catalog, type ComponentSchema, type DynamicBoolean, DynamicBooleanSchema, type DynamicNumber, DynamicNumberSchema, type DynamicString, DynamicStringSchema, type DynamicValue, DynamicValueSchema, type FlatElement, type IndexCondition, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, type ItemCondition, type JsonPatch, type MixedStreamCallbacks, type MixedStreamParser, type OrCondition, type PatchOp, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type ResolvedAction, SPEC_DATA_PART, SPEC_DATA_PART_TYPE, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, type SingleCondition, type Spec, type SpecDataPart, type SpecIssue, type SpecIssueSeverity, type SpecStreamCompiler, type SpecStreamLine, type SpecValidationIssues, type SpecValidationResult, type StateCondition, type StateModel, type StreamChunk, type UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationMode, type ValidationResult, type VisibilityCondition, VisibilityConditionSchema, type VisibilityContext, action, actionBinding, addByPath, applySpecPatch, applySpecStreamPatch, autoFixSpec, buildUserPrompt, builtInValidationFunctions, check, compileSpecStream, createJsonRenderTransform, createMixedStreamParser, createSpecStreamCompiler, defineCatalog, defineSchema, evaluateVisibility, executeAction, findFormValue, formatSpecIssues, getByPath, interpolateString, nestedToFlat, parseSpecStreamLine, pipeJsonRender, removeByPath, resolveAction, resolveActionParam, resolveBindings, resolveDynamicValue, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, setByPath, validateSpec, visibility };
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ interface ActionBinding {
|
|
|
47
47
|
onSuccess?: ActionOnSuccess;
|
|
48
48
|
/** Handler after failed execution */
|
|
49
49
|
onError?: ActionOnError;
|
|
50
|
+
/** Whether to prevent default browser behavior (e.g. navigation on links) */
|
|
51
|
+
preventDefault?: boolean;
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* @deprecated Use ActionBinding instead
|
|
@@ -113,6 +115,7 @@ declare const ActionBindingSchema: z.ZodObject<{
|
|
|
113
115
|
}, z.core.$strip>, z.ZodObject<{
|
|
114
116
|
action: z.ZodString;
|
|
115
117
|
}, z.core.$strip>]>>;
|
|
118
|
+
preventDefault: z.ZodOptional<z.ZodBoolean>;
|
|
116
119
|
}, z.core.$strip>;
|
|
117
120
|
/**
|
|
118
121
|
* @deprecated Use ActionBindingSchema instead
|
|
@@ -144,6 +147,7 @@ declare const ActionSchema: z.ZodObject<{
|
|
|
144
147
|
}, z.core.$strip>, z.ZodObject<{
|
|
145
148
|
action: z.ZodString;
|
|
146
149
|
}, z.core.$strip>]>>;
|
|
150
|
+
preventDefault: z.ZodOptional<z.ZodBoolean>;
|
|
147
151
|
}, z.core.$strip>;
|
|
148
152
|
/**
|
|
149
153
|
* Action handler function signature
|
|
@@ -1129,6 +1133,8 @@ interface Schema<TDef extends SchemaDefinition = SchemaDefinition> {
|
|
|
1129
1133
|
readonly promptTemplate?: PromptTemplate;
|
|
1130
1134
|
/** Default rules baked into the schema (injected before customRules) */
|
|
1131
1135
|
readonly defaultRules?: string[];
|
|
1136
|
+
/** Built-in actions always available at runtime (injected into prompts automatically) */
|
|
1137
|
+
readonly builtInActions?: BuiltInAction[];
|
|
1132
1138
|
/** Create a catalog from this schema */
|
|
1133
1139
|
createCatalog<TCatalog extends InferCatalogInput<TDef["catalog"]>>(catalog: TCatalog): Catalog<TDef, TCatalog>;
|
|
1134
1140
|
}
|
|
@@ -1191,6 +1197,17 @@ interface PromptContext<TCatalog = unknown> {
|
|
|
1191
1197
|
* Prompt template function type
|
|
1192
1198
|
*/
|
|
1193
1199
|
type PromptTemplate<TCatalog = unknown> = (context: PromptContext<TCatalog>) => string;
|
|
1200
|
+
/**
|
|
1201
|
+
* A built-in action that is always available regardless of catalog configuration.
|
|
1202
|
+
* These are handled by the runtime (e.g. ActionProvider) and injected into prompts
|
|
1203
|
+
* automatically so the LLM knows about them.
|
|
1204
|
+
*/
|
|
1205
|
+
interface BuiltInAction {
|
|
1206
|
+
/** Action name (e.g. "setState") */
|
|
1207
|
+
name: string;
|
|
1208
|
+
/** Human-readable description for the LLM */
|
|
1209
|
+
description: string;
|
|
1210
|
+
}
|
|
1194
1211
|
/**
|
|
1195
1212
|
* Schema options
|
|
1196
1213
|
*/
|
|
@@ -1199,6 +1216,13 @@ interface SchemaOptions<TCatalog = unknown> {
|
|
|
1199
1216
|
promptTemplate?: PromptTemplate<TCatalog>;
|
|
1200
1217
|
/** Default rules baked into the schema (injected before customRules in prompts) */
|
|
1201
1218
|
defaultRules?: string[];
|
|
1219
|
+
/**
|
|
1220
|
+
* Built-in actions that are always available regardless of catalog configuration.
|
|
1221
|
+
* These are injected into prompts automatically so the LLM knows about them,
|
|
1222
|
+
* but they don't require handlers in defineRegistry because the runtime
|
|
1223
|
+
* (e.g. ActionProvider) handles them directly.
|
|
1224
|
+
*/
|
|
1225
|
+
builtInActions?: BuiltInAction[];
|
|
1202
1226
|
}
|
|
1203
1227
|
/**
|
|
1204
1228
|
* Spec validation result
|
|
@@ -1312,4 +1336,4 @@ interface UserPromptOptions {
|
|
|
1312
1336
|
*/
|
|
1313
1337
|
declare function buildUserPrompt(options: UserPromptOptions): string;
|
|
1314
1338
|
|
|
1315
|
-
export { type Action, type ActionBinding, ActionBindingSchema, type ActionConfirm, ActionConfirmSchema, type ActionDefinition, type ActionExecutionContext, type ActionHandler, type ActionOnError, ActionOnErrorSchema, type ActionOnSuccess, ActionOnSuccessSchema, ActionSchema, type AndCondition, type Catalog, type ComponentSchema, type DynamicBoolean, DynamicBooleanSchema, type DynamicNumber, DynamicNumberSchema, type DynamicString, DynamicStringSchema, type DynamicValue, DynamicValueSchema, type FlatElement, type IndexCondition, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, type ItemCondition, type JsonPatch, type MixedStreamCallbacks, type MixedStreamParser, type OrCondition, type PatchOp, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type ResolvedAction, SPEC_DATA_PART, SPEC_DATA_PART_TYPE, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, type SingleCondition, type Spec, type SpecDataPart, type SpecIssue, type SpecIssueSeverity, type SpecStreamCompiler, type SpecStreamLine, type SpecValidationIssues, type SpecValidationResult, type StateCondition, type StateModel, type StreamChunk, type UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationMode, type ValidationResult, type VisibilityCondition, VisibilityConditionSchema, type VisibilityContext, action, actionBinding, addByPath, applySpecPatch, applySpecStreamPatch, autoFixSpec, buildUserPrompt, builtInValidationFunctions, check, compileSpecStream, createJsonRenderTransform, createMixedStreamParser, createSpecStreamCompiler, defineCatalog, defineSchema, evaluateVisibility, executeAction, findFormValue, formatSpecIssues, getByPath, interpolateString, nestedToFlat, parseSpecStreamLine, pipeJsonRender, removeByPath, resolveAction, resolveActionParam, resolveBindings, resolveDynamicValue, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, setByPath, validateSpec, visibility };
|
|
1339
|
+
export { type Action, type ActionBinding, ActionBindingSchema, type ActionConfirm, ActionConfirmSchema, type ActionDefinition, type ActionExecutionContext, type ActionHandler, type ActionOnError, ActionOnErrorSchema, type ActionOnSuccess, ActionOnSuccessSchema, ActionSchema, type AndCondition, type BuiltInAction, type Catalog, type ComponentSchema, type DynamicBoolean, DynamicBooleanSchema, type DynamicNumber, DynamicNumberSchema, type DynamicString, DynamicStringSchema, type DynamicValue, DynamicValueSchema, type FlatElement, type IndexCondition, type InferActionParams, type InferCatalogActions, type InferCatalogComponents, type InferCatalogInput, type InferComponentProps, type InferSpec, type ItemCondition, type JsonPatch, type MixedStreamCallbacks, type MixedStreamParser, type OrCondition, type PatchOp, type PromptContext, type PromptOptions, type PromptTemplate, type PropExpression, type PropResolutionContext, type ResolvedAction, SPEC_DATA_PART, SPEC_DATA_PART_TYPE, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaOptions, type SchemaType, type SingleCondition, type Spec, type SpecDataPart, type SpecIssue, type SpecIssueSeverity, type SpecStreamCompiler, type SpecStreamLine, type SpecValidationIssues, type SpecValidationResult, type StateCondition, type StateModel, type StreamChunk, type UIElement, type UserPromptOptions, type ValidateSpecOptions, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationMode, type ValidationResult, type VisibilityCondition, VisibilityConditionSchema, type VisibilityContext, action, actionBinding, addByPath, applySpecPatch, applySpecStreamPatch, autoFixSpec, buildUserPrompt, builtInValidationFunctions, check, compileSpecStream, createJsonRenderTransform, createMixedStreamParser, createSpecStreamCompiler, defineCatalog, defineSchema, evaluateVisibility, executeAction, findFormValue, formatSpecIssues, getByPath, interpolateString, nestedToFlat, parseSpecStreamLine, pipeJsonRender, removeByPath, resolveAction, resolveActionParam, resolveBindings, resolveDynamicValue, resolveElementProps, resolvePropValue, runValidation, runValidationCheck, setByPath, validateSpec, visibility };
|
package/dist/index.js
CHANGED
|
@@ -477,7 +477,28 @@ function createJsonRenderTransform() {
|
|
|
477
477
|
let currentTextId = "";
|
|
478
478
|
let buffering = false;
|
|
479
479
|
let inSpecFence = false;
|
|
480
|
+
let inTextBlock = false;
|
|
481
|
+
let textIdCounter = 0;
|
|
482
|
+
function closeTextBlock(controller) {
|
|
483
|
+
if (inTextBlock) {
|
|
484
|
+
controller.enqueue({ type: "text-end", id: currentTextId });
|
|
485
|
+
inTextBlock = false;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function ensureTextBlock(controller) {
|
|
489
|
+
if (!inTextBlock) {
|
|
490
|
+
textIdCounter++;
|
|
491
|
+
currentTextId = String(textIdCounter);
|
|
492
|
+
controller.enqueue({ type: "text-start", id: currentTextId });
|
|
493
|
+
inTextBlock = true;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function emitTextDelta(delta, controller) {
|
|
497
|
+
ensureTextBlock(controller);
|
|
498
|
+
controller.enqueue({ type: "text-delta", id: currentTextId, delta });
|
|
499
|
+
}
|
|
480
500
|
function emitPatch(patch, controller) {
|
|
501
|
+
closeTextBlock(controller);
|
|
481
502
|
controller.enqueue({
|
|
482
503
|
type: SPEC_DATA_PART_TYPE,
|
|
483
504
|
data: { type: "patch", patch }
|
|
@@ -500,18 +521,10 @@ function createJsonRenderTransform() {
|
|
|
500
521
|
if (patch) {
|
|
501
522
|
emitPatch(patch, controller);
|
|
502
523
|
} else {
|
|
503
|
-
controller
|
|
504
|
-
type: "text-delta",
|
|
505
|
-
id: currentTextId,
|
|
506
|
-
delta: lineBuffer
|
|
507
|
-
});
|
|
524
|
+
emitTextDelta(lineBuffer, controller);
|
|
508
525
|
}
|
|
509
526
|
} else {
|
|
510
|
-
controller
|
|
511
|
-
type: "text-delta",
|
|
512
|
-
id: currentTextId,
|
|
513
|
-
delta: lineBuffer
|
|
514
|
-
});
|
|
527
|
+
emitTextDelta(lineBuffer, controller);
|
|
515
528
|
}
|
|
516
529
|
lineBuffer = "";
|
|
517
530
|
buffering = false;
|
|
@@ -534,35 +547,32 @@ function createJsonRenderTransform() {
|
|
|
534
547
|
return;
|
|
535
548
|
}
|
|
536
549
|
if (!trimmed) {
|
|
537
|
-
controller
|
|
538
|
-
type: "text-delta",
|
|
539
|
-
id: currentTextId,
|
|
540
|
-
delta: "\n"
|
|
541
|
-
});
|
|
550
|
+
emitTextDelta("\n", controller);
|
|
542
551
|
return;
|
|
543
552
|
}
|
|
544
553
|
const patch = parseSpecStreamLine(trimmed);
|
|
545
554
|
if (patch) {
|
|
546
555
|
emitPatch(patch, controller);
|
|
547
556
|
} else {
|
|
548
|
-
controller
|
|
549
|
-
type: "text-delta",
|
|
550
|
-
id: currentTextId,
|
|
551
|
-
delta: line + "\n"
|
|
552
|
-
});
|
|
557
|
+
emitTextDelta(line + "\n", controller);
|
|
553
558
|
}
|
|
554
559
|
}
|
|
555
560
|
return new TransformStream({
|
|
556
561
|
transform(chunk, controller) {
|
|
557
562
|
switch (chunk.type) {
|
|
558
563
|
case "text-start": {
|
|
559
|
-
|
|
564
|
+
const id = chunk.id;
|
|
565
|
+
const idNum = parseInt(id, 10);
|
|
566
|
+
if (!isNaN(idNum) && idNum >= textIdCounter) {
|
|
567
|
+
textIdCounter = idNum;
|
|
568
|
+
}
|
|
569
|
+
currentTextId = id;
|
|
570
|
+
inTextBlock = true;
|
|
560
571
|
controller.enqueue(chunk);
|
|
561
572
|
break;
|
|
562
573
|
}
|
|
563
574
|
case "text-delta": {
|
|
564
575
|
const delta = chunk;
|
|
565
|
-
currentTextId = delta.id;
|
|
566
576
|
const text = delta.delta;
|
|
567
577
|
for (let i = 0; i < text.length; i++) {
|
|
568
578
|
const ch = text.charAt(i);
|
|
@@ -573,11 +583,7 @@ function createJsonRenderTransform() {
|
|
|
573
583
|
buffering = false;
|
|
574
584
|
} else {
|
|
575
585
|
if (!inSpecFence) {
|
|
576
|
-
controller
|
|
577
|
-
type: "text-delta",
|
|
578
|
-
id: currentTextId,
|
|
579
|
-
delta: "\n"
|
|
580
|
-
});
|
|
586
|
+
emitTextDelta("\n", controller);
|
|
581
587
|
}
|
|
582
588
|
}
|
|
583
589
|
} else if (lineBuffer.length === 0 && !buffering) {
|
|
@@ -585,27 +591,22 @@ function createJsonRenderTransform() {
|
|
|
585
591
|
buffering = true;
|
|
586
592
|
lineBuffer += ch;
|
|
587
593
|
} else {
|
|
588
|
-
controller
|
|
589
|
-
type: "text-delta",
|
|
590
|
-
id: currentTextId,
|
|
591
|
-
delta: ch
|
|
592
|
-
});
|
|
594
|
+
emitTextDelta(ch, controller);
|
|
593
595
|
}
|
|
594
596
|
} else if (buffering) {
|
|
595
597
|
lineBuffer += ch;
|
|
596
598
|
} else {
|
|
597
|
-
controller
|
|
598
|
-
type: "text-delta",
|
|
599
|
-
id: currentTextId,
|
|
600
|
-
delta: ch
|
|
601
|
-
});
|
|
599
|
+
emitTextDelta(ch, controller);
|
|
602
600
|
}
|
|
603
601
|
}
|
|
604
602
|
break;
|
|
605
603
|
}
|
|
606
604
|
case "text-end": {
|
|
607
605
|
flushBuffer(controller);
|
|
608
|
-
|
|
606
|
+
if (inTextBlock) {
|
|
607
|
+
controller.enqueue({ type: "text-end", id: currentTextId });
|
|
608
|
+
inTextBlock = false;
|
|
609
|
+
}
|
|
609
610
|
break;
|
|
610
611
|
}
|
|
611
612
|
default: {
|
|
@@ -616,6 +617,7 @@ function createJsonRenderTransform() {
|
|
|
616
617
|
},
|
|
617
618
|
flush(controller) {
|
|
618
619
|
flushBuffer(controller);
|
|
620
|
+
closeTextBlock(controller);
|
|
619
621
|
}
|
|
620
622
|
});
|
|
621
623
|
}
|
|
@@ -912,7 +914,8 @@ var ActionBindingSchema = import_zod3.z.object({
|
|
|
912
914
|
params: import_zod3.z.record(import_zod3.z.string(), DynamicValueSchema).optional(),
|
|
913
915
|
confirm: ActionConfirmSchema.optional(),
|
|
914
916
|
onSuccess: ActionOnSuccessSchema.optional(),
|
|
915
|
-
onError: ActionOnErrorSchema.optional()
|
|
917
|
+
onError: ActionOnErrorSchema.optional(),
|
|
918
|
+
preventDefault: import_zod3.z.boolean().optional()
|
|
916
919
|
});
|
|
917
920
|
var ActionSchema = ActionBindingSchema;
|
|
918
921
|
function resolveAction(binding, stateModel) {
|
|
@@ -1371,6 +1374,7 @@ function defineSchema(builder, options) {
|
|
|
1371
1374
|
definition,
|
|
1372
1375
|
promptTemplate: options?.promptTemplate,
|
|
1373
1376
|
defaultRules: options?.defaultRules,
|
|
1377
|
+
builtInActions: options?.builtInActions,
|
|
1374
1378
|
createCatalog(catalog) {
|
|
1375
1379
|
return createCatalogFromSchema(this, catalog);
|
|
1376
1380
|
}
|
|
@@ -1696,11 +1700,19 @@ Note: state patches appear right after the elements that use them, so the UI fil
|
|
|
1696
1700
|
lines.push("");
|
|
1697
1701
|
}
|
|
1698
1702
|
const actions = catalog.data.actions;
|
|
1699
|
-
|
|
1703
|
+
const builtInActions = catalog.schema.builtInActions ?? [];
|
|
1704
|
+
const hasCustomActions = actions && catalog.actionNames.length > 0;
|
|
1705
|
+
const hasBuiltInActions = builtInActions.length > 0;
|
|
1706
|
+
if (hasCustomActions || hasBuiltInActions) {
|
|
1700
1707
|
lines.push("AVAILABLE ACTIONS:");
|
|
1701
1708
|
lines.push("");
|
|
1702
|
-
for (const
|
|
1703
|
-
lines.push(`- ${name}
|
|
1709
|
+
for (const action2 of builtInActions) {
|
|
1710
|
+
lines.push(`- ${action2.name}: ${action2.description} [built-in]`);
|
|
1711
|
+
}
|
|
1712
|
+
if (hasCustomActions) {
|
|
1713
|
+
for (const [name, def] of Object.entries(actions)) {
|
|
1714
|
+
lines.push(`- ${name}${def.description ? `: ${def.description}` : ""}`);
|
|
1715
|
+
}
|
|
1704
1716
|
}
|
|
1705
1717
|
lines.push("");
|
|
1706
1718
|
}
|