Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge pull request #6130 from xls-nv/phone-type-switch

milind-soni0399ae7a594b
diff --cc server/drivers/phone-proxy.test.ts
index f31ada9674,2d47102fc9..a004d340e1
--- a/server/drivers/phone-proxy.test.ts
+++ b/server/drivers/phone-proxy.test.ts
@@@ -470,19 -603,10 +610,23 @@@ describe("phone MCP tool surface", () =
}
});
+ it("offers swipe a start, a distance and a duration, and tap a duration to hold, as designed", () => {
+ expect(tool("swipe").description).toBe("Swipe the Android screen in a direction. By default the finger moves half the screen through the centre in 260 ms. To scroll a list, a pane or a picker wheel by a chosen amount, give x and y (where the finger starts), distance (pixels it moves) and duration_ms (longer is slower). To do several steps, or to act and then read the screen, in one call, use batch.");
+ expect(tool("swipe").inputSchema).toEqual({ type: "object", properties: { direction: { type: "string", enum: ["up", "down", "left", "right"] }, x: { type: "number" }, y: { type: "number" }, distance: { type: "number" }, duration_ms: { type: "integer" }, serial: { type: "string" } }, required: ["direction"] });
+ expect(tool("tap").description).toBe("Tap Android screen pixel coordinates obtained from read_screen or screenshot. Add duration_ms to hold the tap; about 1000 is a long press. To do several steps, or to act and then read the screen, in one call, use batch.");
+ expect(tool("tap").inputSchema).toEqual({ type: "object", properties: { x: { type: "number" }, y: { type: "number" }, duration_ms: { type: "integer" }, serial: { type: "string" } }, required: ["x", "y"] });
+ });
+
+ it("tells a step what distance and duration_ms mean, naming their actions", () => {
+ const fields = tool("batch").inputSchema.properties.steps.items.properties;
+ expect(fields.distance).toEqual({ type: "number", description: "swipe: pixels the finger moves, 50 to 10000, default half the screen." });
+ expect(fields.duration_ms).toEqual({ type: "integer", description: "tap and swipe: milliseconds a tap is held or a swipe takes, 50 to 2000; without it a tap is not held and a swipe takes 260." });
+ });
+
+ it("tells the bot that other text needs ADBKeyBoard switched on, not chosen as the keyboard", () => {
+ expect(tool("type_text").description).toContain("other text, such as Chinese, emoji or +, needs the ADBKeyBoard app switched on in the phone's keyboard list.");
+ });
+
it("keeps serial out of a step's fields", () => {
expect(tool("batch").inputSchema.properties.steps.items.properties).not.toHaveProperty("serial");
});
diff --cc server/drivers/phone-proxy.ts
index 21f3e78f12,048647c0e4..3f4e08ba79
--- a/server/drivers/phone-proxy.ts
+++ b/server/drivers/phone-proxy.ts
@@@ -296,9 -323,9 +323,9 @@@ const SINGLE_TOOLS =
{ name: "list_apps", description: "List installed launchable Android package names, optionally filtered by a human app name. Prefer open_app first.", inputSchema: { type: "object", properties: { query: { type: "string" }, serial: { type: "string" } } } },
{ name: "open_app", description: "Open an installed Android app directly by its English name, such as Uber or Skyscanner, or by its package name. Do not scan the app drawer first.", inputSchema: { type: "object", properties: { name: { type: "string" }, serial: { type: "string" } }, required: ["name"] } },
{ name: "tap_text", description: "Tap visible Android text or an accessibility label.", inputSchema: { type: "object", properties: { text: { type: "string" }, exact: { type: "boolean" }, index: { type: "integer", minimum: 0 }, serial: { type: "string" } }, required: ["text"] } },
- { name: "tap", description: "Tap Android screen pixel coordinates obtained from read_screen or screenshot.", inputSchema: { type: "object", properties: { x: { type: "number" }, y: { type: "number" }, serial: { type: "string" } }, required: ["x", "y"] } },
- { name: "swipe", description: "Swipe the Android screen in a direction.", inputSchema: { type: "object", properties: { direction: { type: "string", enum: ["up", "down", "left", "right"] }, serial: { type: "string" } }, required: ["direction"] } },
+ { name: "tap", description: "Tap Android screen pixel coordinates obtained from read_screen or screenshot. Add duration_ms to hold the tap; about 1000 is a long press.", inputSchema: { type: "object", properties: { x: { type: "number" }, y: { type: "number" }, duration_ms: { type: "integer" }, serial: { type: "string" } }, required: ["x", "y"] } },
+ { name: "swipe", description: "Swipe the Android screen in a direction. By default the finger moves half the screen through the centre in 260 ms. To scroll a list, a pane or a picker wheel by a chosen amount, give x and y (where the finger starts), distance (pixels it moves) and duration_ms (longer is slower).", inputSchema: { type: "object", properties: { direction: { type: "string", enum: ["up", "down", "left", "right"] }, x: { type: "number" }, y: { type: "number" }, distance: { type: "number" }, duration_ms: { type: "integer" }, serial: { type: "string" } }, required: ["direction"] } },
- { name: "type_text", description: "Type text into the focused Android field. Letters, digits, spaces and _.,@- always work; other text, such as Chinese, emoji or +, needs the ADBKeyBoard keyboard selected on the phone. Set clear to true to empty the field first, which also needs ADBKeyBoard. Never enter passwords or payment details. A one-time code only for a sign-in the person asked for, into the app it was sent for.", inputSchema: { type: "object", properties: { text: { type: "string", maxLength: 256 }, clear: { type: "boolean" }, serial: { type: "string" } }, required: ["text"] } },
+ { name: "type_text", description: "Type text into the focused Android field. Letters, digits, spaces and _.,@- always work; other text, such as Chinese, emoji or +, needs the ADBKeyBoard app switched on in the phone's keyboard list. Set clear to true to empty the field first, which also needs ADBKeyBoard. Never enter passwords or payment details. A one-time code only for a sign-in the person asked for, into the app it was sent for.", inputSchema: { type: "object", properties: { text: { type: "string", maxLength: 256 }, clear: { type: "boolean" }, serial: { type: "string" } }, required: ["text"] } },
{ name: "press", description: "Press an Android navigation or keyboard key. wakeup turns the screen on and sleep turns it off.", inputSchema: { type: "object", properties: { key: { type: "string", enum: Object.keys(KEYCODES) }, serial: { type: "string" } }, required: ["key"] } },
] as const;
@@@ -627,22 -637,18 +657,22 @@@ async function callToolOn(onDevice: OnD
const match = /(\d+)x(\d+)/.exec(size);
if (!match) throw new Error("Could not read Android screen size");
const width = Number(match[1]); const height = Number(match[2]);
- const points: Record<string, [number, number, number, number]> = {
- up: [width / 2, height * 0.75, width / 2, height * 0.25],
- down: [width / 2, height * 0.25, width / 2, height * 0.75],
- left: [width * 0.75, height / 2, width * 0.25, height / 2],
- right: [width * 0.25, height / 2, width * 0.75, height / 2],
+ const moves: Record<string, { x: number; y: number; dx: number; dy: number; distance: number }> = {
+ up: { x: width / 2, y: height * 0.75, dx: 0, dy: -1, distance: height / 2 },
+ down: { x: width / 2, y: height * 0.25, dx: 0, dy: 1, distance: height / 2 },
+ left: { x: width * 0.75, y: height / 2, dx: -1, dy: 0, distance: width / 2 },
+ right: { x: width * 0.25, y: height / 2, dx: 1, dy: 0, distance: width / 2 },
};
- const point = points[direction];
- if (!point) throw new Error("Invalid swipe direction");
- await onDevice(serial, ["shell", "input", "swipe", ...point.map((value) => String(Math.round(value))), "260"]);
- return textResult(`Swiped ${direction}`);
+ const move = Object.hasOwn(moves, direction) ? moves[direction] : undefined;
+ if (!move) throw new Error("Invalid swipe direction");
+ const or = (value: unknown, fallback: number) => (given(value) ? rounded(value) : fallback);
+ const x = or(args.x, move.x); const y = or(args.y, move.y); const distance = or(args.distance, move.distance);
+ const sent = [x, y, x + move.dx * distance, y + move.dy * distance, or(args.duration_ms, 260)].map((value) => String(Math.round(value)));
+ await onDevice(serial, ["shell", "input", "swipe", ...sent]);
+ const chosen = [args.x, args.y, args.distance, args.duration_ms].some(given);
+ return textResult(chosen ? `Swiped from ${sent[0]},${sent[1]} to ${sent[2]},${sent[3]} in ${sent[4]} ms` : `Swiped ${direction}`);
}
- if (name === "type_text") return textResult(await typePhoneText(deviceShell(onDevice, serial), String(args.text ?? ""), args.clear === true));
+ if (name === "type_text") return textResult(await typePhoneText(deviceShell(onDevice, serial), String(args.text ?? ""), args.clear === true, deviceShell(unclaimed, serial)));
if (name === "press") {
const key = String(args.key ?? "").toLowerCase();
if (!KEYCODES[key]) throw new Error("Unsupported Android key");