@matimo/core 0.1.0-alpha.4
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/dist/src/auth/oauth2-config.d.ts +104 -0
- package/dist/src/auth/oauth2-config.d.ts.map +1 -0
- package/dist/src/auth/oauth2-config.js +38 -0
- package/dist/src/auth/oauth2-config.js.map +1 -0
- package/dist/src/auth/oauth2-handler.d.ts +130 -0
- package/dist/src/auth/oauth2-handler.d.ts.map +1 -0
- package/dist/src/auth/oauth2-handler.js +265 -0
- package/dist/src/auth/oauth2-handler.js.map +1 -0
- package/dist/src/auth/oauth2-provider-loader.d.ts +68 -0
- package/dist/src/auth/oauth2-provider-loader.d.ts.map +1 -0
- package/dist/src/auth/oauth2-provider-loader.js +120 -0
- package/dist/src/auth/oauth2-provider-loader.js.map +1 -0
- package/dist/src/core/schema.d.ts +248 -0
- package/dist/src/core/schema.d.ts.map +1 -0
- package/dist/src/core/schema.js +182 -0
- package/dist/src/core/schema.js.map +1 -0
- package/dist/src/core/tool-loader.d.ts +45 -0
- package/dist/src/core/tool-loader.d.ts.map +1 -0
- package/dist/src/core/tool-loader.js +205 -0
- package/dist/src/core/tool-loader.js.map +1 -0
- package/dist/src/core/tool-registry.d.ts +48 -0
- package/dist/src/core/tool-registry.d.ts.map +1 -0
- package/dist/src/core/tool-registry.js +93 -0
- package/dist/src/core/tool-registry.js.map +1 -0
- package/dist/src/core/types.d.ts +157 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +5 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/decorators/index.d.ts +2 -0
- package/dist/src/decorators/index.d.ts.map +1 -0
- package/dist/src/decorators/index.js +2 -0
- package/dist/src/decorators/index.js.map +1 -0
- package/dist/src/decorators/tool-decorator.d.ts +97 -0
- package/dist/src/decorators/tool-decorator.d.ts.map +1 -0
- package/dist/src/decorators/tool-decorator.js +157 -0
- package/dist/src/decorators/tool-decorator.js.map +1 -0
- package/dist/src/encodings/parameter-encoding.d.ts +51 -0
- package/dist/src/encodings/parameter-encoding.d.ts.map +1 -0
- package/dist/src/encodings/parameter-encoding.js +123 -0
- package/dist/src/encodings/parameter-encoding.js.map +1 -0
- package/dist/src/errors/matimo-error.d.ts +34 -0
- package/dist/src/errors/matimo-error.d.ts.map +1 -0
- package/dist/src/errors/matimo-error.js +49 -0
- package/dist/src/errors/matimo-error.js.map +1 -0
- package/dist/src/executors/command-executor.d.ts +19 -0
- package/dist/src/executors/command-executor.d.ts.map +1 -0
- package/dist/src/executors/command-executor.js +98 -0
- package/dist/src/executors/command-executor.js.map +1 -0
- package/dist/src/executors/function-executor.d.ts +23 -0
- package/dist/src/executors/function-executor.d.ts.map +1 -0
- package/dist/src/executors/function-executor.js +164 -0
- package/dist/src/executors/function-executor.js.map +1 -0
- package/dist/src/executors/http-executor.d.ts +26 -0
- package/dist/src/executors/http-executor.d.ts.map +1 -0
- package/dist/src/executors/http-executor.js +137 -0
- package/dist/src/executors/http-executor.js.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/integrations/langchain.d.ts +46 -0
- package/dist/src/integrations/langchain.d.ts.map +1 -0
- package/dist/src/integrations/langchain.js +197 -0
- package/dist/src/integrations/langchain.js.map +1 -0
- package/dist/src/matimo-instance.d.ts +124 -0
- package/dist/src/matimo-instance.d.ts.map +1 -0
- package/dist/src/matimo-instance.js +313 -0
- package/dist/src/matimo-instance.js.map +1 -0
- package/dist/tools/calculator/calculator.d.ts +26 -0
- package/dist/tools/calculator/calculator.d.ts.map +1 -0
- package/dist/tools/calculator/calculator.js +104 -0
- package/dist/tools/calculator/calculator.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +94 -0
- package/tools/calculator/calculator.ts +125 -0
- package/tools/calculator/definition.yaml +71 -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,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AAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,YAAoB;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,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,248 @@
|
|
|
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
|
+
examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
185
|
+
name: z.ZodString;
|
|
186
|
+
params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
187
|
+
description: z.ZodOptional<z.ZodString>;
|
|
188
|
+
}, z.core.$strip>>>;
|
|
189
|
+
deprecated: z.ZodOptional<z.ZodBoolean>;
|
|
190
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
191
|
+
deprecation_message: z.ZodOptional<z.ZodString>;
|
|
192
|
+
_definitionPath: z.ZodOptional<z.ZodString>;
|
|
193
|
+
}, z.core.$loose>;
|
|
194
|
+
export type ToolDefinition = z.infer<typeof ToolDefinitionSchema>;
|
|
195
|
+
export declare const OAuth2EndpointsSchema: z.ZodObject<{
|
|
196
|
+
authorizationUrl: z.ZodString;
|
|
197
|
+
tokenUrl: z.ZodString;
|
|
198
|
+
revokeUrl: z.ZodOptional<z.ZodString>;
|
|
199
|
+
}, z.core.$strip>;
|
|
200
|
+
export type OAuth2Endpoints = z.infer<typeof OAuth2EndpointsSchema>;
|
|
201
|
+
export declare const ProviderDefinitionSchema: z.ZodObject<{
|
|
202
|
+
name: z.ZodString;
|
|
203
|
+
type: z.ZodLiteral<"provider">;
|
|
204
|
+
version: z.ZodString;
|
|
205
|
+
description: z.ZodOptional<z.ZodString>;
|
|
206
|
+
provider: z.ZodObject<{
|
|
207
|
+
name: z.ZodString;
|
|
208
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
209
|
+
endpoints: z.ZodObject<{
|
|
210
|
+
authorizationUrl: z.ZodString;
|
|
211
|
+
tokenUrl: z.ZodString;
|
|
212
|
+
revokeUrl: z.ZodOptional<z.ZodString>;
|
|
213
|
+
}, z.core.$strip>;
|
|
214
|
+
defaultScopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
215
|
+
documentation: z.ZodOptional<z.ZodString>;
|
|
216
|
+
learnMore: z.ZodOptional<z.ZodString>;
|
|
217
|
+
}, z.core.$strip>;
|
|
218
|
+
}, z.core.$strip>;
|
|
219
|
+
export type ProviderDefinition = z.infer<typeof ProviderDefinitionSchema>;
|
|
220
|
+
/**
|
|
221
|
+
* Validate a tool definition against the schema
|
|
222
|
+
* Provides detailed error messages for validation failures
|
|
223
|
+
*
|
|
224
|
+
* @param tool - Tool definition to validate
|
|
225
|
+
* @returns Validated tool definition
|
|
226
|
+
* @throws {Error} If validation fails with detailed error information
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* try {
|
|
231
|
+
* const tool = validateToolDefinition(parsedYAML);
|
|
232
|
+
* } catch (error) {
|
|
233
|
+
* console.error('Invalid tool:', error.message);
|
|
234
|
+
* // Error message includes specific field and validation issue
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export declare function validateToolDefinition(tool: unknown): ToolDefinition;
|
|
239
|
+
/**
|
|
240
|
+
* Validate a provider definition against the schema
|
|
241
|
+
* Provides detailed error messages for validation failures
|
|
242
|
+
*
|
|
243
|
+
* @param provider - Provider definition to validate
|
|
244
|
+
* @returns Validated provider definition
|
|
245
|
+
* @throws {MatimoError} If validation fails with detailed error information
|
|
246
|
+
*/
|
|
247
|
+
export declare function validateProviderDefinition(provider: unknown): ProviderDefinition;
|
|
248
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AAGH,eAAO,MAAM,eAAe;;;;;;;;;;;;;iBAO1B,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAGxD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;iBAM3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAG1D,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAiChC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,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* 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
|
|
80
|
+
.object({
|
|
81
|
+
name: z.string(),
|
|
82
|
+
description: z.string(),
|
|
83
|
+
version: z.string(),
|
|
84
|
+
parameters: z.record(z.string(), ParameterSchema).optional(),
|
|
85
|
+
execution: ExecutionConfigSchema,
|
|
86
|
+
authentication: AuthConfigSchema.optional(),
|
|
87
|
+
output_schema: OutputSchemaSchema.optional(),
|
|
88
|
+
error_handling: ErrorHandlingSchema.optional(),
|
|
89
|
+
rate_limiting: RateLimitingSchema.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(),
|
|
101
|
+
})
|
|
102
|
+
.passthrough(); // Allow additional properties like _definitionPath
|
|
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
|
+
* try {
|
|
135
|
+
* const tool = validateToolDefinition(parsedYAML);
|
|
136
|
+
* } catch (error) {
|
|
137
|
+
* console.error('Invalid tool:', error.message);
|
|
138
|
+
* // Error message includes specific field and validation issue
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function validateToolDefinition(tool) {
|
|
143
|
+
const result = ToolDefinitionSchema.safeParse(tool);
|
|
144
|
+
if (!result.success) {
|
|
145
|
+
// Format detailed error messages from Zod v4
|
|
146
|
+
const errors = result.error.issues
|
|
147
|
+
.map((issue) => {
|
|
148
|
+
const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
|
|
149
|
+
return ` • ${path}: ${issue.message} (${issue.code})`;
|
|
150
|
+
})
|
|
151
|
+
.join('\n');
|
|
152
|
+
throw new MatimoError(`Tool schema validation failed:\n${errors}`, ErrorCode.INVALID_SCHEMA, {
|
|
153
|
+
issues: result.error.issues,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return result.data;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Validate a provider definition against the schema
|
|
160
|
+
* Provides detailed error messages for validation failures
|
|
161
|
+
*
|
|
162
|
+
* @param provider - Provider definition to validate
|
|
163
|
+
* @returns Validated provider definition
|
|
164
|
+
* @throws {MatimoError} If validation fails with detailed error information
|
|
165
|
+
*/
|
|
166
|
+
export function validateProviderDefinition(provider) {
|
|
167
|
+
const result = ProviderDefinitionSchema.safeParse(provider);
|
|
168
|
+
if (!result.success) {
|
|
169
|
+
// Format detailed error messages from Zod v4
|
|
170
|
+
const errors = result.error.issues
|
|
171
|
+
.map((issue) => {
|
|
172
|
+
const path = issue.path.length > 0 ? issue.path.join('.') : 'root';
|
|
173
|
+
return ` • ${path}: ${issue.message} (${issue.code})`;
|
|
174
|
+
})
|
|
175
|
+
.join('\n');
|
|
176
|
+
throw new MatimoError(`Provider schema validation failed:\n${errors}`, ErrorCode.INVALID_SCHEMA, {
|
|
177
|
+
issues: result.error.issues,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return result.data;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
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AM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;aAC/B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACnE,OAAO,OAAO,IAAI,KAAK,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC;QACzD,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,IAAI,WAAW,CACnB,uCAAuC,MAAM,EAAE,EAC/C,SAAS,CAAC,cAAc,EACxB;YACE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;SAC5B,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
*/
|
|
6
|
+
export declare class ToolLoader {
|
|
7
|
+
/**
|
|
8
|
+
* Load a single tool from a YAML or JSON file
|
|
9
|
+
* @param filePath - Path to tool definition file
|
|
10
|
+
* @returns Validated tool definition
|
|
11
|
+
* @throws {Error} If file not found or invalid schema
|
|
12
|
+
*/
|
|
13
|
+
loadToolFromFile(filePath: string): ToolDefinition;
|
|
14
|
+
/**
|
|
15
|
+
* Load all tools from a directory
|
|
16
|
+
* @param dirPath - Path to directory containing tool files
|
|
17
|
+
* @returns Map of tool names to definitions
|
|
18
|
+
* @note Prefers definition.yaml/definition.json over tool.yaml/tool.json
|
|
19
|
+
*/
|
|
20
|
+
loadToolsFromDirectory(dirPath: string): Map<string, ToolDefinition>;
|
|
21
|
+
/**
|
|
22
|
+
* Load a tool from a JSON object
|
|
23
|
+
* @param data - Tool definition as object
|
|
24
|
+
* @returns Validated tool definition
|
|
25
|
+
*/
|
|
26
|
+
loadToolFromObject(data: unknown): ToolDefinition;
|
|
27
|
+
/**
|
|
28
|
+
* Auto-discover tool packages in node_modules/@matimo/*
|
|
29
|
+
* @returns Array of paths to tool directories
|
|
30
|
+
*/
|
|
31
|
+
autoDiscoverPackages(): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Get node_modules path intelligently
|
|
34
|
+
* Works in both normal and monorepo installations
|
|
35
|
+
*/
|
|
36
|
+
private getNodeModulesPath;
|
|
37
|
+
/**
|
|
38
|
+
* Load tools from multiple directories
|
|
39
|
+
* @param dirPaths - Array of directory paths
|
|
40
|
+
* @returns Combined map of all tools
|
|
41
|
+
*/
|
|
42
|
+
loadToolsFromMultiplePaths(dirPaths: string[]): Map<string, ToolDefinition>;
|
|
43
|
+
}
|
|
44
|
+
export default ToolLoader;
|
|
45
|
+
//# 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;;;GAGG;AAEH,qBAAa,UAAU;IACrB;;;;;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;;;OAGG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAiDhC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;;;OAIG;IACH,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;CAkB5E;AAED,eAAe,UAAU,CAAC"}
|