Open History to see the last commit
1import {
2 OrchestratorMcpFailure,
3 DeviceToolCloseInput,
4 DeviceToolError,
5 DeviceToolListResult,
6 DeviceToolOpenInput,
7 DeviceToolOpenResult,
8 DeviceToolScreenshotResult,
9 DeviceToolTargetInput,
10} from "@t3tools/contracts";
11import * as Schema from "effect/Schema";
12import * as FileSystem from "effect/FileSystem";
13import * as Path from "effect/Path";
14import * as ServerConfig from "../../../config.ts";
15import { Tool, Toolkit } from "effect/ai";
16
17import * as McpInvocationContext from "../../McpInvocationContext.ts";
18import * as DeviceService from "../../../device/DeviceService.ts";
19import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
20import * as ProjectService from "../../../project/ProjectService.ts";
21
22const dependencies = [
23 McpInvocationContext.McpInvocationContext,
24 ThreadManagementService.ThreadManagementService,
25 DeviceService.DeviceService,
26];
27
28const DeviceToolFailure = Schema.Union([DeviceToolError, OrchestratorMcpFailure]);
29
30const DeviceListTool = Tool.make("device_list", {
31 description:
32 "List iOS Simulators and Android Emulators on this environment's device hosts, which platforms each host can run, and which devices are already open in this thread's Device panel. Call this before device_open when you do not know a device id.",
33 // Empty Struct emits object|array, which can make providers reject every server tool.
34 parameters: Schema.Struct({
35 hostId: Schema.optional(
36 Schema.String.annotate({ description: "Limit to one device host. Defaults to all hosts." }),
37 ),
38 }),
39 success: DeviceToolListResult,
40 failure: DeviceToolFailure,
41 dependencies,
42})
43 .annotate(Tool.Title, "List devices")
44 .annotate(Tool.Readonly, true)
45 .annotate(Tool.Destructive, false)
46 .annotate(Tool.Idempotent, true)
47 .annotate(Tool.OpenWorld, false);
48
49const DeviceOpenTool = Tool.make("device_open", {
50 description:
51 "Open a simulator or emulator for this thread: boots it if needed, starts its live stream, and shows it in the user's Device panel so they can watch. Returns the agent-device CLI invocation pinned to the device; drive the device with that CLI afterwards.",
52 parameters: DeviceToolOpenInput,
53 success: DeviceToolOpenResult,
54 failure: DeviceToolFailure,
55 dependencies: [
56 ...dependencies,
57 FileSystem.FileSystem,
58 Path.Path,
59 ServerConfig.ServerConfig,
60 // The thread's project can name the EAS project a cloud device runs under.
61 ProjectService.ProjectService,
62 ],
63})
64 .annotate(Tool.Title, "Open device")
65 .annotate(Tool.Readonly, false)
66 .annotate(Tool.Destructive, false)
67 .annotate(Tool.Idempotent, true)
68 .annotate(Tool.OpenWorld, true);
69
70export const DeviceScreenshotTool = Tool.make("device_screenshot", {
71 description:
72 "Capture the current screen of an open device as a PNG image. Use it to see what the user sees; for taps and text use the agent-device CLI.",
73 parameters: DeviceToolTargetInput,
74 success: DeviceToolScreenshotResult,
75 failure: DeviceToolFailure,
76 dependencies,
77})
78 .annotate(Tool.Title, "Screenshot device")
79 .annotate(Tool.Readonly, true)
80 .annotate(Tool.Destructive, false)
81 .annotate(Tool.Idempotent, true)
82 .annotate(Tool.OpenWorld, true);
83
84const DeviceCloseTool = Tool.make("device_close", {
85 description:
86 "Remove a device from this thread's Device panel. Pass shutdown=true to also power the simulator or emulator off.",
87 parameters: DeviceToolCloseInput,
88 success: Schema.Record(Schema.String, Schema.Never).annotate({
89 description: "The device was closed.",
90 }),
91 failure: DeviceToolFailure,
92 dependencies,
93})
94 .annotate(Tool.Title, "Close device")
95 .annotate(Tool.Readonly, false)
96 .annotate(Tool.Destructive, true)
97 .annotate(Tool.Idempotent, true)
98 .annotate(Tool.OpenWorld, true);
99
100export const DeviceStandardToolkit = Toolkit.make(DeviceListTool, DeviceOpenTool, DeviceCloseTool);
101
102export const DeviceScreenshotToolkit = Toolkit.make(DeviceScreenshotTool);
103
104export const DeviceToolkit = Toolkit.make(
105 DeviceListTool,
106 DeviceOpenTool,
107 DeviceScreenshotTool,
108 DeviceCloseTool,
109);