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.
- package/dist/cjs/common/enum.cjs +1 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/main.cjs +3 -6
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/tools/PresentationTool.cjs +291 -0
- package/dist/cjs/tools/PresentationTool.cjs.map +1 -0
- package/dist/esm/common/enum.mjs +1 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -1
- package/dist/esm/tools/PresentationTool.mjs +288 -0
- package/dist/esm/tools/PresentationTool.mjs.map +1 -0
- package/dist/types/common/enum.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/tools/PresentationTool.d.ts +2358 -0
- package/package.json +1 -1
- package/src/common/enum.ts +1 -0
- package/src/index.ts +1 -1
- package/src/tools/PresentationTool.ts +356 -0
- package/dist/cjs/tools/DesktopTools.cjs +0 -270
- package/dist/cjs/tools/DesktopTools.cjs.map +0 -1
- package/dist/esm/tools/DesktopTools.mjs +0 -264
- package/dist/esm/tools/DesktopTools.mjs.map +0 -1
- package/dist/types/tools/DesktopTools.d.ts +0 -104
- package/src/tools/DesktopTools.ts +0 -433
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { tool, DynamicStructuredTool } 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
|
-
export 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
|
-
} as const;
|
|
25
|
-
|
|
26
|
-
export type DesktopToolName =
|
|
27
|
-
(typeof EDesktopTools)[keyof typeof EDesktopTools];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Callback function type for waiting on desktop action results
|
|
31
|
-
* This allows the server (Ranger) to provide a callback that waits for the Electron app
|
|
32
|
-
* to POST results back to the server before returning to the LLM.
|
|
33
|
-
*
|
|
34
|
-
* @param action - The desktop action (click, type, screenshot, etc.)
|
|
35
|
-
* @param args - Arguments for the action
|
|
36
|
-
* @param toolCallId - Unique ID for this tool call (from config.toolCall.id)
|
|
37
|
-
* @returns Promise that resolves with the actual desktop result
|
|
38
|
-
*/
|
|
39
|
-
export type DesktopToolCallback = (
|
|
40
|
-
action: string,
|
|
41
|
-
args: Record<string, unknown>,
|
|
42
|
-
toolCallId: string
|
|
43
|
-
) => Promise<DesktopActionResult>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Result returned from desktop action execution
|
|
47
|
-
*/
|
|
48
|
-
export interface DesktopActionResult {
|
|
49
|
-
success: boolean;
|
|
50
|
-
error?: string;
|
|
51
|
-
screenshot?: {
|
|
52
|
-
base64: string;
|
|
53
|
-
width: number;
|
|
54
|
-
height: number;
|
|
55
|
-
};
|
|
56
|
-
activeWindow?: {
|
|
57
|
-
title: string;
|
|
58
|
-
app: string;
|
|
59
|
-
bounds?: { x: number; y: number; width: number; height: number };
|
|
60
|
-
};
|
|
61
|
-
mousePosition?: { x: number; y: number };
|
|
62
|
-
clipboard?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Check if desktop capability is available based on request headers or context
|
|
67
|
-
* The Ranger Desktop Electron app sets these headers when connected:
|
|
68
|
-
* - X-Ranger-Desktop: true
|
|
69
|
-
* - X-Ranger-Desktop-Capable: true
|
|
70
|
-
*/
|
|
71
|
-
export function hasDesktopCapability(req?: {
|
|
72
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
73
|
-
}): boolean {
|
|
74
|
-
if (!req?.headers) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const desktopApp = req.headers['x-ranger-desktop'];
|
|
79
|
-
const desktopCapable = req.headers['x-ranger-desktop-capable'];
|
|
80
|
-
|
|
81
|
-
return desktopApp === 'true' || desktopCapable === 'true';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Tool schemas
|
|
85
|
-
const ScreenshotSchema = z.object({});
|
|
86
|
-
|
|
87
|
-
const ClickSchema = z.object({
|
|
88
|
-
x: z.number().describe('X coordinate to click'),
|
|
89
|
-
y: z.number().describe('Y coordinate to click'),
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const DoubleClickSchema = z.object({
|
|
93
|
-
x: z.number().describe('X coordinate to double-click'),
|
|
94
|
-
y: z.number().describe('Y coordinate to double-click'),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const RightClickSchema = z.object({
|
|
98
|
-
x: z.number().describe('X coordinate to right-click'),
|
|
99
|
-
y: z.number().describe('Y coordinate to right-click'),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const TypeSchema = z.object({
|
|
103
|
-
text: z.string().describe('Text to type'),
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const KeySchema = z.object({
|
|
107
|
-
key: z
|
|
108
|
-
.string()
|
|
109
|
-
.describe(
|
|
110
|
-
'Key to press (e.g., "Enter", "Tab", "Escape", "Backspace", "Delete", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown", "F1"-"F12")'
|
|
111
|
-
),
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const KeyComboSchema = z.object({
|
|
115
|
-
keys: z
|
|
116
|
-
.array(z.string())
|
|
117
|
-
.describe(
|
|
118
|
-
'Array of keys to press together (e.g., ["Control", "c"] for copy, ["Alt", "Tab"] for window switch)'
|
|
119
|
-
),
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const ScrollSchema = z.object({
|
|
123
|
-
x: z.number().describe('X coordinate to scroll at'),
|
|
124
|
-
y: z.number().describe('Y coordinate to scroll at'),
|
|
125
|
-
deltaX: z.number().optional().describe('Horizontal scroll amount (pixels)'),
|
|
126
|
-
deltaY: z.number().describe('Vertical scroll amount (pixels, negative = up, positive = down)'),
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const DragSchema = z.object({
|
|
130
|
-
startX: z.number().describe('Starting X coordinate'),
|
|
131
|
-
startY: z.number().describe('Starting Y coordinate'),
|
|
132
|
-
endX: z.number().describe('Ending X coordinate'),
|
|
133
|
-
endY: z.number().describe('Ending Y coordinate'),
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const GetActiveWindowSchema = z.object({});
|
|
137
|
-
|
|
138
|
-
const GetMousePositionSchema = z.object({});
|
|
139
|
-
|
|
140
|
-
const ClipboardReadSchema = z.object({});
|
|
141
|
-
|
|
142
|
-
const ClipboardWriteSchema = z.object({
|
|
143
|
-
text: z.string().describe('Text to write to clipboard'),
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const ClipboardPasteSchema = z.object({});
|
|
147
|
-
|
|
148
|
-
const WaitSchema = z.object({
|
|
149
|
-
ms: z.number().describe('Milliseconds to wait'),
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Desktop tool response interface
|
|
154
|
-
* This is what the Electron app returns after executing the action
|
|
155
|
-
*/
|
|
156
|
-
export interface DesktopToolResponse {
|
|
157
|
-
requiresDesktopExecution: true;
|
|
158
|
-
action: string;
|
|
159
|
-
args: Record<string, unknown>;
|
|
160
|
-
toolCallId?: string;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Options for creating desktop tools
|
|
165
|
-
*/
|
|
166
|
-
export interface CreateDesktopToolsOptions {
|
|
167
|
-
/**
|
|
168
|
-
* Optional callback that waits for desktop action results.
|
|
169
|
-
* When provided, tools will await this callback to get actual results from the Electron app.
|
|
170
|
-
* When not provided, tools return markers immediately (for non-server contexts).
|
|
171
|
-
*/
|
|
172
|
-
waitForResult?: DesktopToolCallback;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Format desktop action result for LLM consumption
|
|
177
|
-
*/
|
|
178
|
-
function formatResultForLLM(
|
|
179
|
-
result: DesktopActionResult,
|
|
180
|
-
action: string
|
|
181
|
-
): string {
|
|
182
|
-
if (!result.success && result.error) {
|
|
183
|
-
return `Desktop action "${action}" failed: ${result.error}`;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const parts: string[] = [];
|
|
187
|
-
|
|
188
|
-
if (result.screenshot) {
|
|
189
|
-
parts.push(
|
|
190
|
-
`Screenshot captured (${result.screenshot.width}x${result.screenshot.height})`
|
|
191
|
-
);
|
|
192
|
-
// The base64 image will be handled separately by the message formatter
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (result.activeWindow) {
|
|
196
|
-
parts.push(`**Active Window:**`);
|
|
197
|
-
parts.push(` - Title: ${result.activeWindow.title}`);
|
|
198
|
-
parts.push(` - App: ${result.activeWindow.app}`);
|
|
199
|
-
if (result.activeWindow.bounds) {
|
|
200
|
-
const b = result.activeWindow.bounds;
|
|
201
|
-
parts.push(` - Position: (${b.x}, ${b.y})`);
|
|
202
|
-
parts.push(` - Size: ${b.width}x${b.height}`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (result.mousePosition) {
|
|
207
|
-
parts.push(
|
|
208
|
-
`**Mouse Position:** (${result.mousePosition.x}, ${result.mousePosition.y})`
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (result.clipboard !== undefined) {
|
|
213
|
-
parts.push(`**Clipboard Content:** ${result.clipboard}`);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (parts.length === 0) {
|
|
217
|
-
parts.push(`Desktop action "${action}" completed successfully.`);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return parts.join('\n');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Create desktop automation tools for the agent
|
|
225
|
-
* These tools allow AI to control the user's desktop when Ranger Desktop is running
|
|
226
|
-
*/
|
|
227
|
-
export function createDesktopTools(
|
|
228
|
-
options: CreateDesktopToolsOptions = {}
|
|
229
|
-
): DynamicStructuredTool[] {
|
|
230
|
-
const { waitForResult } = options;
|
|
231
|
-
const tools: DynamicStructuredTool[] = [];
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Helper to create tool function that optionally waits for results
|
|
235
|
-
* The toolCallId is extracted from the RunnableConfig passed by LangChain
|
|
236
|
-
*/
|
|
237
|
-
const createToolFunction = (action: string) => {
|
|
238
|
-
return async (
|
|
239
|
-
args: Record<string, unknown>,
|
|
240
|
-
config?: { toolCall?: { id?: string } }
|
|
241
|
-
): Promise<string> => {
|
|
242
|
-
const toolCallId =
|
|
243
|
-
config?.toolCall?.id ??
|
|
244
|
-
`desktop_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
245
|
-
|
|
246
|
-
// Create marker for Electron app
|
|
247
|
-
const marker: DesktopToolResponse = {
|
|
248
|
-
requiresDesktopExecution: true,
|
|
249
|
-
action,
|
|
250
|
-
args,
|
|
251
|
-
toolCallId,
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
// If no callback, return marker immediately (Electron handles via SSE interception)
|
|
255
|
-
if (!waitForResult) {
|
|
256
|
-
return JSON.stringify(marker);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// With callback: wait for actual results from Electron app
|
|
260
|
-
try {
|
|
261
|
-
const result = await waitForResult(action, args, toolCallId);
|
|
262
|
-
return formatResultForLLM(result, action);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
const errorMessage =
|
|
265
|
-
error instanceof Error ? error.message : String(error);
|
|
266
|
-
return `Desktop action "${action}" failed: ${errorMessage}`;
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// computer_screenshot
|
|
272
|
-
tools.push(
|
|
273
|
-
tool(createToolFunction(EDesktopTools.SCREENSHOT), {
|
|
274
|
-
name: EDesktopTools.SCREENSHOT,
|
|
275
|
-
description:
|
|
276
|
-
'Take a screenshot of the entire screen. Use this to see what is currently displayed on the desktop.',
|
|
277
|
-
schema: ScreenshotSchema,
|
|
278
|
-
})
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
// computer_click
|
|
282
|
-
tools.push(
|
|
283
|
-
tool(createToolFunction(EDesktopTools.CLICK), {
|
|
284
|
-
name: EDesktopTools.CLICK,
|
|
285
|
-
description:
|
|
286
|
-
'Click the mouse at the specified screen coordinates. Use screenshot first to identify the target location.',
|
|
287
|
-
schema: ClickSchema,
|
|
288
|
-
})
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
// computer_double_click
|
|
292
|
-
tools.push(
|
|
293
|
-
tool(createToolFunction(EDesktopTools.DOUBLE_CLICK), {
|
|
294
|
-
name: EDesktopTools.DOUBLE_CLICK,
|
|
295
|
-
description:
|
|
296
|
-
'Double-click the mouse at the specified screen coordinates.',
|
|
297
|
-
schema: DoubleClickSchema,
|
|
298
|
-
})
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
// computer_right_click
|
|
302
|
-
tools.push(
|
|
303
|
-
tool(createToolFunction(EDesktopTools.RIGHT_CLICK), {
|
|
304
|
-
name: EDesktopTools.RIGHT_CLICK,
|
|
305
|
-
description:
|
|
306
|
-
'Right-click the mouse at the specified screen coordinates to open context menus.',
|
|
307
|
-
schema: RightClickSchema,
|
|
308
|
-
})
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
// computer_type
|
|
312
|
-
tools.push(
|
|
313
|
-
tool(createToolFunction(EDesktopTools.TYPE), {
|
|
314
|
-
name: EDesktopTools.TYPE,
|
|
315
|
-
description:
|
|
316
|
-
'Type text using the keyboard. Make sure the target input field is focused first (use click).',
|
|
317
|
-
schema: TypeSchema,
|
|
318
|
-
})
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
// computer_key
|
|
322
|
-
tools.push(
|
|
323
|
-
tool(createToolFunction(EDesktopTools.KEY), {
|
|
324
|
-
name: EDesktopTools.KEY,
|
|
325
|
-
description:
|
|
326
|
-
'Press a single key on the keyboard (Enter, Tab, Escape, arrow keys, function keys, etc.).',
|
|
327
|
-
schema: KeySchema,
|
|
328
|
-
})
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
// computer_key_combo
|
|
332
|
-
tools.push(
|
|
333
|
-
tool(createToolFunction(EDesktopTools.KEY_COMBO), {
|
|
334
|
-
name: EDesktopTools.KEY_COMBO,
|
|
335
|
-
description:
|
|
336
|
-
'Press a key combination (e.g., Ctrl+C to copy, Ctrl+V to paste, Alt+Tab to switch windows).',
|
|
337
|
-
schema: KeyComboSchema,
|
|
338
|
-
})
|
|
339
|
-
);
|
|
340
|
-
|
|
341
|
-
// computer_scroll
|
|
342
|
-
tools.push(
|
|
343
|
-
tool(createToolFunction(EDesktopTools.SCROLL), {
|
|
344
|
-
name: EDesktopTools.SCROLL,
|
|
345
|
-
description:
|
|
346
|
-
'Scroll at the specified screen coordinates. Use negative deltaY to scroll up, positive to scroll down.',
|
|
347
|
-
schema: ScrollSchema,
|
|
348
|
-
})
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
// computer_drag
|
|
352
|
-
tools.push(
|
|
353
|
-
tool(createToolFunction(EDesktopTools.DRAG), {
|
|
354
|
-
name: EDesktopTools.DRAG,
|
|
355
|
-
description:
|
|
356
|
-
'Drag the mouse from one position to another (for moving windows, selecting text, etc.).',
|
|
357
|
-
schema: DragSchema,
|
|
358
|
-
})
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
// computer_get_active_window
|
|
362
|
-
tools.push(
|
|
363
|
-
tool(createToolFunction(EDesktopTools.GET_ACTIVE_WINDOW), {
|
|
364
|
-
name: EDesktopTools.GET_ACTIVE_WINDOW,
|
|
365
|
-
description:
|
|
366
|
-
'Get information about the currently active window (title, application name, position, size).',
|
|
367
|
-
schema: GetActiveWindowSchema,
|
|
368
|
-
})
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
// computer_get_mouse_position
|
|
372
|
-
tools.push(
|
|
373
|
-
tool(createToolFunction(EDesktopTools.GET_MOUSE_POSITION), {
|
|
374
|
-
name: EDesktopTools.GET_MOUSE_POSITION,
|
|
375
|
-
description: 'Get the current mouse cursor position on screen.',
|
|
376
|
-
schema: GetMousePositionSchema,
|
|
377
|
-
})
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
// clipboard_read
|
|
381
|
-
tools.push(
|
|
382
|
-
tool(createToolFunction(EDesktopTools.CLIPBOARD_READ), {
|
|
383
|
-
name: EDesktopTools.CLIPBOARD_READ,
|
|
384
|
-
description: 'Read the current contents of the system clipboard.',
|
|
385
|
-
schema: ClipboardReadSchema,
|
|
386
|
-
})
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
// clipboard_write
|
|
390
|
-
tools.push(
|
|
391
|
-
tool(createToolFunction(EDesktopTools.CLIPBOARD_WRITE), {
|
|
392
|
-
name: EDesktopTools.CLIPBOARD_WRITE,
|
|
393
|
-
description: 'Write text to the system clipboard.',
|
|
394
|
-
schema: ClipboardWriteSchema,
|
|
395
|
-
})
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
// clipboard_paste
|
|
399
|
-
tools.push(
|
|
400
|
-
tool(createToolFunction(EDesktopTools.CLIPBOARD_PASTE), {
|
|
401
|
-
name: EDesktopTools.CLIPBOARD_PASTE,
|
|
402
|
-
description:
|
|
403
|
-
'Paste the clipboard contents (equivalent to Ctrl+V). Use clipboard_write first to set the content.',
|
|
404
|
-
schema: ClipboardPasteSchema,
|
|
405
|
-
})
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
// computer_wait
|
|
409
|
-
tools.push(
|
|
410
|
-
tool(createToolFunction(EDesktopTools.WAIT), {
|
|
411
|
-
name: EDesktopTools.WAIT,
|
|
412
|
-
description:
|
|
413
|
-
'Wait for the specified number of milliseconds. Use this to wait for UI animations or loading.',
|
|
414
|
-
schema: WaitSchema,
|
|
415
|
-
})
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
return tools;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Get all desktop tool names
|
|
423
|
-
*/
|
|
424
|
-
export function getDesktopToolNames(): DesktopToolName[] {
|
|
425
|
-
return Object.values(EDesktopTools);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Check if a tool name is a desktop tool
|
|
430
|
-
*/
|
|
431
|
-
export function isDesktopTool(name: string): name is DesktopToolName {
|
|
432
|
-
return Object.values(EDesktopTools).includes(name as DesktopToolName);
|
|
433
|
-
}
|