illuma-agents 1.0.44 → 1.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"DesktopTools.cjs","sources":["../../../src/tools/DesktopTools.ts"],"sourcesContent":["import { z } from 'zod';\r\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\r\n\r\n/**\r\n * Desktop tool names - keep in sync with Ranger Desktop Electron app\r\n * These tools execute locally in the Electron app, NOT on the server\r\n */\r\nexport const EDesktopTools = {\r\n SCREENSHOT: 'computer_screenshot',\r\n CLICK: 'computer_click',\r\n DOUBLE_CLICK: 'computer_double_click',\r\n RIGHT_CLICK: 'computer_right_click',\r\n TYPE: 'computer_type',\r\n KEY: 'computer_key',\r\n KEY_COMBO: 'computer_key_combo',\r\n SCROLL: 'computer_scroll',\r\n DRAG: 'computer_drag',\r\n GET_ACTIVE_WINDOW: 'computer_get_active_window',\r\n GET_MOUSE_POSITION: 'computer_get_mouse_position',\r\n CLIPBOARD_READ: 'clipboard_read',\r\n CLIPBOARD_WRITE: 'clipboard_write',\r\n CLIPBOARD_PASTE: 'clipboard_paste',\r\n WAIT: 'computer_wait',\r\n} as const;\r\n\r\nexport type DesktopToolName =\r\n (typeof EDesktopTools)[keyof typeof EDesktopTools];\r\n\r\n/**\r\n * Callback function type for waiting on desktop action results\r\n * This allows the server (Ranger) to provide a callback that waits for the Electron app\r\n * to POST results back to the server before returning to the LLM.\r\n *\r\n * @param action - The desktop action (click, type, screenshot, etc.)\r\n * @param args - Arguments for the action\r\n * @param toolCallId - Unique ID for this tool call (from config.toolCall.id)\r\n * @returns Promise that resolves with the actual desktop result\r\n */\r\nexport type DesktopToolCallback = (\r\n action: string,\r\n args: Record<string, unknown>,\r\n toolCallId: string\r\n) => Promise<DesktopActionResult>;\r\n\r\n/**\r\n * Result returned from desktop action execution\r\n */\r\nexport interface DesktopActionResult {\r\n success: boolean;\r\n error?: string;\r\n screenshot?: {\r\n base64: string;\r\n width: number;\r\n height: number;\r\n };\r\n activeWindow?: {\r\n title: string;\r\n app: string;\r\n bounds?: { x: number; y: number; width: number; height: number };\r\n };\r\n mousePosition?: { x: number; y: number };\r\n clipboard?: string;\r\n}\r\n\r\n/**\r\n * Check if desktop capability is available based on request headers or context\r\n * The Ranger Desktop Electron app sets these headers when connected:\r\n * - X-Ranger-Desktop: true\r\n * - X-Ranger-Desktop-Capable: true\r\n */\r\nexport function hasDesktopCapability(req?: {\r\n headers?: Record<string, string | string[] | undefined>;\r\n}): boolean {\r\n if (!req?.headers) {\r\n return false;\r\n }\r\n\r\n const desktopApp = req.headers['x-ranger-desktop'];\r\n const desktopCapable = req.headers['x-ranger-desktop-capable'];\r\n\r\n return desktopApp === 'true' || desktopCapable === 'true';\r\n}\r\n\r\n// Tool schemas\r\nconst ScreenshotSchema = z.object({});\r\n\r\nconst ClickSchema = z.object({\r\n x: z.number().describe('X coordinate to click'),\r\n y: z.number().describe('Y coordinate to click'),\r\n});\r\n\r\nconst DoubleClickSchema = z.object({\r\n x: z.number().describe('X coordinate to double-click'),\r\n y: z.number().describe('Y coordinate to double-click'),\r\n});\r\n\r\nconst RightClickSchema = z.object({\r\n x: z.number().describe('X coordinate to right-click'),\r\n y: z.number().describe('Y coordinate to right-click'),\r\n});\r\n\r\nconst TypeSchema = z.object({\r\n text: z.string().describe('Text to type'),\r\n});\r\n\r\nconst KeySchema = z.object({\r\n key: z\r\n .string()\r\n .describe(\r\n 'Key to press (e.g., \"Enter\", \"Tab\", \"Escape\", \"Backspace\", \"Delete\", \"ArrowUp\", \"ArrowDown\", \"ArrowLeft\", \"ArrowRight\", \"Home\", \"End\", \"PageUp\", \"PageDown\", \"F1\"-\"F12\")'\r\n ),\r\n});\r\n\r\nconst KeyComboSchema = z.object({\r\n keys: z\r\n .array(z.string())\r\n .describe(\r\n 'Array of keys to press together (e.g., [\"Control\", \"c\"] for copy, [\"Alt\", \"Tab\"] for window switch)'\r\n ),\r\n});\r\n\r\nconst ScrollSchema = z.object({\r\n x: z.number().describe('X coordinate to scroll at'),\r\n y: z.number().describe('Y coordinate to scroll at'),\r\n deltaX: z.number().optional().describe('Horizontal scroll amount (pixels)'),\r\n deltaY: z.number().describe('Vertical scroll amount (pixels, negative = up, positive = down)'),\r\n});\r\n\r\nconst DragSchema = z.object({\r\n startX: z.number().describe('Starting X coordinate'),\r\n startY: z.number().describe('Starting Y coordinate'),\r\n endX: z.number().describe('Ending X coordinate'),\r\n endY: z.number().describe('Ending Y coordinate'),\r\n});\r\n\r\nconst GetActiveWindowSchema = z.object({});\r\n\r\nconst GetMousePositionSchema = z.object({});\r\n\r\nconst ClipboardReadSchema = z.object({});\r\n\r\nconst ClipboardWriteSchema = z.object({\r\n text: z.string().describe('Text to write to clipboard'),\r\n});\r\n\r\nconst ClipboardPasteSchema = z.object({});\r\n\r\nconst WaitSchema = z.object({\r\n ms: z.number().describe('Milliseconds to wait'),\r\n});\r\n\r\n/**\r\n * Desktop tool response interface\r\n * This is what the Electron app returns after executing the action\r\n */\r\nexport interface DesktopToolResponse {\r\n requiresDesktopExecution: true;\r\n action: string;\r\n args: Record<string, unknown>;\r\n toolCallId?: string;\r\n}\r\n\r\n/**\r\n * Options for creating desktop tools\r\n */\r\nexport interface CreateDesktopToolsOptions {\r\n /**\r\n * Optional callback that waits for desktop action results.\r\n * When provided, tools will await this callback to get actual results from the Electron app.\r\n * When not provided, tools return markers immediately (for non-server contexts).\r\n */\r\n waitForResult?: DesktopToolCallback;\r\n}\r\n\r\n/**\r\n * Format desktop action result for LLM consumption\r\n */\r\nfunction formatResultForLLM(\r\n result: DesktopActionResult,\r\n action: string\r\n): string {\r\n if (!result.success && result.error) {\r\n return `Desktop action \"${action}\" failed: ${result.error}`;\r\n }\r\n\r\n const parts: string[] = [];\r\n\r\n if (result.screenshot) {\r\n parts.push(\r\n `Screenshot captured (${result.screenshot.width}x${result.screenshot.height})`\r\n );\r\n // The base64 image will be handled separately by the message formatter\r\n }\r\n\r\n if (result.activeWindow) {\r\n parts.push(`**Active Window:**`);\r\n parts.push(` - Title: ${result.activeWindow.title}`);\r\n parts.push(` - App: ${result.activeWindow.app}`);\r\n if (result.activeWindow.bounds) {\r\n const b = result.activeWindow.bounds;\r\n parts.push(` - Position: (${b.x}, ${b.y})`);\r\n parts.push(` - Size: ${b.width}x${b.height}`);\r\n }\r\n }\r\n\r\n if (result.mousePosition) {\r\n parts.push(\r\n `**Mouse Position:** (${result.mousePosition.x}, ${result.mousePosition.y})`\r\n );\r\n }\r\n\r\n if (result.clipboard !== undefined) {\r\n parts.push(`**Clipboard Content:** ${result.clipboard}`);\r\n }\r\n\r\n if (parts.length === 0) {\r\n parts.push(`Desktop action \"${action}\" completed successfully.`);\r\n }\r\n\r\n return parts.join('\\n');\r\n}\r\n\r\n/**\r\n * Create desktop automation tools for the agent\r\n * These tools allow AI to control the user's desktop when Ranger Desktop is running\r\n */\r\nexport function createDesktopTools(\r\n options: CreateDesktopToolsOptions = {}\r\n): DynamicStructuredTool[] {\r\n const { waitForResult } = options;\r\n const tools: DynamicStructuredTool[] = [];\r\n\r\n /**\r\n * Helper to create tool function that optionally waits for results\r\n * The toolCallId is extracted from the RunnableConfig passed by LangChain\r\n */\r\n const createToolFunction = (action: string) => {\r\n return async (\r\n args: Record<string, unknown>,\r\n config?: { toolCall?: { id?: string } }\r\n ): Promise<string> => {\r\n const toolCallId =\r\n config?.toolCall?.id ??\r\n `desktop_${Date.now()}_${Math.random().toString(36).slice(2)}`;\r\n\r\n // Create marker for Electron app\r\n const marker: DesktopToolResponse = {\r\n requiresDesktopExecution: true,\r\n action,\r\n args,\r\n toolCallId,\r\n };\r\n\r\n // If no callback, return marker immediately (Electron handles via SSE interception)\r\n if (!waitForResult) {\r\n return JSON.stringify(marker);\r\n }\r\n\r\n // With callback: wait for actual results from Electron app\r\n try {\r\n const result = await waitForResult(action, args, toolCallId);\r\n return formatResultForLLM(result, action);\r\n } catch (error) {\r\n const errorMessage =\r\n error instanceof Error ? error.message : String(error);\r\n return `Desktop action \"${action}\" failed: ${errorMessage}`;\r\n }\r\n };\r\n };\r\n\r\n // computer_screenshot\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.SCREENSHOT), {\r\n name: EDesktopTools.SCREENSHOT,\r\n description:\r\n 'Take a screenshot of the entire screen. Use this to see what is currently displayed on the desktop.',\r\n schema: ScreenshotSchema,\r\n })\r\n );\r\n\r\n // computer_click\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLICK), {\r\n name: EDesktopTools.CLICK,\r\n description:\r\n 'Click the mouse at the specified screen coordinates. Use screenshot first to identify the target location.',\r\n schema: ClickSchema,\r\n })\r\n );\r\n\r\n // computer_double_click\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.DOUBLE_CLICK), {\r\n name: EDesktopTools.DOUBLE_CLICK,\r\n description:\r\n 'Double-click the mouse at the specified screen coordinates.',\r\n schema: DoubleClickSchema,\r\n })\r\n );\r\n\r\n // computer_right_click\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.RIGHT_CLICK), {\r\n name: EDesktopTools.RIGHT_CLICK,\r\n description:\r\n 'Right-click the mouse at the specified screen coordinates to open context menus.',\r\n schema: RightClickSchema,\r\n })\r\n );\r\n\r\n // computer_type\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.TYPE), {\r\n name: EDesktopTools.TYPE,\r\n description:\r\n 'Type text using the keyboard. Make sure the target input field is focused first (use click).',\r\n schema: TypeSchema,\r\n })\r\n );\r\n\r\n // computer_key\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.KEY), {\r\n name: EDesktopTools.KEY,\r\n description:\r\n 'Press a single key on the keyboard (Enter, Tab, Escape, arrow keys, function keys, etc.).',\r\n schema: KeySchema,\r\n })\r\n );\r\n\r\n // computer_key_combo\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.KEY_COMBO), {\r\n name: EDesktopTools.KEY_COMBO,\r\n description:\r\n 'Press a key combination (e.g., Ctrl+C to copy, Ctrl+V to paste, Alt+Tab to switch windows).',\r\n schema: KeyComboSchema,\r\n })\r\n );\r\n\r\n // computer_scroll\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.SCROLL), {\r\n name: EDesktopTools.SCROLL,\r\n description:\r\n 'Scroll at the specified screen coordinates. Use negative deltaY to scroll up, positive to scroll down.',\r\n schema: ScrollSchema,\r\n })\r\n );\r\n\r\n // computer_drag\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.DRAG), {\r\n name: EDesktopTools.DRAG,\r\n description:\r\n 'Drag the mouse from one position to another (for moving windows, selecting text, etc.).',\r\n schema: DragSchema,\r\n })\r\n );\r\n\r\n // computer_get_active_window\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.GET_ACTIVE_WINDOW), {\r\n name: EDesktopTools.GET_ACTIVE_WINDOW,\r\n description:\r\n 'Get information about the currently active window (title, application name, position, size).',\r\n schema: GetActiveWindowSchema,\r\n })\r\n );\r\n\r\n // computer_get_mouse_position\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.GET_MOUSE_POSITION), {\r\n name: EDesktopTools.GET_MOUSE_POSITION,\r\n description: 'Get the current mouse cursor position on screen.',\r\n schema: GetMousePositionSchema,\r\n })\r\n );\r\n\r\n // clipboard_read\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLIPBOARD_READ), {\r\n name: EDesktopTools.CLIPBOARD_READ,\r\n description: 'Read the current contents of the system clipboard.',\r\n schema: ClipboardReadSchema,\r\n })\r\n );\r\n\r\n // clipboard_write\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLIPBOARD_WRITE), {\r\n name: EDesktopTools.CLIPBOARD_WRITE,\r\n description: 'Write text to the system clipboard.',\r\n schema: ClipboardWriteSchema,\r\n })\r\n );\r\n\r\n // clipboard_paste\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLIPBOARD_PASTE), {\r\n name: EDesktopTools.CLIPBOARD_PASTE,\r\n description:\r\n 'Paste the clipboard contents (equivalent to Ctrl+V). Use clipboard_write first to set the content.',\r\n schema: ClipboardPasteSchema,\r\n })\r\n );\r\n\r\n // computer_wait\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.WAIT), {\r\n name: EDesktopTools.WAIT,\r\n description:\r\n 'Wait for the specified number of milliseconds. Use this to wait for UI animations or loading.',\r\n schema: WaitSchema,\r\n })\r\n );\r\n\r\n return tools;\r\n}\r\n\r\n/**\r\n * Get all desktop tool names\r\n */\r\nexport function getDesktopToolNames(): DesktopToolName[] {\r\n return Object.values(EDesktopTools);\r\n}\r\n\r\n/**\r\n * Check if a tool name is a desktop tool\r\n */\r\nexport function isDesktopTool(name: string): name is DesktopToolName {\r\n return Object.values(EDesktopTools).includes(name as DesktopToolName);\r\n}\r\n"],"names":["z","tools","tool"],"mappings":";;;;;AAGA;;;AAGG;AACU,MAAA,aAAa,GAAG;AAC3B,IAAA,UAAU,EAAE,qBAAqB;AACjC,IAAA,KAAK,EAAE,gBAAgB;AACvB,IAAA,YAAY,EAAE,uBAAuB;AACrC,IAAA,WAAW,EAAE,sBAAsB;AACnC,IAAA,IAAI,EAAE,eAAe;AACrB,IAAA,GAAG,EAAE,cAAc;AACnB,IAAA,SAAS,EAAE,oBAAoB;AAC/B,IAAA,MAAM,EAAE,iBAAiB;AACzB,IAAA,IAAI,EAAE,eAAe;AACrB,IAAA,iBAAiB,EAAE,4BAA4B;AAC/C,IAAA,kBAAkB,EAAE,6BAA6B;AACjD,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,IAAI,EAAE,eAAe;;AA0CvB;;;;;AAKG;AACG,SAAU,oBAAoB,CAAC,GAEpC,EAAA;AACC,IAAA,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE;AACjB,QAAA,OAAO,KAAK;;IAGd,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC;IAClD,MA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B,GAAA;AACjC,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;AACrC;AAEA;;AAEG;AACG,SAAU,aAAa,CAAC,IAAY,EAAA;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,IAAuB,CAAC;AACvE;;;;;;;;"}
@@ -1,264 +0,0 @@
1
- import { z } from 'zod';
2
- import { tool } from '@langchain/core/tools';
3
-
4
- /**
5
- * Desktop tool names - keep in sync with Ranger Desktop Electron app
6
- * These tools execute locally in the Electron app, NOT on the server
7
- */
8
- const EDesktopTools = {
9
- SCREENSHOT: 'computer_screenshot',
10
- CLICK: 'computer_click',
11
- DOUBLE_CLICK: 'computer_double_click',
12
- RIGHT_CLICK: 'computer_right_click',
13
- TYPE: 'computer_type',
14
- KEY: 'computer_key',
15
- KEY_COMBO: 'computer_key_combo',
16
- SCROLL: 'computer_scroll',
17
- DRAG: 'computer_drag',
18
- GET_ACTIVE_WINDOW: 'computer_get_active_window',
19
- GET_MOUSE_POSITION: 'computer_get_mouse_position',
20
- CLIPBOARD_READ: 'clipboard_read',
21
- CLIPBOARD_WRITE: 'clipboard_write',
22
- CLIPBOARD_PASTE: 'clipboard_paste',
23
- WAIT: 'computer_wait',
24
- };
25
- /**
26
- * Check if desktop capability is available based on request headers or context
27
- * The Ranger Desktop Electron app sets these headers when connected:
28
- * - X-Ranger-Desktop: true
29
- * - X-Ranger-Desktop-Capable: true
30
- */
31
- function hasDesktopCapability(req) {
32
- if (!req?.headers) {
33
- return false;
34
- }
35
- const desktopApp = req.headers['x-ranger-desktop'];
36
- const desktopCapable = req.headers['x-ranger-desktop-capable'];
37
- return desktopApp === 'true' || desktopCapable === 'true';
38
- }
39
- // Tool schemas
40
- const ScreenshotSchema = z.object({});
41
- const ClickSchema = z.object({
42
- x: z.number().describe('X coordinate to click'),
43
- y: z.number().describe('Y coordinate to click'),
44
- });
45
- const DoubleClickSchema = z.object({
46
- x: z.number().describe('X coordinate to double-click'),
47
- y: z.number().describe('Y coordinate to double-click'),
48
- });
49
- const RightClickSchema = z.object({
50
- x: z.number().describe('X coordinate to right-click'),
51
- y: z.number().describe('Y coordinate to right-click'),
52
- });
53
- const TypeSchema = z.object({
54
- text: z.string().describe('Text to type'),
55
- });
56
- const KeySchema = z.object({
57
- key: z
58
- .string()
59
- .describe('Key to press (e.g., "Enter", "Tab", "Escape", "Backspace", "Delete", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown", "F1"-"F12")'),
60
- });
61
- const KeyComboSchema = z.object({
62
- keys: z
63
- .array(z.string())
64
- .describe('Array of keys to press together (e.g., ["Control", "c"] for copy, ["Alt", "Tab"] for window switch)'),
65
- });
66
- const ScrollSchema = z.object({
67
- x: z.number().describe('X coordinate to scroll at'),
68
- y: z.number().describe('Y coordinate to scroll at'),
69
- deltaX: z.number().optional().describe('Horizontal scroll amount (pixels)'),
70
- deltaY: z.number().describe('Vertical scroll amount (pixels, negative = up, positive = down)'),
71
- });
72
- const DragSchema = z.object({
73
- startX: z.number().describe('Starting X coordinate'),
74
- startY: z.number().describe('Starting Y coordinate'),
75
- endX: z.number().describe('Ending X coordinate'),
76
- endY: z.number().describe('Ending Y coordinate'),
77
- });
78
- const GetActiveWindowSchema = z.object({});
79
- const GetMousePositionSchema = z.object({});
80
- const ClipboardReadSchema = z.object({});
81
- const ClipboardWriteSchema = z.object({
82
- text: z.string().describe('Text to write to clipboard'),
83
- });
84
- const ClipboardPasteSchema = z.object({});
85
- const WaitSchema = z.object({
86
- ms: z.number().describe('Milliseconds to wait'),
87
- });
88
- /**
89
- * Format desktop action result for LLM consumption
90
- */
91
- function formatResultForLLM(result, action) {
92
- if (!result.success && result.error) {
93
- return `Desktop action "${action}" failed: ${result.error}`;
94
- }
95
- const parts = [];
96
- if (result.screenshot) {
97
- parts.push(`Screenshot captured (${result.screenshot.width}x${result.screenshot.height})`);
98
- // The base64 image will be handled separately by the message formatter
99
- }
100
- if (result.activeWindow) {
101
- parts.push(`**Active Window:**`);
102
- parts.push(` - Title: ${result.activeWindow.title}`);
103
- parts.push(` - App: ${result.activeWindow.app}`);
104
- if (result.activeWindow.bounds) {
105
- const b = result.activeWindow.bounds;
106
- parts.push(` - Position: (${b.x}, ${b.y})`);
107
- parts.push(` - Size: ${b.width}x${b.height}`);
108
- }
109
- }
110
- if (result.mousePosition) {
111
- parts.push(`**Mouse Position:** (${result.mousePosition.x}, ${result.mousePosition.y})`);
112
- }
113
- if (result.clipboard !== undefined) {
114
- parts.push(`**Clipboard Content:** ${result.clipboard}`);
115
- }
116
- if (parts.length === 0) {
117
- parts.push(`Desktop action "${action}" completed successfully.`);
118
- }
119
- return parts.join('\n');
120
- }
121
- /**
122
- * Create desktop automation tools for the agent
123
- * These tools allow AI to control the user's desktop when Ranger Desktop is running
124
- */
125
- function createDesktopTools(options = {}) {
126
- const { waitForResult } = options;
127
- const tools = [];
128
- /**
129
- * Helper to create tool function that optionally waits for results
130
- * The toolCallId is extracted from the RunnableConfig passed by LangChain
131
- */
132
- const createToolFunction = (action) => {
133
- return async (args, config) => {
134
- const toolCallId = config?.toolCall?.id ??
135
- `desktop_${Date.now()}_${Math.random().toString(36).slice(2)}`;
136
- // Create marker for Electron app
137
- const marker = {
138
- requiresDesktopExecution: true,
139
- action,
140
- args,
141
- toolCallId,
142
- };
143
- // If no callback, return marker immediately (Electron handles via SSE interception)
144
- if (!waitForResult) {
145
- return JSON.stringify(marker);
146
- }
147
- // With callback: wait for actual results from Electron app
148
- try {
149
- const result = await waitForResult(action, args, toolCallId);
150
- return formatResultForLLM(result, action);
151
- }
152
- catch (error) {
153
- const errorMessage = error instanceof Error ? error.message : String(error);
154
- return `Desktop action "${action}" failed: ${errorMessage}`;
155
- }
156
- };
157
- };
158
- // computer_screenshot
159
- tools.push(tool(createToolFunction(EDesktopTools.SCREENSHOT), {
160
- name: EDesktopTools.SCREENSHOT,
161
- description: 'Take a screenshot of the entire screen. Use this to see what is currently displayed on the desktop.',
162
- schema: ScreenshotSchema,
163
- }));
164
- // computer_click
165
- tools.push(tool(createToolFunction(EDesktopTools.CLICK), {
166
- name: EDesktopTools.CLICK,
167
- description: 'Click the mouse at the specified screen coordinates. Use screenshot first to identify the target location.',
168
- schema: ClickSchema,
169
- }));
170
- // computer_double_click
171
- tools.push(tool(createToolFunction(EDesktopTools.DOUBLE_CLICK), {
172
- name: EDesktopTools.DOUBLE_CLICK,
173
- description: 'Double-click the mouse at the specified screen coordinates.',
174
- schema: DoubleClickSchema,
175
- }));
176
- // computer_right_click
177
- tools.push(tool(createToolFunction(EDesktopTools.RIGHT_CLICK), {
178
- name: EDesktopTools.RIGHT_CLICK,
179
- description: 'Right-click the mouse at the specified screen coordinates to open context menus.',
180
- schema: RightClickSchema,
181
- }));
182
- // computer_type
183
- tools.push(tool(createToolFunction(EDesktopTools.TYPE), {
184
- name: EDesktopTools.TYPE,
185
- description: 'Type text using the keyboard. Make sure the target input field is focused first (use click).',
186
- schema: TypeSchema,
187
- }));
188
- // computer_key
189
- tools.push(tool(createToolFunction(EDesktopTools.KEY), {
190
- name: EDesktopTools.KEY,
191
- description: 'Press a single key on the keyboard (Enter, Tab, Escape, arrow keys, function keys, etc.).',
192
- schema: KeySchema,
193
- }));
194
- // computer_key_combo
195
- tools.push(tool(createToolFunction(EDesktopTools.KEY_COMBO), {
196
- name: EDesktopTools.KEY_COMBO,
197
- description: 'Press a key combination (e.g., Ctrl+C to copy, Ctrl+V to paste, Alt+Tab to switch windows).',
198
- schema: KeyComboSchema,
199
- }));
200
- // computer_scroll
201
- tools.push(tool(createToolFunction(EDesktopTools.SCROLL), {
202
- name: EDesktopTools.SCROLL,
203
- description: 'Scroll at the specified screen coordinates. Use negative deltaY to scroll up, positive to scroll down.',
204
- schema: ScrollSchema,
205
- }));
206
- // computer_drag
207
- tools.push(tool(createToolFunction(EDesktopTools.DRAG), {
208
- name: EDesktopTools.DRAG,
209
- description: 'Drag the mouse from one position to another (for moving windows, selecting text, etc.).',
210
- schema: DragSchema,
211
- }));
212
- // computer_get_active_window
213
- tools.push(tool(createToolFunction(EDesktopTools.GET_ACTIVE_WINDOW), {
214
- name: EDesktopTools.GET_ACTIVE_WINDOW,
215
- description: 'Get information about the currently active window (title, application name, position, size).',
216
- schema: GetActiveWindowSchema,
217
- }));
218
- // computer_get_mouse_position
219
- tools.push(tool(createToolFunction(EDesktopTools.GET_MOUSE_POSITION), {
220
- name: EDesktopTools.GET_MOUSE_POSITION,
221
- description: 'Get the current mouse cursor position on screen.',
222
- schema: GetMousePositionSchema,
223
- }));
224
- // clipboard_read
225
- tools.push(tool(createToolFunction(EDesktopTools.CLIPBOARD_READ), {
226
- name: EDesktopTools.CLIPBOARD_READ,
227
- description: 'Read the current contents of the system clipboard.',
228
- schema: ClipboardReadSchema,
229
- }));
230
- // clipboard_write
231
- tools.push(tool(createToolFunction(EDesktopTools.CLIPBOARD_WRITE), {
232
- name: EDesktopTools.CLIPBOARD_WRITE,
233
- description: 'Write text to the system clipboard.',
234
- schema: ClipboardWriteSchema,
235
- }));
236
- // clipboard_paste
237
- tools.push(tool(createToolFunction(EDesktopTools.CLIPBOARD_PASTE), {
238
- name: EDesktopTools.CLIPBOARD_PASTE,
239
- description: 'Paste the clipboard contents (equivalent to Ctrl+V). Use clipboard_write first to set the content.',
240
- schema: ClipboardPasteSchema,
241
- }));
242
- // computer_wait
243
- tools.push(tool(createToolFunction(EDesktopTools.WAIT), {
244
- name: EDesktopTools.WAIT,
245
- description: 'Wait for the specified number of milliseconds. Use this to wait for UI animations or loading.',
246
- schema: WaitSchema,
247
- }));
248
- return tools;
249
- }
250
- /**
251
- * Get all desktop tool names
252
- */
253
- function getDesktopToolNames() {
254
- return Object.values(EDesktopTools);
255
- }
256
- /**
257
- * Check if a tool name is a desktop tool
258
- */
259
- function isDesktopTool(name) {
260
- return Object.values(EDesktopTools).includes(name);
261
- }
262
-
263
- export { EDesktopTools, createDesktopTools, getDesktopToolNames, hasDesktopCapability, isDesktopTool };
264
- //# sourceMappingURL=DesktopTools.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DesktopTools.mjs","sources":["../../../src/tools/DesktopTools.ts"],"sourcesContent":["import { z } from 'zod';\r\nimport { tool, DynamicStructuredTool } from '@langchain/core/tools';\r\n\r\n/**\r\n * Desktop tool names - keep in sync with Ranger Desktop Electron app\r\n * These tools execute locally in the Electron app, NOT on the server\r\n */\r\nexport const EDesktopTools = {\r\n SCREENSHOT: 'computer_screenshot',\r\n CLICK: 'computer_click',\r\n DOUBLE_CLICK: 'computer_double_click',\r\n RIGHT_CLICK: 'computer_right_click',\r\n TYPE: 'computer_type',\r\n KEY: 'computer_key',\r\n KEY_COMBO: 'computer_key_combo',\r\n SCROLL: 'computer_scroll',\r\n DRAG: 'computer_drag',\r\n GET_ACTIVE_WINDOW: 'computer_get_active_window',\r\n GET_MOUSE_POSITION: 'computer_get_mouse_position',\r\n CLIPBOARD_READ: 'clipboard_read',\r\n CLIPBOARD_WRITE: 'clipboard_write',\r\n CLIPBOARD_PASTE: 'clipboard_paste',\r\n WAIT: 'computer_wait',\r\n} as const;\r\n\r\nexport type DesktopToolName =\r\n (typeof EDesktopTools)[keyof typeof EDesktopTools];\r\n\r\n/**\r\n * Callback function type for waiting on desktop action results\r\n * This allows the server (Ranger) to provide a callback that waits for the Electron app\r\n * to POST results back to the server before returning to the LLM.\r\n *\r\n * @param action - The desktop action (click, type, screenshot, etc.)\r\n * @param args - Arguments for the action\r\n * @param toolCallId - Unique ID for this tool call (from config.toolCall.id)\r\n * @returns Promise that resolves with the actual desktop result\r\n */\r\nexport type DesktopToolCallback = (\r\n action: string,\r\n args: Record<string, unknown>,\r\n toolCallId: string\r\n) => Promise<DesktopActionResult>;\r\n\r\n/**\r\n * Result returned from desktop action execution\r\n */\r\nexport interface DesktopActionResult {\r\n success: boolean;\r\n error?: string;\r\n screenshot?: {\r\n base64: string;\r\n width: number;\r\n height: number;\r\n };\r\n activeWindow?: {\r\n title: string;\r\n app: string;\r\n bounds?: { x: number; y: number; width: number; height: number };\r\n };\r\n mousePosition?: { x: number; y: number };\r\n clipboard?: string;\r\n}\r\n\r\n/**\r\n * Check if desktop capability is available based on request headers or context\r\n * The Ranger Desktop Electron app sets these headers when connected:\r\n * - X-Ranger-Desktop: true\r\n * - X-Ranger-Desktop-Capable: true\r\n */\r\nexport function hasDesktopCapability(req?: {\r\n headers?: Record<string, string | string[] | undefined>;\r\n}): boolean {\r\n if (!req?.headers) {\r\n return false;\r\n }\r\n\r\n const desktopApp = req.headers['x-ranger-desktop'];\r\n const desktopCapable = req.headers['x-ranger-desktop-capable'];\r\n\r\n return desktopApp === 'true' || desktopCapable === 'true';\r\n}\r\n\r\n// Tool schemas\r\nconst ScreenshotSchema = z.object({});\r\n\r\nconst ClickSchema = z.object({\r\n x: z.number().describe('X coordinate to click'),\r\n y: z.number().describe('Y coordinate to click'),\r\n});\r\n\r\nconst DoubleClickSchema = z.object({\r\n x: z.number().describe('X coordinate to double-click'),\r\n y: z.number().describe('Y coordinate to double-click'),\r\n});\r\n\r\nconst RightClickSchema = z.object({\r\n x: z.number().describe('X coordinate to right-click'),\r\n y: z.number().describe('Y coordinate to right-click'),\r\n});\r\n\r\nconst TypeSchema = z.object({\r\n text: z.string().describe('Text to type'),\r\n});\r\n\r\nconst KeySchema = z.object({\r\n key: z\r\n .string()\r\n .describe(\r\n 'Key to press (e.g., \"Enter\", \"Tab\", \"Escape\", \"Backspace\", \"Delete\", \"ArrowUp\", \"ArrowDown\", \"ArrowLeft\", \"ArrowRight\", \"Home\", \"End\", \"PageUp\", \"PageDown\", \"F1\"-\"F12\")'\r\n ),\r\n});\r\n\r\nconst KeyComboSchema = z.object({\r\n keys: z\r\n .array(z.string())\r\n .describe(\r\n 'Array of keys to press together (e.g., [\"Control\", \"c\"] for copy, [\"Alt\", \"Tab\"] for window switch)'\r\n ),\r\n});\r\n\r\nconst ScrollSchema = z.object({\r\n x: z.number().describe('X coordinate to scroll at'),\r\n y: z.number().describe('Y coordinate to scroll at'),\r\n deltaX: z.number().optional().describe('Horizontal scroll amount (pixels)'),\r\n deltaY: z.number().describe('Vertical scroll amount (pixels, negative = up, positive = down)'),\r\n});\r\n\r\nconst DragSchema = z.object({\r\n startX: z.number().describe('Starting X coordinate'),\r\n startY: z.number().describe('Starting Y coordinate'),\r\n endX: z.number().describe('Ending X coordinate'),\r\n endY: z.number().describe('Ending Y coordinate'),\r\n});\r\n\r\nconst GetActiveWindowSchema = z.object({});\r\n\r\nconst GetMousePositionSchema = z.object({});\r\n\r\nconst ClipboardReadSchema = z.object({});\r\n\r\nconst ClipboardWriteSchema = z.object({\r\n text: z.string().describe('Text to write to clipboard'),\r\n});\r\n\r\nconst ClipboardPasteSchema = z.object({});\r\n\r\nconst WaitSchema = z.object({\r\n ms: z.number().describe('Milliseconds to wait'),\r\n});\r\n\r\n/**\r\n * Desktop tool response interface\r\n * This is what the Electron app returns after executing the action\r\n */\r\nexport interface DesktopToolResponse {\r\n requiresDesktopExecution: true;\r\n action: string;\r\n args: Record<string, unknown>;\r\n toolCallId?: string;\r\n}\r\n\r\n/**\r\n * Options for creating desktop tools\r\n */\r\nexport interface CreateDesktopToolsOptions {\r\n /**\r\n * Optional callback that waits for desktop action results.\r\n * When provided, tools will await this callback to get actual results from the Electron app.\r\n * When not provided, tools return markers immediately (for non-server contexts).\r\n */\r\n waitForResult?: DesktopToolCallback;\r\n}\r\n\r\n/**\r\n * Format desktop action result for LLM consumption\r\n */\r\nfunction formatResultForLLM(\r\n result: DesktopActionResult,\r\n action: string\r\n): string {\r\n if (!result.success && result.error) {\r\n return `Desktop action \"${action}\" failed: ${result.error}`;\r\n }\r\n\r\n const parts: string[] = [];\r\n\r\n if (result.screenshot) {\r\n parts.push(\r\n `Screenshot captured (${result.screenshot.width}x${result.screenshot.height})`\r\n );\r\n // The base64 image will be handled separately by the message formatter\r\n }\r\n\r\n if (result.activeWindow) {\r\n parts.push(`**Active Window:**`);\r\n parts.push(` - Title: ${result.activeWindow.title}`);\r\n parts.push(` - App: ${result.activeWindow.app}`);\r\n if (result.activeWindow.bounds) {\r\n const b = result.activeWindow.bounds;\r\n parts.push(` - Position: (${b.x}, ${b.y})`);\r\n parts.push(` - Size: ${b.width}x${b.height}`);\r\n }\r\n }\r\n\r\n if (result.mousePosition) {\r\n parts.push(\r\n `**Mouse Position:** (${result.mousePosition.x}, ${result.mousePosition.y})`\r\n );\r\n }\r\n\r\n if (result.clipboard !== undefined) {\r\n parts.push(`**Clipboard Content:** ${result.clipboard}`);\r\n }\r\n\r\n if (parts.length === 0) {\r\n parts.push(`Desktop action \"${action}\" completed successfully.`);\r\n }\r\n\r\n return parts.join('\\n');\r\n}\r\n\r\n/**\r\n * Create desktop automation tools for the agent\r\n * These tools allow AI to control the user's desktop when Ranger Desktop is running\r\n */\r\nexport function createDesktopTools(\r\n options: CreateDesktopToolsOptions = {}\r\n): DynamicStructuredTool[] {\r\n const { waitForResult } = options;\r\n const tools: DynamicStructuredTool[] = [];\r\n\r\n /**\r\n * Helper to create tool function that optionally waits for results\r\n * The toolCallId is extracted from the RunnableConfig passed by LangChain\r\n */\r\n const createToolFunction = (action: string) => {\r\n return async (\r\n args: Record<string, unknown>,\r\n config?: { toolCall?: { id?: string } }\r\n ): Promise<string> => {\r\n const toolCallId =\r\n config?.toolCall?.id ??\r\n `desktop_${Date.now()}_${Math.random().toString(36).slice(2)}`;\r\n\r\n // Create marker for Electron app\r\n const marker: DesktopToolResponse = {\r\n requiresDesktopExecution: true,\r\n action,\r\n args,\r\n toolCallId,\r\n };\r\n\r\n // If no callback, return marker immediately (Electron handles via SSE interception)\r\n if (!waitForResult) {\r\n return JSON.stringify(marker);\r\n }\r\n\r\n // With callback: wait for actual results from Electron app\r\n try {\r\n const result = await waitForResult(action, args, toolCallId);\r\n return formatResultForLLM(result, action);\r\n } catch (error) {\r\n const errorMessage =\r\n error instanceof Error ? error.message : String(error);\r\n return `Desktop action \"${action}\" failed: ${errorMessage}`;\r\n }\r\n };\r\n };\r\n\r\n // computer_screenshot\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.SCREENSHOT), {\r\n name: EDesktopTools.SCREENSHOT,\r\n description:\r\n 'Take a screenshot of the entire screen. Use this to see what is currently displayed on the desktop.',\r\n schema: ScreenshotSchema,\r\n })\r\n );\r\n\r\n // computer_click\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLICK), {\r\n name: EDesktopTools.CLICK,\r\n description:\r\n 'Click the mouse at the specified screen coordinates. Use screenshot first to identify the target location.',\r\n schema: ClickSchema,\r\n })\r\n );\r\n\r\n // computer_double_click\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.DOUBLE_CLICK), {\r\n name: EDesktopTools.DOUBLE_CLICK,\r\n description:\r\n 'Double-click the mouse at the specified screen coordinates.',\r\n schema: DoubleClickSchema,\r\n })\r\n );\r\n\r\n // computer_right_click\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.RIGHT_CLICK), {\r\n name: EDesktopTools.RIGHT_CLICK,\r\n description:\r\n 'Right-click the mouse at the specified screen coordinates to open context menus.',\r\n schema: RightClickSchema,\r\n })\r\n );\r\n\r\n // computer_type\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.TYPE), {\r\n name: EDesktopTools.TYPE,\r\n description:\r\n 'Type text using the keyboard. Make sure the target input field is focused first (use click).',\r\n schema: TypeSchema,\r\n })\r\n );\r\n\r\n // computer_key\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.KEY), {\r\n name: EDesktopTools.KEY,\r\n description:\r\n 'Press a single key on the keyboard (Enter, Tab, Escape, arrow keys, function keys, etc.).',\r\n schema: KeySchema,\r\n })\r\n );\r\n\r\n // computer_key_combo\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.KEY_COMBO), {\r\n name: EDesktopTools.KEY_COMBO,\r\n description:\r\n 'Press a key combination (e.g., Ctrl+C to copy, Ctrl+V to paste, Alt+Tab to switch windows).',\r\n schema: KeyComboSchema,\r\n })\r\n );\r\n\r\n // computer_scroll\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.SCROLL), {\r\n name: EDesktopTools.SCROLL,\r\n description:\r\n 'Scroll at the specified screen coordinates. Use negative deltaY to scroll up, positive to scroll down.',\r\n schema: ScrollSchema,\r\n })\r\n );\r\n\r\n // computer_drag\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.DRAG), {\r\n name: EDesktopTools.DRAG,\r\n description:\r\n 'Drag the mouse from one position to another (for moving windows, selecting text, etc.).',\r\n schema: DragSchema,\r\n })\r\n );\r\n\r\n // computer_get_active_window\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.GET_ACTIVE_WINDOW), {\r\n name: EDesktopTools.GET_ACTIVE_WINDOW,\r\n description:\r\n 'Get information about the currently active window (title, application name, position, size).',\r\n schema: GetActiveWindowSchema,\r\n })\r\n );\r\n\r\n // computer_get_mouse_position\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.GET_MOUSE_POSITION), {\r\n name: EDesktopTools.GET_MOUSE_POSITION,\r\n description: 'Get the current mouse cursor position on screen.',\r\n schema: GetMousePositionSchema,\r\n })\r\n );\r\n\r\n // clipboard_read\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLIPBOARD_READ), {\r\n name: EDesktopTools.CLIPBOARD_READ,\r\n description: 'Read the current contents of the system clipboard.',\r\n schema: ClipboardReadSchema,\r\n })\r\n );\r\n\r\n // clipboard_write\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLIPBOARD_WRITE), {\r\n name: EDesktopTools.CLIPBOARD_WRITE,\r\n description: 'Write text to the system clipboard.',\r\n schema: ClipboardWriteSchema,\r\n })\r\n );\r\n\r\n // clipboard_paste\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.CLIPBOARD_PASTE), {\r\n name: EDesktopTools.CLIPBOARD_PASTE,\r\n description:\r\n 'Paste the clipboard contents (equivalent to Ctrl+V). Use clipboard_write first to set the content.',\r\n schema: ClipboardPasteSchema,\r\n })\r\n );\r\n\r\n // computer_wait\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.WAIT), {\r\n name: EDesktopTools.WAIT,\r\n description:\r\n 'Wait for the specified number of milliseconds. Use this to wait for UI animations or loading.',\r\n schema: WaitSchema,\r\n })\r\n );\r\n\r\n return tools;\r\n}\r\n\r\n/**\r\n * Get all desktop tool names\r\n */\r\nexport function getDesktopToolNames(): DesktopToolName[] {\r\n return Object.values(EDesktopTools);\r\n}\r\n\r\n/**\r\n * Check if a tool name is a desktop tool\r\n */\r\nexport function isDesktopTool(name: string): name is DesktopToolName {\r\n return Object.values(EDesktopTools).includes(name as DesktopToolName);\r\n}\r\n"],"names":[],"mappings":";;;AAGA;;;AAGG;AACU,MAAA,aAAa,GAAG;AAC3B,IAAA,UAAU,EAAE,qBAAqB;AACjC,IAAA,KAAK,EAAE,gBAAgB;AACvB,IAAA,YAAY,EAAE,uBAAuB;AACrC,IAAA,WAAW,EAAE,sBAAsB;AACnC,IAAA,IAAI,EAAE,eAAe;AACrB,IAAA,GAAG,EAAE,cAAc;AACnB,IAAA,SAAS,EAAE,oBAAoB;AAC/B,IAAA,MAAM,EAAE,iBAAiB;AACzB,IAAA,IAAI,EAAE,eAAe;AACrB,IAAA,iBAAiB,EAAE,4BAA4B;AAC/C,IAAA,kBAAkB,EAAE,6BAA6B;AACjD,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,IAAI,EAAE,eAAe;;AA0CvB;;;;;AAKG;AACG,SAAU,oBAAoB,CAAC,GAEpC,EAAA;AACC,IAAA,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE;AACjB,QAAA,OAAO,KAAK;;IAGd,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC;IAClD,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,0BAA0B,CAAC;AAE9D,IAAA,OAAO,UAA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a,CAAC,CAAC,QAAQ,CAAC,IAAuB,CAAC;AACvE;;;;"}
@@ -1,104 +0,0 @@
1
- import { DynamicStructuredTool } from '@langchain/core/tools';
2
- /**
3
- * Desktop tool names - keep in sync with Ranger Desktop Electron app
4
- * These tools execute locally in the Electron app, NOT on the server
5
- */
6
- export declare const EDesktopTools: {
7
- readonly SCREENSHOT: "computer_screenshot";
8
- readonly CLICK: "computer_click";
9
- readonly DOUBLE_CLICK: "computer_double_click";
10
- readonly RIGHT_CLICK: "computer_right_click";
11
- readonly TYPE: "computer_type";
12
- readonly KEY: "computer_key";
13
- readonly KEY_COMBO: "computer_key_combo";
14
- readonly SCROLL: "computer_scroll";
15
- readonly DRAG: "computer_drag";
16
- readonly GET_ACTIVE_WINDOW: "computer_get_active_window";
17
- readonly GET_MOUSE_POSITION: "computer_get_mouse_position";
18
- readonly CLIPBOARD_READ: "clipboard_read";
19
- readonly CLIPBOARD_WRITE: "clipboard_write";
20
- readonly CLIPBOARD_PASTE: "clipboard_paste";
21
- readonly WAIT: "computer_wait";
22
- };
23
- export type DesktopToolName = (typeof EDesktopTools)[keyof typeof EDesktopTools];
24
- /**
25
- * Callback function type for waiting on desktop action results
26
- * This allows the server (Ranger) to provide a callback that waits for the Electron app
27
- * to POST results back to the server before returning to the LLM.
28
- *
29
- * @param action - The desktop action (click, type, screenshot, etc.)
30
- * @param args - Arguments for the action
31
- * @param toolCallId - Unique ID for this tool call (from config.toolCall.id)
32
- * @returns Promise that resolves with the actual desktop result
33
- */
34
- export type DesktopToolCallback = (action: string, args: Record<string, unknown>, toolCallId: string) => Promise<DesktopActionResult>;
35
- /**
36
- * Result returned from desktop action execution
37
- */
38
- export interface DesktopActionResult {
39
- success: boolean;
40
- error?: string;
41
- screenshot?: {
42
- base64: string;
43
- width: number;
44
- height: number;
45
- };
46
- activeWindow?: {
47
- title: string;
48
- app: string;
49
- bounds?: {
50
- x: number;
51
- y: number;
52
- width: number;
53
- height: number;
54
- };
55
- };
56
- mousePosition?: {
57
- x: number;
58
- y: number;
59
- };
60
- clipboard?: string;
61
- }
62
- /**
63
- * Check if desktop capability is available based on request headers or context
64
- * The Ranger Desktop Electron app sets these headers when connected:
65
- * - X-Ranger-Desktop: true
66
- * - X-Ranger-Desktop-Capable: true
67
- */
68
- export declare function hasDesktopCapability(req?: {
69
- headers?: Record<string, string | string[] | undefined>;
70
- }): boolean;
71
- /**
72
- * Desktop tool response interface
73
- * This is what the Electron app returns after executing the action
74
- */
75
- export interface DesktopToolResponse {
76
- requiresDesktopExecution: true;
77
- action: string;
78
- args: Record<string, unknown>;
79
- toolCallId?: string;
80
- }
81
- /**
82
- * Options for creating desktop tools
83
- */
84
- export interface CreateDesktopToolsOptions {
85
- /**
86
- * Optional callback that waits for desktop action results.
87
- * When provided, tools will await this callback to get actual results from the Electron app.
88
- * When not provided, tools return markers immediately (for non-server contexts).
89
- */
90
- waitForResult?: DesktopToolCallback;
91
- }
92
- /**
93
- * Create desktop automation tools for the agent
94
- * These tools allow AI to control the user's desktop when Ranger Desktop is running
95
- */
96
- export declare function createDesktopTools(options?: CreateDesktopToolsOptions): DynamicStructuredTool[];
97
- /**
98
- * Get all desktop tool names
99
- */
100
- export declare function getDesktopToolNames(): DesktopToolName[];
101
- /**
102
- * Check if a tool name is a desktop tool
103
- */
104
- export declare function isDesktopTool(name: string): name is DesktopToolName;