@agentforge/tools 0.1.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/README.md ADDED
@@ -0,0 +1,457 @@
1
+ # @agentforge/tools
2
+
3
+ > Standard tools collection for AgentForge framework - 68 production-ready tools for web, data, file, and utility operations.
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @agentforge/tools
9
+ # or
10
+ pnpm add @agentforge/tools
11
+ # or
12
+ yarn add @agentforge/tools
13
+ ```
14
+
15
+ ## 🎯 Overview
16
+
17
+ This package provides a comprehensive collection of **68 ready-to-use tools** organized into four categories:
18
+
19
+ - **🌐 Web Tools** (10 tools) - HTTP requests, web scraping, HTML parsing, URL manipulation
20
+ - **📊 Data Tools** (18 tools) - JSON, CSV, XML processing and data transformation
21
+ - **📁 File Tools** (18 tools) - File operations, directory management, path utilities
22
+ - **🔧 Utility Tools** (22 tools) - Date/time, strings, math, validation
23
+
24
+ All tools are built using the AgentForge tool builder API with:
25
+ - ✅ Full TypeScript support
26
+ - ✅ Zod schema validation
27
+ - ✅ Comprehensive error handling
28
+ - ✅ Detailed documentation
29
+ - ✅ LangChain compatibility
30
+
31
+ ## 🚀 Quick Start
32
+
33
+ ```typescript
34
+ import { httpGet, jsonParser, fileReader, calculator } from '@agentforge/tools';
35
+
36
+ // Make an HTTP GET request
37
+ const response = await httpGet.execute({
38
+ url: 'https://api.example.com/data'
39
+ });
40
+
41
+ // Parse JSON
42
+ const parsed = await jsonParser.execute({
43
+ json: '{"name": "John", "age": 30}'
44
+ });
45
+
46
+ // Read a file
47
+ const file = await fileReader.execute({
48
+ path: './data.txt',
49
+ encoding: 'utf8'
50
+ });
51
+
52
+ // Perform calculations
53
+ const result = await calculator.execute({
54
+ operation: 'add',
55
+ a: 10,
56
+ b: 20
57
+ });
58
+ ```
59
+
60
+ ## 📚 Tool Categories
61
+
62
+ ### 🌐 Web Tools (10 tools)
63
+
64
+ Tools for web interactions and HTTP operations.
65
+
66
+ #### HTTP Client Tools
67
+ - **`httpClient`** - Full-featured HTTP client with all methods (GET, POST, PUT, DELETE, PATCH)
68
+ - **`httpGet`** - Simple GET requests
69
+ - **`httpPost`** - Simple POST requests with JSON body
70
+
71
+ #### Web Scraping Tools
72
+ - **`webScraper`** - Extract data from web pages using CSS selectors
73
+ - **`htmlParser`** - Parse HTML and extract elements
74
+ - **`extractLinks`** - Extract all links from HTML
75
+ - **`extractImages`** - Extract all images from HTML
76
+
77
+ #### URL Tools
78
+ - **`urlValidator`** - Validate and parse URLs
79
+ - **`urlBuilder`** - Build URLs from components
80
+ - **`urlQueryParser`** - Parse query parameters
81
+
82
+ ### 📊 Data Tools (18 tools)
83
+
84
+ Tools for data processing and transformation.
85
+
86
+ #### JSON Tools
87
+ - **`jsonParser`** - Parse JSON strings
88
+ - **`jsonStringify`** - Convert objects to JSON
89
+ - **`jsonQuery`** - Query JSON using dot notation
90
+ - **`jsonValidator`** - Validate JSON syntax
91
+ - **`jsonMerge`** - Merge multiple JSON objects
92
+
93
+ #### CSV Tools
94
+ - **`csvParser`** - Parse CSV to objects
95
+ - **`csvGenerator`** - Generate CSV from objects
96
+ - **`csvToJson`** - Convert CSV to JSON
97
+ - **`jsonToCsv`** - Convert JSON to CSV
98
+
99
+ #### XML Tools
100
+ - **`xmlParser`** - Parse XML to objects
101
+ - **`xmlGenerator`** - Generate XML from objects
102
+ - **`xmlToJson`** - Convert XML to JSON
103
+ - **`jsonToXml`** - Convert JSON to XML
104
+
105
+ #### Data Transformation Tools
106
+ - **`arrayFilter`** - Filter arrays by property values
107
+ - **`arrayMap`** - Extract properties from array objects
108
+ - **`arraySort`** - Sort arrays by property
109
+ - **`arrayGroupBy`** - Group arrays by property
110
+ - **`objectPick`** - Pick specific properties from objects
111
+ - **`objectOmit`** - Omit specific properties from objects
112
+
113
+ ### 📁 File Tools (18 tools)
114
+
115
+ Tools for file system operations.
116
+
117
+ #### File Operations
118
+ - **`fileReader`** - Read file contents
119
+ - **`fileWriter`** - Write content to files
120
+ - **`fileAppend`** - Append content to files
121
+ - **`fileDelete`** - Delete files
122
+ - **`fileExists`** - Check if file/directory exists
123
+
124
+ #### Directory Operations
125
+ - **`directoryList`** - List directory contents
126
+ - **`directoryCreate`** - Create directories
127
+ - **`directoryDelete`** - Delete directories
128
+ - **`fileSearch`** - Search for files by pattern
129
+
130
+ #### Path Utilities
131
+ - **`pathJoin`** - Join path segments
132
+ - **`pathResolve`** - Resolve absolute paths
133
+ - **`pathParse`** - Parse path components
134
+ - **`pathBasename`** - Get filename from path
135
+ - **`pathDirname`** - Get directory from path
136
+ - **`pathExtension`** - Get file extension
137
+ - **`pathRelative`** - Get relative path
138
+ - **`pathNormalize`** - Normalize paths
139
+
140
+ ### 🔧 Utility Tools (22 tools)
141
+
142
+ General utility tools for common operations.
143
+
144
+ #### Date/Time Tools
145
+ - **`currentDateTime`** - Get current date/time
146
+ - **`dateFormatter`** - Format dates
147
+ - **`dateArithmetic`** - Add/subtract time
148
+ - **`dateDifference`** - Calculate date differences
149
+ - **`dateComparison`** - Compare dates
150
+
151
+ #### String Tools
152
+ - **`stringCaseConverter`** - Convert string cases
153
+ - **`stringTrim`** - Trim whitespace
154
+ - **`stringReplace`** - Replace substrings
155
+ - **`stringSplit`** - Split strings
156
+ - **`stringJoin`** - Join string arrays
157
+ - **`stringSubstring`** - Extract substrings
158
+ - **`stringLength`** - Get string length/word count
159
+
160
+ #### Math Tools
161
+ - **`calculator`** - Basic arithmetic operations
162
+ - **`mathFunctions`** - Mathematical functions (sqrt, sin, cos, etc.)
163
+ - **`randomNumber`** - Generate random numbers
164
+ - **`statistics`** - Calculate statistics (avg, median, stddev)
165
+
166
+ #### Validation Tools
167
+ - **`emailValidator`** - Validate email addresses
168
+ - **`urlValidatorSimple`** - Validate URLs
169
+ - **`phoneValidator`** - Validate phone numbers
170
+ - **`creditCardValidator`** - Validate credit cards (Luhn algorithm)
171
+ - **`ipValidator`** - Validate IPv4/IPv6 addresses
172
+ - **`uuidValidator`** - Validate UUIDs
173
+
174
+ ## 💡 Usage Examples
175
+
176
+ ### Web Scraping Example
177
+
178
+ ```typescript
179
+ import { webScraper } from '@agentforge/tools';
180
+
181
+ const result = await webScraper.execute({
182
+ url: 'https://example.com',
183
+ selector: 'article h1',
184
+ extractText: true,
185
+ extractLinks: true,
186
+ extractMetadata: true
187
+ });
188
+
189
+ console.log(result.text);
190
+ console.log(result.links);
191
+ console.log(result.metadata);
192
+ ```
193
+
194
+ ### Data Processing Example
195
+
196
+ ```typescript
197
+ import { csvParser, arrayFilter, arraySort } from '@agentforge/tools';
198
+
199
+ // Parse CSV data
200
+ const parsed = await csvParser.execute({
201
+ csv: 'name,age,city\nJohn,30,NYC\nJane,25,LA',
202
+ hasHeaders: true
203
+ });
204
+
205
+ // Filter the data
206
+ const filtered = await arrayFilter.execute({
207
+ array: parsed.data,
208
+ property: 'age',
209
+ operator: 'greater-than',
210
+ value: 25
211
+ });
212
+
213
+ // Sort the results
214
+ const sorted = await arraySort.execute({
215
+ array: filtered.filtered,
216
+ property: 'age',
217
+ order: 'desc'
218
+ });
219
+
220
+ console.log(sorted.sorted);
221
+ ```
222
+
223
+ ### File Operations Example
224
+
225
+ ```typescript
226
+ import { fileReader, fileWriter, directoryList } from '@agentforge/tools';
227
+
228
+ // Read a file
229
+ const content = await fileReader.execute({
230
+ path: './data.json',
231
+ encoding: 'utf8'
232
+ });
233
+
234
+ // Process and write back
235
+ const processed = JSON.parse(content.content);
236
+ processed.updated = new Date().toISOString();
237
+
238
+ await fileWriter.execute({
239
+ path: './data-updated.json',
240
+ content: JSON.stringify(processed, null, 2),
241
+ createDirs: true
242
+ });
243
+
244
+ // List directory
245
+ const files = await directoryList.execute({
246
+ path: './',
247
+ recursive: false,
248
+ includeDetails: true
249
+ });
250
+
251
+ console.log(files.files);
252
+ ```
253
+
254
+ ### Date/Time Example
255
+
256
+ ```typescript
257
+ import { currentDateTime, dateArithmetic, dateDifference } from '@agentforge/tools';
258
+
259
+ // Get current date
260
+ const now = await currentDateTime.execute({
261
+ format: 'custom',
262
+ customFormat: 'yyyy-MM-dd HH:mm:ss'
263
+ });
264
+
265
+ // Add 7 days
266
+ const future = await dateArithmetic.execute({
267
+ date: now.iso,
268
+ operation: 'add',
269
+ amount: 7,
270
+ unit: 'days'
271
+ });
272
+
273
+ // Calculate difference
274
+ const diff = await dateDifference.execute({
275
+ startDate: now.iso,
276
+ endDate: future.result,
277
+ unit: 'hours'
278
+ });
279
+
280
+ console.log(`${diff.difference} hours until ${future.result}`);
281
+ ```
282
+
283
+ ### String Manipulation Example
284
+
285
+ ```typescript
286
+ import { stringCaseConverter, stringReplace, stringSplit } from '@agentforge/tools';
287
+
288
+ // Convert to different cases
289
+ const camel = await stringCaseConverter.execute({
290
+ text: 'hello world example',
291
+ targetCase: 'camel'
292
+ });
293
+ // Result: "helloWorldExample"
294
+
295
+ const kebab = await stringCaseConverter.execute({
296
+ text: 'HelloWorldExample',
297
+ targetCase: 'kebab'
298
+ });
299
+ // Result: "hello-world-example"
300
+
301
+ // Replace text
302
+ const replaced = await stringReplace.execute({
303
+ text: 'Hello World, Hello Universe',
304
+ search: 'Hello',
305
+ replace: 'Hi',
306
+ global: true
307
+ });
308
+ // Result: "Hi World, Hi Universe"
309
+
310
+ // Split string
311
+ const parts = await stringSplit.execute({
312
+ text: 'apple,banana,orange',
313
+ delimiter: ','
314
+ });
315
+ // Result: ["apple", "banana", "orange"]
316
+ ```
317
+
318
+ ### Validation Example
319
+
320
+ ```typescript
321
+ import { emailValidator, urlValidatorSimple, creditCardValidator } from '@agentforge/tools';
322
+
323
+ // Validate email
324
+ const email = await emailValidator.execute({
325
+ email: 'user@example.com'
326
+ });
327
+ console.log(email.valid); // true
328
+
329
+ // Validate URL
330
+ const url = await urlValidatorSimple.execute({
331
+ url: 'https://example.com/path'
332
+ });
333
+ console.log(url.valid); // true
334
+
335
+ // Validate credit card
336
+ const card = await creditCardValidator.execute({
337
+ cardNumber: '4532-1488-0343-6467'
338
+ });
339
+ console.log(card.valid); // true (passes Luhn check)
340
+ ```
341
+
342
+ ## 🔗 Using with LangChain
343
+
344
+ All tools are compatible with LangChain through the `@agentforge/core` integration:
345
+
346
+ ```typescript
347
+ import { httpGet, jsonParser } from '@agentforge/tools';
348
+ import { toLangChainTool } from '@agentforge/core';
349
+
350
+ // Convert to LangChain tools
351
+ const langchainHttpGet = toLangChainTool(httpGet);
352
+ const langchainJsonParser = toLangChainTool(jsonParser);
353
+
354
+ // Use with LangChain agents
355
+ const tools = [langchainHttpGet, langchainJsonParser];
356
+ ```
357
+
358
+ ## 📖 API Reference
359
+
360
+ ### Tool Structure
361
+
362
+ All tools follow the same structure:
363
+
364
+ ```typescript
365
+ interface Tool<TInput, TOutput> {
366
+ metadata: {
367
+ name: string;
368
+ description: string;
369
+ category: ToolCategory;
370
+ tags?: string[];
371
+ };
372
+ schema: ZodSchema<TInput>;
373
+ execute: (input: TInput) => Promise<TOutput>;
374
+ }
375
+ ```
376
+
377
+ ### Error Handling
378
+
379
+ Most tools return a result object with a `success` field:
380
+
381
+ ```typescript
382
+ const result = await someTool.execute({ ... });
383
+
384
+ if (result.success) {
385
+ console.log(result.data);
386
+ } else {
387
+ console.error(result.error);
388
+ }
389
+ ```
390
+
391
+ ### Type Safety
392
+
393
+ All tools are fully typed with TypeScript:
394
+
395
+ ```typescript
396
+ import { httpGet } from '@agentforge/tools';
397
+
398
+ // TypeScript knows the input type
399
+ const result = await httpGet.execute({
400
+ url: 'https://api.example.com',
401
+ headers: { 'Authorization': 'Bearer token' }
402
+ });
403
+
404
+ // TypeScript knows the output type
405
+ console.log(result.data);
406
+ ```
407
+
408
+ ## 🛠️ Development
409
+
410
+ ```bash
411
+ # Install dependencies
412
+ pnpm install
413
+
414
+ # Build the package
415
+ pnpm build
416
+
417
+ # Run tests
418
+ pnpm test
419
+
420
+ # Type check
421
+ pnpm typecheck
422
+
423
+ # Lint
424
+ pnpm lint
425
+ ```
426
+
427
+ ## 📊 Tool Statistics
428
+
429
+ - **Total Tools**: 68
430
+ - **Web Tools**: 10
431
+ - **Data Tools**: 18
432
+ - **File Tools**: 18
433
+ - **Utility Tools**: 22
434
+ - **Lines of Code**: ~2,500
435
+ - **Full TypeScript Support**: ✅
436
+ - **Zod Validation**: ✅
437
+ - **LangChain Compatible**: ✅
438
+
439
+ ## 🤝 Contributing
440
+
441
+ Contributions are welcome! Please see the main AgentForge repository for contribution guidelines.
442
+
443
+ ## 📄 License
444
+
445
+ MIT
446
+
447
+ ## 🔗 Links
448
+
449
+ - [AgentForge Documentation](https://github.com/agentforge/agentforge)
450
+ - [Tool Builder API](../core/docs/TOOL_BUILDER.md)
451
+ - [LangChain Integration](../core/docs/LANGCHAIN_INTEGRATION.md)
452
+
453
+ ---
454
+
455
+ **Built with ❤️ by the AgentForge Team**
456
+
457
+