Repository navigation
Expand file tree
/
Copy pathagentTools.js
More file actions
475 lines (465 loc) · 14.5 KB
/
Copy pathagentTools.js
File metadata and controls
475 lines (465 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
const FORBIDDEN_TOOL_PREFIXES = ['clipboard_', 'authenticator_', 'get_totp', 'get_clipboard', 'search_clipboard']
let deps = null
function initAgentTools(dependencies) {
deps = dependencies
}
function isForbiddenToolName(name) {
const lower = String(name || '').toLowerCase()
return FORBIDDEN_TOOL_PREFIXES.some((p) => lower.includes(p))
}
function buildToolDefinitions(enabledCategories = null) {
if (!deps) return []
const tools = getAllToolDefinitions()
if (!enabledCategories) return tools.filter((t) => !isForbiddenToolName(t.name))
return tools.filter((t) => enabledCategories.includes(t.category) && !isForbiddenToolName(t.name))
}
function getAllToolDefinitions() {
return [
{
name: 'get_system_stats',
description: 'Get current real-time CPU, RAM, disk, network, battery, and temperature statistics (snapshot only, not historical).',
category: 'system',
parameters: {
type: 'object',
properties: {},
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'query_system_stats_history',
description: 'Query historical system performance from DeskMaster\'s Performance screen database (up to ~30 days). Returns sample counts, averages, min/max, and optional threshold counts (e.g. how many samples had CPU above 50%). Use for questions about past CPU/RAM/disk/network usage.',
category: 'system',
parameters: {
type: 'object',
properties: {
range: {
type: 'string',
enum: ['1h', '6h', '24h', '7d', '30d'],
description: 'Preset time range relative to now'
},
startTime: {
type: 'string',
description: 'Optional ISO start datetime (use with endTime for custom range)'
},
endTime: {
type: 'string',
description: 'Optional ISO end datetime (defaults to now)'
},
cpuThreshold: {
type: 'number',
description: 'If set, count how many stored samples had CPU usage >= this percent (e.g. 50 for above 50%)'
}
},
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'get_app_version',
description: 'Get the DeskMaster application version.',
category: 'system',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: false
},
{
name: 'notes_search',
description: 'Search DeskMaster notes by keyword and return matching page titles and snippets.',
category: 'notes',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' }
},
required: ['query'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'notes_get_page',
description: 'Get the full text content of a note page by its ID.',
category: 'notes',
parameters: {
type: 'object',
properties: {
id: { type: 'string', description: 'Note page ID' }
},
required: ['id'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'notes_create_page',
description: 'Create a new note page with optional title and type (canvas, markdown, or text).',
category: 'notes',
parameters: {
type: 'object',
properties: {
title: { type: 'string' },
type: { type: 'string', enum: ['canvas', 'markdown', 'text'] },
parentId: { type: 'string', description: 'Optional parent note ID' }
},
required: ['title'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'notes_save_page',
description: 'Save text content to an existing text or markdown note page.',
category: 'notes',
parameters: {
type: 'object',
properties: {
id: { type: 'string' },
text: { type: 'string' }
},
required: ['id', 'text'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'bcrypt_generate',
description: 'Generate a bcrypt hash for the given text.',
category: 'tools',
parameters: {
type: 'object',
properties: { text: { type: 'string' } },
required: ['text'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'bcrypt_verify',
description: 'Verify text against a bcrypt hash.',
category: 'tools',
parameters: {
type: 'object',
properties: {
text: { type: 'string' },
hash: { type: 'string' }
},
required: ['text', 'hash'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'get_public_ip',
description: 'Get the public IP address of this machine.',
category: 'tools',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: false
},
{
name: 'get_ip_location',
description: 'Look up geographic location, ISP, and coordinates for IP address(es) using the built-in IP Location Lookup tool (IPGeolocation.io). If no IP is given, looks up the current public IP.',
category: 'tools',
parameters: {
type: 'object',
properties: {
ip: { type: 'string', description: 'Single IP address to look up' },
ips: {
type: 'array',
items: { type: 'string' },
description: 'Multiple IP addresses to look up'
}
},
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'translate_text',
description: 'Translate text to a target language using AI.',
category: 'tools',
parameters: {
type: 'object',
properties: {
text: { type: 'string' },
targetLanguage: { type: 'string' }
},
required: ['text', 'targetLanguage'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'reformat_text',
description: 'Reformat or rewrite text with optional tone instructions.',
category: 'tools',
parameters: {
type: 'object',
properties: {
text: { type: 'string' },
tones: { type: 'string', description: 'Optional tone instructions' }
},
required: ['text'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'uptime_list_monitors',
description: 'List Uptime Kuma monitors if Uptime Kuma is enabled and configured.',
category: 'uptime',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: false
},
{
name: 'gdrive_status',
description: 'Get Google Drive backup connection and last backup status.',
category: 'cloud',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: false
},
{
name: 'gdrive_backup_now',
description: 'Trigger an immediate Google Drive backup.',
category: 'cloud',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: true
},
{
name: 'get_settings_summary',
description: 'Get a non-sensitive summary of DeskMaster settings (theme, enabled stats, timezone count).',
category: 'settings',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: false
},
{
name: 'kb_search',
description: 'Semantic search across the knowledge base (notes and custom documents).',
category: 'kb',
parameters: {
type: 'object',
properties: {
query: { type: 'string' },
limit: { type: 'number' }
},
required: ['query'],
additionalProperties: false
},
requiresConfirm: false
},
{
name: 'kb_list_documents',
description: 'List custom knowledge base documents.',
category: 'kb',
parameters: { type: 'object', properties: {}, additionalProperties: false },
requiresConfirm: false
},
{
name: 'kb_create_document',
description: 'Create a new custom knowledge base document.',
category: 'kb',
parameters: {
type: 'object',
properties: {
title: { type: 'string' },
content: { type: 'string' }
},
required: ['title', 'content'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'kb_update_document',
description: 'Update an existing custom knowledge base document.',
category: 'kb',
parameters: {
type: 'object',
properties: {
id: { type: 'string' },
title: { type: 'string' },
content: { type: 'string' }
},
required: ['id'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'generate_pdf',
description: 'Generate a PDF document from title and text/markdown content. Returns a downloadable file path.',
category: 'documents',
parameters: {
type: 'object',
properties: {
title: { type: 'string' },
content: { type: 'string', description: 'Body text or markdown-style content' },
fileName: { type: 'string', description: 'Optional output file name' }
},
required: ['content'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'generate_docx',
description: 'Generate a Word (.docx) document from title and text content.',
category: 'documents',
parameters: {
type: 'object',
properties: {
title: { type: 'string' },
content: { type: 'string' },
fileName: { type: 'string' }
},
required: ['content'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'generate_xlsx',
description: 'Generate an Excel (.xlsx) spreadsheet. Provide sheets with rows (2D arrays).',
category: 'documents',
parameters: {
type: 'object',
properties: {
title: { type: 'string' },
fileName: { type: 'string' },
sheets: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string' },
rows: {
type: 'array',
items: {
type: 'array',
items: { type: 'string' }
}
}
}
}
}
},
required: ['sheets'],
additionalProperties: false
},
requiresConfirm: true
},
{
name: 'generate_pptx',
description: 'Generate a PowerPoint (.pptx) presentation with slides (title + bullet points).',
category: 'documents',
parameters: {
type: 'object',
properties: {
title: { type: 'string' },
fileName: { type: 'string' },
slides: {
type: 'array',
items: {
type: 'object',
properties: {
title: { type: 'string' },
bullets: { type: 'array', items: { type: 'string' } },
content: { type: 'string' }
}
}
}
},
required: ['slides'],
additionalProperties: false
},
requiresConfirm: true
}
]
}
function getToolMeta(name) {
return getAllToolDefinitions().find((t) => t.name === name)
}
async function executeTool(name, args, { confirmed = false, agentSettings } = {}) {
if (!deps) throw new Error('Agent tools not initialized')
if (isForbiddenToolName(name)) {
throw new Error('This tool is not available to the agent for security reasons.')
}
const meta = getToolMeta(name)
if (!meta) throw new Error(`Unknown tool: ${name}`)
if (meta.requiresConfirm && !confirmed) {
return {
requiresConfirmation: true,
tool: name,
arguments: args,
message: `Tool "${name}" requires user confirmation before execution.`
}
}
switch (name) {
case 'get_system_stats':
return deps.getSystemStats()
case 'query_system_stats_history':
return deps.querySystemStatsHistory(args)
case 'get_app_version':
return { version: deps.getAppVersion() }
case 'notes_search':
return deps.notesSearch(args.query)
case 'notes_get_page':
return deps.notesGetPage(args.id)
case 'notes_create_page':
return deps.notesCreatePage(args)
case 'notes_save_page':
return deps.notesSavePage(args.id, args.text)
case 'bcrypt_generate':
return deps.bcryptGenerate(args.text)
case 'bcrypt_verify':
return deps.bcryptVerify(args.text, args.hash)
case 'get_public_ip':
return deps.getPublicIp()
case 'get_ip_location': {
let ips = Array.isArray(args.ips) ? args.ips.filter(Boolean) : []
if (args.ip) ips.push(args.ip)
if (!ips.length) {
const publicIp = await deps.getPublicIp()
ips = [publicIp]
}
return deps.getIpLocation(ips)
}
case 'translate_text':
return { translated: await deps.translateText(args.text, args.targetLanguage) }
case 'reformat_text':
return { result: await deps.reformatText(args.text, args.tones) }
case 'uptime_list_monitors':
return deps.uptimeListMonitors()
case 'gdrive_status':
return deps.gdriveStatus()
case 'gdrive_backup_now':
return deps.gdriveBackupNow()
case 'get_settings_summary':
return deps.getSettingsSummary()
case 'kb_search':
return deps.kbSearch(args.query, args.limit, agentSettings)
case 'kb_list_documents':
return deps.kbListDocuments()
case 'kb_create_document':
return deps.kbCreateDocument(args.title, args.content, agentSettings)
case 'kb_update_document':
return deps.kbUpdateDocument(args.id, args, agentSettings)
case 'generate_pdf':
return deps.generatePdf(args)
case 'generate_docx':
return deps.generateDocx(args)
case 'generate_xlsx':
return deps.generateXlsx(args)
case 'generate_pptx':
return deps.generatePptx(args)
default:
throw new Error(`Tool handler not implemented: ${name}`)
}
}
module.exports = {
initAgentTools,
buildToolDefinitions,
getToolMeta,
executeTool,
isForbiddenToolName,
FORBIDDEN_TOOL_PREFIXES
}