@frontmcp/plugins 0.6.0 → 0.6.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.
- package/{src/cache → cache}/cache.types.d.ts +26 -3
- package/cache/index.js +412 -0
- package/{src/cache → cache}/providers/cache-memory.provider.d.ts +3 -3
- package/{src/cache → cache}/providers/cache-redis.provider.d.ts +3 -3
- package/cache/providers/cache-vercel-kv.provider.d.ts +24 -0
- package/codecall/index.js +2988 -0
- package/{src/codecall → codecall}/tools/invoke.schema.d.ts +6 -1
- package/esm/cache/index.mjs +395 -0
- package/esm/codecall/index.mjs +2959 -0
- package/esm/index.mjs +2951 -0
- package/esm/package.json +85 -0
- package/index.js +2973 -0
- package/package.json +49 -10
- package/src/cache/README.md +0 -186
- package/src/cache/cache.plugin.js +0 -135
- package/src/cache/cache.plugin.js.map +0 -1
- package/src/cache/cache.symbol.js +0 -5
- package/src/cache/cache.symbol.js.map +0 -1
- package/src/cache/cache.types.js +0 -3
- package/src/cache/cache.types.js.map +0 -1
- package/src/cache/index.js +0 -8
- package/src/cache/index.js.map +0 -1
- package/src/cache/providers/cache-memory.provider.js +0 -110
- package/src/cache/providers/cache-memory.provider.js.map +0 -1
- package/src/cache/providers/cache-redis.provider.js +0 -69
- package/src/cache/providers/cache-redis.provider.js.map +0 -1
- package/src/codecall/README.md +0 -999
- package/src/codecall/codecall.plugin.js +0 -152
- package/src/codecall/codecall.plugin.js.map +0 -1
- package/src/codecall/codecall.symbol.js +0 -4
- package/src/codecall/codecall.symbol.js.map +0 -1
- package/src/codecall/codecall.types.js +0 -262
- package/src/codecall/codecall.types.js.map +0 -1
- package/src/codecall/errors/index.js +0 -6
- package/src/codecall/errors/index.js.map +0 -1
- package/src/codecall/errors/tool-call.errors.js +0 -119
- package/src/codecall/errors/tool-call.errors.js.map +0 -1
- package/src/codecall/index.js +0 -8
- package/src/codecall/index.js.map +0 -1
- package/src/codecall/providers/code-call.config.js +0 -120
- package/src/codecall/providers/code-call.config.js.map +0 -1
- package/src/codecall/security/index.js +0 -7
- package/src/codecall/security/index.js.map +0 -1
- package/src/codecall/security/self-reference-guard.js +0 -70
- package/src/codecall/security/self-reference-guard.js.map +0 -1
- package/src/codecall/security/tool-access-control.service.js +0 -170
- package/src/codecall/security/tool-access-control.service.js.map +0 -1
- package/src/codecall/services/audit-logger.service.js +0 -322
- package/src/codecall/services/audit-logger.service.js.map +0 -1
- package/src/codecall/services/enclave.service.js +0 -214
- package/src/codecall/services/enclave.service.js.map +0 -1
- package/src/codecall/services/error-enrichment.service.js +0 -387
- package/src/codecall/services/error-enrichment.service.js.map +0 -1
- package/src/codecall/services/index.js +0 -13
- package/src/codecall/services/index.js.map +0 -1
- package/src/codecall/services/output-sanitizer.js +0 -260
- package/src/codecall/services/output-sanitizer.js.map +0 -1
- package/src/codecall/services/synonym-expansion.service.js +0 -374
- package/src/codecall/services/synonym-expansion.service.js.map +0 -1
- package/src/codecall/services/tool-search.service.js +0 -587
- package/src/codecall/services/tool-search.service.js.map +0 -1
- package/src/codecall/tools/describe.schema.js +0 -67
- package/src/codecall/tools/describe.schema.js.map +0 -1
- package/src/codecall/tools/describe.tool.js +0 -207
- package/src/codecall/tools/describe.tool.js.map +0 -1
- package/src/codecall/tools/execute.schema.js +0 -116
- package/src/codecall/tools/execute.schema.js.map +0 -1
- package/src/codecall/tools/execute.tool.js +0 -238
- package/src/codecall/tools/execute.tool.js.map +0 -1
- package/src/codecall/tools/index.js +0 -13
- package/src/codecall/tools/index.js.map +0 -1
- package/src/codecall/tools/invoke.schema.js +0 -27
- package/src/codecall/tools/invoke.schema.js.map +0 -1
- package/src/codecall/tools/invoke.tool.js +0 -70
- package/src/codecall/tools/invoke.tool.js.map +0 -1
- package/src/codecall/tools/search.schema.js +0 -60
- package/src/codecall/tools/search.schema.js.map +0 -1
- package/src/codecall/tools/search.tool.js +0 -108
- package/src/codecall/tools/search.tool.js.map +0 -1
- package/src/codecall/utils/describe.utils.js +0 -531
- package/src/codecall/utils/describe.utils.js.map +0 -1
- package/src/codecall/utils/index.js +0 -7
- package/src/codecall/utils/index.js.map +0 -1
- package/src/codecall/utils/mcp-result.js +0 -36
- package/src/codecall/utils/mcp-result.js.map +0 -1
- package/src/index.js +0 -9
- package/src/index.js.map +0 -1
- /package/{src/cache → cache}/cache.plugin.d.ts +0 -0
- /package/{src/cache → cache}/cache.symbol.d.ts +0 -0
- /package/{src/cache → cache}/index.d.ts +0 -0
- /package/{src/codecall → codecall}/codecall.plugin.d.ts +0 -0
- /package/{src/codecall → codecall}/codecall.symbol.d.ts +0 -0
- /package/{src/codecall → codecall}/codecall.types.d.ts +0 -0
- /package/{src/codecall → codecall}/errors/index.d.ts +0 -0
- /package/{src/codecall → codecall}/errors/tool-call.errors.d.ts +0 -0
- /package/{src/codecall → codecall}/index.d.ts +0 -0
- /package/{src/codecall → codecall}/providers/code-call.config.d.ts +0 -0
- /package/{src/codecall → codecall}/security/index.d.ts +0 -0
- /package/{src/codecall → codecall}/security/self-reference-guard.d.ts +0 -0
- /package/{src/codecall → codecall}/security/tool-access-control.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/audit-logger.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/enclave.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/error-enrichment.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/index.d.ts +0 -0
- /package/{src/codecall → codecall}/services/output-sanitizer.d.ts +0 -0
- /package/{src/codecall → codecall}/services/synonym-expansion.service.d.ts +0 -0
- /package/{src/codecall → codecall}/services/tool-search.service.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/describe.schema.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/describe.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/execute.schema.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/execute.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/index.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/invoke.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/search.schema.d.ts +0 -0
- /package/{src/codecall → codecall}/tools/search.tool.d.ts +0 -0
- /package/{src/codecall → codecall}/utils/describe.utils.d.ts +0 -0
- /package/{src/codecall → codecall}/utils/index.d.ts +0 -0
- /package/{src/codecall → codecall}/utils/mcp-result.d.ts +0 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// file: libs/plugins/src/codecall/codecall.plugin.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const sdk_1 = require("@frontmcp/sdk");
|
|
6
|
-
const codecall_types_1 = require("./codecall.types");
|
|
7
|
-
const services_1 = require("./services");
|
|
8
|
-
const tools_1 = require("./tools");
|
|
9
|
-
const code_call_config_1 = tslib_1.__importDefault(require("./providers/code-call.config"));
|
|
10
|
-
const enclave_service_1 = tslib_1.__importDefault(require("./services/enclave.service"));
|
|
11
|
-
const cache_1 = tslib_1.__importDefault(require("../cache"));
|
|
12
|
-
let CodeCallPlugin = class CodeCallPlugin extends sdk_1.DynamicPlugin {
|
|
13
|
-
options;
|
|
14
|
-
constructor(options = {}) {
|
|
15
|
-
super();
|
|
16
|
-
// Parse options with Zod schema to apply all defaults
|
|
17
|
-
this.options = codecall_types_1.codeCallPluginOptionsSchema.parse(options);
|
|
18
|
-
console.log('[CodeCall] Plugin initialized with mode:', this.options.mode);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Dynamic providers allow you to configure the plugin with custom options
|
|
22
|
-
* without touching the plugin decorator.
|
|
23
|
-
*/
|
|
24
|
-
static dynamicProviders(options) {
|
|
25
|
-
// Parse options with Zod schema to apply all defaults
|
|
26
|
-
const parsedOptions = codecall_types_1.codeCallPluginOptionsSchema.parse(options);
|
|
27
|
-
// Create config instance
|
|
28
|
-
const config = new code_call_config_1.default(parsedOptions);
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
name: 'codecall:config',
|
|
32
|
-
provide: code_call_config_1.default,
|
|
33
|
-
useValue: config,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: 'codecall:enclave',
|
|
37
|
-
provide: enclave_service_1.default,
|
|
38
|
-
inject: () => [code_call_config_1.default],
|
|
39
|
-
useFactory: async (cfg) => {
|
|
40
|
-
return new enclave_service_1.default(cfg);
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'codecall:tool-search',
|
|
45
|
-
provide: services_1.ToolSearchService,
|
|
46
|
-
inject: () => [sdk_1.ScopeEntry],
|
|
47
|
-
useFactory: async (scope) => {
|
|
48
|
-
return new services_1.ToolSearchService({
|
|
49
|
-
embeddingOptions: parsedOptions.embedding,
|
|
50
|
-
mode: parsedOptions.mode,
|
|
51
|
-
includeTools: parsedOptions['includeTools'],
|
|
52
|
-
}, scope);
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Hook into list_tools to enforce CodeCall modes:
|
|
59
|
-
*
|
|
60
|
-
* Modes:
|
|
61
|
-
* - codecall_only: Hide all tools from list_tools except CodeCall meta-tools.
|
|
62
|
-
* All other tools must be discovered via codecall:search.
|
|
63
|
-
* - codecall_opt_in: Show all tools in list_tools. Tools opt-in to CodeCall via metadata.
|
|
64
|
-
* - metadata_driven: Use per-tool metadata.codecall to control visibility in list_tools.
|
|
65
|
-
*
|
|
66
|
-
* CodeCall meta-tools (codecall:search, codecall:describe, codecall:execute, codecall:invoke)
|
|
67
|
-
* are ALWAYS visible regardless of mode.
|
|
68
|
-
*/
|
|
69
|
-
async adjustListTools(flowCtx) {
|
|
70
|
-
const { resolvedTools } = flowCtx.state;
|
|
71
|
-
console.log('[CodeCall] adjustListTools hook called, mode:', this.options.mode);
|
|
72
|
-
console.log('[CodeCall] Tools before filter:', resolvedTools?.length ?? 0);
|
|
73
|
-
if (!resolvedTools || resolvedTools.length === 0) {
|
|
74
|
-
console.log('[CodeCall] No tools to filter, returning early');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// Filter tools based on mode
|
|
78
|
-
const filteredTools = resolvedTools.filter(({ tool }) => {
|
|
79
|
-
return this.shouldShowInListTools(tool, this.options.mode);
|
|
80
|
-
});
|
|
81
|
-
console.log('[CodeCall] Tools after filter:', filteredTools.length);
|
|
82
|
-
// Update the state with filtered tools
|
|
83
|
-
flowCtx.state.set('resolvedTools', filteredTools);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Determine if a tool should be visible in list_tools based on mode.
|
|
87
|
-
*
|
|
88
|
-
* @param tool - The tool entry to check
|
|
89
|
-
* @param mode - The current CodeCall mode
|
|
90
|
-
* @returns true if tool should be visible
|
|
91
|
-
*/
|
|
92
|
-
shouldShowInListTools(tool, mode) {
|
|
93
|
-
// CodeCall meta-tools are ALWAYS visible
|
|
94
|
-
if (this.isCodeCallTool(tool)) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
// Get tool's CodeCall metadata
|
|
98
|
-
const codecallMeta = this.getCodeCallMetadata(tool);
|
|
99
|
-
switch (mode) {
|
|
100
|
-
case 'codecall_only':
|
|
101
|
-
// In codecall_only mode, only CodeCall meta-tools and tools with
|
|
102
|
-
// explicit visibleInListTools=true are shown
|
|
103
|
-
return codecallMeta?.visibleInListTools === true;
|
|
104
|
-
case 'codecall_opt_in':
|
|
105
|
-
// In opt_in mode, all tools are shown (they opt-in to CodeCall execution via metadata)
|
|
106
|
-
return true;
|
|
107
|
-
case 'metadata_driven':
|
|
108
|
-
// In metadata_driven mode, use per-tool metadata
|
|
109
|
-
// Default: show unless explicitly hidden
|
|
110
|
-
if (codecallMeta?.visibleInListTools === false) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
// If visibleInListTools is true or undefined, show the tool
|
|
114
|
-
return true;
|
|
115
|
-
default:
|
|
116
|
-
// Unknown mode - default to showing the tool (fail-open for UX)
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Check if a tool is a CodeCall meta-tool.
|
|
122
|
-
* CodeCall meta-tools always remain visible.
|
|
123
|
-
*/
|
|
124
|
-
isCodeCallTool(tool) {
|
|
125
|
-
const name = tool.name || tool.fullName;
|
|
126
|
-
return name.startsWith('codecall:');
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Extract CodeCall-specific metadata from a tool.
|
|
130
|
-
*/
|
|
131
|
-
getCodeCallMetadata(tool) {
|
|
132
|
-
return tool.metadata?.codecall;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
tslib_1.__decorate([
|
|
136
|
-
sdk_1.ListToolsHook.Did('resolveConflicts', { priority: 1000 }),
|
|
137
|
-
tslib_1.__metadata("design:type", Function),
|
|
138
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
139
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
140
|
-
], CodeCallPlugin.prototype, "adjustListTools", null);
|
|
141
|
-
CodeCallPlugin = tslib_1.__decorate([
|
|
142
|
-
(0, sdk_1.Plugin)({
|
|
143
|
-
name: 'codecall',
|
|
144
|
-
description: 'CodeCall plugin: AgentScript-based meta-tools for orchestrating MCP tools',
|
|
145
|
-
providers: [],
|
|
146
|
-
plugins: [cache_1.default],
|
|
147
|
-
tools: [tools_1.SearchTool, tools_1.DescribeTool, tools_1.ExecuteTool, tools_1.InvokeTool],
|
|
148
|
-
}),
|
|
149
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
150
|
-
], CodeCallPlugin);
|
|
151
|
-
exports.default = CodeCallPlugin;
|
|
152
|
-
//# sourceMappingURL=codecall.plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codecall.plugin.js","sourceRoot":"","sources":["../../../src/codecall/codecall.plugin.ts"],"names":[],"m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ntry, ToolEntry } from '@frontmcp/sdk';\n\nimport {\n CodeCallMode,\n CodeCallPluginOptions,\n CodeCallPluginOptionsInput,\n CodeCallToolMetadata,\n codeCallPluginOptionsSchema,\n} from './codecall.types';\nimport { ToolSearchService } from './services';\n\nimport { SearchTool, DescribeTool, ExecuteTool, InvokeTool } from './tools';\n\nimport CodeCallConfig from './providers/code-call.config';\nimport EnclaveService from './services/enclave.service';\nimport CachePlugin from '../cache';\n\n@Plugin({\n name: 'codecall',\n description: 'CodeCall plugin: AgentScript-based meta-tools for orchestrating MCP tools',\n providers: [],\n plugins: [CachePlugin],\n tools: [SearchTool, DescribeTool, ExecuteTool, InvokeTool],\n})\nexport default class CodeCallPlugin extends DynamicPlugin<CodeCallPluginOptions, CodeCallPluginOptionsInput> {\n options: CodeCallPluginOptions;\n\n constructor(options: CodeCallPluginOptionsInput = {}) {\n super();\n // Parse options with Zod schema to apply all defaults\n this.options = codeCallPluginOptionsSchema.parse(options);\n console.log('[CodeCall] Plugin initialized with mode:', this.options.mode);\n }\n\n /**\n * Dynamic providers allow you to configure the plugin with custom options\n * without touching the plugin decorator.\n */\n static override dynamicProviders(options: CodeCallPluginOptionsInput): ProviderType[] {\n // Parse options with Zod schema to apply all defaults\n const parsedOptions = codeCallPluginOptionsSchema.parse(options);\n\n // Create config instance\n const config = new CodeCallConfig(parsedOptions);\n\n return [\n {\n name: 'codecall:config',\n provide: CodeCallConfig,\n useValue: config,\n },\n {\n name: 'codecall:enclave',\n provide: EnclaveService,\n inject: () => [CodeCallConfig],\n useFactory: async (cfg: CodeCallConfig) => {\n return new EnclaveService(cfg);\n },\n },\n {\n name: 'codecall:tool-search',\n provide: ToolSearchService,\n inject: () => [ScopeEntry],\n useFactory: async (scope: ScopeEntry) => {\n return new ToolSearchService(\n {\n embeddingOptions: parsedOptions.embedding,\n mode: parsedOptions.mode,\n includeTools: parsedOptions['includeTools'],\n },\n scope,\n );\n },\n },\n ];\n }\n\n /**\n * Hook into list_tools to enforce CodeCall modes:\n *\n * Modes:\n * - codecall_only: Hide all tools from list_tools except CodeCall meta-tools.\n * All other tools must be discovered via codecall:search.\n * - codecall_opt_in: Show all tools in list_tools. Tools opt-in to CodeCall via metadata.\n * - metadata_driven: Use per-tool metadata.codecall to control visibility in list_tools.\n *\n * CodeCall meta-tools (codecall:search, codecall:describe, codecall:execute, codecall:invoke)\n * are ALWAYS visible regardless of mode.\n */\n @ListToolsHook.Did('resolveConflicts', { priority: 1000 })\n async adjustListTools(flowCtx: FlowCtxOf<'tools:list-tools'>) {\n const { resolvedTools } = flowCtx.state;\n console.log('[CodeCall] adjustListTools hook called, mode:', this.options.mode);\n console.log('[CodeCall] Tools before filter:', resolvedTools?.length ?? 0);\n\n if (!resolvedTools || resolvedTools.length === 0) {\n console.log('[CodeCall] No tools to filter, returning early');\n return;\n }\n\n // Filter tools based on mode\n const filteredTools = resolvedTools.filter(({ tool }) => {\n return this.shouldShowInListTools(tool, this.options.mode);\n });\n\n console.log('[CodeCall] Tools after filter:', filteredTools.length);\n\n // Update the state with filtered tools\n flowCtx.state.set('resolvedTools', filteredTools);\n }\n\n /**\n * Determine if a tool should be visible in list_tools based on mode.\n *\n * @param tool - The tool entry to check\n * @param mode - The current CodeCall mode\n * @returns true if tool should be visible\n */\n private shouldShowInListTools(tool: ToolEntry<any, any, any, any>, mode: CodeCallMode): boolean {\n // CodeCall meta-tools are ALWAYS visible\n if (this.isCodeCallTool(tool)) {\n return true;\n }\n\n // Get tool's CodeCall metadata\n const codecallMeta = this.getCodeCallMetadata(tool);\n\n switch (mode) {\n case 'codecall_only':\n // In codecall_only mode, only CodeCall meta-tools and tools with\n // explicit visibleInListTools=true are shown\n return codecallMeta?.visibleInListTools === true;\n\n case 'codecall_opt_in':\n // In opt_in mode, all tools are shown (they opt-in to CodeCall execution via metadata)\n return true;\n\n case 'metadata_driven':\n // In metadata_driven mode, use per-tool metadata\n // Default: show unless explicitly hidden\n if (codecallMeta?.visibleInListTools === false) {\n return false;\n }\n // If visibleInListTools is true or undefined, show the tool\n return true;\n\n default:\n // Unknown mode - default to showing the tool (fail-open for UX)\n return true;\n }\n }\n\n /**\n * Check if a tool is a CodeCall meta-tool.\n * CodeCall meta-tools always remain visible.\n */\n private isCodeCallTool(tool: ToolEntry<any, any, any, any>): boolean {\n const name = tool.name || tool.fullName;\n return name.startsWith('codecall:');\n }\n\n /**\n * Extract CodeCall-specific metadata from a tool.\n */\n private getCodeCallMetadata(tool: ToolEntry<any, any, any, any>): CodeCallToolMetadata | undefined {\n return (tool.metadata as any)?.codecall as CodeCallToolMetadata | undefined;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codecall.symbol.js","sourceRoot":"","sources":["../../../src/codecall/codecall.symbol.ts"],"names":[],"mappings":";AAAA,qDAAqD","sourcesContent":["// file: libs/plugins/src/codecall/codecall.symbol.ts\n\nimport { CodeCallVmPreset } from './codecall.types';\nimport type { ToolCallResult, CallToolOptions } from './errors';\n\nexport interface CodeCallAstValidationIssue {\n kind: 'IllegalBuiltinAccess' | 'DisallowedGlobal' | 'DisallowedLoop' | 'ParseError';\n message: string;\n location?: { line: number; column: number };\n identifier?: string;\n}\n\nexport interface CodeCallAstValidationResult {\n ok: boolean;\n issues: CodeCallAstValidationIssue[];\n transformedCode?: string;\n}\n\n/**\n * Interface for the AST validator service\n */\nexport interface CodeCallAstValidator {\n /**\n * Validate a JavaScript script before execution\n */\n validate(script: string): Promise<CodeCallAstValidationResult>;\n}\n\n/**\n * Resolved VM options with all defaults applied.\n * Plugins compute this once and pass into providers.\n */\nexport interface ResolvedCodeCallVmOptions {\n preset: CodeCallVmPreset;\n timeoutMs: number;\n allowLoops: boolean;\n maxSteps?: number;\n disabledBuiltins: string[];\n disabledGlobals: string[];\n allowConsole: boolean;\n}\n\n/**\n * Environment available to code running inside the VM.\n * The plugin is responsible for wiring this to the underlying tool pipeline.\n */\nexport interface CodeCallVmEnvironment {\n /**\n * Call a tool from within AgentScript.\n *\n * @param name - Tool name (e.g., 'users:list')\n * @param input - Tool input arguments\n * @param options - Optional behavior configuration\n * @param options.throwOnError - When true (default), throws on error.\n * When false, returns { success, data, error }.\n *\n * SECURITY NOTES:\n * - Cannot call 'codecall:*' tools (self-reference blocked)\n * - Errors are sanitized - no stack traces or internal details exposed\n * - Security guard errors (self-reference, access control) are NEVER catchable\n */\n callTool: <TInput, TResult>(\n name: string,\n input: TInput,\n options?: CallToolOptions,\n ) => Promise<TResult | ToolCallResult<TResult>>;\n\n getTool: (name: string) =>\n | {\n name: string;\n description?: string;\n inputSchema: unknown;\n outputSchema?: unknown | null;\n }\n | undefined;\n\n console?: Console;\n\n mcpLog?: (level: 'debug' | 'info' | 'warn' | 'error', message: string, metadata?: Record<string, unknown>) => void;\n\n mcpNotify?: (event: string, payload: Record<string, unknown>) => void;\n}\n\n/**\n * Result from a tool search query\n */\nexport interface ToolSearchResult {\n toolName: string;\n appId?: string;\n description: string;\n relevanceScore: number;\n}\n\n/**\n * Options for searching tools\n */\nexport interface ToolSearchOptions {\n topK?: number;\n appIds?: string[];\n excludeToolNames?: string[];\n}\n\n/**\n * Interface for the tool search service\n */\nexport interface ToolSearch {\n /**\n * Search for tools matching the query\n */\n search(query: string, options?: ToolSearchOptions): Promise<ToolSearchResult[]>;\n\n /**\n * Check if a tool exists in the index\n */\n hasTool(toolName: string): boolean;\n\n /**\n * Get the total number of indexed tools\n */\n getTotalCount(): number;\n\n /**\n * Initialize the search index with tools\n */\n initialize(): Promise<void>;\n}\n"]}
|
|
@@ -1,262 +0,0 @@
|
|
|
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.optional(),
|
|
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().optional(),
|
|
128
|
-
/**
|
|
129
|
-
* Cache directory for ML models (only used when strategy='ml')
|
|
130
|
-
* @default './.cache/transformers'
|
|
131
|
-
*/
|
|
132
|
-
cacheDir: zod_1.z.string().optional(),
|
|
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().optional(),
|
|
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.union([zod_1.z.literal(false), exports.synonymExpansionConfigSchema]).optional(),
|
|
147
|
-
})
|
|
148
|
-
.optional()
|
|
149
|
-
.transform((opts) => ({
|
|
150
|
-
strategy: opts?.strategy ?? DEFAULT_EMBEDDING_OPTIONS.strategy,
|
|
151
|
-
modelName: opts?.modelName ?? DEFAULT_EMBEDDING_OPTIONS.modelName,
|
|
152
|
-
cacheDir: opts?.cacheDir ?? DEFAULT_EMBEDDING_OPTIONS.cacheDir,
|
|
153
|
-
useHNSW: opts?.useHNSW ?? DEFAULT_EMBEDDING_OPTIONS.useHNSW,
|
|
154
|
-
synonymExpansion: opts?.synonymExpansion ?? DEFAULT_EMBEDDING_OPTIONS.synonymExpansion,
|
|
155
|
-
}));
|
|
156
|
-
exports.codeCallSidecarOptionsSchema = zod_1.z
|
|
157
|
-
.object({
|
|
158
|
-
/**
|
|
159
|
-
* Enable pass-by-reference support via sidecar
|
|
160
|
-
* When enabled, large strings are automatically lifted to a sidecar
|
|
161
|
-
* and resolved at the callTool boundary
|
|
162
|
-
* @default false
|
|
163
|
-
*/
|
|
164
|
-
enabled: zod_1.z.boolean().default(false),
|
|
165
|
-
/**
|
|
166
|
-
* Maximum total size of all stored references in bytes
|
|
167
|
-
* @default 16MB (from security level)
|
|
168
|
-
*/
|
|
169
|
-
maxTotalSize: zod_1.z.number().positive().optional(),
|
|
170
|
-
/**
|
|
171
|
-
* Maximum size of a single reference in bytes
|
|
172
|
-
* @default 4MB (from security level)
|
|
173
|
-
*/
|
|
174
|
-
maxReferenceSize: zod_1.z.number().positive().optional(),
|
|
175
|
-
/**
|
|
176
|
-
* Threshold in bytes to trigger extraction from source code
|
|
177
|
-
* Strings larger than this are lifted to the sidecar
|
|
178
|
-
* @default 64KB (from security level)
|
|
179
|
-
*/
|
|
180
|
-
extractionThreshold: zod_1.z.number().positive().optional(),
|
|
181
|
-
/**
|
|
182
|
-
* Maximum expanded size when resolving references for tool calls
|
|
183
|
-
* @default 8MB (from security level)
|
|
184
|
-
*/
|
|
185
|
-
maxResolvedSize: zod_1.z.number().positive().optional(),
|
|
186
|
-
/**
|
|
187
|
-
* Whether to allow composite handles from string concatenation
|
|
188
|
-
* If false, concatenating references throws an error
|
|
189
|
-
* @default false (strict mode)
|
|
190
|
-
*/
|
|
191
|
-
allowComposites: zod_1.z.boolean().optional(),
|
|
192
|
-
/**
|
|
193
|
-
* Maximum script length (in characters) when sidecar is disabled
|
|
194
|
-
* Prevents large inline data from being embedded in script
|
|
195
|
-
* If null, no limit is enforced
|
|
196
|
-
* @default 64KB
|
|
197
|
-
*/
|
|
198
|
-
maxScriptLengthWhenDisabled: zod_1.z
|
|
199
|
-
.number()
|
|
200
|
-
.positive()
|
|
201
|
-
.nullable()
|
|
202
|
-
.default(64 * 1024),
|
|
203
|
-
})
|
|
204
|
-
.default(() => ({
|
|
205
|
-
enabled: false,
|
|
206
|
-
maxScriptLengthWhenDisabled: 64 * 1024,
|
|
207
|
-
}));
|
|
208
|
-
// Inner schema without the outer .default() - used for extracting input type
|
|
209
|
-
const codeCallPluginOptionsObjectSchema = zod_1.z.object({
|
|
210
|
-
/**
|
|
211
|
-
* CodeCall mode
|
|
212
|
-
* @default 'codecall_only'
|
|
213
|
-
*/
|
|
214
|
-
mode: exports.codeCallModeSchema,
|
|
215
|
-
/**
|
|
216
|
-
* Default number of tools to return in search results
|
|
217
|
-
* @default 8
|
|
218
|
-
*/
|
|
219
|
-
topK: zod_1.z.number().positive().default(8),
|
|
220
|
-
/**
|
|
221
|
-
* Maximum number of tool definitions to include
|
|
222
|
-
* @default 8
|
|
223
|
-
*/
|
|
224
|
-
maxDefinitions: zod_1.z.number().positive().default(8),
|
|
225
|
-
/**
|
|
226
|
-
* Optional filter function for including tools.
|
|
227
|
-
* Signature: (tool: IncludeToolsFilterToolInfo) => boolean
|
|
228
|
-
*/
|
|
229
|
-
includeTools: includeToolsFilterSchema.optional(),
|
|
230
|
-
/**
|
|
231
|
-
* Direct calls configuration
|
|
232
|
-
*/
|
|
233
|
-
directCalls: exports.codeCallDirectCallsOptionsSchema.optional(),
|
|
234
|
-
/**
|
|
235
|
-
* VM execution options
|
|
236
|
-
*/
|
|
237
|
-
vm: exports.codeCallVmOptionsSchema,
|
|
238
|
-
/**
|
|
239
|
-
* Embedding configuration for tool search
|
|
240
|
-
*/
|
|
241
|
-
embedding: exports.codeCallEmbeddingOptionsSchema,
|
|
242
|
-
/**
|
|
243
|
-
* Sidecar (pass-by-reference) configuration
|
|
244
|
-
* When enabled, large data is stored outside the sandbox and resolved at callTool boundary
|
|
245
|
-
*/
|
|
246
|
-
sidecar: exports.codeCallSidecarOptionsSchema,
|
|
247
|
-
});
|
|
248
|
-
// Default values for plugin options
|
|
249
|
-
const DEFAULT_PLUGIN_OPTIONS = {
|
|
250
|
-
mode: 'codecall_only',
|
|
251
|
-
topK: 8,
|
|
252
|
-
maxDefinitions: 8,
|
|
253
|
-
vm: DEFAULT_VM_OPTIONS,
|
|
254
|
-
embedding: DEFAULT_EMBEDDING_OPTIONS,
|
|
255
|
-
sidecar: {
|
|
256
|
-
enabled: false,
|
|
257
|
-
maxScriptLengthWhenDisabled: 64 * 1024,
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
// Full schema with default - used for parsing
|
|
261
|
-
exports.codeCallPluginOptionsSchema = codeCallPluginOptionsObjectSchema.prefault(DEFAULT_PLUGIN_OPTIONS);
|
|
262
|
-
//# sourceMappingURL=codecall.types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,UAAU,EAAE;IAChG,OAAO,EAAE,uFAAuF;CACjG,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAuB,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,UAAU,EAAE;IAClG,OAAO,EAAE,8FAA8F;CACxG,CAAC,CAAC;AAEH,wCAAwC;AAE3B,QAAA,kBAAkB,GAAG,OAAC;KAChC,IAAI,CAAC,CAAC,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;KAC7D,OAAO,CAAC,eAAe,CAAC,CAAC;AAEf,QAAA,sBAAsB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEtH,gCAAgC;AAChC,MAAM,kBAAkB,GAAG;IACzB,MAAM,EAAE,QAAiB;CAC1B,CAAC;AAEW,QAAA,uBAAuB,GAAG,OAAC;KACrC,MAAM,CAAC;IACN;;;OAGG;IACH,MAAM,EAAE,8BAAsB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CAAC,CAAC,CAAC;AAEN,6EAA6E;AAC7E,MAAM,iCAAiC,GAAG,OAAC,CAAC,MAAM,CAAC;IACjD;;;OAGG;IACH,IAAI,EAAE,0BAAkB;IAExB;;;OAGG;IACH,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtC;;;OAGG;IACH,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEhD;;;OAGG;IACH,YAAY,EAAE,wBAAwB,CAAC,QAAQ,EAAE;IAEjD;;OAEG;IACH,WAAW,EAAE,wCAAgC,CAAC,QAAQ,EAAE;IAExD;;OAEG;IACH,EAAE,EAAE,+BAAuB;IAE3B;;OAEG;IACH,SAAS,EAAE,sCAA8B;IAEzC;;;OAGG;IACH,OAAO,EAAE,oCAA4B;CACtC,CAAC,CAAC;AAEH,oCAAoC;AACpC,MAAM,sBAAsB,GAAG;IAC7B,IAAI,EAAE,eAAwB;IAC9B,IAAI,EAAE,CAAC;IACP,cAAc,EAAE,CAAC;IACjB,EAAE,EAAE,kBAAkB;IACtB,SAAS,EAAE,yBAAyB;IACpC,OAAO,EAAE;QACP,OAAO,EAAE,KAAK;QACd,2BAA2B,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.optional(),\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().optional(),\n\n /**\n * Cache directory for ML models (only used when strategy='ml')\n * @default './.cache/transformers'\n */\n cacheDir: z.string().optional(),\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().optional(),\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.union([z.literal(false), synonymExpansionConfigSchema]).optional(),\n })\n .optional()\n .transform((opts) => ({\n strategy: opts?.strategy ?? DEFAULT_EMBEDDING_OPTIONS.strategy,\n modelName: opts?.modelName ?? DEFAULT_EMBEDDING_OPTIONS.modelName,\n cacheDir: opts?.cacheDir ?? DEFAULT_EMBEDDING_OPTIONS.cacheDir,\n useHNSW: opts?.useHNSW ?? DEFAULT_EMBEDDING_OPTIONS.useHNSW,\n synonymExpansion: opts?.synonymExpansion ?? DEFAULT_EMBEDDING_OPTIONS.synonymExpansion,\n }));\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1,119 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAC,CAAC;AACL,CAAC;AAED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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"]}
|
package/src/codecall/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
|