@thenajs/tools 0.6.0 → 0.11.0
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/LICENSE +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parallel.tool.d.ts +21 -0
- package/dist/parallel.tool.d.ts.map +1 -0
- package/dist/parallel.tool.js +93 -0
- package/dist/parallel.tool.js.map +1 -0
- package/package.json +11 -3
- package/dist/shell.tool.d.ts +0 -6
- package/dist/shell.tool.d.ts.map +0 -1
- package/dist/shell.tool.js +0 -26
- package/dist/shell.tool.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 castroneto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ParallelTool } from "./parallel.tool.js";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ParallelTool } from "./parallel.tool.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ToolOutput, ToolType } from "@thenajs/core";
|
|
2
|
+
/**
|
|
3
|
+
* Executa várias tools do próprio agente numa única chamada ao modelo.
|
|
4
|
+
*
|
|
5
|
+
* O ganho é **round-trip**: ler três arquivos custa uma ida ao modelo em vez de
|
|
6
|
+
* três.
|
|
7
|
+
*
|
|
8
|
+
* Ela não recebe tool nenhuma — o `@tools()` entrega as irmãs **já embrulhadas**
|
|
9
|
+
* na cadeia de middleware. É isso que faz cada chamada interna continuar abrindo
|
|
10
|
+
* o próprio nó no report e passando pelos hooks, pela autorização, pelo
|
|
11
|
+
* orçamento e pela política de erro.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ParallelTool {
|
|
14
|
+
execute({ calls }: {
|
|
15
|
+
calls: {
|
|
16
|
+
tool: string;
|
|
17
|
+
args: Record<string, unknown>;
|
|
18
|
+
}[];
|
|
19
|
+
}, siblings: ToolType[]): Promise<ToolOutput>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=parallel.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.tool.d.ts","sourceRoot":"","sources":["../src/parallel.tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG1D;;;;;;;;;;GAUG;AACH,qBAoBa,YAAY;IACjB,OAAO,CACF,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,EAAE,CAAA;KAAE,EACvE,QAAQ,EAAE,QAAQ,EAAE,GAC5B,OAAO,CAAC,UAAU,CAAC;CA4CvB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Tool, input, toToolOutput, tools } from "@thenajs/core";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
/**
|
|
16
|
+
* Executa várias tools do próprio agente numa única chamada ao modelo.
|
|
17
|
+
*
|
|
18
|
+
* O ganho é **round-trip**: ler três arquivos custa uma ida ao modelo em vez de
|
|
19
|
+
* três.
|
|
20
|
+
*
|
|
21
|
+
* Ela não recebe tool nenhuma — o `@tools()` entrega as irmãs **já embrulhadas**
|
|
22
|
+
* na cadeia de middleware. É isso que faz cada chamada interna continuar abrindo
|
|
23
|
+
* o próprio nó no report e passando pelos hooks, pela autorização, pelo
|
|
24
|
+
* orçamento e pela política de erro.
|
|
25
|
+
*/
|
|
26
|
+
let ParallelTool = class ParallelTool {
|
|
27
|
+
async execute({ calls }, siblings) {
|
|
28
|
+
// Sem a si mesma: `parallel` dentro de `parallel` só aninharia lote em lote.
|
|
29
|
+
const available = siblings.filter((t) => t.name !== "parallel");
|
|
30
|
+
const results = await Promise.all(calls.map(async (call) => {
|
|
31
|
+
const target = available.find((t) => t.name === call.tool);
|
|
32
|
+
if (!target) {
|
|
33
|
+
const names = available.map((t) => t.name).join(", ");
|
|
34
|
+
return {
|
|
35
|
+
content: `unknown tool. Available: ${names}`,
|
|
36
|
+
isError: true,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
// O schema da irmã é obrigatório aqui: no caminho normal quem valida
|
|
41
|
+
// os argumentos é o provider, e o `buildToolStep` embrulha o `execute`
|
|
42
|
+
// sem validar. Sem este `parse`, a tool receberia lixo tipado errado.
|
|
43
|
+
const args = target.schema.parse(call.args);
|
|
44
|
+
return toToolOutput(await target.execute(args));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
// Falha de uma chamada não pode derrubar o lote: as irmãs já custaram
|
|
48
|
+
// trabalho, e o modelo consegue corrigir só a que errou.
|
|
49
|
+
return { content: err.message, isError: true };
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
return {
|
|
53
|
+
content: results
|
|
54
|
+
.map((r, i) => {
|
|
55
|
+
const status = r.isError ? "error" : "ok";
|
|
56
|
+
return `[${i + 1}] ${calls[i].tool} → ${status}\n${r.content}`;
|
|
57
|
+
})
|
|
58
|
+
.join("\n\n"),
|
|
59
|
+
// Erro só quando **tudo** falhou: um lote parcialmente bom não é um turno
|
|
60
|
+
// perdido, e marcá-lo como erro faria o `maxFails` do loop contar uma
|
|
61
|
+
// falha que não houve.
|
|
62
|
+
isError: results.every((r) => r.isError),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
__param(0, input()),
|
|
68
|
+
__param(1, tools()),
|
|
69
|
+
__metadata("design:type", Function),
|
|
70
|
+
__metadata("design:paramtypes", [Object, Array]),
|
|
71
|
+
__metadata("design:returntype", Promise)
|
|
72
|
+
], ParallelTool.prototype, "execute", null);
|
|
73
|
+
ParallelTool = __decorate([
|
|
74
|
+
Tool({
|
|
75
|
+
name: "parallel",
|
|
76
|
+
description: "Run several of the other available tools at once and return every result. " +
|
|
77
|
+
"Use it when you need two or more calls that do not depend on each other. " +
|
|
78
|
+
"If one call needs another's result, make them in separate turns.",
|
|
79
|
+
schema: z.object({
|
|
80
|
+
calls: z
|
|
81
|
+
.array(z.object({
|
|
82
|
+
tool: z.string().describe("the name of one of the other available tools"),
|
|
83
|
+
args: z
|
|
84
|
+
.record(z.string(), z.unknown())
|
|
85
|
+
.describe("that tool's arguments, in the shape it declares"),
|
|
86
|
+
}))
|
|
87
|
+
.min(2, "use this tool only for two or more calls")
|
|
88
|
+
.max(8),
|
|
89
|
+
}),
|
|
90
|
+
})
|
|
91
|
+
], ParallelTool);
|
|
92
|
+
export { ParallelTool };
|
|
93
|
+
//# sourceMappingURL=parallel.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.tool.js","sourceRoot":"","sources":["../src/parallel.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;GAUG;AAqBI,IAAM,YAAY,GAAlB,MAAM,YAAY;IACjB,AAAN,KAAK,CAAC,OAAO,CACF,EAAE,KAAK,EAAgE,EACvE,QAAoB;QAE7B,6EAA6E;QAC7E,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;QAEhE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAuB,EAAE;YAC5C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;YAE3D,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACtD,OAAO;oBACL,OAAO,EAAE,4BAA4B,KAAK,EAAE;oBAC5C,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;YAED,IAAI,CAAC;gBACH,qEAAqE;gBACrE,uEAAuE;gBACvE,sEAAsE;gBACtE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,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;gBACzE,IAAI,EAAE,CAAC;qBACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;qBAC/B,QAAQ,CAAC,iDAAiD,CAAC;aAC/D,CAAC,CACH;iBACA,GAAG,CAAC,CAAC,EAAE,0CAA0C,CAAC;iBAClD,GAAG,CAAC,CAAC,CAAC;SACV,CAAC;KACH,CAAC;GACW,YAAY,CAgDxB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thenajs/tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Tools prontas para agentes ThenaJS (ex.:
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"description": "Tools prontas para agentes ThenaJS (ex.: ParallelTool).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "castroneto",
|
|
7
7
|
"repository": {
|
|
@@ -22,8 +22,16 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20.19"
|
|
27
|
+
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@thenajs/core": "^0.
|
|
29
|
+
"@thenajs/core": "^0.11.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"zod": "^4.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
27
35
|
"zod": "^4.0.0"
|
|
28
36
|
}
|
|
29
37
|
}
|
package/dist/shell.tool.d.ts
DELETED
package/dist/shell.tool.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell.tool.d.ts","sourceRoot":"","sources":["../src/shell.tool.ts"],"names":[],"mappings":"AAOA,qBAKa,SAAS;IACd,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;CAI/C"}
|
package/dist/shell.tool.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { exec } from "node:child_process";
|
|
8
|
-
import { promisify } from "node:util";
|
|
9
|
-
import { Tool } from "@thenajs/core";
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
const run = promisify(exec);
|
|
12
|
-
let ShellTool = class ShellTool {
|
|
13
|
-
async execute({ command }) {
|
|
14
|
-
const { stdout, stderr } = await run(command);
|
|
15
|
-
return stdout || stderr;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
ShellTool = __decorate([
|
|
19
|
-
Tool({
|
|
20
|
-
name: "shell",
|
|
21
|
-
description: "Executa um comando shell e retorna a saída.",
|
|
22
|
-
schema: z.object({ command: z.string() }),
|
|
23
|
-
})
|
|
24
|
-
], ShellTool);
|
|
25
|
-
export { ShellTool };
|
|
26
|
-
//# sourceMappingURL=shell.tool.js.map
|
package/dist/shell.tool.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell.tool.js","sourceRoot":"","sources":["../src/shell.tool.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAOrB,IAAM,SAAS,GAAf,MAAM,SAAS;IACpB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAuB;QAC5C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,MAAM,IAAI,MAAM,CAAC;IAC1B,CAAC;CACF,CAAA;AALY,SAAS;IALrB,IAAI,CAAC;QACJ,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,6CAA6C;QAC1D,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;KAC1C,CAAC;GACW,SAAS,CAKrB"}
|