@lmnr-ai/lmnr 0.8.22-alpha.1 → 0.8.22
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-Bb2owkCc.cjs → decorators-CKzMiD2H.cjs} +42 -135
- package/dist/decorators-CKzMiD2H.cjs.map +1 -0
- package/dist/{decorators-Bq6Sf8vt.mjs → decorators-DrWG-1Po.mjs} +37 -136
- package/dist/decorators-DrWG-1Po.mjs.map +1 -0
- package/dist/{dist-TLHkfisO.mjs → dist-BXwORFgR.mjs} +3 -3
- package/dist/{dist-TLHkfisO.mjs.map → dist-BXwORFgR.mjs.map} +1 -1
- package/dist/{dist-DZMJR04H.cjs → dist-CzSNkDiM.cjs} +3 -3
- package/dist/{dist-DZMJR04H.cjs.map → dist-CzSNkDiM.cjs.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-CKzMiD2H.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-DrWG-1Po.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-CzSNkDiM.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-BXwORFgR.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
|
const require_chunk = require("./chunk-Do9eywBl.cjs");
|
|
2
|
-
const require_dist = require("./dist-
|
|
2
|
+
const require_dist = require("./dist-CzSNkDiM.cjs");
|
|
3
3
|
const require_utils = require("./utils-C8Tl1vKD.cjs");
|
|
4
4
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
5
5
|
let _opentelemetry_context_async_hooks = require("@opentelemetry/context-async-hooks");
|
|
@@ -2174,7 +2174,7 @@ const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
|
2174
2174
|
};
|
|
2175
2175
|
if (!window.lmnrStartedRecordingEvents) {
|
|
2176
2176
|
setInterval(sendBatchIfReady, BATCH_TIMEOUT);
|
|
2177
|
-
|
|
2177
|
+
window.lmnrRrweb.record({
|
|
2178
2178
|
emit(event) {
|
|
2179
2179
|
window.lmnrRrwebEventsBatch.push(event);
|
|
2180
2180
|
},
|
|
@@ -2190,17 +2190,12 @@ const injectScript = (sessionRecordingOptions, stringifyCallbackArgs) => {
|
|
|
2190
2190
|
email: sessionRecordingOptions?.maskInputOptions?.email || false,
|
|
2191
2191
|
tel: sessionRecordingOptions?.maskInputOptions?.tel || false
|
|
2192
2192
|
}
|
|
2193
|
-
};
|
|
2194
|
-
window.lmnrRrweb.record(recordOptions);
|
|
2193
|
+
});
|
|
2195
2194
|
setInterval(() => {
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
});
|
|
2201
|
-
} catch {
|
|
2202
|
-
window.lmnrRrweb.record(recordOptions);
|
|
2203
|
-
}
|
|
2195
|
+
window.lmnrRrweb.record.addCustomEvent("heartbeat", {
|
|
2196
|
+
title: document.title,
|
|
2197
|
+
url: document.URL
|
|
2198
|
+
});
|
|
2204
2199
|
}, HEARTBEAT_INTERVAL);
|
|
2205
2200
|
window.lmnrStartedRecordingEvents = true;
|
|
2206
2201
|
}
|
|
@@ -3123,29 +3118,6 @@ function createTargetInfoChangedHandler(context, state, sessionRecordingOptions)
|
|
|
3123
3118
|
}
|
|
3124
3119
|
//#endregion
|
|
3125
3120
|
//#region src/browser/stagehand/v3/instrumentation.ts
|
|
3126
|
-
/**
|
|
3127
|
-
* Guarded _wrap: only wraps `target[methodName]` if it exists as a function.
|
|
3128
|
-
* Prevents the "Cannot wrap non-existent method" warning from
|
|
3129
|
-
* InstrumentationBase._wrap when a handler/method was renamed or removed
|
|
3130
|
-
* in the upstream library (e.g. Stagehand v2 vs v3 differences).
|
|
3131
|
-
*/
|
|
3132
|
-
const safeWrap = (instrumentation, target, methodName, wrapper) => {
|
|
3133
|
-
if (!target) return false;
|
|
3134
|
-
if (typeof target[methodName] !== "function") return false;
|
|
3135
|
-
instrumentation._wrap(target, methodName, wrapper);
|
|
3136
|
-
return true;
|
|
3137
|
-
};
|
|
3138
|
-
/**
|
|
3139
|
-
* Guarded _unwrap counterpart to safeWrap. Only unwraps when the target method
|
|
3140
|
-
* exists AND was previously wrapped via shimmer (has the `__original` marker).
|
|
3141
|
-
*/
|
|
3142
|
-
const safeUnwrap = (instrumentation, target, methodName) => {
|
|
3143
|
-
if (!target) return;
|
|
3144
|
-
const current = target[methodName];
|
|
3145
|
-
if (typeof current !== "function") return;
|
|
3146
|
-
if (!current.__original) return;
|
|
3147
|
-
instrumentation._unwrap(target, methodName);
|
|
3148
|
-
};
|
|
3149
3121
|
var StagehandInstrumentation = class extends _opentelemetry_instrumentation.InstrumentationBase {
|
|
3150
3122
|
constructor(sessionRecordingOptions) {
|
|
3151
3123
|
super("@lmnr/browserbase-stagehand-instrumentation", require_dist.version, { enabled: true });
|
|
@@ -3197,28 +3169,21 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3197
3169
|
}
|
|
3198
3170
|
unpatch(moduleExports, moduleVersion) {
|
|
3199
3171
|
_opentelemetry_api.diag.debug(`unpatching stagehand ${moduleVersion}`);
|
|
3200
|
-
|
|
3172
|
+
this._unwrap(moduleExports, "Stagehand");
|
|
3201
3173
|
if (moduleExports.Stagehand && moduleExports.Stagehand.prototype) {
|
|
3174
|
+
this._unwrap(moduleExports.Stagehand.prototype, "init");
|
|
3175
|
+
this._unwrap(moduleExports.Stagehand.prototype, "close");
|
|
3176
|
+
this._unwrap(moduleExports.Stagehand.prototype, "act");
|
|
3177
|
+
this._unwrap(moduleExports.Stagehand.prototype, "extract");
|
|
3178
|
+
this._unwrap(moduleExports.Stagehand.prototype, "observe");
|
|
3202
3179
|
const prototype = moduleExports.Stagehand.prototype;
|
|
3203
|
-
safeUnwrap(this, prototype, "init");
|
|
3204
|
-
safeUnwrap(this, prototype, "close");
|
|
3205
|
-
safeUnwrap(this, prototype, "act");
|
|
3206
|
-
safeUnwrap(this, prototype, "extract");
|
|
3207
|
-
safeUnwrap(this, prototype, "observe");
|
|
3208
|
-
safeUnwrap(this, prototype, "agent");
|
|
3209
3180
|
if (prototype.actHandler) {
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
}
|
|
3213
|
-
if (prototype.extractHandler) safeUnwrap(this, prototype.extractHandler, "extract");
|
|
3214
|
-
if (prototype.observeHandler) safeUnwrap(this, prototype.observeHandler, "observe");
|
|
3215
|
-
if (prototype.llmClient) safeUnwrap(this, prototype.llmClient, "createChatCompletion");
|
|
3216
|
-
if (prototype.apiClient) {
|
|
3217
|
-
safeUnwrap(this, prototype.apiClient, "act");
|
|
3218
|
-
safeUnwrap(this, prototype.apiClient, "extract");
|
|
3219
|
-
safeUnwrap(this, prototype.apiClient, "observe");
|
|
3220
|
-
safeUnwrap(this, prototype.apiClient, "agentExecute");
|
|
3181
|
+
this._unwrap(prototype.actHandler, "act");
|
|
3182
|
+
this._unwrap(prototype.actHandler, "actFromObserveResult");
|
|
3221
3183
|
}
|
|
3184
|
+
if (prototype.extractHandler) this._unwrap(prototype.extractHandler, "extract");
|
|
3185
|
+
if (prototype.observeHandler) this._unwrap(prototype.observeHandler, "observe");
|
|
3186
|
+
if (prototype.llmClient) this._unwrap(prototype.llmClient, "createChatCompletion");
|
|
3222
3187
|
}
|
|
3223
3188
|
return moduleExports;
|
|
3224
3189
|
}
|
|
@@ -3250,9 +3215,9 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3250
3215
|
const otelTraceId = parentSpan.spanContext().traceId;
|
|
3251
3216
|
const traceId = require_utils.otelTraceIdToUUID(otelTraceId);
|
|
3252
3217
|
const result = await original.bind(this).apply(this);
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3218
|
+
instrumentation._wrap(this, "act", instrumentation.patchStagehandGlobalMethod("act", sessionId, parentSpan));
|
|
3219
|
+
instrumentation._wrap(this, "extract", instrumentation.patchStagehandGlobalMethod("extract", sessionId, parentSpan));
|
|
3220
|
+
instrumentation._wrap(this, "observe", instrumentation.patchStagehandGlobalMethod("observe", sessionId, parentSpan));
|
|
3256
3221
|
if (this.actHandler) instrumentation.patchActHandler(this.actHandler);
|
|
3257
3222
|
if (this.extractHandler) instrumentation.patchExtractHandler(this.extractHandler);
|
|
3258
3223
|
if (this.observeHandler) instrumentation.patchObserveHandler(this.observeHandler);
|
|
@@ -3261,10 +3226,9 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3261
3226
|
provider: this.llmClient.type,
|
|
3262
3227
|
model: this.llmClient.modelName
|
|
3263
3228
|
});
|
|
3264
|
-
|
|
3229
|
+
instrumentation._wrap(this.llmClient, "createChatCompletion", instrumentation.patchStagehandLLMClientCreateChatCompletion());
|
|
3265
3230
|
}
|
|
3266
|
-
|
|
3267
|
-
safeWrap(instrumentation, this, "agent", instrumentation.patchStagehandAgentInitializer(sessionId, parentSpan));
|
|
3231
|
+
instrumentation._wrap(this, "agent", instrumentation.patchStagehandAgentInitializer(sessionId, parentSpan));
|
|
3268
3232
|
if (instrumentation._client) await instrumentation.setupSessionRecording(this, sessionId, traceId);
|
|
3269
3233
|
if (this.context && this.context.pages) for (const page of this.context.pages()) instrumentation.patchStagehandPage(page, parentSpan);
|
|
3270
3234
|
if (this.context && this.context.on) this.context.on("page", (page) => {
|
|
@@ -3399,8 +3363,8 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3399
3363
|
};
|
|
3400
3364
|
}
|
|
3401
3365
|
patchActHandler(actHandler) {
|
|
3402
|
-
|
|
3403
|
-
|
|
3366
|
+
this._wrap(actHandler, "act", this.patchActHandlerAct());
|
|
3367
|
+
this._wrap(actHandler, "actFromObserveResult", this.patchActHandlerActFromObserveResult());
|
|
3404
3368
|
}
|
|
3405
3369
|
patchActHandlerAct() {
|
|
3406
3370
|
return (original) => async function act(...args) {
|
|
@@ -3429,7 +3393,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3429
3393
|
};
|
|
3430
3394
|
}
|
|
3431
3395
|
patchExtractHandler(extractHandler) {
|
|
3432
|
-
|
|
3396
|
+
this._wrap(extractHandler, "extract", this.patchExtractHandlerExtract());
|
|
3433
3397
|
}
|
|
3434
3398
|
patchExtractHandlerExtract() {
|
|
3435
3399
|
return (original) => async function extract(...args) {
|
|
@@ -3453,7 +3417,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3453
3417
|
};
|
|
3454
3418
|
}
|
|
3455
3419
|
patchObserveHandler(observeHandler) {
|
|
3456
|
-
|
|
3420
|
+
this._wrap(observeHandler, "observe", this.patchObserveHandlerObserve());
|
|
3457
3421
|
}
|
|
3458
3422
|
patchObserveHandlerObserve() {
|
|
3459
3423
|
return (original) => async function observe$1(...args) {
|
|
@@ -3481,7 +3445,7 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3481
3445
|
};
|
|
3482
3446
|
}
|
|
3483
3447
|
patchStagehandAgent(agent, sessionId, parentSpan) {
|
|
3484
|
-
|
|
3448
|
+
this._wrap(agent, "execute", this.patchStagehandAgentExecute(sessionId, parentSpan));
|
|
3485
3449
|
this.wrapAgentMethod(agent, "captureScreenshot", parentSpan, {
|
|
3486
3450
|
spanType: "TOOL",
|
|
3487
3451
|
ignoreOutput: true
|
|
@@ -3548,7 +3512,8 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3548
3512
|
};
|
|
3549
3513
|
}
|
|
3550
3514
|
wrapAgentMethod(agent, methodName, parentSpan, options) {
|
|
3551
|
-
|
|
3515
|
+
if (typeof agent[methodName] !== "function") return;
|
|
3516
|
+
this._wrap(agent, methodName, (original) => async function method(...args) {
|
|
3552
3517
|
const currentSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
3553
3518
|
return await Laminar.withSpan(currentSpan ?? parentSpan, async () => await observe({
|
|
3554
3519
|
name: `stagehand.agent.${methodName}`,
|
|
@@ -3570,77 +3535,13 @@ var StagehandInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
3570
3535
|
"keyPress",
|
|
3571
3536
|
"keyDown",
|
|
3572
3537
|
"keyUp"
|
|
3573
|
-
])
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
});
|
|
3577
|
-
}
|
|
3578
|
-
/**
|
|
3579
|
-
* In BROWSERBASE remote mode Stagehand's top-level `act`/`extract`/`observe`/
|
|
3580
|
-
* agent `execute` are routed through an internal `StagehandAPIClient` which
|
|
3581
|
-
* makes HTTP calls to the Stagehand Cloud API. The local `llmClient` and the
|
|
3582
|
-
* local `actHandler`/`extractHandler`/`observeHandler` are therefore never
|
|
3583
|
-
* invoked and our existing wrappers do not fire.
|
|
3584
|
-
*
|
|
3585
|
-
* Wrap the apiClient methods directly so we still emit child spans for the
|
|
3586
|
-
* LLM-backed calls and surface token usage from the response where available.
|
|
3587
|
-
*/
|
|
3588
|
-
patchStagehandApiClient(apiClient, _sessionId, parentSpan, stagehandInstance) {
|
|
3589
|
-
const instrumentation = this;
|
|
3590
|
-
const baseProvider = stagehandInstance?.llmClient?.type;
|
|
3591
|
-
const baseModel = stagehandInstance?.llmClient?.modelName;
|
|
3592
|
-
const wrapApiMethod = (methodName) => {
|
|
3593
|
-
safeWrap(instrumentation, apiClient, methodName, (original) => async function method(...args) {
|
|
3538
|
+
]) {
|
|
3539
|
+
if (typeof page[methodName] !== "function") continue;
|
|
3540
|
+
this._wrap(page, methodName, (original) => async function method(...args) {
|
|
3594
3541
|
const currentSpan = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
3595
|
-
|
|
3596
|
-
const spanName = methodName === "agentExecute" ? "stagehand.apiClient.agentExecute" : `stagehand.apiClient.${methodName}`;
|
|
3597
|
-
return await Laminar.withSpan(currentSpan ?? parentSpan, async () => await observe({
|
|
3598
|
-
name: spanName,
|
|
3599
|
-
input,
|
|
3600
|
-
spanType: "LLM",
|
|
3601
|
-
ignoreInput: true,
|
|
3602
|
-
ignoreOutput: true
|
|
3603
|
-
}, async () => {
|
|
3604
|
-
const span = _opentelemetry_api.trace.getSpan(LaminarContextManager.getContext()) ?? _opentelemetry_api.trace.getActiveSpan();
|
|
3605
|
-
span?.setAttribute(require_utils.TRACE_HAS_BROWSER_SESSION, true);
|
|
3606
|
-
if (baseProvider) span?.setAttribute("gen_ai.system", baseProvider);
|
|
3607
|
-
if (baseModel) span?.setAttribute("gen_ai.request.model", baseModel);
|
|
3608
|
-
try {
|
|
3609
|
-
const firstArg = args[0];
|
|
3610
|
-
const instruction = typeof firstArg === "string" ? firstArg : firstArg?.input ?? firstArg?.instruction;
|
|
3611
|
-
if (typeof instruction === "string" && instruction.length > 0) span?.setAttributes({
|
|
3612
|
-
"gen_ai.prompt.0.role": "user",
|
|
3613
|
-
"gen_ai.prompt.0.content": instruction
|
|
3614
|
-
});
|
|
3615
|
-
} catch {}
|
|
3616
|
-
const result = await original.bind(this).apply(this, args);
|
|
3617
|
-
try {
|
|
3618
|
-
const usage = result?.usage;
|
|
3619
|
-
if (usage) {
|
|
3620
|
-
const inputTokens = usage.input_tokens ?? usage.prompt_tokens ?? 0;
|
|
3621
|
-
const outputTokens = usage.output_tokens ?? usage.completion_tokens ?? 0;
|
|
3622
|
-
span?.setAttributes({
|
|
3623
|
-
"gen_ai.usage.input_tokens": inputTokens,
|
|
3624
|
-
"gen_ai.usage.output_tokens": outputTokens,
|
|
3625
|
-
"llm.usage.total_tokens": inputTokens + outputTokens
|
|
3626
|
-
});
|
|
3627
|
-
}
|
|
3628
|
-
if (methodName === "agentExecute") {
|
|
3629
|
-
const message = result?.message;
|
|
3630
|
-
if (message) span?.setAttributes({
|
|
3631
|
-
"gen_ai.completion.0.role": "assistant",
|
|
3632
|
-
"gen_ai.completion.0.content": typeof message === "string" ? message : JSON.stringify(message)
|
|
3633
|
-
});
|
|
3634
|
-
}
|
|
3635
|
-
} catch {}
|
|
3636
|
-
return result;
|
|
3637
|
-
}));
|
|
3542
|
+
return await Laminar.withSpan(currentSpan ?? parentSpan, async () => await observe({ name: `stagehand.page.${methodName}` }, async (argVals) => await original.bind(this).apply(this, argVals), args));
|
|
3638
3543
|
});
|
|
3639
|
-
}
|
|
3640
|
-
wrapApiMethod("act");
|
|
3641
|
-
wrapApiMethod("extract");
|
|
3642
|
-
wrapApiMethod("observe");
|
|
3643
|
-
wrapApiMethod("agentExecute");
|
|
3544
|
+
}
|
|
3644
3545
|
}
|
|
3645
3546
|
};
|
|
3646
3547
|
//#endregion
|
|
@@ -5879,6 +5780,12 @@ function observeExperimentalDecorator(config) {
|
|
|
5879
5780
|
};
|
|
5880
5781
|
}
|
|
5881
5782
|
//#endregion
|
|
5783
|
+
Object.defineProperty(exports, "ASSOCIATION_PROPERTIES_KEY", {
|
|
5784
|
+
enumerable: true,
|
|
5785
|
+
get: function() {
|
|
5786
|
+
return ASSOCIATION_PROPERTIES_KEY;
|
|
5787
|
+
}
|
|
5788
|
+
});
|
|
5882
5789
|
Object.defineProperty(exports, "Laminar", {
|
|
5883
5790
|
enumerable: true,
|
|
5884
5791
|
get: function() {
|
|
@@ -5976,4 +5883,4 @@ Object.defineProperty(exports, "withTracingLevel", {
|
|
|
5976
5883
|
}
|
|
5977
5884
|
});
|
|
5978
5885
|
|
|
5979
|
-
//# sourceMappingURL=decorators-
|
|
5886
|
+
//# sourceMappingURL=decorators-CKzMiD2H.cjs.map
|