mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:48:27 +00:00
fix: cap ai snapshots for tool calls (#763) (thanks @thesash)
This commit is contained in:
@@ -10,8 +10,6 @@ import {
|
||||
let nextUploadArmId = 0;
|
||||
let nextDialogArmId = 0;
|
||||
|
||||
const MAX_SNAPSHOT_CHARS = 80_000;
|
||||
|
||||
function requireRef(value: unknown): string {
|
||||
const ref = typeof value === "string" ? value.trim() : "";
|
||||
if (!ref) throw new Error("ref is required");
|
||||
@@ -44,18 +42,17 @@ export async function snapshotAiViaPlaywright(opts: {
|
||||
),
|
||||
track: "response",
|
||||
});
|
||||
let snapshot = String(result?.full ?? "");
|
||||
const maxChars = opts.maxChars;
|
||||
const limit =
|
||||
typeof maxChars === "number" && Number.isFinite(maxChars) && maxChars > 0
|
||||
? Math.floor(maxChars)
|
||||
: MAX_SNAPSHOT_CHARS;
|
||||
let snapshot = String(result?.full ?? "");
|
||||
let truncated = false;
|
||||
if (snapshot.length > limit) {
|
||||
: undefined;
|
||||
if (limit && snapshot.length > limit) {
|
||||
snapshot = `${snapshot.slice(0, limit)}\n\n[...TRUNCATED - page too large]`;
|
||||
truncated = true;
|
||||
return { snapshot, truncated: true };
|
||||
}
|
||||
return truncated ? { snapshot, truncated } : { snapshot };
|
||||
return { snapshot };
|
||||
}
|
||||
|
||||
export async function clickViaPlaywright(opts: {
|
||||
|
||||
Reference in New Issue
Block a user