@rasputin-ai/node 0.5.3 → 0.6.1

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 (50) hide show
  1. package/README.md +2 -216
  2. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts +1 -3
  3. package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
  4. package/dist/auto-instrumentation/schedule-instrumentation-manifest-upload.d.ts.map +1 -1
  5. package/dist/auto-instrumentation/source-map-locations.d.ts +1 -1
  6. package/dist/auto-instrumentation/source-map-locations.d.ts.map +1 -1
  7. package/dist/auto-instrumentation/transform-disk-cache.d.ts +1 -1
  8. package/dist/auto-instrumentation/transform-disk-cache.d.ts.map +1 -1
  9. package/dist/execution-recorder/automatic-runtime.d.ts +2 -33
  10. package/dist/execution-recorder/automatic-runtime.d.ts.map +1 -1
  11. package/dist/execution-recorder/encode-frozen.d.ts +0 -8
  12. package/dist/execution-recorder/encode-frozen.d.ts.map +1 -1
  13. package/dist/execution-recorder/execution-recorder-types.d.ts +3 -4
  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/function-plan.d.ts +7 -22
  17. package/dist/execution-recorder/function-plan.d.ts.map +1 -1
  18. package/dist/execution-recorder/redact-keys.d.ts +0 -1
  19. package/dist/execution-recorder/redact-keys.d.ts.map +1 -1
  20. package/dist/execution-recorder/runtime-state-size-budget.d.ts +0 -2
  21. package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
  22. package/dist/execution-recorder/safe-serialize.d.ts +0 -2
  23. package/dist/execution-recorder/safe-serialize.d.ts.map +1 -1
  24. package/dist/execution-recorder/value-freeze.d.ts +0 -1
  25. package/dist/execution-recorder/value-freeze.d.ts.map +1 -1
  26. package/dist/index.js +146 -125
  27. package/dist/instrument/build.js +852 -588
  28. package/dist/instrument/bun.js +639 -373
  29. package/dist/instrument/node.js +605 -339
  30. package/dist/internal.js +143 -122
  31. package/dist/rasputin-init.d.ts +1 -0
  32. package/dist/rasputin-init.d.ts.map +1 -1
  33. package/dist/sdk-meta.d.ts +1 -1
  34. package/package.json +4 -2
  35. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts +0 -29
  36. package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts.map +0 -1
  37. package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts +0 -49
  38. package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts.map +0 -1
  39. package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts +0 -3
  40. package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts.map +0 -1
  41. package/dist/auto-instrumentation/suspension-whitelist.d.ts +0 -33
  42. package/dist/auto-instrumentation/suspension-whitelist.d.ts.map +0 -1
  43. package/dist/auto-instrumentation/transform-source.d.ts +0 -27
  44. package/dist/auto-instrumentation/transform-source.d.ts.map +0 -1
  45. package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts +0 -2
  46. package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts.map +0 -1
  47. package/dist/auto-instrumentation/verify-transformed-source.d.ts +0 -2
  48. package/dist/auto-instrumentation/verify-transformed-source.d.ts.map +0 -1
  49. package/dist/execution-recorder/run-exactly-once.d.ts +0 -7
  50. package/dist/execution-recorder/run-exactly-once.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -13,14 +13,89 @@ import {
13
13
  sourceLocatorFromFile as sourceLocatorFromFile2
14
14
  } from "@rasputin-ai/core";
15
15
 
16
- // src/execution-recorder/function-plan.ts
16
+ // ../recorder/src/run-exactly-once.ts
17
+ var runExactlyOnce = function __rasputinHandleRun__(invoke, callback) {
18
+ let outcome;
19
+ const wrapped = function __rasputinHandleRun__3() {
20
+ try {
21
+ const value = callback();
22
+ outcome = { kind: "value", value };
23
+ return value;
24
+ } catch (caught) {
25
+ outcome = { kind: "throw", error: caught };
26
+ throw caught;
27
+ }
28
+ };
29
+ try {
30
+ invoke(wrapped);
31
+ } catch {
32
+ }
33
+ if (outcome?.kind === "throw") throw outcome.error;
34
+ if (outcome?.kind === "value") return outcome.value;
35
+ return callback();
36
+ };
37
+
38
+ // ../recorder/src/call-handle.ts
39
+ var passthroughHandle = () => ({
40
+ leave: (value) => value,
41
+ fail: () => {
42
+ },
43
+ end: () => {
44
+ },
45
+ run: function __rasputinHandleRun__3(callback) {
46
+ return runExactlyOnce((invoke) => invoke(), callback);
47
+ },
48
+ suspend: (value) => value,
49
+ resume: (value) => value
50
+ });
51
+ var isolateHandle = (handle) => ({
52
+ leave: (value) => {
53
+ try {
54
+ return handle.leave(value);
55
+ } catch {
56
+ return value;
57
+ }
58
+ },
59
+ fail: (error, liveArgs) => {
60
+ try {
61
+ handle.fail(error, liveArgs);
62
+ } catch {
63
+ }
64
+ },
65
+ end: () => {
66
+ try {
67
+ handle.end();
68
+ } catch {
69
+ }
70
+ },
71
+ run: function __rasputinHandleRun__3(callback) {
72
+ return runExactlyOnce((invoke) => handle.run(invoke), callback);
73
+ },
74
+ suspend: (value) => {
75
+ try {
76
+ return handle.suspend(value);
77
+ } catch {
78
+ return value;
79
+ }
80
+ },
81
+ resume: (value) => {
82
+ try {
83
+ return handle.resume(value);
84
+ } catch {
85
+ return value;
86
+ }
87
+ }
88
+ });
89
+
90
+ // ../recorder/src/encoded-function-plan.ts
91
+ var encodedPlanOmitsCallValues = (plan) => plan[6] === 1;
92
+ var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
93
+
94
+ // ../recorder/src/function-plan.ts
17
95
  import {
18
96
  runtimeFunctionId,
19
97
  sourceLocatorFromFile
20
98
  } from "@rasputin-ai/core";
21
- var encodedPlanOmitsCallValues = (plan) => plan[6] === 1;
22
- var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
23
- var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
24
99
  var definitionFromEncodedPlan = (plan) => {
25
100
  const [functionId, name, packageName, packageRelativePath, line, column] = plan;
26
101
  const source = packageRelativePath ? {
@@ -36,7 +111,57 @@ var definitionFromEncodedPlan = (plan) => {
36
111
  ...encodedPlanHasPreBodyParameterEvaluation(plan) ? { parentAttribution: "pre_body_parameter_evaluation" } : {}
37
112
  };
38
113
  };
39
- var estimatedCallBytesFor = (functionId) => EVENT_PAIR_BASE_ESTIMATED_BYTES + Buffer.byteLength(functionId, "utf8") * 2;
114
+
115
+ // ../recorder/src/runtime-symbol.ts
116
+ var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
117
+
118
+ // ../recorder/src/registry.ts
119
+ var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
120
+ var passthroughRun = (_planIndex, _args, callback) => callback();
121
+ var passthroughEnter = () => passthroughHandle();
122
+ var bindPassthrough = (module) => {
123
+ module.cell.run = passthroughRun;
124
+ module.cell.enter = passthroughEnter;
125
+ };
126
+ var attachRunner = (cell) => {
127
+ const run = ((planIndex, args, callback, omitValues) => cell.run(planIndex, args, callback, omitValues));
128
+ run.enter = (planIndex, args, omitValues, callee) => cell.enter(planIndex, args, omitValues, callee);
129
+ return run;
130
+ };
131
+ var isCompatibleRegistry = (value) => typeof Reflect.get(value, "register") === "function" && Array.isArray(Reflect.get(value, "runtimes")) && Array.isArray(Reflect.get(value, "modules"));
132
+ var registerModule = (registry, plans, moduleIndex) => {
133
+ const cell = { run: passthroughRun, enter: passthroughEnter };
134
+ const module = {
135
+ plans,
136
+ cell,
137
+ ...moduleIndex === void 0 ? {} : { moduleIndex }
138
+ };
139
+ registry.modules.push(module);
140
+ registry.runtimes.at(-1)?.bind(module);
141
+ return attachRunner(cell);
142
+ };
143
+ var createRegistry = () => {
144
+ const registry = {
145
+ runtimes: [],
146
+ modules: [],
147
+ register(plans, moduleIndex) {
148
+ return registerModule(registry, plans, moduleIndex);
149
+ }
150
+ };
151
+ return registry;
152
+ };
153
+ var getAutomaticRuntimeRegistry = () => {
154
+ const existing = Reflect.get(globalThis, runtimeSymbol);
155
+ if (existing && typeof existing === "object" && isCompatibleRegistry(existing)) {
156
+ return existing;
157
+ }
158
+ if (existing != null) {
159
+ return createRegistry();
160
+ }
161
+ const registry = createRegistry();
162
+ Reflect.set(globalThis, runtimeSymbol, registry);
163
+ return registry;
164
+ };
40
165
 
41
166
  // src/auto-instrumentation/instrumentation-manifest-registry.ts
42
167
  var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
@@ -233,7 +358,7 @@ var setInstrumentationManifestOnDirty = (onDirty) => {
233
358
 
234
359
  // src/auto-instrumentation/schedule-instrumentation-manifest-upload.ts
235
360
  import {
236
- detectRelease,
361
+ parseReleaseSha,
237
362
  resolveEndpointUrls,
238
363
  uploadInstrumentationManifest
239
364
  } from "@rasputin-ai/core";
@@ -363,7 +488,7 @@ var scheduleInstrumentationManifestUpload = (options) => {
363
488
  if (!options.enabled || !(options.projectApiKey ?? "").trim()) {
364
489
  return noopHandle;
365
490
  }
366
- const release = detectRelease({ release: options.release });
491
+ const release = parseReleaseSha(options.release);
367
492
  if (!release) return noopHandle;
368
493
  const { instrumentationManifestUrl } = resolveEndpointUrls(options.apiUrl);
369
494
  let inflight = Promise.resolve();
@@ -919,6 +1044,10 @@ var ExecutionJournalPool = class {
919
1044
  }
920
1045
  };
921
1046
 
1047
+ // src/execution-recorder/function-plan.ts
1048
+ var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
1049
+ var estimatedCallBytesFor = (functionId) => EVENT_PAIR_BASE_ESTIMATED_BYTES + Buffer.byteLength(functionId, "utf8") * 2;
1050
+
922
1051
  // src/execution-recorder/recorder-memory-budget.ts
923
1052
  var EXECUTION_BASE_ESTIMATED_BYTES = 1024;
924
1053
  var SUMMARY_EVENT_BASE_ESTIMATED_BYTES = 256;
@@ -1054,28 +1183,6 @@ var RecorderMemoryBudget = class {
1054
1183
  }
1055
1184
  };
1056
1185
 
1057
- // src/execution-recorder/run-exactly-once.ts
1058
- var runExactlyOnce = function __rasputinHandleRun__(invoke, callback) {
1059
- let outcome;
1060
- const wrapped = function __rasputinHandleRun__3() {
1061
- try {
1062
- const value = callback();
1063
- outcome = { kind: "value", value };
1064
- return value;
1065
- } catch (caught) {
1066
- outcome = { kind: "throw", error: caught };
1067
- throw caught;
1068
- }
1069
- };
1070
- try {
1071
- invoke(wrapped);
1072
- } catch {
1073
- }
1074
- if (outcome?.kind === "throw") throw outcome.error;
1075
- if (outcome?.kind === "value") return outcome.value;
1076
- return callback();
1077
- };
1078
-
1079
1186
  // src/execution-recorder/runtime-state-size-budget.ts
1080
1187
  import {
1081
1188
  rasputinUnavailable
@@ -1118,6 +1225,7 @@ var dropEventValues = (events) => {
1118
1225
  const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
1119
1226
  const bounded = events.map((event) => {
1120
1227
  if (event.type === "function_enter") {
1228
+ if (event.args === void 0) return { ...event };
1121
1229
  dropped += event.args.length;
1122
1230
  return { ...event, args: event.args.map(marker) };
1123
1231
  }
@@ -2721,7 +2829,10 @@ var createExecutionRecorder = (options) => {
2721
2829
  };
2722
2830
  const encodeEventValues = (events) => events.map((event) => {
2723
2831
  if (event.type === "function_enter") {
2724
- return { ...event, args: event.args.map((argument) => serializer.encode(argument)) };
2832
+ return {
2833
+ ...event,
2834
+ ...event.args === void 0 ? {} : { args: event.args.map((argument) => serializer.encode(argument)) }
2835
+ };
2725
2836
  }
2726
2837
  if (event.type === "function_exit") {
2727
2838
  return { ...event, returnValue: serializer.encode(event.returnValue) };
@@ -2768,7 +2879,7 @@ var createExecutionRecorder = (options) => {
2768
2879
  };
2769
2880
  const eventsHaveOmittedValues = (events) => {
2770
2881
  for (const event of events) {
2771
- if (event.type === "function_enter" && event.args.some((arg) => rasputinTagKind(arg) === "omitted")) {
2882
+ if (event.type === "function_enter" && (event.args ?? []).some((arg) => rasputinTagKind(arg) === "omitted")) {
2772
2883
  return true;
2773
2884
  }
2774
2885
  if (event.type === "function_exit" && rasputinTagKind(event.returnValue) === "omitted") {
@@ -3883,69 +3994,6 @@ var createExecutionRecorder = (options) => {
3883
3994
  };
3884
3995
 
3885
3996
  // src/execution-recorder/automatic-runtime.ts
3886
- var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
3887
- var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
3888
- var passthroughHandle = () => ({
3889
- leave: (value) => value,
3890
- fail: () => {
3891
- },
3892
- end: () => {
3893
- },
3894
- run: function __rasputinHandleRun__3(callback) {
3895
- return runExactlyOnce((invoke) => invoke(), callback);
3896
- },
3897
- suspend: (value) => value,
3898
- resume: (value) => value
3899
- });
3900
- var isolateHandle = (handle) => ({
3901
- leave: (value) => {
3902
- try {
3903
- return handle.leave(value);
3904
- } catch {
3905
- return value;
3906
- }
3907
- },
3908
- fail: (error, liveArgs) => {
3909
- try {
3910
- handle.fail(error, liveArgs);
3911
- } catch {
3912
- }
3913
- },
3914
- end: () => {
3915
- try {
3916
- handle.end();
3917
- } catch {
3918
- }
3919
- },
3920
- run: function __rasputinHandleRun__3(callback) {
3921
- return runExactlyOnce((invoke) => handle.run(invoke), callback);
3922
- },
3923
- suspend: (value) => {
3924
- try {
3925
- return handle.suspend(value);
3926
- } catch {
3927
- return value;
3928
- }
3929
- },
3930
- resume: (value) => {
3931
- try {
3932
- return handle.resume(value);
3933
- } catch {
3934
- return value;
3935
- }
3936
- }
3937
- });
3938
- var passthroughRun = (_planIndex, _args, callback) => callback();
3939
- var passthroughEnter = () => passthroughHandle();
3940
- var bindPassthrough = (module) => {
3941
- module.cell.run = passthroughRun;
3942
- module.cell.enter = passthroughEnter;
3943
- };
3944
- var attachRunner = (cell) => {
3945
- const run = ((planIndex, args, callback, omitValues) => cell.run(planIndex, args, callback, omitValues));
3946
- run.enter = (planIndex, args, omitValues) => cell.enter(planIndex, args, omitValues);
3947
- return run;
3948
- };
3949
3997
  var bindExecution = (execution, module) => {
3950
3998
  const prepared = execution.prepareFunctionPlans(module.plans);
3951
3999
  module.cell.run = (planIndex, args, callback, omitValues) => {
@@ -3956,40 +4004,13 @@ var bindExecution = (execution, module) => {
3956
4004
  try {
3957
4005
  const plan = prepared[planIndex];
3958
4006
  return isolateHandle(
3959
- plan ? execution.enterPreparedFunction(plan, args, omitValues) : passthroughEnter(planIndex, args, omitValues)
4007
+ plan ? execution.enterPreparedFunction(plan, args, omitValues) : passthroughHandle()
3960
4008
  );
3961
4009
  } catch {
3962
4010
  return passthroughHandle();
3963
4011
  }
3964
4012
  };
3965
4013
  };
3966
- var isRegistry = (value) => Array.isArray(Reflect.get(value, "runtimes")) && Array.isArray(Reflect.get(value, "modules")) && typeof Reflect.get(value, "register") === "function";
3967
- var registerModule = (registry, plans) => {
3968
- const cell = { run: passthroughRun, enter: passthroughEnter };
3969
- const module = { plans, cell };
3970
- registry.modules.push(module);
3971
- registry.runtimes.at(-1)?.bind(module);
3972
- return attachRunner(cell);
3973
- };
3974
- var createRegistry = () => {
3975
- const registry = {
3976
- runtimes: [],
3977
- modules: [],
3978
- register(plans) {
3979
- return registerModule(registry, plans);
3980
- }
3981
- };
3982
- return registry;
3983
- };
3984
- var getAutomaticRuntimeRegistry = () => {
3985
- const existing = Reflect.get(globalThis, runtimeSymbol);
3986
- if (existing && typeof existing === "object" && isRegistry(existing)) {
3987
- return existing;
3988
- }
3989
- const registry = createRegistry();
3990
- Reflect.set(globalThis, runtimeSymbol, registry);
3991
- return registry;
3992
- };
3993
4014
  var installAutomaticExecutionRuntime = (execution) => {
3994
4015
  const registry = getAutomaticRuntimeRegistry();
3995
4016
  const runtime = {
@@ -4148,7 +4169,7 @@ var installGlobalHandlers = (client, options = {}) => {
4148
4169
 
4149
4170
  // src/sdk-meta.ts
4150
4171
  var SDK_NAME = "@rasputin-ai/node";
4151
- var SDK_VERSION = "0.5.3";
4172
+ var SDK_VERSION = "0.6.1";
4152
4173
 
4153
4174
  // src/rasputin-init.ts
4154
4175
  var publicExecution = (runtime) => ({
@@ -4227,7 +4248,7 @@ var RasputinInit = (options) => {
4227
4248
  runtime,
4228
4249
  recorderEnabled,
4229
4250
  {
4230
- projectApiKey: options.projectApiKey ?? "",
4251
+ projectApiKey: options.projectApiKey,
4231
4252
  release: options.release,
4232
4253
  apiUrl: options.apiUrl,
4233
4254
  enabled,
@@ -4247,7 +4268,7 @@ var RasputinInit = (options) => {
4247
4268
  createExecutionRecorder({ enabled: false }),
4248
4269
  false,
4249
4270
  {
4250
- projectApiKey: options.projectApiKey ?? "",
4271
+ projectApiKey: options.projectApiKey,
4251
4272
  release: options.release,
4252
4273
  apiUrl: options.apiUrl,
4253
4274
  enabled: false,