@rasputin-ai/node 0.11.0 → 0.11.2

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 +1 @@
1
- {"version":3,"file":"execution-recording-sync.d.ts","sourceRoot":"","sources":["../../src/execution-recorder/execution-recording-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,cAAc,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAEX,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAqB,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAe9F,KAAK,6BAA6B,GAAG,uBAAuB,GAAG;IAC9D,YAAY,EAAE,MAAM,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC5D,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,kBAAkB,GAAG,SAAS,CAAC;IAC7F,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,gBAAgB,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC7D,CAAC;AAEF,KAAK,oCAAoC,GAAG;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AA+BF,eAAO,MAAM,mCAAmC,GAC/C,SAAS,oCAAoC,KAC3C,6BAsrBF,CAAC"}
1
+ {"version":3,"file":"execution-recording-sync.d.ts","sourceRoot":"","sources":["../../src/execution-recorder/execution-recording-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,cAAc,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAEX,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAqB,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAe9F,KAAK,6BAA6B,GAAG,uBAAuB,GAAG;IAC9D,YAAY,EAAE,MAAM,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC5D,cAAc,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,kBAAkB,GAAG,SAAS,CAAC;IAC7F,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,gBAAgB,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC7D,CAAC;AAEF,KAAK,oCAAoC,GAAG;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAwCF,eAAO,MAAM,mCAAmC,GAC/C,SAAS,oCAAoC,KAC3C,6BA0rBF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"session-freeze-overrides.d.ts","sourceRoot":"","sources":["../../src/execution-recorder/session-freeze-overrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,wBAAwB,EAExB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG7E,KAAK,wBAAwB,GAAG;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAsCF,eAAO,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,wBAAwB,GAAG,SA0BhF,CAAC;AAqDF,eAAO,MAAM,wBAAwB,GACpC,SAAS,wBAAwB,GAAG,SAAS,EAC7C,WAAW,OAAO;;;;;;;;;;;;;;;;CAiBjB,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,SAAS,wBAAwB,GAAG,SAAS;+BAMrE,wBAAwB,GAAG,SAAS,KAC7C,cAAc,GAAG,SAAS;CAoB9B,CAAC"}
1
+ {"version":3,"file":"session-freeze-overrides.d.ts","sourceRoot":"","sources":["../../src/execution-recorder/session-freeze-overrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,wBAAwB,EAExB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG7E,KAAK,wBAAwB,GAAG;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AA2CF,eAAO,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,wBAAwB,GAAG,SA4DhF,CAAC;AAqDF,eAAO,MAAM,wBAAwB,GACpC,SAAS,wBAAwB,GAAG,SAAS,EAC7C,WAAW,OAAO;;;;;;;;;;;;;;;;CAiBjB,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,SAAS,wBAAwB,GAAG,SAAS;+BAMrE,wBAAwB,GAAG,SAAS,KAC7C,cAAc,GAAG,SAAS;CAoB9B,CAAC"}
package/dist/index.js CHANGED
@@ -1299,7 +1299,7 @@ var settleFinalBytes = (state) => {
1299
1299
  var dropEventValues = (events) => {
1300
1300
  let dropped = 0;
1301
1301
  const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
1302
- const bounded = events.map((event) => {
1302
+ const bounded2 = events.map((event) => {
1303
1303
  if (event.type === "function_enter") {
1304
1304
  if (event.args === void 0) return { ...event };
1305
1305
  dropped += event.args.length;
@@ -1315,7 +1315,7 @@ var dropEventValues = (events) => {
1315
1315
  }
1316
1316
  return { ...event };
1317
1317
  });
1318
- return { events: bounded, dropped };
1318
+ return { events: bounded2, dropped };
1319
1319
  };
1320
1320
  var truncateUtf8 = (value, maximumBytes) => {
1321
1321
  if (value === void 0 || Buffer.byteLength(value, "utf8") <= maximumBytes) return value;
@@ -2421,8 +2421,8 @@ var encodeFrozenWithBytes = (frozen, visitedNodes, maxSerializedValueBytes) => {
2421
2421
  const encoded = encodeFrozen(frozen);
2422
2422
  const bytes = jsonLiteralUtf8Bytes(encoded);
2423
2423
  if (!isByteBudgetStub(encoded) && bytes > maxSerializedValueBytes) {
2424
- const bounded = truncation("max_serialized_value_bytes", { __serialized_bytes: bytes });
2425
- return { value: bounded, bytes: jsonLiteralUtf8Bytes(bounded), visitedNodes };
2424
+ const bounded2 = truncation("max_serialized_value_bytes", { __serialized_bytes: bytes });
2425
+ return { value: bounded2, bytes: jsonLiteralUtf8Bytes(bounded2), visitedNodes };
2426
2426
  }
2427
2427
  return { value: encoded, bytes, visitedNodes };
2428
2428
  };
@@ -2863,14 +2863,13 @@ var createExecutionRecorder = (options, hooks = {}) => {
2863
2863
  recording.sessionExcludes = createSourceExclusionMatcher(session.excludeSources);
2864
2864
  }
2865
2865
  if (session.maxCapturedCallsPerFunction !== void 0) {
2866
- recording.sessionMaxCapturedCalls = Math.min(
2867
- maxCapturedCallsPerFunction,
2868
- Math.max(1, Math.round(session.maxCapturedCallsPerFunction))
2866
+ recording.sessionMaxCapturedCalls = Math.max(
2867
+ 1,
2868
+ Math.round(session.maxCapturedCallsPerFunction)
2869
2869
  );
2870
2870
  }
2871
2871
  if (session.maxExecutionHoldMs !== void 0) {
2872
- const requestedNs = BigInt(Math.max(1, Math.round(session.maxExecutionHoldMs))) * 1000000n;
2873
- recording.sessionHoldNs = requestedNs < maxExecutionHoldNs ? requestedNs : maxExecutionHoldNs;
2872
+ recording.sessionHoldNs = BigInt(Math.max(1, Math.round(session.maxExecutionHoldMs))) * 1000000n;
2874
2873
  }
2875
2874
  if (wasLight) {
2876
2875
  stats.adaptiveLightExecutions = Math.max(0, stats.adaptiveLightExecutions - 1);
@@ -4241,7 +4240,9 @@ var BOUNDS = {
4241
4240
  maxObjectKeys: { min: 1, max: 100 },
4242
4241
  maxArrayElements: { min: 1, max: 100 },
4243
4242
  maxStringLength: { min: 32, max: 4e3 },
4244
- maxSerializedValueBytes: { min: 1024, max: 64 * 1024 }
4243
+ maxSerializedValueBytes: { min: 1024, max: 64 * 1024 },
4244
+ maxCapturedCallsPerFunction: { min: 1, max: 100 },
4245
+ maxExecutionHoldMs: { min: 1e3, max: 5 * 6e4 }
4245
4246
  };
4246
4247
  var MAX_SERIALIZER_CACHE = 32;
4247
4248
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -4255,9 +4256,10 @@ var optionalStringList = (value) => {
4255
4256
  }
4256
4257
  return out.length > 0 ? out : void 0;
4257
4258
  };
4258
- var clampAgainstProcess = (requested, processValue, min, max) => {
4259
- if (requested === void 0 || !Number.isFinite(requested)) return processValue;
4260
- return Math.min(processValue, Math.min(max, Math.max(min, Math.round(requested))));
4259
+ var bounded = (value, min, max) => Math.min(max, Math.max(min, Math.round(value)));
4260
+ var clampToBounds = (requested, fallback, min, max) => {
4261
+ if (requested === void 0 || !Number.isFinite(requested)) return fallback;
4262
+ return bounded(requested, min, max);
4261
4263
  };
4262
4264
  var parseSessionSettings = (value) => {
4263
4265
  if (!isRecord(value)) return void 0;
@@ -4269,16 +4271,50 @@ var parseSessionSettings = (value) => {
4269
4271
  const maxSerializedValueBytes = optionalFiniteNumber(value.maxSerializedValueBytes);
4270
4272
  const maxCapturedCallsPerFunction = optionalFiniteNumber(value.maxCapturedCallsPerFunction);
4271
4273
  const maxExecutionHoldMs = optionalFiniteNumber(value.maxExecutionHoldMs);
4272
- if (maxDepth !== void 0) overrides.maxDepth = maxDepth;
4273
- if (maxObjectKeys !== void 0) overrides.maxObjectKeys = maxObjectKeys;
4274
- if (maxArrayElements !== void 0) overrides.maxArrayElements = maxArrayElements;
4275
- if (maxStringLength !== void 0) overrides.maxStringLength = maxStringLength;
4276
- if (maxSerializedValueBytes !== void 0)
4277
- overrides.maxSerializedValueBytes = maxSerializedValueBytes;
4274
+ if (maxDepth !== void 0)
4275
+ overrides.maxDepth = bounded(maxDepth, BOUNDS.maxDepth.min, BOUNDS.maxDepth.max);
4276
+ if (maxObjectKeys !== void 0) {
4277
+ overrides.maxObjectKeys = bounded(
4278
+ maxObjectKeys,
4279
+ BOUNDS.maxObjectKeys.min,
4280
+ BOUNDS.maxObjectKeys.max
4281
+ );
4282
+ }
4283
+ if (maxArrayElements !== void 0) {
4284
+ overrides.maxArrayElements = bounded(
4285
+ maxArrayElements,
4286
+ BOUNDS.maxArrayElements.min,
4287
+ BOUNDS.maxArrayElements.max
4288
+ );
4289
+ }
4290
+ if (maxStringLength !== void 0) {
4291
+ overrides.maxStringLength = bounded(
4292
+ maxStringLength,
4293
+ BOUNDS.maxStringLength.min,
4294
+ BOUNDS.maxStringLength.max
4295
+ );
4296
+ }
4297
+ if (maxSerializedValueBytes !== void 0) {
4298
+ overrides.maxSerializedValueBytes = bounded(
4299
+ maxSerializedValueBytes,
4300
+ BOUNDS.maxSerializedValueBytes.min,
4301
+ BOUNDS.maxSerializedValueBytes.max
4302
+ );
4303
+ }
4278
4304
  if (maxCapturedCallsPerFunction !== void 0) {
4279
- overrides.maxCapturedCallsPerFunction = maxCapturedCallsPerFunction;
4305
+ overrides.maxCapturedCallsPerFunction = bounded(
4306
+ maxCapturedCallsPerFunction,
4307
+ BOUNDS.maxCapturedCallsPerFunction.min,
4308
+ BOUNDS.maxCapturedCallsPerFunction.max
4309
+ );
4310
+ }
4311
+ if (maxExecutionHoldMs !== void 0) {
4312
+ overrides.maxExecutionHoldMs = bounded(
4313
+ maxExecutionHoldMs,
4314
+ BOUNDS.maxExecutionHoldMs.min,
4315
+ BOUNDS.maxExecutionHoldMs.max
4316
+ );
4280
4317
  }
4281
- if (maxExecutionHoldMs !== void 0) overrides.maxExecutionHoldMs = maxExecutionHoldMs;
4282
4318
  const excludeSources = optionalStringList(value.excludeSources);
4283
4319
  const redactKeys = optionalStringList(value.redactKeys);
4284
4320
  if (excludeSources) overrides.excludeSources = excludeSources;
@@ -4287,31 +4323,31 @@ var parseSessionSettings = (value) => {
4287
4323
  return Object.keys(overrides).length > 0 ? overrides : void 0;
4288
4324
  };
4289
4325
  var clampSessionFreezeLimits = (overrides, processLimits) => ({
4290
- maxDepth: clampAgainstProcess(
4326
+ maxDepth: clampToBounds(
4291
4327
  overrides?.maxDepth,
4292
4328
  processLimits.maxDepth,
4293
4329
  BOUNDS.maxDepth.min,
4294
4330
  BOUNDS.maxDepth.max
4295
4331
  ),
4296
- maxObjectKeys: clampAgainstProcess(
4332
+ maxObjectKeys: clampToBounds(
4297
4333
  overrides?.maxObjectKeys,
4298
4334
  processLimits.maxObjectKeys,
4299
4335
  BOUNDS.maxObjectKeys.min,
4300
4336
  BOUNDS.maxObjectKeys.max
4301
4337
  ),
4302
- maxArrayElements: clampAgainstProcess(
4338
+ maxArrayElements: clampToBounds(
4303
4339
  overrides?.maxArrayElements,
4304
4340
  processLimits.maxArrayElements,
4305
4341
  BOUNDS.maxArrayElements.min,
4306
4342
  BOUNDS.maxArrayElements.max
4307
4343
  ),
4308
- maxStringLength: clampAgainstProcess(
4344
+ maxStringLength: clampToBounds(
4309
4345
  overrides?.maxStringLength,
4310
4346
  processLimits.maxStringLength,
4311
4347
  BOUNDS.maxStringLength.min,
4312
4348
  BOUNDS.maxStringLength.max
4313
4349
  ),
4314
- maxSerializedValueBytes: clampAgainstProcess(
4350
+ maxSerializedValueBytes: clampToBounds(
4315
4351
  overrides?.maxSerializedValueBytes,
4316
4352
  processLimits.maxSerializedValueBytes,
4317
4353
  BOUNDS.maxSerializedValueBytes.min,
@@ -4393,6 +4429,12 @@ var classifyHttpFailure = (status) => {
4393
4429
  return "non_retryable_http";
4394
4430
  };
4395
4431
  var backoffMs = (attempt) => Math.min(3e3, 250 * 2 ** attempt);
4432
+ var abortFrom = (parent, child) => {
4433
+ const onAbort = () => child.abort();
4434
+ parent.addEventListener("abort", onAbort, { once: true });
4435
+ if (parent.aborted) onAbort();
4436
+ return () => parent.removeEventListener("abort", onAbort);
4437
+ };
4396
4438
  var createExecutionRecordingCoordinator = (options) => {
4397
4439
  const environment = trimmed2(options.environment);
4398
4440
  const nowMs = () => options.nowMs?.() ?? Date.now();
@@ -4511,7 +4553,6 @@ var createExecutionRecordingCoordinator = (options) => {
4511
4553
  if (onAbort) signal.removeEventListener("abort", onAbort);
4512
4554
  }
4513
4555
  };
4514
- const workSignal = (signal) => AbortSignal.any([signal, cancelWork.signal]);
4515
4556
  const interruptWork = () => {
4516
4557
  cancelWork.abort();
4517
4558
  cancelWork = new AbortController();
@@ -4534,19 +4575,17 @@ var createExecutionRecordingCoordinator = (options) => {
4534
4575
  });
4535
4576
  };
4536
4577
  const withRequestTimeout = async (signal, run) => {
4537
- const combined = workSignal(signal);
4538
- const timeout = new AbortController();
4539
- const timer = setTimeout(() => timeout.abort(), REQUEST_TIMEOUT_MS);
4578
+ const request = new AbortController();
4579
+ const timer = setTimeout(() => request.abort(), REQUEST_TIMEOUT_MS);
4540
4580
  timer.unref?.();
4541
- const onAbort = () => timeout.abort();
4542
- combined.addEventListener("abort", onAbort, { once: true });
4543
- if (combined.aborted) timeout.abort();
4544
- const requestSignal = AbortSignal.any([combined, timeout.signal]);
4581
+ const stopParent = abortFrom(signal, request);
4582
+ const stopCancel = abortFrom(cancelWork.signal, request);
4545
4583
  try {
4546
- return await run(requestSignal);
4584
+ return await run(request.signal);
4547
4585
  } finally {
4548
4586
  clearTimeout(timer);
4549
- combined.removeEventListener("abort", onAbort);
4587
+ stopParent();
4588
+ stopCancel();
4550
4589
  }
4551
4590
  };
4552
4591
  const postEncoded = async (url, encoded, signal, readBody) => withRequestTimeout(signal, async (requestSignal) => {
@@ -4799,73 +4838,81 @@ var createExecutionRecordingCoordinator = (options) => {
4799
4838
  await joinUntil(flight, signal);
4800
4839
  };
4801
4840
  const sendRecordings = async (batch, signal) => {
4802
- const combined = workSignal(signal);
4803
- if (combined.aborted) return false;
4804
- let encoded;
4841
+ const followed = new AbortController();
4842
+ const stopParent = abortFrom(signal, followed);
4843
+ const stopCancel = abortFrom(cancelWork.signal, followed);
4844
+ const combined = followed.signal;
4805
4845
  try {
4806
- encoded = await encodeJsonRequestBodyAsync(
4807
- {
4808
- instance_id: instanceId,
4809
- recordings: batch.map((item) => ({
4810
- session_id: item.sessionId,
4811
- execution_id: item.executionId,
4812
- outcome: item.outcome,
4813
- runtime_state: item.runtimeState,
4814
- release: options.release,
4815
- redact_keys: copyRedactKeys([...redactKeys ?? [], ...item.redactKeys ?? []])?.slice(
4816
- 0,
4817
- MAX_REDACT_KEYS
4818
- ),
4819
- scrub_pii: item.scrubPii ?? scrubPii
4820
- }))
4821
- },
4822
- void 0,
4823
- combined
4824
- );
4825
- } catch (error) {
4826
- if (combined.aborted || error instanceof Error && error.name === "AbortError") {
4827
- rememberFailure("aborted");
4828
- return false;
4829
- }
4830
- rememberFailure("network_error");
4831
- return false;
4832
- }
4833
- for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
4834
4846
  if (combined.aborted) return false;
4847
+ let encoded;
4835
4848
  try {
4836
- const { response, body } = await postEncoded(
4837
- options.recordingsUrl,
4838
- encoded,
4839
- combined,
4840
- async (uploadResponse) => {
4841
- if (!uploadResponse.ok) return void 0;
4842
- try {
4843
- return unwrapPayload(await uploadResponse.json());
4844
- } catch {
4845
- return void 0;
4846
- }
4847
- }
4849
+ encoded = await encodeJsonRequestBodyAsync(
4850
+ {
4851
+ instance_id: instanceId,
4852
+ recordings: batch.map((item) => ({
4853
+ session_id: item.sessionId,
4854
+ execution_id: item.executionId,
4855
+ outcome: item.outcome,
4856
+ runtime_state: item.runtimeState,
4857
+ release: options.release,
4858
+ redact_keys: copyRedactKeys([
4859
+ ...redactKeys ?? [],
4860
+ ...item.redactKeys ?? []
4861
+ ])?.slice(0, MAX_REDACT_KEYS),
4862
+ scrub_pii: item.scrubPii ?? scrubPii
4863
+ }))
4864
+ },
4865
+ void 0,
4866
+ combined
4848
4867
  );
4849
- if (response.ok) {
4850
- applyCompletedSessionIds(body?.completed_session_ids);
4851
- return true;
4852
- }
4853
- const kind = classifyHttpFailure(response.status);
4854
- rememberFailure(kind);
4855
- if (kind === "non_retryable_http") return true;
4856
- if (attempt === MAX_RETRIES) return false;
4857
- await wait(backoffMs(attempt), combined);
4858
4868
  } catch (error) {
4859
4869
  if (combined.aborted || error instanceof Error && error.name === "AbortError") {
4860
4870
  rememberFailure("aborted");
4861
4871
  return false;
4862
4872
  }
4863
4873
  rememberFailure("network_error");
4864
- if (attempt === MAX_RETRIES) return false;
4865
- await wait(backoffMs(attempt), combined);
4874
+ return false;
4866
4875
  }
4876
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
4877
+ if (combined.aborted) return false;
4878
+ try {
4879
+ const { response, body } = await postEncoded(
4880
+ options.recordingsUrl,
4881
+ encoded,
4882
+ combined,
4883
+ async (uploadResponse) => {
4884
+ if (!uploadResponse.ok) return void 0;
4885
+ try {
4886
+ return unwrapPayload(await uploadResponse.json());
4887
+ } catch {
4888
+ return void 0;
4889
+ }
4890
+ }
4891
+ );
4892
+ if (response.ok) {
4893
+ applyCompletedSessionIds(body?.completed_session_ids);
4894
+ return true;
4895
+ }
4896
+ const kind = classifyHttpFailure(response.status);
4897
+ rememberFailure(kind);
4898
+ if (kind === "non_retryable_http") return true;
4899
+ if (attempt === MAX_RETRIES) return false;
4900
+ await wait(backoffMs(attempt), combined);
4901
+ } catch (error) {
4902
+ if (combined.aborted || error instanceof Error && error.name === "AbortError") {
4903
+ rememberFailure("aborted");
4904
+ return false;
4905
+ }
4906
+ rememberFailure("network_error");
4907
+ if (attempt === MAX_RETRIES) return false;
4908
+ await wait(backoffMs(attempt), combined);
4909
+ }
4910
+ }
4911
+ return false;
4912
+ } finally {
4913
+ stopParent();
4914
+ stopCancel();
4867
4915
  }
4868
- return false;
4869
4916
  };
4870
4917
  const drainRecordings = async (signal) => {
4871
4918
  while (recordings.length > 0 && !signal.aborted) {
@@ -5197,7 +5244,7 @@ var installGlobalHandlers = (client, options = {}) => {
5197
5244
 
5198
5245
  // src/sdk-meta.ts
5199
5246
  var SDK_NAME = "@rasputin-ai/node";
5200
- var SDK_VERSION = "0.11.0";
5247
+ var SDK_VERSION = "0.11.2";
5201
5248
 
5202
5249
  // src/rasputin-init.ts
5203
5250
  var publicExecution = (runtime) => ({
@@ -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.11.0";
1609
+ var SDK_VERSION = "0.11.2";
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.11.0";
1671
+ var SDK_VERSION = "0.11.2";
1672
1672
 
1673
1673
  // src/auto-instrumentation/transform-disk-cache.ts
1674
1674
  var projectCacheDir = () => {
package/dist/internal.js CHANGED
@@ -1269,7 +1269,7 @@ var settleFinalBytes = (state) => {
1269
1269
  var dropEventValues = (events) => {
1270
1270
  let dropped = 0;
1271
1271
  const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
1272
- const bounded = events.map((event) => {
1272
+ const bounded2 = events.map((event) => {
1273
1273
  if (event.type === "function_enter") {
1274
1274
  if (event.args === void 0) return { ...event };
1275
1275
  dropped += event.args.length;
@@ -1285,7 +1285,7 @@ var dropEventValues = (events) => {
1285
1285
  }
1286
1286
  return { ...event };
1287
1287
  });
1288
- return { events: bounded, dropped };
1288
+ return { events: bounded2, dropped };
1289
1289
  };
1290
1290
  var truncateUtf8 = (value, maximumBytes) => {
1291
1291
  if (value === void 0 || Buffer.byteLength(value, "utf8") <= maximumBytes) return value;
@@ -2391,8 +2391,8 @@ var encodeFrozenWithBytes = (frozen, visitedNodes, maxSerializedValueBytes) => {
2391
2391
  const encoded = encodeFrozen(frozen);
2392
2392
  const bytes = jsonLiteralUtf8Bytes(encoded);
2393
2393
  if (!isByteBudgetStub(encoded) && bytes > maxSerializedValueBytes) {
2394
- const bounded = truncation("max_serialized_value_bytes", { __serialized_bytes: bytes });
2395
- return { value: bounded, bytes: jsonLiteralUtf8Bytes(bounded), visitedNodes };
2394
+ const bounded2 = truncation("max_serialized_value_bytes", { __serialized_bytes: bytes });
2395
+ return { value: bounded2, bytes: jsonLiteralUtf8Bytes(bounded2), visitedNodes };
2396
2396
  }
2397
2397
  return { value: encoded, bytes, visitedNodes };
2398
2398
  };
@@ -2833,14 +2833,13 @@ var createExecutionRecorder = (options, hooks = {}) => {
2833
2833
  recording.sessionExcludes = createSourceExclusionMatcher(session.excludeSources);
2834
2834
  }
2835
2835
  if (session.maxCapturedCallsPerFunction !== void 0) {
2836
- recording.sessionMaxCapturedCalls = Math.min(
2837
- maxCapturedCallsPerFunction,
2838
- Math.max(1, Math.round(session.maxCapturedCallsPerFunction))
2836
+ recording.sessionMaxCapturedCalls = Math.max(
2837
+ 1,
2838
+ Math.round(session.maxCapturedCallsPerFunction)
2839
2839
  );
2840
2840
  }
2841
2841
  if (session.maxExecutionHoldMs !== void 0) {
2842
- const requestedNs = BigInt(Math.max(1, Math.round(session.maxExecutionHoldMs))) * 1000000n;
2843
- recording.sessionHoldNs = requestedNs < maxExecutionHoldNs ? requestedNs : maxExecutionHoldNs;
2842
+ recording.sessionHoldNs = BigInt(Math.max(1, Math.round(session.maxExecutionHoldMs))) * 1000000n;
2844
2843
  }
2845
2844
  if (wasLight) {
2846
2845
  stats.adaptiveLightExecutions = Math.max(0, stats.adaptiveLightExecutions - 1);
@@ -4211,7 +4210,9 @@ var BOUNDS = {
4211
4210
  maxObjectKeys: { min: 1, max: 100 },
4212
4211
  maxArrayElements: { min: 1, max: 100 },
4213
4212
  maxStringLength: { min: 32, max: 4e3 },
4214
- maxSerializedValueBytes: { min: 1024, max: 64 * 1024 }
4213
+ maxSerializedValueBytes: { min: 1024, max: 64 * 1024 },
4214
+ maxCapturedCallsPerFunction: { min: 1, max: 100 },
4215
+ maxExecutionHoldMs: { min: 1e3, max: 5 * 6e4 }
4215
4216
  };
4216
4217
  var MAX_SERIALIZER_CACHE = 32;
4217
4218
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -4225,9 +4226,10 @@ var optionalStringList = (value) => {
4225
4226
  }
4226
4227
  return out.length > 0 ? out : void 0;
4227
4228
  };
4228
- var clampAgainstProcess = (requested, processValue, min, max) => {
4229
- if (requested === void 0 || !Number.isFinite(requested)) return processValue;
4230
- return Math.min(processValue, Math.min(max, Math.max(min, Math.round(requested))));
4229
+ var bounded = (value, min, max) => Math.min(max, Math.max(min, Math.round(value)));
4230
+ var clampToBounds = (requested, fallback, min, max) => {
4231
+ if (requested === void 0 || !Number.isFinite(requested)) return fallback;
4232
+ return bounded(requested, min, max);
4231
4233
  };
4232
4234
  var parseSessionSettings = (value) => {
4233
4235
  if (!isRecord(value)) return void 0;
@@ -4239,16 +4241,50 @@ var parseSessionSettings = (value) => {
4239
4241
  const maxSerializedValueBytes = optionalFiniteNumber(value.maxSerializedValueBytes);
4240
4242
  const maxCapturedCallsPerFunction = optionalFiniteNumber(value.maxCapturedCallsPerFunction);
4241
4243
  const maxExecutionHoldMs = optionalFiniteNumber(value.maxExecutionHoldMs);
4242
- if (maxDepth !== void 0) overrides.maxDepth = maxDepth;
4243
- if (maxObjectKeys !== void 0) overrides.maxObjectKeys = maxObjectKeys;
4244
- if (maxArrayElements !== void 0) overrides.maxArrayElements = maxArrayElements;
4245
- if (maxStringLength !== void 0) overrides.maxStringLength = maxStringLength;
4246
- if (maxSerializedValueBytes !== void 0)
4247
- overrides.maxSerializedValueBytes = maxSerializedValueBytes;
4244
+ if (maxDepth !== void 0)
4245
+ overrides.maxDepth = bounded(maxDepth, BOUNDS.maxDepth.min, BOUNDS.maxDepth.max);
4246
+ if (maxObjectKeys !== void 0) {
4247
+ overrides.maxObjectKeys = bounded(
4248
+ maxObjectKeys,
4249
+ BOUNDS.maxObjectKeys.min,
4250
+ BOUNDS.maxObjectKeys.max
4251
+ );
4252
+ }
4253
+ if (maxArrayElements !== void 0) {
4254
+ overrides.maxArrayElements = bounded(
4255
+ maxArrayElements,
4256
+ BOUNDS.maxArrayElements.min,
4257
+ BOUNDS.maxArrayElements.max
4258
+ );
4259
+ }
4260
+ if (maxStringLength !== void 0) {
4261
+ overrides.maxStringLength = bounded(
4262
+ maxStringLength,
4263
+ BOUNDS.maxStringLength.min,
4264
+ BOUNDS.maxStringLength.max
4265
+ );
4266
+ }
4267
+ if (maxSerializedValueBytes !== void 0) {
4268
+ overrides.maxSerializedValueBytes = bounded(
4269
+ maxSerializedValueBytes,
4270
+ BOUNDS.maxSerializedValueBytes.min,
4271
+ BOUNDS.maxSerializedValueBytes.max
4272
+ );
4273
+ }
4248
4274
  if (maxCapturedCallsPerFunction !== void 0) {
4249
- overrides.maxCapturedCallsPerFunction = maxCapturedCallsPerFunction;
4275
+ overrides.maxCapturedCallsPerFunction = bounded(
4276
+ maxCapturedCallsPerFunction,
4277
+ BOUNDS.maxCapturedCallsPerFunction.min,
4278
+ BOUNDS.maxCapturedCallsPerFunction.max
4279
+ );
4280
+ }
4281
+ if (maxExecutionHoldMs !== void 0) {
4282
+ overrides.maxExecutionHoldMs = bounded(
4283
+ maxExecutionHoldMs,
4284
+ BOUNDS.maxExecutionHoldMs.min,
4285
+ BOUNDS.maxExecutionHoldMs.max
4286
+ );
4250
4287
  }
4251
- if (maxExecutionHoldMs !== void 0) overrides.maxExecutionHoldMs = maxExecutionHoldMs;
4252
4288
  const excludeSources = optionalStringList(value.excludeSources);
4253
4289
  const redactKeys = optionalStringList(value.redactKeys);
4254
4290
  if (excludeSources) overrides.excludeSources = excludeSources;
@@ -4257,31 +4293,31 @@ var parseSessionSettings = (value) => {
4257
4293
  return Object.keys(overrides).length > 0 ? overrides : void 0;
4258
4294
  };
4259
4295
  var clampSessionFreezeLimits = (overrides, processLimits) => ({
4260
- maxDepth: clampAgainstProcess(
4296
+ maxDepth: clampToBounds(
4261
4297
  overrides?.maxDepth,
4262
4298
  processLimits.maxDepth,
4263
4299
  BOUNDS.maxDepth.min,
4264
4300
  BOUNDS.maxDepth.max
4265
4301
  ),
4266
- maxObjectKeys: clampAgainstProcess(
4302
+ maxObjectKeys: clampToBounds(
4267
4303
  overrides?.maxObjectKeys,
4268
4304
  processLimits.maxObjectKeys,
4269
4305
  BOUNDS.maxObjectKeys.min,
4270
4306
  BOUNDS.maxObjectKeys.max
4271
4307
  ),
4272
- maxArrayElements: clampAgainstProcess(
4308
+ maxArrayElements: clampToBounds(
4273
4309
  overrides?.maxArrayElements,
4274
4310
  processLimits.maxArrayElements,
4275
4311
  BOUNDS.maxArrayElements.min,
4276
4312
  BOUNDS.maxArrayElements.max
4277
4313
  ),
4278
- maxStringLength: clampAgainstProcess(
4314
+ maxStringLength: clampToBounds(
4279
4315
  overrides?.maxStringLength,
4280
4316
  processLimits.maxStringLength,
4281
4317
  BOUNDS.maxStringLength.min,
4282
4318
  BOUNDS.maxStringLength.max
4283
4319
  ),
4284
- maxSerializedValueBytes: clampAgainstProcess(
4320
+ maxSerializedValueBytes: clampToBounds(
4285
4321
  overrides?.maxSerializedValueBytes,
4286
4322
  processLimits.maxSerializedValueBytes,
4287
4323
  BOUNDS.maxSerializedValueBytes.min,
@@ -4363,6 +4399,12 @@ var classifyHttpFailure = (status) => {
4363
4399
  return "non_retryable_http";
4364
4400
  };
4365
4401
  var backoffMs = (attempt) => Math.min(3e3, 250 * 2 ** attempt);
4402
+ var abortFrom = (parent, child) => {
4403
+ const onAbort = () => child.abort();
4404
+ parent.addEventListener("abort", onAbort, { once: true });
4405
+ if (parent.aborted) onAbort();
4406
+ return () => parent.removeEventListener("abort", onAbort);
4407
+ };
4366
4408
  var createExecutionRecordingCoordinator = (options) => {
4367
4409
  const environment = trimmed2(options.environment);
4368
4410
  const nowMs = () => options.nowMs?.() ?? Date.now();
@@ -4481,7 +4523,6 @@ var createExecutionRecordingCoordinator = (options) => {
4481
4523
  if (onAbort) signal.removeEventListener("abort", onAbort);
4482
4524
  }
4483
4525
  };
4484
- const workSignal = (signal) => AbortSignal.any([signal, cancelWork.signal]);
4485
4526
  const interruptWork = () => {
4486
4527
  cancelWork.abort();
4487
4528
  cancelWork = new AbortController();
@@ -4504,19 +4545,17 @@ var createExecutionRecordingCoordinator = (options) => {
4504
4545
  });
4505
4546
  };
4506
4547
  const withRequestTimeout = async (signal, run) => {
4507
- const combined = workSignal(signal);
4508
- const timeout = new AbortController();
4509
- const timer = setTimeout(() => timeout.abort(), REQUEST_TIMEOUT_MS);
4548
+ const request = new AbortController();
4549
+ const timer = setTimeout(() => request.abort(), REQUEST_TIMEOUT_MS);
4510
4550
  timer.unref?.();
4511
- const onAbort = () => timeout.abort();
4512
- combined.addEventListener("abort", onAbort, { once: true });
4513
- if (combined.aborted) timeout.abort();
4514
- const requestSignal = AbortSignal.any([combined, timeout.signal]);
4551
+ const stopParent = abortFrom(signal, request);
4552
+ const stopCancel = abortFrom(cancelWork.signal, request);
4515
4553
  try {
4516
- return await run(requestSignal);
4554
+ return await run(request.signal);
4517
4555
  } finally {
4518
4556
  clearTimeout(timer);
4519
- combined.removeEventListener("abort", onAbort);
4557
+ stopParent();
4558
+ stopCancel();
4520
4559
  }
4521
4560
  };
4522
4561
  const postEncoded = async (url, encoded, signal, readBody) => withRequestTimeout(signal, async (requestSignal) => {
@@ -4769,73 +4808,81 @@ var createExecutionRecordingCoordinator = (options) => {
4769
4808
  await joinUntil(flight, signal);
4770
4809
  };
4771
4810
  const sendRecordings = async (batch, signal) => {
4772
- const combined = workSignal(signal);
4773
- if (combined.aborted) return false;
4774
- let encoded;
4811
+ const followed = new AbortController();
4812
+ const stopParent = abortFrom(signal, followed);
4813
+ const stopCancel = abortFrom(cancelWork.signal, followed);
4814
+ const combined = followed.signal;
4775
4815
  try {
4776
- encoded = await encodeJsonRequestBodyAsync(
4777
- {
4778
- instance_id: instanceId,
4779
- recordings: batch.map((item) => ({
4780
- session_id: item.sessionId,
4781
- execution_id: item.executionId,
4782
- outcome: item.outcome,
4783
- runtime_state: item.runtimeState,
4784
- release: options.release,
4785
- redact_keys: copyRedactKeys([...redactKeys ?? [], ...item.redactKeys ?? []])?.slice(
4786
- 0,
4787
- MAX_REDACT_KEYS
4788
- ),
4789
- scrub_pii: item.scrubPii ?? scrubPii
4790
- }))
4791
- },
4792
- void 0,
4793
- combined
4794
- );
4795
- } catch (error) {
4796
- if (combined.aborted || error instanceof Error && error.name === "AbortError") {
4797
- rememberFailure("aborted");
4798
- return false;
4799
- }
4800
- rememberFailure("network_error");
4801
- return false;
4802
- }
4803
- for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
4804
4816
  if (combined.aborted) return false;
4817
+ let encoded;
4805
4818
  try {
4806
- const { response, body } = await postEncoded(
4807
- options.recordingsUrl,
4808
- encoded,
4809
- combined,
4810
- async (uploadResponse) => {
4811
- if (!uploadResponse.ok) return void 0;
4812
- try {
4813
- return unwrapPayload(await uploadResponse.json());
4814
- } catch {
4815
- return void 0;
4816
- }
4817
- }
4819
+ encoded = await encodeJsonRequestBodyAsync(
4820
+ {
4821
+ instance_id: instanceId,
4822
+ recordings: batch.map((item) => ({
4823
+ session_id: item.sessionId,
4824
+ execution_id: item.executionId,
4825
+ outcome: item.outcome,
4826
+ runtime_state: item.runtimeState,
4827
+ release: options.release,
4828
+ redact_keys: copyRedactKeys([
4829
+ ...redactKeys ?? [],
4830
+ ...item.redactKeys ?? []
4831
+ ])?.slice(0, MAX_REDACT_KEYS),
4832
+ scrub_pii: item.scrubPii ?? scrubPii
4833
+ }))
4834
+ },
4835
+ void 0,
4836
+ combined
4818
4837
  );
4819
- if (response.ok) {
4820
- applyCompletedSessionIds(body?.completed_session_ids);
4821
- return true;
4822
- }
4823
- const kind = classifyHttpFailure(response.status);
4824
- rememberFailure(kind);
4825
- if (kind === "non_retryable_http") return true;
4826
- if (attempt === MAX_RETRIES) return false;
4827
- await wait(backoffMs(attempt), combined);
4828
4838
  } catch (error) {
4829
4839
  if (combined.aborted || error instanceof Error && error.name === "AbortError") {
4830
4840
  rememberFailure("aborted");
4831
4841
  return false;
4832
4842
  }
4833
4843
  rememberFailure("network_error");
4834
- if (attempt === MAX_RETRIES) return false;
4835
- await wait(backoffMs(attempt), combined);
4844
+ return false;
4836
4845
  }
4846
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
4847
+ if (combined.aborted) return false;
4848
+ try {
4849
+ const { response, body } = await postEncoded(
4850
+ options.recordingsUrl,
4851
+ encoded,
4852
+ combined,
4853
+ async (uploadResponse) => {
4854
+ if (!uploadResponse.ok) return void 0;
4855
+ try {
4856
+ return unwrapPayload(await uploadResponse.json());
4857
+ } catch {
4858
+ return void 0;
4859
+ }
4860
+ }
4861
+ );
4862
+ if (response.ok) {
4863
+ applyCompletedSessionIds(body?.completed_session_ids);
4864
+ return true;
4865
+ }
4866
+ const kind = classifyHttpFailure(response.status);
4867
+ rememberFailure(kind);
4868
+ if (kind === "non_retryable_http") return true;
4869
+ if (attempt === MAX_RETRIES) return false;
4870
+ await wait(backoffMs(attempt), combined);
4871
+ } catch (error) {
4872
+ if (combined.aborted || error instanceof Error && error.name === "AbortError") {
4873
+ rememberFailure("aborted");
4874
+ return false;
4875
+ }
4876
+ rememberFailure("network_error");
4877
+ if (attempt === MAX_RETRIES) return false;
4878
+ await wait(backoffMs(attempt), combined);
4879
+ }
4880
+ }
4881
+ return false;
4882
+ } finally {
4883
+ stopParent();
4884
+ stopCancel();
4837
4885
  }
4838
- return false;
4839
4886
  };
4840
4887
  const drainRecordings = async (signal) => {
4841
4888
  while (recordings.length > 0 && !signal.aborted) {
@@ -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.11.0";
3
+ export declare const SDK_VERSION = "0.11.2";
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.11.0",
3
+ "version": "0.11.2",
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.11.0",
52
+ "@rasputin-ai/core": "0.11.2",
53
53
  "typescript": "5"
54
54
  },
55
55
  "devDependencies": {