mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 15:23:43 +00:00
fix(browser): accept url alias for open and navigate (#29260)
* fix(browser): expose url alias in tool schema * fix(browser): accept url alias for open and navigate * test(browser): cover url alias for open and navigate
This commit is contained in:
@@ -86,6 +86,7 @@ export const BrowserToolSchema = Type.Object({
|
|||||||
node: Type.Optional(Type.String()),
|
node: Type.Optional(Type.String()),
|
||||||
profile: Type.Optional(Type.String()),
|
profile: Type.Optional(Type.String()),
|
||||||
targetUrl: Type.Optional(Type.String()),
|
targetUrl: Type.Optional(Type.String()),
|
||||||
|
url: Type.Optional(Type.String()),
|
||||||
targetId: Type.Optional(Type.String()),
|
targetId: Type.Optional(Type.String()),
|
||||||
limit: Type.Optional(Type.Number()),
|
limit: Type.Optional(Type.Number()),
|
||||||
maxChars: Type.Optional(Type.Number()),
|
maxChars: Type.Optional(Type.Number()),
|
||||||
|
|||||||
@@ -262,6 +262,51 @@ describe("browser tool snapshot maxChars", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("browser tool url alias support", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
configMocks.loadConfig.mockReturnValue({ browser: {} });
|
||||||
|
nodesUtilsMocks.listNodes.mockResolvedValue([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("accepts url alias for open", async () => {
|
||||||
|
const tool = createBrowserTool();
|
||||||
|
await tool.execute?.("call-1", { action: "open", url: "https://example.com" });
|
||||||
|
|
||||||
|
expect(browserClientMocks.browserOpenTab).toHaveBeenCalledWith(
|
||||||
|
undefined,
|
||||||
|
"https://example.com",
|
||||||
|
expect.objectContaining({ profile: undefined }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("accepts url alias for navigate", async () => {
|
||||||
|
const tool = createBrowserTool();
|
||||||
|
await tool.execute?.("call-1", {
|
||||||
|
action: "navigate",
|
||||||
|
url: "https://example.com",
|
||||||
|
targetId: "tab-1",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(browserActionsMocks.browserNavigate).toHaveBeenCalledWith(
|
||||||
|
undefined,
|
||||||
|
expect.objectContaining({
|
||||||
|
url: "https://example.com",
|
||||||
|
targetId: "tab-1",
|
||||||
|
profile: undefined,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps targetUrl required error label when both params are missing", async () => {
|
||||||
|
const tool = createBrowserTool();
|
||||||
|
|
||||||
|
await expect(tool.execute?.("call-1", { action: "open" })).rejects.toThrow(
|
||||||
|
"targetUrl required",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("browser tool snapshot labels", () => {
|
describe("browser tool snapshot labels", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ function readOptionalTargetAndTimeout(params: Record<string, unknown>) {
|
|||||||
return { targetId, timeoutMs };
|
return { targetId, timeoutMs };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readTargetUrlParam(params: Record<string, unknown>) {
|
||||||
|
return (
|
||||||
|
readStringParam(params, "targetUrl") ??
|
||||||
|
readStringParam(params, "url", { required: true, label: "targetUrl" })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
type BrowserProxyFile = {
|
type BrowserProxyFile = {
|
||||||
path: string;
|
path: string;
|
||||||
base64: string;
|
base64: string;
|
||||||
@@ -405,9 +412,7 @@ export function createBrowserTool(opts?: {
|
|||||||
return formatTabsToolResult(tabs);
|
return formatTabsToolResult(tabs);
|
||||||
}
|
}
|
||||||
case "open": {
|
case "open": {
|
||||||
const targetUrl = readStringParam(params, "targetUrl", {
|
const targetUrl = readTargetUrlParam(params);
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
if (proxyRequest) {
|
if (proxyRequest) {
|
||||||
const result = await proxyRequest({
|
const result = await proxyRequest({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -635,9 +640,7 @@ export function createBrowserTool(opts?: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
case "navigate": {
|
case "navigate": {
|
||||||
const targetUrl = readStringParam(params, "targetUrl", {
|
const targetUrl = readTargetUrlParam(params);
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
const targetId = readStringParam(params, "targetId");
|
const targetId = readStringParam(params, "targetId");
|
||||||
if (proxyRequest) {
|
if (proxyRequest) {
|
||||||
const result = await proxyRequest({
|
const result = await proxyRequest({
|
||||||
|
|||||||
Reference in New Issue
Block a user