@agenticc/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +370 -0
- package/README.zh-CN.md +372 -0
- package/dist/audit/index.d.ts +9 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +9 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/logger.d.ts +211 -0
- package/dist/audit/logger.d.ts.map +1 -0
- package/dist/audit/logger.js +268 -0
- package/dist/audit/logger.js.map +1 -0
- package/dist/audit/query.d.ts +164 -0
- package/dist/audit/query.d.ts.map +1 -0
- package/dist/audit/query.js +250 -0
- package/dist/audit/query.js.map +1 -0
- package/dist/conversation/context-builder.d.ts +119 -0
- package/dist/conversation/context-builder.d.ts.map +1 -0
- package/dist/conversation/context-builder.js +252 -0
- package/dist/conversation/context-builder.js.map +1 -0
- package/dist/conversation/index.d.ts +10 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +10 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/message-store.d.ts +231 -0
- package/dist/conversation/message-store.d.ts.map +1 -0
- package/dist/conversation/message-store.js +404 -0
- package/dist/conversation/message-store.js.map +1 -0
- package/dist/conversation/session.d.ts +201 -0
- package/dist/conversation/session.d.ts.map +1 -0
- package/dist/conversation/session.js +285 -0
- package/dist/conversation/session.js.map +1 -0
- package/dist/core/agent.d.ts +277 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +674 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/agentic-loop.d.ts +98 -0
- package/dist/core/agentic-loop.d.ts.map +1 -0
- package/dist/core/agentic-loop.js +496 -0
- package/dist/core/agentic-loop.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/intent-parser.d.ts +101 -0
- package/dist/core/intent-parser.d.ts.map +1 -0
- package/dist/core/intent-parser.js +221 -0
- package/dist/core/intent-parser.js.map +1 -0
- package/dist/core/plan-generator.d.ts +133 -0
- package/dist/core/plan-generator.d.ts.map +1 -0
- package/dist/core/plan-generator.js +294 -0
- package/dist/core/plan-generator.js.map +1 -0
- package/dist/core/plugin-manager.d.ts +120 -0
- package/dist/core/plugin-manager.d.ts.map +1 -0
- package/dist/core/plugin-manager.js +369 -0
- package/dist/core/plugin-manager.js.map +1 -0
- package/dist/core/response-handler.d.ts +141 -0
- package/dist/core/response-handler.d.ts.map +1 -0
- package/dist/core/response-handler.js +384 -0
- package/dist/core/response-handler.js.map +1 -0
- package/dist/core/tool-executor.d.ts +143 -0
- package/dist/core/tool-executor.d.ts.map +1 -0
- package/dist/core/tool-executor.js +354 -0
- package/dist/core/tool-executor.js.map +1 -0
- package/dist/core/tool-registry.d.ts +133 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +252 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/chunker.d.ts +78 -0
- package/dist/knowledge/chunker.d.ts.map +1 -0
- package/dist/knowledge/chunker.js +233 -0
- package/dist/knowledge/chunker.js.map +1 -0
- package/dist/knowledge/embedder.d.ts +93 -0
- package/dist/knowledge/embedder.d.ts.map +1 -0
- package/dist/knowledge/embedder.js +205 -0
- package/dist/knowledge/embedder.js.map +1 -0
- package/dist/knowledge/index.d.ts +10 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +11 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/loaders/index.d.ts +10 -0
- package/dist/knowledge/loaders/index.d.ts.map +1 -0
- package/dist/knowledge/loaders/index.js +10 -0
- package/dist/knowledge/loaders/index.js.map +1 -0
- package/dist/knowledge/loaders/markdown.d.ts +88 -0
- package/dist/knowledge/loaders/markdown.d.ts.map +1 -0
- package/dist/knowledge/loaders/markdown.js +205 -0
- package/dist/knowledge/loaders/markdown.js.map +1 -0
- package/dist/knowledge/loaders/yaml.d.ts +112 -0
- package/dist/knowledge/loaders/yaml.d.ts.map +1 -0
- package/dist/knowledge/loaders/yaml.js +368 -0
- package/dist/knowledge/loaders/yaml.js.map +1 -0
- package/dist/knowledge/retriever.d.ts +144 -0
- package/dist/knowledge/retriever.d.ts.map +1 -0
- package/dist/knowledge/retriever.js +399 -0
- package/dist/knowledge/retriever.js.map +1 -0
- package/dist/knowledge/store.d.ts +146 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +420 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/llm/adapter.d.ts +194 -0
- package/dist/llm/adapter.d.ts.map +1 -0
- package/dist/llm/adapter.js +42 -0
- package/dist/llm/adapter.js.map +1 -0
- package/dist/llm/adapters/anyrouter.d.ts +84 -0
- package/dist/llm/adapters/anyrouter.d.ts.map +1 -0
- package/dist/llm/adapters/anyrouter.js +372 -0
- package/dist/llm/adapters/anyrouter.js.map +1 -0
- package/dist/llm/adapters/claude.d.ts +66 -0
- package/dist/llm/adapters/claude.d.ts.map +1 -0
- package/dist/llm/adapters/claude.js +323 -0
- package/dist/llm/adapters/claude.js.map +1 -0
- package/dist/llm/adapters/index.d.ts +12 -0
- package/dist/llm/adapters/index.d.ts.map +1 -0
- package/dist/llm/adapters/index.js +12 -0
- package/dist/llm/adapters/index.js.map +1 -0
- package/dist/llm/adapters/mimo.d.ts +85 -0
- package/dist/llm/adapters/mimo.d.ts.map +1 -0
- package/dist/llm/adapters/mimo.js +316 -0
- package/dist/llm/adapters/mimo.js.map +1 -0
- package/dist/llm/adapters/openai.d.ts +53 -0
- package/dist/llm/adapters/openai.d.ts.map +1 -0
- package/dist/llm/adapters/openai.js +293 -0
- package/dist/llm/adapters/openai.js.map +1 -0
- package/dist/llm/adapters/qwen.d.ts +53 -0
- package/dist/llm/adapters/qwen.d.ts.map +1 -0
- package/dist/llm/adapters/qwen.js +299 -0
- package/dist/llm/adapters/qwen.js.map +1 -0
- package/dist/llm/adapters/siliconflow.d.ts +69 -0
- package/dist/llm/adapters/siliconflow.d.ts.map +1 -0
- package/dist/llm/adapters/siliconflow.js +331 -0
- package/dist/llm/adapters/siliconflow.js.map +1 -0
- package/dist/llm/index.d.ts +9 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +12 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/manager.d.ts +97 -0
- package/dist/llm/manager.d.ts.map +1 -0
- package/dist/llm/manager.js +337 -0
- package/dist/llm/manager.js.map +1 -0
- package/dist/test-utils/arbitraries.d.ts +230 -0
- package/dist/test-utils/arbitraries.d.ts.map +1 -0
- package/dist/test-utils/arbitraries.js +280 -0
- package/dist/test-utils/arbitraries.js.map +1 -0
- package/dist/test-utils/cleanup.d.ts +184 -0
- package/dist/test-utils/cleanup.d.ts.map +1 -0
- package/dist/test-utils/cleanup.js +282 -0
- package/dist/test-utils/cleanup.js.map +1 -0
- package/dist/test-utils/config.d.ts +80 -0
- package/dist/test-utils/config.d.ts.map +1 -0
- package/dist/test-utils/config.js +94 -0
- package/dist/test-utils/config.js.map +1 -0
- package/dist/test-utils/index.d.ts +10 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +36 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/test-utils/mocks.d.ts +170 -0
- package/dist/test-utils/mocks.d.ts.map +1 -0
- package/dist/test-utils/mocks.js +281 -0
- package/dist/test-utils/mocks.js.map +1 -0
- package/dist/types/config.d.ts +170 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +120 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/knowledge.d.ts +95 -0
- package/dist/types/knowledge.d.ts.map +1 -0
- package/dist/types/knowledge.js +7 -0
- package/dist/types/knowledge.js.map +1 -0
- package/dist/types/loop.d.ts +148 -0
- package/dist/types/loop.d.ts.map +1 -0
- package/dist/types/loop.js +16 -0
- package/dist/types/loop.js.map +1 -0
- package/dist/types/plugin.d.ts +137 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +15 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/response.d.ts +186 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +99 -0
- package/dist/types/response.js.map +1 -0
- package/dist/types/streaming.d.ts +478 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +483 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/tool.d.ts +118 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +42 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/error.d.ts +22 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +36 -0
- package/dist/utils/error.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Executor
|
|
3
|
+
*
|
|
4
|
+
* Handles the execution of tools with parameter validation,
|
|
5
|
+
* context injection, and error handling.
|
|
6
|
+
*
|
|
7
|
+
* @module core/tool-executor
|
|
8
|
+
*/
|
|
9
|
+
import { ToolNotFoundError } from './tool-registry.js';
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when tool parameter validation fails
|
|
12
|
+
*/
|
|
13
|
+
export class ToolValidationError extends Error {
|
|
14
|
+
toolName;
|
|
15
|
+
parameterName;
|
|
16
|
+
reason;
|
|
17
|
+
constructor(message, toolName, parameterName, reason) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.toolName = toolName;
|
|
20
|
+
this.parameterName = parameterName;
|
|
21
|
+
this.reason = reason;
|
|
22
|
+
this.name = 'ToolValidationError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when tool execution fails
|
|
27
|
+
*/
|
|
28
|
+
export class ToolExecutionError extends Error {
|
|
29
|
+
toolName;
|
|
30
|
+
cause;
|
|
31
|
+
constructor(message, toolName, cause) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.toolName = toolName;
|
|
34
|
+
this.cause = cause;
|
|
35
|
+
this.name = 'ToolExecutionError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when tool execution times out
|
|
40
|
+
*/
|
|
41
|
+
export class ToolTimeoutError extends Error {
|
|
42
|
+
toolName;
|
|
43
|
+
timeoutMs;
|
|
44
|
+
constructor(toolName, timeoutMs) {
|
|
45
|
+
super(`Tool execution timed out after ${timeoutMs}ms: ${toolName}`);
|
|
46
|
+
this.toolName = toolName;
|
|
47
|
+
this.timeoutMs = timeoutMs;
|
|
48
|
+
this.name = 'ToolTimeoutError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Default logger implementation
|
|
53
|
+
*/
|
|
54
|
+
const defaultLogger = {
|
|
55
|
+
info: (message, data) => {
|
|
56
|
+
console.log(`[INFO] ${message}`, data ?? '');
|
|
57
|
+
},
|
|
58
|
+
warn: (message, data) => {
|
|
59
|
+
console.warn(`[WARN] ${message}`, data ?? '');
|
|
60
|
+
},
|
|
61
|
+
error: (message, data) => {
|
|
62
|
+
console.error(`[ERROR] ${message}`, data ?? '');
|
|
63
|
+
},
|
|
64
|
+
debug: (message, data) => {
|
|
65
|
+
console.debug(`[DEBUG] ${message}`, data ?? '');
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Validates a single parameter value against its definition
|
|
70
|
+
*/
|
|
71
|
+
function validateParameterValue(param, value, toolName) {
|
|
72
|
+
// Check required parameters
|
|
73
|
+
if (param.required && (value === undefined || value === null)) {
|
|
74
|
+
throw new ToolValidationError(`Missing required parameter: ${param.name}`, toolName, param.name, 'Parameter is required but was not provided');
|
|
75
|
+
}
|
|
76
|
+
// Skip validation for optional parameters that are not provided
|
|
77
|
+
if (value === undefined || value === null) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Type validation
|
|
81
|
+
const actualType = Array.isArray(value) ? 'array' : typeof value;
|
|
82
|
+
// Handle type mapping
|
|
83
|
+
const expectedType = param.type;
|
|
84
|
+
if (expectedType === 'object' && actualType === 'object' && !Array.isArray(value)) {
|
|
85
|
+
// Valid object
|
|
86
|
+
}
|
|
87
|
+
else if (expectedType === 'array' && Array.isArray(value)) {
|
|
88
|
+
// Valid array
|
|
89
|
+
}
|
|
90
|
+
else if (expectedType === actualType) {
|
|
91
|
+
// Direct type match
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new ToolValidationError(`Invalid type for parameter ${param.name}: expected ${param.type}, got ${actualType}`, toolName, param.name, `Expected type ${param.type} but received ${actualType}`);
|
|
95
|
+
}
|
|
96
|
+
// Enum validation
|
|
97
|
+
if (param.enum && param.enum.length > 0) {
|
|
98
|
+
if (!param.enum.includes(String(value))) {
|
|
99
|
+
throw new ToolValidationError(`Invalid value for parameter ${param.name}: must be one of [${param.enum.join(', ')}]`, toolName, param.name, `Value must be one of: ${param.enum.join(', ')}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validates all parameters for a tool
|
|
105
|
+
*/
|
|
106
|
+
function validateParameters(tool, args) {
|
|
107
|
+
const validatedArgs = {};
|
|
108
|
+
// Validate each defined parameter
|
|
109
|
+
for (const param of tool.parameters) {
|
|
110
|
+
const value = args[param.name];
|
|
111
|
+
validateParameterValue(param, value, tool.name);
|
|
112
|
+
// Use provided value or default
|
|
113
|
+
if (value !== undefined && value !== null) {
|
|
114
|
+
validatedArgs[param.name] = value;
|
|
115
|
+
}
|
|
116
|
+
else if (param.default !== undefined) {
|
|
117
|
+
validatedArgs[param.name] = param.default;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Check for unknown parameters
|
|
121
|
+
const knownParams = new Set(tool.parameters.map((p) => p.name));
|
|
122
|
+
for (const key of Object.keys(args)) {
|
|
123
|
+
if (!knownParams.has(key)) {
|
|
124
|
+
// Include unknown parameters but log a warning
|
|
125
|
+
validatedArgs[key] = args[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return validatedArgs;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates a promise that rejects after a timeout
|
|
132
|
+
*/
|
|
133
|
+
function createTimeout(ms, toolName) {
|
|
134
|
+
return new Promise((_, reject) => {
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
reject(new ToolTimeoutError(toolName, ms));
|
|
137
|
+
}, ms);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Tool Executor
|
|
142
|
+
*
|
|
143
|
+
* Executes tools with parameter validation, context injection,
|
|
144
|
+
* timeout handling, and error management.
|
|
145
|
+
*/
|
|
146
|
+
export class ToolExecutor {
|
|
147
|
+
registry;
|
|
148
|
+
options;
|
|
149
|
+
contextProvider;
|
|
150
|
+
constructor(registry, options = {}) {
|
|
151
|
+
this.registry = registry;
|
|
152
|
+
this.options = {
|
|
153
|
+
defaultTimeout: options.defaultTimeout ?? 30000,
|
|
154
|
+
strictValidation: options.strictValidation ?? true,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Set the context provider for tool execution
|
|
159
|
+
*/
|
|
160
|
+
setContextProvider(provider) {
|
|
161
|
+
this.contextProvider = provider;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create a tool context from the provider or defaults
|
|
165
|
+
*/
|
|
166
|
+
createContext(sessionId) {
|
|
167
|
+
if (this.contextProvider) {
|
|
168
|
+
return {
|
|
169
|
+
knowledgeBase: this.contextProvider.getKnowledgeBase(),
|
|
170
|
+
sessionId: sessionId ?? this.contextProvider.getSessionId(),
|
|
171
|
+
logger: this.contextProvider.getLogger(),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// Return a minimal context if no provider is set
|
|
175
|
+
return {
|
|
176
|
+
knowledgeBase: {
|
|
177
|
+
addDocument: async () => '',
|
|
178
|
+
getDocument: async () => null,
|
|
179
|
+
deleteDocument: async () => false,
|
|
180
|
+
search: async () => [],
|
|
181
|
+
listCategories: async () => [],
|
|
182
|
+
getDocumentsByCategory: async () => [],
|
|
183
|
+
},
|
|
184
|
+
sessionId: sessionId ?? 'default',
|
|
185
|
+
logger: defaultLogger,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Execute a tool by name with the given arguments
|
|
190
|
+
*
|
|
191
|
+
* @param toolName - Name of the tool to execute
|
|
192
|
+
* @param args - Arguments to pass to the tool
|
|
193
|
+
* @param options - Execution options
|
|
194
|
+
* @returns The execution result
|
|
195
|
+
*/
|
|
196
|
+
async execute(toolName, args, options) {
|
|
197
|
+
const startTime = Date.now();
|
|
198
|
+
const timeout = options?.timeout ?? this.options.defaultTimeout;
|
|
199
|
+
// Get the tool
|
|
200
|
+
const tool = this.registry.get(toolName);
|
|
201
|
+
if (!tool) {
|
|
202
|
+
const error = new ToolNotFoundError(toolName);
|
|
203
|
+
return {
|
|
204
|
+
result: {
|
|
205
|
+
success: false,
|
|
206
|
+
content: `Tool not found: ${toolName}`,
|
|
207
|
+
error: {
|
|
208
|
+
code: 'TOOL_NOT_FOUND',
|
|
209
|
+
message: error.message,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
toolName,
|
|
213
|
+
arguments: args,
|
|
214
|
+
durationMs: Date.now() - startTime,
|
|
215
|
+
success: false,
|
|
216
|
+
error,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
// Validate parameters
|
|
220
|
+
let validatedArgs;
|
|
221
|
+
try {
|
|
222
|
+
validatedArgs = this.options.strictValidation ? validateParameters(tool, args) : args;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
if (error instanceof ToolValidationError) {
|
|
226
|
+
return {
|
|
227
|
+
result: {
|
|
228
|
+
success: false,
|
|
229
|
+
content: error.message,
|
|
230
|
+
error: {
|
|
231
|
+
code: 'VALIDATION_ERROR',
|
|
232
|
+
message: error.message,
|
|
233
|
+
details: {
|
|
234
|
+
parameter: error.parameterName,
|
|
235
|
+
reason: error.reason,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
toolName,
|
|
240
|
+
arguments: args,
|
|
241
|
+
durationMs: Date.now() - startTime,
|
|
242
|
+
success: false,
|
|
243
|
+
error,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
// Create context
|
|
249
|
+
const context = this.createContext(options?.sessionId);
|
|
250
|
+
// Execute with timeout
|
|
251
|
+
try {
|
|
252
|
+
const result = await Promise.race([
|
|
253
|
+
tool.execute(validatedArgs, context),
|
|
254
|
+
createTimeout(timeout, toolName),
|
|
255
|
+
]);
|
|
256
|
+
return {
|
|
257
|
+
result,
|
|
258
|
+
toolName,
|
|
259
|
+
arguments: validatedArgs,
|
|
260
|
+
durationMs: Date.now() - startTime,
|
|
261
|
+
success: result.success,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
const execError = error instanceof Error ? error : new Error(String(error));
|
|
266
|
+
// Handle timeout
|
|
267
|
+
if (error instanceof ToolTimeoutError) {
|
|
268
|
+
return {
|
|
269
|
+
result: {
|
|
270
|
+
success: false,
|
|
271
|
+
content: `Tool execution timed out after ${timeout}ms`,
|
|
272
|
+
error: {
|
|
273
|
+
code: 'TIMEOUT',
|
|
274
|
+
message: execError.message,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
toolName,
|
|
278
|
+
arguments: validatedArgs,
|
|
279
|
+
durationMs: Date.now() - startTime,
|
|
280
|
+
success: false,
|
|
281
|
+
error: execError,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// Handle other errors
|
|
285
|
+
return {
|
|
286
|
+
result: {
|
|
287
|
+
success: false,
|
|
288
|
+
content: `Tool execution failed: ${execError.message}`,
|
|
289
|
+
error: {
|
|
290
|
+
code: 'EXECUTION_ERROR',
|
|
291
|
+
message: execError.message,
|
|
292
|
+
details: execError.stack,
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
toolName,
|
|
296
|
+
arguments: validatedArgs,
|
|
297
|
+
durationMs: Date.now() - startTime,
|
|
298
|
+
success: false,
|
|
299
|
+
error: new ToolExecutionError(`Tool execution failed: ${execError.message}`, toolName, execError),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Execute multiple tools in sequence
|
|
305
|
+
*
|
|
306
|
+
* @param calls - Array of tool calls to execute
|
|
307
|
+
* @param options - Execution options
|
|
308
|
+
* @returns Array of execution results
|
|
309
|
+
*/
|
|
310
|
+
async executeSequence(calls, options) {
|
|
311
|
+
const results = [];
|
|
312
|
+
const stopOnError = options?.stopOnError ?? false;
|
|
313
|
+
for (const call of calls) {
|
|
314
|
+
const result = await this.execute(call.toolName, call.args, {
|
|
315
|
+
sessionId: options?.sessionId,
|
|
316
|
+
timeout: options?.timeout,
|
|
317
|
+
});
|
|
318
|
+
results.push(result);
|
|
319
|
+
if (stopOnError && !result.success) {
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return results;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Execute multiple tools in parallel
|
|
327
|
+
*
|
|
328
|
+
* @param calls - Array of tool calls to execute
|
|
329
|
+
* @param options - Execution options
|
|
330
|
+
* @returns Array of execution results
|
|
331
|
+
*/
|
|
332
|
+
async executeParallel(calls, options) {
|
|
333
|
+
const promises = calls.map((call) => this.execute(call.toolName, call.args, {
|
|
334
|
+
sessionId: options?.sessionId,
|
|
335
|
+
timeout: options?.timeout,
|
|
336
|
+
}));
|
|
337
|
+
return Promise.all(promises);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Check if a tool requires confirmation before execution
|
|
341
|
+
*/
|
|
342
|
+
requiresConfirmation(toolName) {
|
|
343
|
+
const tool = this.registry.get(toolName);
|
|
344
|
+
return tool?.requiresConfirmation ?? false;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Get the risk level of a tool
|
|
348
|
+
*/
|
|
349
|
+
getRiskLevel(toolName) {
|
|
350
|
+
const tool = this.registry.get(toolName);
|
|
351
|
+
return tool?.riskLevel;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=tool-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-executor.js","sourceRoot":"","sources":["../../src/core/tool-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAgB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAG1B;IACA;IACA;IAJlB,YACE,OAAe,EACC,QAAgB,EAChB,aAAqB,EACrB,MAAc;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,kBAAa,GAAb,aAAa,CAAQ;QACrB,WAAM,GAAN,MAAM,CAAQ;QAG9B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzB;IACA;IAHlB,YACE,OAAe,EACC,QAAgB,EAChB,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KA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BACnC,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CACnB,KAAiE,EACjE,OAGC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE;YACrC,SAAS,EAAE,OAAO,EAAE,SAAS;YAC7B,OAAO,EAAE,OAAO,EAAE,OAAO;SAC1B,CAAC,CACH,CAAC;QAEF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,QAAgB;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,IAAI,EAAE,oBAAoB,IAAI,KAAK,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,QAAgB;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,IAAI,EAAE,SAAS,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages registration and retrieval of tools for the Agent.
|
|
5
|
+
* Validates tool definitions and provides Function Calling format conversion.
|
|
6
|
+
*
|
|
7
|
+
* @module core/tool-registry
|
|
8
|
+
*/
|
|
9
|
+
import type { Tool, ToolDefinition } from '../types/tool.js';
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when tool registration fails
|
|
12
|
+
*/
|
|
13
|
+
export declare class ToolRegistrationError extends Error {
|
|
14
|
+
readonly toolName: string;
|
|
15
|
+
readonly reason: string;
|
|
16
|
+
constructor(message: string, toolName: string, reason: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Error thrown when a tool is not found
|
|
20
|
+
*/
|
|
21
|
+
export declare class ToolNotFoundError extends Error {
|
|
22
|
+
constructor(toolName: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for tool registration behavior
|
|
26
|
+
*/
|
|
27
|
+
export interface ToolRegistryOptions {
|
|
28
|
+
/** Whether to allow replacing existing tools (default: false) */
|
|
29
|
+
allowReplace?: boolean;
|
|
30
|
+
/** Whether to validate tool definitions strictly (default: true) */
|
|
31
|
+
strictValidation?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registry for managing Agent tools
|
|
35
|
+
*
|
|
36
|
+
* Provides methods to register, retrieve, and list tools.
|
|
37
|
+
* Ensures tool uniqueness and validates definitions.
|
|
38
|
+
*/
|
|
39
|
+
export declare class ToolRegistry {
|
|
40
|
+
private tools;
|
|
41
|
+
private options;
|
|
42
|
+
constructor(options?: ToolRegistryOptions);
|
|
43
|
+
/**
|
|
44
|
+
* Register a tool with the registry
|
|
45
|
+
*
|
|
46
|
+
* @param tool - The tool to register
|
|
47
|
+
* @throws ToolRegistrationError if validation fails or tool already exists
|
|
48
|
+
*/
|
|
49
|
+
register(tool: Tool): void;
|
|
50
|
+
/**
|
|
51
|
+
* Register multiple tools at once
|
|
52
|
+
*
|
|
53
|
+
* @param tools - Array of tools to register
|
|
54
|
+
* @throws ToolRegistrationError if any tool fails validation
|
|
55
|
+
*/
|
|
56
|
+
registerAll(tools: Tool[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get a tool by name
|
|
59
|
+
*
|
|
60
|
+
* @param name - The tool name
|
|
61
|
+
* @returns The tool if found, undefined otherwise
|
|
62
|
+
*/
|
|
63
|
+
get(name: string): Tool | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Get a tool by name, throwing if not found
|
|
66
|
+
*
|
|
67
|
+
* @param name - The tool name
|
|
68
|
+
* @returns The tool
|
|
69
|
+
* @throws ToolNotFoundError if tool doesn't exist
|
|
70
|
+
*/
|
|
71
|
+
getOrThrow(name: string): Tool;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a tool is registered
|
|
74
|
+
*
|
|
75
|
+
* @param name - The tool name
|
|
76
|
+
* @returns true if the tool exists
|
|
77
|
+
*/
|
|
78
|
+
has(name: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Remove a tool from the registry
|
|
81
|
+
*
|
|
82
|
+
* @param name - The tool name
|
|
83
|
+
* @returns true if the tool was removed, false if it didn't exist
|
|
84
|
+
*/
|
|
85
|
+
unregister(name: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* List all registered tools
|
|
88
|
+
*
|
|
89
|
+
* @returns Array of all registered tools
|
|
90
|
+
*/
|
|
91
|
+
list(): Tool[];
|
|
92
|
+
/**
|
|
93
|
+
* List tool names
|
|
94
|
+
*
|
|
95
|
+
* @returns Array of registered tool names
|
|
96
|
+
*/
|
|
97
|
+
listNames(): string[];
|
|
98
|
+
/**
|
|
99
|
+
* List tools by category
|
|
100
|
+
*
|
|
101
|
+
* @param category - The category to filter by
|
|
102
|
+
* @returns Array of tools in the specified category
|
|
103
|
+
*/
|
|
104
|
+
listByCategory(category: string): Tool[];
|
|
105
|
+
/**
|
|
106
|
+
* Get all unique categories
|
|
107
|
+
*
|
|
108
|
+
* @returns Array of unique category names
|
|
109
|
+
*/
|
|
110
|
+
getCategories(): string[];
|
|
111
|
+
/**
|
|
112
|
+
* Get tool definitions in Function Calling format
|
|
113
|
+
*
|
|
114
|
+
* @returns Array of tool definitions for LLM APIs
|
|
115
|
+
*/
|
|
116
|
+
getDefinitions(): ToolDefinition[];
|
|
117
|
+
/**
|
|
118
|
+
* Get tool definitions for specific tools
|
|
119
|
+
*
|
|
120
|
+
* @param names - Array of tool names to get definitions for
|
|
121
|
+
* @returns Array of tool definitions
|
|
122
|
+
*/
|
|
123
|
+
getDefinitionsFor(names: string[]): ToolDefinition[];
|
|
124
|
+
/**
|
|
125
|
+
* Get the number of registered tools
|
|
126
|
+
*/
|
|
127
|
+
get size(): number;
|
|
128
|
+
/**
|
|
129
|
+
* Clear all registered tools
|
|
130
|
+
*/
|
|
131
|
+
clear(): void;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=tool-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../src/core/tool-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAiB,MAAM,kBAAkB,CAAC;AAG5E;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;aAG5B,QAAQ,EAAE,MAAM;aAChB,MAAM,EAAE,MAAM;gBAF9B,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM;CAKjC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,QAAQ,EAAE,MAAM;CAI7B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iEAAiE;IACjE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AA4HD;;;;;GAKG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,OAAO,CAAgC;gBAEnC,OAAO,GAAE,mBAAwB;IAO7C;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAoB1B;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI;IAMhC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ9B;;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