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,633 @@
1
+ # Decorator Guide — Using @tool Decorators
2
+
3
+ Use TypeScript decorators to define tools directly in code instead of YAML.
4
+
5
+ ## Overview
6
+
7
+ The `@tool` decorator provides a way to define Matimo tools using TypeScript decorators. This is useful when:
8
+
9
+ - You want to keep tool logic and definitions together
10
+ - You prefer type-safe tool definitions
11
+ - You're building tools that reference existing TypeScript functions
12
+
13
+ ---
14
+
15
+ ## Basic Usage
16
+
17
+ ### Simple Tool
18
+
19
+ ```typescript
20
+ import { tool, param } from 'matimo/decorators';
21
+
22
+ @tool({
23
+ name: 'greet',
24
+ description: 'Greet a person'
25
+ })
26
+ export class GreetTool {
27
+ @param({
28
+ type: 'string',
29
+ description: 'Person to greet',
30
+ required: true
31
+ })
32
+ name: string;
33
+
34
+ execute(): string {
35
+ return `Hello, ${this.name}!`;
36
+ }
37
+ }
38
+ ```
39
+
40
+ Use with Matimo:
41
+
42
+ ```typescript
43
+ import { MatimoFactory } from 'matimo';
44
+ import { GreetTool } from './tools/greet.tool';
45
+
46
+ const matimo = MatimoFactory.create({
47
+ toolClasses: [GreetTool]
48
+ });
49
+
50
+ const result = await matimo.executeTool('greet', {
51
+ name: 'Alice'
52
+ });
53
+
54
+ console.log(result); // "Hello, Alice!"
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Decorator Options
60
+
61
+ ### @tool
62
+
63
+ Define a tool class.
64
+
65
+ ```typescript
66
+ @tool({
67
+ name: string; // Tool identifier (required)
68
+ description: string; // What the tool does (required)
69
+ version?: string; // Semantic version (default: "1.0.0")
70
+ returnType?: 'object' | 'string' | 'number' | 'boolean' | 'array';
71
+ })
72
+ class MyTool {
73
+ // ...
74
+ }
75
+ ```
76
+
77
+ ### @param
78
+
79
+ Define a parameter.
80
+
81
+ ```typescript
82
+ @param({
83
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array'; // (required)
84
+ description: string; // What the parameter does (required)
85
+ required?: boolean; // Is it mandatory? (default: false)
86
+ default?: unknown; // Default value
87
+ enum?: unknown[]; // Allowed values
88
+ validation?: {
89
+ minLength?: number;
90
+ maxLength?: number;
91
+ min?: number;
92
+ max?: number;
93
+ pattern?: string;
94
+ };
95
+ })
96
+ property: PropertyType;
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Examples
102
+
103
+ ### Calculator Tool
104
+
105
+ ```typescript
106
+ import { tool, param } from 'matimo/decorators';
107
+
108
+ @tool({
109
+ name: 'calculator',
110
+ description: 'Perform basic math operations'
111
+ })
112
+ export class CalculatorTool {
113
+ @param({
114
+ type: 'string',
115
+ description: 'Math operation',
116
+ required: true,
117
+ enum: ['add', 'subtract', 'multiply', 'divide']
118
+ })
119
+ operation: string;
120
+
121
+ @param({
122
+ type: 'number',
123
+ description: 'First operand',
124
+ required: true
125
+ })
126
+ a: number;
127
+
128
+ @param({
129
+ type: 'number',
130
+ description: 'Second operand',
131
+ required: true
132
+ })
133
+ b: number;
134
+
135
+ execute(): { result: number } {
136
+ switch (this.operation) {
137
+ case 'add':
138
+ return { result: this.a + this.b };
139
+ case 'subtract':
140
+ return { result: this.a - this.b };
141
+ case 'multiply':
142
+ return { result: this.a * this.b };
143
+ case 'divide':
144
+ if (this.b === 0) throw new Error('Division by zero');
145
+ return { result: this.a / this.b };
146
+ default:
147
+ throw new Error('Unknown operation');
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ Usage:
154
+
155
+ ```typescript
156
+ const result = await matimo.executeTool('calculator', {
157
+ operation: 'add',
158
+ a: 10,
159
+ b: 5
160
+ });
161
+
162
+ console.log(result); // { result: 15 }
163
+ ```
164
+
165
+ ### Async Tool with HTTP Request
166
+
167
+ ```typescript
168
+ import { tool, param } from 'matimo/decorators';
169
+ import fetch from 'node-fetch';
170
+
171
+ @tool({
172
+ name: 'fetch-user',
173
+ description: 'Fetch user information from an API'
174
+ })
175
+ export class FetchUserTool {
176
+ @param({
177
+ type: 'string',
178
+ description: 'User ID',
179
+ required: true,
180
+ validation: {
181
+ pattern: '^[0-9]+$'
182
+ }
183
+ })
184
+ userId: string;
185
+
186
+ async execute(): Promise<{
187
+ id: number;
188
+ name: string;
189
+ email: string;
190
+ }> {
191
+ const response = await fetch(
192
+ `https://jsonplaceholder.typicode.com/users/${this.userId}`
193
+ );
194
+
195
+ if (!response.ok) {
196
+ throw new Error(`Failed to fetch user: ${response.statusText}`);
197
+ }
198
+
199
+ return await response.json();
200
+ }
201
+ }
202
+ ```
203
+
204
+ ### Tool with Validation
205
+
206
+ ```typescript
207
+ import { tool, param } from 'matimo/decorators';
208
+
209
+ @tool({
210
+ name: 'email-validator',
211
+ description: 'Validate email format'
212
+ })
213
+ export class EmailValidatorTool {
214
+ @param({
215
+ type: 'string',
216
+ description: 'Email address to validate',
217
+ required: true,
218
+ validation: {
219
+ pattern: '^[^@]+@[^@]+\\.[^@]+$'
220
+ }
221
+ })
222
+ email: string;
223
+
224
+ execute(): { valid: boolean; message: string } {
225
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
226
+ const valid = emailRegex.test(this.email);
227
+
228
+ return {
229
+ valid,
230
+ message: valid ? 'Valid email' : 'Invalid email format'
231
+ };
232
+ }
233
+ }
234
+ ```
235
+
236
+ ### Tool with Complex Parameters
237
+
238
+ ```typescript
239
+ import { tool, param } from 'matimo/decorators';
240
+
241
+ @tool({
242
+ name: 'user-create',
243
+ description: 'Create a new user'
244
+ })
245
+ export class UserCreateTool {
246
+ @param({
247
+ type: 'string',
248
+ description: 'User name',
249
+ required: true,
250
+ validation: {
251
+ minLength: 2,
252
+ maxLength: 50
253
+ }
254
+ })
255
+ name: string;
256
+
257
+ @param({
258
+ type: 'string',
259
+ description: 'User email',
260
+ required: true,
261
+ validation: {
262
+ pattern: '^[^@]+@[^@]+\\.[^@]+$'
263
+ }
264
+ })
265
+ email: string;
266
+
267
+ @param({
268
+ type: 'number',
269
+ description: 'User age',
270
+ required: false,
271
+ validation: {
272
+ min: 13,
273
+ max: 120
274
+ }
275
+ })
276
+ age?: number;
277
+
278
+ @param({
279
+ type: 'array',
280
+ description: 'User roles',
281
+ required: false,
282
+ default: ['user']
283
+ })
284
+ roles?: string[];
285
+
286
+ execute(): {
287
+ id: string;
288
+ name: string;
289
+ email: string;
290
+ age?: number;
291
+ roles: string[];
292
+ } {
293
+ return {
294
+ id: `user_${Date.now()}`,
295
+ name: this.name,
296
+ email: this.email,
297
+ age: this.age,
298
+ roles: this.roles || ['user']
299
+ };
300
+ }
301
+ }
302
+ ```
303
+
304
+ ---
305
+
306
+ ## Advanced Features
307
+
308
+ ### Error Handling
309
+
310
+ ```typescript
311
+ import { tool, param } from 'matimo/decorators';
312
+ import { MatimoError, ErrorCode } from 'matimo';
313
+
314
+ @tool({
315
+ name: 'divide',
316
+ description: 'Divide two numbers'
317
+ })
318
+ export class DivideTool {
319
+ @param({
320
+ type: 'number',
321
+ description: 'Dividend',
322
+ required: true
323
+ })
324
+ dividend: number;
325
+
326
+ @param({
327
+ type: 'number',
328
+ description: 'Divisor',
329
+ required: true
330
+ })
331
+ divisor: number;
332
+
333
+ execute(): { result: number } {
334
+ if (this.divisor === 0) {
335
+ throw new MatimoError(
336
+ 'Division by zero not allowed',
337
+ ErrorCode.VALIDATION_FAILED,
338
+ { dividend: this.dividend, divisor: this.divisor }
339
+ );
340
+ }
341
+
342
+ return { result: this.dividend / this.divisor };
343
+ }
344
+ }
345
+ ```
346
+
347
+ ### Type-Safe Results
348
+
349
+ ```typescript
350
+ interface CalculationResult {
351
+ result: number;
352
+ timestamp: string;
353
+ operation: string;
354
+ }
355
+
356
+ @tool({
357
+ name: 'typed-calculator',
358
+ description: 'Type-safe calculator'
359
+ })
360
+ export class TypedCalculatorTool {
361
+ @param({
362
+ type: 'string',
363
+ description: 'Operation',
364
+ required: true,
365
+ enum: ['add', 'subtract']
366
+ })
367
+ operation: string;
368
+
369
+ @param({
370
+ type: 'number',
371
+ description: 'First number',
372
+ required: true
373
+ })
374
+ a: number;
375
+
376
+ @param({
377
+ type: 'number',
378
+ description: 'Second number',
379
+ required: true
380
+ })
381
+ b: number;
382
+
383
+ execute(): CalculationResult {
384
+ let result: number;
385
+
386
+ if (this.operation === 'add') {
387
+ result = this.a + this.b;
388
+ } else {
389
+ result = this.a - this.b;
390
+ }
391
+
392
+ return {
393
+ result,
394
+ timestamp: new Date().toISOString(),
395
+ operation: this.operation
396
+ };
397
+ }
398
+ }
399
+ ```
400
+
401
+ ### Dependency Injection
402
+
403
+ ```typescript
404
+ import { tool, param } from 'matimo/decorators';
405
+
406
+ // Service to inject
407
+ class LoggerService {
408
+ log(message: string): void {
409
+ console.log(`[${new Date().toISOString()}] ${message}`);
410
+ }
411
+ }
412
+
413
+ @tool({
414
+ name: 'logged-operation',
415
+ description: 'Operation with logging'
416
+ })
417
+ export class LoggedOperationTool {
418
+ private logger: LoggerService;
419
+
420
+ constructor(logger: LoggerService) {
421
+ this.logger = logger;
422
+ }
423
+
424
+ @param({
425
+ type: 'string',
426
+ description: 'Operation name',
427
+ required: true
428
+ })
429
+ operation: string;
430
+
431
+ execute(): { success: boolean; message: string } {
432
+ this.logger.log(`Starting operation: ${this.operation}`);
433
+ // ... perform operation ...
434
+ this.logger.log(`Completed operation: ${this.operation}`);
435
+
436
+ return {
437
+ success: true,
438
+ message: `Operation '${this.operation}' completed`
439
+ };
440
+ }
441
+ }
442
+ ```
443
+
444
+ ---
445
+
446
+ ## Decorator vs YAML Comparison
447
+
448
+ ### When to Use Decorators
449
+
450
+ ✅ **Decorators are best for:**
451
+ - Complex business logic
452
+ - Type-safe definitions
453
+ - Reusing existing TypeScript code
454
+ - Tools with dependencies
455
+ - Dynamic behavior
456
+
457
+ ### When to Use YAML
458
+
459
+ ✅ **YAML is best for:**
460
+ - Simple command/HTTP tools
461
+ - Configuration-driven tools
462
+ - Non-technical tool definitions
463
+ - Sharing tools without code
464
+ - External API wrappers
465
+
466
+ ### Example: Decorator vs YAML
467
+
468
+ **Same tool, two approaches:**
469
+
470
+ **Decorator:**
471
+ ```typescript
472
+ @tool({
473
+ name: 'fetch-issue',
474
+ description: 'Fetch GitHub issue by number'
475
+ })
476
+ export class FetchIssueTool {
477
+ @param({
478
+ type: 'string',
479
+ description: 'Repository (owner/repo)',
480
+ required: true
481
+ })
482
+ repo: string;
483
+
484
+ @param({
485
+ type: 'number',
486
+ description: 'Issue number',
487
+ required: true
488
+ })
489
+ number: number;
490
+
491
+ async execute() {
492
+ const [owner, repoName] = this.repo.split('/');
493
+ const response = await fetch(
494
+ `https://api.github.com/repos/${owner}/${repoName}/issues/${this.number}`,
495
+ { headers: { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } }
496
+ );
497
+ return await response.json();
498
+ }
499
+ }
500
+ ```
501
+
502
+ **YAML:**
503
+ ```yaml
504
+ name: fetch-issue
505
+ description: Fetch GitHub issue by number
506
+ version: "1.0.0"
507
+
508
+ parameters:
509
+ repo:
510
+ type: string
511
+ description: Repository (owner/repo)
512
+ required: true
513
+ number:
514
+ type: number
515
+ description: Issue number
516
+ required: true
517
+
518
+ execution:
519
+ type: http
520
+ method: GET
521
+ url: "https://api.github.com/repos/{repo}/issues/{number}"
522
+ auth:
523
+ type: bearer
524
+ secret_env_var: MATIMO_GITHUB_TOKEN
525
+ ```
526
+
527
+ ---
528
+
529
+ ## Best Practices
530
+
531
+ 1. **Naming** — Tool names should be descriptive and kebab-case
532
+ 2. **Validation** — Use validation rules to catch errors early
533
+ 3. **Error Handling** — Return structured errors with context
534
+ 4. **Async Support** — Use `async execute()` for I/O operations
535
+ 5. **Type Safety** — Define proper return types
536
+ 6. **Documentation** — Add JSDoc comments to tools
537
+ 7. **Testing** — Unit test tool logic independently
538
+
539
+ ---
540
+
541
+ ## Testing Decorator Tools
542
+
543
+ ```typescript
544
+ import { CalculatorTool } from './calculator.tool';
545
+
546
+ describe('CalculatorTool', () => {
547
+ let tool: CalculatorTool;
548
+
549
+ beforeEach(() => {
550
+ tool = new CalculatorTool();
551
+ });
552
+
553
+ it('should add two numbers', () => {
554
+ tool.operation = 'add';
555
+ tool.a = 5;
556
+ tool.b = 3;
557
+
558
+ const result = tool.execute();
559
+
560
+ expect(result.result).toBe(8);
561
+ });
562
+
563
+ it('should subtract two numbers', () => {
564
+ tool.operation = 'subtract';
565
+ tool.a = 10;
566
+ tool.b = 3;
567
+
568
+ const result = tool.execute();
569
+
570
+ expect(result.result).toBe(7);
571
+ });
572
+
573
+ it('should throw on division by zero', () => {
574
+ tool.operation = 'divide';
575
+ tool.a = 10;
576
+ tool.b = 0;
577
+
578
+ expect(() => tool.execute()).toThrow('Division by zero');
579
+ });
580
+ });
581
+ ```
582
+
583
+ ---
584
+
585
+ ## Migration from YAML
586
+
587
+ Convert existing YAML tools to decorators:
588
+
589
+ **Before (YAML):**
590
+ ```yaml
591
+ name: echo
592
+ description: Echo input back
593
+ version: "1.0.0"
594
+
595
+ parameters:
596
+ message:
597
+ type: string
598
+ required: true
599
+
600
+ execution:
601
+ type: command
602
+ command: echo
603
+ args: ["{message}"]
604
+ ```
605
+
606
+ **After (Decorator):**
607
+ ```typescript
608
+ @tool({
609
+ name: 'echo',
610
+ description: 'Echo input back'
611
+ })
612
+ export class EchoTool {
613
+ @param({
614
+ type: 'string',
615
+ description: 'Message to echo',
616
+ required: true
617
+ })
618
+ message: string;
619
+
620
+ execute(): { output: string } {
621
+ return { output: this.message };
622
+ }
623
+ }
624
+ ```
625
+
626
+ ---
627
+
628
+ ## See Also
629
+
630
+ - [Quick Start](../getting-started/QUICK_START.md) — Get started in 5 minutes
631
+ - [API Reference](../api-reference/SDK.md) — Complete SDK documentation
632
+ - [Tool Specification](./TOOL_SPECIFICATION.md) — YAML tool schema
633
+ - [CONTRIBUTING.md](../CONTRIBUTING.md) — Development guide
@@ -0,0 +1,5 @@
1
+ OAuth implementation guide (pointer)
2
+
3
+ Original implementation and reference: [OAUTH.md](../architecture/OAUTH.md)
4
+
5
+ This pointer groups OAuth-related material under Tool Development; full migration planned.