@everworker/oneringai 0.2.2 → 0.2.3
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/README.md +63 -17
- package/dist/index.cjs +1022 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +461 -4
- package/dist/index.d.ts +461 -4
- package/dist/index.js +946 -70
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as crypto2 from 'crypto';
|
|
2
2
|
import { randomUUID } from 'crypto';
|
|
3
3
|
import { importPKCS8, SignJWT } from 'jose';
|
|
4
|
-
import * as
|
|
4
|
+
import * as fs17 from 'fs';
|
|
5
5
|
import { promises, existsSync } from 'fs';
|
|
6
6
|
import { EventEmitter } from 'eventemitter3';
|
|
7
7
|
import * as path2 from 'path';
|
|
@@ -19,7 +19,7 @@ import * as z from 'zod/v4';
|
|
|
19
19
|
import spawn$1 from 'cross-spawn';
|
|
20
20
|
import process2 from 'process';
|
|
21
21
|
import { PassThrough } from 'stream';
|
|
22
|
-
import * as
|
|
22
|
+
import * as fs16 from 'fs/promises';
|
|
23
23
|
import { stat, readFile, mkdir, writeFile, readdir } from 'fs/promises';
|
|
24
24
|
import * as simpleIcons from 'simple-icons';
|
|
25
25
|
import { exec, spawn } from 'child_process';
|
|
@@ -641,7 +641,7 @@ var init_JWTBearer = __esm({
|
|
|
641
641
|
this.privateKey = config.privateKey;
|
|
642
642
|
} else if (config.privateKeyPath) {
|
|
643
643
|
try {
|
|
644
|
-
this.privateKey =
|
|
644
|
+
this.privateKey = fs17.readFileSync(config.privateKeyPath, "utf8");
|
|
645
645
|
} catch (error) {
|
|
646
646
|
throw new Error(`Failed to read private key from ${config.privateKeyPath}: ${error.message}`);
|
|
647
647
|
}
|
|
@@ -1292,10 +1292,10 @@ var init_Logger = __esm({
|
|
|
1292
1292
|
initFileStream(filePath) {
|
|
1293
1293
|
try {
|
|
1294
1294
|
const dir = path2.dirname(filePath);
|
|
1295
|
-
if (!
|
|
1296
|
-
|
|
1295
|
+
if (!fs17.existsSync(dir)) {
|
|
1296
|
+
fs17.mkdirSync(dir, { recursive: true });
|
|
1297
1297
|
}
|
|
1298
|
-
this.fileStream =
|
|
1298
|
+
this.fileStream = fs17.createWriteStream(filePath, {
|
|
1299
1299
|
flags: "a",
|
|
1300
1300
|
// append mode
|
|
1301
1301
|
encoding: "utf8"
|
|
@@ -14632,12 +14632,12 @@ var require_dist = __commonJS({
|
|
|
14632
14632
|
throw new Error(`Unknown format "${name}"`);
|
|
14633
14633
|
return f;
|
|
14634
14634
|
};
|
|
14635
|
-
function addFormats(ajv, list,
|
|
14635
|
+
function addFormats(ajv, list, fs18, exportName) {
|
|
14636
14636
|
var _a;
|
|
14637
14637
|
var _b;
|
|
14638
14638
|
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
14639
14639
|
for (const f of list)
|
|
14640
|
-
ajv.addFormat(f,
|
|
14640
|
+
ajv.addFormat(f, fs18[f]);
|
|
14641
14641
|
}
|
|
14642
14642
|
module.exports = exports$1 = formatsPlugin;
|
|
14643
14643
|
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
@@ -16691,6 +16691,9 @@ var ToolManager = class extends EventEmitter {
|
|
|
16691
16691
|
if (options.priority !== void 0) existing.priority = options.priority;
|
|
16692
16692
|
if (options.conditions !== void 0) existing.conditions = options.conditions;
|
|
16693
16693
|
if (options.permission !== void 0) existing.permission = options.permission;
|
|
16694
|
+
if (options.tags !== void 0) existing.tags = options.tags;
|
|
16695
|
+
if (options.category !== void 0) existing.category = options.category;
|
|
16696
|
+
if (options.source !== void 0) existing.source = options.source;
|
|
16694
16697
|
return;
|
|
16695
16698
|
}
|
|
16696
16699
|
const namespace = options.namespace ?? "default";
|
|
@@ -16709,7 +16712,10 @@ var ToolManager = class extends EventEmitter {
|
|
|
16709
16712
|
successCount: 0,
|
|
16710
16713
|
failureCount: 0
|
|
16711
16714
|
},
|
|
16712
|
-
permission: effectivePermission
|
|
16715
|
+
permission: effectivePermission,
|
|
16716
|
+
tags: options.tags,
|
|
16717
|
+
category: options.category,
|
|
16718
|
+
source: options.source
|
|
16713
16719
|
};
|
|
16714
16720
|
this.registry.set(name, registration);
|
|
16715
16721
|
this.addToNamespace(name, namespace);
|
|
@@ -17292,6 +17298,9 @@ var ToolManager = class extends EventEmitter {
|
|
|
17292
17298
|
const namespaces = {};
|
|
17293
17299
|
const priorities = {};
|
|
17294
17300
|
const permissions = {};
|
|
17301
|
+
const tags = {};
|
|
17302
|
+
const categories = {};
|
|
17303
|
+
const sources = {};
|
|
17295
17304
|
for (const [name, reg] of this.registry) {
|
|
17296
17305
|
enabled[name] = reg.enabled;
|
|
17297
17306
|
namespaces[name] = reg.namespace;
|
|
@@ -17299,8 +17308,17 @@ var ToolManager = class extends EventEmitter {
|
|
|
17299
17308
|
if (reg.permission) {
|
|
17300
17309
|
permissions[name] = reg.permission;
|
|
17301
17310
|
}
|
|
17311
|
+
if (reg.tags) {
|
|
17312
|
+
tags[name] = reg.tags;
|
|
17313
|
+
}
|
|
17314
|
+
if (reg.category) {
|
|
17315
|
+
categories[name] = reg.category;
|
|
17316
|
+
}
|
|
17317
|
+
if (reg.source) {
|
|
17318
|
+
sources[name] = reg.source;
|
|
17319
|
+
}
|
|
17302
17320
|
}
|
|
17303
|
-
return { enabled, namespaces, priorities, permissions };
|
|
17321
|
+
return { enabled, namespaces, priorities, permissions, tags, categories, sources };
|
|
17304
17322
|
}
|
|
17305
17323
|
/**
|
|
17306
17324
|
* Load state (restores enabled/disabled, namespaces, priorities, permissions)
|
|
@@ -17324,6 +17342,24 @@ var ToolManager = class extends EventEmitter {
|
|
|
17324
17342
|
this.setPermission(name, permission);
|
|
17325
17343
|
}
|
|
17326
17344
|
}
|
|
17345
|
+
if (state.tags) {
|
|
17346
|
+
for (const [name, toolTags] of Object.entries(state.tags)) {
|
|
17347
|
+
const reg = this.registry.get(name);
|
|
17348
|
+
if (reg) reg.tags = toolTags;
|
|
17349
|
+
}
|
|
17350
|
+
}
|
|
17351
|
+
if (state.categories) {
|
|
17352
|
+
for (const [name, category] of Object.entries(state.categories)) {
|
|
17353
|
+
const reg = this.registry.get(name);
|
|
17354
|
+
if (reg) reg.category = category;
|
|
17355
|
+
}
|
|
17356
|
+
}
|
|
17357
|
+
if (state.sources) {
|
|
17358
|
+
for (const [name, source] of Object.entries(state.sources)) {
|
|
17359
|
+
const reg = this.registry.get(name);
|
|
17360
|
+
if (reg) reg.source = source;
|
|
17361
|
+
}
|
|
17362
|
+
}
|
|
17327
17363
|
}
|
|
17328
17364
|
// ==========================================================================
|
|
17329
17365
|
// Private Helpers
|
|
@@ -28317,8 +28353,8 @@ init_constants();
|
|
|
28317
28353
|
throw new Error("Configuration file not found. Searched: " + this.DEFAULT_PATHS.join(", "));
|
|
28318
28354
|
}
|
|
28319
28355
|
try {
|
|
28320
|
-
const
|
|
28321
|
-
const content =
|
|
28356
|
+
const fs18 = __require("fs");
|
|
28357
|
+
const content = fs18.readFileSync(configPath, "utf-8");
|
|
28322
28358
|
let config = JSON.parse(content);
|
|
28323
28359
|
config = this.interpolateEnvVars(config);
|
|
28324
28360
|
this.validate(config);
|
|
@@ -28347,10 +28383,10 @@ init_constants();
|
|
|
28347
28383
|
* Find configuration file synchronously
|
|
28348
28384
|
*/
|
|
28349
28385
|
static findConfigSync() {
|
|
28350
|
-
const
|
|
28386
|
+
const fs18 = __require("fs");
|
|
28351
28387
|
for (const path6 of this.DEFAULT_PATHS) {
|
|
28352
28388
|
try {
|
|
28353
|
-
|
|
28389
|
+
fs18.accessSync(resolve(path6));
|
|
28354
28390
|
return resolve(path6);
|
|
28355
28391
|
} catch {
|
|
28356
28392
|
}
|
|
@@ -34511,7 +34547,7 @@ var OpenAISTTProvider = class extends BaseMediaProvider {
|
|
|
34511
34547
|
if (Buffer.isBuffer(audio)) {
|
|
34512
34548
|
return new File([new Uint8Array(audio)], "audio.wav", { type: "audio/wav" });
|
|
34513
34549
|
} else if (typeof audio === "string") {
|
|
34514
|
-
return
|
|
34550
|
+
return fs17.createReadStream(audio);
|
|
34515
34551
|
} else {
|
|
34516
34552
|
throw new Error("Invalid audio input: must be Buffer or file path");
|
|
34517
34553
|
}
|
|
@@ -35064,7 +35100,7 @@ var TextToSpeech = class _TextToSpeech {
|
|
|
35064
35100
|
*/
|
|
35065
35101
|
async toFile(text, filePath, options) {
|
|
35066
35102
|
const response = await this.synthesize(text, options);
|
|
35067
|
-
await
|
|
35103
|
+
await fs16.writeFile(filePath, response.audio);
|
|
35068
35104
|
}
|
|
35069
35105
|
// ======================== Introspection Methods ========================
|
|
35070
35106
|
/**
|
|
@@ -35412,7 +35448,7 @@ var SpeechToText = class _SpeechToText {
|
|
|
35412
35448
|
* @param options - Optional transcription parameters
|
|
35413
35449
|
*/
|
|
35414
35450
|
async transcribeFile(filePath, options) {
|
|
35415
|
-
const audio = await
|
|
35451
|
+
const audio = await fs16.readFile(filePath);
|
|
35416
35452
|
return this.transcribe(audio, options);
|
|
35417
35453
|
}
|
|
35418
35454
|
/**
|
|
@@ -35738,7 +35774,7 @@ var OpenAIImageProvider = class extends BaseMediaProvider {
|
|
|
35738
35774
|
if (Buffer.isBuffer(image)) {
|
|
35739
35775
|
return new File([new Uint8Array(image)], "image.png", { type: "image/png" });
|
|
35740
35776
|
}
|
|
35741
|
-
return
|
|
35777
|
+
return fs17.createReadStream(image);
|
|
35742
35778
|
}
|
|
35743
35779
|
/**
|
|
35744
35780
|
* Handle OpenAI API errors
|
|
@@ -35885,8 +35921,8 @@ var GoogleImageProvider = class extends BaseMediaProvider {
|
|
|
35885
35921
|
if (Buffer.isBuffer(image)) {
|
|
35886
35922
|
imageBytes = image.toString("base64");
|
|
35887
35923
|
} else {
|
|
35888
|
-
const
|
|
35889
|
-
const buffer =
|
|
35924
|
+
const fs18 = await import('fs');
|
|
35925
|
+
const buffer = fs18.readFileSync(image);
|
|
35890
35926
|
imageBytes = buffer.toString("base64");
|
|
35891
35927
|
}
|
|
35892
35928
|
return {
|
|
@@ -36047,7 +36083,7 @@ var GrokImageProvider = class extends BaseMediaProvider {
|
|
|
36047
36083
|
if (Buffer.isBuffer(image)) {
|
|
36048
36084
|
return new File([new Uint8Array(image)], "image.png", { type: "image/png" });
|
|
36049
36085
|
}
|
|
36050
|
-
return
|
|
36086
|
+
return fs17.createReadStream(image);
|
|
36051
36087
|
}
|
|
36052
36088
|
/**
|
|
36053
36089
|
* Handle API errors
|
|
@@ -37497,8 +37533,8 @@ var OpenAISoraProvider = class extends BaseMediaProvider {
|
|
|
37497
37533
|
return new File([new Uint8Array(image)], "input.png", { type: "image/png" });
|
|
37498
37534
|
}
|
|
37499
37535
|
if (!image.startsWith("http")) {
|
|
37500
|
-
const
|
|
37501
|
-
const data =
|
|
37536
|
+
const fs18 = await import('fs');
|
|
37537
|
+
const data = fs18.readFileSync(image);
|
|
37502
37538
|
return new File([new Uint8Array(data)], "input.png", { type: "image/png" });
|
|
37503
37539
|
}
|
|
37504
37540
|
const response = await fetch(image);
|
|
@@ -37676,7 +37712,7 @@ var GoogleVeoProvider = class extends BaseMediaProvider {
|
|
|
37676
37712
|
if (video.videoBytes) {
|
|
37677
37713
|
buffer = Buffer.from(video.videoBytes, "base64");
|
|
37678
37714
|
} else if (video.uri) {
|
|
37679
|
-
const
|
|
37715
|
+
const fs18 = await import('fs/promises');
|
|
37680
37716
|
const os3 = await import('os');
|
|
37681
37717
|
const path6 = await import('path');
|
|
37682
37718
|
const tempDir = os3.tmpdir();
|
|
@@ -37687,11 +37723,11 @@ var GoogleVeoProvider = class extends BaseMediaProvider {
|
|
|
37687
37723
|
// Pass as GeneratedVideo
|
|
37688
37724
|
downloadPath: tempFile
|
|
37689
37725
|
});
|
|
37690
|
-
buffer = await
|
|
37691
|
-
await
|
|
37726
|
+
buffer = await fs18.readFile(tempFile);
|
|
37727
|
+
await fs18.unlink(tempFile).catch(() => {
|
|
37692
37728
|
});
|
|
37693
37729
|
} catch (downloadError) {
|
|
37694
|
-
await
|
|
37730
|
+
await fs18.unlink(tempFile).catch(() => {
|
|
37695
37731
|
});
|
|
37696
37732
|
throw new ProviderError(
|
|
37697
37733
|
"google",
|
|
@@ -37813,8 +37849,8 @@ var GoogleVeoProvider = class extends BaseMediaProvider {
|
|
|
37813
37849
|
if (image.startsWith("http://") || image.startsWith("https://")) {
|
|
37814
37850
|
return { imageUri: image };
|
|
37815
37851
|
}
|
|
37816
|
-
const
|
|
37817
|
-
const data = await
|
|
37852
|
+
const fs18 = await import('fs/promises');
|
|
37853
|
+
const data = await fs18.readFile(image);
|
|
37818
37854
|
return {
|
|
37819
37855
|
imageBytes: data.toString("base64")
|
|
37820
37856
|
};
|
|
@@ -38121,8 +38157,8 @@ var GrokImagineProvider = class extends BaseMediaProvider {
|
|
|
38121
38157
|
if (image.startsWith("http") || image.startsWith("data:")) {
|
|
38122
38158
|
return image;
|
|
38123
38159
|
}
|
|
38124
|
-
const
|
|
38125
|
-
const data =
|
|
38160
|
+
const fs18 = await import('fs');
|
|
38161
|
+
const data = fs18.readFileSync(image);
|
|
38126
38162
|
const base64 = data.toString("base64");
|
|
38127
38163
|
const ext = image.split(".").pop()?.toLowerCase() || "png";
|
|
38128
38164
|
const mimeType = ext === "jpg" || ext === "jpeg" ? "image/jpeg" : `image/${ext}`;
|
|
@@ -42394,10 +42430,10 @@ var FileMediaStorage = class {
|
|
|
42394
42430
|
}
|
|
42395
42431
|
async save(data, metadata) {
|
|
42396
42432
|
const dir = metadata.userId ? path2.join(this.outputDir, metadata.userId) : this.outputDir;
|
|
42397
|
-
await
|
|
42433
|
+
await fs16.mkdir(dir, { recursive: true });
|
|
42398
42434
|
const filename = metadata.suggestedFilename ?? this.generateFilename(metadata);
|
|
42399
42435
|
const filePath = path2.join(dir, filename);
|
|
42400
|
-
await
|
|
42436
|
+
await fs16.writeFile(filePath, data);
|
|
42401
42437
|
const format = metadata.format.toLowerCase();
|
|
42402
42438
|
const mimeType = MIME_TYPES2[format] ?? "application/octet-stream";
|
|
42403
42439
|
return {
|
|
@@ -42408,7 +42444,7 @@ var FileMediaStorage = class {
|
|
|
42408
42444
|
}
|
|
42409
42445
|
async read(location) {
|
|
42410
42446
|
try {
|
|
42411
|
-
return await
|
|
42447
|
+
return await fs16.readFile(location);
|
|
42412
42448
|
} catch (err) {
|
|
42413
42449
|
if (err.code === "ENOENT") {
|
|
42414
42450
|
return null;
|
|
@@ -42418,7 +42454,7 @@ var FileMediaStorage = class {
|
|
|
42418
42454
|
}
|
|
42419
42455
|
async delete(location) {
|
|
42420
42456
|
try {
|
|
42421
|
-
await
|
|
42457
|
+
await fs16.unlink(location);
|
|
42422
42458
|
} catch (err) {
|
|
42423
42459
|
if (err.code === "ENOENT") {
|
|
42424
42460
|
return;
|
|
@@ -42428,7 +42464,7 @@ var FileMediaStorage = class {
|
|
|
42428
42464
|
}
|
|
42429
42465
|
async exists(location) {
|
|
42430
42466
|
try {
|
|
42431
|
-
await
|
|
42467
|
+
await fs16.access(location);
|
|
42432
42468
|
return true;
|
|
42433
42469
|
} catch {
|
|
42434
42470
|
return false;
|
|
@@ -42437,11 +42473,11 @@ var FileMediaStorage = class {
|
|
|
42437
42473
|
async list(options) {
|
|
42438
42474
|
await this.ensureDir();
|
|
42439
42475
|
let entries = [];
|
|
42440
|
-
const files = await
|
|
42476
|
+
const files = await fs16.readdir(this.outputDir);
|
|
42441
42477
|
for (const file of files) {
|
|
42442
42478
|
const filePath = path2.join(this.outputDir, file);
|
|
42443
42479
|
try {
|
|
42444
|
-
const stat6 = await
|
|
42480
|
+
const stat6 = await fs16.stat(filePath);
|
|
42445
42481
|
if (!stat6.isFile()) continue;
|
|
42446
42482
|
const ext = path2.extname(file).slice(1).toLowerCase();
|
|
42447
42483
|
const mimeType = MIME_TYPES2[ext] ?? "application/octet-stream";
|
|
@@ -42481,7 +42517,7 @@ var FileMediaStorage = class {
|
|
|
42481
42517
|
}
|
|
42482
42518
|
async ensureDir() {
|
|
42483
42519
|
if (!this.initialized) {
|
|
42484
|
-
await
|
|
42520
|
+
await fs16.mkdir(this.outputDir, { recursive: true });
|
|
42485
42521
|
this.initialized = true;
|
|
42486
42522
|
}
|
|
42487
42523
|
}
|
|
@@ -42489,6 +42525,230 @@ var FileMediaStorage = class {
|
|
|
42489
42525
|
function createFileMediaStorage(config) {
|
|
42490
42526
|
return new FileMediaStorage(config);
|
|
42491
42527
|
}
|
|
42528
|
+
function getDefaultBaseDirectory4() {
|
|
42529
|
+
const platform2 = process.platform;
|
|
42530
|
+
if (platform2 === "win32") {
|
|
42531
|
+
const appData = process.env.APPDATA || process.env.LOCALAPPDATA;
|
|
42532
|
+
if (appData) {
|
|
42533
|
+
return join(appData, "oneringai", "custom-tools");
|
|
42534
|
+
}
|
|
42535
|
+
}
|
|
42536
|
+
return join(homedir(), ".oneringai", "custom-tools");
|
|
42537
|
+
}
|
|
42538
|
+
function sanitizeName(name) {
|
|
42539
|
+
return name.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").toLowerCase() || "default";
|
|
42540
|
+
}
|
|
42541
|
+
var FileCustomToolStorage = class {
|
|
42542
|
+
baseDirectory;
|
|
42543
|
+
indexPath;
|
|
42544
|
+
prettyPrint;
|
|
42545
|
+
index = null;
|
|
42546
|
+
constructor(config = {}) {
|
|
42547
|
+
this.baseDirectory = config.baseDirectory ?? getDefaultBaseDirectory4();
|
|
42548
|
+
this.prettyPrint = config.prettyPrint ?? true;
|
|
42549
|
+
this.indexPath = join(this.baseDirectory, "_index.json");
|
|
42550
|
+
}
|
|
42551
|
+
/**
|
|
42552
|
+
* Save a custom tool definition
|
|
42553
|
+
*/
|
|
42554
|
+
async save(definition) {
|
|
42555
|
+
const sanitized = sanitizeName(definition.name);
|
|
42556
|
+
const filePath = join(this.baseDirectory, `${sanitized}.json`);
|
|
42557
|
+
await this.ensureDirectory(this.baseDirectory);
|
|
42558
|
+
const data = this.prettyPrint ? JSON.stringify(definition, null, 2) : JSON.stringify(definition);
|
|
42559
|
+
const tempPath = `${filePath}.tmp`;
|
|
42560
|
+
try {
|
|
42561
|
+
await promises.writeFile(tempPath, data, "utf-8");
|
|
42562
|
+
await promises.rename(tempPath, filePath);
|
|
42563
|
+
} catch (error) {
|
|
42564
|
+
try {
|
|
42565
|
+
await promises.unlink(tempPath);
|
|
42566
|
+
} catch {
|
|
42567
|
+
}
|
|
42568
|
+
throw error;
|
|
42569
|
+
}
|
|
42570
|
+
await this.updateIndex(definition);
|
|
42571
|
+
}
|
|
42572
|
+
/**
|
|
42573
|
+
* Load a custom tool definition by name
|
|
42574
|
+
*/
|
|
42575
|
+
async load(name) {
|
|
42576
|
+
const sanitized = sanitizeName(name);
|
|
42577
|
+
const filePath = join(this.baseDirectory, `${sanitized}.json`);
|
|
42578
|
+
try {
|
|
42579
|
+
const data = await promises.readFile(filePath, "utf-8");
|
|
42580
|
+
return JSON.parse(data);
|
|
42581
|
+
} catch (error) {
|
|
42582
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
42583
|
+
return null;
|
|
42584
|
+
}
|
|
42585
|
+
if (error instanceof SyntaxError) {
|
|
42586
|
+
return null;
|
|
42587
|
+
}
|
|
42588
|
+
throw error;
|
|
42589
|
+
}
|
|
42590
|
+
}
|
|
42591
|
+
/**
|
|
42592
|
+
* Delete a custom tool definition
|
|
42593
|
+
*/
|
|
42594
|
+
async delete(name) {
|
|
42595
|
+
const sanitized = sanitizeName(name);
|
|
42596
|
+
const filePath = join(this.baseDirectory, `${sanitized}.json`);
|
|
42597
|
+
try {
|
|
42598
|
+
await promises.unlink(filePath);
|
|
42599
|
+
} catch (error) {
|
|
42600
|
+
if (error instanceof Error && "code" in error && error.code !== "ENOENT") {
|
|
42601
|
+
throw error;
|
|
42602
|
+
}
|
|
42603
|
+
}
|
|
42604
|
+
await this.removeFromIndex(name);
|
|
42605
|
+
}
|
|
42606
|
+
/**
|
|
42607
|
+
* Check if a custom tool exists
|
|
42608
|
+
*/
|
|
42609
|
+
async exists(name) {
|
|
42610
|
+
const sanitized = sanitizeName(name);
|
|
42611
|
+
const filePath = join(this.baseDirectory, `${sanitized}.json`);
|
|
42612
|
+
try {
|
|
42613
|
+
await promises.access(filePath);
|
|
42614
|
+
return true;
|
|
42615
|
+
} catch {
|
|
42616
|
+
return false;
|
|
42617
|
+
}
|
|
42618
|
+
}
|
|
42619
|
+
/**
|
|
42620
|
+
* List custom tools (summaries only)
|
|
42621
|
+
*/
|
|
42622
|
+
async list(options) {
|
|
42623
|
+
const index = await this.loadIndex();
|
|
42624
|
+
let entries = [...index.tools];
|
|
42625
|
+
if (options?.tags && options.tags.length > 0) {
|
|
42626
|
+
entries = entries.filter((e) => {
|
|
42627
|
+
const entryTags = e.tags ?? [];
|
|
42628
|
+
return options.tags.some((t) => entryTags.includes(t));
|
|
42629
|
+
});
|
|
42630
|
+
}
|
|
42631
|
+
if (options?.category) {
|
|
42632
|
+
entries = entries.filter((e) => e.category === options.category);
|
|
42633
|
+
}
|
|
42634
|
+
if (options?.search) {
|
|
42635
|
+
const searchLower = options.search.toLowerCase();
|
|
42636
|
+
entries = entries.filter(
|
|
42637
|
+
(e) => e.name.toLowerCase().includes(searchLower) || e.description.toLowerCase().includes(searchLower)
|
|
42638
|
+
);
|
|
42639
|
+
}
|
|
42640
|
+
entries.sort(
|
|
42641
|
+
(a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
|
42642
|
+
);
|
|
42643
|
+
if (options?.offset) {
|
|
42644
|
+
entries = entries.slice(options.offset);
|
|
42645
|
+
}
|
|
42646
|
+
if (options?.limit) {
|
|
42647
|
+
entries = entries.slice(0, options.limit);
|
|
42648
|
+
}
|
|
42649
|
+
return entries.map((e) => ({
|
|
42650
|
+
name: e.name,
|
|
42651
|
+
displayName: e.displayName,
|
|
42652
|
+
description: e.description,
|
|
42653
|
+
createdAt: e.createdAt,
|
|
42654
|
+
updatedAt: e.updatedAt,
|
|
42655
|
+
metadata: {
|
|
42656
|
+
tags: e.tags,
|
|
42657
|
+
category: e.category
|
|
42658
|
+
}
|
|
42659
|
+
}));
|
|
42660
|
+
}
|
|
42661
|
+
/**
|
|
42662
|
+
* Update metadata without loading full definition
|
|
42663
|
+
*/
|
|
42664
|
+
async updateMetadata(name, metadata) {
|
|
42665
|
+
const definition = await this.load(name);
|
|
42666
|
+
if (!definition) {
|
|
42667
|
+
throw new Error(`Custom tool '${name}' not found`);
|
|
42668
|
+
}
|
|
42669
|
+
definition.metadata = { ...definition.metadata, ...metadata };
|
|
42670
|
+
definition.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
42671
|
+
await this.save(definition);
|
|
42672
|
+
}
|
|
42673
|
+
/**
|
|
42674
|
+
* Get storage path
|
|
42675
|
+
*/
|
|
42676
|
+
getPath() {
|
|
42677
|
+
return this.baseDirectory;
|
|
42678
|
+
}
|
|
42679
|
+
// ==========================================================================
|
|
42680
|
+
// Private Helpers
|
|
42681
|
+
// ==========================================================================
|
|
42682
|
+
async ensureDirectory(dir) {
|
|
42683
|
+
try {
|
|
42684
|
+
await promises.mkdir(dir, { recursive: true });
|
|
42685
|
+
} catch (error) {
|
|
42686
|
+
if (error instanceof Error && "code" in error && error.code !== "EEXIST") {
|
|
42687
|
+
throw error;
|
|
42688
|
+
}
|
|
42689
|
+
}
|
|
42690
|
+
}
|
|
42691
|
+
async loadIndex() {
|
|
42692
|
+
if (this.index) {
|
|
42693
|
+
return this.index;
|
|
42694
|
+
}
|
|
42695
|
+
try {
|
|
42696
|
+
const data = await promises.readFile(this.indexPath, "utf-8");
|
|
42697
|
+
this.index = JSON.parse(data);
|
|
42698
|
+
return this.index;
|
|
42699
|
+
} catch (error) {
|
|
42700
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
42701
|
+
this.index = {
|
|
42702
|
+
version: 1,
|
|
42703
|
+
tools: [],
|
|
42704
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
42705
|
+
};
|
|
42706
|
+
return this.index;
|
|
42707
|
+
}
|
|
42708
|
+
throw error;
|
|
42709
|
+
}
|
|
42710
|
+
}
|
|
42711
|
+
async saveIndex() {
|
|
42712
|
+
if (!this.index) return;
|
|
42713
|
+
await this.ensureDirectory(this.baseDirectory);
|
|
42714
|
+
this.index.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
|
|
42715
|
+
const data = this.prettyPrint ? JSON.stringify(this.index, null, 2) : JSON.stringify(this.index);
|
|
42716
|
+
await promises.writeFile(this.indexPath, data, "utf-8");
|
|
42717
|
+
}
|
|
42718
|
+
async updateIndex(definition) {
|
|
42719
|
+
const index = await this.loadIndex();
|
|
42720
|
+
const entry = this.definitionToIndexEntry(definition);
|
|
42721
|
+
const existingIdx = index.tools.findIndex((e) => e.name === definition.name);
|
|
42722
|
+
if (existingIdx >= 0) {
|
|
42723
|
+
index.tools[existingIdx] = entry;
|
|
42724
|
+
} else {
|
|
42725
|
+
index.tools.push(entry);
|
|
42726
|
+
}
|
|
42727
|
+
await this.saveIndex();
|
|
42728
|
+
}
|
|
42729
|
+
async removeFromIndex(name) {
|
|
42730
|
+
const index = await this.loadIndex();
|
|
42731
|
+
index.tools = index.tools.filter((e) => e.name !== name);
|
|
42732
|
+
await this.saveIndex();
|
|
42733
|
+
}
|
|
42734
|
+
definitionToIndexEntry(definition) {
|
|
42735
|
+
return {
|
|
42736
|
+
name: definition.name,
|
|
42737
|
+
displayName: definition.displayName,
|
|
42738
|
+
description: definition.description,
|
|
42739
|
+
createdAt: definition.createdAt,
|
|
42740
|
+
updatedAt: definition.updatedAt,
|
|
42741
|
+
tags: definition.metadata?.tags,
|
|
42742
|
+
category: definition.metadata?.category
|
|
42743
|
+
};
|
|
42744
|
+
}
|
|
42745
|
+
};
|
|
42746
|
+
function createFileCustomToolStorage(config) {
|
|
42747
|
+
return new FileCustomToolStorage(config);
|
|
42748
|
+
}
|
|
42749
|
+
|
|
42750
|
+
// src/domain/entities/CustomToolDefinition.ts
|
|
42751
|
+
var CUSTOM_TOOL_DEFINITION_VERSION = 1;
|
|
42492
42752
|
|
|
42493
42753
|
// src/capabilities/agents/StreamHelpers.ts
|
|
42494
42754
|
var StreamHelpers = class {
|
|
@@ -43585,8 +43845,8 @@ var FileStorage = class {
|
|
|
43585
43845
|
}
|
|
43586
43846
|
async ensureDirectory() {
|
|
43587
43847
|
try {
|
|
43588
|
-
await
|
|
43589
|
-
await
|
|
43848
|
+
await fs16.mkdir(this.directory, { recursive: true });
|
|
43849
|
+
await fs16.chmod(this.directory, 448);
|
|
43590
43850
|
} catch (error) {
|
|
43591
43851
|
}
|
|
43592
43852
|
}
|
|
@@ -43602,13 +43862,13 @@ var FileStorage = class {
|
|
|
43602
43862
|
const filePath = this.getFilePath(key);
|
|
43603
43863
|
const plaintext = JSON.stringify(token);
|
|
43604
43864
|
const encrypted = encrypt(plaintext, this.encryptionKey);
|
|
43605
|
-
await
|
|
43606
|
-
await
|
|
43865
|
+
await fs16.writeFile(filePath, encrypted, "utf8");
|
|
43866
|
+
await fs16.chmod(filePath, 384);
|
|
43607
43867
|
}
|
|
43608
43868
|
async getToken(key) {
|
|
43609
43869
|
const filePath = this.getFilePath(key);
|
|
43610
43870
|
try {
|
|
43611
|
-
const encrypted = await
|
|
43871
|
+
const encrypted = await fs16.readFile(filePath, "utf8");
|
|
43612
43872
|
const decrypted = decrypt(encrypted, this.encryptionKey);
|
|
43613
43873
|
return JSON.parse(decrypted);
|
|
43614
43874
|
} catch (error) {
|
|
@@ -43617,7 +43877,7 @@ var FileStorage = class {
|
|
|
43617
43877
|
}
|
|
43618
43878
|
console.error("Failed to read/decrypt token file:", error);
|
|
43619
43879
|
try {
|
|
43620
|
-
await
|
|
43880
|
+
await fs16.unlink(filePath);
|
|
43621
43881
|
} catch {
|
|
43622
43882
|
}
|
|
43623
43883
|
return null;
|
|
@@ -43626,7 +43886,7 @@ var FileStorage = class {
|
|
|
43626
43886
|
async deleteToken(key) {
|
|
43627
43887
|
const filePath = this.getFilePath(key);
|
|
43628
43888
|
try {
|
|
43629
|
-
await
|
|
43889
|
+
await fs16.unlink(filePath);
|
|
43630
43890
|
} catch (error) {
|
|
43631
43891
|
if (error.code !== "ENOENT") {
|
|
43632
43892
|
throw error;
|
|
@@ -43636,7 +43896,7 @@ var FileStorage = class {
|
|
|
43636
43896
|
async hasToken(key) {
|
|
43637
43897
|
const filePath = this.getFilePath(key);
|
|
43638
43898
|
try {
|
|
43639
|
-
await
|
|
43899
|
+
await fs16.access(filePath);
|
|
43640
43900
|
return true;
|
|
43641
43901
|
} catch {
|
|
43642
43902
|
return false;
|
|
@@ -43647,7 +43907,7 @@ var FileStorage = class {
|
|
|
43647
43907
|
*/
|
|
43648
43908
|
async listTokens() {
|
|
43649
43909
|
try {
|
|
43650
|
-
const files = await
|
|
43910
|
+
const files = await fs16.readdir(this.directory);
|
|
43651
43911
|
return files.filter((f) => f.endsWith(".token")).map((f) => f.replace(".token", ""));
|
|
43652
43912
|
} catch {
|
|
43653
43913
|
return [];
|
|
@@ -43658,10 +43918,10 @@ var FileStorage = class {
|
|
|
43658
43918
|
*/
|
|
43659
43919
|
async clearAll() {
|
|
43660
43920
|
try {
|
|
43661
|
-
const files = await
|
|
43921
|
+
const files = await fs16.readdir(this.directory);
|
|
43662
43922
|
const tokenFiles = files.filter((f) => f.endsWith(".token"));
|
|
43663
43923
|
await Promise.all(
|
|
43664
|
-
tokenFiles.map((f) =>
|
|
43924
|
+
tokenFiles.map((f) => fs16.unlink(path2.join(this.directory, f)).catch(() => {
|
|
43665
43925
|
}))
|
|
43666
43926
|
);
|
|
43667
43927
|
} catch {
|
|
@@ -44088,14 +44348,14 @@ var FileConnectorStorage = class {
|
|
|
44088
44348
|
await this.ensureDirectory();
|
|
44089
44349
|
const filePath = this.getFilePath(name);
|
|
44090
44350
|
const json = JSON.stringify(stored, null, 2);
|
|
44091
|
-
await
|
|
44092
|
-
await
|
|
44351
|
+
await fs16.writeFile(filePath, json, "utf8");
|
|
44352
|
+
await fs16.chmod(filePath, 384);
|
|
44093
44353
|
await this.updateIndex(name, "add");
|
|
44094
44354
|
}
|
|
44095
44355
|
async get(name) {
|
|
44096
44356
|
const filePath = this.getFilePath(name);
|
|
44097
44357
|
try {
|
|
44098
|
-
const json = await
|
|
44358
|
+
const json = await fs16.readFile(filePath, "utf8");
|
|
44099
44359
|
return JSON.parse(json);
|
|
44100
44360
|
} catch (error) {
|
|
44101
44361
|
const err = error;
|
|
@@ -44108,7 +44368,7 @@ var FileConnectorStorage = class {
|
|
|
44108
44368
|
async delete(name) {
|
|
44109
44369
|
const filePath = this.getFilePath(name);
|
|
44110
44370
|
try {
|
|
44111
|
-
await
|
|
44371
|
+
await fs16.unlink(filePath);
|
|
44112
44372
|
await this.updateIndex(name, "remove");
|
|
44113
44373
|
return true;
|
|
44114
44374
|
} catch (error) {
|
|
@@ -44122,7 +44382,7 @@ var FileConnectorStorage = class {
|
|
|
44122
44382
|
async has(name) {
|
|
44123
44383
|
const filePath = this.getFilePath(name);
|
|
44124
44384
|
try {
|
|
44125
|
-
await
|
|
44385
|
+
await fs16.access(filePath);
|
|
44126
44386
|
return true;
|
|
44127
44387
|
} catch {
|
|
44128
44388
|
return false;
|
|
@@ -44148,13 +44408,13 @@ var FileConnectorStorage = class {
|
|
|
44148
44408
|
*/
|
|
44149
44409
|
async clear() {
|
|
44150
44410
|
try {
|
|
44151
|
-
const files = await
|
|
44411
|
+
const files = await fs16.readdir(this.directory);
|
|
44152
44412
|
const connectorFiles = files.filter(
|
|
44153
44413
|
(f) => f.endsWith(".connector.json") || f === "_index.json"
|
|
44154
44414
|
);
|
|
44155
44415
|
await Promise.all(
|
|
44156
44416
|
connectorFiles.map(
|
|
44157
|
-
(f) =>
|
|
44417
|
+
(f) => fs16.unlink(path2.join(this.directory, f)).catch(() => {
|
|
44158
44418
|
})
|
|
44159
44419
|
)
|
|
44160
44420
|
);
|
|
@@ -44181,8 +44441,8 @@ var FileConnectorStorage = class {
|
|
|
44181
44441
|
async ensureDirectory() {
|
|
44182
44442
|
if (this.initialized) return;
|
|
44183
44443
|
try {
|
|
44184
|
-
await
|
|
44185
|
-
await
|
|
44444
|
+
await fs16.mkdir(this.directory, { recursive: true });
|
|
44445
|
+
await fs16.chmod(this.directory, 448);
|
|
44186
44446
|
this.initialized = true;
|
|
44187
44447
|
} catch {
|
|
44188
44448
|
this.initialized = true;
|
|
@@ -44193,7 +44453,7 @@ var FileConnectorStorage = class {
|
|
|
44193
44453
|
*/
|
|
44194
44454
|
async loadIndex() {
|
|
44195
44455
|
try {
|
|
44196
|
-
const json = await
|
|
44456
|
+
const json = await fs16.readFile(this.indexPath, "utf8");
|
|
44197
44457
|
return JSON.parse(json);
|
|
44198
44458
|
} catch {
|
|
44199
44459
|
return { connectors: {} };
|
|
@@ -44211,8 +44471,8 @@ var FileConnectorStorage = class {
|
|
|
44211
44471
|
delete index.connectors[hash];
|
|
44212
44472
|
}
|
|
44213
44473
|
const json = JSON.stringify(index, null, 2);
|
|
44214
|
-
await
|
|
44215
|
-
await
|
|
44474
|
+
await fs16.writeFile(this.indexPath, json, "utf8");
|
|
44475
|
+
await fs16.chmod(this.indexPath, 384);
|
|
44216
44476
|
}
|
|
44217
44477
|
};
|
|
44218
44478
|
|
|
@@ -46667,8 +46927,8 @@ function createMessageWithImages(text, imageUrls, role = "user" /* USER */) {
|
|
|
46667
46927
|
var execAsync = promisify(exec);
|
|
46668
46928
|
function cleanupTempFile(filePath) {
|
|
46669
46929
|
try {
|
|
46670
|
-
if (
|
|
46671
|
-
|
|
46930
|
+
if (fs17.existsSync(filePath)) {
|
|
46931
|
+
fs17.unlinkSync(filePath);
|
|
46672
46932
|
}
|
|
46673
46933
|
} catch {
|
|
46674
46934
|
}
|
|
@@ -46719,7 +46979,7 @@ async function readClipboardImageMac() {
|
|
|
46719
46979
|
end try
|
|
46720
46980
|
`;
|
|
46721
46981
|
const { stdout } = await execAsync(`osascript -e '${script}'`);
|
|
46722
|
-
if (stdout.includes("success") ||
|
|
46982
|
+
if (stdout.includes("success") || fs17.existsSync(tempFile)) {
|
|
46723
46983
|
return await convertFileToDataUri(tempFile);
|
|
46724
46984
|
}
|
|
46725
46985
|
return {
|
|
@@ -46736,14 +46996,14 @@ async function readClipboardImageLinux() {
|
|
|
46736
46996
|
try {
|
|
46737
46997
|
try {
|
|
46738
46998
|
await execAsync(`xclip -selection clipboard -t image/png -o > "${tempFile}"`);
|
|
46739
|
-
if (
|
|
46999
|
+
if (fs17.existsSync(tempFile) && fs17.statSync(tempFile).size > 0) {
|
|
46740
47000
|
return await convertFileToDataUri(tempFile);
|
|
46741
47001
|
}
|
|
46742
47002
|
} catch {
|
|
46743
47003
|
}
|
|
46744
47004
|
try {
|
|
46745
47005
|
await execAsync(`wl-paste -t image/png > "${tempFile}"`);
|
|
46746
|
-
if (
|
|
47006
|
+
if (fs17.existsSync(tempFile) && fs17.statSync(tempFile).size > 0) {
|
|
46747
47007
|
return await convertFileToDataUri(tempFile);
|
|
46748
47008
|
}
|
|
46749
47009
|
} catch {
|
|
@@ -46770,7 +47030,7 @@ async function readClipboardImageWindows() {
|
|
|
46770
47030
|
}
|
|
46771
47031
|
`;
|
|
46772
47032
|
await execAsync(`powershell -Command "${psScript}"`);
|
|
46773
|
-
if (
|
|
47033
|
+
if (fs17.existsSync(tempFile) && fs17.statSync(tempFile).size > 0) {
|
|
46774
47034
|
return await convertFileToDataUri(tempFile);
|
|
46775
47035
|
}
|
|
46776
47036
|
return {
|
|
@@ -46783,7 +47043,7 @@ async function readClipboardImageWindows() {
|
|
|
46783
47043
|
}
|
|
46784
47044
|
async function convertFileToDataUri(filePath) {
|
|
46785
47045
|
try {
|
|
46786
|
-
const imageBuffer =
|
|
47046
|
+
const imageBuffer = fs17.readFileSync(filePath);
|
|
46787
47047
|
const base64Image = imageBuffer.toString("base64");
|
|
46788
47048
|
const magic = imageBuffer.slice(0, 4).toString("hex");
|
|
46789
47049
|
let mimeType = "image/png";
|
|
@@ -47039,6 +47299,13 @@ __export(tools_exports, {
|
|
|
47039
47299
|
bash: () => bash,
|
|
47040
47300
|
createBashTool: () => createBashTool,
|
|
47041
47301
|
createCreatePRTool: () => createCreatePRTool,
|
|
47302
|
+
createCustomToolDelete: () => createCustomToolDelete,
|
|
47303
|
+
createCustomToolDraft: () => createCustomToolDraft,
|
|
47304
|
+
createCustomToolList: () => createCustomToolList,
|
|
47305
|
+
createCustomToolLoad: () => createCustomToolLoad,
|
|
47306
|
+
createCustomToolMetaTools: () => createCustomToolMetaTools,
|
|
47307
|
+
createCustomToolSave: () => createCustomToolSave,
|
|
47308
|
+
createCustomToolTest: () => createCustomToolTest,
|
|
47042
47309
|
createDesktopGetCursorTool: () => createDesktopGetCursorTool,
|
|
47043
47310
|
createDesktopGetScreenSizeTool: () => createDesktopGetScreenSizeTool,
|
|
47044
47311
|
createDesktopKeyboardKeyTool: () => createDesktopKeyboardKeyTool,
|
|
@@ -47069,6 +47336,12 @@ __export(tools_exports, {
|
|
|
47069
47336
|
createWebScrapeTool: () => createWebScrapeTool,
|
|
47070
47337
|
createWebSearchTool: () => createWebSearchTool,
|
|
47071
47338
|
createWriteFileTool: () => createWriteFileTool,
|
|
47339
|
+
customToolDelete: () => customToolDelete,
|
|
47340
|
+
customToolDraft: () => customToolDraft,
|
|
47341
|
+
customToolList: () => customToolList,
|
|
47342
|
+
customToolLoad: () => customToolLoad,
|
|
47343
|
+
customToolSave: () => customToolSave,
|
|
47344
|
+
customToolTest: () => customToolTest,
|
|
47072
47345
|
desktopGetCursor: () => desktopGetCursor,
|
|
47073
47346
|
desktopGetScreenSize: () => desktopGetScreenSize,
|
|
47074
47347
|
desktopKeyboardKey: () => desktopKeyboardKey,
|
|
@@ -47083,6 +47356,7 @@ __export(tools_exports, {
|
|
|
47083
47356
|
desktopWindowList: () => desktopWindowList,
|
|
47084
47357
|
developerTools: () => developerTools,
|
|
47085
47358
|
editFile: () => editFile,
|
|
47359
|
+
executeInVM: () => executeInVM,
|
|
47086
47360
|
executeJavaScript: () => executeJavaScript,
|
|
47087
47361
|
expandTilde: () => expandTilde,
|
|
47088
47362
|
getAllBuiltInTools: () => getAllBuiltInTools,
|
|
@@ -47097,6 +47371,7 @@ __export(tools_exports, {
|
|
|
47097
47371
|
getToolsRequiringConnector: () => getToolsRequiringConnector,
|
|
47098
47372
|
glob: () => glob,
|
|
47099
47373
|
grep: () => grep,
|
|
47374
|
+
hydrateCustomTool: () => hydrateCustomTool,
|
|
47100
47375
|
isBlockedCommand: () => isBlockedCommand,
|
|
47101
47376
|
isExcludedExtension: () => isExcludedExtension,
|
|
47102
47377
|
jsonManipulator: () => jsonManipulator,
|
|
@@ -52004,6 +52279,498 @@ var desktopTools = [
|
|
|
52004
52279
|
desktopWindowFocus
|
|
52005
52280
|
];
|
|
52006
52281
|
|
|
52282
|
+
// src/tools/custom-tools/customToolDelete.ts
|
|
52283
|
+
function createCustomToolDelete(storage) {
|
|
52284
|
+
return {
|
|
52285
|
+
definition: {
|
|
52286
|
+
type: "function",
|
|
52287
|
+
function: {
|
|
52288
|
+
name: "custom_tool_delete",
|
|
52289
|
+
description: "Delete a custom tool from persistent storage.",
|
|
52290
|
+
parameters: {
|
|
52291
|
+
type: "object",
|
|
52292
|
+
properties: {
|
|
52293
|
+
name: {
|
|
52294
|
+
type: "string",
|
|
52295
|
+
description: "Name of the tool to delete"
|
|
52296
|
+
}
|
|
52297
|
+
},
|
|
52298
|
+
required: ["name"]
|
|
52299
|
+
}
|
|
52300
|
+
}
|
|
52301
|
+
},
|
|
52302
|
+
permission: { scope: "session", riskLevel: "medium" },
|
|
52303
|
+
execute: async (args) => {
|
|
52304
|
+
try {
|
|
52305
|
+
const exists = await storage.exists(args.name);
|
|
52306
|
+
if (!exists) {
|
|
52307
|
+
return { success: false, name: args.name, error: `Custom tool '${args.name}' not found` };
|
|
52308
|
+
}
|
|
52309
|
+
await storage.delete(args.name);
|
|
52310
|
+
return { success: true, name: args.name };
|
|
52311
|
+
} catch (error) {
|
|
52312
|
+
return { success: false, name: args.name, error: error.message };
|
|
52313
|
+
}
|
|
52314
|
+
},
|
|
52315
|
+
describeCall: (args) => args.name
|
|
52316
|
+
};
|
|
52317
|
+
}
|
|
52318
|
+
var customToolDelete = createCustomToolDelete(new FileCustomToolStorage());
|
|
52319
|
+
|
|
52320
|
+
// src/tools/custom-tools/sandboxDescription.ts
|
|
52321
|
+
init_Connector();
|
|
52322
|
+
function formatConnectorEntry2(c) {
|
|
52323
|
+
const parts = [];
|
|
52324
|
+
const serviceOrVendor = c.serviceType ?? c.vendor ?? void 0;
|
|
52325
|
+
if (serviceOrVendor) parts.push(`Service: ${serviceOrVendor}`);
|
|
52326
|
+
if (c.config.description) parts.push(c.config.description);
|
|
52327
|
+
if (c.baseURL) parts.push(`URL: ${c.baseURL}`);
|
|
52328
|
+
const details = parts.map((p) => ` ${p}`).join("\n");
|
|
52329
|
+
return ` \u2022 "${c.name}" (${c.displayName})
|
|
52330
|
+
${details}`;
|
|
52331
|
+
}
|
|
52332
|
+
function buildConnectorList(context) {
|
|
52333
|
+
const registry = context?.connectorRegistry ?? Connector.asRegistry();
|
|
52334
|
+
const connectors = registry.listAll();
|
|
52335
|
+
if (connectors.length === 0) {
|
|
52336
|
+
return " No connectors registered.";
|
|
52337
|
+
}
|
|
52338
|
+
return connectors.map(formatConnectorEntry2).join("\n\n");
|
|
52339
|
+
}
|
|
52340
|
+
var SANDBOX_API_REFERENCE = `SANDBOX API (available inside custom tool code):
|
|
52341
|
+
|
|
52342
|
+
1. authenticatedFetch(url, options, connectorName)
|
|
52343
|
+
Makes authenticated HTTP requests using the connector's credentials.
|
|
52344
|
+
Auth headers are added automatically \u2014 DO NOT set Authorization header manually.
|
|
52345
|
+
|
|
52346
|
+
Parameters:
|
|
52347
|
+
\u2022 url: Full URL or path relative to the connector's base URL
|
|
52348
|
+
- Full: "https://api.github.com/user/repos"
|
|
52349
|
+
- Relative: "/user/repos" (resolved against connector's base URL)
|
|
52350
|
+
\u2022 options: Standard fetch options { method, headers, body }
|
|
52351
|
+
- For POST/PUT: set body to JSON.stringify(data) and headers to { 'Content-Type': 'application/json' }
|
|
52352
|
+
\u2022 connectorName: Name of a registered connector (see REGISTERED CONNECTORS below)
|
|
52353
|
+
|
|
52354
|
+
Returns: Promise<Response>
|
|
52355
|
+
\u2022 response.ok \u2014 true if status 200-299
|
|
52356
|
+
\u2022 response.status \u2014 HTTP status code
|
|
52357
|
+
\u2022 await response.json() \u2014 parse JSON body
|
|
52358
|
+
\u2022 await response.text() \u2014 get text body
|
|
52359
|
+
|
|
52360
|
+
2. fetch(url, options) \u2014 Standard fetch without authentication
|
|
52361
|
+
|
|
52362
|
+
3. connectors.list() \u2014 Array of available connector names
|
|
52363
|
+
4. connectors.get(name) \u2014 Connector info: { displayName, description, baseURL, serviceType }
|
|
52364
|
+
|
|
52365
|
+
VARIABLES:
|
|
52366
|
+
\u2022 input \u2014 the tool's input arguments (matches inputSchema)
|
|
52367
|
+
\u2022 output \u2014 SET THIS to return the tool's result to the caller
|
|
52368
|
+
|
|
52369
|
+
GLOBALS: console.log/error/warn, JSON, Math, Date, Buffer, Promise, Array, Object, String, Number, Boolean, setTimeout, setInterval, URL, URLSearchParams, RegExp, Map, Set, Error, TextEncoder, TextDecoder
|
|
52370
|
+
|
|
52371
|
+
LIMITS: No file system access, no require/import. Code runs in async context (await is available).`;
|
|
52372
|
+
function buildDraftDescription(context) {
|
|
52373
|
+
const connectorList = buildConnectorList(context);
|
|
52374
|
+
return `Validate a draft custom tool definition. Checks name format, schema structure, and code syntax.
|
|
52375
|
+
|
|
52376
|
+
When writing the "code" field, you have access to the full VM sandbox:
|
|
52377
|
+
|
|
52378
|
+
${SANDBOX_API_REFERENCE}
|
|
52379
|
+
|
|
52380
|
+
REGISTERED CONNECTORS:
|
|
52381
|
+
${connectorList}
|
|
52382
|
+
|
|
52383
|
+
CODE EXAMPLES:
|
|
52384
|
+
|
|
52385
|
+
// Simple data processing tool
|
|
52386
|
+
const items = input.data;
|
|
52387
|
+
output = items.filter(i => i.score > 0.8).sort((a, b) => b.score - a.score);
|
|
52388
|
+
|
|
52389
|
+
// API tool using a connector
|
|
52390
|
+
const resp = await authenticatedFetch('/user/repos', { method: 'GET' }, 'github');
|
|
52391
|
+
const repos = await resp.json();
|
|
52392
|
+
output = repos.map(r => ({ name: r.full_name, stars: r.stargazers_count }));
|
|
52393
|
+
|
|
52394
|
+
// Tool that chains multiple API calls
|
|
52395
|
+
const users = await (await authenticatedFetch('/users', {}, 'my-api')).json();
|
|
52396
|
+
const enriched = await Promise.all(users.map(async u => {
|
|
52397
|
+
const details = await (await authenticatedFetch(\`/users/\${u.id}\`, {}, 'my-api')).json();
|
|
52398
|
+
return { ...u, ...details };
|
|
52399
|
+
}));
|
|
52400
|
+
output = enriched;`;
|
|
52401
|
+
}
|
|
52402
|
+
function buildTestDescription(context) {
|
|
52403
|
+
const connectorList = buildConnectorList(context);
|
|
52404
|
+
return `Test custom tool code by executing it in the VM sandbox with provided test input. Returns execution result, captured logs, and timing.
|
|
52405
|
+
|
|
52406
|
+
The code runs in the same sandbox as execute_javascript:
|
|
52407
|
+
|
|
52408
|
+
${SANDBOX_API_REFERENCE}
|
|
52409
|
+
|
|
52410
|
+
REGISTERED CONNECTORS:
|
|
52411
|
+
${connectorList}
|
|
52412
|
+
|
|
52413
|
+
The testInput you provide will be available as the \`input\` variable in the code.
|
|
52414
|
+
Set \`output\` to the value you want returned.`;
|
|
52415
|
+
}
|
|
52416
|
+
|
|
52417
|
+
// src/tools/custom-tools/customToolDraft.ts
|
|
52418
|
+
var NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
52419
|
+
function createCustomToolDraft() {
|
|
52420
|
+
return {
|
|
52421
|
+
definition: {
|
|
52422
|
+
type: "function",
|
|
52423
|
+
function: {
|
|
52424
|
+
name: "custom_tool_draft",
|
|
52425
|
+
description: "Validate a draft custom tool definition. Checks name format, schema structure, and code syntax.",
|
|
52426
|
+
parameters: {
|
|
52427
|
+
type: "object",
|
|
52428
|
+
properties: {
|
|
52429
|
+
name: {
|
|
52430
|
+
type: "string",
|
|
52431
|
+
description: 'Tool name (lowercase, underscores, must start with letter). Example: "fetch_weather"'
|
|
52432
|
+
},
|
|
52433
|
+
description: {
|
|
52434
|
+
type: "string",
|
|
52435
|
+
description: "What the tool does"
|
|
52436
|
+
},
|
|
52437
|
+
inputSchema: {
|
|
52438
|
+
type: "object",
|
|
52439
|
+
description: 'JSON Schema for the tool input (must have type: "object")'
|
|
52440
|
+
},
|
|
52441
|
+
outputSchema: {
|
|
52442
|
+
type: "object",
|
|
52443
|
+
description: "Optional JSON Schema for the tool output (documentation only)"
|
|
52444
|
+
},
|
|
52445
|
+
code: {
|
|
52446
|
+
type: "string",
|
|
52447
|
+
description: "JavaScript code that reads `input` and sets `output`. Runs in the same sandbox as execute_javascript. See tool description for full API reference."
|
|
52448
|
+
},
|
|
52449
|
+
tags: {
|
|
52450
|
+
type: "array",
|
|
52451
|
+
description: "Optional tags for categorization",
|
|
52452
|
+
items: { type: "string" }
|
|
52453
|
+
},
|
|
52454
|
+
connectorName: {
|
|
52455
|
+
type: "string",
|
|
52456
|
+
description: "Optional connector name if the tool requires API access"
|
|
52457
|
+
}
|
|
52458
|
+
},
|
|
52459
|
+
required: ["name", "description", "inputSchema", "code"]
|
|
52460
|
+
}
|
|
52461
|
+
}
|
|
52462
|
+
},
|
|
52463
|
+
descriptionFactory: (context) => buildDraftDescription(context),
|
|
52464
|
+
permission: { scope: "always", riskLevel: "low" },
|
|
52465
|
+
execute: async (args) => {
|
|
52466
|
+
const errors = [];
|
|
52467
|
+
if (!args.name || typeof args.name !== "string") {
|
|
52468
|
+
errors.push("name is required and must be a string");
|
|
52469
|
+
} else if (!NAME_PATTERN.test(args.name)) {
|
|
52470
|
+
errors.push(
|
|
52471
|
+
`name "${args.name}" is invalid. Must match /^[a-z][a-z0-9_]*$/ (lowercase, underscores, start with letter)`
|
|
52472
|
+
);
|
|
52473
|
+
}
|
|
52474
|
+
if (!args.description || typeof args.description !== "string" || args.description.trim().length === 0) {
|
|
52475
|
+
errors.push("description is required and must be a non-empty string");
|
|
52476
|
+
}
|
|
52477
|
+
if (!args.inputSchema || typeof args.inputSchema !== "object") {
|
|
52478
|
+
errors.push("inputSchema is required and must be an object");
|
|
52479
|
+
} else if (args.inputSchema.type !== "object") {
|
|
52480
|
+
errors.push('inputSchema.type must be "object"');
|
|
52481
|
+
}
|
|
52482
|
+
if (!args.code || typeof args.code !== "string" || args.code.trim().length === 0) {
|
|
52483
|
+
errors.push("code is required and must be a non-empty string");
|
|
52484
|
+
} else {
|
|
52485
|
+
try {
|
|
52486
|
+
new Function(args.code);
|
|
52487
|
+
} catch (e) {
|
|
52488
|
+
errors.push(`code has syntax error: ${e.message}`);
|
|
52489
|
+
}
|
|
52490
|
+
}
|
|
52491
|
+
if (errors.length > 0) {
|
|
52492
|
+
return { success: false, errors };
|
|
52493
|
+
}
|
|
52494
|
+
return {
|
|
52495
|
+
success: true,
|
|
52496
|
+
validated: {
|
|
52497
|
+
name: args.name,
|
|
52498
|
+
description: args.description,
|
|
52499
|
+
inputSchema: args.inputSchema,
|
|
52500
|
+
outputSchema: args.outputSchema,
|
|
52501
|
+
code: args.code,
|
|
52502
|
+
tags: args.tags,
|
|
52503
|
+
connectorName: args.connectorName
|
|
52504
|
+
}
|
|
52505
|
+
};
|
|
52506
|
+
},
|
|
52507
|
+
describeCall: (args) => args.name ?? "unknown"
|
|
52508
|
+
};
|
|
52509
|
+
}
|
|
52510
|
+
var customToolDraft = createCustomToolDraft();
|
|
52511
|
+
|
|
52512
|
+
// src/tools/custom-tools/customToolList.ts
|
|
52513
|
+
function createCustomToolList(storage) {
|
|
52514
|
+
return {
|
|
52515
|
+
definition: {
|
|
52516
|
+
type: "function",
|
|
52517
|
+
function: {
|
|
52518
|
+
name: "custom_tool_list",
|
|
52519
|
+
description: "List saved custom tools from persistent storage. Supports filtering by search text, tags, and category.",
|
|
52520
|
+
parameters: {
|
|
52521
|
+
type: "object",
|
|
52522
|
+
properties: {
|
|
52523
|
+
search: {
|
|
52524
|
+
type: "string",
|
|
52525
|
+
description: "Search text (case-insensitive substring match on name + description)"
|
|
52526
|
+
},
|
|
52527
|
+
tags: {
|
|
52528
|
+
type: "array",
|
|
52529
|
+
description: "Filter by tags (any match)",
|
|
52530
|
+
items: { type: "string" }
|
|
52531
|
+
},
|
|
52532
|
+
category: {
|
|
52533
|
+
type: "string",
|
|
52534
|
+
description: "Filter by category"
|
|
52535
|
+
},
|
|
52536
|
+
limit: {
|
|
52537
|
+
type: "number",
|
|
52538
|
+
description: "Maximum number of results"
|
|
52539
|
+
},
|
|
52540
|
+
offset: {
|
|
52541
|
+
type: "number",
|
|
52542
|
+
description: "Offset for pagination"
|
|
52543
|
+
}
|
|
52544
|
+
}
|
|
52545
|
+
}
|
|
52546
|
+
}
|
|
52547
|
+
},
|
|
52548
|
+
permission: { scope: "always", riskLevel: "low" },
|
|
52549
|
+
execute: async (args) => {
|
|
52550
|
+
const tools = await storage.list({
|
|
52551
|
+
search: args.search,
|
|
52552
|
+
tags: args.tags,
|
|
52553
|
+
category: args.category,
|
|
52554
|
+
limit: args.limit,
|
|
52555
|
+
offset: args.offset
|
|
52556
|
+
});
|
|
52557
|
+
return { tools, total: tools.length };
|
|
52558
|
+
},
|
|
52559
|
+
describeCall: (args) => args.search ?? "all tools"
|
|
52560
|
+
};
|
|
52561
|
+
}
|
|
52562
|
+
var customToolList = createCustomToolList(new FileCustomToolStorage());
|
|
52563
|
+
|
|
52564
|
+
// src/tools/custom-tools/customToolLoad.ts
|
|
52565
|
+
function createCustomToolLoad(storage) {
|
|
52566
|
+
return {
|
|
52567
|
+
definition: {
|
|
52568
|
+
type: "function",
|
|
52569
|
+
function: {
|
|
52570
|
+
name: "custom_tool_load",
|
|
52571
|
+
description: "Load a full custom tool definition from storage (including code). Use this to inspect, modify, or hydrate a saved tool.",
|
|
52572
|
+
parameters: {
|
|
52573
|
+
type: "object",
|
|
52574
|
+
properties: {
|
|
52575
|
+
name: {
|
|
52576
|
+
type: "string",
|
|
52577
|
+
description: "Name of the tool to load"
|
|
52578
|
+
}
|
|
52579
|
+
},
|
|
52580
|
+
required: ["name"]
|
|
52581
|
+
}
|
|
52582
|
+
}
|
|
52583
|
+
},
|
|
52584
|
+
permission: { scope: "always", riskLevel: "low" },
|
|
52585
|
+
execute: async (args) => {
|
|
52586
|
+
const tool = await storage.load(args.name);
|
|
52587
|
+
if (!tool) {
|
|
52588
|
+
return { success: false, error: `Custom tool '${args.name}' not found` };
|
|
52589
|
+
}
|
|
52590
|
+
return { success: true, tool };
|
|
52591
|
+
},
|
|
52592
|
+
describeCall: (args) => args.name
|
|
52593
|
+
};
|
|
52594
|
+
}
|
|
52595
|
+
var customToolLoad = createCustomToolLoad(new FileCustomToolStorage());
|
|
52596
|
+
|
|
52597
|
+
// src/tools/custom-tools/customToolSave.ts
|
|
52598
|
+
function createCustomToolSave(storage) {
|
|
52599
|
+
return {
|
|
52600
|
+
definition: {
|
|
52601
|
+
type: "function",
|
|
52602
|
+
function: {
|
|
52603
|
+
name: "custom_tool_save",
|
|
52604
|
+
description: "Save a custom tool definition to persistent storage. The tool can later be loaded, hydrated, and registered on any agent.",
|
|
52605
|
+
parameters: {
|
|
52606
|
+
type: "object",
|
|
52607
|
+
properties: {
|
|
52608
|
+
name: {
|
|
52609
|
+
type: "string",
|
|
52610
|
+
description: "Tool name (must match /^[a-z][a-z0-9_]*$/)"
|
|
52611
|
+
},
|
|
52612
|
+
description: {
|
|
52613
|
+
type: "string",
|
|
52614
|
+
description: "What the tool does"
|
|
52615
|
+
},
|
|
52616
|
+
displayName: {
|
|
52617
|
+
type: "string",
|
|
52618
|
+
description: "Optional human-readable display name"
|
|
52619
|
+
},
|
|
52620
|
+
inputSchema: {
|
|
52621
|
+
type: "object",
|
|
52622
|
+
description: "JSON Schema for input parameters"
|
|
52623
|
+
},
|
|
52624
|
+
outputSchema: {
|
|
52625
|
+
type: "object",
|
|
52626
|
+
description: "Optional JSON Schema for output"
|
|
52627
|
+
},
|
|
52628
|
+
code: {
|
|
52629
|
+
type: "string",
|
|
52630
|
+
description: "JavaScript code (same sandbox as execute_javascript)"
|
|
52631
|
+
},
|
|
52632
|
+
tags: {
|
|
52633
|
+
type: "array",
|
|
52634
|
+
description: "Tags for categorization",
|
|
52635
|
+
items: { type: "string" }
|
|
52636
|
+
},
|
|
52637
|
+
category: {
|
|
52638
|
+
type: "string",
|
|
52639
|
+
description: "Category grouping"
|
|
52640
|
+
},
|
|
52641
|
+
generationPrompt: {
|
|
52642
|
+
type: "string",
|
|
52643
|
+
description: "The prompt that was used to generate this tool (for reference)"
|
|
52644
|
+
},
|
|
52645
|
+
connectorNames: {
|
|
52646
|
+
type: "array",
|
|
52647
|
+
description: "Connector names this tool uses",
|
|
52648
|
+
items: { type: "string" }
|
|
52649
|
+
}
|
|
52650
|
+
},
|
|
52651
|
+
required: ["name", "description", "inputSchema", "code"]
|
|
52652
|
+
}
|
|
52653
|
+
}
|
|
52654
|
+
},
|
|
52655
|
+
permission: { scope: "session", riskLevel: "medium" },
|
|
52656
|
+
execute: async (args) => {
|
|
52657
|
+
try {
|
|
52658
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
52659
|
+
const existing = await storage.load(args.name);
|
|
52660
|
+
const definition = {
|
|
52661
|
+
version: CUSTOM_TOOL_DEFINITION_VERSION,
|
|
52662
|
+
name: args.name,
|
|
52663
|
+
displayName: args.displayName,
|
|
52664
|
+
description: args.description,
|
|
52665
|
+
inputSchema: args.inputSchema,
|
|
52666
|
+
outputSchema: args.outputSchema,
|
|
52667
|
+
code: args.code,
|
|
52668
|
+
createdAt: existing?.createdAt ?? now,
|
|
52669
|
+
updatedAt: now,
|
|
52670
|
+
metadata: {
|
|
52671
|
+
tags: args.tags,
|
|
52672
|
+
category: args.category,
|
|
52673
|
+
generationPrompt: args.generationPrompt,
|
|
52674
|
+
connectorNames: args.connectorNames,
|
|
52675
|
+
requiresConnector: (args.connectorNames?.length ?? 0) > 0
|
|
52676
|
+
}
|
|
52677
|
+
};
|
|
52678
|
+
await storage.save(definition);
|
|
52679
|
+
return {
|
|
52680
|
+
success: true,
|
|
52681
|
+
name: args.name,
|
|
52682
|
+
storagePath: storage.getPath()
|
|
52683
|
+
};
|
|
52684
|
+
} catch (error) {
|
|
52685
|
+
return {
|
|
52686
|
+
success: false,
|
|
52687
|
+
name: args.name,
|
|
52688
|
+
storagePath: storage.getPath(),
|
|
52689
|
+
error: error.message
|
|
52690
|
+
};
|
|
52691
|
+
}
|
|
52692
|
+
},
|
|
52693
|
+
describeCall: (args) => args.name
|
|
52694
|
+
};
|
|
52695
|
+
}
|
|
52696
|
+
var customToolSave = createCustomToolSave(new FileCustomToolStorage());
|
|
52697
|
+
|
|
52698
|
+
// src/tools/custom-tools/customToolTest.ts
|
|
52699
|
+
init_Connector();
|
|
52700
|
+
var DEFAULT_TEST_TIMEOUT = 1e4;
|
|
52701
|
+
var MAX_TEST_TIMEOUT = 3e4;
|
|
52702
|
+
function createCustomToolTest() {
|
|
52703
|
+
return {
|
|
52704
|
+
definition: {
|
|
52705
|
+
type: "function",
|
|
52706
|
+
function: {
|
|
52707
|
+
name: "custom_tool_test",
|
|
52708
|
+
description: "Test custom tool code by executing it in the VM sandbox with provided test input.",
|
|
52709
|
+
parameters: {
|
|
52710
|
+
type: "object",
|
|
52711
|
+
properties: {
|
|
52712
|
+
code: {
|
|
52713
|
+
type: "string",
|
|
52714
|
+
description: "JavaScript code to test. See tool description for full sandbox API reference."
|
|
52715
|
+
},
|
|
52716
|
+
inputSchema: {
|
|
52717
|
+
type: "object",
|
|
52718
|
+
description: "The input schema (for documentation, not enforced at test time)"
|
|
52719
|
+
},
|
|
52720
|
+
testInput: {
|
|
52721
|
+
description: "Test input data \u2014 available as `input` in the code"
|
|
52722
|
+
},
|
|
52723
|
+
connectorName: {
|
|
52724
|
+
type: "string",
|
|
52725
|
+
description: "Optional connector name for authenticated API access"
|
|
52726
|
+
},
|
|
52727
|
+
timeout: {
|
|
52728
|
+
type: "number",
|
|
52729
|
+
description: `Execution timeout in ms. Default: ${DEFAULT_TEST_TIMEOUT}, max: ${MAX_TEST_TIMEOUT}`
|
|
52730
|
+
}
|
|
52731
|
+
},
|
|
52732
|
+
required: ["code", "inputSchema", "testInput"]
|
|
52733
|
+
}
|
|
52734
|
+
},
|
|
52735
|
+
timeout: MAX_TEST_TIMEOUT + 5e3
|
|
52736
|
+
},
|
|
52737
|
+
descriptionFactory: (context) => buildTestDescription(context),
|
|
52738
|
+
permission: { scope: "session", riskLevel: "medium" },
|
|
52739
|
+
execute: async (args, context) => {
|
|
52740
|
+
const logs = [];
|
|
52741
|
+
const startTime = Date.now();
|
|
52742
|
+
const timeout = Math.min(Math.max(args.timeout || DEFAULT_TEST_TIMEOUT, 0), MAX_TEST_TIMEOUT);
|
|
52743
|
+
try {
|
|
52744
|
+
const registry = context?.connectorRegistry ?? Connector.asRegistry();
|
|
52745
|
+
const result = await executeInVM(
|
|
52746
|
+
args.code,
|
|
52747
|
+
args.testInput,
|
|
52748
|
+
timeout,
|
|
52749
|
+
logs,
|
|
52750
|
+
context?.userId,
|
|
52751
|
+
registry
|
|
52752
|
+
);
|
|
52753
|
+
return {
|
|
52754
|
+
success: true,
|
|
52755
|
+
result,
|
|
52756
|
+
logs,
|
|
52757
|
+
executionTime: Date.now() - startTime
|
|
52758
|
+
};
|
|
52759
|
+
} catch (error) {
|
|
52760
|
+
return {
|
|
52761
|
+
success: false,
|
|
52762
|
+
result: null,
|
|
52763
|
+
logs,
|
|
52764
|
+
error: error.message,
|
|
52765
|
+
executionTime: Date.now() - startTime
|
|
52766
|
+
};
|
|
52767
|
+
}
|
|
52768
|
+
},
|
|
52769
|
+
describeCall: (args) => `testing code (${args.code.length} chars)`
|
|
52770
|
+
};
|
|
52771
|
+
}
|
|
52772
|
+
var customToolTest = createCustomToolTest();
|
|
52773
|
+
|
|
52007
52774
|
// src/tools/registry.generated.ts
|
|
52008
52775
|
var toolRegistry = [
|
|
52009
52776
|
{
|
|
@@ -52015,6 +52782,60 @@ var toolRegistry = [
|
|
|
52015
52782
|
tool: executeJavaScript,
|
|
52016
52783
|
safeByDefault: false
|
|
52017
52784
|
},
|
|
52785
|
+
{
|
|
52786
|
+
name: "custom_tool_delete",
|
|
52787
|
+
exportName: "customToolDelete",
|
|
52788
|
+
displayName: "Custom Tool Delete",
|
|
52789
|
+
category: "custom-tools",
|
|
52790
|
+
description: "Delete a custom tool from persistent storage.",
|
|
52791
|
+
tool: customToolDelete,
|
|
52792
|
+
safeByDefault: false
|
|
52793
|
+
},
|
|
52794
|
+
{
|
|
52795
|
+
name: "custom_tool_draft",
|
|
52796
|
+
exportName: "customToolDraft",
|
|
52797
|
+
displayName: "Custom Tool Draft",
|
|
52798
|
+
category: "custom-tools",
|
|
52799
|
+
description: "Validate a draft custom tool definition. Checks name format, schema structure, and code syntax.",
|
|
52800
|
+
tool: customToolDraft,
|
|
52801
|
+
safeByDefault: true
|
|
52802
|
+
},
|
|
52803
|
+
{
|
|
52804
|
+
name: "custom_tool_list",
|
|
52805
|
+
exportName: "customToolList",
|
|
52806
|
+
displayName: "Custom Tool List",
|
|
52807
|
+
category: "custom-tools",
|
|
52808
|
+
description: "List saved custom tools from persistent storage. Supports filtering by search text, tags, and category.",
|
|
52809
|
+
tool: customToolList,
|
|
52810
|
+
safeByDefault: true
|
|
52811
|
+
},
|
|
52812
|
+
{
|
|
52813
|
+
name: "custom_tool_load",
|
|
52814
|
+
exportName: "customToolLoad",
|
|
52815
|
+
displayName: "Custom Tool Load",
|
|
52816
|
+
category: "custom-tools",
|
|
52817
|
+
description: "Load a full custom tool definition from storage (including code).",
|
|
52818
|
+
tool: customToolLoad,
|
|
52819
|
+
safeByDefault: true
|
|
52820
|
+
},
|
|
52821
|
+
{
|
|
52822
|
+
name: "custom_tool_save",
|
|
52823
|
+
exportName: "customToolSave",
|
|
52824
|
+
displayName: "Custom Tool Save",
|
|
52825
|
+
category: "custom-tools",
|
|
52826
|
+
description: "Save a custom tool definition to persistent storage.",
|
|
52827
|
+
tool: customToolSave,
|
|
52828
|
+
safeByDefault: false
|
|
52829
|
+
},
|
|
52830
|
+
{
|
|
52831
|
+
name: "custom_tool_test",
|
|
52832
|
+
exportName: "customToolTest",
|
|
52833
|
+
displayName: "Custom Tool Test",
|
|
52834
|
+
category: "custom-tools",
|
|
52835
|
+
description: "Test custom tool code by executing it in the VM sandbox with provided test input.",
|
|
52836
|
+
tool: customToolTest,
|
|
52837
|
+
safeByDefault: false
|
|
52838
|
+
},
|
|
52018
52839
|
{
|
|
52019
52840
|
name: "desktop_get_cursor",
|
|
52020
52841
|
exportName: "desktopGetCursor",
|
|
@@ -52215,6 +53036,61 @@ function getToolCategories() {
|
|
|
52215
53036
|
return [...new Set(toolRegistry.map((entry) => entry.category))];
|
|
52216
53037
|
}
|
|
52217
53038
|
|
|
53039
|
+
// src/tools/custom-tools/factories.ts
|
|
53040
|
+
function createCustomToolMetaTools(options) {
|
|
53041
|
+
const storage = options?.storage ?? new FileCustomToolStorage();
|
|
53042
|
+
return [
|
|
53043
|
+
createCustomToolDraft(),
|
|
53044
|
+
createCustomToolTest(),
|
|
53045
|
+
createCustomToolSave(storage),
|
|
53046
|
+
createCustomToolList(storage),
|
|
53047
|
+
createCustomToolLoad(storage),
|
|
53048
|
+
createCustomToolDelete(storage)
|
|
53049
|
+
];
|
|
53050
|
+
}
|
|
53051
|
+
|
|
53052
|
+
// src/tools/custom-tools/hydrate.ts
|
|
53053
|
+
init_Connector();
|
|
53054
|
+
var DEFAULT_TIMEOUT2 = 1e4;
|
|
53055
|
+
var MAX_TIMEOUT = 3e4;
|
|
53056
|
+
function hydrateCustomTool(definition, options) {
|
|
53057
|
+
const defaultTimeout = options?.defaultTimeout ?? DEFAULT_TIMEOUT2;
|
|
53058
|
+
const maxTimeout = options?.maxTimeout ?? MAX_TIMEOUT;
|
|
53059
|
+
return {
|
|
53060
|
+
definition: {
|
|
53061
|
+
type: "function",
|
|
53062
|
+
function: {
|
|
53063
|
+
name: definition.name,
|
|
53064
|
+
description: definition.description,
|
|
53065
|
+
parameters: definition.inputSchema
|
|
53066
|
+
},
|
|
53067
|
+
timeout: maxTimeout + 5e3
|
|
53068
|
+
},
|
|
53069
|
+
permission: { scope: "session", riskLevel: "medium" },
|
|
53070
|
+
execute: async (args, context) => {
|
|
53071
|
+
const logs = [];
|
|
53072
|
+
const registry = context?.connectorRegistry ?? Connector.asRegistry();
|
|
53073
|
+
const result = await executeInVM(
|
|
53074
|
+
definition.code,
|
|
53075
|
+
args,
|
|
53076
|
+
defaultTimeout,
|
|
53077
|
+
logs,
|
|
53078
|
+
context?.userId,
|
|
53079
|
+
registry
|
|
53080
|
+
);
|
|
53081
|
+
return result;
|
|
53082
|
+
},
|
|
53083
|
+
describeCall: (args) => {
|
|
53084
|
+
if (!args || typeof args !== "object") return definition.name;
|
|
53085
|
+
const firstKey = Object.keys(args)[0];
|
|
53086
|
+
if (!firstKey) return definition.name;
|
|
53087
|
+
const val = args[firstKey];
|
|
53088
|
+
const str = typeof val === "string" ? val : JSON.stringify(val);
|
|
53089
|
+
return str.length > 50 ? str.slice(0, 47) + "..." : str;
|
|
53090
|
+
}
|
|
53091
|
+
};
|
|
53092
|
+
}
|
|
53093
|
+
|
|
52218
53094
|
// src/tools/ToolRegistry.ts
|
|
52219
53095
|
init_Connector();
|
|
52220
53096
|
var ToolRegistry = class {
|
|
@@ -52551,6 +53427,6 @@ REMEMBER: Keep it conversational, ask one question at a time, and only output th
|
|
|
52551
53427
|
}
|
|
52552
53428
|
};
|
|
52553
53429
|
|
|
52554
|
-
export { AGENT_DEFINITION_FORMAT_VERSION, AIError, APPROVAL_STATE_VERSION, Agent, AgentContextNextGen, ApproximateTokenEstimator, BaseMediaProvider, BasePluginNextGen, BaseProvider, BaseTextProvider, BraveProvider, CONNECTOR_CONFIG_VERSION, CONTEXT_SESSION_FORMAT_VERSION, CheckpointManager, CircuitBreaker, CircuitOpenError, Connector, ConnectorConfigStore, ConnectorTools, ConsoleMetrics, ContentType, ContextOverflowError, DEFAULT_ALLOWLIST, DEFAULT_BACKOFF_CONFIG, DEFAULT_BASE_DELAY_MS, DEFAULT_CHECKPOINT_STRATEGY, DEFAULT_CIRCUIT_BREAKER_CONFIG, DEFAULT_CONFIG2 as DEFAULT_CONFIG, DEFAULT_CONNECTOR_TIMEOUT, DEFAULT_CONTEXT_CONFIG, DEFAULT_DESKTOP_CONFIG, DEFAULT_FEATURES, DEFAULT_FILESYSTEM_CONFIG, DEFAULT_HISTORY_MANAGER_CONFIG, DEFAULT_MAX_DELAY_MS, DEFAULT_MAX_RETRIES, DEFAULT_MEMORY_CONFIG, DEFAULT_PERMISSION_CONFIG, DEFAULT_RATE_LIMITER_CONFIG, DEFAULT_RETRYABLE_STATUSES, DEFAULT_SHELL_CONFIG, DESKTOP_TOOL_NAMES, DefaultCompactionStrategy, DependencyCycleError, DocumentReader, ErrorHandler, ExecutionContext, ExternalDependencyHandler, FileAgentDefinitionStorage, FileConnectorStorage, FileContextStorage, FileMediaStorage as FileMediaOutputHandler, FileMediaStorage, FilePersistentInstructionsStorage, FileStorage, FormatDetector, FrameworkLogger, HookManager, IMAGE_MODELS, IMAGE_MODEL_REGISTRY, ImageGeneration, InContextMemoryPluginNextGen, InMemoryAgentStateStorage, InMemoryHistoryStorage, InMemoryMetrics, InMemoryPlanStorage, InMemoryStorage, InvalidConfigError, InvalidToolArgumentsError, LLM_MODELS, LoggingPlugin, MCPClient, MCPConnectionError, MCPError, MCPProtocolError, MCPRegistry, MCPResourceError, MCPTimeoutError, MCPToolError, MEMORY_PRIORITY_VALUES, MODEL_REGISTRY, MemoryConnectorStorage, MemoryEvictionCompactor, MemoryStorage, MessageBuilder, MessageRole, ModelNotSupportedError, NoOpMetrics, NutTreeDriver, OAuthManager, ParallelTasksError, PersistentInstructionsPluginNextGen, PlanningAgent, ProviderAuthError, ProviderConfigAgent, ProviderContextLengthError, ProviderError, ProviderErrorMapper, ProviderNotFoundError, ProviderRateLimitError, RapidAPIProvider, RateLimitError, SERVICE_DEFINITIONS, SERVICE_INFO, SERVICE_URL_PATTERNS, SIMPLE_ICONS_CDN, STT_MODELS, STT_MODEL_REGISTRY, ScopedConnectorRegistry, ScrapeProvider, SearchProvider, SerperProvider, Services, SpeechToText, StrategyRegistry, StreamEventType, StreamHelpers, StreamState, SummarizeCompactor, TERMINAL_TASK_STATUSES, TTS_MODELS, TTS_MODEL_REGISTRY, TaskTimeoutError, TaskValidationError, TavilyProvider, TextToSpeech, TokenBucketRateLimiter, ToolCallState, ToolExecutionError, ToolExecutionPipeline, ToolManager, ToolNotFoundError, ToolPermissionManager, ToolRegistry, ToolTimeoutError, TruncateCompactor, VENDORS, VENDOR_ICON_MAP, VIDEO_MODELS, VIDEO_MODEL_REGISTRY, Vendor, VideoGeneration, WorkingMemory, WorkingMemoryPluginNextGen, addJitter, allVendorTemplates, assertNotDestroyed, authenticatedFetch, backoffSequence, backoffWait, bash, buildAuthConfig, buildEndpointWithQuery, buildQueryString, calculateBackoff, calculateCost, calculateEntrySize, calculateImageCost, calculateSTTCost, calculateTTSCost, calculateVideoCost, canTaskExecute, createAgentStorage, createAuthenticatedFetch, createBashTool, createConnectorFromTemplate, createCreatePRTool, createDesktopGetCursorTool, createDesktopGetScreenSizeTool, createDesktopKeyboardKeyTool, createDesktopKeyboardTypeTool, createDesktopMouseClickTool, createDesktopMouseDragTool, createDesktopMouseMoveTool, createDesktopMouseScrollTool, createDesktopScreenshotTool, createDesktopWindowFocusTool, createDesktopWindowListTool, createEditFileTool, createEstimator, createExecuteJavaScriptTool, createFileAgentDefinitionStorage, createFileContextStorage, createFileMediaStorage, createGetPRTool, createGitHubReadFileTool, createGlobTool, createGrepTool, createImageGenerationTool, createImageProvider, createListDirectoryTool, createMessageWithImages, createMetricsCollector, createPRCommentsTool, createPRFilesTool, createPlan, createProvider, createReadFileTool, createSearchCodeTool, createSearchFilesTool, createSpeechToTextTool, createTask, createTextMessage, createTextToSpeechTool, createVideoProvider, createVideoTools, createWriteFileTool, defaultDescribeCall, desktopGetCursor, desktopGetScreenSize, desktopKeyboardKey, desktopKeyboardType, desktopMouseClick, desktopMouseDrag, desktopMouseMove, desktopMouseScroll, desktopScreenshot, desktopTools, desktopWindowFocus, desktopWindowList, detectDependencyCycle, detectServiceFromURL, developerTools, documentToContent, editFile, evaluateCondition, extractJSON, extractJSONField, extractNumber, findConnectorByServiceTypes, forPlan, forTasks, generateEncryptionKey, generateSimplePlan, generateWebAPITool, getActiveImageModels, getActiveModels, getActiveSTTModels, getActiveTTSModels, getActiveVideoModels, getAllBuiltInTools, getAllServiceIds, getAllVendorLogos, getAllVendorTemplates, getBackgroundOutput, getConnectorTools, getCredentialsSetupURL, getDesktopDriver, getDocsURL, getImageModelInfo, getImageModelsByVendor, getImageModelsWithFeature, getMediaOutputHandler, getMediaStorage, getModelInfo, getModelsByVendor, getNextExecutableTasks, getRegisteredScrapeProviders, getSTTModelInfo, getSTTModelsByVendor, getSTTModelsWithFeature, getServiceDefinition, getServiceInfo, getServicesByCategory, getTTSModelInfo, getTTSModelsByVendor, getTTSModelsWithFeature, getTaskDependencies, getToolByName, getToolCallDescription, getToolCategories, getToolRegistry, getToolsByCategory, getToolsRequiringConnector, getVendorAuthTemplate, getVendorColor, getVendorDefaultBaseURL, getVendorInfo, getVendorLogo, getVendorLogoCdnUrl, getVendorLogoSvg, getVendorTemplate, getVideoModelInfo, getVideoModelsByVendor, getVideoModelsWithAudio, getVideoModelsWithFeature, glob, globalErrorHandler, grep, hasClipboardImage, hasVendorLogo, isBlockedCommand, isErrorEvent, isExcludedExtension, isKnownService, isOutputTextDelta, isResponseComplete, isSimpleScope, isStreamEvent, isTaskAwareScope, isTaskBlocked, isTerminalMemoryStatus, isTerminalStatus, isToolCallArgumentsDelta, isToolCallArgumentsDone, isToolCallStart, isVendor, killBackgroundProcess, listConnectorsByServiceTypes, listDirectory, listVendorIds, listVendors, listVendorsByAuthType, listVendorsByCategory, listVendorsWithLogos, logger, mergeTextPieces, metrics, parseKeyCombo, parseRepository, readClipboardImage, readDocumentAsContent, readFile5 as readFile, registerScrapeProvider, resetDefaultDriver, resolveConnector, resolveDependencies, resolveRepository, retryWithBackoff, scopeEquals, scopeMatches, setMediaOutputHandler, setMediaStorage, setMetricsCollector, simpleTokenEstimator, toConnectorOptions, toolRegistry, tools_exports as tools, updateTaskStatus, validatePath, writeFile5 as writeFile };
|
|
53430
|
+
export { AGENT_DEFINITION_FORMAT_VERSION, AIError, APPROVAL_STATE_VERSION, Agent, AgentContextNextGen, ApproximateTokenEstimator, BaseMediaProvider, BasePluginNextGen, BaseProvider, BaseTextProvider, BraveProvider, CONNECTOR_CONFIG_VERSION, CONTEXT_SESSION_FORMAT_VERSION, CUSTOM_TOOL_DEFINITION_VERSION, CheckpointManager, CircuitBreaker, CircuitOpenError, Connector, ConnectorConfigStore, ConnectorTools, ConsoleMetrics, ContentType, ContextOverflowError, DEFAULT_ALLOWLIST, DEFAULT_BACKOFF_CONFIG, DEFAULT_BASE_DELAY_MS, DEFAULT_CHECKPOINT_STRATEGY, DEFAULT_CIRCUIT_BREAKER_CONFIG, DEFAULT_CONFIG2 as DEFAULT_CONFIG, DEFAULT_CONNECTOR_TIMEOUT, DEFAULT_CONTEXT_CONFIG, DEFAULT_DESKTOP_CONFIG, DEFAULT_FEATURES, DEFAULT_FILESYSTEM_CONFIG, DEFAULT_HISTORY_MANAGER_CONFIG, DEFAULT_MAX_DELAY_MS, DEFAULT_MAX_RETRIES, DEFAULT_MEMORY_CONFIG, DEFAULT_PERMISSION_CONFIG, DEFAULT_RATE_LIMITER_CONFIG, DEFAULT_RETRYABLE_STATUSES, DEFAULT_SHELL_CONFIG, DESKTOP_TOOL_NAMES, DefaultCompactionStrategy, DependencyCycleError, DocumentReader, ErrorHandler, ExecutionContext, ExternalDependencyHandler, FileAgentDefinitionStorage, FileConnectorStorage, FileContextStorage, FileCustomToolStorage, FileMediaStorage as FileMediaOutputHandler, FileMediaStorage, FilePersistentInstructionsStorage, FileStorage, FormatDetector, FrameworkLogger, HookManager, IMAGE_MODELS, IMAGE_MODEL_REGISTRY, ImageGeneration, InContextMemoryPluginNextGen, InMemoryAgentStateStorage, InMemoryHistoryStorage, InMemoryMetrics, InMemoryPlanStorage, InMemoryStorage, InvalidConfigError, InvalidToolArgumentsError, LLM_MODELS, LoggingPlugin, MCPClient, MCPConnectionError, MCPError, MCPProtocolError, MCPRegistry, MCPResourceError, MCPTimeoutError, MCPToolError, MEMORY_PRIORITY_VALUES, MODEL_REGISTRY, MemoryConnectorStorage, MemoryEvictionCompactor, MemoryStorage, MessageBuilder, MessageRole, ModelNotSupportedError, NoOpMetrics, NutTreeDriver, OAuthManager, ParallelTasksError, PersistentInstructionsPluginNextGen, PlanningAgent, ProviderAuthError, ProviderConfigAgent, ProviderContextLengthError, ProviderError, ProviderErrorMapper, ProviderNotFoundError, ProviderRateLimitError, RapidAPIProvider, RateLimitError, SERVICE_DEFINITIONS, SERVICE_INFO, SERVICE_URL_PATTERNS, SIMPLE_ICONS_CDN, STT_MODELS, STT_MODEL_REGISTRY, ScopedConnectorRegistry, ScrapeProvider, SearchProvider, SerperProvider, Services, SpeechToText, StrategyRegistry, StreamEventType, StreamHelpers, StreamState, SummarizeCompactor, TERMINAL_TASK_STATUSES, TTS_MODELS, TTS_MODEL_REGISTRY, TaskTimeoutError, TaskValidationError, TavilyProvider, TextToSpeech, TokenBucketRateLimiter, ToolCallState, ToolExecutionError, ToolExecutionPipeline, ToolManager, ToolNotFoundError, ToolPermissionManager, ToolRegistry, ToolTimeoutError, TruncateCompactor, VENDORS, VENDOR_ICON_MAP, VIDEO_MODELS, VIDEO_MODEL_REGISTRY, Vendor, VideoGeneration, WorkingMemory, WorkingMemoryPluginNextGen, addJitter, allVendorTemplates, assertNotDestroyed, authenticatedFetch, backoffSequence, backoffWait, bash, buildAuthConfig, buildEndpointWithQuery, buildQueryString, calculateBackoff, calculateCost, calculateEntrySize, calculateImageCost, calculateSTTCost, calculateTTSCost, calculateVideoCost, canTaskExecute, createAgentStorage, createAuthenticatedFetch, createBashTool, createConnectorFromTemplate, createCreatePRTool, createCustomToolDelete, createCustomToolDraft, createCustomToolList, createCustomToolLoad, createCustomToolMetaTools, createCustomToolSave, createCustomToolTest, createDesktopGetCursorTool, createDesktopGetScreenSizeTool, createDesktopKeyboardKeyTool, createDesktopKeyboardTypeTool, createDesktopMouseClickTool, createDesktopMouseDragTool, createDesktopMouseMoveTool, createDesktopMouseScrollTool, createDesktopScreenshotTool, createDesktopWindowFocusTool, createDesktopWindowListTool, createEditFileTool, createEstimator, createExecuteJavaScriptTool, createFileAgentDefinitionStorage, createFileContextStorage, createFileCustomToolStorage, createFileMediaStorage, createGetPRTool, createGitHubReadFileTool, createGlobTool, createGrepTool, createImageGenerationTool, createImageProvider, createListDirectoryTool, createMessageWithImages, createMetricsCollector, createPRCommentsTool, createPRFilesTool, createPlan, createProvider, createReadFileTool, createSearchCodeTool, createSearchFilesTool, createSpeechToTextTool, createTask, createTextMessage, createTextToSpeechTool, createVideoProvider, createVideoTools, createWriteFileTool, customToolDelete, customToolDraft, customToolList, customToolLoad, customToolSave, customToolTest, defaultDescribeCall, desktopGetCursor, desktopGetScreenSize, desktopKeyboardKey, desktopKeyboardType, desktopMouseClick, desktopMouseDrag, desktopMouseMove, desktopMouseScroll, desktopScreenshot, desktopTools, desktopWindowFocus, desktopWindowList, detectDependencyCycle, detectServiceFromURL, developerTools, documentToContent, editFile, evaluateCondition, extractJSON, extractJSONField, extractNumber, findConnectorByServiceTypes, forPlan, forTasks, generateEncryptionKey, generateSimplePlan, generateWebAPITool, getActiveImageModels, getActiveModels, getActiveSTTModels, getActiveTTSModels, getActiveVideoModels, getAllBuiltInTools, getAllServiceIds, getAllVendorLogos, getAllVendorTemplates, getBackgroundOutput, getConnectorTools, getCredentialsSetupURL, getDesktopDriver, getDocsURL, getImageModelInfo, getImageModelsByVendor, getImageModelsWithFeature, getMediaOutputHandler, getMediaStorage, getModelInfo, getModelsByVendor, getNextExecutableTasks, getRegisteredScrapeProviders, getSTTModelInfo, getSTTModelsByVendor, getSTTModelsWithFeature, getServiceDefinition, getServiceInfo, getServicesByCategory, getTTSModelInfo, getTTSModelsByVendor, getTTSModelsWithFeature, getTaskDependencies, getToolByName, getToolCallDescription, getToolCategories, getToolRegistry, getToolsByCategory, getToolsRequiringConnector, getVendorAuthTemplate, getVendorColor, getVendorDefaultBaseURL, getVendorInfo, getVendorLogo, getVendorLogoCdnUrl, getVendorLogoSvg, getVendorTemplate, getVideoModelInfo, getVideoModelsByVendor, getVideoModelsWithAudio, getVideoModelsWithFeature, glob, globalErrorHandler, grep, hasClipboardImage, hasVendorLogo, hydrateCustomTool, isBlockedCommand, isErrorEvent, isExcludedExtension, isKnownService, isOutputTextDelta, isResponseComplete, isSimpleScope, isStreamEvent, isTaskAwareScope, isTaskBlocked, isTerminalMemoryStatus, isTerminalStatus, isToolCallArgumentsDelta, isToolCallArgumentsDone, isToolCallStart, isVendor, killBackgroundProcess, listConnectorsByServiceTypes, listDirectory, listVendorIds, listVendors, listVendorsByAuthType, listVendorsByCategory, listVendorsWithLogos, logger, mergeTextPieces, metrics, parseKeyCombo, parseRepository, readClipboardImage, readDocumentAsContent, readFile5 as readFile, registerScrapeProvider, resetDefaultDriver, resolveConnector, resolveDependencies, resolveRepository, retryWithBackoff, scopeEquals, scopeMatches, setMediaOutputHandler, setMediaStorage, setMetricsCollector, simpleTokenEstimator, toConnectorOptions, toolRegistry, tools_exports as tools, updateTaskStatus, validatePath, writeFile5 as writeFile };
|
|
52555
53431
|
//# sourceMappingURL=index.js.map
|
|
52556
53432
|
//# sourceMappingURL=index.js.map
|