@json-render/core 0.6.1 → 0.7.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/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/dist/index.mjs
CHANGED
|
@@ -402,7 +402,28 @@ function createJsonRenderTransform() {
|
|
|
402
402
|
let currentTextId = "";
|
|
403
403
|
let buffering = false;
|
|
404
404
|
let inSpecFence = false;
|
|
405
|
+
let inTextBlock = false;
|
|
406
|
+
let textIdCounter = 0;
|
|
407
|
+
function closeTextBlock(controller) {
|
|
408
|
+
if (inTextBlock) {
|
|
409
|
+
controller.enqueue({ type: "text-end", id: currentTextId });
|
|
410
|
+
inTextBlock = false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function ensureTextBlock(controller) {
|
|
414
|
+
if (!inTextBlock) {
|
|
415
|
+
textIdCounter++;
|
|
416
|
+
currentTextId = String(textIdCounter);
|
|
417
|
+
controller.enqueue({ type: "text-start", id: currentTextId });
|
|
418
|
+
inTextBlock = true;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function emitTextDelta(delta, controller) {
|
|
422
|
+
ensureTextBlock(controller);
|
|
423
|
+
controller.enqueue({ type: "text-delta", id: currentTextId, delta });
|
|
424
|
+
}
|
|
405
425
|
function emitPatch(patch, controller) {
|
|
426
|
+
closeTextBlock(controller);
|
|
406
427
|
controller.enqueue({
|
|
407
428
|
type: SPEC_DATA_PART_TYPE,
|
|
408
429
|
data: { type: "patch", patch }
|
|
@@ -425,18 +446,10 @@ function createJsonRenderTransform() {
|
|
|
425
446
|
if (patch) {
|
|
426
447
|
emitPatch(patch, controller);
|
|
427
448
|
} else {
|
|
428
|
-
controller
|
|
429
|
-
type: "text-delta",
|
|
430
|
-
id: currentTextId,
|
|
431
|
-
delta: lineBuffer
|
|
432
|
-
});
|
|
449
|
+
emitTextDelta(lineBuffer, controller);
|
|
433
450
|
}
|
|
434
451
|
} else {
|
|
435
|
-
controller
|
|
436
|
-
type: "text-delta",
|
|
437
|
-
id: currentTextId,
|
|
438
|
-
delta: lineBuffer
|
|
439
|
-
});
|
|
452
|
+
emitTextDelta(lineBuffer, controller);
|
|
440
453
|
}
|
|
441
454
|
lineBuffer = "";
|
|
442
455
|
buffering = false;
|
|
@@ -459,35 +472,32 @@ function createJsonRenderTransform() {
|
|
|
459
472
|
return;
|
|
460
473
|
}
|
|
461
474
|
if (!trimmed) {
|
|
462
|
-
controller
|
|
463
|
-
type: "text-delta",
|
|
464
|
-
id: currentTextId,
|
|
465
|
-
delta: "\n"
|
|
466
|
-
});
|
|
475
|
+
emitTextDelta("\n", controller);
|
|
467
476
|
return;
|
|
468
477
|
}
|
|
469
478
|
const patch = parseSpecStreamLine(trimmed);
|
|
470
479
|
if (patch) {
|
|
471
480
|
emitPatch(patch, controller);
|
|
472
481
|
} else {
|
|
473
|
-
controller
|
|
474
|
-
type: "text-delta",
|
|
475
|
-
id: currentTextId,
|
|
476
|
-
delta: line + "\n"
|
|
477
|
-
});
|
|
482
|
+
emitTextDelta(line + "\n", controller);
|
|
478
483
|
}
|
|
479
484
|
}
|
|
480
485
|
return new TransformStream({
|
|
481
486
|
transform(chunk, controller) {
|
|
482
487
|
switch (chunk.type) {
|
|
483
488
|
case "text-start": {
|
|
484
|
-
|
|
489
|
+
const id = chunk.id;
|
|
490
|
+
const idNum = parseInt(id, 10);
|
|
491
|
+
if (!isNaN(idNum) && idNum >= textIdCounter) {
|
|
492
|
+
textIdCounter = idNum;
|
|
493
|
+
}
|
|
494
|
+
currentTextId = id;
|
|
495
|
+
inTextBlock = true;
|
|
485
496
|
controller.enqueue(chunk);
|
|
486
497
|
break;
|
|
487
498
|
}
|
|
488
499
|
case "text-delta": {
|
|
489
500
|
const delta = chunk;
|
|
490
|
-
currentTextId = delta.id;
|
|
491
501
|
const text = delta.delta;
|
|
492
502
|
for (let i = 0; i < text.length; i++) {
|
|
493
503
|
const ch = text.charAt(i);
|
|
@@ -498,11 +508,7 @@ function createJsonRenderTransform() {
|
|
|
498
508
|
buffering = false;
|
|
499
509
|
} else {
|
|
500
510
|
if (!inSpecFence) {
|
|
501
|
-
controller
|
|
502
|
-
type: "text-delta",
|
|
503
|
-
id: currentTextId,
|
|
504
|
-
delta: "\n"
|
|
505
|
-
});
|
|
511
|
+
emitTextDelta("\n", controller);
|
|
506
512
|
}
|
|
507
513
|
}
|
|
508
514
|
} else if (lineBuffer.length === 0 && !buffering) {
|
|
@@ -510,27 +516,22 @@ function createJsonRenderTransform() {
|
|
|
510
516
|
buffering = true;
|
|
511
517
|
lineBuffer += ch;
|
|
512
518
|
} else {
|
|
513
|
-
controller
|
|
514
|
-
type: "text-delta",
|
|
515
|
-
id: currentTextId,
|
|
516
|
-
delta: ch
|
|
517
|
-
});
|
|
519
|
+
emitTextDelta(ch, controller);
|
|
518
520
|
}
|
|
519
521
|
} else if (buffering) {
|
|
520
522
|
lineBuffer += ch;
|
|
521
523
|
} else {
|
|
522
|
-
controller
|
|
523
|
-
type: "text-delta",
|
|
524
|
-
id: currentTextId,
|
|
525
|
-
delta: ch
|
|
526
|
-
});
|
|
524
|
+
emitTextDelta(ch, controller);
|
|
527
525
|
}
|
|
528
526
|
}
|
|
529
527
|
break;
|
|
530
528
|
}
|
|
531
529
|
case "text-end": {
|
|
532
530
|
flushBuffer(controller);
|
|
533
|
-
|
|
531
|
+
if (inTextBlock) {
|
|
532
|
+
controller.enqueue({ type: "text-end", id: currentTextId });
|
|
533
|
+
inTextBlock = false;
|
|
534
|
+
}
|
|
534
535
|
break;
|
|
535
536
|
}
|
|
536
537
|
default: {
|
|
@@ -541,6 +542,7 @@ function createJsonRenderTransform() {
|
|
|
541
542
|
},
|
|
542
543
|
flush(controller) {
|
|
543
544
|
flushBuffer(controller);
|
|
545
|
+
closeTextBlock(controller);
|
|
544
546
|
}
|
|
545
547
|
});
|
|
546
548
|
}
|
|
@@ -837,7 +839,8 @@ var ActionBindingSchema = z3.object({
|
|
|
837
839
|
params: z3.record(z3.string(), DynamicValueSchema).optional(),
|
|
838
840
|
confirm: ActionConfirmSchema.optional(),
|
|
839
841
|
onSuccess: ActionOnSuccessSchema.optional(),
|
|
840
|
-
onError: ActionOnErrorSchema.optional()
|
|
842
|
+
onError: ActionOnErrorSchema.optional(),
|
|
843
|
+
preventDefault: z3.boolean().optional()
|
|
841
844
|
});
|
|
842
845
|
var ActionSchema = ActionBindingSchema;
|
|
843
846
|
function resolveAction(binding, stateModel) {
|
|
@@ -1296,6 +1299,7 @@ function defineSchema(builder, options) {
|
|
|
1296
1299
|
definition,
|
|
1297
1300
|
promptTemplate: options?.promptTemplate,
|
|
1298
1301
|
defaultRules: options?.defaultRules,
|
|
1302
|
+
builtInActions: options?.builtInActions,
|
|
1299
1303
|
createCatalog(catalog) {
|
|
1300
1304
|
return createCatalogFromSchema(this, catalog);
|
|
1301
1305
|
}
|
|
@@ -1621,11 +1625,19 @@ Note: state patches appear right after the elements that use them, so the UI fil
|
|
|
1621
1625
|
lines.push("");
|
|
1622
1626
|
}
|
|
1623
1627
|
const actions = catalog.data.actions;
|
|
1624
|
-
|
|
1628
|
+
const builtInActions = catalog.schema.builtInActions ?? [];
|
|
1629
|
+
const hasCustomActions = actions && catalog.actionNames.length > 0;
|
|
1630
|
+
const hasBuiltInActions = builtInActions.length > 0;
|
|
1631
|
+
if (hasCustomActions || hasBuiltInActions) {
|
|
1625
1632
|
lines.push("AVAILABLE ACTIONS:");
|
|
1626
1633
|
lines.push("");
|
|
1627
|
-
for (const
|
|
1628
|
-
lines.push(`- ${name}
|
|
1634
|
+
for (const action2 of builtInActions) {
|
|
1635
|
+
lines.push(`- ${action2.name}: ${action2.description} [built-in]`);
|
|
1636
|
+
}
|
|
1637
|
+
if (hasCustomActions) {
|
|
1638
|
+
for (const [name, def] of Object.entries(actions)) {
|
|
1639
|
+
lines.push(`- ${name}${def.description ? `: ${def.description}` : ""}`);
|
|
1640
|
+
}
|
|
1629
1641
|
}
|
|
1630
1642
|
lines.push("");
|
|
1631
1643
|
}
|