mirror of https://github.com/openclaw/openclaw.git
refactor: share browser console result formatting
This commit is contained in:
parent
997256d370
commit
414e9c87cb
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue