@rasputin-ai/node 0.5.3 → 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 (40) hide show
  1. package/README.md +3 -1
  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/execution-recorder-types.d.ts +2 -1
  11. package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
  12. package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
  13. package/dist/execution-recorder/function-plan.d.ts +7 -22
  14. package/dist/execution-recorder/function-plan.d.ts.map +1 -1
  15. package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
  16. package/dist/index.js +144 -123
  17. package/dist/instrument/build.js +852 -588
  18. package/dist/instrument/bun.js +639 -373
  19. package/dist/instrument/node.js +605 -339
  20. package/dist/internal.js +141 -120
  21. package/dist/rasputin-init.d.ts +1 -0
  22. package/dist/rasputin-init.d.ts.map +1 -1
  23. package/dist/sdk-meta.d.ts +1 -1
  24. package/package.json +4 -2
  25. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts +0 -29
  26. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts.map +0 -1
  27. package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts +0 -49
  28. package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts.map +0 -1
  29. package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts +0 -3
  30. package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts.map +0 -1
  31. package/dist/auto-instrumentation/suspension-whitelist.d.ts +0 -33
  32. package/dist/auto-instrumentation/suspension-whitelist.d.ts.map +0 -1
  33. package/dist/auto-instrumentation/transform-source.d.ts +0 -27
  34. package/dist/auto-instrumentation/transform-source.d.ts.map +0 -1
  35. package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts +0 -2
  36. package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts.map +0 -1
  37. package/dist/auto-instrumentation/verify-transformed-source.d.ts +0 -2
  38. package/dist/auto-instrumentation/verify-transformed-source.d.ts.map +0 -1
  39. package/dist/execution-recorder/run-exactly-once.d.ts +0 -7
  40. package/dist/execution-recorder/run-exactly-once.d.ts.map +0 -1
@@ -12,11 +12,7 @@ import {
12
12
  sourceLocatorFromFile as sourceLocatorFromFile2
13
13
  } from "@rasputin-ai/core";
14
14
 
15
- // src/execution-recorder/function-plan.ts
16
- import {
17
- runtimeFunctionId,
18
- sourceLocatorFromFile
19
- } from "@rasputin-ai/core";
15
+ // ../recorder/src/encoded-function-plan.ts
20
16
  var withPreBodyParameterEvaluation = (plan) => [
21
17
  plan[0],
22
18
  plan[1],
@@ -27,6 +23,12 @@ var withPreBodyParameterEvaluation = (plan) => [
27
23
  plan[6],
28
24
  1
29
25
  ];
26
+
27
+ // ../recorder/src/function-plan.ts
28
+ import {
29
+ runtimeFunctionId,
30
+ sourceLocatorFromFile
31
+ } from "@rasputin-ai/core";
30
32
  var encodeFunctionPlan = (source) => {
31
33
  const locator = sourceLocatorFromFile(source.filePath);
32
34
  const definition = {
@@ -43,6 +45,9 @@ var encodeFunctionPlan = (source) => {
43
45
  ];
44
46
  };
45
47
 
48
+ // ../recorder/src/runtime-symbol.ts
49
+ var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
50
+
46
51
  // src/auto-instrumentation/instrumentation-manifest-registry.ts
47
52
  var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
48
53
  var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
@@ -118,52 +123,10 @@ import {
118
123
  import { homedir } from "node:os";
119
124
  import { dirname as dirname2, join as join2 } from "node:path";
120
125
 
121
- // src/sdk-meta.ts
122
- var SDK_VERSION = "0.5.3";
123
-
124
- // src/auto-instrumentation/source-map-locations.ts
125
- import { readFileSync } from "node:fs";
126
- import { dirname, isAbsolute as isAbsolute2, join, resolve as resolve3 } from "node:path";
127
- import { fileURLToPath, pathToFileURL } from "node:url";
128
- import { LEAST_UPPER_BOUND, originalPositionFor, TraceMap } from "@jridgewell/trace-mapping";
129
- var sourceMapComment = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
130
- var decodeDataUrl = (url) => {
131
- const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
132
- if (base64?.[1]) return Buffer.from(base64[1], "base64").toString("utf8");
133
- const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
134
- return raw?.[1] ? decodeURIComponent(raw[1]) : void 0;
135
- };
136
- var sourceMapFor = (generatedPath, source) => {
137
- const match = sourceMapComment.exec(source);
138
- const reference = match?.[1] ?? match?.[2];
139
- if (reference?.startsWith("data:")) {
140
- const payload = decodeDataUrl(reference);
141
- return payload ? { payload, mapUrl: pathToFileURL(generatedPath).href } : void 0;
142
- }
143
- const mapPath = reference ? resolve3(dirname(generatedPath), reference) : `${generatedPath}.map`;
144
- return {
145
- payload: readFileSync(mapPath, "utf8"),
146
- mapUrl: pathToFileURL(mapPath).href
147
- };
148
- };
149
- var sourceMapPayloadForCache = (generatedPath, source) => {
150
- try {
151
- return sourceMapFor(generatedPath, source)?.payload ?? "";
152
- } catch {
153
- return "";
154
- }
155
- };
156
-
157
- // src/auto-instrumentation/transform-source.ts
158
- import { basename, resolve as resolve4 } from "node:path";
159
- import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap2 } from "@jridgewell/trace-mapping";
160
- import ts6 from "typescript";
161
-
162
- // src/execution-recorder/automatic-runtime.ts
163
- var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
164
- var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
126
+ // ../instrumentation/src/classify-function.ts
127
+ import ts4 from "typescript";
165
128
 
166
- // src/auto-instrumentation/collect-instrumentation-delta.ts
129
+ // ../instrumentation/src/collect-instrumentation-delta.ts
167
130
  import ts from "typescript";
168
131
  var paramBindingFromName = (name, sourceFile) => {
169
132
  if (ts.isIdentifier(name)) return { kind: "identifier", name: name.text };
@@ -340,41 +303,436 @@ var collectParamDestructure = (declaration, caller, context) => {
340
303
  };
341
304
  };
342
305
 
343
- // src/auto-instrumentation/parameter-initializer-may-run-code.ts
306
+ // ../instrumentation/src/parse-source.ts
344
307
  import ts2 from "typescript";
345
- var unwrap = (expression) => {
346
- let current = expression;
347
- while (ts2.isParenthesizedExpression(current) || ts2.isNonNullExpression(current)) {
348
- current = current.expression;
308
+
309
+ // ../instrumentation/src/svelte-generated.ts
310
+ import ts3 from "typescript";
311
+
312
+ // ../instrumentation/src/edits.ts
313
+ var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
314
+ var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
315
+ var separateFromPreviousToken = (source, position, text) => {
316
+ if (position <= 0 || text.length === 0) return text;
317
+ if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
318
+ return ` ${text}`;
349
319
  }
350
- return current;
320
+ return text;
351
321
  };
352
- var isSafeLiteralInitializer = (expression) => {
353
- const current = unwrap(expression);
354
- if (ts2.isNumericLiteral(current) || ts2.isStringLiteral(current) || ts2.isNoSubstitutionTemplateLiteral(current) || ts2.isBigIntLiteral(current)) {
355
- return true;
322
+ var uniqueName = (source, base) => {
323
+ let name = base;
324
+ while (source.includes(name)) name += "_";
325
+ return name;
326
+ };
327
+ var wrap = (edits, start, end, open, close, depth) => {
328
+ const width = Math.max(0, end - start);
329
+ edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
330
+ edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
331
+ };
332
+ var compareEdits = (left, right) => {
333
+ if (left.position !== right.position) return right.position - left.position;
334
+ if (left.kind !== right.kind) {
335
+ const rank = { replace: 0, close: 1, open: 2 };
336
+ return rank[left.kind] - rank[right.kind];
356
337
  }
357
- if (current.kind === ts2.SyntaxKind.TrueKeyword || current.kind === ts2.SyntaxKind.FalseKeyword || current.kind === ts2.SyntaxKind.NullKeyword) {
358
- return true;
338
+ if (left.kind === "close") {
339
+ if (left.width !== right.width) return right.width - left.width;
340
+ return left.depth - right.depth;
341
+ }
342
+ if (left.kind === "open") {
343
+ if (left.width !== right.width) return left.width - right.width;
344
+ return right.depth - left.depth;
359
345
  }
360
- if (ts2.isIdentifier(current) && current.text === "undefined") return true;
361
- if (ts2.isPrefixUnaryExpression(current) && (current.operator === ts2.SyntaxKind.PlusToken || current.operator === ts2.SyntaxKind.MinusToken)) {
362
- return ts2.isNumericLiteral(unwrap(current.operand));
346
+ return 0;
347
+ };
348
+ var applyEdits = (source, edits) => {
349
+ const ordered = [...edits].sort(compareEdits);
350
+ let transformed = source;
351
+ for (const edit of ordered) {
352
+ const text = separateFromPreviousToken(transformed, edit.position, textOf(edit));
353
+ transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
363
354
  }
364
- return false;
355
+ return transformed;
365
356
  };
366
- var functionHasPreBodyParameterEvaluation = (node) => {
367
- for (const parameter of node.parameters) {
368
- if (ts2.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
369
- if (!parameter.initializer) continue;
370
- if (!isSafeLiteralInitializer(parameter.initializer)) return true;
357
+ var textOf = (edit) => edit.text;
358
+
359
+ // ../node_modules/.bun/@jridgewell+sourcemap-codec@1.6.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
360
+ var comma = ",".charCodeAt(0);
361
+ var semicolon = ";".charCodeAt(0);
362
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
363
+ var intToChar = new Uint8Array(64);
364
+ var charToInt = new Uint8Array(128);
365
+ for (let i = 0; i < chars.length; i++) {
366
+ const c = chars.charCodeAt(i);
367
+ intToChar[i] = c;
368
+ charToInt[c] = i;
369
+ }
370
+ function encodeInteger(builder, num) {
371
+ do {
372
+ let clamped = num & 31;
373
+ num >>>= 5;
374
+ if (num > 0) clamped |= 32;
375
+ builder.write(intToChar[clamped]);
376
+ } while (num > 0);
377
+ }
378
+ function encodeSign(num) {
379
+ return num < 0 ? -num << 1 | 1 : num << 1;
380
+ }
381
+ var bufLength = 1024 * 16;
382
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
383
+ decode(buf) {
384
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
385
+ return out.toString();
386
+ }
387
+ } : {
388
+ decode(buf) {
389
+ let out = "";
390
+ for (let i = 0; i < buf.length; i++) {
391
+ out += String.fromCharCode(buf[i]);
392
+ }
393
+ return out;
371
394
  }
372
- return false;
373
395
  };
396
+ var StringWriter = class {
397
+ constructor() {
398
+ this.pos = 0;
399
+ this.out = "";
400
+ this.buffer = new Uint8Array(bufLength);
401
+ }
402
+ write(v) {
403
+ const { buffer } = this;
404
+ buffer[this.pos++] = v;
405
+ if (this.pos === bufLength) {
406
+ this.out += td.decode(buffer);
407
+ this.pos = 0;
408
+ }
409
+ }
410
+ flush() {
411
+ const { buffer, out, pos } = this;
412
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
413
+ }
414
+ };
415
+ function encode(decoded) {
416
+ const writer = new StringWriter();
417
+ let sourcesIndex = 0;
418
+ let sourceLine = 0;
419
+ let sourceColumn = 0;
420
+ let namesIndex = 0;
421
+ for (let i = 0; i < decoded.length; i++) {
422
+ const line = decoded[i];
423
+ if (i > 0) writer.write(semicolon);
424
+ if (line.length === 0) continue;
425
+ let genColumn = 0;
426
+ for (let j = 0; j < line.length; j++) {
427
+ const segment = line[j];
428
+ if (j > 0) writer.write(comma);
429
+ encodeInteger(writer, encodeSign(segment[0] - genColumn));
430
+ genColumn = segment[0];
431
+ if (segment.length === 1) continue;
432
+ encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
433
+ encodeInteger(writer, encodeSign(segment[2] - sourceLine));
434
+ encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
435
+ sourcesIndex = segment[1];
436
+ sourceLine = segment[2];
437
+ sourceColumn = segment[3];
438
+ if (segment.length === 4) continue;
439
+ encodeInteger(writer, encodeSign(segment[4] - namesIndex));
440
+ namesIndex = segment[4];
441
+ }
442
+ }
443
+ return writer.flush();
444
+ }
374
445
 
375
- // src/auto-instrumentation/suspension-whitelist.ts
376
- import ts3 from "typescript";
377
- var nodeFlags = ts3.NodeFlags;
446
+ // ../node_modules/.bun/@jridgewell+gen-mapping@0.3.13/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
447
+ import { TraceMap, decodedMappings } from "@jridgewell/trace-mapping";
448
+ var SetArray = class {
449
+ constructor() {
450
+ this._indexes = { __proto__: null };
451
+ this.array = [];
452
+ }
453
+ };
454
+ function cast(set) {
455
+ return set;
456
+ }
457
+ function get(setarr, key) {
458
+ return cast(setarr)._indexes[key];
459
+ }
460
+ function put(setarr, key) {
461
+ const index = get(setarr, key);
462
+ if (index !== void 0) return index;
463
+ const { array, _indexes: indexes } = cast(setarr);
464
+ const length = array.push(key);
465
+ return indexes[key] = length - 1;
466
+ }
467
+ var COLUMN = 0;
468
+ var SOURCES_INDEX = 1;
469
+ var SOURCE_LINE = 2;
470
+ var SOURCE_COLUMN = 3;
471
+ var NAMES_INDEX = 4;
472
+ var NO_NAME = -1;
473
+ var GenMapping = class {
474
+ constructor({ file, sourceRoot } = {}) {
475
+ this._names = new SetArray();
476
+ this._sources = new SetArray();
477
+ this._sourcesContent = [];
478
+ this._mappings = [];
479
+ this.file = file;
480
+ this.sourceRoot = sourceRoot;
481
+ this._ignoreList = new SetArray();
482
+ }
483
+ };
484
+ function cast2(map) {
485
+ return map;
486
+ }
487
+ function addSegment(map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
488
+ return addSegmentInternal(
489
+ false,
490
+ map,
491
+ genLine,
492
+ genColumn,
493
+ source,
494
+ sourceLine,
495
+ sourceColumn,
496
+ name,
497
+ content
498
+ );
499
+ }
500
+ function toDecodedMap(map) {
501
+ const {
502
+ _mappings: mappings,
503
+ _sources: sources,
504
+ _sourcesContent: sourcesContent,
505
+ _names: names,
506
+ _ignoreList: ignoreList
507
+ // _originalScopes: originalScopes,
508
+ // _generatedRanges: generatedRanges,
509
+ } = cast2(map);
510
+ removeEmptyFinalLines(mappings);
511
+ return {
512
+ version: 3,
513
+ file: map.file || void 0,
514
+ names: names.array,
515
+ sourceRoot: map.sourceRoot || void 0,
516
+ sources: sources.array,
517
+ sourcesContent,
518
+ mappings,
519
+ // originalScopes,
520
+ // generatedRanges,
521
+ ignoreList: ignoreList.array
522
+ };
523
+ }
524
+ function toEncodedMap(map) {
525
+ const decoded = toDecodedMap(map);
526
+ return Object.assign({}, decoded, {
527
+ // originalScopes: decoded.originalScopes.map((os) => encodeOriginalScopes(os)),
528
+ // generatedRanges: encodeGeneratedRanges(decoded.generatedRanges as GeneratedRange[]),
529
+ mappings: encode(decoded.mappings)
530
+ });
531
+ }
532
+ function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
533
+ const {
534
+ _mappings: mappings,
535
+ _sources: sources,
536
+ _sourcesContent: sourcesContent,
537
+ _names: names
538
+ // _originalScopes: originalScopes,
539
+ } = cast2(map);
540
+ const line = getIndex(mappings, genLine);
541
+ const index = getColumnIndex(line, genColumn);
542
+ if (!source) {
543
+ if (skipable && skipSourceless(line, index)) return;
544
+ return insert(line, index, [genColumn]);
545
+ }
546
+ assert(sourceLine);
547
+ assert(sourceColumn);
548
+ const sourcesIndex = put(sources, source);
549
+ const namesIndex = name ? put(names, name) : NO_NAME;
550
+ if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
551
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
552
+ return;
553
+ }
554
+ return insert(
555
+ line,
556
+ index,
557
+ name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]
558
+ );
559
+ }
560
+ function assert(_val) {
561
+ }
562
+ function getIndex(arr, index) {
563
+ for (let i = arr.length; i <= index; i++) {
564
+ arr[i] = [];
565
+ }
566
+ return arr[index];
567
+ }
568
+ function getColumnIndex(line, genColumn) {
569
+ let index = line.length;
570
+ for (let i = index - 1; i >= 0; index = i--) {
571
+ const current = line[i];
572
+ if (genColumn >= current[COLUMN]) break;
573
+ }
574
+ return index;
575
+ }
576
+ function insert(array, index, value) {
577
+ for (let i = array.length; i > index; i--) {
578
+ array[i] = array[i - 1];
579
+ }
580
+ array[index] = value;
581
+ }
582
+ function removeEmptyFinalLines(mappings) {
583
+ const { length } = mappings;
584
+ let len = length;
585
+ for (let i = len - 1; i >= 0; len = i, i--) {
586
+ if (mappings[i].length > 0) break;
587
+ }
588
+ if (len < length) mappings.length = len;
589
+ }
590
+ function skipSourceless(line, index) {
591
+ if (index === 0) return true;
592
+ const prev = line[index - 1];
593
+ return prev.length === 1;
594
+ }
595
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
596
+ if (index === 0) return false;
597
+ const prev = line[index - 1];
598
+ if (prev.length === 1) return false;
599
+ return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
600
+ }
601
+
602
+ // ../instrumentation/src/exact-transform-map.ts
603
+ import { originalPositionFor, TraceMap as TraceMap2 } from "@jridgewell/trace-mapping";
604
+ var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
605
+ var decodeInlineSourceMap = (url) => {
606
+ const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
607
+ if (base64?.[1]) {
608
+ try {
609
+ return Buffer.from(base64[1], "base64").toString("utf8");
610
+ } catch {
611
+ return void 0;
612
+ }
613
+ }
614
+ const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
615
+ if (!raw?.[1]) return void 0;
616
+ try {
617
+ return decodeURIComponent(raw[1]);
618
+ } catch {
619
+ return void 0;
620
+ }
621
+ };
622
+ var upstreamTraceMap = (original) => {
623
+ const match = SOURCEMAP_COMMENT.exec(original);
624
+ const url = match?.[1] ?? match?.[2];
625
+ if (!url) return void 0;
626
+ const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
627
+ if (!payload) return void 0;
628
+ try {
629
+ return new TraceMap2(payload);
630
+ } catch {
631
+ return void 0;
632
+ }
633
+ };
634
+ var lineStartsOf = (text) => {
635
+ const starts = [0];
636
+ for (let index = 0; index < text.length; index++) {
637
+ if (text[index] === "\n") starts.push(index + 1);
638
+ }
639
+ return starts;
640
+ };
641
+ var positionAt = (starts, offset) => {
642
+ let low = 0;
643
+ let high = starts.length - 1;
644
+ while (low < high) {
645
+ const mid = low + high + 1 >> 1;
646
+ if ((starts[mid] ?? 0) <= offset) low = mid;
647
+ else high = mid - 1;
648
+ }
649
+ return { line: low, column: offset - (starts[low] ?? 0) };
650
+ };
651
+ var sortedEdits = (edits) => [...edits].sort(compareEdits);
652
+ var originalOffsetToGenerated = (originalOffset, edits) => {
653
+ let generated = originalOffset;
654
+ for (const edit of edits) {
655
+ const delta = edit.text.length - edit.deleteCount;
656
+ if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
657
+ else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
658
+ }
659
+ return generated;
660
+ };
661
+ var mappingOffsets = (original, edits) => {
662
+ const offsets = /* @__PURE__ */ new Set([0, original.length]);
663
+ for (const start of lineStartsOf(original)) offsets.add(start);
664
+ for (const edit of edits) {
665
+ offsets.add(edit.position);
666
+ offsets.add(edit.position + edit.deleteCount);
667
+ }
668
+ return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
669
+ };
670
+ var encodeColumnMappings = (original, generated, file, edits) => {
671
+ const upstream = upstreamTraceMap(original);
672
+ const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
673
+ if (sources.length === 0) sources.push(file);
674
+ const applied = sortedEdits(edits);
675
+ const originalStarts = lineStartsOf(original);
676
+ const generatedStarts = lineStartsOf(generated);
677
+ const map = new GenMapping({ file });
678
+ const seen = /* @__PURE__ */ new Set();
679
+ for (const originalOffset of mappingOffsets(original, edits)) {
680
+ const generatedOffset = Math.min(
681
+ originalOffsetToGenerated(originalOffset, applied),
682
+ generated.length
683
+ );
684
+ const originalPosition = positionAt(originalStarts, originalOffset);
685
+ const generatedPosition = positionAt(generatedStarts, generatedOffset);
686
+ let source = sources[0] ?? file;
687
+ let mappedLine = originalPosition.line;
688
+ let mappedColumn = originalPosition.column;
689
+ if (upstream) {
690
+ const mapped = originalPositionFor(upstream, {
691
+ line: originalPosition.line + 1,
692
+ column: originalPosition.column
693
+ });
694
+ if (mapped.source && mapped.line != null && mapped.column != null) {
695
+ source = mapped.source;
696
+ mappedLine = mapped.line - 1;
697
+ mappedColumn = mapped.column;
698
+ }
699
+ }
700
+ const key = `${generatedPosition.line}:${generatedPosition.column}`;
701
+ if (seen.has(key)) continue;
702
+ seen.add(key);
703
+ addSegment(
704
+ map,
705
+ generatedPosition.line,
706
+ generatedPosition.column,
707
+ source,
708
+ mappedLine,
709
+ mappedColumn
710
+ );
711
+ }
712
+ const encoded = toEncodedMap(map);
713
+ return {
714
+ sources: encoded.sources.filter((source) => Boolean(source)),
715
+ mappings: encoded.mappings
716
+ };
717
+ };
718
+ var attachInlineSourceMap = (original, generated, filePath, edits, basenameOf) => {
719
+ const file = basenameOf(filePath);
720
+ const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
721
+ const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
722
+ const comment = `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
723
+ JSON.stringify({ version: 3, file, sources, mappings })
724
+ ).toString("base64")} */`;
725
+ return withoutUpstream.endsWith("\n") ? `${withoutUpstream.slice(0, -1)}${comment}
726
+ ` : `${withoutUpstream}${comment}`;
727
+ };
728
+
729
+ // ../instrumentation/src/browser-function-edits.ts
730
+ import { propertyNameIsSensitive } from "@rasputin-ai/core";
731
+ import ts10 from "typescript";
732
+
733
+ // ../instrumentation/src/suspension-whitelist.ts
734
+ import ts5 from "typescript";
735
+ var nodeFlags = ts5.NodeFlags;
378
736
  var AWAIT_USING_FLAG = nodeFlags.AwaitUsing ?? 0;
379
737
  var USING_FLAG = nodeFlags.Using ?? 0;
380
738
  var KNOWN_SUSPENSION_KIND_NAMES = [
@@ -384,8 +742,8 @@ var KNOWN_SUSPENSION_KIND_NAMES = [
384
742
  "YieldKeyword",
385
743
  "UsingKeyword"
386
744
  ];
387
- var isFunctionLike = (node) => ts3.isFunctionLike(node);
388
- var isAsyncFunctionLike = (node) => (ts3.getCombinedModifierFlags(node) & ts3.ModifierFlags.Async) !== 0;
745
+ var isFunctionLike = (node) => ts5.isFunctionLike(node);
746
+ var isAsyncFunctionLike = (node) => (ts5.getCombinedModifierFlags(node) & ts5.ModifierFlags.Async) !== 0;
389
747
  var isAsyncGeneratorLike = (node) => isFunctionLike(node) && isAsyncFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken);
390
748
  var isSyncGeneratorLike = (node) => isFunctionLike(node) && "asteriskToken" in node && Boolean(node.asteriskToken) && !isAsyncFunctionLike(node);
391
749
  var visitOwnBody = (node, visitNode) => {
@@ -396,7 +754,7 @@ var visitOwnBody = (node, visitNode) => {
396
754
  return;
397
755
  }
398
756
  if (visitNode(candidate)) return;
399
- ts3.forEachChild(candidate, visit);
757
+ ts5.forEachChild(candidate, visit);
400
758
  };
401
759
  visit(node.body);
402
760
  };
@@ -424,16 +782,16 @@ var slicesOutside = (start, end, spans) => {
424
782
  };
425
783
  var sliceHasAwaitKeyword = (source, start, end) => {
426
784
  if (end <= start) return false;
427
- const scanner = ts3.createScanner(
428
- ts3.ScriptTarget.Latest,
785
+ const scanner = ts5.createScanner(
786
+ ts5.ScriptTarget.Latest,
429
787
  true,
430
- ts3.LanguageVariant.Standard,
788
+ ts5.LanguageVariant.Standard,
431
789
  source.slice(start, end)
432
790
  );
433
791
  while (true) {
434
792
  const token = scanner.scan();
435
- if (token === ts3.SyntaxKind.EndOfFileToken) return false;
436
- if (token === ts3.SyntaxKind.AwaitKeyword) return true;
793
+ if (token === ts5.SyntaxKind.EndOfFileToken) return false;
794
+ if (token === ts5.SyntaxKind.AwaitKeyword) return true;
437
795
  }
438
796
  };
439
797
  var ownBodyHasAwaitKeyword = (node, sourceFile) => {
@@ -451,7 +809,7 @@ var isAwaitUsingList = (node) => {
451
809
  return (node.flags & AWAIT_USING_FLAG) === AWAIT_USING_FLAG && (node.flags & USING_FLAG) !== 0;
452
810
  };
453
811
  var unknownSuspensionKind = (node) => {
454
- const name = ts3.SyntaxKind[node.kind];
812
+ const name = ts5.SyntaxKind[node.kind];
455
813
  if (typeof name !== "string" || !/Await|Yield|Using/.test(name)) return false;
456
814
  return !KNOWN_SUSPENSION_KIND_NAMES.includes(name);
457
815
  };
@@ -464,9 +822,9 @@ var ownSuspensionFacts = (node, sourceFile) => {
464
822
  awaitKeyword: ownBodyHasAwaitKeyword(node, sourceFile)
465
823
  };
466
824
  visitOwnBody(node, (candidate) => {
467
- if (ts3.isAwaitExpression(candidate)) facts.awaitExpressions = true;
468
- if (ts3.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
469
- if (ts3.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
825
+ if (ts5.isAwaitExpression(candidate)) facts.awaitExpressions = true;
826
+ if (ts5.isForOfStatement(candidate) && candidate.awaitModifier) facts.forAwait = true;
827
+ if (ts5.isVariableDeclarationList(candidate) && isAwaitUsingList(candidate)) {
470
828
  facts.awaitUsing = true;
471
829
  }
472
830
  if (unknownSuspensionKind(candidate)) facts.unknown = true;
@@ -477,7 +835,7 @@ var ownSuspensionFacts = (node, sourceFile) => {
477
835
  var bodyHasDirectEval = (node) => {
478
836
  let found = false;
479
837
  visitOwnBody(node, (candidate) => {
480
- if (ts3.isCallExpression(candidate) && ts3.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
838
+ if (ts5.isCallExpression(candidate) && ts5.isIdentifier(candidate.expression) && candidate.expression.text === "eval") {
481
839
  found = true;
482
840
  }
483
841
  return found;
@@ -499,25 +857,61 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
499
857
  return { action: "inline" };
500
858
  };
501
859
 
502
- // src/auto-instrumentation/verify-instrumentation-isomorphism.ts
503
- import ts4 from "typescript";
860
+ // ../instrumentation/src/transform-source.ts
861
+ import { basename, resolve as resolve3 } from "node:path";
862
+ import ts9 from "typescript";
863
+
864
+ // ../instrumentation/src/parameter-initializer-may-run-code.ts
865
+ import ts6 from "typescript";
866
+ var unwrap = (expression) => {
867
+ let current = expression;
868
+ while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
869
+ current = current.expression;
870
+ }
871
+ return current;
872
+ };
873
+ var isSafeLiteralInitializer = (expression) => {
874
+ const current = unwrap(expression);
875
+ if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
876
+ return true;
877
+ }
878
+ if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
879
+ return true;
880
+ }
881
+ if (ts6.isIdentifier(current) && current.text === "undefined") return true;
882
+ if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
883
+ return ts6.isNumericLiteral(unwrap(current.operand));
884
+ }
885
+ return false;
886
+ };
887
+ var functionHasPreBodyParameterEvaluation = (node) => {
888
+ for (const parameter of node.parameters) {
889
+ if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
890
+ if (!parameter.initializer) continue;
891
+ if (!isSafeLiteralInitializer(parameter.initializer)) return true;
892
+ }
893
+ return false;
894
+ };
895
+
896
+ // ../instrumentation/src/verify-instrumentation-isomorphism.ts
897
+ import ts7 from "typescript";
504
898
  var RASPUTIN_IDENT = /^__rasputin/;
505
899
  var scriptKindFor = (filePath) => {
506
- if (/\.tsx$/i.test(filePath)) return ts4.ScriptKind.TSX;
507
- if (/\.jsx$/i.test(filePath)) return ts4.ScriptKind.JSX;
508
- if (/\.[cm]?ts$/i.test(filePath)) return ts4.ScriptKind.TS;
509
- return ts4.ScriptKind.JS;
900
+ if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
901
+ if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
902
+ if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
903
+ return ts7.ScriptKind.JS;
510
904
  };
511
- var parse = (filePath, source) => ts4.createSourceFile(filePath, source, ts4.ScriptTarget.Latest, true, scriptKindFor(filePath));
905
+ var parse = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor(filePath));
512
906
  var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
513
907
  var identText = (node) => {
514
- if (ts4.isIdentifier(node)) return node.text;
515
- if (ts4.isPrivateIdentifier(node)) return node.text;
908
+ if (ts7.isIdentifier(node)) return node.text;
909
+ if (ts7.isPrivateIdentifier(node)) return node.text;
516
910
  return void 0;
517
911
  };
518
912
  var calleeName = (expression) => {
519
- if (ts4.isIdentifier(expression)) return expression.text;
520
- if (ts4.isPropertyAccessExpression(expression)) {
913
+ if (ts7.isIdentifier(expression)) return expression.text;
914
+ if (ts7.isPropertyAccessExpression(expression)) {
521
915
  const object = identText(expression.expression);
522
916
  const property = identText(expression.name);
523
917
  if (object && isRasputinName(object) && property) return `${object}.${property}`;
@@ -525,7 +919,7 @@ var calleeName = (expression) => {
525
919
  return void 0;
526
920
  };
527
921
  var isRasputinCall = (node, methods) => {
528
- if (!ts4.isCallExpression(node)) return false;
922
+ if (!ts7.isCallExpression(node)) return false;
529
923
  const name = calleeName(node.expression);
530
924
  if (!name) return false;
531
925
  if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
@@ -535,20 +929,20 @@ var unwrapCall = (node) => {
535
929
  let current = node;
536
930
  while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
537
931
  current = current.arguments[0];
538
- if (ts4.isParenthesizedExpression(current)) current = current.expression;
932
+ if (ts7.isParenthesizedExpression(current)) current = current.expression;
539
933
  }
540
- if (ts4.isParenthesizedExpression(current)) return current.expression;
934
+ if (ts7.isParenthesizedExpression(current)) return current.expression;
541
935
  return current;
542
936
  };
543
937
  var isRasputinStatement = (node) => {
544
- if (ts4.isEmptyStatement(node)) return true;
545
- if (ts4.isVariableStatement(node)) {
938
+ if (ts7.isEmptyStatement(node)) return true;
939
+ if (ts7.isVariableStatement(node)) {
546
940
  return node.declarationList.declarations.every((declaration) => {
547
941
  const name = identText(declaration.name);
548
942
  return Boolean(name && isRasputinName(name));
549
943
  });
550
944
  }
551
- if (ts4.isExpressionStatement(node)) {
945
+ if (ts7.isExpressionStatement(node)) {
552
946
  if (!isRasputinCall(node.expression)) return false;
553
947
  const unwrapped = unwrapCall(node.expression);
554
948
  return unwrapped === node.expression;
@@ -562,7 +956,7 @@ var isRasputinTryWrapper = (node) => {
562
956
  (statement) => !isRasputinStatement(statement)
563
957
  );
564
958
  const leftover = catchCalls[0];
565
- const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts4.isThrowStatement(leftover) && ts4.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
959
+ const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
566
960
  if (!leftoverThrow && catchCalls.length > 0) return false;
567
961
  return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
568
962
  };
@@ -570,7 +964,7 @@ var flattenStatements = (statements) => {
570
964
  const flattened = [];
571
965
  for (const statement of statements) {
572
966
  if (isRasputinStatement(statement)) continue;
573
- if (ts4.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
967
+ if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
574
968
  flattened.push(...flattenStatements(statement.tryBlock.statements));
575
969
  continue;
576
970
  }
@@ -579,38 +973,38 @@ var flattenStatements = (statements) => {
579
973
  return flattened;
580
974
  };
581
975
  var extra = (node) => {
582
- if (ts4.isIdentifier(node) || ts4.isPrivateIdentifier(node)) {
976
+ if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
583
977
  return isRasputinName(node.text) ? "" : node.text;
584
978
  }
585
- if (ts4.isStringLiteral(node) || ts4.isNumericLiteral(node) || ts4.isNoSubstitutionTemplateLiteral(node)) {
979
+ if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
586
980
  return node.text;
587
981
  }
588
- if (ts4.isToken(node) && !ts4.isIdentifier(node)) return ts4.SyntaxKind[node.kind] ?? "";
982
+ if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
589
983
  return "";
590
984
  };
591
985
  var signatureOf = (node) => {
592
986
  const unwrapped = unwrapCall(node);
593
987
  if (unwrapped !== node) return signatureOf(unwrapped);
594
- if (ts4.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
595
- if (ts4.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
988
+ if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
989
+ if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
596
990
  return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
597
991
  }
598
- if (ts4.isBlock(unwrapped)) {
992
+ if (ts7.isBlock(unwrapped)) {
599
993
  const statements = flattenStatements(unwrapped.statements);
600
994
  return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
601
995
  }
602
- if (ts4.isCatchClause(unwrapped)) {
996
+ if (ts7.isCatchClause(unwrapped)) {
603
997
  const statements = flattenStatements(unwrapped.block.statements);
604
998
  const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
605
999
  return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
606
1000
  }
607
- if (ts4.isArrowFunction(unwrapped) && ts4.isBlock(unwrapped.body)) {
1001
+ if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
608
1002
  const statements = flattenStatements(unwrapped.body.statements);
609
1003
  const only = statements[0];
610
- if (statements.length === 1 && only && ts4.isReturnStatement(only) && only.expression) {
1004
+ if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
611
1005
  const expression = only.expression;
612
1006
  const parts2 = [];
613
- ts4.forEachChild(unwrapped, (child) => {
1007
+ ts7.forEachChild(unwrapped, (child) => {
614
1008
  if (child === unwrapped.body) {
615
1009
  const part2 = signatureOf(expression);
616
1010
  if (part2) parts2.push(part2);
@@ -623,11 +1017,11 @@ var signatureOf = (node) => {
623
1017
  }
624
1018
  }
625
1019
  const parts = [];
626
- ts4.forEachChild(unwrapped, (child) => {
1020
+ ts7.forEachChild(unwrapped, (child) => {
627
1021
  const part = signatureOf(child);
628
1022
  if (part) parts.push(part);
629
1023
  });
630
- const kind = ts4.SyntaxKind[unwrapped.kind] ?? "Node";
1024
+ const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
631
1025
  const label = extra(unwrapped);
632
1026
  return `${kind}${label}[${parts.join(",")}]`;
633
1027
  };
@@ -635,15 +1029,15 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
635
1029
  return signatureOf(parse(filePath, original)) === signatureOf(parse(filePath, transformed));
636
1030
  };
637
1031
 
638
- // src/auto-instrumentation/verify-transformed-source.ts
639
- import ts5 from "typescript";
640
- var transpileForVerification = (filePath, code) => ts5.transpileModule(code, {
1032
+ // ../instrumentation/src/verify-transformed-source.ts
1033
+ import ts8 from "typescript";
1034
+ var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
641
1035
  compilerOptions: {
642
1036
  // ES2020 downlevel keeps native @decorators out of `new Function`.
643
- target: ts5.ScriptTarget.ES2020,
644
- module: ts5.ModuleKind.ESNext,
1037
+ target: ts8.ScriptTarget.ES2020,
1038
+ module: ts8.ModuleKind.ESNext,
645
1039
  allowJs: true,
646
- jsx: ts5.JsxEmit.React,
1040
+ jsx: ts8.JsxEmit.React,
647
1041
  experimentalDecorators: true
648
1042
  },
649
1043
  reportDiagnostics: true,
@@ -651,7 +1045,7 @@ var transpileForVerification = (filePath, code) => ts5.transpileModule(code, {
651
1045
  });
652
1046
  var hasScanOrParseError = (diagnostics) => Boolean(
653
1047
  diagnostics?.some(
654
- (diagnostic) => diagnostic.category === ts5.DiagnosticCategory.Error && diagnostic.code < 2e3
1048
+ (diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
655
1049
  )
656
1050
  );
657
1051
  var scriptBodyForEngine = (emitted) => (
@@ -660,39 +1054,39 @@ var scriptBodyForEngine = (emitted) => (
660
1054
  );
661
1055
  var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
662
1056
  var scriptKindFor2 = (filePath) => {
663
- if (/\.tsx$/i.test(filePath)) return ts5.ScriptKind.TSX;
664
- if (/\.jsx$/i.test(filePath)) return ts5.ScriptKind.JSX;
665
- if (/\.[cm]?ts$/i.test(filePath)) return ts5.ScriptKind.TS;
666
- return ts5.ScriptKind.JS;
1057
+ if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
1058
+ if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
1059
+ if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
1060
+ return ts8.ScriptKind.JS;
667
1061
  };
668
- var isIterationStatement = (node) => ts5.isForStatement(node) || ts5.isForOfStatement(node) || ts5.isForInStatement(node) || ts5.isWhileStatement(node) || ts5.isDoStatement(node);
1062
+ var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
669
1063
  var unwrapLabeled = (node) => {
670
1064
  let current = node;
671
- while (ts5.isLabeledStatement(current)) current = current.statement;
1065
+ while (ts8.isLabeledStatement(current)) current = current.statement;
672
1066
  return current;
673
1067
  };
674
1068
  var hasInvalidLabelJump = (sourceFile) => {
675
1069
  const visit = (node, labels) => {
676
- if (ts5.isFunctionLike(node)) {
1070
+ if (ts8.isFunctionLike(node)) {
677
1071
  let nestedInvalid = false;
678
- ts5.forEachChild(node, (child) => {
1072
+ ts8.forEachChild(node, (child) => {
679
1073
  if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
680
1074
  });
681
1075
  return nestedInvalid;
682
1076
  }
683
- if (ts5.isLabeledStatement(node)) {
1077
+ if (ts8.isLabeledStatement(node)) {
684
1078
  const next = new Map(labels);
685
1079
  next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
686
1080
  return visit(node.statement, next);
687
1081
  }
688
- if (ts5.isContinueStatement(node) && node.label) {
1082
+ if (ts8.isContinueStatement(node) && node.label) {
689
1083
  if (labels.get(node.label.text) !== true) return true;
690
1084
  }
691
- if (ts5.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
1085
+ if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
692
1086
  return true;
693
1087
  }
694
1088
  let invalid = false;
695
- ts5.forEachChild(node, (child) => {
1089
+ ts8.forEachChild(node, (child) => {
696
1090
  if (visit(child, labels)) invalid = true;
697
1091
  });
698
1092
  return invalid;
@@ -735,10 +1129,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
735
1129
  var transformedSourceIsInvalid = (filePath, code) => {
736
1130
  if (GLUED_INSTRUMENTATION.test(code)) return true;
737
1131
  if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
738
- const sourceFile = ts5.createSourceFile(
1132
+ const sourceFile = ts8.createSourceFile(
739
1133
  filePath,
740
1134
  code,
741
- ts5.ScriptTarget.Latest,
1135
+ ts8.ScriptTarget.Latest,
742
1136
  true,
743
1137
  scriptKindFor2(filePath)
744
1138
  );
@@ -750,16 +1144,7 @@ var transformedSourceIsInvalid = (filePath, code) => {
750
1144
  return !engineAccepts(scriptBodyForEngine(outputText));
751
1145
  };
752
1146
 
753
- // src/auto-instrumentation/transform-source.ts
754
- var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
755
- var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
756
- var separateFromPreviousToken = (source, position, text) => {
757
- if (position <= 0 || text.length === 0) return text;
758
- if (isIdentContinue(source.charCodeAt(position - 1)) && isIdentStart(text.charCodeAt(0))) {
759
- return ` ${text}`;
760
- }
761
- return text;
762
- };
1147
+ // ../instrumentation/src/transform-source.ts
763
1148
  var RASPUTIN_INSTRUMENTATION_MARKER = "rasputin.instrumented.v3";
764
1149
  var RASPUTIN_INSTRUMENTATION_PREAMBLE = `/*${RASPUTIN_INSTRUMENTATION_MARKER}*/`;
765
1150
  var sourceIsRasputinInstrumented = (source) => source.includes(RASPUTIN_INSTRUMENTATION_PREAMBLE);
@@ -768,25 +1153,25 @@ var alreadyInstrumentedResult = (source) => ({
768
1153
  delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
769
1154
  });
770
1155
  var scriptKindFor3 = (filePath) => {
771
- if (/\.tsx$/i.test(filePath)) return ts6.ScriptKind.TSX;
772
- if (/\.jsx$/i.test(filePath)) return ts6.ScriptKind.JSX;
773
- if (/\.[cm]?ts$/i.test(filePath)) return ts6.ScriptKind.TS;
774
- return ts6.ScriptKind.JS;
1156
+ if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
1157
+ if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
1158
+ if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
1159
+ return ts9.ScriptKind.JS;
775
1160
  };
776
1161
  var functionName = (node, sourceFile) => {
777
- if (ts6.isConstructorDeclaration(node)) return "constructor";
1162
+ if (ts9.isConstructorDeclaration(node)) return "constructor";
778
1163
  if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
779
1164
  const parent = node.parent;
780
- if (ts6.isVariableDeclaration(parent) && ts6.isIdentifier(parent.name)) return parent.name.text;
781
- if (ts6.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
782
- if (ts6.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
1165
+ if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
1166
+ if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
1167
+ if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
783
1168
  const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
784
1169
  return `anonymous@${location.line + 1}:${location.character + 1}`;
785
1170
  };
786
1171
  var functionLocationPosition = (node, sourceFile) => {
787
1172
  if (node.name) return node.name.getStart(sourceFile);
788
1173
  const parent = node.parent;
789
- if ((ts6.isVariableDeclaration(parent) || ts6.isPropertyAssignment(parent)) && parent.name) {
1174
+ if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
790
1175
  return parent.name.getStart(sourceFile);
791
1176
  }
792
1177
  return node.getStart(sourceFile);
@@ -799,12 +1184,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
799
1184
  }
800
1185
  return end;
801
1186
  };
802
- var isStaticPropertyName = (name) => ts6.isIdentifier(name) || ts6.isStringLiteral(name) || ts6.isNoSubstitutionTemplateLiteral(name) || ts6.isNumericLiteral(name);
1187
+ var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
803
1188
  var canReconstructBinding = (name) => {
804
- if (ts6.isIdentifier(name)) return true;
805
- if (ts6.isArrayBindingPattern(name)) {
1189
+ if (ts9.isIdentifier(name)) return true;
1190
+ if (ts9.isArrayBindingPattern(name)) {
806
1191
  return name.elements.every(
807
- (element) => ts6.isOmittedExpression(element) || canReconstructBinding(element.name)
1192
+ (element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
808
1193
  );
809
1194
  }
810
1195
  return name.elements.every((element) => {
@@ -813,10 +1198,10 @@ var canReconstructBinding = (name) => {
813
1198
  });
814
1199
  };
815
1200
  var bindingValue = (name, sourceFile) => {
816
- if (ts6.isIdentifier(name)) return name.text;
817
- if (ts6.isArrayBindingPattern(name)) {
1201
+ if (ts9.isIdentifier(name)) return name.text;
1202
+ if (ts9.isArrayBindingPattern(name)) {
818
1203
  const values = name.elements.map((element) => {
819
- if (ts6.isOmittedExpression(element)) return "";
1204
+ if (ts9.isOmittedExpression(element)) return "";
820
1205
  const value = bindingValue(element.name, sourceFile);
821
1206
  return element.dotDotDotToken ? `...${value}` : value;
822
1207
  });
@@ -826,7 +1211,7 @@ var bindingValue = (name, sourceFile) => {
826
1211
  const value = bindingValue(element.name, sourceFile);
827
1212
  if (element.dotDotDotToken) return `...${value}`;
828
1213
  if (!element.propertyName) return value;
829
- const key = ts6.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
1214
+ const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
830
1215
  return `${key}:${value}`;
831
1216
  });
832
1217
  return `{${properties.join(",")}}`;
@@ -834,7 +1219,7 @@ var bindingValue = (name, sourceFile) => {
834
1219
  var arrowArgsCapture = (node) => {
835
1220
  const sourceFile = node.getSourceFile();
836
1221
  const params = node.parameters.filter(
837
- (parameter) => !(ts6.isIdentifier(parameter.name) && parameter.name.text === "this")
1222
+ (parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
838
1223
  );
839
1224
  if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
840
1225
  return {
@@ -849,18 +1234,13 @@ var arrowArgsCapture = (node) => {
849
1234
  return { args: `[${values.join(",")}]`, omitValues: false };
850
1235
  };
851
1236
  var isSupportedFunction = (node) => {
852
- if (!ts6.isFunctionDeclaration(node) && !ts6.isFunctionExpression(node) && !ts6.isArrowFunction(node) && !ts6.isMethodDeclaration(node) && !ts6.isGetAccessorDeclaration(node) && !ts6.isSetAccessorDeclaration(node)) {
1237
+ if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
853
1238
  return false;
854
1239
  }
855
1240
  if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
856
1241
  return true;
857
1242
  };
858
- var uniqueName = (source, base) => {
859
- let name = base;
860
- while (source.includes(name)) name += "_";
861
- return name;
862
- };
863
- var isDirectivePrologue = (statement) => ts6.isExpressionStatement(statement) && ts6.isStringLiteral(statement.expression);
1243
+ var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
864
1244
  var insertPositionAfterPrologue = (source, sourceFile) => {
865
1245
  const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
866
1246
  let end = shebangEnd;
@@ -907,178 +1287,11 @@ var collectWrappedFunction = (node, sourceFile, absolutePath, mapLocation) => {
907
1287
  instrumented: true
908
1288
  };
909
1289
  };
910
- var wrap = (edits, start, end, open, close, depth) => {
911
- const width = Math.max(0, end - start);
912
- edits.push({ position: start, text: open, deleteCount: 0, depth, width, kind: "open" });
913
- edits.push({ position: end, text: close, deleteCount: 0, depth, width, kind: "close" });
914
- };
915
- var compareEdits = (left, right) => {
916
- if (left.position !== right.position) return right.position - left.position;
917
- if (left.kind !== right.kind) {
918
- const rank = { replace: 0, close: 1, open: 2 };
919
- return rank[left.kind] - rank[right.kind];
920
- }
921
- if (left.kind === "close") {
922
- if (left.width !== right.width) return right.width - left.width;
923
- return left.depth - right.depth;
924
- }
925
- if (left.kind === "open") {
926
- if (left.width !== right.width) return left.width - right.width;
927
- return right.depth - left.depth;
928
- }
929
- return 0;
930
- };
931
- var VLQ_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
932
- var encodeVlq = (value) => {
933
- let vlq = value < 0 ? -value << 1 | 1 : value << 1;
934
- let encoded = "";
935
- do {
936
- let digit = vlq & 31;
937
- vlq >>>= 5;
938
- if (vlq > 0) digit |= 32;
939
- encoded += VLQ_ALPHABET[digit];
940
- } while (vlq > 0);
941
- return encoded;
942
- };
943
- var SOURCEMAP_COMMENT = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
944
- var decodeInlineSourceMap = (url) => {
945
- const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
946
- if (base64?.[1]) {
947
- try {
948
- return Buffer.from(base64[1], "base64").toString("utf8");
949
- } catch {
950
- return void 0;
951
- }
952
- }
953
- const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
954
- if (!raw?.[1]) return void 0;
955
- try {
956
- return decodeURIComponent(raw[1]);
957
- } catch {
958
- return void 0;
959
- }
960
- };
961
- var upstreamTraceMap = (original) => {
962
- const match = SOURCEMAP_COMMENT.exec(original);
963
- const url = match?.[1] ?? match?.[2];
964
- if (!url) return void 0;
965
- const payload = url.startsWith("data:") ? decodeInlineSourceMap(url) : void 0;
966
- if (!payload) return void 0;
967
- try {
968
- return new TraceMap2(payload);
969
- } catch {
970
- return void 0;
971
- }
972
- };
973
- var lineStartsOf = (text) => {
974
- const starts = [0];
975
- for (let index = 0; index < text.length; index++) {
976
- if (text[index] === "\n") starts.push(index + 1);
977
- }
978
- return starts;
979
- };
980
- var positionAt = (starts, offset) => {
981
- let low = 0;
982
- let high = starts.length - 1;
983
- while (low < high) {
984
- const mid = low + high + 1 >> 1;
985
- if ((starts[mid] ?? 0) <= offset) low = mid;
986
- else high = mid - 1;
987
- }
988
- return { line: low, column: offset - (starts[low] ?? 0) };
989
- };
990
- var sortedEdits = (edits) => [...edits].sort(compareEdits);
991
- var originalOffsetToGenerated = (originalOffset, edits) => {
992
- let generated = originalOffset;
993
- for (const edit of edits) {
994
- const delta = edit.text.length - edit.deleteCount;
995
- if (originalOffset >= edit.position + edit.deleteCount) generated += delta;
996
- else if (originalOffset >= edit.position) generated = edit.position + edit.text.length;
997
- }
998
- return generated;
999
- };
1000
- var mappingOffsets = (original, edits) => {
1001
- const offsets = /* @__PURE__ */ new Set([0, original.length]);
1002
- for (const start of lineStartsOf(original)) offsets.add(start);
1003
- for (const edit of edits) {
1004
- offsets.add(edit.position);
1005
- offsets.add(edit.position + edit.deleteCount);
1006
- }
1007
- return [...offsets].filter((offset) => offset >= 0 && offset <= original.length).sort((left, right) => left - right);
1008
- };
1009
- var encodeColumnMappings = (original, generated, file, edits) => {
1010
- const upstream = upstreamTraceMap(original);
1011
- const sources = (upstream?.sources.filter((source) => Boolean(source)) ?? [file]).filter((source, index, all) => all.indexOf(source) === index);
1012
- if (sources.length === 0) sources.push(file);
1013
- const applied = sortedEdits(edits);
1014
- const originalStarts = lineStartsOf(original);
1015
- const generatedStarts = lineStartsOf(generated);
1016
- const pointsByLine = Array.from({ length: generatedStarts.length }, () => []);
1017
- const seen = /* @__PURE__ */ new Set();
1018
- for (const originalOffset of mappingOffsets(original, edits)) {
1019
- const generatedOffset = Math.min(
1020
- originalOffsetToGenerated(originalOffset, applied),
1021
- generated.length
1022
- );
1023
- const originalPosition = positionAt(originalStarts, originalOffset);
1024
- const generatedPosition = positionAt(generatedStarts, generatedOffset);
1025
- let sourceIndex = 0;
1026
- let mappedLine = originalPosition.line;
1027
- let mappedColumn = originalPosition.column;
1028
- if (upstream) {
1029
- const mapped = originalPositionFor2(upstream, {
1030
- line: originalPosition.line + 1,
1031
- column: originalPosition.column
1032
- });
1033
- if (mapped.source && mapped.line != null && mapped.column != null) {
1034
- const index = sources.indexOf(mapped.source);
1035
- sourceIndex = index >= 0 ? index : 0;
1036
- mappedLine = mapped.line - 1;
1037
- mappedColumn = mapped.column;
1038
- }
1039
- }
1040
- const key = `${generatedPosition.line}:${generatedPosition.column}`;
1041
- if (seen.has(key)) continue;
1042
- seen.add(key);
1043
- pointsByLine[generatedPosition.line]?.push({
1044
- generatedColumn: generatedPosition.column,
1045
- sourceIndex,
1046
- originalLine: mappedLine,
1047
- originalColumn: mappedColumn
1048
- });
1049
- }
1050
- const lines = pointsByLine.map((segments) => {
1051
- segments.sort((left, right) => left.generatedColumn - right.generatedColumn);
1052
- let lastGeneratedColumn = 0;
1053
- let lastSourceIndex = 0;
1054
- let lastOriginalLine = 0;
1055
- let lastOriginalColumn = 0;
1056
- return segments.map((point) => {
1057
- const encoded = `${encodeVlq(point.generatedColumn - lastGeneratedColumn)}${encodeVlq(point.sourceIndex - lastSourceIndex)}${encodeVlq(point.originalLine - lastOriginalLine)}${encodeVlq(point.originalColumn - lastOriginalColumn)}`;
1058
- lastGeneratedColumn = point.generatedColumn;
1059
- lastSourceIndex = point.sourceIndex;
1060
- lastOriginalLine = point.originalLine;
1061
- lastOriginalColumn = point.originalColumn;
1062
- return encoded;
1063
- }).join(",");
1064
- });
1065
- return { sources, mappings: lines.join(";") };
1066
- };
1067
- var attachInlineSourceMap = (original, generated, filePath, edits) => {
1068
- const file = basename(filePath);
1069
- const withoutUpstream = generated.replace(SOURCEMAP_COMMENT, "");
1070
- const { sources, mappings } = encodeColumnMappings(original, withoutUpstream, file, edits);
1071
- const comment = `/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
1072
- JSON.stringify({ version: 3, file, sources, mappings })
1073
- ).toString("base64")} */`;
1074
- return withoutUpstream.endsWith("\n") ? `${withoutUpstream.slice(0, -1)}${comment}
1075
- ` : `${withoutUpstream}${comment}`;
1076
- };
1077
1290
  var insertAfterSuperOrPrologue = (body, sourceFile) => {
1078
1291
  const end = functionBodyPrologueEnd(body, sourceFile);
1079
1292
  for (const statement of body.statements) {
1080
1293
  if (isDirectivePrologue(statement)) continue;
1081
- if (ts6.isExpressionStatement(statement) && ts6.isCallExpression(statement.expression) && statement.expression.expression.kind === ts6.SyntaxKind.SuperKeyword) {
1294
+ if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
1082
1295
  return statement.end;
1083
1296
  }
1084
1297
  break;
@@ -1089,15 +1302,15 @@ var failEpilogue = (handleName, errorName, args, restoreOnCatch) => `}catch(${er
1089
1302
  var walkOwnBody = (node, visitNode) => {
1090
1303
  if (!node.body) return;
1091
1304
  const visit = (candidate) => {
1092
- if (candidate !== node && ts6.isFunctionLike(candidate)) return;
1305
+ if (candidate !== node && ts9.isFunctionLike(candidate)) return;
1093
1306
  visitNode(candidate);
1094
- ts6.forEachChild(candidate, visit);
1307
+ ts9.forEachChild(candidate, visit);
1095
1308
  };
1096
1309
  visit(node.body);
1097
1310
  };
1098
1311
  var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
1099
1312
  walkOwnBody(node, (candidate) => {
1100
- if (!ts6.isAwaitExpression(candidate)) return;
1313
+ if (!ts9.isAwaitExpression(candidate)) return;
1101
1314
  wrap(
1102
1315
  edits,
1103
1316
  candidate.expression.getStart(sourceFile),
@@ -1118,7 +1331,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
1118
1331
  };
1119
1332
  var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
1120
1333
  walkOwnBody(node, (candidate) => {
1121
- if (!ts6.isTryStatement(candidate)) return;
1334
+ if (!ts9.isTryStatement(candidate)) return;
1122
1335
  const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
1123
1336
  for (const block of blocks) {
1124
1337
  if (!block) continue;
@@ -1134,10 +1347,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
1134
1347
  });
1135
1348
  };
1136
1349
  var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
1137
- if (!node.body || !ts6.isBlock(node.body)) return;
1350
+ if (!node.body || !ts9.isBlock(node.body)) return;
1138
1351
  const visit = (candidate, at) => {
1139
- if (candidate !== node && ts6.isFunctionLike(candidate)) return;
1140
- if (ts6.isReturnStatement(candidate) && candidate.expression) {
1352
+ if (candidate !== node && ts9.isFunctionLike(candidate)) return;
1353
+ if (ts9.isReturnStatement(candidate) && candidate.expression) {
1141
1354
  const expression = candidate.expression;
1142
1355
  wrap(
1143
1356
  edits,
@@ -1149,17 +1362,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
1149
1362
  );
1150
1363
  return;
1151
1364
  }
1152
- ts6.forEachChild(candidate, (child) => visit(child, at + 1));
1365
+ ts9.forEachChild(candidate, (child) => visit(child, at + 1));
1153
1366
  };
1154
1367
  visit(node.body, depth + 1);
1155
1368
  };
1156
1369
  var transformSource = (source, options) => {
1157
1370
  if (source.includes("@rasputin-ignore-file")) return void 0;
1158
1371
  if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
1159
- const sourceFile = ts6.createSourceFile(
1372
+ const sourceFile = ts9.createSourceFile(
1160
1373
  options.filePath,
1161
1374
  source,
1162
- ts6.ScriptTarget.Latest,
1375
+ ts9.ScriptTarget.Latest,
1163
1376
  true,
1164
1377
  scriptKindFor3(options.filePath)
1165
1378
  );
@@ -1167,7 +1380,7 @@ var transformSource = (source, options) => {
1167
1380
  const plansName = uniqueName(source, "__rasputinPlans__");
1168
1381
  const handleName = uniqueName(source, "__rasputinH__");
1169
1382
  const errorName = uniqueName(source, "__rasputinE__");
1170
- const absolutePath = resolve4(options.filePath);
1383
+ const absolutePath = resolve3(options.filePath);
1171
1384
  const edits = [];
1172
1385
  const delta = {
1173
1386
  functions: [],
@@ -1202,7 +1415,7 @@ var transformSource = (source, options) => {
1202
1415
  collected.asyncFunction = true;
1203
1416
  skipFunction(collected, "unsupported_async_generator");
1204
1417
  }
1205
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1418
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1206
1419
  return;
1207
1420
  }
1208
1421
  if (isSyncGeneratorLike(node) && node.body) {
@@ -1213,10 +1426,10 @@ var transformSource = (source, options) => {
1213
1426
  options.mapLocation
1214
1427
  );
1215
1428
  if (collected) skipFunction(collected, "unsupported_sync_generator");
1216
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1429
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1217
1430
  return;
1218
1431
  }
1219
- if (ts6.isConstructorDeclaration(node) && node.body) {
1432
+ if (ts9.isConstructorDeclaration(node) && node.body) {
1220
1433
  const collected = collectWrappedFunction(
1221
1434
  node,
1222
1435
  sourceFile,
@@ -1224,13 +1437,13 @@ var transformSource = (source, options) => {
1224
1437
  options.mapLocation
1225
1438
  );
1226
1439
  if (collected) skipFunction(collected, "unsupported_constructor");
1227
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1440
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1228
1441
  return;
1229
1442
  }
1230
1443
  if (isSupportedFunction(node)) {
1231
1444
  const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
1232
1445
  if (!collected) {
1233
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1446
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1234
1447
  return;
1235
1448
  }
1236
1449
  const asyncFunction = isAsyncFunctionLike(node);
@@ -1238,7 +1451,7 @@ var transformSource = (source, options) => {
1238
1451
  const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
1239
1452
  if (decision.action === "skip") {
1240
1453
  skipFunction(collected, decision.reason);
1241
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1454
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1242
1455
  return;
1243
1456
  }
1244
1457
  if (functionHasPreBodyParameterEvaluation(node)) {
@@ -1251,29 +1464,29 @@ var transformSource = (source, options) => {
1251
1464
  suspendResume: decision.action === "suspend_resume"
1252
1465
  });
1253
1466
  delta.functions.push(collected);
1254
- ts6.forEachChild(node, (child) => visit(child, collected, depth + 1));
1467
+ ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
1255
1468
  return;
1256
1469
  }
1257
- if (caller && (ts6.isCallExpression(node) || ts6.isNewExpression(node))) {
1470
+ if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
1258
1471
  const site = collectCallSite(node, caller, collectContext);
1259
1472
  if (site) delta.callSites.push(site);
1260
1473
  }
1261
- if (caller && ts6.isVariableDeclaration(node)) {
1474
+ if (caller && ts9.isVariableDeclaration(node)) {
1262
1475
  const destructure = collectParamDestructure(node, caller, collectContext);
1263
1476
  if (destructure) delta.destructures.push(destructure);
1264
1477
  }
1265
- ts6.forEachChild(node, (child) => visit(child, caller, depth + 1));
1478
+ ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1266
1479
  };
1267
1480
  visit(sourceFile, void 0, 0);
1268
1481
  if (pending.length === 0) {
1269
1482
  return delta.functions.length > 0 ? { code: source, delta } : void 0;
1270
1483
  }
1271
1484
  for (const [planIndex, entry] of pending.entries()) {
1272
- const captured = ts6.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
1485
+ const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
1273
1486
  const omitArg = captured.omitValues ? ",true" : "";
1274
1487
  const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
1275
1488
  const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
1276
- if (ts6.isBlock(entry.node.body)) {
1489
+ if (ts9.isBlock(entry.node.body)) {
1277
1490
  const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
1278
1491
  const closeAt = entry.node.body.end - 1;
1279
1492
  wrap(
@@ -1327,12 +1540,7 @@ var transformSource = (source, options) => {
1327
1540
  width: 0,
1328
1541
  kind: "replace"
1329
1542
  });
1330
- edits.sort(compareEdits);
1331
- let transformed = source;
1332
- for (const edit of edits) {
1333
- const text = separateFromPreviousToken(transformed, edit.position, edit.text);
1334
- transformed = `${transformed.slice(0, edit.position)}${text}${transformed.slice(edit.position + edit.deleteCount)}`;
1335
- }
1543
+ const transformed = applyEdits(source, edits);
1336
1544
  const verify = options.verifyTransform ?? true;
1337
1545
  const refuseTransformed = () => {
1338
1546
  for (const entry of pending) {
@@ -1360,7 +1568,65 @@ var transformSource = (source, options) => {
1360
1568
  if (verify && !instrumentationTreesAreIsomorphic(options.filePath, source, transformed)) {
1361
1569
  return refuseTransformed();
1362
1570
  }
1363
- return { code: attachInlineSourceMap(source, transformed, options.filePath, edits), delta };
1571
+ return {
1572
+ code: attachInlineSourceMap(source, transformed, options.filePath, edits, basename),
1573
+ delta
1574
+ };
1575
+ };
1576
+
1577
+ // ../instrumentation/src/json-producer-sites.ts
1578
+ import ts11 from "typescript";
1579
+
1580
+ // ../instrumentation/src/literal-sites.ts
1581
+ import ts12 from "typescript";
1582
+
1583
+ // ../instrumentation/src/observe-sites.ts
1584
+ import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
1585
+ import ts13 from "typescript";
1586
+
1587
+ // ../instrumentation/src/verify-browser-source.ts
1588
+ import ts14 from "typescript";
1589
+
1590
+ // ../instrumentation/src/provenance-function-edits.ts
1591
+ import ts15 from "typescript";
1592
+
1593
+ // ../instrumentation/src/source-map-location.ts
1594
+ import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
1595
+
1596
+ // src/sdk-meta.ts
1597
+ var SDK_VERSION = "0.6.0";
1598
+
1599
+ // src/auto-instrumentation/source-map-locations.ts
1600
+ import { readFileSync } from "node:fs";
1601
+ import { dirname, isAbsolute as isAbsolute2, join, resolve as resolve4 } from "node:path";
1602
+ import { fileURLToPath, pathToFileURL } from "node:url";
1603
+ import { LEAST_UPPER_BOUND, originalPositionFor as originalPositionFor3, TraceMap as TraceMap4 } from "@jridgewell/trace-mapping";
1604
+ var sourceMapComment = /(?:\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)|\/\*[#@][ \t]*sourceMappingURL=([^\s*'"]+)[ \t]*\*\/)\s*$/;
1605
+ var decodeDataUrl = (url) => {
1606
+ const base64 = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.+)$/i.exec(url);
1607
+ if (base64?.[1]) return Buffer.from(base64[1], "base64").toString("utf8");
1608
+ const raw = /^data:application\/json(?:;charset=[^;,]+)?,(.+)$/i.exec(url);
1609
+ return raw?.[1] ? decodeURIComponent(raw[1]) : void 0;
1610
+ };
1611
+ var sourceMapFor = (generatedPath, source) => {
1612
+ const match = sourceMapComment.exec(source);
1613
+ const reference = match?.[1] ?? match?.[2];
1614
+ if (reference?.startsWith("data:")) {
1615
+ const payload = decodeDataUrl(reference);
1616
+ return payload ? { payload, mapUrl: pathToFileURL(generatedPath).href } : void 0;
1617
+ }
1618
+ const mapPath = reference ? resolve4(dirname(generatedPath), reference) : `${generatedPath}.map`;
1619
+ return {
1620
+ payload: readFileSync(mapPath, "utf8"),
1621
+ mapUrl: pathToFileURL(mapPath).href
1622
+ };
1623
+ };
1624
+ var sourceMapPayloadForCache = (generatedPath, source) => {
1625
+ try {
1626
+ return sourceMapFor(generatedPath, source)?.payload ?? "";
1627
+ } catch {
1628
+ return "";
1629
+ }
1364
1630
  };
1365
1631
 
1366
1632
  // src/auto-instrumentation/transform-disk-cache.ts