illuma-agents 1.0.43 → 1.0.45
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.
- package/dist/cjs/tools/DesktopTools.cjs +215 -147
- package/dist/cjs/tools/DesktopTools.cjs.map +1 -1
- package/dist/esm/tools/DesktopTools.mjs +215 -147
- package/dist/esm/tools/DesktopTools.mjs.map +1 -1
- package/dist/types/tools/DesktopTools.d.ts +30 -0
- package/package.json +1 -1
- package/src/tools/DesktopTools.ts +324 -302
|
@@ -21,6 +21,12 @@ const EDesktopTools = {
|
|
|
21
21
|
CLIPBOARD_WRITE: 'clipboard_write',
|
|
22
22
|
CLIPBOARD_PASTE: 'clipboard_paste',
|
|
23
23
|
WAIT: 'computer_wait',
|
|
24
|
+
// Native UI Automation tools (Windows) - faster and more reliable than screenshot-based
|
|
25
|
+
UI_FIND_ELEMENT: 'ui_find_element',
|
|
26
|
+
UI_CLICK_ELEMENT: 'ui_click_element',
|
|
27
|
+
UI_GET_WINDOW_TREE: 'ui_get_window_tree',
|
|
28
|
+
UI_FIND_BUTTONS: 'ui_find_buttons',
|
|
29
|
+
UI_FIND_INPUTS: 'ui_find_inputs',
|
|
24
30
|
};
|
|
25
31
|
/**
|
|
26
32
|
* Check if desktop capability is available based on request headers or context
|
|
@@ -85,6 +91,23 @@ const ClipboardPasteSchema = z.object({});
|
|
|
85
91
|
const WaitSchema = z.object({
|
|
86
92
|
ms: z.number().describe('Milliseconds to wait'),
|
|
87
93
|
});
|
|
94
|
+
// ============ Native UI Automation Schemas (Windows) ============
|
|
95
|
+
const UIFindElementSchema = z.object({
|
|
96
|
+
name: z.string().optional().describe('Element name/label to find (e.g., "Submit", "OK", "File")'),
|
|
97
|
+
automationId: z.string().optional().describe('Automation ID of element (unique identifier)'),
|
|
98
|
+
controlType: z.string().optional().describe('Type of control: Button, Edit, Text, ComboBox, List, Menu, MenuItem, Window, etc.'),
|
|
99
|
+
});
|
|
100
|
+
const UIClickElementSchema = z.object({
|
|
101
|
+
name: z.string().optional().describe('Element name/label to click'),
|
|
102
|
+
automationId: z.string().optional().describe('Automation ID of element to click'),
|
|
103
|
+
controlType: z.string().optional().describe('Type of control: Button, Edit, etc.'),
|
|
104
|
+
clickType: z.enum(['left', 'right', 'double']).optional().describe('Click type (default: left)'),
|
|
105
|
+
});
|
|
106
|
+
const UIGetWindowTreeSchema = z.object({
|
|
107
|
+
maxDepth: z.number().optional().describe('Maximum depth to traverse (default: 3)'),
|
|
108
|
+
});
|
|
109
|
+
const UIFindButtonsSchema = z.object({});
|
|
110
|
+
const UIFindInputsSchema = z.object({});
|
|
88
111
|
/**
|
|
89
112
|
* Format desktop action result for LLM consumption
|
|
90
113
|
*/
|
|
@@ -113,35 +136,46 @@ function formatResultForLLM(result, action) {
|
|
|
113
136
|
if (result.clipboard !== undefined) {
|
|
114
137
|
parts.push(`**Clipboard Content:** ${result.clipboard}`);
|
|
115
138
|
}
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
// UI Automation results
|
|
140
|
+
if (result.uiElement) {
|
|
141
|
+
const el = result.uiElement;
|
|
142
|
+
parts.push(`**UI Element Found:**`);
|
|
143
|
+
parts.push(` - Name: "${el.name}"`);
|
|
144
|
+
parts.push(` - AutomationId: "${el.automationId}"`);
|
|
145
|
+
parts.push(` - Type: ${el.controlType}`);
|
|
146
|
+
if (el.boundingRectangle) {
|
|
147
|
+
const b = el.boundingRectangle;
|
|
148
|
+
parts.push(` - Bounds: (${b.x}, ${b.y}) ${b.width}x${b.height}`);
|
|
149
|
+
parts.push(` - Center: (${Math.round(b.x + b.width / 2)}, ${Math.round(b.y + b.height / 2)})`);
|
|
150
|
+
}
|
|
151
|
+
parts.push(` - Enabled: ${el.isEnabled}`);
|
|
118
152
|
}
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const toolCallId = config?.toolCall?.id || `desktop-${Date.now()}`;
|
|
126
|
-
if (waitForResult) {
|
|
127
|
-
// Server context: wait for actual result from Electron app
|
|
128
|
-
try {
|
|
129
|
-
const result = await waitForResult(action, args, toolCallId);
|
|
130
|
-
return formatResultForLLM(result, action);
|
|
153
|
+
if (result.uiElements && result.uiElements.length > 0) {
|
|
154
|
+
parts.push(`**UI Elements Found (${result.uiElements.length}):**`);
|
|
155
|
+
for (const el of result.uiElements.slice(0, 20)) { // Limit to 20
|
|
156
|
+
const bounds = el.boundingRectangle ?
|
|
157
|
+
` at (${el.boundingRectangle.x}, ${el.boundingRectangle.y})` : '';
|
|
158
|
+
parts.push(` - [${el.controlType}] "${el.name}"${el.automationId ? ` (id: ${el.automationId})` : ''}${bounds}`);
|
|
131
159
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return `Desktop action "${action}" failed: ${errorMessage}`;
|
|
160
|
+
if (result.uiElements.length > 20) {
|
|
161
|
+
parts.push(` ... and ${result.uiElements.length - 20} more`);
|
|
135
162
|
}
|
|
136
163
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
164
|
+
if (result.uiTree) {
|
|
165
|
+
parts.push(`**UI Tree:**`);
|
|
166
|
+
parts.push('```json');
|
|
167
|
+
parts.push(JSON.stringify(result.uiTree, null, 2).slice(0, 3000)); // Limit size
|
|
168
|
+
parts.push('```');
|
|
169
|
+
}
|
|
170
|
+
if (result.data && !result.uiElement && !result.uiElements && !result.uiTree) {
|
|
171
|
+
// Generic data fallback
|
|
172
|
+
parts.push(`**Result:**`);
|
|
173
|
+
parts.push(JSON.stringify(result.data, null, 2).slice(0, 2000));
|
|
174
|
+
}
|
|
175
|
+
if (parts.length === 0) {
|
|
176
|
+
parts.push(`Desktop action "${action}" completed successfully.`);
|
|
177
|
+
}
|
|
178
|
+
return parts.join('\\n');
|
|
145
179
|
}
|
|
146
180
|
/**
|
|
147
181
|
* Create desktop automation tools for the agent
|
|
@@ -149,128 +183,162 @@ async function createToolResult(action, args, config, waitForResult) {
|
|
|
149
183
|
*/
|
|
150
184
|
function createDesktopTools(options = {}) {
|
|
151
185
|
const { waitForResult } = options;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
186
|
+
const tools = [];
|
|
187
|
+
/**
|
|
188
|
+
* Helper to create tool function that optionally waits for results
|
|
189
|
+
* The toolCallId is extracted from the RunnableConfig passed by LangChain
|
|
190
|
+
*/
|
|
191
|
+
const createToolFunction = (action) => {
|
|
192
|
+
return async (args, config) => {
|
|
193
|
+
const toolCallId = config?.toolCall?.id ??
|
|
194
|
+
`desktop_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
195
|
+
// Create marker for Electron app
|
|
196
|
+
const marker = {
|
|
197
|
+
requiresDesktopExecution: true,
|
|
198
|
+
action,
|
|
199
|
+
args,
|
|
200
|
+
toolCallId,
|
|
201
|
+
};
|
|
202
|
+
// If no callback, return marker immediately (Electron handles via SSE interception)
|
|
203
|
+
if (!waitForResult) {
|
|
204
|
+
return JSON.stringify(marker);
|
|
205
|
+
}
|
|
206
|
+
// With callback: wait for actual results from Electron app
|
|
207
|
+
try {
|
|
208
|
+
const result = await waitForResult(action, args, toolCallId);
|
|
209
|
+
return formatResultForLLM(result, action);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
213
|
+
return `Desktop action "${action}" failed: ${errorMessage}`;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
// computer_screenshot
|
|
218
|
+
tools.push(tool(createToolFunction(EDesktopTools.SCREENSHOT), {
|
|
219
|
+
name: EDesktopTools.SCREENSHOT,
|
|
220
|
+
description: 'Take a screenshot of the entire screen. Use this to see what is currently displayed on the desktop.',
|
|
221
|
+
schema: ScreenshotSchema,
|
|
222
|
+
}));
|
|
223
|
+
// computer_click
|
|
224
|
+
tools.push(tool(createToolFunction(EDesktopTools.CLICK), {
|
|
225
|
+
name: EDesktopTools.CLICK,
|
|
226
|
+
description: 'Click the mouse at the specified screen coordinates. Use screenshot first to identify the target location.',
|
|
227
|
+
schema: ClickSchema,
|
|
228
|
+
}));
|
|
229
|
+
// computer_double_click
|
|
230
|
+
tools.push(tool(createToolFunction(EDesktopTools.DOUBLE_CLICK), {
|
|
231
|
+
name: EDesktopTools.DOUBLE_CLICK,
|
|
232
|
+
description: 'Double-click the mouse at the specified screen coordinates.',
|
|
233
|
+
schema: DoubleClickSchema,
|
|
234
|
+
}));
|
|
235
|
+
// computer_right_click
|
|
236
|
+
tools.push(tool(createToolFunction(EDesktopTools.RIGHT_CLICK), {
|
|
237
|
+
name: EDesktopTools.RIGHT_CLICK,
|
|
238
|
+
description: 'Right-click the mouse at the specified screen coordinates to open context menus.',
|
|
239
|
+
schema: RightClickSchema,
|
|
240
|
+
}));
|
|
241
|
+
// computer_type
|
|
242
|
+
tools.push(tool(createToolFunction(EDesktopTools.TYPE), {
|
|
243
|
+
name: EDesktopTools.TYPE,
|
|
244
|
+
description: 'Type text using the keyboard. Make sure the target input field is focused first (use click).',
|
|
245
|
+
schema: TypeSchema,
|
|
246
|
+
}));
|
|
247
|
+
// computer_key
|
|
248
|
+
tools.push(tool(createToolFunction(EDesktopTools.KEY), {
|
|
249
|
+
name: EDesktopTools.KEY,
|
|
250
|
+
description: 'Press a single key on the keyboard (Enter, Tab, Escape, arrow keys, function keys, etc.).',
|
|
251
|
+
schema: KeySchema,
|
|
252
|
+
}));
|
|
253
|
+
// computer_key_combo
|
|
254
|
+
tools.push(tool(createToolFunction(EDesktopTools.KEY_COMBO), {
|
|
255
|
+
name: EDesktopTools.KEY_COMBO,
|
|
256
|
+
description: 'Press a key combination (e.g., Ctrl+C to copy, Ctrl+V to paste, Alt+Tab to switch windows).',
|
|
257
|
+
schema: KeyComboSchema,
|
|
258
|
+
}));
|
|
259
|
+
// computer_scroll
|
|
260
|
+
tools.push(tool(createToolFunction(EDesktopTools.SCROLL), {
|
|
261
|
+
name: EDesktopTools.SCROLL,
|
|
262
|
+
description: 'Scroll at the specified screen coordinates. Use negative deltaY to scroll up, positive to scroll down.',
|
|
263
|
+
schema: ScrollSchema,
|
|
264
|
+
}));
|
|
265
|
+
// computer_drag
|
|
266
|
+
tools.push(tool(createToolFunction(EDesktopTools.DRAG), {
|
|
267
|
+
name: EDesktopTools.DRAG,
|
|
268
|
+
description: 'Drag the mouse from one position to another (for moving windows, selecting text, etc.).',
|
|
269
|
+
schema: DragSchema,
|
|
270
|
+
}));
|
|
271
|
+
// computer_get_active_window
|
|
272
|
+
tools.push(tool(createToolFunction(EDesktopTools.GET_ACTIVE_WINDOW), {
|
|
273
|
+
name: EDesktopTools.GET_ACTIVE_WINDOW,
|
|
274
|
+
description: 'Get information about the currently active window (title, application name, position, size).',
|
|
275
|
+
schema: GetActiveWindowSchema,
|
|
276
|
+
}));
|
|
277
|
+
// computer_get_mouse_position
|
|
278
|
+
tools.push(tool(createToolFunction(EDesktopTools.GET_MOUSE_POSITION), {
|
|
279
|
+
name: EDesktopTools.GET_MOUSE_POSITION,
|
|
280
|
+
description: 'Get the current mouse cursor position on screen.',
|
|
281
|
+
schema: GetMousePositionSchema,
|
|
282
|
+
}));
|
|
283
|
+
// clipboard_read
|
|
284
|
+
tools.push(tool(createToolFunction(EDesktopTools.CLIPBOARD_READ), {
|
|
285
|
+
name: EDesktopTools.CLIPBOARD_READ,
|
|
286
|
+
description: 'Read the current contents of the system clipboard.',
|
|
287
|
+
schema: ClipboardReadSchema,
|
|
288
|
+
}));
|
|
289
|
+
// clipboard_write
|
|
290
|
+
tools.push(tool(createToolFunction(EDesktopTools.CLIPBOARD_WRITE), {
|
|
291
|
+
name: EDesktopTools.CLIPBOARD_WRITE,
|
|
292
|
+
description: 'Write text to the system clipboard.',
|
|
293
|
+
schema: ClipboardWriteSchema,
|
|
294
|
+
}));
|
|
295
|
+
// clipboard_paste
|
|
296
|
+
tools.push(tool(createToolFunction(EDesktopTools.CLIPBOARD_PASTE), {
|
|
297
|
+
name: EDesktopTools.CLIPBOARD_PASTE,
|
|
298
|
+
description: 'Paste the clipboard contents (equivalent to Ctrl+V). Use clipboard_write first to set the content.',
|
|
299
|
+
schema: ClipboardPasteSchema,
|
|
300
|
+
}));
|
|
301
|
+
// computer_wait
|
|
302
|
+
tools.push(tool(createToolFunction(EDesktopTools.WAIT), {
|
|
303
|
+
name: EDesktopTools.WAIT,
|
|
304
|
+
description: 'Wait for the specified number of milliseconds. Use this to wait for UI animations or loading.',
|
|
305
|
+
schema: WaitSchema,
|
|
306
|
+
}));
|
|
307
|
+
// ============ Native UI Automation Tools (Windows) ============
|
|
308
|
+
// These are FASTER and MORE RELIABLE than screenshot-based automation
|
|
309
|
+
// They find elements by semantic properties (name, automationId, type)
|
|
310
|
+
// instead of relying on pixel coordinates from screenshots
|
|
311
|
+
// ui_find_element
|
|
312
|
+
tools.push(tool(createToolFunction(EDesktopTools.UI_FIND_ELEMENT), {
|
|
313
|
+
name: EDesktopTools.UI_FIND_ELEMENT,
|
|
314
|
+
description: '🚀 PREFERRED: Find a UI element by semantic properties (name, automationId, controlType). MUCH FASTER than screenshot analysis. Returns element bounds for clicking. Windows only.',
|
|
315
|
+
schema: UIFindElementSchema,
|
|
316
|
+
}));
|
|
317
|
+
// ui_click_element
|
|
318
|
+
tools.push(tool(createToolFunction(EDesktopTools.UI_CLICK_ELEMENT), {
|
|
319
|
+
name: EDesktopTools.UI_CLICK_ELEMENT,
|
|
320
|
+
description: '🚀 PREFERRED: Find and click a UI element by name/automationId. More reliable than coordinate-based clicking. Example: ui_click_element({name: "OK"}) or ui_click_element({controlType: "Button", name: "Submit"}). Windows only.',
|
|
321
|
+
schema: UIClickElementSchema,
|
|
322
|
+
}));
|
|
323
|
+
// ui_get_window_tree
|
|
324
|
+
tools.push(tool(createToolFunction(EDesktopTools.UI_GET_WINDOW_TREE), {
|
|
325
|
+
name: EDesktopTools.UI_GET_WINDOW_TREE,
|
|
326
|
+
description: 'Get the UI element tree of the active window. Shows all buttons, inputs, menus, etc. with their names and automationIds. Use this to discover elements before clicking. Windows only.',
|
|
327
|
+
schema: UIGetWindowTreeSchema,
|
|
328
|
+
}));
|
|
329
|
+
// ui_find_buttons
|
|
330
|
+
tools.push(tool(createToolFunction(EDesktopTools.UI_FIND_BUTTONS), {
|
|
331
|
+
name: EDesktopTools.UI_FIND_BUTTONS,
|
|
332
|
+
description: 'Find all clickable buttons in the active window. Returns list with names and positions. Useful for discovering available actions. Windows only.',
|
|
333
|
+
schema: UIFindButtonsSchema,
|
|
334
|
+
}));
|
|
335
|
+
// ui_find_inputs
|
|
336
|
+
tools.push(tool(createToolFunction(EDesktopTools.UI_FIND_INPUTS), {
|
|
337
|
+
name: EDesktopTools.UI_FIND_INPUTS,
|
|
338
|
+
description: 'Find all text input fields in the active window. Returns list with names and positions. Useful for discovering form fields. Windows only.',
|
|
339
|
+
schema: UIFindInputsSchema,
|
|
340
|
+
}));
|
|
341
|
+
return tools;
|
|
274
342
|
}
|
|
275
343
|
/**
|
|
276
344
|
* Get all desktop tool names
|
|
@@ -1 +1 @@
|
|
|
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 * Type for tool configuration passed by LangChain runtime\r\n */\r\ntype ToolCallConfig = { toolCall?: { id?: string } };\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 a tool result (either wait for callback or return marker)\r\n */\r\nasync function createToolResult(\r\n action: string,\r\n args: Record<string, unknown>,\r\n config: ToolCallConfig | undefined,\r\n waitForResult?: DesktopToolCallback\r\n): Promise<string> {\r\n const toolCallId = config?.toolCall?.id || `desktop-${Date.now()}`;\r\n\r\n if (waitForResult) {\r\n // Server context: wait for actual result 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 // Non-server context: return marker for later processing\r\n const response: DesktopToolResponse = {\r\n requiresDesktopExecution: true,\r\n action,\r\n args,\r\n toolCallId,\r\n };\r\n return JSON.stringify(response);\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\r\n return [\r\n // computer_screenshot\r\n tool(\r\n async (_args, config) => {\r\n return createToolResult(\r\n EDesktopTools.SCREENSHOT,\r\n {},\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.CLICK,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.DOUBLE_CLICK,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.RIGHT_CLICK,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.TYPE,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.KEY,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.KEY_COMBO,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.SCROLL,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.DRAG,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (_args, config) => {\r\n return createToolResult(\r\n EDesktopTools.GET_ACTIVE_WINDOW,\r\n {},\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (_args, config) => {\r\n return createToolResult(\r\n EDesktopTools.GET_MOUSE_POSITION,\r\n {},\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (_args, config) => {\r\n return createToolResult(\r\n EDesktopTools.CLIPBOARD_READ,\r\n {},\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.CLIPBOARD_WRITE,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (_args, config) => {\r\n return createToolResult(\r\n EDesktopTools.CLIPBOARD_PASTE,\r\n {},\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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 tool(\r\n async (args, config) => {\r\n return createToolResult(\r\n EDesktopTools.WAIT,\r\n args,\r\n config as ToolCallConfig,\r\n waitForResult\r\n );\r\n },\r\n {\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}\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":";;;AAQA;;;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,EAA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;AACrC;AAEA;;AAEG;AACG,SAAU,aAAa,CAAC,IAAY,EAAA;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,IAAuB,CAAC;AACvE;;;;"}
|
|
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 // Native UI Automation tools (Windows) - faster and more reliable than screenshot-based\r\n UI_FIND_ELEMENT: 'ui_find_element',\r\n UI_CLICK_ELEMENT: 'ui_click_element',\r\n UI_GET_WINDOW_TREE: 'ui_get_window_tree',\r\n UI_FIND_BUTTONS: 'ui_find_buttons',\r\n UI_FIND_INPUTS: 'ui_find_inputs',\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 // UI Automation results\r\n uiElement?: {\r\n name: string;\r\n automationId: string;\r\n controlType: string;\r\n boundingRectangle?: { x: number; y: number; width: number; height: number };\r\n isEnabled: boolean;\r\n };\r\n uiElements?: Array<{\r\n name: string;\r\n automationId: string;\r\n controlType: string;\r\n boundingRectangle?: { x: number; y: number; width: number; height: number };\r\n }>;\r\n uiTree?: unknown;\r\n // Generic data for extended results\r\n data?: unknown;\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// ============ Native UI Automation Schemas (Windows) ============\r\n\r\nconst UIFindElementSchema = z.object({\r\n name: z.string().optional().describe('Element name/label to find (e.g., \"Submit\", \"OK\", \"File\")'),\r\n automationId: z.string().optional().describe('Automation ID of element (unique identifier)'),\r\n controlType: z.string().optional().describe('Type of control: Button, Edit, Text, ComboBox, List, Menu, MenuItem, Window, etc.'),\r\n});\r\n\r\nconst UIClickElementSchema = z.object({\r\n name: z.string().optional().describe('Element name/label to click'),\r\n automationId: z.string().optional().describe('Automation ID of element to click'),\r\n controlType: z.string().optional().describe('Type of control: Button, Edit, etc.'),\r\n clickType: z.enum(['left', 'right', 'double']).optional().describe('Click type (default: left)'),\r\n});\r\n\r\nconst UIGetWindowTreeSchema = z.object({\r\n maxDepth: z.number().optional().describe('Maximum depth to traverse (default: 3)'),\r\n});\r\n\r\nconst UIFindButtonsSchema = z.object({});\r\n\r\nconst UIFindInputsSchema = z.object({});\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 // UI Automation results\r\n if (result.uiElement) {\r\n const el = result.uiElement;\r\n parts.push(`**UI Element Found:**`);\r\n parts.push(` - Name: \"${el.name}\"`);\r\n parts.push(` - AutomationId: \"${el.automationId}\"`);\r\n parts.push(` - Type: ${el.controlType}`);\r\n if (el.boundingRectangle) {\r\n const b = el.boundingRectangle;\r\n parts.push(` - Bounds: (${b.x}, ${b.y}) ${b.width}x${b.height}`);\r\n parts.push(` - Center: (${Math.round(b.x + b.width/2)}, ${Math.round(b.y + b.height/2)})`);\r\n }\r\n parts.push(` - Enabled: ${el.isEnabled}`);\r\n }\r\n\r\n if (result.uiElements && result.uiElements.length > 0) {\r\n parts.push(`**UI Elements Found (${result.uiElements.length}):**`);\r\n for (const el of result.uiElements.slice(0, 20)) { // Limit to 20\r\n const bounds = el.boundingRectangle ? \r\n ` at (${el.boundingRectangle.x}, ${el.boundingRectangle.y})` : '';\r\n parts.push(` - [${el.controlType}] \"${el.name}\"${el.automationId ? ` (id: ${el.automationId})` : ''}${bounds}`);\r\n }\r\n if (result.uiElements.length > 20) {\r\n parts.push(` ... and ${result.uiElements.length - 20} more`);\r\n }\r\n }\r\n\r\n if (result.uiTree) {\r\n parts.push(`**UI Tree:**`);\r\n parts.push('```json');\r\n parts.push(JSON.stringify(result.uiTree, null, 2).slice(0, 3000)); // Limit size\r\n parts.push('```');\r\n }\r\n\r\n if (result.data && !result.uiElement && !result.uiElements && !result.uiTree) {\r\n // Generic data fallback\r\n parts.push(`**Result:**`);\r\n parts.push(JSON.stringify(result.data, null, 2).slice(0, 2000));\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 // ============ Native UI Automation Tools (Windows) ============\r\n // These are FASTER and MORE RELIABLE than screenshot-based automation\r\n // They find elements by semantic properties (name, automationId, type)\r\n // instead of relying on pixel coordinates from screenshots\r\n\r\n // ui_find_element\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.UI_FIND_ELEMENT), {\r\n name: EDesktopTools.UI_FIND_ELEMENT,\r\n description:\r\n '🚀 PREFERRED: Find a UI element by semantic properties (name, automationId, controlType). MUCH FASTER than screenshot analysis. Returns element bounds for clicking. Windows only.',\r\n schema: UIFindElementSchema,\r\n })\r\n );\r\n\r\n // ui_click_element\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.UI_CLICK_ELEMENT), {\r\n name: EDesktopTools.UI_CLICK_ELEMENT,\r\n description:\r\n '🚀 PREFERRED: Find and click a UI element by name/automationId. More reliable than coordinate-based clicking. Example: ui_click_element({name: \"OK\"}) or ui_click_element({controlType: \"Button\", name: \"Submit\"}). Windows only.',\r\n schema: UIClickElementSchema,\r\n })\r\n );\r\n\r\n // ui_get_window_tree\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.UI_GET_WINDOW_TREE), {\r\n name: EDesktopTools.UI_GET_WINDOW_TREE,\r\n description:\r\n 'Get the UI element tree of the active window. Shows all buttons, inputs, menus, etc. with their names and automationIds. Use this to discover elements before clicking. Windows only.',\r\n schema: UIGetWindowTreeSchema,\r\n })\r\n );\r\n\r\n // ui_find_buttons\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.UI_FIND_BUTTONS), {\r\n name: EDesktopTools.UI_FIND_BUTTONS,\r\n description:\r\n 'Find all clickable buttons in the active window. Returns list with names and positions. Useful for discovering available actions. Windows only.',\r\n schema: UIFindButtonsSchema,\r\n })\r\n );\r\n\r\n // ui_find_inputs\r\n tools.push(\r\n tool(createToolFunction(EDesktopTools.UI_FIND_INPUTS), {\r\n name: EDesktopTools.UI_FIND_INPUTS,\r\n description:\r\n 'Find all text input fields in the active window. Returns list with names and positions. Useful for discovering form fields. Windows only.',\r\n schema: UIFindInputsSchema,\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;;AAErB,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,gBAAgB,EAAE,kBAAkB;AACpC,IAAA,kBAAkB,EAAE,oBAAoB;AACxC,IAAA,eAAe,EAAE,iBAAiB;AAClC,IAAA,cAAc,EAAE,gBAAgB;;AA2DlC;;;;;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,UAAU,KAAK,MAAM,IAAI,cAAc,KAAK,MAAM;AAC3D;AAEA;AACA,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;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{
|
|
|
19
19
|
readonly CLIPBOARD_WRITE: "clipboard_write";
|
|
20
20
|
readonly CLIPBOARD_PASTE: "clipboard_paste";
|
|
21
21
|
readonly WAIT: "computer_wait";
|
|
22
|
+
readonly UI_FIND_ELEMENT: "ui_find_element";
|
|
23
|
+
readonly UI_CLICK_ELEMENT: "ui_click_element";
|
|
24
|
+
readonly UI_GET_WINDOW_TREE: "ui_get_window_tree";
|
|
25
|
+
readonly UI_FIND_BUTTONS: "ui_find_buttons";
|
|
26
|
+
readonly UI_FIND_INPUTS: "ui_find_inputs";
|
|
22
27
|
};
|
|
23
28
|
export type DesktopToolName = (typeof EDesktopTools)[keyof typeof EDesktopTools];
|
|
24
29
|
/**
|
|
@@ -58,6 +63,31 @@ export interface DesktopActionResult {
|
|
|
58
63
|
y: number;
|
|
59
64
|
};
|
|
60
65
|
clipboard?: string;
|
|
66
|
+
uiElement?: {
|
|
67
|
+
name: string;
|
|
68
|
+
automationId: string;
|
|
69
|
+
controlType: string;
|
|
70
|
+
boundingRectangle?: {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
};
|
|
76
|
+
isEnabled: boolean;
|
|
77
|
+
};
|
|
78
|
+
uiElements?: Array<{
|
|
79
|
+
name: string;
|
|
80
|
+
automationId: string;
|
|
81
|
+
controlType: string;
|
|
82
|
+
boundingRectangle?: {
|
|
83
|
+
x: number;
|
|
84
|
+
y: number;
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
};
|
|
88
|
+
}>;
|
|
89
|
+
uiTree?: unknown;
|
|
90
|
+
data?: unknown;
|
|
61
91
|
}
|
|
62
92
|
/**
|
|
63
93
|
* Check if desktop capability is available based on request headers or context
|