@rasputin-ai/node 0.5.2 → 0.6.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.
Files changed (42) hide show
  1. package/README.md +4 -2
  2. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts +1 -1
  3. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
  4. package/dist/auto-instrumentation/source-map-locations.d.ts +1 -1
  5. package/dist/auto-instrumentation/source-map-locations.d.ts.map +1 -1
  6. package/dist/auto-instrumentation/transform-disk-cache.d.ts +1 -1
  7. package/dist/auto-instrumentation/transform-disk-cache.d.ts.map +1 -1
  8. package/dist/execution-recorder/automatic-runtime.d.ts +2 -33
  9. package/dist/execution-recorder/automatic-runtime.d.ts.map +1 -1
  10. package/dist/execution-recorder/encode-frozen.d.ts.map +1 -1
  11. package/dist/execution-recorder/execution-recorder-types.d.ts +3 -2
  12. package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
  13. package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
  14. package/dist/execution-recorder/function-plan.d.ts +7 -22
  15. package/dist/execution-recorder/function-plan.d.ts.map +1 -1
  16. package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
  17. package/dist/execution-recorder/value-freeze.d.ts.map +1 -1
  18. package/dist/index.js +228 -155
  19. package/dist/instrument/build.js +852 -588
  20. package/dist/instrument/bun.js +639 -373
  21. package/dist/instrument/node.js +605 -339
  22. package/dist/internal.js +225 -152
  23. package/dist/rasputin-init.d.ts +1 -0
  24. package/dist/rasputin-init.d.ts.map +1 -1
  25. package/dist/sdk-meta.d.ts +1 -1
  26. package/package.json +4 -2
  27. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts +0 -29
  28. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts.map +0 -1
  29. package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts +0 -49
  30. package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts.map +0 -1
  31. package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts +0 -3
  32. package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts.map +0 -1
  33. package/dist/auto-instrumentation/suspension-whitelist.d.ts +0 -33
  34. package/dist/auto-instrumentation/suspension-whitelist.d.ts.map +0 -1
  35. package/dist/auto-instrumentation/transform-source.d.ts +0 -27
  36. package/dist/auto-instrumentation/transform-source.d.ts.map +0 -1
  37. package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts +0 -2
  38. package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts.map +0 -1
  39. package/dist/auto-instrumentation/verify-transformed-source.d.ts +0 -2
  40. package/dist/auto-instrumentation/verify-transformed-source.d.ts.map +0 -1
  41. package/dist/execution-recorder/run-exactly-once.d.ts +0 -7
  42. package/dist/execution-recorder/run-exactly-once.d.ts.map +0 -1
@@ -9,11 +9,7 @@ import {
9
9
  sourceLocatorFromFile as sourceLocatorFromFile2
10
10
  } from "@rasputin-ai/core";
11
11
 
12
- // src/execution-recorder/function-plan.ts
13
- import {
14
- runtimeFunctionId,
15
- sourceLocatorFromFile
16
- } from "@rasputin-ai/core";
12
+ // ../recorder/src/encoded-function-plan.ts
17
13
  var withPreBodyParameterEvaluation = (plan) => [
18
14
  plan[0],
19
15
  plan[1],
@@ -24,6 +20,12 @@ var withPreBodyParameterEvaluation = (plan) => [
24
20
  plan[6],
25
21
  1
26
22
  ];
23
+
24
+ // ../recorder/src/function-plan.ts
25
+ import {
26
+ runtimeFunctionId,
27
+ sourceLocatorFromFile
28
+ } from "@rasputin-ai/core";
27
29
  var encodeFunctionPlan = (source) => {
28
30
  const locator = sourceLocatorFromFile(source.filePath);
29
31
  const definition = {
@@ -40,6 +42,9 @@ var encodeFunctionPlan = (source) => {
40
42
  ];
41
43
  };
42
44
 
45
+ // ../recorder/src/runtime-symbol.ts
46
+ var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
47
+
43
48
  // src/auto-instrumentation/instrumentation-manifest-registry.ts
44
49
  var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
45
50
  var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
@@ -180,19 +185,10 @@ import {
180
185
  import { homedir } from "node:os";
181
186
  import { dirname as dirname2, join as join2 } from "node:path";
182
187
 
183
- // src/sdk-meta.ts
184
- var SDK_VERSION = "0.5.2";
185
-
186
- // src/auto-instrumentation/transform-source.ts
187
- import { basename, resolve as resolve4 } from "node:path";
188
- import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap2 } from "@jridgewell/trace-mapping";
189
- import ts6 from "typescript";
190
-
191
- // src/execution-recorder/automatic-runtime.ts
192
- var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
193
- var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
188
+ // ../instrumentation/src/classify-function.ts
189
+ import ts4 from "typescript";
194
190
 
195
- // src/auto-instrumentation/collect-instrumentation-delta.ts
191
+ // ../instrumentation/src/collect-instrumentation-delta.ts
196
192
  import ts from "typescript";
197
193
  var paramBindingFromName = (name, sourceFile) => {
198
194
  if (ts.isIdentifier(name)) return { kind: "identifier", name: name.text };
@@ -369,41 +365,436 @@ var collectParamDestructure = (declaration, caller, context) => {
369
365
  };
370
366
  };
371
367
 
372
- // src/auto-instrumentation/parameter-initializer-may-run-code.ts
368
+ // ../instrumentation/src/parse-source.ts
373
369
  import ts2 from "typescript";
374
- var unwrap = (expression) => {
375
- let current = expression;
376
- while (ts2.isParenthesizedExpression(current) || ts2.isNonNullExpression(current)) {
377
- current = current.expression;
370
+
371
+ // ../instrumentation/src/svelte-generated.ts
372
+ import ts3 from "typescript";
373
+
374
+ // ../instrumentation/src/edits.ts
375
+ var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
376
+ var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
377
+ var separateFromPreviousToken = (source, position, text) => {
378
+ if (position <= 0 || text.length === 0) return text;
379
+ if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
380
+ return ` ${text}`;
378
381
  }
379
- return current;
382
+ return text;
380
383
  };
381
- var isSafeLiteralInitializer = (expression) => {
382
- const current = unwrap(expression);
383
- if (ts2.isNumericLiteral(current) || ts2.isStringLiteral(current) || ts2.isNoSubstitutionTemplateLiteral(current) || ts2.isBigIntLiteral(current)) {
384
- return true;
384
+ var uniqueName = (source, base) => {
385
+ let name = base;
386
+ while (source.includes(name)) name += "_";
387
+ return name;
388
+ };
389
+ var wrap = (edits, start, end, open, close, depth) => {
390
+ const width = Math.max(0, end - start);
391
+ edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
392
+ edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
393
+ };
394
+ var compareEdits = (left, right) => {
395
+ if (left.position !== right.position) return right.position - left.position;
396
+ if (left.kind !== right.kind) {
397
+ const rank = { replace: 0, close: 1, open: 2 };
398
+ return rank[left.kind] - rank[right.kind];
385
399
  }
386
- if (current.kind === ts2.SyntaxKind.TrueKeyword || current.kind === ts2.SyntaxKind.FalseKeyword || current.kind === ts2.SyntaxKind.NullKeyword) {
387
- return true;
400
+ if (left.kind === "close") {
401
+ if (left.width !== right.width) return right.width - left.width;
402
+ return left.depth - right.depth;
388
403
  }
389
- if (ts2.isIdentifier(current) && current.text === "undefined") return true;
390
- if (ts2.isPrefixUnaryExpression(current) && (current.operator === ts2.SyntaxKind.PlusToken || current.operator === ts2.SyntaxKind.MinusToken)) {
391
- return ts2.isNumericLiteral(unwrap(current.operand));
404
+ if (left.kind === "open") {
405
+ if (left.width !== right.width) return left.width - right.width;
406
+ return right.depth - left.depth;
392
407
  }
393
- return false;
408
+ return 0;
394
409
  };
395
- var functionHasPreBodyParameterEvaluation = (node) => {
396
- for (const parameter of node.parameters) {
397
- if (ts2.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
398
- if (!parameter.initializer) continue;
399
- if (!isSafeLiteralInitializer(parameter.initializer)) return true;
410
+ var applyEdits = (source, edits) => {
411
+ const ordered = [...edits].sort(compareEdits);
412
+ let transformed = source;
413
+ for (const edit of ordered) {
414
+ const text = separateFromPreviousToken(transformed, edit.position, textOf(edit));
415
+ transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
400
416
  }
401
- return false;
417
+ return transformed;
402
418
  };
419
+ var textOf = (edit) => edit.text;
403
420
 
404
- // src/auto-instrumentation/suspension-whitelist.ts
405
- import ts3 from "typescript";
406
- var nodeFlags = ts3.NodeFlags;
421
+ // ../node_modules/.bun/@jridgewell+sourcemap-codec@1.6.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
422
+ var comma = ",".charCodeAt(0);
423
+ var semicolon = ";".charCodeAt(0);
424
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
425
+ var intToChar = new Uint8Array(64);
426
+ var charToInt = new Uint8Array(128);
427
+ for (let i = 0; i < chars.length; i++) {
428
+ const c = chars.charCodeAt(i);
429
+ intToChar[i] = c;
430
+ charToInt[c] = i;
431
+ }
432
+ function encodeInteger(builder, num) {
433
+ do {
434
+ let clamped = num & 31;
435
+ num >>>= 5;
436
+ if (num > 0) clamped |= 32;
437
+ builder.write(intToChar[clamped]);
438
+ } while (num > 0);
439
+ }
440
+ function encodeSign(num) {
441
+ return num < 0 ? -num << 1 | 1 : num << 1;
442
+ }
443
+ var bufLength = 1024 * 16;
444
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
445
+ decode(buf) {
446
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
447
+ return out.toString();
448
+ }
449
+ } : {
450
+ decode(buf) {
451
+ let out = "";
452
+ for (let i = 0; i < buf.length; i++) {
453
+ out += String.fromCharCode(buf[i]);
454
+ }
455
+ return out;
456
+ }
457
+ };
458
+ var StringWriter = class {
459
+ constructor() {
460
+ this.pos = 0;
461
+ this.out = "";
462
+ this.buffer = new Uint8Array(bufLength);
463
+ }
464
+ write(v) {
465
+ const { buffer } = this;
466
+ buffer[this.pos++] = v;
467
+ if (this.pos === bufLength) {
468
+ this.out += td.decode(buffer);
469
+ this.pos = 0;
470
+ }
471
+ }
472
+ flush() {
473
+ const { buffer, out, pos } = this;
474
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
475
+ }
476
+ };
477
+ function encode(decoded) {
478
+ const writer = new StringWriter();
479
+ let sourcesIndex = 0;
480
+ let sourceLine = 0;
481
+ let sourceColumn = 0;
482
+ let namesIndex = 0;
483
+ for (let i = 0; i < decoded.length; i++) {
484
+ const line = decoded[i];
485
+ if (i > 0) writer.write(semicolon);
486
+ if (line.length === 0) continue;
487
+ let genColumn = 0;
488
+ for (let j = 0; j < line.length; j++) {
489
+ const segment = line[j];
490
+ if (j > 0) writer.write(comma);
491
+ encodeInteger(writer, encodeSign(segment[0] - genColumn));
492
+ genColumn = segment[0];
493
+ if (segment.length === 1) continue;
494
+ encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
495
+ encodeInteger(writer, encodeSign(segment[2] - sourceLine));
496
+ encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
497
+ sourcesIndex = segment[1];
498
+ sourceLine = segment[2];
499
+ sourceColumn = segment[3];
500
+ if (segment.length === 4) continue;
501
+ encodeInteger(writer, encodeSign(segment[4] - namesIndex));
502
+ namesIndex = segment[4];
503
+ }
504
+ }
505
+ return writer.flush();
506
+ }
507
+
508
+ // ../node_modules/.bun/@jridgewell+gen-mapping@0.3.13/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
509
+ import { TraceMap as TraceMap2, decodedMappings } from "@jridgewell/trace-mapping";
510
+ var SetArray = class {
511
+ constructor() {
512
+ this._indexes = { __proto__: null };
513
+ this.array = [];
514
+ }
515
+ };
516
+ function cast(set) {
517
+ return set;
518
+ }
519
+ function get(setarr, key) {
520
+ return cast(setarr)._indexes[key];
521
+ }
522
+ function put(setarr, key) {
523
+ const index = get(setarr, key);
524
+ if (index !== void 0) return index;
525
+ const { array, _indexes: indexes } = cast(setarr);
526
+ const length = array.push(key);
527
+ return indexes[key] = length - 1;
528
+ }
529
+ var COLUMN = 0;
530
+ var SOURCES_INDEX = 1;
531
+ var SOURCE_LINE = 2;
532
+ var SOURCE_COLUMN = 3;
533
+ var NAMES_INDEX = 4;
534
+ var NO_NAME = -1;
535
+ var GenMapping = class {
536
+ constructor({ file, sourceRoot } = {}) {
537
+ this._names = new SetArray();
538
+ this._sources = new SetArray();
539
+ this._sourcesContent = [];
540
+ this._mappings = [];
541
+ this.file = file;
542
+ this.sourceRoot = sourceRoot;
543
+ this._ignoreList = new SetArray();
544
+ }
545
+ };
546
+ function cast2(map) {
547
+ return map;
548
+ }
549
+ function addSegment(map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
550
+ return addSegmentInternal(
551
+ false,
552
+ map,
553
+ genLine,
554
+ genColumn,
555
+ source,
556
+ sourceLine,
557
+ sourceColumn,
558
+ name,
559
+ content
560
+ );
561
+ }
562
+ function toDecodedMap(map) {
563
+ const {
564
+ _mappings: mappings,
565
+ _sources: sources,
566
+ _sourcesContent: sourcesContent,
567
+ _names: names,
568
+ _ignoreList: ignoreList
569
+ // _originalScopes: originalScopes,
570
+ // _generatedRanges: generatedRanges,
571
+ } = cast2(map);
572
+ removeEmptyFinalLines(mappings);
573
+ return {
574
+ version: 3,
575
+ file: map.file || void 0,
576
+ names: names.array,
577
+ sourceRoot: map.sourceRoot || void 0,
578
+ sources: sources.array,
579
+ sourcesContent,
580
+ mappings,
581
+ // originalScopes,
582
+ // generatedRanges,
583
+ ignoreList: ignoreList.array
584
+ };
585
+ }
586
+ function toEncodedMap(map) {
587
+ const decoded = toDecodedMap(map);
588
+ return Object.assign({}, decoded, {
589
+ // originalScopes: decoded.originalScopes.map((os) => encodeOriginalScopes(os)),
590
+ // generatedRanges: encodeGeneratedRanges(decoded.generatedRanges as GeneratedRange[]),
591
+ mappings: encode(decoded.mappings)
592
+ });
593
+ }
594
+ function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
595
+ const {
596
+ _mappings: mappings,
597
+ _sources: sources,
598
+ _sourcesContent: sourcesContent,
599
+ _names: names
600
+ // _originalScopes: originalScopes,
601
+ } = cast2(map);
602
+ const line = getIndex(mappings, genLine);
603
+ const index = getColumnIndex(line, genColumn);
604
+ if (!source) {
605
+ if (skipable && skipSourceless(line, index)) return;
606
+ return insert(line, index, [genColumn]);
607
+ }
608
+ assert(sourceLine);
609
+ assert(sourceColumn);
610
+ const sourcesIndex = put(sources, source);
611
+ const namesIndex = name ? put(names, name) : NO_NAME;
612
+ if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
613
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
614
+ return;
615
+ }
616
+ return insert(
617
+ line,
618
+ index,
619
+ name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]
620
+ );
621
+ }
622
+ function assert(_val) {
623
+ }
624
+ function getIndex(arr, index) {
625
+ for (let i = arr.length; i <= index; i++) {
626
+ arr[i] = [];
627
+ }
628
+ return arr[index];
629
+ }
630
+ function getColumnIndex(line, genColumn) {
631
+ let index = line.length;
632
+ for (let i = index - 1; i >= 0; index = i--) {
633
+ const current = line[i];
634
+ if (genColumn >= current[COLUMN]) break;
635
+ }
636
+ return index;
637
+ }
638
+ function insert(array, index, value) {
639
+ for (let i = array.length; i > index; i--) {
640
+ array[i] = array[i - 1];
641
+ }
642
+ array[index] = value;
643
+ }
644
+ function removeEmptyFinalLines(mappings) {
645
+ const { length } = mappings;
646
+ let len = length;
647
+ for (let i = len - 1; i >= 0; len = i, i--) {
648
+ if (mappings[i].length > 0) break;
649
+ }
650
+ if (len < length) mappings.length = len;
651
+ }
652
+ function skipSourceless(line, index) {
653
+ if (index === 0) return true;
654
+ const prev = line[index - 1];
655
+ return prev.length === 1;
656
+ }
657
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
658
+ if (index === 0) return false;
659
+ const prev = line[index - 1];
660
+ if (prev.length === 1) return false;
661
+ return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
662
+ }
663
+
664
+ // ../instrumentation/src/exact-transform-map.ts
665
+ import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
666
+ var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
667
+ var decodeInlineSourceMap = (url) => {
668
+ const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
669
+ if (base64?.[1]) {
670
+ try {
671
+ return Buffer.from(base64[1], "base64").toString("utf8");
672
+ } catch {
673
+ return void 0;
674
+ }
675
+ }
676
+ const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
677
+ if (!raw?.[1]) return void 0;
678
+ try {
679
+ return decodeURIComponent(raw[1]);
680
+ } catch {
681
+ return void 0;
682
+ }
683
+ };
684
+ var upstreamTraceMap = (original) => {
685
+ const match = SOURCEMAP_COMMENT.exec(original);
686
+ const url = match?.[1] ?? match?.[2];
687
+ if (!url) return void 0;
688
+ const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
689
+ if (!payload) return void 0;
690
+ try {
691
+ return new TraceMap3(payload);
692
+ } catch {
693
+ return void 0;
694
+ }
695
+ };
696
+ var lineStartsOf = (text) => {
697
+ const starts = [0];
698
+ for (let index = 0; index < text.length; index++) {
699
+ if (text[index] === "\n") starts.push(index + 1);
700
+ }
701
+ return starts;
702
+ };
703
+ var positionAt = (starts, offset) => {
704
+ let low = 0;
705
+ let high = starts.length - 1;
706
+ while (low < high) {
707
+ const mid = low + high + 1 >> 1;
708
+ if ((starts[mid] ?? 0) <= offset) low = mid;
709
+ else high = mid - 1;
710
+ }
711
+ return { line: low, column: offset - (starts[low] ?? 0) };
712
+ };
713
+ var sortedEdits = (edits) => [...edits].sort(compareEdits);
714
+ var originalOffsetToGenerated = (originalOffset, edits) => {
715
+ let generated = originalOffset;
716
+ for (const edit of edits) {
717
+ const delta = edit.text.length - edit.deleteCount;
718
+ if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
719
+ else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
720
+ }
721
+ return generated;
722
+ };
723
+ var mappingOffsets = (original, edits) => {
724
+ const offsets = /* @__PURE__ */ new Set([0, original.length]);
725
+ for (const start of lineStartsOf(original)) offsets.add(start);
726
+ for (const edit of edits) {
727
+ offsets.add(edit.position);
728
+ offsets.add(edit.position + edit.deleteCount);
729
+ }
730
+ return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
731
+ };
732
+ var encodeColumnMappings = (original, generated, file, edits) => {
733
+ const upstream = upstreamTraceMap(original);
734
+ const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
735
+ if (sources.length === 0) sources.push(file);
736
+ const applied = sortedEdits(edits);
737
+ const originalStarts = lineStartsOf(original);
738
+ const generatedStarts = lineStartsOf(generated);
739
+ const map = new GenMapping({ file });
740
+ const seen = /* @__PURE__ */ new Set();
741
+ for (const originalOffset of mappingOffsets(original, edits)) {
742
+ const generatedOffset = Math.min(
743
+ originalOffsetToGenerated(originalOffset, applied),
744
+ generated.length
745
+ );
746
+ const originalPosition = positionAt(originalStarts, originalOffset);
747
+ const generatedPosition = positionAt(generatedStarts, generatedOffset);
748
+ let source = sources[0] ?? file;
749
+ let mappedLine = originalPosition.line;
750
+ let mappedColumn = originalPosition.column;
751
+ if (upstream) {
752
+ const mapped = originalPositionFor2(upstream, {
753
+ line: originalPosition.line + 1,
754
+ column: originalPosition.column
755
+ });
756
+ if (mapped.source && mapped.line != null && mapped.column != null) {
757
+ source = mapped.source;
758
+ mappedLine = mapped.line - 1;
759
+ mappedColumn = mapped.column;
760
+ }
761
+ }
762
+ const key = `${generatedPosition.line}:${generatedPosition.column}`;
763
+ if (seen.has(key)) continue;
764
+ seen.add(key);
765
+ addSegment(
766
+ map,
767
+ generatedPosition.line,
768
+ generatedPosition.column,
769
+ source,
770
+ mappedLine,
771
+ mappedColumn
772
+ );
773
+ }
774
+ const encoded = toEncodedMap(map);
775
+ return {
776
+ sources: encoded.sources.filter((source) => Boolean(source)),
777
+ mappings: encoded.mappings
778
+ };
779
+ };
780
+ var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) => {
781
+ const file = basenameOf(filePath);
782
+ const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
783
+ const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
784
+ const comment = `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
785
+ JSON.stringify({ version: 3, file, sources, mappings })
786
+ ).toString("base64")} */`;
787
+ return withoutUpstream.endsWith("\n") ? `${withoutUpstream.slice(0, -1)}${comment}
788
+ ` : `${withoutUpstream}${comment}`;
789
+ };
790
+
791
+ // ../instrumentation/src/browser-function-edits.ts
792
+ import { propertyNameIsSensitive } from "@rasputin-ai/core";
793
+ import ts10 from "typescript";
794
+
795
+ // ../instrumentation/src/suspension-whitelist.ts
796
+ import ts5 from "typescript";
797
+ var nodeFlags = ts5.NodeFlags;
407
798
  var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
408
799
  var USING_FLAG = nodeFlags.Using ?? 0;
409
800
  var KNOWN_SUSPENSION_KIND_NAMES = [
@@ -413,8 +804,8 @@ var KNOWN_SUSPENSION_KIND_NAMES = [
413
804
  "YieldKeyword",
414
805
  "UsingKeyword"
415
806
  ];
416
- var isFunctionLike = (node) => ts3.isFunctionLike(node);
417
- var isAsyncFunctionLike = (node) => (ts3.getCombinedModifierFlags(node) & ts3.ModifierFlags.Async) !== 0;
807
+ var isFunctionLike = (node) => ts5.isFunctionLike(node);
808
+ var isAsyncFunctionLike = (node) => (ts5.getCombinedModifierFlags(node) & ts5.ModifierFlags.Async) !== 0;
418
809
  var isAsyncGeneratorLike = (node) => isFunctionLike(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
419
810
  var isSyncGeneratorLike = (node) => isFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken) && !isAsyncFunctionLike(node);
420
811
  var visitOwnBody = (node, visitNode) => {
@@ -425,7 +816,7 @@ var visitOwnBody = (node, visitNode) => {
425
816
  return;
426
817
  }
427
818
  if (visitNode(candidate)) return;
428
- ts3.forEachChild(candidate, visit);
819
+ ts5.forEachChild(candidate, visit);
429
820
  };
430
821
  visit(node.body);
431
822
  };
@@ -453,16 +844,16 @@ var slicesOutside = (start, end, spans) => {
453
844
  };
454
845
  var sliceHasAwaitKeyword = (source, start, end) => {
455
846
  if (end <= start) return false;
456
- const scanner = ts3.createScanner(
457
- ts3.ScriptTarget.Latest,
847
+ const scanner = ts5.createScanner(
848
+ ts5.ScriptTarget.Latest,
458
849
  true,
459
- ts3.LanguageVariant.Standard,
850
+ ts5.LanguageVariant.Standard,
460
851
  source.slice(start, end)
461
852
  );
462
853
  while (true) {
463
854
  const token = scanner.scan();
464
- if (token === ts3.SyntaxKind.EndOfFileToken) return false;
465
- if (token === ts3.SyntaxKind.AwaitKeyword) return true;
855
+ if (token === ts5.SyntaxKind.EndOfFileToken) return false;
856
+ if (token === ts5.SyntaxKind.AwaitKeyword) return true;
466
857
  }
467
858
  };
468
859
  var ownBodyHasAwaitKeyword = (node, sourceFile) => {
@@ -480,7 +871,7 @@ var isAwaitUsingList = (node) => {
480
871
  return (node.flags & AWAIT_USING_FLAG) === AWAIT_USING_FLAG && (node.flags & USING_FLAG) !== 0;
481
872
  };
482
873
  var unknownSuspensionKind = (node) => {
483
- const name = ts3.SyntaxKind[node.kind];
874
+ const name = ts5.SyntaxKind[node.kind];
484
875
  if (typeof name !== "string" || !/Await|Yield|Using/.test(name)) return false;
485
876
  return !KNOWN_SUSPENSION_KIND_NAMES.includes(name);
486
877
  };
@@ -493,9 +884,9 @@ var ownSuspensionFacts = (node, sourceFile) => {
493
884
  awaitKeyword: ownBodyHasAwaitKeyword(node, sourceFile)
494
885
  };
495
886
  visitOwnBody(node, (candidate) => {
496
- if (ts3.isAwaitExpression(candidate)) facts.awaitExpressions = true;
497
- if (ts3.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
498
- if (ts3.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
887
+ if (ts5.isAwaitExpression(candidate)) facts.awaitExpressions = true;
888
+ if (ts5.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
889
+ if (ts5.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
499
890
  facts.awaitUsing = true;
500
891
  }
501
892
  if (unknownSuspensionKind(candidate)) facts.unknown = true;
@@ -506,7 +897,7 @@ var ownSuspensionFacts = (node, sourceFile) => {
506
897
  var bodyHasDirectEval = (node) => {
507
898
  let found = false;
508
899
  visitOwnBody(node, (candidate) => {
509
- if (ts3.isCallExpression(candidate) && ts3.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
900
+ if (ts5.isCallExpression(candidate) && ts5.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
510
901
  found = true;
511
902
  }
512
903
  return found;
@@ -528,25 +919,61 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
528
919
  return { action: "inline" };
529
920
  };
530
921
 
531
- // src/auto-instrumentation/verify-instrumentation-isomorphism.ts
532
- import ts4 from "typescript";
922
+ // ../instrumentation/src/transform-source.ts
923
+ import { basename, resolve as resolve4 } from "node:path";
924
+ import ts9 from "typescript";
925
+
926
+ // ../instrumentation/src/parameter-initializer-may-run-code.ts
927
+ import ts6 from "typescript";
928
+ var unwrap = (expression) => {
929
+ let current = expression;
930
+ while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
931
+ current = current.expression;
932
+ }
933
+ return current;
934
+ };
935
+ var isSafeLiteralInitializer = (expression) => {
936
+ const current = unwrap(expression);
937
+ if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
938
+ return true;
939
+ }
940
+ if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
941
+ return true;
942
+ }
943
+ if (ts6.isIdentifier(current) && current.text === "undefined") return true;
944
+ if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
945
+ return ts6.isNumericLiteral(unwrap(current.operand));
946
+ }
947
+ return false;
948
+ };
949
+ var functionHasPreBodyParameterEvaluation = (node) => {
950
+ for (const parameter of node.parameters) {
951
+ if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
952
+ if (!parameter.initializer) continue;
953
+ if (!isSafeLiteralInitializer(parameter.initializer)) return true;
954
+ }
955
+ return false;
956
+ };
957
+
958
+ // ../instrumentation/src/verify-instrumentation-isomorphism.ts
959
+ import ts7 from "typescript";
533
960
  var RASPUTIN_IDENT = /^__rasputin/;
534
961
  var scriptKindFor = (filePath) => {
535
- if (/\.tsx$/i.test(filePath)) return ts4.ScriptKind.TSX;
536
- if (/\.jsx$/i.test(filePath)) return ts4.ScriptKind.JSX;
537
- if (/\.[cm]?ts$/i.test(filePath)) return ts4.ScriptKind.TS;
538
- return ts4.ScriptKind.JS;
962
+ if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
963
+ if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
964
+ if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
965
+ return ts7.ScriptKind.JS;
539
966
  };
540
- var parse = (filePath, source) => ts4.createSourceFile(filePath, source, ts4.ScriptTarget.Latest, true, scriptKindFor(filePath));
967
+ var parse = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor(filePath));
541
968
  var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
542
969
  var identText = (node) => {
543
- if (ts4.isIdentifier(node)) return node.text;
544
- if (ts4.isPrivateIdentifier(node)) return node.text;
970
+ if (ts7.isIdentifier(node)) return node.text;
971
+ if (ts7.isPrivateIdentifier(node)) return node.text;
545
972
  return void 0;
546
973
  };
547
974
  var calleeName = (expression) => {
548
- if (ts4.isIdentifier(expression)) return expression.text;
549
- if (ts4.isPropertyAccessExpression(expression)) {
975
+ if (ts7.isIdentifier(expression)) return expression.text;
976
+ if (ts7.isPropertyAccessExpression(expression)) {
550
977
  const object = identText(expression.expression);
551
978
  const property = identText(expression.name);
552
979
  if (object && isRasputinName(object) && property) return `${object}.${property}`;
@@ -554,7 +981,7 @@ var calleeName = (expression) => {
554
981
  return void 0;
555
982
  };
556
983
  var isRasputinCall = (node, methods) => {
557
- if (!ts4.isCallExpression(node)) return false;
984
+ if (!ts7.isCallExpression(node)) return false;
558
985
  const name = calleeName(node.expression);
559
986
  if (!name) return false;
560
987
  if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
@@ -564,20 +991,20 @@ var unwrapCall = (node) => {
564
991
  let current = node;
565
992
  while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
566
993
  current = current.arguments[0];
567
- if (ts4.isParenthesizedExpression(current)) current = current.expression;
994
+ if (ts7.isParenthesizedExpression(current)) current = current.expression;
568
995
  }
569
- if (ts4.isParenthesizedExpression(current)) return current.expression;
996
+ if (ts7.isParenthesizedExpression(current)) return current.expression;
570
997
  return current;
571
998
  };
572
999
  var isRasputinStatement = (node) => {
573
- if (ts4.isEmptyStatement(node)) return true;
574
- if (ts4.isVariableStatement(node)) {
1000
+ if (ts7.isEmptyStatement(node)) return true;
1001
+ if (ts7.isVariableStatement(node)) {
575
1002
  return node.declarationList.declarations.every((declaration) => {
576
1003
  const name = identText(declaration.name);
577
1004
  return Boolean(name && isRasputinName(name));
578
1005
  });
579
1006
  }
580
- if (ts4.isExpressionStatement(node)) {
1007
+ if (ts7.isExpressionStatement(node)) {
581
1008
  if (!isRasputinCall(node.expression)) return false;
582
1009
  const unwrapped = unwrapCall(node.expression);
583
1010
  return unwrapped === node.expression;
@@ -591,7 +1018,7 @@ var isRasputinTryWrapper = (node) => {
591
1018
  (statement) => !isRasputinStatement(statement)
592
1019
  );
593
1020
  const leftover = catchCalls[0];
594
- const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts4.isThrowStatement(leftover) && ts4.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
1021
+ const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
595
1022
  if (!leftoverThrow && catchCalls.length > 0) return false;
596
1023
  return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
597
1024
  };
@@ -599,7 +1026,7 @@ var flattenStatements = (statements) => {
599
1026
  const flattened = [];
600
1027
  for (const statement of statements) {
601
1028
  if (isRasputinStatement(statement)) continue;
602
- if (ts4.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
1029
+ if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
603
1030
  flattened.push(...flattenStatements(statement.tryBlock.statements));
604
1031
  continue;
605
1032
  }
@@ -608,38 +1035,38 @@ var flattenStatements = (statements) => {
608
1035
  return flattened;
609
1036
  };
610
1037
  var extra = (node) => {
611
- if (ts4.isIdentifier(node) || ts4.isPrivateIdentifier(node)) {
1038
+ if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
612
1039
  return isRasputinName(node.text) ? "" : node.text;
613
1040
  }
614
- if (ts4.isStringLiteral(node) || ts4.isNumericLiteral(node) || ts4.isNoSubstitutionTemplateLiteral(node)) {
1041
+ if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
615
1042
  return node.text;
616
1043
  }
617
- if (ts4.isToken(node) && !ts4.isIdentifier(node)) return ts4.SyntaxKind[node.kind] ?? "";
1044
+ if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
618
1045
  return "";
619
1046
  };
620
1047
  var signatureOf = (node) => {
621
1048
  const unwrapped = unwrapCall(node);
622
1049
  if (unwrapped !== node) return signatureOf(unwrapped);
623
- if (ts4.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
624
- if (ts4.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
1050
+ if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
1051
+ if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
625
1052
  return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
626
1053
  }
627
- if (ts4.isBlock(unwrapped)) {
1054
+ if (ts7.isBlock(unwrapped)) {
628
1055
  const statements = flattenStatements(unwrapped.statements);
629
1056
  return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
630
1057
  }
631
- if (ts4.isCatchClause(unwrapped)) {
1058
+ if (ts7.isCatchClause(unwrapped)) {
632
1059
  const statements = flattenStatements(unwrapped.block.statements);
633
1060
  const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
634
1061
  return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
635
1062
  }
636
- if (ts4.isArrowFunction(unwrapped) && ts4.isBlock(unwrapped.body)) {
1063
+ if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
637
1064
  const statements = flattenStatements(unwrapped.body.statements);
638
1065
  const only = statements[0];
639
- if (statements.length === 1 && only && ts4.isReturnStatement(only) && only.expression) {
1066
+ if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
640
1067
  const expression = only.expression;
641
1068
  const parts2 = [];
642
- ts4.forEachChild(unwrapped, (child) => {
1069
+ ts7.forEachChild(unwrapped, (child) => {
643
1070
  if (child === unwrapped.body) {
644
1071
  const part2 = signatureOf(expression);
645
1072
  if (part2) parts2.push(part2);
@@ -652,11 +1079,11 @@ var signatureOf = (node) => {
652
1079
  }
653
1080
  }
654
1081
  const parts = [];
655
- ts4.forEachChild(unwrapped, (child) => {
1082
+ ts7.forEachChild(unwrapped, (child) => {
656
1083
  const part = signatureOf(child);
657
1084
  if (part) parts.push(part);
658
1085
  });
659
- const kind = ts4.SyntaxKind[unwrapped.kind] ?? "Node";
1086
+ const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
660
1087
  const label = extra(unwrapped);
661
1088
  return `${kind}${label}[${parts.join(",")}]`;
662
1089
  };
@@ -664,15 +1091,15 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
664
1091
  return signatureOf(parse(filePath, original)) === signatureOf(parse(filePath, transformed));
665
1092
  };
666
1093
 
667
- // src/auto-instrumentation/verify-transformed-source.ts
668
- import ts5 from "typescript";
669
- var transpileForVerification = (filePath, code) => ts5.transpileModule(code, {
1094
+ // ../instrumentation/src/verify-transformed-source.ts
1095
+ import ts8 from "typescript";
1096
+ var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
670
1097
  compilerOptions: {
671
1098
  // ES2020 downlevel keeps native @decorators out of `new Function`.
672
- target: ts5.ScriptTarget.ES2020,
673
- module: ts5.ModuleKind.ESNext,
1099
+ target: ts8.ScriptTarget.ES2020,
1100
+ module: ts8.ModuleKind.ESNext,
674
1101
  allowJs: true,
675
- jsx: ts5.JsxEmit.React,
1102
+ jsx: ts8.JsxEmit.React,
676
1103
  experimentalDecorators: true
677
1104
  },
678
1105
  reportDiagnostics: true,
@@ -680,7 +1107,7 @@ var transpileForVerification = (filePath, code) => ts5.transpileModule(code, {
680
1107
  });
681
1108
  var hasScanOrParseError = (diagnostics) => Boolean(
682
1109
  diagnostics?.some(
683
- (diagnostic) => diagnostic.category === ts5.DiagnosticCategory.Error && diagnostic.code < 2e3
1110
+ (diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
684
1111
  )
685
1112
  );
686
1113
  var scriptBodyForEngine = (emitted) => (
@@ -689,39 +1116,39 @@ var scriptBodyForEngine = (emitted) => (
689
1116
  );
690
1117
  var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
691
1118
  var scriptKindFor2 = (filePath) => {
692
- if (/\.tsx$/i.test(filePath)) return ts5.ScriptKind.TSX;
693
- if (/\.jsx$/i.test(filePath)) return ts5.ScriptKind.JSX;
694
- if (/\.[cm]?ts$/i.test(filePath)) return ts5.ScriptKind.TS;
695
- return ts5.ScriptKind.JS;
1119
+ if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
1120
+ if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
1121
+ if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
1122
+ return ts8.ScriptKind.JS;
696
1123
  };
697
- var isIterationStatement = (node) => ts5.isForStatement(node) || ts5.isForOfStatement(node) || ts5.isForInStatement(node) || ts5.isWhileStatement(node) || ts5.isDoStatement(node);
1124
+ var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
698
1125
  var unwrapLabeled = (node) => {
699
1126
  let current = node;
700
- while (ts5.isLabeledStatement(current)) current = current.statement;
1127
+ while (ts8.isLabeledStatement(current)) current = current.statement;
701
1128
  return current;
702
1129
  };
703
1130
  var hasInvalidLabelJump = (sourceFile) => {
704
1131
  const visit = (node, labels) => {
705
- if (ts5.isFunctionLike(node)) {
1132
+ if (ts8.isFunctionLike(node)) {
706
1133
  let nestedInvalid = false;
707
- ts5.forEachChild(node, (child) => {
1134
+ ts8.forEachChild(node, (child) => {
708
1135
  if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
709
1136
  });
710
1137
  return nestedInvalid;
711
1138
  }
712
- if (ts5.isLabeledStatement(node)) {
1139
+ if (ts8.isLabeledStatement(node)) {
713
1140
  const next = new Map(labels);
714
1141
  next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
715
1142
  return visit(node.statement, next);
716
1143
  }
717
- if (ts5.isContinueStatement(node) && node.label) {
1144
+ if (ts8.isContinueStatement(node) && node.label) {
718
1145
  if (labels.get(node.label.text) !== true) return true;
719
1146
  }
720
- if (ts5.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
1147
+ if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
721
1148
  return true;
722
1149
  }
723
1150
  let invalid = false;
724
- ts5.forEachChild(node, (child) => {
1151
+ ts8.forEachChild(node, (child) => {
725
1152
  if (visit(child, labels)) invalid = true;
726
1153
  });
727
1154
  return invalid;
@@ -764,10 +1191,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
764
1191
  var transformedSourceIsInvalid = (filePath, code) => {
765
1192
  if (GLUED_INSTRUMENTATION.test(code)) return true;
766
1193
  if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
767
- const sourceFile = ts5.createSourceFile(
1194
+ const sourceFile = ts8.createSourceFile(
768
1195
  filePath,
769
1196
  code,
770
- ts5.ScriptTarget.Latest,
1197
+ ts8.ScriptTarget.Latest,
771
1198
  true,
772
1199
  scriptKindFor2(filePath)
773
1200
  );
@@ -779,16 +1206,7 @@ var transformedSourceIsInvalid = (filePath, code) => {
779
1206
  return !engineAccepts(scriptBodyForEngine(outputText));
780
1207
  };
781
1208
 
782
- // src/auto-instrumentation/transform-source.ts
783
- var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
784
- var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
785
- var separateFromPreviousToken = (source, position, text) => {
786
- if (position <= 0 || text.length === 0) return text;
787
- if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
788
- return ` ${text}`;
789
- }
790
- return text;
791
- };
1209
+ // ../instrumentation/src/transform-source.ts
792
1210
  var RASPUTIN_INSTRUMENTATION_MARKER = "rasputin.instrumented.v3";
793
1211
  var RASPUTIN_INSTRUMENTATION_PREAMBLE = `/*${RASPUTIN_INSTRUMENTATION_MARKER}*/`;
794
1212
  var sourceIsRasputinInstrumented = (source) => source.includes(RASPUTIN_INSTRUMENTATION_PREAMBLE);
@@ -797,25 +1215,25 @@ var alreadyInstrumentedResult = (source) => ({
797
1215
  delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
798
1216
  });
799
1217
  var scriptKindFor3 = (filePath) => {
800
- if (/\.tsx$/i.test(filePath)) return ts6.ScriptKind.TSX;
801
- if (/\.jsx$/i.test(filePath)) return ts6.ScriptKind.JSX;
802
- if (/\.[cm]?ts$/i.test(filePath)) return ts6.ScriptKind.TS;
803
- return ts6.ScriptKind.JS;
1218
+ if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
1219
+ if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
1220
+ if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
1221
+ return ts9.ScriptKind.JS;
804
1222
  };
805
1223
  var functionName = (node, sourceFile) => {
806
- if (ts6.isConstructorDeclaration(node)) return "constructor";
1224
+ if (ts9.isConstructorDeclaration(node)) return "constructor";
807
1225
  if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
808
1226
  const parent = node.parent;
809
- if (ts6.isVariableDeclaration(parent) && ts6.isIdentifier(parent.name)) return parent.name.text;
810
- if (ts6.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
811
- if (ts6.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
1227
+ if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
1228
+ if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
1229
+ if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
812
1230
  const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
813
1231
  return `anonymous@${location.line + 1}:${location.character + 1}`;
814
1232
  };
815
1233
  var functionLocationPosition = (node, sourceFile) => {
816
1234
  if (node.name) return node.name.getStart(sourceFile);
817
1235
  const parent = node.parent;
818
- if ((ts6.isVariableDeclaration(parent) || ts6.isPropertyAssignment(parent)) && parent.name) {
1236
+ if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
819
1237
  return parent.name.getStart(sourceFile);
820
1238
  }
821
1239
  return node.getStart(sourceFile);
@@ -828,12 +1246,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
828
1246
  }
829
1247
  return end;
830
1248
  };
831
- var isStaticPropertyName = (name) => ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNoSubstitutionTemplateLiteral(name) || ts6.isNumericLiteral(name);
1249
+ var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
832
1250
  var canReconstructBinding = (name) => {
833
- if (ts6.isIdentifier(name)) return true;
834
- if (ts6.isArrayBindingPattern(name)) {
1251
+ if (ts9.isIdentifier(name)) return true;
1252
+ if (ts9.isArrayBindingPattern(name)) {
835
1253
  return name.elements.every(
836
- (element) => ts6.isOmittedExpression(element) || canReconstructBinding(element.name)
1254
+ (element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
837
1255
  );
838
1256
  }
839
1257
  return name.elements.every((element) => {
@@ -842,10 +1260,10 @@ var canReconstructBinding = (name) => {
842
1260
  });
843
1261
  };
844
1262
  var bindingValue = (name, sourceFile) => {
845
- if (ts6.isIdentifier(name)) return name.text;
846
- if (ts6.isArrayBindingPattern(name)) {
1263
+ if (ts9.isIdentifier(name)) return name.text;
1264
+ if (ts9.isArrayBindingPattern(name)) {
847
1265
  const values = name.elements.map((element) => {
848
- if (ts6.isOmittedExpression(element)) return "";
1266
+ if (ts9.isOmittedExpression(element)) return "";
849
1267
  const value = bindingValue(element.name, sourceFile);
850
1268
  return element.dotDotDotToken ? `...${value}` : value;
851
1269
  });
@@ -855,7 +1273,7 @@ var bindingValue = (name, sourceFile) => {
855
1273
  const value = bindingValue(element.name, sourceFile);
856
1274
  if (element.dotDotDotToken) return `...${value}`;
857
1275
  if (!element.propertyName) return value;
858
- const key = ts6.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
1276
+ const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
859
1277
  return `${key}:${value}`;
860
1278
  });
861
1279
  return `{${properties.join(",")}}`;
@@ -863,7 +1281,7 @@ var bindingValue = (name, sourceFile) => {
863
1281
  var arrowArgsCapture = (node) => {
864
1282
  const sourceFile = node.getSourceFile();
865
1283
  const params = node.parameters.filter(
866
- (parameter) => !(ts6.isIdentifier(parameter.name) && parameter.name.text === "this")
1284
+ (parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
867
1285
  );
868
1286
  if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
869
1287
  return {
@@ -878,18 +1296,13 @@ var arrowArgsCapture = (node) => {
878
1296
  return { args: `[${values.join(",")}]`, omitValues: false };
879
1297
  };
880
1298
  var isSupportedFunction = (node) => {
881
- if (!ts6.isFunctionDeclaration(node) && !ts6.isFunctionExpression(node) && !ts6.isArrowFunction(node) && !ts6.isMethodDeclaration(node) && !ts6.isGetAccessorDeclaration(node) && !ts6.isSetAccessorDeclaration(node)) {
1299
+ if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
882
1300
  return false;
883
1301
  }
884
1302
  if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
885
1303
  return true;
886
1304
  };
887
- var uniqueName = (source, base) => {
888
- let name = base;
889
- while (source.includes(name)) name += "_";
890
- return name;
891
- };
892
- var isDirectivePrologue = (statement) => ts6.isExpressionStatement(statement) && ts6.isStringLiteral(statement.expression);
1305
+ var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
893
1306
  var insertPositionAfterPrologue = (source, sourceFile) => {
894
1307
  const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
895
1308
  let end = shebangEnd;
@@ -936,178 +1349,11 @@ var collectWrappedFunction = (node, sourceFile, absolutePath, mapLocation) => {
936
1349
  instrumented: true
937
1350
  };
938
1351
  };
939
- var wrap = (edits, start, end, open, close, depth) => {
940
- const width = Math.max(0, end - start);
941
- edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
942
- edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
943
- };
944
- var compareEdits = (left, right) => {
945
- if (left.position !== right.position) return right.position - left.position;
946
- if (left.kind !== right.kind) {
947
- const rank = { replace: 0, close: 1, open: 2 };
948
- return rank[left.kind] - rank[right.kind];
949
- }
950
- if (left.kind === "close") {
951
- if (left.width !== right.width) return right.width - left.width;
952
- return left.depth - right.depth;
953
- }
954
- if (left.kind === "open") {
955
- if (left.width !== right.width) return left.width - right.width;
956
- return right.depth - left.depth;
957
- }
958
- return 0;
959
- };
960
- var VLQ_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
961
- var encodeVlq = (value) => {
962
- let vlq = value < 0 ? -value << 1 | 1 : value << 1;
963
- let encoded = "";
964
- do {
965
- let digit = vlq & 31;
966
- vlq >>>= 5;
967
- if (vlq > 0) digit |= 32;
968
- encoded += VLQ_ALPHABET[digit];
969
- } while (vlq > 0);
970
- return encoded;
971
- };
972
- var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
973
- var decodeInlineSourceMap = (url) => {
974
- const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
975
- if (base64?.[1]) {
976
- try {
977
- return Buffer.from(base64[1], "base64").toString("utf8");
978
- } catch {
979
- return void 0;
980
- }
981
- }
982
- const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
983
- if (!raw?.[1]) return void 0;
984
- try {
985
- return decodeURIComponent(raw[1]);
986
- } catch {
987
- return void 0;
988
- }
989
- };
990
- var upstreamTraceMap = (original) => {
991
- const match = SOURCEMAP_COMMENT.exec(original);
992
- const url = match?.[1] ?? match?.[2];
993
- if (!url) return void 0;
994
- const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
995
- if (!payload) return void 0;
996
- try {
997
- return new TraceMap2(payload);
998
- } catch {
999
- return void 0;
1000
- }
1001
- };
1002
- var lineStartsOf = (text) => {
1003
- const starts = [0];
1004
- for (let index = 0; index < text.length; index++) {
1005
- if (text[index] === "\n") starts.push(index + 1);
1006
- }
1007
- return starts;
1008
- };
1009
- var positionAt = (starts, offset) => {
1010
- let low = 0;
1011
- let high = starts.length - 1;
1012
- while (low < high) {
1013
- const mid = low + high + 1 >> 1;
1014
- if ((starts[mid] ?? 0) <= offset) low = mid;
1015
- else high = mid - 1;
1016
- }
1017
- return { line: low, column: offset - (starts[low] ?? 0) };
1018
- };
1019
- var sortedEdits = (edits) => [...edits].sort(compareEdits);
1020
- var originalOffsetToGenerated = (originalOffset, edits) => {
1021
- let generated = originalOffset;
1022
- for (const edit of edits) {
1023
- const delta = edit.text.length - edit.deleteCount;
1024
- if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
1025
- else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
1026
- }
1027
- return generated;
1028
- };
1029
- var mappingOffsets = (original, edits) => {
1030
- const offsets = /* @__PURE__ */ new Set([0, original.length]);
1031
- for (const start of lineStartsOf(original)) offsets.add(start);
1032
- for (const edit of edits) {
1033
- offsets.add(edit.position);
1034
- offsets.add(edit.position + edit.deleteCount);
1035
- }
1036
- return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
1037
- };
1038
- var encodeColumnMappings = (original, generated, file, edits) => {
1039
- const upstream = upstreamTraceMap(original);
1040
- const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
1041
- if (sources.length === 0) sources.push(file);
1042
- const applied = sortedEdits(edits);
1043
- const originalStarts = lineStartsOf(original);
1044
- const generatedStarts = lineStartsOf(generated);
1045
- const pointsByLine = Array.from({ length: generatedStarts.length }, () => []);
1046
- const seen = /* @__PURE__ */ new Set();
1047
- for (const originalOffset of mappingOffsets(original, edits)) {
1048
- const generatedOffset = Math.min(
1049
- originalOffsetToGenerated(originalOffset, applied),
1050
- generated.length
1051
- );
1052
- const originalPosition = positionAt(originalStarts, originalOffset);
1053
- const generatedPosition = positionAt(generatedStarts, generatedOffset);
1054
- let sourceIndex = 0;
1055
- let mappedLine = originalPosition.line;
1056
- let mappedColumn = originalPosition.column;
1057
- if (upstream) {
1058
- const mapped = originalPositionFor2(upstream, {
1059
- line: originalPosition.line + 1,
1060
- column: originalPosition.column
1061
- });
1062
- if (mapped.source && mapped.line != null && mapped.column != null) {
1063
- const index = sources.indexOf(mapped.source);
1064
- sourceIndex = index >= 0 ? index : 0;
1065
- mappedLine = mapped.line - 1;
1066
- mappedColumn = mapped.column;
1067
- }
1068
- }
1069
- const key = `${generatedPosition.line}:${generatedPosition.column}`;
1070
- if (seen.has(key)) continue;
1071
- seen.add(key);
1072
- pointsByLine[generatedPosition.line]?.push({
1073
- generatedColumn: generatedPosition.column,
1074
- sourceIndex,
1075
- originalLine: mappedLine,
1076
- originalColumn: mappedColumn
1077
- });
1078
- }
1079
- const lines = pointsByLine.map((segments) => {
1080
- segments.sort((left, right) => left.generatedColumn - right.generatedColumn);
1081
- let lastGeneratedColumn = 0;
1082
- let lastSourceIndex = 0;
1083
- let lastOriginalLine = 0;
1084
- let lastOriginalColumn = 0;
1085
- return segments.map((point) => {
1086
- const encoded = `${encodeVlq(point.generatedColumn - lastGeneratedColumn)}${encodeVlq(point.sourceIndex - lastSourceIndex)}${encodeVlq(point.originalLine - lastOriginalLine)}${encodeVlq(point.originalColumn - lastOriginalColumn)}`;
1087
- lastGeneratedColumn = point.generatedColumn;
1088
- lastSourceIndex = point.sourceIndex;
1089
- lastOriginalLine = point.originalLine;
1090
- lastOriginalColumn = point.originalColumn;
1091
- return encoded;
1092
- }).join(",");
1093
- });
1094
- return { sources, mappings: lines.join(";") };
1095
- };
1096
- var attachInlineSourceMap = (original, generated, filePath, edits) => {
1097
- const file = basename(filePath);
1098
- const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
1099
- const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
1100
- const comment = `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
1101
- JSON.stringify({ version: 3, file, sources, mappings })
1102
- ).toString("base64")} */`;
1103
- return withoutUpstream.endsWith("\n") ? `${withoutUpstream.slice(0, -1)}${comment}
1104
- ` : `${withoutUpstream}${comment}`;
1105
- };
1106
1352
  var insertAfterSuperOrPrologue = (body, sourceFile) => {
1107
1353
  const end = functionBodyPrologueEnd(body, sourceFile);
1108
1354
  for (const statement of body.statements) {
1109
1355
  if (isDirectivePrologue(statement)) continue;
1110
- if (ts6.isExpressionStatement(statement) && ts6.isCallExpression(statement.expression) && statement.expression.expression.kind === ts6.SyntaxKind.SuperKeyword) {
1356
+ if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
1111
1357
  return statement.end;
1112
1358
  }
1113
1359
  break;
@@ -1118,15 +1364,15 @@ var failEpilogue = (handleName, errorName, args, restoreOnCatch) => `}catch(${er
1118
1364
  var walkOwnBody = (node, visitNode) => {
1119
1365
  if (!node.body) return;
1120
1366
  const visit = (candidate) => {
1121
- if (candidate !== node && ts6.isFunctionLike(candidate)) return;
1367
+ if (candidate !== node && ts9.isFunctionLike(candidate)) return;
1122
1368
  visitNode(candidate);
1123
- ts6.forEachChild(candidate, visit);
1369
+ ts9.forEachChild(candidate, visit);
1124
1370
  };
1125
1371
  visit(node.body);
1126
1372
  };
1127
1373
  var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
1128
1374
  walkOwnBody(node, (candidate) => {
1129
- if (!ts6.isAwaitExpression(candidate)) return;
1375
+ if (!ts9.isAwaitExpression(candidate)) return;
1130
1376
  wrap(
1131
1377
  edits,
1132
1378
  candidate.expression.getStart(sourceFile),
@@ -1147,7 +1393,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
1147
1393
  };
1148
1394
  var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
1149
1395
  walkOwnBody(node, (candidate) => {
1150
- if (!ts6.isTryStatement(candidate)) return;
1396
+ if (!ts9.isTryStatement(candidate)) return;
1151
1397
  const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
1152
1398
  for (const block of blocks) {
1153
1399
  if (!block) continue;
@@ -1163,10 +1409,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
1163
1409
  });
1164
1410
  };
1165
1411
  var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
1166
- if (!node.body || !ts6.isBlock(node.body)) return;
1412
+ if (!node.body || !ts9.isBlock(node.body)) return;
1167
1413
  const visit = (candidate, at) => {
1168
- if (candidate !== node && ts6.isFunctionLike(candidate)) return;
1169
- if (ts6.isReturnStatement(candidate) && candidate.expression) {
1414
+ if (candidate !== node && ts9.isFunctionLike(candidate)) return;
1415
+ if (ts9.isReturnStatement(candidate) && candidate.expression) {
1170
1416
  const expression = candidate.expression;
1171
1417
  wrap(
1172
1418
  edits,
@@ -1178,17 +1424,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
1178
1424
  );
1179
1425
  return;
1180
1426
  }
1181
- ts6.forEachChild(candidate, (child) => visit(child, at + 1));
1427
+ ts9.forEachChild(candidate, (child) => visit(child, at + 1));
1182
1428
  };
1183
1429
  visit(node.body, depth + 1);
1184
1430
  };
1185
1431
  var transformSource = (source, options) => {
1186
1432
  if (source.includes("@rasputin-ignore-file")) return void 0;
1187
1433
  if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
1188
- const sourceFile = ts6.createSourceFile(
1434
+ const sourceFile = ts9.createSourceFile(
1189
1435
  options.filePath,
1190
1436
  source,
1191
- ts6.ScriptTarget.Latest,
1437
+ ts9.ScriptTarget.Latest,
1192
1438
  true,
1193
1439
  scriptKindFor3(options.filePath)
1194
1440
  );
@@ -1231,7 +1477,7 @@ var transformSource = (source, options) => {
1231
1477
  collected.asyncFunction = true;
1232
1478
  skipFunction(collected, "unsupported_async_generator");
1233
1479
  }
1234
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1480
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1235
1481
  return;
1236
1482
  }
1237
1483
  if (isSyncGeneratorLike(node) && node.body) {
@@ -1242,10 +1488,10 @@ var transformSource = (source, options) => {
1242
1488
  options.mapLocation
1243
1489
  );
1244
1490
  if (collected) skipFunction(collected, "unsupported_sync_generator");
1245
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1491
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1246
1492
  return;
1247
1493
  }
1248
- if (ts6.isConstructorDeclaration(node) && node.body) {
1494
+ if (ts9.isConstructorDeclaration(node) && node.body) {
1249
1495
  const collected = collectWrappedFunction(
1250
1496
  node,
1251
1497
  sourceFile,
@@ -1253,13 +1499,13 @@ var transformSource = (source, options) => {
1253
1499
  options.mapLocation
1254
1500
  );
1255
1501
  if (collected) skipFunction(collected, "unsupported_constructor");
1256
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1502
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1257
1503
  return;
1258
1504
  }
1259
1505
  if (isSupportedFunction(node)) {
1260
1506
  const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
1261
1507
  if (!collected) {
1262
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1508
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1263
1509
  return;
1264
1510
  }
1265
1511
  const asyncFunction = isAsyncFunctionLike(node);
@@ -1267,7 +1513,7 @@ var transformSource = (source, options) => {
1267
1513
  const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
1268
1514
  if (decision.action === "skip") {
1269
1515
  skipFunction(collected, decision.reason);
1270
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1516
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1271
1517
  return;
1272
1518
  }
1273
1519
  if (functionHasPreBodyParameterEvaluation(node)) {
@@ -1280,29 +1526,29 @@ var transformSource = (source, options) => {
1280
1526
  suspendResume: decision.action === "suspend_resume"
1281
1527
  });
1282
1528
  delta.functions.push(collected);
1283
- ts6.forEachChild(node, (child) => visit(child, collected, depth + 1));
1529
+ ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
1284
1530
  return;
1285
1531
  }
1286
- if (caller && (ts6.isCallExpression(node) || ts6.isNewExpression(node))) {
1532
+ if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
1287
1533
  const site = collectCallSite(node, caller, collectContext);
1288
1534
  if (site) delta.callSites.push(site);
1289
1535
  }
1290
- if (caller && ts6.isVariableDeclaration(node)) {
1536
+ if (caller && ts9.isVariableDeclaration(node)) {
1291
1537
  const destructure = collectParamDestructure(node, caller, collectContext);
1292
1538
  if (destructure) delta.destructures.push(destructure);
1293
1539
  }
1294
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1540
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1295
1541
  };
1296
1542
  visit(sourceFile, void 0, 0);
1297
1543
  if (pending.length === 0) {
1298
1544
  return delta.functions.length > 0 ? { code: source, delta } : void 0;
1299
1545
  }
1300
1546
  for (const [planIndex, entry] of pending.entries()) {
1301
- const captured = ts6.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
1547
+ const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
1302
1548
  const omitArg = captured.omitValues ? ",true" : "";
1303
1549
  const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
1304
1550
  const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
1305
- if (ts6.isBlock(entry.node.body)) {
1551
+ if (ts9.isBlock(entry.node.body)) {
1306
1552
  const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
1307
1553
  const closeAt = entry.node.body.end - 1;
1308
1554
  wrap(
@@ -1356,12 +1602,7 @@ var transformSource = (source, options) => {
1356
1602
  width: 0,
1357
1603
  kind: "replace"
1358
1604
  });
1359
- edits.sort(compareEdits);
1360
- let transformed = source;
1361
- for (const edit of edits) {
1362
- const text = separateFromPreviousToken(transformed, edit.position, edit.text);
1363
- transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
1364
- }
1605
+ const transformed = applyEdits(source, edits);
1365
1606
  const verify = options.verifyTransform ?? true;
1366
1607
  const refuseTransformed = () => {
1367
1608
  for (const entry of pending) {
@@ -1389,9 +1630,34 @@ var transformSource = (source, options) => {
1389
1630
  if (verify && !instrumentationTreesAreIsomorphic(options.filePath, source, transformed)) {
1390
1631
  return refuseTransformed();
1391
1632
  }
1392
- return { code: attachInlineSourceMap(source, transformed, options.filePath, edits), delta };
1633
+ return {
1634
+ code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
1635
+ delta
1636
+ };
1393
1637
  };
1394
1638
 
1639
+ // ../instrumentation/src/json-producer-sites.ts
1640
+ import ts11 from "typescript";
1641
+
1642
+ // ../instrumentation/src/literal-sites.ts
1643
+ import ts12 from "typescript";
1644
+
1645
+ // ../instrumentation/src/observe-sites.ts
1646
+ import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
1647
+ import ts13 from "typescript";
1648
+
1649
+ // ../instrumentation/src/verify-browser-source.ts
1650
+ import ts14 from "typescript";
1651
+
1652
+ // ../instrumentation/src/provenance-function-edits.ts
1653
+ import ts15 from "typescript";
1654
+
1655
+ // ../instrumentation/src/source-map-location.ts
1656
+ import { originalPositionFor as originalPositionFor3, TraceMap as TraceMap4 } from "@jridgewell/trace-mapping";
1657
+
1658
+ // src/sdk-meta.ts
1659
+ var SDK_VERSION = "0.6.0";
1660
+
1395
1661
  // src/auto-instrumentation/transform-disk-cache.ts
1396
1662
  var projectCacheDir = () => {
1397
1663
  let directory = process.cwd();