matimo 0.1.0-alpha.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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +651 -0
  3. package/dist/auth/oauth2-config.d.ts +104 -0
  4. package/dist/auth/oauth2-config.d.ts.map +1 -0
  5. package/dist/auth/oauth2-config.js +38 -0
  6. package/dist/auth/oauth2-config.js.map +1 -0
  7. package/dist/auth/oauth2-handler.d.ts +130 -0
  8. package/dist/auth/oauth2-handler.d.ts.map +1 -0
  9. package/dist/auth/oauth2-handler.js +265 -0
  10. package/dist/auth/oauth2-handler.js.map +1 -0
  11. package/dist/auth/oauth2-provider-loader.d.ts +68 -0
  12. package/dist/auth/oauth2-provider-loader.d.ts.map +1 -0
  13. package/dist/auth/oauth2-provider-loader.js +120 -0
  14. package/dist/auth/oauth2-provider-loader.js.map +1 -0
  15. package/dist/core/schema.d.ts +238 -0
  16. package/dist/core/schema.d.ts.map +1 -0
  17. package/dist/core/schema.js +168 -0
  18. package/dist/core/schema.js.map +1 -0
  19. package/dist/core/tool-loader.d.ts +29 -0
  20. package/dist/core/tool-loader.d.ts.map +1 -0
  21. package/dist/core/tool-loader.js +98 -0
  22. package/dist/core/tool-loader.js.map +1 -0
  23. package/dist/core/tool-registry.d.ts +48 -0
  24. package/dist/core/tool-registry.d.ts.map +1 -0
  25. package/dist/core/tool-registry.js +89 -0
  26. package/dist/core/tool-registry.js.map +1 -0
  27. package/dist/core/types.d.ts +143 -0
  28. package/dist/core/types.d.ts.map +1 -0
  29. package/dist/core/types.js +5 -0
  30. package/dist/core/types.js.map +1 -0
  31. package/dist/decorators/index.d.ts +2 -0
  32. package/dist/decorators/index.d.ts.map +1 -0
  33. package/dist/decorators/index.js +2 -0
  34. package/dist/decorators/index.js.map +1 -0
  35. package/dist/decorators/tool-decorator.d.ts +97 -0
  36. package/dist/decorators/tool-decorator.d.ts.map +1 -0
  37. package/dist/decorators/tool-decorator.js +154 -0
  38. package/dist/decorators/tool-decorator.js.map +1 -0
  39. package/dist/encodings/parameter-encoding.d.ts +51 -0
  40. package/dist/encodings/parameter-encoding.d.ts.map +1 -0
  41. package/dist/encodings/parameter-encoding.js +116 -0
  42. package/dist/encodings/parameter-encoding.js.map +1 -0
  43. package/dist/errors/matimo-error.d.ts +34 -0
  44. package/dist/errors/matimo-error.d.ts.map +1 -0
  45. package/dist/errors/matimo-error.js +49 -0
  46. package/dist/errors/matimo-error.js.map +1 -0
  47. package/dist/executors/command-executor.d.ts +19 -0
  48. package/dist/executors/command-executor.d.ts.map +1 -0
  49. package/dist/executors/command-executor.js +94 -0
  50. package/dist/executors/command-executor.js.map +1 -0
  51. package/dist/executors/http-executor.d.ts +26 -0
  52. package/dist/executors/http-executor.d.ts.map +1 -0
  53. package/dist/executors/http-executor.js +133 -0
  54. package/dist/executors/http-executor.js.map +1 -0
  55. package/dist/index.d.ts +22 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +23 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/matimo-instance.d.ts +98 -0
  60. package/dist/matimo-instance.d.ts.map +1 -0
  61. package/dist/matimo-instance.js +260 -0
  62. package/dist/matimo-instance.js.map +1 -0
  63. package/docs/Gemfile +5 -0
  64. package/docs/RELEASES.md +69 -0
  65. package/docs/ROADMAP.md +138 -0
  66. package/docs/_config.yml +27 -0
  67. package/docs/api-reference/ERRORS.md +445 -0
  68. package/docs/api-reference/SDK.md +582 -0
  69. package/docs/api-reference/TYPES.md +415 -0
  70. package/docs/architecture/OAUTH.md +1366 -0
  71. package/docs/architecture/OVERVIEW.md +564 -0
  72. package/docs/assets/logo.png +0 -0
  73. package/docs/community/COMMIT_GUIDELINES.md +552 -0
  74. package/docs/framework-integrations/LANGCHAIN.md +286 -0
  75. package/docs/getting-started/QUICK_START.md +211 -0
  76. package/docs/getting-started/YOUR_FIRST_TOOL.md +217 -0
  77. package/docs/getting-started/installation.md +124 -0
  78. package/docs/index.md +288 -0
  79. package/docs/tool-development/DECORATOR_GUIDE.md +633 -0
  80. package/docs/tool-development/OAUTH_LINK.md +5 -0
  81. package/docs/tool-development/PROVIDER_CONFIGURATION.md +458 -0
  82. package/docs/tool-development/TESTING.md +412 -0
  83. package/docs/tool-development/TOOL_SPECIFICATION.md +793 -0
  84. package/docs/tool-development/YAML_TOOLS.md +65 -0
  85. package/docs/troubleshooting/FAQ.md +391 -0
  86. package/docs/user-guide/AUTHENTICATION.md +255 -0
  87. package/docs/user-guide/DEVELOPMENT_STANDARDS.md +698 -0
  88. package/docs/user-guide/SDK_PATTERNS.md +316 -0
  89. package/docs/user-guide/TOOL_DISCOVERY.md +209 -0
  90. package/package.json +96 -0
@@ -0,0 +1,582 @@
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