@matimo/core 0.1.0-alpha.9 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +341 -14
  2. package/dist/approval/approval-handler.d.ts +5 -1
  3. package/dist/approval/approval-handler.d.ts.map +1 -1
  4. package/dist/approval/approval-handler.js +7 -1
  5. package/dist/approval/approval-handler.js.map +1 -1
  6. package/dist/auth/oauth2-handler.d.ts +2 -2
  7. package/dist/auth/oauth2-handler.d.ts.map +1 -1
  8. package/dist/auth/oauth2-handler.js +2 -2
  9. package/dist/auth/oauth2-handler.js.map +1 -1
  10. package/dist/auth/oauth2-provider-loader.d.ts +2 -2
  11. package/dist/auth/oauth2-provider-loader.d.ts.map +1 -1
  12. package/dist/auth/oauth2-provider-loader.js +2 -2
  13. package/dist/auth/oauth2-provider-loader.js.map +1 -1
  14. package/dist/core/schema.d.ts +42 -11
  15. package/dist/core/schema.d.ts.map +1 -1
  16. package/dist/core/schema.js +42 -6
  17. package/dist/core/schema.js.map +1 -1
  18. package/dist/core/skill-content-parser.d.ts +91 -0
  19. package/dist/core/skill-content-parser.d.ts.map +1 -0
  20. package/dist/core/skill-content-parser.js +248 -0
  21. package/dist/core/skill-content-parser.js.map +1 -0
  22. package/dist/core/skill-loader.d.ts +46 -0
  23. package/dist/core/skill-loader.d.ts.map +1 -0
  24. package/dist/core/skill-loader.js +311 -0
  25. package/dist/core/skill-loader.js.map +1 -0
  26. package/dist/core/skill-registry.d.ts +131 -0
  27. package/dist/core/skill-registry.d.ts.map +1 -0
  28. package/dist/core/skill-registry.js +316 -0
  29. package/dist/core/skill-registry.js.map +1 -0
  30. package/dist/core/tfidf-embedding.d.ts +45 -0
  31. package/dist/core/tfidf-embedding.d.ts.map +1 -0
  32. package/dist/core/tfidf-embedding.js +199 -0
  33. package/dist/core/tfidf-embedding.js.map +1 -0
  34. package/dist/core/tool-loader.d.ts +4 -2
  35. package/dist/core/tool-loader.d.ts.map +1 -1
  36. package/dist/core/tool-loader.js +35 -12
  37. package/dist/core/tool-loader.js.map +1 -1
  38. package/dist/core/tool-registry.d.ts +1 -1
  39. package/dist/core/tool-registry.d.ts.map +1 -1
  40. package/dist/core/tool-registry.js +1 -1
  41. package/dist/core/tool-registry.js.map +1 -1
  42. package/dist/core/types.d.ts +204 -7
  43. package/dist/core/types.d.ts.map +1 -1
  44. package/dist/decorators/index.d.ts +1 -1
  45. package/dist/decorators/index.d.ts.map +1 -1
  46. package/dist/decorators/index.js +1 -1
  47. package/dist/decorators/index.js.map +1 -1
  48. package/dist/decorators/tool-decorator.js +1 -1
  49. package/dist/decorators/tool-decorator.js.map +1 -1
  50. package/dist/encodings/parameter-encoding.d.ts +1 -1
  51. package/dist/encodings/parameter-encoding.d.ts.map +1 -1
  52. package/dist/encodings/parameter-encoding.js +10 -5
  53. package/dist/encodings/parameter-encoding.js.map +1 -1
  54. package/dist/errors/matimo-error.d.ts +11 -2
  55. package/dist/errors/matimo-error.d.ts.map +1 -1
  56. package/dist/errors/matimo-error.js +25 -1
  57. package/dist/errors/matimo-error.js.map +1 -1
  58. package/dist/executors/command-executor.d.ts +10 -3
  59. package/dist/executors/command-executor.d.ts.map +1 -1
  60. package/dist/executors/command-executor.js +30 -6
  61. package/dist/executors/command-executor.js.map +1 -1
  62. package/dist/executors/function-executor.d.ts +11 -4
  63. package/dist/executors/function-executor.d.ts.map +1 -1
  64. package/dist/executors/function-executor.js +46 -26
  65. package/dist/executors/function-executor.js.map +1 -1
  66. package/dist/executors/http-executor.d.ts +80 -5
  67. package/dist/executors/http-executor.d.ts.map +1 -1
  68. package/dist/executors/http-executor.js +233 -29
  69. package/dist/executors/http-executor.js.map +1 -1
  70. package/dist/index.d.ts +45 -23
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +34 -16
  73. package/dist/index.js.map +1 -1
  74. package/dist/integrations/langchain.d.ts +57 -2
  75. package/dist/integrations/langchain.d.ts.map +1 -1
  76. package/dist/integrations/langchain.js +71 -4
  77. package/dist/integrations/langchain.js.map +1 -1
  78. package/dist/logging/winston-logger.d.ts.map +1 -1
  79. package/dist/logging/winston-logger.js +9 -1
  80. package/dist/logging/winston-logger.js.map +1 -1
  81. package/dist/matimo-instance.d.ts +231 -19
  82. package/dist/matimo-instance.d.ts.map +1 -1
  83. package/dist/matimo-instance.js +747 -48
  84. package/dist/matimo-instance.js.map +1 -1
  85. package/dist/mcp/index.d.ts +18 -0
  86. package/dist/mcp/index.d.ts.map +1 -0
  87. package/dist/mcp/index.js +24 -0
  88. package/dist/mcp/index.js.map +1 -0
  89. package/dist/mcp/mcp-server.d.ts +141 -0
  90. package/dist/mcp/mcp-server.d.ts.map +1 -0
  91. package/dist/mcp/mcp-server.js +754 -0
  92. package/dist/mcp/mcp-server.js.map +1 -0
  93. package/dist/mcp/secrets/aws-resolver.d.ts +41 -0
  94. package/dist/mcp/secrets/aws-resolver.d.ts.map +1 -0
  95. package/dist/mcp/secrets/aws-resolver.js +141 -0
  96. package/dist/mcp/secrets/aws-resolver.js.map +1 -0
  97. package/dist/mcp/secrets/dotenv-resolver.d.ts +23 -0
  98. package/dist/mcp/secrets/dotenv-resolver.d.ts.map +1 -0
  99. package/dist/mcp/secrets/dotenv-resolver.js +94 -0
  100. package/dist/mcp/secrets/dotenv-resolver.js.map +1 -0
  101. package/dist/mcp/secrets/env-resolver.d.ts +14 -0
  102. package/dist/mcp/secrets/env-resolver.d.ts.map +1 -0
  103. package/dist/mcp/secrets/env-resolver.js +27 -0
  104. package/dist/mcp/secrets/env-resolver.js.map +1 -0
  105. package/dist/mcp/secrets/index.d.ts +14 -0
  106. package/dist/mcp/secrets/index.d.ts.map +1 -0
  107. package/dist/mcp/secrets/index.js +13 -0
  108. package/dist/mcp/secrets/index.js.map +1 -0
  109. package/dist/mcp/secrets/resolver-chain.d.ts +34 -0
  110. package/dist/mcp/secrets/resolver-chain.d.ts.map +1 -0
  111. package/dist/mcp/secrets/resolver-chain.js +141 -0
  112. package/dist/mcp/secrets/resolver-chain.js.map +1 -0
  113. package/dist/mcp/secrets/types.d.ts +73 -0
  114. package/dist/mcp/secrets/types.d.ts.map +1 -0
  115. package/dist/mcp/secrets/types.js +8 -0
  116. package/dist/mcp/secrets/types.js.map +1 -0
  117. package/dist/mcp/secrets/vault-resolver.d.ts +43 -0
  118. package/dist/mcp/secrets/vault-resolver.d.ts.map +1 -0
  119. package/dist/mcp/secrets/vault-resolver.js +127 -0
  120. package/dist/mcp/secrets/vault-resolver.js.map +1 -0
  121. package/dist/mcp/tool-converter.d.ts +40 -0
  122. package/dist/mcp/tool-converter.d.ts.map +1 -0
  123. package/dist/mcp/tool-converter.js +185 -0
  124. package/dist/mcp/tool-converter.js.map +1 -0
  125. package/dist/policy/approval-manifest.d.ts +76 -0
  126. package/dist/policy/approval-manifest.d.ts.map +1 -0
  127. package/dist/policy/approval-manifest.js +197 -0
  128. package/dist/policy/approval-manifest.js.map +1 -0
  129. package/dist/policy/content-validator.d.ts +19 -0
  130. package/dist/policy/content-validator.d.ts.map +1 -0
  131. package/dist/policy/content-validator.js +196 -0
  132. package/dist/policy/content-validator.js.map +1 -0
  133. package/dist/policy/default-policy.d.ts +46 -0
  134. package/dist/policy/default-policy.d.ts.map +1 -0
  135. package/dist/policy/default-policy.js +241 -0
  136. package/dist/policy/default-policy.js.map +1 -0
  137. package/dist/policy/events.d.ts +71 -0
  138. package/dist/policy/events.d.ts.map +1 -0
  139. package/dist/policy/events.js +8 -0
  140. package/dist/policy/events.js.map +1 -0
  141. package/dist/policy/index.d.ts +13 -0
  142. package/dist/policy/index.d.ts.map +1 -0
  143. package/dist/policy/index.js +9 -0
  144. package/dist/policy/index.js.map +1 -0
  145. package/dist/policy/integrity-tracker.d.ts +62 -0
  146. package/dist/policy/integrity-tracker.d.ts.map +1 -0
  147. package/dist/policy/integrity-tracker.js +79 -0
  148. package/dist/policy/integrity-tracker.js.map +1 -0
  149. package/dist/policy/policy-loader.d.ts +58 -0
  150. package/dist/policy/policy-loader.d.ts.map +1 -0
  151. package/dist/policy/policy-loader.js +156 -0
  152. package/dist/policy/policy-loader.js.map +1 -0
  153. package/dist/policy/risk-classifier.d.ts +18 -0
  154. package/dist/policy/risk-classifier.d.ts.map +1 -0
  155. package/dist/policy/risk-classifier.js +47 -0
  156. package/dist/policy/risk-classifier.js.map +1 -0
  157. package/dist/policy/types.d.ts +131 -0
  158. package/dist/policy/types.d.ts.map +1 -0
  159. package/dist/policy/types.js +8 -0
  160. package/dist/policy/types.js.map +1 -0
  161. package/package.json +22 -6
  162. package/tools/matimo_approve_tool/definition.yaml +36 -0
  163. package/tools/matimo_approve_tool/matimo_approve_tool.ts +90 -0
  164. package/tools/matimo_create_skill/definition.yaml +46 -0
  165. package/tools/matimo_create_skill/matimo_create_skill.ts +75 -0
  166. package/tools/matimo_create_tool/definition.yaml +48 -0
  167. package/tools/matimo_create_tool/matimo_create_tool.ts +137 -0
  168. package/tools/matimo_get_skill/definition.yaml +60 -0
  169. package/tools/matimo_get_skill/matimo_get_skill.ts +182 -0
  170. package/tools/matimo_get_tool/definition.yaml +36 -0
  171. package/tools/matimo_get_tool/matimo_get_tool.ts +56 -0
  172. package/tools/matimo_get_tool_status/definition.yaml +42 -0
  173. package/tools/matimo_get_tool_status/matimo_get_tool_status.ts +101 -0
  174. package/tools/matimo_list_skills/definition.yaml +52 -0
  175. package/tools/matimo_list_skills/matimo_list_skills.ts +138 -0
  176. package/tools/matimo_list_user_tools/definition.yaml +32 -0
  177. package/tools/matimo_list_user_tools/matimo_list_user_tools.ts +74 -0
  178. package/tools/matimo_reload_tools/definition.yaml +35 -0
  179. package/tools/matimo_reload_tools/matimo_reload_tools.ts +29 -0
  180. package/tools/matimo_search_tools/definition.yaml +32 -0
  181. package/tools/matimo_search_tools/matimo_search_tools.ts +82 -0
  182. package/tools/matimo_validate_skill/definition.yaml +43 -0
  183. package/tools/matimo_validate_skill/matimo_validate_skill.ts +137 -0
  184. package/tools/matimo_validate_tool/definition.yaml +34 -0
  185. package/tools/matimo_validate_tool/matimo_validate_tool.ts +168 -0
  186. package/tools/shared/skill-validation.ts +335 -0
  187. package/LICENSE +0 -21
@@ -1 +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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AAU,aAAa,CAAC,KAAc,EAAE,OAAO,GAAG,qBAAqB;IAC3E,8CAA8C;IAC9C,MAAM,KAAK,GAAG,KAA4C,CAAC;IAC3D,MAAM,QAAQ,GAAG,KAAK,EAAE,QAA+C,CAAC;IACxE,MAAM,UAAU,GAAI,QAAQ,EAAE,MAA6B,IAAI,GAAG,CAAC;IACnE,MAAM,OAAO,GAAG,QAAQ,EAAE,IAA2C,CAAC;IACtE,MAAM,IAAI,GAA4B,EAAE,UAAU,EAAE,CAAC;IACrD,IAAI,OAAO,KAAK,SAAS;QAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAClD,oFAAoF;IACpF,IAAI,CAAC,aAAa,GAAG,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC3D,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,gBAAgB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAC3E,CAAC;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"}
@@ -1,4 +1,4 @@
1
- import { ToolDefinition } from '../core/schema';
1
+ import { ToolDefinition } from '../core/schema.js';
2
2
  /**
3
3
  * CommandExecutor - Executes shell commands
4
4
  * Handles parameter templating, timeouts, and error capture
@@ -7,9 +7,16 @@ export declare class CommandExecutor {
7
7
  private cwd?;
8
8
  constructor(cwd?: string);
9
9
  /**
10
- * Execute a tool that runs a shell command
10
+ * Execute a tool that runs a shell command.
11
+ *
12
+ * @param tool - Tool definition
13
+ * @param params - Tool parameters
14
+ * @param credentials - Optional per-call credential overrides. Keys must match the env-var
15
+ * names used by the tool (e.g. `SLACK_BOT_TOKEN`). When provided they are merged on top of
16
+ * `process.env` inside the child process so the spawned script sees them as normal env vars.
17
+ * Values are never logged. Falls back to the current environment when not provided.
11
18
  */
12
- execute(tool: ToolDefinition, params: Record<string, unknown>): Promise<unknown>;
19
+ execute(tool: ToolDefinition, params: Record<string, unknown>, credentials?: Record<string, string>): Promise<unknown>;
13
20
  /**
14
21
  * Replace parameter placeholders in a string
15
22
  */
@@ -1 +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"}
1
+ {"version":3,"file":"command-executor.d.ts","sourceRoot":"","sources":["../../src/executors/command-executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;GAGG;AAEH,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAC,CAAS;gBAET,GAAG,CAAC,EAAE,MAAM;IAIxB;;;;;;;;;OASG;IACG,OAAO,CACX,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,OAAO,CAAC,OAAO,CAAC;IA4GnB;;OAEG;IACH,OAAO,CAAC,cAAc;CASvB;AAED,eAAe,eAAe,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { spawn } from 'child_process';
2
- import { MatimoError, ErrorCode } from '../errors/matimo-error';
2
+ import { MatimoError, ErrorCode } from '../errors/matimo-error.js';
3
3
  /**
4
4
  * CommandExecutor - Executes shell commands
5
5
  * Handles parameter templating, timeouts, and error capture
@@ -9,9 +9,16 @@ export class CommandExecutor {
9
9
  this.cwd = cwd;
10
10
  }
11
11
  /**
12
- * Execute a tool that runs a shell command
12
+ * Execute a tool that runs a shell command.
13
+ *
14
+ * @param tool - Tool definition
15
+ * @param params - Tool parameters
16
+ * @param credentials - Optional per-call credential overrides. Keys must match the env-var
17
+ * names used by the tool (e.g. `SLACK_BOT_TOKEN`). When provided they are merged on top of
18
+ * `process.env` inside the child process so the spawned script sees them as normal env vars.
19
+ * Values are never logged. Falls back to the current environment when not provided.
13
20
  */
14
- async execute(tool, params) {
21
+ async execute(tool, params, credentials) {
15
22
  if (tool.execution.type !== 'command') {
16
23
  throw new MatimoError('Tool execution type is not command', ErrorCode.EXECUTION_FAILED, {
17
24
  expectedType: 'command',
@@ -20,13 +27,29 @@ export class CommandExecutor {
20
27
  }
21
28
  const { command, args = [], timeout = 30000 } = tool.execution;
22
29
  const startTime = Date.now();
23
- // Implement parameter templating
24
- const templatedCommand = this.templateString(command, params);
30
+ // SECURITY: command must be a fixed executable — never a templated value.
31
+ // Only 'args' may contain {placeholder} tokens.
32
+ // ReDoS protection: commands are typically <256 chars; limit regex testing to 1024 chars
33
+ // to prevent polynomial backtracking on malicious inputs (e.g. repeated opening braces).
34
+ if (command.length <= 1024 && /\{[^}]+\}/u.test(command)) {
35
+ throw new MatimoError(`execution.command must not contain parameter placeholders — only 'args' may be templated. ` +
36
+ `Found: '${command}'. Move the dynamic part into 'args'.`, ErrorCode.EXECUTION_FAILED, { toolName: tool.name });
37
+ }
38
+ else if (command.length > 1024) {
39
+ throw new MatimoError(`execution.command exceeds maximum length (1024 chars): ${command.length} chars. ` +
40
+ 'Command must be a simple executable path.', ErrorCode.EXECUTION_FAILED, { toolName: tool.name, length: command.length });
41
+ }
42
+ const templatedCommand = command; // Never template the executable
25
43
  const templatedArgs = args.map((arg) => this.templateString(arg, params));
26
44
  return new Promise((resolve) => {
27
45
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
46
  const spawnOptions = {
29
47
  stdio: ['pipe', 'pipe', 'pipe'],
48
+ // Merge per-call credentials on top of the current environment so that
49
+ // the spawned process sees them as ordinary env vars. This is safe:
50
+ // values are held only in memory for the duration of the spawn setup
51
+ // and are never written to disk or logged.
52
+ env: credentials ? { ...process.env, ...credentials } : process.env,
30
53
  };
31
54
  // Set working directory if provided
32
55
  if (this.cwd) {
@@ -89,7 +112,8 @@ export class CommandExecutor {
89
112
  let result = str;
90
113
  for (const [key, value] of Object.entries(params)) {
91
114
  const placeholder = `{${key}}`;
92
- result = result.replace(new RegExp(placeholder, 'g'), String(value));
115
+ const replacement = String(value);
116
+ result = result.replace(new RegExp(placeholder, 'g'), () => replacement);
93
117
  }
94
118
  return result;
95
119
  }
@@ -1 +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;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OAAO;wBACP,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE;wBACrB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE;wBACrB,QAAQ;wBACR,QAAQ;qBACT,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC1B,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;gBAExC,OAAO,CAAC;oBACN,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,KAAK,CAAC,OAAO;oBACpB,QAAQ,EAAE,CAAC,CAAC;oBACZ,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,GAAW,EAAE,MAA+B;QACjE,IAAI,MAAM,GAAG,GAAG,CAAC;QACjB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,MAAM,WAAW,GAAG,IAAI,GAAG,GAAG,CAAC;YAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAClC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,eAAe,eAAe,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ToolDefinition } from '../core/schema';
1
+ import { ToolDefinition } from '../core/schema.js';
2
2
  /**
3
3
  * FunctionExecutor - Executes async functions
4
4
  * Supports functions defined in:
@@ -14,10 +14,17 @@ export declare class FunctionExecutor {
14
14
  private toolsPath;
15
15
  constructor(toolsPath?: string);
16
16
  /**
17
- * Execute a tool that runs an async function
18
- * Supports both embedded code and external .ts/.js files
17
+ * Execute a tool that runs an async function.
18
+ * Supports both embedded code and external .ts/.js files.
19
+ *
20
+ * @param tool - Tool definition
21
+ * @param params - Tool parameters
22
+ * @param credentials - Optional per-call credential overrides passed as `context.credentials`
23
+ * to the tool function. The function can use them with:
24
+ * `const token = context?.credentials?.MY_TOKEN ?? process.env.MY_TOKEN;`
25
+ * Values are never logged. Falls back to undefined when not provided.
19
26
  */
20
- execute(tool: ToolDefinition, params: Record<string, unknown>): Promise<unknown>;
27
+ execute(tool: ToolDefinition, params: Record<string, unknown>, credentials?: Record<string, string>): Promise<unknown>;
21
28
  }
22
29
  export default FunctionExecutor;
23
30
  //# sourceMappingURL=function-executor.d.ts.map
@@ -1 +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;AAIhD;;;;;;;;;;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;CAkLvF;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"function-executor.d.ts","sourceRoot":"","sources":["../../src/executors/function-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,CAAC,EAAE,MAAM;IAI9B;;;;;;;;;;OAUG;IACG,OAAO,CACX,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,OAAO,CAAC,OAAO,CAAC;CAkMpB;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,9 +1,7 @@
1
- import fs from 'fs';
2
1
  import path from 'path';
3
2
  import { pathToFileURL } from 'node:url';
4
- import axios from 'axios';
5
- import { MatimoError, ErrorCode } from '../errors/matimo-error';
6
- import { getGlobalMatimoLogger } from '../logging/logger';
3
+ import { MatimoError, ErrorCode } from '../errors/matimo-error.js';
4
+ import { getGlobalMatimoLogger } from '../logging/index.js';
7
5
  /**
8
6
  * FunctionExecutor - Executes async functions
9
7
  * Supports functions defined in:
@@ -20,10 +18,17 @@ export class FunctionExecutor {
20
18
  this.toolsPath = toolsPath || process.cwd();
21
19
  }
22
20
  /**
23
- * Execute a tool that runs an async function
24
- * Supports both embedded code and external .ts/.js files
21
+ * Execute a tool that runs an async function.
22
+ * Supports both embedded code and external .ts/.js files.
23
+ *
24
+ * @param tool - Tool definition
25
+ * @param params - Tool parameters
26
+ * @param credentials - Optional per-call credential overrides passed as `context.credentials`
27
+ * to the tool function. The function can use them with:
28
+ * `const token = context?.credentials?.MY_TOKEN ?? process.env.MY_TOKEN;`
29
+ * Values are never logged. Falls back to undefined when not provided.
25
30
  */
26
- async execute(tool, params) {
31
+ async execute(tool, params, credentials) {
27
32
  if (tool.execution.type !== 'function') {
28
33
  throw new MatimoError('Tool execution type is not function', ErrorCode.EXECUTION_FAILED, {
29
34
  expectedType: 'function',
@@ -129,7 +134,7 @@ export class FunctionExecutor {
129
134
  import(fileUrl)
130
135
  .then((module) => {
131
136
  const fn = (module.default || module);
132
- const result = fn(params);
137
+ const result = fn(params, credentials ? { credentials } : undefined);
133
138
  // Handle both Promise and non-Promise returns
134
139
  if (result instanceof Promise) {
135
140
  result.then(handleSuccess).catch(handleError);
@@ -141,28 +146,43 @@ export class FunctionExecutor {
141
146
  .catch(handleError);
142
147
  }
143
148
  else {
144
- // Execute embedded code (legacy) - create function from string
145
- // SECURITY WARNING: Embedded code execution runs arbitrary JS with fs/path/axios access.
146
- // This is a potential RCE vector if tool YAML files come from untrusted sources.
147
- // Embedded code is DISABLED by default. Must explicitly opt-in via MATIMO_ALLOW_EMBEDDED_CODE=true
148
- const embeddedCodeDisabled = process.env.MATIMO_ALLOW_EMBEDDED_CODE !== 'true';
149
- if (embeddedCodeDisabled) {
150
- throw new MatimoError('Embedded code execution is disabled by default for security. Use external .ts/.js files instead.', ErrorCode.EXECUTION_FAILED, {
149
+ // ── Embedded code execution ──────────────────────────────────────
150
+ // Requires explicit admin opt-in: MATIMO_ALLOW_EMBEDDED_CODE=true
151
+ // Even when enabled, a static security scan runs before evaluation
152
+ // to block known exploit patterns. No dangerous globals are passed
153
+ // into the sandbox only `params` is accessible.
154
+ if (process.env.MATIMO_ALLOW_EMBEDDED_CODE !== 'true') {
155
+ throw new MatimoError(`Tool '${tool.name}': embedded code execution is disabled by default. ` +
156
+ 'Set MATIMO_ALLOW_EMBEDDED_CODE=true to enable, or use a colocated .ts/.js file instead ' +
157
+ "(set execution.code to its relative path, e.g. './my-tool.ts').", ErrorCode.EXECUTION_FAILED, {
151
158
  toolName: tool.name,
152
- recommendation: 'Create a separate .ts file in the tool directory instead of using embedded code',
153
- enableFeatureFlag: 'Set MATIMO_ALLOW_EMBEDDED_CODE=true to enable (not recommended)',
159
+ recommendation: 'Create a separate .ts file in the tool directory and set execution.code to its relative path',
154
160
  });
155
161
  }
156
- // Log warning when embedded code is executed
162
+ // Static security scan reject code containing dangerous constructs
163
+ // BEFORE new Function() is ever called.
164
+ const BLOCKED_PATTERNS = [
165
+ { re: /\brequire\s*\(/u, label: 'require()' },
166
+ { re: /\bimport\s*\(/u, label: 'dynamic import()' },
167
+ { re: /\bprocess\b/u, label: 'process object' },
168
+ { re: /\b__dirname\b|\b__filename\b/u, label: '__dirname / __filename' },
169
+ { re: /\beval\s*\(/u, label: 'eval()' },
170
+ { re: /\bnew\s+Function\b/u, label: 'new Function()' },
171
+ { re: /\bglobalThis\b|\bglobal\b/u, label: 'global / globalThis' },
172
+ ];
173
+ for (const { re, label } of BLOCKED_PATTERNS) {
174
+ if (re.test(code)) {
175
+ throw new MatimoError(`Embedded code in tool '${tool.name}' contains a blocked construct: '${label}'. ` +
176
+ 'Embedded code may only access the provided params argument.', ErrorCode.EXECUTION_FAILED, { toolName: tool.name, blockedConstruct: label });
177
+ }
178
+ }
157
179
  const logger = getGlobalMatimoLogger();
158
- logger.warn(`⚠️ Warning: Executing embedded code from tool '${tool.name}'. This carries security risks if tool YAML is from untrusted sources.`, { toolName: tool.name });
159
- // In ESM modules, require is not available by default
160
- // We pass a safe require function that embedded code can use
161
- const functionBody = `return (${code})`;
162
- const fn = new Function(functionBody)();
163
- // Pass undefined for require in ESM - embedded code should use import syntax
164
- const result = fn(params, {}, fs, path, axios, undefined);
165
- // Handle both Promise and non-Promise returns
180
+ logger.warn(`Executing embedded code for tool '${tool.name}'. Ensure this tool YAML is from a trusted source.`, { toolName: tool.name });
181
+ // Execute with strict mode and only params in scope.
182
+ // No fs, path, axios, or require are passed embedded code is
183
+ // intentionally limited to pure data transformation of params.
184
+ const fn = new Function('params', '"use strict";\nreturn (' + code + ')(params);');
185
+ const result = fn(params);
166
186
  if (result instanceof Promise) {
167
187
  result.then(handleSuccess).catch(handleError);
168
188
  }
@@ -1 +1 @@
1
- {"version":3,"file":"function-executor.js","sourceRoot":"","sources":["../../src/executors/function-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AA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,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;oBAE1D,8CAA8C;oBAC9C,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;wBAC9B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;oBAChD,CAAC;yBAAM,CAAC;wBACN,aAAa,CAAC,MAAM,CAAC,CAAC;oBACxB,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,WAAW,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"function-executor.js","sourceRoot":"","sources":["../../src/executors/function-executor.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,gBAAgB;IAG3B,YAAY,SAAkB;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,OAAO,CACX,IAAoB,EACpB,MAA+B,EAC/B,WAAoC;QAEpC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACvC,MAAM,IAAI,WAAW,CAAC,qCAAqC,EAAE,SAAS,CAAC,gBAAgB,EAAE;gBACvF,YAAY,EAAE,UAAU;gBACxB,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI;aAChC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,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C;wBACJ,CAAC;oBACH,CAAC;oBAED,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAC;oBACvC,MAAM,CAAC,IAAI,CACT,qCAAqC,IAAI,CAAC,IAAI,oDAAoD,EAClG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CACxB,CAAC;oBAEF,qDAAqD;oBACrD,+DAA+D;oBAC/D,+DAA+D;oBAC/D,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,GAAG,YAAY,CAE5D,CAAC;oBAEtB,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;oBAC1B,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;wBAC9B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;oBAChD,CAAC;yBAAM,CAAC;wBACN,aAAa,CAAC,MAAM,CAAC,CAAC;oBACxB,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,WAAW,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,24 +1,99 @@
1
- import { ToolDefinition } from '../core/schema';
1
+ import { ToolDefinition } from '../core/schema.js';
2
2
  /**
3
3
  * HttpExecutor - Executes HTTP requests
4
4
  * Handles authentication, retries, and response validation
5
5
  */
6
6
  export declare class HttpExecutor {
7
7
  /**
8
- * Execute a tool that makes an HTTP request
8
+ * Execute a tool that makes an HTTP request.
9
+ *
10
+ * @param tool - Tool definition
11
+ * @param params - Tool parameters (already env-injected by MatimoInstance)
12
+ * @param credentials - Optional per-call credential overrides. Used for
13
+ * `authentication.type: basic` (username_env / password_env keys) instead of
14
+ * reading from `process.env`. Other auth schemes (bearer, api_key) are handled
15
+ * upstream via parameter templating in MatimoInstance.injectAuthParameters().
16
+ * Values are never logged.
9
17
  */
10
- execute(tool: ToolDefinition, params: Record<string, unknown>): Promise<unknown>;
18
+ execute(tool: ToolDefinition, params: Record<string, unknown>, credentials?: Record<string, string>): Promise<unknown>;
19
+ /**
20
+ * Automatically inject `Authorization: Basic <base64(username:password)>` when
21
+ * the tool declares `authentication.type: basic` with `username_env` and `password_env`.
22
+ *
23
+ * This is a zero-friction pattern: developers only set two natural env vars
24
+ * (e.g. TWILIO_ACCOUNT_SID + TWILIO_AUTH_TOKEN) and Matimo handles encoding.
25
+ * No pre-computed base64 credential string required.
26
+ *
27
+ * When `credentials` is provided the lookup order is:
28
+ * 1. `credentials[envVarName]` (per-call override — multi-tenant use)
29
+ * 2. `process.env[envVarName]` (singleton / single-tenant fallback)
30
+ *
31
+ * Credential values are never logged or included in error details.
32
+ */
33
+ private applyBasicAuth;
11
34
  /**
12
35
  * Replace parameter placeholders in a string
13
36
  */
14
37
  private templateString;
38
+ /**
39
+ * Check if a string is an unfilled placeholder
40
+ * Only matches single placeholders like "{param}", not "{...}" or embedded placeholders
41
+ */
42
+ private isUnfilledPlaceholder;
43
+ /**
44
+ * Validate that all URL parameters are provided
45
+ */
46
+ private validateUrlParameters;
15
47
  /**
16
48
  * Build query string from query_params, only including provided values
17
49
  */
18
50
  private buildQueryString;
19
51
  /**
20
- * Replace parameter placeholders in an object (headers, body)
21
- * Recursively handles nested objects
52
+ * Replace parameter placeholders in an object (headers, body, query params)
53
+ *
54
+ * CORE PRINCIPLE: "Define once in YAML, embed correctly at execution time"
55
+ *
56
+ * This method intelligently handles different parameter types:
57
+ * - STRING placeholders like "{title}": Always templated as strings
58
+ * - OBJECT placeholders like "{parent}": Embedded directly as JSON objects (not stringified) if paramDefinitions specifies type:object
59
+ * - ARRAY placeholders like "{items}": Embedded directly as JSON arrays (not stringified) if paramDefinitions specifies type:array
60
+ *
61
+ * Key behaviors:
62
+ * - Recursively processes nested objects
63
+ * - Skips keys with unfilled placeholders (e.g., "{sort_by}" when sort_by not provided)
64
+ * - Uses parameter schema type from YAML to determine how to embed values
65
+ * - Preserves JSON structure for complex types (objects/arrays) sent to APIs
66
+ *
67
+ * @example
68
+ * ```
69
+ * // YAML definition:
70
+ * parameters:
71
+ * parent:
72
+ * type: object // <-- Tells executor to embed as-is, not stringify
73
+ * items:
74
+ * type: array // <-- Tells executor to embed as-is, not stringify
75
+ * title:
76
+ * type: string // <-- String templating applies
77
+ *
78
+ * body:
79
+ * parent: "{parent}" // Object embedded as {"id": "123", ...}
80
+ * items: "{items}" // Array embedded as [{"name": "a"}, ...]
81
+ * title: "{title}" // String embedded as "My Title"
82
+ *
83
+ * // JavaScript call:
84
+ * const result = await matimo.execute('notion_create_page', {
85
+ * parent: { database_id: 'abc123' }, // JavaScript object
86
+ * items: [{ type: 'text' }], // JavaScript array
87
+ * title: 'Create This Page' // String
88
+ * });
89
+ *
90
+ * // HTTP body sent to API:
91
+ * {
92
+ * "parent": {"database_id": "abc123"}, // Proper JSON object
93
+ * "items": [{"type": "text"}], // Proper JSON array
94
+ * "title": "Create This Page" // String
95
+ * }
96
+ * ```
22
97
  */
23
98
  private templateObject;
24
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http-executor.d.ts","sourceRoot":"","sources":["../../src/executors/http-executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;;GAGG;AAEH,qBAAa,YAAY;IACvB;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAoFtF;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;OAGG;IACH,OAAO,CAAC,cAAc;CA2BvB;AAED,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"http-executor.d.ts","sourceRoot":"","sources":["../../src/executors/http-executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;;GAGG;AAEH,qBAAa,YAAY;IACvB;;;;;;;;;;OAUG;IACG,OAAO,CACX,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,OAAO,CAAC,OAAO,CAAC;IAmHnB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,cAAc;IA4BtB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;IACH,OAAO,CAAC,cAAc;CA+GvB;AAED,eAAe,YAAY,CAAC"}