@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,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const describeToolDescription = "Get input/output schemas for tools from search results.\n\nINPUT: toolNames: string[] - tool names from search\nOUTPUT per tool: inputSchema (JSON Schema), outputSchema (JSON Schema), usageExamples (up to 5 callTool examples)\n\nIMPORTANT: If notFound array is non-empty \u2192 re-search with corrected queries.\nFLOW: search \u2192 describe \u2192 execute/invoke";
|
|
3
|
+
export declare const describeToolInputSchema: z.ZodObject<{
|
|
4
|
+
toolNames: z.ZodArray<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export type DescribeToolInput = z.infer<typeof describeToolInputSchema>;
|
|
7
|
+
export declare const describeToolOutputSchema: z.ZodObject<{
|
|
8
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
appId: z.ZodString;
|
|
11
|
+
description: z.ZodString;
|
|
12
|
+
inputSchema: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
13
|
+
outputSchema: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
14
|
+
annotations: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
title: z.ZodOptional<z.ZodString>;
|
|
16
|
+
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
usageExamples: z.ZodArray<z.ZodObject<{
|
|
22
|
+
description: z.ZodString;
|
|
23
|
+
code: z.ZodString;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
notFound: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type DescribeToolOutput = z.infer<typeof describeToolOutputSchema>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeToolOutputSchema = exports.describeToolInputSchema = exports.describeToolDescription = void 0;
|
|
4
|
+
// file: libs/plugins/src/codecall/tools/describe.schema.ts
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
|
+
exports.describeToolDescription = `Get input/output schemas for tools from search results.
|
|
8
|
+
|
|
9
|
+
INPUT: toolNames: string[] - tool names from search
|
|
10
|
+
OUTPUT per tool: inputSchema (JSON Schema), outputSchema (JSON Schema), usageExamples (up to 5 callTool examples)
|
|
11
|
+
|
|
12
|
+
IMPORTANT: If notFound array is non-empty → re-search with corrected queries.
|
|
13
|
+
FLOW: search → describe → execute/invoke`;
|
|
14
|
+
exports.describeToolInputSchema = zod_1.z.object({
|
|
15
|
+
toolNames: zod_1.z
|
|
16
|
+
.array(zod_1.z.string())
|
|
17
|
+
.min(1)
|
|
18
|
+
.superRefine((toolNames, ctx) => {
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const duplicates = new Set();
|
|
21
|
+
for (const name of toolNames) {
|
|
22
|
+
if (seen.has(name)) {
|
|
23
|
+
duplicates.add(name);
|
|
24
|
+
}
|
|
25
|
+
seen.add(name);
|
|
26
|
+
}
|
|
27
|
+
if (duplicates.size > 0) {
|
|
28
|
+
ctx.addIssue({
|
|
29
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
30
|
+
message: `Duplicate tool names are not allowed: ${Array.from(duplicates).join(', ')}`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
.describe('Array of unique tool names (from codecall:search results) to fetch their detailed schemas and usage examples. Example: ["users:list", "billing:getInvoice"]'),
|
|
35
|
+
});
|
|
36
|
+
exports.describeToolOutputSchema = zod_1.z.object({
|
|
37
|
+
tools: zod_1.z
|
|
38
|
+
.array(zod_1.z.object({
|
|
39
|
+
name: zod_1.z.string().describe('Tool name to be used in callTool() within codecall:execute scripts'),
|
|
40
|
+
appId: zod_1.z.string().describe('The app ID this tool belongs to'),
|
|
41
|
+
description: zod_1.z.string().describe('Detailed description of what this tool does'),
|
|
42
|
+
inputSchema: zod_1.z
|
|
43
|
+
.record(zod_1.z.string(), zod_1.z.unknown())
|
|
44
|
+
.nullable()
|
|
45
|
+
.describe('JSON Schema object describing the tool input parameters'),
|
|
46
|
+
outputSchema: zod_1.z
|
|
47
|
+
.record(zod_1.z.string(), zod_1.z.unknown())
|
|
48
|
+
.nullable()
|
|
49
|
+
.describe('JSON Schema object describing the tool output structure'),
|
|
50
|
+
annotations: types_js_1.ToolAnnotationsSchema.optional().describe('MCP tool annotations (metadata)'),
|
|
51
|
+
usageExamples: zod_1.z
|
|
52
|
+
.array(zod_1.z.object({
|
|
53
|
+
description: zod_1.z.string().describe('Description of what this example demonstrates'),
|
|
54
|
+
code: zod_1.z
|
|
55
|
+
.string()
|
|
56
|
+
.describe('JavaScript code example showing how to call this tool using callTool(). Format: const result = await callTool("tool:name", { ...params });'),
|
|
57
|
+
}))
|
|
58
|
+
.max(5)
|
|
59
|
+
.describe('Up to 5 practical examples of how to use this tool in a codecall:execute script'),
|
|
60
|
+
}))
|
|
61
|
+
.describe('Array of tool descriptions with schemas and usage examples'),
|
|
62
|
+
notFound: zod_1.z
|
|
63
|
+
.array(zod_1.z.string())
|
|
64
|
+
.optional()
|
|
65
|
+
.describe('Tool names that were requested but not found in the index. Check these for typos.'),
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=describe.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.schema.js","sourceRoot":"","sources":["../../../../src/codecall/tools/describe.schema.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAC3D,6BAAwB;AACxB,iEAA2E;AAE9D,QAAA,uBAAuB,GAAG;;;;;;yCAME,CAAC;AAE7B,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,OAAC;SACT,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;SACjB,GAAG,CAAC,CAAC,CAAC;SACN,WAAW,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACnB,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,GAAG,C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AA4I,CAC7I;SACJ,CAAC,CACH;aACA,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,iFAAiF,CAAC;KAC/F,CAAC,CACH;SACA,QAAQ,CAAC,4DAA4D,CAAC;IACzE,QAAQ,EAAE,OAAC;SACR,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CAAC,mFAAmF,CAAC;CACjG,CAAC,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/tools/describe.schema.ts\nimport { z } from 'zod';\nimport { ToolAnnotationsSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport const describeToolDescription = `Get input/output schemas for tools from search results.\n\nINPUT: toolNames: string[] - tool names from search\nOUTPUT per tool: inputSchema (JSON Schema), outputSchema (JSON Schema), usageExamples (up to 5 callTool examples)\n\nIMPORTANT: If notFound array is non-empty → re-search with corrected queries.\nFLOW: search → describe → execute/invoke`;\n\nexport const describeToolInputSchema = z.object({\n toolNames: z\n .array(z.string())\n .min(1)\n .superRefine((toolNames, ctx) => {\n const seen = new Set<string>();\n const duplicates = new Set<string>();\n for (const name of toolNames) {\n if (seen.has(name)) {\n duplicates.add(name);\n }\n seen.add(name);\n }\n if (duplicates.size > 0) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Duplicate tool names are not allowed: ${Array.from(duplicates).join(', ')}`,\n });\n }\n })\n .describe(\n 'Array of unique tool names (from codecall:search results) to fetch their detailed schemas and usage examples. Example: [\"users:list\", \"billing:getInvoice\"]',\n ),\n});\n\nexport type DescribeToolInput = z.infer<typeof describeToolInputSchema>;\n\nexport const describeToolOutputSchema = z.object({\n tools: z\n .array(\n z.object({\n name: z.string().describe('Tool name to be used in callTool() within codecall:execute scripts'),\n appId: z.string().describe('The app ID this tool belongs to'),\n description: z.string().describe('Detailed description of what this tool does'),\n inputSchema: z\n .record(z.string(), z.unknown())\n .nullable()\n .describe('JSON Schema object describing the tool input parameters'),\n outputSchema: z\n .record(z.string(), z.unknown())\n .nullable()\n .describe('JSON Schema object describing the tool output structure'),\n annotations: ToolAnnotationsSchema.optional().describe('MCP tool annotations (metadata)'),\n usageExamples: z\n .array(\n z.object({\n description: z.string().describe('Description of what this example demonstrates'),\n code: z\n .string()\n .describe(\n 'JavaScript code example showing how to call this tool using callTool(). Format: const result = await callTool(\"tool:name\", { ...params });',\n ),\n }),\n )\n .max(5)\n .describe('Up to 5 practical examples of how to use this tool in a codecall:execute script'),\n }),\n )\n .describe('Array of tool descriptions with schemas and usage examples'),\n notFound: z\n .array(z.string())\n .optional()\n .describe('Tool names that were requested but not found in the index. Check these for typos.'),\n});\n\nexport type DescribeToolOutput = z.infer<typeof describeToolOutputSchema>;\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ToolContext } from '@frontmcp/sdk';
|
|
2
|
+
import { DescribeToolInput, DescribeToolOutput } from './describe.schema';
|
|
3
|
+
export default class DescribeTool extends ToolContext {
|
|
4
|
+
execute(input: DescribeToolInput): Promise<DescribeToolOutput>;
|
|
5
|
+
/**
|
|
6
|
+
* Get the input schema for a tool, converting from Zod to JSON Schema.
|
|
7
|
+
* This ensures that property descriptions from .describe() are included.
|
|
8
|
+
*
|
|
9
|
+
* Priority:
|
|
10
|
+
* 1. Convert from tool.inputSchema (Zod) to get descriptions
|
|
11
|
+
* 2. Fall back to rawInputSchema if conversion fails
|
|
12
|
+
* 3. Return null if no schema available
|
|
13
|
+
*/
|
|
14
|
+
private getInputSchema;
|
|
15
|
+
/**
|
|
16
|
+
* Convert a schema to JSON Schema format.
|
|
17
|
+
* Handles Zod schemas, raw shapes, and already-JSON-Schema objects.
|
|
18
|
+
*
|
|
19
|
+
* Uses Zod v4's built-in z.toJSONSchema() for conversion.
|
|
20
|
+
*/
|
|
21
|
+
private toJsonSchema;
|
|
22
|
+
/**
|
|
23
|
+
* Extract app ID from tool metadata or owner.
|
|
24
|
+
*/
|
|
25
|
+
private extractAppId;
|
|
26
|
+
/**
|
|
27
|
+
* Generate up to 5 usage examples for a tool.
|
|
28
|
+
*
|
|
29
|
+
* Priority:
|
|
30
|
+
* 1. User-provided examples from @Tool decorator metadata (up to 5)
|
|
31
|
+
* 2. Smart intent-based generation to fill remaining slots
|
|
32
|
+
* 3. Returns at least 1 example
|
|
33
|
+
*/
|
|
34
|
+
private generateExamples;
|
|
35
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// file: libs/plugins/src/codecall/tools/describe.tool.ts
|
|
5
|
+
const sdk_1 = require("@frontmcp/sdk");
|
|
6
|
+
const v4_1 = require("zod/v4");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const describe_schema_1 = require("./describe.schema");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const security_1 = require("../security");
|
|
11
|
+
let DescribeTool = class DescribeTool extends sdk_1.ToolContext {
|
|
12
|
+
async execute(input) {
|
|
13
|
+
const { toolNames } = input;
|
|
14
|
+
const tools = [];
|
|
15
|
+
const notFound = [];
|
|
16
|
+
// Get all available tools from the registry
|
|
17
|
+
const allTools = this.scope.tools.getTools(true);
|
|
18
|
+
const toolMap = new Map(allTools.map((t) => [t.name, t]));
|
|
19
|
+
const fullNameMap = new Map(allTools.map((t) => [t.fullName, t]));
|
|
20
|
+
for (const toolName of toolNames) {
|
|
21
|
+
// Security: Don't allow describing CodeCall tools themselves
|
|
22
|
+
if ((0, security_1.isBlockedSelfReference)(toolName)) {
|
|
23
|
+
notFound.push(toolName);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
// Find the tool by name or fullName
|
|
27
|
+
const tool = toolMap.get(toolName) || fullNameMap.get(toolName);
|
|
28
|
+
if (!tool) {
|
|
29
|
+
notFound.push(toolName);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
// Extract app ID from tool owner or metadata
|
|
33
|
+
const appId = this.extractAppId(tool);
|
|
34
|
+
// Get input schema - convert from Zod to ensure descriptions are included
|
|
35
|
+
const inputSchema = this.getInputSchema(tool);
|
|
36
|
+
// Get output schema - convert from Zod if needed
|
|
37
|
+
const outputSchema = this.toJsonSchema(tool.outputSchema);
|
|
38
|
+
// Generate usage examples: user-provided > smart generation > basic fallback
|
|
39
|
+
const usageExamples = this.generateExamples(tool, inputSchema ?? undefined);
|
|
40
|
+
tools.push({
|
|
41
|
+
name: tool.name,
|
|
42
|
+
appId,
|
|
43
|
+
description: tool.metadata?.description || `Tool: ${tool.name}`,
|
|
44
|
+
inputSchema: inputSchema || null,
|
|
45
|
+
outputSchema: outputSchema || null,
|
|
46
|
+
annotations: tool.metadata?.annotations,
|
|
47
|
+
usageExamples,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
tools,
|
|
52
|
+
notFound: notFound.length > 0 ? notFound : undefined,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the input schema for a tool, converting from Zod to JSON Schema.
|
|
57
|
+
* This ensures that property descriptions from .describe() are included.
|
|
58
|
+
*
|
|
59
|
+
* Priority:
|
|
60
|
+
* 1. Convert from tool.inputSchema (Zod) to get descriptions
|
|
61
|
+
* 2. Fall back to rawInputSchema if conversion fails
|
|
62
|
+
* 3. Return null if no schema available
|
|
63
|
+
*/
|
|
64
|
+
getInputSchema(tool) {
|
|
65
|
+
// First, try to convert from the Zod inputSchema to ensure descriptions are included
|
|
66
|
+
if (tool.inputSchema && typeof tool.inputSchema === 'object' && Object.keys(tool.inputSchema).length > 0) {
|
|
67
|
+
try {
|
|
68
|
+
// tool.inputSchema is a ZodRawShape (Record<string, ZodType>)
|
|
69
|
+
const firstValue = Object.values(tool.inputSchema)[0];
|
|
70
|
+
if (firstValue instanceof zod_1.ZodType) {
|
|
71
|
+
// Convert Zod shape to JSON Schema - this preserves .describe() annotations
|
|
72
|
+
return (0, v4_1.toJSONSchema)(zod_1.z.object(tool.inputSchema));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Fall through to rawInputSchema
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Fall back to rawInputSchema if available
|
|
80
|
+
if (tool.rawInputSchema) {
|
|
81
|
+
return tool.rawInputSchema;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convert a schema to JSON Schema format.
|
|
87
|
+
* Handles Zod schemas, raw shapes, and already-JSON-Schema objects.
|
|
88
|
+
*
|
|
89
|
+
* Uses Zod v4's built-in z.toJSONSchema() for conversion.
|
|
90
|
+
*/
|
|
91
|
+
toJsonSchema(schema) {
|
|
92
|
+
if (!schema) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// Check if it's a Zod schema
|
|
96
|
+
if (schema instanceof zod_1.ZodType) {
|
|
97
|
+
try {
|
|
98
|
+
// Use Zod v4's toJSONSchema conversion
|
|
99
|
+
return (0, v4_1.toJSONSchema)(schema);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// If conversion fails, return null
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Check if it's a raw Zod shape (Record<string, ZodTypeAny>)
|
|
107
|
+
if (typeof schema === 'object' && schema !== null && !Array.isArray(schema)) {
|
|
108
|
+
const obj = schema;
|
|
109
|
+
const firstValue = Object.values(obj)[0];
|
|
110
|
+
// If the first value is a ZodType, treat the whole thing as a raw shape
|
|
111
|
+
if (firstValue instanceof zod_1.ZodType) {
|
|
112
|
+
try {
|
|
113
|
+
// Wrap in z.object and convert using Zod v4's toJSONSchema
|
|
114
|
+
return (0, v4_1.toJSONSchema)(zod_1.z.object(obj));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Already a JSON Schema object
|
|
121
|
+
if ('type' in obj || 'properties' in obj || '$schema' in obj) {
|
|
122
|
+
return schema;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// String literal output schemas (like 'text', 'json', etc.) - not a JSON Schema
|
|
126
|
+
if (typeof schema === 'string') {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
// Array output schemas - not directly convertible
|
|
130
|
+
if (Array.isArray(schema)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Extract app ID from tool metadata or owner.
|
|
137
|
+
*/
|
|
138
|
+
extractAppId(tool) {
|
|
139
|
+
// Check codecall metadata first
|
|
140
|
+
if (tool.metadata?.codecall?.appId) {
|
|
141
|
+
return tool.metadata.codecall.appId;
|
|
142
|
+
}
|
|
143
|
+
// Check source metadata
|
|
144
|
+
if (tool.metadata?.source) {
|
|
145
|
+
return tool.metadata.source;
|
|
146
|
+
}
|
|
147
|
+
// Check owner
|
|
148
|
+
if (tool.owner?.id) {
|
|
149
|
+
return tool.owner.id;
|
|
150
|
+
}
|
|
151
|
+
// Extract from tool name (namespace:name -> namespace)
|
|
152
|
+
const nameParts = tool.name?.split(':');
|
|
153
|
+
if (nameParts && nameParts.length > 1) {
|
|
154
|
+
return nameParts[0];
|
|
155
|
+
}
|
|
156
|
+
return 'unknown';
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Generate up to 5 usage examples for a tool.
|
|
160
|
+
*
|
|
161
|
+
* Priority:
|
|
162
|
+
* 1. User-provided examples from @Tool decorator metadata (up to 5)
|
|
163
|
+
* 2. Smart intent-based generation to fill remaining slots
|
|
164
|
+
* 3. Returns at least 1 example
|
|
165
|
+
*/
|
|
166
|
+
generateExamples(tool, inputSchema) {
|
|
167
|
+
const result = [];
|
|
168
|
+
// Priority 1: Use user-provided examples from metadata (up to 5)
|
|
169
|
+
const examples = tool.metadata?.examples;
|
|
170
|
+
if (examples && Array.isArray(examples)) {
|
|
171
|
+
for (const ex of examples.slice(0, 5)) {
|
|
172
|
+
result.push({
|
|
173
|
+
description: ex.description || 'Example usage',
|
|
174
|
+
code: `const result = await callTool('${tool.name}', ${JSON.stringify(ex.input, null, 2)});
|
|
175
|
+
return result;`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Priority 2: If fewer than 5 user examples, add smart-generated example
|
|
180
|
+
if (result.length < 5) {
|
|
181
|
+
result.push((0, utils_1.generateSmartExample)(tool.name, inputSchema, tool.metadata?.description));
|
|
182
|
+
}
|
|
183
|
+
return result.slice(0, 5);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
DescribeTool = tslib_1.__decorate([
|
|
187
|
+
(0, sdk_1.Tool)({
|
|
188
|
+
name: 'codecall:describe',
|
|
189
|
+
cache: {
|
|
190
|
+
ttl: 60, // 1 minute
|
|
191
|
+
slideWindow: false,
|
|
192
|
+
},
|
|
193
|
+
codecall: {
|
|
194
|
+
enabledInCodeCall: false,
|
|
195
|
+
visibleInListTools: true,
|
|
196
|
+
},
|
|
197
|
+
description: describe_schema_1.describeToolDescription,
|
|
198
|
+
inputSchema: describe_schema_1.describeToolInputSchema,
|
|
199
|
+
outputSchema: describe_schema_1.describeToolOutputSchema,
|
|
200
|
+
annotations: {
|
|
201
|
+
readOnlyHint: true,
|
|
202
|
+
openWorldHint: true,
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
], DescribeTool);
|
|
206
|
+
exports.default = DescribeTool;
|
|
207
|
+
//# sourceMappingURL=describe.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.tool.js","sourceRoot":"","sources":["../../../../src/codecall/tools/describe.tool.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,uCAA6D;AAE7D,+BAAsC;AAItC,6BAAiC;AACjC,uDAM2B;AAC3B,oCAAgD;AAChD,0CAAqD;AAo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AC,EAAE,CAAC;gBACtC,MAAM,CAAC,IAAI,CAAC;oBACV,WAAW,EAAE,EAAE,CAAC,WAAW,IAAI,eAAe;oBAC9C,IAAI,EAAE,kCAAkC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;eACnF;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,yEAAyE;QACzE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,IAAI,CAAC,IAAA,4BAAoB,EAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;QACxF,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AAjNoB,YAAY;IAlBhC,IAAA,UAAI,EAAC;QACJ,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE;YACL,GAAG,EAAE,EAAE,EAAE,WAAW;YACpB,WAAW,EAAE,KAAK;SACnB;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,KAAK;YACxB,kBAAkB,EAAE,IAAI;SACzB;QACD,WAAW,EAAE,yCAAuB;QACpC,WAAW,EAAE,yCAAuB;QACpC,YAAY,EAAE,0CAAwB;QACtC,WAAW,EAAE;YACX,YAAY,EAAE,IAAI;YAClB,aAAa,EAAE,IAAI;SACpB;KACF,CAAC;GACmB,YAAY,CAiNhC;kBAjNoB,YAAY","sourcesContent":["// file: libs/plugins/src/codecall/tools/describe.tool.ts\nimport { Tool, ToolContext, ToolEntry } from '@frontmcp/sdk';\nimport type { JSONSchema } from 'zod/v4/core';\nimport { toJSONSchema } from 'zod/v4';\n\n/** JSON Schema type from Zod v4 */\ntype JsonSchema = JSONSchema.JSONSchema;\nimport { z, ZodType } from 'zod';\nimport {\n DescribeToolInput,\n describeToolInputSchema,\n DescribeToolOutput,\n describeToolOutputSchema,\n describeToolDescription,\n} from './describe.schema';\nimport { generateSmartExample } from '../utils';\nimport { isBlockedSelfReference } from '../security';\n\n@Tool({\n name: 'codecall:describe',\n cache: {\n ttl: 60, // 1 minute\n slideWindow: false,\n },\n codecall: {\n enabledInCodeCall: false,\n visibleInListTools: true,\n },\n description: describeToolDescription,\n inputSchema: describeToolInputSchema,\n outputSchema: describeToolOutputSchema,\n annotations: {\n readOnlyHint: true,\n openWorldHint: true,\n },\n})\nexport default class DescribeTool extends ToolContext {\n async execute(input: DescribeToolInput): Promise<DescribeToolOutput> {\n const { toolNames } = input;\n\n const tools: DescribeToolOutput['tools'] = [];\n const notFound: string[] = [];\n\n // Get all available tools from the registry\n const allTools = this.scope.tools.getTools(true);\n const toolMap = new Map(allTools.map((t) => [t.name, t]));\n const fullNameMap = new Map(allTools.map((t) => [t.fullName, t]));\n\n for (const toolName of toolNames) {\n // Security: Don't allow describing CodeCall tools themselves\n if (isBlockedSelfReference(toolName)) {\n notFound.push(toolName);\n continue;\n }\n\n // Find the tool by name or fullName\n const tool = toolMap.get(toolName) || fullNameMap.get(toolName);\n\n if (!tool) {\n notFound.push(toolName);\n continue;\n }\n\n // Extract app ID from tool owner or metadata\n const appId = this.extractAppId(tool);\n\n // Get input schema - convert from Zod to ensure descriptions are included\n const inputSchema = this.getInputSchema(tool);\n\n // Get output schema - convert from Zod if needed\n const outputSchema = this.toJsonSchema(tool.outputSchema);\n\n // Generate usage examples: user-provided > smart generation > basic fallback\n const usageExamples = this.generateExamples(tool, inputSchema ?? undefined);\n\n tools.push({\n name: tool.name,\n appId,\n description: tool.metadata?.description || `Tool: ${tool.name}`,\n inputSchema: (inputSchema as Record<string, unknown>) || null,\n outputSchema: (outputSchema as Record<string, unknown>) || null,\n annotations: tool.metadata?.annotations,\n usageExamples,\n });\n }\n\n return {\n tools,\n notFound: notFound.length > 0 ? notFound : undefined,\n };\n }\n\n /**\n * Get the input schema for a tool, converting from Zod to JSON Schema.\n * This ensures that property descriptions from .describe() are included.\n *\n * Priority:\n * 1. Convert from tool.inputSchema (Zod) to get descriptions\n * 2. Fall back to rawInputSchema if conversion fails\n * 3. Return null if no schema available\n */\n private getInputSchema(tool: ToolEntry<any, any>): JsonSchema | null {\n // First, try to convert from the Zod inputSchema to ensure descriptions are included\n if (tool.inputSchema && typeof tool.inputSchema === 'object' && Object.keys(tool.inputSchema).length > 0) {\n try {\n // tool.inputSchema is a ZodRawShape (Record<string, ZodType>)\n const firstValue = Object.values(tool.inputSchema)[0];\n if (firstValue instanceof ZodType) {\n // Convert Zod shape to JSON Schema - this preserves .describe() annotations\n return toJSONSchema(z.object(tool.inputSchema as Record<string, ZodType>)) as JsonSchema;\n }\n } catch {\n // Fall through to rawInputSchema\n }\n }\n\n // Fall back to rawInputSchema if available\n if (tool.rawInputSchema) {\n return tool.rawInputSchema as JsonSchema;\n }\n\n return null;\n }\n\n /**\n * Convert a schema to JSON Schema format.\n * Handles Zod schemas, raw shapes, and already-JSON-Schema objects.\n *\n * Uses Zod v4's built-in z.toJSONSchema() for conversion.\n */\n private toJsonSchema(schema: unknown): JsonSchema | null {\n if (!schema) {\n return null;\n }\n\n // Check if it's a Zod schema\n if (schema instanceof ZodType) {\n try {\n // Use Zod v4's toJSONSchema conversion\n return toJSONSchema(schema);\n } catch {\n // If conversion fails, return null\n return null;\n }\n }\n\n // Check if it's a raw Zod shape (Record<string, ZodTypeAny>)\n if (typeof schema === 'object' && schema !== null && !Array.isArray(schema)) {\n const obj = schema as Record<string, unknown>;\n const firstValue = Object.values(obj)[0];\n\n // If the first value is a ZodType, treat the whole thing as a raw shape\n if (firstValue instanceof ZodType) {\n try {\n // Wrap in z.object and convert using Zod v4's toJSONSchema\n return toJSONSchema(z.object(obj as Record<string, ZodType>) as any) as JsonSchema;\n } catch {\n return null;\n }\n }\n\n // Already a JSON Schema object\n if ('type' in obj || 'properties' in obj || '$schema' in obj) {\n return schema as JsonSchema;\n }\n }\n\n // String literal output schemas (like 'text', 'json', etc.) - not a JSON Schema\n if (typeof schema === 'string') {\n return null;\n }\n\n // Array output schemas - not directly convertible\n if (Array.isArray(schema)) {\n return null;\n }\n\n return null;\n }\n\n /**\n * Extract app ID from tool metadata or owner.\n */\n private extractAppId(tool: {\n name?: string;\n metadata?: { codecall?: { appId?: string }; source?: string };\n owner?: { id?: string };\n }): string {\n // Check codecall metadata first\n if (tool.metadata?.codecall?.appId) {\n return tool.metadata.codecall.appId;\n }\n\n // Check source metadata\n if (tool.metadata?.source) {\n return tool.metadata.source;\n }\n\n // Check owner\n if (tool.owner?.id) {\n return tool.owner.id;\n }\n\n // Extract from tool name (namespace:name -> namespace)\n const nameParts = tool.name?.split(':');\n if (nameParts && nameParts.length > 1) {\n return nameParts[0];\n }\n\n return 'unknown';\n }\n\n /**\n * Generate up to 5 usage examples for a tool.\n *\n * Priority:\n * 1. User-provided examples from @Tool decorator metadata (up to 5)\n * 2. Smart intent-based generation to fill remaining slots\n * 3. Returns at least 1 example\n */\n private generateExamples(\n tool: ToolEntry<any, any>,\n inputSchema?: JsonSchema,\n ): Array<{ description: string; code: string }> {\n const result: Array<{ description: string; code: string }> = [];\n\n // Priority 1: Use user-provided examples from metadata (up to 5)\n const examples = tool.metadata?.examples;\n if (examples && Array.isArray(examples)) {\n for (const ex of examples.slice(0, 5)) {\n result.push({\n description: ex.description || 'Example usage',\n code: `const result = await callTool('${tool.name}', ${JSON.stringify(ex.input, null, 2)});\nreturn result;`,\n });\n }\n }\n\n // Priority 2: If fewer than 5 user examples, add smart-generated example\n if (result.length < 5) {\n result.push(generateSmartExample(tool.name, inputSchema, tool.metadata?.description));\n }\n\n return result.slice(0, 5);\n }\n}\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const executeToolDescription = "Execute AgentScript (safe JS subset) for multi-tool orchestration.\n\nAPI: await callTool(name, args, opts?)\n- Default: throws on error\n- Safe mode: { throwOnError: false } \u2192 returns { success, data?, error? }\n\nEXAMPLE:\nconst users = await callTool('users:list', { active: true });\nconst results = [];\nfor (const u of users.items) {\n const orders = await callTool('orders:list', { userId: u.id });\n results.push({ id: u.id, total: orders.items.reduce((s,o) => s + o.amount, 0) });\n}\nreturn results;\n\nALLOWED: for, for-of, arrow fn, map/filter/reduce/find, Math.*, JSON.*, if/else, destructuring, spread, template literals\nBLOCKED: while, do-while, function decl, eval, require, fetch, setTimeout, process, globalThis\n\nERRORS: NOT_FOUND | VALIDATION | EXECUTION | TIMEOUT | ACCESS_DENIED\nSTATUS: ok | syntax_error | illegal_access | runtime_error | tool_error | timeout\nLIMITS: 10K iter/loop, 30s timeout, 100 calls max";
|
|
3
|
+
export declare const executeToolInputSchema: z.ZodObject<{
|
|
4
|
+
script: z.ZodString;
|
|
5
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type ExecuteToolInput = z.infer<typeof executeToolInputSchema>;
|
|
8
|
+
/**
|
|
9
|
+
* Result variants
|
|
10
|
+
*/
|
|
11
|
+
export declare const codeCallOkResultSchema: z.ZodObject<{
|
|
12
|
+
status: z.ZodLiteral<"ok">;
|
|
13
|
+
result: z.ZodUnknown;
|
|
14
|
+
logs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const codeCallSyntaxErrorResultSchema: z.ZodObject<{
|
|
17
|
+
status: z.ZodLiteral<"syntax_error">;
|
|
18
|
+
error: z.ZodObject<{
|
|
19
|
+
message: z.ZodString;
|
|
20
|
+
location: z.ZodOptional<z.ZodObject<{
|
|
21
|
+
line: z.ZodNumber;
|
|
22
|
+
column: z.ZodNumber;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export declare const codeCallIllegalAccessResultSchema: z.ZodObject<{
|
|
27
|
+
status: z.ZodLiteral<"illegal_access">;
|
|
28
|
+
error: z.ZodObject<{
|
|
29
|
+
message: z.ZodString;
|
|
30
|
+
kind: z.ZodUnion<readonly [z.ZodLiteral<"IllegalBuiltinAccess">, z.ZodLiteral<"DisallowedGlobal">, z.ZodString]>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const codeCallRuntimeErrorResultSchema: z.ZodObject<{
|
|
34
|
+
status: z.ZodLiteral<"runtime_error">;
|
|
35
|
+
error: z.ZodObject<{
|
|
36
|
+
source: z.ZodLiteral<"script">;
|
|
37
|
+
message: z.ZodString;
|
|
38
|
+
name: z.ZodOptional<z.ZodString>;
|
|
39
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export declare const codeCallToolErrorResultSchema: z.ZodObject<{
|
|
43
|
+
status: z.ZodLiteral<"tool_error">;
|
|
44
|
+
error: z.ZodObject<{
|
|
45
|
+
source: z.ZodLiteral<"tool">;
|
|
46
|
+
toolName: z.ZodString;
|
|
47
|
+
toolInput: z.ZodUnknown;
|
|
48
|
+
message: z.ZodString;
|
|
49
|
+
code: z.ZodOptional<z.ZodString>;
|
|
50
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
export declare const codeCallTimeoutResultSchema: z.ZodObject<{
|
|
54
|
+
status: z.ZodLiteral<"timeout">;
|
|
55
|
+
error: z.ZodObject<{
|
|
56
|
+
message: z.ZodString;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
/**
|
|
60
|
+
* Discriminated union for the whole result
|
|
61
|
+
*/
|
|
62
|
+
export declare const executeToolOutputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
63
|
+
status: z.ZodLiteral<"ok">;
|
|
64
|
+
result: z.ZodUnknown;
|
|
65
|
+
logs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
66
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
67
|
+
status: z.ZodLiteral<"syntax_error">;
|
|
68
|
+
error: z.ZodObject<{
|
|
69
|
+
message: z.ZodString;
|
|
70
|
+
location: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
line: z.ZodNumber;
|
|
72
|
+
column: z.ZodNumber;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
76
|
+
status: z.ZodLiteral<"illegal_access">;
|
|
77
|
+
error: z.ZodObject<{
|
|
78
|
+
message: z.ZodString;
|
|
79
|
+
kind: z.ZodUnion<readonly [z.ZodLiteral<"IllegalBuiltinAccess">, z.ZodLiteral<"DisallowedGlobal">, z.ZodString]>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
82
|
+
status: z.ZodLiteral<"runtime_error">;
|
|
83
|
+
error: z.ZodObject<{
|
|
84
|
+
source: z.ZodLiteral<"script">;
|
|
85
|
+
message: z.ZodString;
|
|
86
|
+
name: z.ZodOptional<z.ZodString>;
|
|
87
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
88
|
+
}, z.core.$strip>;
|
|
89
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
90
|
+
status: z.ZodLiteral<"tool_error">;
|
|
91
|
+
error: z.ZodObject<{
|
|
92
|
+
source: z.ZodLiteral<"tool">;
|
|
93
|
+
toolName: z.ZodString;
|
|
94
|
+
toolInput: z.ZodUnknown;
|
|
95
|
+
message: z.ZodString;
|
|
96
|
+
code: z.ZodOptional<z.ZodString>;
|
|
97
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
100
|
+
status: z.ZodLiteral<"timeout">;
|
|
101
|
+
error: z.ZodObject<{
|
|
102
|
+
message: z.ZodString;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
}, z.core.$strip>], "status">;
|
|
105
|
+
/**
|
|
106
|
+
* Inferred types
|
|
107
|
+
* (you can export whichever ones you actually need)
|
|
108
|
+
*/
|
|
109
|
+
export type CodeCallOkResult = z.infer<typeof codeCallOkResultSchema>;
|
|
110
|
+
export type CodeCallSyntaxErrorResult = z.infer<typeof codeCallSyntaxErrorResultSchema>;
|
|
111
|
+
export type CodeCallIllegalAccessResult = z.infer<typeof codeCallIllegalAccessResultSchema>;
|
|
112
|
+
export type CodeCallRuntimeErrorResult = z.infer<typeof codeCallRuntimeErrorResultSchema>;
|
|
113
|
+
export type CodeCallToolErrorResult = z.infer<typeof codeCallToolErrorResultSchema>;
|
|
114
|
+
export type CodeCallTimeoutResult = z.infer<typeof codeCallTimeoutResultSchema>;
|
|
115
|
+
export type CodeCallExecuteResult = CodeCallOkResult | CodeCallSyntaxErrorResult | CodeCallIllegalAccessResult | CodeCallRuntimeErrorResult | CodeCallToolErrorResult | CodeCallTimeoutResult;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeToolOutputSchema = exports.codeCallTimeoutResultSchema = exports.codeCallToolErrorResultSchema = exports.codeCallRuntimeErrorResultSchema = exports.codeCallIllegalAccessResultSchema = exports.codeCallSyntaxErrorResultSchema = exports.codeCallOkResultSchema = exports.executeToolInputSchema = exports.executeToolDescription = void 0;
|
|
4
|
+
// file: libs/plugins/src/codecall/tools/execute.schema.ts
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
/** Minimum script length - at least a simple callTool invocation */
|
|
7
|
+
const MIN_EXECUTE_SCRIPT_LENGTH = 'return callTool("a",{})'.length;
|
|
8
|
+
exports.executeToolDescription = `Execute AgentScript (safe JS subset) for multi-tool orchestration.
|
|
9
|
+
|
|
10
|
+
API: await callTool(name, args, opts?)
|
|
11
|
+
- Default: throws on error
|
|
12
|
+
- Safe mode: { throwOnError: false } → returns { success, data?, error? }
|
|
13
|
+
|
|
14
|
+
EXAMPLE:
|
|
15
|
+
const users = await callTool('users:list', { active: true });
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const u of users.items) {
|
|
18
|
+
const orders = await callTool('orders:list', { userId: u.id });
|
|
19
|
+
results.push({ id: u.id, total: orders.items.reduce((s,o) => s + o.amount, 0) });
|
|
20
|
+
}
|
|
21
|
+
return results;
|
|
22
|
+
|
|
23
|
+
ALLOWED: for, for-of, arrow fn, map/filter/reduce/find, Math.*, JSON.*, if/else, destructuring, spread, template literals
|
|
24
|
+
BLOCKED: while, do-while, function decl, eval, require, fetch, setTimeout, process, globalThis
|
|
25
|
+
|
|
26
|
+
ERRORS: NOT_FOUND | VALIDATION | EXECUTION | TIMEOUT | ACCESS_DENIED
|
|
27
|
+
STATUS: ok | syntax_error | illegal_access | runtime_error | tool_error | timeout
|
|
28
|
+
LIMITS: 10K iter/loop, 30s timeout, 100 calls max`;
|
|
29
|
+
exports.executeToolInputSchema = zod_1.z.object({
|
|
30
|
+
script: zod_1.z
|
|
31
|
+
.string()
|
|
32
|
+
.min(MIN_EXECUTE_SCRIPT_LENGTH)
|
|
33
|
+
.max(100 * 1024) // 100 KB
|
|
34
|
+
.describe('JavaScript code to execute in the sandbox. Must return a value (implicitly or via explicit return). Use callTool(name, input) to invoke tools.'),
|
|
35
|
+
allowedTools: zod_1.z
|
|
36
|
+
.array(zod_1.z.string())
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Optional whitelist of tool names that can be called from this script. If not provided, all indexed tools are available. Example: ["users:list", "billing:getInvoice"]'),
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Shared "payload" schemas
|
|
42
|
+
*/
|
|
43
|
+
const syntaxErrorPayloadSchema = zod_1.z.object({
|
|
44
|
+
message: zod_1.z.string(),
|
|
45
|
+
location: zod_1.z
|
|
46
|
+
.object({
|
|
47
|
+
line: zod_1.z.number(),
|
|
48
|
+
column: zod_1.z.number(),
|
|
49
|
+
})
|
|
50
|
+
.optional(),
|
|
51
|
+
});
|
|
52
|
+
const illegalAccessErrorPayloadSchema = zod_1.z.object({
|
|
53
|
+
message: zod_1.z.string(),
|
|
54
|
+
kind: zod_1.z.union([
|
|
55
|
+
zod_1.z.literal('IllegalBuiltinAccess'),
|
|
56
|
+
zod_1.z.literal('DisallowedGlobal'),
|
|
57
|
+
zod_1.z.string(), // same as your original type: 'A' | 'B' | string
|
|
58
|
+
]),
|
|
59
|
+
});
|
|
60
|
+
const runtimeErrorPayloadSchema = zod_1.z.object({
|
|
61
|
+
source: zod_1.z.literal('script'),
|
|
62
|
+
message: zod_1.z.string(),
|
|
63
|
+
name: zod_1.z.string().optional(),
|
|
64
|
+
stack: zod_1.z.string().optional(),
|
|
65
|
+
});
|
|
66
|
+
const toolErrorPayloadSchema = zod_1.z.object({
|
|
67
|
+
source: zod_1.z.literal('tool'),
|
|
68
|
+
toolName: zod_1.z.string(),
|
|
69
|
+
toolInput: zod_1.z.unknown(),
|
|
70
|
+
message: zod_1.z.string(),
|
|
71
|
+
code: zod_1.z.string().optional(),
|
|
72
|
+
details: zod_1.z.unknown().optional(),
|
|
73
|
+
});
|
|
74
|
+
const timeoutErrorPayloadSchema = zod_1.z.object({
|
|
75
|
+
message: zod_1.z.string(),
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Result variants
|
|
79
|
+
*/
|
|
80
|
+
exports.codeCallOkResultSchema = zod_1.z.object({
|
|
81
|
+
status: zod_1.z.literal('ok'),
|
|
82
|
+
result: zod_1.z.unknown(),
|
|
83
|
+
logs: zod_1.z.array(zod_1.z.string()).optional(),
|
|
84
|
+
});
|
|
85
|
+
exports.codeCallSyntaxErrorResultSchema = zod_1.z.object({
|
|
86
|
+
status: zod_1.z.literal('syntax_error'),
|
|
87
|
+
error: syntaxErrorPayloadSchema,
|
|
88
|
+
});
|
|
89
|
+
exports.codeCallIllegalAccessResultSchema = zod_1.z.object({
|
|
90
|
+
status: zod_1.z.literal('illegal_access'),
|
|
91
|
+
error: illegalAccessErrorPayloadSchema,
|
|
92
|
+
});
|
|
93
|
+
exports.codeCallRuntimeErrorResultSchema = zod_1.z.object({
|
|
94
|
+
status: zod_1.z.literal('runtime_error'),
|
|
95
|
+
error: runtimeErrorPayloadSchema,
|
|
96
|
+
});
|
|
97
|
+
exports.codeCallToolErrorResultSchema = zod_1.z.object({
|
|
98
|
+
status: zod_1.z.literal('tool_error'),
|
|
99
|
+
error: toolErrorPayloadSchema,
|
|
100
|
+
});
|
|
101
|
+
exports.codeCallTimeoutResultSchema = zod_1.z.object({
|
|
102
|
+
status: zod_1.z.literal('timeout'),
|
|
103
|
+
error: timeoutErrorPayloadSchema,
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* Discriminated union for the whole result
|
|
107
|
+
*/
|
|
108
|
+
exports.executeToolOutputSchema = zod_1.z.discriminatedUnion('status', [
|
|
109
|
+
exports.codeCallOkResultSchema,
|
|
110
|
+
exports.codeCallSyntaxErrorResultSchema,
|
|
111
|
+
exports.codeCallIllegalAccessResultSchema,
|
|
112
|
+
exports.codeCallRuntimeErrorResultSchema,
|
|
113
|
+
exports.codeCallToolErrorResultSchema,
|
|
114
|
+
exports.codeCallTimeoutResultSchema,
|
|
115
|
+
]);
|
|
116
|
+
//# sourceMappingURL=execute.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.schema.js","sourceRoot":"","sources":["../../../../src/codecall/tools/execute.schema.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAC1D,6BAAwB;AAExB,oEAAoE;AACpE,MAAM,yBAAyB,GAAG,yBAAyB,CAAC,MAAM,CAAC;AAEtD,QAAA,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;kDAoBY,CAAC;AAEtC,QAAA,sBAAsB,GAAG,OAAC,CAAC,M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AAC,OAAO,CAAC,YAAY,CAAC;IAC/B,KAAK,EAAE,sBAAsB;CAC9B,CAAC,CAAC;AAEU,QAAA,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAClD,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC5B,KAAK,EAAE,yBAAyB;CACjC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,uBAAuB,GAAG,OAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE;IACpE,8BAAsB;IACtB,uCAA+B;IAC/B,yCAAiC;IACjC,wCAAgC;IAChC,qCAA6B;IAC7B,mCAA2B;CAC5B,CAAC,CAAC","sourcesContent":["// file: libs/plugins/src/codecall/tools/execute.schema.ts\nimport { z } from 'zod';\n\n/** Minimum script length - at least a simple callTool invocation */\nconst MIN_EXECUTE_SCRIPT_LENGTH = 'return callTool(\"a\",{})'.length;\n\nexport const executeToolDescription = `Execute AgentScript (safe JS subset) for multi-tool orchestration.\n\nAPI: await callTool(name, args, opts?)\n- Default: throws on error\n- Safe mode: { throwOnError: false } → returns { success, data?, error? }\n\nEXAMPLE:\nconst users = await callTool('users:list', { active: true });\nconst results = [];\nfor (const u of users.items) {\n const orders = await callTool('orders:list', { userId: u.id });\n results.push({ id: u.id, total: orders.items.reduce((s,o) => s + o.amount, 0) });\n}\nreturn results;\n\nALLOWED: for, for-of, arrow fn, map/filter/reduce/find, Math.*, JSON.*, if/else, destructuring, spread, template literals\nBLOCKED: while, do-while, function decl, eval, require, fetch, setTimeout, process, globalThis\n\nERRORS: NOT_FOUND | VALIDATION | EXECUTION | TIMEOUT | ACCESS_DENIED\nSTATUS: ok | syntax_error | illegal_access | runtime_error | tool_error | timeout\nLIMITS: 10K iter/loop, 30s timeout, 100 calls max`;\n\nexport const executeToolInputSchema = z.object({\n script: z\n .string()\n .min(MIN_EXECUTE_SCRIPT_LENGTH)\n .max(100 * 1024) // 100 KB\n .describe(\n 'JavaScript code to execute in the sandbox. Must return a value (implicitly or via explicit return). Use callTool(name, input) to invoke tools.',\n ),\n allowedTools: z\n .array(z.string())\n .optional()\n .describe(\n 'Optional whitelist of tool names that can be called from this script. If not provided, all indexed tools are available. Example: [\"users:list\", \"billing:getInvoice\"]',\n ),\n});\n\nexport type ExecuteToolInput = z.infer<typeof executeToolInputSchema>;\n\n/**\n * Shared \"payload\" schemas\n */\nconst syntaxErrorPayloadSchema = z.object({\n message: z.string(),\n location: z\n .object({\n line: z.number(),\n column: z.number(),\n })\n .optional(),\n});\n\nconst illegalAccessErrorPayloadSchema = z.object({\n message: z.string(),\n kind: z.union([\n z.literal('IllegalBuiltinAccess'),\n z.literal('DisallowedGlobal'),\n z.string(), // same as your original type: 'A' | 'B' | string\n ]),\n});\n\nconst runtimeErrorPayloadSchema = z.object({\n source: z.literal('script'),\n message: z.string(),\n name: z.string().optional(),\n stack: z.string().optional(),\n});\n\nconst toolErrorPayloadSchema = z.object({\n source: z.literal('tool'),\n toolName: z.string(),\n toolInput: z.unknown(),\n message: z.string(),\n code: z.string().optional(),\n details: z.unknown().optional(),\n});\n\nconst timeoutErrorPayloadSchema = z.object({\n message: z.string(),\n});\n\n/**\n * Result variants\n */\nexport const codeCallOkResultSchema = z.object({\n status: z.literal('ok'),\n result: z.unknown(),\n logs: z.array(z.string()).optional(),\n});\n\nexport const codeCallSyntaxErrorResultSchema = z.object({\n status: z.literal('syntax_error'),\n error: syntaxErrorPayloadSchema,\n});\n\nexport const codeCallIllegalAccessResultSchema = z.object({\n status: z.literal('illegal_access'),\n error: illegalAccessErrorPayloadSchema,\n});\n\nexport const codeCallRuntimeErrorResultSchema = z.object({\n status: z.literal('runtime_error'),\n error: runtimeErrorPayloadSchema,\n});\n\nexport const codeCallToolErrorResultSchema = z.object({\n status: z.literal('tool_error'),\n error: toolErrorPayloadSchema,\n});\n\nexport const codeCallTimeoutResultSchema = z.object({\n status: z.literal('timeout'),\n error: timeoutErrorPayloadSchema,\n});\n\n/**\n * Discriminated union for the whole result\n */\nexport const executeToolOutputSchema = z.discriminatedUnion('status', [\n codeCallOkResultSchema,\n codeCallSyntaxErrorResultSchema,\n codeCallIllegalAccessResultSchema,\n codeCallRuntimeErrorResultSchema,\n codeCallToolErrorResultSchema,\n codeCallTimeoutResultSchema,\n]);\n\n/**\n * Inferred types\n * (you can export whichever ones you actually need)\n */\nexport type CodeCallOkResult = z.infer<typeof codeCallOkResultSchema>;\nexport type CodeCallSyntaxErrorResult = z.infer<typeof codeCallSyntaxErrorResultSchema>;\nexport type CodeCallIllegalAccessResult = z.infer<typeof codeCallIllegalAccessResultSchema>;\nexport type CodeCallRuntimeErrorResult = z.infer<typeof codeCallRuntimeErrorResultSchema>;\nexport type CodeCallToolErrorResult = z.infer<typeof codeCallToolErrorResultSchema>;\nexport type CodeCallTimeoutResult = z.infer<typeof codeCallTimeoutResultSchema>;\n\nexport type CodeCallExecuteResult =\n | CodeCallOkResult\n | CodeCallSyntaxErrorResult\n | CodeCallIllegalAccessResult\n | CodeCallRuntimeErrorResult\n | CodeCallToolErrorResult\n | CodeCallTimeoutResult;\n"]}
|