@lmnr-ai/lmnr 0.8.22-alpha.1 → 0.8.23
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/worker/index.cjs +1 -1
- package/dist/cli/worker/index.mjs +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{decorators-Bq6Sf8vt.mjs → decorators-BKinfQHD.mjs} +55 -142
- package/dist/decorators-BKinfQHD.mjs.map +1 -0
- package/dist/{decorators-Bb2owkCc.cjs → decorators-LxN0pWBY.cjs} +60 -141
- package/dist/decorators-LxN0pWBY.cjs.map +1 -0
- package/dist/{dist-DZMJR04H.cjs → dist-B7-TO5Cy.cjs} +3 -3
- package/dist/{dist-DZMJR04H.cjs.map → dist-B7-TO5Cy.cjs.map} +1 -1
- package/dist/{dist-TLHkfisO.mjs → dist-CUxvL7k9.mjs} +3 -3
- package/dist/{dist-TLHkfisO.mjs.map → dist-CUxvL7k9.mjs.map} +1 -1
- package/dist/index.cjs +29 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +29 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/decorators-Bb2owkCc.cjs.map +0 -1
- package/dist/decorators-Bq6Sf8vt.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require("../../chunk-Do9eywBl.cjs");
|
|
2
|
-
const require_decorators = require("../../decorators-
|
|
2
|
+
const require_decorators = require("../../decorators-LxN0pWBY.cjs");
|
|
3
3
|
const require_cli_worker_build = require("./build.cjs");
|
|
4
4
|
let readline = require("readline");
|
|
5
5
|
readline = require_chunk.__toESM(readline);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as Laminar,
|
|
1
|
+
import { d as Laminar, g as consumeStreamResult } from "../../decorators-BKinfQHD.mjs";
|
|
2
2
|
import { buildFile, loadModule, selectRolloutFunction } from "./build.mjs";
|
|
3
3
|
import * as readline from "readline";
|
|
4
4
|
//#region src/cli/worker/index.ts
|
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const require_chunk = require("./chunk-Do9eywBl.cjs");
|
|
3
|
-
const require_dist = require("./dist-
|
|
3
|
+
const require_dist = require("./dist-B7-TO5Cy.cjs");
|
|
4
4
|
const require_utils = require("./utils-C8Tl1vKD.cjs");
|
|
5
5
|
const require_file_utils = require("./file-utils-yJ5ephze.cjs");
|
|
6
6
|
const require_proxy_to_lmnr_cli = require("./proxy-to-lmnr-cli-OA7sXzcz.cjs");
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { r as __require } from "./chunk-BEJ448es.mjs";
|
|
3
|
-
import { n as version, t as LaminarClient } from "./dist-
|
|
3
|
+
import { n as version, t as LaminarClient } from "./dist-CUxvL7k9.mjs";
|
|
4
4
|
import { i as getDirname, s as initializeLogger } from "./utils-CHJ0KZUR.mjs";
|
|
5
5
|
import { i as writeToFile, n as loadFromPaths, r as printToConsole } from "./file-utils-CHoR9VB8.mjs";
|
|
6
6
|
import { t as proxyToLmnrCli } from "./proxy-to-lmnr-cli-DNDxudgt.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as __require } from "./chunk-BEJ448es.mjs";
|
|
2
|
-
import { n as version, t as LaminarClient } from "./dist-
|
|
2
|
+
import { n as version, t as LaminarClient } from "./dist-CUxvL7k9.mjs";
|
|
3
3
|
import { A as SPAN_OUTPUT, C as PARENT_SPAN_PATH, D as SPAN_INPUT, E as SPAN_IDS_PATH, F as TRACE_TYPE, I as USER_ID, M as SPAN_SDK_VERSION, N as SPAN_TYPE, O as SPAN_INSTRUMENTATION_SOURCE, P as TRACE_HAS_BROWSER_SESSION, S as PARENT_SPAN_IDS_PATH, T as SESSION_ID, _ as validateTracingConfig, c as loadEnv, g as tryToOtelSpanContext, h as parseOtelHeaders, j as SPAN_PATH, k as SPAN_LANGUAGE_VERSION, l as metadataToAttributes, m as otelTraceIdToUUID, o as getOtelEnvVar, p as otelSpanIdToUUID, r as deserializeLaminarSpanContext, s as initializeLogger, t as NIL_UUID, u as newUUID, v as ASSOCIATION_PROPERTIES, w as ROLLOUT_SESSION_ID, x as LaminarAttributes, y as ASSOCIATION_PROPERTIES_OVERRIDES } from "./utils-CHJ0KZUR.mjs";
|
|
4
4
|
import { DiagConsoleLogger, DiagLogLevel, ROOT_CONTEXT, SpanStatusCode, context, createContextKey, diag, isSpanContextValid, trace } from "@opentelemetry/api";
|
|
5
5
|
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
@@ -2170,7 +2170,7 @@ const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
|
2170
2170
|
};
|
|
2171
2171
|
if (!window.lmnrStartedRecordingEvents) {
|
|
2172
2172
|
setInterval(sendBatchIfReady, BATCH_TIMEOUT);
|
|
2173
|
-
|
|
2173
|
+
window.lmnrRrweb.record({
|
|
2174
2174
|
emit(event) {
|
|
2175
2175
|
window.lmnrRrwebEventsBatch.push(event);
|
|
2176
2176
|
},
|
|
@@ -2186,17 +2186,12 @@ const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
|
2186
2186
|
email: sessionRecordingOptions?.maskInputOptions?.email || false,
|
|
2187
2187
|
tel: sessionRecordingOptions?.maskInputOptions?.tel || false
|
|
2188
2188
|
}
|
|
2189
|
-
};
|
|
2190
|
-
window.lmnrRrweb.record(recordOptions);
|
|
2189
|
+
});
|
|
2191
2190
|
setInterval(() => {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
});
|
|
2197
|
-
} catch {
|
|
2198
|
-
window.lmnrRrweb.record(recordOptions);
|
|
2199
|
-
}
|
|
2191
|
+
window.lmnrRrweb.record.addCustomEvent("heartbeat", {
|
|
2192
|
+
title: document.title,
|
|
2193
|
+
url: document.URL
|
|
2194
|
+
});
|
|
2200
2195
|
}, HEARTBEAT_INTERVAL);
|
|
2201
2196
|
window.lmnrStartedRecordingEvents = true;
|
|
2202
2197
|
}
|
|
@@ -2925,14 +2920,26 @@ function shouldSkipUrl(url) {
|
|
|
2925
2920
|
return SKIP_URL_PATTERNS.some((pattern) => url.startsWith(pattern));
|
|
2926
2921
|
}
|
|
2927
2922
|
/**
|
|
2923
|
+
* Send a CDP command to the given page. Works across Stagehand 3.0.x and 3.1.x+.
|
|
2924
|
+
*
|
|
2925
|
+
* `page.sendCDP` was added in Stagehand 3.1.0. On 3.0.x we fall back to
|
|
2926
|
+
* `getSessionForFrame(mainFrameId()).send(...)` (both methods are public on
|
|
2927
|
+
* the 3.0.x Page; `mainSession` is not).
|
|
2928
|
+
*/
|
|
2929
|
+
async function sendCDP(page, method, params) {
|
|
2930
|
+
if (typeof page.sendCDP === "function") return await page.sendCDP(method, params);
|
|
2931
|
+
if (typeof page.getSessionForFrame === "function") return await page.getSessionForFrame(page.mainFrameId()).send(method, params);
|
|
2932
|
+
throw new Error("Stagehand page does not expose sendCDP or getSessionForFrame; unable to send CDP commands");
|
|
2933
|
+
}
|
|
2934
|
+
/**
|
|
2928
2935
|
* Create an isolated world for a page and return the execution context ID
|
|
2929
2936
|
*/
|
|
2930
2937
|
async function getOrCreateIsolatedWorld(page) {
|
|
2931
2938
|
try {
|
|
2932
|
-
const frameTreeResult = await Promise.race([
|
|
2939
|
+
const frameTreeResult = await Promise.race([sendCDP(page, "Page.getFrameTree"), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("Timeout getting frame tree")), CDP_OPERATION_TIMEOUT_MS))]);
|
|
2933
2940
|
if (!frameTreeResult) return null;
|
|
2934
2941
|
const frameId = frameTreeResult.frameTree.frame.id;
|
|
2935
|
-
const isolatedWorldResult = await Promise.race([
|
|
2942
|
+
const isolatedWorldResult = await Promise.race([sendCDP(page, "Page.createIsolatedWorld", {
|
|
2936
2943
|
frameId,
|
|
2937
2944
|
worldName: "laminar-recorder"
|
|
2938
2945
|
}), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("Timeout creating isolated world")), CDP_OPERATION_TIMEOUT_MS))]);
|
|
@@ -2951,7 +2958,7 @@ async function getOrCreateIsolatedWorld(page) {
|
|
|
2951
2958
|
*/
|
|
2952
2959
|
async function isRecorderPresent(page, contextId) {
|
|
2953
2960
|
try {
|
|
2954
|
-
const result = await Promise.race([
|
|
2961
|
+
const result = await Promise.race([sendCDP(page, "Runtime.evaluate", {
|
|
2955
2962
|
expression: "typeof window.lmnrRrweb !== 'undefined'",
|
|
2956
2963
|
contextId,
|
|
2957
2964
|
returnByValue: true
|
|
@@ -2994,7 +3001,7 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
2994
3001
|
return contextId;
|
|
2995
3002
|
}
|
|
2996
3003
|
try {
|
|
2997
|
-
await
|
|
3004
|
+
await sendCDP(page, "Runtime.evaluate", {
|
|
2998
3005
|
expression: RECORDER,
|
|
2999
3006
|
contextId
|
|
3000
3007
|
});
|
|
@@ -3005,7 +3012,7 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
3005
3012
|
const optionsJson = JSON.stringify(sessionRecordingOptions ?? {});
|
|
3006
3013
|
const injectExpression = `(${injectScript.toString()})(${optionsJson}, true);`;
|
|
3007
3014
|
try {
|
|
3008
|
-
await
|
|
3015
|
+
await sendCDP(page, "Runtime.evaluate", {
|
|
3009
3016
|
expression: injectExpression,
|
|
3010
3017
|
contextId
|
|
3011
3018
|
});
|
|
@@ -3014,7 +3021,7 @@ async function injectRecorderViaCDP(page, state, conn, sessionRecordingOptions,
|
|
|
3014
3021
|
return null;
|
|
3015
3022
|
}
|
|
3016
3023
|
try {
|
|
3017
|
-
await
|
|
3024
|
+
await sendCDP(page, "Runtime.addBinding", { name: "lmnrSendEvents" });
|
|
3018
3025
|
logger$8.debug(`Added binding 'lmnrSendEvents' for page ${frameId}, context ${contextId}`);
|
|
3019
3026
|
} catch (error) {
|
|
3020
3027
|
logger$8.debug(`Binding may already exist: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -3119,29 +3126,6 @@ function createTargetInfoChangedHandler(context, state, sessionRecordingOptions)
|
|
|
3119
3126
|
}
|
|
3120
3127
|
//#endregion
|
|
3121
3128
|
//#region src/browser/stagehand/v3/instrumentation.ts
|
|
3122
|
-
/**
|
|
3123
|
-
* Guarded _wrap: only wraps `target[methodName]` if it exists as a function.
|
|
3124
|
-
* Prevents the "Cannot wrap non-existent method" warning from
|
|
3125
|
-
* InstrumentationBase._wrap when a handler/method was renamed or removed
|
|
3126
|
-
* in the upstream library (e.g. Stagehand v2 vs v3 differences).
|
|
3127
|
-
*/
|
|
3128
|
-
const safeWrap = (instrumentation, target, methodName, wrapper) => {
|
|
3129
|
-
if (!target) return false;
|
|
3130
|
-
if (typeof target[methodName] !== "function") return false;
|
|
3131
|
-
instrumentation._wrap(target, methodName, wrapper);
|
|
3132
|
-
return true;
|
|
3133
|
-
};
|
|
3134
|
-
/**
|
|
3135
|
-
* Guarded _unwrap counterpart to safeWrap. Only unwraps when the target method
|
|
3136
|
-
* exists AND was previously wrapped via shimmer (has the `__original` marker).
|
|
3137
|
-
*/
|
|
3138
|
-
const safeUnwrap = (instrumentation, target, methodName) => {
|
|
3139
|
-
if (!target) return;
|
|
3140
|
-
const current = target[methodName];
|
|
3141
|
-
if (typeof current !== "function") return;
|
|
3142
|
-
if (!current.__original) return;
|
|
3143
|
-
instrumentation._unwrap(target, methodName);
|
|
3144
|
-
};
|
|
3145
3129
|
var StagehandInstrumentation = class extends InstrumentationBase {
|
|
3146
3130
|
constructor(sessionRecordingOptions) {
|
|
3147
3131
|
super("@lmnr/browserbase-stagehand-instrumentation", version, { enabled: true });
|
|
@@ -3193,28 +3177,21 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3193
3177
|
}
|
|
3194
3178
|
unpatch(moduleExports, moduleVersion) {
|
|
3195
3179
|
diag.debug(`unpatching stagehand ${moduleVersion}`);
|
|
3196
|
-
|
|
3180
|
+
this._unwrap(moduleExports, "Stagehand");
|
|
3197
3181
|
if (moduleExports.Stagehand && moduleExports.Stagehand.prototype) {
|
|
3182
|
+
this._unwrap(moduleExports.Stagehand.prototype, "init");
|
|
3183
|
+
this._unwrap(moduleExports.Stagehand.prototype, "close");
|
|
3184
|
+
this._unwrap(moduleExports.Stagehand.prototype, "act");
|
|
3185
|
+
this._unwrap(moduleExports.Stagehand.prototype, "extract");
|
|
3186
|
+
this._unwrap(moduleExports.Stagehand.prototype, "observe");
|
|
3198
3187
|
const prototype = moduleExports.Stagehand.prototype;
|
|
3199
|
-
safeUnwrap(this, prototype, "init");
|
|
3200
|
-
safeUnwrap(this, prototype, "close");
|
|
3201
|
-
safeUnwrap(this, prototype, "act");
|
|
3202
|
-
safeUnwrap(this, prototype, "extract");
|
|
3203
|
-
safeUnwrap(this, prototype, "observe");
|
|
3204
|
-
safeUnwrap(this, prototype, "agent");
|
|
3205
3188
|
if (prototype.actHandler) {
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
}
|
|
3209
|
-
if (prototype.extractHandler) safeUnwrap(this, prototype.extractHandler, "extract");
|
|
3210
|
-
if (prototype.observeHandler) safeUnwrap(this, prototype.observeHandler, "observe");
|
|
3211
|
-
if (prototype.llmClient) safeUnwrap(this, prototype.llmClient, "createChatCompletion");
|
|
3212
|
-
if (prototype.apiClient) {
|
|
3213
|
-
safeUnwrap(this, prototype.apiClient, "act");
|
|
3214
|
-
safeUnwrap(this, prototype.apiClient, "extract");
|
|
3215
|
-
safeUnwrap(this, prototype.apiClient, "observe");
|
|
3216
|
-
safeUnwrap(this, prototype.apiClient, "agentExecute");
|
|
3189
|
+
this._unwrap(prototype.actHandler, "act");
|
|
3190
|
+
this._unwrap(prototype.actHandler, "actFromObserveResult");
|
|
3217
3191
|
}
|
|
3192
|
+
if (prototype.extractHandler) this._unwrap(prototype.extractHandler, "extract");
|
|
3193
|
+
if (prototype.observeHandler) this._unwrap(prototype.observeHandler, "observe");
|
|
3194
|
+
if (prototype.llmClient) this._unwrap(prototype.llmClient, "createChatCompletion");
|
|
3218
3195
|
}
|
|
3219
3196
|
return moduleExports;
|
|
3220
3197
|
}
|
|
@@ -3246,9 +3223,9 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3246
3223
|
const otelTraceId = parentSpan.spanContext().traceId;
|
|
3247
3224
|
const traceId = otelTraceIdToUUID(otelTraceId);
|
|
3248
3225
|
const result = await original.bind(this).apply(this);
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3226
|
+
instrumentation._wrap(this, "act", instrumentation.patchStagehandGlobalMethod("act", sessionId, parentSpan));
|
|
3227
|
+
instrumentation._wrap(this, "extract", instrumentation.patchStagehandGlobalMethod("extract", sessionId, parentSpan));
|
|
3228
|
+
instrumentation._wrap(this, "observe", instrumentation.patchStagehandGlobalMethod("observe", sessionId, parentSpan));
|
|
3252
3229
|
if (this.actHandler) instrumentation.patchActHandler(this.actHandler);
|
|
3253
3230
|
if (this.extractHandler) instrumentation.patchExtractHandler(this.extractHandler);
|
|
3254
3231
|
if (this.observeHandler) instrumentation.patchObserveHandler(this.observeHandler);
|
|
@@ -3257,10 +3234,9 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3257
3234
|
provider: this.llmClient.type,
|
|
3258
3235
|
model: this.llmClient.modelName
|
|
3259
3236
|
});
|
|
3260
|
-
|
|
3237
|
+
instrumentation._wrap(this.llmClient, "createChatCompletion", instrumentation.patchStagehandLLMClientCreateChatCompletion());
|
|
3261
3238
|
}
|
|
3262
|
-
|
|
3263
|
-
safeWrap(instrumentation, this, "agent", instrumentation.patchStagehandAgentInitializer(sessionId, parentSpan));
|
|
3239
|
+
instrumentation._wrap(this, "agent", instrumentation.patchStagehandAgentInitializer(sessionId, parentSpan));
|
|
3264
3240
|
if (instrumentation._client) await instrumentation.setupSessionRecording(this, sessionId, traceId);
|
|
3265
3241
|
if (this.context && this.context.pages) for (const page of this.context.pages()) instrumentation.patchStagehandPage(page, parentSpan);
|
|
3266
3242
|
if (this.context && this.context.on) this.context.on("page", (page) => {
|
|
@@ -3395,8 +3371,8 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3395
3371
|
};
|
|
3396
3372
|
}
|
|
3397
3373
|
patchActHandler(actHandler) {
|
|
3398
|
-
|
|
3399
|
-
|
|
3374
|
+
this._wrap(actHandler, "act", this.patchActHandlerAct());
|
|
3375
|
+
this._wrap(actHandler, "actFromObserveResult", this.patchActHandlerActFromObserveResult());
|
|
3400
3376
|
}
|
|
3401
3377
|
patchActHandlerAct() {
|
|
3402
3378
|
return (original) => async function act(...args) {
|
|
@@ -3425,7 +3401,7 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3425
3401
|
};
|
|
3426
3402
|
}
|
|
3427
3403
|
patchExtractHandler(extractHandler) {
|
|
3428
|
-
|
|
3404
|
+
this._wrap(extractHandler, "extract", this.patchExtractHandlerExtract());
|
|
3429
3405
|
}
|
|
3430
3406
|
patchExtractHandlerExtract() {
|
|
3431
3407
|
return (original) => async function extract(...args) {
|
|
@@ -3449,7 +3425,7 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3449
3425
|
};
|
|
3450
3426
|
}
|
|
3451
3427
|
patchObserveHandler(observeHandler) {
|
|
3452
|
-
|
|
3428
|
+
this._wrap(observeHandler, "observe", this.patchObserveHandlerObserve());
|
|
3453
3429
|
}
|
|
3454
3430
|
patchObserveHandlerObserve() {
|
|
3455
3431
|
return (original) => async function observe$1(...args) {
|
|
@@ -3477,7 +3453,7 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3477
3453
|
};
|
|
3478
3454
|
}
|
|
3479
3455
|
patchStagehandAgent(agent, sessionId, parentSpan) {
|
|
3480
|
-
|
|
3456
|
+
this._wrap(agent, "execute", this.patchStagehandAgentExecute(sessionId, parentSpan));
|
|
3481
3457
|
this.wrapAgentMethod(agent, "captureScreenshot", parentSpan, {
|
|
3482
3458
|
spanType: "TOOL",
|
|
3483
3459
|
ignoreOutput: true
|
|
@@ -3544,7 +3520,8 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3544
3520
|
};
|
|
3545
3521
|
}
|
|
3546
3522
|
wrapAgentMethod(agent, methodName, parentSpan, options) {
|
|
3547
|
-
|
|
3523
|
+
if (typeof agent[methodName] !== "function") return;
|
|
3524
|
+
this._wrap(agent, methodName, (original) => async function method(...args) {
|
|
3548
3525
|
const currentSpan = trace.getSpan(LaminarContextManager.getContext()) ?? trace.getActiveSpan();
|
|
3549
3526
|
return await Laminar.withSpan(currentSpan ?? parentSpan, async () => await observe({
|
|
3550
3527
|
name: `stagehand.agent.${methodName}`,
|
|
@@ -3566,77 +3543,13 @@ var StagehandInstrumentation = class extends InstrumentationBase {
|
|
|
3566
3543
|
"keyPress",
|
|
3567
3544
|
"keyDown",
|
|
3568
3545
|
"keyUp"
|
|
3569
|
-
])
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
});
|
|
3573
|
-
}
|
|
3574
|
-
/**
|
|
3575
|
-
* In BROWSERBASE remote mode Stagehand's top-level `act`/`extract`/`observe`/
|
|
3576
|
-
* agent `execute` are routed through an internal `StagehandAPIClient` which
|
|
3577
|
-
* makes HTTP calls to the Stagehand Cloud API. The local `llmClient` and the
|
|
3578
|
-
* local `actHandler`/`extractHandler`/`observeHandler` are therefore never
|
|
3579
|
-
* invoked and our existing wrappers do not fire.
|
|
3580
|
-
*
|
|
3581
|
-
* Wrap the apiClient methods directly so we still emit child spans for the
|
|
3582
|
-
* LLM-backed calls and surface token usage from the response where available.
|
|
3583
|
-
*/
|
|
3584
|
-
patchStagehandApiClient(apiClient, _sessionId, parentSpan, stagehandInstance) {
|
|
3585
|
-
const instrumentation = this;
|
|
3586
|
-
const baseProvider = stagehandInstance?.llmClient?.type;
|
|
3587
|
-
const baseModel = stagehandInstance?.llmClient?.modelName;
|
|
3588
|
-
const wrapApiMethod = (methodName) => {
|
|
3589
|
-
safeWrap(instrumentation, apiClient, methodName, (original) => async function method(...args) {
|
|
3546
|
+
]) {
|
|
3547
|
+
if (typeof page[methodName] !== "function") continue;
|
|
3548
|
+
this._wrap(page, methodName, (original) => async function method(...args) {
|
|
3590
3549
|
const currentSpan = trace.getSpan(LaminarContextManager.getContext()) ?? trace.getActiveSpan();
|
|
3591
|
-
|
|
3592
|
-
const spanName = methodName === "agentExecute" ? "stagehand.apiClient.agentExecute" : `stagehand.apiClient.${methodName}`;
|
|
3593
|
-
return await Laminar.withSpan(currentSpan ?? parentSpan, async () => await observe({
|
|
3594
|
-
name: spanName,
|
|
3595
|
-
input,
|
|
3596
|
-
spanType: "LLM",
|
|
3597
|
-
ignoreInput: true,
|
|
3598
|
-
ignoreOutput: true
|
|
3599
|
-
}, async () => {
|
|
3600
|
-
const span = trace.getSpan(LaminarContextManager.getContext()) ?? trace.getActiveSpan();
|
|
3601
|
-
span?.setAttribute(TRACE_HAS_BROWSER_SESSION, true);
|
|
3602
|
-
if (baseProvider) span?.setAttribute("gen_ai.system", baseProvider);
|
|
3603
|
-
if (baseModel) span?.setAttribute("gen_ai.request.model", baseModel);
|
|
3604
|
-
try {
|
|
3605
|
-
const firstArg = args[0];
|
|
3606
|
-
const instruction = typeof firstArg === "string" ? firstArg : firstArg?.input ?? firstArg?.instruction;
|
|
3607
|
-
if (typeof instruction === "string" && instruction.length > 0) span?.setAttributes({
|
|
3608
|
-
"gen_ai.prompt.0.role": "user",
|
|
3609
|
-
"gen_ai.prompt.0.content": instruction
|
|
3610
|
-
});
|
|
3611
|
-
} catch {}
|
|
3612
|
-
const result = await original.bind(this).apply(this, args);
|
|
3613
|
-
try {
|
|
3614
|
-
const usage = result?.usage;
|
|
3615
|
-
if (usage) {
|
|
3616
|
-
const inputTokens = usage.input_tokens ?? usage.prompt_tokens ?? 0;
|
|
3617
|
-
const outputTokens = usage.output_tokens ?? usage.completion_tokens ?? 0;
|
|
3618
|
-
span?.setAttributes({
|
|
3619
|
-
"gen_ai.usage.input_tokens": inputTokens,
|
|
3620
|
-
"gen_ai.usage.output_tokens": outputTokens,
|
|
3621
|
-
"llm.usage.total_tokens": inputTokens + outputTokens
|
|
3622
|
-
});
|
|
3623
|
-
}
|
|
3624
|
-
if (methodName === "agentExecute") {
|
|
3625
|
-
const message = result?.message;
|
|
3626
|
-
if (message) span?.setAttributes({
|
|
3627
|
-
"gen_ai.completion.0.role": "assistant",
|
|
3628
|
-
"gen_ai.completion.0.content": typeof message === "string" ? message : JSON.stringify(message)
|
|
3629
|
-
});
|
|
3630
|
-
}
|
|
3631
|
-
} catch {}
|
|
3632
|
-
return result;
|
|
3633
|
-
}));
|
|
3550
|
+
return await Laminar.withSpan(currentSpan ?? parentSpan, async () => await observe({ name: `stagehand.page.${methodName}` }, async (argVals) => await original.bind(this).apply(this, argVals), args));
|
|
3634
3551
|
});
|
|
3635
|
-
}
|
|
3636
|
-
wrapApiMethod("act");
|
|
3637
|
-
wrapApiMethod("extract");
|
|
3638
|
-
wrapApiMethod("observe");
|
|
3639
|
-
wrapApiMethod("agentExecute");
|
|
3552
|
+
}
|
|
3640
3553
|
}
|
|
3641
3554
|
};
|
|
3642
3555
|
//#endregion
|
|
@@ -5875,6 +5788,6 @@ function observeExperimentalDecorator(config) {
|
|
|
5875
5788
|
};
|
|
5876
5789
|
}
|
|
5877
5790
|
//#endregion
|
|
5878
|
-
export { getSpanProcessor as a, LaminarSpanProcessor as c, Laminar as d, instrumentClaudeAgentQuery as f,
|
|
5791
|
+
export { stringifyPromptForTelemetry as _, getSpanProcessor as a, LaminarSpanProcessor as c, Laminar as d, instrumentClaudeAgentQuery as f, consumeStreamResult as g, TracingLevel as h, withTracingLevel as i, getLangVersion as l, LaminarContextManager as m, observeDecorator as n, getTracer as o, ASSOCIATION_PROPERTIES_KEY as p, observeExperimentalDecorator as r, getTracerProvider as s, observe as t, initializeLaminarInstrumentations as u };
|
|
5879
5792
|
|
|
5880
|
-
//# sourceMappingURL=decorators-
|
|
5793
|
+
//# sourceMappingURL=decorators-BKinfQHD.mjs.map
|