@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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E,CAAC;YACpB,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACrD,+CAA+C;gBAC/C,IAAI,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;oBACjC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ToolDefinition } from './core/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Options for MatimoInstance initialization
|
|
4
|
+
*/
|
|
5
|
+
export interface InitOptions {
|
|
6
|
+
toolPaths?: string[];
|
|
7
|
+
autoDiscover?: boolean;
|
|
8
|
+
includeCore?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Matimo Instance - Single initialization point for tool execution
|
|
12
|
+
* Combines loader, registry, and executors into one interface
|
|
13
|
+
*/
|
|
14
|
+
export declare class MatimoInstance {
|
|
15
|
+
private toolPaths;
|
|
16
|
+
private loader;
|
|
17
|
+
private registry;
|
|
18
|
+
private commandExecutor;
|
|
19
|
+
private httpExecutor;
|
|
20
|
+
private functionExecutor;
|
|
21
|
+
private constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Initialize Matimo with tools from directory or auto-discovery
|
|
24
|
+
* @param options - Initialization options (string for backward compatibility)
|
|
25
|
+
* @returns MatimoInstance ready to execute tools
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Backward compatible - single path
|
|
29
|
+
* const matimo = await MatimoInstance.init('./tools');
|
|
30
|
+
*
|
|
31
|
+
* // New - auto-discovery
|
|
32
|
+
* const matimo = await MatimoInstance.init({ autoDiscover: true });
|
|
33
|
+
*
|
|
34
|
+
* // Explicit paths
|
|
35
|
+
* const matimo = await MatimoInstance.init({
|
|
36
|
+
* toolPaths: ['./tools', require.resolve('@matimo/slack/tools')]
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
static init(options?: InitOptions | string): Promise<MatimoInstance>;
|
|
40
|
+
/**
|
|
41
|
+
* Get tool paths
|
|
42
|
+
* @returns Array of tool paths
|
|
43
|
+
*/
|
|
44
|
+
getToolPaths(): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Execute a tool by name with parameters
|
|
47
|
+
* @param toolName - Name of the tool to execute
|
|
48
|
+
* @param params - Tool parameters
|
|
49
|
+
* @returns Tool execution result
|
|
50
|
+
*/
|
|
51
|
+
execute(toolName: string, params: Record<string, unknown>): Promise<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Get a tool definition by name
|
|
54
|
+
* @param toolName - Name of the tool
|
|
55
|
+
* @returns Tool definition or undefined
|
|
56
|
+
*/
|
|
57
|
+
getTool(toolName: string): ToolDefinition | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* List all available tools
|
|
60
|
+
* @returns Array of tool definitions
|
|
61
|
+
*/
|
|
62
|
+
listTools(): ToolDefinition[];
|
|
63
|
+
/**
|
|
64
|
+
* Get all available tools (alias for listTools)
|
|
65
|
+
* @returns Array of tool definitions
|
|
66
|
+
*/
|
|
67
|
+
getAllTools(): ToolDefinition[];
|
|
68
|
+
/**
|
|
69
|
+
* Search tools by name or description
|
|
70
|
+
* @param query - Search query
|
|
71
|
+
* @returns Matching tools
|
|
72
|
+
*/
|
|
73
|
+
searchTools(query: string): ToolDefinition[];
|
|
74
|
+
/**
|
|
75
|
+
* Get tools by tag
|
|
76
|
+
* @param tag - Tag to search for
|
|
77
|
+
* @returns Tools with the given tag
|
|
78
|
+
*/
|
|
79
|
+
getToolsByTag(tag: string): ToolDefinition[];
|
|
80
|
+
/**
|
|
81
|
+
* Automatically inject parameters from environment variables
|
|
82
|
+
* Uses a YAML-native, scale-friendly approach:
|
|
83
|
+
*
|
|
84
|
+
* 1. Scans the execution config for all parameter placeholders
|
|
85
|
+
* 2. For each parameter not provided by user, checks if it looks like auth (TOKEN, KEY, SECRET, etc.)
|
|
86
|
+
* 3. If yes, attempts to load from environment: MATIMO_<PARAM_NAME> or <PARAM_NAME>
|
|
87
|
+
*
|
|
88
|
+
* This works for ANY tool with ANY auth parameter name - no hardcoding needed.
|
|
89
|
+
* Scales to unlimited tools - contributors just submit YAML.
|
|
90
|
+
*
|
|
91
|
+
* Examples:
|
|
92
|
+
* - GMAIL_ACCESS_TOKEN → looks in env vars
|
|
93
|
+
* - GITHUB_TOKEN → looks in env vars
|
|
94
|
+
* - SLACK_BOT_TOKEN → looks in env vars
|
|
95
|
+
* - MY_CUSTOM_API_KEY → looks in env vars
|
|
96
|
+
* - ANY_SECRET → looks in env vars
|
|
97
|
+
*/
|
|
98
|
+
private injectAuthParameters;
|
|
99
|
+
/**
|
|
100
|
+
* Extract all parameter placeholders from execution config
|
|
101
|
+
* Scans headers, body, URL, and query_params for {paramName} patterns
|
|
102
|
+
*/
|
|
103
|
+
private extractParameterPlaceholders;
|
|
104
|
+
/**
|
|
105
|
+
* Recursively scan object for parameter placeholders
|
|
106
|
+
*/
|
|
107
|
+
private scanObjectForParams;
|
|
108
|
+
/**
|
|
109
|
+
* Get the appropriate executor for a tool
|
|
110
|
+
*/
|
|
111
|
+
private getExecutor;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Matimo namespace - Entry point for the SDK
|
|
115
|
+
*/
|
|
116
|
+
export declare const matimo: {
|
|
117
|
+
/**
|
|
118
|
+
* Initialize Matimo with a tools directory
|
|
119
|
+
* @param toolsPath - Path to tools directory
|
|
120
|
+
* @returns MatimoInstance ready to use
|
|
121
|
+
*/
|
|
122
|
+
init(toolsPath: string): Promise<MatimoInstance>;
|
|
123
|
+
};
|
|
124
|
+
//# sourceM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AAoB;IAoD5B;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAkDpC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA0C3B;;OAEG;IACH,OAAO,CAAC,WAAW;CAiBpB;AAED;;GAEG;AACH,eAAO,MAAM,MAAM;IACjB;;;;OAIG;oBACmB,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CAGvD,CAAC"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { ToolLoader } from './core/tool-loader';
|
|
3
|
+
import { ToolRegistry } from './core/tool-registry';
|
|
4
|
+
import { CommandExecutor } from './executors/command-executor';
|
|
5
|
+
import { HttpExecutor } from './executors/http-executor';
|
|
6
|
+
import { FunctionExecutor } from './executors/function-executor';
|
|
7
|
+
import { MatimoError, ErrorCode } from './errors/matimo-error';
|
|
8
|
+
/**
|
|
9
|
+
* Matimo Instance - Single initialization point for tool execution
|
|
10
|
+
* Combines loader, registry, and executors into one interface
|
|
11
|
+
*/
|
|
12
|
+
export class MatimoInstance {
|
|
13
|
+
constructor(toolPaths) {
|
|
14
|
+
this.toolPaths = toolPaths;
|
|
15
|
+
this.loader = new ToolLoader();
|
|
16
|
+
this.registry = new ToolRegistry();
|
|
17
|
+
// Use the first path (primary) as working directory for command executor
|
|
18
|
+
const workingDir = toolPaths.length > 0 ? path.dirname(toolPaths[0]) : process.cwd();
|
|
19
|
+
this.commandExecutor = new CommandExecutor(workingDir);
|
|
20
|
+
this.httpExecutor = new HttpExecutor();
|
|
21
|
+
this.functionExecutor = new FunctionExecutor(toolPaths[0] || '');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Initialize Matimo with tools from directory or auto-discovery
|
|
25
|
+
* @param options - Initialization options (string for backward compatibility)
|
|
26
|
+
* @returns MatimoInstance ready to execute tools
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Backward compatible - single path
|
|
30
|
+
* const matimo = await MatimoInstance.init('./tools');
|
|
31
|
+
*
|
|
32
|
+
* // New - auto-discovery
|
|
33
|
+
* const matimo = await MatimoInstance.init({ autoDiscover: true });
|
|
34
|
+
*
|
|
35
|
+
* // Explicit paths
|
|
36
|
+
* const matimo = await MatimoInstance.init({
|
|
37
|
+
* toolPaths: ['./tools', require.resolve('@matimo/slack/tools')]
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
static async init(options) {
|
|
41
|
+
let finalOptions;
|
|
42
|
+
// Backward compatibility: if string is passed, treat as toolPath
|
|
43
|
+
if (typeof options === 'string') {
|
|
44
|
+
finalOptions = {
|
|
45
|
+
toolPaths: [options],
|
|
46
|
+
autoDiscover: false,
|
|
47
|
+
includeCore: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
finalOptions = {
|
|
52
|
+
autoDiscover: false,
|
|
53
|
+
includeCore: true,
|
|
54
|
+
...options,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const toolPaths = [];
|
|
58
|
+
// Include core tools (calculator, etc.) - currently not used in monorepo
|
|
59
|
+
// Use explicit toolPaths or autoDiscover instead
|
|
60
|
+
// if (finalOptions.includeCore) { ... }
|
|
61
|
+
// Add explicit paths
|
|
62
|
+
if (finalOptions.toolPaths) {
|
|
63
|
+
toolPaths.push(...finalOptions.toolPaths);
|
|
64
|
+
}
|
|
65
|
+
// Auto-discover @matimo/* packages
|
|
66
|
+
if (finalOptions.autoDiscover) {
|
|
67
|
+
const discoveredPaths = new ToolLoader().autoDiscoverPackages();
|
|
68
|
+
toolPaths.push(...discoveredPaths);
|
|
69
|
+
}
|
|
70
|
+
const instance = new MatimoInstance(toolPaths);
|
|
71
|
+
// Load tools from all paths
|
|
72
|
+
const allTools = instance.loader.loadToolsFromMultiplePaths(toolPaths);
|
|
73
|
+
instance.registry.registerAll(Array.from(allTools.values()));
|
|
74
|
+
return instance;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get tool paths
|
|
78
|
+
* @returns Array of tool paths
|
|
79
|
+
*/
|
|
80
|
+
getToolPaths() {
|
|
81
|
+
return [...this.toolPaths];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Execute a tool by name with parameters
|
|
85
|
+
* @param toolName - Name of the tool to execute
|
|
86
|
+
* @param params - Tool parameters
|
|
87
|
+
* @returns Tool execution result
|
|
88
|
+
*/
|
|
89
|
+
async execute(toolName, params) {
|
|
90
|
+
const tool = this.registry.get(toolName);
|
|
91
|
+
if (!tool) {
|
|
92
|
+
throw new MatimoError(`Tool '${toolName}' not found in registry`, ErrorCode.TOOL_NOT_FOUND, {
|
|
93
|
+
toolName,
|
|
94
|
+
availableTools: this.registry.getAll().map((t) => t.name),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Auto-inject authentication parameters from environment variables
|
|
98
|
+
const finalParams = this.injectAuthParameters(tool, params);
|
|
99
|
+
const executor = this.getExecutor(tool);
|
|
100
|
+
return executor.execute(tool, finalParams);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get a tool definition by name
|
|
104
|
+
* @param toolName - Name of the tool
|
|
105
|
+
* @returns Tool definition or undefined
|
|
106
|
+
*/
|
|
107
|
+
getTool(toolName) {
|
|
108
|
+
return this.registry.get(toolName);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* List all available tools
|
|
112
|
+
* @returns Array of tool definitions
|
|
113
|
+
*/
|
|
114
|
+
listTools() {
|
|
115
|
+
return this.registry.getAll();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get all available tools (alias for listTools)
|
|
119
|
+
* @returns Array of tool definitions
|
|
120
|
+
*/
|
|
121
|
+
getAllTools() {
|
|
122
|
+
return this.registry.getAll();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Search tools by name or description
|
|
126
|
+
* @param query - Search query
|
|
127
|
+
* @returns Matching tools
|
|
128
|
+
*/
|
|
129
|
+
searchTools(query) {
|
|
130
|
+
return this.registry.search(query);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get tools by tag
|
|
134
|
+
* @param tag - Tag to search for
|
|
135
|
+
* @returns Tools with the given tag
|
|
136
|
+
*/
|
|
137
|
+
getToolsByTag(tag) {
|
|
138
|
+
return this.registry.getByTag(tag);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Automatically inject parameters from environment variables
|
|
142
|
+
* Uses a YAML-native, scale-friendly approach:
|
|
143
|
+
*
|
|
144
|
+
* 1. Scans the execution config for all parameter placeholders
|
|
145
|
+
* 2. For each parameter not provided by user, checks if it looks like auth (TOKEN, KEY, SECRET, etc.)
|
|
146
|
+
* 3. If yes, attempts to load from environment: MATIMO_<PARAM_NAME> or <PARAM_NAME>
|
|
147
|
+
*
|
|
148
|
+
* This works for ANY tool with ANY auth parameter name - no hardcoding needed.
|
|
149
|
+
* Scales to unlimited tools - contributors just submit YAML.
|
|
150
|
+
*
|
|
151
|
+
* Examples:
|
|
152
|
+
* - GMAIL_ACCESS_TOKEN → looks in env vars
|
|
153
|
+
* - GITHUB_TOKEN → looks in env vars
|
|
154
|
+
* - SLACK_BOT_TOKEN → looks in env vars
|
|
155
|
+
* - MY_CUSTOM_API_KEY → looks in env vars
|
|
156
|
+
* - ANY_SECRET → looks in env vars
|
|
157
|
+
*/
|
|
158
|
+
injectAuthParameters(tool, params) {
|
|
159
|
+
const result = { ...params };
|
|
160
|
+
// Collect all parameter names referenced in the execution config
|
|
161
|
+
const referencedParams = this.extractParameterPlaceholders(tool);
|
|
162
|
+
// Auth-related parameter name patterns (case-insensitive)
|
|
163
|
+
const authPatterns = [
|
|
164
|
+
'token',
|
|
165
|
+
'key',
|
|
166
|
+
'secret',
|
|
167
|
+
'password',
|
|
168
|
+
'credential',
|
|
169
|
+
'auth',
|
|
170
|
+
'bearer',
|
|
171
|
+
'api_key',
|
|
172
|
+
];
|
|
173
|
+
// Check each referenced parameter
|
|
174
|
+
for (const paramName of referencedParams) {
|
|
175
|
+
// Skip if user already provided it
|
|
176
|
+
if (paramName in result) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// Check if parameter name looks like auth
|
|
180
|
+
const lowerName = paramName.toLowerCase();
|
|
181
|
+
const isAuthParam = authPatterns.some((pattern) => lowerName.includes(pattern));
|
|
182
|
+
if (isAuthParam) {
|
|
183
|
+
// Try to load from environment
|
|
184
|
+
// First try MATIMO_ prefixed version for organization
|
|
185
|
+
let envValue = process.env[`MATIMO_${paramName}`];
|
|
186
|
+
// If not found, try the parameter name directly
|
|
187
|
+
if (!envValue) {
|
|
188
|
+
envValue = process.env[paramName];
|
|
189
|
+
}
|
|
190
|
+
// If found, inject it
|
|
191
|
+
if (envValue) {
|
|
192
|
+
result[paramName] = envValue;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Extract all parameter placeholders from execution config
|
|
200
|
+
* Scans headers, body, URL, and query_params for {paramName} patterns
|
|
201
|
+
*/
|
|
202
|
+
extractParameterPlaceholders(tool) {
|
|
203
|
+
const params = new Set();
|
|
204
|
+
const placeholderRegex = /\{([^}]+)\}/g;
|
|
205
|
+
const execution = tool.execution;
|
|
206
|
+
// Scan URL
|
|
207
|
+
if ('url' in execution && execution.url) {
|
|
208
|
+
let match;
|
|
209
|
+
while ((match = placeholderRegex.exec(execution.url)) !== null) {
|
|
210
|
+
params.add(match[1]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Scan headers
|
|
214
|
+
if ('headers' in execution && execution.headers && typeof execution.headers === 'object') {
|
|
215
|
+
for (const value of Object.values(execution.headers)) {
|
|
216
|
+
if (typeof value === 'string') {
|
|
217
|
+
let match;
|
|
218
|
+
while ((match = placeholderRegex.exec(value)) !== null) {
|
|
219
|
+
params.add(match[1]);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Scan body (recursively for nested objects)
|
|
225
|
+
if ('body' in execution && execution.body) {
|
|
226
|
+
this.scanObjectForParams(execution.body, params);
|
|
227
|
+
}
|
|
228
|
+
// Scan query_params
|
|
229
|
+
if ('query_params' in execution &&
|
|
230
|
+
execution.query_params &&
|
|
231
|
+
typeof execution.query_params === 'object') {
|
|
232
|
+
for (const value of Object.values(execution.query_params)) {
|
|
233
|
+
if (typeof value === 'string') {
|
|
234
|
+
let match;
|
|
235
|
+
while ((match = placeholderRegex.exec(value)) !== null) {
|
|
236
|
+
params.add(match[1]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return params;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Recursively scan object for parameter placeholders
|
|
245
|
+
*/
|
|
246
|
+
scanObjectForParams(obj, params, visited = new WeakSet()) {
|
|
247
|
+
if (!obj || typeof obj !== 'object') {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
// Prevent infinite loops
|
|
251
|
+
if (visited.has(obj)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
visited.add(obj);
|
|
255
|
+
const placeholderRegex = /\{([^}]+)\}/g;
|
|
256
|
+
if (Array.isArray(obj)) {
|
|
257
|
+
for (const item of obj) {
|
|
258
|
+
if (typeof item === 'string') {
|
|
259
|
+
let match;
|
|
260
|
+
while ((match = placeholderRegex.exec(item)) !== null) {
|
|
261
|
+
params.add(match[1]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else if (item && typeof item === 'object') {
|
|
265
|
+
this.scanObjectForParams(item, params, visited);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
for (const value of Object.values(obj)) {
|
|
271
|
+
if (typeof value === 'string') {
|
|
272
|
+
let match;
|
|
273
|
+
while ((match = placeholderRegex.exec(value)) !== null) {
|
|
274
|
+
params.add(match[1]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else if (value && typeof value === 'object') {
|
|
278
|
+
this.scanObjectForParams(value, params, visited);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get the appropriate executor for a tool
|
|
285
|
+
*/
|
|
286
|
+
getExecutor(tool) {
|
|
287
|
+
const executionType = tool.execution.type;
|
|
288
|
+
switch (executionType) {
|
|
289
|
+
case 'command':
|
|
290
|
+
return this.commandExecutor;
|
|
291
|
+
case 'http':
|
|
292
|
+
return this.httpExecutor;
|
|
293
|
+
case 'function':
|
|
294
|
+
return this.functionExecutor;
|
|
295
|
+
default:
|
|
296
|
+
throw new MatimoError(`Unsupported execution type: ${executionType}`, ErrorCode.EXECUTION_FAILED, { executionType });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Matimo namespace - Entry point for the SDK
|
|
302
|
+
*/
|
|
303
|
+
export const matimo = {
|
|
304
|
+
/**
|
|
305
|
+
* Initialize Matimo with a tools directory
|
|
306
|
+
* @param toolsPath - Path to tools directory
|
|
307
|
+
* @returns MatimoInstance ready to use
|
|
308
|
+
*/
|
|
309
|
+
async init(toolsPath) {
|
|
310
|
+
return MatimoInstance.init(toolsPath);
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
//# sourceMappingURL=matimo-instance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matimo-instance.js","sourceRoot":"","sources":["../../src/matimo-instance.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,2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C,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,IAAoB;QACtC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAc,CAAC;QACpD,QAAQ,aAAa,EAAE,CAAC;YACtB,KAAK,SAAS;gBACZ,OAAO,IAAI,CAAC,eAAe,CAAC;YAC9B,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,YAAY,CAAC;YAC3B,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC,gBAAgB,CAAC;YAC/B;gBACE,MAAM,IAAI,WAAW,CACnB,+BAA+B,aAAa,EAAE,EAC9C,SAAS,CAAC,gBAAgB,EAC1B,EAAE,aAAa,EAAE,CAClB,CAAC;QACN,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,SAAiB;QAC1B,OAAO,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculator utility functions
|
|
3
|
+
*/
|
|
4
|
+
declare const Calculator: {
|
|
5
|
+
/**
|
|
6
|
+
* Normalize operation name to handle variations
|
|
7
|
+
*/
|
|
8
|
+
normalizeOperation(op: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Perform arithmetic calculation
|
|
11
|
+
*/
|
|
12
|
+
calculate(operation: string, a: number, b: number): {
|
|
13
|
+
result: number;
|
|
14
|
+
operation: string;
|
|
15
|
+
original_operation: string;
|
|
16
|
+
operands: {
|
|
17
|
+
a: number;
|
|
18
|
+
b: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* CLI entry point
|
|
24
|
+
*/
|
|
25
|
+
declare function main(): void;
|
|
26
|
+
//# sourceMappingURL=calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../../../tools/calculator/calculator.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,QAAA,MAAM,UAAU;IACd;;OAEG;2BACoB,MAAM,GAAG,MAAM;IAsCtC;;OAEG;yBAEU,MAAM,KACd,MAAM,KACN,MAAM,GACR;QACD,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,QAAQ,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KACpC;CA+BF,CAAC;AAEF;;GAEG;AACH,iBAAS,IAAI,IAAI,IAAI,CAyBpB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Calculator implementation
|
|
3
|
+
// This script is executed by the calculator tool
|
|
4
|
+
/**
|
|
5
|
+
* Calculator utility functions
|
|
6
|
+
*/
|
|
7
|
+
const Calculator = {
|
|
8
|
+
/**
|
|
9
|
+
* Normalize operation name to handle variations
|
|
10
|
+
*/
|
|
11
|
+
normalizeOperation(op) {
|
|
12
|
+
const normalized = op.toLowerCase().trim();
|
|
13
|
+
// Map variations to canonical operation names
|
|
14
|
+
const operationMap = {
|
|
15
|
+
// Addition variants
|
|
16
|
+
add: 'add',
|
|
17
|
+
addition: 'add',
|
|
18
|
+
sum: 'add',
|
|
19
|
+
plus: 'add',
|
|
20
|
+
'+': 'add',
|
|
21
|
+
// Subtraction variants
|
|
22
|
+
subtract: 'subtract',
|
|
23
|
+
subtraction: 'subtract',
|
|
24
|
+
minus: 'subtract',
|
|
25
|
+
sub: 'subtract',
|
|
26
|
+
'-': 'subtract',
|
|
27
|
+
// Multiplication variants
|
|
28
|
+
multiply: 'multiply',
|
|
29
|
+
multiplication: 'multiply',
|
|
30
|
+
times: 'multiply',
|
|
31
|
+
product: 'multiply',
|
|
32
|
+
mul: 'multiply',
|
|
33
|
+
'*': 'multiply',
|
|
34
|
+
x: 'multiply',
|
|
35
|
+
// Division variants
|
|
36
|
+
divide: 'divide',
|
|
37
|
+
division: 'divide',
|
|
38
|
+
div: 'divide',
|
|
39
|
+
'/': 'divide',
|
|
40
|
+
};
|
|
41
|
+
return operationMap[normalized] || normalized;
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Perform arithmetic calculation
|
|
45
|
+
*/
|
|
46
|
+
calculate(operation, a, b) {
|
|
47
|
+
const normalizedOp = this.normalizeOperation(operation);
|
|
48
|
+
let result;
|
|
49
|
+
switch (normalizedOp) {
|
|
50
|
+
case 'add':
|
|
51
|
+
result = a + b;
|
|
52
|
+
break;
|
|
53
|
+
case 'subtract':
|
|
54
|
+
result = a - b;
|
|
55
|
+
break;
|
|
56
|
+
case 'multiply':
|
|
57
|
+
result = a * b;
|
|
58
|
+
break;
|
|
59
|
+
case 'divide':
|
|
60
|
+
if (b === 0) {
|
|
61
|
+
throw new Error('Division by zero');
|
|
62
|
+
}
|
|
63
|
+
result = a / b;
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
throw new Error(`Unknown operation: ${operation}`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
result,
|
|
70
|
+
operation: normalizedOp,
|
|
71
|
+
original_operation: operation,
|
|
72
|
+
operands: { a, b },
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* CLI entry point
|
|
78
|
+
*/
|
|
79
|
+
function main() {
|
|
80
|
+
try {
|
|
81
|
+
const [operation, aStr, bStr] = process.argv.slice(2);
|
|
82
|
+
if (!operation || !aStr || !bStr) {
|
|
83
|
+
console.error('Usage: calculator.ts <operation> <a> <b>');
|
|
84
|
+
console.error('Operations: add, subtract, multiply, divide');
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
const a = parseFloat(aStr);
|
|
88
|
+
const b = parseFloat(bStr);
|
|
89
|
+
if (isNaN(a) || isNaN(b)) {
|
|
90
|
+
console.error('Error: Arguments must be valid numbers');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
const result = Calculator.calculate(operation, a, b);
|
|
94
|
+
console.log(JSON.stringify(result));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
98
|
+
console.error(message);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Execute CLI entry point
|
|
103
|
+
main();
|
|
104
|
+
//# sourceMappingURL=calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../../tools/calculator/calculator.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,iDAAiD;AAEjD;;GAEG;AACH,MAAM,UAAU,GAAG;IACjB;;OAEG;IACH,kBAAkB,CAAC,EAAU;QAC3B,MAAM,UAAU,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAE3C,8CAA8C;QAC9C,MAAM,YAAY,GAA2B;YAC3C,oBAAoB;YACpB,GAAG,EAAE,KAAK;YACV,QAAQ,EAAE,KAAK;YACf,GAAG,EAAE,KAAK;YACV,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,KAAK;YAEV,uBAAuB;YACvB,QAAQ,EAAE,UAAU;YACpB,WAAW,EAAE,UAAU;YACvB,KAAK,EAAE,UAAU;YACjB,GAAG,EAAE,UAAU;YACf,GAAG,EAAE,UAAU;YAEf,0BAA0B;YAC1B,QAAQ,EAAE,UAAU;YACpB,cAAc,EAAE,UAAU;YAC1B,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,UAAU;YACnB,GAAG,EAAE,UAAU;YACf,GAAG,EAAE,UAAU;YACf,CAAC,EAAE,U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