matimo 0.1.0-alpha.2 → 0.1.0-alpha.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 +80 -26
- package/dist/core/schema.d.ts +1 -1
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +8 -3
- package/dist/core/schema.js.map +1 -1
- package/dist/core/tool-loader.d.ts.map +1 -1
- package/dist/core/tool-loader.js +15 -4
- package/dist/core/tool-loader.js.map +1 -1
- package/dist/core/tool-registry.d.ts.map +1 -1
- package/dist/core/tool-registry.js +5 -1
- package/dist/core/tool-registry.js.map +1 -1
- package/dist/decorators/tool-decorator.d.ts.map +1 -1
- package/dist/decorators/tool-decorator.js +7 -4
- package/dist/decorators/tool-decorator.js.map +1 -1
- package/dist/encodings/parameter-encoding.d.ts.map +1 -1
- package/dist/encodings/parameter-encoding.js +9 -2
- package/dist/encodings/parameter-encoding.js.map +1 -1
- package/dist/executors/command-executor.d.ts.map +1 -1
- package/dist/executors/command-executor.js +5 -1
- package/dist/executors/command-executor.js.map +1 -1
- package/dist/executors/http-executor.d.ts.map +1 -1
- package/dist/executors/http-executor.js +5 -1
- package/dist/executors/http-executor.js.map +1 -1
- package/package.json +4 -8
- package/tools/calculator/calculator.ts +78 -0
- package/tools/calculator/definition.yaml +71 -0
- package/tools/echo-tool/definition.yaml +35 -0
- package/tools/examples/calculator.yaml +54 -0
- package/tools/examples/echo-tool.yaml +35 -0
- package/tools/examples/http-client.yaml +66 -0
- package/tools/github/definition.yaml +41 -0
- package/tools/gmail/README.md +1189 -0
- package/tools/gmail/create-draft/definition.yaml +99 -0
- package/tools/gmail/definition.yaml +49 -0
- package/tools/gmail/delete-message/definition.yaml +42 -0
- package/tools/gmail/get-message/definition.yaml +89 -0
- package/tools/gmail/list-messages/definition.yaml +84 -0
- package/tools/gmail/send-email/definition.yaml +95 -0
- package/tools/http-client/definition.yaml +73 -0
- package/tools/slack/README.md +200 -0
- package/tools/slack/assets/icon.svg +9 -0
- package/tools/slack/assets/logo-dark.svg +14 -0
- package/tools/slack/assets/logo-light.svg +14 -0
- package/tools/slack/assets/logo.svg +14 -0
- package/tools/slack/definition.yaml +54 -0
- package/tools/slack/get-user/definition.yaml +31 -0
- package/tools/slack/list-channels/definition.yaml +46 -0
- package/tools/slack/send-message/definition.yaml +30 -0
- package/tools/slack/slack_add_reaction/definition.yaml +45 -0
- package/tools/slack/slack_create_channel/definition.yaml +41 -0
- package/tools/slack/slack_get_channel_history/definition.yaml +58 -0
- package/tools/slack/slack_get_reactions/definition.yaml +36 -0
- package/tools/slack/slack_get_thread_replies/definition.yaml +45 -0
- package/tools/slack/slack_get_user_info/definition.yaml +32 -0
- package/tools/slack/slack_join_channel/definition.yaml +35 -0
- package/tools/slack/slack_reply_to_message/definition.yaml +49 -0
- package/tools/slack/slack_search_messages/definition.yaml +46 -0
- package/tools/slack/slack_send_channel_message/definition.yaml +34 -0
- package/tools/slack/slack_send_dm/definition.yaml +37 -0
- package/tools/slack/slack_set_channel_topic/definition.yaml +40 -0
- package/tools/slack/slack_upload_file/definition.yaml +152 -0
- package/docs/Gemfile +0 -5
- package/docs/RELEASES.md +0 -90
- package/docs/ROADMAP.md +0 -138
- package/docs/_config.yml +0 -27
- package/docs/api-reference/ERRORS.md +0 -445
- package/docs/api-reference/SDK.md +0 -582
- package/docs/api-reference/TYPES.md +0 -415
- package/docs/architecture/OAUTH.md +0 -1366
- package/docs/architecture/OVERVIEW.md +0 -564
- package/docs/assets/logo.png +0 -0
- package/docs/community/COMMIT_GUIDELINES.md +0 -552
- package/docs/framework-integrations/LANGCHAIN.md +0 -286
- package/docs/getting-started/QUICK_START.md +0 -212
- package/docs/getting-started/YOUR_FIRST_TOOL.md +0 -217
- package/docs/getting-started/installation.md +0 -124
- package/docs/index.md +0 -289
- package/docs/tool-development/DECORATOR_GUIDE.md +0 -633
- package/docs/tool-development/OAUTH_LINK.md +0 -5
- package/docs/tool-development/PROVIDER_CONFIGURATION.md +0 -458
- package/docs/tool-development/TESTING.md +0 -412
- package/docs/tool-development/TOOL_SPECIFICATION.md +0 -793
- package/docs/tool-development/YAML_TOOLS.md +0 -65
- package/docs/troubleshooting/FAQ.md +0 -391
- package/docs/user-guide/AUTHENTICATION.md +0 -255
- package/docs/user-guide/DEVELOPMENT_STANDARDS.md +0 -698
- package/docs/user-guide/SDK_PATTERNS.md +0 -316
- package/docs/user-guide/TOOL_DISCOVERY.md +0 -209
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
# API Reference — Complete SDK
|
|
2
|
-
|
|
3
|
-
Complete reference for the Matimo TypeScript SDK.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [MatimoFactory](#matimofactory)
|
|
8
|
-
- [ToolLoader](#toolloader)
|
|
9
|
-
- [ToolRegistry](#toolregistry)
|
|
10
|
-
- [Executors](#executors)
|
|
11
|
-
- [CommandExecutor](#commandexecutor)
|
|
12
|
-
- [HttpExecutor](#httpexecutor)
|
|
13
|
-
- [Error Handling](#error-handling)
|
|
14
|
-
- [Types](#types)
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## MatimoFactory
|
|
19
|
-
|
|
20
|
-
Factory pattern for creating Matimo instances.
|
|
21
|
-
|
|
22
|
-
### Methods
|
|
23
|
-
|
|
24
|
-
#### `create(options)`
|
|
25
|
-
|
|
26
|
-
Create a new Matimo instance with factory pattern.
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
const matimo = MatimoFactory.create({
|
|
30
|
-
toolsPath: './tools',
|
|
31
|
-
validateOnLoad: true
|
|
32
|
-
});
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
**Parameters:**
|
|
36
|
-
- `toolsPath` (string, required) - Path to tools directory
|
|
37
|
-
- `validateOnLoad` (boolean, optional, default: true) - Validate tools on load
|
|
38
|
-
|
|
39
|
-
**Returns:** `Matimo` instance
|
|
40
|
-
|
|
41
|
-
**Example:**
|
|
42
|
-
```typescript
|
|
43
|
-
import { MatimoFactory } from 'matimo';
|
|
44
|
-
|
|
45
|
-
const matimo = MatimoFactory.create({
|
|
46
|
-
toolsPath: './tools'
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const tools = matimo.getToolRegistry().listTools();
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## ToolLoader
|
|
55
|
-
|
|
56
|
-
Load tool definitions from YAML/JSON files.
|
|
57
|
-
|
|
58
|
-
### Constructor
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
const loader = new ToolLoader(toolsPath: string);
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Methods
|
|
65
|
-
|
|
66
|
-
#### `loadToolsFromDirectory()`
|
|
67
|
-
|
|
68
|
-
Load all tools from a directory recursively.
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
const tools = await loader.loadToolsFromDirectory();
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Returns:** `ToolDefinition[]` - Array of loaded tools
|
|
75
|
-
|
|
76
|
-
**Throws:**
|
|
77
|
-
- `FileNotFoundError` - If tools directory doesn't exist
|
|
78
|
-
- `SchemaValidationError` - If tool schema is invalid
|
|
79
|
-
|
|
80
|
-
**Example:**
|
|
81
|
-
```typescript
|
|
82
|
-
const loader = new ToolLoader('./tools');
|
|
83
|
-
const tools = await loader.loadToolsFromDirectory();
|
|
84
|
-
console.log(`Loaded ${tools.length} tools`);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
#### `loadToolFromFile(filePath)`
|
|
88
|
-
|
|
89
|
-
Load a single tool from a YAML/JSON file.
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
const tool = await loader.loadToolFromFile('./tools/calculator/tool.yaml');
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Parameters:**
|
|
96
|
-
- `filePath` (string) - Path to tool file
|
|
97
|
-
|
|
98
|
-
**Returns:** `ToolDefinition` - Loaded tool definition
|
|
99
|
-
|
|
100
|
-
**Throws:**
|
|
101
|
-
- `FileNotFoundError` - If file doesn't exist
|
|
102
|
-
- `SchemaValidationError` - If tool schema is invalid
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## ToolRegistry
|
|
107
|
-
|
|
108
|
-
In-memory registry of loaded tools.
|
|
109
|
-
|
|
110
|
-
### Methods
|
|
111
|
-
|
|
112
|
-
#### `listTools()`
|
|
113
|
-
|
|
114
|
-
Get all loaded tools.
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
const tools = registry.listTools();
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
**Returns:** `ToolDefinition[]`
|
|
121
|
-
|
|
122
|
-
**Example:**
|
|
123
|
-
```typescript
|
|
124
|
-
registry.listTools().forEach(tool => {
|
|
125
|
-
console.log(`${tool.name}: ${tool.description}`);
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
#### `getTool(name)`
|
|
130
|
-
|
|
131
|
-
Get a tool by name.
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
const tool = registry.getTool('calculator');
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Parameters:**
|
|
138
|
-
- `name` (string) - Tool name
|
|
139
|
-
|
|
140
|
-
**Returns:** `ToolDefinition | undefined`
|
|
141
|
-
|
|
142
|
-
**Example:**
|
|
143
|
-
```typescript
|
|
144
|
-
const tool = registry.getTool('github-create-issue');
|
|
145
|
-
if (tool) {
|
|
146
|
-
console.log(tool.parameters);
|
|
147
|
-
} else {
|
|
148
|
-
console.log('Tool not found');
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
#### `registerTool(tool)`
|
|
153
|
-
|
|
154
|
-
Register a tool in the registry.
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
registry.registerTool(toolDefinition);
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
**Parameters:**
|
|
161
|
-
- `tool` (ToolDefinition) - Tool definition
|
|
162
|
-
|
|
163
|
-
**Example:**
|
|
164
|
-
```typescript
|
|
165
|
-
const newTool = {
|
|
166
|
-
name: 'my-tool',
|
|
167
|
-
description: 'My custom tool',
|
|
168
|
-
version: '1.0.0',
|
|
169
|
-
// ... other required fields
|
|
170
|
-
};
|
|
171
|
-
registry.registerTool(newTool);
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
---
|
|
175
|
-
|
|
176
|
-
## Executors
|
|
177
|
-
|
|
178
|
-
Execute tools with different backends.
|
|
179
|
-
|
|
180
|
-
### CommandExecutor
|
|
181
|
-
|
|
182
|
-
Execute shell commands.
|
|
183
|
-
|
|
184
|
-
#### Constructor
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
const executor = new CommandExecutor();
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
#### `execute(tool, params, context?)`
|
|
191
|
-
|
|
192
|
-
Execute a command-based tool.
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
const result = await executor.execute(tool, {
|
|
196
|
-
param1: 'value1',
|
|
197
|
-
param2: 'value2'
|
|
198
|
-
});
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
**Parameters:**
|
|
202
|
-
- `tool` (ToolDefinition) - Tool to execute
|
|
203
|
-
- `params` (Record<string, unknown>) - Tool parameters
|
|
204
|
-
- `context` (ExecutionContext, optional) - Execution context with traceId, etc.
|
|
205
|
-
|
|
206
|
-
**Returns:** `ExecutionResult`
|
|
207
|
-
|
|
208
|
-
**Throws:**
|
|
209
|
-
- `ValidationError` - If parameters don't match schema
|
|
210
|
-
- `ExecutionError` - If command fails
|
|
211
|
-
|
|
212
|
-
**Example:**
|
|
213
|
-
```typescript
|
|
214
|
-
const executor = new CommandExecutor();
|
|
215
|
-
const result = await executor.execute(calculator, {
|
|
216
|
-
operation: 'add',
|
|
217
|
-
a: 5,
|
|
218
|
-
b: 3
|
|
219
|
-
});
|
|
220
|
-
console.log(result.output); // { result: 8 }
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
#### `validateParameters(tool, params)`
|
|
224
|
-
|
|
225
|
-
Validate parameters against tool schema.
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
const isValid = executor.validateParameters(tool, params);
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
**Parameters:**
|
|
232
|
-
- `tool` (ToolDefinition) - Tool definition
|
|
233
|
-
- `params` (unknown) - Parameters to validate
|
|
234
|
-
|
|
235
|
-
**Returns:** `boolean`
|
|
236
|
-
|
|
237
|
-
---
|
|
238
|
-
|
|
239
|
-
### HttpExecutor
|
|
240
|
-
|
|
241
|
-
Execute HTTP requests.
|
|
242
|
-
|
|
243
|
-
#### Constructor
|
|
244
|
-
|
|
245
|
-
```typescript
|
|
246
|
-
const executor = new HttpExecutor();
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
#### `execute(tool, params, context?)`
|
|
250
|
-
|
|
251
|
-
Execute an HTTP-based tool.
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
const result = await executor.execute(tool, {
|
|
255
|
-
endpoint: '/api/users',
|
|
256
|
-
method: 'GET'
|
|
257
|
-
});
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
**Parameters:**
|
|
261
|
-
- `tool` (ToolDefinition) - Tool to execute
|
|
262
|
-
- `params` (Record<string, unknown>) - Tool parameters
|
|
263
|
-
- `context` (ExecutionContext, optional) - Execution context
|
|
264
|
-
|
|
265
|
-
**Returns:** `ExecutionResult`
|
|
266
|
-
|
|
267
|
-
**Throws:**
|
|
268
|
-
- `ValidationError` - If parameters don't match schema
|
|
269
|
-
- `ExecutionError` - If HTTP request fails
|
|
270
|
-
- `AuthError` - If authentication fails
|
|
271
|
-
|
|
272
|
-
**Example:**
|
|
273
|
-
```typescript
|
|
274
|
-
const executor = new HttpExecutor();
|
|
275
|
-
const result = await executor.execute(githubApi, {
|
|
276
|
-
endpoint: '/repos/{owner}/{repo}/issues',
|
|
277
|
-
method: 'POST',
|
|
278
|
-
body: { title: 'Bug Report' }
|
|
279
|
-
});
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
---
|
|
283
|
-
|
|
284
|
-
## Error Handling
|
|
285
|
-
|
|
286
|
-
All errors inherit from `MatimoError`.
|
|
287
|
-
|
|
288
|
-
### Error Codes
|
|
289
|
-
|
|
290
|
-
```typescript
|
|
291
|
-
enum ErrorCode {
|
|
292
|
-
INVALID_SCHEMA = 'INVALID_SCHEMA',
|
|
293
|
-
EXECUTION_FAILED = 'EXECUTION_FAILED',
|
|
294
|
-
AUTH_FAILED = 'AUTH_FAILED',
|
|
295
|
-
TOOL_NOT_FOUND = 'TOOL_NOT_FOUND',
|
|
296
|
-
FILE_NOT_FOUND = 'FILE_NOT_FOUND',
|
|
297
|
-
VALIDATION_FAILED = 'VALIDATION_FAILED'
|
|
298
|
-
}
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### MatimoError
|
|
302
|
-
|
|
303
|
-
Base error class.
|
|
304
|
-
|
|
305
|
-
```typescript
|
|
306
|
-
throw new MatimoError(
|
|
307
|
-
message: string,
|
|
308
|
-
code: ErrorCode,
|
|
309
|
-
context?: Record<string, unknown>
|
|
310
|
-
);
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
**Example:**
|
|
314
|
-
```typescript
|
|
315
|
-
try {
|
|
316
|
-
const result = await executor.execute(tool, params);
|
|
317
|
-
} catch (error) {
|
|
318
|
-
if (error instanceof MatimoError) {
|
|
319
|
-
console.error(`[${error.code}] ${error.message}`);
|
|
320
|
-
if (error.context) {
|
|
321
|
-
console.error('Context:', error.context);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Common Errors
|
|
328
|
-
|
|
329
|
-
#### ValidationError
|
|
330
|
-
|
|
331
|
-
Parameters don't match tool schema.
|
|
332
|
-
|
|
333
|
-
```typescript
|
|
334
|
-
catch (error) {
|
|
335
|
-
if (error.code === 'VALIDATION_FAILED') {
|
|
336
|
-
console.error('Invalid parameters:', error.message);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
#### ExecutionError
|
|
342
|
-
|
|
343
|
-
Tool execution failed.
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
catch (error) {
|
|
347
|
-
if (error.code === 'EXECUTION_FAILED') {
|
|
348
|
-
console.error('Tool failed:', error.message);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
#### AuthError
|
|
354
|
-
|
|
355
|
-
Authentication failed.
|
|
356
|
-
|
|
357
|
-
```typescript
|
|
358
|
-
catch (error) {
|
|
359
|
-
if (error.code === 'AUTH_FAILED') {
|
|
360
|
-
console.error('Authentication failed:', error.message);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
---
|
|
366
|
-
|
|
367
|
-
## Types
|
|
368
|
-
|
|
369
|
-
### ToolDefinition
|
|
370
|
-
|
|
371
|
-
```typescript
|
|
372
|
-
interface ToolDefinition {
|
|
373
|
-
name: string;
|
|
374
|
-
description: string;
|
|
375
|
-
version: string;
|
|
376
|
-
parameters: Record<string, Parameter>;
|
|
377
|
-
execution: ExecutionConfig;
|
|
378
|
-
output_schema?: OutputSchema;
|
|
379
|
-
authentication?: AuthConfig;
|
|
380
|
-
error_handling?: ErrorHandlingConfig;
|
|
381
|
-
}
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Parameter
|
|
385
|
-
|
|
386
|
-
```typescript
|
|
387
|
-
interface Parameter {
|
|
388
|
-
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
389
|
-
description: string;
|
|
390
|
-
required: boolean;
|
|
391
|
-
enum?: unknown[];
|
|
392
|
-
default?: unknown;
|
|
393
|
-
validation?: {
|
|
394
|
-
minLength?: number;
|
|
395
|
-
maxLength?: number;
|
|
396
|
-
min?: number;
|
|
397
|
-
max?: number;
|
|
398
|
-
pattern?: string;
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
### ExecutionConfig
|
|
404
|
-
|
|
405
|
-
```typescript
|
|
406
|
-
interface ExecutionConfig {
|
|
407
|
-
type: 'command' | 'http' | 'script';
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
interface CommandExecution extends ExecutionConfig {
|
|
411
|
-
type: 'command';
|
|
412
|
-
command: string;
|
|
413
|
-
args?: string[];
|
|
414
|
-
env?: Record<string, string>;
|
|
415
|
-
timeout_ms?: number;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
interface HttpExecution extends ExecutionConfig {
|
|
419
|
-
type: 'http';
|
|
420
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
421
|
-
url: string;
|
|
422
|
-
headers?: Record<string, string>;
|
|
423
|
-
auth?: AuthConfig;
|
|
424
|
-
timeout_ms?: number;
|
|
425
|
-
}
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
### OutputSchema
|
|
429
|
-
|
|
430
|
-
```typescript
|
|
431
|
-
interface OutputSchema {
|
|
432
|
-
type: 'object' | 'array' | 'string' | 'number' | 'boolean';
|
|
433
|
-
properties?: Record<string, OutputSchema>;
|
|
434
|
-
items?: OutputSchema;
|
|
435
|
-
required?: string[];
|
|
436
|
-
description?: string;
|
|
437
|
-
}
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
### AuthConfig
|
|
441
|
-
|
|
442
|
-
```typescript
|
|
443
|
-
interface AuthConfig {
|
|
444
|
-
type: 'api_key' | 'bearer' | 'oauth2' | 'basic';
|
|
445
|
-
location?: 'header' | 'query' | 'body';
|
|
446
|
-
name?: string; // For api_key and basic
|
|
447
|
-
secret_env_var: string;
|
|
448
|
-
}
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
### ExecutionResult
|
|
452
|
-
|
|
453
|
-
```typescript
|
|
454
|
-
interface ExecutionResult {
|
|
455
|
-
success: boolean;
|
|
456
|
-
output: unknown;
|
|
457
|
-
duration_ms: number;
|
|
458
|
-
error?: {
|
|
459
|
-
code: string;
|
|
460
|
-
message: string;
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
### ExecutionContext
|
|
466
|
-
|
|
467
|
-
```typescript
|
|
468
|
-
interface ExecutionContext {
|
|
469
|
-
traceId: string;
|
|
470
|
-
userId?: string;
|
|
471
|
-
metadata?: Record<string, unknown>;
|
|
472
|
-
}
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
---
|
|
476
|
-
|
|
477
|
-
## Complete Example
|
|
478
|
-
|
|
479
|
-
```typescript
|
|
480
|
-
import { MatimoFactory } from 'matimo';
|
|
481
|
-
|
|
482
|
-
// 1. Create Matimo instance
|
|
483
|
-
const matimo = MatimoFactory.create({
|
|
484
|
-
toolsPath: './tools'
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
// 2. List available tools
|
|
488
|
-
const tools = matimo.getToolRegistry().listTools();
|
|
489
|
-
console.log(`Available tools: ${tools.map(t => t.name).join(', ')}`);
|
|
490
|
-
|
|
491
|
-
// 3. Get specific tool
|
|
492
|
-
const calculator = matimo.getToolRegistry().getTool('calculator');
|
|
493
|
-
if (!calculator) {
|
|
494
|
-
throw new Error('Calculator tool not found');
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// 4. Execute with error handling
|
|
498
|
-
try {
|
|
499
|
-
const result = await matimo.executeTool('calculator', {
|
|
500
|
-
operation: 'add',
|
|
501
|
-
a: 10,
|
|
502
|
-
b: 5
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
console.log('Result:', result);
|
|
506
|
-
// Output: Result: { result: 15 }
|
|
507
|
-
} catch (error) {
|
|
508
|
-
if (error.code === 'VALIDATION_FAILED') {
|
|
509
|
-
console.error('Invalid parameters');
|
|
510
|
-
} else if (error.code === 'EXECUTION_FAILED') {
|
|
511
|
-
console.error('Tool execution failed:', error.message);
|
|
512
|
-
} else {
|
|
513
|
-
console.error('Unknown error:', error);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
---
|
|
519
|
-
|
|
520
|
-
## Advanced Usage
|
|
521
|
-
|
|
522
|
-
### Custom Execution Context
|
|
523
|
-
|
|
524
|
-
```typescript
|
|
525
|
-
const result = await executor.execute(tool, params, {
|
|
526
|
-
traceId: 'trace-12345',
|
|
527
|
-
userId: 'user-789',
|
|
528
|
-
metadata: {
|
|
529
|
-
source: 'api',
|
|
530
|
-
version: '1.0'
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
```
|
|
534
|
-
|
|
535
|
-
### Parameter Templating
|
|
536
|
-
|
|
537
|
-
```yaml
|
|
538
|
-
# In tool YAML:
|
|
539
|
-
execution:
|
|
540
|
-
type: command
|
|
541
|
-
command: echo
|
|
542
|
-
args:
|
|
543
|
-
- "Hello {name}, your age is {age}"
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
```typescript
|
|
547
|
-
const result = await executor.execute(tool, {
|
|
548
|
-
name: 'Alice',
|
|
549
|
-
age: 30
|
|
550
|
-
});
|
|
551
|
-
// Output: "Hello Alice, your age is 30"
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
### Output Validation
|
|
555
|
-
|
|
556
|
-
HTTP executor automatically validates responses against `output_schema`:
|
|
557
|
-
|
|
558
|
-
```yaml
|
|
559
|
-
output_schema:
|
|
560
|
-
type: object
|
|
561
|
-
properties:
|
|
562
|
-
id:
|
|
563
|
-
type: number
|
|
564
|
-
name:
|
|
565
|
-
type: string
|
|
566
|
-
email:
|
|
567
|
-
type: string
|
|
568
|
-
required:
|
|
569
|
-
- id
|
|
570
|
-
- name
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
The executor will throw `ValidationError` if the response doesn't match.
|
|
574
|
-
|
|
575
|
-
---
|
|
576
|
-
|
|
577
|
-
## See Also
|
|
578
|
-
|
|
579
|
-
- [Quick Start](../getting-started/QUICK_START.md) — Get started in 5 minutes
|
|
580
|
-
- [Tool Specification](../tool-development/TOOL_SPECIFICATION.md) — Write YAML tools
|
|
581
|
-
- [Decorator Guide](../tool-development/DECORATOR_GUIDE.md) — Use decorators
|
|
582
|
-
- [CONTRIBUTING.md](../CONTRIBUTING.md) — Development guide
|