@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,157 @@
|
|
|
1
|
+
import { MatimoError, ErrorCode } from '../errors/matimo-error';
|
|
2
|
+
/**
|
|
3
|
+
* Global Matimo instance for decorator usage
|
|
4
|
+
* Set via setGlobalMatimoInstance() before using @tool decorators
|
|
5
|
+
*/
|
|
6
|
+
let globalMatimoInstance = null;
|
|
7
|
+
/**
|
|
8
|
+
* Set the global Matimo instance for decorator usage
|
|
9
|
+
*
|
|
10
|
+
* Must be called before any @tool decorated methods are invoked
|
|
11
|
+
*
|
|
12
|
+
* @param instance - The MatimoInstance to use globally
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const matimo = await MatimoInstance.init('./tools');
|
|
17
|
+
* setGlobalMatimoInstance(matimo);
|
|
18
|
+
*
|
|
19
|
+
* class MyAgent {
|
|
20
|
+
* @tool('calculator')
|
|
21
|
+
* async calculate(operation: string, a: number, b: number) { }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* const agent = new MyAgent();
|
|
25
|
+
* await agent.calculate('add', 5, 3);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function setGlobalMatimoInstance(instance) {
|
|
29
|
+
globalMatimoInstance = instance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the global Matimo instance
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} If no global instance is set
|
|
35
|
+
*/
|
|
36
|
+
export function getGlobalMatimoInstance() {
|
|
37
|
+
if (!globalMatimoInstance) {
|
|
38
|
+
throw new MatimoError('Global MatimoInstance not set. Call setGlobalMatimoInstance() before using @tool decorator.', ErrorCode.TOOL_NOT_FOUND);
|
|
39
|
+
}
|
|
40
|
+
return globalMatimoInstance;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Tool decorator - transforms a method into a tool executor
|
|
44
|
+
*
|
|
45
|
+
* Automatically calls matimo.execute() with the method's arguments mapped to tool parameters.
|
|
46
|
+
* Must be used in a class that has a `matimo` property or after setGlobalMatimoInstance() is called.
|
|
47
|
+
*
|
|
48
|
+
* Works with both traditional and modern TypeScript decorator syntax.
|
|
49
|
+
*
|
|
50
|
+
* @param toolName - Name of the tool to execute (e.g., 'calculator', 'github-get-repo')
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // Using global instance
|
|
55
|
+
* const matimo = await MatimoInstance.init('./tools');
|
|
56
|
+
* setGlobalMatimoInstance(matimo);
|
|
57
|
+
*
|
|
58
|
+
* class MyAgent {
|
|
59
|
+
* @tool('calculator')
|
|
60
|
+
* async calculate(operation: string, a: number, b: number) {
|
|
61
|
+
* // Automatically executes: matimo.execute('calculator', { operation, a, b })
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* @tool('github-get-repo')
|
|
65
|
+
* async getRepo(owner: string, repo: string) {
|
|
66
|
+
* // Automatically executes: matimo.execute('github-get-repo', { owner, repo })
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* const agent = new MyAgent();
|
|
71
|
+
* const result = await agent.calculate('add', 5, 3);
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Using instance property
|
|
77
|
+
* class MyAgent {
|
|
78
|
+
* constructor(public matimo: MatimoInstance) {}
|
|
79
|
+
*
|
|
80
|
+
* @tool('calculator')
|
|
81
|
+
* async calculate(operation: string, a: number, b: number) { }
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* const matimo = await MatimoInstance.init('./tools');
|
|
85
|
+
* const agent = new MyAgent(matimo);
|
|
86
|
+
* const result = await agent.calculate('add', 5, 3);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export function tool(toolName) {
|
|
90
|
+
return function (_target,
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
_context) {
|
|
93
|
+
// Handle modern experimental decorator API
|
|
94
|
+
// The decorator can be used on methods and will receive the method and context
|
|
95
|
+
// Return a new function that intercepts the call
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
return async function (...args) {
|
|
98
|
+
return executeToolViaDecorator(toolName, this, args);
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Execute tool via decorator - shared logic for both decorator syntaxes
|
|
104
|
+
* Exported for testing purposes
|
|
105
|
+
*/
|
|
106
|
+
export async function executeToolViaDecorator(toolName, thisArg,
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
args) {
|
|
109
|
+
// Get Matimo instance (from class property or global)
|
|
110
|
+
let matimoInstance = null;
|
|
111
|
+
if (thisArg && typeof thisArg === 'object' && 'matimo' in thisArg) {
|
|
112
|
+
matimoInstance = thisArg.matimo || null;
|
|
113
|
+
}
|
|
114
|
+
if (!matimoInstance) {
|
|
115
|
+
matimoInstance = globalMatimoInstance;
|
|
116
|
+
}
|
|
117
|
+
if (!matimoInstance) {
|
|
118
|
+
throw new MatimoError(`Matimo instance not found for @tool('${toolName}') decorator. ` +
|
|
119
|
+
`Either add matimo property to class or call setGlobalMatimoInstance() first.`, ErrorCode.TOOL_NOT_FOUND, { toolName });
|
|
120
|
+
}
|
|
121
|
+
// Get tool definition
|
|
122
|
+
const toolDef = matimoInstance.getTool(toolName);
|
|
123
|
+
if (!toolDef) {
|
|
124
|
+
throw new MatimoError(`Tool '${toolName}' not found in Matimo registry`, ErrorCode.TOOL_NOT_FOUND, {
|
|
125
|
+
toolName,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Convert positional arguments to parameters object
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
const params = convertArgsToParams(args, toolDef);
|
|
131
|
+
// Execute tool via Matimo
|
|
132
|
+
return matimoInstance.execute(toolName, params);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Convert positional arguments to named parameters object
|
|
136
|
+
* Maps function arguments to tool parameter names in order
|
|
137
|
+
* Exported for testing purposes
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```
|
|
141
|
+
* Tool has parameters: { operation, a, b }
|
|
142
|
+
* Args: ['add', 5, 3]
|
|
143
|
+
* Result: { operation: 'add', a: 5, b: 3 }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export function convertArgsToParams(args, toolDef) {
|
|
147
|
+
const params = {};
|
|
148
|
+
if (!toolDef.parameters) {
|
|
149
|
+
return params;
|
|
150
|
+
}
|
|
151
|
+
const paramNames = Object.keys(toolDef.parameters);
|
|
152
|
+
for (let i = 0; i < args.length && i < paramNames.length; i++) {
|
|
153
|
+
params[paramNames[i]] = args[i];
|
|
154
|
+
}
|
|
155
|
+
return params;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=tool-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-decorator.js","sourceRoot":"","sources":["../../../src/decorators/tool-decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;GAGG;AACH,IAAI,oBAAoB,GAA0B,IAAI,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAA+B;IACrE,oBAAoB,GAAG,QAAQ,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,MAAM,IAAI,WAAW,CACnB,6FAA6F,EAC7F,SAAS,CAAC,cAAc,CACzB,CAAC;IACJ,CAAC;IACD,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UA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,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC;AACD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAe,EACf,OAAuB;IAEvB,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9D,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic parameter encoding system for transforming input parameters
|
|
3
|
+
* Used to convert structured parameters into API-specific formats (MIME, JSON, etc.)
|
|
4
|
+
*
|
|
5
|
+
* This is YAML-driven via the parameter_encoding directive in tool definitions.
|
|
6
|
+
* No tool-specific code needed - keeps Matimo universal.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Encoding configuration from YAML
|
|
10
|
+
*/
|
|
11
|
+
export interface ParameterEncodingConfig {
|
|
12
|
+
source: string[];
|
|
13
|
+
target: string;
|
|
14
|
+
encoding: string;
|
|
15
|
+
options?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Apply parameter encodings to transform input parameters
|
|
19
|
+
* @param params - User-provided parameters
|
|
20
|
+
* @param encodings - List of encoding configurations from tool YAML
|
|
21
|
+
* @returns Parameters with encoded values added
|
|
22
|
+
*/
|
|
23
|
+
export declare function applyParameterEncodings(params: Record<string, unknown>, encodings: ParameterEncodingConfig[]): Record<string, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Example usage in YAML:
|
|
26
|
+
*
|
|
27
|
+
* execution:
|
|
28
|
+
* type: http
|
|
29
|
+
* method: POST
|
|
30
|
+
* url: 'https://www.googleapis.com/gmail/v1/users/me/messages/send'
|
|
31
|
+
* headers:
|
|
32
|
+
* Content-Type: 'application/json'
|
|
33
|
+
* Authorization: 'Bearer {GMAIL_ACCESS_TOKEN}'
|
|
34
|
+
*
|
|
35
|
+
* parameter_encoding:
|
|
36
|
+
* - source: [to, subject, body, cc, bcc, is_html]
|
|
37
|
+
* target: raw
|
|
38
|
+
* encoding: mime_rfc2822_base64url
|
|
39
|
+
*
|
|
40
|
+
* body:
|
|
41
|
+
* raw: '{raw}'
|
|
42
|
+
*
|
|
43
|
+
* Then users call:
|
|
44
|
+
* matimo.execute('gmail-send-email', {
|
|
45
|
+
* to: 'user@example.com',
|
|
46
|
+
* subject: 'Hello',
|
|
47
|
+
* body: 'Hi there',
|
|
48
|
+
* GMAIL_ACCESS_TOKEN: token
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
//# sourceMappingURL=parameter-encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-encoding.d.ts","sourceRoot":"","sources":["../../../src/encodings/parameter-encoding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,EAAE,uBAAuB,EAAE,GACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBzB;AAkFD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic parameter encoding system for transforming input parameters
|
|
3
|
+
* Used to convert structured parameters into API-specific formats (MIME, JSON, etc.)
|
|
4
|
+
*
|
|
5
|
+
* This is YAML-driven via the parameter_encoding directive in tool definitions.
|
|
6
|
+
* No tool-specific code needed - keeps Matimo universal.
|
|
7
|
+
*/
|
|
8
|
+
import { MatimoError, ErrorCode } from '../errors/matimo-error';
|
|
9
|
+
/**
|
|
10
|
+
* Apply parameter encodings to transform input parameters
|
|
11
|
+
* @param params - User-provided parameters
|
|
12
|
+
* @param encodings - List of encoding configurations from tool YAML
|
|
13
|
+
* @returns Parameters with encoded values added
|
|
14
|
+
*/
|
|
15
|
+
export function applyParameterEncodings(params, encodings) {
|
|
16
|
+
const result = { ...params };
|
|
17
|
+
for (const config of encodings) {
|
|
18
|
+
// Extract source parameters
|
|
19
|
+
const sourceValues = {};
|
|
20
|
+
for (const key of config.source) {
|
|
21
|
+
if (key in params) {
|
|
22
|
+
sourceValues[key] = params[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Apply encoding function
|
|
26
|
+
const encodedValue = encodeParameters(sourceValues, config.encoding, config.options);
|
|
27
|
+
// Store in target parameter
|
|
28
|
+
result[config.target] = encodedValue;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Route to specific encoding function based on type
|
|
34
|
+
*/
|
|
35
|
+
function encodeParameters(sourceValues, encoding, _options) {
|
|
36
|
+
switch (encoding) {
|
|
37
|
+
case 'mime_rfc2822_base64url':
|
|
38
|
+
return encodeMimeRfc2822(sourceValues);
|
|
39
|
+
case 'json_compact':
|
|
40
|
+
return JSON.stringify(sourceValues);
|
|
41
|
+
case 'url_encoded':
|
|
42
|
+
return encodeUrlParams(sourceValues);
|
|
43
|
+
default:
|
|
44
|
+
throw new MatimoError(`Unknown parameter encoding type: ${encoding}`, ErrorCode.INVALID_PARAMETER, {
|
|
45
|
+
encodingType: encoding,
|
|
46
|
+
supportedTypes: ['mime_rfc2822_base64url', 'json_compact', 'url_encoded'],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Encode parameters as RFC 2822 MIME message with base64url encoding
|
|
52
|
+
* Used for Gmail and other email APIs that accept raw MIME format
|
|
53
|
+
*/
|
|
54
|
+
function encodeMimeRfc2822(sourceValues) {
|
|
55
|
+
const to = sourceValues.to;
|
|
56
|
+
const subject = sourceValues.subject;
|
|
57
|
+
const body = sourceValues.body;
|
|
58
|
+
const cc = sourceValues.cc;
|
|
59
|
+
const bcc = sourceValues.bcc;
|
|
60
|
+
const isHtml = sourceValues.is_html || false;
|
|
61
|
+
if (!to || !subject || !body) {
|
|
62
|
+
throw new MatimoError('MIME encoding requires: to, subject, body parameters', ErrorCode.INVALID_PARAMETER, {
|
|
63
|
+
requiredFields: ['to', 'subject', 'body'],
|
|
64
|
+
providedFields: Object.keys(sourceValues),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Build RFC 2822 MIME message
|
|
68
|
+
let message = '';
|
|
69
|
+
message += `To: ${to}\r\n`;
|
|
70
|
+
message += `Subject: ${subject}\r\n`;
|
|
71
|
+
if (cc)
|
|
72
|
+
message += `Cc: ${cc}\r\n`;
|
|
73
|
+
if (bcc)
|
|
74
|
+
message += `Bcc: ${bcc}\r\n`;
|
|
75
|
+
message += `Content-Type: ${isHtml ? 'text/html' : 'text/plain'}; charset="UTF-8"\r\n`;
|
|
76
|
+
message += 'Content-Transfer-Encoding: 7bit\r\n';
|
|
77
|
+
message += '\r\n'; // Empty line separates headers from body
|
|
78
|
+
message += body;
|
|
79
|
+
// Convert to base64url
|
|
80
|
+
const base64 = Buffer.from(message).toString('base64');
|
|
81
|
+
// Replace standard base64 characters with URL-safe variants
|
|
82
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Encode parameters as URL-encoded form data
|
|
86
|
+
*/
|
|
87
|
+
function encodeUrlParams(sourceValues) {
|
|
88
|
+
const params = new URLSearchParams();
|
|
89
|
+
for (const [key, value] of Object.entries(sourceValues)) {
|
|
90
|
+
if (value !== undefined && value !== null) {
|
|
91
|
+
params.append(key, String(value));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return params.toString();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Example usage in YAML:
|
|
98
|
+
*
|
|
99
|
+
* execution:
|
|
100
|
+
* type: http
|
|
101
|
+
* method: POST
|
|
102
|
+
* url: 'https://www.googleapis.com/gmail/v1/users/me/messages/send'
|
|
103
|
+
* headers:
|
|
104
|
+
* Content-Type: 'application/json'
|
|
105
|
+
* Authorization: 'Bearer {GMAIL_ACCESS_TOKEN}'
|
|
106
|
+
*
|
|
107
|
+
* parameter_encoding:
|
|
108
|
+
* - source: [to, subject, body, cc, bcc, is_html]
|
|
109
|
+
* target: raw
|
|
110
|
+
* encoding: mime_rfc2822_base64url
|
|
111
|
+
*
|
|
112
|
+
* body:
|
|
113
|
+
* raw: '{raw}'
|
|
114
|
+
*
|
|
115
|
+
* Then users call:
|
|
116
|
+
* matimo.execute('gmail-send-email', {
|
|
117
|
+
* to: 'user@example.com',
|
|
118
|
+
* subject: 'Hello',
|
|
119
|
+
* body: 'Hi there',
|
|
120
|
+
* GMAIL_ACCESS_TOKEN: token
|
|
121
|
+
* });
|
|
122
|
+
*/
|
|
123
|
+
//# sourceMappingURL=parameter-encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-encoding.js","sourceRoot":"","sources":["../../../src/encodings/parameter-encoding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAA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,4DAA4D;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,YAAqC;IAC5D,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACxD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes and custom error class for Matimo
|
|
3
|
+
*/
|
|
4
|
+
export declare enum ErrorCode {
|
|
5
|
+
INVALID_SCHEMA = "INVALID_SCHEMA",
|
|
6
|
+
EXECUTION_FAILED = "EXECUTION_FAILED",
|
|
7
|
+
AUTH_FAILED = "AUTH_FAILED",
|
|
8
|
+
TOOL_NOT_FOUND = "TOOL_NOT_FOUND",
|
|
9
|
+
FILE_NOT_FOUND = "FILE_NOT_FOUND",
|
|
10
|
+
VALIDATION_FAILED = "VALIDATION_FAILED",
|
|
11
|
+
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
|
|
12
|
+
TIMEOUT = "TIMEOUT",
|
|
13
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
14
|
+
INVALID_PARAMETER = "INVALID_PARAMETER",
|
|
15
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Custom error class for Matimo
|
|
19
|
+
*/
|
|
20
|
+
export declare class MatimoError extends Error {
|
|
21
|
+
code: ErrorCode;
|
|
22
|
+
details?: Record<string, unknown> | undefined;
|
|
23
|
+
constructor(message: string, code: ErrorCode, details?: Record<string, unknown> | undefined);
|
|
24
|
+
toJSON(): Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a validation error with context
|
|
28
|
+
*/
|
|
29
|
+
export declare function createValidationError(message: string, details?: Record<string, unknown>): MatimoError;
|
|
30
|
+
/**
|
|
31
|
+
* Create an execution error with context
|
|
32
|
+
*/
|
|
33
|
+
export declare function createExecutionError(message: string, details?: Record<string, unknown>): MatimoError;
|
|
34
|
+
//# sourceMappingURL=matimo-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matimo-error.d.ts","sourceRoot":"","sources":["../../../src/errors/matimo-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,SAAS;IACnB,cAAc,mBAAmB;IACjC,gBAAgB,qBAAqB;IACrC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,cAAc,mBAAmB;IACjC,iBAAiB,sBAAsB;IACvC,mBAAmB,wBAAwB;IAC3C,OAAO,YAAY;IACnB,aAAa,kBAAkB;IAC/B,iBAAiB,sBAAsB;IACvC,aAAa,kBAAkB;CAChC;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAG3B,IAAI,EAAE,SAAS;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFxC,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,SAAS,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;IAM1C,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAQlC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,WAAW,CAEb;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,WAAW,CAEb"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes and custom error class for Matimo
|
|
3
|
+
*/
|
|
4
|
+
export var ErrorCode;
|
|
5
|
+
(function (ErrorCode) {
|
|
6
|
+
ErrorCode["INVALID_SCHEMA"] = "INVALID_SCHEMA";
|
|
7
|
+
ErrorCode["EXECUTION_FAILED"] = "EXECUTION_FAILED";
|
|
8
|
+
ErrorCode["AUTH_FAILED"] = "AUTH_FAILED";
|
|
9
|
+
ErrorCode["TOOL_NOT_FOUND"] = "TOOL_NOT_FOUND";
|
|
10
|
+
ErrorCode["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
|
|
11
|
+
ErrorCode["VALIDATION_FAILED"] = "VALIDATION_FAILED";
|
|
12
|
+
ErrorCode["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
|
|
13
|
+
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
14
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
15
|
+
ErrorCode["INVALID_PARAMETER"] = "INVALID_PARAMETER";
|
|
16
|
+
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
17
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Custom error class for Matimo
|
|
20
|
+
*/
|
|
21
|
+
export class MatimoError extends Error {
|
|
22
|
+
constructor(message, code, details) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.details = details;
|
|
26
|
+
this.name = 'MatimoError';
|
|
27
|
+
}
|
|
28
|
+
toJSON() {
|
|
29
|
+
return {
|
|
30
|
+
name: this.name,
|
|
31
|
+
message: this.message,
|
|
32
|
+
code: this.code,
|
|
33
|
+
details: this.details,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a validation error with context
|
|
39
|
+
*/
|
|
40
|
+
export function createValidationError(message, details) {
|
|
41
|
+
return new MatimoError(message, ErrorCode.VALIDATION_FAILED, details);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create an execution error with context
|
|
45
|
+
*/
|
|
46
|
+
export function createExecutionError(message, details) {
|
|
47
|
+
return new MatimoError(message, ErrorCode.EXECUTION_FAILED, details);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=matimo-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matimo-error.js","sourceRoot":"","sources":["../../../src/errors/matimo-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAN,IAAY,SAYX;AAZD,WAAY,SAAS;IACnB,8CAAiC,CAAA;IACjC,kDAAqC,CAAA;IACrC,wCAA2B,CAAA;IAC3B,8CAAiC,CAAA;IACjC,8CAAiC,CAAA;IACjC,oDAAuC,CAAA;IACvC,wDAA2C,CAAA;IAC3C,gCAAmB,CAAA;IACnB,4CAA+B,CAAA;IAC/B,oDAAuC,CAAA;IACvC,4CAA+B,CAAA;AACjC,CAAC,EAZW,SAAS,KAAT,SAAS,QAYpB;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YACE,OAAe,EACR,IAAe,EACf,OAAiC;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAW;QACf,YAAO,GAAP,OAAO,CAA0B;QAGxC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,OAAiC;IAEjC,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,OAAiC;IAEjC,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ToolDefinition } from '../core/schema';
|
|
2
|
+
/**
|
|
3
|
+
* CommandExecutor - Executes shell commands
|
|
4
|
+
* Handles parameter templating, timeouts, and error capture
|
|
5
|
+
*/
|
|
6
|
+
export declare class CommandExecutor {
|
|
7
|
+
private cwd?;
|
|
8
|
+
constructor(cwd?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Execute a tool that runs a shell command
|
|
11
|
+
*/
|
|
12
|
+
execute(tool: ToolDefinition, params: Record<string, unknown>): Promise<unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Replace parameter placeholders in a string
|
|
15
|
+
*/
|
|
16
|
+
private templateString;
|
|
17
|
+
}
|
|
18
|
+
export default CommandExecutor;
|
|
19
|
+
//# sourceMappingURL=command-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-executor.d.ts","sourceRoot":"","sources":["../../../src/executors/command-executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;GAGG;AAEH,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAC,CAAS;gBAET,GAAG,CAAC,EAAE,MAAM;IAIxB;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAqFtF;;OAEG;IACH,OAAO,CAAC,cAAc;CAQvB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { MatimoError, ErrorCode } from '../errors/matimo-error';
|
|
3
|
+
/**
|
|
4
|
+
* CommandExecutor - Executes shell commands
|
|
5
|
+
* Handles parameter templating, timeouts, and error capture
|
|
6
|
+
*/
|
|
7
|
+
export class CommandExecutor {
|
|
8
|
+
constructor(cwd) {
|
|
9
|
+
this.cwd = cwd;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Execute a tool that runs a shell command
|
|
13
|
+
*/
|
|
14
|
+
async execute(tool, params) {
|
|
15
|
+
if (tool.execution.type !== 'command') {
|
|
16
|
+
throw new MatimoError('Tool execution type is not command', ErrorCode.EXECUTION_FAILED, {
|
|
17
|
+
expectedType: 'command',
|
|
18
|
+
actualType: tool.execution.type,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const { command, args = [], timeout = 30000 } = tool.execution;
|
|
22
|
+
const startTime = Date.now();
|
|
23
|
+
// Implement parameter templating
|
|
24
|
+
const templatedCommand = this.templateString(command, params);
|
|
25
|
+
const templatedArgs = args.map((arg) => this.templateString(arg, params));
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
const spawnOptions = {
|
|
29
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
30
|
+
};
|
|
31
|
+
// Set working directory if provided
|
|
32
|
+
if (this.cwd) {
|
|
33
|
+
spawnOptions.cwd = this.cwd;
|
|
34
|
+
}
|
|
35
|
+
const child = spawn(templatedCommand, templatedArgs, spawnOptions);
|
|
36
|
+
let stdout = '';
|
|
37
|
+
let stderr = '';
|
|
38
|
+
let timedOut = false;
|
|
39
|
+
// Set up timeout
|
|
40
|
+
const timer = setTimeout(() => {
|
|
41
|
+
timedOut = true;
|
|
42
|
+
child.kill('SIGTERM');
|
|
43
|
+
}, timeout);
|
|
44
|
+
child.stdout?.on('data', (data) => {
|
|
45
|
+
stdout += data.toString();
|
|
46
|
+
});
|
|
47
|
+
child.stderr?.on('data', (data) => {
|
|
48
|
+
stderr += data.toString();
|
|
49
|
+
});
|
|
50
|
+
child.on('close', (code) => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
const duration = Date.now() - startTime;
|
|
53
|
+
if (timedOut) {
|
|
54
|
+
resolve({
|
|
55
|
+
success: false,
|
|
56
|
+
error: 'timeout',
|
|
57
|
+
exitCode: -1,
|
|
58
|
+
duration,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const exitCode = code || 0;
|
|
63
|
+
const success = exitCode === 0;
|
|
64
|
+
resolve({
|
|
65
|
+
success,
|
|
66
|
+
stdout: stdout.trim(),
|
|
67
|
+
stderr: stderr.trim(),
|
|
68
|
+
exitCode,
|
|
69
|
+
duration,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
child.on('error', (error) => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
const duration = Date.now() - startTime;
|
|
76
|
+
resolve({
|
|
77
|
+
success: false,
|
|
78
|
+
error: error.message,
|
|
79
|
+
exitCode: -1,
|
|
80
|
+
duration,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Replace parameter placeholders in a string
|
|
87
|
+
*/
|
|
88
|
+
templateString(str, params) {
|
|
89
|
+
let result = str;
|
|
90
|
+
for (const [key, value] of Object.entries(params)) {
|
|
91
|
+
const placeholder = `{${key}}`;
|
|
92
|
+
result = result.replace(new RegExp(placeholder, 'g'), String(value));
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export default CommandExecutor;
|
|
98
|
+
//# sourceMappingURL=command-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-executor.js","sourceRoot":"","sources":["../../../src/executors/command-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;GAGG;AAEH,MAAM,OAAO,eAAe;IAG1B,YAAY,GAAY;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,IAAoB,EAAE,MAA+B;QACjE,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,WAAW,CAAC,oCAAoC,EAAE,SAAS,CAAC,gBAAgB,EAAE;gBACtF,YAAY,EAAE,SAAS;gBACvB,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI;aAChC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;QAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,iCAAiC;QACjC,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;QAE1E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAA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|
|
2
|
+
/**
|
|
3
|
+
* FunctionExecutor - Executes async functions
|
|
4
|
+
* Supports functions defined in:
|
|
5
|
+
* 1. Embedded code in tool YAML (legacy)
|
|
6
|
+
* 2. Colocated .ts files (recommended)
|
|
7
|
+
*
|
|
8
|
+
* For .ts files, the tool directory structure should be:
|
|
9
|
+
* tools/provider/tool-name/
|
|
10
|
+
* ├── definition.yaml
|
|
11
|
+
* └── tool-name.ts (exports default async function)
|
|
12
|
+
*/
|
|
13
|
+
export declare class FunctionExecutor {
|
|
14
|
+
private toolsPath;
|
|
15
|
+
constructor(toolsPath?: string);
|
|
16
|
+
/**
|
|
17
|
+
* Execute a tool that runs an async function
|
|
18
|
+
* Supports both embedded code and external .ts/.js files
|
|
19
|
+
*/
|
|
20
|
+
execute(tool: ToolDefinition, params: Record<string, unknown>): Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
export default FunctionExecutor;
|
|
23
|
+
//# sourceMappingURL=function-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-executor.d.ts","sourceRoot":"","sources":["../../../src/executors/function-executor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,CAAC,EAAE,MAAM;IAI9B;;;OAGG;IACG,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAmKvF;AAED,eAAe,gBAAgB,CAAC"}
|