@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.
- package/package.json +8 -3
- package/src/cache/cache.plugin.js +27 -25
- package/src/cache/cache.plugin.js.map +1 -1
- package/src/cache/providers/cache-memory.provider.js +2 -1
- package/src/cache/providers/cache-memory.provider.js.map +1 -1
- package/src/cache/providers/cache-redis.provider.js +1 -0
- package/src/cache/providers/cache-redis.provider.js.map +1 -1
- package/src/codecall/README.md +999 -0
- package/src/codecall/codecall.plugin.d.ts +41 -0
- package/src/codecall/codecall.plugin.js +152 -0
- package/src/codecall/codecall.plugin.js.map +1 -0
- package/src/codecall/codecall.symbol.d.ts +106 -0
- package/src/codecall/codecall.symbol.js +4 -0
- package/src/codecall/codecall.symbol.js.map +1 -0
- package/src/codecall/codecall.types.d.ts +289 -0
- package/src/codecall/codecall.types.js +258 -0
- package/src/codecall/codecall.types.js.map +1 -0
- package/src/codecall/errors/index.d.ts +1 -0
- package/src/codecall/errors/index.js +6 -0
- package/src/codecall/errors/index.js.map +1 -0
- package/src/codecall/errors/tool-call.errors.d.ts +79 -0
- package/src/codecall/errors/tool-call.errors.js +119 -0
- package/src/codecall/errors/tool-call.errors.js.map +1 -0
- package/src/codecall/index.d.ts +2 -0
- package/src/codecall/index.js +8 -0
- package/src/codecall/index.js.map +1 -0
- package/src/codecall/providers/code-call.config.d.ts +29 -0
- package/src/codecall/providers/code-call.config.js +120 -0
- package/src/codecall/providers/code-call.config.js.map +1 -0
- package/src/codecall/security/index.d.ts +2 -0
- package/src/codecall/security/index.js +7 -0
- package/src/codecall/security/index.js.map +1 -0
- package/src/codecall/security/self-reference-guard.d.ts +32 -0
- package/src/codecall/security/self-reference-guard.js +70 -0
- package/src/codecall/security/self-reference-guard.js.map +1 -0
- package/src/codecall/security/tool-access-control.service.d.ts +104 -0
- package/src/codecall/security/tool-access-control.service.js +170 -0
- package/src/codecall/security/tool-access-control.service.js.map +1 -0
- package/src/codecall/services/audit-logger.service.d.ts +186 -0
- package/src/codecall/services/audit-logger.service.js +322 -0
- package/src/codecall/services/audit-logger.service.js.map +1 -0
- package/src/codecall/services/enclave.service.d.ts +62 -0
- package/src/codecall/services/enclave.service.js +214 -0
- package/src/codecall/services/enclave.service.js.map +1 -0
- package/src/codecall/services/error-enrichment.service.d.ts +94 -0
- package/src/codecall/services/error-enrichment.service.js +387 -0
- package/src/codecall/services/error-enrichment.service.js.map +1 -0
- package/src/codecall/services/index.d.ts +6 -0
- package/src/codecall/services/index.js +13 -0
- package/src/codecall/services/index.js.map +1 -0
- package/src/codecall/services/output-sanitizer.d.ts +86 -0
- package/src/codecall/services/output-sanitizer.js +260 -0
- package/src/codecall/services/output-sanitizer.js.map +1 -0
- package/src/codecall/services/synonym-expansion.service.d.ts +66 -0
- package/src/codecall/services/synonym-expansion.service.js +374 -0
- package/src/codecall/services/synonym-expansion.service.js.map +1 -0
- package/src/codecall/services/tool-search.service.d.ts +175 -0
- package/src/codecall/services/tool-search.service.js +587 -0
- package/src/codecall/services/tool-search.service.js.map +1 -0
- package/src/codecall/tools/describe.schema.d.ts +28 -0
- package/src/codecall/tools/describe.schema.js +67 -0
- package/src/codecall/tools/describe.schema.js.map +1 -0
- package/src/codecall/tools/describe.tool.d.ts +35 -0
- package/src/codecall/tools/describe.tool.js +207 -0
- package/src/codecall/tools/describe.tool.js.map +1 -0
- package/src/codecall/tools/execute.schema.d.ts +115 -0
- package/src/codecall/tools/execute.schema.js +116 -0
- package/src/codecall/tools/execute.schema.js.map +1 -0
- package/src/codecall/tools/execute.tool.d.ts +5 -0
- package/src/codecall/tools/execute.tool.js +238 -0
- package/src/codecall/tools/execute.tool.js.map +1 -0
- package/src/codecall/tools/index.d.ts +4 -0
- package/src/codecall/tools/index.js +13 -0
- package/src/codecall/tools/index.js.map +1 -0
- package/src/codecall/tools/invoke.schema.d.ts +99 -0
- package/src/codecall/tools/invoke.schema.js +27 -0
- package/src/codecall/tools/invoke.schema.js.map +1 -0
- package/src/codecall/tools/invoke.tool.d.ts +13 -0
- package/src/codecall/tools/invoke.tool.js +70 -0
- package/src/codecall/tools/invoke.tool.js.map +1 -0
- package/src/codecall/tools/search.schema.d.ts +30 -0
- package/src/codecall/tools/search.schema.js +60 -0
- package/src/codecall/tools/search.schema.js.map +1 -0
- package/src/codecall/tools/search.tool.d.ts +5 -0
- package/src/codecall/tools/search.tool.js +108 -0
- package/src/codecall/tools/search.tool.js.map +1 -0
- package/src/codecall/utils/describe.utils.d.ts +86 -0
- package/src/codecall/utils/describe.utils.js +531 -0
- package/src/codecall/utils/describe.utils.js.map +1 -0
- package/src/codecall/utils/index.d.ts +2 -0
- package/src/codecall/utils/index.js +7 -0
- package/src/codecall/utils/index.js.map +1 -0
- package/src/codecall/utils/mcp-result.d.ts +6 -0
- package/src/codecall/utils/mcp-result.js +36 -0
- package/src/codecall/utils/mcp-result.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: libs/plugins/src/codecall/codecall.types.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.codeCallPluginOptionsSchema = exports.codeCallSidecarOptionsSchema = exports.codeCallEmbeddingOptionsSchema = exports.synonymExpansionConfigSchema = exports.embeddingStrategySchema = exports.codeCallDirectCallsOptionsSchema = exports.codeCallVmOptionsSchema = exports.codeCallVmPresetSchema = exports.codeCallModeSchema = void 0;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
// Helper schemas for filter functions with runtime validation
|
|
7
|
+
const directCallsFilterSchema = zod_1.z.custom((val) => typeof val === 'function', {
|
|
8
|
+
message: 'filter must be a function with signature (tool: DirectCallsFilterToolInfo) => boolean',
|
|
9
|
+
});
|
|
10
|
+
const includeToolsFilterSchema = zod_1.z.custom((val) => typeof val === 'function', {
|
|
11
|
+
message: 'includeTools must be a function with signature (tool: IncludeToolsFilterToolInfo) => boolean',
|
|
12
|
+
});
|
|
13
|
+
// ===== Zod Schemas with Defaults =====
|
|
14
|
+
exports.codeCallModeSchema = zod_1.z
|
|
15
|
+
.enum(['codecall_only', 'codecall_opt_in', 'metadata_driven'])
|
|
16
|
+
.default('codecall_only');
|
|
17
|
+
exports.codeCallVmPresetSchema = zod_1.z.enum(['locked_down', 'secure', 'balanced', 'experimental']).default('secure');
|
|
18
|
+
// Default values for VM options
|
|
19
|
+
const DEFAULT_VM_OPTIONS = {
|
|
20
|
+
preset: 'secure',
|
|
21
|
+
};
|
|
22
|
+
exports.codeCallVmOptionsSchema = zod_1.z
|
|
23
|
+
.object({
|
|
24
|
+
/**
|
|
25
|
+
* CSP-like preset; see README.
|
|
26
|
+
* @default 'secure'
|
|
27
|
+
*/
|
|
28
|
+
preset: exports.codeCallVmPresetSchema,
|
|
29
|
+
/**
|
|
30
|
+
* Timeout for script execution in milliseconds
|
|
31
|
+
* Defaults vary by preset
|
|
32
|
+
*/
|
|
33
|
+
timeoutMs: zod_1.z.number().positive().optional(),
|
|
34
|
+
/**
|
|
35
|
+
* Allow loop constructs (for, while, do-while)
|
|
36
|
+
* Defaults vary by preset
|
|
37
|
+
*/
|
|
38
|
+
allowLoops: zod_1.z.boolean().optional(),
|
|
39
|
+
/**
|
|
40
|
+
* Maximum number of steps (if applicable)
|
|
41
|
+
* Defaults vary by preset
|
|
42
|
+
*/
|
|
43
|
+
maxSteps: zod_1.z.number().positive().optional(),
|
|
44
|
+
/**
|
|
45
|
+
* List of disabled builtin functions
|
|
46
|
+
* Defaults vary by preset
|
|
47
|
+
*/
|
|
48
|
+
disabledBuiltins: zod_1.z.array(zod_1.z.string()).optional(),
|
|
49
|
+
/**
|
|
50
|
+
* List of disabled global variables
|
|
51
|
+
* Defaults vary by preset
|
|
52
|
+
*/
|
|
53
|
+
disabledGlobals: zod_1.z.array(zod_1.z.string()).optional(),
|
|
54
|
+
/**
|
|
55
|
+
* Allow console.log/warn/error
|
|
56
|
+
* Defaults vary by preset
|
|
57
|
+
*/
|
|
58
|
+
allowConsole: zod_1.z.boolean().optional(),
|
|
59
|
+
})
|
|
60
|
+
.default(() => DEFAULT_VM_OPTIONS);
|
|
61
|
+
exports.codeCallDirectCallsOptionsSchema = zod_1.z.object({
|
|
62
|
+
/**
|
|
63
|
+
* Enable/disable the `codecall.invoke` meta-tool.
|
|
64
|
+
*/
|
|
65
|
+
enabled: zod_1.z.boolean(),
|
|
66
|
+
/**
|
|
67
|
+
* Optional allowlist of tool names.
|
|
68
|
+
*/
|
|
69
|
+
allowedTools: zod_1.z.array(zod_1.z.string()).optional(),
|
|
70
|
+
/**
|
|
71
|
+
* Optional advanced filter function.
|
|
72
|
+
* Signature: (tool: DirectCallsFilterToolInfo) => boolean
|
|
73
|
+
*/
|
|
74
|
+
filter: directCallsFilterSchema.optional(),
|
|
75
|
+
});
|
|
76
|
+
exports.embeddingStrategySchema = zod_1.z.enum(['tfidf', 'ml']).default('tfidf');
|
|
77
|
+
// Synonym expansion configuration schema
|
|
78
|
+
exports.synonymExpansionConfigSchema = zod_1.z
|
|
79
|
+
.object({
|
|
80
|
+
/**
|
|
81
|
+
* Enable/disable synonym expansion for TF-IDF search.
|
|
82
|
+
* When enabled, queries are expanded with synonyms to improve relevance.
|
|
83
|
+
* For example, "add user" will also match tools containing "create user".
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
86
|
+
enabled: zod_1.z.boolean().default(true),
|
|
87
|
+
/**
|
|
88
|
+
* Additional synonym groups beyond the defaults.
|
|
89
|
+
* Each group is an array of related terms that should be treated as equivalent.
|
|
90
|
+
* @example [['customer', 'client', 'buyer'], ['order', 'purchase', 'transaction']]
|
|
91
|
+
*/
|
|
92
|
+
additionalSynonyms: zod_1.z.array(zod_1.z.array(zod_1.z.string())).optional(),
|
|
93
|
+
/**
|
|
94
|
+
* Replace default synonyms entirely with additionalSynonyms.
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
replaceDefaults: zod_1.z.boolean().default(false),
|
|
98
|
+
/**
|
|
99
|
+
* Maximum number of synonym expansions per term.
|
|
100
|
+
* Prevents query explosion for terms with many synonyms.
|
|
101
|
+
* @default 5
|
|
102
|
+
*/
|
|
103
|
+
maxExpansionsPerTerm: zod_1.z.number().positive().default(5),
|
|
104
|
+
})
|
|
105
|
+
.default({ enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 });
|
|
106
|
+
// Default values for embedding options
|
|
107
|
+
const DEFAULT_EMBEDDING_OPTIONS = {
|
|
108
|
+
strategy: 'tfidf',
|
|
109
|
+
modelName: 'Xenova/all-MiniLM-L6-v2',
|
|
110
|
+
cacheDir: './.cache/transformers',
|
|
111
|
+
useHNSW: false,
|
|
112
|
+
synonymExpansion: { enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 },
|
|
113
|
+
};
|
|
114
|
+
exports.codeCallEmbeddingOptionsSchema = zod_1.z
|
|
115
|
+
.object({
|
|
116
|
+
/**
|
|
117
|
+
* Embedding strategy to use for tool search
|
|
118
|
+
* - 'tfidf': Lightweight, synchronous TF-IDF based search (no ML models required)
|
|
119
|
+
* - 'ml': ML-based semantic search using transformers.js (better quality, requires model download)
|
|
120
|
+
* @default 'tfidf'
|
|
121
|
+
*/
|
|
122
|
+
strategy: exports.embeddingStrategySchema,
|
|
123
|
+
/**
|
|
124
|
+
* Model name for ML-based embeddings (only used when strategy='ml')
|
|
125
|
+
* @default 'Xenova/all-MiniLM-L6-v2'
|
|
126
|
+
*/
|
|
127
|
+
modelName: zod_1.z.string().default('Xenova/all-MiniLM-L6-v2'),
|
|
128
|
+
/**
|
|
129
|
+
* Cache directory for ML models (only used when strategy='ml')
|
|
130
|
+
* @default './.cache/transformers'
|
|
131
|
+
*/
|
|
132
|
+
cacheDir: zod_1.z.string().default('./.cache/transformers'),
|
|
133
|
+
/**
|
|
134
|
+
* Enable HNSW index for faster search (only used when strategy='ml')
|
|
135
|
+
* When enabled, provides O(log n) search instead of O(n) brute-force
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
useHNSW: zod_1.z.boolean().default(false),
|
|
139
|
+
/**
|
|
140
|
+
* Synonym expansion configuration for TF-IDF search.
|
|
141
|
+
* When enabled, queries like "add user" will match tools for "create user".
|
|
142
|
+
* Only applies when strategy is 'tfidf' (ML already handles semantic similarity).
|
|
143
|
+
* Set to false to disable, or provide a config object to customize.
|
|
144
|
+
* @default { enabled: true }
|
|
145
|
+
*/
|
|
146
|
+
synonymExpansion: zod_1.z
|
|
147
|
+
.union([zod_1.z.literal(false), exports.synonymExpansionConfigSchema])
|
|
148
|
+
.optional()
|
|
149
|
+
.default({ enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 }),
|
|
150
|
+
})
|
|
151
|
+
.default(DEFAULT_EMBEDDING_OPTIONS);
|
|
152
|
+
exports.codeCallSidecarOptionsSchema = zod_1.z
|
|
153
|
+
.object({
|
|
154
|
+
/**
|
|
155
|
+
* Enable pass-by-reference support via sidecar
|
|
156
|
+
* When enabled, large strings are automatically lifted to a sidecar
|
|
157
|
+
* and resolved at the callTool boundary
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
enabled: zod_1.z.boolean().default(false),
|
|
161
|
+
/**
|
|
162
|
+
* Maximum total size of all stored references in bytes
|
|
163
|
+
* @default 16MB (from security level)
|
|
164
|
+
*/
|
|
165
|
+
maxTotalSize: zod_1.z.number().positive().optional(),
|
|
166
|
+
/**
|
|
167
|
+
* Maximum size of a single reference in bytes
|
|
168
|
+
* @default 4MB (from security level)
|
|
169
|
+
*/
|
|
170
|
+
maxReferenceSize: zod_1.z.number().positive().optional(),
|
|
171
|
+
/**
|
|
172
|
+
* Threshold in bytes to trigger extraction from source code
|
|
173
|
+
* Strings larger than this are lifted to the sidecar
|
|
174
|
+
* @default 64KB (from security level)
|
|
175
|
+
*/
|
|
176
|
+
extractionThreshold: zod_1.z.number().positive().optional(),
|
|
177
|
+
/**
|
|
178
|
+
* Maximum expanded size when resolving references for tool calls
|
|
179
|
+
* @default 8MB (from security level)
|
|
180
|
+
*/
|
|
181
|
+
maxResolvedSize: zod_1.z.number().positive().optional(),
|
|
182
|
+
/**
|
|
183
|
+
* Whether to allow composite handles from string concatenation
|
|
184
|
+
* If false, concatenating references throws an error
|
|
185
|
+
* @default false (strict mode)
|
|
186
|
+
*/
|
|
187
|
+
allowComposites: zod_1.z.boolean().optional(),
|
|
188
|
+
/**
|
|
189
|
+
* Maximum script length (in characters) when sidecar is disabled
|
|
190
|
+
* Prevents large inline data from being embedded in script
|
|
191
|
+
* If null, no limit is enforced
|
|
192
|
+
* @default 64KB
|
|
193
|
+
*/
|
|
194
|
+
maxScriptLengthWhenDisabled: zod_1.z
|
|
195
|
+
.number()
|
|
196
|
+
.positive()
|
|
197
|
+
.nullable()
|
|
198
|
+
.default(64 * 1024),
|
|
199
|
+
})
|
|
200
|
+
.default(() => ({
|
|
201
|
+
enabled: false,
|
|
202
|
+
maxScriptLengthWhenDisabled: 64 * 1024,
|
|
203
|
+
}));
|
|
204
|
+
// Inner schema without the outer .default() - used for extracting input type
|
|
205
|
+
const codeCallPluginOptionsObjectSchema = zod_1.z.object({
|
|
206
|
+
/**
|
|
207
|
+
* CodeCall mode
|
|
208
|
+
* @default 'codecall_only'
|
|
209
|
+
*/
|
|
210
|
+
mode: exports.codeCallModeSchema,
|
|
211
|
+
/**
|
|
212
|
+
* Default number of tools to return in search results
|
|
213
|
+
* @default 8
|
|
214
|
+
*/
|
|
215
|
+
topK: zod_1.z.number().positive().default(8),
|
|
216
|
+
/**
|
|
217
|
+
* Maximum number of tool definitions to include
|
|
218
|
+
* @default 8
|
|
219
|
+
*/
|
|
220
|
+
maxDefinitions: zod_1.z.number().positive().default(8),
|
|
221
|
+
/**
|
|
222
|
+
* Optional filter function for including tools.
|
|
223
|
+
* Signature: (tool: IncludeToolsFilterToolInfo) => boolean
|
|
224
|
+
*/
|
|
225
|
+
includeTools: includeToolsFilterSchema.optional(),
|
|
226
|
+
/**
|
|
227
|
+
* Direct calls configuration
|
|
228
|
+
*/
|
|
229
|
+
directCalls: exports.codeCallDirectCallsOptionsSchema.optional(),
|
|
230
|
+
/**
|
|
231
|
+
* VM execution options
|
|
232
|
+
*/
|
|
233
|
+
vm: exports.codeCallVmOptionsSchema,
|
|
234
|
+
/**
|
|
235
|
+
* Embedding configuration for tool search
|
|
236
|
+
*/
|
|
237
|
+
embedding: exports.codeCallEmbeddingOptionsSchema,
|
|
238
|
+
/**
|
|
239
|
+
* Sidecar (pass-by-reference) configuration
|
|
240
|
+
* When enabled, large data is stored outside the sandbox and resolved at callTool boundary
|
|
241
|
+
*/
|
|
242
|
+
sidecar: exports.codeCallSidecarOptionsSchema,
|
|
243
|
+
});
|
|
244
|
+
// Default values for plugin options
|
|
245
|
+
const DEFAULT_PLUGIN_OPTIONS = {
|
|
246
|
+
mode: 'codecall_only',
|
|
247
|
+
topK: 8,
|
|
248
|
+
maxDefinitions: 8,
|
|
249
|
+
vm: DEFAULT_VM_OPTIONS,
|
|
250
|
+
embedding: DEFAULT_EMBEDDING_OPTIONS,
|
|
251
|
+
sidecar: {
|
|
252
|
+
enabled: false,
|
|
253
|
+
maxScriptLengthWhenDisabled: 64 * 1024,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
// Full schema with default - used for parsing
|
|
257
|
+
exports.codeCallPluginOptionsSchema = codeCallPluginOptionsObjectSchema.prefault(DEFAULT_PLUGIN_OPTIONS);
|
|
258
|
+
//# sourceMappingURL=codecall.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecall.types.js","sourceRoot":"","sources":["../../../src/codecall/codecall.types.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;AAEpD,6BAAwB;AAmCxB,8DAA8D;AAC9D,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAsB,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK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B,EAAE,EAAE,GAAG,IAAI;KACvC;CACF,CAAC;AAEF,8CAA8C;AACjC,QAAA,2BAA2B,GAAG,iCAAiC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/codecall.types.ts\n\nimport { z } from 'zod';\n\n// ===== Filter Function Types =====\n\n/**\n * Tool info passed to the directCalls filter function\n */\nexport interface DirectCallsFilterToolInfo {\n name: string;\n appId?: string;\n source?: string;\n tags?: string[];\n}\n\n/**\n * Tool info passed to the includeTools filter function\n */\nexport interface IncludeToolsFilterToolInfo {\n name: string;\n appId?: string;\n source?: string;\n description?: string;\n tags?: string[];\n}\n\n/**\n * Function type for directCalls filter\n */\nexport type DirectCallsFilterFn = (tool: DirectCallsFilterToolInfo) => boolean;\n\n/**\n * Function type for includeTools filter\n */\nexport type IncludeToolsFilterFn = (tool: IncludeToolsFilterToolInfo) => boolean;\n\n// Helper schemas for filter functions with runtime validation\nconst directCallsFilterSchema = z.custom<DirectCallsFilterFn>((val) => typeof val === 'function', {\n message: 'filter must be a function with signature (tool: DirectCallsFilterToolInfo) => boolean',\n});\n\nconst includeToolsFilterSchema = z.custom<IncludeToolsFilterFn>((val) => typeof val === 'function', {\n message: 'includeTools must be a function with signature (tool: IncludeToolsFilterToolInfo) => boolean',\n});\n\n// ===== Zod Schemas with Defaults =====\n\nexport const codeCallModeSchema = z\n .enum(['codecall_only', 'codecall_opt_in', 'metadata_driven'])\n .default('codecall_only');\n\nexport const codeCallVmPresetSchema = z.enum(['locked_down', 'secure', 'balanced', 'experimental']).default('secure');\n\n// Default values for VM options\nconst DEFAULT_VM_OPTIONS = {\n preset: 'secure' as const,\n};\n\nexport const codeCallVmOptionsSchema = z\n .object({\n /**\n * CSP-like preset; see README.\n * @default 'secure'\n */\n preset: codeCallVmPresetSchema,\n\n /**\n * Timeout for script execution in milliseconds\n * Defaults vary by preset\n */\n timeoutMs: z.number().positive().optional(),\n\n /**\n * Allow loop constructs (for, while, do-while)\n * Defaults vary by preset\n */\n allowLoops: z.boolean().optional(),\n\n /**\n * Maximum number of steps (if applicable)\n * Defaults vary by preset\n */\n maxSteps: z.number().positive().optional(),\n\n /**\n * List of disabled builtin functions\n * Defaults vary by preset\n */\n disabledBuiltins: z.array(z.string()).optional(),\n\n /**\n * List of disabled global variables\n * Defaults vary by preset\n */\n disabledGlobals: z.array(z.string()).optional(),\n\n /**\n * Allow console.log/warn/error\n * Defaults vary by preset\n */\n allowConsole: z.boolean().optional(),\n })\n .default(() => DEFAULT_VM_OPTIONS);\n\nexport const codeCallDirectCallsOptionsSchema = z.object({\n /**\n * Enable/disable the `codecall.invoke` meta-tool.\n */\n enabled: z.boolean(),\n\n /**\n * Optional allowlist of tool names.\n */\n allowedTools: z.array(z.string()).optional(),\n\n /**\n * Optional advanced filter function.\n * Signature: (tool: DirectCallsFilterToolInfo) => boolean\n */\n filter: directCallsFilterSchema.optional(),\n});\n\nexport const embeddingStrategySchema = z.enum(['tfidf', 'ml']).default('tfidf');\n\n// Synonym expansion configuration schema\nexport const synonymExpansionConfigSchema = z\n .object({\n /**\n * Enable/disable synonym expansion for TF-IDF search.\n * When enabled, queries are expanded with synonyms to improve relevance.\n * For example, \"add user\" will also match tools containing \"create user\".\n * @default true\n */\n enabled: z.boolean().default(true),\n\n /**\n * Additional synonym groups beyond the defaults.\n * Each group is an array of related terms that should be treated as equivalent.\n * @example [['customer', 'client', 'buyer'], ['order', 'purchase', 'transaction']]\n */\n additionalSynonyms: z.array(z.array(z.string())).optional(),\n\n /**\n * Replace default synonyms entirely with additionalSynonyms.\n * @default false\n */\n replaceDefaults: z.boolean().default(false),\n\n /**\n * Maximum number of synonym expansions per term.\n * Prevents query explosion for terms with many synonyms.\n * @default 5\n */\n maxExpansionsPerTerm: z.number().positive().default(5),\n })\n .default({ enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 });\n\n// Default values for embedding options\nconst DEFAULT_EMBEDDING_OPTIONS = {\n strategy: 'tfidf' as const,\n modelName: 'Xenova/all-MiniLM-L6-v2',\n cacheDir: './.cache/transformers',\n useHNSW: false,\n synonymExpansion: { enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 },\n};\n\nexport const codeCallEmbeddingOptionsSchema = z\n .object({\n /**\n * Embedding strategy to use for tool search\n * - 'tfidf': Lightweight, synchronous TF-IDF based search (no ML models required)\n * - 'ml': ML-based semantic search using transformers.js (better quality, requires model download)\n * @default 'tfidf'\n */\n strategy: embeddingStrategySchema,\n\n /**\n * Model name for ML-based embeddings (only used when strategy='ml')\n * @default 'Xenova/all-MiniLM-L6-v2'\n */\n modelName: z.string().default('Xenova/all-MiniLM-L6-v2'),\n\n /**\n * Cache directory for ML models (only used when strategy='ml')\n * @default './.cache/transformers'\n */\n cacheDir: z.string().default('./.cache/transformers'),\n\n /**\n * Enable HNSW index for faster search (only used when strategy='ml')\n * When enabled, provides O(log n) search instead of O(n) brute-force\n * @default false\n */\n useHNSW: z.boolean().default(false),\n\n /**\n * Synonym expansion configuration for TF-IDF search.\n * When enabled, queries like \"add user\" will match tools for \"create user\".\n * Only applies when strategy is 'tfidf' (ML already handles semantic similarity).\n * Set to false to disable, or provide a config object to customize.\n * @default { enabled: true }\n */\n synonymExpansion: z\n .union([z.literal(false), synonymExpansionConfigSchema])\n .optional()\n .default({ enabled: true, replaceDefaults: false, maxExpansionsPerTerm: 5 }),\n })\n .default(DEFAULT_EMBEDDING_OPTIONS);\n\nexport const codeCallSidecarOptionsSchema = z\n .object({\n /**\n * Enable pass-by-reference support via sidecar\n * When enabled, large strings are automatically lifted to a sidecar\n * and resolved at the callTool boundary\n * @default false\n */\n enabled: z.boolean().default(false),\n\n /**\n * Maximum total size of all stored references in bytes\n * @default 16MB (from security level)\n */\n maxTotalSize: z.number().positive().optional(),\n\n /**\n * Maximum size of a single reference in bytes\n * @default 4MB (from security level)\n */\n maxReferenceSize: z.number().positive().optional(),\n\n /**\n * Threshold in bytes to trigger extraction from source code\n * Strings larger than this are lifted to the sidecar\n * @default 64KB (from security level)\n */\n extractionThreshold: z.number().positive().optional(),\n\n /**\n * Maximum expanded size when resolving references for tool calls\n * @default 8MB (from security level)\n */\n maxResolvedSize: z.number().positive().optional(),\n\n /**\n * Whether to allow composite handles from string concatenation\n * If false, concatenating references throws an error\n * @default false (strict mode)\n */\n allowComposites: z.boolean().optional(),\n\n /**\n * Maximum script length (in characters) when sidecar is disabled\n * Prevents large inline data from being embedded in script\n * If null, no limit is enforced\n * @default 64KB\n */\n maxScriptLengthWhenDisabled: z\n .number()\n .positive()\n .nullable()\n .default(64 * 1024),\n })\n .default(() => ({\n enabled: false,\n maxScriptLengthWhenDisabled: 64 * 1024,\n }));\n\n// Inner schema without the outer .default() - used for extracting input type\nconst codeCallPluginOptionsObjectSchema = z.object({\n /**\n * CodeCall mode\n * @default 'codecall_only'\n */\n mode: codeCallModeSchema,\n\n /**\n * Default number of tools to return in search results\n * @default 8\n */\n topK: z.number().positive().default(8),\n\n /**\n * Maximum number of tool definitions to include\n * @default 8\n */\n maxDefinitions: z.number().positive().default(8),\n\n /**\n * Optional filter function for including tools.\n * Signature: (tool: IncludeToolsFilterToolInfo) => boolean\n */\n includeTools: includeToolsFilterSchema.optional(),\n\n /**\n * Direct calls configuration\n */\n directCalls: codeCallDirectCallsOptionsSchema.optional(),\n\n /**\n * VM execution options\n */\n vm: codeCallVmOptionsSchema,\n\n /**\n * Embedding configuration for tool search\n */\n embedding: codeCallEmbeddingOptionsSchema,\n\n /**\n * Sidecar (pass-by-reference) configuration\n * When enabled, large data is stored outside the sandbox and resolved at callTool boundary\n */\n sidecar: codeCallSidecarOptionsSchema,\n});\n\n// Default values for plugin options\nconst DEFAULT_PLUGIN_OPTIONS = {\n mode: 'codecall_only' as const,\n topK: 8,\n maxDefinitions: 8,\n vm: DEFAULT_VM_OPTIONS,\n embedding: DEFAULT_EMBEDDING_OPTIONS,\n sidecar: {\n enabled: false,\n maxScriptLengthWhenDisabled: 64 * 1024,\n },\n};\n\n// Full schema with default - used for parsing\nexport const codeCallPluginOptionsSchema = codeCallPluginOptionsObjectSchema.prefault(DEFAULT_PLUGIN_OPTIONS);\n\n// ===== TypeScript Types =====\n\n// Output types (after parsing, with defaults applied) - use for internal plugin logic\nexport type CodeCallMode = z.infer<typeof codeCallModeSchema>;\nexport type CodeCallVmPreset = z.infer<typeof codeCallVmPresetSchema>;\nexport type CodeCallVmOptions = z.infer<typeof codeCallVmOptionsSchema>;\nexport type CodeCallDirectCallsOptions = z.infer<typeof codeCallDirectCallsOptionsSchema>;\nexport type EmbeddingStrategy = z.infer<typeof embeddingStrategySchema>;\nexport type SynonymExpansionConfig = z.infer<typeof synonymExpansionConfigSchema>;\nexport type CodeCallSidecarOptions = z.infer<typeof codeCallSidecarOptionsSchema>;\n\nexport type CodeCallEmbeddingOptions = z.infer<typeof codeCallEmbeddingOptionsSchema>;\nexport type CodeCallEmbeddingOptionsInput = z.input<typeof codeCallEmbeddingOptionsSchema>;\n\n/**\n * Resolved options type (after parsing with defaults applied).\n * Use this for internal plugin logic where all defaults are guaranteed.\n */\nexport type CodeCallPluginOptions = z.infer<typeof codeCallPluginOptionsSchema>;\n\n/**\n * Input options type (what users provide to init()).\n * All fields with defaults are optional.\n */\nexport type CodeCallPluginOptionsInput = z.input<typeof codeCallPluginOptionsObjectSchema>;\n\n/**\n * Per-tool metadata used by CodeCall.\n * This maps to `metadata.codecall` on tools.\n */\nexport interface CodeCallToolMetadata {\n /**\n * If true, this tool stays visible in `list_tools`\n * even when CodeCall is hiding most tools.\n */\n visibleInListTools?: boolean;\n\n /**\n * Whether this tool can be used via CodeCall.\n * Semantics depend on CodeCallMode (see README).\n */\n enabledInCodeCall?: boolean;\n\n /** Optional extra indexing hints */\n appId?: string;\n source?: string;\n tags?: string[];\n}\n\n// ----- meta-tool contracts -----\n\nexport type CodeCallSearchInput = {\n query: string;\n topK?: number;\n filter?: {\n appIds?: string[];\n tags?: string[];\n includeOpenApi?: boolean;\n includeInline?: boolean;\n };\n};\n\nexport type CodeCallSearchResult = {\n tools: {\n name: string;\n description: string;\n appId?: string;\n source?: string;\n score: number;\n }[];\n};\n\nexport type CodeCallDescribeInput = {\n tools: string[];\n max?: number;\n};\n\nexport type CodeCallDescribeResult = {\n tools: {\n name: string;\n description: string;\n inputSchema: unknown;\n outputSchema?: unknown | null;\n examples?: {\n input: unknown;\n output?: unknown;\n }[];\n }[];\n};\n\nexport type CodeCallExecuteInput = {\n script: string;\n /**\n * Arbitrary, readonly context exposed as `codecallContext`.\n */\n context?: Record<string, unknown>;\n};\n\n// ---- global FrontMCP metadata extension ----\n\ndeclare global {\n interface ExtendFrontMcpToolMetadata {\n /**\n * CodeCall-specific metadata, attached via `@Tool({ metadata: { codecall: ... } })`\n * or whatever your decorator mapping is.\n */\n codecall?: CodeCallToolMetadata;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tool-call.errors';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/codecall/errors/index.ts"],"names":[],"mappings":";AAAA,kDAAkD;;;AAElD,6DAAmC","sourcesContent":["// file: libs/plugins/src/codecall/errors/index.ts\n\nexport * from './tool-call.errors';\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes exposed to AgentScript via result-based error handling.
|
|
3
|
+
* These are the ONLY error codes scripts can see - no internal details.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TOOL_CALL_ERROR_CODES: {
|
|
6
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
7
|
+
readonly VALIDATION: "VALIDATION";
|
|
8
|
+
readonly EXECUTION: "EXECUTION";
|
|
9
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
10
|
+
readonly ACCESS_DENIED: "ACCESS_DENIED";
|
|
11
|
+
readonly SELF_REFERENCE: "SELF_REFERENCE";
|
|
12
|
+
};
|
|
13
|
+
export type ToolCallErrorCode = (typeof TOOL_CALL_ERROR_CODES)[keyof typeof TOOL_CALL_ERROR_CODES];
|
|
14
|
+
/**
|
|
15
|
+
* Sanitized error structure exposed to AgentScript.
|
|
16
|
+
* Contains NO stack traces, NO internal details, NO sensitive information.
|
|
17
|
+
*/
|
|
18
|
+
export interface ToolCallError {
|
|
19
|
+
readonly code: ToolCallErrorCode;
|
|
20
|
+
readonly message: string;
|
|
21
|
+
readonly toolName: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result type for callTool when throwOnError is false.
|
|
25
|
+
*/
|
|
26
|
+
export type ToolCallResult<T> = {
|
|
27
|
+
success: true;
|
|
28
|
+
data: T;
|
|
29
|
+
} | {
|
|
30
|
+
success: false;
|
|
31
|
+
error: ToolCallError;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Options for callTool behavior.
|
|
35
|
+
*/
|
|
36
|
+
export interface CallToolOptions {
|
|
37
|
+
/**
|
|
38
|
+
* When true (default), errors are thrown and can be caught.
|
|
39
|
+
* When false, errors are returned as { success: false, error: ToolCallError }.
|
|
40
|
+
*
|
|
41
|
+
* SECURITY: Even when throwOnError is true, only sanitized errors are thrown.
|
|
42
|
+
* Internal security guard errors are NEVER exposed to scripts.
|
|
43
|
+
*/
|
|
44
|
+
throwOnError?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a sanitized ToolCallError for script consumption.
|
|
48
|
+
* This function ensures no internal details leak to AgentScript.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createToolCallError(code: ToolCallErrorCode, toolName: string, rawMessage?: string): ToolCallError;
|
|
51
|
+
/**
|
|
52
|
+
* FATAL: Self-reference attack detected.
|
|
53
|
+
* This error is thrown internally and causes immediate execution termination.
|
|
54
|
+
* The script NEVER sees this error - it only sees the sanitized version.
|
|
55
|
+
*/
|
|
56
|
+
export declare class SelfReferenceError extends Error {
|
|
57
|
+
readonly code: "SELF_REFERENCE";
|
|
58
|
+
readonly toolName: string;
|
|
59
|
+
constructor(toolName: string);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Internal error for tool access denial.
|
|
63
|
+
* Only the sanitized version is exposed to scripts.
|
|
64
|
+
*/
|
|
65
|
+
export declare class ToolAccessDeniedError extends Error {
|
|
66
|
+
readonly code: "ACCESS_DENIED";
|
|
67
|
+
readonly toolName: string;
|
|
68
|
+
readonly reason: string;
|
|
69
|
+
constructor(toolName: string, reason: string);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Internal error for tool not found.
|
|
73
|
+
* Only the sanitized version is exposed to scripts.
|
|
74
|
+
*/
|
|
75
|
+
export declare class ToolNotFoundError extends Error {
|
|
76
|
+
readonly code: "NOT_FOUND";
|
|
77
|
+
readonly toolName: string;
|
|
78
|
+
constructor(toolName: string);
|
|
79
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: libs/plugins/src/codecall/errors/tool-call.errors.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ToolNotFoundError = exports.ToolAccessDeniedError = exports.SelfReferenceError = exports.TOOL_CALL_ERROR_CODES = void 0;
|
|
5
|
+
exports.createToolCallError = createToolCallError;
|
|
6
|
+
/**
|
|
7
|
+
* Error codes exposed to AgentScript via result-based error handling.
|
|
8
|
+
* These are the ONLY error codes scripts can see - no internal details.
|
|
9
|
+
*/
|
|
10
|
+
exports.TOOL_CALL_ERROR_CODES = {
|
|
11
|
+
NOT_FOUND: 'NOT_FOUND',
|
|
12
|
+
VALIDATION: 'VALIDATION',
|
|
13
|
+
EXECUTION: 'EXECUTION',
|
|
14
|
+
TIMEOUT: 'TIMEOUT',
|
|
15
|
+
ACCESS_DENIED: 'ACCESS_DENIED',
|
|
16
|
+
SELF_REFERENCE: 'SELF_REFERENCE',
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates a sanitized ToolCallError for script consumption.
|
|
20
|
+
* This function ensures no internal details leak to AgentScript.
|
|
21
|
+
*/
|
|
22
|
+
function createToolCallError(code, toolName, rawMessage) {
|
|
23
|
+
// Sanitize message - remove any potentially sensitive information
|
|
24
|
+
const sanitizedMessage = getSanitizedMessage(code, toolName, rawMessage);
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
code,
|
|
27
|
+
message: sanitizedMessage,
|
|
28
|
+
toolName,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get a safe, generic message for each error code.
|
|
33
|
+
* Internal details are NEVER included.
|
|
34
|
+
*/
|
|
35
|
+
function getSanitizedMessage(code, toolName, rawMessage) {
|
|
36
|
+
switch (code) {
|
|
37
|
+
case exports.TOOL_CALL_ERROR_CODES.NOT_FOUND:
|
|
38
|
+
return `Tool "${toolName}" was not found`;
|
|
39
|
+
case exports.TOOL_CALL_ERROR_CODES.VALIDATION:
|
|
40
|
+
// For validation, we can include a sanitized version of the message
|
|
41
|
+
// but strip any internal paths or stack traces
|
|
42
|
+
return rawMessage ? sanitizeValidationMessage(rawMessage) : `Input validation failed for tool "${toolName}"`;
|
|
43
|
+
case exports.TOOL_CALL_ERROR_CODES.EXECUTION:
|
|
44
|
+
return `Tool "${toolName}" execution failed`;
|
|
45
|
+
case exports.TOOL_CALL_ERROR_CODES.TIMEOUT:
|
|
46
|
+
return `Tool "${toolName}" execution timed out`;
|
|
47
|
+
case exports.TOOL_CALL_ERROR_CODES.ACCESS_DENIED:
|
|
48
|
+
return `Access denied for tool "${toolName}"`;
|
|
49
|
+
case exports.TOOL_CALL_ERROR_CODES.SELF_REFERENCE:
|
|
50
|
+
return `Cannot call CodeCall tools from within AgentScript`;
|
|
51
|
+
default:
|
|
52
|
+
return `An error occurred while calling "${toolName}"`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sanitize validation error messages to remove internal details.
|
|
57
|
+
*/
|
|
58
|
+
function sanitizeValidationMessage(message) {
|
|
59
|
+
// Remove file paths (Unix and Windows)
|
|
60
|
+
let sanitized = message.replace(/(?:\/[\w.-]+)+|(?:[A-Za-z]:\\[\w\\.-]+)+/g, '[path]');
|
|
61
|
+
// Remove line numbers and stack traces
|
|
62
|
+
sanitized = sanitized.replace(/\bat line \d+/gi, '');
|
|
63
|
+
sanitized = sanitized.replace(/\bline \d+/gi, '');
|
|
64
|
+
sanitized = sanitized.replace(/:\d+:\d+/g, '');
|
|
65
|
+
// Remove "at" stack trace lines
|
|
66
|
+
sanitized = sanitized.replace(/\n\s*at .*/g, '');
|
|
67
|
+
// Truncate if too long (prevent information disclosure via long messages)
|
|
68
|
+
if (sanitized.length > 200) {
|
|
69
|
+
sanitized = sanitized.substring(0, 200) + '...';
|
|
70
|
+
}
|
|
71
|
+
return sanitized.trim();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* FATAL: Self-reference attack detected.
|
|
75
|
+
* This error is thrown internally and causes immediate execution termination.
|
|
76
|
+
* The script NEVER sees this error - it only sees the sanitized version.
|
|
77
|
+
*/
|
|
78
|
+
class SelfReferenceError extends Error {
|
|
79
|
+
code = exports.TOOL_CALL_ERROR_CODES.SELF_REFERENCE;
|
|
80
|
+
toolName;
|
|
81
|
+
constructor(toolName) {
|
|
82
|
+
super(`Self-reference attack: Attempted to call CodeCall tool "${toolName}" from within AgentScript`);
|
|
83
|
+
this.name = 'SelfReferenceError';
|
|
84
|
+
this.toolName = toolName;
|
|
85
|
+
Object.freeze(this);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.SelfReferenceError = SelfReferenceError;
|
|
89
|
+
/**
|
|
90
|
+
* Internal error for tool access denial.
|
|
91
|
+
* Only the sanitized version is exposed to scripts.
|
|
92
|
+
*/
|
|
93
|
+
class ToolAccessDeniedError extends Error {
|
|
94
|
+
code = exports.TOOL_CALL_ERROR_CODES.ACCESS_DENIED;
|
|
95
|
+
toolName;
|
|
96
|
+
reason;
|
|
97
|
+
constructor(toolName, reason) {
|
|
98
|
+
super(`Access denied for tool "${toolName}": ${reason}`);
|
|
99
|
+
this.name = 'ToolAccessDeniedError';
|
|
100
|
+
this.toolName = toolName;
|
|
101
|
+
this.reason = reason;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ToolAccessDeniedError = ToolAccessDeniedError;
|
|
105
|
+
/**
|
|
106
|
+
* Internal error for tool not found.
|
|
107
|
+
* Only the sanitized version is exposed to scripts.
|
|
108
|
+
*/
|
|
109
|
+
class ToolNotFoundError extends Error {
|
|
110
|
+
code = exports.TOOL_CALL_ERROR_CODES.NOT_FOUND;
|
|
111
|
+
toolName;
|
|
112
|
+
constructor(toolName) {
|
|
113
|
+
super(`Tool "${toolName}" not found`);
|
|
114
|
+
this.name = 'ToolNotFoundError';
|
|
115
|
+
this.toolName = toolName;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.ToolNotFoundError = ToolNotFoundError;
|
|
119
|
+
//# sourceMappingURL=tool-call.errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call.errors.js","sourceRoot":"","sources":["../../../../src/codecall/errors/tool-call.errors.ts"],"names":[],"mappings":";AAAA,6DAA6D;;;AAkD7D,kDASC;AAzDD;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACnC,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAiCX;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,IAAuB,EAAE,QAAgB,EAAE,UAAmB;IAChG,kEAAkE;IAClE,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAEzE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI;QACJ,OAAO,EAAE,gBAAgB;QACzB,QAAQ;KACT,CA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codecall/errors/tool-call.errors.ts\n\n/**\n * Error codes exposed to AgentScript via result-based error handling.\n * These are the ONLY error codes scripts can see - no internal details.\n */\nexport const TOOL_CALL_ERROR_CODES = {\n NOT_FOUND: 'NOT_FOUND',\n VALIDATION: 'VALIDATION',\n EXECUTION: 'EXECUTION',\n TIMEOUT: 'TIMEOUT',\n ACCESS_DENIED: 'ACCESS_DENIED',\n SELF_REFERENCE: 'SELF_REFERENCE',\n} as const;\n\nexport type ToolCallErrorCode = (typeof TOOL_CALL_ERROR_CODES)[keyof typeof TOOL_CALL_ERROR_CODES];\n\n/**\n * Sanitized error structure exposed to AgentScript.\n * Contains NO stack traces, NO internal details, NO sensitive information.\n */\nexport interface ToolCallError {\n readonly code: ToolCallErrorCode;\n readonly message: string;\n readonly toolName: string;\n}\n\n/**\n * Result type for callTool when throwOnError is false.\n */\nexport type ToolCallResult<T> = { success: true; data: T } | { success: false; error: ToolCallError };\n\n/**\n * Options for callTool behavior.\n */\nexport interface CallToolOptions {\n /**\n * When true (default), errors are thrown and can be caught.\n * When false, errors are returned as { success: false, error: ToolCallError }.\n *\n * SECURITY: Even when throwOnError is true, only sanitized errors are thrown.\n * Internal security guard errors are NEVER exposed to scripts.\n */\n throwOnError?: boolean;\n}\n\n/**\n * Creates a sanitized ToolCallError for script consumption.\n * This function ensures no internal details leak to AgentScript.\n */\nexport function createToolCallError(code: ToolCallErrorCode, toolName: string, rawMessage?: string): ToolCallError {\n // Sanitize message - remove any potentially sensitive information\n const sanitizedMessage = getSanitizedMessage(code, toolName, rawMessage);\n\n return Object.freeze({\n code,\n message: sanitizedMessage,\n toolName,\n });\n}\n\n/**\n * Get a safe, generic message for each error code.\n * Internal details are NEVER included.\n */\nfunction getSanitizedMessage(code: ToolCallErrorCode, toolName: string, rawMessage?: string): string {\n switch (code) {\n case TOOL_CALL_ERROR_CODES.NOT_FOUND:\n return `Tool \"${toolName}\" was not found`;\n\n case TOOL_CALL_ERROR_CODES.VALIDATION:\n // For validation, we can include a sanitized version of the message\n // but strip any internal paths or stack traces\n return rawMessage ? sanitizeValidationMessage(rawMessage) : `Input validation failed for tool \"${toolName}\"`;\n\n case TOOL_CALL_ERROR_CODES.EXECUTION:\n return `Tool \"${toolName}\" execution failed`;\n\n case TOOL_CALL_ERROR_CODES.TIMEOUT:\n return `Tool \"${toolName}\" execution timed out`;\n\n case TOOL_CALL_ERROR_CODES.ACCESS_DENIED:\n return `Access denied for tool \"${toolName}\"`;\n\n case TOOL_CALL_ERROR_CODES.SELF_REFERENCE:\n return `Cannot call CodeCall tools from within AgentScript`;\n\n default:\n return `An error occurred while calling \"${toolName}\"`;\n }\n}\n\n/**\n * Sanitize validation error messages to remove internal details.\n */\nfunction sanitizeValidationMessage(message: string): string {\n // Remove file paths (Unix and Windows)\n let sanitized = message.replace(/(?:\\/[\\w.-]+)+|(?:[A-Za-z]:\\\\[\\w\\\\.-]+)+/g, '[path]');\n\n // Remove line numbers and stack traces\n sanitized = sanitized.replace(/\\bat line \\d+/gi, '');\n sanitized = sanitized.replace(/\\bline \\d+/gi, '');\n sanitized = sanitized.replace(/:\\d+:\\d+/g, '');\n\n // Remove \"at\" stack trace lines\n sanitized = sanitized.replace(/\\n\\s*at .*/g, '');\n\n // Truncate if too long (prevent information disclosure via long messages)\n if (sanitized.length > 200) {\n sanitized = sanitized.substring(0, 200) + '...';\n }\n\n return sanitized.trim();\n}\n\n/**\n * FATAL: Self-reference attack detected.\n * This error is thrown internally and causes immediate execution termination.\n * The script NEVER sees this error - it only sees the sanitized version.\n */\nexport class SelfReferenceError extends Error {\n readonly code = TOOL_CALL_ERROR_CODES.SELF_REFERENCE;\n readonly toolName: string;\n\n constructor(toolName: string) {\n super(`Self-reference attack: Attempted to call CodeCall tool \"${toolName}\" from within AgentScript`);\n this.name = 'SelfReferenceError';\n this.toolName = toolName;\n Object.freeze(this);\n }\n}\n\n/**\n * Internal error for tool access denial.\n * Only the sanitized version is exposed to scripts.\n */\nexport class ToolAccessDeniedError extends Error {\n readonly code = TOOL_CALL_ERROR_CODES.ACCESS_DENIED;\n readonly toolName: string;\n readonly reason: string;\n\n constructor(toolName: string, reason: string) {\n super(`Access denied for tool \"${toolName}\": ${reason}`);\n this.name = 'ToolAccessDeniedError';\n this.toolName = toolName;\n this.reason = reason;\n }\n}\n\n/**\n * Internal error for tool not found.\n * Only the sanitized version is exposed to scripts.\n */\nexport class ToolNotFoundError extends Error {\n readonly code = TOOL_CALL_ERROR_CODES.NOT_FOUND;\n readonly toolName: string;\n\n constructor(toolName: string) {\n super(`Tool \"${toolName}\" not found`);\n this.name = 'ToolNotFoundError';\n this.toolName = toolName;\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var codecall_plugin_1 = require("./codecall.plugin");
|
|
6
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tslib_1.__importDefault(codecall_plugin_1).default; } });
|
|
7
|
+
tslib_1.__exportStar(require("./codecall.types"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codecall/index.ts"],"names":[],"mappings":";;;;AAAA,qDAA4C;AAAnC,mIAAA,OAAO,OAAA;AAChB,2DAAiC","sourcesContent":["export { default } from './codecall.plugin';\nexport * from './codecall.types';\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseConfig } from '@frontmcp/sdk';
|
|
2
|
+
import { CodeCallPluginOptions } from '../codecall.types';
|
|
3
|
+
import { ResolvedCodeCallVmOptions } from '../codecall.symbol';
|
|
4
|
+
/**
|
|
5
|
+
* CodeCall configuration provider with convict-like API
|
|
6
|
+
* Extends BaseConfig to provide type-safe dotted path access
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Get values with dotted path notation
|
|
10
|
+
* config.get('vm.preset') // returns 'secure'
|
|
11
|
+
* config.get('embedding.strategy') // returns 'tfidf'
|
|
12
|
+
* config.get('directCalls.enabled') // returns true
|
|
13
|
+
*
|
|
14
|
+
* // Get with default value
|
|
15
|
+
* config.get('vm.timeoutMs', 5000) // returns value or 5000
|
|
16
|
+
*
|
|
17
|
+
* // Get entire sections
|
|
18
|
+
* config.getSection('vm') // returns entire vm config
|
|
19
|
+
* config.getAll() // returns complete config
|
|
20
|
+
*
|
|
21
|
+
* // Require values (throws if undefined)
|
|
22
|
+
* config.getOrThrow('mode') // throws if undefined
|
|
23
|
+
* config.getRequired('topK') // same as getOrThrow
|
|
24
|
+
*/
|
|
25
|
+
export default class CodeCallConfig extends BaseConfig<CodeCallPluginOptions & {
|
|
26
|
+
resolvedVm: ResolvedCodeCallVmOptions;
|
|
27
|
+
}> {
|
|
28
|
+
constructor(options?: Partial<CodeCallPluginOptions>);
|
|
29
|
+
}
|