@vinhnt-sdk/tools 0.4.1 → 0.4.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 +114 -80
- package/dist/context.d.ts +6 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @vinhnt-sdk/tools
|
|
2
2
|
|
|
3
|
-
> Version: 0.
|
|
3
|
+
> Version: 0.4.2 | Status: STABLE
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Tool framework and built-in tools for vinhnt-sdk — file, shell, git, web, search, middleware, and more.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -14,34 +14,39 @@ npm install @vinhnt-sdk/tools
|
|
|
14
14
|
pnpm add @vinhnt-sdk/tools
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **defineTool** — Define tools with Zod schemas, JSON Schema, risk levels, and annotations
|
|
20
|
+
- **ToolMiddleware** — Wrap tool execution with cross-cutting concerns (logging, auth, retry)
|
|
21
|
+
- **ToolHook** — Pre/post lifecycle hooks for tool calls
|
|
22
|
+
- **ToolRegistry** — Tool registration, lookup, and execution with filtering
|
|
23
|
+
- **LazyToolRegistry** — Lazy-load tools on first use
|
|
24
|
+
- **ToolProvider** — Plugin-based tool discovery
|
|
25
|
+
- **Built-in Tools** — File, shell, git, web search, glob, grep, image tools
|
|
26
|
+
- **ToolSaga** — Compensation actions for multi-step tool operations
|
|
27
|
+
|
|
17
28
|
## Quick Start
|
|
18
29
|
|
|
19
30
|
```typescript
|
|
20
|
-
import { defineTool, ToolRegistry } from
|
|
21
|
-
import
|
|
31
|
+
import { defineTool, ToolRegistry } from "@vinhnt-sdk/tools";
|
|
32
|
+
import { z } from "zod";
|
|
22
33
|
|
|
23
|
-
// Define a custom tool
|
|
24
34
|
const calculatorTool = defineTool({
|
|
25
35
|
name: "calculator",
|
|
26
36
|
description: "Evaluate math expressions",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
required: ["expression"],
|
|
33
|
-
},
|
|
37
|
+
risk: "read",
|
|
38
|
+
input: z.object({
|
|
39
|
+
expression: z.string().describe("Math expression"),
|
|
40
|
+
}),
|
|
34
41
|
async execute(args, context) {
|
|
35
42
|
const result = Function(`"use strict"; return (${args.expression})`)();
|
|
36
43
|
return { success: true, output: String(result) };
|
|
37
44
|
},
|
|
38
|
-
});
|
|
45
|
+
}).toDefinition();
|
|
39
46
|
|
|
40
|
-
// Register tool
|
|
41
47
|
const registry = new ToolRegistry();
|
|
42
48
|
registry.register(calculatorTool);
|
|
43
49
|
|
|
44
|
-
// Execute tool
|
|
45
50
|
const result = await registry.execute("calculator", { expression: "2 + 2" });
|
|
46
51
|
console.log(result.output); // "4"
|
|
47
52
|
```
|
|
@@ -51,31 +56,50 @@ console.log(result.output); // "4"
|
|
|
51
56
|
### Tool Definition
|
|
52
57
|
|
|
53
58
|
```typescript
|
|
54
|
-
import { defineTool } from
|
|
59
|
+
import { defineTool } from "@vinhnt-sdk/tools";
|
|
60
|
+
import { z } from "zod";
|
|
55
61
|
|
|
56
62
|
const myTool = defineTool({
|
|
57
63
|
name: "my-tool",
|
|
58
64
|
description: "My custom tool",
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
risk: "read", // "none" | "read" | "write" | "destructive" | "external"
|
|
66
|
+
input: z.object({
|
|
67
|
+
input: z.string().describe("Input parameter"),
|
|
68
|
+
}),
|
|
69
|
+
annotations: {
|
|
70
|
+
title: "My Tool",
|
|
71
|
+
readOnlyHint: true,
|
|
72
|
+
openWorldHint: false,
|
|
66
73
|
},
|
|
67
74
|
async execute(args, context) {
|
|
68
|
-
// args.input is the input parameter
|
|
69
|
-
// context contains sessionId, userId, etc.
|
|
70
75
|
return { success: true, output: `Processed: ${args.input}` };
|
|
71
76
|
},
|
|
72
|
-
});
|
|
77
|
+
}).toDefinition();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### ToolMiddleware
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import type { ToolMiddleware } from "@vinhnt-sdk/tools";
|
|
84
|
+
|
|
85
|
+
const loggingMiddleware: ToolMiddleware = {
|
|
86
|
+
id: "logging",
|
|
87
|
+
async execute(tool, input, next) {
|
|
88
|
+
console.log(`Tool ${tool.id} called with`, input);
|
|
89
|
+
const result = await next(input);
|
|
90
|
+
console.log(`Tool ${tool.id} returned`, result);
|
|
91
|
+
return result;
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Apply middleware via ToolRegistry
|
|
96
|
+
const registry = new ToolRegistry({ middleware: [loggingMiddleware] });
|
|
73
97
|
```
|
|
74
98
|
|
|
75
|
-
###
|
|
99
|
+
### ToolRegistry
|
|
76
100
|
|
|
77
101
|
```typescript
|
|
78
|
-
import { ToolRegistry } from
|
|
102
|
+
import { ToolRegistry } from "@vinhnt-sdk/tools";
|
|
79
103
|
|
|
80
104
|
const registry = new ToolRegistry();
|
|
81
105
|
|
|
@@ -98,80 +122,90 @@ const validation = registry.validate("calculator", { expression: "2 + 2" });
|
|
|
98
122
|
|
|
99
123
|
### Built-in Tools
|
|
100
124
|
|
|
101
|
-
| Tool | Description | Risk Level |
|
|
125
|
+
| Tool Factory | Description | Risk Level |
|
|
102
126
|
|------|-------------|------------|
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
127
|
+
| `createReadFileTool` | Read file contents | read |
|
|
128
|
+
| `createWriteFileTool` | Write to files | destructive |
|
|
129
|
+
| `createEditFileTool` | Edit files | destructive |
|
|
130
|
+
| `createApplyPatchTool` | Apply patches | destructive |
|
|
131
|
+
| `createListDirectoryTool` | List directory contents | read |
|
|
132
|
+
| `createShellTool` | Execute shell commands | external |
|
|
133
|
+
| `createGlobFilesTool` | Find files by pattern | read |
|
|
134
|
+
| `createGrepFilesTool` | Search file contents | read |
|
|
135
|
+
| `createWebSearchTool` | Search the web | external |
|
|
136
|
+
| `createWebFetchTool` | Fetch web pages | external |
|
|
137
|
+
| `createGitStatusTool` | Get git status | read |
|
|
138
|
+
| `createGitDiffTool` | Get git diff | read |
|
|
139
|
+
| `createGitLogTool` | Get git log | read |
|
|
140
|
+
| `createGitCommitTool` | Create git commits | write |
|
|
141
|
+
| `createReadImageTool` | Read image files | read |
|
|
142
|
+
| `createQuestionTool` | Ask user questions | read |
|
|
143
|
+
| `createTodoWriteTool` | Write todo items | write |
|
|
114
144
|
|
|
115
145
|
## Dependencies
|
|
116
146
|
|
|
117
|
-
- `@vinhnt-sdk/schema`
|
|
147
|
+
- `@vinhnt-sdk/schema` >=0.5.0
|
|
148
|
+
- `@vinhnt-sdk/guard` workspace:*
|
|
149
|
+
- `@vinhnt-sdk/sandbox` workspace:*
|
|
118
150
|
- `@vinhnt-sdk/security` workspace:*
|
|
119
151
|
- `zod` ^4.4.3
|
|
120
152
|
|
|
121
|
-
##
|
|
153
|
+
## Usage Examples
|
|
122
154
|
|
|
123
|
-
|
|
155
|
+
### Tool Middleware Pattern
|
|
124
156
|
|
|
125
|
-
|
|
157
|
+
```typescript
|
|
158
|
+
import type { ToolMiddleware, ToolDefinition, ToolExecutionResult } from "@vinhnt-sdk/tools";
|
|
159
|
+
|
|
160
|
+
const authMiddleware: ToolMiddleware = {
|
|
161
|
+
id: "auth",
|
|
162
|
+
async execute(tool, input, next) {
|
|
163
|
+
// Check permissions before execution
|
|
164
|
+
if (tool.risk === "destructive") {
|
|
165
|
+
const approved = await checkApproval(tool.id);
|
|
166
|
+
if (!approved) {
|
|
167
|
+
return { status: "denied", reason: "Not approved" };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return next(input);
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
```
|
|
126
174
|
|
|
127
|
-
###
|
|
175
|
+
### Tool Hooks
|
|
128
176
|
|
|
129
177
|
```typescript
|
|
130
|
-
import {
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
properties: {
|
|
138
|
-
location: { type: "string", description: "City name" },
|
|
139
|
-
},
|
|
140
|
-
required: ["location"],
|
|
178
|
+
import type { ToolHook } from "@vinhnt-sdk/tools";
|
|
179
|
+
|
|
180
|
+
const auditHook: ToolHook = {
|
|
181
|
+
id: "audit",
|
|
182
|
+
async pre({ toolId, tool, input }) {
|
|
183
|
+
await logAudit(toolId, "start", input);
|
|
184
|
+
return null; // Continue execution
|
|
141
185
|
},
|
|
142
|
-
async
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
success: true,
|
|
147
|
-
output: {
|
|
148
|
-
temperature: weather.temp,
|
|
149
|
-
condition: weather.condition,
|
|
150
|
-
},
|
|
151
|
-
};
|
|
186
|
+
async post({ toolId, tool, input, result }) {
|
|
187
|
+
await logAudit(toolId, "end", { input, result });
|
|
188
|
+
return null; // Don't modify result
|
|
152
189
|
},
|
|
153
|
-
}
|
|
190
|
+
};
|
|
154
191
|
```
|
|
155
192
|
|
|
156
|
-
###
|
|
193
|
+
### ToolSaga (Compensation)
|
|
157
194
|
|
|
158
195
|
```typescript
|
|
159
|
-
import {
|
|
160
|
-
import { defineTool } from '@vinhnt-sdk/tools';
|
|
196
|
+
import { ToolSaga } from "@vinhnt-sdk/tools";
|
|
161
197
|
|
|
162
|
-
const
|
|
163
|
-
model: yourModelProvider,
|
|
164
|
-
store: yourStore,
|
|
165
|
-
tools: [calculatorTool, weatherTool],
|
|
166
|
-
});
|
|
198
|
+
const saga = new ToolSaga();
|
|
167
199
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
200
|
+
// Register steps with compensation
|
|
201
|
+
saga.addStep({
|
|
202
|
+
tool: "create-file",
|
|
203
|
+
input: { path: "/tmp/file.txt", content: "hello" },
|
|
204
|
+
compensate: { tool: "delete-file", input: { path: "/tmp/file.txt" } },
|
|
172
205
|
});
|
|
173
206
|
|
|
174
|
-
|
|
207
|
+
// Execute all steps; compensate on failure
|
|
208
|
+
const result = await saga.execute(context);
|
|
175
209
|
```
|
|
176
210
|
|
|
177
211
|
## License
|
package/dist/context.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ export interface ToolContext {
|
|
|
16
16
|
readonly parentContext?: RequestContext;
|
|
17
17
|
/** Environment variables for subprocess execution (shell tool) */
|
|
18
18
|
readonly env: Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* The active workspace root for this run.
|
|
21
|
+
* Tools should resolve file paths relative to this directory.
|
|
22
|
+
* Falls back to AgentKernelConfig.workspaceRoot if not set per-run.
|
|
23
|
+
*/
|
|
24
|
+
readonly workspaceRoot?: string;
|
|
19
25
|
/**
|
|
20
26
|
* Request human approval for a permission-bound operation.
|
|
21
27
|
* Returns the user's decision: "once" (allow once), "always" (approve forever), or "reject".
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,Q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AAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC;IAExC,kEAAkE;IAClE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAErC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEhC;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE;QACT,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,sGAAsG;QACtG,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KAClC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAE7B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,IAAI,CAAC;IAET;;;;OAIG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEnD,qDAAqD;IACrD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,11 @@ export { defineTool, toolToDefinition, zodSchemaToNestedJsonSchema } from "./def
|
|
|
7
7
|
export { commandPattern, prefix } from "./arity.js";
|
|
8
8
|
export type { ToolDefinitionLike } from "@vinhnt-sdk/schema";
|
|
9
9
|
export type { ToolDefinition, ToolRisk, ToolAnnotations } from "./definitions.js";
|
|
10
|
+
export { KNOWN_TOOL_RISKS } from "./definitions.js";
|
|
10
11
|
export type { ToolFilter, ToolPermissionRule, ToolMaterialization } from "./registry.js";
|
|
11
12
|
export { ToolRegistry } from "./registry.js";
|
|
12
13
|
export type { ToolContext, PermissionReply } from "./context.js";
|
|
13
|
-
export type { ToolHook, ToolExecutionResult } from "./types.js";
|
|
14
|
+
export type { ToolHook, ToolExecutionResult, ToolMiddleware } from "./types.js";
|
|
14
15
|
export type { JsonSchema7Object, JsonSchemaProperty } from "./json-schema.js";
|
|
15
16
|
export { validateInput } from "./validate.js";
|
|
16
17
|
export { ToolInputError } from "./validate.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpD,YAAY,EAAE,kBAAkB,EAAE,MAA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B,CAAC;AAI/G,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,OAAO,EAAE,uBAAuB,IAAI,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAItF,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { defineTool, toolToDefinition, zodSchemaToNestedJsonSchema } from "./define-tool.js";
|
|
6
6
|
export { commandPattern, prefix } from "./arity.js";
|
|
7
|
+
export { KNOWN_TOOL_RISKS } from "./definitions.js";
|
|
7
8
|
export { ToolRegistry } from "./registry.js";
|
|
8
9
|
// === Validation ===
|
|
9
10
|
export { validateInput } from "./validate.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpD,OAAO,EAAE,gBAA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MAAM,mBAAmB,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,oBAAoB;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGvG,oBAAoB;AAEpB,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE/G,sBAAsB;AAEtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,sBAAsB;AAEtB,OAAO,EAAE,uBAAuB,IAAI,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEtF,2BAA2B;AAE3B,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -29,4 +29,26 @@ export interface ToolHook {
|
|
|
29
29
|
result: ToolExecutionResult;
|
|
30
30
|
}): Promise<ToolExecutionResult | null>;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Tool middleware — wraps tool execution with cross-cutting concerns.
|
|
34
|
+
*
|
|
35
|
+
* Inspired by Mastra's tool middleware pattern.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const loggingMiddleware: ToolMiddleware = {
|
|
40
|
+
* id: "logging",
|
|
41
|
+
* execute: async (tool, input, next) => {
|
|
42
|
+
* console.log(`Tool ${tool.id} called with`, input);
|
|
43
|
+
* const result = await next(input);
|
|
44
|
+
* console.log(`Tool ${tool.id} returned`, result);
|
|
45
|
+
* return result;
|
|
46
|
+
* },
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface ToolMiddleware {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
execute(tool: ToolDefinition, input: unknown, next: (input: unknown) => Promise<ToolExecutionResult>): Promise<ToolExecutionResult>;
|
|
53
|
+
}
|
|
32
54
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,kCAAkC;AAClC,MAAM,MAAM,mBAAmB,GAC3B;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACtC;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,gFAAgF;AAChF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GACnE,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,IAAI,CAAC,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,mBAAmB,CAAA;KAAE,GACjG,OAAO,CAAC,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,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vinhnt-sdk/tools",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Built-in tools for VNT Agent — file, shell, git, web, search, image, and more",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@vinhnt-sdk/schema": ">=0.5.0",
|
|
48
49
|
"zod": "^4.4.3",
|
|
49
|
-
"@vinhnt-sdk/guard": "0.4.
|
|
50
|
-
"@vinhnt-sdk/
|
|
51
|
-
"@vinhnt-sdk/
|
|
52
|
-
"@vinhnt-sdk/schema": "0.4.1"
|
|
50
|
+
"@vinhnt-sdk/guard": "0.4.2",
|
|
51
|
+
"@vinhnt-sdk/security": "0.4.2",
|
|
52
|
+
"@vinhnt-sdk/sandbox": "0.4.2"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsc -b",
|