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
package/package.json
CHANGED
package/src/common/enum.ts
CHANGED
|
@@ -163,6 +163,7 @@ export enum Callback {
|
|
|
163
163
|
export enum Constants {
|
|
164
164
|
OFFICIAL_CODE_BASEURL = 'https://api.illuma.ai/v1',
|
|
165
165
|
EXECUTE_CODE = 'execute_code',
|
|
166
|
+
CREATE_PRESENTATION = 'create_presentation',
|
|
166
167
|
TOOL_SEARCH = 'tool_search',
|
|
167
168
|
PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code',
|
|
168
169
|
WEB_SEARCH = 'web_search',
|
package/src/index.ts
CHANGED
|
@@ -11,8 +11,8 @@ export * from './graphs';
|
|
|
11
11
|
/* Tools */
|
|
12
12
|
export * from './tools/Calculator';
|
|
13
13
|
export * from './tools/CodeExecutor';
|
|
14
|
+
export * from './tools/PresentationTool';
|
|
14
15
|
export * from './tools/BrowserTools';
|
|
15
|
-
export * from './tools/DesktopTools';
|
|
16
16
|
export * from './tools/ProgrammaticToolCalling';
|
|
17
17
|
export * from './tools/ToolSearch';
|
|
18
18
|
export * from './tools/handlers';
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { config } from 'dotenv';
|
|
3
|
+
import fetch, { RequestInit } from 'node-fetch';
|
|
4
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
5
|
+
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
6
|
+
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
7
|
+
import type * as t from '@/types';
|
|
8
|
+
import { EnvVar, Constants } from '@/common';
|
|
9
|
+
import { getCodeBaseURL } from './CodeExecutor';
|
|
10
|
+
|
|
11
|
+
config();
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// PRESENTATION TOOL CONSTANTS
|
|
15
|
+
// =============================================================================
|
|
16
|
+
|
|
17
|
+
const PRESENTATIONS_ENDPOINT = `${getCodeBaseURL()}/presentations/create`;
|
|
18
|
+
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// SCHEMA DEFINITIONS
|
|
21
|
+
// =============================================================================
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Position and size model (matches code-executor PptxPositionModel)
|
|
25
|
+
*/
|
|
26
|
+
const PositionSchema = z.object({
|
|
27
|
+
left: z.number().describe('Left position in points'),
|
|
28
|
+
top: z.number().describe('Top position in points'),
|
|
29
|
+
width: z.number().describe('Width in points'),
|
|
30
|
+
height: z.number().describe('Height in points'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Font styling model
|
|
35
|
+
*/
|
|
36
|
+
const FontSchema = z.object({
|
|
37
|
+
name: z.string().default('Arial').describe('Font family name'),
|
|
38
|
+
size: z.number().default(16).describe('Font size in points'),
|
|
39
|
+
italic: z.boolean().optional().describe('Italic text'),
|
|
40
|
+
color: z.string().default('000000').describe('Hex color without #'),
|
|
41
|
+
font_weight: z.number().optional().default(400).describe('400 = normal, 600+ = bold'),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Fill/background color model
|
|
46
|
+
*/
|
|
47
|
+
const FillSchema = z.object({
|
|
48
|
+
color: z.string().describe('Hex color without #'),
|
|
49
|
+
opacity: z.number().optional().default(1.0),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Spacing/margin model
|
|
54
|
+
*/
|
|
55
|
+
const SpacingSchema = z.object({
|
|
56
|
+
top: z.number().default(0),
|
|
57
|
+
bottom: z.number().default(0),
|
|
58
|
+
left: z.number().default(0),
|
|
59
|
+
right: z.number().default(0),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Paragraph model
|
|
64
|
+
*/
|
|
65
|
+
const ParagraphSchema = z.object({
|
|
66
|
+
text: z.string().describe('Text content (can contain basic HTML like <b>, <i>)'),
|
|
67
|
+
alignment: z.enum(['left', 'center', 'right', 'justify']).optional(),
|
|
68
|
+
font: FontSchema.optional(),
|
|
69
|
+
spacing: SpacingSchema.optional(),
|
|
70
|
+
line_height: z.number().optional(),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Picture source model
|
|
75
|
+
*/
|
|
76
|
+
const PictureSchema = z.object({
|
|
77
|
+
is_network: z.boolean().default(false).describe('True if path is a URL'),
|
|
78
|
+
path: z.string().describe('Image file path or URL'),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Object fit settings for images
|
|
83
|
+
*/
|
|
84
|
+
const ObjectFitSchema = z.object({
|
|
85
|
+
fit: z.enum(['contain', 'cover', 'fill']).optional(),
|
|
86
|
+
focus: z.array(z.number()).optional().describe('Focus point [x%, y%]'),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Text box shape
|
|
91
|
+
*/
|
|
92
|
+
const TextBoxShapeSchema = z.object({
|
|
93
|
+
shape_type: z.literal('textbox').default('textbox'),
|
|
94
|
+
position: PositionSchema,
|
|
95
|
+
paragraphs: z.array(ParagraphSchema).describe('Text paragraphs in the box'),
|
|
96
|
+
margin: SpacingSchema.optional(),
|
|
97
|
+
fill: FillSchema.optional(),
|
|
98
|
+
text_wrap: z.boolean().optional().default(true),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Auto shape (rectangle, rounded rectangle, etc.)
|
|
103
|
+
*/
|
|
104
|
+
const AutoShapeSchema = z.object({
|
|
105
|
+
shape_type: z.literal('autoshape').default('autoshape'),
|
|
106
|
+
autoshape_type: z.string().default('RECTANGLE').describe('Shape type: RECTANGLE, ROUNDED_RECTANGLE, OVAL, etc.'),
|
|
107
|
+
position: PositionSchema,
|
|
108
|
+
paragraphs: z.array(ParagraphSchema).optional(),
|
|
109
|
+
margin: SpacingSchema.optional(),
|
|
110
|
+
fill: FillSchema.optional(),
|
|
111
|
+
border_radius: z.number().optional(),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Picture shape
|
|
116
|
+
*/
|
|
117
|
+
const PictureShapeSchema = z.object({
|
|
118
|
+
shape_type: z.literal('picture').default('picture'),
|
|
119
|
+
position: PositionSchema,
|
|
120
|
+
picture: PictureSchema,
|
|
121
|
+
margin: SpacingSchema.optional(),
|
|
122
|
+
clip: z.boolean().optional().default(true),
|
|
123
|
+
opacity: z.number().optional(),
|
|
124
|
+
shape: z.enum(['rectangle', 'circle']).optional(),
|
|
125
|
+
object_fit: ObjectFitSchema.optional(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Connector/line shape
|
|
130
|
+
*/
|
|
131
|
+
const ConnectorSchema = z.object({
|
|
132
|
+
shape_type: z.literal('connector').default('connector'),
|
|
133
|
+
connector_type: z.string().default('STRAIGHT').describe('STRAIGHT, ELBOW, CURVE'),
|
|
134
|
+
position: PositionSchema,
|
|
135
|
+
thickness: z.number().optional().default(0.5),
|
|
136
|
+
color: z.string().optional().default('000000'),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Union of all shape types
|
|
141
|
+
*/
|
|
142
|
+
const ShapeSchema = z.discriminatedUnion('shape_type', [
|
|
143
|
+
TextBoxShapeSchema,
|
|
144
|
+
AutoShapeSchema,
|
|
145
|
+
PictureShapeSchema,
|
|
146
|
+
ConnectorSchema,
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Slide model
|
|
151
|
+
*/
|
|
152
|
+
const SlideSchema = z.object({
|
|
153
|
+
background: FillSchema.optional().describe('Slide background color'),
|
|
154
|
+
note: z.string().optional().describe('Speaker notes for this slide'),
|
|
155
|
+
shapes: z.array(ShapeSchema).describe('Shapes on this slide'),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Brand settings for consistent theming
|
|
160
|
+
*/
|
|
161
|
+
const BrandSettingsSchema = z.object({
|
|
162
|
+
primary_color: z.string().default('000033').describe('Primary brand color'),
|
|
163
|
+
secondary_color: z.string().default('666666').describe('Secondary color'),
|
|
164
|
+
accent_color: z.string().default('0066CC').describe('Accent color'),
|
|
165
|
+
background_color: z.string().default('FFFFFF').describe('Background color'),
|
|
166
|
+
font_heading: z.string().default('Arial').describe('Heading font'),
|
|
167
|
+
font_body: z.string().default('Arial').describe('Body font'),
|
|
168
|
+
logo_url: z.string().optional().describe('Company logo URL'),
|
|
169
|
+
company_name: z.string().optional().describe('Company name'),
|
|
170
|
+
chart_colors: z.array(z.string()).optional().describe('Chart color palette'),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Full presentation model
|
|
175
|
+
*/
|
|
176
|
+
const PresentationSchema = z.object({
|
|
177
|
+
name: z.string().optional().describe('Presentation name'),
|
|
178
|
+
width: z.number().default(1280).describe('Slide width in points'),
|
|
179
|
+
height: z.number().default(720).describe('Slide height in points'),
|
|
180
|
+
slides: z.array(SlideSchema).describe('Array of slides'),
|
|
181
|
+
shapes: z.array(ShapeSchema).optional().describe('Global shapes (on all slides)'),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Main tool input schema
|
|
186
|
+
*/
|
|
187
|
+
const CreatePresentationToolSchema = z.object({
|
|
188
|
+
presentation: PresentationSchema.describe(
|
|
189
|
+
'The complete presentation structure with slides and shapes'
|
|
190
|
+
),
|
|
191
|
+
brand: BrandSettingsSchema.optional().describe(
|
|
192
|
+
'Brand settings for consistent theming'
|
|
193
|
+
),
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// =============================================================================
|
|
197
|
+
// RESPONSE TYPES
|
|
198
|
+
// =============================================================================
|
|
199
|
+
|
|
200
|
+
interface CreatePresentationResult {
|
|
201
|
+
success: boolean;
|
|
202
|
+
file_id: string;
|
|
203
|
+
filename: string;
|
|
204
|
+
session_id: string;
|
|
205
|
+
message?: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// =============================================================================
|
|
209
|
+
// TOOL PARAMETERS
|
|
210
|
+
// =============================================================================
|
|
211
|
+
|
|
212
|
+
export interface PresentationToolParams {
|
|
213
|
+
apiKey?: string;
|
|
214
|
+
[EnvVar.CODE_API_KEY]?: string;
|
|
215
|
+
user_id?: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// =============================================================================
|
|
219
|
+
// TOOL CREATION
|
|
220
|
+
// =============================================================================
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Creates a presentation generation tool for LangChain agents.
|
|
224
|
+
*
|
|
225
|
+
* This tool allows agents to create PowerPoint presentations by providing
|
|
226
|
+
* structured slide data. The presentation is generated by the code-executor
|
|
227
|
+
* service and returned as a downloadable file.
|
|
228
|
+
*
|
|
229
|
+
* Architecture notes:
|
|
230
|
+
* - Charts and complex visualizations should be rendered as images on the client
|
|
231
|
+
* - The tool accepts image URLs/paths for chart/table screenshots
|
|
232
|
+
* - Text boxes, shapes, and images are supported as native PPTX elements
|
|
233
|
+
*/
|
|
234
|
+
function createPresentationTool(
|
|
235
|
+
params: PresentationToolParams = {}
|
|
236
|
+
): DynamicStructuredTool<typeof CreatePresentationToolSchema> {
|
|
237
|
+
const apiKey =
|
|
238
|
+
params[EnvVar.CODE_API_KEY] ??
|
|
239
|
+
params.apiKey ??
|
|
240
|
+
getEnvironmentVariable(EnvVar.CODE_API_KEY) ??
|
|
241
|
+
'';
|
|
242
|
+
|
|
243
|
+
if (!apiKey) {
|
|
244
|
+
throw new Error('No API key provided for presentation tool.');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const description = `
|
|
248
|
+
Create a PowerPoint presentation from structured slide data.
|
|
249
|
+
|
|
250
|
+
USE THIS TOOL WHEN:
|
|
251
|
+
- User asks for a PowerPoint, PPTX, or presentation file
|
|
252
|
+
- User wants to export content as a presentation
|
|
253
|
+
|
|
254
|
+
SLIDE STRUCTURE:
|
|
255
|
+
Each slide contains shapes: textbox, autoshape, picture, connector.
|
|
256
|
+
- textbox: Text with paragraphs and formatting
|
|
257
|
+
- autoshape: Colored shapes (rectangles, rounded rectangles) with optional text
|
|
258
|
+
- picture: Images from URLs or file paths
|
|
259
|
+
- connector: Lines and connectors
|
|
260
|
+
|
|
261
|
+
STANDARD SLIDE DIMENSIONS:
|
|
262
|
+
- Width: 1280 points (13.33 inches)
|
|
263
|
+
- Height: 720 points (7.5 inches)
|
|
264
|
+
|
|
265
|
+
LAYOUT TIPS:
|
|
266
|
+
- Title: position ~{left: 80, top: 40, width: 1120, height: 80}
|
|
267
|
+
- Content area: position ~{left: 80, top: 140, width: 1120, height: 520}
|
|
268
|
+
- Leave margins of ~80 points on sides
|
|
269
|
+
|
|
270
|
+
NOTES:
|
|
271
|
+
- Charts/tables should be rendered as images and included via picture shapes
|
|
272
|
+
- Use brand settings for consistent theming across slides
|
|
273
|
+
- Generated file is auto-delivered to the user (no download links needed)
|
|
274
|
+
`.trim();
|
|
275
|
+
|
|
276
|
+
return tool<typeof CreatePresentationToolSchema>(
|
|
277
|
+
async ({ presentation, brand }, config) => {
|
|
278
|
+
const { session_id } = (config.toolCall ?? {}) as {
|
|
279
|
+
session_id?: string;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const requestBody = {
|
|
283
|
+
presentation,
|
|
284
|
+
brand,
|
|
285
|
+
session_id,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const fetchOptions: RequestInit = {
|
|
290
|
+
method: 'POST',
|
|
291
|
+
headers: {
|
|
292
|
+
'Content-Type': 'application/json',
|
|
293
|
+
'User-Agent': 'Ranger/1.0',
|
|
294
|
+
'X-API-Key': apiKey,
|
|
295
|
+
},
|
|
296
|
+
body: JSON.stringify(requestBody),
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
if (process.env.PROXY != null && process.env.PROXY !== '') {
|
|
300
|
+
fetchOptions.agent = new HttpsProxyAgent(process.env.PROXY);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const response = await fetch(PRESENTATIONS_ENDPOINT, fetchOptions);
|
|
304
|
+
|
|
305
|
+
if (!response.ok) {
|
|
306
|
+
const errorText = await response.text();
|
|
307
|
+
throw new Error(`Presentation creation failed: ${response.status} - ${errorText}`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const result: CreatePresentationResult = await response.json();
|
|
311
|
+
|
|
312
|
+
if (!result.success) {
|
|
313
|
+
throw new Error(`Presentation creation failed: ${result.message}`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const slideCount = presentation.slides.length;
|
|
317
|
+
const formattedOutput = `
|
|
318
|
+
Presentation created successfully!
|
|
319
|
+
- Slides: ${slideCount}
|
|
320
|
+
- File ID: ${result.file_id}
|
|
321
|
+
- Filename: ${result.filename}
|
|
322
|
+
|
|
323
|
+
The PowerPoint file is ready for download.
|
|
324
|
+
`.trim();
|
|
325
|
+
|
|
326
|
+
// Return content and artifact (like code executor)
|
|
327
|
+
// The artifact contains file info for client-side handling
|
|
328
|
+
return [
|
|
329
|
+
formattedOutput,
|
|
330
|
+
{
|
|
331
|
+
session_id: result.session_id,
|
|
332
|
+
file_id: result.file_id,
|
|
333
|
+
filename: result.filename,
|
|
334
|
+
type: 'presentation',
|
|
335
|
+
files: [{
|
|
336
|
+
id: result.file_id,
|
|
337
|
+
name: result.filename,
|
|
338
|
+
}],
|
|
339
|
+
},
|
|
340
|
+
];
|
|
341
|
+
} catch (error) {
|
|
342
|
+
throw new Error(
|
|
343
|
+
`Presentation creation error:\n\n${(error as Error | undefined)?.message}`
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: Constants.CREATE_PRESENTATION,
|
|
349
|
+
description,
|
|
350
|
+
schema: CreatePresentationToolSchema,
|
|
351
|
+
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export { createPresentationTool, CreatePresentationToolSchema };
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var zod = require('zod');
|
|
4
|
-
var tools = require('@langchain/core/tools');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Desktop tool names - keep in sync with Ranger Desktop Electron app
|
|
8
|
-
* These tools execute locally in the Electron app, NOT on the server
|
|
9
|
-
*/
|
|
10
|
-
const EDesktopTools = {
|
|
11
|
-
SCREENSHOT: 'computer_screenshot',
|
|
12
|
-
CLICK: 'computer_click',
|
|
13
|
-
DOUBLE_CLICK: 'computer_double_click',
|
|
14
|
-
RIGHT_CLICK: 'computer_right_click',
|
|
15
|
-
TYPE: 'computer_type',
|
|
16
|
-
KEY: 'computer_key',
|
|
17
|
-
KEY_COMBO: 'computer_key_combo',
|
|
18
|
-
SCROLL: 'computer_scroll',
|
|
19
|
-
DRAG: 'computer_drag',
|
|
20
|
-
GET_ACTIVE_WINDOW: 'computer_get_active_window',
|
|
21
|
-
GET_MOUSE_POSITION: 'computer_get_mouse_position',
|
|
22
|
-
CLIPBOARD_READ: 'clipboard_read',
|
|
23
|
-
CLIPBOARD_WRITE: 'clipboard_write',
|
|
24
|
-
CLIPBOARD_PASTE: 'clipboard_paste',
|
|
25
|
-
WAIT: 'computer_wait',
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Check if desktop capability is available based on request headers or context
|
|
29
|
-
* The Ranger Desktop Electron app sets these headers when connected:
|
|
30
|
-
* - X-Ranger-Desktop: true
|
|
31
|
-
* - X-Ranger-Desktop-Capable: true
|
|
32
|
-
*/
|
|
33
|
-
function hasDesktopCapability(req) {
|
|
34
|
-
if (!req?.headers) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const desktopApp = req.headers['x-ranger-desktop'];
|
|
38
|
-
const desktopCapable = req.headers['x-ranger-desktop-capable'];
|
|
39
|
-
return desktopApp === 'true' || desktopCapable === 'true';
|
|
40
|
-
}
|
|
41
|
-
// Tool schemas
|
|
42
|
-
const ScreenshotSchema = zod.z.object({});
|
|
43
|
-
const ClickSchema = zod.z.object({
|
|
44
|
-
x: zod.z.number().describe('X coordinate to click'),
|
|
45
|
-
y: zod.z.number().describe('Y coordinate to click'),
|
|
46
|
-
});
|
|
47
|
-
const DoubleClickSchema = zod.z.object({
|
|
48
|
-
x: zod.z.number().describe('X coordinate to double-click'),
|
|
49
|
-
y: zod.z.number().describe('Y coordinate to double-click'),
|
|
50
|
-
});
|
|
51
|
-
const RightClickSchema = zod.z.object({
|
|
52
|
-
x: zod.z.number().describe('X coordinate to right-click'),
|
|
53
|
-
y: zod.z.number().describe('Y coordinate to right-click'),
|
|
54
|
-
});
|
|
55
|
-
const TypeSchema = zod.z.object({
|
|
56
|
-
text: zod.z.string().describe('Text to type'),
|
|
57
|
-
});
|
|
58
|
-
const KeySchema = zod.z.object({
|
|
59
|
-
key: zod.z
|
|
60
|
-
.string()
|
|
61
|
-
.describe('Key to press (e.g., "Enter", "Tab", "Escape", "Backspace", "Delete", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown", "F1"-"F12")'),
|
|
62
|
-
});
|
|
63
|
-
const KeyComboSchema = zod.z.object({
|
|
64
|
-
keys: zod.z
|
|
65
|
-
.array(zod.z.string())
|
|
66
|
-
.describe('Array of keys to press together (e.g., ["Control", "c"] for copy, ["Alt", "Tab"] for window switch)'),
|
|
67
|
-
});
|
|
68
|
-
const ScrollSchema = zod.z.object({
|
|
69
|
-
x: zod.z.number().describe('X coordinate to scroll at'),
|
|
70
|
-
y: zod.z.number().describe('Y coordinate to scroll at'),
|
|
71
|
-
deltaX: zod.z.number().optional().describe('Horizontal scroll amount (pixels)'),
|
|
72
|
-
deltaY: zod.z.number().describe('Vertical scroll amount (pixels, negative = up, positive = down)'),
|
|
73
|
-
});
|
|
74
|
-
const DragSchema = zod.z.object({
|
|
75
|
-
startX: zod.z.number().describe('Starting X coordinate'),
|
|
76
|
-
startY: zod.z.number().describe('Starting Y coordinate'),
|
|
77
|
-
endX: zod.z.number().describe('Ending X coordinate'),
|
|
78
|
-
endY: zod.z.number().describe('Ending Y coordinate'),
|
|
79
|
-
});
|
|
80
|
-
const GetActiveWindowSchema = zod.z.object({});
|
|
81
|
-
const GetMousePositionSchema = zod.z.object({});
|
|
82
|
-
const ClipboardReadSchema = zod.z.object({});
|
|
83
|
-
const ClipboardWriteSchema = zod.z.object({
|
|
84
|
-
text: zod.z.string().describe('Text to write to clipboard'),
|
|
85
|
-
});
|
|
86
|
-
const ClipboardPasteSchema = zod.z.object({});
|
|
87
|
-
const WaitSchema = zod.z.object({
|
|
88
|
-
ms: zod.z.number().describe('Milliseconds to wait'),
|
|
89
|
-
});
|
|
90
|
-
/**
|
|
91
|
-
* Format desktop action result for LLM consumption
|
|
92
|
-
*/
|
|
93
|
-
function formatResultForLLM(result, action) {
|
|
94
|
-
if (!result.success && result.error) {
|
|
95
|
-
return `Desktop action "${action}" failed: ${result.error}`;
|
|
96
|
-
}
|
|
97
|
-
const parts = [];
|
|
98
|
-
if (result.screenshot) {
|
|
99
|
-
parts.push(`Screenshot captured (${result.screenshot.width}x${result.screenshot.height})`);
|
|
100
|
-
// The base64 image will be handled separately by the message formatter
|
|
101
|
-
}
|
|
102
|
-
if (result.activeWindow) {
|
|
103
|
-
parts.push(`**Active Window:**`);
|
|
104
|
-
parts.push(` - Title: ${result.activeWindow.title}`);
|
|
105
|
-
parts.push(` - App: ${result.activeWindow.app}`);
|
|
106
|
-
if (result.activeWindow.bounds) {
|
|
107
|
-
const b = result.activeWindow.bounds;
|
|
108
|
-
parts.push(` - Position: (${b.x}, ${b.y})`);
|
|
109
|
-
parts.push(` - Size: ${b.width}x${b.height}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (result.mousePosition) {
|
|
113
|
-
parts.push(`**Mouse Position:** (${result.mousePosition.x}, ${result.mousePosition.y})`);
|
|
114
|
-
}
|
|
115
|
-
if (result.clipboard !== undefined) {
|
|
116
|
-
parts.push(`**Clipboard Content:** ${result.clipboard}`);
|
|
117
|
-
}
|
|
118
|
-
if (parts.length === 0) {
|
|
119
|
-
parts.push(`Desktop action "${action}" completed successfully.`);
|
|
120
|
-
}
|
|
121
|
-
return parts.join('\n');
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Create desktop automation tools for the agent
|
|
125
|
-
* These tools allow AI to control the user's desktop when Ranger Desktop is running
|
|
126
|
-
*/
|
|
127
|
-
function createDesktopTools(options = {}) {
|
|
128
|
-
const { waitForResult } = options;
|
|
129
|
-
const tools$1 = [];
|
|
130
|
-
/**
|
|
131
|
-
* Helper to create tool function that optionally waits for results
|
|
132
|
-
* The toolCallId is extracted from the RunnableConfig passed by LangChain
|
|
133
|
-
*/
|
|
134
|
-
const createToolFunction = (action) => {
|
|
135
|
-
return async (args, config) => {
|
|
136
|
-
const toolCallId = config?.toolCall?.id ??
|
|
137
|
-
`desktop_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
138
|
-
// Create marker for Electron app
|
|
139
|
-
const marker = {
|
|
140
|
-
requiresDesktopExecution: true,
|
|
141
|
-
action,
|
|
142
|
-
args,
|
|
143
|
-
toolCallId,
|
|
144
|
-
};
|
|
145
|
-
// If no callback, return marker immediately (Electron handles via SSE interception)
|
|
146
|
-
if (!waitForResult) {
|
|
147
|
-
return JSON.stringify(marker);
|
|
148
|
-
}
|
|
149
|
-
// With callback: wait for actual results from Electron app
|
|
150
|
-
try {
|
|
151
|
-
const result = await waitForResult(action, args, toolCallId);
|
|
152
|
-
return formatResultForLLM(result, action);
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
156
|
-
return `Desktop action "${action}" failed: ${errorMessage}`;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
// computer_screenshot
|
|
161
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.SCREENSHOT), {
|
|
162
|
-
name: EDesktopTools.SCREENSHOT,
|
|
163
|
-
description: 'Take a screenshot of the entire screen. Use this to see what is currently displayed on the desktop.',
|
|
164
|
-
schema: ScreenshotSchema,
|
|
165
|
-
}));
|
|
166
|
-
// computer_click
|
|
167
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.CLICK), {
|
|
168
|
-
name: EDesktopTools.CLICK,
|
|
169
|
-
description: 'Click the mouse at the specified screen coordinates. Use screenshot first to identify the target location.',
|
|
170
|
-
schema: ClickSchema,
|
|
171
|
-
}));
|
|
172
|
-
// computer_double_click
|
|
173
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.DOUBLE_CLICK), {
|
|
174
|
-
name: EDesktopTools.DOUBLE_CLICK,
|
|
175
|
-
description: 'Double-click the mouse at the specified screen coordinates.',
|
|
176
|
-
schema: DoubleClickSchema,
|
|
177
|
-
}));
|
|
178
|
-
// computer_right_click
|
|
179
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.RIGHT_CLICK), {
|
|
180
|
-
name: EDesktopTools.RIGHT_CLICK,
|
|
181
|
-
description: 'Right-click the mouse at the specified screen coordinates to open context menus.',
|
|
182
|
-
schema: RightClickSchema,
|
|
183
|
-
}));
|
|
184
|
-
// computer_type
|
|
185
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.TYPE), {
|
|
186
|
-
name: EDesktopTools.TYPE,
|
|
187
|
-
description: 'Type text using the keyboard. Make sure the target input field is focused first (use click).',
|
|
188
|
-
schema: TypeSchema,
|
|
189
|
-
}));
|
|
190
|
-
// computer_key
|
|
191
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.KEY), {
|
|
192
|
-
name: EDesktopTools.KEY,
|
|
193
|
-
description: 'Press a single key on the keyboard (Enter, Tab, Escape, arrow keys, function keys, etc.).',
|
|
194
|
-
schema: KeySchema,
|
|
195
|
-
}));
|
|
196
|
-
// computer_key_combo
|
|
197
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.KEY_COMBO), {
|
|
198
|
-
name: EDesktopTools.KEY_COMBO,
|
|
199
|
-
description: 'Press a key combination (e.g., Ctrl+C to copy, Ctrl+V to paste, Alt+Tab to switch windows).',
|
|
200
|
-
schema: KeyComboSchema,
|
|
201
|
-
}));
|
|
202
|
-
// computer_scroll
|
|
203
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.SCROLL), {
|
|
204
|
-
name: EDesktopTools.SCROLL,
|
|
205
|
-
description: 'Scroll at the specified screen coordinates. Use negative deltaY to scroll up, positive to scroll down.',
|
|
206
|
-
schema: ScrollSchema,
|
|
207
|
-
}));
|
|
208
|
-
// computer_drag
|
|
209
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.DRAG), {
|
|
210
|
-
name: EDesktopTools.DRAG,
|
|
211
|
-
description: 'Drag the mouse from one position to another (for moving windows, selecting text, etc.).',
|
|
212
|
-
schema: DragSchema,
|
|
213
|
-
}));
|
|
214
|
-
// computer_get_active_window
|
|
215
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.GET_ACTIVE_WINDOW), {
|
|
216
|
-
name: EDesktopTools.GET_ACTIVE_WINDOW,
|
|
217
|
-
description: 'Get information about the currently active window (title, application name, position, size).',
|
|
218
|
-
schema: GetActiveWindowSchema,
|
|
219
|
-
}));
|
|
220
|
-
// computer_get_mouse_position
|
|
221
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.GET_MOUSE_POSITION), {
|
|
222
|
-
name: EDesktopTools.GET_MOUSE_POSITION,
|
|
223
|
-
description: 'Get the current mouse cursor position on screen.',
|
|
224
|
-
schema: GetMousePositionSchema,
|
|
225
|
-
}));
|
|
226
|
-
// clipboard_read
|
|
227
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.CLIPBOARD_READ), {
|
|
228
|
-
name: EDesktopTools.CLIPBOARD_READ,
|
|
229
|
-
description: 'Read the current contents of the system clipboard.',
|
|
230
|
-
schema: ClipboardReadSchema,
|
|
231
|
-
}));
|
|
232
|
-
// clipboard_write
|
|
233
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.CLIPBOARD_WRITE), {
|
|
234
|
-
name: EDesktopTools.CLIPBOARD_WRITE,
|
|
235
|
-
description: 'Write text to the system clipboard.',
|
|
236
|
-
schema: ClipboardWriteSchema,
|
|
237
|
-
}));
|
|
238
|
-
// clipboard_paste
|
|
239
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.CLIPBOARD_PASTE), {
|
|
240
|
-
name: EDesktopTools.CLIPBOARD_PASTE,
|
|
241
|
-
description: 'Paste the clipboard contents (equivalent to Ctrl+V). Use clipboard_write first to set the content.',
|
|
242
|
-
schema: ClipboardPasteSchema,
|
|
243
|
-
}));
|
|
244
|
-
// computer_wait
|
|
245
|
-
tools$1.push(tools.tool(createToolFunction(EDesktopTools.WAIT), {
|
|
246
|
-
name: EDesktopTools.WAIT,
|
|
247
|
-
description: 'Wait for the specified number of milliseconds. Use this to wait for UI animations or loading.',
|
|
248
|
-
schema: WaitSchema,
|
|
249
|
-
}));
|
|
250
|
-
return tools$1;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Get all desktop tool names
|
|
254
|
-
*/
|
|
255
|
-
function getDesktopToolNames() {
|
|
256
|
-
return Object.values(EDesktopTools);
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Check if a tool name is a desktop tool
|
|
260
|
-
*/
|
|
261
|
-
function isDesktopTool(name) {
|
|
262
|
-
return Object.values(EDesktopTools).includes(name);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
exports.EDesktopTools = EDesktopTools;
|
|
266
|
-
exports.createDesktopTools = createDesktopTools;
|
|
267
|
-
exports.getDesktopToolNames = getDesktopToolNames;
|
|
268
|
-
exports.hasDesktopCapability = hasDesktopCapability;
|
|
269
|
-
exports.isDesktopTool = isDesktopTool;
|
|
270
|
-
//# sourceMappingURL=DesktopTools.cjs.map
|