@frontmcp/plugins 0.4.1 → 0.5.1

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 (98) hide show
  1. package/package.json +8 -3
  2. package/src/cache/cache.plugin.js +27 -25
  3. package/src/cache/cache.plugin.js.map +1 -1
  4. package/src/cache/providers/cache-memory.provider.js +2 -1
  5. package/src/cache/providers/cache-memory.provider.js.map +1 -1
  6. package/src/cache/providers/cache-redis.provider.js +1 -0
  7. package/src/cache/providers/cache-redis.provider.js.map +1 -1
  8. package/src/codecall/README.md +999 -0
  9. package/src/codecall/codecall.plugin.d.ts +41 -0
  10. package/src/codecall/codecall.plugin.js +152 -0
  11. package/src/codecall/codecall.plugin.js.map +1 -0
  12. package/src/codecall/codecall.symbol.d.ts +106 -0
  13. package/src/codecall/codecall.symbol.js +4 -0
  14. package/src/codecall/codecall.symbol.js.map +1 -0
  15. package/src/codecall/codecall.types.d.ts +289 -0
  16. package/src/codecall/codecall.types.js +258 -0
  17. package/src/codecall/codecall.types.js.map +1 -0
  18. package/src/codecall/errors/index.d.ts +1 -0
  19. package/src/codecall/errors/index.js +6 -0
  20. package/src/codecall/errors/index.js.map +1 -0
  21. package/src/codecall/errors/tool-call.errors.d.ts +79 -0
  22. package/src/codecall/errors/tool-call.errors.js +119 -0
  23. package/src/codecall/errors/tool-call.errors.js.map +1 -0
  24. package/src/codecall/index.d.ts +2 -0
  25. package/src/codecall/index.js +8 -0
  26. package/src/codecall/index.js.map +1 -0
  27. package/src/codecall/providers/code-call.config.d.ts +29 -0
  28. package/src/codecall/providers/code-call.config.js +120 -0
  29. package/src/codecall/providers/code-call.config.js.map +1 -0
  30. package/src/codecall/security/index.d.ts +2 -0
  31. package/src/codecall/security/index.js +7 -0
  32. package/src/codecall/security/index.js.map +1 -0
  33. package/src/codecall/security/self-reference-guard.d.ts +32 -0
  34. package/src/codecall/security/self-reference-guard.js +70 -0
  35. package/src/codecall/security/self-reference-guard.js.map +1 -0
  36. package/src/codecall/security/tool-access-control.service.d.ts +104 -0
  37. package/src/codecall/security/tool-access-control.service.js +170 -0
  38. package/src/codecall/security/tool-access-control.service.js.map +1 -0
  39. package/src/codecall/services/audit-logger.service.d.ts +186 -0
  40. package/src/codecall/services/audit-logger.service.js +322 -0
  41. package/src/codecall/services/audit-logger.service.js.map +1 -0
  42. package/src/codecall/services/enclave.service.d.ts +62 -0
  43. package/src/codecall/services/enclave.service.js +214 -0
  44. package/src/codecall/services/enclave.service.js.map +1 -0
  45. package/src/codecall/services/error-enrichment.service.d.ts +94 -0
  46. package/src/codecall/services/error-enrichment.service.js +387 -0
  47. package/src/codecall/services/error-enrichment.service.js.map +1 -0
  48. package/src/codecall/services/index.d.ts +6 -0
  49. package/src/codecall/services/index.js +13 -0
  50. package/src/codecall/services/index.js.map +1 -0
  51. package/src/codecall/services/output-sanitizer.d.ts +86 -0
  52. package/src/codecall/services/output-sanitizer.js +260 -0
  53. package/src/codecall/services/output-sanitizer.js.map +1 -0
  54. package/src/codecall/services/synonym-expansion.service.d.ts +66 -0
  55. package/src/codecall/services/synonym-expansion.service.js +374 -0
  56. package/src/codecall/services/synonym-expansion.service.js.map +1 -0
  57. package/src/codecall/services/tool-search.service.d.ts +175 -0
  58. package/src/codecall/services/tool-search.service.js +587 -0
  59. package/src/codecall/services/tool-search.service.js.map +1 -0
  60. package/src/codecall/tools/describe.schema.d.ts +28 -0
  61. package/src/codecall/tools/describe.schema.js +67 -0
  62. package/src/codecall/tools/describe.schema.js.map +1 -0
  63. package/src/codecall/tools/describe.tool.d.ts +35 -0
  64. package/src/codecall/tools/describe.tool.js +207 -0
  65. package/src/codecall/tools/describe.tool.js.map +1 -0
  66. package/src/codecall/tools/execute.schema.d.ts +115 -0
  67. package/src/codecall/tools/execute.schema.js +116 -0
  68. package/src/codecall/tools/execute.schema.js.map +1 -0
  69. package/src/codecall/tools/execute.tool.d.ts +5 -0
  70. package/src/codecall/tools/execute.tool.js +238 -0
  71. package/src/codecall/tools/execute.tool.js.map +1 -0
  72. package/src/codecall/tools/index.d.ts +4 -0
  73. package/src/codecall/tools/index.js +13 -0
  74. package/src/codecall/tools/index.js.map +1 -0
  75. package/src/codecall/tools/invoke.schema.d.ts +99 -0
  76. package/src/codecall/tools/invoke.schema.js +27 -0
  77. package/src/codecall/tools/invoke.schema.js.map +1 -0
  78. package/src/codecall/tools/invoke.tool.d.ts +13 -0
  79. package/src/codecall/tools/invoke.tool.js +70 -0
  80. package/src/codecall/tools/invoke.tool.js.map +1 -0
  81. package/src/codecall/tools/search.schema.d.ts +30 -0
  82. package/src/codecall/tools/search.schema.js +60 -0
  83. package/src/codecall/tools/search.schema.js.map +1 -0
  84. package/src/codecall/tools/search.tool.d.ts +5 -0
  85. package/src/codecall/tools/search.tool.js +108 -0
  86. package/src/codecall/tools/search.tool.js.map +1 -0
  87. package/src/codecall/utils/describe.utils.d.ts +86 -0
  88. package/src/codecall/utils/describe.utils.js +531 -0
  89. package/src/codecall/utils/describe.utils.js.map +1 -0
  90. package/src/codecall/utils/index.d.ts +2 -0
  91. package/src/codecall/utils/index.js +7 -0
  92. package/src/codecall/utils/index.js.map +1 -0
  93. package/src/codecall/utils/mcp-result.d.ts +6 -0
  94. package/src/codecall/utils/mcp-result.js +36 -0
  95. package/src/codecall/utils/mcp-result.js.map +1 -0
  96. package/src/index.d.ts +2 -0
  97. package/src/index.js +3 -1
  98. package/src/index.js.map +1 -1
@@ -0,0 +1,387 @@
1
+ "use strict";
2
+ // file: libs/plugins/src/codecall/services/error-enrichment.service.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ErrorEnrichmentService = exports.ERROR_CATEGORIES = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const sdk_1 = require("@frontmcp/sdk");
7
+ /**
8
+ * Error categories for classification.
9
+ */
10
+ exports.ERROR_CATEGORIES = {
11
+ /** Script syntax or parsing error */
12
+ SYNTAX: 'syntax',
13
+ /** AST validation blocked dangerous code */
14
+ SECURITY: 'security',
15
+ /** Script exceeded timeout */
16
+ TIMEOUT: 'timeout',
17
+ /** Tool not found */
18
+ TOOL_NOT_FOUND: 'tool_not_found',
19
+ /** Tool access denied */
20
+ TOOL_ACCESS_DENIED: 'tool_access_denied',
21
+ /** Tool validation error */
22
+ TOOL_VALIDATION: 'tool_validation',
23
+ /** Tool execution error */
24
+ TOOL_EXECUTION: 'tool_execution',
25
+ /** Runtime error in script */
26
+ RUNTIME: 'runtime',
27
+ /** Unknown error */
28
+ UNKNOWN: 'unknown',
29
+ };
30
+ /**
31
+ * Error patterns for classification and enrichment.
32
+ */
33
+ const ERROR_PATTERNS = [
34
+ // Syntax errors
35
+ {
36
+ pattern: /SyntaxError|Unexpected token|Unexpected identifier|missing \)|missing \}/i,
37
+ category: exports.ERROR_CATEGORIES.SYNTAX,
38
+ suggestions: [
39
+ 'Check for missing parentheses, brackets, or braces',
40
+ 'Verify all strings are properly quoted',
41
+ 'Ensure semicolons are used correctly (if required)',
42
+ 'Check for typos in keywords like "function", "return", "const"',
43
+ ],
44
+ recoverable: true,
45
+ },
46
+ {
47
+ pattern: /Unterminated string|Invalid or unexpected token/i,
48
+ category: exports.ERROR_CATEGORIES.SYNTAX,
49
+ suggestions: [
50
+ 'Check that all strings are closed with matching quotes',
51
+ 'Ensure template literals use backticks (`)',
52
+ 'Verify there are no unescaped special characters in strings',
53
+ ],
54
+ recoverable: true,
55
+ },
56
+ // Security errors (AST validation)
57
+ {
58
+ pattern: /eval|Function constructor|dangerous pattern|blocked|forbidden/i,
59
+ category: exports.ERROR_CATEGORIES.SECURITY,
60
+ suggestions: [
61
+ 'Avoid using eval() or new Function()',
62
+ 'Do not access global objects like process, require, or import',
63
+ 'Use callTool() to interact with external systems',
64
+ ],
65
+ docs: ['codecall/security'],
66
+ recoverable: true,
67
+ },
68
+ {
69
+ pattern: /self.?reference|codecall:/i,
70
+ category: exports.ERROR_CATEGORIES.SECURITY,
71
+ suggestions: [
72
+ 'CodeCall tools (codecall:*) cannot be called from within scripts',
73
+ 'Use the tools directly from your LLM context instead',
74
+ ],
75
+ recoverable: false,
76
+ },
77
+ // Timeout errors
78
+ {
79
+ pattern: /timeout|timed out|exceeded.*time/i,
80
+ category: exports.ERROR_CATEGORIES.TIMEOUT,
81
+ suggestions: [
82
+ 'Reduce the number of tool calls in your script',
83
+ 'Avoid infinite loops or deep recursion',
84
+ 'Break large operations into smaller scripts',
85
+ 'Consider using pagination for data fetching',
86
+ ],
87
+ recoverable: true,
88
+ },
89
+ // Tool not found
90
+ {
91
+ pattern: /tool.*not found|unknown tool|no such tool/i,
92
+ category: exports.ERROR_CATEGORIES.TOOL_NOT_FOUND,
93
+ suggestions: [
94
+ 'Use codecall:search to find available tools',
95
+ 'Check the tool name for typos',
96
+ 'Verify the tool is available in your current context',
97
+ ],
98
+ example: `// First search for the tool
99
+ const results = await codecall:search({ query: "user management" });
100
+
101
+ // Then use the correct tool name
102
+ const user = await callTool('users:getById', { id: '123' });`,
103
+ recoverable: true,
104
+ },
105
+ // Tool access denied
106
+ {
107
+ pattern: /access denied|permission denied|not authorized|forbidden/i,
108
+ category: exports.ERROR_CATEGORIES.TOOL_ACCESS_DENIED,
109
+ suggestions: [
110
+ 'Check if the tool is in the allowedTools list',
111
+ 'Verify your authentication credentials',
112
+ 'Contact your administrator for access',
113
+ ],
114
+ recoverable: false,
115
+ },
116
+ // Tool validation errors
117
+ {
118
+ pattern: /validation|invalid input|required.*missing|type.*expected/i,
119
+ category: exports.ERROR_CATEGORIES.TOOL_VALIDATION,
120
+ suggestions: [
121
+ 'Use codecall:describe to check the tool input schema',
122
+ 'Ensure all required parameters are provided',
123
+ 'Verify parameter types match the schema',
124
+ ],
125
+ example: `// Check tool schema first
126
+ const schema = await codecall:describe({ toolNames: ['users:create'] });
127
+
128
+ // Then provide correct input
129
+ const user = await callTool('users:create', {
130
+ name: 'John', // required: string
131
+ email: 'j@ex.com', // required: string
132
+ age: 30 // optional: number
133
+ });`,
134
+ recoverable: true,
135
+ },
136
+ // Runtime errors
137
+ {
138
+ pattern: /TypeError|ReferenceError|is not defined|is not a function|cannot read property/i,
139
+ category: exports.ERROR_CATEGORIES.RUNTIME,
140
+ suggestions: [
141
+ 'Check that all variables are defined before use',
142
+ 'Verify function names and property access',
143
+ 'Handle null/undefined values with optional chaining (?.) or nullish coalescing (??)',
144
+ ],
145
+ example: `// Use optional chaining for safe property access
146
+ const name = result?.user?.name ?? 'Unknown';
147
+
148
+ // Check for undefined before using
149
+ if (result && result.data) {
150
+ return result.data;
151
+ }`,
152
+ recoverable: true,
153
+ },
154
+ {
155
+ pattern: /Maximum call stack|stack overflow|too much recursion/i,
156
+ category: exports.ERROR_CATEGORIES.RUNTIME,
157
+ suggestions: [
158
+ 'Check for infinite recursion in your script',
159
+ 'Add a base case to recursive functions',
160
+ 'Consider using iteration instead of recursion',
161
+ ],
162
+ recoverable: true,
163
+ },
164
+ ];
165
+ /**
166
+ * Error Enrichment Service
167
+ *
168
+ * Transforms raw errors into user-friendly, actionable error messages.
169
+ * Provides suggestions for fixing common errors and links to documentation.
170
+ *
171
+ * Security: Never exposes internal details, only provides helpful guidance.
172
+ */
173
+ let ErrorEnrichmentService = class ErrorEnrichmentService {
174
+ /**
175
+ * Enrich an error with category, suggestions, and examples.
176
+ *
177
+ * @param error - The error to enrich (Error object, string, or unknown)
178
+ * @param context - Optional context for more specific suggestions
179
+ * @returns Enriched error with actionable information
180
+ */
181
+ enrich(error, context) {
182
+ const message = this.extractMessage(error);
183
+ const code = this.extractCode(error);
184
+ // Try to match against known patterns
185
+ for (const pattern of ERROR_PATTERNS) {
186
+ if (pattern.pattern.test(message)) {
187
+ return {
188
+ category: pattern.category,
189
+ message: this.formatMessage(message, pattern.category),
190
+ suggestions: this.contextualizeSuggestions(pattern.suggestions, context),
191
+ docs: pattern.docs,
192
+ example: pattern.example,
193
+ code,
194
+ recoverable: pattern.recoverable,
195
+ };
196
+ }
197
+ }
198
+ // Default to unknown error
199
+ return {
200
+ category: exports.ERROR_CATEGORIES.UNKNOWN,
201
+ message: this.formatMessage(message, exports.ERROR_CATEGORIES.UNKNOWN),
202
+ suggestions: [
203
+ 'Check your script for errors',
204
+ 'Use codecall:search to find available tools',
205
+ 'Use codecall:describe to check tool schemas',
206
+ ],
207
+ code,
208
+ recoverable: true,
209
+ };
210
+ }
211
+ /**
212
+ * Enrich a tool-specific error.
213
+ */
214
+ enrichToolError(toolName, errorCode, rawMessage) {
215
+ switch (errorCode) {
216
+ case 'NOT_FOUND':
217
+ return {
218
+ category: exports.ERROR_CATEGORIES.TOOL_NOT_FOUND,
219
+ message: `Tool "${toolName}" was not found`,
220
+ suggestions: [
221
+ `Use codecall:search to find tools similar to "${toolName}"`,
222
+ 'Check the tool name for typos',
223
+ 'The tool may not be available in your current context',
224
+ ],
225
+ recoverable: true,
226
+ };
227
+ case 'ACCESS_DENIED':
228
+ return {
229
+ category: exports.ERROR_CATEGORIES.TOOL_ACCESS_DENIED,
230
+ message: `Access denied for tool "${toolName}"`,
231
+ suggestions: [
232
+ 'Check if the tool is in your allowedTools list',
233
+ 'Verify your authentication credentials',
234
+ 'Contact your administrator if you need access',
235
+ ],
236
+ recoverable: false,
237
+ };
238
+ case 'VALIDATION':
239
+ return {
240
+ category: exports.ERROR_CATEGORIES.TOOL_VALIDATION,
241
+ message: `Input validation failed for tool "${toolName}"`,
242
+ suggestions: [
243
+ `Run codecall:describe({ toolNames: ['${toolName}'] }) to see the expected schema`,
244
+ 'Ensure all required parameters are provided',
245
+ 'Check that parameter types are correct',
246
+ ],
247
+ example: `// Get tool schema
248
+ const info = await callTool('codecall:describe', { toolNames: ['${toolName}'] });
249
+ console.log(info.tools[0].inputSchema);`,
250
+ recoverable: true,
251
+ };
252
+ case 'TIMEOUT':
253
+ return {
254
+ category: exports.ERROR_CATEGORIES.TIMEOUT,
255
+ message: `Tool "${toolName}" execution timed out`,
256
+ suggestions: [
257
+ 'The operation may be taking too long',
258
+ 'Try with simpler or smaller inputs',
259
+ 'Consider breaking the operation into smaller parts',
260
+ ],
261
+ recoverable: true,
262
+ };
263
+ case 'SELF_REFERENCE':
264
+ return {
265
+ category: exports.ERROR_CATEGORIES.SECURITY,
266
+ message: `Cannot call CodeCall tool "${toolName}" from within a script`,
267
+ suggestions: [
268
+ 'CodeCall meta-tools (codecall:*) cannot be called from scripts',
269
+ 'Use these tools directly from your LLM conversation',
270
+ 'For tool calls, use regular tools instead',
271
+ ],
272
+ recoverable: false,
273
+ };
274
+ default:
275
+ return {
276
+ category: exports.ERROR_CATEGORIES.TOOL_EXECUTION,
277
+ message: `Tool "${toolName}" execution failed`,
278
+ suggestions: [
279
+ 'Check the tool input parameters',
280
+ 'Try with simpler inputs to isolate the issue',
281
+ 'The tool may be temporarily unavailable',
282
+ ],
283
+ recoverable: true,
284
+ };
285
+ }
286
+ }
287
+ /**
288
+ * Create a brief error summary for logging.
289
+ */
290
+ summarize(error) {
291
+ const enriched = this.enrich(error);
292
+ return `[${enriched.category}] ${enriched.message}`;
293
+ }
294
+ /**
295
+ * Extract error message from various error types.
296
+ */
297
+ extractMessage(error) {
298
+ if (error instanceof Error) {
299
+ return error.message;
300
+ }
301
+ if (typeof error === 'string') {
302
+ return error;
303
+ }
304
+ if (error && typeof error === 'object' && 'message' in error) {
305
+ return String(error.message);
306
+ }
307
+ return 'An unknown error occurred';
308
+ }
309
+ /**
310
+ * Extract error code if available.
311
+ */
312
+ extractCode(error) {
313
+ if (error && typeof error === 'object' && 'code' in error) {
314
+ return String(error.code);
315
+ }
316
+ return undefined;
317
+ }
318
+ /**
319
+ * Format error message for user consumption.
320
+ * Removes technical details while keeping useful information.
321
+ */
322
+ formatMessage(message, category) {
323
+ // Remove file paths
324
+ let formatted = message.replace(/(?:\/[\w.-]+)+|(?:[A-Za-z]:\\[\w\\.-]+)+/g, '');
325
+ // Remove line numbers
326
+ formatted = formatted.replace(/:\d+:\d+/g, '');
327
+ // Remove stack traces
328
+ formatted = formatted.replace(/\n\s*at .*/g, '');
329
+ // Clean up whitespace
330
+ formatted = formatted.replace(/\s+/g, ' ').trim();
331
+ // Truncate if too long
332
+ if (formatted.length > 200) {
333
+ formatted = formatted.substring(0, 200) + '...';
334
+ }
335
+ // Add category prefix if message is too generic
336
+ if (formatted.length < 20) {
337
+ const prefix = this.getCategoryPrefix(category);
338
+ if (prefix) {
339
+ formatted = `${prefix}: ${formatted}`;
340
+ }
341
+ }
342
+ return formatted || 'An error occurred';
343
+ }
344
+ /**
345
+ * Get a human-readable prefix for error category.
346
+ */
347
+ getCategoryPrefix(category) {
348
+ switch (category) {
349
+ case exports.ERROR_CATEGORIES.SYNTAX:
350
+ return 'Syntax error';
351
+ case exports.ERROR_CATEGORIES.SECURITY:
352
+ return 'Security violation';
353
+ case exports.ERROR_CATEGORIES.TIMEOUT:
354
+ return 'Timeout';
355
+ case exports.ERROR_CATEGORIES.TOOL_NOT_FOUND:
356
+ return 'Tool not found';
357
+ case exports.ERROR_CATEGORIES.TOOL_ACCESS_DENIED:
358
+ return 'Access denied';
359
+ case exports.ERROR_CATEGORIES.TOOL_VALIDATION:
360
+ return 'Validation error';
361
+ case exports.ERROR_CATEGORIES.TOOL_EXECUTION:
362
+ return 'Execution error';
363
+ case exports.ERROR_CATEGORIES.RUNTIME:
364
+ return 'Runtime error';
365
+ default:
366
+ return 'Error';
367
+ }
368
+ }
369
+ /**
370
+ * Contextualize suggestions based on context.
371
+ */
372
+ contextualizeSuggestions(suggestions, context) {
373
+ if (!context?.toolName) {
374
+ return suggestions;
375
+ }
376
+ return suggestions.map((s) => s.replace(/the tool/gi, `"${context.toolName}"`));
377
+ }
378
+ };
379
+ exports.ErrorEnrichmentService = ErrorEnrichmentService;
380
+ exports.ErrorEnrichmentService = ErrorEnrichmentService = tslib_1.__decorate([
381
+ (0, sdk_1.Provider)({
382
+ name: 'codecall:error-enrichment',
383
+ scope: sdk_1.ProviderScope.GLOBAL,
384
+ })
385
+ ], ErrorEnrichmentService);
386
+ exports.default = ErrorEnrichmentService;
387
+ //# sourceMappingURL=error-enrichment.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-enrichment.service.js","sourceRoot":"","sources":["../../../../src/codecall/services/error-enrichment.service.ts"],"names":[],"mappings":";AAAA,uEAAuE;;;;AAEvE,uCAAwD;AAExD;;GAEG;AACU,QAAA,gBAAgB,GAAG;IAC9B,qCAAqC;IACrC,MAAM,EAAE,QAAQ;IAChB,4CAA4C;IAC5C,QAAQ,EAAE,UAAU;IACpB,8BAA8B;IAC9B,OAAO,EAAE,SAAS;IAClB,qBAAqB;IACrB,cAAc,EAAE,gBAAgB;IAChC,yBAAyB;IACzB,kBAAkB,EAAE,oBAAoB;IACxC,4BAA4B;IAC5B,eAAe,EAAE,iBAAiB;IAClC,2BAA2B;IAC3B,cAAc,EAAE,gBAAgB;IAChC,8BAA8B;IAC9B,OAAO,EAAE,SAAS;IAClB,oBAAoB;IACpB,OAAO,EAAE,SAAS;CACV,CAAC;AA0CX;;GAEG;AACH,MAAM,cAAc,GAAmB;IACrC,gBAAgB;IAChB;QACE,OAAO,EAAE,2EAA2E;QACpF,QAAQ,EAAE,wBAAgB,CAAC,MAAM;QACjC,WAAW,EAAE;YACX,oDAAoD;YACpD,wCAAwC;YACxC,oDAAoD;YACpD,gEAAgE;SACjE;QACD,WAAW,EAAE,IAAI;KAClB;IACD;QACE,OAAO,EAAE,kDAAkD;QAC3D,QAAQ,EAAE,wBAAgB,CAAC,MAAM;QACjC,WAAW,EAAE;YACX,wDAAwD;YACxD,4CAA4C;YAC5C,6DAA6D;SAC9D;QACD,WAAW,EAAE,IAAI;KAClB;IAED,mCAAmC;IACnC;QACE,OAAO,EAAE,gEAAgE;QACzE,QAAQ,EAAE,wBAAgB,CAAC,QAAQ;QACnC,WAAW,EAAE;YACX,sCAAsC;YACtC,+DAA+D;YAC/D,kDAAkD;SACnD;QACD,IAAI,EAAE,CAAC,mBAAmB,CAAC;QAC3B,WAAW,EAAE,IAAI;KAClB;IACD;QACE,OAAO,EAAE,4BAA4B;QACrC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AAO,CAAC;QACnB,CAAC;IACH,CAAC;IAED;;OAEG;IACK,wBAAwB,CAAC,WAAqB,EAAE,OAA+B;QACrF,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;YACvB,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClF,CAAC;CACF,CAAA;AAlOY,wDAAsB;iCAAtB,sBAAsB;IAJlC,IAAA,cAAQ,EAAC;QACR,IAAI,EAAE,2BAA2B;QACjC,KAAK,EAAE,mBAAa,CAAC,MAAM;KAC5B,CAAC;GACW,sBAAsB,CAkOlC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/services/error-enrichment.service.ts\n\nimport { Provider, ProviderScope } from '@frontmcp/sdk';\n\n/**\n * Error categories for classification.\n */\nexport const ERROR_CATEGORIES = {\n /** Script syntax or parsing error */\n SYNTAX: 'syntax',\n /** AST validation blocked dangerous code */\n SECURITY: 'security',\n /** Script exceeded timeout */\n TIMEOUT: 'timeout',\n /** Tool not found */\n TOOL_NOT_FOUND: 'tool_not_found',\n /** Tool access denied */\n TOOL_ACCESS_DENIED: 'tool_access_denied',\n /** Tool validation error */\n TOOL_VALIDATION: 'tool_validation',\n /** Tool execution error */\n TOOL_EXECUTION: 'tool_execution',\n /** Runtime error in script */\n RUNTIME: 'runtime',\n /** Unknown error */\n UNKNOWN: 'unknown',\n} as const;\n\nexport type ErrorCategory = (typeof ERROR_CATEGORIES)[keyof typeof ERROR_CATEGORIES];\n\n/**\n * Enriched error with actionable suggestions.\n */\nexport interface EnrichedError {\n /** Error category */\n category: ErrorCategory;\n /** User-friendly error message */\n message: string;\n /** Actionable suggestions for fixing the error */\n suggestions: string[];\n /** Related documentation links */\n docs?: string[];\n /** Example of correct usage (if applicable) */\n example?: string;\n /** Original error code (if available) */\n code?: string;\n /** Whether the error is recoverable */\n recoverable: boolean;\n}\n\n/**\n * Error patterns for classification.\n */\ninterface ErrorPattern {\n /** Pattern to match against error message */\n pattern: RegExp;\n /** Category to assign */\n category: ErrorCategory;\n /** Suggestions for this error type */\n suggestions: string[];\n /** Documentation links */\n docs?: string[];\n /** Example of correct usage */\n example?: string;\n /** Whether this error is recoverable */\n recoverable: boolean;\n}\n\n/**\n * Error patterns for classification and enrichment.\n */\nconst ERROR_PATTERNS: ErrorPattern[] = [\n // Syntax errors\n {\n pattern: /SyntaxError|Unexpected token|Unexpected identifier|missing \\)|missing \\}/i,\n category: ERROR_CATEGORIES.SYNTAX,\n suggestions: [\n 'Check for missing parentheses, brackets, or braces',\n 'Verify all strings are properly quoted',\n 'Ensure semicolons are used correctly (if required)',\n 'Check for typos in keywords like \"function\", \"return\", \"const\"',\n ],\n recoverable: true,\n },\n {\n pattern: /Unterminated string|Invalid or unexpected token/i,\n category: ERROR_CATEGORIES.SYNTAX,\n suggestions: [\n 'Check that all strings are closed with matching quotes',\n 'Ensure template literals use backticks (`)',\n 'Verify there are no unescaped special characters in strings',\n ],\n recoverable: true,\n },\n\n // Security errors (AST validation)\n {\n pattern: /eval|Function constructor|dangerous pattern|blocked|forbidden/i,\n category: ERROR_CATEGORIES.SECURITY,\n suggestions: [\n 'Avoid using eval() or new Function()',\n 'Do not access global objects like process, require, or import',\n 'Use callTool() to interact with external systems',\n ],\n docs: ['codecall/security'],\n recoverable: true,\n },\n {\n pattern: /self.?reference|codecall:/i,\n category: ERROR_CATEGORIES.SECURITY,\n suggestions: [\n 'CodeCall tools (codecall:*) cannot be called from within scripts',\n 'Use the tools directly from your LLM context instead',\n ],\n recoverable: false,\n },\n\n // Timeout errors\n {\n pattern: /timeout|timed out|exceeded.*time/i,\n category: ERROR_CATEGORIES.TIMEOUT,\n suggestions: [\n 'Reduce the number of tool calls in your script',\n 'Avoid infinite loops or deep recursion',\n 'Break large operations into smaller scripts',\n 'Consider using pagination for data fetching',\n ],\n recoverable: true,\n },\n\n // Tool not found\n {\n pattern: /tool.*not found|unknown tool|no such tool/i,\n category: ERROR_CATEGORIES.TOOL_NOT_FOUND,\n suggestions: [\n 'Use codecall:search to find available tools',\n 'Check the tool name for typos',\n 'Verify the tool is available in your current context',\n ],\n example: `// First search for the tool\nconst results = await codecall:search({ query: \"user management\" });\n\n// Then use the correct tool name\nconst user = await callTool('users:getById', { id: '123' });`,\n recoverable: true,\n },\n\n // Tool access denied\n {\n pattern: /access denied|permission denied|not authorized|forbidden/i,\n category: ERROR_CATEGORIES.TOOL_ACCESS_DENIED,\n suggestions: [\n 'Check if the tool is in the allowedTools list',\n 'Verify your authentication credentials',\n 'Contact your administrator for access',\n ],\n recoverable: false,\n },\n\n // Tool validation errors\n {\n pattern: /validation|invalid input|required.*missing|type.*expected/i,\n category: ERROR_CATEGORIES.TOOL_VALIDATION,\n suggestions: [\n 'Use codecall:describe to check the tool input schema',\n 'Ensure all required parameters are provided',\n 'Verify parameter types match the schema',\n ],\n example: `// Check tool schema first\nconst schema = await codecall:describe({ toolNames: ['users:create'] });\n\n// Then provide correct input\nconst user = await callTool('users:create', {\n name: 'John', // required: string\n email: 'j@ex.com', // required: string\n age: 30 // optional: number\n});`,\n recoverable: true,\n },\n\n // Runtime errors\n {\n pattern: /TypeError|ReferenceError|is not defined|is not a function|cannot read property/i,\n category: ERROR_CATEGORIES.RUNTIME,\n suggestions: [\n 'Check that all variables are defined before use',\n 'Verify function names and property access',\n 'Handle null/undefined values with optional chaining (?.) or nullish coalescing (??)',\n ],\n example: `// Use optional chaining for safe property access\nconst name = result?.user?.name ?? 'Unknown';\n\n// Check for undefined before using\nif (result && result.data) {\n return result.data;\n}`,\n recoverable: true,\n },\n {\n pattern: /Maximum call stack|stack overflow|too much recursion/i,\n category: ERROR_CATEGORIES.RUNTIME,\n suggestions: [\n 'Check for infinite recursion in your script',\n 'Add a base case to recursive functions',\n 'Consider using iteration instead of recursion',\n ],\n recoverable: true,\n },\n];\n\n/**\n * Error Enrichment Service\n *\n * Transforms raw errors into user-friendly, actionable error messages.\n * Provides suggestions for fixing common errors and links to documentation.\n *\n * Security: Never exposes internal details, only provides helpful guidance.\n */\n@Provider({\n name: 'codecall:error-enrichment',\n scope: ProviderScope.GLOBAL,\n})\nexport class ErrorEnrichmentService {\n /**\n * Enrich an error with category, suggestions, and examples.\n *\n * @param error - The error to enrich (Error object, string, or unknown)\n * @param context - Optional context for more specific suggestions\n * @returns Enriched error with actionable information\n */\n enrich(error: unknown, context?: { toolName?: string; scriptSnippet?: string }): EnrichedError {\n const message = this.extractMessage(error);\n const code = this.extractCode(error);\n\n // Try to match against known patterns\n for (const pattern of ERROR_PATTERNS) {\n if (pattern.pattern.test(message)) {\n return {\n category: pattern.category,\n message: this.formatMessage(message, pattern.category),\n suggestions: this.contextualizeSuggestions(pattern.suggestions, context),\n docs: pattern.docs,\n example: pattern.example,\n code,\n recoverable: pattern.recoverable,\n };\n }\n }\n\n // Default to unknown error\n return {\n category: ERROR_CATEGORIES.UNKNOWN,\n message: this.formatMessage(message, ERROR_CATEGORIES.UNKNOWN),\n suggestions: [\n 'Check your script for errors',\n 'Use codecall:search to find available tools',\n 'Use codecall:describe to check tool schemas',\n ],\n code,\n recoverable: true,\n };\n }\n\n /**\n * Enrich a tool-specific error.\n */\n enrichToolError(toolName: string, errorCode: string, rawMessage?: string): EnrichedError {\n switch (errorCode) {\n case 'NOT_FOUND':\n return {\n category: ERROR_CATEGORIES.TOOL_NOT_FOUND,\n message: `Tool \"${toolName}\" was not found`,\n suggestions: [\n `Use codecall:search to find tools similar to \"${toolName}\"`,\n 'Check the tool name for typos',\n 'The tool may not be available in your current context',\n ],\n recoverable: true,\n };\n\n case 'ACCESS_DENIED':\n return {\n category: ERROR_CATEGORIES.TOOL_ACCESS_DENIED,\n message: `Access denied for tool \"${toolName}\"`,\n suggestions: [\n 'Check if the tool is in your allowedTools list',\n 'Verify your authentication credentials',\n 'Contact your administrator if you need access',\n ],\n recoverable: false,\n };\n\n case 'VALIDATION':\n return {\n category: ERROR_CATEGORIES.TOOL_VALIDATION,\n message: `Input validation failed for tool \"${toolName}\"`,\n suggestions: [\n `Run codecall:describe({ toolNames: ['${toolName}'] }) to see the expected schema`,\n 'Ensure all required parameters are provided',\n 'Check that parameter types are correct',\n ],\n example: `// Get tool schema\nconst info = await callTool('codecall:describe', { toolNames: ['${toolName}'] });\nconsole.log(info.tools[0].inputSchema);`,\n recoverable: true,\n };\n\n case 'TIMEOUT':\n return {\n category: ERROR_CATEGORIES.TIMEOUT,\n message: `Tool \"${toolName}\" execution timed out`,\n suggestions: [\n 'The operation may be taking too long',\n 'Try with simpler or smaller inputs',\n 'Consider breaking the operation into smaller parts',\n ],\n recoverable: true,\n };\n\n case 'SELF_REFERENCE':\n return {\n category: ERROR_CATEGORIES.SECURITY,\n message: `Cannot call CodeCall tool \"${toolName}\" from within a script`,\n suggestions: [\n 'CodeCall meta-tools (codecall:*) cannot be called from scripts',\n 'Use these tools directly from your LLM conversation',\n 'For tool calls, use regular tools instead',\n ],\n recoverable: false,\n };\n\n default:\n return {\n category: ERROR_CATEGORIES.TOOL_EXECUTION,\n message: `Tool \"${toolName}\" execution failed`,\n suggestions: [\n 'Check the tool input parameters',\n 'Try with simpler inputs to isolate the issue',\n 'The tool may be temporarily unavailable',\n ],\n recoverable: true,\n };\n }\n }\n\n /**\n * Create a brief error summary for logging.\n */\n summarize(error: unknown): string {\n const enriched = this.enrich(error);\n return `[${enriched.category}] ${enriched.message}`;\n }\n\n /**\n * Extract error message from various error types.\n */\n private extractMessage(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n if (typeof error === 'string') {\n return error;\n }\n if (error && typeof error === 'object' && 'message' in error) {\n return String((error as { message: unknown }).message);\n }\n return 'An unknown error occurred';\n }\n\n /**\n * Extract error code if available.\n */\n private extractCode(error: unknown): string | undefined {\n if (error && typeof error === 'object' && 'code' in error) {\n return String((error as { code: unknown }).code);\n }\n return undefined;\n }\n\n /**\n * Format error message for user consumption.\n * Removes technical details while keeping useful information.\n */\n private formatMessage(message: string, category: ErrorCategory): string {\n // Remove file paths\n let formatted = message.replace(/(?:\\/[\\w.-]+)+|(?:[A-Za-z]:\\\\[\\w\\\\.-]+)+/g, '');\n\n // Remove line numbers\n formatted = formatted.replace(/:\\d+:\\d+/g, '');\n\n // Remove stack traces\n formatted = formatted.replace(/\\n\\s*at .*/g, '');\n\n // Clean up whitespace\n formatted = formatted.replace(/\\s+/g, ' ').trim();\n\n // Truncate if too long\n if (formatted.length > 200) {\n formatted = formatted.substring(0, 200) + '...';\n }\n\n // Add category prefix if message is too generic\n if (formatted.length < 20) {\n const prefix = this.getCategoryPrefix(category);\n if (prefix) {\n formatted = `${prefix}: ${formatted}`;\n }\n }\n\n return formatted || 'An error occurred';\n }\n\n /**\n * Get a human-readable prefix for error category.\n */\n private getCategoryPrefix(category: ErrorCategory): string {\n switch (category) {\n case ERROR_CATEGORIES.SYNTAX:\n return 'Syntax error';\n case ERROR_CATEGORIES.SECURITY:\n return 'Security violation';\n case ERROR_CATEGORIES.TIMEOUT:\n return 'Timeout';\n case ERROR_CATEGORIES.TOOL_NOT_FOUND:\n return 'Tool not found';\n case ERROR_CATEGORIES.TOOL_ACCESS_DENIED:\n return 'Access denied';\n case ERROR_CATEGORIES.TOOL_VALIDATION:\n return 'Validation error';\n case ERROR_CATEGORIES.TOOL_EXECUTION:\n return 'Execution error';\n case ERROR_CATEGORIES.RUNTIME:\n return 'Runtime error';\n default:\n return 'Error';\n }\n }\n\n /**\n * Contextualize suggestions based on context.\n */\n private contextualizeSuggestions(suggestions: string[], context?: { toolName?: string }): string[] {\n if (!context?.toolName) {\n return suggestions;\n }\n\n return suggestions.map((s) => s.replace(/the tool/gi, `\"${context.toolName}\"`));\n }\n}\n\nexport default ErrorEnrichmentService;\n"]}
@@ -0,0 +1,6 @@
1
+ export * from './audit-logger.service';
2
+ export * from './output-sanitizer';
3
+ export * from './error-enrichment.service';
4
+ export * from './tool-search.service';
5
+ export * from './synonym-expansion.service';
6
+ export { default as EnclaveService } from './enclave.service';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // file: libs/plugins/src/codecall/services/index.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.EnclaveService = void 0;
5
+ const tslib_1 = require("tslib");
6
+ tslib_1.__exportStar(require("./audit-logger.service"), exports);
7
+ tslib_1.__exportStar(require("./output-sanitizer"), exports);
8
+ tslib_1.__exportStar(require("./error-enrichment.service"), exports);
9
+ tslib_1.__exportStar(require("./tool-search.service"), exports);
10
+ tslib_1.__exportStar(require("./synonym-expansion.service"), exports);
11
+ var enclave_service_1 = require("./enclave.service");
12
+ Object.defineProperty(exports, "EnclaveService", { enumerable: true, get: function () { return tslib_1.__importDefault(enclave_service_1).default; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codecall/services/index.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;AAEpD,iEAAuC;AACvC,6DAAmC;AACnC,qEAA2C;AAC3C,gEAAsC;AACtC,sEAA4C;AAC5C,qDAA8D;AAArD,0IAAA,OAAO,OAAkB","sourcesContent":["// file: libs/plugins/src/codecall/services/index.ts\n\nexport * from './audit-logger.service';\nexport * from './output-sanitizer';\nexport * from './error-enrichment.service';\nexport * from './tool-search.service';\nexport * from './synonym-expansion.service';\nexport { default as EnclaveService } from './enclave.service';\n"]}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Output Sanitizer for CodeCall
3
+ *
4
+ * Sanitizes script outputs to prevent information leakage through:
5
+ * - Error messages with stack traces or file paths
6
+ * - Large outputs that could contain sensitive data
7
+ * - Recursive structures that could cause DoS
8
+ *
9
+ * Security considerations:
10
+ * - All sanitization is defensive (fail-safe)
11
+ * - Outputs are truncated, not rejected
12
+ * - Circular references are handled
13
+ * - Prototype pollution is prevented
14
+ */
15
+ /**
16
+ * Configuration for output sanitization.
17
+ */
18
+ export interface OutputSanitizerConfig {
19
+ /**
20
+ * Maximum depth for nested objects/arrays.
21
+ * @default 10
22
+ */
23
+ maxDepth: number;
24
+ /**
25
+ * Maximum length for string values.
26
+ * @default 10000
27
+ */
28
+ maxStringLength: number;
29
+ /**
30
+ * Maximum number of keys in an object.
31
+ * @default 100
32
+ */
33
+ maxObjectKeys: number;
34
+ /**
35
+ * Maximum number of items in an array.
36
+ * @default 1000
37
+ */
38
+ maxArrayLength: number;
39
+ /**
40
+ * Maximum total size of serialized output in bytes.
41
+ * @default 1MB
42
+ */
43
+ maxTotalSize: number;
44
+ /**
45
+ * Remove error stack traces.
46
+ * @default true
47
+ */
48
+ removeStackTraces: boolean;
49
+ /**
50
+ * Remove file paths from strings.
51
+ * @default true
52
+ */
53
+ removeFilePaths: boolean;
54
+ }
55
+ /**
56
+ * Default sanitization configuration.
57
+ */
58
+ export declare const DEFAULT_SANITIZER_CONFIG: OutputSanitizerConfig;
59
+ /**
60
+ * Result of sanitization.
61
+ */
62
+ export interface SanitizationResult<T> {
63
+ /** Sanitized value */
64
+ value: T;
65
+ /** Whether any sanitization was applied */
66
+ wasModified: boolean;
67
+ /** Warnings about what was sanitized */
68
+ warnings: string[];
69
+ }
70
+ /**
71
+ * Sanitize output from CodeCall script execution.
72
+ *
73
+ * @param output - Raw output from script
74
+ * @param config - Sanitization configuration
75
+ * @returns Sanitized output with metadata
76
+ */
77
+ export declare function sanitizeOutput<T = unknown>(output: unknown, config?: Partial<OutputSanitizerConfig>): SanitizationResult<T>;
78
+ /**
79
+ * Quick check if a value needs sanitization.
80
+ * Used for optimization - skip sanitization for simple values.
81
+ */
82
+ export declare function needsSanitization(value: unknown): boolean;
83
+ /**
84
+ * Sanitize a log message (less aggressive than output sanitization).
85
+ */
86
+ export declare function sanitizeLogMessage(message: string, maxLength?: number): string;