refactor: share browser console result formatting

This commit is contained in:
Peter Steinberger 2026-03-14 01:00:17 +00:00
parent 997256d370
commit 414e9c87cb
1 changed files with 21 additions and 26 deletions

View File

@ -54,6 +54,25 @@ function formatTabsToolResult(tabs: unknown[]): AgentToolResult<unknown> {
};
}
function formatConsoleToolResult(result: {
targetId?: string;
messages?: unknown[];
}): AgentToolResult<unknown> {
const wrapped = wrapBrowserExternalJson({
kind: "console",
payload: result,
includeWarning: false,
});
return {
content: [{ type: "text" as const, text: wrapped.wrappedText }],
details: {
...wrapped.safeDetails,
targetId: typeof result.targetId === "string" ? result.targetId : undefined,
messageCount: Array.isArray(result.messages) ? result.messages.length : undefined,
},
};
}
function isChromeStaleTargetError(profile: string | undefined, err: unknown): boolean {
if (profile !== "chrome") {
return false;
@ -258,34 +277,10 @@ export async function executeConsoleAction(params: {
targetId,
},
})) as { ok?: boolean; targetId?: string; messages?: unknown[] };
const wrapped = wrapBrowserExternalJson({
kind: "console",
payload: result,
includeWarning: false,
});
return {
content: [{ type: "text" as const, text: wrapped.wrappedText }],
details: {
...wrapped.safeDetails,
targetId: typeof result.targetId === "string" ? result.targetId : undefined,
messageCount: Array.isArray(result.messages) ? result.messages.length : undefined,
},
};
return formatConsoleToolResult(result);
}
const result = await browserConsoleMessages(baseUrl, { level, targetId, profile });
const wrapped = wrapBrowserExternalJson({
kind: "console",
payload: result,
includeWarning: false,
});
return {
content: [{ type: "text" as const, text: wrapped.wrappedText }],
details: {
...wrapped.safeDetails,
targetId: result.targetId,
messageCount: result.messages.length,
},
};
return formatConsoleToolResult(result);
}
export async function executeActAction(params: {