@matimo/core 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +252 -0
- package/destructive-keywords.yaml +70 -0
- package/dist/approval/approval-handler.d.ts +74 -0
- package/dist/approval/approval-handler.d.ts.map +1 -0
- package/dist/approval/approval-handler.js +210 -0
- package/dist/approval/approval-handler.js.map +1 -0
- package/dist/auth/oauth2-config.d.ts +104 -0
- package/dist/auth/oauth2-config.d.ts.map +1 -0
- package/dist/auth/oauth2-config.js +38 -0
- package/dist/auth/oauth2-config.js.map +1 -0
- package/dist/auth/oauth2-handler.d.ts +130 -0
- package/dist/auth/oauth2-handler.d.ts.map +1 -0
- package/dist/auth/oauth2-handler.js +265 -0
- package/dist/auth/oauth2-handler.js.map +1 -0
- package/dist/auth/oauth2-provider-loader.d.ts +68 -0
- package/dist/auth/oauth2-provider-loader.d.ts.map +1 -0
- package/dist/auth/oauth2-provider-loader.js +120 -0
- package/dist/auth/oauth2-provider-loader.js.map +1 -0
- package/dist/core/schema.d.ts +259 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +187 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/tool-loader.d.ts +57 -0
- package/dist/core/tool-loader.d.ts.map +1 -0
- package/dist/core/tool-loader.js +250 -0
- package/dist/core/tool-loader.js.map +1 -0
- package/dist/core/tool-registry.d.ts +48 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +93 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/core/types.d.ts +162 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/tool-decorator.d.ts +97 -0
- package/dist/decorators/tool-decorator.d.ts.map +1 -0
- package/dist/decorators/tool-decorator.js +157 -0
- package/dist/decorators/tool-decorator.js.map +1 -0
- package/dist/encodings/parameter-encoding.d.ts +51 -0
- package/dist/encodings/parameter-encoding.d.ts.map +1 -0
- package/dist/encodings/parameter-encoding.js +124 -0
- package/dist/encodings/parameter-encoding.js.map +1 -0
- package/dist/errors/matimo-error.d.ts +41 -0
- package/dist/errors/matimo-error.d.ts.map +1 -0
- package/dist/errors/matimo-error.js +71 -0
- package/dist/errors/matimo-error.js.map +1 -0
- package/dist/executors/command-executor.d.ts +19 -0
- package/dist/executors/command-executor.d.ts.map +1 -0
- package/dist/executors/command-executor.js +98 -0
- package/dist/executors/command-executor.js.map +1 -0
- package/dist/executors/function-executor.d.ts +23 -0
- package/dist/executors/function-executor.d.ts.map +1 -0
- package/dist/executors/function-executor.js +181 -0
- package/dist/executors/function-executor.js.map +1 -0
- package/dist/executors/http-executor.d.ts +78 -0
- package/dist/executors/http-executor.d.ts.map +1 -0
- package/dist/executors/http-executor.js +279 -0
- package/dist/executors/http-executor.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/langchain.d.ts +46 -0
- package/dist/integrations/langchain.d.ts.map +1 -0
- package/dist/integrations/langchain.js +197 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +96 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +53 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/winston-logger.d.ts +29 -0
- package/dist/logging/winston-logger.d.ts.map +1 -0
- package/dist/logging/winston-logger.js +73 -0
- package/dist/logging/winston-logger.js.map +1 -0
- package/dist/matimo-instance.d.ts +140 -0
- package/dist/matimo-instance.d.ts.map +1 -0
- package/dist/matimo-instance.js +412 -0
- package/dist/matimo-instance.js.map +1 -0
- package/package.json +96 -0
- package/tools/calculator/calculator.ts +145 -0
- package/tools/calculator/definition.yaml +70 -0
- package/tools/edit/definition.yaml +115 -0
- package/tools/edit/edit.ts +187 -0
- package/tools/execute/definition.yaml +90 -0
- package/tools/execute/execute.ts +207 -0
- package/tools/read/definition.yaml +106 -0
- package/tools/read/read.ts +118 -0
- package/tools/search/definition.yaml +148 -0
- package/tools/search/search.ts +192 -0
- package/tools/web/definition.yaml +132 -0
- package/tools/web/web.ts +134 -0
|
@@ -0,0 +1,412 @@
|
|
|
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
|
+
import { getLoggerConfig, createLogger, setGlobalMatimoLogger, } from './logging';
|
|
9
|
+
import { getGlobalApprovalHandler } from './approval/approval-handler';
|
|
10
|
+
/**
|
|
11
|
+
* Matimo Instance - Single initialization point for tool execution
|
|
12
|
+
* Combines loader, registry, and executors into one interface
|
|
13
|
+
*/
|
|
14
|
+
export class MatimoInstance {
|
|
15
|
+
constructor(toolPaths, logger) {
|
|
16
|
+
this.toolPaths = toolPaths;
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
this.loader = new ToolLoader();
|
|
19
|
+
this.registry = new ToolRegistry();
|
|
20
|
+
// Use the first path (primary) as working directory for command executor
|
|
21
|
+
const workingDir = toolPaths.length > 0 ? path.dirname(toolPaths[0]) : process.cwd();
|
|
22
|
+
this.commandExecutor = new CommandExecutor(workingDir);
|
|
23
|
+
this.httpExecutor = new HttpExecutor();
|
|
24
|
+
this.functionExecutor = new FunctionExecutor(toolPaths[0] || '');
|
|
25
|
+
this.approvalHandler = getGlobalApprovalHandler();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initialize Matimo with tools from directory or auto-discovery
|
|
29
|
+
* @param options - Initialization options (string for backward compatibility)
|
|
30
|
+
* @returns MatimoInstance ready to execute tools
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Backward compatible - single path
|
|
34
|
+
* const matimo = await MatimoInstance.init('./tools');
|
|
35
|
+
*
|
|
36
|
+
* // New - auto-discovery
|
|
37
|
+
* const matimo = await MatimoInstance.init({ autoDiscover: true });
|
|
38
|
+
*
|
|
39
|
+
* // Explicit paths with logging config
|
|
40
|
+
* const matimo = await MatimoInstance.init({
|
|
41
|
+
* toolPaths: ['./tools'],
|
|
42
|
+
* logLevel: 'debug',
|
|
43
|
+
* logFormat: 'json'
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // Custom logger
|
|
47
|
+
* const matimo = await MatimoInstance.init({
|
|
48
|
+
* toolPaths: ['./tools'],
|
|
49
|
+
* logger: myCustomLogger
|
|
50
|
+
* });
|
|
51
|
+
*/
|
|
52
|
+
static async init(options) {
|
|
53
|
+
let finalOptions;
|
|
54
|
+
// Backward compatibility: if string is passed, treat as toolPath
|
|
55
|
+
if (typeof options === 'string') {
|
|
56
|
+
finalOptions = {
|
|
57
|
+
toolPaths: [options],
|
|
58
|
+
autoDiscover: false,
|
|
59
|
+
includeCore: false,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
finalOptions = {
|
|
64
|
+
autoDiscover: false,
|
|
65
|
+
includeCore: true,
|
|
66
|
+
...options,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Initialize logger from config and environment variables
|
|
70
|
+
const loggerConfig = getLoggerConfig({
|
|
71
|
+
logLevel: finalOptions.logLevel,
|
|
72
|
+
logFormat: finalOptions.logFormat,
|
|
73
|
+
logger: finalOptions.logger,
|
|
74
|
+
});
|
|
75
|
+
const logger = createLogger(loggerConfig);
|
|
76
|
+
// Set global logger for use by modules
|
|
77
|
+
setGlobalMatimoLogger(logger);
|
|
78
|
+
logger.debug('Matimo SDK initializing', {
|
|
79
|
+
logLevel: loggerConfig.logLevel,
|
|
80
|
+
logFormat: loggerConfig.logFormat,
|
|
81
|
+
hasPaths: !!finalOptions.toolPaths?.length,
|
|
82
|
+
autoDiscover: finalOptions.autoDiscover,
|
|
83
|
+
});
|
|
84
|
+
const toolPaths = [];
|
|
85
|
+
// Include core tools (calculator, etc.) - currently not used in monorepo
|
|
86
|
+
// Use explicit toolPaths or autoDiscover instead
|
|
87
|
+
// if (finalOptions.includeCore) { ... }
|
|
88
|
+
// Add explicit paths
|
|
89
|
+
if (finalOptions.toolPaths) {
|
|
90
|
+
toolPaths.push(...finalOptions.toolPaths);
|
|
91
|
+
logger.debug(`Adding explicit tool paths`, { count: finalOptions.toolPaths.length });
|
|
92
|
+
}
|
|
93
|
+
// Auto-discover @matimo/* packages
|
|
94
|
+
if (finalOptions.autoDiscover) {
|
|
95
|
+
const discoveredPaths = new ToolLoader().autoDiscoverPackages();
|
|
96
|
+
toolPaths.push(...discoveredPaths);
|
|
97
|
+
logger.debug(`Auto-discovered tool paths`, { count: discoveredPaths.length });
|
|
98
|
+
}
|
|
99
|
+
const instance = new MatimoInstance(toolPaths, logger);
|
|
100
|
+
// Load tools from all paths
|
|
101
|
+
const allTools = instance.loader.loadToolsFromMultiplePaths(toolPaths);
|
|
102
|
+
instance.registry.registerAll(Array.from(allTools.values()));
|
|
103
|
+
logger.info(`Matimo SDK initialized successfully`, {
|
|
104
|
+
toolCount: allTools.size,
|
|
105
|
+
paths: toolPaths.length,
|
|
106
|
+
});
|
|
107
|
+
return instance;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get tool paths
|
|
111
|
+
* @returns Array of tool paths
|
|
112
|
+
*/
|
|
113
|
+
getToolPaths() {
|
|
114
|
+
return [...this.toolPaths];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the logger instance
|
|
118
|
+
* @returns MatimoLogger instance
|
|
119
|
+
*/
|
|
120
|
+
getLogger() {
|
|
121
|
+
return this.logger;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Execute a tool by name with parameters
|
|
125
|
+
* @param toolName - Name of the tool to execute
|
|
126
|
+
* @param params - Tool parameters
|
|
127
|
+
* @returns Tool execution result
|
|
128
|
+
*/
|
|
129
|
+
async execute(toolName, params) {
|
|
130
|
+
const tool = this.registry.get(toolName);
|
|
131
|
+
if (!tool) {
|
|
132
|
+
const availableTools = this.registry.getAll().map((t) => t.name);
|
|
133
|
+
this.logger.error(`Tool not found: ${toolName}`, {
|
|
134
|
+
toolName,
|
|
135
|
+
availableTools,
|
|
136
|
+
});
|
|
137
|
+
throw new MatimoError(`Tool '${toolName}' not found in registry`, ErrorCode.TOOL_NOT_FOUND, {
|
|
138
|
+
toolName,
|
|
139
|
+
availableTools,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
this.logger.debug(`Executing tool: ${toolName}`, {
|
|
143
|
+
toolName,
|
|
144
|
+
paramCount: Object.keys(params).length,
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
// Simple approval flow:
|
|
148
|
+
// 1. Check if tool requires approval (from YAML or keyword detection)
|
|
149
|
+
// 2. Check if pre-approved via env vars
|
|
150
|
+
// 3. Call approval callback if not pre-approved
|
|
151
|
+
// Prefer execution-type-specific checks to reduce false positives.
|
|
152
|
+
// - `command` tools: scan `params.command`
|
|
153
|
+
// - SQL tools (convention): scan `params.sql`
|
|
154
|
+
// If configured via `MATIMO_APPROVAL_SCAN_ALL_PARAMS=true`, fall back
|
|
155
|
+
// to scanning all string-valued params.
|
|
156
|
+
const executionType = (tool.execution.type || '');
|
|
157
|
+
let scanContent;
|
|
158
|
+
if (executionType === 'command' && typeof params.command === 'string') {
|
|
159
|
+
scanContent = params.command;
|
|
160
|
+
}
|
|
161
|
+
else if (typeof params.sql === 'string') {
|
|
162
|
+
scanContent = params.sql;
|
|
163
|
+
}
|
|
164
|
+
else if (process.env.MATIMO_APPROVAL_SCAN_ALL_PARAMS === 'true') {
|
|
165
|
+
const parts = [];
|
|
166
|
+
for (const val of Object.values(params)) {
|
|
167
|
+
if (typeof val === 'string')
|
|
168
|
+
parts.push(val);
|
|
169
|
+
}
|
|
170
|
+
if (parts.length > 0)
|
|
171
|
+
scanContent = parts.join(' ');
|
|
172
|
+
}
|
|
173
|
+
const requiresApproval = this.approvalHandler.requiresApproval(tool.requires_approval, scanContent);
|
|
174
|
+
if (requiresApproval && !this.approvalHandler.isPreApproved(toolName)) {
|
|
175
|
+
this.logger.debug(`Approval required for: ${toolName}`, { toolName });
|
|
176
|
+
await this.approvalHandler.requestApproval({
|
|
177
|
+
toolName,
|
|
178
|
+
description: tool.description,
|
|
179
|
+
params,
|
|
180
|
+
});
|
|
181
|
+
this.logger.info(`Destructive operation approved: ${toolName}`, { toolName });
|
|
182
|
+
}
|
|
183
|
+
// Auto-inject authentication parameters from environment variables
|
|
184
|
+
const finalParams = this.injectAuthParameters(tool, params);
|
|
185
|
+
const executor = this.getExecutor(tool);
|
|
186
|
+
const result = await executor.execute(tool, finalParams);
|
|
187
|
+
this.logger.debug(`Tool executed successfully: ${toolName}`, {
|
|
188
|
+
toolName,
|
|
189
|
+
hasResult: !!result,
|
|
190
|
+
});
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
this.logger.error(`Tool execution failed: ${toolName}`, {
|
|
195
|
+
toolName,
|
|
196
|
+
error: error instanceof Error ? error.message : String(error),
|
|
197
|
+
});
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get a tool definition by name
|
|
203
|
+
* @param toolName - Name of the tool
|
|
204
|
+
* @returns Tool definition or undefined
|
|
205
|
+
*/
|
|
206
|
+
getTool(toolName) {
|
|
207
|
+
return this.registry.get(toolName);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* List all available tools
|
|
211
|
+
* @returns Array of tool definitions
|
|
212
|
+
*/
|
|
213
|
+
listTools() {
|
|
214
|
+
return this.registry.getAll();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get all available tools (alias for listTools)
|
|
218
|
+
* @returns Array of tool definitions
|
|
219
|
+
*/
|
|
220
|
+
getAllTools() {
|
|
221
|
+
return this.registry.getAll();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Search tools by name or description
|
|
225
|
+
* @param query - Search query
|
|
226
|
+
* @returns Matching tools
|
|
227
|
+
*/
|
|
228
|
+
searchTools(query) {
|
|
229
|
+
return this.registry.search(query);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get tools by tag
|
|
233
|
+
* @param tag - Tag to search for
|
|
234
|
+
* @returns Tools with the given tag
|
|
235
|
+
*/
|
|
236
|
+
getToolsByTag(tag) {
|
|
237
|
+
return this.registry.getByTag(tag);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Automatically inject parameters from environment variables
|
|
241
|
+
* Uses a YAML-native, scale-friendly approach:
|
|
242
|
+
*
|
|
243
|
+
* 1. Scans the execution config for all parameter placeholders
|
|
244
|
+
* 2. For each parameter not provided by user, checks if it looks like auth (TOKEN, KEY, SECRET, etc.)
|
|
245
|
+
* 3. If yes, attempts to load from environment: MATIMO_<PARAM_NAME> or <PARAM_NAME>
|
|
246
|
+
*
|
|
247
|
+
* This works for ANY tool with ANY auth parameter name - no hardcoding needed.
|
|
248
|
+
* Scales to unlimited tools - contributors just submit YAML.
|
|
249
|
+
*
|
|
250
|
+
* Examples:
|
|
251
|
+
* - GMAIL_ACCESS_TOKEN → looks in env vars
|
|
252
|
+
* - GITHUB_TOKEN → looks in env vars
|
|
253
|
+
* - SLACK_BOT_TOKEN → looks in env vars
|
|
254
|
+
* - MY_CUSTOM_API_KEY → looks in env vars
|
|
255
|
+
* - ANY_SECRET → looks in env vars
|
|
256
|
+
*/
|
|
257
|
+
injectAuthParameters(tool, params) {
|
|
258
|
+
const result = { ...params };
|
|
259
|
+
// Collect all parameter names referenced in the execution config
|
|
260
|
+
const referencedParams = this.extractParameterPlaceholders(tool);
|
|
261
|
+
// Auth-related parameter name patterns (case-insensitive)
|
|
262
|
+
const authPatterns = [
|
|
263
|
+
'token',
|
|
264
|
+
'key',
|
|
265
|
+
'secret',
|
|
266
|
+
'password',
|
|
267
|
+
'credential',
|
|
268
|
+
'auth',
|
|
269
|
+
'bearer',
|
|
270
|
+
'api_key',
|
|
271
|
+
];
|
|
272
|
+
// Check each referenced parameter
|
|
273
|
+
for (const paramName of referencedParams) {
|
|
274
|
+
// Skip if user already provided it
|
|
275
|
+
if (paramName in result) {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
// Check if parameter name looks like auth
|
|
279
|
+
const lowerName = paramName.toLowerCase();
|
|
280
|
+
const isAuthParam = authPatterns.some((pattern) => lowerName.includes(pattern));
|
|
281
|
+
if (isAuthParam) {
|
|
282
|
+
// Try to load from environment
|
|
283
|
+
// First try MATIMO_ prefixed version for organization
|
|
284
|
+
let envValue = process.env[`MATIMO_${paramName}`];
|
|
285
|
+
// If not found, try the parameter name directly
|
|
286
|
+
if (!envValue) {
|
|
287
|
+
envValue = process.env[paramName];
|
|
288
|
+
}
|
|
289
|
+
// If found, inject it
|
|
290
|
+
if (envValue) {
|
|
291
|
+
result[paramName] = envValue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Extract all parameter placeholders from execution config
|
|
299
|
+
* Scans headers, body, URL, and query_params for {paramName} patterns
|
|
300
|
+
*/
|
|
301
|
+
extractParameterPlaceholders(tool) {
|
|
302
|
+
const params = new Set();
|
|
303
|
+
const placeholderRegex = /\{([^}]+)\}/g;
|
|
304
|
+
const execution = tool.execution;
|
|
305
|
+
// Scan URL
|
|
306
|
+
if ('url' in execution && execution.url) {
|
|
307
|
+
let match;
|
|
308
|
+
while ((match = placeholderRegex.exec(execution.url)) !== null) {
|
|
309
|
+
params.add(match[1]);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Scan headers
|
|
313
|
+
if ('headers' in execution && execution.headers && typeof execution.headers === 'object') {
|
|
314
|
+
for (const value of Object.values(execution.headers)) {
|
|
315
|
+
if (typeof value === 'string') {
|
|
316
|
+
let match;
|
|
317
|
+
while ((match = placeholderRegex.exec(value)) !== null) {
|
|
318
|
+
params.add(match[1]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// Scan body (recursively for nested objects)
|
|
324
|
+
if ('body' in execution && execution.body) {
|
|
325
|
+
this.scanObjectForParams(execution.body, params);
|
|
326
|
+
}
|
|
327
|
+
// Scan query_params
|
|
328
|
+
if ('query_params' in execution &&
|
|
329
|
+
execution.query_params &&
|
|
330
|
+
typeof execution.query_params === 'object') {
|
|
331
|
+
for (const value of Object.values(execution.query_params)) {
|
|
332
|
+
if (typeof value === 'string') {
|
|
333
|
+
let match;
|
|
334
|
+
while ((match = placeholderRegex.exec(value)) !== null) {
|
|
335
|
+
params.add(match[1]);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return params;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Recursively scan object for parameter placeholders
|
|
344
|
+
*/
|
|
345
|
+
scanObjectForParams(obj, params, visited = new WeakSet()) {
|
|
346
|
+
if (!obj || typeof obj !== 'object') {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// Prevent infinite loops
|
|
350
|
+
if (visited.has(obj)) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
visited.add(obj);
|
|
354
|
+
const placeholderRegex = /\{([^}]+)\}/g;
|
|
355
|
+
if (Array.isArray(obj)) {
|
|
356
|
+
for (const item of obj) {
|
|
357
|
+
if (typeof item === 'string') {
|
|
358
|
+
let match;
|
|
359
|
+
while ((match = placeholderRegex.exec(item)) !== null) {
|
|
360
|
+
params.add(match[1]);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if (item && typeof item === 'object') {
|
|
364
|
+
this.scanObjectForParams(item, params, visited);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
for (const value of Object.values(obj)) {
|
|
370
|
+
if (typeof value === 'string') {
|
|
371
|
+
let match;
|
|
372
|
+
while ((match = placeholderRegex.exec(value)) !== null) {
|
|
373
|
+
params.add(match[1]);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if (value && typeof value === 'object') {
|
|
377
|
+
this.scanObjectForParams(value, params, visited);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get the appropriate executor for a tool
|
|
384
|
+
*/
|
|
385
|
+
getExecutor(tool) {
|
|
386
|
+
const executionType = tool.execution.type;
|
|
387
|
+
switch (executionType) {
|
|
388
|
+
case 'command':
|
|
389
|
+
return this.commandExecutor;
|
|
390
|
+
case 'http':
|
|
391
|
+
return this.httpExecutor;
|
|
392
|
+
case 'function':
|
|
393
|
+
return this.functionExecutor;
|
|
394
|
+
default:
|
|
395
|
+
throw new MatimoError(`Unsupported execution type: ${executionType}`, ErrorCode.EXECUTION_FAILED, { executionType });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Matimo namespace - Entry point for the SDK
|
|
401
|
+
*/
|
|
402
|
+
export const matimo = {
|
|
403
|
+
/**
|
|
404
|
+
* Initialize Matimo with a tools directory
|
|
405
|
+
* @param toolsPath - Path to tools directory
|
|
406
|
+
* @returns MatimoInstance ready to use
|
|
407
|
+
*/
|
|
408
|
+
async init(toolsPath) {
|
|
409
|
+
return MatimoInstance.init(toolsPath);
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
//# 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,2BAA2B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAGL,eAAe,EACf,YAAY,EACZ,qBAAqB,GACtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAmB,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAWxF;;;GAGG;AACH,MAAM,OAAO,cAAc;IAUzB,YAAoB,SAAmB,EAAE,MAAoB;QAC3D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;QACnC,yEAAyE;QACzE,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACrF,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,UAAU,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,CAAC,KAAK,IAAI,EAAE,CAAC;wBACvD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACvB,CAAC;gBACH,CAAC;qBAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC9C,IAAI,CAAC,mBAAmB,CAAC,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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@matimo/core",
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
|
+
"description": "Core SDK for Matimo: Framework-agnostic YAML-driven tool ecosystem for AI agents.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"packageManager": "pnpm@8.15.0",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18.0.0",
|
|
17
|
+
"pnpm": ">=8.0.0"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ai",
|
|
21
|
+
"agent",
|
|
22
|
+
"tools",
|
|
23
|
+
"mcp",
|
|
24
|
+
"llm",
|
|
25
|
+
"claude",
|
|
26
|
+
"langchain",
|
|
27
|
+
"crewai",
|
|
28
|
+
"ai-agent",
|
|
29
|
+
"langchain-tools",
|
|
30
|
+
"claude-tools",
|
|
31
|
+
"framework-agnostic",
|
|
32
|
+
"yaml-tools",
|
|
33
|
+
"agent-toolkit",
|
|
34
|
+
"typescript-ai"
|
|
35
|
+
],
|
|
36
|
+
"author": "Sajesh Nair <vsajeshnair@gmail.com>",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/tallclub/matimo.git"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/tallclub/matimo#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/tallclub/matimo/issues"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"tools",
|
|
49
|
+
"destructive-keywords.yaml",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
],
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
58
|
+
"axios": "^1.13.4",
|
|
59
|
+
"dotenv": "^17.2.3",
|
|
60
|
+
"js-yaml": "^4.1.1",
|
|
61
|
+
"winston": "^3.19.0",
|
|
62
|
+
"yaml": "^2.8.2",
|
|
63
|
+
"zod": "^4.3.6"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@commitlint/cli": "^20.3.1",
|
|
67
|
+
"@commitlint/config-conventional": "^20.3.1",
|
|
68
|
+
"@langchain/core": "^1.1.19",
|
|
69
|
+
"@types/jest": "^30.0.0",
|
|
70
|
+
"@types/js-yaml": "^4.0.9",
|
|
71
|
+
"@types/node": "^25.1.0",
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
73
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
74
|
+
"eslint": "^9.39.2",
|
|
75
|
+
"husky": "^9.1.7",
|
|
76
|
+
"jest": "^30.2.0",
|
|
77
|
+
"langchain": "^1.2.18",
|
|
78
|
+
"prettier": "^3.8.1",
|
|
79
|
+
"ts-jest": "^29.4.6",
|
|
80
|
+
"ts-node": "^10.9.2",
|
|
81
|
+
"tsx": "^4.21.0",
|
|
82
|
+
"typescript": "^5.9.3"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build": "tsc",
|
|
86
|
+
"watch": "tsc --watch",
|
|
87
|
+
"test": "jest",
|
|
88
|
+
"test:watch": "jest --watch",
|
|
89
|
+
"test:coverage": "jest --coverage",
|
|
90
|
+
"lint": "eslint src test --ext .ts",
|
|
91
|
+
"lint:fix": "eslint src test --ext .ts --fix",
|
|
92
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.json\" \"*.md\"",
|
|
93
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
94
|
+
"dev": "tsx src/index.ts"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculator Tool - Perform basic arithmetic operations
|
|
3
|
+
* Pattern: Function-based tool (same as execute)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { MatimoError, ErrorCode } from '../../src/errors/matimo-error';
|
|
7
|
+
import { getGlobalMatimoLogger } from '../../src/logging/logger';
|
|
8
|
+
|
|
9
|
+
interface CalculatorParams {
|
|
10
|
+
operation: string;
|
|
11
|
+
a: number;
|
|
12
|
+
b: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface CalculatorResult {
|
|
16
|
+
result: number;
|
|
17
|
+
operation: string;
|
|
18
|
+
original_operation: string;
|
|
19
|
+
operands: {
|
|
20
|
+
a: number;
|
|
21
|
+
b: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Normalize operation name to handle variations
|
|
27
|
+
*/
|
|
28
|
+
function normalizeOperation(op: string): string {
|
|
29
|
+
const normalized = op.toLowerCase().trim();
|
|
30
|
+
|
|
31
|
+
// Map variations to canonical operation names
|
|
32
|
+
const operationMap: Record<string, string> = {
|
|
33
|
+
// Addition variants
|
|
34
|
+
add: 'add',
|
|
35
|
+
addition: 'add',
|
|
36
|
+
sum: 'add',
|
|
37
|
+
plus: 'add',
|
|
38
|
+
'+': 'add',
|
|
39
|
+
|
|
40
|
+
// Subtraction variants
|
|
41
|
+
subtract: 'subtract',
|
|
42
|
+
subtraction: 'subtract',
|
|
43
|
+
minus: 'subtract',
|
|
44
|
+
sub: 'subtract',
|
|
45
|
+
'-': 'subtract',
|
|
46
|
+
|
|
47
|
+
// Multiplication variants
|
|
48
|
+
multiply: 'multiply',
|
|
49
|
+
multiplication: 'multiply',
|
|
50
|
+
times: 'multiply',
|
|
51
|
+
product: 'multiply',
|
|
52
|
+
mul: 'multiply',
|
|
53
|
+
'*': 'multiply',
|
|
54
|
+
x: 'multiply',
|
|
55
|
+
|
|
56
|
+
// Division variants
|
|
57
|
+
divide: 'divide',
|
|
58
|
+
division: 'divide',
|
|
59
|
+
div: 'divide',
|
|
60
|
+
'/': 'divide',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return operationMap[normalized] || normalized;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Perform arithmetic calculation
|
|
68
|
+
*/
|
|
69
|
+
export default async function calculator(
|
|
70
|
+
params: CalculatorParams
|
|
71
|
+
): Promise<CalculatorResult> {
|
|
72
|
+
const logger = getGlobalMatimoLogger();
|
|
73
|
+
const { operation, a, b } = params;
|
|
74
|
+
|
|
75
|
+
logger.debug('Calculator tool invoked', {
|
|
76
|
+
operation,
|
|
77
|
+
a,
|
|
78
|
+
b,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (typeof a !== 'number' || typeof b !== 'number') {
|
|
82
|
+
logger.error('Invalid calculator parameters', {
|
|
83
|
+
a,
|
|
84
|
+
b,
|
|
85
|
+
expectedTypes: 'numbers',
|
|
86
|
+
});
|
|
87
|
+
throw new MatimoError('Parameters a and b must be numbers', ErrorCode.INVALID_PARAMETER, {
|
|
88
|
+
a,
|
|
89
|
+
b,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const normalizedOp = normalizeOperation(operation);
|
|
94
|
+
let result: number;
|
|
95
|
+
|
|
96
|
+
switch (normalizedOp) {
|
|
97
|
+
case 'add':
|
|
98
|
+
result = a + b;
|
|
99
|
+
break;
|
|
100
|
+
case 'subtract':
|
|
101
|
+
result = a - b;
|
|
102
|
+
break;
|
|
103
|
+
case 'multiply':
|
|
104
|
+
result = a * b;
|
|
105
|
+
break;
|
|
106
|
+
case 'divide':
|
|
107
|
+
if (b === 0) {
|
|
108
|
+
logger.error('Division by zero attempted', {
|
|
109
|
+
a,
|
|
110
|
+
b,
|
|
111
|
+
});
|
|
112
|
+
throw new MatimoError('Division by zero', ErrorCode.EXECUTION_FAILED, {
|
|
113
|
+
a,
|
|
114
|
+
b,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
result = a / b;
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
logger.error('Unsupported calculator operation', {
|
|
121
|
+
operation: normalizedOp,
|
|
122
|
+
requested: operation,
|
|
123
|
+
});
|
|
124
|
+
throw new MatimoError('Invalid operation', ErrorCode.INVALID_PARAMETER, {
|
|
125
|
+
operation,
|
|
126
|
+
normalizedOperation: normalizedOp,
|
|
127
|
+
validOperations: ['add', 'addition', 'sum', 'plus', 'subtract', 'subtraction', 'minus', 'multiply', 'multiplication', 'times', 'divide', 'division', 'div'],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const returnValue = {
|
|
132
|
+
result,
|
|
133
|
+
operation: normalizedOp,
|
|
134
|
+
original_operation: operation,
|
|
135
|
+
operands: { a, b },
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
logger.info('Calculator operation completed', {
|
|
139
|
+
operation: normalizedOp,
|
|
140
|
+
operands: { a, b },
|
|
141
|
+
result,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return returnValue;
|
|
145
|
+
}
|