@rasputin-ai/node 0.16.0 → 1.0.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 (33) hide show
  1. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
  2. package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts.map +1 -1
  3. package/dist/create-rasputin-runtime.d.ts +72 -0
  4. package/dist/create-rasputin-runtime.d.ts.map +1 -0
  5. package/dist/execution-metrics/encode-execution-metrics-upload.d.ts.map +1 -1
  6. package/dist/execution-metrics/execution-metrics-collector.d.ts +3 -3
  7. package/dist/execution-metrics/execution-metrics-collector.d.ts.map +1 -1
  8. package/dist/execution-recorder/adaptive-recording-options.d.ts +3 -0
  9. package/dist/execution-recorder/adaptive-recording-options.d.ts.map +1 -1
  10. package/dist/execution-recorder/bind-adaptive-recorder.d.ts.map +1 -1
  11. package/dist/execution-recorder/execution-journal.d.ts +16 -1
  12. package/dist/execution-recorder/execution-journal.d.ts.map +1 -1
  13. package/dist/execution-recorder/execution-recorder-types.d.ts +18 -13
  14. package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
  15. package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
  16. package/dist/execution-recorder/execution-recording-sync.d.ts +0 -1
  17. package/dist/execution-recorder/execution-recording-sync.d.ts.map +1 -1
  18. package/dist/execution-recorder/runtime-state-size-budget.d.ts +3 -3
  19. package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
  20. package/dist/function-metrics/create-metrics-only-runtime.d.ts.map +1 -1
  21. package/dist/function-metrics/function-metrics-collector.d.ts.map +1 -1
  22. package/dist/index.js +878 -412
  23. package/dist/instrument/build.js +211 -355
  24. package/dist/instrument/bun.js +135 -246
  25. package/dist/instrument/node.js +135 -246
  26. package/dist/internal.d.ts +2 -0
  27. package/dist/internal.d.ts.map +1 -1
  28. package/dist/internal.js +983 -341
  29. package/dist/rasputin-init.d.ts +7 -60
  30. package/dist/rasputin-init.d.ts.map +1 -1
  31. package/dist/sdk-meta.d.ts +1 -1
  32. package/dist/sdk-meta.d.ts.map +1 -1
  33. package/package.json +3 -3
@@ -5,61 +5,6 @@ import {
5
5
  hashInstrumentationManifest
6
6
  } from "@rasputin-ai/core";
7
7
 
8
- // ../recorder/src/encoded-function-plan.ts
9
- var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
10
- var withPreBodyParameterEvaluation = (plan) => [
11
- plan[0],
12
- plan[1],
13
- plan[2],
14
- plan[3],
15
- plan[4],
16
- plan[5],
17
- plan[6],
18
- 1
19
- ];
20
-
21
- // ../recorder/src/function-plan.ts
22
- import {
23
- runtimeFunctionId,
24
- sourceLocatorFromFile
25
- } from "@rasputin-ai/core";
26
- var encodeFunctionPlan = (source) => {
27
- const locator = sourceLocatorFromFile(source.filePath);
28
- const definition = {
29
- name: source.name,
30
- ...locator ? { source: { ...locator, line: source.line, column: source.column } } : {}
31
- };
32
- return [
33
- runtimeFunctionId(definition),
34
- source.name,
35
- locator?.packageName ?? null,
36
- locator?.packageRelativePath ?? null,
37
- source.line,
38
- source.column
39
- ];
40
- };
41
- var definitionFromEncodedPlan = (plan) => {
42
- const [functionId, name, packageName, packageRelativePath, line, column] = plan;
43
- const source = packageRelativePath ? {
44
- ...packageName ? { packageName } : {},
45
- packageRelativePath,
46
- ...line == null ? {} : { line },
47
- ...column == null ? {} : { column }
48
- } : void 0;
49
- return {
50
- functionId,
51
- name,
52
- ...source ? { source } : {},
53
- ...encodedPlanHasPreBodyParameterEvaluation(plan) ? { parentAttribution: "pre_body_parameter_evaluation" } : {}
54
- };
55
- };
56
-
57
- // ../recorder/src/runtime-symbol.ts
58
- var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
59
-
60
- // ../instrumentation/src/classify-function.ts
61
- import ts3 from "typescript";
62
-
63
8
  // ../instrumentation/src/collect-instrumentation-delta.ts
64
9
  import ts from "typescript";
65
10
  var paramBindingFromName = (name, sourceFile) => {
@@ -128,91 +73,6 @@ var mappedLocation = (sourceFile, position, absolutePath, mapLocation) => {
128
73
  };
129
74
  return mapLocation ? mapLocation(raw) : raw;
130
75
  };
131
- var unwrapExpression = (expression) => {
132
- let current = expression;
133
- while (ts.isParenthesizedExpression(current) || ts.isNonNullExpression(current)) {
134
- current = current.expression;
135
- }
136
- if (ts.isAwaitExpression(current)) return unwrapExpression(current.expression);
137
- return current;
138
- };
139
- var calleeFromExpression = (expression, sourceFile) => {
140
- const current = unwrapExpression(expression);
141
- if (ts.isIdentifier(current)) {
142
- return { calleeName: current.text, calleeText: current.text };
143
- }
144
- if (ts.isPropertyAccessExpression(current) && ts.isIdentifier(current.name)) {
145
- return {
146
- calleeName: current.name.text,
147
- calleeText: current.getText(sourceFile).replace(/\s+/g, "")
148
- };
149
- }
150
- return null;
151
- };
152
- var resultBindingForCall = (call) => {
153
- let node = call.parent;
154
- if (ts.isAwaitExpression(node)) node = node.parent;
155
- if (!ts.isVariableDeclaration(node)) return null;
156
- if (!ts.isIdentifier(node.name)) return null;
157
- const initializer = node.initializer;
158
- if (!initializer) return null;
159
- const inner = unwrapExpression(initializer);
160
- if (inner !== call) return null;
161
- return node.name.text;
162
- };
163
- var argIdentifiersForCall = (call) => {
164
- const identifiers = [];
165
- call.arguments?.forEach((argument, index) => {
166
- if (ts.isIdentifier(argument)) {
167
- identifiers.push({ index, kind: "identifier", name: argument.text });
168
- return;
169
- }
170
- if (!ts.isObjectLiteralExpression(argument)) return;
171
- const properties = [];
172
- for (const property of argument.properties) {
173
- if (ts.isShorthandPropertyAssignment(property)) {
174
- properties.push({ key: property.name.text, name: property.name.text });
175
- continue;
176
- }
177
- if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && ts.isIdentifier(property.initializer)) {
178
- properties.push({ key: property.name.text, name: property.initializer.text });
179
- }
180
- }
181
- if (properties.length > 0) {
182
- identifiers.push({ index, kind: "object", properties });
183
- }
184
- });
185
- return identifiers;
186
- };
187
- var collectCallSite = (call, caller, context) => {
188
- const callee = calleeFromExpression(call.expression, context.sourceFile);
189
- if (!callee) return null;
190
- const start = mappedLocation(
191
- context.sourceFile,
192
- call.getStart(context.sourceFile),
193
- context.absolutePath,
194
- context.mapLocation
195
- );
196
- const end = mappedLocation(
197
- context.sourceFile,
198
- call.end,
199
- context.absolutePath,
200
- context.mapLocation
201
- );
202
- if (!start || !end) return null;
203
- return {
204
- callerFunctionId: caller.functionId,
205
- calleeName: callee.calleeName,
206
- calleeText: callee.calleeText,
207
- filePath: start.filePath,
208
- line: start.line,
209
- column: start.column,
210
- endLine: end.line,
211
- endColumn: end.column,
212
- resultBinding: resultBindingForCall(call),
213
- argIdentifiers: argIdentifiersForCall(call)
214
- };
215
- };
216
76
  var collectParamDestructure = (declaration, caller, context) => {
217
77
  if (!declaration.initializer || !ts.isIdentifier(declaration.initializer)) return null;
218
78
  if (!ts.isObjectBindingPattern(declaration.name) && !ts.isArrayBindingPattern(declaration.name)) {
@@ -237,9 +97,6 @@ var collectParamDestructure = (declaration, caller, context) => {
237
97
  };
238
98
  };
239
99
 
240
- // ../instrumentation/src/parse-source.ts
241
- import ts2 from "typescript";
242
-
243
100
  // ../instrumentation/src/edits.ts
244
101
  var isIdentContinue = (code) => code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
245
102
  var isIdentStart = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122 || code === 36 || code === 95;
@@ -681,9 +538,43 @@ var withFunctionMetricDeclarationRegistration = (code, declarations) => {
681
538
  return `${code.slice(0, match.index)}${suffix}${code.slice(match.index)}`;
682
539
  };
683
540
 
684
- // ../instrumentation/src/browser-function-edits.ts
685
- import { propertyNameIsSensitive } from "@rasputin-ai/core";
686
- import ts10 from "typescript";
541
+ // ../instrumentation/src/parameter-initializer-may-run-code.ts
542
+ import ts2 from "typescript";
543
+ var unwrap = (expression) => {
544
+ let current = expression;
545
+ while (ts2.isParenthesizedExpression(current) || ts2.isNonNullExpression(current)) {
546
+ current = current.expression;
547
+ }
548
+ return current;
549
+ };
550
+ var isSafeLiteralInitializer = (expression) => {
551
+ const current = unwrap(expression);
552
+ if (ts2.isNumericLiteral(current) || ts2.isStringLiteral(current) || ts2.isNoSubstitutionTemplateLiteral(current) || ts2.isBigIntLiteral(current)) {
553
+ return true;
554
+ }
555
+ if (current.kind === ts2.SyntaxKind.TrueKeyword || current.kind === ts2.SyntaxKind.FalseKeyword || current.kind === ts2.SyntaxKind.NullKeyword) {
556
+ return true;
557
+ }
558
+ if (ts2.isIdentifier(current) && current.text === "undefined") return true;
559
+ if (ts2.isPrefixUnaryExpression(current) && (current.operator === ts2.SyntaxKind.PlusToken || current.operator === ts2.SyntaxKind.MinusToken)) {
560
+ return ts2.isNumericLiteral(unwrap(current.operand));
561
+ }
562
+ return false;
563
+ };
564
+ var functionHasPreBodyParameterEvaluation = (node) => {
565
+ for (const parameter of node.parameters) {
566
+ if (ts2.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
567
+ if (!parameter.initializer) continue;
568
+ if (!isSafeLiteralInitializer(parameter.initializer)) return true;
569
+ }
570
+ return false;
571
+ };
572
+
573
+ // ../instrumentation/src/parse-source.ts
574
+ import ts3 from "typescript";
575
+
576
+ // ../instrumentation/src/source-map-location.ts
577
+ import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
687
578
 
688
579
  // ../instrumentation/src/suspension-whitelist.ts
689
580
  import ts4 from "typescript";
@@ -814,7 +705,61 @@ var decideAsyncInstrumentation = (node, sourceFile) => {
814
705
 
815
706
  // ../instrumentation/src/transform-source.ts
816
707
  import { basename, resolve } from "node:path";
817
- import ts9 from "typescript";
708
+
709
+ // ../recorder/src/encoded-function-plan.ts
710
+ var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
711
+ var withPreBodyParameterEvaluation = (plan) => [
712
+ plan[0],
713
+ plan[1],
714
+ plan[2],
715
+ plan[3],
716
+ plan[4],
717
+ plan[5],
718
+ plan[6],
719
+ 1
720
+ ];
721
+
722
+ // ../recorder/src/function-plan.ts
723
+ import {
724
+ runtimeFunctionId,
725
+ sourceLocatorFromFile
726
+ } from "@rasputin-ai/core";
727
+ var encodeFunctionPlan = (source) => {
728
+ const locator = sourceLocatorFromFile(source.filePath);
729
+ const definition = {
730
+ name: source.name,
731
+ ...locator ? { source: { ...locator, line: source.line, column: source.column } } : {}
732
+ };
733
+ return [
734
+ runtimeFunctionId(definition),
735
+ source.name,
736
+ locator?.packageName ?? null,
737
+ locator?.packageRelativePath ?? null,
738
+ source.line,
739
+ source.column
740
+ ];
741
+ };
742
+ var definitionFromEncodedPlan = (plan) => {
743
+ const [functionId, name, packageName, packageRelativePath, line, column] = plan;
744
+ const source = packageRelativePath ? {
745
+ ...packageName ? { packageName } : {},
746
+ packageRelativePath,
747
+ ...line == null ? {} : { line },
748
+ ...column == null ? {} : { column }
749
+ } : void 0;
750
+ return {
751
+ functionId,
752
+ name,
753
+ ...source ? { source } : {},
754
+ ...encodedPlanHasPreBodyParameterEvaluation(plan) ? { parentAttribution: "pre_body_parameter_evaluation" } : {}
755
+ };
756
+ };
757
+
758
+ // ../recorder/src/runtime-symbol.ts
759
+ var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
760
+
761
+ // ../instrumentation/src/transform-source.ts
762
+ import ts8 from "typescript";
818
763
 
819
764
  // ../instrumentation/src/function-metric-declarations.ts
820
765
  import {
@@ -1068,57 +1013,25 @@ var collectFunctionMetricDeclarations = (input) => {
1068
1013
  return declarations;
1069
1014
  };
1070
1015
 
1071
- // ../instrumentation/src/parameter-initializer-may-run-code.ts
1072
- import ts6 from "typescript";
1073
- var unwrap = (expression) => {
1074
- let current = expression;
1075
- while (ts6.isParenthesizedExpression(current) || ts6.isNonNullExpression(current)) {
1076
- current = current.expression;
1077
- }
1078
- return current;
1079
- };
1080
- var isSafeLiteralInitializer = (expression) => {
1081
- const current = unwrap(expression);
1082
- if (ts6.isNumericLiteral(current) || ts6.isStringLiteral(current) || ts6.isNoSubstitutionTemplateLiteral(current) || ts6.isBigIntLiteral(current)) {
1083
- return true;
1084
- }
1085
- if (current.kind === ts6.SyntaxKind.TrueKeyword || current.kind === ts6.SyntaxKind.FalseKeyword || current.kind === ts6.SyntaxKind.NullKeyword) {
1086
- return true;
1087
- }
1088
- if (ts6.isIdentifier(current) && current.text === "undefined") return true;
1089
- if (ts6.isPrefixUnaryExpression(current) && (current.operator === ts6.SyntaxKind.PlusToken || current.operator === ts6.SyntaxKind.MinusToken)) {
1090
- return ts6.isNumericLiteral(unwrap(current.operand));
1091
- }
1092
- return false;
1093
- };
1094
- var functionHasPreBodyParameterEvaluation = (node) => {
1095
- for (const parameter of node.parameters) {
1096
- if (ts6.isIdentifier(parameter.name) && parameter.name.text === "this") continue;
1097
- if (!parameter.initializer) continue;
1098
- if (!isSafeLiteralInitializer(parameter.initializer)) return true;
1099
- }
1100
- return false;
1101
- };
1102
-
1103
1016
  // ../instrumentation/src/verify-instrumentation-isomorphism.ts
1104
- import ts7 from "typescript";
1017
+ import ts6 from "typescript";
1105
1018
  var RASPUTIN_IDENT = /^__rasputin/;
1106
1019
  var scriptKindFor = (filePath) => {
1107
- if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
1108
- if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
1109
- if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
1110
- return ts7.ScriptKind.JS;
1020
+ if (/\.tsx$/i.test(filePath)) return ts6.ScriptKind.TSX;
1021
+ if (/\.jsx$/i.test(filePath)) return ts6.ScriptKind.JSX;
1022
+ if (/\.[cm]?ts$/i.test(filePath)) return ts6.ScriptKind.TS;
1023
+ return ts6.ScriptKind.JS;
1111
1024
  };
1112
- var parse = (filePath, source) => ts7.createSourceFile(filePath, source, ts7.ScriptTarget.Latest, true, scriptKindFor(filePath));
1025
+ var parse = (filePath, source) => ts6.createSourceFile(filePath, source, ts6.ScriptTarget.Latest, true, scriptKindFor(filePath));
1113
1026
  var isRasputinName = (name) => RASPUTIN_IDENT.test(name);
1114
1027
  var identText = (node) => {
1115
- if (ts7.isIdentifier(node)) return node.text;
1116
- if (ts7.isPrivateIdentifier(node)) return node.text;
1028
+ if (ts6.isIdentifier(node)) return node.text;
1029
+ if (ts6.isPrivateIdentifier(node)) return node.text;
1117
1030
  return void 0;
1118
1031
  };
1119
1032
  var calleeName = (expression) => {
1120
- if (ts7.isIdentifier(expression)) return expression.text;
1121
- if (ts7.isPropertyAccessExpression(expression)) {
1033
+ if (ts6.isIdentifier(expression)) return expression.text;
1034
+ if (ts6.isPropertyAccessExpression(expression)) {
1122
1035
  const object = identText(expression.expression);
1123
1036
  const property = identText(expression.name);
1124
1037
  if (object && isRasputinName(object) && property) return `${object}.${property}`;
@@ -1126,7 +1039,7 @@ var calleeName = (expression) => {
1126
1039
  return void 0;
1127
1040
  };
1128
1041
  var isRasputinCall = (node, methods) => {
1129
- if (!ts7.isCallExpression(node)) return false;
1042
+ if (!ts6.isCallExpression(node)) return false;
1130
1043
  const name = calleeName(node.expression);
1131
1044
  if (!name) return false;
1132
1045
  if (isRasputinName(name)) return !methods || methods.has(name.split(".")[1] ?? "");
@@ -1136,20 +1049,20 @@ var unwrapCall = (node) => {
1136
1049
  let current = node;
1137
1050
  while (isRasputinCall(current) && current.arguments.length === 1 && current.arguments[0]) {
1138
1051
  current = current.arguments[0];
1139
- if (ts7.isParenthesizedExpression(current)) current = current.expression;
1052
+ if (ts6.isParenthesizedExpression(current)) current = current.expression;
1140
1053
  }
1141
- if (ts7.isParenthesizedExpression(current)) return current.expression;
1054
+ if (ts6.isParenthesizedExpression(current)) return current.expression;
1142
1055
  return current;
1143
1056
  };
1144
1057
  var isRasputinStatement = (node) => {
1145
- if (ts7.isEmptyStatement(node)) return true;
1146
- if (ts7.isVariableStatement(node)) {
1058
+ if (ts6.isEmptyStatement(node)) return true;
1059
+ if (ts6.isVariableStatement(node)) {
1147
1060
  return node.declarationList.declarations.every((declaration) => {
1148
1061
  const name = identText(declaration.name);
1149
1062
  return Boolean(name && isRasputinName(name));
1150
1063
  });
1151
1064
  }
1152
- if (ts7.isExpressionStatement(node)) {
1065
+ if (ts6.isExpressionStatement(node)) {
1153
1066
  if (!isRasputinCall(node.expression)) return false;
1154
1067
  const unwrapped = unwrapCall(node.expression);
1155
1068
  return unwrapped === node.expression;
@@ -1163,7 +1076,7 @@ var isRasputinTryWrapper = (node) => {
1163
1076
  (statement) => !isRasputinStatement(statement)
1164
1077
  );
1165
1078
  const leftover = catchCalls[0];
1166
- const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts7.isThrowStatement(leftover) && ts7.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
1079
+ const leftoverThrow = catchCalls.length === 1 && leftover !== void 0 && ts6.isThrowStatement(leftover) && ts6.isIdentifier(leftover.expression) && isRasputinName(leftover.expression.text);
1167
1080
  if (!leftoverThrow && catchCalls.length > 0) return false;
1168
1081
  return node.finallyBlock.statements.every((statement) => isRasputinStatement(statement));
1169
1082
  };
@@ -1171,7 +1084,7 @@ var flattenStatements = (statements) => {
1171
1084
  const flattened = [];
1172
1085
  for (const statement of statements) {
1173
1086
  if (isRasputinStatement(statement)) continue;
1174
- if (ts7.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
1087
+ if (ts6.isTryStatement(statement) && isRasputinTryWrapper(statement)) {
1175
1088
  flattened.push(...flattenStatements(statement.tryBlock.statements));
1176
1089
  continue;
1177
1090
  }
@@ -1180,38 +1093,38 @@ var flattenStatements = (statements) => {
1180
1093
  return flattened;
1181
1094
  };
1182
1095
  var extra = (node) => {
1183
- if (ts7.isIdentifier(node) || ts7.isPrivateIdentifier(node)) {
1096
+ if (ts6.isIdentifier(node) || ts6.isPrivateIdentifier(node)) {
1184
1097
  return isRasputinName(node.text) ? "" : node.text;
1185
1098
  }
1186
- if (ts7.isStringLiteral(node) || ts7.isNumericLiteral(node) || ts7.isNoSubstitutionTemplateLiteral(node)) {
1099
+ if (ts6.isStringLiteral(node) || ts6.isNumericLiteral(node) || ts6.isNoSubstitutionTemplateLiteral(node)) {
1187
1100
  return node.text;
1188
1101
  }
1189
- if (ts7.isToken(node) && !ts7.isIdentifier(node)) return ts7.SyntaxKind[node.kind] ?? "";
1102
+ if (ts6.isToken(node) && !ts6.isIdentifier(node)) return ts6.SyntaxKind[node.kind] ?? "";
1190
1103
  return "";
1191
1104
  };
1192
1105
  var signatureOf = (node) => {
1193
1106
  const unwrapped = unwrapCall(node);
1194
1107
  if (unwrapped !== node) return signatureOf(unwrapped);
1195
- if (ts7.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
1196
- if (ts7.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
1108
+ if (ts6.isEmptyStatement(unwrapped) || isRasputinStatement(unwrapped)) return "";
1109
+ if (ts6.isTryStatement(unwrapped) && isRasputinTryWrapper(unwrapped)) {
1197
1110
  return flattenStatements(unwrapped.tryBlock.statements).map(signatureOf).filter(Boolean).join("");
1198
1111
  }
1199
- if (ts7.isBlock(unwrapped)) {
1112
+ if (ts6.isBlock(unwrapped)) {
1200
1113
  const statements = flattenStatements(unwrapped.statements);
1201
1114
  return `Block[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
1202
1115
  }
1203
- if (ts7.isCatchClause(unwrapped)) {
1116
+ if (ts6.isCatchClause(unwrapped)) {
1204
1117
  const statements = flattenStatements(unwrapped.block.statements);
1205
1118
  const variable = unwrapped.variableDeclaration ? signatureOf(unwrapped.variableDeclaration) : "";
1206
1119
  return `Catch${variable}[${statements.map(signatureOf).filter(Boolean).join(",")}]`;
1207
1120
  }
1208
- if (ts7.isArrowFunction(unwrapped) && ts7.isBlock(unwrapped.body)) {
1121
+ if (ts6.isArrowFunction(unwrapped) && ts6.isBlock(unwrapped.body)) {
1209
1122
  const statements = flattenStatements(unwrapped.body.statements);
1210
1123
  const only = statements[0];
1211
- if (statements.length === 1 && only && ts7.isReturnStatement(only) && only.expression) {
1124
+ if (statements.length === 1 && only && ts6.isReturnStatement(only) && only.expression) {
1212
1125
  const expression = only.expression;
1213
1126
  const parts2 = [];
1214
- ts7.forEachChild(unwrapped, (child) => {
1127
+ ts6.forEachChild(unwrapped, (child) => {
1215
1128
  if (child === unwrapped.body) {
1216
1129
  const part2 = signatureOf(expression);
1217
1130
  if (part2) parts2.push(part2);
@@ -1224,11 +1137,11 @@ var signatureOf = (node) => {
1224
1137
  }
1225
1138
  }
1226
1139
  const parts = [];
1227
- ts7.forEachChild(unwrapped, (child) => {
1140
+ ts6.forEachChild(unwrapped, (child) => {
1228
1141
  const part = signatureOf(child);
1229
1142
  if (part) parts.push(part);
1230
1143
  });
1231
- const kind = ts7.SyntaxKind[unwrapped.kind] ?? "Node";
1144
+ const kind = ts6.SyntaxKind[unwrapped.kind] ?? "Node";
1232
1145
  const label = extra(unwrapped);
1233
1146
  return `${kind}${label}[${parts.join(",")}]`;
1234
1147
  };
@@ -1237,14 +1150,14 @@ var instrumentationTreesAreIsomorphic = (filePath, original, transformed) => {
1237
1150
  };
1238
1151
 
1239
1152
  // ../instrumentation/src/verify-transformed-source.ts
1240
- import ts8 from "typescript";
1241
- var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
1153
+ import ts7 from "typescript";
1154
+ var transpileForVerification = (filePath, code) => ts7.transpileModule(code, {
1242
1155
  compilerOptions: {
1243
1156
  // ES2020 downlevel keeps native @decorators out of `new Function`.
1244
- target: ts8.ScriptTarget.ES2020,
1245
- module: ts8.ModuleKind.ESNext,
1157
+ target: ts7.ScriptTarget.ES2020,
1158
+ module: ts7.ModuleKind.ESNext,
1246
1159
  allowJs: true,
1247
- jsx: ts8.JsxEmit.React,
1160
+ jsx: ts7.JsxEmit.React,
1248
1161
  experimentalDecorators: true
1249
1162
  },
1250
1163
  reportDiagnostics: true,
@@ -1252,7 +1165,7 @@ var transpileForVerification = (filePath, code) => ts8.transpileModule(code, {
1252
1165
  });
1253
1166
  var hasScanOrParseError = (diagnostics) => Boolean(
1254
1167
  diagnostics?.some(
1255
- (diagnostic) => diagnostic.category === ts8.DiagnosticCategory.Error && diagnostic.code < 2e3
1168
+ (diagnostic) => diagnostic.category === ts7.DiagnosticCategory.Error && diagnostic.code < 2e3
1256
1169
  )
1257
1170
  );
1258
1171
  var scriptBodyForEngine = (emitted) => (
@@ -1261,39 +1174,39 @@ var scriptBodyForEngine = (emitted) => (
1261
1174
  );
1262
1175
  var looksTyped = (filePath) => /\.[cm]?tsx?$/i.test(filePath);
1263
1176
  var scriptKindFor2 = (filePath) => {
1264
- if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
1265
- if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
1266
- if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
1267
- return ts8.ScriptKind.JS;
1177
+ if (/\.tsx$/i.test(filePath)) return ts7.ScriptKind.TSX;
1178
+ if (/\.jsx$/i.test(filePath)) return ts7.ScriptKind.JSX;
1179
+ if (/\.[cm]?ts$/i.test(filePath)) return ts7.ScriptKind.TS;
1180
+ return ts7.ScriptKind.JS;
1268
1181
  };
1269
- var isIterationStatement = (node) => ts8.isForStatement(node) || ts8.isForOfStatement(node) || ts8.isForInStatement(node) || ts8.isWhileStatement(node) || ts8.isDoStatement(node);
1182
+ var isIterationStatement = (node) => ts7.isForStatement(node) || ts7.isForOfStatement(node) || ts7.isForInStatement(node) || ts7.isWhileStatement(node) || ts7.isDoStatement(node);
1270
1183
  var unwrapLabeled = (node) => {
1271
1184
  let current = node;
1272
- while (ts8.isLabeledStatement(current)) current = current.statement;
1185
+ while (ts7.isLabeledStatement(current)) current = current.statement;
1273
1186
  return current;
1274
1187
  };
1275
1188
  var hasInvalidLabelJump = (sourceFile) => {
1276
1189
  const visit = (node, labels) => {
1277
- if (ts8.isFunctionLike(node)) {
1190
+ if (ts7.isFunctionLike(node)) {
1278
1191
  let nestedInvalid = false;
1279
- ts8.forEachChild(node, (child) => {
1192
+ ts7.forEachChild(node, (child) => {
1280
1193
  if (visit(child, /* @__PURE__ */ new Map())) nestedInvalid = true;
1281
1194
  });
1282
1195
  return nestedInvalid;
1283
1196
  }
1284
- if (ts8.isLabeledStatement(node)) {
1197
+ if (ts7.isLabeledStatement(node)) {
1285
1198
  const next = new Map(labels);
1286
1199
  next.set(node.label.text, isIterationStatement(unwrapLabeled(node.statement)));
1287
1200
  return visit(node.statement, next);
1288
1201
  }
1289
- if (ts8.isContinueStatement(node) && node.label) {
1202
+ if (ts7.isContinueStatement(node) && node.label) {
1290
1203
  if (labels.get(node.label.text) !== true) return true;
1291
1204
  }
1292
- if (ts8.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
1205
+ if (ts7.isBreakStatement(node) && node.label && !labels.has(node.label.text)) {
1293
1206
  return true;
1294
1207
  }
1295
1208
  let invalid = false;
1296
- ts8.forEachChild(node, (child) => {
1209
+ ts7.forEachChild(node, (child) => {
1297
1210
  if (visit(child, labels)) invalid = true;
1298
1211
  });
1299
1212
  return invalid;
@@ -1336,10 +1249,10 @@ var UNTERMINATED_BARE_LEAVE = /\breturn\s+__rasputin\w*\.leave\(\)(?!\s*;|\()/;
1336
1249
  var transformedSourceIsInvalid = (filePath, code) => {
1337
1250
  if (GLUED_INSTRUMENTATION.test(code)) return true;
1338
1251
  if (UNTERMINATED_BARE_LEAVE.test(code)) return true;
1339
- const sourceFile = ts8.createSourceFile(
1252
+ const sourceFile = ts7.createSourceFile(
1340
1253
  filePath,
1341
1254
  code,
1342
- ts8.ScriptTarget.Latest,
1255
+ ts7.ScriptTarget.Latest,
1343
1256
  true,
1344
1257
  scriptKindFor2(filePath)
1345
1258
  );
@@ -1360,25 +1273,25 @@ var alreadyInstrumentedResult = (source) => ({
1360
1273
  delta: { functions: [], callSites: [], destructures: [], alreadyInstrumented: true }
1361
1274
  });
1362
1275
  var scriptKindFor3 = (filePath) => {
1363
- if (/\.tsx$/i.test(filePath)) return ts9.ScriptKind.TSX;
1364
- if (/\.jsx$/i.test(filePath)) return ts9.ScriptKind.JSX;
1365
- if (/\.[cm]?ts$/i.test(filePath)) return ts9.ScriptKind.TS;
1366
- return ts9.ScriptKind.JS;
1276
+ if (/\.tsx$/i.test(filePath)) return ts8.ScriptKind.TSX;
1277
+ if (/\.jsx$/i.test(filePath)) return ts8.ScriptKind.JSX;
1278
+ if (/\.[cm]?ts$/i.test(filePath)) return ts8.ScriptKind.TS;
1279
+ return ts8.ScriptKind.JS;
1367
1280
  };
1368
1281
  var functionName = (node, sourceFile) => {
1369
- if (ts9.isConstructorDeclaration(node)) return "constructor";
1282
+ if (ts8.isConstructorDeclaration(node)) return "constructor";
1370
1283
  if (node.name) return node.name.getText(sourceFile).replace(/^['"]|['"]$/g, "");
1371
1284
  const parent = node.parent;
1372
- if (ts9.isVariableDeclaration(parent) && ts9.isIdentifier(parent.name)) return parent.name.text;
1373
- if (ts9.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
1374
- if (ts9.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
1285
+ if (ts8.isVariableDeclaration(parent) && ts8.isIdentifier(parent.name)) return parent.name.text;
1286
+ if (ts8.isPropertyAssignment(parent)) return parent.name.getText(sourceFile);
1287
+ if (ts8.isPropertyDeclaration(parent) && parent.name) return parent.name.getText(sourceFile);
1375
1288
  const location = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
1376
1289
  return `anonymous@${location.line + 1}:${location.character + 1}`;
1377
1290
  };
1378
1291
  var functionLocationPosition = (node, sourceFile) => {
1379
1292
  if (node.name) return node.name.getStart(sourceFile);
1380
1293
  const parent = node.parent;
1381
- if ((ts9.isVariableDeclaration(parent) || ts9.isPropertyAssignment(parent)) && parent.name) {
1294
+ if ((ts8.isVariableDeclaration(parent) || ts8.isPropertyAssignment(parent)) && parent.name) {
1382
1295
  return parent.name.getStart(sourceFile);
1383
1296
  }
1384
1297
  return node.getStart(sourceFile);
@@ -1391,12 +1304,12 @@ var functionBodyPrologueEnd = (body, sourceFile) => {
1391
1304
  }
1392
1305
  return end;
1393
1306
  };
1394
- var isStaticPropertyName = (name) => ts9.isIdentifier(name) || ts9.isStringLiteral(name) || ts9.isNoSubstitutionTemplateLiteral(name) || ts9.isNumericLiteral(name);
1307
+ var isStaticPropertyName = (name) => ts8.isIdentifier(name) || ts8.isStringLiteral(name) || ts8.isNoSubstitutionTemplateLiteral(name) || ts8.isNumericLiteral(name);
1395
1308
  var canReconstructBinding = (name) => {
1396
- if (ts9.isIdentifier(name)) return true;
1397
- if (ts9.isArrayBindingPattern(name)) {
1309
+ if (ts8.isIdentifier(name)) return true;
1310
+ if (ts8.isArrayBindingPattern(name)) {
1398
1311
  return name.elements.every(
1399
- (element) => ts9.isOmittedExpression(element) || canReconstructBinding(element.name)
1312
+ (element) => ts8.isOmittedExpression(element) || canReconstructBinding(element.name)
1400
1313
  );
1401
1314
  }
1402
1315
  return name.elements.every((element) => {
@@ -1405,10 +1318,10 @@ var canReconstructBinding = (name) => {
1405
1318
  });
1406
1319
  };
1407
1320
  var bindingValue = (name, sourceFile) => {
1408
- if (ts9.isIdentifier(name)) return name.text;
1409
- if (ts9.isArrayBindingPattern(name)) {
1321
+ if (ts8.isIdentifier(name)) return name.text;
1322
+ if (ts8.isArrayBindingPattern(name)) {
1410
1323
  const values = name.elements.map((element) => {
1411
- if (ts9.isOmittedExpression(element)) return "";
1324
+ if (ts8.isOmittedExpression(element)) return "";
1412
1325
  const value = bindingValue(element.name, sourceFile);
1413
1326
  return element.dotDotDotToken ? `...${value}` : value;
1414
1327
  });
@@ -1418,7 +1331,7 @@ var bindingValue = (name, sourceFile) => {
1418
1331
  const value = bindingValue(element.name, sourceFile);
1419
1332
  if (element.dotDotDotToken) return `...${value}`;
1420
1333
  if (!element.propertyName) return value;
1421
- const key = ts9.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
1334
+ const key = ts8.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText(sourceFile);
1422
1335
  return `${key}:${value}`;
1423
1336
  });
1424
1337
  return `{${properties.join(",")}}`;
@@ -1426,7 +1339,7 @@ var bindingValue = (name, sourceFile) => {
1426
1339
  var arrowArgsCapture = (node) => {
1427
1340
  const sourceFile = node.getSourceFile();
1428
1341
  const params = node.parameters.filter(
1429
- (parameter) => !(ts9.isIdentifier(parameter.name) && parameter.name.text === "this")
1342
+ (parameter) => !(ts8.isIdentifier(parameter.name) && parameter.name.text === "this")
1430
1343
  );
1431
1344
  if (!params.every((parameter) => canReconstructBinding(parameter.name))) {
1432
1345
  return {
@@ -1441,13 +1354,13 @@ var arrowArgsCapture = (node) => {
1441
1354
  return { args: `[${values.join(",")}]`, omitValues: false };
1442
1355
  };
1443
1356
  var isSupportedFunction = (node) => {
1444
- if (!ts9.isFunctionDeclaration(node) && !ts9.isFunctionExpression(node) && !ts9.isArrowFunction(node) && !ts9.isMethodDeclaration(node) && !ts9.isGetAccessorDeclaration(node) && !ts9.isSetAccessorDeclaration(node)) {
1357
+ if (!ts8.isFunctionDeclaration(node) && !ts8.isFunctionExpression(node) && !ts8.isArrowFunction(node) && !ts8.isMethodDeclaration(node) && !ts8.isGetAccessorDeclaration(node) && !ts8.isSetAccessorDeclaration(node)) {
1445
1358
  return false;
1446
1359
  }
1447
1360
  if (!node.body || "asteriskToken" in node && node.asteriskToken) return false;
1448
1361
  return true;
1449
1362
  };
1450
- var isDirectivePrologue = (statement) => ts9.isExpressionStatement(statement) && ts9.isStringLiteral(statement.expression);
1363
+ var isDirectivePrologue = (statement) => ts8.isExpressionStatement(statement) && ts8.isStringLiteral(statement.expression);
1451
1364
  var insertPositionAfterPrologue = (source, sourceFile) => {
1452
1365
  const shebangEnd = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
1453
1366
  let end = shebangEnd;
@@ -1498,7 +1411,7 @@ var insertAfterSuperOrPrologue = (body, sourceFile) => {
1498
1411
  const end = functionBodyPrologueEnd(body, sourceFile);
1499
1412
  for (const statement of body.statements) {
1500
1413
  if (isDirectivePrologue(statement)) continue;
1501
- if (ts9.isExpressionStatement(statement) && ts9.isCallExpression(statement.expression) && statement.expression.expression.kind === ts9.SyntaxKind.SuperKeyword) {
1414
+ if (ts8.isExpressionStatement(statement) && ts8.isCallExpression(statement.expression) && statement.expression.expression.kind === ts8.SyntaxKind.SuperKeyword) {
1502
1415
  return statement.end;
1503
1416
  }
1504
1417
  break;
@@ -1509,15 +1422,15 @@ var failEpilogue = (handleName, errorName, args2, restoreOnCatch) => `}catch(${e
1509
1422
  var walkOwnBody = (node, visitNode) => {
1510
1423
  if (!node.body) return;
1511
1424
  const visit = (candidate) => {
1512
- if (candidate !== node && ts9.isFunctionLike(candidate)) return;
1425
+ if (candidate !== node && ts8.isFunctionLike(candidate)) return;
1513
1426
  visitNode(candidate);
1514
- ts9.forEachChild(candidate, visit);
1427
+ ts8.forEachChild(candidate, visit);
1515
1428
  };
1516
1429
  visit(node.body);
1517
1430
  };
1518
1431
  var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
1519
1432
  walkOwnBody(node, (candidate) => {
1520
- if (!ts9.isAwaitExpression(candidate)) return;
1433
+ if (!ts8.isAwaitExpression(candidate)) return;
1521
1434
  wrap(
1522
1435
  edits,
1523
1436
  candidate.expression.getStart(sourceFile),
@@ -1538,7 +1451,7 @@ var collectAwaitWraps = (node, sourceFile, handleName, edits, depth) => {
1538
1451
  };
1539
1452
  var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) => {
1540
1453
  walkOwnBody(node, (candidate) => {
1541
- if (!ts9.isTryStatement(candidate)) return;
1454
+ if (!ts8.isTryStatement(candidate)) return;
1542
1455
  const blocks = [candidate.catchClause?.block, candidate.finallyBlock];
1543
1456
  for (const block of blocks) {
1544
1457
  if (!block) continue;
@@ -1554,10 +1467,10 @@ var collectCatchFinallyResumes = (node, sourceFile, handleName, edits, depth) =>
1554
1467
  });
1555
1468
  };
1556
1469
  var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
1557
- if (!node.body || !ts9.isBlock(node.body)) return;
1470
+ if (!node.body || !ts8.isBlock(node.body)) return;
1558
1471
  const visit = (candidate, at) => {
1559
- if (candidate !== node && ts9.isFunctionLike(candidate)) return;
1560
- if (ts9.isReturnStatement(candidate) && candidate.expression) {
1472
+ if (candidate !== node && ts8.isFunctionLike(candidate)) return;
1473
+ if (ts8.isReturnStatement(candidate) && candidate.expression) {
1561
1474
  const expression = candidate.expression;
1562
1475
  wrap(
1563
1476
  edits,
@@ -1569,17 +1482,17 @@ var collectReturnWraps = (node, sourceFile, handleName, edits, depth) => {
1569
1482
  );
1570
1483
  return;
1571
1484
  }
1572
- ts9.forEachChild(candidate, (child) => visit(child, at + 1));
1485
+ ts8.forEachChild(candidate, (child) => visit(child, at + 1));
1573
1486
  };
1574
1487
  visit(node.body, depth + 1);
1575
1488
  };
1576
1489
  var transformSource = (source, options) => {
1577
1490
  if (source.includes("@rasputin-ignore-file")) return void 0;
1578
1491
  if (sourceIsRasputinInstrumented(source)) return alreadyInstrumentedResult(source);
1579
- const sourceFile = ts9.createSourceFile(
1492
+ const sourceFile = ts8.createSourceFile(
1580
1493
  options.filePath,
1581
1494
  source,
1582
- ts9.ScriptTarget.Latest,
1495
+ ts8.ScriptTarget.Latest,
1583
1496
  true,
1584
1497
  scriptKindFor3(options.filePath)
1585
1498
  );
@@ -1643,7 +1556,7 @@ var transformSource = (source, options) => {
1643
1556
  collected.asyncFunction = true;
1644
1557
  skipFunction(node, collected, "unsupported_async_generator");
1645
1558
  }
1646
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1559
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1647
1560
  return;
1648
1561
  }
1649
1562
  if (isSyncGeneratorLike(node) && node.body) {
@@ -1655,10 +1568,10 @@ var transformSource = (source, options) => {
1655
1568
  );
1656
1569
  if (collected)
1657
1570
  skipFunction(node, collected, "unsupported_sync_generator");
1658
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1571
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1659
1572
  return;
1660
1573
  }
1661
- if (ts9.isConstructorDeclaration(node) && node.body) {
1574
+ if (ts8.isConstructorDeclaration(node) && node.body) {
1662
1575
  const collected = collectWrappedFunction(
1663
1576
  node,
1664
1577
  sourceFile,
@@ -1667,13 +1580,13 @@ var transformSource = (source, options) => {
1667
1580
  );
1668
1581
  if (collected)
1669
1582
  skipFunction(node, collected, "unsupported_constructor");
1670
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1583
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1671
1584
  return;
1672
1585
  }
1673
1586
  if (isSupportedFunction(node)) {
1674
1587
  const collected = collectWrappedFunction(node, sourceFile, absolutePath, options.mapLocation);
1675
1588
  if (!collected) {
1676
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1589
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1677
1590
  return;
1678
1591
  }
1679
1592
  if (options.decideFunction?.({
@@ -1682,7 +1595,7 @@ var transformSource = (source, options) => {
1682
1595
  filePath: options.filePath,
1683
1596
  name: collected.name
1684
1597
  }) === "skip") {
1685
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1598
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1686
1599
  return;
1687
1600
  }
1688
1601
  const asyncFunction = isAsyncFunctionLike(node);
@@ -1690,7 +1603,7 @@ var transformSource = (source, options) => {
1690
1603
  const decision = asyncFunction ? decideAsyncInstrumentation(node, sourceFile) : { action: "inline" };
1691
1604
  if (decision.action === "skip") {
1692
1605
  skipFunction(node, collected, decision.reason);
1693
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1606
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1694
1607
  return;
1695
1608
  }
1696
1609
  if (functionHasPreBodyParameterEvaluation(node)) {
@@ -1704,29 +1617,25 @@ var transformSource = (source, options) => {
1704
1617
  });
1705
1618
  delta.functions.push(collected);
1706
1619
  rememberIdentity(node, collected);
1707
- ts9.forEachChild(node, (child) => visit(child, collected, depth + 1));
1620
+ ts8.forEachChild(node, (child) => visit(child, collected, depth + 1));
1708
1621
  return;
1709
1622
  }
1710
- if (caller && (ts9.isCallExpression(node) || ts9.isNewExpression(node))) {
1711
- const site = collectCallSite(node, caller, collectContext);
1712
- if (site) delta.callSites.push(site);
1713
- }
1714
- if (caller && ts9.isVariableDeclaration(node)) {
1623
+ if (caller && ts8.isVariableDeclaration(node)) {
1715
1624
  const destructure = collectParamDestructure(node, caller, collectContext);
1716
1625
  if (destructure) delta.destructures.push(destructure);
1717
1626
  }
1718
- ts9.forEachChild(node, (child) => visit(child, caller, depth + 1));
1627
+ ts8.forEachChild(node, (child) => visit(child, caller, depth + 1));
1719
1628
  };
1720
1629
  visit(sourceFile, void 0, 0);
1721
1630
  if (pending.length === 0) {
1722
1631
  return delta.functions.length > 0 ? withDeclarations({ code: source, delta }) : void 0;
1723
1632
  }
1724
1633
  for (const [planIndex, entry] of pending.entries()) {
1725
- const captured = ts9.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
1634
+ const captured = ts8.isArrowFunction(entry.node) ? arrowArgsCapture(entry.node) : { args: "arguments", omitValues: false };
1726
1635
  const omitArg = captured.omitValues ? ",true" : "";
1727
1636
  const enterCall = `${runName}.enter(${planIndex},${captured.args}${omitArg})`;
1728
1637
  const epilogue = failEpilogue(handleName, errorName, captured.args, entry.suspendResume);
1729
- if (ts9.isBlock(entry.node.body)) {
1638
+ if (ts8.isBlock(entry.node.body)) {
1730
1639
  const prologueAt = insertAfterSuperOrPrologue(entry.node.body, sourceFile);
1731
1640
  const closeAt = entry.node.body.end - 1;
1732
1641
  wrap(
@@ -1815,33 +1724,14 @@ var transformSource = (source, options) => {
1815
1724
  });
1816
1725
  };
1817
1726
 
1818
- // ../instrumentation/src/json-producer-sites.ts
1819
- import ts11 from "typescript";
1820
-
1821
- // ../instrumentation/src/literal-sites.ts
1822
- import ts12 from "typescript";
1823
-
1824
- // ../instrumentation/src/observe-sites.ts
1825
- import { propertyNameIsSensitive as propertyNameIsSensitive2 } from "@rasputin-ai/core";
1826
- import ts13 from "typescript";
1827
-
1828
- // ../instrumentation/src/verify-browser-source.ts
1829
- import ts14 from "typescript";
1830
-
1831
- // ../instrumentation/src/provenance-function-edits.ts
1832
- import ts15 from "typescript";
1833
-
1834
- // ../instrumentation/src/source-map-location.ts
1835
- import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
1836
-
1837
1727
  // src/auto-instrumentation/instrumentation-manifest-registry.ts
1838
- import { createHash } from "node:crypto";
1839
1728
  import { resolve as resolve2 } from "node:path";
1840
1729
  import {
1841
1730
  INSTRUMENTATION_MANIFEST_SCHEMA_VERSION,
1842
- sourceLocatorFromFile as sourceLocatorFromFile3
1731
+ sourceLocatorFromFile as sourceLocatorFromFile3,
1732
+ sourceLocatorKey
1843
1733
  } from "@rasputin-ai/core";
1844
- var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
1734
+ var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v4";
1845
1735
  var registrySymbol = Symbol.for(INSTRUMENTATION_MANIFEST_SYMBOL);
1846
1736
  var getRegistry = () => {
1847
1737
  const existing = Reflect.get(globalThis, registrySymbol);
@@ -1860,11 +1750,16 @@ var getRegistry = () => {
1860
1750
  Reflect.set(globalThis, registrySymbol, registry);
1861
1751
  return registry;
1862
1752
  };
1863
- var sourceAt = (filePath, line, column) => {
1864
- const source = sourceLocatorFromFile3(filePath);
1865
- return source ? { ...source, line, column } : void 0;
1753
+ var rememberSource = (sources, source) => {
1754
+ const key = sourceLocatorKey(source);
1755
+ const previous = sources.get(key);
1756
+ sources.set(key, {
1757
+ ...previous,
1758
+ packageRelativePath: source.packageRelativePath,
1759
+ ...source.packageName ? { packageName: source.packageName } : previous?.packageName ? { packageName: previous.packageName } : {},
1760
+ ...source.repositoryPath ? { repositoryPath: source.repositoryPath } : previous?.repositoryPath ? { repositoryPath: previous.repositoryPath } : {}
1761
+ });
1866
1762
  };
1867
- var stableId = (kind, ...parts) => `${kind}_${createHash("sha256").update(parts.join("\0")).digest("base64url").slice(0, 24)}`;
1868
1763
  var recordInstrumentationManifestDelta = (filePath, delta) => {
1869
1764
  const registry = getRegistry();
1870
1765
  if (delta.alreadyInstrumented) {
@@ -1885,12 +1780,8 @@ var snapshotInstrumentationManifest = (options = {}) => {
1885
1780
  if (registry.snapshotCache && registry.snapshotCache.generation === registry.generation && registry.snapshotCache.optionsKey === optionsKey) {
1886
1781
  return registry.snapshotCache.manifest;
1887
1782
  }
1888
- const functions = new Map(
1889
- registry.prebuilt?.functions.map((fn) => [fn.functionId, fn])
1890
- );
1891
- const callSites = new Map(
1892
- registry.prebuilt?.callSites.map((site) => [site.id, site])
1893
- );
1783
+ const sources = /* @__PURE__ */ new Map();
1784
+ for (const source of registry.prebuilt?.sources ?? []) rememberSource(sources, source);
1894
1785
  const remember = (manifest) => {
1895
1786
  registry.snapshotCache = {
1896
1787
  generation: registry.generation,
@@ -1899,53 +1790,21 @@ var snapshotInstrumentationManifest = (options = {}) => {
1899
1790
  };
1900
1791
  return manifest;
1901
1792
  };
1902
- for (const delta of registry.files.values()) {
1793
+ for (const [filePath, delta] of registry.files) {
1794
+ let recorded = false;
1903
1795
  for (const fn of delta.functions) {
1904
1796
  const definition = definitionFromEncodedPlan(fn.plan);
1905
1797
  if (!definition.source) continue;
1906
- if (!fn.metricsDeclaration) {
1907
- throw new Error(`Missing function metrics declaration: ${fn.functionId}`);
1908
- }
1909
- functions.set(definition.functionId, {
1910
- ...functions.get(definition.functionId),
1911
- functionId: definition.functionId,
1912
- source: {
1913
- packageRelativePath: definition.source.packageRelativePath,
1914
- ...definition.source.packageName ? { packageName: definition.source.packageName } : {},
1915
- ...definition.source.repositoryPath ? { repositoryPath: definition.source.repositoryPath } : {}
1916
- },
1917
- name: fn.name,
1918
- startLine: fn.startLine,
1919
- startColumn: fn.startColumn,
1920
- endLine: fn.endLine,
1921
- endColumn: fn.endColumn,
1922
- metricsDeclaration: fn.metricsDeclaration,
1923
- ...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
1924
- });
1925
- }
1926
- for (const site of delta.callSites) {
1927
- const source = sourceAt(site.filePath, site.line, site.column);
1928
- if (!source) continue;
1929
- const id = stableId(
1930
- "cs",
1931
- site.callerFunctionId,
1932
- source.packageName ?? "",
1933
- source.packageRelativePath,
1934
- site.line,
1935
- site.column
1936
- );
1937
- callSites.set(id, {
1938
- id,
1939
- callerFunctionId: site.callerFunctionId,
1940
- calleeName: site.calleeName,
1941
- calleeText: site.calleeText,
1942
- line: site.line,
1943
- column: site.column,
1944
- endLine: site.endLine,
1945
- endColumn: site.endColumn,
1946
- resultBinding: site.resultBinding
1798
+ rememberSource(sources, {
1799
+ packageRelativePath: definition.source.packageRelativePath,
1800
+ ...definition.source.packageName ? { packageName: definition.source.packageName } : {},
1801
+ ...definition.source.repositoryPath ? { repositoryPath: definition.source.repositoryPath } : {}
1947
1802
  });
1803
+ recorded = true;
1948
1804
  }
1805
+ if (recorded) continue;
1806
+ const locator = sourceLocatorFromFile3(filePath);
1807
+ if (locator) rememberSource(sources, locator);
1949
1808
  }
1950
1809
  if (registry.prebuilt && registry.files.size === 0) {
1951
1810
  if (!options.sourceRoot && !options.sourceRoots) return remember(registry.prebuilt);
@@ -1957,9 +1816,7 @@ var snapshotInstrumentationManifest = (options = {}) => {
1957
1816
  }
1958
1817
  });
1959
1818
  }
1960
- if (functions.size === 0 && callSites.size === 0) {
1961
- return remember(void 0);
1962
- }
1819
+ if (sources.size === 0) return remember(void 0);
1963
1820
  const packages = { ...registry.prebuilt?.sourceRoots?.packages, ...options.sourceRoots };
1964
1821
  const sourceRoot = options.sourceRoot ?? registry.prebuilt?.sourceRoots?.default;
1965
1822
  return remember({
@@ -1970,8 +1827,7 @@ var snapshotInstrumentationManifest = (options = {}) => {
1970
1827
  packages
1971
1828
  }
1972
1829
  } : {},
1973
- functions: [...functions.values()],
1974
- callSites: [...callSites.values()]
1830
+ sources: [...sources.values()]
1975
1831
  });
1976
1832
  };
1977
1833
  var resetInstrumentationManifestRegistry = () => {