@rasputin-ai/node 0.12.0 → 0.13.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.
@@ -1,4 +1,4 @@
1
- import { type InstrumentationManifestContent } from '@rasputin-ai/core';
1
+ import { type InstrumentationManifestContent, type InstrumentationParamBinding } from '@rasputin-ai/core';
2
2
  import type { InstrumentationManifestDelta } from '@rasputin-ai/instrumentation';
3
3
  type SnapshotOptions = {
4
4
  sourceRoot?: string;
@@ -17,6 +17,7 @@ export declare const instrumentationCoverageStats: () => {
17
17
  };
18
18
  export declare const instrumentationManifestModuleCount: () => number;
19
19
  export declare const snapshotInstrumentationManifest: (options?: SnapshotOptions) => InstrumentationManifestContent | undefined;
20
+ export declare const paramsForRuntimeFunction: (functionId: string) => InstrumentationParamBinding[] | undefined;
20
21
  export declare const markInstrumentationManifestUploaded: (generation: number) => void;
21
22
  export declare const setInstrumentationManifestOnDirty: (onDirty?: () => void) => void;
22
23
  export declare const resetInstrumentationManifestRegistry: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation-manifest-registry.d.ts","sourceRoot":"","sources":["../../src/auto-instrumentation/instrumentation-manifest-registry.ts"],"names":[],"mappings":"AAOA,OAAO,EAGN,KAAK,8BAA8B,EAKnC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAwBjF,KAAK,eAAe,GAAG;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,CAAC;AAoCF,eAAO,MAAM,kCAAkC,GAC9C,UAAU,MAAM,EAChB,OAAO,4BAA4B,KACjC,IASF,CAAC;AAEF,eAAO,MAAM,qCAAqC,GACjD,UAAU,8BAA8B,KACtC,IAKF,CAAC;AAcF,eAAO,MAAM,oCAAoC,GAAI,MAAM,MAAM,GAAG,SAAS,KAAG,IAG/E,CAAC;AAEF,eAAO,MAAM,8BAA8B,QAAO,OAMjD,CAAC;AAEF,eAAO,MAAM,iCAAiC,QAAO,MAAkC,CAAC;AAExF,eAAO,MAAM,4BAA4B,QAAO;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CA0BxC,CAAC;AAEF,eAAO,MAAM,kCAAkC,QAAO,MAKrD,CAAC;AAQF,eAAO,MAAM,+BAA+B,GAC3C,UAAS,eAAoB,KAC3B,8BAA8B,GAAG,SA+GnC,CAAC;AAEF,eAAO,MAAM,mCAAmC,GAAI,YAAY,MAAM,KAAG,IAGxE,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,IAAI,KAAG,IAExE,CAAC;AAEF,eAAO,MAAM,oCAAoC,QAAO,IAEvD,CAAC"}
1
+ {"version":3,"file":"instrumentation-manifest-registry.d.ts","sourceRoot":"","sources":["../../src/auto-instrumentation/instrumentation-manifest-registry.ts"],"names":[],"mappings":"AAOA,OAAO,EAGN,KAAK,8BAA8B,EAEnC,KAAK,2BAA2B,EAGhC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AA4BjF,KAAK,eAAe,GAAG;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,CAAC;AAoCF,eAAO,MAAM,kCAAkC,GAC9C,UAAU,MAAM,EAChB,OAAO,4BAA4B,KACjC,IASF,CAAC;AAEF,eAAO,MAAM,qCAAqC,GACjD,UAAU,8BAA8B,KACtC,IAKF,CAAC;AAcF,eAAO,MAAM,oCAAoC,GAAI,MAAM,MAAM,GAAG,SAAS,KAAG,IAG/E,CAAC;AAEF,eAAO,MAAM,8BAA8B,QAAO,OAMjD,CAAC;AAEF,eAAO,MAAM,iCAAiC,QAAO,MAAkC,CAAC;AAExF,eAAO,MAAM,4BAA4B,QAAO;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CA0BxC,CAAC;AAEF,eAAO,MAAM,kCAAkC,QAAO,MAKrD,CAAC;AAQF,eAAO,MAAM,+BAA+B,GAC3C,UAAS,eAAoB,KAC3B,8BAA8B,GAAG,SAkGnC,CAAC;AAkBF,eAAO,MAAM,wBAAwB,GACpC,YAAY,MAAM,KAChB,2BAA2B,EAAE,GAAG,SAGlC,CAAC;AAEF,eAAO,MAAM,mCAAmC,GAAI,YAAY,MAAM,KAAG,IAGxE,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,IAAI,KAAG,IAExE,CAAC;AAEF,eAAO,MAAM,oCAAoC,QAAO,IAEvD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"execution-recorder.d.ts","sourceRoot":"","sources":["../../src/execution-recorder/execution-recorder.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,sBAAsB,EAAsB,MAAM,4BAA4B,CAAC;AAC7F,OAAO,KAAK,EAEX,wBAAwB,EACxB,gBAAgB,EAGhB,MAAM,4BAA4B,CAAC;AAmRpC,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,GACnC,SAAS,wBAAwB,GAAG,SAAS,EAC7C,QAAO,sBAA2B,KAChC,gBAy3DF,CAAC"}
1
+ {"version":3,"file":"execution-recorder.d.ts","sourceRoot":"","sources":["../../src/execution-recorder/execution-recorder.ts"],"names":[],"mappings":"AA8CA,OAAO,KAAK,EAAE,sBAAsB,EAAsB,MAAM,4BAA4B,CAAC;AAC7F,OAAO,KAAK,EAEX,wBAAwB,EACxB,gBAAgB,EAGhB,MAAM,4BAA4B,CAAC;AAmRpC,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,GACnC,SAAS,wBAAwB,GAAG,SAAS,EAC7C,QAAO,sBAA2B,KAChC,gBA65DF,CAAC"}
package/dist/index.js CHANGED
@@ -222,7 +222,6 @@ var snapshotInstrumentationManifest = (options = {}) => {
222
222
  }
223
223
  const functions = [];
224
224
  const callSites = [];
225
- const destructures = [];
226
225
  const remember = (manifest) => {
227
226
  registry.snapshotCache = {
228
227
  generation: registry.generation,
@@ -237,13 +236,16 @@ var snapshotInstrumentationManifest = (options = {}) => {
237
236
  if (!definition.source) continue;
238
237
  functions.push({
239
238
  functionId: definition.functionId,
240
- source: definition.source,
239
+ source: {
240
+ packageRelativePath: definition.source.packageRelativePath,
241
+ ...definition.source.packageName ? { packageName: definition.source.packageName } : {},
242
+ ...definition.source.repositoryPath ? { repositoryPath: definition.source.repositoryPath } : {}
243
+ },
241
244
  name: fn.name,
242
245
  startLine: fn.startLine,
243
246
  startColumn: fn.startColumn,
244
247
  endLine: fn.endLine,
245
248
  endColumn: fn.endColumn,
246
- params: fn.params,
247
249
  ...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
248
250
  });
249
251
  }
@@ -262,40 +264,25 @@ var snapshotInstrumentationManifest = (options = {}) => {
262
264
  callerFunctionId: site.callerFunctionId,
263
265
  calleeName: site.calleeName,
264
266
  calleeText: site.calleeText,
265
- source,
266
267
  line: site.line,
267
268
  column: site.column,
268
269
  endLine: site.endLine,
269
270
  endColumn: site.endColumn,
270
- resultBinding: site.resultBinding,
271
- argIdentifiers: site.argIdentifiers
272
- });
273
- }
274
- for (const destructure of delta.destructures) {
275
- const source = sourceAt(destructure.filePath, destructure.line, destructure.column);
276
- if (!source) continue;
277
- destructures.push({
278
- callerFunctionId: destructure.callerFunctionId,
279
- sourceParam: destructure.sourceParam,
280
- source,
281
- line: destructure.line,
282
- column: destructure.column,
283
- binding: destructure.binding
271
+ resultBinding: site.resultBinding
284
272
  });
285
273
  }
286
274
  }
287
275
  if (registry.prebuilt && registry.files.size === 0) {
288
- const prebuilt = registry.prebuilt;
289
- if (!options.sourceRoot && !options.sourceRoots) return remember(prebuilt);
276
+ if (!options.sourceRoot && !options.sourceRoots) return remember(registry.prebuilt);
290
277
  return remember({
291
- ...prebuilt,
278
+ ...registry.prebuilt,
292
279
  sourceRoots: {
293
280
  ...options.sourceRoot ? { default: options.sourceRoot } : {},
294
281
  packages: { ...options.sourceRoots ?? {} }
295
282
  }
296
283
  });
297
284
  }
298
- if (functions.length === 0 && callSites.length === 0 && destructures.length === 0) {
285
+ if (functions.length === 0 && callSites.length === 0) {
299
286
  return remember(void 0);
300
287
  }
301
288
  const packages = { ...options.sourceRoots ?? {} };
@@ -308,10 +295,27 @@ var snapshotInstrumentationManifest = (options = {}) => {
308
295
  }
309
296
  } : {},
310
297
  functions,
311
- callSites,
312
- destructures
298
+ callSites
313
299
  });
314
300
  };
301
+ var collectParamsByFunctionId = () => {
302
+ const registry = getRegistry();
303
+ if (registry.paramsCache?.generation === registry.generation) return registry.paramsCache.params;
304
+ const params = /* @__PURE__ */ new Map();
305
+ for (const delta of registry.files.values()) {
306
+ for (const fn of delta.functions) {
307
+ if (!fn.params || fn.params.length === 0) continue;
308
+ const definition = definitionFromEncodedPlan(fn.plan);
309
+ params.set(definition.functionId, fn.params);
310
+ }
311
+ }
312
+ registry.paramsCache = { generation: registry.generation, params };
313
+ return params;
314
+ };
315
+ var paramsForRuntimeFunction = (functionId) => {
316
+ const params = collectParamsByFunctionId().get(functionId);
317
+ return params && params.length > 0 ? params : void 0;
318
+ };
315
319
  var markInstrumentationManifestUploaded = (generation) => {
316
320
  const registry = getRegistry();
317
321
  if (registry.generation === generation) registry.uploadedGeneration = generation;
@@ -3017,11 +3021,14 @@ var createExecutionRecorder = (options, hooks = {}) => {
3017
3021
  };
3018
3022
  const skipCapture = (store, plan) => store.suppressCapture || plan.excluded || Boolean(store.recording.sessionExcludes?.(plan.definition));
3019
3023
  const durationSamplingApplies = (recording) => durationSamplingEnabled && recording.identityResolved === true && !recording.captureValues && !recording.retainSuccess;
3020
- const callerStore = (store, functionId, callId) => ({
3021
- ...store,
3022
- currentFunctionId: functionId,
3023
- ...callId === void 0 ? {} : { currentCallId: callId }
3024
- });
3024
+ const callStoreFor = (store, functionId, callId) => {
3025
+ const next = { ...store, currentCallId: callId };
3026
+ if (durationSamplingEnabled) next.currentFunctionId = functionId;
3027
+ return next;
3028
+ };
3029
+ const samplingStore = (store, functionId) => {
3030
+ return durationSamplingEnabled ? { ...store, currentFunctionId: functionId } : store;
3031
+ };
3025
3032
  const decideCallTiming = (recording, plan, callerFunctionId) => {
3026
3033
  if (!durationSamplingApplies(recording) || !durationSamples) return true;
3027
3034
  const typeKey = executionTypeKey(recording.execution);
@@ -3102,12 +3109,14 @@ var createExecutionRecorder = (options, hooks = {}) => {
3102
3109
  if (cached) return cached;
3103
3110
  const prepared = plans.map((encoded) => {
3104
3111
  const definition = definitionFromEncodedPlan(encoded);
3112
+ const params = paramsForRuntimeFunction(definition.functionId);
3113
+ const withParams = params && params.length > 0 ? { ...definition, params } : definition;
3105
3114
  return storePlan({
3106
3115
  runtimePlanId: nextRuntimePlanId++,
3107
- definition,
3108
- functionId: definition.functionId,
3109
- excluded: excludesSource(definition),
3110
- estimatedCallBytes: estimatedCallBytesFor(definition.functionId),
3116
+ definition: withParams,
3117
+ functionId: withParams.functionId,
3118
+ excluded: excludesSource(withParams),
3119
+ estimatedCallBytes: estimatedCallBytesFor(withParams.functionId),
3111
3120
  omitCallValues: encodedPlanOmitsCallValues(encoded)
3112
3121
  });
3113
3122
  });
@@ -3821,7 +3830,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3821
3830
  const startedAtNs2 = timed ? readCallClock() : 0n;
3822
3831
  try {
3823
3832
  const result = runStore(
3824
- callerStore(store, plan.functionId),
3833
+ samplingStore(store, plan.functionId),
3825
3834
  function __rasputinHandleRun__5() {
3826
3835
  return callback();
3827
3836
  }
@@ -3845,7 +3854,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3845
3854
  const startedAtNs = timed ? readCallClock() : 0n;
3846
3855
  if (!journal) {
3847
3856
  memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes);
3848
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3857
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3849
3858
  return observeRecordedCallback(
3850
3859
  recording,
3851
3860
  recorderStartedAtNs,
@@ -3864,7 +3873,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3864
3873
  countDroppedEvents(recording, droppedBefore);
3865
3874
  settleInFlight(recording);
3866
3875
  };
3867
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3876
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3868
3877
  return observeRecordedCallback(
3869
3878
  recording,
3870
3879
  recorderStartedAtNs,
@@ -3878,7 +3887,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3878
3887
  });
3879
3888
  }
3880
3889
  if (!memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes)) {
3881
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3890
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3882
3891
  return observeRecordedCallback(
3883
3892
  recording,
3884
3893
  recorderStartedAtNs,
@@ -3897,7 +3906,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3897
3906
  journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
3898
3907
  } catch {
3899
3908
  journal.dropCall();
3900
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3909
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3901
3910
  return observeRecordedCallback(
3902
3911
  recording,
3903
3912
  recorderStartedAtNs,
@@ -3909,7 +3918,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3909
3918
  );
3910
3919
  });
3911
3920
  }
3912
- const callStore = callerStore(store, plan.functionId, callId);
3921
+ const callStore = callStoreFor(store, plan.functionId, callId);
3913
3922
  return runStore(callStore, function __rasputinHandleRun__5() {
3914
3923
  return observeRecordedCallback(
3915
3924
  recording,
@@ -3981,6 +3990,25 @@ var createExecutionRecorder = (options, hooks = {}) => {
3981
3990
  this.parentStore = parentStore;
3982
3991
  this.group = group;
3983
3992
  this.captureDroppedThrow = captureDroppedThrow;
3993
+ this.callerClaimed = false;
3994
+ }
3995
+ claimCaller() {
3996
+ if (this.callerClaimed || !durationSamplingEnabled || !this.plan) return;
3997
+ if (this.activeStore !== this.parentStore) return;
3998
+ this.previousFunctionId = this.parentStore.currentFunctionId;
3999
+ this.parentStore.currentFunctionId = this.plan.functionId;
4000
+ this.callerClaimed = true;
4001
+ }
4002
+ reclaimCaller() {
4003
+ if (!durationSamplingEnabled || !this.plan || this.activeStore !== this.parentStore) return;
4004
+ this.parentStore.currentFunctionId = this.plan.functionId;
4005
+ this.callerClaimed = true;
4006
+ }
4007
+ releaseCaller() {
4008
+ if (!this.callerClaimed) return;
4009
+ this.callerClaimed = false;
4010
+ if (this.previousFunctionId === void 0) delete this.parentStore.currentFunctionId;
4011
+ else this.parentStore.currentFunctionId = this.previousFunctionId;
3984
4012
  }
3985
4013
  leave(value) {
3986
4014
  try {
@@ -4050,6 +4078,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4050
4078
  try {
4051
4079
  if (this.ended) return;
4052
4080
  this.ended = true;
4081
+ this.releaseCaller();
4053
4082
  if (this.mode !== "excluded") settleInFlight(this.recording);
4054
4083
  expectStore(this, this.activeStore);
4055
4084
  enterStore(this, this.parentStore);
@@ -4073,6 +4102,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4073
4102
  try {
4074
4103
  expectStore(this, this.activeStore);
4075
4104
  this.suspended = true;
4105
+ this.releaseCaller();
4076
4106
  enterStore(this, this.parentStore);
4077
4107
  return value;
4078
4108
  } catch {
@@ -4086,6 +4116,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4086
4116
  expectStore(this, this.parentStore);
4087
4117
  this.suspended = false;
4088
4118
  enterStore(this, this.activeStore);
4119
+ this.reclaimCaller();
4089
4120
  } else {
4090
4121
  expectStore(this, this.activeStore);
4091
4122
  }
@@ -4144,12 +4175,11 @@ var createExecutionRecorder = (options, hooks = {}) => {
4144
4175
  capturedError.commit();
4145
4176
  };
4146
4177
  const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, group, captureDroppedThrow) => {
4147
- const activeStore = callerStore(parentStore, plan.functionId);
4148
4178
  const frame = new CallFrame(
4149
4179
  mode,
4150
4180
  recording,
4151
4181
  parentStore,
4152
- activeStore,
4182
+ parentStore,
4153
4183
  plan,
4154
4184
  args,
4155
4185
  omitCallValues,
@@ -4160,7 +4190,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
4160
4190
  group,
4161
4191
  captureDroppedThrow
4162
4192
  );
4163
- enterStore(frame, activeStore);
4193
+ frame.claimCaller();
4194
+ enterStore(frame, parentStore);
4164
4195
  return frame;
4165
4196
  };
4166
4197
  const enterPreparedFunctionFromStore = (store, plan, args, omitValues) => {
@@ -4307,7 +4338,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4307
4338
  false
4308
4339
  );
4309
4340
  }
4310
- const callStore = callerStore(store, plan.functionId, callId);
4341
+ const callStore = callStoreFor(store, plan.functionId, callId);
4311
4342
  const captured = new CallFrame(
4312
4343
  "captured",
4313
4344
  recording,
@@ -5466,7 +5497,7 @@ var installGlobalHandlers = (client, options = {}) => {
5466
5497
 
5467
5498
  // src/sdk-meta.ts
5468
5499
  var SDK_NAME = "@rasputin-ai/node";
5469
- var SDK_VERSION = "0.12.0";
5500
+ var SDK_VERSION = "0.13.0";
5470
5501
 
5471
5502
  // src/rasputin-init.ts
5472
5503
  var publicExecution = (runtime) => ({
@@ -1592,7 +1592,6 @@ var snapshotInstrumentationManifest = (options = {}) => {
1592
1592
  }
1593
1593
  const functions = [];
1594
1594
  const callSites = [];
1595
- const destructures = [];
1596
1595
  const remember = (manifest) => {
1597
1596
  registry.snapshotCache = {
1598
1597
  generation: registry.generation,
@@ -1607,13 +1606,16 @@ var snapshotInstrumentationManifest = (options = {}) => {
1607
1606
  if (!definition.source) continue;
1608
1607
  functions.push({
1609
1608
  functionId: definition.functionId,
1610
- source: definition.source,
1609
+ source: {
1610
+ packageRelativePath: definition.source.packageRelativePath,
1611
+ ...definition.source.packageName ? { packageName: definition.source.packageName } : {},
1612
+ ...definition.source.repositoryPath ? { repositoryPath: definition.source.repositoryPath } : {}
1613
+ },
1611
1614
  name: fn.name,
1612
1615
  startLine: fn.startLine,
1613
1616
  startColumn: fn.startColumn,
1614
1617
  endLine: fn.endLine,
1615
1618
  endColumn: fn.endColumn,
1616
- params: fn.params,
1617
1619
  ...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
1618
1620
  });
1619
1621
  }
@@ -1632,40 +1634,25 @@ var snapshotInstrumentationManifest = (options = {}) => {
1632
1634
  callerFunctionId: site.callerFunctionId,
1633
1635
  calleeName: site.calleeName,
1634
1636
  calleeText: site.calleeText,
1635
- source,
1636
1637
  line: site.line,
1637
1638
  column: site.column,
1638
1639
  endLine: site.endLine,
1639
1640
  endColumn: site.endColumn,
1640
- resultBinding: site.resultBinding,
1641
- argIdentifiers: site.argIdentifiers
1642
- });
1643
- }
1644
- for (const destructure of delta.destructures) {
1645
- const source = sourceAt(destructure.filePath, destructure.line, destructure.column);
1646
- if (!source) continue;
1647
- destructures.push({
1648
- callerFunctionId: destructure.callerFunctionId,
1649
- sourceParam: destructure.sourceParam,
1650
- source,
1651
- line: destructure.line,
1652
- column: destructure.column,
1653
- binding: destructure.binding
1641
+ resultBinding: site.resultBinding
1654
1642
  });
1655
1643
  }
1656
1644
  }
1657
1645
  if (registry.prebuilt && registry.files.size === 0) {
1658
- const prebuilt = registry.prebuilt;
1659
- if (!options.sourceRoot && !options.sourceRoots) return remember(prebuilt);
1646
+ if (!options.sourceRoot && !options.sourceRoots) return remember(registry.prebuilt);
1660
1647
  return remember({
1661
- ...prebuilt,
1648
+ ...registry.prebuilt,
1662
1649
  sourceRoots: {
1663
1650
  ...options.sourceRoot ? { default: options.sourceRoot } : {},
1664
1651
  packages: { ...options.sourceRoots ?? {} }
1665
1652
  }
1666
1653
  });
1667
1654
  }
1668
- if (functions.length === 0 && callSites.length === 0 && destructures.length === 0) {
1655
+ if (functions.length === 0 && callSites.length === 0) {
1669
1656
  return remember(void 0);
1670
1657
  }
1671
1658
  const packages = { ...options.sourceRoots ?? {} };
@@ -1678,8 +1665,7 @@ var snapshotInstrumentationManifest = (options = {}) => {
1678
1665
  }
1679
1666
  } : {},
1680
1667
  functions,
1681
- callSites,
1682
- destructures
1668
+ callSites
1683
1669
  });
1684
1670
  };
1685
1671
  var resetInstrumentationManifestRegistry = () => {
@@ -1606,7 +1606,7 @@ import ts14 from "typescript";
1606
1606
  import { originalPositionFor as originalPositionFor2, TraceMap as TraceMap3 } from "@jridgewell/trace-mapping";
1607
1607
 
1608
1608
  // src/sdk-meta.ts
1609
- var SDK_VERSION = "0.12.0";
1609
+ var SDK_VERSION = "0.13.0";
1610
1610
 
1611
1611
  // src/auto-instrumentation/source-map-locations.ts
1612
1612
  import { readFileSync } from "node:fs";
@@ -1668,7 +1668,7 @@ import ts14 from "typescript";
1668
1668
  import { originalPositionFor as originalPositionFor3, TraceMap as TraceMap4 } from "@jridgewell/trace-mapping";
1669
1669
 
1670
1670
  // src/sdk-meta.ts
1671
- var SDK_VERSION = "0.12.0";
1671
+ var SDK_VERSION = "0.13.0";
1672
1672
 
1673
1673
  // src/auto-instrumentation/transform-disk-cache.ts
1674
1674
  var projectCacheDir = () => {
package/dist/internal.js CHANGED
@@ -314,7 +314,6 @@ var snapshotInstrumentationManifest = (options = {}) => {
314
314
  }
315
315
  const functions = [];
316
316
  const callSites = [];
317
- const destructures = [];
318
317
  const remember = (manifest) => {
319
318
  registry.snapshotCache = {
320
319
  generation: registry.generation,
@@ -329,13 +328,16 @@ var snapshotInstrumentationManifest = (options = {}) => {
329
328
  if (!definition.source) continue;
330
329
  functions.push({
331
330
  functionId: definition.functionId,
332
- source: definition.source,
331
+ source: {
332
+ packageRelativePath: definition.source.packageRelativePath,
333
+ ...definition.source.packageName ? { packageName: definition.source.packageName } : {},
334
+ ...definition.source.repositoryPath ? { repositoryPath: definition.source.repositoryPath } : {}
335
+ },
333
336
  name: fn.name,
334
337
  startLine: fn.startLine,
335
338
  startColumn: fn.startColumn,
336
339
  endLine: fn.endLine,
337
340
  endColumn: fn.endColumn,
338
- params: fn.params,
339
341
  ...fn.instrumented === false ? { instrumented: false, skipReason: fn.skipReason } : {}
340
342
  });
341
343
  }
@@ -354,40 +356,25 @@ var snapshotInstrumentationManifest = (options = {}) => {
354
356
  callerFunctionId: site.callerFunctionId,
355
357
  calleeName: site.calleeName,
356
358
  calleeText: site.calleeText,
357
- source,
358
359
  line: site.line,
359
360
  column: site.column,
360
361
  endLine: site.endLine,
361
362
  endColumn: site.endColumn,
362
- resultBinding: site.resultBinding,
363
- argIdentifiers: site.argIdentifiers
364
- });
365
- }
366
- for (const destructure of delta.destructures) {
367
- const source = sourceAt(destructure.filePath, destructure.line, destructure.column);
368
- if (!source) continue;
369
- destructures.push({
370
- callerFunctionId: destructure.callerFunctionId,
371
- sourceParam: destructure.sourceParam,
372
- source,
373
- line: destructure.line,
374
- column: destructure.column,
375
- binding: destructure.binding
363
+ resultBinding: site.resultBinding
376
364
  });
377
365
  }
378
366
  }
379
367
  if (registry.prebuilt && registry.files.size === 0) {
380
- const prebuilt = registry.prebuilt;
381
- if (!options.sourceRoot && !options.sourceRoots) return remember(prebuilt);
368
+ if (!options.sourceRoot && !options.sourceRoots) return remember(registry.prebuilt);
382
369
  return remember({
383
- ...prebuilt,
370
+ ...registry.prebuilt,
384
371
  sourceRoots: {
385
372
  ...options.sourceRoot ? { default: options.sourceRoot } : {},
386
373
  packages: { ...options.sourceRoots ?? {} }
387
374
  }
388
375
  });
389
376
  }
390
- if (functions.length === 0 && callSites.length === 0 && destructures.length === 0) {
377
+ if (functions.length === 0 && callSites.length === 0) {
391
378
  return remember(void 0);
392
379
  }
393
380
  const packages = { ...options.sourceRoots ?? {} };
@@ -400,10 +387,27 @@ var snapshotInstrumentationManifest = (options = {}) => {
400
387
  }
401
388
  } : {},
402
389
  functions,
403
- callSites,
404
- destructures
390
+ callSites
405
391
  });
406
392
  };
393
+ var collectParamsByFunctionId = () => {
394
+ const registry = getRegistry();
395
+ if (registry.paramsCache?.generation === registry.generation) return registry.paramsCache.params;
396
+ const params = /* @__PURE__ */ new Map();
397
+ for (const delta of registry.files.values()) {
398
+ for (const fn of delta.functions) {
399
+ if (!fn.params || fn.params.length === 0) continue;
400
+ const definition = definitionFromEncodedPlan(fn.plan);
401
+ params.set(definition.functionId, fn.params);
402
+ }
403
+ }
404
+ registry.paramsCache = { generation: registry.generation, params };
405
+ return params;
406
+ };
407
+ var paramsForRuntimeFunction = (functionId) => {
408
+ const params = collectParamsByFunctionId().get(functionId);
409
+ return params && params.length > 0 ? params : void 0;
410
+ };
407
411
  var markInstrumentationManifestUploaded = (generation) => {
408
412
  const registry = getRegistry();
409
413
  if (registry.generation === generation) registry.uploadedGeneration = generation;
@@ -2987,11 +2991,14 @@ var createExecutionRecorder = (options, hooks = {}) => {
2987
2991
  };
2988
2992
  const skipCapture = (store, plan) => store.suppressCapture || plan.excluded || Boolean(store.recording.sessionExcludes?.(plan.definition));
2989
2993
  const durationSamplingApplies = (recording) => durationSamplingEnabled && recording.identityResolved === true && !recording.captureValues && !recording.retainSuccess;
2990
- const callerStore = (store, functionId, callId) => ({
2991
- ...store,
2992
- currentFunctionId: functionId,
2993
- ...callId === void 0 ? {} : { currentCallId: callId }
2994
- });
2994
+ const callStoreFor = (store, functionId, callId) => {
2995
+ const next = { ...store, currentCallId: callId };
2996
+ if (durationSamplingEnabled) next.currentFunctionId = functionId;
2997
+ return next;
2998
+ };
2999
+ const samplingStore = (store, functionId) => {
3000
+ return durationSamplingEnabled ? { ...store, currentFunctionId: functionId } : store;
3001
+ };
2995
3002
  const decideCallTiming = (recording, plan, callerFunctionId) => {
2996
3003
  if (!durationSamplingApplies(recording) || !durationSamples) return true;
2997
3004
  const typeKey = executionTypeKey(recording.execution);
@@ -3072,12 +3079,14 @@ var createExecutionRecorder = (options, hooks = {}) => {
3072
3079
  if (cached) return cached;
3073
3080
  const prepared = plans.map((encoded) => {
3074
3081
  const definition = definitionFromEncodedPlan(encoded);
3082
+ const params = paramsForRuntimeFunction(definition.functionId);
3083
+ const withParams = params && params.length > 0 ? { ...definition, params } : definition;
3075
3084
  return storePlan({
3076
3085
  runtimePlanId: nextRuntimePlanId++,
3077
- definition,
3078
- functionId: definition.functionId,
3079
- excluded: excludesSource(definition),
3080
- estimatedCallBytes: estimatedCallBytesFor(definition.functionId),
3086
+ definition: withParams,
3087
+ functionId: withParams.functionId,
3088
+ excluded: excludesSource(withParams),
3089
+ estimatedCallBytes: estimatedCallBytesFor(withParams.functionId),
3081
3090
  omitCallValues: encodedPlanOmitsCallValues(encoded)
3082
3091
  });
3083
3092
  });
@@ -3791,7 +3800,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3791
3800
  const startedAtNs2 = timed ? readCallClock() : 0n;
3792
3801
  try {
3793
3802
  const result = runStore(
3794
- callerStore(store, plan.functionId),
3803
+ samplingStore(store, plan.functionId),
3795
3804
  function __rasputinHandleRun__5() {
3796
3805
  return callback();
3797
3806
  }
@@ -3815,7 +3824,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3815
3824
  const startedAtNs = timed ? readCallClock() : 0n;
3816
3825
  if (!journal) {
3817
3826
  memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes);
3818
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3827
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3819
3828
  return observeRecordedCallback(
3820
3829
  recording,
3821
3830
  recorderStartedAtNs,
@@ -3834,7 +3843,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3834
3843
  countDroppedEvents(recording, droppedBefore);
3835
3844
  settleInFlight(recording);
3836
3845
  };
3837
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3846
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3838
3847
  return observeRecordedCallback(
3839
3848
  recording,
3840
3849
  recorderStartedAtNs,
@@ -3848,7 +3857,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3848
3857
  });
3849
3858
  }
3850
3859
  if (!memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes)) {
3851
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3860
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3852
3861
  return observeRecordedCallback(
3853
3862
  recording,
3854
3863
  recorderStartedAtNs,
@@ -3867,7 +3876,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3867
3876
  journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
3868
3877
  } catch {
3869
3878
  journal.dropCall();
3870
- return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3879
+ return runStore(samplingStore(store, plan.functionId), function __rasputinHandleRun__5() {
3871
3880
  return observeRecordedCallback(
3872
3881
  recording,
3873
3882
  recorderStartedAtNs,
@@ -3879,7 +3888,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3879
3888
  );
3880
3889
  });
3881
3890
  }
3882
- const callStore = callerStore(store, plan.functionId, callId);
3891
+ const callStore = callStoreFor(store, plan.functionId, callId);
3883
3892
  return runStore(callStore, function __rasputinHandleRun__5() {
3884
3893
  return observeRecordedCallback(
3885
3894
  recording,
@@ -3951,6 +3960,25 @@ var createExecutionRecorder = (options, hooks = {}) => {
3951
3960
  this.parentStore = parentStore;
3952
3961
  this.group = group;
3953
3962
  this.captureDroppedThrow = captureDroppedThrow;
3963
+ this.callerClaimed = false;
3964
+ }
3965
+ claimCaller() {
3966
+ if (this.callerClaimed || !durationSamplingEnabled || !this.plan) return;
3967
+ if (this.activeStore !== this.parentStore) return;
3968
+ this.previousFunctionId = this.parentStore.currentFunctionId;
3969
+ this.parentStore.currentFunctionId = this.plan.functionId;
3970
+ this.callerClaimed = true;
3971
+ }
3972
+ reclaimCaller() {
3973
+ if (!durationSamplingEnabled || !this.plan || this.activeStore !== this.parentStore) return;
3974
+ this.parentStore.currentFunctionId = this.plan.functionId;
3975
+ this.callerClaimed = true;
3976
+ }
3977
+ releaseCaller() {
3978
+ if (!this.callerClaimed) return;
3979
+ this.callerClaimed = false;
3980
+ if (this.previousFunctionId === void 0) delete this.parentStore.currentFunctionId;
3981
+ else this.parentStore.currentFunctionId = this.previousFunctionId;
3954
3982
  }
3955
3983
  leave(value) {
3956
3984
  try {
@@ -4020,6 +4048,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4020
4048
  try {
4021
4049
  if (this.ended) return;
4022
4050
  this.ended = true;
4051
+ this.releaseCaller();
4023
4052
  if (this.mode !== "excluded") settleInFlight(this.recording);
4024
4053
  expectStore(this, this.activeStore);
4025
4054
  enterStore(this, this.parentStore);
@@ -4043,6 +4072,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4043
4072
  try {
4044
4073
  expectStore(this, this.activeStore);
4045
4074
  this.suspended = true;
4075
+ this.releaseCaller();
4046
4076
  enterStore(this, this.parentStore);
4047
4077
  return value;
4048
4078
  } catch {
@@ -4056,6 +4086,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4056
4086
  expectStore(this, this.parentStore);
4057
4087
  this.suspended = false;
4058
4088
  enterStore(this, this.activeStore);
4089
+ this.reclaimCaller();
4059
4090
  } else {
4060
4091
  expectStore(this, this.activeStore);
4061
4092
  }
@@ -4114,12 +4145,11 @@ var createExecutionRecorder = (options, hooks = {}) => {
4114
4145
  capturedError.commit();
4115
4146
  };
4116
4147
  const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, group, captureDroppedThrow) => {
4117
- const activeStore = callerStore(parentStore, plan.functionId);
4118
4148
  const frame = new CallFrame(
4119
4149
  mode,
4120
4150
  recording,
4121
4151
  parentStore,
4122
- activeStore,
4152
+ parentStore,
4123
4153
  plan,
4124
4154
  args,
4125
4155
  omitCallValues,
@@ -4130,7 +4160,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
4130
4160
  group,
4131
4161
  captureDroppedThrow
4132
4162
  );
4133
- enterStore(frame, activeStore);
4163
+ frame.claimCaller();
4164
+ enterStore(frame, parentStore);
4134
4165
  return frame;
4135
4166
  };
4136
4167
  const enterPreparedFunctionFromStore = (store, plan, args, omitValues) => {
@@ -4277,7 +4308,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4277
4308
  false
4278
4309
  );
4279
4310
  }
4280
- const callStore = callerStore(store, plan.functionId, callId);
4311
+ const callStore = callStoreFor(store, plan.functionId, callId);
4281
4312
  const captured = new CallFrame(
4282
4313
  "captured",
4283
4314
  recording,
@@ -1,4 +1,4 @@
1
1
  /** Generated by scripts/generate-sdk-meta.ts — do not edit. */
2
2
  export declare const SDK_NAME = "@rasputin-ai/node";
3
- export declare const SDK_VERSION = "0.12.0";
3
+ export declare const SDK_VERSION = "0.13.0";
4
4
  //# sourceMappingURL=sdk-meta.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rasputin-ai/node",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Official Rasputin AI SDK for Node and Bun.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@jridgewell/trace-mapping": "0.3.31",
52
- "@rasputin-ai/core": "0.12.0",
52
+ "@rasputin-ai/core": "0.13.0",
53
53
  "typescript": "5"
54
54
  },
55
55
  "devDependencies": {