@agenticforge/tools 1.0.2 → 1.1.1

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.en.md ADDED
@@ -0,0 +1,53 @@
1
+ # @agenticforge/tools
2
+
3
+ [![npm](https://img.shields.io/npm/v/@agenticforge/tools)](https://www.npmjs.com/package/@agenticforge/tools)
4
+ [![license](https://img.shields.io/github/license/LittleBlacky/AgenticFORGE)](https://github.com/LittleBlacky/AgenticFORGE/blob/main/LICENSE)
5
+
6
+ Tool abstraction layer for AgenticFORGE — `Tool` base class, `ToolRegistry`, `ToolChain`, and async executor.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @agenticforge/tools
12
+ ```
13
+
14
+ ## Exports
15
+
16
+ | Name | Description |
17
+ |------|-------------|
18
+ | `Tool` | Tool base class — wraps parameter definitions and execution logic |
19
+ | `toolAction` | Tool action factory with Zod-based parameter validation |
20
+ | `ToolRegistry` | Registry for managing available tools |
21
+ | `ToolChain` | Tool chain — compose multiple tools in sequence or parallel |
22
+ | `AsyncToolExecutor` | Async tool executor with timeout and concurrency control |
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import {Tool, toolAction, ToolRegistry} from "@agenticforge/tools";
28
+ import {z} from "zod";
29
+
30
+ const searchTool = new Tool({
31
+ name: "search",
32
+ description: "Search the web for information",
33
+ parameters: [
34
+ {name: "query", type: "string", description: "Search query", required: true},
35
+ ],
36
+ action: toolAction(z.object({query: z.string()}), async ({query}) => {
37
+ return `Search results for: ${query}`;
38
+ }),
39
+ });
40
+
41
+ const registry = new ToolRegistry();
42
+ registry.register(searchTool);
43
+
44
+ const tool = registry.get("search");
45
+ const result = await tool.execute({query: "AgenticFORGE"});
46
+ console.log(result);
47
+ ```
48
+
49
+ ## Links
50
+
51
+ - [GitHub](https://github.com/LittleBlacky/AgenticFORGE/tree/main/packages/tools)
52
+ - [npm](https://www.npmjs.com/package/@agenticforge/tools)
53
+ - [Root README](https://github.com/LittleBlacky/AgenticFORGE)
@@ -1,341 +1 @@
1
- 'use strict';
2
-
3
- require('reflect-metadata');
4
- var zod = require('zod');
5
-
6
- var __defProp$3 = Object.defineProperty;
7
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- const TOOL_ACTIONS_META_KEY = /* @__PURE__ */ Symbol("tool:actions");
10
- function toolAction(key, description) {
11
- return function(target, propertyKey, _descriptor) {
12
- const existing = Reflect.getMetadata(TOOL_ACTIONS_META_KEY, target) ?? [];
13
- existing.push({ key, description, method: propertyKey });
14
- Reflect.defineMetadata(TOOL_ACTIONS_META_KEY, existing, target);
15
- };
16
- }
17
- class Tool {
18
- constructor(name, description, expandable = false) {
19
- __publicField$3(this, "name");
20
- __publicField$3(this, "description");
21
- __publicField$3(this, "expandable");
22
- this.name = name;
23
- this.description = description;
24
- this.expandable = expandable;
25
- }
26
- /**
27
- * Validate that required parameters are present and have basic types.
28
- * Returns true if valid.
29
- */
30
- validateParameters(parameters) {
31
- const params = this.getParameters();
32
- for (const p of params) {
33
- if (p.required && (parameters[p.name] === void 0 || parameters[p.name] === null)) {
34
- return false;
35
- }
36
- }
37
- return true;
38
- }
39
- /**
40
- * Validate and coerce parameters, returning a Result object.
41
- */
42
- validateAndNormalizeParameters(parameters) {
43
- const params = this.getParameters();
44
- const data = {};
45
- for (const p of params) {
46
- const val = parameters[p.name];
47
- if (val === void 0 || val === null) {
48
- if (p.required) {
49
- return { success: false, error: `Missing required parameter: ${p.name}` };
50
- }
51
- data[p.name] = p.default;
52
- } else {
53
- data[p.name] = val;
54
- }
55
- }
56
- for (const [key, val] of Object.entries(parameters)) {
57
- if (!(key in data)) data[key] = val;
58
- }
59
- return { success: true, data };
60
- }
61
- /**
62
- * Convert this Tool to an OpenAI function-calling schema.
63
- */
64
- toOpenAISchema() {
65
- const params = this.getParameters();
66
- const properties = {};
67
- const required = [];
68
- for (const p of params) {
69
- properties[p.name] = {
70
- type: mapType(p.type),
71
- description: p.description,
72
- ...p.default !== null && p.default !== void 0 ? { default: p.default } : {}
73
- };
74
- if (p.required) required.push(p.name);
75
- }
76
- return {
77
- type: "function",
78
- function: {
79
- name: this.name,
80
- description: this.description,
81
- parameters: {
82
- type: "object",
83
- properties,
84
- ...required.length > 0 ? { required } : {}
85
- }
86
- }
87
- };
88
- }
89
- /**
90
- * Return a formatted description of all available tool actions (for system prompt).
91
- */
92
- describe() {
93
- const params = this.getParameters();
94
- const paramStr = params.map(
95
- (p) => ` - ${p.name} (${p.type}${p.required ? ", required" : ""}): ${p.description}`
96
- ).join("\n");
97
- return `Tool: ${this.name}
98
- Description: ${this.description}
99
- Parameters:
100
- ${paramStr}`;
101
- }
102
- }
103
- function mapType(type) {
104
- const t = (type ?? "string").toLowerCase();
105
- if (["string", "number", "integer", "boolean", "array", "object"].includes(t)) {
106
- return t;
107
- }
108
- return "string";
109
- }
110
- function defineFunctionTool(options) {
111
- return options;
112
- }
113
-
114
- var __defProp$2 = Object.defineProperty;
115
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
116
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
117
- class ToolChain {
118
- constructor(name, description) {
119
- __publicField$2(this, "name");
120
- __publicField$2(this, "description");
121
- __publicField$2(this, "steps", []);
122
- this.name = name;
123
- this.description = description;
124
- }
125
- addStep(toolName, inputTemplate, outputKey) {
126
- this.steps.push({ toolName, inputTemplate, outputKey });
127
- return this;
128
- }
129
- getSteps() {
130
- return [...this.steps];
131
- }
132
- /**
133
- * Execute the chain against a registry.
134
- * @param registry ToolRegistry that holds the referenced tools.
135
- * @param input Initial `{input}` value.
136
- * @returns The value stored under the last step's outputKey.
137
- */
138
- async execute(registry, input) {
139
- const context = { input };
140
- for (const step of this.steps) {
141
- const resolvedInput = interpolate(step.inputTemplate, context);
142
- const result = await registry.execute(step.toolName, { input: resolvedInput });
143
- context[step.outputKey] = result;
144
- }
145
- const lastStep = this.steps[this.steps.length - 1];
146
- if (!lastStep) return input;
147
- return context[lastStep.outputKey] ?? input;
148
- }
149
- }
150
- class ToolChainManager {
151
- constructor(registry) {
152
- __publicField$2(this, "chains", /* @__PURE__ */ new Map());
153
- __publicField$2(this, "registry");
154
- this.registry = registry;
155
- }
156
- registerChain(chain) {
157
- this.chains.set(chain.name, chain);
158
- }
159
- getChain(name) {
160
- return this.chains.get(name);
161
- }
162
- listChains() {
163
- return Array.from(this.chains.keys());
164
- }
165
- async executeChain(chainName, input) {
166
- const chain = this.chains.get(chainName);
167
- if (!chain) throw new Error(`ToolChain not found: ${chainName}`);
168
- return chain.execute(this.registry, input);
169
- }
170
- }
171
- function interpolate(template, context) {
172
- return template.replace(/\{(\w+)\}/g, (_match, key) => {
173
- return context[key] ?? `{${key}}`;
174
- });
175
- }
176
-
177
- var __defProp$1 = Object.defineProperty;
178
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
179
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
180
- class ToolRegistry {
181
- constructor() {
182
- __publicField$1(this, "tools", /* @__PURE__ */ new Map());
183
- __publicField$1(this, "functions", /* @__PURE__ */ new Map());
184
- }
185
- // ---------------------------------------------------------------------------
186
- // Registration
187
- // ---------------------------------------------------------------------------
188
- registerTool(tool) {
189
- this.tools.set(tool.name, tool);
190
- }
191
- unregisterTool(name) {
192
- return this.tools.delete(name);
193
- }
194
- registerFunction(name, description, func, schema) {
195
- this.functions.set(name, {
196
- name,
197
- description,
198
- func,
199
- schema
200
- });
201
- }
202
- unregisterFunction(name) {
203
- return this.functions.delete(name);
204
- }
205
- // ---------------------------------------------------------------------------
206
- // Lookup
207
- // ---------------------------------------------------------------------------
208
- getTool(name) {
209
- return this.tools.get(name);
210
- }
211
- getFunction(name) {
212
- return this.functions.get(name);
213
- }
214
- getAllTools() {
215
- return Array.from(this.tools.values());
216
- }
217
- listTools() {
218
- return [
219
- ...Array.from(this.tools.keys()),
220
- ...Array.from(this.functions.keys())
221
- ];
222
- }
223
- hasTool(name) {
224
- return this.tools.has(name) || this.functions.has(name);
225
- }
226
- // ---------------------------------------------------------------------------
227
- // Execution
228
- // ---------------------------------------------------------------------------
229
- async execute(name, parameters) {
230
- const tool = this.tools.get(name);
231
- if (tool) {
232
- return await tool.run(parameters);
233
- }
234
- const fn = this.functions.get(name);
235
- if (fn) {
236
- return await fn.func(parameters);
237
- }
238
- throw new Error(`Tool not found: ${name}`);
239
- }
240
- // ---------------------------------------------------------------------------
241
- // Description (for system prompts)
242
- // ---------------------------------------------------------------------------
243
- getAvailableTools() {
244
- const lines = [];
245
- for (const tool of this.tools.values()) {
246
- lines.push(tool.describe());
247
- }
248
- for (const fn of this.functions.values()) {
249
- lines.push(`Tool: ${fn.name}
250
- Description: ${fn.description}`);
251
- }
252
- if (lines.length === 0) return "\u6682\u65E0\u53EF\u7528\u5DE5\u5177";
253
- return lines.join("\n\n");
254
- }
255
- getOpenAISchemas() {
256
- const schemas = [];
257
- for (const tool of this.tools.values()) {
258
- schemas.push(tool.toOpenAISchema());
259
- }
260
- for (const fn of this.functions.values()) {
261
- schemas.push({
262
- type: "function",
263
- function: {
264
- name: fn.name,
265
- description: fn.description,
266
- parameters: {
267
- type: "object",
268
- properties: {
269
- input: { type: "string", description: "\u8F93\u5165\u6587\u672C" }
270
- }
271
- }
272
- }
273
- });
274
- }
275
- return schemas;
276
- }
277
- }
278
-
279
- var __defProp = Object.defineProperty;
280
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
281
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
282
- class AsyncToolExecutor {
283
- constructor(registry, concurrency = 4) {
284
- __publicField(this, "registry");
285
- __publicField(this, "concurrency");
286
- this.registry = registry;
287
- this.concurrency = Math.max(1, concurrency);
288
- }
289
- /**
290
- * Execute a batch of tool calls with bounded concurrency.
291
- */
292
- async executeBatch(requests) {
293
- const results = [];
294
- let idx = 0;
295
- const worker = async () => {
296
- while (idx < requests.length) {
297
- const req = requests[idx++];
298
- results.push(await this.executeSingle(req));
299
- }
300
- };
301
- const workers = Array.from({ length: Math.min(this.concurrency, requests.length) }, worker);
302
- await Promise.all(workers);
303
- return results;
304
- }
305
- /**
306
- * Execute a single tool call.
307
- */
308
- async executeSingle(request) {
309
- const start = Date.now();
310
- try {
311
- const output = await this.registry.execute(request.toolName, request.parameters);
312
- return {
313
- id: request.id,
314
- toolName: request.toolName,
315
- output,
316
- durationMs: Date.now() - start
317
- };
318
- } catch (error) {
319
- return {
320
- id: request.id,
321
- toolName: request.toolName,
322
- output: "",
323
- error: error instanceof Error ? error.message : String(error),
324
- durationMs: Date.now() - start
325
- };
326
- }
327
- }
328
- }
329
-
330
- Object.defineProperty(exports, "z", {
331
- enumerable: true,
332
- get: function () { return zod.z; }
333
- });
334
- exports.AsyncToolExecutor = AsyncToolExecutor;
335
- exports.Tool = Tool;
336
- exports.ToolChain = ToolChain;
337
- exports.ToolChainManager = ToolChainManager;
338
- exports.ToolRegistry = ToolRegistry;
339
- exports.defineFunctionTool = defineFunctionTool;
340
- exports.toolAction = toolAction;
341
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";var t=require("zod");const e=Symbol("tool:actions");function n(t){const e=(t??"string").toLowerCase();return["string","number","integer","boolean","array","object"].includes(e)?e:"string"}function s(t,e){return t.replace(/\{(\w+)\}/g,(t,n)=>e[n]??`{${n}}`)}Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return t.z}}),exports.AsyncToolExecutor=class{registry;concurrency;constructor(t,e=4){this.registry=t,this.concurrency=Math.max(1,e)}async executeBatch(t){const e=[];let n=0;const s=Array.from({length:Math.min(this.concurrency,t.length)},async()=>{for(;n<t.length;){const s=t[n++];e.push(await this.executeSingle(s))}});return await Promise.all(s),e}async executeSingle(t){const e=Date.now();try{const n=await this.registry.execute(t.toolName,t.parameters);return{id:t.id,toolName:t.toolName,output:n,durationMs:Date.now()-e}}catch(n){return{id:t.id,toolName:t.toolName,output:"",error:n instanceof Error?n.message:String(n),durationMs:Date.now()-e}}}},exports.Tool=class{name;description;expandable;constructor(t,e,n=!1){this.name=t,this.description=e,this.expandable=n}validateParameters(t){const e=this.getParameters();for(const n of e)if(n.required&&(void 0===t[n.name]||null===t[n.name]))return!1;return!0}validateAndNormalizeParameters(t){const e=this.getParameters(),n={};for(const s of e){const e=t[s.name];if(null==e){if(s.required)return{success:!1,error:`Missing required parameter: ${s.name}`};n[s.name]=s.default}else n[s.name]=e}for(const[e,s]of Object.entries(t))e in n||(n[e]=s);return{success:!0,data:n}}toOpenAISchema(){const t=this.getParameters(),e={},s=[];for(const r of t)e[r.name]={type:n(r.type),description:r.description,...null!==r.default&&void 0!==r.default?{default:r.default}:{}},r.required&&s.push(r.name);return{type:"function",function:{name:this.name,description:this.description,parameters:{type:"object",properties:e,...s.length>0?{required:s}:{}}}}}describe(){const t=this.getParameters().map(t=>` - ${t.name} (${t.type}${t.required?", required":""}): ${t.description}`).join("\n");return`Tool: ${this.name}\nDescription: ${this.description}\nParameters:\n${t}`}},exports.ToolChain=class{name;description;steps=[];constructor(t,e){this.name=t,this.description=e}addStep(t,e,n){return this.steps.push({toolName:t,inputTemplate:e,outputKey:n}),this}getSteps(){return[...this.steps]}async execute(t,e){const n={input:e};for(const e of this.steps){const r=s(e.inputTemplate,n),o=await t.execute(e.toolName,{input:r});n[e.outputKey]=o}const r=this.steps[this.steps.length-1];return r?n[r.outputKey]??e:e}},exports.ToolChainManager=class{chains=new Map;registry;constructor(t){this.registry=t}registerChain(t){this.chains.set(t.name,t)}getChain(t){return this.chains.get(t)}listChains(){return Array.from(this.chains.keys())}async executeChain(t,e){const n=this.chains.get(t);if(!n)throw new Error(`ToolChain not found: ${t}`);return n.execute(this.registry,e)}},exports.ToolRegistry=class{tools=new Map;functions=new Map;registerTool(t){this.tools.set(t.name,t)}unregisterTool(t){return this.tools.delete(t)}registerFunction(t,e,n,s){this.functions.set(t,{name:t,description:e,func:n,schema:s})}unregisterFunction(t){return this.functions.delete(t)}getTool(t){return this.tools.get(t)}getFunction(t){return this.functions.get(t)}getAllTools(){return Array.from(this.tools.values())}listTools(){return[...Array.from(this.tools.keys()),...Array.from(this.functions.keys())]}hasTool(t){return this.tools.has(t)||this.functions.has(t)}async execute(t,e){const n=this.tools.get(t);if(n)return await n.run(e);const s=this.functions.get(t);if(s)return await s.func(e);throw new Error(`Tool not found: ${t}`)}getAvailableTools(){const t=[];for(const e of this.tools.values())t.push(e.describe());for(const e of this.functions.values())t.push(`Tool: ${e.name}\nDescription: ${e.description}`);return 0===t.length?"暂无可用工具":t.join("\n\n")}getOpenAISchemas(){const t=[];for(const e of this.tools.values())t.push(e.toOpenAISchema());for(const e of this.functions.values())t.push({type:"function",function:{name:e.name,description:e.description,parameters:{type:"object",properties:{input:{type:"string",description:"输入文本"}}}}});return t}},exports.defineFunctionTool=function(t){return t},exports.toolAction=function(t,n){return function(s,r,o){const i=Reflect.getMetadata(e,s)??[];i.push({key:t,description:n,method:r}),Reflect.defineMetadata(e,i,s)}};
package/dist/esm/index.js CHANGED
@@ -1,329 +1 @@
1
- import 'reflect-metadata';
2
- export { z } from 'zod';
3
-
4
- var __defProp$3 = Object.defineProperty;
5
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
7
- const TOOL_ACTIONS_META_KEY = /* @__PURE__ */ Symbol("tool:actions");
8
- function toolAction(key, description) {
9
- return function(target, propertyKey, _descriptor) {
10
- const existing = Reflect.getMetadata(TOOL_ACTIONS_META_KEY, target) ?? [];
11
- existing.push({ key, description, method: propertyKey });
12
- Reflect.defineMetadata(TOOL_ACTIONS_META_KEY, existing, target);
13
- };
14
- }
15
- class Tool {
16
- constructor(name, description, expandable = false) {
17
- __publicField$3(this, "name");
18
- __publicField$3(this, "description");
19
- __publicField$3(this, "expandable");
20
- this.name = name;
21
- this.description = description;
22
- this.expandable = expandable;
23
- }
24
- /**
25
- * Validate that required parameters are present and have basic types.
26
- * Returns true if valid.
27
- */
28
- validateParameters(parameters) {
29
- const params = this.getParameters();
30
- for (const p of params) {
31
- if (p.required && (parameters[p.name] === void 0 || parameters[p.name] === null)) {
32
- return false;
33
- }
34
- }
35
- return true;
36
- }
37
- /**
38
- * Validate and coerce parameters, returning a Result object.
39
- */
40
- validateAndNormalizeParameters(parameters) {
41
- const params = this.getParameters();
42
- const data = {};
43
- for (const p of params) {
44
- const val = parameters[p.name];
45
- if (val === void 0 || val === null) {
46
- if (p.required) {
47
- return { success: false, error: `Missing required parameter: ${p.name}` };
48
- }
49
- data[p.name] = p.default;
50
- } else {
51
- data[p.name] = val;
52
- }
53
- }
54
- for (const [key, val] of Object.entries(parameters)) {
55
- if (!(key in data)) data[key] = val;
56
- }
57
- return { success: true, data };
58
- }
59
- /**
60
- * Convert this Tool to an OpenAI function-calling schema.
61
- */
62
- toOpenAISchema() {
63
- const params = this.getParameters();
64
- const properties = {};
65
- const required = [];
66
- for (const p of params) {
67
- properties[p.name] = {
68
- type: mapType(p.type),
69
- description: p.description,
70
- ...p.default !== null && p.default !== void 0 ? { default: p.default } : {}
71
- };
72
- if (p.required) required.push(p.name);
73
- }
74
- return {
75
- type: "function",
76
- function: {
77
- name: this.name,
78
- description: this.description,
79
- parameters: {
80
- type: "object",
81
- properties,
82
- ...required.length > 0 ? { required } : {}
83
- }
84
- }
85
- };
86
- }
87
- /**
88
- * Return a formatted description of all available tool actions (for system prompt).
89
- */
90
- describe() {
91
- const params = this.getParameters();
92
- const paramStr = params.map(
93
- (p) => ` - ${p.name} (${p.type}${p.required ? ", required" : ""}): ${p.description}`
94
- ).join("\n");
95
- return `Tool: ${this.name}
96
- Description: ${this.description}
97
- Parameters:
98
- ${paramStr}`;
99
- }
100
- }
101
- function mapType(type) {
102
- const t = (type ?? "string").toLowerCase();
103
- if (["string", "number", "integer", "boolean", "array", "object"].includes(t)) {
104
- return t;
105
- }
106
- return "string";
107
- }
108
- function defineFunctionTool(options) {
109
- return options;
110
- }
111
-
112
- var __defProp$2 = Object.defineProperty;
113
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
114
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
115
- class ToolChain {
116
- constructor(name, description) {
117
- __publicField$2(this, "name");
118
- __publicField$2(this, "description");
119
- __publicField$2(this, "steps", []);
120
- this.name = name;
121
- this.description = description;
122
- }
123
- addStep(toolName, inputTemplate, outputKey) {
124
- this.steps.push({ toolName, inputTemplate, outputKey });
125
- return this;
126
- }
127
- getSteps() {
128
- return [...this.steps];
129
- }
130
- /**
131
- * Execute the chain against a registry.
132
- * @param registry ToolRegistry that holds the referenced tools.
133
- * @param input Initial `{input}` value.
134
- * @returns The value stored under the last step's outputKey.
135
- */
136
- async execute(registry, input) {
137
- const context = { input };
138
- for (const step of this.steps) {
139
- const resolvedInput = interpolate(step.inputTemplate, context);
140
- const result = await registry.execute(step.toolName, { input: resolvedInput });
141
- context[step.outputKey] = result;
142
- }
143
- const lastStep = this.steps[this.steps.length - 1];
144
- if (!lastStep) return input;
145
- return context[lastStep.outputKey] ?? input;
146
- }
147
- }
148
- class ToolChainManager {
149
- constructor(registry) {
150
- __publicField$2(this, "chains", /* @__PURE__ */ new Map());
151
- __publicField$2(this, "registry");
152
- this.registry = registry;
153
- }
154
- registerChain(chain) {
155
- this.chains.set(chain.name, chain);
156
- }
157
- getChain(name) {
158
- return this.chains.get(name);
159
- }
160
- listChains() {
161
- return Array.from(this.chains.keys());
162
- }
163
- async executeChain(chainName, input) {
164
- const chain = this.chains.get(chainName);
165
- if (!chain) throw new Error(`ToolChain not found: ${chainName}`);
166
- return chain.execute(this.registry, input);
167
- }
168
- }
169
- function interpolate(template, context) {
170
- return template.replace(/\{(\w+)\}/g, (_match, key) => {
171
- return context[key] ?? `{${key}}`;
172
- });
173
- }
174
-
175
- var __defProp$1 = Object.defineProperty;
176
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
177
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
178
- class ToolRegistry {
179
- constructor() {
180
- __publicField$1(this, "tools", /* @__PURE__ */ new Map());
181
- __publicField$1(this, "functions", /* @__PURE__ */ new Map());
182
- }
183
- // ---------------------------------------------------------------------------
184
- // Registration
185
- // ---------------------------------------------------------------------------
186
- registerTool(tool) {
187
- this.tools.set(tool.name, tool);
188
- }
189
- unregisterTool(name) {
190
- return this.tools.delete(name);
191
- }
192
- registerFunction(name, description, func, schema) {
193
- this.functions.set(name, {
194
- name,
195
- description,
196
- func,
197
- schema
198
- });
199
- }
200
- unregisterFunction(name) {
201
- return this.functions.delete(name);
202
- }
203
- // ---------------------------------------------------------------------------
204
- // Lookup
205
- // ---------------------------------------------------------------------------
206
- getTool(name) {
207
- return this.tools.get(name);
208
- }
209
- getFunction(name) {
210
- return this.functions.get(name);
211
- }
212
- getAllTools() {
213
- return Array.from(this.tools.values());
214
- }
215
- listTools() {
216
- return [
217
- ...Array.from(this.tools.keys()),
218
- ...Array.from(this.functions.keys())
219
- ];
220
- }
221
- hasTool(name) {
222
- return this.tools.has(name) || this.functions.has(name);
223
- }
224
- // ---------------------------------------------------------------------------
225
- // Execution
226
- // ---------------------------------------------------------------------------
227
- async execute(name, parameters) {
228
- const tool = this.tools.get(name);
229
- if (tool) {
230
- return await tool.run(parameters);
231
- }
232
- const fn = this.functions.get(name);
233
- if (fn) {
234
- return await fn.func(parameters);
235
- }
236
- throw new Error(`Tool not found: ${name}`);
237
- }
238
- // ---------------------------------------------------------------------------
239
- // Description (for system prompts)
240
- // ---------------------------------------------------------------------------
241
- getAvailableTools() {
242
- const lines = [];
243
- for (const tool of this.tools.values()) {
244
- lines.push(tool.describe());
245
- }
246
- for (const fn of this.functions.values()) {
247
- lines.push(`Tool: ${fn.name}
248
- Description: ${fn.description}`);
249
- }
250
- if (lines.length === 0) return "\u6682\u65E0\u53EF\u7528\u5DE5\u5177";
251
- return lines.join("\n\n");
252
- }
253
- getOpenAISchemas() {
254
- const schemas = [];
255
- for (const tool of this.tools.values()) {
256
- schemas.push(tool.toOpenAISchema());
257
- }
258
- for (const fn of this.functions.values()) {
259
- schemas.push({
260
- type: "function",
261
- function: {
262
- name: fn.name,
263
- description: fn.description,
264
- parameters: {
265
- type: "object",
266
- properties: {
267
- input: { type: "string", description: "\u8F93\u5165\u6587\u672C" }
268
- }
269
- }
270
- }
271
- });
272
- }
273
- return schemas;
274
- }
275
- }
276
-
277
- var __defProp = Object.defineProperty;
278
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
279
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
280
- class AsyncToolExecutor {
281
- constructor(registry, concurrency = 4) {
282
- __publicField(this, "registry");
283
- __publicField(this, "concurrency");
284
- this.registry = registry;
285
- this.concurrency = Math.max(1, concurrency);
286
- }
287
- /**
288
- * Execute a batch of tool calls with bounded concurrency.
289
- */
290
- async executeBatch(requests) {
291
- const results = [];
292
- let idx = 0;
293
- const worker = async () => {
294
- while (idx < requests.length) {
295
- const req = requests[idx++];
296
- results.push(await this.executeSingle(req));
297
- }
298
- };
299
- const workers = Array.from({ length: Math.min(this.concurrency, requests.length) }, worker);
300
- await Promise.all(workers);
301
- return results;
302
- }
303
- /**
304
- * Execute a single tool call.
305
- */
306
- async executeSingle(request) {
307
- const start = Date.now();
308
- try {
309
- const output = await this.registry.execute(request.toolName, request.parameters);
310
- return {
311
- id: request.id,
312
- toolName: request.toolName,
313
- output,
314
- durationMs: Date.now() - start
315
- };
316
- } catch (error) {
317
- return {
318
- id: request.id,
319
- toolName: request.toolName,
320
- output: "",
321
- error: error instanceof Error ? error.message : String(error),
322
- durationMs: Date.now() - start
323
- };
324
- }
325
- }
326
- }
327
-
328
- export { AsyncToolExecutor, Tool, ToolChain, ToolChainManager, ToolRegistry, defineFunctionTool, toolAction };
329
- //# sourceMappingURL=index.js.map
1
+ export{z}from"zod";const t=Symbol("tool:actions");function e(e,n){return function(s,r,o){const i=Reflect.getMetadata(t,s)??[];i.push({key:e,description:n,method:r}),Reflect.defineMetadata(t,i,s)}}class n{name;description;expandable;constructor(t,e,n=!1){this.name=t,this.description=e,this.expandable=n}validateParameters(t){const e=this.getParameters();for(const n of e)if(n.required&&(void 0===t[n.name]||null===t[n.name]))return!1;return!0}validateAndNormalizeParameters(t){const e=this.getParameters(),n={};for(const s of e){const e=t[s.name];if(null==e){if(s.required)return{success:!1,error:`Missing required parameter: ${s.name}`};n[s.name]=s.default}else n[s.name]=e}for(const[e,s]of Object.entries(t))e in n||(n[e]=s);return{success:!0,data:n}}toOpenAISchema(){const t=this.getParameters(),e={},n=[];for(const r of t)e[r.name]={type:s(r.type),description:r.description,...null!==r.default&&void 0!==r.default?{default:r.default}:{}},r.required&&n.push(r.name);return{type:"function",function:{name:this.name,description:this.description,parameters:{type:"object",properties:e,...n.length>0?{required:n}:{}}}}}describe(){const t=this.getParameters().map(t=>` - ${t.name} (${t.type}${t.required?", required":""}): ${t.description}`).join("\n");return`Tool: ${this.name}\nDescription: ${this.description}\nParameters:\n${t}`}}function s(t){const e=(t??"string").toLowerCase();return["string","number","integer","boolean","array","object"].includes(e)?e:"string"}function r(t){return t}class o{name;description;steps=[];constructor(t,e){this.name=t,this.description=e}addStep(t,e,n){return this.steps.push({toolName:t,inputTemplate:e,outputKey:n}),this}getSteps(){return[...this.steps]}async execute(t,e){const n={input:e};for(const e of this.steps){const s=a(e.inputTemplate,n),r=await t.execute(e.toolName,{input:s});n[e.outputKey]=r}const s=this.steps[this.steps.length-1];return s?n[s.outputKey]??e:e}}class i{chains=new Map;registry;constructor(t){this.registry=t}registerChain(t){this.chains.set(t.name,t)}getChain(t){return this.chains.get(t)}listChains(){return Array.from(this.chains.keys())}async executeChain(t,e){const n=this.chains.get(t);if(!n)throw new Error(`ToolChain not found: ${t}`);return n.execute(this.registry,e)}}function a(t,e){return t.replace(/\{(\w+)\}/g,(t,n)=>e[n]??`{${n}}`)}class c{tools=new Map;functions=new Map;registerTool(t){this.tools.set(t.name,t)}unregisterTool(t){return this.tools.delete(t)}registerFunction(t,e,n,s){this.functions.set(t,{name:t,description:e,func:n,schema:s})}unregisterFunction(t){return this.functions.delete(t)}getTool(t){return this.tools.get(t)}getFunction(t){return this.functions.get(t)}getAllTools(){return Array.from(this.tools.values())}listTools(){return[...Array.from(this.tools.keys()),...Array.from(this.functions.keys())]}hasTool(t){return this.tools.has(t)||this.functions.has(t)}async execute(t,e){const n=this.tools.get(t);if(n)return await n.run(e);const s=this.functions.get(t);if(s)return await s.func(e);throw new Error(`Tool not found: ${t}`)}getAvailableTools(){const t=[];for(const e of this.tools.values())t.push(e.describe());for(const e of this.functions.values())t.push(`Tool: ${e.name}\nDescription: ${e.description}`);return 0===t.length?"暂无可用工具":t.join("\n\n")}getOpenAISchemas(){const t=[];for(const e of this.tools.values())t.push(e.toOpenAISchema());for(const e of this.functions.values())t.push({type:"function",function:{name:e.name,description:e.description,parameters:{type:"object",properties:{input:{type:"string",description:"输入文本"}}}}});return t}}class u{registry;concurrency;constructor(t,e=4){this.registry=t,this.concurrency=Math.max(1,e)}async executeBatch(t){const e=[];let n=0;const s=Array.from({length:Math.min(this.concurrency,t.length)},async()=>{for(;n<t.length;){const s=t[n++];e.push(await this.executeSingle(s))}});return await Promise.all(s),e}async executeSingle(t){const e=Date.now();try{const n=await this.registry.execute(t.toolName,t.parameters);return{id:t.id,toolName:t.toolName,output:n,durationMs:Date.now()-e}}catch(n){return{id:t.id,toolName:t.toolName,output:"",error:n instanceof Error?n.message:String(n),durationMs:Date.now()-e}}}}export{u as AsyncToolExecutor,n as Tool,o as ToolChain,i as ToolChainManager,c as ToolRegistry,r as defineFunctionTool,e as toolAction};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticforge/tools",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Tooling core for AgenticFORGE",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/Tool.ts","../../src/ToolChain.ts","../../src/ToolRegistry.ts","../../src/AsyncToolExecutor.ts"],"sourcesContent":["import \"reflect-metadata\";\nimport {z, type ZodType} from \"zod\";\nimport type {ToolParameter} from \"./types\";\n\nexport type {ToolParameter};\n\n// ---------------------------------------------------------------------------\n// OpenAI function-calling schema\n// ---------------------------------------------------------------------------\n\nexport interface OpenAIFunctionSchema {\n type: \"function\";\n function: {\n name: string;\n description: string;\n parameters: Record<string, unknown>;\n };\n}\n\n// ---------------------------------------------------------------------------\n// toolAction decorator\n// ---------------------------------------------------------------------------\n\nconst TOOL_ACTIONS_META_KEY = Symbol(\"tool:actions\");\n\nexport interface ToolActionMeta {\n key: string;\n description: string;\n method: string;\n}\n\n/**\n * Decorator that registers a method as a named tool action.\n * Usage: @toolAction(\"action_key\", \"Description\")\n */\nexport function toolAction(key: string, description: string) {\n return function (\n target: object,\n propertyKey: string,\n _descriptor: PropertyDescriptor,\n ): void {\n const existing: ToolActionMeta[] =\n Reflect.getMetadata(TOOL_ACTIONS_META_KEY, target) ?? [];\n existing.push({key, description, method: propertyKey});\n Reflect.defineMetadata(TOOL_ACTIONS_META_KEY, existing, target);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Tool base class\n// ---------------------------------------------------------------------------\n\nexport abstract class Tool {\n readonly name: string;\n readonly description: string;\n readonly expandable: boolean;\n\n constructor(name: string, description: string, expandable = false) {\n this.name = name;\n this.description = description;\n this.expandable = expandable;\n }\n\n abstract run(parameters: Record<string, unknown>): Promise<string> | string;\n abstract getParameters(): ToolParameter[];\n\n /**\n * Validate that required parameters are present and have basic types.\n * Returns true if valid.\n */\n validateParameters(parameters: Record<string, unknown>): boolean {\n const params = this.getParameters();\n for (const p of params) {\n if (p.required && (parameters[p.name] === undefined || parameters[p.name] === null)) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Validate and coerce parameters, returning a Result object.\n */\n validateAndNormalizeParameters(\n parameters: Record<string, unknown>,\n ): {success: true; data: Record<string, unknown>} | {success: false; error: string} {\n const params = this.getParameters();\n const data: Record<string, unknown> = {};\n\n for (const p of params) {\n const val = parameters[p.name];\n if (val === undefined || val === null) {\n if (p.required) {\n return {success: false, error: `Missing required parameter: ${p.name}`};\n }\n data[p.name] = p.default;\n } else {\n data[p.name] = val;\n }\n }\n\n // pass through any extra parameters\n for (const [key, val] of Object.entries(parameters)) {\n if (!(key in data)) data[key] = val;\n }\n\n return {success: true, data};\n }\n\n /**\n * Convert this Tool to an OpenAI function-calling schema.\n */\n toOpenAISchema(): OpenAIFunctionSchema {\n const params = this.getParameters();\n const properties: Record<string, unknown> = {};\n const required: string[] = [];\n\n for (const p of params) {\n properties[p.name] = {\n type: mapType(p.type),\n description: p.description,\n ...(p.default !== null && p.default !== undefined\n ? {default: p.default}\n : {}),\n };\n if (p.required) required.push(p.name);\n }\n\n return {\n type: \"function\",\n function: {\n name: this.name,\n description: this.description,\n parameters: {\n type: \"object\",\n properties,\n ...(required.length > 0 ? {required} : {}),\n },\n },\n };\n }\n\n /**\n * Return a formatted description of all available tool actions (for system prompt).\n */\n describe(): string {\n const params = this.getParameters();\n const paramStr = params\n .map(\n (p) =>\n ` - ${p.name} (${p.type}${p.required ? \", required\" : \"\"}): ${p.description}`,\n )\n .join(\"\\n\");\n return `Tool: ${this.name}\\nDescription: ${this.description}\\nParameters:\\n${paramStr}`;\n }\n}\n\nfunction mapType(type: string): string {\n const t = (type ?? \"string\").toLowerCase();\n if ([\"string\", \"number\", \"integer\", \"boolean\", \"array\", \"object\"].includes(t)) {\n return t;\n }\n return \"string\";\n}\n\n// ---------------------------------------------------------------------------\n// FunctionTool — wraps a plain async/sync function\n// ---------------------------------------------------------------------------\n\nexport interface FunctionTool<TArgs = Record<string, unknown>> {\n name: string;\n description: string;\n func: (args: TArgs) => string | Promise<string>;\n schema?: ZodType<TArgs>;\n}\n\n/**\n * Convenience factory for creating type-safe function tools.\n *\n * ```ts\n * const myTool = defineFunctionTool({\n * name: \"myTool\",\n * description: \"...\",\n * schema: z.object({ input: z.string() }),\n * func: ({ input }) => input.toUpperCase(),\n * });\n * ```\n */\nexport function defineFunctionTool<TArgs extends Record<string, unknown>>(\n options: FunctionTool<TArgs>,\n): FunctionTool<TArgs> {\n return options;\n}\n\nexport {z};\n","import {ToolRegistry} from \"./ToolRegistry\";\n\n// ---------------------------------------------------------------------------\n// ToolChain step definition\n// ---------------------------------------------------------------------------\n\nexport interface ToolChainStep {\n /** Name of the tool/function to call */\n toolName: string;\n /** Input template string; use {variableName} to reference context variables */\n inputTemplate: string;\n /** Key under which the step output is stored in context */\n outputKey: string;\n}\n\n// ---------------------------------------------------------------------------\n// ToolChain\n// ---------------------------------------------------------------------------\n\n/**\n * A sequential chain of tool steps.\n * Each step can reference outputs of prior steps via `{key}` placeholders.\n *\n * ```ts\n * const chain = new ToolChain(\"my_chain\", \"Does X then Y\");\n * chain.addStep(\"search\", \"{input}\", \"search_result\");\n * chain.addStep(\"summarize\", \"{search_result}\", \"summary\");\n * ```\n */\nexport class ToolChain {\n readonly name: string;\n readonly description: string;\n private readonly steps: ToolChainStep[] = [];\n\n constructor(name: string, description: string) {\n this.name = name;\n this.description = description;\n }\n\n addStep(toolName: string, inputTemplate: string, outputKey: string): this {\n this.steps.push({toolName, inputTemplate, outputKey});\n return this;\n }\n\n getSteps(): ToolChainStep[] {\n return [...this.steps];\n }\n\n /**\n * Execute the chain against a registry.\n * @param registry ToolRegistry that holds the referenced tools.\n * @param input Initial `{input}` value.\n * @returns The value stored under the last step's outputKey.\n */\n async execute(registry: ToolRegistry, input: string): Promise<string> {\n const context: Record<string, string> = {input};\n\n for (const step of this.steps) {\n const resolvedInput = interpolate(step.inputTemplate, context);\n const result = await registry.execute(step.toolName, {input: resolvedInput});\n context[step.outputKey] = result;\n }\n\n const lastStep = this.steps[this.steps.length - 1];\n if (!lastStep) return input;\n return context[lastStep.outputKey] ?? input;\n }\n}\n\n// ---------------------------------------------------------------------------\n// ToolChainManager\n// ---------------------------------------------------------------------------\n\n/**\n * Manages multiple named ToolChains and executes them against a shared registry.\n */\nexport class ToolChainManager {\n private readonly chains = new Map<string, ToolChain>();\n private readonly registry: ToolRegistry;\n\n constructor(registry: ToolRegistry) {\n this.registry = registry;\n }\n\n registerChain(chain: ToolChain): void {\n this.chains.set(chain.name, chain);\n }\n\n getChain(name: string): ToolChain | undefined {\n return this.chains.get(name);\n }\n\n listChains(): string[] {\n return Array.from(this.chains.keys());\n }\n\n async executeChain(chainName: string, input: string): Promise<string> {\n const chain = this.chains.get(chainName);\n if (!chain) throw new Error(`ToolChain not found: ${chainName}`);\n return chain.execute(this.registry, input);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Replace `{key}` placeholders with values from context. */\nfunction interpolate(template: string, context: Record<string, string>): string {\n return template.replace(/\\{(\\w+)\\}/g, (_match, key: string) => {\n return context[key] ?? `{${key}}`;\n });\n}\n","import {Tool, type FunctionTool, type OpenAIFunctionSchema} from \"./Tool\";\n\n/**\n * Central registry that manages Tool instances and raw FunctionTools.\n * Supports registration, lookup, and execution.\n */\nexport class ToolRegistry {\n private readonly tools = new Map<string, Tool>();\n private readonly functions = new Map<string, FunctionTool<Record<string, unknown>>>();\n\n // ---------------------------------------------------------------------------\n // Registration\n // ---------------------------------------------------------------------------\n\n registerTool(tool: Tool): void {\n this.tools.set(tool.name, tool);\n }\n\n unregisterTool(name: string): boolean {\n return this.tools.delete(name);\n }\n\n registerFunction<TArgs extends Record<string, unknown>>(\n name: string,\n description: string,\n func: (args: TArgs) => string | Promise<string>,\n schema?: FunctionTool<TArgs>[\"schema\"],\n ): void {\n this.functions.set(name, {\n name,\n description,\n func: func as FunctionTool<Record<string, unknown>>[\"func\"],\n schema: schema as FunctionTool<Record<string, unknown>>[\"schema\"],\n });\n }\n\n unregisterFunction(name: string): boolean {\n return this.functions.delete(name);\n }\n\n // ---------------------------------------------------------------------------\n // Lookup\n // ---------------------------------------------------------------------------\n\n getTool(name: string): Tool | undefined {\n return this.tools.get(name);\n }\n\n getFunction(name: string): FunctionTool<Record<string, unknown>> | undefined {\n return this.functions.get(name);\n }\n\n getAllTools(): Tool[] {\n return Array.from(this.tools.values());\n }\n\n listTools(): string[] {\n return [\n ...Array.from(this.tools.keys()),\n ...Array.from(this.functions.keys()),\n ];\n }\n\n hasTool(name: string): boolean {\n return this.tools.has(name) || this.functions.has(name);\n }\n\n // ---------------------------------------------------------------------------\n // Execution\n // ---------------------------------------------------------------------------\n\n async execute(name: string, parameters: Record<string, unknown>): Promise<string> {\n const tool = this.tools.get(name);\n if (tool) {\n return await tool.run(parameters);\n }\n\n const fn = this.functions.get(name);\n if (fn) {\n return await fn.func(parameters);\n }\n\n throw new Error(`Tool not found: ${name}`);\n }\n\n // ---------------------------------------------------------------------------\n // Description (for system prompts)\n // ---------------------------------------------------------------------------\n\n getAvailableTools(): string {\n const lines: string[] = [];\n\n for (const tool of this.tools.values()) {\n lines.push(tool.describe());\n }\n\n for (const fn of this.functions.values()) {\n lines.push(`Tool: ${fn.name}\\nDescription: ${fn.description}`);\n }\n\n if (lines.length === 0) return \"暂无可用工具\";\n return lines.join(\"\\n\\n\");\n }\n\n getOpenAISchemas(): Array<OpenAIFunctionSchema | Record<string, unknown>> {\n const schemas: Array<OpenAIFunctionSchema | Record<string, unknown>> = [];\n\n for (const tool of this.tools.values()) {\n schemas.push(tool.toOpenAISchema());\n }\n\n for (const fn of this.functions.values()) {\n schemas.push({\n type: \"function\",\n function: {\n name: fn.name,\n description: fn.description,\n parameters: {\n type: \"object\",\n properties: {\n input: {type: \"string\", description: \"输入文本\"},\n },\n },\n },\n });\n }\n\n return schemas;\n }\n}\n","import {ToolRegistry} from \"./ToolRegistry\";\n\nexport interface ToolCallRequest {\n id: string;\n toolName: string;\n parameters: Record<string, unknown>;\n}\n\nexport interface ToolCallResult {\n id: string;\n toolName: string;\n output: string;\n error?: string;\n durationMs: number;\n}\n\n/**\n * Executes multiple tool calls concurrently and collects results.\n */\nexport class AsyncToolExecutor {\n private readonly registry: ToolRegistry;\n private readonly concurrency: number;\n\n constructor(registry: ToolRegistry, concurrency = 4) {\n this.registry = registry;\n this.concurrency = Math.max(1, concurrency);\n }\n\n /**\n * Execute a batch of tool calls with bounded concurrency.\n */\n async executeBatch(requests: ToolCallRequest[]): Promise<ToolCallResult[]> {\n const results: ToolCallResult[] = [];\n let idx = 0;\n\n const worker = async (): Promise<void> => {\n while (idx < requests.length) {\n const req = requests[idx++]!;\n results.push(await this.executeSingle(req));\n }\n };\n\n const workers = Array.from({length: Math.min(this.concurrency, requests.length)}, worker);\n await Promise.all(workers);\n return results;\n }\n\n /**\n * Execute a single tool call.\n */\n async executeSingle(request: ToolCallRequest): Promise<ToolCallResult> {\n const start = Date.now();\n try {\n const output = await this.registry.execute(request.toolName, request.parameters);\n return {\n id: request.id,\n toolName: request.toolName,\n output,\n durationMs: Date.now() - start,\n };\n } catch (error) {\n return {\n id: request.id,\n toolName: request.toolName,\n output: \"\",\n error: error instanceof Error ? error.message : String(error),\n durationMs: Date.now() - start,\n };\n }\n }\n}\n"],"names":["__publicField"],"mappings":";;;;;;;;AAuBA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AQ,QAAA;AAAA,QAClB,MAAA,EAAQ,EAAA;AAAA,QACR,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAAA,QAC5D,UAAA,EAAY,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC3B;AAAA,IACF;AAAA,EACF;AACF;;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/Tool.ts","../../src/ToolChain.ts","../../src/ToolRegistry.ts","../../src/AsyncToolExecutor.ts"],"sourcesContent":["import \"reflect-metadata\";\nimport {z, type ZodType} from \"zod\";\nimport type {ToolParameter} from \"./types\";\n\nexport type {ToolParameter};\n\n// ---------------------------------------------------------------------------\n// OpenAI function-calling schema\n// ---------------------------------------------------------------------------\n\nexport interface OpenAIFunctionSchema {\n type: \"function\";\n function: {\n name: string;\n description: string;\n parameters: Record<string, unknown>;\n };\n}\n\n// ---------------------------------------------------------------------------\n// toolAction decorator\n// ---------------------------------------------------------------------------\n\nconst TOOL_ACTIONS_META_KEY = Symbol(\"tool:actions\");\n\nexport interface ToolActionMeta {\n key: string;\n description: string;\n method: string;\n}\n\n/**\n * Decorator that registers a method as a named tool action.\n * Usage: @toolAction(\"action_key\", \"Description\")\n */\nexport function toolAction(key: string, description: string) {\n return function (\n target: object,\n propertyKey: string,\n _descriptor: PropertyDescriptor,\n ): void {\n const existing: ToolActionMeta[] =\n Reflect.getMetadata(TOOL_ACTIONS_META_KEY, target) ?? [];\n existing.push({key, description, method: propertyKey});\n Reflect.defineMetadata(TOOL_ACTIONS_META_KEY, existing, target);\n };\n}\n\n// ---------------------------------------------------------------------------\n// Tool base class\n// ---------------------------------------------------------------------------\n\nexport abstract class Tool {\n readonly name: string;\n readonly description: string;\n readonly expandable: boolean;\n\n constructor(name: string, description: string, expandable = false) {\n this.name = name;\n this.description = description;\n this.expandable = expandable;\n }\n\n abstract run(parameters: Record<string, unknown>): Promise<string> | string;\n abstract getParameters(): ToolParameter[];\n\n /**\n * Validate that required parameters are present and have basic types.\n * Returns true if valid.\n */\n validateParameters(parameters: Record<string, unknown>): boolean {\n const params = this.getParameters();\n for (const p of params) {\n if (p.required && (parameters[p.name] === undefined || parameters[p.name] === null)) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Validate and coerce parameters, returning a Result object.\n */\n validateAndNormalizeParameters(\n parameters: Record<string, unknown>,\n ): {success: true; data: Record<string, unknown>} | {success: false; error: string} {\n const params = this.getParameters();\n const data: Record<string, unknown> = {};\n\n for (const p of params) {\n const val = parameters[p.name];\n if (val === undefined || val === null) {\n if (p.required) {\n return {success: false, error: `Missing required parameter: ${p.name}`};\n }\n data[p.name] = p.default;\n } else {\n data[p.name] = val;\n }\n }\n\n // pass through any extra parameters\n for (const [key, val] of Object.entries(parameters)) {\n if (!(key in data)) data[key] = val;\n }\n\n return {success: true, data};\n }\n\n /**\n * Convert this Tool to an OpenAI function-calling schema.\n */\n toOpenAISchema(): OpenAIFunctionSchema {\n const params = this.getParameters();\n const properties: Record<string, unknown> = {};\n const required: string[] = [];\n\n for (const p of params) {\n properties[p.name] = {\n type: mapType(p.type),\n description: p.description,\n ...(p.default !== null && p.default !== undefined\n ? {default: p.default}\n : {}),\n };\n if (p.required) required.push(p.name);\n }\n\n return {\n type: \"function\",\n function: {\n name: this.name,\n description: this.description,\n parameters: {\n type: \"object\",\n properties,\n ...(required.length > 0 ? {required} : {}),\n },\n },\n };\n }\n\n /**\n * Return a formatted description of all available tool actions (for system prompt).\n */\n describe(): string {\n const params = this.getParameters();\n const paramStr = params\n .map(\n (p) =>\n ` - ${p.name} (${p.type}${p.required ? \", required\" : \"\"}): ${p.description}`,\n )\n .join(\"\\n\");\n return `Tool: ${this.name}\\nDescription: ${this.description}\\nParameters:\\n${paramStr}`;\n }\n}\n\nfunction mapType(type: string): string {\n const t = (type ?? \"string\").toLowerCase();\n if ([\"string\", \"number\", \"integer\", \"boolean\", \"array\", \"object\"].includes(t)) {\n return t;\n }\n return \"string\";\n}\n\n// ---------------------------------------------------------------------------\n// FunctionTool — wraps a plain async/sync function\n// ---------------------------------------------------------------------------\n\nexport interface FunctionTool<TArgs = Record<string, unknown>> {\n name: string;\n description: string;\n func: (args: TArgs) => string | Promise<string>;\n schema?: ZodType<TArgs>;\n}\n\n/**\n * Convenience factory for creating type-safe function tools.\n *\n * ```ts\n * const myTool = defineFunctionTool({\n * name: \"myTool\",\n * description: \"...\",\n * schema: z.object({ input: z.string() }),\n * func: ({ input }) => input.toUpperCase(),\n * });\n * ```\n */\nexport function defineFunctionTool<TArgs extends Record<string, unknown>>(\n options: FunctionTool<TArgs>,\n): FunctionTool<TArgs> {\n return options;\n}\n\nexport {z};\n","import {ToolRegistry} from \"./ToolRegistry\";\n\n// ---------------------------------------------------------------------------\n// ToolChain step definition\n// ---------------------------------------------------------------------------\n\nexport interface ToolChainStep {\n /** Name of the tool/function to call */\n toolName: string;\n /** Input template string; use {variableName} to reference context variables */\n inputTemplate: string;\n /** Key under which the step output is stored in context */\n outputKey: string;\n}\n\n// ---------------------------------------------------------------------------\n// ToolChain\n// ---------------------------------------------------------------------------\n\n/**\n * A sequential chain of tool steps.\n * Each step can reference outputs of prior steps via `{key}` placeholders.\n *\n * ```ts\n * const chain = new ToolChain(\"my_chain\", \"Does X then Y\");\n * chain.addStep(\"search\", \"{input}\", \"search_result\");\n * chain.addStep(\"summarize\", \"{search_result}\", \"summary\");\n * ```\n */\nexport class ToolChain {\n readonly name: string;\n readonly description: string;\n private readonly steps: ToolChainStep[] = [];\n\n constructor(name: string, description: string) {\n this.name = name;\n this.description = description;\n }\n\n addStep(toolName: string, inputTemplate: string, outputKey: string): this {\n this.steps.push({toolName, inputTemplate, outputKey});\n return this;\n }\n\n getSteps(): ToolChainStep[] {\n return [...this.steps];\n }\n\n /**\n * Execute the chain against a registry.\n * @param registry ToolRegistry that holds the referenced tools.\n * @param input Initial `{input}` value.\n * @returns The value stored under the last step's outputKey.\n */\n async execute(registry: ToolRegistry, input: string): Promise<string> {\n const context: Record<string, string> = {input};\n\n for (const step of this.steps) {\n const resolvedInput = interpolate(step.inputTemplate, context);\n const result = await registry.execute(step.toolName, {input: resolvedInput});\n context[step.outputKey] = result;\n }\n\n const lastStep = this.steps[this.steps.length - 1];\n if (!lastStep) return input;\n return context[lastStep.outputKey] ?? input;\n }\n}\n\n// ---------------------------------------------------------------------------\n// ToolChainManager\n// ---------------------------------------------------------------------------\n\n/**\n * Manages multiple named ToolChains and executes them against a shared registry.\n */\nexport class ToolChainManager {\n private readonly chains = new Map<string, ToolChain>();\n private readonly registry: ToolRegistry;\n\n constructor(registry: ToolRegistry) {\n this.registry = registry;\n }\n\n registerChain(chain: ToolChain): void {\n this.chains.set(chain.name, chain);\n }\n\n getChain(name: string): ToolChain | undefined {\n return this.chains.get(name);\n }\n\n listChains(): string[] {\n return Array.from(this.chains.keys());\n }\n\n async executeChain(chainName: string, input: string): Promise<string> {\n const chain = this.chains.get(chainName);\n if (!chain) throw new Error(`ToolChain not found: ${chainName}`);\n return chain.execute(this.registry, input);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Replace `{key}` placeholders with values from context. */\nfunction interpolate(template: string, context: Record<string, string>): string {\n return template.replace(/\\{(\\w+)\\}/g, (_match, key: string) => {\n return context[key] ?? `{${key}}`;\n });\n}\n","import {Tool, type FunctionTool, type OpenAIFunctionSchema} from \"./Tool\";\n\n/**\n * Central registry that manages Tool instances and raw FunctionTools.\n * Supports registration, lookup, and execution.\n */\nexport class ToolRegistry {\n private readonly tools = new Map<string, Tool>();\n private readonly functions = new Map<string, FunctionTool<Record<string, unknown>>>();\n\n // ---------------------------------------------------------------------------\n // Registration\n // ---------------------------------------------------------------------------\n\n registerTool(tool: Tool): void {\n this.tools.set(tool.name, tool);\n }\n\n unregisterTool(name: string): boolean {\n return this.tools.delete(name);\n }\n\n registerFunction<TArgs extends Record<string, unknown>>(\n name: string,\n description: string,\n func: (args: TArgs) => string | Promise<string>,\n schema?: FunctionTool<TArgs>[\"schema\"],\n ): void {\n this.functions.set(name, {\n name,\n description,\n func: func as FunctionTool<Record<string, unknown>>[\"func\"],\n schema: schema as FunctionTool<Record<string, unknown>>[\"schema\"],\n });\n }\n\n unregisterFunction(name: string): boolean {\n return this.functions.delete(name);\n }\n\n // ---------------------------------------------------------------------------\n // Lookup\n // ---------------------------------------------------------------------------\n\n getTool(name: string): Tool | undefined {\n return this.tools.get(name);\n }\n\n getFunction(name: string): FunctionTool<Record<string, unknown>> | undefined {\n return this.functions.get(name);\n }\n\n getAllTools(): Tool[] {\n return Array.from(this.tools.values());\n }\n\n listTools(): string[] {\n return [\n ...Array.from(this.tools.keys()),\n ...Array.from(this.functions.keys()),\n ];\n }\n\n hasTool(name: string): boolean {\n return this.tools.has(name) || this.functions.has(name);\n }\n\n // ---------------------------------------------------------------------------\n // Execution\n // ---------------------------------------------------------------------------\n\n async execute(name: string, parameters: Record<string, unknown>): Promise<string> {\n const tool = this.tools.get(name);\n if (tool) {\n return await tool.run(parameters);\n }\n\n const fn = this.functions.get(name);\n if (fn) {\n return await fn.func(parameters);\n }\n\n throw new Error(`Tool not found: ${name}`);\n }\n\n // ---------------------------------------------------------------------------\n // Description (for system prompts)\n // ---------------------------------------------------------------------------\n\n getAvailableTools(): string {\n const lines: string[] = [];\n\n for (const tool of this.tools.values()) {\n lines.push(tool.describe());\n }\n\n for (const fn of this.functions.values()) {\n lines.push(`Tool: ${fn.name}\\nDescription: ${fn.description}`);\n }\n\n if (lines.length === 0) return \"暂无可用工具\";\n return lines.join(\"\\n\\n\");\n }\n\n getOpenAISchemas(): Array<OpenAIFunctionSchema | Record<string, unknown>> {\n const schemas: Array<OpenAIFunctionSchema | Record<string, unknown>> = [];\n\n for (const tool of this.tools.values()) {\n schemas.push(tool.toOpenAISchema());\n }\n\n for (const fn of this.functions.values()) {\n schemas.push({\n type: \"function\",\n function: {\n name: fn.name,\n description: fn.description,\n parameters: {\n type: \"object\",\n properties: {\n input: {type: \"string\", description: \"输入文本\"},\n },\n },\n },\n });\n }\n\n return schemas;\n }\n}\n","import {ToolRegistry} from \"./ToolRegistry\";\n\nexport interface ToolCallRequest {\n id: string;\n toolName: string;\n parameters: Record<string, unknown>;\n}\n\nexport interface ToolCallResult {\n id: string;\n toolName: string;\n output: string;\n error?: string;\n durationMs: number;\n}\n\n/**\n * Executes multiple tool calls concurrently and collects results.\n */\nexport class AsyncToolExecutor {\n private readonly registry: ToolRegistry;\n private readonly concurrency: number;\n\n constructor(registry: ToolRegistry, concurrency = 4) {\n this.registry = registry;\n this.concurrency = Math.max(1, concurrency);\n }\n\n /**\n * Execute a batch of tool calls with bounded concurrency.\n */\n async executeBatch(requests: ToolCallRequest[]): Promise<ToolCallResult[]> {\n const results: ToolCallResult[] = [];\n let idx = 0;\n\n const worker = async (): Promise<void> => {\n while (idx < requests.length) {\n const req = requests[idx++]!;\n results.push(await this.executeSingle(req));\n }\n };\n\n const workers = Array.from({length: Math.min(this.concurrency, requests.length)}, worker);\n await Promise.all(workers);\n return results;\n }\n\n /**\n * Execute a single tool call.\n */\n async executeSingle(request: ToolCallRequest): Promise<ToolCallResult> {\n const start = Date.now();\n try {\n const output = await this.registry.execute(request.toolName, request.parameters);\n return {\n id: request.id,\n toolName: request.toolName,\n output,\n durationMs: Date.now() - start,\n };\n } catch (error) {\n return {\n id: request.id,\n toolName: request.toolName,\n output: \"\",\n error: error instanceof Error ? error.message : String(error),\n durationMs: Date.now() - start,\n };\n }\n }\n}\n"],"names":["__publicField"],"mappings":";;;;;;AAuBA,MAAM,qBAAA,0BAA+B,cAAc,CAAA;AAY5C,SAAS,UAAA,CAAW,KAAa,WAAA,EAAqB;AAC3D,EAAA,OAAO,SACL,MAAA,EACA,WAAA,EACA,WAAA,EACM;AACN,IAAA,MAAM,WACJ,OAAA,CAAQ,WAAA,CAAY,qBAAA,EAAuB,MAAM,KAAK,EAAC;AACzD,IAAA,QAAA,CAAS,KAAK,EA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