@lmnr-ai/lmnr 0.7.5-alpha.2 → 0.7.5
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/dist/cli.d.mts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +8 -3
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +8 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/{evaluations-DS4TjeW7.d.mts → evaluations-abooxERH.d.mts} +9 -2
- package/dist/{evaluations-DS4TjeW7.d.ts → evaluations-abooxERH.d.ts} +9 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +455 -317
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +460 -322
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -551,7 +551,7 @@ var AgentResource = class extends BaseResource {
|
|
|
551
551
|
};
|
|
552
552
|
|
|
553
553
|
// package.json
|
|
554
|
-
var version = "0.7.5
|
|
554
|
+
var version = "0.7.5";
|
|
555
555
|
|
|
556
556
|
// src/version.ts
|
|
557
557
|
var getLangVersion = () => {
|
|
@@ -1077,8 +1077,15 @@ var import_instrumentation_azure = require("@traceloop/instrumentation-azure");
|
|
|
1077
1077
|
var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
|
|
1078
1078
|
var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
|
|
1079
1079
|
var import_instrumentation_cohere = require("@traceloop/instrumentation-cohere");
|
|
1080
|
+
var import_instrumentation_langchain = require("@traceloop/instrumentation-langchain");
|
|
1081
|
+
var import_instrumentation_llamaindex = require("@traceloop/instrumentation-llamaindex");
|
|
1082
|
+
var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
|
|
1083
|
+
var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
|
|
1084
|
+
var import_instrumentation_qdrant = require("@traceloop/instrumentation-qdrant");
|
|
1085
|
+
var import_instrumentation_together = require("@traceloop/instrumentation-together");
|
|
1086
|
+
var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
|
|
1080
1087
|
|
|
1081
|
-
// src/
|
|
1088
|
+
// src/browser/playwright.ts
|
|
1082
1089
|
var import_api5 = require("@opentelemetry/api");
|
|
1083
1090
|
var import_instrumentation = require("@opentelemetry/instrumentation");
|
|
1084
1091
|
|
|
@@ -1720,202 +1727,6 @@ var _Laminar = class _Laminar {
|
|
|
1720
1727
|
_Laminar.isInitialized = false;
|
|
1721
1728
|
var Laminar = _Laminar;
|
|
1722
1729
|
|
|
1723
|
-
// src/opentelemetry-lib/instrumentation/kernel.ts
|
|
1724
|
-
var WRAPPED_BROWSER_METHODS = [
|
|
1725
|
-
"create",
|
|
1726
|
-
"retrieve",
|
|
1727
|
-
"list",
|
|
1728
|
-
"delete",
|
|
1729
|
-
"deleteByID",
|
|
1730
|
-
"loadExtensions"
|
|
1731
|
-
];
|
|
1732
|
-
var WRAPPED_COMPUTER_METHODS = [
|
|
1733
|
-
"captureScreenshot",
|
|
1734
|
-
"clickMouse",
|
|
1735
|
-
"dragMouse",
|
|
1736
|
-
"moveMouse",
|
|
1737
|
-
"pressKey",
|
|
1738
|
-
"scroll",
|
|
1739
|
-
"typeText"
|
|
1740
|
-
];
|
|
1741
|
-
var WRAPPED_PROCESS_METHODS = [
|
|
1742
|
-
"exec",
|
|
1743
|
-
"kill",
|
|
1744
|
-
"spawn",
|
|
1745
|
-
"status",
|
|
1746
|
-
"stdin",
|
|
1747
|
-
"stdoutStream"
|
|
1748
|
-
];
|
|
1749
|
-
var KernelInstrumentation = class extends import_instrumentation.InstrumentationBase {
|
|
1750
|
-
constructor() {
|
|
1751
|
-
super(
|
|
1752
|
-
"@lmnr/kernel-instrumentation",
|
|
1753
|
-
version,
|
|
1754
|
-
{
|
|
1755
|
-
enabled: true
|
|
1756
|
-
}
|
|
1757
|
-
);
|
|
1758
|
-
}
|
|
1759
|
-
init() {
|
|
1760
|
-
const module2 = new import_instrumentation.InstrumentationNodeModuleDefinition(
|
|
1761
|
-
"@onkernel/sdk",
|
|
1762
|
-
[">=0.7.0"],
|
|
1763
|
-
this.patch.bind(this),
|
|
1764
|
-
this.unpatch.bind(this)
|
|
1765
|
-
);
|
|
1766
|
-
return module2;
|
|
1767
|
-
}
|
|
1768
|
-
manuallyInstrument(kernelModule) {
|
|
1769
|
-
for (const wrappedMethod of WRAPPED_BROWSER_METHODS) {
|
|
1770
|
-
this._wrap(
|
|
1771
|
-
kernelModule.Kernel.Browsers.prototype,
|
|
1772
|
-
wrappedMethod,
|
|
1773
|
-
this.patchMethod("Browser", wrappedMethod, "DEFAULT")
|
|
1774
|
-
);
|
|
1775
|
-
}
|
|
1776
|
-
for (const wrappedMethod of WRAPPED_COMPUTER_METHODS) {
|
|
1777
|
-
if (wrappedMethod === "captureScreenshot") {
|
|
1778
|
-
this._wrap(
|
|
1779
|
-
kernelModule.Kernel.Browsers.Computer.prototype,
|
|
1780
|
-
wrappedMethod,
|
|
1781
|
-
this.patchTakeScreenshot()
|
|
1782
|
-
);
|
|
1783
|
-
} else {
|
|
1784
|
-
this._wrap(
|
|
1785
|
-
kernelModule.Kernel.Browsers.Computer.prototype,
|
|
1786
|
-
wrappedMethod,
|
|
1787
|
-
this.patchMethod("Computer", wrappedMethod, "TOOL")
|
|
1788
|
-
);
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
for (const wrappedMethod of WRAPPED_PROCESS_METHODS) {
|
|
1792
|
-
this._wrap(
|
|
1793
|
-
kernelModule.Kernel.Browsers.Process.prototype,
|
|
1794
|
-
wrappedMethod,
|
|
1795
|
-
this.patchProcessMethod(wrappedMethod)
|
|
1796
|
-
);
|
|
1797
|
-
}
|
|
1798
|
-
this._wrap(
|
|
1799
|
-
kernelModule.Kernel.prototype,
|
|
1800
|
-
"app",
|
|
1801
|
-
this.patchAppFactory()
|
|
1802
|
-
);
|
|
1803
|
-
}
|
|
1804
|
-
patchMethod(className, method, spanType) {
|
|
1805
|
-
return (original) => async function(...args) {
|
|
1806
|
-
return await observe(
|
|
1807
|
-
{
|
|
1808
|
-
name: `${className}.${method}`,
|
|
1809
|
-
spanType
|
|
1810
|
-
},
|
|
1811
|
-
async (innerArgs) => await original.bind(this).apply(this, innerArgs),
|
|
1812
|
-
args
|
|
1813
|
-
);
|
|
1814
|
-
};
|
|
1815
|
-
}
|
|
1816
|
-
patchTakeScreenshot() {
|
|
1817
|
-
return (original) => async function(...args) {
|
|
1818
|
-
const span = Laminar.startSpan({
|
|
1819
|
-
name: `Computer.captureScreenshot`,
|
|
1820
|
-
spanType: "TOOL",
|
|
1821
|
-
input: args
|
|
1822
|
-
});
|
|
1823
|
-
try {
|
|
1824
|
-
const result = await original.bind(this).apply(this, args);
|
|
1825
|
-
span.setAttribute("lmnr.span.output", "<BASE64_ENCODED_IMAGE>");
|
|
1826
|
-
return result;
|
|
1827
|
-
} finally {
|
|
1828
|
-
span.end();
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
|
-
}
|
|
1832
|
-
patchProcessMethod(method) {
|
|
1833
|
-
return (original) => async function(...args) {
|
|
1834
|
-
const span = Laminar.startSpan({
|
|
1835
|
-
name: `Process.${method}`,
|
|
1836
|
-
spanType: "TOOL",
|
|
1837
|
-
input: args
|
|
1838
|
-
});
|
|
1839
|
-
try {
|
|
1840
|
-
const result = await original.bind(this).apply(this, args);
|
|
1841
|
-
const output = {
|
|
1842
|
-
...result?.stderr_b64 ? { stderr: Buffer.from(result.stderr_b64, "base64").toString("utf-8") } : {},
|
|
1843
|
-
...result?.stdout_b64 ? { stdout: Buffer.from(result.stdout_b64, "base64").toString("utf-8") } : {},
|
|
1844
|
-
...result
|
|
1845
|
-
};
|
|
1846
|
-
span.setAttribute("lmnr.span.output", JSON.stringify(output));
|
|
1847
|
-
return result;
|
|
1848
|
-
} finally {
|
|
1849
|
-
span.end();
|
|
1850
|
-
}
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1853
|
-
patchAppFactory() {
|
|
1854
|
-
const plugin = this;
|
|
1855
|
-
return (original) => function(name) {
|
|
1856
|
-
const kernelApp = original.call(this, name);
|
|
1857
|
-
plugin._wrap(
|
|
1858
|
-
kernelApp,
|
|
1859
|
-
"action",
|
|
1860
|
-
plugin.patchKernelAppAction()
|
|
1861
|
-
);
|
|
1862
|
-
return kernelApp;
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
patchKernelAppAction() {
|
|
1866
|
-
return (original) => function(name, handler) {
|
|
1867
|
-
const wrappedHandler = async (context6, payload) => {
|
|
1868
|
-
const result = await observe(
|
|
1869
|
-
{
|
|
1870
|
-
name: `action.${name}`,
|
|
1871
|
-
spanType: "DEFAULT"
|
|
1872
|
-
},
|
|
1873
|
-
async (innerCtx, innerPayload) => {
|
|
1874
|
-
const result2 = await handler(innerCtx, innerPayload);
|
|
1875
|
-
return result2;
|
|
1876
|
-
},
|
|
1877
|
-
context6,
|
|
1878
|
-
payload
|
|
1879
|
-
);
|
|
1880
|
-
await Laminar.flush();
|
|
1881
|
-
return result;
|
|
1882
|
-
};
|
|
1883
|
-
return original.call(this, name, wrappedHandler);
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
patch(moduleExports) {
|
|
1887
|
-
import_api5.diag.debug("Patching @onkernel/sdk");
|
|
1888
|
-
this.manuallyInstrument(moduleExports);
|
|
1889
|
-
return moduleExports;
|
|
1890
|
-
}
|
|
1891
|
-
unpatch(moduleExports) {
|
|
1892
|
-
import_api5.diag.debug("Unpatching @onkernel/sdk");
|
|
1893
|
-
for (const wrappedMethod of WRAPPED_BROWSER_METHODS) {
|
|
1894
|
-
this._unwrap(moduleExports.Kernel.Browsers.prototype, wrappedMethod);
|
|
1895
|
-
}
|
|
1896
|
-
for (const wrappedMethod of WRAPPED_COMPUTER_METHODS) {
|
|
1897
|
-
this._unwrap(moduleExports.Kernel.Browsers.Computer.prototype, wrappedMethod);
|
|
1898
|
-
}
|
|
1899
|
-
for (const wrappedMethod of WRAPPED_PROCESS_METHODS) {
|
|
1900
|
-
this._unwrap(moduleExports.Kernel.Browsers.Process.prototype, wrappedMethod);
|
|
1901
|
-
}
|
|
1902
|
-
this._unwrap(moduleExports.Kernel.prototype, "app");
|
|
1903
|
-
}
|
|
1904
|
-
};
|
|
1905
|
-
|
|
1906
|
-
// src/opentelemetry-lib/tracing/instrumentations.ts
|
|
1907
|
-
var import_instrumentation_langchain = require("@traceloop/instrumentation-langchain");
|
|
1908
|
-
var import_instrumentation_llamaindex = require("@traceloop/instrumentation-llamaindex");
|
|
1909
|
-
var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
|
|
1910
|
-
var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
|
|
1911
|
-
var import_instrumentation_qdrant = require("@traceloop/instrumentation-qdrant");
|
|
1912
|
-
var import_instrumentation_together = require("@traceloop/instrumentation-together");
|
|
1913
|
-
var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertexai");
|
|
1914
|
-
|
|
1915
|
-
// src/browser/playwright.ts
|
|
1916
|
-
var import_api6 = require("@opentelemetry/api");
|
|
1917
|
-
var import_instrumentation2 = require("@opentelemetry/instrumentation");
|
|
1918
|
-
|
|
1919
1730
|
// src/browser/utils.ts
|
|
1920
1731
|
var import_v3 = require("zod/v3");
|
|
1921
1732
|
|
|
@@ -2275,8 +2086,13 @@ var modelToProvider = (model) => {
|
|
|
2275
2086
|
var injectScript = (sessionRecordingOptions) => {
|
|
2276
2087
|
const BATCH_TIMEOUT = 2e3;
|
|
2277
2088
|
const MAX_WORKER_PROMISES = 50;
|
|
2278
|
-
const HEARTBEAT_INTERVAL =
|
|
2089
|
+
const HEARTBEAT_INTERVAL = 2e3;
|
|
2090
|
+
const CHUNK_SIZE = 256 * 1024;
|
|
2091
|
+
const CHUNK_SEND_DELAY = 100;
|
|
2279
2092
|
window.lmnrRrwebEventsBatch = [];
|
|
2093
|
+
window.lmnrChunkQueue = [];
|
|
2094
|
+
window.lmnrChunkSequence = 0;
|
|
2095
|
+
window.lmnrCurrentBatchId = null;
|
|
2280
2096
|
const createCompressionWorker = () => {
|
|
2281
2097
|
const workerCode = `
|
|
2282
2098
|
self.onmessage = async (e) => {
|
|
@@ -2330,6 +2146,22 @@ var injectScript = (sessionRecordingOptions) => {
|
|
|
2330
2146
|
let compressionWorker = null;
|
|
2331
2147
|
const workerPromises = /* @__PURE__ */ new Map();
|
|
2332
2148
|
let workerId = 0;
|
|
2149
|
+
let workerSupported = null;
|
|
2150
|
+
const testWorkerSupport = () => {
|
|
2151
|
+
if (workerSupported !== null) {
|
|
2152
|
+
return workerSupported;
|
|
2153
|
+
}
|
|
2154
|
+
try {
|
|
2155
|
+
const testWorker = createCompressionWorker();
|
|
2156
|
+
testWorker.terminate();
|
|
2157
|
+
workerSupported = true;
|
|
2158
|
+
return true;
|
|
2159
|
+
} catch (error) {
|
|
2160
|
+
console.warn("Web Workers blocked by CSP, will use main thread compression:", error);
|
|
2161
|
+
workerSupported = false;
|
|
2162
|
+
return false;
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2333
2165
|
const cleanupWorker = () => {
|
|
2334
2166
|
if (compressionWorker) {
|
|
2335
2167
|
compressionWorker.terminate();
|
|
@@ -2420,6 +2252,9 @@ var injectScript = (sessionRecordingOptions) => {
|
|
|
2420
2252
|
};
|
|
2421
2253
|
const compressLargeObjectTransferable = async (data) => {
|
|
2422
2254
|
try {
|
|
2255
|
+
if (!testWorkerSupport()) {
|
|
2256
|
+
return compressSmallObject(data);
|
|
2257
|
+
}
|
|
2423
2258
|
cleanupStalePromises();
|
|
2424
2259
|
const jsonString = await stringifyNonBlocking(data);
|
|
2425
2260
|
const encoder = new TextEncoder();
|
|
@@ -2443,6 +2278,7 @@ var injectScript = (sessionRecordingOptions) => {
|
|
|
2443
2278
|
compressionWorker.onerror = (error) => {
|
|
2444
2279
|
console.error("Compression worker error:", error);
|
|
2445
2280
|
cleanupWorker();
|
|
2281
|
+
compressSmallObject(data).then(resolve, reject);
|
|
2446
2282
|
};
|
|
2447
2283
|
}
|
|
2448
2284
|
const id = ++workerId;
|
|
@@ -2469,60 +2305,113 @@ var injectScript = (sessionRecordingOptions) => {
|
|
|
2469
2305
|
return await compressLargeObjectTransferable(data);
|
|
2470
2306
|
} catch (error) {
|
|
2471
2307
|
console.warn("Transferable failed, falling back to string method:", error);
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2308
|
+
try {
|
|
2309
|
+
const jsonString = await stringifyNonBlocking(data);
|
|
2310
|
+
return new Promise((resolve, reject) => {
|
|
2311
|
+
if (!compressionWorker) {
|
|
2312
|
+
compressionWorker = createCompressionWorker();
|
|
2313
|
+
compressionWorker.onmessage = (e) => {
|
|
2314
|
+
const { id: id2, success, data: result, error: error2 } = e.data;
|
|
2315
|
+
const promise = workerPromises.get(id2);
|
|
2316
|
+
if (promise) {
|
|
2317
|
+
workerPromises.delete(id2);
|
|
2318
|
+
if (success) {
|
|
2319
|
+
promise.resolve(result);
|
|
2320
|
+
} else {
|
|
2321
|
+
promise.reject(new Error(error2));
|
|
2322
|
+
}
|
|
2485
2323
|
}
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
};
|
|
2492
|
-
}
|
|
2493
|
-
const id = ++workerId;
|
|
2494
|
-
workerPromises.set(id, { resolve, reject });
|
|
2495
|
-
setTimeout(() => {
|
|
2496
|
-
if (workerPromises.has(id)) {
|
|
2497
|
-
workerPromises.delete(id);
|
|
2498
|
-
reject(new Error("Compression timeout"));
|
|
2324
|
+
};
|
|
2325
|
+
compressionWorker.onerror = (error2) => {
|
|
2326
|
+
console.error("Compression worker error:", error2);
|
|
2327
|
+
cleanupWorker();
|
|
2328
|
+
};
|
|
2499
2329
|
}
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2330
|
+
const id = ++workerId;
|
|
2331
|
+
workerPromises.set(id, { resolve, reject });
|
|
2332
|
+
setTimeout(() => {
|
|
2333
|
+
if (workerPromises.has(id)) {
|
|
2334
|
+
workerPromises.delete(id);
|
|
2335
|
+
reject(new Error("Compression timeout"));
|
|
2336
|
+
}
|
|
2337
|
+
}, 1e4);
|
|
2338
|
+
compressionWorker.postMessage({ jsonString, id });
|
|
2339
|
+
});
|
|
2340
|
+
} catch (workerError) {
|
|
2341
|
+
logger5.warn(`Worker creation failed, falling back to main thread compression: ${workerError instanceof Error ? workerError.message : String(workerError)}`);
|
|
2342
|
+
return await compressSmallObject(data);
|
|
2343
|
+
}
|
|
2503
2344
|
}
|
|
2504
2345
|
};
|
|
2505
2346
|
setInterval(cleanupWorker, 5e3);
|
|
2506
2347
|
const isLargeEvent = (type) => {
|
|
2507
2348
|
const LARGE_EVENT_TYPES = [
|
|
2508
|
-
2
|
|
2349
|
+
2
|
|
2509
2350
|
// FullSnapshot
|
|
2510
|
-
3
|
|
2511
|
-
// IncrementalSnapshot
|
|
2512
2351
|
];
|
|
2513
2352
|
if (LARGE_EVENT_TYPES.includes(type)) {
|
|
2514
2353
|
return true;
|
|
2515
2354
|
}
|
|
2516
2355
|
return false;
|
|
2517
2356
|
};
|
|
2357
|
+
const createChunks = (str, batchId) => {
|
|
2358
|
+
const chunks = [];
|
|
2359
|
+
const totalChunks = Math.ceil(str.length / CHUNK_SIZE);
|
|
2360
|
+
for (let i = 0; i < str.length; i += CHUNK_SIZE) {
|
|
2361
|
+
const chunk = str.slice(i, i + CHUNK_SIZE);
|
|
2362
|
+
chunks.push({
|
|
2363
|
+
batchId,
|
|
2364
|
+
chunkIndex: chunks.length,
|
|
2365
|
+
totalChunks,
|
|
2366
|
+
data: chunk,
|
|
2367
|
+
isFinal: chunks.length === totalChunks - 1
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
2370
|
+
return chunks;
|
|
2371
|
+
};
|
|
2372
|
+
const sendChunks = async (chunks) => {
|
|
2373
|
+
if (typeof window.lmnrSendEvents !== "function") {
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
window.lmnrChunkQueue.push(...chunks);
|
|
2377
|
+
while (window.lmnrChunkQueue.length > 0) {
|
|
2378
|
+
const chunk = window.lmnrChunkQueue.shift();
|
|
2379
|
+
try {
|
|
2380
|
+
await window.lmnrSendEvents(chunk);
|
|
2381
|
+
await new Promise((resolve) => setTimeout(resolve, CHUNK_SEND_DELAY));
|
|
2382
|
+
} catch (error) {
|
|
2383
|
+
console.error("Failed to send chunk:", error);
|
|
2384
|
+
window.lmnrChunkQueue = window.lmnrChunkQueue.filter(
|
|
2385
|
+
(c) => c.batchId !== chunk.batchId
|
|
2386
|
+
);
|
|
2387
|
+
break;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2518
2391
|
const sendBatchIfReady = async () => {
|
|
2519
2392
|
if (window.lmnrRrwebEventsBatch.length > 0 && typeof window.lmnrSendEvents === "function") {
|
|
2520
2393
|
const events = window.lmnrRrwebEventsBatch;
|
|
2521
2394
|
window.lmnrRrwebEventsBatch = [];
|
|
2522
2395
|
try {
|
|
2523
|
-
|
|
2396
|
+
const batchId = `${Date.now()}_${window.lmnrChunkSequence++}`;
|
|
2397
|
+
window.lmnrCurrentBatchId = batchId;
|
|
2398
|
+
const batchString = JSON.stringify(events);
|
|
2399
|
+
if (batchString.length <= CHUNK_SIZE) {
|
|
2400
|
+
const chunk = {
|
|
2401
|
+
batchId,
|
|
2402
|
+
chunkIndex: 0,
|
|
2403
|
+
totalChunks: 1,
|
|
2404
|
+
data: batchString,
|
|
2405
|
+
isFinal: true
|
|
2406
|
+
};
|
|
2407
|
+
await window.lmnrSendEvents(chunk);
|
|
2408
|
+
} else {
|
|
2409
|
+
const chunks = createChunks(batchString, batchId);
|
|
2410
|
+
await sendChunks(chunks);
|
|
2411
|
+
}
|
|
2524
2412
|
} catch (error) {
|
|
2525
|
-
|
|
2413
|
+
console.error("Failed to send events:", error);
|
|
2414
|
+
window.lmnrRrwebEventsBatch = [];
|
|
2526
2415
|
}
|
|
2527
2416
|
}
|
|
2528
2417
|
};
|
|
@@ -2534,38 +2423,101 @@ var injectScript = (sessionRecordingOptions) => {
|
|
|
2534
2423
|
});
|
|
2535
2424
|
return base64url.slice(base64url.indexOf(",") + 1);
|
|
2536
2425
|
};
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2426
|
+
if (!window.lmnrStartedRecordingEvents) {
|
|
2427
|
+
let heartbeat2 = function() {
|
|
2428
|
+
setInterval(
|
|
2429
|
+
() => {
|
|
2430
|
+
window.lmnrRrweb.record.addCustomEvent("heartbeat", {
|
|
2431
|
+
title: document.title,
|
|
2432
|
+
url: document.URL
|
|
2433
|
+
});
|
|
2434
|
+
},
|
|
2435
|
+
HEARTBEAT_INTERVAL
|
|
2436
|
+
);
|
|
2437
|
+
};
|
|
2438
|
+
var heartbeat = heartbeat2;
|
|
2439
|
+
setInterval(sendBatchIfReady, BATCH_TIMEOUT);
|
|
2440
|
+
window.lmnrRrweb.record({
|
|
2441
|
+
async emit(event) {
|
|
2442
|
+
try {
|
|
2443
|
+
const isLarge = isLargeEvent(event.type);
|
|
2444
|
+
const compressedResult = isLarge ? await compressLargeObject(event.data) : await compressSmallObject(event.data);
|
|
2445
|
+
const base64Data = await bufferToBase64(compressedResult);
|
|
2446
|
+
const eventToSend = {
|
|
2447
|
+
...event,
|
|
2448
|
+
data: base64Data
|
|
2449
|
+
};
|
|
2450
|
+
window.lmnrRrwebEventsBatch.push(eventToSend);
|
|
2451
|
+
} catch (error) {
|
|
2452
|
+
console.warn("Failed to push event to batch", error);
|
|
2453
|
+
}
|
|
2454
|
+
},
|
|
2455
|
+
recordCanvas: true,
|
|
2456
|
+
collectFonts: true,
|
|
2457
|
+
recordCrossOriginIframes: true,
|
|
2458
|
+
maskInputOptions: {
|
|
2459
|
+
password: true,
|
|
2460
|
+
textarea: sessionRecordingOptions?.maskInputOptions?.textarea || false,
|
|
2461
|
+
text: sessionRecordingOptions?.maskInputOptions?.text || false,
|
|
2462
|
+
number: sessionRecordingOptions?.maskInputOptions?.number || false,
|
|
2463
|
+
select: sessionRecordingOptions?.maskInputOptions?.select || false,
|
|
2464
|
+
email: sessionRecordingOptions?.maskInputOptions?.email || false,
|
|
2465
|
+
tel: sessionRecordingOptions?.maskInputOptions?.tel || false
|
|
2557
2466
|
}
|
|
2558
|
-
}
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
maskInputOptions: sessionRecordingOptions?.maskInputOptions
|
|
2563
|
-
});
|
|
2467
|
+
});
|
|
2468
|
+
heartbeat2();
|
|
2469
|
+
window.lmnrStartedRecordingEvents = true;
|
|
2470
|
+
}
|
|
2564
2471
|
};
|
|
2472
|
+
var OLD_BUFFER_TIMEOUT = 6e4;
|
|
2473
|
+
async function sendEvents(chunk, client, chunkBuffers, sessionId, traceId) {
|
|
2474
|
+
try {
|
|
2475
|
+
const { batchId, chunkIndex, totalChunks, data } = chunk;
|
|
2476
|
+
if (!sessionId || !traceId) {
|
|
2477
|
+
logger5.debug("Missing sessionId or traceId in chunk");
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2480
|
+
if (!chunkBuffers.has(batchId)) {
|
|
2481
|
+
chunkBuffers.set(batchId, {
|
|
2482
|
+
chunks: /* @__PURE__ */ new Map(),
|
|
2483
|
+
total: totalChunks,
|
|
2484
|
+
timestamp: Date.now()
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
const buffer = chunkBuffers.get(batchId);
|
|
2488
|
+
buffer.chunks.set(chunkIndex, data);
|
|
2489
|
+
if (buffer.chunks.size === totalChunks) {
|
|
2490
|
+
let fullData = "";
|
|
2491
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
2492
|
+
fullData += buffer.chunks.get(i);
|
|
2493
|
+
}
|
|
2494
|
+
const events = JSON.parse(fullData);
|
|
2495
|
+
if (events && events.length > 0) {
|
|
2496
|
+
await client.browserEvents.send({ sessionId, traceId, events }).catch((error) => {
|
|
2497
|
+
logger5.debug(`Failed to send events: ${error instanceof Error ? error.message : String(error)}`);
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
chunkBuffers.delete(batchId);
|
|
2501
|
+
}
|
|
2502
|
+
const currentTime = Date.now();
|
|
2503
|
+
const toDelete = [];
|
|
2504
|
+
for (const [bid, buffer2] of chunkBuffers.entries()) {
|
|
2505
|
+
if (currentTime - buffer2.timestamp > OLD_BUFFER_TIMEOUT) {
|
|
2506
|
+
toDelete.push(bid);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
for (const bid of toDelete) {
|
|
2510
|
+
logger5.debug(`Cleaning up incomplete chunk buffer: ${bid}`);
|
|
2511
|
+
chunkBuffers.delete(bid);
|
|
2512
|
+
}
|
|
2513
|
+
} catch (error) {
|
|
2514
|
+
logger5.debug(`Could not send events: ${error instanceof Error ? error.message : String(error)}`);
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2565
2517
|
|
|
2566
2518
|
// src/browser/playwright.ts
|
|
2567
2519
|
var logger6 = initializeLogger();
|
|
2568
|
-
var PlaywrightInstrumentation = class extends
|
|
2520
|
+
var PlaywrightInstrumentation = class extends import_instrumentation.InstrumentationBase {
|
|
2569
2521
|
constructor(client, sessionRecordingOptions) {
|
|
2570
2522
|
super(
|
|
2571
2523
|
"@lmnr/playwright-instrumentation",
|
|
@@ -2594,7 +2546,7 @@ var PlaywrightInstrumentation = class extends import_instrumentation2.Instrument
|
|
|
2594
2546
|
return this._parentSpans.get(sessionId);
|
|
2595
2547
|
}
|
|
2596
2548
|
init() {
|
|
2597
|
-
const module2 = new
|
|
2549
|
+
const module2 = new import_instrumentation.InstrumentationNodeModuleDefinition(
|
|
2598
2550
|
"playwright",
|
|
2599
2551
|
// TODO: test if the older versions work
|
|
2600
2552
|
[">=1.0.0"],
|
|
@@ -2632,7 +2584,7 @@ var PlaywrightInstrumentation = class extends import_instrumentation2.Instrument
|
|
|
2632
2584
|
return pwModule;
|
|
2633
2585
|
}
|
|
2634
2586
|
patch(moduleExports, moduleVersion) {
|
|
2635
|
-
|
|
2587
|
+
import_api5.diag.debug(`patching playwright ${moduleVersion}`);
|
|
2636
2588
|
const browsers = ["chromium", "firefox", "webkit"];
|
|
2637
2589
|
for (const browserType of browsers) {
|
|
2638
2590
|
if (moduleExports[browserType]) {
|
|
@@ -2661,7 +2613,7 @@ var PlaywrightInstrumentation = class extends import_instrumentation2.Instrument
|
|
|
2661
2613
|
return moduleExports;
|
|
2662
2614
|
}
|
|
2663
2615
|
unpatch(moduleExports, moduleVersion) {
|
|
2664
|
-
|
|
2616
|
+
import_api5.diag.debug(`unpatching playwright ${moduleVersion}`);
|
|
2665
2617
|
const browsers = ["chromium", "firefox", "webkit"];
|
|
2666
2618
|
for (const browserType of browsers) {
|
|
2667
2619
|
if (moduleExports[browserType]) {
|
|
@@ -2729,7 +2681,7 @@ var PlaywrightInstrumentation = class extends import_instrumentation2.Instrument
|
|
|
2729
2681
|
await originalBringToFront();
|
|
2730
2682
|
await takeFullSnapshot(page);
|
|
2731
2683
|
};
|
|
2732
|
-
const currentSpan =
|
|
2684
|
+
const currentSpan = import_api5.trace.getSpan(LaminarContextManager.getContext()) ?? import_api5.trace.getActiveSpan();
|
|
2733
2685
|
currentSpan?.setAttribute(TRACE_HAS_BROWSER_SESSION, true);
|
|
2734
2686
|
const otelTraceId = currentSpan?.spanContext().traceId;
|
|
2735
2687
|
const traceId = otelTraceId ? otelTraceIdToUUID(otelTraceId) : NIL_UUID;
|
|
@@ -2747,20 +2699,11 @@ var PlaywrightInstrumentation = class extends import_instrumentation2.Instrument
|
|
|
2747
2699
|
logger6.error(`Error in onClose handler: ${error instanceof Error ? error.message : String(error)}`);
|
|
2748
2700
|
}
|
|
2749
2701
|
});
|
|
2702
|
+
const chunkBuffers = /* @__PURE__ */ new Map();
|
|
2750
2703
|
await injectSessionRecorder(page, this._sessionRecordingOptions);
|
|
2751
2704
|
try {
|
|
2752
|
-
await page.exposeFunction(LMNR_SEND_EVENTS_FUNCTION_NAME, async (
|
|
2753
|
-
|
|
2754
|
-
if (events != null && events.length > 0) {
|
|
2755
|
-
await this._client.browserEvents.send({
|
|
2756
|
-
sessionId,
|
|
2757
|
-
traceId,
|
|
2758
|
-
events
|
|
2759
|
-
});
|
|
2760
|
-
}
|
|
2761
|
-
} catch (error) {
|
|
2762
|
-
logger6.debug(`Could not send events: ${error instanceof Error ? error.message : String(error)}`);
|
|
2763
|
-
}
|
|
2705
|
+
await page.exposeFunction(LMNR_SEND_EVENTS_FUNCTION_NAME, async (chunk) => {
|
|
2706
|
+
await sendEvents(chunk, this._client, chunkBuffers, sessionId, traceId);
|
|
2764
2707
|
});
|
|
2765
2708
|
} catch (error) {
|
|
2766
2709
|
logger6.debug("Could not expose function " + LMNR_SEND_EVENTS_FUNCTION_NAME + `: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -2769,10 +2712,10 @@ var PlaywrightInstrumentation = class extends import_instrumentation2.Instrument
|
|
|
2769
2712
|
};
|
|
2770
2713
|
|
|
2771
2714
|
// src/browser/stagehand.ts
|
|
2772
|
-
var
|
|
2773
|
-
var
|
|
2715
|
+
var import_api6 = require("@opentelemetry/api");
|
|
2716
|
+
var import_instrumentation2 = require("@opentelemetry/instrumentation");
|
|
2774
2717
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
2775
|
-
var StagehandInstrumentation = class extends
|
|
2718
|
+
var StagehandInstrumentation = class extends import_instrumentation2.InstrumentationBase {
|
|
2776
2719
|
constructor(playwrightInstrumentation) {
|
|
2777
2720
|
super(
|
|
2778
2721
|
"@lmnr/browserbase-stagehand-instrumentation",
|
|
@@ -2787,7 +2730,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
2787
2730
|
this.playwrightInstrumentation = playwrightInstrumentation;
|
|
2788
2731
|
}
|
|
2789
2732
|
init() {
|
|
2790
|
-
const module2 = new
|
|
2733
|
+
const module2 = new import_instrumentation2.InstrumentationNodeModuleDefinition(
|
|
2791
2734
|
"@browserbasehq/stagehand",
|
|
2792
2735
|
[">=1.0.0"],
|
|
2793
2736
|
this.patch.bind(this),
|
|
@@ -2796,7 +2739,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
2796
2739
|
return module2;
|
|
2797
2740
|
}
|
|
2798
2741
|
patch(moduleExports, moduleVersion) {
|
|
2799
|
-
|
|
2742
|
+
import_api6.diag.debug(`patching stagehand ${moduleVersion}`);
|
|
2800
2743
|
const descriptor = Object.getOwnPropertyDescriptor(moduleExports, "Stagehand");
|
|
2801
2744
|
if (descriptor && !descriptor.configurable) {
|
|
2802
2745
|
const originalStagehand = moduleExports.Stagehand;
|
|
@@ -2819,7 +2762,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
2819
2762
|
}
|
|
2820
2763
|
}
|
|
2821
2764
|
manuallyInstrument(Stagehand) {
|
|
2822
|
-
|
|
2765
|
+
import_api6.diag.debug("manually instrumenting stagehand");
|
|
2823
2766
|
if (Stagehand && Stagehand.prototype) {
|
|
2824
2767
|
this._wrap(
|
|
2825
2768
|
Stagehand.prototype,
|
|
@@ -2834,7 +2777,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
2834
2777
|
}
|
|
2835
2778
|
}
|
|
2836
2779
|
unpatch(moduleExports, moduleVersion) {
|
|
2837
|
-
|
|
2780
|
+
import_api6.diag.debug(`unpatching stagehand ${moduleVersion}`);
|
|
2838
2781
|
this._unwrap(moduleExports, "Stagehand");
|
|
2839
2782
|
if (moduleExports.Stagehand) {
|
|
2840
2783
|
this._unwrap(moduleExports.Stagehand.prototype, "init");
|
|
@@ -3012,7 +2955,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
3012
2955
|
try {
|
|
3013
2956
|
prettySchema = prettyPrintZodSchema(schema);
|
|
3014
2957
|
} catch (error) {
|
|
3015
|
-
|
|
2958
|
+
import_api6.diag.warn("Error pretty printing zod schema", { error });
|
|
3016
2959
|
}
|
|
3017
2960
|
input[0] = { ...rest, schema: prettySchema };
|
|
3018
2961
|
}
|
|
@@ -3099,7 +3042,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
3099
3042
|
try {
|
|
3100
3043
|
prettySchema = prettyPrintZodSchema(schema);
|
|
3101
3044
|
} catch (error) {
|
|
3102
|
-
|
|
3045
|
+
import_api6.diag.warn("Error pretty printing zod schema", { error });
|
|
3103
3046
|
}
|
|
3104
3047
|
return await observe(
|
|
3105
3048
|
{
|
|
@@ -3124,7 +3067,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
3124
3067
|
try {
|
|
3125
3068
|
prettySchema = prettyPrintZodSchema(schema);
|
|
3126
3069
|
} catch (error) {
|
|
3127
|
-
|
|
3070
|
+
import_api6.diag.warn("Error pretty printing zod schema", { error });
|
|
3128
3071
|
}
|
|
3129
3072
|
return await observe(
|
|
3130
3073
|
{
|
|
@@ -3171,7 +3114,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
3171
3114
|
ignoreInput: true,
|
|
3172
3115
|
ignoreOutput: true
|
|
3173
3116
|
}, async () => {
|
|
3174
|
-
const currentSpan =
|
|
3117
|
+
const currentSpan = import_api6.trace.getSpan(LaminarContextManager.getContext()) ?? import_api6.trace.getActiveSpan();
|
|
3175
3118
|
const span = currentSpan;
|
|
3176
3119
|
const innerOptions = options.options;
|
|
3177
3120
|
const recordedProvider = instrumentation.globalLLMClientOptions.get(this)?.provider;
|
|
@@ -3297,7 +3240,7 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
3297
3240
|
spanType: "LLM"
|
|
3298
3241
|
},
|
|
3299
3242
|
async () => {
|
|
3300
|
-
const span =
|
|
3243
|
+
const span = import_api6.trace.getSpan(LaminarContextManager.getContext()) ?? import_api6.trace.getActiveSpan();
|
|
3301
3244
|
const provider = instrumentation.globalAgentOptions.get(this)?.provider ?? instrumentation.globalLLMClientOptions.get(this)?.provider;
|
|
3302
3245
|
const model = instrumentation.globalAgentOptions.get(this)?.model ?? instrumentation.globalLLMClientOptions.get(this)?.model;
|
|
3303
3246
|
span?.setAttributes({
|
|
@@ -3352,10 +3295,10 @@ var StagehandInstrumentation = class extends import_instrumentation3.Instrumenta
|
|
|
3352
3295
|
};
|
|
3353
3296
|
|
|
3354
3297
|
// src/browser/puppeteer.ts
|
|
3355
|
-
var
|
|
3356
|
-
var
|
|
3298
|
+
var import_api7 = require("@opentelemetry/api");
|
|
3299
|
+
var import_instrumentation3 = require("@opentelemetry/instrumentation");
|
|
3357
3300
|
var logger7 = initializeLogger();
|
|
3358
|
-
var PuppeteerInstrumentation = class extends
|
|
3301
|
+
var PuppeteerInstrumentation = class extends import_instrumentation3.InstrumentationBase {
|
|
3359
3302
|
constructor(client, sessionRecordingOptions) {
|
|
3360
3303
|
super(
|
|
3361
3304
|
"@lmnr/puppeteer-instrumentation",
|
|
@@ -3369,7 +3312,7 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3369
3312
|
this._sessionRecordingOptions = sessionRecordingOptions;
|
|
3370
3313
|
}
|
|
3371
3314
|
init() {
|
|
3372
|
-
const puppeteerInstrumentation = new
|
|
3315
|
+
const puppeteerInstrumentation = new import_instrumentation3.InstrumentationNodeModuleDefinition(
|
|
3373
3316
|
"puppeteer",
|
|
3374
3317
|
// About two years before first writing this instrumentation
|
|
3375
3318
|
// and apparently no big breaking changes afterwards
|
|
@@ -3378,7 +3321,7 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3378
3321
|
this.patch.bind(this),
|
|
3379
3322
|
this.unpatch.bind(this)
|
|
3380
3323
|
);
|
|
3381
|
-
const puppeteerCoreInstrumentation = new
|
|
3324
|
+
const puppeteerCoreInstrumentation = new import_instrumentation3.InstrumentationNodeModuleDefinition(
|
|
3382
3325
|
"puppeteer-core",
|
|
3383
3326
|
[">=19.0.0"],
|
|
3384
3327
|
this.patch.bind(this),
|
|
@@ -3400,7 +3343,7 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3400
3343
|
return puppeteerModule;
|
|
3401
3344
|
}
|
|
3402
3345
|
patch(moduleExports, moduleVersion) {
|
|
3403
|
-
|
|
3346
|
+
import_api7.diag.debug(`patching puppeteer ${moduleVersion}`);
|
|
3404
3347
|
this._wrap(
|
|
3405
3348
|
moduleExports,
|
|
3406
3349
|
`launch`,
|
|
@@ -3434,7 +3377,7 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3434
3377
|
return moduleExports;
|
|
3435
3378
|
}
|
|
3436
3379
|
unpatch(moduleExports, moduleVersion) {
|
|
3437
|
-
|
|
3380
|
+
import_api7.diag.debug(`unpatching puppeteer ${moduleVersion}`);
|
|
3438
3381
|
this._unwrap(
|
|
3439
3382
|
moduleExports,
|
|
3440
3383
|
`launch`
|
|
@@ -3535,7 +3478,7 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3535
3478
|
await originalBringToFront();
|
|
3536
3479
|
await takeFullSnapshot(page);
|
|
3537
3480
|
};
|
|
3538
|
-
const currentSpan =
|
|
3481
|
+
const currentSpan = import_api7.trace.getSpan(LaminarContextManager.getContext()) ?? import_api7.trace.getActiveSpan();
|
|
3539
3482
|
currentSpan?.setAttribute(TRACE_HAS_BROWSER_SESSION, true);
|
|
3540
3483
|
const otelTraceId = currentSpan?.spanContext().traceId;
|
|
3541
3484
|
const traceId = otelTraceId ? otelTraceIdToUUID(otelTraceId) : NIL_UUID;
|
|
@@ -3550,19 +3493,10 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3550
3493
|
});
|
|
3551
3494
|
});
|
|
3552
3495
|
await injectSessionRecorder(page, this._sessionRecordingOptions);
|
|
3496
|
+
const chunkBuffers = /* @__PURE__ */ new Map();
|
|
3553
3497
|
try {
|
|
3554
|
-
await page.exposeFunction(LMNR_SEND_EVENTS_FUNCTION_NAME, async (
|
|
3555
|
-
|
|
3556
|
-
if (events != null && events.length > 0) {
|
|
3557
|
-
await this._client.browserEvents.send({
|
|
3558
|
-
sessionId,
|
|
3559
|
-
traceId,
|
|
3560
|
-
events
|
|
3561
|
-
});
|
|
3562
|
-
}
|
|
3563
|
-
} catch (error) {
|
|
3564
|
-
logger7.debug(`Could not send events: ${error instanceof Error ? error.message : String(error)}`);
|
|
3565
|
-
}
|
|
3498
|
+
await page.exposeFunction(LMNR_SEND_EVENTS_FUNCTION_NAME, async (chunk) => {
|
|
3499
|
+
await sendEvents(chunk, this._client, chunkBuffers, sessionId, traceId);
|
|
3566
3500
|
});
|
|
3567
3501
|
} catch (error) {
|
|
3568
3502
|
logger7.debug("Could not expose function " + LMNR_SEND_EVENTS_FUNCTION_NAME + `: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -3570,6 +3504,191 @@ var PuppeteerInstrumentation = class extends import_instrumentation4.Instrumenta
|
|
|
3570
3504
|
}
|
|
3571
3505
|
};
|
|
3572
3506
|
|
|
3507
|
+
// src/opentelemetry-lib/instrumentation/kernel.ts
|
|
3508
|
+
var import_api8 = require("@opentelemetry/api");
|
|
3509
|
+
var import_instrumentation4 = require("@opentelemetry/instrumentation");
|
|
3510
|
+
var WRAPPED_BROWSER_METHODS = [
|
|
3511
|
+
"create",
|
|
3512
|
+
"retrieve",
|
|
3513
|
+
"list",
|
|
3514
|
+
"delete",
|
|
3515
|
+
"deleteByID",
|
|
3516
|
+
"loadExtensions"
|
|
3517
|
+
];
|
|
3518
|
+
var WRAPPED_COMPUTER_METHODS = [
|
|
3519
|
+
"captureScreenshot",
|
|
3520
|
+
"clickMouse",
|
|
3521
|
+
"dragMouse",
|
|
3522
|
+
"moveMouse",
|
|
3523
|
+
"pressKey",
|
|
3524
|
+
"scroll",
|
|
3525
|
+
"typeText"
|
|
3526
|
+
];
|
|
3527
|
+
var WRAPPED_PROCESS_METHODS = [
|
|
3528
|
+
"exec",
|
|
3529
|
+
"kill",
|
|
3530
|
+
"spawn",
|
|
3531
|
+
"status",
|
|
3532
|
+
"stdin",
|
|
3533
|
+
"stdoutStream"
|
|
3534
|
+
];
|
|
3535
|
+
var KernelInstrumentation = class extends import_instrumentation4.InstrumentationBase {
|
|
3536
|
+
constructor() {
|
|
3537
|
+
super(
|
|
3538
|
+
"@lmnr/kernel-instrumentation",
|
|
3539
|
+
version,
|
|
3540
|
+
{
|
|
3541
|
+
enabled: true
|
|
3542
|
+
}
|
|
3543
|
+
);
|
|
3544
|
+
}
|
|
3545
|
+
init() {
|
|
3546
|
+
const module2 = new import_instrumentation4.InstrumentationNodeModuleDefinition(
|
|
3547
|
+
"@onkernel/sdk",
|
|
3548
|
+
[">=0.7.0"],
|
|
3549
|
+
this.patch.bind(this),
|
|
3550
|
+
this.unpatch.bind(this)
|
|
3551
|
+
);
|
|
3552
|
+
return module2;
|
|
3553
|
+
}
|
|
3554
|
+
manuallyInstrument(kernelModule) {
|
|
3555
|
+
for (const wrappedMethod of WRAPPED_BROWSER_METHODS) {
|
|
3556
|
+
this._wrap(
|
|
3557
|
+
kernelModule.Kernel.Browsers.prototype,
|
|
3558
|
+
wrappedMethod,
|
|
3559
|
+
this.patchMethod("Browser", wrappedMethod, "DEFAULT")
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
for (const wrappedMethod of WRAPPED_COMPUTER_METHODS) {
|
|
3563
|
+
if (wrappedMethod === "captureScreenshot") {
|
|
3564
|
+
this._wrap(
|
|
3565
|
+
kernelModule.Kernel.Browsers.Computer.prototype,
|
|
3566
|
+
wrappedMethod,
|
|
3567
|
+
this.patchTakeScreenshot()
|
|
3568
|
+
);
|
|
3569
|
+
} else {
|
|
3570
|
+
this._wrap(
|
|
3571
|
+
kernelModule.Kernel.Browsers.Computer.prototype,
|
|
3572
|
+
wrappedMethod,
|
|
3573
|
+
this.patchMethod("Computer", wrappedMethod, "TOOL")
|
|
3574
|
+
);
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
for (const wrappedMethod of WRAPPED_PROCESS_METHODS) {
|
|
3578
|
+
this._wrap(
|
|
3579
|
+
kernelModule.Kernel.Browsers.Process.prototype,
|
|
3580
|
+
wrappedMethod,
|
|
3581
|
+
this.patchProcessMethod(wrappedMethod)
|
|
3582
|
+
);
|
|
3583
|
+
}
|
|
3584
|
+
this._wrap(
|
|
3585
|
+
kernelModule.Kernel.prototype,
|
|
3586
|
+
"app",
|
|
3587
|
+
this.patchAppFactory()
|
|
3588
|
+
);
|
|
3589
|
+
}
|
|
3590
|
+
patchMethod(className, method, spanType) {
|
|
3591
|
+
return (original) => async function(...args) {
|
|
3592
|
+
return await observe(
|
|
3593
|
+
{
|
|
3594
|
+
name: `${className}.${method}`,
|
|
3595
|
+
spanType
|
|
3596
|
+
},
|
|
3597
|
+
async (innerArgs) => await original.bind(this).apply(this, innerArgs),
|
|
3598
|
+
args
|
|
3599
|
+
);
|
|
3600
|
+
};
|
|
3601
|
+
}
|
|
3602
|
+
patchTakeScreenshot() {
|
|
3603
|
+
return (original) => async function(...args) {
|
|
3604
|
+
const span = Laminar.startSpan({
|
|
3605
|
+
name: `Computer.captureScreenshot`,
|
|
3606
|
+
spanType: "TOOL",
|
|
3607
|
+
input: args
|
|
3608
|
+
});
|
|
3609
|
+
try {
|
|
3610
|
+
const res = await original.bind(this).apply(this, args);
|
|
3611
|
+
span.setAttribute("lmnr.span.output", "<BASE64_ENCODED_IMAGE>");
|
|
3612
|
+
return res;
|
|
3613
|
+
} finally {
|
|
3614
|
+
span.end();
|
|
3615
|
+
}
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
patchProcessMethod(method) {
|
|
3619
|
+
return (original) => async function(...args) {
|
|
3620
|
+
const span = Laminar.startSpan({
|
|
3621
|
+
name: `Process.${method}`,
|
|
3622
|
+
spanType: "TOOL",
|
|
3623
|
+
input: args
|
|
3624
|
+
});
|
|
3625
|
+
try {
|
|
3626
|
+
const result = await original.bind(this).apply(this, args);
|
|
3627
|
+
const output = {
|
|
3628
|
+
...result?.stderr_b64 ? { stderr: Buffer.from(result.stderr_b64, "base64").toString("utf-8") } : {},
|
|
3629
|
+
...result?.stdout_b64 ? { stdout: Buffer.from(result.stdout_b64, "base64").toString("utf-8") } : {},
|
|
3630
|
+
...result
|
|
3631
|
+
};
|
|
3632
|
+
span.setAttribute("lmnr.span.output", JSON.stringify(output));
|
|
3633
|
+
return result;
|
|
3634
|
+
} finally {
|
|
3635
|
+
span.end();
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
patchAppFactory() {
|
|
3640
|
+
const plugin = this;
|
|
3641
|
+
return (original) => function(name) {
|
|
3642
|
+
const kernelApp = original.call(this, name);
|
|
3643
|
+
plugin._wrap(
|
|
3644
|
+
kernelApp,
|
|
3645
|
+
"action",
|
|
3646
|
+
plugin.patchKernelAppAction()
|
|
3647
|
+
);
|
|
3648
|
+
return kernelApp;
|
|
3649
|
+
};
|
|
3650
|
+
}
|
|
3651
|
+
patchKernelAppAction() {
|
|
3652
|
+
return (original) => function(name, handler) {
|
|
3653
|
+
const wrappedHandler = async (context6, payload) => {
|
|
3654
|
+
const result = await observe(
|
|
3655
|
+
{
|
|
3656
|
+
name: `action.${name}`,
|
|
3657
|
+
spanType: "DEFAULT"
|
|
3658
|
+
},
|
|
3659
|
+
async (innerCtx, innerPayload) => {
|
|
3660
|
+
const result2 = await handler(innerCtx, innerPayload);
|
|
3661
|
+
return result2;
|
|
3662
|
+
},
|
|
3663
|
+
context6,
|
|
3664
|
+
payload
|
|
3665
|
+
);
|
|
3666
|
+
await Laminar.flush();
|
|
3667
|
+
return result;
|
|
3668
|
+
};
|
|
3669
|
+
return original.call(this, name, wrappedHandler);
|
|
3670
|
+
};
|
|
3671
|
+
}
|
|
3672
|
+
patch(moduleExports) {
|
|
3673
|
+
import_api8.diag.debug("Patching @onkernel/sdk");
|
|
3674
|
+
this.manuallyInstrument(moduleExports);
|
|
3675
|
+
return moduleExports;
|
|
3676
|
+
}
|
|
3677
|
+
unpatch(moduleExports) {
|
|
3678
|
+
import_api8.diag.debug("Unpatching @onkernel/sdk");
|
|
3679
|
+
for (const wrappedMethod of WRAPPED_BROWSER_METHODS) {
|
|
3680
|
+
this._unwrap(moduleExports.Kernel.Browsers.prototype, wrappedMethod);
|
|
3681
|
+
}
|
|
3682
|
+
for (const wrappedMethod of WRAPPED_COMPUTER_METHODS) {
|
|
3683
|
+
this._unwrap(moduleExports.Kernel.Browsers.Computer.prototype, wrappedMethod);
|
|
3684
|
+
}
|
|
3685
|
+
for (const wrappedMethod of WRAPPED_PROCESS_METHODS) {
|
|
3686
|
+
this._unwrap(moduleExports.Kernel.Browsers.Process.prototype, wrappedMethod);
|
|
3687
|
+
}
|
|
3688
|
+
this._unwrap(moduleExports.Kernel.prototype, "app");
|
|
3689
|
+
}
|
|
3690
|
+
};
|
|
3691
|
+
|
|
3573
3692
|
// src/opentelemetry-lib/tracing/instrumentations.ts
|
|
3574
3693
|
var initializeLaminarInstrumentations = (options = {}) => {
|
|
3575
3694
|
const url = options.baseUrl ?? process?.env?.LMNR_BASE_URL ?? "https://api.lmnr.ai";
|
|
@@ -4461,15 +4580,15 @@ Error: ${error.message}
|
|
|
4461
4580
|
}) {
|
|
4462
4581
|
this.cliProgress.stop();
|
|
4463
4582
|
const url = getEvaluationUrl(projectId, evaluationId, this.baseUrl);
|
|
4464
|
-
process.stdout.write(
|
|
4465
|
-
Check results at ${url}
|
|
4466
|
-
`);
|
|
4583
|
+
process.stdout.write("\n");
|
|
4467
4584
|
process.stdout.write("\nAverage scores:\n");
|
|
4468
4585
|
for (const key in averageScores) {
|
|
4469
|
-
process.stdout.write(`${key}: ${
|
|
4586
|
+
process.stdout.write(`${key}: ${averageScores[key]}
|
|
4470
4587
|
`);
|
|
4471
4588
|
}
|
|
4472
|
-
process.stdout.write(
|
|
4589
|
+
process.stdout.write(`
|
|
4590
|
+
Check results at ${url}
|
|
4591
|
+
`);
|
|
4473
4592
|
}
|
|
4474
4593
|
};
|
|
4475
4594
|
var Evaluation = class {
|
|
@@ -4562,10 +4681,18 @@ var Evaluation = class {
|
|
|
4562
4681
|
if (this.data instanceof LaminarDataset) {
|
|
4563
4682
|
this.data.setClient(this.client);
|
|
4564
4683
|
}
|
|
4565
|
-
this.progressReporter.start({ length: await this.getLength() });
|
|
4566
4684
|
let resultDatapoints;
|
|
4567
4685
|
try {
|
|
4568
4686
|
const evaluation = await this.client.evals.init(this.name, this.groupName, this.metadata);
|
|
4687
|
+
const url = getEvaluationUrl(
|
|
4688
|
+
evaluation.projectId,
|
|
4689
|
+
evaluation.id,
|
|
4690
|
+
this.progressReporter.baseUrl
|
|
4691
|
+
);
|
|
4692
|
+
process.stdout.write(`
|
|
4693
|
+
Check results at ${url}
|
|
4694
|
+
`);
|
|
4695
|
+
this.progressReporter.start({ length: await this.getLength() });
|
|
4569
4696
|
resultDatapoints = await this.evaluateInBatches(evaluation.id);
|
|
4570
4697
|
const averageScores = getAverageScores(resultDatapoints);
|
|
4571
4698
|
if (this.uploadPromises.length > 0) {
|
|
@@ -4578,11 +4705,22 @@ var Evaluation = class {
|
|
|
4578
4705
|
});
|
|
4579
4706
|
this.isFinished = true;
|
|
4580
4707
|
await Laminar.shutdown();
|
|
4581
|
-
return
|
|
4708
|
+
return {
|
|
4709
|
+
averageScores,
|
|
4710
|
+
projectId: evaluation.projectId,
|
|
4711
|
+
evaluationId: evaluation.id,
|
|
4712
|
+
url
|
|
4713
|
+
};
|
|
4582
4714
|
} catch (e) {
|
|
4583
4715
|
this.progressReporter.stopWithError(e);
|
|
4584
4716
|
this.isFinished = true;
|
|
4585
|
-
return {
|
|
4717
|
+
return {
|
|
4718
|
+
averageScores: {},
|
|
4719
|
+
projectId: "",
|
|
4720
|
+
evaluationId: "",
|
|
4721
|
+
url: "",
|
|
4722
|
+
errorMessage: e instanceof Error ? e.message : String(e)
|
|
4723
|
+
};
|
|
4586
4724
|
}
|
|
4587
4725
|
}
|
|
4588
4726
|
async evaluateInBatches(evalId) {
|
|
@@ -4730,7 +4868,7 @@ async function evaluate({
|
|
|
4730
4868
|
if (globalThis._set_global_evaluation) {
|
|
4731
4869
|
globalThis._evaluations = [...globalThis._evaluations ?? [], evaluation];
|
|
4732
4870
|
} else {
|
|
4733
|
-
await evaluation.run();
|
|
4871
|
+
return await evaluation.run();
|
|
4734
4872
|
}
|
|
4735
4873
|
}
|
|
4736
4874
|
|