@assistant-ui/metro 0.0.3 → 0.0.5
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.cts.map +1 -1
- package/dist/transformer.cjs +357 -103
- package/dist/transformer.cjs.map +1 -1
- package/dist/transformer.d.cts.map +1 -1
- package/package.json +12 -10
package/dist/transformer.cjs
CHANGED
|
@@ -40,9 +40,9 @@ _babel_types = __toESM(_babel_types, 1);
|
|
|
40
40
|
const DIRECTIVE = "use generative";
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region ../x-generative-compiler/dist/package.js
|
|
43
|
-
var version = "0.0.
|
|
43
|
+
var version = "0.0.9";
|
|
44
44
|
//#endregion
|
|
45
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
45
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js
|
|
46
46
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
47
47
|
const SEMVER_SPEC_VERSION = "2.0.0";
|
|
48
48
|
const MAX_LENGTH = 256;
|
|
@@ -67,12 +67,12 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
67
67
|
};
|
|
68
68
|
}));
|
|
69
69
|
//#endregion
|
|
70
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
70
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/debug.js
|
|
71
71
|
var require_debug = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
72
72
|
module.exports = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
|
|
73
73
|
}));
|
|
74
74
|
//#endregion
|
|
75
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
75
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/re.js
|
|
76
76
|
var require_re = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
77
77
|
const { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH, MAX_LENGTH } = require_constants();
|
|
78
78
|
const debug = require_debug();
|
|
@@ -151,7 +151,7 @@ var require_re = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
151
151
|
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
|
|
152
152
|
}));
|
|
153
153
|
//#endregion
|
|
154
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
154
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/parse-options.js
|
|
155
155
|
var require_parse_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
156
156
|
const looseOption = Object.freeze({ loose: true });
|
|
157
157
|
const emptyOpts = Object.freeze({});
|
|
@@ -163,7 +163,7 @@ var require_parse_options = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
163
163
|
module.exports = parseOptions;
|
|
164
164
|
}));
|
|
165
165
|
//#endregion
|
|
166
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
166
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/identifiers.js
|
|
167
167
|
var require_identifiers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
168
168
|
const numeric = /^[0-9]+$/;
|
|
169
169
|
const compareIdentifiers = (a, b) => {
|
|
@@ -183,7 +183,7 @@ var require_identifiers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
183
183
|
};
|
|
184
184
|
}));
|
|
185
185
|
//#endregion
|
|
186
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
186
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/classes/semver.js
|
|
187
187
|
var require_semver$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
188
188
|
const debug = require_debug();
|
|
189
189
|
const { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
|
|
@@ -368,7 +368,7 @@ var require_semver$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
368
368
|
};
|
|
369
369
|
}));
|
|
370
370
|
//#endregion
|
|
371
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
371
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/parse.js
|
|
372
372
|
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
373
373
|
const SemVer = require_semver$1();
|
|
374
374
|
const parse = (version, options, throwErrors = false) => {
|
|
@@ -383,7 +383,7 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
383
383
|
module.exports = parse;
|
|
384
384
|
}));
|
|
385
385
|
//#endregion
|
|
386
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
386
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/valid.js
|
|
387
387
|
var require_valid$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
388
388
|
const parse = require_parse();
|
|
389
389
|
const valid = (version, options) => {
|
|
@@ -393,7 +393,7 @@ var require_valid$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
393
393
|
module.exports = valid;
|
|
394
394
|
}));
|
|
395
395
|
//#endregion
|
|
396
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
396
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/clean.js
|
|
397
397
|
var require_clean = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
398
398
|
const parse = require_parse();
|
|
399
399
|
const clean = (version, options) => {
|
|
@@ -403,7 +403,7 @@ var require_clean = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
403
403
|
module.exports = clean;
|
|
404
404
|
}));
|
|
405
405
|
//#endregion
|
|
406
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
406
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/inc.js
|
|
407
407
|
var require_inc = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
408
408
|
const SemVer = require_semver$1();
|
|
409
409
|
const inc = (version, release, options, identifier, identifierBase) => {
|
|
@@ -421,7 +421,7 @@ var require_inc = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
421
421
|
module.exports = inc;
|
|
422
422
|
}));
|
|
423
423
|
//#endregion
|
|
424
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
424
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/diff.js
|
|
425
425
|
var require_diff = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
426
426
|
const parse = require_parse();
|
|
427
427
|
const diff = (version1, version2) => {
|
|
@@ -449,28 +449,28 @@ var require_diff = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
449
449
|
module.exports = diff;
|
|
450
450
|
}));
|
|
451
451
|
//#endregion
|
|
452
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
452
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/major.js
|
|
453
453
|
var require_major = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
454
454
|
const SemVer = require_semver$1();
|
|
455
455
|
const major = (a, loose) => new SemVer(a, loose).major;
|
|
456
456
|
module.exports = major;
|
|
457
457
|
}));
|
|
458
458
|
//#endregion
|
|
459
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
459
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/minor.js
|
|
460
460
|
var require_minor = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
461
461
|
const SemVer = require_semver$1();
|
|
462
462
|
const minor = (a, loose) => new SemVer(a, loose).minor;
|
|
463
463
|
module.exports = minor;
|
|
464
464
|
}));
|
|
465
465
|
//#endregion
|
|
466
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
466
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/patch.js
|
|
467
467
|
var require_patch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
468
468
|
const SemVer = require_semver$1();
|
|
469
469
|
const patch = (a, loose) => new SemVer(a, loose).patch;
|
|
470
470
|
module.exports = patch;
|
|
471
471
|
}));
|
|
472
472
|
//#endregion
|
|
473
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
473
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/prerelease.js
|
|
474
474
|
var require_prerelease = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
475
475
|
const parse = require_parse();
|
|
476
476
|
const prerelease = (version, options) => {
|
|
@@ -480,28 +480,28 @@ var require_prerelease = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
480
480
|
module.exports = prerelease;
|
|
481
481
|
}));
|
|
482
482
|
//#endregion
|
|
483
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
483
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/compare.js
|
|
484
484
|
var require_compare = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
485
485
|
const SemVer = require_semver$1();
|
|
486
486
|
const compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
487
487
|
module.exports = compare;
|
|
488
488
|
}));
|
|
489
489
|
//#endregion
|
|
490
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
490
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/rcompare.js
|
|
491
491
|
var require_rcompare = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
492
492
|
const compare = require_compare();
|
|
493
493
|
const rcompare = (a, b, loose) => compare(b, a, loose);
|
|
494
494
|
module.exports = rcompare;
|
|
495
495
|
}));
|
|
496
496
|
//#endregion
|
|
497
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
497
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/compare-loose.js
|
|
498
498
|
var require_compare_loose = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
499
499
|
const compare = require_compare();
|
|
500
500
|
const compareLoose = (a, b) => compare(a, b, true);
|
|
501
501
|
module.exports = compareLoose;
|
|
502
502
|
}));
|
|
503
503
|
//#endregion
|
|
504
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
504
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/compare-build.js
|
|
505
505
|
var require_compare_build = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
506
506
|
const SemVer = require_semver$1();
|
|
507
507
|
const compareBuild = (a, b, loose) => {
|
|
@@ -512,63 +512,63 @@ var require_compare_build = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
512
512
|
module.exports = compareBuild;
|
|
513
513
|
}));
|
|
514
514
|
//#endregion
|
|
515
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
515
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/sort.js
|
|
516
516
|
var require_sort = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
517
517
|
const compareBuild = require_compare_build();
|
|
518
518
|
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
|
|
519
519
|
module.exports = sort;
|
|
520
520
|
}));
|
|
521
521
|
//#endregion
|
|
522
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
522
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/rsort.js
|
|
523
523
|
var require_rsort = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
524
524
|
const compareBuild = require_compare_build();
|
|
525
525
|
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
|
|
526
526
|
module.exports = rsort;
|
|
527
527
|
}));
|
|
528
528
|
//#endregion
|
|
529
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
529
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/gt.js
|
|
530
530
|
var require_gt = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
531
531
|
const compare = require_compare();
|
|
532
532
|
const gt = (a, b, loose) => compare(a, b, loose) > 0;
|
|
533
533
|
module.exports = gt;
|
|
534
534
|
}));
|
|
535
535
|
//#endregion
|
|
536
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
536
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/lt.js
|
|
537
537
|
var require_lt = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
538
538
|
const compare = require_compare();
|
|
539
539
|
const lt = (a, b, loose) => compare(a, b, loose) < 0;
|
|
540
540
|
module.exports = lt;
|
|
541
541
|
}));
|
|
542
542
|
//#endregion
|
|
543
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
543
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/eq.js
|
|
544
544
|
var require_eq = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
545
545
|
const compare = require_compare();
|
|
546
546
|
const eq = (a, b, loose) => compare(a, b, loose) === 0;
|
|
547
547
|
module.exports = eq;
|
|
548
548
|
}));
|
|
549
549
|
//#endregion
|
|
550
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
550
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/neq.js
|
|
551
551
|
var require_neq = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
552
552
|
const compare = require_compare();
|
|
553
553
|
const neq = (a, b, loose) => compare(a, b, loose) !== 0;
|
|
554
554
|
module.exports = neq;
|
|
555
555
|
}));
|
|
556
556
|
//#endregion
|
|
557
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
557
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/gte.js
|
|
558
558
|
var require_gte = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
559
559
|
const compare = require_compare();
|
|
560
560
|
const gte = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
561
561
|
module.exports = gte;
|
|
562
562
|
}));
|
|
563
563
|
//#endregion
|
|
564
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
564
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/lte.js
|
|
565
565
|
var require_lte = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
566
566
|
const compare = require_compare();
|
|
567
567
|
const lte = (a, b, loose) => compare(a, b, loose) <= 0;
|
|
568
568
|
module.exports = lte;
|
|
569
569
|
}));
|
|
570
570
|
//#endregion
|
|
571
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
571
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/cmp.js
|
|
572
572
|
var require_cmp = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
573
573
|
const eq = require_eq();
|
|
574
574
|
const neq = require_neq();
|
|
@@ -600,7 +600,7 @@ var require_cmp = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
600
600
|
module.exports = cmp;
|
|
601
601
|
}));
|
|
602
602
|
//#endregion
|
|
603
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
603
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/coerce.js
|
|
604
604
|
var require_coerce = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
605
605
|
const SemVer = require_semver$1();
|
|
606
606
|
const parse = require_parse();
|
|
@@ -623,12 +623,16 @@ var require_coerce = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
623
623
|
}
|
|
624
624
|
if (match === null) return null;
|
|
625
625
|
const major = match[2];
|
|
626
|
-
|
|
626
|
+
const minor = match[3] || "0";
|
|
627
|
+
const patch = match[4] || "0";
|
|
628
|
+
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
|
|
629
|
+
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
630
|
+
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
627
631
|
};
|
|
628
632
|
module.exports = coerce;
|
|
629
633
|
}));
|
|
630
634
|
//#endregion
|
|
631
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
635
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/truncate.js
|
|
632
636
|
var require_truncate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
633
637
|
const parse = require_parse();
|
|
634
638
|
const constants = require_constants();
|
|
@@ -639,7 +643,8 @@ var require_truncate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
639
643
|
return clonedVersion && doTruncation(clonedVersion, truncation);
|
|
640
644
|
};
|
|
641
645
|
const cloneInputVersion = (version, options) => {
|
|
642
|
-
|
|
646
|
+
const versionStringToParse = version instanceof SemVer ? version.version : version;
|
|
647
|
+
return parse(versionStringToParse, options);
|
|
643
648
|
};
|
|
644
649
|
const doTruncation = (version, truncation) => {
|
|
645
650
|
if (isPrerelease(truncation)) return version.version;
|
|
@@ -661,7 +666,7 @@ var require_truncate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
661
666
|
module.exports = truncate;
|
|
662
667
|
}));
|
|
663
668
|
//#endregion
|
|
664
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
669
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/lrucache.js
|
|
665
670
|
var require_lrucache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
666
671
|
var LRUCache = class {
|
|
667
672
|
constructor() {
|
|
@@ -694,7 +699,7 @@ var require_lrucache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
694
699
|
module.exports = LRUCache;
|
|
695
700
|
}));
|
|
696
701
|
//#endregion
|
|
697
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
702
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/classes/range.js
|
|
698
703
|
var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
699
704
|
const SPACE_CHARACTERS = /\s+/g;
|
|
700
705
|
module.exports = class Range {
|
|
@@ -844,12 +849,13 @@ var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
844
849
|
};
|
|
845
850
|
const replaceTilde = (comp, options) => {
|
|
846
851
|
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
852
|
+
const z = options.includePrerelease ? "-0" : "";
|
|
847
853
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
848
854
|
debug("tilde", comp, _, M, m, p, pr);
|
|
849
855
|
let ret;
|
|
850
856
|
if (isX(M)) ret = "";
|
|
851
|
-
else if (isX(m)) ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
852
|
-
else if (isX(p)) ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
857
|
+
else if (isX(m)) ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
858
|
+
else if (isX(p)) ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
853
859
|
else if (pr) {
|
|
854
860
|
debug("replaceTilde pr", pr);
|
|
855
861
|
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
@@ -970,7 +976,7 @@ var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
970
976
|
};
|
|
971
977
|
}));
|
|
972
978
|
//#endregion
|
|
973
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
979
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/classes/comparator.js
|
|
974
980
|
var require_comparator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
975
981
|
const ANY = Symbol("SemVer ANY");
|
|
976
982
|
module.exports = class Comparator {
|
|
@@ -1040,7 +1046,7 @@ var require_comparator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1040
1046
|
const Range = require_range();
|
|
1041
1047
|
}));
|
|
1042
1048
|
//#endregion
|
|
1043
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1049
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/functions/satisfies.js
|
|
1044
1050
|
var require_satisfies = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1045
1051
|
const Range = require_range();
|
|
1046
1052
|
const satisfies = (version, range, options) => {
|
|
@@ -1054,14 +1060,14 @@ var require_satisfies = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1054
1060
|
module.exports = satisfies;
|
|
1055
1061
|
}));
|
|
1056
1062
|
//#endregion
|
|
1057
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1063
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/to-comparators.js
|
|
1058
1064
|
var require_to_comparators = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1059
1065
|
const Range = require_range();
|
|
1060
1066
|
const toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
|
|
1061
1067
|
module.exports = toComparators;
|
|
1062
1068
|
}));
|
|
1063
1069
|
//#endregion
|
|
1064
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1070
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/max-satisfying.js
|
|
1065
1071
|
var require_max_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1066
1072
|
const SemVer = require_semver$1();
|
|
1067
1073
|
const Range = require_range();
|
|
@@ -1087,7 +1093,7 @@ var require_max_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1087
1093
|
module.exports = maxSatisfying;
|
|
1088
1094
|
}));
|
|
1089
1095
|
//#endregion
|
|
1090
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1096
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/min-satisfying.js
|
|
1091
1097
|
var require_min_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1092
1098
|
const SemVer = require_semver$1();
|
|
1093
1099
|
const Range = require_range();
|
|
@@ -1113,7 +1119,7 @@ var require_min_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1113
1119
|
module.exports = minSatisfying;
|
|
1114
1120
|
}));
|
|
1115
1121
|
//#endregion
|
|
1116
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1122
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/min-version.js
|
|
1117
1123
|
var require_min_version = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1118
1124
|
const SemVer = require_semver$1();
|
|
1119
1125
|
const Range = require_range();
|
|
@@ -1153,7 +1159,7 @@ var require_min_version = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1153
1159
|
module.exports = minVersion;
|
|
1154
1160
|
}));
|
|
1155
1161
|
//#endregion
|
|
1156
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1162
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/valid.js
|
|
1157
1163
|
var require_valid = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1158
1164
|
const Range = require_range();
|
|
1159
1165
|
const validRange = (range, options) => {
|
|
@@ -1166,7 +1172,7 @@ var require_valid = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1166
1172
|
module.exports = validRange;
|
|
1167
1173
|
}));
|
|
1168
1174
|
//#endregion
|
|
1169
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1175
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/outside.js
|
|
1170
1176
|
var require_outside = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1171
1177
|
const SemVer = require_semver$1();
|
|
1172
1178
|
const Comparator = require_comparator();
|
|
@@ -1219,21 +1225,21 @@ var require_outside = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1219
1225
|
module.exports = outside;
|
|
1220
1226
|
}));
|
|
1221
1227
|
//#endregion
|
|
1222
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1228
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/gtr.js
|
|
1223
1229
|
var require_gtr = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1224
1230
|
const outside = require_outside();
|
|
1225
1231
|
const gtr = (version, range, options) => outside(version, range, ">", options);
|
|
1226
1232
|
module.exports = gtr;
|
|
1227
1233
|
}));
|
|
1228
1234
|
//#endregion
|
|
1229
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1235
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/ltr.js
|
|
1230
1236
|
var require_ltr = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1231
1237
|
const outside = require_outside();
|
|
1232
1238
|
const ltr = (version, range, options) => outside(version, range, "<", options);
|
|
1233
1239
|
module.exports = ltr;
|
|
1234
1240
|
}));
|
|
1235
1241
|
//#endregion
|
|
1236
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1242
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/intersects.js
|
|
1237
1243
|
var require_intersects = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1238
1244
|
const Range = require_range();
|
|
1239
1245
|
const intersects = (r1, r2, options) => {
|
|
@@ -1244,7 +1250,7 @@ var require_intersects = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1244
1250
|
module.exports = intersects;
|
|
1245
1251
|
}));
|
|
1246
1252
|
//#endregion
|
|
1247
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1253
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/simplify.js
|
|
1248
1254
|
var require_simplify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1249
1255
|
const satisfies = require_satisfies();
|
|
1250
1256
|
const compare = require_compare();
|
|
@@ -1274,7 +1280,7 @@ var require_simplify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1274
1280
|
};
|
|
1275
1281
|
}));
|
|
1276
1282
|
//#endregion
|
|
1277
|
-
//#region ../../node_modules/.pnpm/semver@7.8.
|
|
1283
|
+
//#region ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/subset.js
|
|
1278
1284
|
var require_subset = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1279
1285
|
const Range = require_range();
|
|
1280
1286
|
const Comparator = require_comparator();
|
|
@@ -1424,6 +1430,11 @@ var import_semver = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1424
1430
|
rcompareIdentifiers: identifiers.rcompareIdentifiers
|
|
1425
1431
|
};
|
|
1426
1432
|
})))();
|
|
1433
|
+
const parserPlugins = [
|
|
1434
|
+
"typescript",
|
|
1435
|
+
"jsx",
|
|
1436
|
+
"explicitResourceManagement"
|
|
1437
|
+
];
|
|
1427
1438
|
const traverse = typeof _babel_traverse.default === "function" ? _babel_traverse.default : _babel_traverse.default.default;
|
|
1428
1439
|
const generate = typeof _babel_generator.default === "function" ? _babel_generator.default : _babel_generator.default.default;
|
|
1429
1440
|
/** The required wrapper around a toolkit's tools (stripped at build time). */
|
|
@@ -1443,16 +1454,25 @@ const DISTRIBUTION_PACKAGES = [
|
|
|
1443
1454
|
"@assistant-ui/react-native",
|
|
1444
1455
|
"@assistant-ui/react-ink"
|
|
1445
1456
|
];
|
|
1457
|
+
/** Package that exports the generative UI runtime split by export condition. */
|
|
1458
|
+
const GENERATIVE_UI_PACKAGE = "@assistant-ui/react-generative-ui";
|
|
1446
1459
|
/**
|
|
1447
1460
|
* The class whose instances expose split-by-condition tools (`present()`,
|
|
1448
1461
|
* `promptUser()`). A toolkit entry that calls a method on one of these passes
|
|
1449
1462
|
* through untouched — the library, not this compiler, routes its halves.
|
|
1450
1463
|
*/
|
|
1451
1464
|
const GENERATIVE_FACTORY = "JSONGenerativeUI";
|
|
1465
|
+
/**
|
|
1466
|
+
* The factory producing an interactable's complete tool entry. Unlike
|
|
1467
|
+
* `JSONGenerativeUI`, its package has no per-target builds, so this compiler
|
|
1468
|
+
* splits the inline config: the client keeps `render`, the server drops it.
|
|
1469
|
+
* The factory's own `execute` is internal and client-safe (frontend tool).
|
|
1470
|
+
*/
|
|
1471
|
+
const INTERACTABLE_TOOL_FACTORY = "unstable_interactableTool";
|
|
1452
1472
|
/** Thrown when a `"use generative"` file violates an authoring constraint. */
|
|
1453
1473
|
var GenerativeCompileError = class extends Error {
|
|
1454
1474
|
constructor(message, filename) {
|
|
1455
|
-
super(`[assistant-ui/
|
|
1475
|
+
super(`[assistant-ui/use-generative]${filename ? ` ${filename}:` : ""} ${message}`);
|
|
1456
1476
|
this.name = "GenerativeCompileError";
|
|
1457
1477
|
}
|
|
1458
1478
|
};
|
|
@@ -1471,7 +1491,89 @@ function isGenerativeModule(code) {
|
|
|
1471
1491
|
i = end + 2;
|
|
1472
1492
|
} else break;
|
|
1473
1493
|
}
|
|
1474
|
-
|
|
1494
|
+
const quote = code[i];
|
|
1495
|
+
if (quote !== "\"" && quote !== "'") return false;
|
|
1496
|
+
const directiveStart = i + 1;
|
|
1497
|
+
if (!code.startsWith("use generative", directiveStart)) return false;
|
|
1498
|
+
const directiveEnd = directiveStart + 14;
|
|
1499
|
+
if (code[directiveEnd] !== quote) return false;
|
|
1500
|
+
return hasDirectiveTerminator(code, directiveEnd + 1);
|
|
1501
|
+
}
|
|
1502
|
+
function hasDirectiveTerminator(code, start) {
|
|
1503
|
+
let i = start;
|
|
1504
|
+
let sawLineTerminator = false;
|
|
1505
|
+
for (;;) {
|
|
1506
|
+
if (i >= code.length) return true;
|
|
1507
|
+
const char = code.charCodeAt(i);
|
|
1508
|
+
if (isSemicolon(char)) return true;
|
|
1509
|
+
if (isLineTerminator(char)) {
|
|
1510
|
+
sawLineTerminator = true;
|
|
1511
|
+
i++;
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
if (code.startsWith("//", i)) {
|
|
1515
|
+
const lineEnd = nextLineTerminatorIndex(code, i + 2);
|
|
1516
|
+
if (lineEnd === -1) return true;
|
|
1517
|
+
sawLineTerminator = true;
|
|
1518
|
+
i = lineEnd + 1;
|
|
1519
|
+
continue;
|
|
1520
|
+
}
|
|
1521
|
+
if (code.startsWith("/*", i)) {
|
|
1522
|
+
const end = code.indexOf("*/", i + 2);
|
|
1523
|
+
if (end === -1) return false;
|
|
1524
|
+
sawLineTerminator ||= containsLineTerminator(code, i + 2, end);
|
|
1525
|
+
i = end + 2;
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
if (/\s/.test(code[i])) {
|
|
1529
|
+
i++;
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
return sawLineTerminator && !startsExpressionContinuation(code, i);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function nextLineTerminatorIndex(code, start) {
|
|
1536
|
+
for (let i = start; i < code.length; i++) if (isLineTerminator(code.charCodeAt(i))) return i;
|
|
1537
|
+
return -1;
|
|
1538
|
+
}
|
|
1539
|
+
function containsLineTerminator(code, start, end) {
|
|
1540
|
+
for (let i = start; i < end; i++) if (isLineTerminator(code.charCodeAt(i))) return true;
|
|
1541
|
+
return false;
|
|
1542
|
+
}
|
|
1543
|
+
function startsExpressionContinuation(code, start) {
|
|
1544
|
+
switch (code[start]) {
|
|
1545
|
+
case ".":
|
|
1546
|
+
case "+":
|
|
1547
|
+
case "-":
|
|
1548
|
+
case "*":
|
|
1549
|
+
case "/":
|
|
1550
|
+
case "%":
|
|
1551
|
+
case "<":
|
|
1552
|
+
case ">":
|
|
1553
|
+
case "=":
|
|
1554
|
+
case "!":
|
|
1555
|
+
case "&":
|
|
1556
|
+
case "|":
|
|
1557
|
+
case "^":
|
|
1558
|
+
case "?":
|
|
1559
|
+
case ":":
|
|
1560
|
+
case ",":
|
|
1561
|
+
case "[":
|
|
1562
|
+
case "(":
|
|
1563
|
+
case "`": return true;
|
|
1564
|
+
}
|
|
1565
|
+
return startsKeywordContinuation(code, start, "as") || startsKeywordContinuation(code, start, "in") || startsKeywordContinuation(code, start, "instanceof") || startsKeywordContinuation(code, start, "satisfies");
|
|
1566
|
+
}
|
|
1567
|
+
function startsKeywordContinuation(code, start, keyword) {
|
|
1568
|
+
if (!code.startsWith(keyword, start)) return false;
|
|
1569
|
+
const next = code[start + keyword.length];
|
|
1570
|
+
return next === void 0 || !/[\p{ID_Continue}$]/u.test(next);
|
|
1571
|
+
}
|
|
1572
|
+
function isSemicolon(char) {
|
|
1573
|
+
return char === 59;
|
|
1574
|
+
}
|
|
1575
|
+
function isLineTerminator(char) {
|
|
1576
|
+
return char === 10 || char === 13 || char === 8232 || char === 8233;
|
|
1475
1577
|
}
|
|
1476
1578
|
/**
|
|
1477
1579
|
* Rewrites a `"use generative"` module for a single build target, keeping only the
|
|
@@ -1481,17 +1583,14 @@ function compileGenerative(code, options) {
|
|
|
1481
1583
|
const { target, filename } = options;
|
|
1482
1584
|
const ast = (0, _babel_parser.parse)(code, {
|
|
1483
1585
|
sourceType: "module",
|
|
1484
|
-
plugins:
|
|
1485
|
-
"typescript",
|
|
1486
|
-
"jsx",
|
|
1487
|
-
"explicitResourceManagement"
|
|
1488
|
-
]
|
|
1586
|
+
plugins: parserPlugins
|
|
1489
1587
|
});
|
|
1490
1588
|
if (!ast.program.directives.some((d) => d.value.value === "use generative")) throw new GenerativeCompileError(`missing "${DIRECTIVE}" directive`, filename);
|
|
1491
1589
|
ensureCompilerCompatibleWithCore(ast, filename);
|
|
1492
1590
|
ensureDefaultExport(ast, filename);
|
|
1493
1591
|
const generativeInstances = collectGenerativeInstances(ast);
|
|
1494
|
-
const
|
|
1592
|
+
const interactableToolImports = collectInteractableToolImports(ast);
|
|
1593
|
+
const toolkitSpreadNames = collectToolkitSpreadNames(ast, filename, createToolkitNameContext());
|
|
1495
1594
|
const flags = {
|
|
1496
1595
|
keptRender: false,
|
|
1497
1596
|
keptBackendExecute: false
|
|
@@ -1508,7 +1607,7 @@ function compileGenerative(code, options) {
|
|
|
1508
1607
|
}
|
|
1509
1608
|
if (_babel_types.isIdentifier(callee, { name: TOOLKIT_WRAPPER })) {
|
|
1510
1609
|
if (!object) throw new GenerativeCompileError(`${TOOLKIT_WRAPPER}() takes an inline object literal of tools`, filename);
|
|
1511
|
-
compileToolkit(object, target, generativeInstances,
|
|
1610
|
+
compileToolkit(object, target, generativeInstances, interactableToolImports, toolkitSpreadNames, flags, filename);
|
|
1512
1611
|
path.replaceWith(object);
|
|
1513
1612
|
path.skip();
|
|
1514
1613
|
}
|
|
@@ -1520,7 +1619,7 @@ function compileGenerative(code, options) {
|
|
|
1520
1619
|
if (target === "server" && keptBackendExecute && (options.injectServerOnly ?? true)) ast.program.body.unshift(_babel_types.importDeclaration([], _babel_types.stringLiteral("server-only")));
|
|
1521
1620
|
const result = generate(ast, {
|
|
1522
1621
|
sourceMaps: options.sourceMaps ?? false,
|
|
1523
|
-
filename,
|
|
1622
|
+
...filename ? { filename } : {},
|
|
1524
1623
|
jsescOption: { minimal: true }
|
|
1525
1624
|
}, code);
|
|
1526
1625
|
return {
|
|
@@ -1642,6 +1741,15 @@ function unwrapToCall(node, name) {
|
|
|
1642
1741
|
return null;
|
|
1643
1742
|
}
|
|
1644
1743
|
/**
|
|
1744
|
+
* Unwraps a statement to its variable declaration through an `export` wrapper,
|
|
1745
|
+
* or returns `null`.
|
|
1746
|
+
*/
|
|
1747
|
+
function asVariableDeclaration(statement) {
|
|
1748
|
+
if (_babel_types.isVariableDeclaration(statement)) return statement;
|
|
1749
|
+
if (_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration)) return statement.declaration;
|
|
1750
|
+
return null;
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1645
1753
|
* Collects the names bound to `new JSONGenerativeUI(...)` (e.g.
|
|
1646
1754
|
* `const generative = new JSONGenerativeUI({ library })`). A toolkit entry that
|
|
1647
1755
|
* calls a method on one of these is a generative tool whose halves the library
|
|
@@ -1649,17 +1757,56 @@ function unwrapToCall(node, name) {
|
|
|
1649
1757
|
*/
|
|
1650
1758
|
function collectGenerativeInstances(ast) {
|
|
1651
1759
|
const names = /* @__PURE__ */ new Set();
|
|
1760
|
+
const generativeFactories = collectGenerativeFactoryImports(ast);
|
|
1652
1761
|
for (const statement of ast.program.body) {
|
|
1653
|
-
|
|
1654
|
-
|
|
1762
|
+
const variableDeclaration = asVariableDeclaration(statement);
|
|
1763
|
+
if (!variableDeclaration) continue;
|
|
1764
|
+
for (const declaration of variableDeclaration.declarations) {
|
|
1655
1765
|
const { id, init } = declaration;
|
|
1656
|
-
if (_babel_types.isIdentifier(id) && _babel_types.isNewExpression(init) && _babel_types.isIdentifier(init.callee
|
|
1766
|
+
if (_babel_types.isIdentifier(id) && _babel_types.isNewExpression(init) && _babel_types.isIdentifier(init.callee) && generativeFactories.has(init.callee.name)) names.add(id.name);
|
|
1657
1767
|
}
|
|
1658
1768
|
}
|
|
1659
1769
|
return names;
|
|
1660
1770
|
}
|
|
1771
|
+
function collectGenerativeFactoryImports(ast) {
|
|
1772
|
+
const names = /* @__PURE__ */ new Set();
|
|
1773
|
+
for (const statement of ast.program.body) {
|
|
1774
|
+
if (!_babel_types.isImportDeclaration(statement) || statement.source.value !== GENERATIVE_UI_PACKAGE) continue;
|
|
1775
|
+
for (const specifier of statement.specifiers) if (_babel_types.isImportSpecifier(specifier) && _babel_types.isIdentifier(specifier.imported, { name: GENERATIVE_FACTORY })) names.add(specifier.local.name);
|
|
1776
|
+
}
|
|
1777
|
+
return names;
|
|
1778
|
+
}
|
|
1661
1779
|
/**
|
|
1662
|
-
*
|
|
1780
|
+
* Collects the local names `unstable_interactableTool` is imported under from a
|
|
1781
|
+
* distribution package, so toolkit entries calling it can be recognized
|
|
1782
|
+
* (and a same-named local function can't smuggle an arbitrary call through).
|
|
1783
|
+
*/
|
|
1784
|
+
function collectInteractableToolImports(ast) {
|
|
1785
|
+
const names = /* @__PURE__ */ new Set();
|
|
1786
|
+
for (const statement of ast.program.body) {
|
|
1787
|
+
if (!_babel_types.isImportDeclaration(statement)) continue;
|
|
1788
|
+
if (!packageNameFromSpecifier(statement.source.value)) continue;
|
|
1789
|
+
for (const specifier of statement.specifiers) if (_babel_types.isImportSpecifier(specifier) && _babel_types.isIdentifier(specifier.imported, { name: INTERACTABLE_TOOL_FACTORY })) names.add(specifier.local.name);
|
|
1790
|
+
}
|
|
1791
|
+
return names;
|
|
1792
|
+
}
|
|
1793
|
+
function createToolkitNameContext() {
|
|
1794
|
+
return {
|
|
1795
|
+
importedToolkitNamesByFile: /* @__PURE__ */ new Map(),
|
|
1796
|
+
resolvingImportedToolkitNames: /* @__PURE__ */ new Set()
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* The inline config of an `unstable_interactableTool({ ... })` toolkit entry, or `null`
|
|
1801
|
+
* when the entry is some other expression.
|
|
1802
|
+
*/
|
|
1803
|
+
function interactableToolConfig(value, imports) {
|
|
1804
|
+
return _babel_types.isCallExpression(value) && _babel_types.isIdentifier(value.callee) && imports.has(value.callee.name) && _babel_types.isObjectExpression(value.arguments[0]) ? value.arguments[0] : null;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Toolkit identifiers that are safe to spread into a `defineToolkit({ ... })`,
|
|
1808
|
+
* paired with the static tool names they contain. A `null` name list means the
|
|
1809
|
+
* spread is safe, but its names are not statically known for duplicate checks.
|
|
1663
1810
|
*
|
|
1664
1811
|
* Two kinds qualify:
|
|
1665
1812
|
*
|
|
@@ -1672,30 +1819,39 @@ function collectGenerativeInstances(ast) {
|
|
|
1672
1819
|
* export crosses the generative-module boundary, so named imports don't
|
|
1673
1820
|
* qualify — they would be `undefined` once that module is build-split.
|
|
1674
1821
|
*/
|
|
1675
|
-
function
|
|
1676
|
-
const
|
|
1677
|
-
const
|
|
1822
|
+
function collectToolkitSpreadNames(ast, filename, context) {
|
|
1823
|
+
const spreadNames = /* @__PURE__ */ new Map();
|
|
1824
|
+
const localToolkitCalls = /* @__PURE__ */ new Map();
|
|
1678
1825
|
for (const statement of ast.program.body) {
|
|
1679
|
-
|
|
1680
|
-
|
|
1826
|
+
const localDeclaration = asVariableDeclaration(statement);
|
|
1827
|
+
if (localDeclaration) {
|
|
1828
|
+
for (const declaration of localDeclaration.declarations) {
|
|
1681
1829
|
const { id, init } = declaration;
|
|
1682
|
-
if (_babel_types.isIdentifier(id) && init
|
|
1830
|
+
if (_babel_types.isIdentifier(id) && init) {
|
|
1831
|
+
const toolkitCall = unwrapToToolkitCall(init);
|
|
1832
|
+
if (toolkitCall) localToolkitCalls.set(id.name, toolkitCall);
|
|
1833
|
+
}
|
|
1683
1834
|
}
|
|
1684
1835
|
continue;
|
|
1685
1836
|
}
|
|
1686
1837
|
if (_babel_types.isImportDeclaration(statement)) {
|
|
1687
1838
|
const defaultSpecifier = statement.specifiers.find((specifier) => _babel_types.isImportDefaultSpecifier(specifier));
|
|
1688
1839
|
if (!defaultSpecifier) continue;
|
|
1689
|
-
const
|
|
1690
|
-
|
|
1691
|
-
if (isGenerative === void 0) {
|
|
1692
|
-
isGenerative = isGenerativeImport(source, filename);
|
|
1693
|
-
generativeBySource.set(source, isGenerative);
|
|
1694
|
-
}
|
|
1695
|
-
if (isGenerative) names.add(defaultSpecifier.local.name);
|
|
1840
|
+
const names = getGenerativeImportToolkitNames(statement.source.value, filename, context);
|
|
1841
|
+
if (names !== void 0) spreadNames.set(defaultSpecifier.local.name, names);
|
|
1696
1842
|
}
|
|
1697
1843
|
}
|
|
1698
|
-
|
|
1844
|
+
const resolveLocal = (name) => {
|
|
1845
|
+
if (spreadNames.has(name)) return spreadNames.get(name);
|
|
1846
|
+
const call = localToolkitCalls.get(name);
|
|
1847
|
+
if (!call) return void 0;
|
|
1848
|
+
const object = _babel_types.isObjectExpression(call.arguments[0]) ? call.arguments[0] : null;
|
|
1849
|
+
const publicNames = uniqueToolkitNames(object ? collectToolkitObjectNames(object, spreadNames) : null);
|
|
1850
|
+
spreadNames.set(name, publicNames);
|
|
1851
|
+
return publicNames;
|
|
1852
|
+
};
|
|
1853
|
+
for (const name of localToolkitCalls.keys()) resolveLocal(name);
|
|
1854
|
+
return spreadNames;
|
|
1699
1855
|
}
|
|
1700
1856
|
const MODULE_EXTENSIONS = [
|
|
1701
1857
|
".ts",
|
|
@@ -1708,29 +1864,60 @@ const MODULE_EXTENSIONS = [
|
|
|
1708
1864
|
".cjs"
|
|
1709
1865
|
];
|
|
1710
1866
|
/** Extensions a specifier may carry that actually map to a TS source file. */
|
|
1711
|
-
const REWRITABLE_JS_EXTENSIONS = new Set([
|
|
1867
|
+
const REWRITABLE_JS_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1712
1868
|
".js",
|
|
1713
1869
|
".jsx",
|
|
1714
1870
|
".mjs",
|
|
1715
1871
|
".cjs"
|
|
1716
1872
|
]);
|
|
1717
1873
|
/**
|
|
1718
|
-
*
|
|
1719
|
-
* Relative specifiers and `tsconfig` path aliases
|
|
1720
|
-
* anything else (a bare package, an unresolvable
|
|
1721
|
-
* non-generative, and thus an unsafe spread.
|
|
1874
|
+
* Reads the static tool names from the default export of an imported
|
|
1875
|
+
* `"use generative"` module. Relative specifiers and `tsconfig` path aliases
|
|
1876
|
+
* (e.g. `@/tools`) are resolved; anything else (a bare package, an unresolvable
|
|
1877
|
+
* alias) is treated as non-generative, and thus an unsafe spread.
|
|
1722
1878
|
*/
|
|
1723
|
-
function
|
|
1879
|
+
function getGenerativeImportToolkitNames(source, filename, context) {
|
|
1724
1880
|
const cleanFilename = cleanAbsoluteFilename(filename);
|
|
1725
|
-
if (!cleanFilename) return
|
|
1881
|
+
if (!cleanFilename) return void 0;
|
|
1726
1882
|
const resolved = resolveImportedModuleFile(source, cleanFilename);
|
|
1727
|
-
if (!resolved) return
|
|
1883
|
+
if (!resolved) return void 0;
|
|
1884
|
+
if (context.importedToolkitNamesByFile.has(resolved)) return context.importedToolkitNamesByFile.get(resolved);
|
|
1885
|
+
if (context.resolvingImportedToolkitNames.has(resolved)) return null;
|
|
1886
|
+
let code;
|
|
1728
1887
|
try {
|
|
1729
|
-
|
|
1888
|
+
code = (0, node_fs.readFileSync)(resolved, "utf8");
|
|
1730
1889
|
} catch {
|
|
1731
|
-
|
|
1890
|
+
context.importedToolkitNamesByFile.set(resolved, void 0);
|
|
1891
|
+
return;
|
|
1892
|
+
}
|
|
1893
|
+
if (!isGenerativeModule(code)) {
|
|
1894
|
+
context.importedToolkitNamesByFile.set(resolved, void 0);
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
context.resolvingImportedToolkitNames.add(resolved);
|
|
1898
|
+
try {
|
|
1899
|
+
const names = getDefaultExportToolkitNames((0, _babel_parser.parse)(code, {
|
|
1900
|
+
sourceType: "module",
|
|
1901
|
+
plugins: parserPlugins
|
|
1902
|
+
}), resolved, context);
|
|
1903
|
+
context.importedToolkitNamesByFile.set(resolved, names);
|
|
1904
|
+
return names;
|
|
1905
|
+
} catch (error) {
|
|
1906
|
+
if (error instanceof GenerativeCompileError) throw error;
|
|
1907
|
+
context.importedToolkitNamesByFile.set(resolved, null);
|
|
1908
|
+
return null;
|
|
1909
|
+
} finally {
|
|
1910
|
+
context.resolvingImportedToolkitNames.delete(resolved);
|
|
1732
1911
|
}
|
|
1733
1912
|
}
|
|
1913
|
+
function getDefaultExportToolkitNames(ast, filename, context) {
|
|
1914
|
+
const def = ast.program.body.find((stmt) => _babel_types.isExportDefaultDeclaration(stmt));
|
|
1915
|
+
if (!def) return null;
|
|
1916
|
+
const toolkitCall = unwrapToToolkitCall(def.declaration);
|
|
1917
|
+
if (!toolkitCall || !_babel_types.isObjectExpression(toolkitCall.arguments[0])) return null;
|
|
1918
|
+
const spreadNames = collectToolkitSpreadNames(ast, filename, context);
|
|
1919
|
+
return uniqueToolkitNames(collectToolkitObjectNames(toolkitCall.arguments[0], spreadNames));
|
|
1920
|
+
}
|
|
1734
1921
|
/** Resolves an import specifier (relative or `tsconfig`-aliased) to a file on disk. */
|
|
1735
1922
|
function resolveImportedModuleFile(source, fromFilename) {
|
|
1736
1923
|
if (source.startsWith(".")) return resolveModuleFileAtPath(node_path.resolve(node_path.dirname(fromFilename), source));
|
|
@@ -1871,13 +2058,64 @@ function parseJsonc(text) {
|
|
|
1871
2058
|
function unwrapToToolkitCall(node) {
|
|
1872
2059
|
return unwrapToCall(node, TOOLKIT_WRAPPER) ?? unwrapToCall(node, MCP_TOOLKIT_WRAPPER);
|
|
1873
2060
|
}
|
|
1874
|
-
function
|
|
1875
|
-
|
|
2061
|
+
function collectToolkitObjectNames(object, toolkitSpreadNames) {
|
|
2062
|
+
const names = [];
|
|
2063
|
+
for (const entry of object.properties) {
|
|
2064
|
+
const entryNames = toolkitEntryNames(entry, toolkitSpreadNames);
|
|
2065
|
+
if (!entryNames) return null;
|
|
2066
|
+
names.push(...entryNames);
|
|
2067
|
+
}
|
|
2068
|
+
return names;
|
|
2069
|
+
}
|
|
2070
|
+
function uniqueToolkitNames(names) {
|
|
2071
|
+
return names ? [...new Set(names)] : names;
|
|
2072
|
+
}
|
|
2073
|
+
function toolkitEntryNames(entry, toolkitSpreadNames) {
|
|
2074
|
+
if (_babel_types.isSpreadElement(entry)) {
|
|
2075
|
+
if (_babel_types.isIdentifier(entry.argument)) return toolkitSpreadNames.get(entry.argument.name) ?? null;
|
|
2076
|
+
const directMcpToolkit = unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER);
|
|
2077
|
+
if (directMcpToolkit && _babel_types.isObjectExpression(directMcpToolkit.arguments[0])) return collectToolkitObjectNames(directMcpToolkit.arguments[0], toolkitSpreadNames);
|
|
2078
|
+
return null;
|
|
2079
|
+
}
|
|
2080
|
+
if (_babel_types.isObjectProperty(entry) || _babel_types.isObjectMethod(entry)) {
|
|
2081
|
+
const name = memberName(entry.key, entry.computed);
|
|
2082
|
+
return name ? [name] : [];
|
|
2083
|
+
}
|
|
2084
|
+
return [];
|
|
2085
|
+
}
|
|
2086
|
+
function warnDuplicateToolkitNames(object, toolkitSpreadNames, filename) {
|
|
2087
|
+
const names = collectToolkitObjectNames(object, toolkitSpreadNames);
|
|
2088
|
+
if (!names) return;
|
|
2089
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2090
|
+
const warned = /* @__PURE__ */ new Set();
|
|
2091
|
+
for (const name of names) {
|
|
2092
|
+
if (seen.has(name)) {
|
|
2093
|
+
if (!warned.has(name)) {
|
|
2094
|
+
console.warn(new GenerativeCompileError(`Duplicate tool name "${name}" while composing toolkits. JavaScript object spread keeps the last definition.`, filename).message);
|
|
2095
|
+
warned.add(name);
|
|
2096
|
+
}
|
|
2097
|
+
continue;
|
|
2098
|
+
}
|
|
2099
|
+
seen.add(name);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
function isSafeToolkitSpread(entry, toolkitSpreadNames) {
|
|
2103
|
+
if (_babel_types.isIdentifier(entry.argument)) return toolkitSpreadNames.has(entry.argument.name);
|
|
1876
2104
|
const directMcpToolkit = unwrapToCall(entry.argument, MCP_TOOLKIT_WRAPPER);
|
|
1877
2105
|
return !!directMcpToolkit && _babel_types.isObjectExpression(directMcpToolkit.arguments[0]);
|
|
1878
2106
|
}
|
|
2107
|
+
function genericUnsafeToolkitEntryMessage() {
|
|
2108
|
+
return "each tool must be an inline object literal (`name: { ... }`) or a compiler-visible toolkit spread / generative tool (e.g. `...defineMcpToolkit(...)`, `...baseToolkit`, `generative.present()`, or `unstable_interactableTool(...)`) so its `execute` can be routed";
|
|
2109
|
+
}
|
|
2110
|
+
function describeUnsafeToolkitEntry(entry) {
|
|
2111
|
+
if (!_babel_types.isObjectProperty(entry)) return genericUnsafeToolkitEntryMessage();
|
|
2112
|
+
const toolName = memberName(entry.key, entry.computed);
|
|
2113
|
+
const raw = entryRawValue(entry);
|
|
2114
|
+
if (!toolName || !raw) return genericUnsafeToolkitEntryMessage();
|
|
2115
|
+
return `tool "${toolName}" cannot be \`${generate(raw).code}\`; use an inline object literal (\`${toolName}: { ... }\`) or a compiler-visible toolkit spread / generative tool so its \`execute\` can be routed`;
|
|
2116
|
+
}
|
|
1879
2117
|
/** The `JSONGenerativeUI` methods that produce a split-by-condition tool. */
|
|
1880
|
-
const GENERATIVE_TOOL_METHODS = new Set(["present", "promptUser"]);
|
|
2118
|
+
const GENERATIVE_TOOL_METHODS = /* @__PURE__ */ new Set(["present", "promptUser"]);
|
|
1881
2119
|
/**
|
|
1882
2120
|
* Whether a toolkit entry's value is a call to a tool-producing method on a
|
|
1883
2121
|
* collected `JSONGenerativeUI` instance (`generative.present()`), which passes
|
|
@@ -1908,12 +2146,13 @@ function compileComponents(object, target, flags, filename) {
|
|
|
1908
2146
|
* `generative.present()` passes through, the library having already split it.
|
|
1909
2147
|
* Mutates the object in place and records outcomes in {@link TargetFlags}.
|
|
1910
2148
|
*/
|
|
1911
|
-
function compileToolkit(object, target, instances,
|
|
2149
|
+
function compileToolkit(object, target, instances, interactableToolImports, toolkitSpreadNames, flags, filename) {
|
|
2150
|
+
if (target === "client") warnDuplicateToolkitNames(object, toolkitSpreadNames, filename);
|
|
1912
2151
|
const nextProperties = [];
|
|
1913
2152
|
for (const entry of object.properties) {
|
|
1914
2153
|
const value = entryValue(entry);
|
|
1915
2154
|
if (!value) {
|
|
1916
|
-
if (_babel_types.isSpreadElement(entry) && isSafeToolkitSpread(entry,
|
|
2155
|
+
if (_babel_types.isSpreadElement(entry) && isSafeToolkitSpread(entry, toolkitSpreadNames)) {
|
|
1917
2156
|
nextProperties.push(entry);
|
|
1918
2157
|
continue;
|
|
1919
2158
|
}
|
|
@@ -1922,19 +2161,27 @@ function compileToolkit(object, target, instances, safeToolkitSpreads, flags, fi
|
|
|
1922
2161
|
nextProperties.push(entry);
|
|
1923
2162
|
continue;
|
|
1924
2163
|
}
|
|
1925
|
-
|
|
2164
|
+
const config = raw && interactableToolConfig(raw, interactableToolImports);
|
|
2165
|
+
if (config) {
|
|
2166
|
+
if (target === "client") flags.keptRender = true;
|
|
2167
|
+
else removeMember(config, "render");
|
|
2168
|
+
nextProperties.push(entry);
|
|
2169
|
+
continue;
|
|
2170
|
+
}
|
|
2171
|
+
throw new GenerativeCompileError(describeUnsafeToolkitEntry(entry), filename);
|
|
1926
2172
|
}
|
|
2173
|
+
const toolName = _babel_types.isObjectProperty(entry) ? memberName(entry.key, entry.computed) : void 0;
|
|
1927
2174
|
const execute = findMember(value, "execute");
|
|
1928
2175
|
const isStub = execute ? executeIsStubTool(execute) : false;
|
|
1929
2176
|
const isExternal = execute ? executeIsExternalTool(execute) : false;
|
|
1930
|
-
const type = inferToolType(value, filename);
|
|
2177
|
+
const type = inferToolType(value, toolName, filename);
|
|
1931
2178
|
const hasRender = !!findMember(value, "render");
|
|
1932
2179
|
const hasRenderText = !!findMember(value, "renderText");
|
|
1933
|
-
if (type === "frontend" && !hasRender && !hasRenderText) throw new GenerativeCompileError("
|
|
1934
|
-
if (type === "human" && !hasRender) throw new GenerativeCompileError("
|
|
1935
|
-
if (type === "provider" && execute) applyProviderToolConfig(value, execute, filename);
|
|
2180
|
+
if (type === "frontend" && !hasRender && !hasRenderText) throw new GenerativeCompileError(`${typedToolSubject("frontend", toolName)} must declare a \`render\` or \`renderText\` (it has no server execute to show otherwise)`, filename);
|
|
2181
|
+
if (type === "human" && !hasRender) throw new GenerativeCompileError(`${typedToolSubject("human", toolName)} must declare a \`render\` so it can collect input`, filename);
|
|
2182
|
+
if (type === "provider" && execute) applyProviderToolConfig(value, execute, toolName, filename);
|
|
1936
2183
|
if (isExternal) {
|
|
1937
|
-
if (!hasRender && !hasRenderText) throw new GenerativeCompileError("
|
|
2184
|
+
if (!hasRender && !hasRenderText) throw new GenerativeCompileError(`${typedToolSubject("external", toolName)} must declare a \`render\` or \`renderText\` (assistant-ui only renders calls for tools defined elsewhere)`, filename);
|
|
1938
2185
|
if (target === "server") continue;
|
|
1939
2186
|
stripExternalToolMetadata(value);
|
|
1940
2187
|
}
|
|
@@ -1954,7 +2201,7 @@ function compileToolkit(object, target, instances, safeToolkitSpreads, flags, fi
|
|
|
1954
2201
|
}
|
|
1955
2202
|
object.properties = nextProperties;
|
|
1956
2203
|
}
|
|
1957
|
-
function applyProviderToolConfig(object, execute, filename) {
|
|
2204
|
+
function applyProviderToolConfig(object, execute, toolName, filename) {
|
|
1958
2205
|
if (!_babel_types.isObjectProperty(execute) || !_babel_types.isCallExpression(execute.value) || execute.value.arguments.length !== 1 || !_babel_types.isObjectExpression(execute.value.arguments[0])) throw new GenerativeCompileError("`providerTool(...)` must receive an inline object literal", filename);
|
|
1959
2206
|
const existingNames = new Set(object.properties.flatMap((prop) => {
|
|
1960
2207
|
if (!_babel_types.isObjectProperty(prop) && !_babel_types.isObjectMethod(prop)) return [];
|
|
@@ -1967,7 +2214,7 @@ function applyProviderToolConfig(object, execute, filename) {
|
|
|
1967
2214
|
const name = memberName(prop.key, prop.computed);
|
|
1968
2215
|
if (!name) throw new GenerativeCompileError("`providerTool(...)` config can only contain static property names", filename);
|
|
1969
2216
|
if (_babel_types.isFunctionExpression(prop.value) || _babel_types.isArrowFunctionExpression(prop.value)) throw new GenerativeCompileError("`providerTool(...)` config cannot contain function-valued properties", filename);
|
|
1970
|
-
if (existingNames.has(name) || configNames.has(name)) throw new GenerativeCompileError(
|
|
2217
|
+
if (existingNames.has(name) || configNames.has(name)) throw new GenerativeCompileError(`\`providerTool(...)\` config${toolName ? ` for "${toolName}"` : ""} duplicates "${name}"`, filename);
|
|
1971
2218
|
configNames.add(name);
|
|
1972
2219
|
object.properties.push(prop);
|
|
1973
2220
|
}
|
|
@@ -2030,15 +2277,22 @@ function stripUseClient(member) {
|
|
|
2030
2277
|
* The loader writes the result back as a `type` field (see {@link setToolType})
|
|
2031
2278
|
* so the runtime keeps it.
|
|
2032
2279
|
*/
|
|
2033
|
-
function inferToolType(object, filename) {
|
|
2280
|
+
function inferToolType(object, toolName, filename) {
|
|
2034
2281
|
const execute = findMember(object, "execute");
|
|
2035
|
-
if (!execute) throw new GenerativeCompileError(
|
|
2282
|
+
if (!execute) throw new GenerativeCompileError(`${toolSubject(toolName)} must declare an \`execute\`; use \`humanTool()\` for a human-in-the-loop tool`, filename);
|
|
2036
2283
|
if (executeIsHumanTool(execute)) return "human";
|
|
2037
2284
|
if (executeIsProviderTool(execute)) return "provider";
|
|
2038
2285
|
if (executeIsStubTool(execute)) return "frontend";
|
|
2039
2286
|
if (executeIsExternalTool(execute)) return "backend";
|
|
2040
2287
|
return executeIsClient(execute) ? "frontend" : "backend";
|
|
2041
2288
|
}
|
|
2289
|
+
function toolSubject(toolName) {
|
|
2290
|
+
return toolName ? `tool "${toolName}"` : "every tool";
|
|
2291
|
+
}
|
|
2292
|
+
function typedToolSubject(type, toolName) {
|
|
2293
|
+
if (toolName) return `${type} tool "${toolName}"`;
|
|
2294
|
+
return `${/^[aeiou]/i.test(type) ? "an" : "a"} ${type} tool`;
|
|
2295
|
+
}
|
|
2042
2296
|
function stripExternalToolMetadata(object) {
|
|
2043
2297
|
removeMember(object, "description");
|
|
2044
2298
|
removeMember(object, "parameters");
|