@matimo/core 0.1.0-alpha.10

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -0
  3. package/destructive-keywords.yaml +70 -0
  4. package/dist/approval/approval-handler.d.ts +74 -0
  5. package/dist/approval/approval-handler.d.ts.map +1 -0
  6. package/dist/approval/approval-handler.js +210 -0
  7. package/dist/approval/approval-handler.js.map +1 -0
  8. package/dist/auth/oauth2-config.d.ts +104 -0
  9. package/dist/auth/oauth2-config.d.ts.map +1 -0
  10. package/dist/auth/oauth2-config.js +38 -0
  11. package/dist/auth/oauth2-config.js.map +1 -0
  12. package/dist/auth/oauth2-handler.d.ts +130 -0
  13. package/dist/auth/oauth2-handler.d.ts.map +1 -0
  14. package/dist/auth/oauth2-handler.js +265 -0
  15. package/dist/auth/oauth2-handler.js.map +1 -0
  16. package/dist/auth/oauth2-provider-loader.d.ts +68 -0
  17. package/dist/auth/oauth2-provider-loader.d.ts.map +1 -0
  18. package/dist/auth/oauth2-provider-loader.js +120 -0
  19. package/dist/auth/oauth2-provider-loader.js.map +1 -0
  20. package/dist/core/schema.d.ts +259 -0
  21. package/dist/core/schema.d.ts.map +1 -0
  22. package/dist/core/schema.js +187 -0
  23. package/dist/core/schema.js.map +1 -0
  24. package/dist/core/tool-loader.d.ts +57 -0
  25. package/dist/core/tool-loader.d.ts.map +1 -0
  26. package/dist/core/tool-loader.js +250 -0
  27. package/dist/core/tool-loader.js.map +1 -0
  28. package/dist/core/tool-registry.d.ts +48 -0
  29. package/dist/core/tool-registry.d.ts.map +1 -0
  30. package/dist/core/tool-registry.js +93 -0
  31. package/dist/core/tool-registry.js.map +1 -0
  32. package/dist/core/types.d.ts +162 -0
  33. package/dist/core/types.d.ts.map +1 -0
  34. package/dist/core/types.js +5 -0
  35. package/dist/core/types.js.map +1 -0
  36. package/dist/decorators/index.d.ts +2 -0
  37. package/dist/decorators/index.d.ts.map +1 -0
  38. package/dist/decorators/index.js +2 -0
  39. package/dist/decorators/index.js.map +1 -0
  40. package/dist/decorators/tool-decorator.d.ts +97 -0
  41. package/dist/decorators/tool-decorator.d.ts.map +1 -0
  42. package/dist/decorators/tool-decorator.js +157 -0
  43. package/dist/decorators/tool-decorator.js.map +1 -0
  44. package/dist/encodings/parameter-encoding.d.ts +51 -0
  45. package/dist/encodings/parameter-encoding.d.ts.map +1 -0
  46. package/dist/encodings/parameter-encoding.js +124 -0
  47. package/dist/encodings/parameter-encoding.js.map +1 -0
  48. package/dist/errors/matimo-error.d.ts +41 -0
  49. package/dist/errors/matimo-error.d.ts.map +1 -0
  50. package/dist/errors/matimo-error.js +71 -0
  51. package/dist/errors/matimo-error.js.map +1 -0
  52. package/dist/executors/command-executor.d.ts +19 -0
  53. package/dist/executors/command-executor.d.ts.map +1 -0
  54. package/dist/executors/command-executor.js +98 -0
  55. package/dist/executors/command-executor.js.map +1 -0
  56. package/dist/executors/function-executor.d.ts +23 -0
  57. package/dist/executors/function-executor.d.ts.map +1 -0
  58. package/dist/executors/function-executor.js +181 -0
  59. package/dist/executors/function-executor.js.map +1 -0
  60. package/dist/executors/http-executor.d.ts +78 -0
  61. package/dist/executors/http-executor.d.ts.map +1 -0
  62. package/dist/executors/http-executor.js +279 -0
  63. package/dist/executors/http-executor.js.map +1 -0
  64. package/dist/index.d.ts +30 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +33 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/integrations/langchain.d.ts +46 -0
  69. package/dist/integrations/langchain.d.ts.map +1 -0
  70. package/dist/integrations/langchain.js +197 -0
  71. package/dist/integrations/langchain.js.map +1 -0
  72. package/dist/logging/index.d.ts +3 -0
  73. package/dist/logging/index.d.ts.map +1 -0
  74. package/dist/logging/index.js +3 -0
  75. package/dist/logging/index.js.map +1 -0
  76. package/dist/logging/logger.d.ts +96 -0
  77. package/dist/logging/logger.d.ts.map +1 -0
  78. package/dist/logging/logger.js +53 -0
  79. package/dist/logging/logger.js.map +1 -0
  80. package/dist/logging/winston-logger.d.ts +29 -0
  81. package/dist/logging/winston-logger.d.ts.map +1 -0
  82. package/dist/logging/winston-logger.js +73 -0
  83. package/dist/logging/winston-logger.js.map +1 -0
  84. package/dist/matimo-instance.d.ts +140 -0
  85. package/dist/matimo-instance.d.ts.map +1 -0
  86. package/dist/matimo-instance.js +412 -0
  87. package/dist/matimo-instance.js.map +1 -0
  88. package/package.json +96 -0
  89. package/tools/calculator/calculator.ts +145 -0
  90. package/tools/calculator/definition.yaml +70 -0
  91. package/tools/edit/definition.yaml +115 -0
  92. package/tools/edit/edit.ts +187 -0
  93. package/tools/execute/definition.yaml +90 -0
  94. package/tools/execute/execute.ts +207 -0
  95. package/tools/read/definition.yaml +106 -0
  96. package/tools/read/read.ts +118 -0
  97. package/tools/search/definition.yaml +148 -0
  98. package/tools/search/search.ts +192 -0
  99. package/tools/web/definition.yaml +132 -0
  100. package/tools/web/web.ts +134 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * OAuth2ProviderLoader - Loads provider definitions from YAML files
3
+ *
4
+ * Pattern: Configuration-driven providers
5
+ * - Loads provider definitions from tools/[provider]/definition.yaml
6
+ * - Discovers providers with type: provider
7
+ * - Makes endpoints available to OAuth2Handler
8
+ * - Supports infinite providers without code changes
9
+ *
10
+ * Usage:
11
+ * ```typescript
12
+ * const loader = new OAuth2ProviderLoader('./tools');
13
+ * const providers = await loader.loadProviders();
14
+ * const googleEndpoints = providers.get('google');
15
+ * ```
16
+ */
17
+ import fs from 'fs/promises';
18
+ import path from 'path';
19
+ import YAML from 'yaml';
20
+ import { MatimoError, ErrorCode } from '../errors/matimo-error';
21
+ import { validateProviderDefinition } from '../core/schema';
22
+ /**
23
+ * OAuth2ProviderLoader - Loads OAuth2 provider configurations from YAML
24
+ *
25
+ * Design Principle:
26
+ * - Configuration-driven: All provider config in YAML files
27
+ * - Discoverable: Automatically finds tools/[provider]/definition.yaml with type: provider
28
+ * - Extensible: Add new providers by adding YAML file, no code changes
29
+ * - Overridable: Users can override via env vars or runtime config
30
+ */
31
+ export class OAuth2ProviderLoader {
32
+ constructor(toolsPath) {
33
+ this.providers = new Map();
34
+ this.definitions = new Map();
35
+ this.toolsPath = toolsPath;
36
+ }
37
+ /**
38
+ * Load all provider definitions from tools directory
39
+ *
40
+ * Discovers tools/[provider]/definition.yaml files with type: provider
41
+ * Validates and stores provider endpoint configurations
42
+ *
43
+ * @returns Map of provider name → OAuth2Endpoints
44
+ * @throws MatimoError if invalid provider definition found
45
+ */
46
+ async loadProviders() {
47
+ try {
48
+ const entries = await fs.readdir(this.toolsPath, { withFileTypes: true });
49
+ for (const entry of entries) {
50
+ if (!entry.isDirectory())
51
+ continue;
52
+ const definitionPath = path.join(this.toolsPath, entry.name, 'definition.yaml');
53
+ try {
54
+ const content = await fs.readFile(definitionPath, 'utf-8');
55
+ const definition = YAML.parse(content);
56
+ // Check if this is a provider definition
57
+ if (definition.type === 'provider') {
58
+ this.validateProviderDefinition(definition);
59
+ this.registerProvider(definition);
60
+ }
61
+ }
62
+ catch {
63
+ // If file doesn't exist or isn't valid YAML, skip silently
64
+ // Not all provider directories will have provider definitions
65
+ }
66
+ }
67
+ return this.providers;
68
+ }
69
+ catch (error) {
70
+ throw new MatimoError('Failed to load OAuth2 provider definitions', ErrorCode.TOOL_NOT_FOUND, {
71
+ toolsPath: this.toolsPath,
72
+ error: error.message,
73
+ });
74
+ }
75
+ }
76
+ /**
77
+ * Get endpoints for a specific provider
78
+ * @param providerName - Name of the provider (e.g., 'google', 'github')
79
+ * @returns OAuth2Endpoints or undefined if provider not found
80
+ */
81
+ getProvider(providerName) {
82
+ return this.providers.get(providerName);
83
+ }
84
+ /**
85
+ * Get full provider definition
86
+ * @param providerName - Name of the provider
87
+ * @returns ProviderDefinition or undefined if provider not found
88
+ */
89
+ getDefinition(providerName) {
90
+ return this.definitions.get(providerName);
91
+ }
92
+ /**
93
+ * List all loaded providers
94
+ */
95
+ listProviders() {
96
+ return Array.from(this.providers.keys());
97
+ }
98
+ /**
99
+ * Validate provider definition structure using Zod schema
100
+ */
101
+ validateProviderDefinition(definition) {
102
+ try {
103
+ // Use Zod schema validation for consistency with tool validation
104
+ validateProviderDefinition(definition);
105
+ }
106
+ catch (error) {
107
+ const message = error instanceof Error ? error.message : String(error);
108
+ throw new MatimoError(`Provider validation failed: ${message}`, ErrorCode.INVALID_SCHEMA);
109
+ }
110
+ }
111
+ /**
112
+ * Register a provider definition
113
+ */
114
+ registerProvider(definition) {
115
+ const providerName = definition.provider.name;
116
+ this.providers.set(providerName, definition.provider.endpoints);
117
+ this.definitions.set(providerName, definition);
118
+ }
119
+ }
120
+ //# sourceMappingURL=oauth2-provider-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2-provider-loader.js","sourceRoot":"","sources":["../../src/auth/oauth2-provider-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,0BAA0B,EAA2B,MAAM,gBAAgB,CAAC;AAErF;;;;;;;;GAQG;AACH,MAAM,OAAO,oBAAoB;IAK/B,YAAY,SAAiB;QAHrB,cAAS,GAAiC,IAAI,GAAG,EAAE,CAAC;QACpD,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;QAG/D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa;QACjB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YAE1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,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACO,0BAA0B,CAAC,UAA8B;QACjE,IAAI,CAAC;YACH,iEAAiE;YACjE,0BAA0B,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,MAAM,IAAI,WAAW,CAAC,+BAA+B,OAAO,EAAE,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,UAA8B;QACrD,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;QAE9C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACjD,CAAC;CACF"}
@@ -0,0 +1,259 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Core Zod validation schemas for all Matimo tool properties.
4
+ * These schemas ensure YAML tools conform to the spec on load.
5
+ */
6
+ export declare const ParameterSchema: z.ZodObject<{
7
+ type: z.ZodEnum<{
8
+ string: "string";
9
+ number: "number";
10
+ boolean: "boolean";
11
+ object: "object";
12
+ array: "array";
13
+ }>;
14
+ description: z.ZodString;
15
+ required: z.ZodOptional<z.ZodBoolean>;
16
+ enum: z.ZodOptional<z.ZodArray<z.ZodAny>>;
17
+ default: z.ZodOptional<z.ZodAny>;
18
+ examples: z.ZodOptional<z.ZodArray<z.ZodAny>>;
19
+ }, z.core.$strip>;
20
+ export type Parameter = z.infer<typeof ParameterSchema>;
21
+ export declare const AuthConfigSchema: z.ZodObject<{
22
+ type: z.ZodOptional<z.ZodEnum<{
23
+ api_key: "api_key";
24
+ oauth2: "oauth2";
25
+ basic: "basic";
26
+ bearer: "bearer";
27
+ custom: "custom";
28
+ }>>;
29
+ location: z.ZodOptional<z.ZodEnum<{
30
+ body: "body";
31
+ header: "header";
32
+ query: "query";
33
+ }>>;
34
+ name: z.ZodOptional<z.ZodString>;
35
+ provider: z.ZodOptional<z.ZodString>;
36
+ required: z.ZodOptional<z.ZodBoolean>;
37
+ }, z.core.$strip>;
38
+ export type AuthConfig = z.infer<typeof AuthConfigSchema>;
39
+ export declare const ExecutionConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
40
+ type: z.ZodLiteral<"command">;
41
+ command: z.ZodString;
42
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
43
+ cwd: z.ZodOptional<z.ZodString>;
44
+ shell: z.ZodOptional<z.ZodBoolean>;
45
+ timeout: z.ZodOptional<z.ZodNumber>;
46
+ }, z.core.$strip>, z.ZodObject<{
47
+ type: z.ZodLiteral<"http">;
48
+ method: z.ZodEnum<{
49
+ GET: "GET";
50
+ POST: "POST";
51
+ PUT: "PUT";
52
+ DELETE: "DELETE";
53
+ PATCH: "PATCH";
54
+ }>;
55
+ url: z.ZodString;
56
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
57
+ body: z.ZodOptional<z.ZodUnknown>;
58
+ query_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
59
+ parameter_encoding: z.ZodOptional<z.ZodArray<z.ZodObject<{
60
+ source: z.ZodArray<z.ZodString>;
61
+ target: z.ZodString;
62
+ encoding: z.ZodString;
63
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
64
+ }, z.core.$strip>>>;
65
+ timeout: z.ZodOptional<z.ZodNumber>;
66
+ }, z.core.$strip>, z.ZodObject<{
67
+ type: z.ZodLiteral<"function">;
68
+ code: z.ZodString;
69
+ timeout: z.ZodOptional<z.ZodNumber>;
70
+ }, z.core.$strip>], "type">;
71
+ export type ExecutionConfig = z.infer<typeof ExecutionConfigSchema>;
72
+ export declare const OutputSchemaSchema: z.ZodObject<{
73
+ type: z.ZodOptional<z.ZodString>;
74
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
75
+ required: z.ZodOptional<z.ZodArray<z.ZodString>>;
76
+ description: z.ZodOptional<z.ZodString>;
77
+ }, z.core.$strip>;
78
+ export type OutputSchema = z.infer<typeof OutputSchemaSchema>;
79
+ export declare const ErrorHandlingSchema: z.ZodObject<{
80
+ retry: z.ZodOptional<z.ZodNumber>;
81
+ backoff_type: z.ZodOptional<z.ZodEnum<{
82
+ exponential: "exponential";
83
+ linear: "linear";
84
+ }>>;
85
+ initial_delay_ms: z.ZodOptional<z.ZodNumber>;
86
+ max_delay_ms: z.ZodOptional<z.ZodNumber>;
87
+ }, z.core.$strip>;
88
+ export type ErrorHandling = z.infer<typeof ErrorHandlingSchema>;
89
+ export declare const RateLimitingSchema: z.ZodObject<{
90
+ enabled: z.ZodOptional<z.ZodBoolean>;
91
+ requests_per_minute: z.ZodOptional<z.ZodNumber>;
92
+ burst_size: z.ZodOptional<z.ZodNumber>;
93
+ quota_per_hour: z.ZodOptional<z.ZodNumber>;
94
+ }, z.core.$strip>;
95
+ export type RateLimiting = z.infer<typeof RateLimitingSchema>;
96
+ export declare const ToolDefinitionSchema: z.ZodObject<{
97
+ name: z.ZodString;
98
+ description: z.ZodString;
99
+ version: z.ZodString;
100
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
101
+ type: z.ZodEnum<{
102
+ string: "string";
103
+ number: "number";
104
+ boolean: "boolean";
105
+ object: "object";
106
+ array: "array";
107
+ }>;
108
+ description: z.ZodString;
109
+ required: z.ZodOptional<z.ZodBoolean>;
110
+ enum: z.ZodOptional<z.ZodArray<z.ZodAny>>;
111
+ default: z.ZodOptional<z.ZodAny>;
112
+ examples: z.ZodOptional<z.ZodArray<z.ZodAny>>;
113
+ }, z.core.$strip>>>;
114
+ execution: z.ZodDiscriminatedUnion<[z.ZodObject<{
115
+ type: z.ZodLiteral<"command">;
116
+ command: z.ZodString;
117
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
+ cwd: z.ZodOptional<z.ZodString>;
119
+ shell: z.ZodOptional<z.ZodBoolean>;
120
+ timeout: z.ZodOptional<z.ZodNumber>;
121
+ }, z.core.$strip>, z.ZodObject<{
122
+ type: z.ZodLiteral<"http">;
123
+ method: z.ZodEnum<{
124
+ GET: "GET";
125
+ POST: "POST";
126
+ PUT: "PUT";
127
+ DELETE: "DELETE";
128
+ PATCH: "PATCH";
129
+ }>;
130
+ url: z.ZodString;
131
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
132
+ body: z.ZodOptional<z.ZodUnknown>;
133
+ query_params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
134
+ parameter_encoding: z.ZodOptional<z.ZodArray<z.ZodObject<{
135
+ source: z.ZodArray<z.ZodString>;
136
+ target: z.ZodString;
137
+ encoding: z.ZodString;
138
+ options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
139
+ }, z.core.$strip>>>;
140
+ timeout: z.ZodOptional<z.ZodNumber>;
141
+ }, z.core.$strip>, z.ZodObject<{
142
+ type: z.ZodLiteral<"function">;
143
+ code: z.ZodString;
144
+ timeout: z.ZodOptional<z.ZodNumber>;
145
+ }, z.core.$strip>], "type">;
146
+ authentication: z.ZodOptional<z.ZodObject<{
147
+ type: z.ZodOptional<z.ZodEnum<{
148
+ api_key: "api_key";
149
+ oauth2: "oauth2";
150
+ basic: "basic";
151
+ bearer: "bearer";
152
+ custom: "custom";
153
+ }>>;
154
+ location: z.ZodOptional<z.ZodEnum<{
155
+ body: "body";
156
+ header: "header";
157
+ query: "query";
158
+ }>>;
159
+ name: z.ZodOptional<z.ZodString>;
160
+ provider: z.ZodOptional<z.ZodString>;
161
+ required: z.ZodOptional<z.ZodBoolean>;
162
+ }, z.core.$strip>>;
163
+ output_schema: z.ZodOptional<z.ZodObject<{
164
+ type: z.ZodOptional<z.ZodString>;
165
+ properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
166
+ required: z.ZodOptional<z.ZodArray<z.ZodString>>;
167
+ description: z.ZodOptional<z.ZodString>;
168
+ }, z.core.$strip>>;
169
+ error_handling: z.ZodOptional<z.ZodObject<{
170
+ retry: z.ZodOptional<z.ZodNumber>;
171
+ backoff_type: z.ZodOptional<z.ZodEnum<{
172
+ exponential: "exponential";
173
+ linear: "linear";
174
+ }>>;
175
+ initial_delay_ms: z.ZodOptional<z.ZodNumber>;
176
+ max_delay_ms: z.ZodOptional<z.ZodNumber>;
177
+ }, z.core.$strip>>;
178
+ rate_limiting: z.ZodOptional<z.ZodObject<{
179
+ enabled: z.ZodOptional<z.ZodBoolean>;
180
+ requests_per_minute: z.ZodOptional<z.ZodNumber>;
181
+ burst_size: z.ZodOptional<z.ZodNumber>;
182
+ quota_per_hour: z.ZodOptional<z.ZodNumber>;
183
+ }, z.core.$strip>>;
184
+ requires_approval: z.ZodOptional<z.ZodBoolean>;
185
+ examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
186
+ name: z.ZodString;
187
+ params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
188
+ description: z.ZodOptional<z.ZodString>;
189
+ }, z.core.$strip>>>;
190
+ deprecated: z.ZodOptional<z.ZodBoolean>;
191
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
192
+ deprecation_message: z.ZodOptional<z.ZodString>;
193
+ }, z.core.$strip>;
194
+ export type ToolDefinition = z.infer<typeof ToolDefinitionSchema> & {
195
+ /**
196
+ * Internal metadata indicating where this tool definition was loaded from.
197
+ * Not part of the external schema; added programmatically after validation.
198
+ */
199
+ _definitionPath?: string;
200
+ };
201
+ export declare const OAuth2EndpointsSchema: z.ZodObject<{
202
+ authorizationUrl: z.ZodString;
203
+ tokenUrl: z.ZodString;
204
+ revokeUrl: z.ZodOptional<z.ZodString>;
205
+ }, z.core.$strip>;
206
+ export type OAuth2Endpoints = z.infer<typeof OAuth2EndpointsSchema>;
207
+ export declare const ProviderDefinitionSchema: z.ZodObject<{
208
+ name: z.ZodString;
209
+ type: z.ZodLiteral<"provider">;
210
+ version: z.ZodString;
211
+ description: z.ZodOptional<z.ZodString>;
212
+ provider: z.ZodObject<{
213
+ name: z.ZodString;
214
+ displayName: z.ZodOptional<z.ZodString>;
215
+ endpoints: z.ZodObject<{
216
+ authorizationUrl: z.ZodString;
217
+ tokenUrl: z.ZodString;
218
+ revokeUrl: z.ZodOptional<z.ZodString>;
219
+ }, z.core.$strip>;
220
+ defaultScopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
221
+ documentation: z.ZodOptional<z.ZodString>;
222
+ learnMore: z.ZodOptional<z.ZodString>;
223
+ }, z.core.$strip>;
224
+ }, z.core.$strip>;
225
+ export type ProviderDefinition = z.infer<typeof ProviderDefinitionSchema>;
226
+ /**
227
+ * Validate a tool definition against the schema
228
+ * Provides detailed error messages for validation failures
229
+ *
230
+ * @param tool - Tool definition to validate
231
+ * @returns Validated tool definition
232
+ * @throws {Error} If validation fails with detailed error information
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * import { getGlobalMatimoLogger } from '../logging';
237
+ *
238
+ * try {
239
+ * const tool = validateToolDefinition(parsedYAML);
240
+ * } catch (error) {
241
+ * const logger = getGlobalMatimoLogger();
242
+ * logger.error('Invalid tool definition', {
243
+ * details: error.message
244
+ * });
245
+ * throw error;
246
+ * }
247
+ * ```
248
+ */
249
+ export declare function validateToolDefinition(tool: unknown): ToolDefinition;
250
+ /**
251
+ * Validate a provider definition against the schema
252
+ * Provides detailed error messages for validation failures
253
+ *
254
+ * @param provider - Provider definition to validate
255
+ * @returns Validated provider definition
256
+ * @throws {MatimoError} If validation fails with detailed error information
257
+ */
258
+ export declare function validateProviderDefinition(provider: unknown): ProviderDefinition;
259
+ //# sourceMappingUR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AGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAKF,eAAO,MAAM,qBAAqB;;;;iBAIhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAGpE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;iBAanC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAkBpE;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,OAAO,GAAG,kBAAkB,CAsBhF"}
@@ -0,0 +1,187 @@
1
+ import { z } from 'zod';
2
+ import { MatimoError, ErrorCode } from '../errors/matimo-error';
3
+ /**
4
+ * Core Zod validation schemas for all Matimo tool properties.
5
+ * These schemas ensure YAML tools conform to the spec on load.
6
+ */
7
+ // Parameter types that tools can define
8
+ export const ParameterSchema = z.object({
9
+ type: z.enum(['string', 'number', 'boolean', 'array', 'object']),
10
+ description: z.string(),
11
+ required: z.boolean().optional(),
12
+ enum: z.array(z.any()).optional(),
13
+ default: z.any().optional(),
14
+ examples: z.array(z.any()).optional(),
15
+ });
16
+ // Authentication configuration
17
+ export const AuthConfigSchema = z.object({
18
+ type: z.enum(['api_key', 'basic', 'bearer', 'oauth2', 'custom']).optional(),
19
+ location: z.enum(['header', 'query', 'body']).optional(),
20
+ name: z.string().optional(),
21
+ provider: z.string().optional(),
22
+ required: z.boolean().optional(),
23
+ });
24
+ // Execution configuration (command, HTTP, or function)
25
+ export const ExecutionConfigSchema = z.discriminatedUnion('type', [
26
+ z.object({
27
+ type: z.literal('command'),
28
+ command: z.string(),
29
+ args: z.array(z.string()).optional(),
30
+ cwd: z.string().optional(),
31
+ shell: z.boolean().optional(),
32
+ timeout: z.number().optional(),
33
+ }),
34
+ z.object({
35
+ type: z.literal('http'),
36
+ method: z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']),
37
+ url: z.string(),
38
+ headers: z.record(z.string(), z.string()).optional(),
39
+ body: z.unknown().optional(),
40
+ query_params: z.record(z.string(), z.string()).optional(),
41
+ parameter_encoding: z
42
+ .array(z.object({
43
+ source: z.array(z.string()),
44
+ target: z.string(),
45
+ encoding: z.string(),
46
+ options: z.record(z.string(), z.unknown()).optional(),
47
+ }))
48
+ .optional(),
49
+ timeout: z.number().optional(),
50
+ }),
51
+ z.object({
52
+ type: z.literal('function'),
53
+ code: z.string(),
54
+ timeout: z.number().optional(),
55
+ }),
56
+ ]);
57
+ // Output schema for validation
58
+ export const OutputSchemaSchema = z.object({
59
+ type: z.string().optional(),
60
+ properties: z.record(z.string(), z.unknown()).optional(),
61
+ required: z.array(z.string()).optional(),
62
+ description: z.string().optional(),
63
+ });
64
+ // Error handling configuration
65
+ export const ErrorHandlingSchema = z.object({
66
+ retry: z.number().optional(),
67
+ backoff_type: z.enum(['linear', 'exponential']).optional(),
68
+ initial_delay_ms: z.number().optional(),
69
+ max_delay_ms: z.number().optional(),
70
+ });
71
+ // Rate limiting configuration
72
+ export const RateLimitingSchema = z.object({
73
+ enabled: z.boolean().optional(),
74
+ requests_per_minute: z.number().optional(),
75
+ burst_size: z.number().optional(),
76
+ quota_per_hour: z.number().optional(),
77
+ });
78
+ // Complete tool definition
79
+ export const ToolDefinitionSchema = z.object({
80
+ name: z.string(),
81
+ description: z.string(),
82
+ version: z.string(),
83
+ parameters: z.record(z.string(), ParameterSchema).optional(),
84
+ execution: ExecutionConfigSchema,
85
+ authentication: AuthConfigSchema.optional(),
86
+ output_schema: OutputSchemaSchema.optional(),
87
+ error_handling: ErrorHandlingSchema.optional(),
88
+ rate_limiting: RateLimitingSchema.optional(),
89
+ requires_approval: z.boolean().optional(),
90
+ examples: z
91
+ .array(z.object({
92
+ name: z.string(),
93
+ params: z.record(z.string(), z.unknown()),
94
+ description: z.string().optional(),
95
+ }))
96
+ .optional(),
97
+ deprecated: z.boolean().optional(),
98
+ tags: z.array(z.string()).optional(),
99
+ deprecation_message: z.string().optional(),
100
+ // _definitionPath: z.string().optional(), // Internal use for tracking source file path
101
+ });
102
+ // export type ToolDefinition = z.infer<typeof ToolDefinitionSchema>;
103
+ // OAuth2 provider endpoints schema
104
+ export const OAuth2EndpointsSchema = z.object({
105
+ authorizationUrl: z.string().url(),
106
+ tokenUrl: z.string().url(),
107
+ revokeUrl: z.string().url().optional(),
108
+ });
109
+ // Provider definition schema
110
+ export const ProviderDefinitionSchema = z.object({
111
+ name: z.string(),
112
+ type: z.literal('provider'),
113
+ version: z.string(),
114
+ description: z.string().optional(),
115
+ provider: z.object({
116
+ name: z.string(),
117
+ displayName: z.string().optional(),
118
+ endpoints: OAuth2EndpointsSchema,
119
+ defaultScopes: z.array(z.string()).optional(),
120
+ documentation: z.string().url().optional(),
121
+ learnMore: z.string().url().optional(),
122
+ }),
123
+ });
124
+ /**
125
+ * Validate a tool definition against the schema
126
+ * Provides detailed error messages for validation failures
127
+ *
128
+ * @param tool - Tool definition to validate
129
+ * @returns Validated tool definition
130
+ * @throws {Error} If validation fails with detailed error information
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * import { getGlobalMatimoLogger } from '../logging';
135
+ *
136
+ * try {
137
+ * const tool = validateToolDefinition(parsedYAML);
138
+ * } catch (error) {
139
+ * const logger = getGlobalMatimoLogger();
140
+ * logger.error('Invalid tool definition', {
141
+ * details: error.message
142
+ * });
143
+ * throw error;
144
+ * }
145
+ * ```
146
+ */
147
+ export function validateToolDefinition(tool) {
148
+ const result = ToolDefinitionSchema.safeParse(tool);
149
+ if (!result.success) {
150
+ // Format detailed error messages from Zod v4
151
+ const errors = result.error.issues
152
+ .map((issue) => {
153
+ const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
154
+ return ` • ${path}: ${issue.message} (${issue.code})`;
155
+ })
156
+ .join('\n');
157
+ throw new MatimoError(`Tool schema validation failed:\n${errors}`, ErrorCode.INVALID_SCHEMA, {
158
+ issues: result.error.issues,
159
+ });
160
+ }
161
+ return result.data;
162
+ }
163
+ /**
164
+ * Validate a provider definition against the schema
165
+ * Provides detailed error messages for validation failures
166
+ *
167
+ * @param provider - Provider definition to validate
168
+ * @returns Validated provider definition
169
+ * @throws {MatimoError} If validation fails with detailed error information
170
+ */
171
+ export function validateProviderDefinition(provider) {
172
+ const result = ProviderDefinitionSchema.safeParse(provider);
173
+ if (!result.success) {
174
+ // Format detailed error messages from Zod v4
175
+ const errors = result.error.issues
176
+ .map((issue) => {
177
+ const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
178
+ return ` • ${path}: ${issue.message} (${issue.code})`;
179
+ })
180
+ .join('\n');
181
+ throw new MatimoError(`Provider schema validation failed:\n${errors}`, ErrorCode.INVALID_SCHEMA, {
182
+ issues: result.error.issues,
183
+ });
184
+ }
185
+ return result.data;
186
+ }
187
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;GAGG;AAEH,wCAAwC;AACxC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAChC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,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C,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { ToolDefinition } from './schema';
2
+ /**
3
+ * Tool Loader - Loads and validates YAML/JSON tool definitions
4
+ * Implements TDD pattern: test failures guide implementation
5
+ * Features caching for efficient discovery with thousands of tools
6
+ */
7
+ export declare class ToolLoader {
8
+ /**
9
+ * Static cache for discovered paths - populated on first autoDiscover call
10
+ * Subsequent calls return cached result (O(1) instead of O(n))
11
+ */
12
+ private static discoveredPathsCache;
13
+ /**
14
+ * Discover packages using only fs and path (no createRequire needed)
15
+ * Searches for tools in node_modules/@matimo/* and workspace packages
16
+ */
17
+ private getNodeModulesPath;
18
+ /**
19
+ * Load a single tool from a YAML or JSON file
20
+ * @param filePath - Path to tool definition file
21
+ * @returns Validated tool definition
22
+ * @throws {Error} If file not found or invalid schema
23
+ */
24
+ loadToolFromFile(filePath: string): ToolDefinition;
25
+ /**
26
+ * Load all tools from a directory
27
+ * @param dirPath - Path to directory containing tool files
28
+ * @returns Map of tool names to definitions
29
+ * @note Prefers definition.yaml/definition.json over tool.yaml/tool.json
30
+ */
31
+ loadToolsFromDirectory(dirPath: string): Map<string, ToolDefinition>;
32
+ /**
33
+ * Load a tool from a JSON object
34
+ * @param data - Tool definition as object
35
+ * @returns Validated tool definition
36
+ */
37
+ loadToolFromObject(data: unknown): ToolDefinition;
38
+ /**
39
+ * Auto-discover tool packages in node_modules/@matimo/* and core tools
40
+ * Features efficient caching: first call discovers, subsequent calls return cached result
41
+ * @returns Array of paths to tool directories
42
+ */
43
+ autoDiscoverPackages(): string[];
44
+ /**
45
+ * Clear the discovery cache (useful for testing or dynamic tool loading scenarios)
46
+ * @internal Used for testing only
47
+ */
48
+ static clearDiscoveryCache(): void;
49
+ /**
50
+ * Load tools from multiple directories
51
+ * @param dirPaths - Array of directory paths
52
+ * @returns Combined map of all tools
53
+ */
54
+ loadToolsFromMultiplePaths(dirPaths: string[]): Map<string, ToolDefinition>;
55
+ }
56
+ export default ToolLoader;
57
+ //# sourceMappingURL=tool-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-loader.d.ts","sourceRoot":"","sources":["../../src/core/tool-loader.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAA0B,MAAM,UAAU,CAAC;AAGlE;;;;GAIG;AAEH,qBAAa,UAAU;IACrB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAyB;IAC5D;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;IAgDlD;;;;;OAKG;IACH,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;IAkDpE;;;;OAIG;IACH,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc;IAIjD;;;;OAIG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAkFhC;;;OAGG;IACH,MAAM,CAAC,mBAAmB,IAAI,IAAI;IAIlC;;;;OAIG;IACH,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;CAkB5E;AAED,eAAe,UAAU,CAAC"}