@rasputin-ai/node 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts +1 -1
- package/dist/auto-instrumentation/instrumentation-manifest-registry.d.ts.map +1 -1
- package/dist/auto-instrumentation/source-map-locations.d.ts +1 -1
- package/dist/auto-instrumentation/source-map-locations.d.ts.map +1 -1
- package/dist/auto-instrumentation/transform-disk-cache.d.ts +1 -1
- package/dist/auto-instrumentation/transform-disk-cache.d.ts.map +1 -1
- package/dist/execution-recorder/automatic-runtime.d.ts +2 -33
- package/dist/execution-recorder/automatic-runtime.d.ts.map +1 -1
- package/dist/execution-recorder/encode-frozen.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder-types.d.ts +3 -2
- package/dist/execution-recorder/execution-recorder-types.d.ts.map +1 -1
- package/dist/execution-recorder/execution-recorder.d.ts.map +1 -1
- package/dist/execution-recorder/function-plan.d.ts +7 -22
- package/dist/execution-recorder/function-plan.d.ts.map +1 -1
- package/dist/execution-recorder/runtime-state-size-budget.d.ts.map +1 -1
- package/dist/execution-recorder/value-freeze.d.ts.map +1 -1
- package/dist/index.js +228 -155
- package/dist/instrument/build.js +852 -588
- package/dist/instrument/bun.js +639 -373
- package/dist/instrument/node.js +605 -339
- package/dist/internal.js +225 -152
- package/dist/rasputin-init.d.ts +1 -0
- package/dist/rasputin-init.d.ts.map +1 -1
- package/dist/sdk-meta.d.ts +1 -1
- package/package.json +4 -2
- package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts +0 -29
- package/dist/auto-instrumentation/collect-instrumentation-delta.d.ts.map +0 -1
- package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts +0 -49
- package/dist/auto-instrumentation/instrumentation-manifest-delta.d.ts.map +0 -1
- package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts +0 -3
- package/dist/auto-instrumentation/parameter-initializer-may-run-code.d.ts.map +0 -1
- package/dist/auto-instrumentation/suspension-whitelist.d.ts +0 -33
- package/dist/auto-instrumentation/suspension-whitelist.d.ts.map +0 -1
- package/dist/auto-instrumentation/transform-source.d.ts +0 -27
- package/dist/auto-instrumentation/transform-source.d.ts.map +0 -1
- package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts +0 -2
- package/dist/auto-instrumentation/verify-instrumentation-isomorphism.d.ts.map +0 -1
- package/dist/auto-instrumentation/verify-transformed-source.d.ts +0 -2
- package/dist/auto-instrumentation/verify-transformed-source.d.ts.map +0 -1
- package/dist/execution-recorder/run-exactly-once.d.ts +0 -7
- package/dist/execution-recorder/run-exactly-once.d.ts.map +0 -1
package/dist/internal.js
CHANGED
|
@@ -115,14 +115,89 @@ import {
|
|
|
115
115
|
sourceLocatorFromFile as sourceLocatorFromFile2
|
|
116
116
|
} from "@rasputin-ai/core";
|
|
117
117
|
|
|
118
|
-
// src/
|
|
118
|
+
// ../recorder/src/run-exactly-once.ts
|
|
119
|
+
var runExactlyOnce = function __rasputinHandleRun__(invoke, callback) {
|
|
120
|
+
let outcome;
|
|
121
|
+
const wrapped = function __rasputinHandleRun__3() {
|
|
122
|
+
try {
|
|
123
|
+
const value = callback();
|
|
124
|
+
outcome = { kind: "value", value };
|
|
125
|
+
return value;
|
|
126
|
+
} catch (caught) {
|
|
127
|
+
outcome = { kind: "throw", error: caught };
|
|
128
|
+
throw caught;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
try {
|
|
132
|
+
invoke(wrapped);
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
if (outcome?.kind === "throw") throw outcome.error;
|
|
136
|
+
if (outcome?.kind === "value") return outcome.value;
|
|
137
|
+
return callback();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// ../recorder/src/call-handle.ts
|
|
141
|
+
var passthroughHandle = () => ({
|
|
142
|
+
leave: (value) => value,
|
|
143
|
+
fail: () => {
|
|
144
|
+
},
|
|
145
|
+
end: () => {
|
|
146
|
+
},
|
|
147
|
+
run: function __rasputinHandleRun__3(callback) {
|
|
148
|
+
return runExactlyOnce((invoke) => invoke(), callback);
|
|
149
|
+
},
|
|
150
|
+
suspend: (value) => value,
|
|
151
|
+
resume: (value) => value
|
|
152
|
+
});
|
|
153
|
+
var isolateHandle = (handle) => ({
|
|
154
|
+
leave: (value) => {
|
|
155
|
+
try {
|
|
156
|
+
return handle.leave(value);
|
|
157
|
+
} catch {
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
fail: (error, liveArgs) => {
|
|
162
|
+
try {
|
|
163
|
+
handle.fail(error, liveArgs);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
end: () => {
|
|
168
|
+
try {
|
|
169
|
+
handle.end();
|
|
170
|
+
} catch {
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
run: function __rasputinHandleRun__3(callback) {
|
|
174
|
+
return runExactlyOnce((invoke) => handle.run(invoke), callback);
|
|
175
|
+
},
|
|
176
|
+
suspend: (value) => {
|
|
177
|
+
try {
|
|
178
|
+
return handle.suspend(value);
|
|
179
|
+
} catch {
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
resume: (value) => {
|
|
184
|
+
try {
|
|
185
|
+
return handle.resume(value);
|
|
186
|
+
} catch {
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// ../recorder/src/encoded-function-plan.ts
|
|
193
|
+
var encodedPlanOmitsCallValues = (plan) => plan[6] === 1;
|
|
194
|
+
var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
|
|
195
|
+
|
|
196
|
+
// ../recorder/src/function-plan.ts
|
|
119
197
|
import {
|
|
120
198
|
runtimeFunctionId,
|
|
121
199
|
sourceLocatorFromFile
|
|
122
200
|
} from "@rasputin-ai/core";
|
|
123
|
-
var encodedPlanOmitsCallValues = (plan) => plan[6] === 1;
|
|
124
|
-
var encodedPlanHasPreBodyParameterEvaluation = (plan) => plan[7] === 1;
|
|
125
|
-
var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
|
|
126
201
|
var definitionFromEncodedPlan = (plan) => {
|
|
127
202
|
const [functionId, name, packageName, packageRelativePath, line, column] = plan;
|
|
128
203
|
const source = packageRelativePath ? {
|
|
@@ -138,7 +213,57 @@ var definitionFromEncodedPlan = (plan) => {
|
|
|
138
213
|
...encodedPlanHasPreBodyParameterEvaluation(plan) ? { parentAttribution: "pre_body_parameter_evaluation" } : {}
|
|
139
214
|
};
|
|
140
215
|
};
|
|
141
|
-
|
|
216
|
+
|
|
217
|
+
// ../recorder/src/runtime-symbol.ts
|
|
218
|
+
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
219
|
+
|
|
220
|
+
// ../recorder/src/registry.ts
|
|
221
|
+
var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
|
|
222
|
+
var passthroughRun = (_planIndex, _args, callback) => callback();
|
|
223
|
+
var passthroughEnter = () => passthroughHandle();
|
|
224
|
+
var bindPassthrough = (module) => {
|
|
225
|
+
module.cell.run = passthroughRun;
|
|
226
|
+
module.cell.enter = passthroughEnter;
|
|
227
|
+
};
|
|
228
|
+
var attachRunner = (cell) => {
|
|
229
|
+
const run = ((planIndex, args, callback, omitValues) => cell.run(planIndex, args, callback, omitValues));
|
|
230
|
+
run.enter = (planIndex, args, omitValues, callee) => cell.enter(planIndex, args, omitValues, callee);
|
|
231
|
+
return run;
|
|
232
|
+
};
|
|
233
|
+
var isCompatibleRegistry = (value) => typeof Reflect.get(value, "register") === "function" && Array.isArray(Reflect.get(value, "runtimes")) && Array.isArray(Reflect.get(value, "modules"));
|
|
234
|
+
var registerModule = (registry, plans, moduleIndex) => {
|
|
235
|
+
const cell = { run: passthroughRun, enter: passthroughEnter };
|
|
236
|
+
const module = {
|
|
237
|
+
plans,
|
|
238
|
+
cell,
|
|
239
|
+
...moduleIndex === void 0 ? {} : { moduleIndex }
|
|
240
|
+
};
|
|
241
|
+
registry.modules.push(module);
|
|
242
|
+
registry.runtimes.at(-1)?.bind(module);
|
|
243
|
+
return attachRunner(cell);
|
|
244
|
+
};
|
|
245
|
+
var createRegistry = () => {
|
|
246
|
+
const registry = {
|
|
247
|
+
runtimes: [],
|
|
248
|
+
modules: [],
|
|
249
|
+
register(plans, moduleIndex) {
|
|
250
|
+
return registerModule(registry, plans, moduleIndex);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
return registry;
|
|
254
|
+
};
|
|
255
|
+
var getAutomaticRuntimeRegistry = () => {
|
|
256
|
+
const existing = Reflect.get(globalThis, runtimeSymbol);
|
|
257
|
+
if (existing && typeof existing === "object" && isCompatibleRegistry(existing)) {
|
|
258
|
+
return existing;
|
|
259
|
+
}
|
|
260
|
+
if (existing != null) {
|
|
261
|
+
return createRegistry();
|
|
262
|
+
}
|
|
263
|
+
const registry = createRegistry();
|
|
264
|
+
Reflect.set(globalThis, runtimeSymbol, registry);
|
|
265
|
+
return registry;
|
|
266
|
+
};
|
|
142
267
|
|
|
143
268
|
// src/auto-instrumentation/instrumentation-manifest-registry.ts
|
|
144
269
|
var INSTRUMENTATION_MANIFEST_SYMBOL = "rasputin.instrumentation.manifest.v3";
|
|
@@ -890,6 +1015,10 @@ var ExecutionJournalPool = class {
|
|
|
890
1015
|
}
|
|
891
1016
|
};
|
|
892
1017
|
|
|
1018
|
+
// src/execution-recorder/function-plan.ts
|
|
1019
|
+
var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
|
|
1020
|
+
var estimatedCallBytesFor = (functionId) => EVENT_PAIR_BASE_ESTIMATED_BYTES + Buffer.byteLength(functionId, "utf8") * 2;
|
|
1021
|
+
|
|
893
1022
|
// src/execution-recorder/recorder-memory-budget.ts
|
|
894
1023
|
var EXECUTION_BASE_ESTIMATED_BYTES = 1024;
|
|
895
1024
|
var SUMMARY_EVENT_BASE_ESTIMATED_BYTES = 256;
|
|
@@ -1025,28 +1154,6 @@ var RecorderMemoryBudget = class {
|
|
|
1025
1154
|
}
|
|
1026
1155
|
};
|
|
1027
1156
|
|
|
1028
|
-
// src/execution-recorder/run-exactly-once.ts
|
|
1029
|
-
var runExactlyOnce = function __rasputinHandleRun__(invoke, callback) {
|
|
1030
|
-
let outcome;
|
|
1031
|
-
const wrapped = function __rasputinHandleRun__3() {
|
|
1032
|
-
try {
|
|
1033
|
-
const value = callback();
|
|
1034
|
-
outcome = { kind: "value", value };
|
|
1035
|
-
return value;
|
|
1036
|
-
} catch (caught) {
|
|
1037
|
-
outcome = { kind: "throw", error: caught };
|
|
1038
|
-
throw caught;
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
try {
|
|
1042
|
-
invoke(wrapped);
|
|
1043
|
-
} catch {
|
|
1044
|
-
}
|
|
1045
|
-
if (outcome?.kind === "throw") throw outcome.error;
|
|
1046
|
-
if (outcome?.kind === "value") return outcome.value;
|
|
1047
|
-
return callback();
|
|
1048
|
-
};
|
|
1049
|
-
|
|
1050
1157
|
// src/execution-recorder/runtime-state-size-budget.ts
|
|
1051
1158
|
import {
|
|
1052
1159
|
rasputinUnavailable
|
|
@@ -1089,6 +1196,7 @@ var dropEventValues = (events) => {
|
|
|
1089
1196
|
const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
|
|
1090
1197
|
const bounded = events.map((event) => {
|
|
1091
1198
|
if (event.type === "function_enter") {
|
|
1199
|
+
if (event.args === void 0) return { ...event };
|
|
1092
1200
|
dropped += event.args.length;
|
|
1093
1201
|
return { ...event, args: event.args.map(marker) };
|
|
1094
1202
|
}
|
|
@@ -1272,7 +1380,7 @@ var defaults = {
|
|
|
1272
1380
|
maxObjectKeys: 30,
|
|
1273
1381
|
maxArrayElements: 20,
|
|
1274
1382
|
maxStringLength: 500,
|
|
1275
|
-
maxSerializedValueBytes:
|
|
1383
|
+
maxSerializedValueBytes: 16 * 1024
|
|
1276
1384
|
};
|
|
1277
1385
|
var compileFreezeLimits = (options) => ({
|
|
1278
1386
|
maxDepth: options.maxDepth ?? defaults.maxDepth,
|
|
@@ -1599,6 +1707,21 @@ var redactUrlUserinfo = (text) => {
|
|
|
1599
1707
|
};
|
|
1600
1708
|
var redactUrlLikeString = (text, redactKeys) => redactSensitiveQuery(redactUrlUserinfo(text), redactKeys);
|
|
1601
1709
|
var isFrozenAtom = (value) => typeof value === "object" && value !== null && FROZEN in value;
|
|
1710
|
+
var isRetainedOverflowChild = (value) => {
|
|
1711
|
+
if (isFrozenAtom(value)) {
|
|
1712
|
+
if (value[FROZEN] === "truncated") return true;
|
|
1713
|
+
return (value[FROZEN] === "Map" || value[FROZEN] === "Set") && value.truncated === true;
|
|
1714
|
+
}
|
|
1715
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
1716
|
+
const last = value[value.length - 1];
|
|
1717
|
+
return isFrozenAtom(last) && last[FROZEN] === "truncated";
|
|
1718
|
+
};
|
|
1719
|
+
var keepOverflowChild = (child, overflowedOnChild) => {
|
|
1720
|
+
if (!overflowedOnChild) return true;
|
|
1721
|
+
if (child === void 0) return false;
|
|
1722
|
+
return isRetainedOverflowChild(child);
|
|
1723
|
+
};
|
|
1724
|
+
var BYTE_LIMIT = "max_serialized_value_bytes";
|
|
1602
1725
|
var createValueFreezer = (options = {}) => {
|
|
1603
1726
|
const limits = compileFreezeLimits(options);
|
|
1604
1727
|
const redactKeys = compileRedactKeys(options.redactKeys);
|
|
@@ -1731,20 +1854,32 @@ var createValueFreezer = (options = {}) => {
|
|
|
1731
1854
|
for (const mapKey of Map.prototype.keys.call(value)) {
|
|
1732
1855
|
if (counted2 >= limits.maxArrayElements || metrics.oversize) break;
|
|
1733
1856
|
const key = freezeInner(mapKey, depth + 1, path, metrics);
|
|
1857
|
+
if (!keepOverflowChild(key, metrics.oversize)) break;
|
|
1734
1858
|
if (typeof mapKey === "string" && keyIsRedacted(mapKey, redactKeys)) {
|
|
1735
1859
|
add(metrics, stringEstimate(REDACTED));
|
|
1860
|
+
if (metrics.oversize) break;
|
|
1736
1861
|
entries.push([key, REDACTED]);
|
|
1737
1862
|
} else {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1863
|
+
const mapValue = freezeInner(
|
|
1864
|
+
Map.prototype.get.call(value, mapKey),
|
|
1865
|
+
depth + 1,
|
|
1866
|
+
path,
|
|
1867
|
+
metrics
|
|
1868
|
+
);
|
|
1869
|
+
if (!keepOverflowChild(mapValue, metrics.oversize)) break;
|
|
1870
|
+
entries.push([key, mapValue]);
|
|
1742
1871
|
}
|
|
1743
1872
|
counted2++;
|
|
1744
1873
|
}
|
|
1874
|
+
const hitBytes2 = metrics.oversize && counted2 < Math.min(size, limits.maxArrayElements);
|
|
1875
|
+
const hitCount = size > limits.maxArrayElements;
|
|
1745
1876
|
return atom("Map", {
|
|
1746
1877
|
entries,
|
|
1747
|
-
...
|
|
1878
|
+
...hitBytes2 || hitCount ? {
|
|
1879
|
+
truncated: true,
|
|
1880
|
+
reason: hitBytes2 ? BYTE_LIMIT : "max_array_elements",
|
|
1881
|
+
originalLength: size
|
|
1882
|
+
} : {}
|
|
1748
1883
|
});
|
|
1749
1884
|
}
|
|
1750
1885
|
if (types.isSet(value)) {
|
|
@@ -1755,12 +1890,20 @@ var createValueFreezer = (options = {}) => {
|
|
|
1755
1890
|
const size = setSize ? setSize.call(value) : 0;
|
|
1756
1891
|
for (const item of Set.prototype.values.call(value)) {
|
|
1757
1892
|
if (counted2 >= limits.maxArrayElements || metrics.oversize) break;
|
|
1758
|
-
|
|
1893
|
+
const frozen = freezeInner(item, depth + 1, path, metrics);
|
|
1894
|
+
if (!keepOverflowChild(frozen, metrics.oversize)) break;
|
|
1895
|
+
values.push(frozen);
|
|
1759
1896
|
counted2++;
|
|
1760
1897
|
}
|
|
1898
|
+
const hitBytes2 = metrics.oversize && counted2 < Math.min(size, limits.maxArrayElements);
|
|
1899
|
+
const hitCount = size > limits.maxArrayElements;
|
|
1761
1900
|
return atom("Set", {
|
|
1762
1901
|
values,
|
|
1763
|
-
...
|
|
1902
|
+
...hitBytes2 || hitCount ? {
|
|
1903
|
+
truncated: true,
|
|
1904
|
+
reason: hitBytes2 ? BYTE_LIMIT : "max_array_elements",
|
|
1905
|
+
originalLength: size
|
|
1906
|
+
} : {}
|
|
1764
1907
|
});
|
|
1765
1908
|
}
|
|
1766
1909
|
if (Array.isArray(value)) {
|
|
@@ -1778,26 +1921,39 @@ var createValueFreezer = (options = {}) => {
|
|
|
1778
1921
|
}
|
|
1779
1922
|
if (!descriptor) {
|
|
1780
1923
|
add(metrics, NODE + 16);
|
|
1924
|
+
if (metrics.oversize) break;
|
|
1781
1925
|
items.push(atom("hole"));
|
|
1782
1926
|
redactNext = false;
|
|
1783
1927
|
continue;
|
|
1784
1928
|
}
|
|
1785
1929
|
if (!("value" in descriptor)) {
|
|
1786
1930
|
add(metrics, NODE + 16);
|
|
1931
|
+
if (metrics.oversize) break;
|
|
1787
1932
|
items.push(atom("accessor"));
|
|
1788
1933
|
redactNext = false;
|
|
1789
1934
|
continue;
|
|
1790
1935
|
}
|
|
1791
1936
|
if (redactNext) {
|
|
1792
1937
|
add(metrics, stringEstimate(REDACTED));
|
|
1938
|
+
if (metrics.oversize) break;
|
|
1793
1939
|
items.push(REDACTED);
|
|
1794
1940
|
redactNext = false;
|
|
1795
1941
|
} else {
|
|
1796
|
-
|
|
1942
|
+
const frozen = freezeInner(descriptor.value, depth + 1, path, metrics);
|
|
1943
|
+
if (!keepOverflowChild(frozen, metrics.oversize)) break;
|
|
1944
|
+
items.push(frozen);
|
|
1797
1945
|
redactNext = typeof descriptor.value === "string" && keyIsRedacted(descriptor.value, redactKeys);
|
|
1798
1946
|
}
|
|
1799
1947
|
}
|
|
1800
|
-
if (
|
|
1948
|
+
if (metrics.oversize && items.length < maxItems) {
|
|
1949
|
+
add(metrics, NODE + 32);
|
|
1950
|
+
items.push(
|
|
1951
|
+
atom("truncated", {
|
|
1952
|
+
reason: BYTE_LIMIT,
|
|
1953
|
+
originalLength: value.length
|
|
1954
|
+
})
|
|
1955
|
+
);
|
|
1956
|
+
} else if (value.length > limits.maxArrayElements) {
|
|
1801
1957
|
add(metrics, NODE + 32);
|
|
1802
1958
|
items.push(
|
|
1803
1959
|
atom("truncated", {
|
|
@@ -1905,30 +2061,41 @@ var createValueFreezer = (options = {}) => {
|
|
|
1905
2061
|
const pairIsSensitive = pairLabel !== void 0 && typeof pairLabel.value === "string" && keyIsRedacted(pairLabel.value, redactKeys);
|
|
1906
2062
|
const { keys, truncated } = ownEnumerableKeys(value, limits.maxObjectKeys);
|
|
1907
2063
|
const maxKeys = truncated ? Math.max(0, limits.maxObjectKeys - 1) : keys.length;
|
|
2064
|
+
let kept = 0;
|
|
1908
2065
|
for (let index = 0; index < maxKeys; index++) {
|
|
2066
|
+
if (metrics.oversize) break;
|
|
1909
2067
|
const key = keys[index];
|
|
1910
|
-
if (key === void 0
|
|
2068
|
+
if (key === void 0) continue;
|
|
1911
2069
|
add(metrics, stringEstimate(key));
|
|
2070
|
+
if (metrics.oversize) break;
|
|
1912
2071
|
if (keyIsRedacted(key, redactKeys) || key === "value" && pairIsSensitive) {
|
|
1913
2072
|
add(metrics, stringEstimate(REDACTED));
|
|
2073
|
+
if (metrics.oversize) break;
|
|
1914
2074
|
assignFrozenField(fields, key, REDACTED);
|
|
2075
|
+
kept++;
|
|
1915
2076
|
continue;
|
|
1916
2077
|
}
|
|
1917
2078
|
const slot = ownData(value, key);
|
|
1918
2079
|
if (slot) {
|
|
1919
2080
|
const field = typeof slot.value === "string" && propertyNameLooksLikeUrl(key) ? redactUrlLikeString(slot.value, redactKeys) : slot.value;
|
|
1920
|
-
|
|
2081
|
+
const frozen = freezeInner(field, depth + 1, path, metrics);
|
|
2082
|
+
if (!keepOverflowChild(frozen, metrics.oversize)) break;
|
|
2083
|
+
assignFrozenField(fields, key, frozen);
|
|
2084
|
+
kept++;
|
|
1921
2085
|
} else {
|
|
1922
2086
|
add(metrics, NODE + 16);
|
|
2087
|
+
if (metrics.oversize) break;
|
|
1923
2088
|
assignFrozenField(fields, key, atom("accessor"));
|
|
2089
|
+
kept++;
|
|
1924
2090
|
}
|
|
1925
2091
|
}
|
|
1926
|
-
|
|
2092
|
+
const hitBytes = metrics.oversize && kept < maxKeys;
|
|
2093
|
+
if (hitBytes || truncated) {
|
|
1927
2094
|
return atom("instance", {
|
|
1928
2095
|
type: typeName,
|
|
1929
2096
|
value: fields,
|
|
1930
2097
|
truncated: true,
|
|
1931
|
-
reason: "max_object_keys"
|
|
2098
|
+
reason: hitBytes ? BYTE_LIMIT : "max_object_keys"
|
|
1932
2099
|
});
|
|
1933
2100
|
}
|
|
1934
2101
|
if (typeName) return atom("instance", { type: typeName, value: fields });
|
|
@@ -1952,22 +2119,11 @@ var createValueFreezer = (options = {}) => {
|
|
|
1952
2119
|
}
|
|
1953
2120
|
try {
|
|
1954
2121
|
const frozen = freezeInner(value, 0, path, metrics);
|
|
1955
|
-
if (metrics.oversize) {
|
|
1956
|
-
return {
|
|
1957
|
-
value: atom("truncated", {
|
|
1958
|
-
reason: "max_serialized_value_bytes",
|
|
1959
|
-
serializedBytes: metrics.estimatedBytes
|
|
1960
|
-
}),
|
|
1961
|
-
estimatedBytes: metrics.estimatedBytes,
|
|
1962
|
-
visitedNodes: metrics.visitedNodes,
|
|
1963
|
-
oversize: true
|
|
1964
|
-
};
|
|
1965
|
-
}
|
|
1966
2122
|
return {
|
|
1967
2123
|
value: frozen,
|
|
1968
2124
|
estimatedBytes: metrics.estimatedBytes,
|
|
1969
2125
|
visitedNodes: metrics.visitedNodes,
|
|
1970
|
-
oversize:
|
|
2126
|
+
oversize: metrics.oversize
|
|
1971
2127
|
};
|
|
1972
2128
|
} catch {
|
|
1973
2129
|
return {
|
|
@@ -2257,14 +2413,18 @@ var encodeFrozen = (value) => {
|
|
|
2257
2413
|
}
|
|
2258
2414
|
return value;
|
|
2259
2415
|
};
|
|
2416
|
+
var isByteBudgetStub = (encoded) => {
|
|
2417
|
+
if (typeof encoded !== "object" || encoded === null || Array.isArray(encoded)) return false;
|
|
2418
|
+
const record = encoded;
|
|
2419
|
+
if (record.__rasputin_truncated !== true || record.__reason !== "max_serialized_value_bytes") {
|
|
2420
|
+
return false;
|
|
2421
|
+
}
|
|
2422
|
+
return Object.keys(record).every((key) => key.startsWith("__"));
|
|
2423
|
+
};
|
|
2260
2424
|
var encodeFrozenWithBytes = (frozen, visitedNodes, maxSerializedValueBytes) => {
|
|
2261
2425
|
const encoded = encodeFrozen(frozen);
|
|
2262
|
-
if (typeof encoded === "object" && encoded !== null && !Array.isArray(encoded) && encoded.__reason === "max_serialized_value_bytes") {
|
|
2263
|
-
const bytes2 = jsonLiteralUtf8Bytes(encoded);
|
|
2264
|
-
return { value: encoded, bytes: bytes2, visitedNodes };
|
|
2265
|
-
}
|
|
2266
2426
|
const bytes = jsonLiteralUtf8Bytes(encoded);
|
|
2267
|
-
if (bytes > maxSerializedValueBytes) {
|
|
2427
|
+
if (!isByteBudgetStub(encoded) && bytes > maxSerializedValueBytes) {
|
|
2268
2428
|
const bounded = truncation("max_serialized_value_bytes", { __serialized_bytes: bytes });
|
|
2269
2429
|
return { value: bounded, bytes: jsonLiteralUtf8Bytes(bounded), visitedNodes };
|
|
2270
2430
|
}
|
|
@@ -2575,7 +2735,7 @@ var createExecutionRecorder = (options) => {
|
|
|
2575
2735
|
const sweepIntervalNs = maxExecutionHoldNs / 4n < 50000000n ? maxExecutionHoldNs / 4n : 50000000n;
|
|
2576
2736
|
const memoryBudget = new RecorderMemoryBudget(
|
|
2577
2737
|
maxActiveMemoryBytes,
|
|
2578
|
-
options.maxSerializedValueBytes ??
|
|
2738
|
+
options.maxSerializedValueBytes ?? 16 * 1024
|
|
2579
2739
|
);
|
|
2580
2740
|
const serializer = createSafeSerializer(options);
|
|
2581
2741
|
const excludesSource = createSourceExclusionMatcher(options.excludeSources);
|
|
@@ -2640,7 +2800,10 @@ var createExecutionRecorder = (options) => {
|
|
|
2640
2800
|
};
|
|
2641
2801
|
const encodeEventValues = (events) => events.map((event) => {
|
|
2642
2802
|
if (event.type === "function_enter") {
|
|
2643
|
-
return {
|
|
2803
|
+
return {
|
|
2804
|
+
...event,
|
|
2805
|
+
...event.args === void 0 ? {} : { args: event.args.map((argument) => serializer.encode(argument)) }
|
|
2806
|
+
};
|
|
2644
2807
|
}
|
|
2645
2808
|
if (event.type === "function_exit") {
|
|
2646
2809
|
return { ...event, returnValue: serializer.encode(event.returnValue) };
|
|
@@ -2687,7 +2850,7 @@ var createExecutionRecorder = (options) => {
|
|
|
2687
2850
|
};
|
|
2688
2851
|
const eventsHaveOmittedValues = (events) => {
|
|
2689
2852
|
for (const event of events) {
|
|
2690
|
-
if (event.type === "function_enter" && event.args.some((arg) => rasputinTagKind(arg) === "omitted")) {
|
|
2853
|
+
if (event.type === "function_enter" && (event.args ?? []).some((arg) => rasputinTagKind(arg) === "omitted")) {
|
|
2691
2854
|
return true;
|
|
2692
2855
|
}
|
|
2693
2856
|
if (event.type === "function_exit" && rasputinTagKind(event.returnValue) === "omitted") {
|
|
@@ -3802,69 +3965,6 @@ var createExecutionRecorder = (options) => {
|
|
|
3802
3965
|
};
|
|
3803
3966
|
|
|
3804
3967
|
// src/execution-recorder/automatic-runtime.ts
|
|
3805
|
-
var AUTOMATIC_RUNTIME_SYMBOL = "rasputin.execution.runtime.v3";
|
|
3806
|
-
var runtimeSymbol = Symbol.for(AUTOMATIC_RUNTIME_SYMBOL);
|
|
3807
|
-
var passthroughHandle = () => ({
|
|
3808
|
-
leave: (value) => value,
|
|
3809
|
-
fail: () => {
|
|
3810
|
-
},
|
|
3811
|
-
end: () => {
|
|
3812
|
-
},
|
|
3813
|
-
run: function __rasputinHandleRun__3(callback) {
|
|
3814
|
-
return runExactlyOnce((invoke) => invoke(), callback);
|
|
3815
|
-
},
|
|
3816
|
-
suspend: (value) => value,
|
|
3817
|
-
resume: (value) => value
|
|
3818
|
-
});
|
|
3819
|
-
var isolateHandle = (handle) => ({
|
|
3820
|
-
leave: (value) => {
|
|
3821
|
-
try {
|
|
3822
|
-
return handle.leave(value);
|
|
3823
|
-
} catch {
|
|
3824
|
-
return value;
|
|
3825
|
-
}
|
|
3826
|
-
},
|
|
3827
|
-
fail: (error, liveArgs) => {
|
|
3828
|
-
try {
|
|
3829
|
-
handle.fail(error, liveArgs);
|
|
3830
|
-
} catch {
|
|
3831
|
-
}
|
|
3832
|
-
},
|
|
3833
|
-
end: () => {
|
|
3834
|
-
try {
|
|
3835
|
-
handle.end();
|
|
3836
|
-
} catch {
|
|
3837
|
-
}
|
|
3838
|
-
},
|
|
3839
|
-
run: function __rasputinHandleRun__3(callback) {
|
|
3840
|
-
return runExactlyOnce((invoke) => handle.run(invoke), callback);
|
|
3841
|
-
},
|
|
3842
|
-
suspend: (value) => {
|
|
3843
|
-
try {
|
|
3844
|
-
return handle.suspend(value);
|
|
3845
|
-
} catch {
|
|
3846
|
-
return value;
|
|
3847
|
-
}
|
|
3848
|
-
},
|
|
3849
|
-
resume: (value) => {
|
|
3850
|
-
try {
|
|
3851
|
-
return handle.resume(value);
|
|
3852
|
-
} catch {
|
|
3853
|
-
return value;
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
});
|
|
3857
|
-
var passthroughRun = (_planIndex, _args, callback) => callback();
|
|
3858
|
-
var passthroughEnter = () => passthroughHandle();
|
|
3859
|
-
var bindPassthrough = (module) => {
|
|
3860
|
-
module.cell.run = passthroughRun;
|
|
3861
|
-
module.cell.enter = passthroughEnter;
|
|
3862
|
-
};
|
|
3863
|
-
var attachRunner = (cell) => {
|
|
3864
|
-
const run = ((planIndex, args, callback, omitValues) => cell.run(planIndex, args, callback, omitValues));
|
|
3865
|
-
run.enter = (planIndex, args, omitValues) => cell.enter(planIndex, args, omitValues);
|
|
3866
|
-
return run;
|
|
3867
|
-
};
|
|
3868
3968
|
var bindExecution = (execution, module) => {
|
|
3869
3969
|
const prepared = execution.prepareFunctionPlans(module.plans);
|
|
3870
3970
|
module.cell.run = (planIndex, args, callback, omitValues) => {
|
|
@@ -3875,40 +3975,13 @@ var bindExecution = (execution, module) => {
|
|
|
3875
3975
|
try {
|
|
3876
3976
|
const plan = prepared[planIndex];
|
|
3877
3977
|
return isolateHandle(
|
|
3878
|
-
plan ? execution.enterPreparedFunction(plan, args, omitValues) :
|
|
3978
|
+
plan ? execution.enterPreparedFunction(plan, args, omitValues) : passthroughHandle()
|
|
3879
3979
|
);
|
|
3880
3980
|
} catch {
|
|
3881
3981
|
return passthroughHandle();
|
|
3882
3982
|
}
|
|
3883
3983
|
};
|
|
3884
3984
|
};
|
|
3885
|
-
var isRegistry = (value) => Array.isArray(Reflect.get(value, "runtimes")) && Array.isArray(Reflect.get(value, "modules")) && typeof Reflect.get(value, "register") === "function";
|
|
3886
|
-
var registerModule = (registry, plans) => {
|
|
3887
|
-
const cell = { run: passthroughRun, enter: passthroughEnter };
|
|
3888
|
-
const module = { plans, cell };
|
|
3889
|
-
registry.modules.push(module);
|
|
3890
|
-
registry.runtimes.at(-1)?.bind(module);
|
|
3891
|
-
return attachRunner(cell);
|
|
3892
|
-
};
|
|
3893
|
-
var createRegistry = () => {
|
|
3894
|
-
const registry = {
|
|
3895
|
-
runtimes: [],
|
|
3896
|
-
modules: [],
|
|
3897
|
-
register(plans) {
|
|
3898
|
-
return registerModule(registry, plans);
|
|
3899
|
-
}
|
|
3900
|
-
};
|
|
3901
|
-
return registry;
|
|
3902
|
-
};
|
|
3903
|
-
var getAutomaticRuntimeRegistry = () => {
|
|
3904
|
-
const existing = Reflect.get(globalThis, runtimeSymbol);
|
|
3905
|
-
if (existing && typeof existing === "object" && isRegistry(existing)) {
|
|
3906
|
-
return existing;
|
|
3907
|
-
}
|
|
3908
|
-
const registry = createRegistry();
|
|
3909
|
-
Reflect.set(globalThis, runtimeSymbol, registry);
|
|
3910
|
-
return registry;
|
|
3911
|
-
};
|
|
3912
3985
|
var installAutomaticExecutionRuntime = (execution) => {
|
|
3913
3986
|
const registry = getAutomaticRuntimeRegistry();
|
|
3914
3987
|
const runtime = {
|
package/dist/rasputin-init.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export type RasputinNodeClient = Omit<RasputinClient, 'getStats'> & {
|
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
47
|
* RasputinInit({
|
|
48
|
+
* dsn: process.env.RASPUTIN_DSN!,
|
|
48
49
|
* projectApiKey: process.env.RASPUTIN_PROJECT_API_KEY!,
|
|
49
50
|
* release: process.env.RASPUTIN_RELEASE!,
|
|
50
51
|
* environment: process.env.NODE_ENV ?? 'development',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rasputin-init.d.ts","sourceRoot":"","sources":["../src/rasputin-init.ts"],"names":[],"mappings":"AAMA,OAAO,EAIN,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAK9B,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IACnD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG;IAC3D,qFAAqF;IACrF,QAAQ,EAAE,sBAAsB,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,GAAG;IACnE,+EAA+E;IAC/E,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE,MAAM,uBAAuB,CAAC;IACxC;;;OAGG;IACH,mBAAmB,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACvD,CAAC;AA+DF
|
|
1
|
+
{"version":3,"file":"rasputin-init.d.ts","sourceRoot":"","sources":["../src/rasputin-init.ts"],"names":[],"mappings":"AAMA,OAAO,EAIN,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EACtB,MAAM,sBAAsB,CAAC;AAK9B,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IACnD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG;IAC3D,qFAAqF;IACrF,QAAQ,EAAE,sBAAsB,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,GAAG;IACnE,+EAA+E;IAC/E,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE,MAAM,uBAAuB,CAAC;IACxC;;;OAGG;IACH,mBAAmB,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACvD,CAAC;AA+DF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,mBAAmB,KAAG,kBAmE3D,CAAC"}
|
package/dist/sdk-meta.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rasputin-ai/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Official Rasputin AI SDK for Node and Bun.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -49,11 +49,13 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
52
|
-
"@rasputin-ai/core": "0.
|
|
52
|
+
"@rasputin-ai/core": "0.6.0",
|
|
53
53
|
"typescript": "5"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@rasputin-ai/core": "workspace:*",
|
|
57
|
+
"@rasputin-ai/instrumentation": "workspace:*",
|
|
58
|
+
"@rasputin-ai/recorder": "workspace:*",
|
|
57
59
|
"@types/bun": "1.3.14",
|
|
58
60
|
"@types/node": "22.13.10",
|
|
59
61
|
"esbuild": "0.25.12"
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Walks the TypeScript AST while a module is being transformed and records the static facts
|
|
3
|
-
* Rasputin needs for replay: instrumented functions, call sites, and parameter destructuring
|
|
4
|
-
* bindings. transform-source calls these collectors and passes the delta to the manifest
|
|
5
|
-
* registry so the server can map runtime locations back to Git.
|
|
6
|
-
*/
|
|
7
|
-
import type { InstrumentationParamBinding } from '@rasputin-ai/core';
|
|
8
|
-
import ts from 'typescript';
|
|
9
|
-
import type { RawManifestCallSite, RawManifestDestructure, RawManifestFunction } from './instrumentation-manifest-delta';
|
|
10
|
-
type SourceLocation = {
|
|
11
|
-
filePath: string;
|
|
12
|
-
line: number;
|
|
13
|
-
column: number;
|
|
14
|
-
};
|
|
15
|
-
type SourceLocationMapper = (location: SourceLocation) => SourceLocation | undefined;
|
|
16
|
-
type CollectContext = {
|
|
17
|
-
sourceFile: ts.SourceFile;
|
|
18
|
-
mapLocation?: SourceLocationMapper;
|
|
19
|
-
absolutePath: string;
|
|
20
|
-
};
|
|
21
|
-
export declare const collectFunctionParams: (node: ts.FunctionLikeDeclaration, sourceFile: ts.SourceFile) => {
|
|
22
|
-
params: InstrumentationParamBinding[];
|
|
23
|
-
paramNames: Set<string>;
|
|
24
|
-
};
|
|
25
|
-
export declare const mappedLocation: (sourceFile: ts.SourceFile, position: number, absolutePath: string, mapLocation?: SourceLocationMapper) => SourceLocation | undefined;
|
|
26
|
-
export declare const collectCallSite: (call: ts.CallExpression | ts.NewExpression, caller: RawManifestFunction, context: CollectContext) => RawManifestCallSite | null;
|
|
27
|
-
export declare const collectParamDestructure: (declaration: ts.VariableDeclaration, caller: RawManifestFunction, context: CollectContext) => RawManifestDestructure | null;
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=collect-instrumentation-delta.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collect-instrumentation-delta.d.ts","sourceRoot":"","sources":["../../src/auto-instrumentation/collect-instrumentation-delta.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAgC,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EACX,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAE1C,KAAK,cAAc,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,oBAAoB,GAAG,CAAC,QAAQ,EAAE,cAAc,KAAK,cAAc,GAAG,SAAS,CAAC;AAErF,KAAK,cAAc,GAAG;IACrB,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IAC1B,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAqCF,eAAO,MAAM,qBAAqB,GACjC,MAAM,EAAE,CAAC,uBAAuB,EAChC,YAAY,EAAE,CAAC,UAAU,KACvB;IAAE,MAAM,EAAE,2BAA2B,EAAE,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAQlE,CAAC;AA2BF,eAAO,MAAM,cAAc,GAC1B,YAAY,EAAE,CAAC,UAAU,EACzB,UAAU,MAAM,EAChB,cAAc,MAAM,EACpB,cAAc,oBAAoB,+BASlC,CAAC;AAuEF,eAAO,MAAM,eAAe,GAC3B,MAAM,EAAE,CAAC,cAAc,GAAG,EAAE,CAAC,aAAa,EAC1C,QAAQ,mBAAmB,EAC3B,SAAS,cAAc,KACrB,mBAAmB,GAAG,IA4BxB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GACnC,aAAa,EAAE,CAAC,mBAAmB,EACnC,QAAQ,mBAAmB,EAC3B,SAAS,cAAc,KACrB,sBAAsB,GAAG,IAsB3B,CAAC"}
|