@browserbasehq/stagehand 3.0.6-alpha-a8a7c537fba30d8ce1441d9e454616086ae61fae → 3.0.6-alpha-fdbb58ce7ad8e63a4048089d0b548d76b1803782
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/index.d.ts +14 -0
- package/dist/index.js +1219 -238
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ var __spreadValues = (a, b) => {
|
|
|
26
26
|
return a;
|
|
27
27
|
};
|
|
28
28
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
29
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
29
30
|
var __objRest = (source, exclude) => {
|
|
30
31
|
var target = {};
|
|
31
32
|
for (var prop in source)
|
|
@@ -65,8 +66,45 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
65
66
|
mod
|
|
66
67
|
));
|
|
67
68
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
69
|
+
var __decoratorStart = (base) => {
|
|
70
|
+
var _a4;
|
|
71
|
+
return [, , , __create((_a4 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a4 : null)];
|
|
72
|
+
};
|
|
73
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
74
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
75
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
76
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
77
|
+
var __runInitializers = (array, flags, self2, value) => {
|
|
78
|
+
for (var i2 = 0, fns = array[flags >> 1], n = fns && fns.length; i2 < n; i2++) flags & 1 ? fns[i2].call(self2) : value = fns[i2].call(self2, value);
|
|
79
|
+
return value;
|
|
80
|
+
};
|
|
81
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
82
|
+
var fn, it, done, ctx, access, k = flags & 7, s2 = !!(flags & 8), p = !!(flags & 16);
|
|
83
|
+
var j = k > 3 ? array.length + 1 : k ? s2 ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
84
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
85
|
+
var desc = k && (!p && !s2 && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
86
|
+
return __privateGet(this, extra);
|
|
87
|
+
}, set [name](x2) {
|
|
88
|
+
return __privateSet(this, extra, x2);
|
|
89
|
+
} }, name));
|
|
90
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
91
|
+
for (var i2 = decorators.length - 1; i2 >= 0; i2--) {
|
|
92
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
93
|
+
if (k) {
|
|
94
|
+
ctx.static = s2, ctx.private = p, access = ctx.access = { has: p ? (x2) => __privateIn(target, x2) : (x2) => name in x2 };
|
|
95
|
+
if (k ^ 3) access.get = p ? (x2) => (k ^ 1 ? __privateGet : __privateMethod)(x2, target, k ^ 4 ? extra : desc.get) : (x2) => x2[name];
|
|
96
|
+
if (k > 2) access.set = p ? (x2, y) => __privateSet(x2, target, y, k ^ 4 ? extra : desc.set) : (x2, y) => x2[name] = y;
|
|
97
|
+
}
|
|
98
|
+
it = (0, decorators[i2])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
99
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
100
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
101
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
102
|
+
}
|
|
103
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
104
|
+
};
|
|
68
105
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
69
106
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
107
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
70
108
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
71
109
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
72
110
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
@@ -141,7 +179,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
141
179
|
var STAGEHAND_VERSION;
|
|
142
180
|
var init_version = __esm({
|
|
143
181
|
"lib/version.ts"() {
|
|
144
|
-
STAGEHAND_VERSION = "3.0.6-alpha-
|
|
182
|
+
STAGEHAND_VERSION = "3.0.6-alpha-fdbb58ce7ad8e63a4048089d0b548d76b1803782";
|
|
145
183
|
}
|
|
146
184
|
});
|
|
147
185
|
|
|
@@ -1260,8 +1298,8 @@ function normalizeXPath(x2) {
|
|
|
1260
1298
|
if (s2.length > 1 && s2.endsWith("/")) s2 = s2.slice(0, -1);
|
|
1261
1299
|
return s2;
|
|
1262
1300
|
}
|
|
1263
|
-
function parseXPathToSteps(
|
|
1264
|
-
const s2 =
|
|
1301
|
+
function parseXPathToSteps(path8) {
|
|
1302
|
+
const s2 = path8.trim();
|
|
1265
1303
|
let i2 = 0;
|
|
1266
1304
|
const steps = [];
|
|
1267
1305
|
while (i2 < s2.length) {
|
|
@@ -3422,8 +3460,8 @@ var init_frameLocator = __esm({
|
|
|
3422
3460
|
});
|
|
3423
3461
|
|
|
3424
3462
|
// lib/v3/understudy/deepLocator.ts
|
|
3425
|
-
function parseXPath(
|
|
3426
|
-
const s2 =
|
|
3463
|
+
function parseXPath(path8) {
|
|
3464
|
+
const s2 = path8.trim();
|
|
3427
3465
|
let i2 = 0;
|
|
3428
3466
|
const steps = [];
|
|
3429
3467
|
while (i2 < s2.length) {
|
|
@@ -3454,10 +3492,10 @@ function buildXPathFromSteps2(steps) {
|
|
|
3454
3492
|
}
|
|
3455
3493
|
function deepLocatorThroughIframes(page, root, xpathOrSelector) {
|
|
3456
3494
|
return __async(this, null, function* () {
|
|
3457
|
-
let
|
|
3458
|
-
if (
|
|
3459
|
-
if (!
|
|
3460
|
-
const steps = parseXPath(
|
|
3495
|
+
let path8 = xpathOrSelector.trim();
|
|
3496
|
+
if (path8.startsWith("xpath=")) path8 = path8.slice("xpath=".length).trim();
|
|
3497
|
+
if (!path8.startsWith("/")) path8 = "/" + path8;
|
|
3498
|
+
const steps = parseXPath(path8);
|
|
3461
3499
|
let fl;
|
|
3462
3500
|
let buf = [];
|
|
3463
3501
|
const flushIntoFrameLocator = () => {
|
|
@@ -3652,6 +3690,780 @@ var init_deepLocator = __esm({
|
|
|
3652
3690
|
}
|
|
3653
3691
|
});
|
|
3654
3692
|
|
|
3693
|
+
// lib/v3/flowLogger.ts
|
|
3694
|
+
function truncateCdpIds(value) {
|
|
3695
|
+
return value.replace(
|
|
3696
|
+
/([iI]d:?"?)([0-9A-F]{32})(?="?[,})\s]|$)/g,
|
|
3697
|
+
(_, pre, id) => `${pre}${id.slice(0, 4)}\u2026${id.slice(-4)}`
|
|
3698
|
+
);
|
|
3699
|
+
}
|
|
3700
|
+
function truncateLine(value, maxLen) {
|
|
3701
|
+
const collapsed = value.replace(/\s+/g, " ");
|
|
3702
|
+
if (collapsed.length <= maxLen) return collapsed;
|
|
3703
|
+
const endLen = Math.floor(maxLen * 0.3);
|
|
3704
|
+
const startLen = maxLen - endLen - 1;
|
|
3705
|
+
return `${collapsed.slice(0, startLen)}\u2026${collapsed.slice(-endLen)}`;
|
|
3706
|
+
}
|
|
3707
|
+
function formatValue(value) {
|
|
3708
|
+
if (typeof value === "string") return `'${value}'`;
|
|
3709
|
+
if (value == null || typeof value !== "object") return String(value);
|
|
3710
|
+
try {
|
|
3711
|
+
return JSON.stringify(value);
|
|
3712
|
+
} catch (e2) {
|
|
3713
|
+
return "[unserializable]";
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
function formatArgs(args) {
|
|
3717
|
+
if (args === void 0) return "";
|
|
3718
|
+
return (Array.isArray(args) ? args : [args]).filter((e2) => e2 !== void 0).map(formatValue).filter((e2) => e2.length > 0).join(", ");
|
|
3719
|
+
}
|
|
3720
|
+
function formatTag(label, id, icon) {
|
|
3721
|
+
return id ? `[${icon} #${shortId(id)}${label ? " " + label : ""}]` : "\u2911";
|
|
3722
|
+
}
|
|
3723
|
+
function formatTimestamp() {
|
|
3724
|
+
const d = /* @__PURE__ */ new Date();
|
|
3725
|
+
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
3726
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.${pad(d.getMilliseconds(), 3)}${pad(nonce++ % 100)}`;
|
|
3727
|
+
}
|
|
3728
|
+
function sanitizeOptions(options) {
|
|
3729
|
+
const sanitize = (obj) => {
|
|
3730
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
3731
|
+
if (Array.isArray(obj)) return obj.map(sanitize);
|
|
3732
|
+
const result = {};
|
|
3733
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3734
|
+
result[key] = SENSITIVE_KEYS.test(key) ? "******" : sanitize(value);
|
|
3735
|
+
}
|
|
3736
|
+
return result;
|
|
3737
|
+
};
|
|
3738
|
+
return sanitize(__spreadValues({}, options));
|
|
3739
|
+
}
|
|
3740
|
+
function removeQuotes(str) {
|
|
3741
|
+
return str.replace(/([^\\])["']/g, "$1").replace(/^["']|["']$/g, "").trim();
|
|
3742
|
+
}
|
|
3743
|
+
function prettifyEvent(event) {
|
|
3744
|
+
var _a4, _b, _c, _d2, _e, _f, _g, _h;
|
|
3745
|
+
const parts = [];
|
|
3746
|
+
if (event.category === "AgentTask") {
|
|
3747
|
+
parts.push(formatTag("", event.taskId, "\u{1F170}"));
|
|
3748
|
+
} else if (event.category === "StagehandStep") {
|
|
3749
|
+
parts.push(formatTag("", event.taskId, "\u{1F170}"));
|
|
3750
|
+
parts.push(formatTag(event.stepLabel, event.stepId, "\u{1F182}"));
|
|
3751
|
+
} else if (event.category === "UnderstudyAction") {
|
|
3752
|
+
parts.push(formatTag("", event.taskId, "\u{1F170}"));
|
|
3753
|
+
parts.push(formatTag(event.stepLabel, event.stepId, "\u{1F182}"));
|
|
3754
|
+
parts.push(formatTag(event.actionLabel, event.actionId, "\u{1F184}"));
|
|
3755
|
+
} else if (event.category === "CDP") {
|
|
3756
|
+
parts.push(formatTag("", event.taskId, "\u{1F170}"));
|
|
3757
|
+
parts.push(formatTag(event.stepLabel, event.stepId, "\u{1F182}"));
|
|
3758
|
+
parts.push(formatTag(event.actionLabel, event.actionId, "\u{1F184}"));
|
|
3759
|
+
parts.push(formatTag("CDP", event.targetId, "\u{1F172}"));
|
|
3760
|
+
} else if (event.category === "LLM") {
|
|
3761
|
+
parts.push(formatTag("", event.taskId, "\u{1F170}"));
|
|
3762
|
+
parts.push(formatTag(event.stepLabel, event.stepId, "\u{1F182}"));
|
|
3763
|
+
parts.push(formatTag("LLM", event.requestId, "\u{1F9E0}"));
|
|
3764
|
+
}
|
|
3765
|
+
let details = "";
|
|
3766
|
+
const argsStr = event.params ? formatArgs(event.params) : "";
|
|
3767
|
+
if (event.category === "AgentTask") {
|
|
3768
|
+
if (event.event === "started") {
|
|
3769
|
+
details = `\u25B7 ${event.method}(${argsStr})`;
|
|
3770
|
+
} else if (event.event === "completed") {
|
|
3771
|
+
const m2 = event.metrics;
|
|
3772
|
+
const durationSec = (m2 == null ? void 0 : m2.durationMs) ? (m2.durationMs / 1e3).toFixed(1) : "?";
|
|
3773
|
+
const llmStats = `${(_a4 = m2 == null ? void 0 : m2.llmRequests) != null ? _a4 : 0} LLM calls \uA71B${(_b = m2 == null ? void 0 : m2.inputTokens) != null ? _b : 0} \uA71C${(_c = m2 == null ? void 0 : m2.outputTokens) != null ? _c : 0} tokens`;
|
|
3774
|
+
const cdpStats = `${(_d2 = m2 == null ? void 0 : m2.cdpEvents) != null ? _d2 : 0} CDP msgs`;
|
|
3775
|
+
details = `\u2713 Agent.execute() DONE in ${durationSec}s | ${llmStats} | ${cdpStats}`;
|
|
3776
|
+
}
|
|
3777
|
+
} else if (event.category === "StagehandStep") {
|
|
3778
|
+
if (event.event === "started") {
|
|
3779
|
+
details = `\u25B7 ${event.method}(${argsStr})`;
|
|
3780
|
+
} else if (event.event === "completed") {
|
|
3781
|
+
const durationSec = ((_e = event.metrics) == null ? void 0 : _e.durationMs) ? (event.metrics.durationMs / 1e3).toFixed(2) : "?";
|
|
3782
|
+
details = `\u2713 ${event.stepLabel || "STEP"} completed in ${durationSec}s`;
|
|
3783
|
+
}
|
|
3784
|
+
} else if (event.category === "UnderstudyAction") {
|
|
3785
|
+
if (event.event === "started") {
|
|
3786
|
+
details = `\u25B7 ${event.method}(${argsStr})`;
|
|
3787
|
+
} else if (event.event === "completed") {
|
|
3788
|
+
const durationSec = ((_f = event.metrics) == null ? void 0 : _f.durationMs) ? (event.metrics.durationMs / 1e3).toFixed(2) : "?";
|
|
3789
|
+
details = `\u2713 ${event.actionLabel || "ACTION"} completed in ${durationSec}s`;
|
|
3790
|
+
}
|
|
3791
|
+
} else if (event.category === "CDP") {
|
|
3792
|
+
const icon = event.event === "call" ? "\u23F5" : "\u23F4";
|
|
3793
|
+
details = `${icon} ${event.method}(${argsStr})`;
|
|
3794
|
+
} else if (event.category === "LLM") {
|
|
3795
|
+
if (event.event === "request") {
|
|
3796
|
+
const promptStr = event.prompt ? " " + String(event.prompt) : "";
|
|
3797
|
+
details = `${event.model} \u23F4${promptStr}`;
|
|
3798
|
+
} else if (event.event === "response") {
|
|
3799
|
+
const hasTokens = event.inputTokens !== void 0 || event.outputTokens !== void 0;
|
|
3800
|
+
const tokenStr = hasTokens ? ` \uA71B${(_g = event.inputTokens) != null ? _g : 0} \uA71C${(_h = event.outputTokens) != null ? _h : 0} |` : "";
|
|
3801
|
+
const outputStr = event.output ? " " + String(event.output) : "";
|
|
3802
|
+
details = `${event.model} \u21B3${tokenStr}${outputStr}`;
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
if (!details) return null;
|
|
3806
|
+
const fullLine = `${formatTimestamp()} ${parts.join(" ")} ${details}`;
|
|
3807
|
+
const cleaned = removeQuotes(fullLine);
|
|
3808
|
+
const processed = event.category === "CDP" ? truncateCdpIds(cleaned) : cleaned;
|
|
3809
|
+
return truncateLine(processed, MAX_LINE_LENGTH);
|
|
3810
|
+
}
|
|
3811
|
+
function shouldFilterCdpEvent(event) {
|
|
3812
|
+
var _a4;
|
|
3813
|
+
if (event.category !== "CDP") return false;
|
|
3814
|
+
if (((_a4 = event.method) == null ? void 0 : _a4.endsWith(".enable")) || event.method === "enable")
|
|
3815
|
+
return true;
|
|
3816
|
+
return event.event === "message" && NOISY_CDP_EVENTS.has(event.method);
|
|
3817
|
+
}
|
|
3818
|
+
function createJsonlStream(ctx) {
|
|
3819
|
+
return new import_node_stream.Writable({
|
|
3820
|
+
objectMode: true,
|
|
3821
|
+
write(chunk, _, cb) {
|
|
3822
|
+
if (ctx.initialized && isWritable(ctx.fileStreams.jsonl)) {
|
|
3823
|
+
ctx.fileStreams.jsonl.write(chunk, cb);
|
|
3824
|
+
} else cb();
|
|
3825
|
+
}
|
|
3826
|
+
});
|
|
3827
|
+
}
|
|
3828
|
+
function createPrettyStream(ctx, category, streamKey) {
|
|
3829
|
+
return new import_node_stream.Writable({
|
|
3830
|
+
objectMode: true,
|
|
3831
|
+
write(chunk, _, cb) {
|
|
3832
|
+
const stream = ctx.fileStreams[streamKey];
|
|
3833
|
+
if (!ctx.initialized || !isWritable(stream)) return cb();
|
|
3834
|
+
try {
|
|
3835
|
+
const event = JSON.parse(chunk);
|
|
3836
|
+
if (event.category !== category || shouldFilterCdpEvent(event))
|
|
3837
|
+
return cb();
|
|
3838
|
+
const line = prettifyEvent(event);
|
|
3839
|
+
if (line) stream.write(line + "\n", cb);
|
|
3840
|
+
else cb();
|
|
3841
|
+
} catch (e2) {
|
|
3842
|
+
cb();
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3847
|
+
function getConfigDir() {
|
|
3848
|
+
return CONFIG_DIR ? import_node_path.default.resolve(CONFIG_DIR) : "";
|
|
3849
|
+
}
|
|
3850
|
+
function extractFromContent(content, result) {
|
|
3851
|
+
var _a4, _b, _c, _d2;
|
|
3852
|
+
for (const part of content) {
|
|
3853
|
+
const p = part;
|
|
3854
|
+
if (!result.text && p.text) {
|
|
3855
|
+
result.text = p.type === "text" || !p.type ? p.text : void 0;
|
|
3856
|
+
}
|
|
3857
|
+
if (p.type === "image" || p.type === "image_url") {
|
|
3858
|
+
const url = (_a4 = p.image_url) == null ? void 0 : _a4.url;
|
|
3859
|
+
if (url == null ? void 0 : url.startsWith("data:"))
|
|
3860
|
+
result.extras.push(`${dataToKb(url)}kb image`);
|
|
3861
|
+
else if ((_b = p.source) == null ? void 0 : _b.data)
|
|
3862
|
+
result.extras.push(`${dataToKb(p.source.data)}kb image`);
|
|
3863
|
+
else result.extras.push("image");
|
|
3864
|
+
} else if ((_c = p.source) == null ? void 0 : _c.data) {
|
|
3865
|
+
result.extras.push(`${dataToKb(p.source.data)}kb image`);
|
|
3866
|
+
} else if ((_d2 = p.inlineData) == null ? void 0 : _d2.data) {
|
|
3867
|
+
result.extras.push(`${dataToKb(p.inlineData.data)}kb image`);
|
|
3868
|
+
}
|
|
3869
|
+
if (p.type === "tool_result" && Array.isArray(p.content)) {
|
|
3870
|
+
extractFromContent(p.content, result);
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
function buildPreview(text, extras, maxLen) {
|
|
3875
|
+
if (!text && extras.length === 0) return void 0;
|
|
3876
|
+
let result = text || "";
|
|
3877
|
+
if (maxLen && result.length > maxLen)
|
|
3878
|
+
result = result.slice(0, maxLen) + "...";
|
|
3879
|
+
if (extras.length > 0) {
|
|
3880
|
+
const extrasStr = extras.map((e2) => `+{${e2}}`).join(" ");
|
|
3881
|
+
result = result ? `${result} ${extrasStr}` : extrasStr;
|
|
3882
|
+
}
|
|
3883
|
+
return result || void 0;
|
|
3884
|
+
}
|
|
3885
|
+
function formatLlmPromptPreview(messages, options) {
|
|
3886
|
+
try {
|
|
3887
|
+
const lastUserMsg = messages.filter((m2) => m2.role === "user").pop();
|
|
3888
|
+
if (!lastUserMsg) return void 0;
|
|
3889
|
+
const result = {
|
|
3890
|
+
text: void 0,
|
|
3891
|
+
extras: []
|
|
3892
|
+
};
|
|
3893
|
+
if (typeof lastUserMsg.content === "string") {
|
|
3894
|
+
result.text = lastUserMsg.content;
|
|
3895
|
+
} else if (Array.isArray(lastUserMsg.content)) {
|
|
3896
|
+
extractFromContent(lastUserMsg.content, result);
|
|
3897
|
+
} else {
|
|
3898
|
+
return void 0;
|
|
3899
|
+
}
|
|
3900
|
+
if (result.text) {
|
|
3901
|
+
result.text = result.text.replace(/^[Ii]nstruction: /, "");
|
|
3902
|
+
}
|
|
3903
|
+
if (options == null ? void 0 : options.hasSchema) result.extras.push("schema");
|
|
3904
|
+
if (options == null ? void 0 : options.toolCount) result.extras.push(`${options.toolCount} tools`);
|
|
3905
|
+
return buildPreview(result.text, result.extras);
|
|
3906
|
+
} catch (e2) {
|
|
3907
|
+
return void 0;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
function formatCuaPromptPreview(messages, maxLen = 100) {
|
|
3911
|
+
try {
|
|
3912
|
+
const lastMsg = messages.filter((m2) => {
|
|
3913
|
+
const msg = m2;
|
|
3914
|
+
return msg.role === "user" || msg.type === "tool_result";
|
|
3915
|
+
}).pop();
|
|
3916
|
+
if (!lastMsg) return void 0;
|
|
3917
|
+
const result = {
|
|
3918
|
+
text: void 0,
|
|
3919
|
+
extras: []
|
|
3920
|
+
};
|
|
3921
|
+
if (typeof lastMsg.content === "string") {
|
|
3922
|
+
result.text = lastMsg.content;
|
|
3923
|
+
} else if (typeof lastMsg.text === "string") {
|
|
3924
|
+
result.text = lastMsg.text;
|
|
3925
|
+
} else if (Array.isArray(lastMsg.parts)) {
|
|
3926
|
+
extractFromContent(lastMsg.parts, result);
|
|
3927
|
+
} else if (Array.isArray(lastMsg.content)) {
|
|
3928
|
+
extractFromContent(lastMsg.content, result);
|
|
3929
|
+
}
|
|
3930
|
+
return buildPreview(result.text, result.extras, maxLen);
|
|
3931
|
+
} catch (e2) {
|
|
3932
|
+
return void 0;
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
function formatCuaResponsePreview(output, maxLen = 100) {
|
|
3936
|
+
var _a4, _b, _c, _d2;
|
|
3937
|
+
try {
|
|
3938
|
+
const items = (_d2 = (_c = (_b = (_a4 = output == null ? void 0 : output.candidates) == null ? void 0 : _a4[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) != null ? _d2 : Array.isArray(output) ? output : [];
|
|
3939
|
+
const preview = items.map((item) => {
|
|
3940
|
+
var _a5;
|
|
3941
|
+
const i2 = item;
|
|
3942
|
+
if (i2.text) return i2.text.slice(0, 50);
|
|
3943
|
+
if ((_a5 = i2.functionCall) == null ? void 0 : _a5.name) return `fn:${i2.functionCall.name}`;
|
|
3944
|
+
if (i2.type === "tool_use" && i2.name) return `tool_use:${i2.name}`;
|
|
3945
|
+
return i2.type ? `[${i2.type}]` : "[item]";
|
|
3946
|
+
}).join(" ");
|
|
3947
|
+
return preview.slice(0, maxLen);
|
|
3948
|
+
} catch (e2) {
|
|
3949
|
+
return "[error]";
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
function logAction(actionType) {
|
|
3953
|
+
return function(originalMethod) {
|
|
3954
|
+
if (!CONFIG_DIR) {
|
|
3955
|
+
return originalMethod;
|
|
3956
|
+
}
|
|
3957
|
+
return function(...args) {
|
|
3958
|
+
return __async(this, null, function* () {
|
|
3959
|
+
SessionFileLogger.logUnderstudyActionEvent({
|
|
3960
|
+
actionType,
|
|
3961
|
+
args: args.length > 0 ? args : void 0
|
|
3962
|
+
});
|
|
3963
|
+
try {
|
|
3964
|
+
return yield originalMethod.apply(this, args);
|
|
3965
|
+
} finally {
|
|
3966
|
+
SessionFileLogger.logUnderstudyActionCompleted();
|
|
3967
|
+
}
|
|
3968
|
+
});
|
|
3969
|
+
};
|
|
3970
|
+
};
|
|
3971
|
+
}
|
|
3972
|
+
function logStagehandStep(invocation, label) {
|
|
3973
|
+
return function(originalMethod) {
|
|
3974
|
+
if (!CONFIG_DIR) {
|
|
3975
|
+
return originalMethod;
|
|
3976
|
+
}
|
|
3977
|
+
return function(...args) {
|
|
3978
|
+
return __async(this, null, function* () {
|
|
3979
|
+
SessionFileLogger.logStagehandStepEvent({
|
|
3980
|
+
invocation,
|
|
3981
|
+
args: args.length > 0 ? args : void 0,
|
|
3982
|
+
label
|
|
3983
|
+
});
|
|
3984
|
+
try {
|
|
3985
|
+
return yield originalMethod.apply(this, args);
|
|
3986
|
+
} finally {
|
|
3987
|
+
SessionFileLogger.logStagehandStepCompleted();
|
|
3988
|
+
}
|
|
3989
|
+
});
|
|
3990
|
+
};
|
|
3991
|
+
};
|
|
3992
|
+
}
|
|
3993
|
+
var import_node_async_hooks2, import_node_fs, import_node_stream, import_uuid, import_node_path, import_pino2, MAX_LINE_LENGTH, CONFIG_DIR, NOISY_CDP_EVENTS, loggerContext, dataToKb, shortId, nonce, SENSITIVE_KEYS, isWritable, SessionFileLogger;
|
|
3994
|
+
var init_flowLogger = __esm({
|
|
3995
|
+
"lib/v3/flowLogger.ts"() {
|
|
3996
|
+
import_node_async_hooks2 = require("async_hooks");
|
|
3997
|
+
import_node_fs = __toESM(require("fs"));
|
|
3998
|
+
import_node_stream = require("stream");
|
|
3999
|
+
import_uuid = require("uuid");
|
|
4000
|
+
import_node_path = __toESM(require("path"));
|
|
4001
|
+
import_pino2 = __toESM(require("pino"));
|
|
4002
|
+
MAX_LINE_LENGTH = 160;
|
|
4003
|
+
CONFIG_DIR = process.env.BROWSERBASE_CONFIG_DIR || "";
|
|
4004
|
+
NOISY_CDP_EVENTS = /* @__PURE__ */ new Set([
|
|
4005
|
+
"Target.targetInfoChanged",
|
|
4006
|
+
"Runtime.executionContextCreated",
|
|
4007
|
+
"Runtime.executionContextDestroyed",
|
|
4008
|
+
"Runtime.executionContextsCleared",
|
|
4009
|
+
"Page.lifecycleEvent",
|
|
4010
|
+
"Network.dataReceived",
|
|
4011
|
+
"Network.loadingFinished",
|
|
4012
|
+
"Network.requestWillBeSentExtraInfo",
|
|
4013
|
+
"Network.responseReceivedExtraInfo",
|
|
4014
|
+
"Network.requestWillBeSent",
|
|
4015
|
+
"Network.responseReceived"
|
|
4016
|
+
]);
|
|
4017
|
+
loggerContext = new import_node_async_hooks2.AsyncLocalStorage();
|
|
4018
|
+
dataToKb = (data) => (data.length * 0.75 / 1024).toFixed(1);
|
|
4019
|
+
shortId = (id) => id ? id.slice(-4) : "-";
|
|
4020
|
+
nonce = 0;
|
|
4021
|
+
SENSITIVE_KEYS = /apikey|api_key|key|secret|token|password|passwd|pwd|credential|auth/i;
|
|
4022
|
+
isWritable = (s2) => !!(s2 && !s2.destroyed && s2.writable);
|
|
4023
|
+
SessionFileLogger = class _SessionFileLogger {
|
|
4024
|
+
/**
|
|
4025
|
+
* Initialize a new logging context. Call this at the start of a session.
|
|
4026
|
+
* If BROWSERBASE_CONFIG_DIR is not set, logging is disabled.
|
|
4027
|
+
*/
|
|
4028
|
+
static init(sessionId, v3Options) {
|
|
4029
|
+
const configDir = getConfigDir();
|
|
4030
|
+
if (!configDir) return;
|
|
4031
|
+
const sessionDir = import_node_path.default.join(configDir, "sessions", sessionId);
|
|
4032
|
+
const ctx = {
|
|
4033
|
+
logger: (0, import_pino2.default)({ level: "silent" }),
|
|
4034
|
+
// Placeholder, replaced below
|
|
4035
|
+
metrics: {
|
|
4036
|
+
llmRequests: 0,
|
|
4037
|
+
llmInputTokens: 0,
|
|
4038
|
+
llmOutputTokens: 0,
|
|
4039
|
+
cdpEvents: 0
|
|
4040
|
+
},
|
|
4041
|
+
sessionId,
|
|
4042
|
+
sessionDir,
|
|
4043
|
+
configDir,
|
|
4044
|
+
initPromise: Promise.resolve(),
|
|
4045
|
+
initialized: false,
|
|
4046
|
+
// Span context - mutable, injected into every log via mixin
|
|
4047
|
+
taskId: null,
|
|
4048
|
+
stepId: null,
|
|
4049
|
+
stepLabel: null,
|
|
4050
|
+
actionId: null,
|
|
4051
|
+
actionLabel: null,
|
|
4052
|
+
fileStreams: {
|
|
4053
|
+
agent: null,
|
|
4054
|
+
stagehand: null,
|
|
4055
|
+
understudy: null,
|
|
4056
|
+
cdp: null,
|
|
4057
|
+
llm: null,
|
|
4058
|
+
jsonl: null
|
|
4059
|
+
}
|
|
4060
|
+
};
|
|
4061
|
+
ctx.initPromise = _SessionFileLogger.initAsync(ctx, v3Options);
|
|
4062
|
+
loggerContext.enterWith(ctx);
|
|
4063
|
+
}
|
|
4064
|
+
static initAsync(ctx, v3Options) {
|
|
4065
|
+
return __async(this, null, function* () {
|
|
4066
|
+
try {
|
|
4067
|
+
yield import_node_fs.default.promises.mkdir(ctx.sessionDir, { recursive: true });
|
|
4068
|
+
if (v3Options) {
|
|
4069
|
+
const sanitizedOptions = sanitizeOptions(v3Options);
|
|
4070
|
+
const sessionJsonPath = import_node_path.default.join(ctx.sessionDir, "session.json");
|
|
4071
|
+
yield import_node_fs.default.promises.writeFile(
|
|
4072
|
+
sessionJsonPath,
|
|
4073
|
+
JSON.stringify(sanitizedOptions, null, 2),
|
|
4074
|
+
"utf-8"
|
|
4075
|
+
);
|
|
4076
|
+
}
|
|
4077
|
+
const latestLink = import_node_path.default.join(ctx.configDir, "sessions", "latest");
|
|
4078
|
+
try {
|
|
4079
|
+
try {
|
|
4080
|
+
yield import_node_fs.default.promises.unlink(latestLink);
|
|
4081
|
+
} catch (e2) {
|
|
4082
|
+
}
|
|
4083
|
+
yield import_node_fs.default.promises.symlink(ctx.sessionId, latestLink, "dir");
|
|
4084
|
+
} catch (e2) {
|
|
4085
|
+
}
|
|
4086
|
+
const dir = ctx.sessionDir;
|
|
4087
|
+
ctx.fileStreams.agent = import_node_fs.default.createWriteStream(
|
|
4088
|
+
import_node_path.default.join(dir, "agent_events.log"),
|
|
4089
|
+
{ flags: "a" }
|
|
4090
|
+
);
|
|
4091
|
+
ctx.fileStreams.stagehand = import_node_fs.default.createWriteStream(
|
|
4092
|
+
import_node_path.default.join(dir, "stagehand_events.log"),
|
|
4093
|
+
{ flags: "a" }
|
|
4094
|
+
);
|
|
4095
|
+
ctx.fileStreams.understudy = import_node_fs.default.createWriteStream(
|
|
4096
|
+
import_node_path.default.join(dir, "understudy_events.log"),
|
|
4097
|
+
{ flags: "a" }
|
|
4098
|
+
);
|
|
4099
|
+
ctx.fileStreams.cdp = import_node_fs.default.createWriteStream(
|
|
4100
|
+
import_node_path.default.join(dir, "cdp_events.log"),
|
|
4101
|
+
{ flags: "a" }
|
|
4102
|
+
);
|
|
4103
|
+
ctx.fileStreams.llm = import_node_fs.default.createWriteStream(
|
|
4104
|
+
import_node_path.default.join(dir, "llm_events.log"),
|
|
4105
|
+
{ flags: "a" }
|
|
4106
|
+
);
|
|
4107
|
+
ctx.fileStreams.jsonl = import_node_fs.default.createWriteStream(
|
|
4108
|
+
import_node_path.default.join(dir, "session_events.jsonl"),
|
|
4109
|
+
{ flags: "a" }
|
|
4110
|
+
);
|
|
4111
|
+
ctx.initialized = true;
|
|
4112
|
+
const streams = [
|
|
4113
|
+
{ stream: createJsonlStream(ctx) },
|
|
4114
|
+
{ stream: createPrettyStream(ctx, "AgentTask", "agent") },
|
|
4115
|
+
{ stream: createPrettyStream(ctx, "StagehandStep", "stagehand") },
|
|
4116
|
+
{ stream: createPrettyStream(ctx, "UnderstudyAction", "understudy") },
|
|
4117
|
+
{ stream: createPrettyStream(ctx, "CDP", "cdp") },
|
|
4118
|
+
{ stream: createPrettyStream(ctx, "LLM", "llm") }
|
|
4119
|
+
];
|
|
4120
|
+
ctx.logger = (0, import_pino2.default)(
|
|
4121
|
+
{
|
|
4122
|
+
level: "info",
|
|
4123
|
+
// Mixin adds eventId and current span context to every log
|
|
4124
|
+
mixin() {
|
|
4125
|
+
const store = loggerContext.getStore();
|
|
4126
|
+
return {
|
|
4127
|
+
eventId: (0, import_uuid.v7)(),
|
|
4128
|
+
sessionId: store == null ? void 0 : store.sessionId,
|
|
4129
|
+
taskId: store == null ? void 0 : store.taskId,
|
|
4130
|
+
stepId: store == null ? void 0 : store.stepId,
|
|
4131
|
+
stepLabel: store == null ? void 0 : store.stepLabel,
|
|
4132
|
+
actionId: store == null ? void 0 : store.actionId,
|
|
4133
|
+
actionLabel: store == null ? void 0 : store.actionLabel
|
|
4134
|
+
};
|
|
4135
|
+
}
|
|
4136
|
+
},
|
|
4137
|
+
import_pino2.default.multistream(streams)
|
|
4138
|
+
);
|
|
4139
|
+
} catch (e2) {
|
|
4140
|
+
}
|
|
4141
|
+
});
|
|
4142
|
+
}
|
|
4143
|
+
static close() {
|
|
4144
|
+
return __async(this, null, function* () {
|
|
4145
|
+
const ctx = loggerContext.getStore();
|
|
4146
|
+
if (!ctx) return;
|
|
4147
|
+
yield ctx.initPromise;
|
|
4148
|
+
_SessionFileLogger.logAgentTaskCompleted();
|
|
4149
|
+
yield Promise.all(
|
|
4150
|
+
Object.values(ctx.fileStreams).filter(Boolean).map((s2) => new Promise((r2) => s2.end(r2)))
|
|
4151
|
+
).catch(() => {
|
|
4152
|
+
});
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4155
|
+
static get sessionId() {
|
|
4156
|
+
var _a4, _b;
|
|
4157
|
+
return (_b = (_a4 = loggerContext.getStore()) == null ? void 0 : _a4.sessionId) != null ? _b : null;
|
|
4158
|
+
}
|
|
4159
|
+
static get sessionDir() {
|
|
4160
|
+
var _a4, _b;
|
|
4161
|
+
return (_b = (_a4 = loggerContext.getStore()) == null ? void 0 : _a4.sessionDir) != null ? _b : null;
|
|
4162
|
+
}
|
|
4163
|
+
/**
|
|
4164
|
+
* Get the current logger context object.
|
|
4165
|
+
*/
|
|
4166
|
+
static getContext() {
|
|
4167
|
+
var _a4;
|
|
4168
|
+
return (_a4 = loggerContext.getStore()) != null ? _a4 : null;
|
|
4169
|
+
}
|
|
4170
|
+
// ===========================================================================
|
|
4171
|
+
// Agent Task Events
|
|
4172
|
+
// ===========================================================================
|
|
4173
|
+
/**
|
|
4174
|
+
* Start a new task and log it.
|
|
4175
|
+
*/
|
|
4176
|
+
static logAgentTaskStarted({
|
|
4177
|
+
invocation,
|
|
4178
|
+
args
|
|
4179
|
+
}) {
|
|
4180
|
+
const ctx = loggerContext.getStore();
|
|
4181
|
+
if (!ctx) return;
|
|
4182
|
+
ctx.taskId = (0, import_uuid.v7)();
|
|
4183
|
+
ctx.stepId = null;
|
|
4184
|
+
ctx.stepLabel = null;
|
|
4185
|
+
ctx.actionId = null;
|
|
4186
|
+
ctx.actionLabel = null;
|
|
4187
|
+
ctx.metrics = {
|
|
4188
|
+
taskStartTime: Date.now(),
|
|
4189
|
+
llmRequests: 0,
|
|
4190
|
+
llmInputTokens: 0,
|
|
4191
|
+
llmOutputTokens: 0,
|
|
4192
|
+
cdpEvents: 0
|
|
4193
|
+
};
|
|
4194
|
+
ctx.logger.info({
|
|
4195
|
+
category: "AgentTask",
|
|
4196
|
+
event: "started",
|
|
4197
|
+
method: invocation,
|
|
4198
|
+
params: args
|
|
4199
|
+
});
|
|
4200
|
+
}
|
|
4201
|
+
/**
|
|
4202
|
+
* Log task completion with metrics summary.
|
|
4203
|
+
*/
|
|
4204
|
+
static logAgentTaskCompleted(options) {
|
|
4205
|
+
const ctx = loggerContext.getStore();
|
|
4206
|
+
if (!ctx || !ctx.metrics.taskStartTime) return;
|
|
4207
|
+
const durationMs = Date.now() - ctx.metrics.taskStartTime;
|
|
4208
|
+
const event = {
|
|
4209
|
+
category: "AgentTask",
|
|
4210
|
+
event: "completed",
|
|
4211
|
+
method: "Agent.execute",
|
|
4212
|
+
metrics: {
|
|
4213
|
+
durationMs,
|
|
4214
|
+
llmRequests: ctx.metrics.llmRequests,
|
|
4215
|
+
inputTokens: ctx.metrics.llmInputTokens,
|
|
4216
|
+
outputTokens: ctx.metrics.llmOutputTokens,
|
|
4217
|
+
cdpEvents: ctx.metrics.cdpEvents
|
|
4218
|
+
}
|
|
4219
|
+
};
|
|
4220
|
+
if (options == null ? void 0 : options.cacheHit) {
|
|
4221
|
+
event.msg = "CACHE HIT, NO LLM NEEDED";
|
|
4222
|
+
}
|
|
4223
|
+
ctx.logger.info(event);
|
|
4224
|
+
ctx.taskId = null;
|
|
4225
|
+
ctx.stepId = null;
|
|
4226
|
+
ctx.stepLabel = null;
|
|
4227
|
+
ctx.actionId = null;
|
|
4228
|
+
ctx.actionLabel = null;
|
|
4229
|
+
ctx.metrics.taskStartTime = void 0;
|
|
4230
|
+
}
|
|
4231
|
+
// ===========================================================================
|
|
4232
|
+
// Stagehand Step Events
|
|
4233
|
+
// ===========================================================================
|
|
4234
|
+
static logStagehandStepEvent({
|
|
4235
|
+
invocation,
|
|
4236
|
+
args,
|
|
4237
|
+
label
|
|
4238
|
+
}) {
|
|
4239
|
+
const ctx = loggerContext.getStore();
|
|
4240
|
+
if (!ctx) return (0, import_uuid.v7)();
|
|
4241
|
+
ctx.stepId = (0, import_uuid.v7)();
|
|
4242
|
+
ctx.stepLabel = label.toUpperCase();
|
|
4243
|
+
ctx.actionId = null;
|
|
4244
|
+
ctx.actionLabel = null;
|
|
4245
|
+
ctx.metrics.stepStartTime = Date.now();
|
|
4246
|
+
ctx.logger.info({
|
|
4247
|
+
category: "StagehandStep",
|
|
4248
|
+
event: "started",
|
|
4249
|
+
method: invocation,
|
|
4250
|
+
params: args
|
|
4251
|
+
});
|
|
4252
|
+
return ctx.stepId;
|
|
4253
|
+
}
|
|
4254
|
+
static logStagehandStepCompleted() {
|
|
4255
|
+
const ctx = loggerContext.getStore();
|
|
4256
|
+
if (!ctx || !ctx.stepId) return;
|
|
4257
|
+
const durationMs = ctx.metrics.stepStartTime ? Date.now() - ctx.metrics.stepStartTime : 0;
|
|
4258
|
+
ctx.logger.info({
|
|
4259
|
+
category: "StagehandStep",
|
|
4260
|
+
event: "completed",
|
|
4261
|
+
metrics: { durationMs }
|
|
4262
|
+
});
|
|
4263
|
+
ctx.stepId = null;
|
|
4264
|
+
ctx.stepLabel = null;
|
|
4265
|
+
ctx.actionId = null;
|
|
4266
|
+
ctx.actionLabel = null;
|
|
4267
|
+
ctx.metrics.stepStartTime = void 0;
|
|
4268
|
+
}
|
|
4269
|
+
// ===========================================================================
|
|
4270
|
+
// Understudy Action Events
|
|
4271
|
+
// ===========================================================================
|
|
4272
|
+
static logUnderstudyActionEvent({
|
|
4273
|
+
actionType,
|
|
4274
|
+
target,
|
|
4275
|
+
args
|
|
4276
|
+
}) {
|
|
4277
|
+
const ctx = loggerContext.getStore();
|
|
4278
|
+
if (!ctx) return (0, import_uuid.v7)();
|
|
4279
|
+
ctx.actionId = (0, import_uuid.v7)();
|
|
4280
|
+
ctx.actionLabel = actionType.toUpperCase().replace("UNDERSTUDY.", "").replace("PAGE.", "");
|
|
4281
|
+
ctx.metrics.actionStartTime = Date.now();
|
|
4282
|
+
const params = {};
|
|
4283
|
+
if (target) params.target = target;
|
|
4284
|
+
if (args) params.args = args;
|
|
4285
|
+
ctx.logger.info({
|
|
4286
|
+
category: "UnderstudyAction",
|
|
4287
|
+
event: "started",
|
|
4288
|
+
method: actionType,
|
|
4289
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
4290
|
+
});
|
|
4291
|
+
return ctx.actionId;
|
|
4292
|
+
}
|
|
4293
|
+
static logUnderstudyActionCompleted() {
|
|
4294
|
+
const ctx = loggerContext.getStore();
|
|
4295
|
+
if (!ctx || !ctx.actionId) return;
|
|
4296
|
+
const durationMs = ctx.metrics.actionStartTime ? Date.now() - ctx.metrics.actionStartTime : 0;
|
|
4297
|
+
ctx.logger.info({
|
|
4298
|
+
category: "UnderstudyAction",
|
|
4299
|
+
event: "completed",
|
|
4300
|
+
metrics: { durationMs }
|
|
4301
|
+
});
|
|
4302
|
+
ctx.actionId = null;
|
|
4303
|
+
ctx.actionLabel = null;
|
|
4304
|
+
ctx.metrics.actionStartTime = void 0;
|
|
4305
|
+
}
|
|
4306
|
+
// ===========================================================================
|
|
4307
|
+
// CDP Events
|
|
4308
|
+
// ===========================================================================
|
|
4309
|
+
static logCdpEvent(eventType, {
|
|
4310
|
+
method,
|
|
4311
|
+
params,
|
|
4312
|
+
targetId
|
|
4313
|
+
}, explicitCtx) {
|
|
4314
|
+
const ctx = explicitCtx != null ? explicitCtx : loggerContext.getStore();
|
|
4315
|
+
if (!ctx) return;
|
|
4316
|
+
if (eventType === "call") ctx.metrics.cdpEvents++;
|
|
4317
|
+
ctx.logger.info({
|
|
4318
|
+
category: "CDP",
|
|
4319
|
+
event: eventType,
|
|
4320
|
+
method,
|
|
4321
|
+
params,
|
|
4322
|
+
targetId
|
|
4323
|
+
});
|
|
4324
|
+
}
|
|
4325
|
+
static logCdpCallEvent(data, ctx) {
|
|
4326
|
+
_SessionFileLogger.logCdpEvent("call", data, ctx);
|
|
4327
|
+
}
|
|
4328
|
+
static logCdpMessageEvent(data, ctx) {
|
|
4329
|
+
_SessionFileLogger.logCdpEvent("message", data, ctx);
|
|
4330
|
+
}
|
|
4331
|
+
// ===========================================================================
|
|
4332
|
+
// LLM Events
|
|
4333
|
+
// ===========================================================================
|
|
4334
|
+
static logLlmRequest({
|
|
4335
|
+
requestId,
|
|
4336
|
+
model,
|
|
4337
|
+
prompt
|
|
4338
|
+
}, explicitCtx) {
|
|
4339
|
+
const ctx = explicitCtx != null ? explicitCtx : loggerContext.getStore();
|
|
4340
|
+
if (!ctx) return;
|
|
4341
|
+
ctx.metrics.llmRequests++;
|
|
4342
|
+
ctx.logger.info({
|
|
4343
|
+
category: "LLM",
|
|
4344
|
+
event: "request",
|
|
4345
|
+
requestId,
|
|
4346
|
+
method: "LLM.request",
|
|
4347
|
+
model,
|
|
4348
|
+
prompt
|
|
4349
|
+
});
|
|
4350
|
+
}
|
|
4351
|
+
static logLlmResponse({
|
|
4352
|
+
requestId,
|
|
4353
|
+
model,
|
|
4354
|
+
output,
|
|
4355
|
+
inputTokens,
|
|
4356
|
+
outputTokens
|
|
4357
|
+
}, explicitCtx) {
|
|
4358
|
+
const ctx = explicitCtx != null ? explicitCtx : loggerContext.getStore();
|
|
4359
|
+
if (!ctx) return;
|
|
4360
|
+
ctx.metrics.llmInputTokens += inputTokens != null ? inputTokens : 0;
|
|
4361
|
+
ctx.metrics.llmOutputTokens += outputTokens != null ? outputTokens : 0;
|
|
4362
|
+
ctx.logger.info({
|
|
4363
|
+
category: "LLM",
|
|
4364
|
+
event: "response",
|
|
4365
|
+
requestId,
|
|
4366
|
+
method: "LLM.response",
|
|
4367
|
+
model,
|
|
4368
|
+
output,
|
|
4369
|
+
inputTokens,
|
|
4370
|
+
outputTokens
|
|
4371
|
+
});
|
|
4372
|
+
}
|
|
4373
|
+
// ===========================================================================
|
|
4374
|
+
// LLM Logging Middleware
|
|
4375
|
+
// ===========================================================================
|
|
4376
|
+
/**
|
|
4377
|
+
* Create middleware for wrapping language models with LLM call logging.
|
|
4378
|
+
* Returns a no-op middleware when logging is disabled.
|
|
4379
|
+
*/
|
|
4380
|
+
static createLlmLoggingMiddleware(modelId) {
|
|
4381
|
+
if (!CONFIG_DIR) {
|
|
4382
|
+
return {
|
|
4383
|
+
wrapGenerate: (_0) => __async(null, [_0], function* ({ doGenerate }) {
|
|
4384
|
+
return doGenerate();
|
|
4385
|
+
})
|
|
4386
|
+
};
|
|
4387
|
+
}
|
|
4388
|
+
return {
|
|
4389
|
+
wrapGenerate: (_0) => __async(null, [_0], function* ({ doGenerate, params }) {
|
|
4390
|
+
var _a4, _b, _c, _d2, _e;
|
|
4391
|
+
const ctx = _SessionFileLogger.getContext();
|
|
4392
|
+
if (!ctx) {
|
|
4393
|
+
return doGenerate();
|
|
4394
|
+
}
|
|
4395
|
+
const llmRequestId = (0, import_uuid.v7)();
|
|
4396
|
+
const toolCount = Array.isArray(params.tools) ? params.tools.length : 0;
|
|
4397
|
+
const messages = (_a4 = params.prompt) != null ? _a4 : [];
|
|
4398
|
+
const lastMsg = messages.filter((m2) => m2.role !== "system").pop();
|
|
4399
|
+
const extracted = {
|
|
4400
|
+
text: void 0,
|
|
4401
|
+
extras: []
|
|
4402
|
+
};
|
|
4403
|
+
let rolePrefix = (_b = lastMsg == null ? void 0 : lastMsg.role) != null ? _b : "?";
|
|
4404
|
+
if (lastMsg) {
|
|
4405
|
+
if (typeof lastMsg.content === "string") {
|
|
4406
|
+
extracted.text = lastMsg.content;
|
|
4407
|
+
} else if (Array.isArray(lastMsg.content)) {
|
|
4408
|
+
const toolResult = lastMsg.content.find((p) => p.type === "tool-result");
|
|
4409
|
+
if (toolResult) {
|
|
4410
|
+
rolePrefix = `tool result: ${toolResult.toolName}()`;
|
|
4411
|
+
const out = toolResult.output;
|
|
4412
|
+
if ((out == null ? void 0 : out.type) === "json" && out.value) {
|
|
4413
|
+
extracted.text = JSON.stringify(out.value).slice(0, 150);
|
|
4414
|
+
} else if (Array.isArray(out == null ? void 0 : out.value)) {
|
|
4415
|
+
extractFromContent(out.value, extracted);
|
|
4416
|
+
}
|
|
4417
|
+
} else {
|
|
4418
|
+
extractFromContent(lastMsg.content, extracted);
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
const promptText = extracted.text || "(no text)";
|
|
4423
|
+
const promptPreview = `${rolePrefix}: ${promptText} +{${toolCount} tools}`;
|
|
4424
|
+
_SessionFileLogger.logLlmRequest(
|
|
4425
|
+
{
|
|
4426
|
+
requestId: llmRequestId,
|
|
4427
|
+
model: modelId,
|
|
4428
|
+
operation: "generateText",
|
|
4429
|
+
prompt: promptPreview
|
|
4430
|
+
},
|
|
4431
|
+
ctx
|
|
4432
|
+
);
|
|
4433
|
+
const result = yield doGenerate();
|
|
4434
|
+
const res = result;
|
|
4435
|
+
let outputPreview = res.text || "";
|
|
4436
|
+
if (!outputPreview && res.content) {
|
|
4437
|
+
if (typeof res.content === "string") {
|
|
4438
|
+
outputPreview = res.content;
|
|
4439
|
+
} else if (Array.isArray(res.content)) {
|
|
4440
|
+
outputPreview = res.content.map(
|
|
4441
|
+
(c) => c.text || (c.type === "tool-call" ? `tool call: ${c.toolName}()` : `[${c.type}]`)
|
|
4442
|
+
).join(" ");
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
if (!outputPreview && ((_c = res.toolCalls) == null ? void 0 : _c.length)) {
|
|
4446
|
+
outputPreview = `[${res.toolCalls.length} tool calls]`;
|
|
4447
|
+
}
|
|
4448
|
+
_SessionFileLogger.logLlmResponse(
|
|
4449
|
+
{
|
|
4450
|
+
requestId: llmRequestId,
|
|
4451
|
+
model: modelId,
|
|
4452
|
+
operation: "generateText",
|
|
4453
|
+
output: outputPreview || "[empty]",
|
|
4454
|
+
inputTokens: (_d2 = result.usage) == null ? void 0 : _d2.inputTokens,
|
|
4455
|
+
outputTokens: (_e = result.usage) == null ? void 0 : _e.outputTokens
|
|
4456
|
+
},
|
|
4457
|
+
ctx
|
|
4458
|
+
);
|
|
4459
|
+
return result;
|
|
4460
|
+
})
|
|
4461
|
+
};
|
|
4462
|
+
}
|
|
4463
|
+
};
|
|
4464
|
+
}
|
|
4465
|
+
});
|
|
4466
|
+
|
|
3655
4467
|
// ../../node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js
|
|
3656
4468
|
var require_escape_string_regexp = __commonJS({
|
|
3657
4469
|
"../../node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js"(exports2, module2) {
|
|
@@ -3961,7 +4773,7 @@ var require_common = __commonJS({
|
|
|
3961
4773
|
// ../../node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/browser.js
|
|
3962
4774
|
var require_browser = __commonJS({
|
|
3963
4775
|
"../../node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/browser.js"(exports2, module2) {
|
|
3964
|
-
exports2.formatArgs =
|
|
4776
|
+
exports2.formatArgs = formatArgs2;
|
|
3965
4777
|
exports2.save = save;
|
|
3966
4778
|
exports2.load = load;
|
|
3967
4779
|
exports2.useColors = useColors;
|
|
@@ -4067,7 +4879,7 @@ var require_browser = __commonJS({
|
|
|
4067
4879
|
typeof navigator !== "undefined" && navigator.userAgent && (m2 = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m2[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
4068
4880
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
4069
4881
|
}
|
|
4070
|
-
function
|
|
4882
|
+
function formatArgs2(args) {
|
|
4071
4883
|
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
|
|
4072
4884
|
if (!this.useColors) {
|
|
4073
4885
|
return;
|
|
@@ -4250,7 +5062,7 @@ var require_node = __commonJS({
|
|
|
4250
5062
|
var util = require("util");
|
|
4251
5063
|
exports2.init = init;
|
|
4252
5064
|
exports2.log = log;
|
|
4253
|
-
exports2.formatArgs =
|
|
5065
|
+
exports2.formatArgs = formatArgs2;
|
|
4254
5066
|
exports2.save = save;
|
|
4255
5067
|
exports2.load = load;
|
|
4256
5068
|
exports2.useColors = useColors;
|
|
@@ -4366,7 +5178,7 @@ var require_node = __commonJS({
|
|
|
4366
5178
|
function useColors() {
|
|
4367
5179
|
return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
4368
5180
|
}
|
|
4369
|
-
function
|
|
5181
|
+
function formatArgs2(args) {
|
|
4370
5182
|
const { namespace: name, useColors: useColors2 } = this;
|
|
4371
5183
|
if (useColors2) {
|
|
4372
5184
|
const c = this.color;
|
|
@@ -4432,11 +5244,11 @@ var require_src = __commonJS({
|
|
|
4432
5244
|
var require_is_docker = __commonJS({
|
|
4433
5245
|
"../../node_modules/.pnpm/is-docker@2.2.1/node_modules/is-docker/index.js"(exports2, module2) {
|
|
4434
5246
|
"use strict";
|
|
4435
|
-
var
|
|
5247
|
+
var fs12 = require("fs");
|
|
4436
5248
|
var isDocker;
|
|
4437
5249
|
function hasDockerEnv() {
|
|
4438
5250
|
try {
|
|
4439
|
-
|
|
5251
|
+
fs12.statSync("/.dockerenv");
|
|
4440
5252
|
return true;
|
|
4441
5253
|
} catch (_) {
|
|
4442
5254
|
return false;
|
|
@@ -4444,7 +5256,7 @@ var require_is_docker = __commonJS({
|
|
|
4444
5256
|
}
|
|
4445
5257
|
function hasDockerCGroup() {
|
|
4446
5258
|
try {
|
|
4447
|
-
return
|
|
5259
|
+
return fs12.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
4448
5260
|
} catch (_) {
|
|
4449
5261
|
return false;
|
|
4450
5262
|
}
|
|
@@ -4463,7 +5275,7 @@ var require_is_wsl = __commonJS({
|
|
|
4463
5275
|
"../../node_modules/.pnpm/is-wsl@2.2.0/node_modules/is-wsl/index.js"(exports2, module2) {
|
|
4464
5276
|
"use strict";
|
|
4465
5277
|
var os3 = require("os");
|
|
4466
|
-
var
|
|
5278
|
+
var fs12 = require("fs");
|
|
4467
5279
|
var isDocker = require_is_docker();
|
|
4468
5280
|
var isWsl3 = () => {
|
|
4469
5281
|
if (process.platform !== "linux") {
|
|
@@ -4476,7 +5288,7 @@ var require_is_wsl = __commonJS({
|
|
|
4476
5288
|
return true;
|
|
4477
5289
|
}
|
|
4478
5290
|
try {
|
|
4479
|
-
return
|
|
5291
|
+
return fs12.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isDocker() : false;
|
|
4480
5292
|
} catch (_) {
|
|
4481
5293
|
return false;
|
|
4482
5294
|
}
|
|
@@ -10393,31 +11205,31 @@ var require_node_domexception = __commonJS({
|
|
|
10393
11205
|
});
|
|
10394
11206
|
|
|
10395
11207
|
// ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/from.js
|
|
10396
|
-
var
|
|
11208
|
+
var import_node_fs2, import_node_path2, import_node_domexception, stat, blobFromSync, blobFrom, fileFrom, fileFromSync, fromBlob, fromFile, _path, _start, _BlobDataItem, BlobDataItem;
|
|
10397
11209
|
var init_from = __esm({
|
|
10398
11210
|
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/from.js"() {
|
|
10399
|
-
|
|
10400
|
-
|
|
11211
|
+
import_node_fs2 = require("fs");
|
|
11212
|
+
import_node_path2 = require("path");
|
|
10401
11213
|
import_node_domexception = __toESM(require_node_domexception(), 1);
|
|
10402
11214
|
init_file();
|
|
10403
11215
|
init_fetch_blob();
|
|
10404
|
-
({ stat } =
|
|
10405
|
-
blobFromSync = (
|
|
10406
|
-
blobFrom = (
|
|
10407
|
-
fileFrom = (
|
|
10408
|
-
fileFromSync = (
|
|
10409
|
-
fromBlob = (stat2,
|
|
10410
|
-
path:
|
|
11216
|
+
({ stat } = import_node_fs2.promises);
|
|
11217
|
+
blobFromSync = (path8, type) => fromBlob((0, import_node_fs2.statSync)(path8), path8, type);
|
|
11218
|
+
blobFrom = (path8, type) => stat(path8).then((stat2) => fromBlob(stat2, path8, type));
|
|
11219
|
+
fileFrom = (path8, type) => stat(path8).then((stat2) => fromFile(stat2, path8, type));
|
|
11220
|
+
fileFromSync = (path8, type) => fromFile((0, import_node_fs2.statSync)(path8), path8, type);
|
|
11221
|
+
fromBlob = (stat2, path8, type = "") => new fetch_blob_default([new BlobDataItem({
|
|
11222
|
+
path: path8,
|
|
10411
11223
|
size: stat2.size,
|
|
10412
11224
|
lastModified: stat2.mtimeMs,
|
|
10413
11225
|
start: 0
|
|
10414
11226
|
})], { type });
|
|
10415
|
-
fromFile = (stat2,
|
|
10416
|
-
path:
|
|
11227
|
+
fromFile = (stat2, path8, type = "") => new file_default([new BlobDataItem({
|
|
11228
|
+
path: path8,
|
|
10417
11229
|
size: stat2.size,
|
|
10418
11230
|
lastModified: stat2.mtimeMs,
|
|
10419
11231
|
start: 0
|
|
10420
|
-
})], (0,
|
|
11232
|
+
})], (0, import_node_path2.basename)(path8), { type, lastModified: stat2.mtimeMs });
|
|
10421
11233
|
_BlobDataItem = class _BlobDataItem {
|
|
10422
11234
|
constructor(options) {
|
|
10423
11235
|
__privateAdd(this, _path);
|
|
@@ -10445,7 +11257,7 @@ var init_from = __esm({
|
|
|
10445
11257
|
if (mtimeMs > this.lastModified) {
|
|
10446
11258
|
throw new import_node_domexception.default("The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.", "NotReadableError");
|
|
10447
11259
|
}
|
|
10448
|
-
yield* __yieldStar((0,
|
|
11260
|
+
yield* __yieldStar((0, import_node_fs2.createReadStream)(__privateGet(this, _path), {
|
|
10449
11261
|
start: __privateGet(this, _start),
|
|
10450
11262
|
end: __privateGet(this, _start) + this.size - 1
|
|
10451
11263
|
}));
|
|
@@ -10851,7 +11663,7 @@ function consumeBody(data) {
|
|
|
10851
11663
|
if (body === null) {
|
|
10852
11664
|
return import_node_buffer.Buffer.alloc(0);
|
|
10853
11665
|
}
|
|
10854
|
-
if (!(body instanceof
|
|
11666
|
+
if (!(body instanceof import_node_stream2.default)) {
|
|
10855
11667
|
return import_node_buffer.Buffer.alloc(0);
|
|
10856
11668
|
}
|
|
10857
11669
|
const accum = [];
|
|
@@ -10896,10 +11708,10 @@ function consumeBody(data) {
|
|
|
10896
11708
|
}
|
|
10897
11709
|
});
|
|
10898
11710
|
}
|
|
10899
|
-
var
|
|
11711
|
+
var import_node_stream2, import_node_util, import_node_buffer, pipeline, INTERNALS, Body, clone, getNonSpecFormDataBoundary, extractContentType, getTotalBytes, writeToStream;
|
|
10900
11712
|
var init_body = __esm({
|
|
10901
11713
|
"../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/body.js"() {
|
|
10902
|
-
|
|
11714
|
+
import_node_stream2 = __toESM(require("stream"), 1);
|
|
10903
11715
|
import_node_util = require("util");
|
|
10904
11716
|
import_node_buffer = require("buffer");
|
|
10905
11717
|
init_fetch_blob();
|
|
@@ -10907,7 +11719,7 @@ var init_body = __esm({
|
|
|
10907
11719
|
init_fetch_error();
|
|
10908
11720
|
init_base();
|
|
10909
11721
|
init_is();
|
|
10910
|
-
pipeline = (0, import_node_util.promisify)(
|
|
11722
|
+
pipeline = (0, import_node_util.promisify)(import_node_stream2.default.pipeline);
|
|
10911
11723
|
INTERNALS = Symbol("Body internals");
|
|
10912
11724
|
Body = class {
|
|
10913
11725
|
constructor(body, {
|
|
@@ -10924,7 +11736,7 @@ var init_body = __esm({
|
|
|
10924
11736
|
body = import_node_buffer.Buffer.from(body);
|
|
10925
11737
|
} else if (ArrayBuffer.isView(body)) {
|
|
10926
11738
|
body = import_node_buffer.Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
10927
|
-
} else if (body instanceof
|
|
11739
|
+
} else if (body instanceof import_node_stream2.default) {
|
|
10928
11740
|
} else if (body instanceof FormData2) {
|
|
10929
11741
|
body = formDataToBlob(body);
|
|
10930
11742
|
boundary = body.type.split("=")[1];
|
|
@@ -10933,9 +11745,9 @@ var init_body = __esm({
|
|
|
10933
11745
|
}
|
|
10934
11746
|
let stream = body;
|
|
10935
11747
|
if (import_node_buffer.Buffer.isBuffer(body)) {
|
|
10936
|
-
stream =
|
|
11748
|
+
stream = import_node_stream2.default.Readable.from(body);
|
|
10937
11749
|
} else if (isBlob(body)) {
|
|
10938
|
-
stream =
|
|
11750
|
+
stream = import_node_stream2.default.Readable.from(body.stream());
|
|
10939
11751
|
}
|
|
10940
11752
|
this[INTERNALS] = {
|
|
10941
11753
|
body,
|
|
@@ -10945,7 +11757,7 @@ var init_body = __esm({
|
|
|
10945
11757
|
error: null
|
|
10946
11758
|
};
|
|
10947
11759
|
this.size = size;
|
|
10948
|
-
if (body instanceof
|
|
11760
|
+
if (body instanceof import_node_stream2.default) {
|
|
10949
11761
|
body.on("error", (error_) => {
|
|
10950
11762
|
const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
|
|
10951
11763
|
this[INTERNALS].error = error;
|
|
@@ -11051,9 +11863,9 @@ var init_body = __esm({
|
|
|
11051
11863
|
if (instance.bodyUsed) {
|
|
11052
11864
|
throw new Error("cannot clone body after it is used");
|
|
11053
11865
|
}
|
|
11054
|
-
if (body instanceof
|
|
11055
|
-
p1 = new
|
|
11056
|
-
p2 = new
|
|
11866
|
+
if (body instanceof import_node_stream2.default && typeof body.getBoundary !== "function") {
|
|
11867
|
+
p1 = new import_node_stream2.PassThrough({ highWaterMark });
|
|
11868
|
+
p2 = new import_node_stream2.PassThrough({ highWaterMark });
|
|
11057
11869
|
body.pipe(p1);
|
|
11058
11870
|
body.pipe(p2);
|
|
11059
11871
|
instance[INTERNALS].stream = p1;
|
|
@@ -11088,7 +11900,7 @@ var init_body = __esm({
|
|
|
11088
11900
|
if (body && typeof body.getBoundary === "function") {
|
|
11089
11901
|
return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
|
|
11090
11902
|
}
|
|
11091
|
-
if (body instanceof
|
|
11903
|
+
if (body instanceof import_node_stream2.default) {
|
|
11092
11904
|
return null;
|
|
11093
11905
|
}
|
|
11094
11906
|
return "text/plain;charset=UTF-8";
|
|
@@ -11862,7 +12674,7 @@ function fetch2(url, options_) {
|
|
|
11862
12674
|
const abort = () => {
|
|
11863
12675
|
const error = new AbortError("The operation was aborted.");
|
|
11864
12676
|
reject(error);
|
|
11865
|
-
if (request.body && request.body instanceof
|
|
12677
|
+
if (request.body && request.body instanceof import_node_stream3.default.Readable) {
|
|
11866
12678
|
request.body.destroy(error);
|
|
11867
12679
|
}
|
|
11868
12680
|
if (!response || !response.body) {
|
|
@@ -11961,7 +12773,7 @@ function fetch2(url, options_) {
|
|
|
11961
12773
|
requestOptions.headers.delete(name);
|
|
11962
12774
|
}
|
|
11963
12775
|
}
|
|
11964
|
-
if (response_.statusCode !== 303 && request.body && options_.body instanceof
|
|
12776
|
+
if (response_.statusCode !== 303 && request.body && options_.body instanceof import_node_stream3.default.Readable) {
|
|
11965
12777
|
reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
|
|
11966
12778
|
finalize();
|
|
11967
12779
|
return;
|
|
@@ -11988,7 +12800,7 @@ function fetch2(url, options_) {
|
|
|
11988
12800
|
signal.removeEventListener("abort", abortAndFinalize);
|
|
11989
12801
|
});
|
|
11990
12802
|
}
|
|
11991
|
-
let body = (0,
|
|
12803
|
+
let body = (0, import_node_stream3.pipeline)(response_, new import_node_stream3.PassThrough(), (error) => {
|
|
11992
12804
|
if (error) {
|
|
11993
12805
|
reject(error);
|
|
11994
12806
|
}
|
|
@@ -12016,7 +12828,7 @@ function fetch2(url, options_) {
|
|
|
12016
12828
|
finishFlush: import_node_zlib.default.Z_SYNC_FLUSH
|
|
12017
12829
|
};
|
|
12018
12830
|
if (codings === "gzip" || codings === "x-gzip") {
|
|
12019
|
-
body = (0,
|
|
12831
|
+
body = (0, import_node_stream3.pipeline)(body, import_node_zlib.default.createGunzip(zlibOptions), (error) => {
|
|
12020
12832
|
if (error) {
|
|
12021
12833
|
reject(error);
|
|
12022
12834
|
}
|
|
@@ -12026,20 +12838,20 @@ function fetch2(url, options_) {
|
|
|
12026
12838
|
return;
|
|
12027
12839
|
}
|
|
12028
12840
|
if (codings === "deflate" || codings === "x-deflate") {
|
|
12029
|
-
const raw = (0,
|
|
12841
|
+
const raw = (0, import_node_stream3.pipeline)(response_, new import_node_stream3.PassThrough(), (error) => {
|
|
12030
12842
|
if (error) {
|
|
12031
12843
|
reject(error);
|
|
12032
12844
|
}
|
|
12033
12845
|
});
|
|
12034
12846
|
raw.once("data", (chunk) => {
|
|
12035
12847
|
if ((chunk[0] & 15) === 8) {
|
|
12036
|
-
body = (0,
|
|
12848
|
+
body = (0, import_node_stream3.pipeline)(body, import_node_zlib.default.createInflate(), (error) => {
|
|
12037
12849
|
if (error) {
|
|
12038
12850
|
reject(error);
|
|
12039
12851
|
}
|
|
12040
12852
|
});
|
|
12041
12853
|
} else {
|
|
12042
|
-
body = (0,
|
|
12854
|
+
body = (0, import_node_stream3.pipeline)(body, import_node_zlib.default.createInflateRaw(), (error) => {
|
|
12043
12855
|
if (error) {
|
|
12044
12856
|
reject(error);
|
|
12045
12857
|
}
|
|
@@ -12057,7 +12869,7 @@ function fetch2(url, options_) {
|
|
|
12057
12869
|
return;
|
|
12058
12870
|
}
|
|
12059
12871
|
if (codings === "br") {
|
|
12060
|
-
body = (0,
|
|
12872
|
+
body = (0, import_node_stream3.pipeline)(body, import_node_zlib.default.createBrotliDecompress(), (error) => {
|
|
12061
12873
|
if (error) {
|
|
12062
12874
|
reject(error);
|
|
12063
12875
|
}
|
|
@@ -12105,13 +12917,13 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
|
12105
12917
|
});
|
|
12106
12918
|
});
|
|
12107
12919
|
}
|
|
12108
|
-
var import_node_http2, import_node_https, import_node_zlib,
|
|
12920
|
+
var import_node_http2, import_node_https, import_node_zlib, import_node_stream3, import_node_buffer2, supportedSchemas;
|
|
12109
12921
|
var init_src = __esm({
|
|
12110
12922
|
"../../node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js"() {
|
|
12111
12923
|
import_node_http2 = __toESM(require("http"), 1);
|
|
12112
12924
|
import_node_https = __toESM(require("https"), 1);
|
|
12113
12925
|
import_node_zlib = __toESM(require("zlib"), 1);
|
|
12114
|
-
|
|
12926
|
+
import_node_stream3 = __toESM(require("stream"), 1);
|
|
12115
12927
|
import_node_buffer2 = require("buffer");
|
|
12116
12928
|
init_dist();
|
|
12117
12929
|
init_body();
|
|
@@ -15687,9 +16499,9 @@ var require_util2 = __commonJS({
|
|
|
15687
16499
|
exports2.removeUndefinedValuesInObject = removeUndefinedValuesInObject;
|
|
15688
16500
|
exports2.isValidFile = isValidFile;
|
|
15689
16501
|
exports2.getWellKnownCertificateConfigFileLocation = getWellKnownCertificateConfigFileLocation;
|
|
15690
|
-
var
|
|
16502
|
+
var fs12 = require("fs");
|
|
15691
16503
|
var os3 = require("os");
|
|
15692
|
-
var
|
|
16504
|
+
var path8 = require("path");
|
|
15693
16505
|
var WELL_KNOWN_CERTIFICATE_CONFIG_FILE = "certificate_config.json";
|
|
15694
16506
|
var CLOUDSDK_CONFIG_DIRECTORY = "gcloud";
|
|
15695
16507
|
function snakeToCamel(str) {
|
|
@@ -15781,7 +16593,7 @@ var require_util2 = __commonJS({
|
|
|
15781
16593
|
function isValidFile(filePath) {
|
|
15782
16594
|
return __async(this, null, function* () {
|
|
15783
16595
|
try {
|
|
15784
|
-
const stats = yield
|
|
16596
|
+
const stats = yield fs12.promises.lstat(filePath);
|
|
15785
16597
|
return stats.isFile();
|
|
15786
16598
|
} catch (e2) {
|
|
15787
16599
|
return false;
|
|
@@ -15789,8 +16601,8 @@ var require_util2 = __commonJS({
|
|
|
15789
16601
|
});
|
|
15790
16602
|
}
|
|
15791
16603
|
function getWellKnownCertificateConfigFileLocation() {
|
|
15792
|
-
const configDir = process.env.CLOUDSDK_CONFIG || (_isWindows() ?
|
|
15793
|
-
return
|
|
16604
|
+
const configDir = process.env.CLOUDSDK_CONFIG || (_isWindows() ? path8.join(process.env.APPDATA || "", CLOUDSDK_CONFIG_DIRECTORY) : path8.join(process.env.HOME || "", ".config", CLOUDSDK_CONFIG_DIRECTORY));
|
|
16605
|
+
return path8.join(configDir, WELL_KNOWN_CERTIFICATE_CONFIG_FILE);
|
|
15794
16606
|
}
|
|
15795
16607
|
function _isWindows() {
|
|
15796
16608
|
return os3.platform().startsWith("win");
|
|
@@ -17666,10 +18478,10 @@ var require_src5 = __commonJS({
|
|
|
17666
18478
|
value: true
|
|
17667
18479
|
});
|
|
17668
18480
|
exports2.GoogleToken = void 0;
|
|
17669
|
-
var
|
|
18481
|
+
var fs12 = _interopRequireWildcard(require("fs"));
|
|
17670
18482
|
var _gaxios = require_src2();
|
|
17671
18483
|
var jws = _interopRequireWildcard(require_jws());
|
|
17672
|
-
var
|
|
18484
|
+
var path8 = _interopRequireWildcard(require("path"));
|
|
17673
18485
|
var _util = require("util");
|
|
17674
18486
|
function _interopRequireWildcard(e2, t2) {
|
|
17675
18487
|
if ("function" == typeof WeakMap) var r2 = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakMap();
|
|
@@ -17909,7 +18721,7 @@ var require_src5 = __commonJS({
|
|
|
17909
18721
|
});
|
|
17910
18722
|
};
|
|
17911
18723
|
}
|
|
17912
|
-
var readFile =
|
|
18724
|
+
var readFile = fs12.readFile ? (0, _util.promisify)(fs12.readFile) : /* @__PURE__ */ _asyncToGenerator(/* @__PURE__ */ _regenerator().m(function _callee() {
|
|
17913
18725
|
return _regenerator().w(function(_context) {
|
|
17914
18726
|
while (1) switch (_context.n) {
|
|
17915
18727
|
case 0:
|
|
@@ -18043,7 +18855,7 @@ var require_src5 = __commonJS({
|
|
|
18043
18855
|
return _regenerator().w(function(_context2) {
|
|
18044
18856
|
while (1) switch (_context2.n) {
|
|
18045
18857
|
case 0:
|
|
18046
|
-
ext =
|
|
18858
|
+
ext = path8.extname(keyFile);
|
|
18047
18859
|
_t = ext;
|
|
18048
18860
|
_context2.n = _t === ".json" ? 1 : _t === ".der" ? 4 : _t === ".crt" ? 4 : _t === ".pem" ? 4 : _t === ".p12" ? 6 : _t === ".pfx" ? 6 : 7;
|
|
18049
18861
|
break;
|
|
@@ -19713,15 +20525,15 @@ var require_filesubjecttokensupplier = __commonJS({
|
|
|
19713
20525
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
19714
20526
|
exports2.FileSubjectTokenSupplier = void 0;
|
|
19715
20527
|
var util_1 = require("util");
|
|
19716
|
-
var
|
|
20528
|
+
var fs12 = require("fs");
|
|
19717
20529
|
var _a4;
|
|
19718
|
-
var readFile = (0, util_1.promisify)((_a4 =
|
|
20530
|
+
var readFile = (0, util_1.promisify)((_a4 = fs12.readFile) != null ? _a4 : () => {
|
|
19719
20531
|
});
|
|
19720
20532
|
var _a5;
|
|
19721
|
-
var realpath = (0, util_1.promisify)((_a5 =
|
|
20533
|
+
var realpath = (0, util_1.promisify)((_a5 = fs12.realpath) != null ? _a5 : () => {
|
|
19722
20534
|
});
|
|
19723
20535
|
var _a6;
|
|
19724
|
-
var lstat = (0, util_1.promisify)((_a6 =
|
|
20536
|
+
var lstat = (0, util_1.promisify)((_a6 = fs12.lstat) != null ? _a6 : () => {
|
|
19725
20537
|
});
|
|
19726
20538
|
var FileSubjectTokenSupplier = class {
|
|
19727
20539
|
/**
|
|
@@ -19841,7 +20653,7 @@ var require_certificatesubjecttokensupplier = __commonJS({
|
|
|
19841
20653
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
19842
20654
|
exports2.CertificateSubjectTokenSupplier = exports2.InvalidConfigurationError = exports2.CertificateSourceUnavailableError = exports2.CERTIFICATE_CONFIGURATION_ENV_VARIABLE = void 0;
|
|
19843
20655
|
var util_1 = require_util2();
|
|
19844
|
-
var
|
|
20656
|
+
var fs12 = require("fs");
|
|
19845
20657
|
var crypto_1 = require("crypto");
|
|
19846
20658
|
var https2 = require("https");
|
|
19847
20659
|
exports2.CERTIFICATE_CONFIGURATION_ENV_VARIABLE = "GOOGLE_API_CERTIFICATE_CONFIG";
|
|
@@ -19936,7 +20748,7 @@ var require_certificatesubjecttokensupplier = __commonJS({
|
|
|
19936
20748
|
const configPath = this.certificateConfigPath;
|
|
19937
20749
|
let fileContents;
|
|
19938
20750
|
try {
|
|
19939
|
-
fileContents = yield
|
|
20751
|
+
fileContents = yield fs12.promises.readFile(configPath, "utf8");
|
|
19940
20752
|
} catch (err) {
|
|
19941
20753
|
throw new CertificateSourceUnavailableError(`Failed to read certificate config file at: ${configPath}`);
|
|
19942
20754
|
}
|
|
@@ -19959,14 +20771,14 @@ var require_certificatesubjecttokensupplier = __commonJS({
|
|
|
19959
20771
|
return __async(this, null, function* () {
|
|
19960
20772
|
let cert, key;
|
|
19961
20773
|
try {
|
|
19962
|
-
cert = yield
|
|
20774
|
+
cert = yield fs12.promises.readFile(certPath);
|
|
19963
20775
|
new crypto_1.X509Certificate(cert);
|
|
19964
20776
|
} catch (err) {
|
|
19965
20777
|
const message = err instanceof Error ? err.message : String(err);
|
|
19966
20778
|
throw new CertificateSourceUnavailableError(`Failed to read certificate file at ${certPath}: ${message}`);
|
|
19967
20779
|
}
|
|
19968
20780
|
try {
|
|
19969
|
-
key = yield
|
|
20781
|
+
key = yield fs12.promises.readFile(keyPath);
|
|
19970
20782
|
(0, crypto_1.createPrivateKey)(key);
|
|
19971
20783
|
} catch (err) {
|
|
19972
20784
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -19983,7 +20795,7 @@ var require_certificatesubjecttokensupplier = __commonJS({
|
|
|
19983
20795
|
return JSON.stringify([leafCert.raw.toString("base64")]);
|
|
19984
20796
|
}
|
|
19985
20797
|
try {
|
|
19986
|
-
const chainPems = yield
|
|
20798
|
+
const chainPems = yield fs12.promises.readFile(this.trustChainPath, "utf8");
|
|
19987
20799
|
const pemBlocks = (_a4 = chainPems.match(/-----BEGIN CERTIFICATE-----[^-]+-----END CERTIFICATE-----/g)) != null ? _a4 : [];
|
|
19988
20800
|
const chainCerts = pemBlocks.map((pem, index) => {
|
|
19989
20801
|
try {
|
|
@@ -20685,7 +21497,7 @@ var require_pluggable_auth_handler = __commonJS({
|
|
|
20685
21497
|
exports2.PluggableAuthHandler = exports2.ExecutableError = void 0;
|
|
20686
21498
|
var executable_response_1 = require_executable_response();
|
|
20687
21499
|
var childProcess2 = require("child_process");
|
|
20688
|
-
var
|
|
21500
|
+
var fs12 = require("fs");
|
|
20689
21501
|
var ExecutableError = class extends Error {
|
|
20690
21502
|
constructor(message, code) {
|
|
20691
21503
|
super(`The executable failed with exit code: ${code} and error message: ${message}.`);
|
|
@@ -20771,14 +21583,14 @@ var require_pluggable_auth_handler = __commonJS({
|
|
|
20771
21583
|
}
|
|
20772
21584
|
let filePath;
|
|
20773
21585
|
try {
|
|
20774
|
-
filePath = yield
|
|
21586
|
+
filePath = yield fs12.promises.realpath(this.outputFile);
|
|
20775
21587
|
} catch (e2) {
|
|
20776
21588
|
return void 0;
|
|
20777
21589
|
}
|
|
20778
|
-
if (!(yield
|
|
21590
|
+
if (!(yield fs12.promises.lstat(filePath)).isFile()) {
|
|
20779
21591
|
return void 0;
|
|
20780
21592
|
}
|
|
20781
|
-
const responseString = yield
|
|
21593
|
+
const responseString = yield fs12.promises.readFile(filePath, {
|
|
20782
21594
|
encoding: "utf8"
|
|
20783
21595
|
});
|
|
20784
21596
|
if (responseString === "") {
|
|
@@ -21205,11 +22017,11 @@ var require_googleauth = __commonJS({
|
|
|
21205
22017
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
21206
22018
|
exports2.GoogleAuth = exports2.GoogleAuthExceptionMessages = void 0;
|
|
21207
22019
|
var child_process_1 = require("child_process");
|
|
21208
|
-
var
|
|
22020
|
+
var fs12 = require("fs");
|
|
21209
22021
|
var gaxios_1 = require_src2();
|
|
21210
22022
|
var gcpMetadata = require_src4();
|
|
21211
22023
|
var os3 = require("os");
|
|
21212
|
-
var
|
|
22024
|
+
var path8 = require("path");
|
|
21213
22025
|
var crypto_1 = require_crypto3();
|
|
21214
22026
|
var computeclient_1 = require_computeclient();
|
|
21215
22027
|
var idtokenclient_1 = require_idtokenclient();
|
|
@@ -21507,12 +22319,12 @@ var require_googleauth = __commonJS({
|
|
|
21507
22319
|
} else {
|
|
21508
22320
|
const home = process.env["HOME"];
|
|
21509
22321
|
if (home) {
|
|
21510
|
-
location =
|
|
22322
|
+
location = path8.join(home, ".config");
|
|
21511
22323
|
}
|
|
21512
22324
|
}
|
|
21513
22325
|
if (location) {
|
|
21514
|
-
location =
|
|
21515
|
-
if (!
|
|
22326
|
+
location = path8.join(location, "gcloud", "application_default_credentials.json");
|
|
22327
|
+
if (!fs12.existsSync(location)) {
|
|
21516
22328
|
location = null;
|
|
21517
22329
|
}
|
|
21518
22330
|
}
|
|
@@ -21535,8 +22347,8 @@ var require_googleauth = __commonJS({
|
|
|
21535
22347
|
throw new Error("The file path is invalid.");
|
|
21536
22348
|
}
|
|
21537
22349
|
try {
|
|
21538
|
-
filePath =
|
|
21539
|
-
if (!
|
|
22350
|
+
filePath = fs12.realpathSync(filePath);
|
|
22351
|
+
if (!fs12.lstatSync(filePath).isFile()) {
|
|
21540
22352
|
throw new Error();
|
|
21541
22353
|
}
|
|
21542
22354
|
} catch (err) {
|
|
@@ -21545,7 +22357,7 @@ var require_googleauth = __commonJS({
|
|
|
21545
22357
|
}
|
|
21546
22358
|
throw err;
|
|
21547
22359
|
}
|
|
21548
|
-
const readStream =
|
|
22360
|
+
const readStream = fs12.createReadStream(filePath);
|
|
21549
22361
|
return this.fromStream(readStream, options);
|
|
21550
22362
|
});
|
|
21551
22363
|
}
|
|
@@ -22020,8 +22832,8 @@ var require_googleauth = __commonJS({
|
|
|
22020
22832
|
if (this.jsonContent) {
|
|
22021
22833
|
return this._cacheClientFromJSON(this.jsonContent, this.clientOptions);
|
|
22022
22834
|
} else if (this.keyFilename) {
|
|
22023
|
-
const filePath =
|
|
22024
|
-
const stream =
|
|
22835
|
+
const filePath = path8.resolve(this.keyFilename);
|
|
22836
|
+
const stream = fs12.createReadStream(filePath);
|
|
22025
22837
|
return yield this.fromStreamAsync(stream, this.clientOptions);
|
|
22026
22838
|
} else if (this.apiKey) {
|
|
22027
22839
|
const client = yield this.fromAPIKey(this.apiKey, this.clientOptions);
|
|
@@ -24391,11 +25203,12 @@ var page_exports = {};
|
|
|
24391
25203
|
__export(page_exports, {
|
|
24392
25204
|
Page: () => Page
|
|
24393
25205
|
});
|
|
24394
|
-
var import_fs7, LIFECYCLE_NAME, Page;
|
|
25206
|
+
var import_fs7, LIFECYCLE_NAME, _keyPress_dec, _type_dec, _dragAndDrop_dec, _scroll_dec, _click_dec, _evaluate_dec, _waitForLoadState_dec, _screenshot_dec, _goForward_dec, _goBack_dec, _reload_dec, _goto_dec, _close_dec, _init, _Page, Page;
|
|
24395
25207
|
var init_page = __esm({
|
|
24396
25208
|
"lib/v3/understudy/page.ts"() {
|
|
24397
25209
|
import_fs7 = require("fs");
|
|
24398
25210
|
init_logger();
|
|
25211
|
+
init_flowLogger();
|
|
24399
25212
|
init_frame();
|
|
24400
25213
|
init_frameLocator();
|
|
24401
25214
|
init_deepLocator();
|
|
@@ -24415,22 +25228,33 @@ var init_page = __esm({
|
|
|
24415
25228
|
domcontentloaded: "DOMContentLoaded",
|
|
24416
25229
|
networkidle: "networkIdle"
|
|
24417
25230
|
};
|
|
24418
|
-
Page =
|
|
25231
|
+
_close_dec = [logAction("Page.close")], _goto_dec = [logAction("Page.goto")], _reload_dec = [logAction("Page.reload")], _goBack_dec = [logAction("Page.goBack")], _goForward_dec = [logAction("Page.goForward")], _screenshot_dec = [logAction("Page.screenshot")], _waitForLoadState_dec = [logAction("Page.waitForLoadState")], _evaluate_dec = [logAction("Page.evaluate")], _click_dec = [logAction("Page.click")], _scroll_dec = [logAction("Page.scroll")], _dragAndDrop_dec = [logAction("Page.dragAndDrop")], _type_dec = [logAction("Page.type")], _keyPress_dec = [logAction("Page.keyPress")];
|
|
25232
|
+
_Page = class _Page {
|
|
24419
25233
|
constructor(conn, mainSession, _targetId, mainFrameId, apiClient, browserIsRemote = false) {
|
|
24420
25234
|
this.conn = conn;
|
|
24421
25235
|
this.mainSession = mainSession;
|
|
24422
25236
|
this._targetId = _targetId;
|
|
25237
|
+
__runInitializers(_init, 5, this);
|
|
24423
25238
|
/** Every CDP child session this page owns (top-level + adopted OOPIF sessions). */
|
|
24424
25239
|
this.sessions = /* @__PURE__ */ new Map();
|
|
25240
|
+
// sessionId -> session
|
|
25241
|
+
/** Unified truth for frame topology + ownership. */
|
|
25242
|
+
this.registry = void 0;
|
|
25243
|
+
/** A convenience wrapper bound to the current main frame id (top-level session). */
|
|
25244
|
+
this.mainFrameWrapper = void 0;
|
|
24425
25245
|
/** Compact ordinal per frameId (used by snapshot encoding). */
|
|
24426
25246
|
this.frameOrdinals = /* @__PURE__ */ new Map();
|
|
24427
25247
|
this.nextOrdinal = 0;
|
|
24428
25248
|
/** cache Frames per frameId so everyone uses the same one */
|
|
24429
25249
|
this.frameCache = /* @__PURE__ */ new Map();
|
|
25250
|
+
this.browserIsRemote = void 0;
|
|
25251
|
+
/** Stable id for Frames created by this Page (use top-level TargetId). */
|
|
25252
|
+
this.pageId = void 0;
|
|
24430
25253
|
/** Cached current URL for synchronous page.url() */
|
|
24431
25254
|
this._currentUrl = "about:blank";
|
|
24432
25255
|
this.navigationCommandSeq = 0;
|
|
24433
25256
|
this.latestNavigationCommandId = 0;
|
|
25257
|
+
this.networkManager = void 0;
|
|
24434
25258
|
/** Optional API client for routing page operations to the API */
|
|
24435
25259
|
this.apiClient = null;
|
|
24436
25260
|
this.consoleListeners = /* @__PURE__ */ new Set();
|
|
@@ -24856,9 +25680,6 @@ var init_page = __esm({
|
|
|
24856
25680
|
mainFrame() {
|
|
24857
25681
|
return this.mainFrameWrapper;
|
|
24858
25682
|
}
|
|
24859
|
-
/**
|
|
24860
|
-
* Close this top-level page (tab). Best-effort via Target.closeTarget.
|
|
24861
|
-
*/
|
|
24862
25683
|
close() {
|
|
24863
25684
|
return __async(this, null, function* () {
|
|
24864
25685
|
try {
|
|
@@ -24967,11 +25788,6 @@ var init_page = __esm({
|
|
|
24967
25788
|
}
|
|
24968
25789
|
}
|
|
24969
25790
|
}
|
|
24970
|
-
// -------- Convenience APIs delegated to the current main frame --------
|
|
24971
|
-
/**
|
|
24972
|
-
* Navigate the page; optionally wait for a lifecycle state.
|
|
24973
|
-
* Waits on the **current** main frame and follows root swaps during navigation.
|
|
24974
|
-
*/
|
|
24975
25791
|
goto(url, options) {
|
|
24976
25792
|
return __async(this, null, function* () {
|
|
24977
25793
|
var _a4, _b;
|
|
@@ -25024,9 +25840,6 @@ var init_page = __esm({
|
|
|
25024
25840
|
}
|
|
25025
25841
|
});
|
|
25026
25842
|
}
|
|
25027
|
-
/**
|
|
25028
|
-
* Reload the page; optionally wait for a lifecycle state.
|
|
25029
|
-
*/
|
|
25030
25843
|
reload(options) {
|
|
25031
25844
|
return __async(this, null, function* () {
|
|
25032
25845
|
var _a4, _b;
|
|
@@ -25061,9 +25874,6 @@ var init_page = __esm({
|
|
|
25061
25874
|
}
|
|
25062
25875
|
});
|
|
25063
25876
|
}
|
|
25064
|
-
/**
|
|
25065
|
-
* Navigate back in history if possible; optionally wait for a lifecycle state.
|
|
25066
|
-
*/
|
|
25067
25877
|
goBack(options) {
|
|
25068
25878
|
return __async(this, null, function* () {
|
|
25069
25879
|
var _a4, _b;
|
|
@@ -25104,9 +25914,6 @@ var init_page = __esm({
|
|
|
25104
25914
|
}
|
|
25105
25915
|
});
|
|
25106
25916
|
}
|
|
25107
|
-
/**
|
|
25108
|
-
* Navigate forward in history if possible; optionally wait for a lifecycle state.
|
|
25109
|
-
*/
|
|
25110
25917
|
goForward(options) {
|
|
25111
25918
|
return __async(this, null, function* () {
|
|
25112
25919
|
var _a4, _b;
|
|
@@ -25194,36 +26001,6 @@ var init_page = __esm({
|
|
|
25194
26001
|
}
|
|
25195
26002
|
});
|
|
25196
26003
|
}
|
|
25197
|
-
/**
|
|
25198
|
-
* Capture a screenshot with Playwright-style options.
|
|
25199
|
-
*
|
|
25200
|
-
* @param options Optional screenshot configuration.
|
|
25201
|
-
* @param options.animations Control CSS/Web animations during capture. Use
|
|
25202
|
-
* "disabled" to fast-forward finite animations and pause infinite ones.
|
|
25203
|
-
* @param options.caret Either hide the text caret (default) or leave it
|
|
25204
|
-
* visible via "initial".
|
|
25205
|
-
* @param options.clip Restrict capture to a specific rectangle (in CSS
|
|
25206
|
-
* pixels). Cannot be combined with `fullPage`.
|
|
25207
|
-
* @param options.fullPage Capture the full scrollable page instead of the
|
|
25208
|
-
* current viewport.
|
|
25209
|
-
* @param options.mask Array of locators that should be covered with an
|
|
25210
|
-
* overlay while the screenshot is taken.
|
|
25211
|
-
* @param options.maskColor CSS color used for the mask overlay (default
|
|
25212
|
-
* `#FF00FF`).
|
|
25213
|
-
* @param options.omitBackground Make the default page background transparent
|
|
25214
|
-
* (PNG only).
|
|
25215
|
-
* @param options.path File path to write the screenshot to. The file extension
|
|
25216
|
-
* determines the image type when `type` is not explicitly provided.
|
|
25217
|
-
* @param options.quality JPEG quality (0–100). Only applies when
|
|
25218
|
-
* `type === "jpeg"`.
|
|
25219
|
-
* @param options.scale Render scale: use "css" for one pixel per CSS pixel,
|
|
25220
|
-
* otherwise the default "device" leverages the current device pixel ratio.
|
|
25221
|
-
* @param options.style Additional CSS text injected into every frame before
|
|
25222
|
-
* capture (removed afterwards).
|
|
25223
|
-
* @param options.timeout Maximum capture duration in milliseconds before a
|
|
25224
|
-
* timeout error is thrown.
|
|
25225
|
-
* @param options.type Image format (`"png"` by default).
|
|
25226
|
-
*/
|
|
25227
26004
|
screenshot(options) {
|
|
25228
26005
|
return __async(this, null, function* () {
|
|
25229
26006
|
var _a4, _b, _c, _d2, _e;
|
|
@@ -25326,22 +26103,11 @@ var init_page = __esm({
|
|
|
25326
26103
|
withOrd.sort((a, b) => a.ord - b.ord);
|
|
25327
26104
|
return withOrd.map(({ id }) => this.frameForId(id));
|
|
25328
26105
|
}
|
|
25329
|
-
/**
|
|
25330
|
-
* Wait until the page reaches a lifecycle state on the current main frame.
|
|
25331
|
-
* Mirrors Playwright's API signatures.
|
|
25332
|
-
*/
|
|
25333
26106
|
waitForLoadState(state, timeoutMs) {
|
|
25334
26107
|
return __async(this, null, function* () {
|
|
25335
26108
|
yield this.waitForMainLoadState(state, timeoutMs != null ? timeoutMs : 15e3);
|
|
25336
26109
|
});
|
|
25337
26110
|
}
|
|
25338
|
-
/**
|
|
25339
|
-
* Evaluate a function or expression in the current main frame's main world.
|
|
25340
|
-
* - If a string is provided, it is treated as a JS expression.
|
|
25341
|
-
* - If a function is provided, it is stringified and invoked with the optional argument.
|
|
25342
|
-
* - The return value should be JSON-serializable. Non-serializable objects will
|
|
25343
|
-
* best-effort serialize via JSON.stringify inside the page context.
|
|
25344
|
-
*/
|
|
25345
26111
|
evaluate(pageFunctionOrExpression, arg) {
|
|
25346
26112
|
return __async(this, null, function* () {
|
|
25347
26113
|
var _a4;
|
|
@@ -25356,15 +26122,15 @@ var init_page = __esm({
|
|
|
25356
26122
|
const fnSrc = pageFunctionOrExpression.toString();
|
|
25357
26123
|
const argJson = JSON.stringify(arg);
|
|
25358
26124
|
expression = `(() => {
|
|
25359
|
-
|
|
25360
|
-
|
|
25361
|
-
|
|
25362
|
-
|
|
25363
|
-
|
|
25364
|
-
|
|
25365
|
-
|
|
25366
|
-
|
|
25367
|
-
|
|
26125
|
+
const __fn = ${fnSrc};
|
|
26126
|
+
const __arg = ${argJson};
|
|
26127
|
+
try {
|
|
26128
|
+
const __res = __fn(__arg);
|
|
26129
|
+
return Promise.resolve(__res).then(v => {
|
|
26130
|
+
try { return JSON.parse(JSON.stringify(v)); } catch { return v; }
|
|
26131
|
+
});
|
|
26132
|
+
} catch (e) { throw e; }
|
|
26133
|
+
})()`;
|
|
25368
26134
|
}
|
|
25369
26135
|
const { result, exceptionDetails } = yield this.mainSession.send(
|
|
25370
26136
|
"Runtime.evaluate",
|
|
@@ -25386,6 +26152,7 @@ var init_page = __esm({
|
|
|
25386
26152
|
* Force the page viewport to an exact CSS size and device scale factor.
|
|
25387
26153
|
* Ensures screenshots match width x height pixels when deviceScaleFactor = 1.
|
|
25388
26154
|
*/
|
|
26155
|
+
// @logAction("Page.setViewportSize") // disabled because it's pretty noisy, can always re-enable if needed for debugging
|
|
25389
26156
|
setViewportSize(width, height, options) {
|
|
25390
26157
|
return __async(this, null, function* () {
|
|
25391
26158
|
var _a4;
|
|
@@ -25569,12 +26336,6 @@ var init_page = __esm({
|
|
|
25569
26336
|
if (options == null ? void 0 : options.returnXpath) return [fromXpath != null ? fromXpath : "", toXpath != null ? toXpath : ""];
|
|
25570
26337
|
});
|
|
25571
26338
|
}
|
|
25572
|
-
/**
|
|
25573
|
-
* Type a string by dispatching keyDown/keyUp events per character.
|
|
25574
|
-
* Focus must already be on the desired element. Uses CDP Input.dispatchKeyEvent
|
|
25575
|
-
* and never falls back to Input.insertText. Optional delay applies between
|
|
25576
|
-
* successive characters.
|
|
25577
|
-
*/
|
|
25578
26339
|
type(text, options) {
|
|
25579
26340
|
return __async(this, null, function* () {
|
|
25580
26341
|
var _a4;
|
|
@@ -25647,11 +26408,6 @@ var init_page = __esm({
|
|
|
25647
26408
|
}
|
|
25648
26409
|
});
|
|
25649
26410
|
}
|
|
25650
|
-
/**
|
|
25651
|
-
* Press a single key or key combination (keyDown then keyUp).
|
|
25652
|
-
* For printable characters, uses the text path on keyDown; for named keys, sets key/code/VK.
|
|
25653
|
-
* Supports key combinations with modifiers like "Cmd+A", "Ctrl+C", "Shift+Tab", etc.
|
|
25654
|
-
*/
|
|
25655
26411
|
keyPress(key, options) {
|
|
25656
26412
|
return __async(this, null, function* () {
|
|
25657
26413
|
var _a4;
|
|
@@ -25999,6 +26755,22 @@ var init_page = __esm({
|
|
|
25999
26755
|
});
|
|
26000
26756
|
}
|
|
26001
26757
|
};
|
|
26758
|
+
_init = __decoratorStart(null);
|
|
26759
|
+
__decorateElement(_init, 1, "close", _close_dec, _Page);
|
|
26760
|
+
__decorateElement(_init, 1, "goto", _goto_dec, _Page);
|
|
26761
|
+
__decorateElement(_init, 1, "reload", _reload_dec, _Page);
|
|
26762
|
+
__decorateElement(_init, 1, "goBack", _goBack_dec, _Page);
|
|
26763
|
+
__decorateElement(_init, 1, "goForward", _goForward_dec, _Page);
|
|
26764
|
+
__decorateElement(_init, 1, "screenshot", _screenshot_dec, _Page);
|
|
26765
|
+
__decorateElement(_init, 1, "waitForLoadState", _waitForLoadState_dec, _Page);
|
|
26766
|
+
__decorateElement(_init, 1, "evaluate", _evaluate_dec, _Page);
|
|
26767
|
+
__decorateElement(_init, 1, "click", _click_dec, _Page);
|
|
26768
|
+
__decorateElement(_init, 1, "scroll", _scroll_dec, _Page);
|
|
26769
|
+
__decorateElement(_init, 1, "dragAndDrop", _dragAndDrop_dec, _Page);
|
|
26770
|
+
__decorateElement(_init, 1, "type", _type_dec, _Page);
|
|
26771
|
+
__decorateElement(_init, 1, "keyPress", _keyPress_dec, _Page);
|
|
26772
|
+
__decoratorMetadata(_init, _Page);
|
|
26773
|
+
Page = _Page;
|
|
26002
26774
|
}
|
|
26003
26775
|
});
|
|
26004
26776
|
|
|
@@ -26093,6 +26865,7 @@ var import_fs8 = __toESM(require("fs"));
|
|
|
26093
26865
|
var import_os2 = __toESM(require("os"));
|
|
26094
26866
|
var import_path6 = __toESM(require("path"));
|
|
26095
26867
|
var import_process2 = __toESM(require("process"));
|
|
26868
|
+
var import_uuid6 = require("uuid");
|
|
26096
26869
|
|
|
26097
26870
|
// lib/utils.ts
|
|
26098
26871
|
init_sdkErrors();
|
|
@@ -26583,9 +27356,9 @@ function transformSchema(schema, currentPath) {
|
|
|
26583
27356
|
}
|
|
26584
27357
|
return [schema, []];
|
|
26585
27358
|
}
|
|
26586
|
-
function injectUrls(obj,
|
|
27359
|
+
function injectUrls(obj, path8, idToUrlMapping) {
|
|
26587
27360
|
var _a4, _b;
|
|
26588
|
-
if (
|
|
27361
|
+
if (path8.length === 0) return;
|
|
26589
27362
|
const toId = (value) => {
|
|
26590
27363
|
if (typeof value === "number") {
|
|
26591
27364
|
return String(value);
|
|
@@ -26595,7 +27368,7 @@ function injectUrls(obj, path7, idToUrlMapping) {
|
|
|
26595
27368
|
}
|
|
26596
27369
|
return void 0;
|
|
26597
27370
|
};
|
|
26598
|
-
const [key, ...rest] =
|
|
27371
|
+
const [key, ...rest] = path8;
|
|
26599
27372
|
if (key === "*") {
|
|
26600
27373
|
if (Array.isArray(obj)) {
|
|
26601
27374
|
if (rest.length === 0) {
|
|
@@ -26613,7 +27386,7 @@ function injectUrls(obj, path7, idToUrlMapping) {
|
|
|
26613
27386
|
}
|
|
26614
27387
|
if (obj && typeof obj === "object") {
|
|
26615
27388
|
const record = obj;
|
|
26616
|
-
if (
|
|
27389
|
+
if (path8.length === 1) {
|
|
26617
27390
|
const fieldValue = record[key];
|
|
26618
27391
|
const id = toId(fieldValue);
|
|
26619
27392
|
if (id !== void 0) {
|
|
@@ -26673,8 +27446,8 @@ function loadApiKeyFromEnv(provider, logger) {
|
|
|
26673
27446
|
}
|
|
26674
27447
|
return void 0;
|
|
26675
27448
|
}
|
|
26676
|
-
function trimTrailingTextNode(
|
|
26677
|
-
return
|
|
27449
|
+
function trimTrailingTextNode(path8) {
|
|
27450
|
+
return path8 == null ? void 0 : path8.replace(/\/text\(\)(\[\d+\])?$/iu, "");
|
|
26678
27451
|
}
|
|
26679
27452
|
function jsonSchemaToZod(schema) {
|
|
26680
27453
|
switch (schema.type) {
|
|
@@ -27058,12 +27831,12 @@ var ActCache = class {
|
|
|
27058
27831
|
const {
|
|
27059
27832
|
value: entry,
|
|
27060
27833
|
error,
|
|
27061
|
-
path:
|
|
27834
|
+
path: path8
|
|
27062
27835
|
} = yield this.storage.readJson(`${context.cacheKey}.json`);
|
|
27063
|
-
if (error &&
|
|
27836
|
+
if (error && path8) {
|
|
27064
27837
|
this.logger({
|
|
27065
27838
|
category: "cache",
|
|
27066
|
-
message: `failed to read act cache entry: ${
|
|
27839
|
+
message: `failed to read act cache entry: ${path8}`,
|
|
27067
27840
|
level: 2,
|
|
27068
27841
|
auxiliary: {
|
|
27069
27842
|
error: { value: String(error), type: "string" }
|
|
@@ -27104,11 +27877,11 @@ var ActCache = class {
|
|
|
27104
27877
|
actionDescription: result.actionDescription,
|
|
27105
27878
|
message: result.message
|
|
27106
27879
|
};
|
|
27107
|
-
const { error, path:
|
|
27880
|
+
const { error, path: path8 } = yield this.storage.writeJson(
|
|
27108
27881
|
`${context.cacheKey}.json`,
|
|
27109
27882
|
entry
|
|
27110
27883
|
);
|
|
27111
|
-
if (error &&
|
|
27884
|
+
if (error && path8) {
|
|
27112
27885
|
this.logger({
|
|
27113
27886
|
category: "cache",
|
|
27114
27887
|
message: "failed to write act cache entry",
|
|
@@ -27226,11 +27999,11 @@ var ActCache = class {
|
|
|
27226
27999
|
}
|
|
27227
28000
|
refreshCacheEntry(context, entry) {
|
|
27228
28001
|
return __async(this, null, function* () {
|
|
27229
|
-
const { error, path:
|
|
28002
|
+
const { error, path: path8 } = yield this.storage.writeJson(
|
|
27230
28003
|
`${context.cacheKey}.json`,
|
|
27231
28004
|
entry
|
|
27232
28005
|
);
|
|
27233
|
-
if (error &&
|
|
28006
|
+
if (error && path8) {
|
|
27234
28007
|
this.logger({
|
|
27235
28008
|
category: "cache",
|
|
27236
28009
|
message: "failed to update act cache entry after self-heal",
|
|
@@ -27372,14 +28145,14 @@ var AgentCache = class {
|
|
|
27372
28145
|
const {
|
|
27373
28146
|
value: entry,
|
|
27374
28147
|
error,
|
|
27375
|
-
path:
|
|
28148
|
+
path: path8
|
|
27376
28149
|
} = yield this.storage.readJson(
|
|
27377
28150
|
`agent-${context.cacheKey}.json`
|
|
27378
28151
|
);
|
|
27379
|
-
if (error &&
|
|
28152
|
+
if (error && path8) {
|
|
27380
28153
|
this.logger({
|
|
27381
28154
|
category: "cache",
|
|
27382
|
-
message: `failed to read agent cache entry: ${
|
|
28155
|
+
message: `failed to read agent cache entry: ${path8}`,
|
|
27383
28156
|
level: 1,
|
|
27384
28157
|
auxiliary: {
|
|
27385
28158
|
error: { value: String(error), type: "string" }
|
|
@@ -27527,11 +28300,11 @@ var AgentCache = class {
|
|
|
27527
28300
|
result: cloneForCache(result),
|
|
27528
28301
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
27529
28302
|
};
|
|
27530
|
-
const { error, path:
|
|
28303
|
+
const { error, path: path8 } = yield this.storage.writeJson(
|
|
27531
28304
|
`agent-${context.cacheKey}.json`,
|
|
27532
28305
|
entry
|
|
27533
28306
|
);
|
|
27534
|
-
if (error &&
|
|
28307
|
+
if (error && path8) {
|
|
27535
28308
|
this.logger({
|
|
27536
28309
|
category: "cache",
|
|
27537
28310
|
message: "failed to write agent cache entry",
|
|
@@ -28531,6 +29304,7 @@ var SupportedPlaywrightAction = /* @__PURE__ */ ((SupportedPlaywrightAction2) =>
|
|
|
28531
29304
|
// lib/v3/handlers/handlerUtils/actHandlerUtils.ts
|
|
28532
29305
|
init_deepLocator();
|
|
28533
29306
|
init_logger();
|
|
29307
|
+
init_flowLogger();
|
|
28534
29308
|
init_sdkErrors();
|
|
28535
29309
|
var UnderstudyCommandException = class extends Error {
|
|
28536
29310
|
constructor(message) {
|
|
@@ -28574,6 +29348,11 @@ function performUnderstudyMethod(page, frame, method, rawXPath, args, domSettleT
|
|
|
28574
29348
|
initialUrl,
|
|
28575
29349
|
domSettleTimeoutMs
|
|
28576
29350
|
};
|
|
29351
|
+
SessionFileLogger.logUnderstudyActionEvent({
|
|
29352
|
+
actionType: `Understudy.${method}`,
|
|
29353
|
+
target: selectorRaw,
|
|
29354
|
+
args: Array.from(args)
|
|
29355
|
+
});
|
|
28577
29356
|
try {
|
|
28578
29357
|
const handler = (_a4 = METHOD_HANDLER_MAP[method]) != null ? _a4 : null;
|
|
28579
29358
|
if (handler) {
|
|
@@ -28618,6 +29397,8 @@ function performUnderstudyMethod(page, frame, method, rawXPath, args, domSettleT
|
|
|
28618
29397
|
}
|
|
28619
29398
|
});
|
|
28620
29399
|
throw new UnderstudyCommandException(msg);
|
|
29400
|
+
} finally {
|
|
29401
|
+
SessionFileLogger.logUnderstudyActionCompleted();
|
|
28621
29402
|
}
|
|
28622
29403
|
});
|
|
28623
29404
|
}
|
|
@@ -30251,6 +31032,9 @@ function calculateCompressionStats(originalSize, compressedSize, screenshotCount
|
|
|
30251
31032
|
};
|
|
30252
31033
|
}
|
|
30253
31034
|
|
|
31035
|
+
// lib/v3/handlers/v3AgentHandler.ts
|
|
31036
|
+
init_flowLogger();
|
|
31037
|
+
|
|
30254
31038
|
// lib/v3/agent/utils/actionMapping.ts
|
|
30255
31039
|
function mapToolResultToActions({
|
|
30256
31040
|
toolCallName,
|
|
@@ -30351,12 +31135,12 @@ var V3AgentHandler = class {
|
|
|
30351
31135
|
const baseModel = this.llmClient.getLanguageModel();
|
|
30352
31136
|
const wrappedModel = (0, import_ai11.wrapLanguageModel)({
|
|
30353
31137
|
model: baseModel,
|
|
30354
|
-
middleware: {
|
|
31138
|
+
middleware: __spreadValues({
|
|
30355
31139
|
transformParams: (_0) => __async(this, [_0], function* ({ params }) {
|
|
30356
31140
|
const { processedPrompt } = processMessages(params);
|
|
30357
31141
|
return __spreadProps(__spreadValues({}, params), { prompt: processedPrompt });
|
|
30358
31142
|
})
|
|
30359
|
-
}
|
|
31143
|
+
}, SessionFileLogger.createLlmLoggingMiddleware(baseModel.modelId))
|
|
30360
31144
|
});
|
|
30361
31145
|
const initialPageUrl = (yield this.v3.context.awaitActivePage()).url();
|
|
30362
31146
|
return {
|
|
@@ -30801,6 +31585,8 @@ function compressGoogleConversationImages(items, keepMostRecentCount = 2) {
|
|
|
30801
31585
|
}
|
|
30802
31586
|
|
|
30803
31587
|
// lib/v3/agent/AnthropicCUAClient.ts
|
|
31588
|
+
init_flowLogger();
|
|
31589
|
+
var import_uuid2 = require("uuid");
|
|
30804
31590
|
var AnthropicCUAClient = class extends AgentClient {
|
|
30805
31591
|
constructor(type, modelName, userProvidedInstructions, clientOptions, tools) {
|
|
30806
31592
|
super(type, modelName, userProvidedInstructions);
|
|
@@ -31119,6 +31905,13 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
31119
31905
|
if (thinking) {
|
|
31120
31906
|
requestParams.thinking = thinking;
|
|
31121
31907
|
}
|
|
31908
|
+
const llmRequestId = (0, import_uuid2.v7)();
|
|
31909
|
+
SessionFileLogger.logLlmRequest({
|
|
31910
|
+
requestId: llmRequestId,
|
|
31911
|
+
model: this.modelName,
|
|
31912
|
+
operation: "CUA.getAction",
|
|
31913
|
+
prompt: formatCuaPromptPreview(messages)
|
|
31914
|
+
});
|
|
31122
31915
|
const startTime = Date.now();
|
|
31123
31916
|
const response = yield this.client.beta.messages.create(requestParams);
|
|
31124
31917
|
const endTime = Date.now();
|
|
@@ -31128,6 +31921,14 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
31128
31921
|
output_tokens: response.usage.output_tokens,
|
|
31129
31922
|
inference_time_ms: elapsedMs
|
|
31130
31923
|
};
|
|
31924
|
+
SessionFileLogger.logLlmResponse({
|
|
31925
|
+
requestId: llmRequestId,
|
|
31926
|
+
model: this.modelName,
|
|
31927
|
+
operation: "CUA.getAction",
|
|
31928
|
+
output: formatCuaResponsePreview(response.content),
|
|
31929
|
+
inputTokens: response.usage.input_tokens,
|
|
31930
|
+
outputTokens: response.usage.output_tokens
|
|
31931
|
+
});
|
|
31131
31932
|
this.lastMessageId = response.id;
|
|
31132
31933
|
return {
|
|
31133
31934
|
// Cast the response content to our internal type
|
|
@@ -31406,7 +32207,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
31406
32207
|
y
|
|
31407
32208
|
}, input);
|
|
31408
32209
|
} else if (action === "drag" || action === "left_click_drag") {
|
|
31409
|
-
const
|
|
32210
|
+
const path8 = input.path || (input.coordinate ? [
|
|
31410
32211
|
{
|
|
31411
32212
|
x: input.start_coordinate[0],
|
|
31412
32213
|
y: input.start_coordinate[1]
|
|
@@ -31418,7 +32219,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
31418
32219
|
] : []);
|
|
31419
32220
|
return __spreadValues({
|
|
31420
32221
|
type: "drag",
|
|
31421
|
-
path:
|
|
32222
|
+
path: path8
|
|
31422
32223
|
}, input);
|
|
31423
32224
|
} else if (action === "wait") {
|
|
31424
32225
|
return __spreadValues({
|
|
@@ -31478,6 +32279,8 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
31478
32279
|
// lib/v3/agent/OpenAICUAClient.ts
|
|
31479
32280
|
var import_openai = __toESM(require("openai"));
|
|
31480
32281
|
init_sdkErrors();
|
|
32282
|
+
init_flowLogger();
|
|
32283
|
+
var import_uuid3 = require("uuid");
|
|
31481
32284
|
var OpenAICUAClient = class extends AgentClient {
|
|
31482
32285
|
constructor(type, modelName, userProvidedInstructions, clientOptions, tools) {
|
|
31483
32286
|
super(type, modelName, userProvidedInstructions);
|
|
@@ -31750,6 +32553,13 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
31750
32553
|
if (previousResponseId) {
|
|
31751
32554
|
requestParams.previous_response_id = previousResponseId;
|
|
31752
32555
|
}
|
|
32556
|
+
const llmRequestId = (0, import_uuid3.v7)();
|
|
32557
|
+
SessionFileLogger.logLlmRequest({
|
|
32558
|
+
requestId: llmRequestId,
|
|
32559
|
+
model: this.modelName,
|
|
32560
|
+
operation: "CUA.getAction",
|
|
32561
|
+
prompt: formatCuaPromptPreview(inputItems)
|
|
32562
|
+
});
|
|
31753
32563
|
const startTime = Date.now();
|
|
31754
32564
|
const response = yield this.client.responses.create(requestParams);
|
|
31755
32565
|
const endTime = Date.now();
|
|
@@ -31759,6 +32569,14 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
31759
32569
|
output_tokens: response.usage.output_tokens,
|
|
31760
32570
|
inference_time_ms: elapsedMs
|
|
31761
32571
|
};
|
|
32572
|
+
SessionFileLogger.logLlmResponse({
|
|
32573
|
+
requestId: llmRequestId,
|
|
32574
|
+
model: this.modelName,
|
|
32575
|
+
operation: "CUA.getAction",
|
|
32576
|
+
output: formatCuaResponsePreview(response.output),
|
|
32577
|
+
inputTokens: response.usage.input_tokens,
|
|
32578
|
+
outputTokens: response.usage.output_tokens
|
|
32579
|
+
});
|
|
31762
32580
|
this.lastResponseId = response.id;
|
|
31763
32581
|
return {
|
|
31764
32582
|
output: response.output,
|
|
@@ -32127,6 +32945,8 @@ function mapJsonTypeToGoogleType(jsonType) {
|
|
|
32127
32945
|
}
|
|
32128
32946
|
|
|
32129
32947
|
// lib/v3/agent/GoogleCUAClient.ts
|
|
32948
|
+
init_flowLogger();
|
|
32949
|
+
var import_uuid4 = require("uuid");
|
|
32130
32950
|
var GoogleCUAClient = class extends AgentClient {
|
|
32131
32951
|
constructor(type, modelName, userProvidedInstructions, clientOptions, tools) {
|
|
32132
32952
|
super(type, modelName, userProvidedInstructions);
|
|
@@ -32308,6 +33128,13 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
32308
33128
|
const baseDelayS = 1;
|
|
32309
33129
|
let lastError = null;
|
|
32310
33130
|
let response = null;
|
|
33131
|
+
const llmRequestId = (0, import_uuid4.v7)();
|
|
33132
|
+
SessionFileLogger.logLlmRequest({
|
|
33133
|
+
requestId: llmRequestId,
|
|
33134
|
+
model: this.modelName,
|
|
33135
|
+
operation: "CUA.generateContent",
|
|
33136
|
+
prompt: formatCuaPromptPreview(compressedHistory)
|
|
33137
|
+
});
|
|
32311
33138
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
32312
33139
|
try {
|
|
32313
33140
|
if (attempt > 0) {
|
|
@@ -32351,6 +33178,14 @@ var GoogleCUAClient = class extends AgentClient {
|
|
|
32351
33178
|
const endTime = Date.now();
|
|
32352
33179
|
const elapsedMs = endTime - startTime;
|
|
32353
33180
|
const { usageMetadata } = response;
|
|
33181
|
+
SessionFileLogger.logLlmResponse({
|
|
33182
|
+
requestId: llmRequestId,
|
|
33183
|
+
model: this.modelName,
|
|
33184
|
+
operation: "CUA.generateContent",
|
|
33185
|
+
output: formatCuaResponsePreview(response),
|
|
33186
|
+
inputTokens: usageMetadata == null ? void 0 : usageMetadata.promptTokenCount,
|
|
33187
|
+
outputTokens: usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount
|
|
33188
|
+
});
|
|
32354
33189
|
const result = yield this.processResponse(response, logger);
|
|
32355
33190
|
if (response.candidates && response.candidates[0]) {
|
|
32356
33191
|
const sanitizedContent = JSON.parse(
|
|
@@ -33543,6 +34378,7 @@ var AgentProvider = class _AgentProvider {
|
|
|
33543
34378
|
};
|
|
33544
34379
|
|
|
33545
34380
|
// lib/v3/handlers/v3CuaAgentHandler.ts
|
|
34381
|
+
init_flowLogger();
|
|
33546
34382
|
var V3CuaAgentHandler = class {
|
|
33547
34383
|
constructor(v3, logger, options, tools) {
|
|
33548
34384
|
this.v3 = v3;
|
|
@@ -33578,7 +34414,19 @@ var V3CuaAgentHandler = class {
|
|
|
33578
34414
|
}
|
|
33579
34415
|
}
|
|
33580
34416
|
yield new Promise((r2) => setTimeout(r2, 300));
|
|
33581
|
-
|
|
34417
|
+
const shouldLog = action.type !== "screenshot";
|
|
34418
|
+
if (shouldLog) {
|
|
34419
|
+
SessionFileLogger.logUnderstudyActionEvent({
|
|
34420
|
+
actionType: `v3CUA.${action.type}`,
|
|
34421
|
+
target: this.computePointerTarget(action),
|
|
34422
|
+
args: [action]
|
|
34423
|
+
});
|
|
34424
|
+
}
|
|
34425
|
+
try {
|
|
34426
|
+
yield this.executeAction(action);
|
|
34427
|
+
} finally {
|
|
34428
|
+
if (shouldLog) SessionFileLogger.logUnderstudyActionCompleted();
|
|
34429
|
+
}
|
|
33582
34430
|
action.timestamp = Date.now();
|
|
33583
34431
|
yield new Promise((r2) => setTimeout(r2, waitBetween));
|
|
33584
34432
|
try {
|
|
@@ -33808,13 +34656,13 @@ var V3CuaAgentHandler = class {
|
|
|
33808
34656
|
return { success: true };
|
|
33809
34657
|
}
|
|
33810
34658
|
case "drag": {
|
|
33811
|
-
const { path:
|
|
33812
|
-
if (Array.isArray(
|
|
33813
|
-
const start =
|
|
33814
|
-
const end =
|
|
34659
|
+
const { path: path8 } = action;
|
|
34660
|
+
if (Array.isArray(path8) && path8.length >= 2) {
|
|
34661
|
+
const start = path8[0];
|
|
34662
|
+
const end = path8[path8.length - 1];
|
|
33815
34663
|
if (recording) {
|
|
33816
34664
|
const xps = yield page.dragAndDrop(start.x, start.y, end.x, end.y, {
|
|
33817
|
-
steps: Math.min(20, Math.max(5,
|
|
34665
|
+
steps: Math.min(20, Math.max(5, path8.length)),
|
|
33818
34666
|
delay: 10,
|
|
33819
34667
|
returnXpath: true
|
|
33820
34668
|
});
|
|
@@ -33836,7 +34684,7 @@ var V3CuaAgentHandler = class {
|
|
|
33836
34684
|
}
|
|
33837
34685
|
} else {
|
|
33838
34686
|
yield page.dragAndDrop(start.x, start.y, end.x, end.y, {
|
|
33839
|
-
steps: Math.min(20, Math.max(5,
|
|
34687
|
+
steps: Math.min(20, Math.max(5, path8.length)),
|
|
33840
34688
|
delay: 10
|
|
33841
34689
|
});
|
|
33842
34690
|
}
|
|
@@ -33905,6 +34753,10 @@ var V3CuaAgentHandler = class {
|
|
|
33905
34753
|
}
|
|
33906
34754
|
});
|
|
33907
34755
|
}
|
|
34756
|
+
// helper to make pointer target human-readable for logging
|
|
34757
|
+
computePointerTarget(action) {
|
|
34758
|
+
return typeof action.x === "number" && typeof action.y === "number" ? `(${action.x}, ${action.y})` : typeof action.selector === "string" ? action.selector : typeof action.input === "string" ? action.input : typeof action.description === "string" ? action.description : void 0;
|
|
34759
|
+
}
|
|
33908
34760
|
ensureXPath(value) {
|
|
33909
34761
|
if (typeof value !== "string") return null;
|
|
33910
34762
|
const trimmed = value.trim();
|
|
@@ -34072,7 +34924,7 @@ function createBrowserbaseSession(apiKey, projectId, params, resumeSessionId) {
|
|
|
34072
34924
|
}
|
|
34073
34925
|
|
|
34074
34926
|
// ../../node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/chrome-launcher.js
|
|
34075
|
-
var
|
|
34927
|
+
var fs7 = __toESM(require("fs"), 1);
|
|
34076
34928
|
var net = __toESM(require("net"), 1);
|
|
34077
34929
|
|
|
34078
34930
|
// ../../node_modules/.pnpm/chrome-launcher@1.2.0/node_modules/chrome-launcher/dist/chrome-finder.js
|
|
@@ -34519,15 +35371,15 @@ function toWSLPath(dir, fallback) {
|
|
|
34519
35371
|
return fallback;
|
|
34520
35372
|
}
|
|
34521
35373
|
}
|
|
34522
|
-
function getLocalAppDataPath(
|
|
35374
|
+
function getLocalAppDataPath(path8) {
|
|
34523
35375
|
const userRegExp = /\/mnt\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
|
|
34524
|
-
const results = userRegExp.exec(
|
|
35376
|
+
const results = userRegExp.exec(path8) || [];
|
|
34525
35377
|
return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local`;
|
|
34526
35378
|
}
|
|
34527
|
-
function getWSLLocalAppDataPath(
|
|
35379
|
+
function getWSLLocalAppDataPath(path8) {
|
|
34528
35380
|
const userRegExp = /\/([a-z])\/Users\/([^\/:]+)\/AppData\//;
|
|
34529
|
-
const results = userRegExp.exec(
|
|
34530
|
-
return toWSLPath(`${results[1]}:\\Users\\${results[2]}\\AppData\\Local`, getLocalAppDataPath(
|
|
35381
|
+
const results = userRegExp.exec(path8) || [];
|
|
35382
|
+
return toWSLPath(`${results[1]}:\\Users\\${results[2]}\\AppData\\Local`, getLocalAppDataPath(path8));
|
|
34531
35383
|
}
|
|
34532
35384
|
function makeUnixTmpDir() {
|
|
34533
35385
|
return import_child_process.default.execSync("mktemp -d -t lighthouse.XXXXXXX").toString().trim();
|
|
@@ -34852,7 +35704,7 @@ var Launcher = class _Launcher {
|
|
|
34852
35704
|
this.opts = opts;
|
|
34853
35705
|
this.tmpDirandPidFileReady = false;
|
|
34854
35706
|
this.remoteDebuggingPipes = null;
|
|
34855
|
-
this.fs = moduleOverrides.fs ||
|
|
35707
|
+
this.fs = moduleOverrides.fs || fs7;
|
|
34856
35708
|
this.spawn = moduleOverrides.spawn || import_child_process3.spawn;
|
|
34857
35709
|
lighthouse_logger_default.setLevel(defaults(this.opts.logLevel, "silent"));
|
|
34858
35710
|
this.startingUrl = defaults(this.opts.startingUrl, "about:blank");
|
|
@@ -35170,6 +36022,7 @@ init_sdkErrors();
|
|
|
35170
36022
|
|
|
35171
36023
|
// lib/v3/llm/aisdk.ts
|
|
35172
36024
|
var import_ai13 = require("ai");
|
|
36025
|
+
var import_uuid5 = require("uuid");
|
|
35173
36026
|
|
|
35174
36027
|
// lib/v3/llm/LLMClient.ts
|
|
35175
36028
|
var import_ai12 = require("ai");
|
|
@@ -35191,6 +36044,7 @@ var LLMClient = class {
|
|
|
35191
36044
|
};
|
|
35192
36045
|
|
|
35193
36046
|
// lib/v3/llm/aisdk.ts
|
|
36047
|
+
init_flowLogger();
|
|
35194
36048
|
var AISdkClient = class extends LLMClient {
|
|
35195
36049
|
constructor({
|
|
35196
36050
|
model,
|
|
@@ -35284,6 +36138,16 @@ var AISdkClient = class extends LLMClient {
|
|
|
35284
36138
|
const isGPT5 = this.model.modelId.includes("gpt-5");
|
|
35285
36139
|
const isGPT51 = this.model.modelId.includes("gpt-5.1");
|
|
35286
36140
|
if (options.response_model) {
|
|
36141
|
+
const llmRequestId2 = (0, import_uuid5.v7)();
|
|
36142
|
+
const promptPreview2 = formatLlmPromptPreview(options.messages, {
|
|
36143
|
+
hasSchema: true
|
|
36144
|
+
});
|
|
36145
|
+
SessionFileLogger.logLlmRequest({
|
|
36146
|
+
requestId: llmRequestId2,
|
|
36147
|
+
model: this.model.modelId,
|
|
36148
|
+
operation: "generateObject",
|
|
36149
|
+
prompt: promptPreview2
|
|
36150
|
+
});
|
|
35287
36151
|
try {
|
|
35288
36152
|
objectResponse = yield (0, import_ai13.generateObject)({
|
|
35289
36153
|
model: this.model,
|
|
@@ -35299,6 +36163,12 @@ var AISdkClient = class extends LLMClient {
|
|
|
35299
36163
|
} : void 0
|
|
35300
36164
|
});
|
|
35301
36165
|
} catch (err) {
|
|
36166
|
+
SessionFileLogger.logLlmResponse({
|
|
36167
|
+
requestId: llmRequestId2,
|
|
36168
|
+
model: this.model.modelId,
|
|
36169
|
+
operation: "generateObject",
|
|
36170
|
+
output: `[error: ${err instanceof Error ? err.message : "unknown"}]`
|
|
36171
|
+
});
|
|
35302
36172
|
if (import_ai13.NoObjectGeneratedError.isInstance(err)) {
|
|
35303
36173
|
(_g = this.logger) == null ? void 0 : _g.call(this, {
|
|
35304
36174
|
category: "AISDK error",
|
|
@@ -35345,6 +36215,14 @@ var AISdkClient = class extends LLMClient {
|
|
|
35345
36215
|
total_tokens: (_l = objectResponse.usage.totalTokens) != null ? _l : 0
|
|
35346
36216
|
}
|
|
35347
36217
|
};
|
|
36218
|
+
SessionFileLogger.logLlmResponse({
|
|
36219
|
+
requestId: llmRequestId2,
|
|
36220
|
+
model: this.model.modelId,
|
|
36221
|
+
operation: "generateObject",
|
|
36222
|
+
output: JSON.stringify(objectResponse.object),
|
|
36223
|
+
inputTokens: objectResponse.usage.inputTokens,
|
|
36224
|
+
outputTokens: objectResponse.usage.outputTokens
|
|
36225
|
+
});
|
|
35348
36226
|
(_m = this.logger) == null ? void 0 : _m.call(this, {
|
|
35349
36227
|
category: "aisdk",
|
|
35350
36228
|
message: "response",
|
|
@@ -35376,13 +36254,35 @@ var AISdkClient = class extends LLMClient {
|
|
|
35376
36254
|
};
|
|
35377
36255
|
}
|
|
35378
36256
|
}
|
|
35379
|
-
const
|
|
35380
|
-
|
|
35381
|
-
|
|
35382
|
-
|
|
35383
|
-
toolChoice: Object.keys(tools).length > 0 ? options.tool_choice === "required" ? "required" : options.tool_choice === "none" ? "none" : "auto" : void 0,
|
|
35384
|
-
temperature: options.temperature
|
|
36257
|
+
const llmRequestId = (0, import_uuid5.v7)();
|
|
36258
|
+
const toolCount = Object.keys(tools).length;
|
|
36259
|
+
const promptPreview = formatLlmPromptPreview(options.messages, {
|
|
36260
|
+
toolCount
|
|
35385
36261
|
});
|
|
36262
|
+
SessionFileLogger.logLlmRequest({
|
|
36263
|
+
requestId: llmRequestId,
|
|
36264
|
+
model: this.model.modelId,
|
|
36265
|
+
operation: "generateText",
|
|
36266
|
+
prompt: promptPreview
|
|
36267
|
+
});
|
|
36268
|
+
let textResponse;
|
|
36269
|
+
try {
|
|
36270
|
+
textResponse = yield (0, import_ai13.generateText)({
|
|
36271
|
+
model: this.model,
|
|
36272
|
+
messages: formattedMessages,
|
|
36273
|
+
tools: Object.keys(tools).length > 0 ? tools : void 0,
|
|
36274
|
+
toolChoice: Object.keys(tools).length > 0 ? options.tool_choice === "required" ? "required" : options.tool_choice === "none" ? "none" : "auto" : void 0,
|
|
36275
|
+
temperature: options.temperature
|
|
36276
|
+
});
|
|
36277
|
+
} catch (err) {
|
|
36278
|
+
SessionFileLogger.logLlmResponse({
|
|
36279
|
+
requestId: llmRequestId,
|
|
36280
|
+
model: this.model.modelId,
|
|
36281
|
+
operation: "generateText",
|
|
36282
|
+
output: `[error: ${err instanceof Error ? err.message : "unknown"}]`
|
|
36283
|
+
});
|
|
36284
|
+
throw err;
|
|
36285
|
+
}
|
|
35386
36286
|
const transformedToolCalls = (textResponse.toolCalls || []).map(
|
|
35387
36287
|
(toolCall) => ({
|
|
35388
36288
|
id: toolCall.toolCallId || `call_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
@@ -35417,6 +36317,14 @@ var AISdkClient = class extends LLMClient {
|
|
|
35417
36317
|
total_tokens: (_r = textResponse.usage.totalTokens) != null ? _r : 0
|
|
35418
36318
|
}
|
|
35419
36319
|
};
|
|
36320
|
+
SessionFileLogger.logLlmResponse({
|
|
36321
|
+
requestId: llmRequestId,
|
|
36322
|
+
model: this.model.modelId,
|
|
36323
|
+
operation: "generateText",
|
|
36324
|
+
output: textResponse.text || (transformedToolCalls.length > 0 ? `[${transformedToolCalls.length} tool calls]` : ""),
|
|
36325
|
+
inputTokens: textResponse.usage.inputTokens,
|
|
36326
|
+
outputTokens: textResponse.usage.outputTokens
|
|
36327
|
+
});
|
|
35420
36328
|
(_s = this.logger) == null ? void 0 : _s.call(this, {
|
|
35421
36329
|
category: "aisdk",
|
|
35422
36330
|
message: "response",
|
|
@@ -43213,37 +44121,37 @@ function createOpenAI(options = {}) {
|
|
|
43213
44121
|
);
|
|
43214
44122
|
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
43215
44123
|
provider: `${providerName}.chat`,
|
|
43216
|
-
url: ({ path:
|
|
44124
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43217
44125
|
headers: getHeaders,
|
|
43218
44126
|
fetch: options.fetch
|
|
43219
44127
|
});
|
|
43220
44128
|
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
43221
44129
|
provider: `${providerName}.completion`,
|
|
43222
|
-
url: ({ path:
|
|
44130
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43223
44131
|
headers: getHeaders,
|
|
43224
44132
|
fetch: options.fetch
|
|
43225
44133
|
});
|
|
43226
44134
|
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
43227
44135
|
provider: `${providerName}.embedding`,
|
|
43228
|
-
url: ({ path:
|
|
44136
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43229
44137
|
headers: getHeaders,
|
|
43230
44138
|
fetch: options.fetch
|
|
43231
44139
|
});
|
|
43232
44140
|
const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
|
|
43233
44141
|
provider: `${providerName}.image`,
|
|
43234
|
-
url: ({ path:
|
|
44142
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43235
44143
|
headers: getHeaders,
|
|
43236
44144
|
fetch: options.fetch
|
|
43237
44145
|
});
|
|
43238
44146
|
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
43239
44147
|
provider: `${providerName}.transcription`,
|
|
43240
|
-
url: ({ path:
|
|
44148
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43241
44149
|
headers: getHeaders,
|
|
43242
44150
|
fetch: options.fetch
|
|
43243
44151
|
});
|
|
43244
44152
|
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
43245
44153
|
provider: `${providerName}.speech`,
|
|
43246
|
-
url: ({ path:
|
|
44154
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43247
44155
|
headers: getHeaders,
|
|
43248
44156
|
fetch: options.fetch
|
|
43249
44157
|
});
|
|
@@ -43258,7 +44166,7 @@ function createOpenAI(options = {}) {
|
|
|
43258
44166
|
const createResponsesModel = (modelId) => {
|
|
43259
44167
|
return new OpenAIResponsesLanguageModel(modelId, {
|
|
43260
44168
|
provider: `${providerName}.responses`,
|
|
43261
|
-
url: ({ path:
|
|
44169
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
43262
44170
|
headers: getHeaders,
|
|
43263
44171
|
fetch: options.fetch,
|
|
43264
44172
|
fileIdPrefixes: ["file-"]
|
|
@@ -53437,7 +54345,7 @@ function createXai(options = {}) {
|
|
|
53437
54345
|
const createImageModel = (modelId) => {
|
|
53438
54346
|
return new OpenAICompatibleImageModel(modelId, {
|
|
53439
54347
|
provider: "xai.image",
|
|
53440
|
-
url: ({ path:
|
|
54348
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
53441
54349
|
headers: getHeaders,
|
|
53442
54350
|
fetch: options.fetch,
|
|
53443
54351
|
errorStructure: xaiErrorStructure
|
|
@@ -57704,14 +58612,14 @@ function createAzure(options = {}) {
|
|
|
57704
58612
|
description: "Azure OpenAI resource name"
|
|
57705
58613
|
});
|
|
57706
58614
|
const apiVersion = (_a4 = options.apiVersion) != null ? _a4 : "v1";
|
|
57707
|
-
const url = ({ path:
|
|
58615
|
+
const url = ({ path: path8, modelId }) => {
|
|
57708
58616
|
var _a22;
|
|
57709
58617
|
const baseUrlPrefix = (_a22 = options.baseURL) != null ? _a22 : `https://${getResourceName()}.openai.azure.com/openai`;
|
|
57710
58618
|
let fullUrl;
|
|
57711
58619
|
if (options.useDeploymentBasedUrls) {
|
|
57712
|
-
fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${
|
|
58620
|
+
fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path8}`);
|
|
57713
58621
|
} else {
|
|
57714
|
-
fullUrl = new URL(`${baseUrlPrefix}/v1${
|
|
58622
|
+
fullUrl = new URL(`${baseUrlPrefix}/v1${path8}`);
|
|
57715
58623
|
}
|
|
57716
58624
|
fullUrl.searchParams.set("api-version", apiVersion);
|
|
57717
58625
|
return fullUrl.toString();
|
|
@@ -58627,7 +59535,7 @@ function createGroq(options = {}) {
|
|
|
58627
59535
|
);
|
|
58628
59536
|
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
58629
59537
|
provider: "groq.chat",
|
|
58630
|
-
url: ({ path:
|
|
59538
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
58631
59539
|
headers: getHeaders,
|
|
58632
59540
|
fetch: options.fetch
|
|
58633
59541
|
});
|
|
@@ -58642,7 +59550,7 @@ function createGroq(options = {}) {
|
|
|
58642
59550
|
const createTranscriptionModel = (modelId) => {
|
|
58643
59551
|
return new GroqTranscriptionModel(modelId, {
|
|
58644
59552
|
provider: "groq.transcription",
|
|
58645
|
-
url: ({ path:
|
|
59553
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
58646
59554
|
headers: getHeaders,
|
|
58647
59555
|
fetch: options.fetch
|
|
58648
59556
|
});
|
|
@@ -58697,7 +59605,7 @@ function createCerebras(options = {}) {
|
|
|
58697
59605
|
const createLanguageModel = (modelId) => {
|
|
58698
59606
|
return new OpenAICompatibleChatLanguageModel(modelId, {
|
|
58699
59607
|
provider: `cerebras.chat`,
|
|
58700
|
-
url: ({ path:
|
|
59608
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
58701
59609
|
headers: getHeaders,
|
|
58702
59610
|
fetch: options.fetch,
|
|
58703
59611
|
errorStructure: cerebrasErrorStructure,
|
|
@@ -58816,7 +59724,7 @@ function createTogetherAI(options = {}) {
|
|
|
58816
59724
|
);
|
|
58817
59725
|
const getCommonModelConfig = (modelType) => ({
|
|
58818
59726
|
provider: `togetherai.${modelType}`,
|
|
58819
|
-
url: ({ path:
|
|
59727
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
58820
59728
|
headers: getHeaders,
|
|
58821
59729
|
fetch: options.fetch
|
|
58822
59730
|
});
|
|
@@ -59702,7 +60610,7 @@ function createDeepSeek(options = {}) {
|
|
|
59702
60610
|
const createLanguageModel = (modelId) => {
|
|
59703
60611
|
return new OpenAICompatibleChatLanguageModel(modelId, {
|
|
59704
60612
|
provider: `deepseek.chat`,
|
|
59705
|
-
url: ({ path:
|
|
60613
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
59706
60614
|
headers: getHeaders,
|
|
59707
60615
|
fetch: options.fetch,
|
|
59708
60616
|
metadataExtractor: deepSeekMetadataExtractor
|
|
@@ -61412,13 +62320,13 @@ function createOllama(options = {}) {
|
|
|
61412
62320
|
}, options.headers);
|
|
61413
62321
|
const createCompletionModel = (modelId, settings = {}) => new OllamaCompletionLanguageModel(modelId, settings, {
|
|
61414
62322
|
provider: `${providerName}.completion`,
|
|
61415
|
-
url: ({ path:
|
|
62323
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
61416
62324
|
headers: getHeaders,
|
|
61417
62325
|
fetch: options.fetch
|
|
61418
62326
|
});
|
|
61419
62327
|
const createEmbeddingModel = (modelId, settings = {}) => new OllamaEmbeddingModel(modelId, settings, {
|
|
61420
62328
|
provider: `${providerName}.embedding`,
|
|
61421
|
-
url: ({ path:
|
|
62329
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
61422
62330
|
headers: getHeaders,
|
|
61423
62331
|
fetch: options.fetch
|
|
61424
62332
|
});
|
|
@@ -61433,7 +62341,7 @@ function createOllama(options = {}) {
|
|
|
61433
62341
|
const createResponsesModel = (modelId) => {
|
|
61434
62342
|
return new OllamaResponsesLanguageModel(modelId, {
|
|
61435
62343
|
provider: `${providerName}.responses`,
|
|
61436
|
-
url: ({ path:
|
|
62344
|
+
url: ({ path: path8 }) => `${baseURL}${path8}`,
|
|
61437
62345
|
headers: getHeaders,
|
|
61438
62346
|
fetch: options.fetch
|
|
61439
62347
|
});
|
|
@@ -61875,6 +62783,8 @@ var CdpConnection = class _CdpConnection {
|
|
|
61875
62783
|
this.inflight = /* @__PURE__ */ new Map();
|
|
61876
62784
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
61877
62785
|
this.sessions = /* @__PURE__ */ new Map();
|
|
62786
|
+
/** Maps sessionId -> targetId (1:1 mapping) */
|
|
62787
|
+
this.sessionToTarget = /* @__PURE__ */ new Map();
|
|
61878
62788
|
this.id = null;
|
|
61879
62789
|
// root
|
|
61880
62790
|
this.transportCloseHandlers = /* @__PURE__ */ new Set();
|
|
@@ -61931,7 +62841,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
61931
62841
|
}
|
|
61932
62842
|
send(method, params) {
|
|
61933
62843
|
return __async(this, null, function* () {
|
|
61934
|
-
var _a4;
|
|
62844
|
+
var _a4, _b;
|
|
61935
62845
|
const id = this.nextId++;
|
|
61936
62846
|
const payload = { id, method, params };
|
|
61937
62847
|
const stack = (_a4 = new Error().stack) == null ? void 0 : _a4.split("\n").slice(1, 4).join("\n");
|
|
@@ -61946,6 +62856,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
61946
62856
|
ts: Date.now()
|
|
61947
62857
|
});
|
|
61948
62858
|
});
|
|
62859
|
+
(_b = this.cdpLogger) == null ? void 0 : _b.call(this, { method, params, targetId: null });
|
|
61949
62860
|
this.ws.send(JSON.stringify(payload));
|
|
61950
62861
|
return p;
|
|
61951
62862
|
});
|
|
@@ -61982,6 +62893,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
61982
62893
|
session = new CdpSession(this, sessionId);
|
|
61983
62894
|
this.sessions.set(sessionId, session);
|
|
61984
62895
|
}
|
|
62896
|
+
this.sessionToTarget.set(sessionId, targetId);
|
|
61985
62897
|
return session;
|
|
61986
62898
|
});
|
|
61987
62899
|
}
|
|
@@ -61992,6 +62904,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
61992
62904
|
});
|
|
61993
62905
|
}
|
|
61994
62906
|
onMessage(json) {
|
|
62907
|
+
var _a4;
|
|
61995
62908
|
const msg = JSON.parse(json);
|
|
61996
62909
|
if ("id" in msg) {
|
|
61997
62910
|
const rec = this.inflight.get(msg.id);
|
|
@@ -62010,6 +62923,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
62010
62923
|
if (!this.sessions.has(p.sessionId)) {
|
|
62011
62924
|
this.sessions.set(p.sessionId, new CdpSession(this, p.sessionId));
|
|
62012
62925
|
}
|
|
62926
|
+
this.sessionToTarget.set(p.sessionId, p.targetInfo.targetId);
|
|
62013
62927
|
} else if (msg.method === "Target.detachedFromTarget") {
|
|
62014
62928
|
const p = msg.params;
|
|
62015
62929
|
for (const [id, entry] of this.inflight.entries()) {
|
|
@@ -62019,8 +62933,19 @@ var CdpConnection = class _CdpConnection {
|
|
|
62019
62933
|
}
|
|
62020
62934
|
}
|
|
62021
62935
|
this.sessions.delete(p.sessionId);
|
|
62936
|
+
this.sessionToTarget.delete(p.sessionId);
|
|
62937
|
+
} else if (msg.method === "Target.targetDestroyed") {
|
|
62938
|
+
const p = msg.params;
|
|
62939
|
+
for (const [sessionId2, targetId2] of this.sessionToTarget.entries()) {
|
|
62940
|
+
if (targetId2 === p.targetId) {
|
|
62941
|
+
this.sessionToTarget.delete(sessionId2);
|
|
62942
|
+
break;
|
|
62943
|
+
}
|
|
62944
|
+
}
|
|
62022
62945
|
}
|
|
62023
62946
|
const { method, params, sessionId } = msg;
|
|
62947
|
+
const targetId = this.sessionToTarget.get(sessionId) || sessionId;
|
|
62948
|
+
(_a4 = this.cdpEventLogger) == null ? void 0 : _a4.call(this, { method, params, targetId });
|
|
62024
62949
|
if (sessionId) {
|
|
62025
62950
|
const session = this.sessions.get(sessionId);
|
|
62026
62951
|
session == null ? void 0 : session.dispatch(method, params);
|
|
@@ -62031,7 +62956,7 @@ var CdpConnection = class _CdpConnection {
|
|
|
62031
62956
|
}
|
|
62032
62957
|
}
|
|
62033
62958
|
_sendViaSession(sessionId, method, params) {
|
|
62034
|
-
var _a4;
|
|
62959
|
+
var _a4, _b, _c;
|
|
62035
62960
|
const id = this.nextId++;
|
|
62036
62961
|
const payload = { id, method, params, sessionId };
|
|
62037
62962
|
const stack = (_a4 = new Error().stack) == null ? void 0 : _a4.split("\n").slice(1, 4).join("\n");
|
|
@@ -62046,6 +62971,8 @@ var CdpConnection = class _CdpConnection {
|
|
|
62046
62971
|
ts: Date.now()
|
|
62047
62972
|
});
|
|
62048
62973
|
});
|
|
62974
|
+
const targetId = (_b = this.sessionToTarget.get(sessionId)) != null ? _b : null;
|
|
62975
|
+
(_c = this.cdpLogger) == null ? void 0 : _c.call(this, { method, params, targetId });
|
|
62049
62976
|
this.ws.send(JSON.stringify(payload));
|
|
62050
62977
|
return p;
|
|
62051
62978
|
}
|
|
@@ -63081,7 +64008,7 @@ var StagehandAPIClient = class {
|
|
|
63081
64008
|
}
|
|
63082
64009
|
});
|
|
63083
64010
|
}
|
|
63084
|
-
request(
|
|
64011
|
+
request(path8, options) {
|
|
63085
64012
|
return __async(this, null, function* () {
|
|
63086
64013
|
var _a4;
|
|
63087
64014
|
const defaultHeaders = {
|
|
@@ -63099,7 +64026,7 @@ var StagehandAPIClient = class {
|
|
|
63099
64026
|
defaultHeaders["Content-Type"] = "application/json";
|
|
63100
64027
|
}
|
|
63101
64028
|
const response = yield this.fetchWithCookies(
|
|
63102
|
-
`${(_a4 = process.env.STAGEHAND_API_URL) != null ? _a4 : "https://api.stagehand.browserbase.com/v1"}${
|
|
64029
|
+
`${(_a4 = process.env.STAGEHAND_API_URL) != null ? _a4 : "https://api.stagehand.browserbase.com/v1"}${path8}`,
|
|
63103
64030
|
__spreadProps(__spreadValues({}, options), {
|
|
63104
64031
|
headers: __spreadValues(__spreadValues({}, defaultHeaders), options.headers)
|
|
63105
64032
|
})
|
|
@@ -63110,6 +64037,7 @@ var StagehandAPIClient = class {
|
|
|
63110
64037
|
};
|
|
63111
64038
|
|
|
63112
64039
|
// lib/v3/v3.ts
|
|
64040
|
+
init_flowLogger();
|
|
63113
64041
|
init_sdkErrors();
|
|
63114
64042
|
var DEFAULT_MODEL_NAME = "openai/gpt-4.1-mini";
|
|
63115
64043
|
var DEFAULT_VIEWPORT = { width: 1288, height: 711 };
|
|
@@ -63135,15 +64063,27 @@ function resolveModelConfiguration(model) {
|
|
|
63135
64063
|
return { modelName: DEFAULT_MODEL_NAME };
|
|
63136
64064
|
}
|
|
63137
64065
|
import_dotenv.default.config({ path: ".env" });
|
|
64066
|
+
var _observe_dec, _extract_dec, _act_dec, _init2;
|
|
64067
|
+
_act_dec = [logStagehandStep("Stagehand.act", "ACT")], _extract_dec = [logStagehandStep("Stagehand.extract", "EXTRACT")], _observe_dec = [logStagehandStep("Stagehand.observe", "OBSERVE")];
|
|
63138
64068
|
var _V3 = class _V3 {
|
|
63139
64069
|
constructor(opts) {
|
|
64070
|
+
__runInitializers(_init2, 5, this);
|
|
64071
|
+
this.opts = void 0;
|
|
63140
64072
|
this.state = { kind: "UNINITIALIZED" };
|
|
63141
64073
|
this.actHandler = null;
|
|
63142
64074
|
this.extractHandler = null;
|
|
63143
64075
|
this.observeHandler = null;
|
|
63144
64076
|
this.ctx = null;
|
|
64077
|
+
this.llmClient = void 0;
|
|
64078
|
+
this.modelName = void 0;
|
|
64079
|
+
this.modelClientOptions = void 0;
|
|
64080
|
+
this.llmProvider = void 0;
|
|
63145
64081
|
this.overrideLlmClients = /* @__PURE__ */ new Map();
|
|
64082
|
+
this.domSettleTimeoutMs = void 0;
|
|
63146
64083
|
this._isClosing = false;
|
|
64084
|
+
this.browserbaseSessionId = void 0;
|
|
64085
|
+
this.browserbaseSessionUrl = void 0;
|
|
64086
|
+
this.browserbaseDebugUrl = void 0;
|
|
63147
64087
|
this._onCdpClosed = (why) => {
|
|
63148
64088
|
if (this.state.kind === "BROWSERBASE") {
|
|
63149
64089
|
void this._logBrowserbaseSessionStatus();
|
|
@@ -63154,8 +64094,14 @@ var _V3 = class _V3 {
|
|
|
63154
64094
|
this.experimental = false;
|
|
63155
64095
|
this.logInferenceToFile = false;
|
|
63156
64096
|
this.disableAPI = false;
|
|
64097
|
+
this.externalLogger = void 0;
|
|
63157
64098
|
this.verbose = 1;
|
|
64099
|
+
this.stagehandLogger = void 0;
|
|
63158
64100
|
this._history = [];
|
|
64101
|
+
this.instanceId = void 0;
|
|
64102
|
+
this.cacheStorage = void 0;
|
|
64103
|
+
this.actCache = void 0;
|
|
64104
|
+
this.agentCache = void 0;
|
|
63159
64105
|
this.apiClient = null;
|
|
63160
64106
|
this.stagehandMetrics = {
|
|
63161
64107
|
actPromptTokens: 0,
|
|
@@ -63184,11 +64130,11 @@ var _V3 = class _V3 {
|
|
|
63184
64130
|
totalCachedInputTokens: 0,
|
|
63185
64131
|
totalInferenceTimeMs: 0
|
|
63186
64132
|
};
|
|
63187
|
-
var _a4, _b, _c, _d2
|
|
64133
|
+
var _a4, _b, _c, _d2;
|
|
63188
64134
|
_V3._installProcessGuards();
|
|
63189
64135
|
this.externalLogger = opts.logger;
|
|
63190
64136
|
this.verbose = (_a4 = opts.verbose) != null ? _a4 : 1;
|
|
63191
|
-
this.instanceId = (
|
|
64137
|
+
this.instanceId = (0, import_uuid6.v7)();
|
|
63192
64138
|
const loggerOptions = {
|
|
63193
64139
|
pretty: true,
|
|
63194
64140
|
level: "info"
|
|
@@ -63211,11 +64157,11 @@ var _V3 = class _V3 {
|
|
|
63211
64157
|
}
|
|
63212
64158
|
const { modelName, clientOptions } = resolveModelConfiguration(opts.model);
|
|
63213
64159
|
this.modelName = modelName;
|
|
63214
|
-
this.experimental = (
|
|
63215
|
-
this.logInferenceToFile = (
|
|
64160
|
+
this.experimental = (_b = opts.experimental) != null ? _b : false;
|
|
64161
|
+
this.logInferenceToFile = (_c = opts.logInferenceToFile) != null ? _c : false;
|
|
63216
64162
|
this.llmProvider = new LLMProvider(this.logger);
|
|
63217
64163
|
this.domSettleTimeoutMs = opts.domSettleTimeout;
|
|
63218
|
-
this.disableAPI = (
|
|
64164
|
+
this.disableAPI = (_d2 = opts.disableAPI) != null ? _d2 : false;
|
|
63219
64165
|
const baseClientOptions = clientOptions ? __spreadValues({}, clientOptions) : {};
|
|
63220
64166
|
if (opts.llmClient) {
|
|
63221
64167
|
this.llmClient = opts.llmClient;
|
|
@@ -63270,6 +64216,7 @@ var _V3 = class _V3 {
|
|
|
63270
64216
|
act: this.act.bind(this)
|
|
63271
64217
|
});
|
|
63272
64218
|
this.opts = opts;
|
|
64219
|
+
SessionFileLogger.init(this.instanceId, opts);
|
|
63273
64220
|
_V3._instances.add(this);
|
|
63274
64221
|
}
|
|
63275
64222
|
get browserbaseSessionID() {
|
|
@@ -63571,6 +64518,9 @@ var _V3 = class _V3 {
|
|
|
63571
64518
|
this.ctx = yield V3Context.create(lbo.cdpUrl, {
|
|
63572
64519
|
env: "LOCAL"
|
|
63573
64520
|
});
|
|
64521
|
+
const logCtx2 = SessionFileLogger.getContext();
|
|
64522
|
+
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx2);
|
|
64523
|
+
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx2);
|
|
63574
64524
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
63575
64525
|
this.state = {
|
|
63576
64526
|
kind: "LOCAL",
|
|
@@ -63651,6 +64601,9 @@ var _V3 = class _V3 {
|
|
|
63651
64601
|
env: "LOCAL",
|
|
63652
64602
|
localBrowserLaunchOptions: lbo
|
|
63653
64603
|
});
|
|
64604
|
+
const logCtx = SessionFileLogger.getContext();
|
|
64605
|
+
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
64606
|
+
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
63654
64607
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
63655
64608
|
this.state = {
|
|
63656
64609
|
kind: "LOCAL",
|
|
@@ -63718,6 +64671,9 @@ var _V3 = class _V3 {
|
|
|
63718
64671
|
env: "BROWSERBASE",
|
|
63719
64672
|
apiClient: this.apiClient
|
|
63720
64673
|
});
|
|
64674
|
+
const logCtx = SessionFileLogger.getContext();
|
|
64675
|
+
this.ctx.conn.cdpLogger = (info) => SessionFileLogger.logCdpCallEvent(info, logCtx);
|
|
64676
|
+
this.ctx.conn.cdpEventLogger = (info) => SessionFileLogger.logCdpMessageEvent(info, logCtx);
|
|
63721
64677
|
this.ctx.conn.onTransportClosed(this._onCdpClosed);
|
|
63722
64678
|
this.state = { kind: "BROWSERBASE", sessionId, ws, bb };
|
|
63723
64679
|
this.browserbaseSessionId = sessionId;
|
|
@@ -64020,6 +64976,10 @@ var _V3 = class _V3 {
|
|
|
64020
64976
|
if (this._isClosing && !(opts == null ? void 0 : opts.force)) return;
|
|
64021
64977
|
this._isClosing = true;
|
|
64022
64978
|
try {
|
|
64979
|
+
try {
|
|
64980
|
+
yield SessionFileLogger.close();
|
|
64981
|
+
} catch (e2) {
|
|
64982
|
+
}
|
|
64023
64983
|
try {
|
|
64024
64984
|
if (((_a4 = this.ctx) == null ? void 0 : _a4.conn) && this._onCdpClosed) {
|
|
64025
64985
|
(_c = (_b = this.ctx.conn).offTransportClosed) == null ? void 0 : _c.call(_b, this._onCdpClosed);
|
|
@@ -64105,7 +65065,7 @@ var _V3 = class _V3 {
|
|
|
64105
65065
|
return frameTree.frame.id;
|
|
64106
65066
|
}
|
|
64107
65067
|
if (this.isPuppeteerPage(page)) {
|
|
64108
|
-
const cdp = yield page.
|
|
65068
|
+
const cdp = yield page.createCDPSession();
|
|
64109
65069
|
const { frameTree } = yield cdp.send("Page.getFrameTree");
|
|
64110
65070
|
this.logger({
|
|
64111
65071
|
category: "v3",
|
|
@@ -64278,6 +65238,10 @@ var _V3 = class _V3 {
|
|
|
64278
65238
|
execute: (instructionOrOptions) => __async(this, null, function* () {
|
|
64279
65239
|
return withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
64280
65240
|
var _a5, _b2;
|
|
65241
|
+
SessionFileLogger.logAgentTaskStarted({
|
|
65242
|
+
invocation: "Agent.execute",
|
|
65243
|
+
args: [instructionOrOptions]
|
|
65244
|
+
});
|
|
64281
65245
|
if ((options == null ? void 0 : options.integrations) && !this.experimental) {
|
|
64282
65246
|
throw new ExperimentalNotConfiguredError("MCP integrations");
|
|
64283
65247
|
}
|
|
@@ -64314,6 +65278,7 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64314
65278
|
if (cacheContext) {
|
|
64315
65279
|
const replayed = yield this.agentCache.tryReplay(cacheContext);
|
|
64316
65280
|
if (replayed) {
|
|
65281
|
+
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
64317
65282
|
return replayed;
|
|
64318
65283
|
}
|
|
64319
65284
|
}
|
|
@@ -64349,6 +65314,7 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64349
65314
|
if (recording) {
|
|
64350
65315
|
this.discardAgentReplayRecording();
|
|
64351
65316
|
}
|
|
65317
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
64352
65318
|
}
|
|
64353
65319
|
}));
|
|
64354
65320
|
})
|
|
@@ -64359,6 +65325,10 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64359
65325
|
return {
|
|
64360
65326
|
execute: (instructionOrOptions) => __async(this, null, function* () {
|
|
64361
65327
|
return withInstanceLogContext(this.instanceId, () => __async(this, null, function* () {
|
|
65328
|
+
SessionFileLogger.logAgentTaskStarted({
|
|
65329
|
+
invocation: "Agent.execute",
|
|
65330
|
+
args: [instructionOrOptions]
|
|
65331
|
+
});
|
|
64362
65332
|
if (typeof instructionOrOptions === "object" && instructionOrOptions.callbacks && !this.experimental) {
|
|
64363
65333
|
throw new ExperimentalNotConfiguredError("Agent callbacks");
|
|
64364
65334
|
}
|
|
@@ -64374,6 +65344,7 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64374
65344
|
if (cacheContext2) {
|
|
64375
65345
|
const replayed = yield this.agentCache.tryReplayAsStream(cacheContext2);
|
|
64376
65346
|
if (replayed) {
|
|
65347
|
+
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
64377
65348
|
return replayed;
|
|
64378
65349
|
}
|
|
64379
65350
|
}
|
|
@@ -64381,14 +65352,17 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64381
65352
|
instructionOrOptions
|
|
64382
65353
|
);
|
|
64383
65354
|
if (cacheContext2) {
|
|
64384
|
-
|
|
65355
|
+
const wrappedStream = this.agentCache.wrapStreamForCaching(
|
|
64385
65356
|
cacheContext2,
|
|
64386
65357
|
streamResult,
|
|
64387
65358
|
() => this.beginAgentReplayRecording(),
|
|
64388
65359
|
() => this.endAgentReplayRecording(),
|
|
64389
65360
|
() => this.discardAgentReplayRecording()
|
|
64390
65361
|
);
|
|
65362
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
65363
|
+
return wrappedStream;
|
|
64391
65364
|
}
|
|
65365
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
64392
65366
|
return streamResult;
|
|
64393
65367
|
}
|
|
64394
65368
|
const { handler, resolvedOptions, cacheContext } = yield this.prepareAgentExecution(
|
|
@@ -64399,6 +65373,7 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64399
65373
|
if (cacheContext) {
|
|
64400
65374
|
const replayed = yield this.agentCache.tryReplay(cacheContext);
|
|
64401
65375
|
if (replayed) {
|
|
65376
|
+
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
64402
65377
|
return replayed;
|
|
64403
65378
|
}
|
|
64404
65379
|
}
|
|
@@ -64435,12 +65410,18 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
64435
65410
|
if (recording) {
|
|
64436
65411
|
this.discardAgentReplayRecording();
|
|
64437
65412
|
}
|
|
65413
|
+
SessionFileLogger.logAgentTaskCompleted();
|
|
64438
65414
|
}
|
|
64439
65415
|
}));
|
|
64440
65416
|
})
|
|
64441
65417
|
};
|
|
64442
65418
|
}
|
|
64443
65419
|
};
|
|
65420
|
+
_init2 = __decoratorStart(null);
|
|
65421
|
+
__decorateElement(_init2, 1, "act", _act_dec, _V3);
|
|
65422
|
+
__decorateElement(_init2, 1, "extract", _extract_dec, _V3);
|
|
65423
|
+
__decorateElement(_init2, 1, "observe", _observe_dec, _V3);
|
|
65424
|
+
__decoratorMetadata(_init2, _V3);
|
|
64444
65425
|
_V3._processGuardsInstalled = false;
|
|
64445
65426
|
_V3._instances = /* @__PURE__ */ new Set();
|
|
64446
65427
|
var V3 = _V3;
|