@botbotgo/kit 1.0.106
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/README.md +65 -0
- package/config/build/build.sh +182 -0
- package/config/build/tsconfig.dts.json +34 -0
- package/config/build/tsup.config.ts +19 -0
- package/config/build/vitest.config.ts +29 -0
- package/config/tool.yaml +11 -0
- package/dist/agent-context.d.ts +3 -0
- package/dist/agent-context.d.ts.map +1 -0
- package/dist/api/adapters/LangChainToolsHub.d.ts +35 -0
- package/dist/api/adapters/LangChainToolsHub.d.ts.map +1 -0
- package/dist/api/createAgentTools.d.ts +52 -0
- package/dist/api/createAgentTools.d.ts.map +1 -0
- package/dist/api/expose/extension-init/index.d.ts +3 -0
- package/dist/api/expose/extension-init/index.d.ts.map +1 -0
- package/dist/api/expose/extension-init/initExtension.d.ts +21 -0
- package/dist/api/expose/extension-init/initExtension.d.ts.map +1 -0
- package/dist/api/expose/index.d.ts +16 -0
- package/dist/api/expose/index.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/build.d.ts +21 -0
- package/dist/api/expose/mcp-build/build.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/generator.d.ts +15 -0
- package/dist/api/expose/mcp-build/generator.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/index.d.ts +8 -0
- package/dist/api/expose/mcp-build/index.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/init.d.ts +17 -0
- package/dist/api/expose/mcp-build/init.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/run.d.ts +17 -0
- package/dist/api/expose/mcp-build/run.d.ts.map +1 -0
- package/dist/api/expose/mcp-build/types.d.ts +25 -0
- package/dist/api/expose/mcp-build/types.d.ts.map +1 -0
- package/dist/api/expose/mcpServer.d.ts +74 -0
- package/dist/api/expose/mcpServer.d.ts.map +1 -0
- package/dist/api/expose/openapi.d.ts +23 -0
- package/dist/api/expose/openapi.d.ts.map +1 -0
- package/dist/api/expose/openapiHttp.d.ts +51 -0
- package/dist/api/expose/openapiHttp.d.ts.map +1 -0
- package/dist/api/extension/contextRunner.d.ts +10 -0
- package/dist/api/extension/contextRunner.d.ts.map +1 -0
- package/dist/api/extension/createExtension.d.ts +38 -0
- package/dist/api/extension/createExtension.d.ts.map +1 -0
- package/dist/api/extension/dynamicImportAdapter.d.ts +25 -0
- package/dist/api/extension/dynamicImportAdapter.d.ts.map +1 -0
- package/dist/api/extension/generateExtensionManifest.d.ts +29 -0
- package/dist/api/extension/generateExtensionManifest.d.ts.map +1 -0
- package/dist/api/extension/index.d.ts +23 -0
- package/dist/api/extension/index.d.ts.map +1 -0
- package/dist/api/extension/loadToolYaml.d.ts +7 -0
- package/dist/api/extension/loadToolYaml.d.ts.map +1 -0
- package/dist/api/extension/overrideWithConfig.d.ts +2 -0
- package/dist/api/extension/overrideWithConfig.d.ts.map +1 -0
- package/dist/api/extension/registerExtension.d.ts +32 -0
- package/dist/api/extension/registerExtension.d.ts.map +1 -0
- package/dist/api/extension/registerFromManifest.d.ts +43 -0
- package/dist/api/extension/registerFromManifest.d.ts.map +1 -0
- package/dist/api/extension/resolvePackageRoot.d.ts +2 -0
- package/dist/api/extension/resolvePackageRoot.d.ts.map +1 -0
- package/dist/api/extension/support/groupPrefix.d.ts +21 -0
- package/dist/api/extension/support/groupPrefix.d.ts.map +1 -0
- package/dist/api/extension/support/types.d.ts +15 -0
- package/dist/api/extension/support/types.d.ts.map +1 -0
- package/dist/api/register-tools.d.ts +17 -0
- package/dist/api/register-tools.d.ts.map +1 -0
- package/dist/api/resolveAgentSkillRoots.d.ts +7 -0
- package/dist/api/resolveAgentSkillRoots.d.ts.map +1 -0
- package/dist/api/runtimeFromConfig.d.ts +20 -0
- package/dist/api/runtimeFromConfig.d.ts.map +1 -0
- package/dist/api/runtimeFromConfig.helpers.d.ts +12 -0
- package/dist/api/runtimeFromConfig.helpers.d.ts.map +1 -0
- package/dist/api/runtimeFromConfig.types.d.ts +37 -0
- package/dist/api/runtimeFromConfig.types.d.ts.map +1 -0
- package/dist/build.cjs +30 -0
- package/dist/build.cjs.map +1 -0
- package/dist/build.d.ts +13 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +5 -0
- package/dist/build.js.map +1 -0
- package/dist/canonicalCoreSchemas-PHGTNPN5.js +3 -0
- package/dist/canonicalCoreSchemas-PHGTNPN5.js.map +1 -0
- package/dist/canonicalCoreSchemas-TY7NCWCC.cjs +16 -0
- package/dist/canonicalCoreSchemas-TY7NCWCC.cjs.map +1 -0
- package/dist/chunk-4OOTCNR7.js +324 -0
- package/dist/chunk-4OOTCNR7.js.map +1 -0
- package/dist/chunk-4VKCWJHF.cjs +3043 -0
- package/dist/chunk-4VKCWJHF.cjs.map +1 -0
- package/dist/chunk-AGLGFQUW.cjs +259 -0
- package/dist/chunk-AGLGFQUW.cjs.map +1 -0
- package/dist/chunk-AZUXVVGV.cjs +1073 -0
- package/dist/chunk-AZUXVVGV.cjs.map +1 -0
- package/dist/chunk-BDUSB6GT.js +520 -0
- package/dist/chunk-BDUSB6GT.js.map +1 -0
- package/dist/chunk-BNIE2IKZ.cjs +100 -0
- package/dist/chunk-BNIE2IKZ.cjs.map +1 -0
- package/dist/chunk-BTHDNP3C.cjs +350 -0
- package/dist/chunk-BTHDNP3C.cjs.map +1 -0
- package/dist/chunk-GGFAGLDC.js +1049 -0
- package/dist/chunk-GGFAGLDC.js.map +1 -0
- package/dist/chunk-ITX6A2BT.js +92 -0
- package/dist/chunk-ITX6A2BT.js.map +1 -0
- package/dist/chunk-IVL4TBFB.js +248 -0
- package/dist/chunk-IVL4TBFB.js.map +1 -0
- package/dist/chunk-JH4ZF3FN.js +3013 -0
- package/dist/chunk-JH4ZF3FN.js.map +1 -0
- package/dist/chunk-JW4EMVTE.cjs +553 -0
- package/dist/chunk-JW4EMVTE.cjs.map +1 -0
- package/dist/chunk-NTWOVFEY.js +16 -0
- package/dist/chunk-NTWOVFEY.js.map +1 -0
- package/dist/chunk-UUNG3GL3.cjs +19 -0
- package/dist/chunk-UUNG3GL3.cjs.map +1 -0
- package/dist/core/registry/ToolRegistry.d.ts +68 -0
- package/dist/core/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/core/runtime/Budget.d.ts +63 -0
- package/dist/core/runtime/Budget.d.ts.map +1 -0
- package/dist/core/runtime/Evidence.d.ts +19 -0
- package/dist/core/runtime/Evidence.d.ts.map +1 -0
- package/dist/core/runtime/PTCRuntime.d.ts +124 -0
- package/dist/core/runtime/PTCRuntime.d.ts.map +1 -0
- package/dist/core/runtime/PTCRuntimeObservability.d.ts +26 -0
- package/dist/core/runtime/PTCRuntimeObservability.d.ts.map +1 -0
- package/dist/core/runtime/PTCRuntimePipeline.d.ts +69 -0
- package/dist/core/runtime/PTCRuntimePipeline.d.ts.map +1 -0
- package/dist/core/runtime/PolicyEngine.d.ts +67 -0
- package/dist/core/runtime/PolicyEngine.d.ts.map +1 -0
- package/dist/core/runtime/Retry.d.ts +33 -0
- package/dist/core/runtime/Retry.d.ts.map +1 -0
- package/dist/core/runtime/SchemaValidator.d.ts +42 -0
- package/dist/core/runtime/SchemaValidator.d.ts.map +1 -0
- package/dist/core/runtime/toolObservation.d.ts +7 -0
- package/dist/core/runtime/toolObservation.d.ts.map +1 -0
- package/dist/core/types/Events.d.ts +99 -0
- package/dist/core/types/Events.d.ts.map +1 -0
- package/dist/core/types/ToolIntent.d.ts +40 -0
- package/dist/core/types/ToolIntent.d.ts.map +1 -0
- package/dist/core/types/ToolResult.d.ts +44 -0
- package/dist/core/types/ToolResult.d.ts.map +1 -0
- package/dist/core/types/ToolSpec.d.ts +116 -0
- package/dist/core/types/ToolSpec.d.ts.map +1 -0
- package/dist/core/types/ToolTypeHandler.d.ts +88 -0
- package/dist/core/types/ToolTypeHandler.d.ts.map +1 -0
- package/dist/core/types/index.d.ts +7 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/index.cjs +399 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +394 -0
- package/dist/index.js.map +1 -0
- package/dist/observability/EventLog.d.ts +60 -0
- package/dist/observability/EventLog.d.ts.map +1 -0
- package/dist/observability/Logger.d.ts +33 -0
- package/dist/observability/Logger.d.ts.map +1 -0
- package/dist/observability/Metrics.d.ts +70 -0
- package/dist/observability/Metrics.d.ts.map +1 -0
- package/dist/observability/Tracing.d.ts +69 -0
- package/dist/observability/Tracing.d.ts.map +1 -0
- package/dist/sdk.cjs +493 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.ts +17 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +443 -0
- package/dist/sdk.js.map +1 -0
- package/dist/security/sandbox.d.ts +10 -0
- package/dist/security/sandbox.d.ts.map +1 -0
- package/dist/security/ssrf.d.ts +24 -0
- package/dist/security/ssrf.d.ts.map +1 -0
- package/dist/templates/mcp-server.js +48 -0
- package/dist/templates/n8n-invoker.js +11 -0
- package/dist/templates/skill-invoker.js +11 -0
- package/dist/templates/tool-index.js +9 -0
- package/dist/tools/discoveryFactory.d.ts +117 -0
- package/dist/tools/discoveryFactory.d.ts.map +1 -0
- package/dist/tools/function/index.d.ts +10 -0
- package/dist/tools/function/index.d.ts.map +1 -0
- package/dist/tools/function/scanner.d.ts +29 -0
- package/dist/tools/function/scanner.d.ts.map +1 -0
- package/dist/tools/function/schemaFromTs.d.ts +16 -0
- package/dist/tools/function/schemaFromTs.d.ts.map +1 -0
- package/dist/tools/function/types.d.ts +20 -0
- package/dist/tools/function/types.d.ts.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/langchain/LangChainLoader.d.ts +7 -0
- package/dist/tools/langchain/LangChainLoader.d.ts.map +1 -0
- package/dist/tools/langchain/directoryApply.d.ts +5 -0
- package/dist/tools/langchain/directoryApply.d.ts.map +1 -0
- package/dist/tools/langchain/directoryLoad.d.ts +13 -0
- package/dist/tools/langchain/directoryLoad.d.ts.map +1 -0
- package/dist/tools/langchain/index.d.ts +3 -0
- package/dist/tools/langchain/index.d.ts.map +1 -0
- package/dist/tools/langchain/scanner.d.ts +8 -0
- package/dist/tools/langchain/scanner.d.ts.map +1 -0
- package/dist/tools/langchain/types.d.ts +5 -0
- package/dist/tools/langchain/types.d.ts.map +1 -0
- package/dist/tools/mcp/MCPClientAdapter.d.ts +34 -0
- package/dist/tools/mcp/MCPClientAdapter.d.ts.map +1 -0
- package/dist/tools/mcp/MCPLoader.d.ts +8 -0
- package/dist/tools/mcp/MCPLoader.d.ts.map +1 -0
- package/dist/tools/mcp/MCPProcessManager.d.ts +29 -0
- package/dist/tools/mcp/MCPProcessManager.d.ts.map +1 -0
- package/dist/tools/mcp/connectMCP.d.ts +47 -0
- package/dist/tools/mcp/connectMCP.d.ts.map +1 -0
- package/dist/tools/mcp/directoryApply.d.ts +10 -0
- package/dist/tools/mcp/directoryApply.d.ts.map +1 -0
- package/dist/tools/mcp/index.d.ts +16 -0
- package/dist/tools/mcp/index.d.ts.map +1 -0
- package/dist/tools/mcp/mcpSpecToToolSpec.d.ts +8 -0
- package/dist/tools/mcp/mcpSpecToToolSpec.d.ts.map +1 -0
- package/dist/tools/mcp/registerMCPTools.d.ts +24 -0
- package/dist/tools/mcp/registerMCPTools.d.ts.map +1 -0
- package/dist/tools/mcp/scanner.d.ts +8 -0
- package/dist/tools/mcp/scanner.d.ts.map +1 -0
- package/dist/tools/mcp/support/types.d.ts +3 -0
- package/dist/tools/mcp/support/types.d.ts.map +1 -0
- package/dist/tools/n8n/N8nLoader.d.ts +25 -0
- package/dist/tools/n8n/N8nLoader.d.ts.map +1 -0
- package/dist/tools/n8n/directoryApply.d.ts +10 -0
- package/dist/tools/n8n/directoryApply.d.ts.map +1 -0
- package/dist/tools/n8n/index.d.ts +6 -0
- package/dist/tools/n8n/index.d.ts.map +1 -0
- package/dist/tools/n8n/scanN8n.d.ts +20 -0
- package/dist/tools/n8n/scanN8n.d.ts.map +1 -0
- package/dist/tools/n8n/types.d.ts +18 -0
- package/dist/tools/n8n/types.d.ts.map +1 -0
- package/dist/tools/scanPackage.d.ts +42 -0
- package/dist/tools/scanPackage.d.ts.map +1 -0
- package/dist/tools/skill/SkillLoader.d.ts +20 -0
- package/dist/tools/skill/SkillLoader.d.ts.map +1 -0
- package/dist/tools/skill/SkillManifest.d.ts +79 -0
- package/dist/tools/skill/SkillManifest.d.ts.map +1 -0
- package/dist/tools/skill/SkillMdParser.d.ts +31 -0
- package/dist/tools/skill/SkillMdParser.d.ts.map +1 -0
- package/dist/tools/skill/directoryApply.d.ts +10 -0
- package/dist/tools/skill/directoryApply.d.ts.map +1 -0
- package/dist/tools/skill/index.d.ts +8 -0
- package/dist/tools/skill/index.d.ts.map +1 -0
- package/dist/tools/skill/scanSkill.d.ts +20 -0
- package/dist/tools/skill/scanSkill.d.ts.map +1 -0
- package/dist/tools/skill/types.d.ts +19 -0
- package/dist/tools/skill/types.d.ts.map +1 -0
- package/dist/tools/util/canonicalCoreSchemas.d.ts +15 -0
- package/dist/tools/util/canonicalCoreSchemas.d.ts.map +1 -0
- package/dist/tools/util/index.d.ts +13 -0
- package/dist/tools/util/index.d.ts.map +1 -0
- package/dist/tools/util/resolveEntry.d.ts +6 -0
- package/dist/tools/util/resolveEntry.d.ts.map +1 -0
- package/dist/tools/util/scanUtil.d.ts +9 -0
- package/dist/tools/util/scanUtil.d.ts.map +1 -0
- package/dist/tools/util/toolConfig.d.ts +38 -0
- package/dist/tools/util/toolConfig.d.ts.map +1 -0
- package/dist/tools/util/toolDescriptor.d.ts +117 -0
- package/dist/tools/util/toolDescriptor.d.ts.map +1 -0
- package/dist/utils/cli/help.d.ts +2 -0
- package/dist/utils/cli/help.d.ts.map +1 -0
- package/dist/utils/cli/index.cjs +700 -0
- package/dist/utils/cli/index.cjs.map +1 -0
- package/dist/utils/cli/index.d.ts +9 -0
- package/dist/utils/cli/index.d.ts.map +1 -0
- package/dist/utils/cli/index.js +677 -0
- package/dist/utils/cli/index.js.map +1 -0
- package/dist/utils/cli/toolRuntime.d.ts +19 -0
- package/dist/utils/cli/toolRuntime.d.ts.map +1 -0
- package/dist/utils/log.d.ts +2 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/npmCache.d.ts +11 -0
- package/dist/utils/npmCache.d.ts.map +1 -0
- package/dist/utils/npmVersion.d.ts +10 -0
- package/dist/utils/npmVersion.d.ts.map +1 -0
- package/dist/utils/overrideWithConfig.d.ts +2 -0
- package/dist/utils/overrideWithConfig.d.ts.map +1 -0
- package/package.json +125 -0
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { initProject, buildMCPPackage, runMCPServer } from '../../chunk-4OOTCNR7.js';
|
|
3
|
+
import { findAndLoadToolConfig, getToolSourceDescriptors, resolveToolDescriptor, runMCPServerOverStdio, createMCPServerStreamableHttp, createHttpService, resolveSandboxedPath, createRuntimeFromConfig, getDisplayScope } from '../../chunk-JH4ZF3FN.js';
|
|
4
|
+
import '../../chunk-GGFAGLDC.js';
|
|
5
|
+
import '../../chunk-IVL4TBFB.js';
|
|
6
|
+
import '../../chunk-BDUSB6GT.js';
|
|
7
|
+
import { enrichSpecWithCanonicalSchema } from '../../chunk-NTWOVFEY.js';
|
|
8
|
+
import * as path2 from 'path';
|
|
9
|
+
import path2__default from 'path';
|
|
10
|
+
import { realpathSync } from 'fs';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
import * as fs from 'fs/promises';
|
|
13
|
+
|
|
14
|
+
function toPackageName(name) {
|
|
15
|
+
return name.trim().toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
|
16
|
+
}
|
|
17
|
+
function packageJsonTemplate(packageName) {
|
|
18
|
+
return `{
|
|
19
|
+
"name": "${packageName}",
|
|
20
|
+
"version": "0.0.1",
|
|
21
|
+
"description": "Tools extension for @botbotgo/kit",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": ["dist"],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsx generate-manifest.ts && tsc -p tsconfig.build.json",
|
|
36
|
+
"clean": "rm -rf dist",
|
|
37
|
+
"pretest": "npm run build",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@botbotgo/kit": "latest"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@botbotgo/kit": "*"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"tsx": "^4.19.2",
|
|
48
|
+
"typescript": "~5.7.2",
|
|
49
|
+
"vitest": "^2.1.8"
|
|
50
|
+
},
|
|
51
|
+
"license": "MIT"
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
function tsconfigTemplate() {
|
|
56
|
+
return `{
|
|
57
|
+
"compilerOptions": {
|
|
58
|
+
"target": "ES2022",
|
|
59
|
+
"module": "NodeNext",
|
|
60
|
+
"moduleResolution": "NodeNext",
|
|
61
|
+
"lib": ["ES2022"],
|
|
62
|
+
"strict": true,
|
|
63
|
+
"skipLibCheck": true,
|
|
64
|
+
"declaration": true,
|
|
65
|
+
"declarationMap": true,
|
|
66
|
+
"sourceMap": true,
|
|
67
|
+
"outDir": "./dist",
|
|
68
|
+
"rootDir": ".",
|
|
69
|
+
"resolveJsonModule": true,
|
|
70
|
+
"isolatedModules": true
|
|
71
|
+
},
|
|
72
|
+
"include": ["./**/*.ts"],
|
|
73
|
+
"exclude": ["node_modules", "dist", "**/dist/**"]
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
function tsconfigBuildTemplate() {
|
|
78
|
+
return `{
|
|
79
|
+
"extends": "./tsconfig.json",
|
|
80
|
+
"compilerOptions": { "rootDir": ".", "outDir": "dist" },
|
|
81
|
+
"include": ["./**/*.ts"],
|
|
82
|
+
"exclude": ["node_modules", "dist", "**/dist/**", "**/tsconfig*.json", "**/*.test.ts", "test", "scripts", "generate-manifest.ts"]
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
function generateManifestTemplate() {
|
|
87
|
+
return `/**
|
|
88
|
+
* Build step: run framework generateManifest (scan src, emit manifest).
|
|
89
|
+
* Tool names in the manifest are the exported function names.
|
|
90
|
+
*/
|
|
91
|
+
import { generateManifest } from "@botbotgo/kit/sdk";
|
|
92
|
+
|
|
93
|
+
generateManifest(process.cwd());
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
function extensionIndexTemplate() {
|
|
97
|
+
return `import { createExtension } from "@botbotgo/kit/sdk";
|
|
98
|
+
import type { ToolRegistry, ToolAdapter } from "@botbotgo/kit/sdk";
|
|
99
|
+
|
|
100
|
+
const ext = createExtension({ importMeta: import.meta });
|
|
101
|
+
|
|
102
|
+
/** Framework contract: extension exports register(registry, options). */
|
|
103
|
+
export function register(
|
|
104
|
+
registry: ToolRegistry,
|
|
105
|
+
options?: { only?: string[]; namePrefixes?: string[] },
|
|
106
|
+
): ToolAdapter {
|
|
107
|
+
return ext.register(registry, options ?? {});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const getExtensionContext = ext.getContext;
|
|
111
|
+
export const runWithExtensionContext = ext.runWith;
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
function helloWorldTemplate() {
|
|
115
|
+
return `/**
|
|
116
|
+
* A simple hello-world tool.
|
|
117
|
+
* @tool
|
|
118
|
+
* @effect none
|
|
119
|
+
*/
|
|
120
|
+
export async function helloWorld(_args: Record<string, unknown>) {
|
|
121
|
+
return {
|
|
122
|
+
result: { message: "Hello, World!" },
|
|
123
|
+
evidence: [
|
|
124
|
+
{
|
|
125
|
+
type: "tool",
|
|
126
|
+
ref: "helloWorld",
|
|
127
|
+
summary: "Hello, World!",
|
|
128
|
+
createdAt: new Date().toISOString(),
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
function readmeTemplate(packageName) {
|
|
136
|
+
return `# ${packageName}
|
|
137
|
+
|
|
138
|
+
Scaffolded by \`agent-tool init ${packageName}\`.
|
|
139
|
+
|
|
140
|
+
## Quick start
|
|
141
|
+
|
|
142
|
+
\`\`\`bash
|
|
143
|
+
npm install
|
|
144
|
+
npm run build
|
|
145
|
+
\`\`\`
|
|
146
|
+
|
|
147
|
+
Add more tools under \`src/\` (export async functions with \`@tool\` JSDoc), then \`npm run build\` again.
|
|
148
|
+
|
|
149
|
+
## Use in tool config
|
|
150
|
+
|
|
151
|
+
In your \`tool.yaml\`:
|
|
152
|
+
|
|
153
|
+
\`\`\`yaml
|
|
154
|
+
tools:
|
|
155
|
+
file:./path/to/${packageName}: {}
|
|
156
|
+
\`\`\`
|
|
157
|
+
|
|
158
|
+
Or publish and use: \`npm:@your-scope/${packageName}\`
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
function templates(packageName) {
|
|
162
|
+
return {
|
|
163
|
+
"package.json": packageJsonTemplate(packageName),
|
|
164
|
+
"tsconfig.json": tsconfigTemplate(),
|
|
165
|
+
"tsconfig.build.json": tsconfigBuildTemplate(),
|
|
166
|
+
"generate-manifest.ts": generateManifestTemplate(),
|
|
167
|
+
"index.ts": extensionIndexTemplate(),
|
|
168
|
+
"src/helloWorld.ts": helloWorldTemplate(),
|
|
169
|
+
"README.md": readmeTemplate(packageName)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function initExtension(options) {
|
|
173
|
+
const parent = path2.resolve(options.parentDir ?? process.cwd());
|
|
174
|
+
const name = options.extensionName.trim();
|
|
175
|
+
if (!name) {
|
|
176
|
+
throw new Error("Extension name is required");
|
|
177
|
+
}
|
|
178
|
+
const targetPath = path2.join(parent, name);
|
|
179
|
+
const baseName = toPackageName(name) || name.replace(/\s/g, "-").toLowerCase();
|
|
180
|
+
const scopeNorm = options.scope?.trim().replace(/^@/, "") || "";
|
|
181
|
+
const packageName = scopeNorm ? `@${scopeNorm}/${baseName}` : baseName;
|
|
182
|
+
const filesCreated = [];
|
|
183
|
+
const tmpl = templates(packageName);
|
|
184
|
+
await fs.mkdir(targetPath, { recursive: true });
|
|
185
|
+
for (const [relPath, content] of Object.entries(tmpl)) {
|
|
186
|
+
const fullPath = path2.join(targetPath, relPath);
|
|
187
|
+
await fs.mkdir(path2.dirname(fullPath), { recursive: true });
|
|
188
|
+
await fs.writeFile(fullPath, content.trimStart(), "utf8");
|
|
189
|
+
filesCreated.push(relPath);
|
|
190
|
+
}
|
|
191
|
+
return { targetPath, filesCreated };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/utils/cli/help.ts
|
|
195
|
+
function printHelp(bin = "agent-tool") {
|
|
196
|
+
process.stdout.write(`
|
|
197
|
+
Usage: ${bin} <command> [options] [args]
|
|
198
|
+
|
|
199
|
+
Primary commands:
|
|
200
|
+
ls List all tools (scope, name, description).
|
|
201
|
+
describe <tool path> Show tool details (schema, capabilities, etc.).
|
|
202
|
+
run <tool path> [params] Run a tool. Params: JSON, e.g. '{"path":"README.md"}'
|
|
203
|
+
start mcp Start MCP server (default: Streamable HTTP; use --stdio for stdio).
|
|
204
|
+
start http Start OpenAPI HTTP server (API + Swagger).
|
|
205
|
+
|
|
206
|
+
Other commands:
|
|
207
|
+
init [extension name] Create extension scaffold (folder + src + hello-world + generate-manifest + index + package.json). With no name: create MCP project in --path. Then: cd <folder> && npm install && npm run build.
|
|
208
|
+
build Scan folder for @tool / SKILL / n8n, generate MCP npm package.
|
|
209
|
+
serve Start the generated MCP server (stdio) for testing.
|
|
210
|
+
list Alias for ls.
|
|
211
|
+
show <tool> Alias for describe.
|
|
212
|
+
help Show this help.
|
|
213
|
+
|
|
214
|
+
Options:
|
|
215
|
+
--path, -p <path> For init/build/serve: path (default: cwd).
|
|
216
|
+
--scope, -s <scope> For init [extension name]: npm package scope (e.g. wallee \u2192 @wallee/<name>).
|
|
217
|
+
--out, -o <path> For build: output directory.
|
|
218
|
+
--include, -i <glob> For build: glob for TS files.
|
|
219
|
+
--include-n8n For build: include n8n workflow tools.
|
|
220
|
+
--verbose, -v Print step logs (config load, cache, tools registered).
|
|
221
|
+
--stdio For start mcp: use stdio transport (default: Streamable HTTP).
|
|
222
|
+
--port <number> For start mcp/http: port (default: 3000).
|
|
223
|
+
--host <string> For start mcp/http: host (default: 127.0.0.1).
|
|
224
|
+
--help, -h Show this help.
|
|
225
|
+
|
|
226
|
+
Examples:
|
|
227
|
+
${bin} ls
|
|
228
|
+
${bin} describe core.fs.readText
|
|
229
|
+
${bin} run core.fs.readText '{"path":"README.md"}'
|
|
230
|
+
${bin} start mcp
|
|
231
|
+
${bin} start mcp --stdio
|
|
232
|
+
${bin} start http --port 3000
|
|
233
|
+
${bin} build --path . --out dist
|
|
234
|
+
${bin} init my-extension
|
|
235
|
+
|
|
236
|
+
For agent run (ReAct + agent.yaml): use your BotBotGo runtime entrypoint or app wrapper
|
|
237
|
+
`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/utils/cli/index.ts
|
|
241
|
+
var DEFAULT_CORE_CONFIG = {
|
|
242
|
+
sandboxRoot: process.cwd(),
|
|
243
|
+
enableSandboxValidation: false};
|
|
244
|
+
async function getRuntimeWithTools(pathOpt, verbose = false) {
|
|
245
|
+
const cwd = process.cwd();
|
|
246
|
+
const searchDir = path2__default.resolve(cwd, pathOpt ?? ".");
|
|
247
|
+
const stepLog = verbose ? (msg) => process.stderr.write(`[agent-tool] ${msg}
|
|
248
|
+
`) : void 0;
|
|
249
|
+
if (stepLog) stepLog(`Loading tool config from ${searchDir}`);
|
|
250
|
+
const config = findAndLoadToolConfig(searchDir);
|
|
251
|
+
let sandboxRoot = cwd;
|
|
252
|
+
if (config.sandboxedPath && typeof config.sandboxedPath === "string" && config.configPath) {
|
|
253
|
+
sandboxRoot = resolveSandboxedPath(config.configPath, config.sandboxedPath);
|
|
254
|
+
}
|
|
255
|
+
if (stepLog) {
|
|
256
|
+
if (config.configPath) {
|
|
257
|
+
const n = getToolSourceDescriptors(config).length;
|
|
258
|
+
stepLog(`Config: ${config.configPath} (${n} tool(s)), sandbox: ${sandboxRoot}`);
|
|
259
|
+
} else {
|
|
260
|
+
stepLog("No tool.yaml found");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const coreConfig = {
|
|
264
|
+
sandboxRoot,
|
|
265
|
+
enableSandboxValidation: config.enableSandboxValidation ?? DEFAULT_CORE_CONFIG.enableSandboxValidation,
|
|
266
|
+
allowedHosts: []
|
|
267
|
+
};
|
|
268
|
+
const result = await createRuntimeFromConfig({
|
|
269
|
+
coreTools: coreConfig,
|
|
270
|
+
configFilePath: config.configPath,
|
|
271
|
+
stepLog
|
|
272
|
+
});
|
|
273
|
+
if (stepLog) stepLog(`Registered ${result.registry.snapshot().length} tool(s)`);
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
function parseToolName(fullName) {
|
|
277
|
+
const i = fullName.indexOf("/");
|
|
278
|
+
if (i < 0) return { scope: "", name: fullName };
|
|
279
|
+
return { scope: fullName.slice(0, i), name: fullName.slice(i + 1) };
|
|
280
|
+
}
|
|
281
|
+
function parseArgv(argv) {
|
|
282
|
+
const args = argv.slice(2);
|
|
283
|
+
let command = "help";
|
|
284
|
+
let startSub = "http";
|
|
285
|
+
let help = false;
|
|
286
|
+
let verbose = false;
|
|
287
|
+
let mcpStdio = false;
|
|
288
|
+
let pathOpt = "";
|
|
289
|
+
let extensionName = "";
|
|
290
|
+
let scope = "";
|
|
291
|
+
let outDir = "";
|
|
292
|
+
let include = [];
|
|
293
|
+
let includeN8n = false;
|
|
294
|
+
let toolName = "";
|
|
295
|
+
let toolArgsJson = "{}";
|
|
296
|
+
let port = 3e3;
|
|
297
|
+
let host = "127.0.0.1";
|
|
298
|
+
const commands = [
|
|
299
|
+
"init",
|
|
300
|
+
"build",
|
|
301
|
+
"serve",
|
|
302
|
+
"list",
|
|
303
|
+
"ls",
|
|
304
|
+
"show",
|
|
305
|
+
"describe",
|
|
306
|
+
"run",
|
|
307
|
+
"start",
|
|
308
|
+
"help"
|
|
309
|
+
];
|
|
310
|
+
const startSubcommands = ["mcp", "http"];
|
|
311
|
+
for (let i = 0; i < args.length; i++) {
|
|
312
|
+
const arg = args[i];
|
|
313
|
+
if (arg === "--help" || arg === "-h") {
|
|
314
|
+
help = true;
|
|
315
|
+
} else if (arg === "--verbose" || arg === "-v") {
|
|
316
|
+
verbose = true;
|
|
317
|
+
} else if (arg === "--stdio") {
|
|
318
|
+
mcpStdio = true;
|
|
319
|
+
} else if (arg === "--path" || arg === "-p") {
|
|
320
|
+
pathOpt = path2__default.resolve(process.cwd(), args[++i] ?? "");
|
|
321
|
+
} else if (arg === "--out" || arg === "-o") {
|
|
322
|
+
outDir = path2__default.resolve(process.cwd(), args[++i] ?? "");
|
|
323
|
+
} else if (arg === "--include" || arg === "-i") {
|
|
324
|
+
const v = args[++i];
|
|
325
|
+
if (v) include.push(v);
|
|
326
|
+
} else if (arg === "--include-n8n") {
|
|
327
|
+
includeN8n = true;
|
|
328
|
+
} else if (arg === "--port") {
|
|
329
|
+
const v = args[++i];
|
|
330
|
+
if (v !== void 0) port = parseInt(v, 10) || 3e3;
|
|
331
|
+
} else if (arg === "--host") {
|
|
332
|
+
const v = args[++i];
|
|
333
|
+
if (v !== void 0) host = v;
|
|
334
|
+
} else if (arg === "--scope" || arg === "-s") {
|
|
335
|
+
scope = args[++i] ?? "";
|
|
336
|
+
} else if (arg && !arg.startsWith("-") && commands.includes(arg)) {
|
|
337
|
+
command = arg;
|
|
338
|
+
const nextArg = args[i + 1];
|
|
339
|
+
if (command === "init" && nextArg !== void 0 && !nextArg.startsWith("-")) {
|
|
340
|
+
extensionName = args[++i] ?? "";
|
|
341
|
+
} else if ((command === "show" || command === "describe") && nextArg !== void 0 && !nextArg.startsWith("-")) {
|
|
342
|
+
toolName = args[++i] ?? "";
|
|
343
|
+
} else if (command === "run" && nextArg !== void 0 && !nextArg.startsWith("-")) {
|
|
344
|
+
toolName = args[++i] ?? "";
|
|
345
|
+
const runNext = args[i + 1];
|
|
346
|
+
if (runNext !== void 0 && !runNext.startsWith("-")) {
|
|
347
|
+
toolArgsJson = args[++i] ?? "{}";
|
|
348
|
+
}
|
|
349
|
+
} else if (command === "start" && nextArg !== void 0 && !nextArg.startsWith("-") && startSubcommands.includes(nextArg)) {
|
|
350
|
+
startSub = args[++i];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return { command, startSub, help, verbose, mcpStdio, pathOpt, extensionName, scope, outDir, include, includeN8n, toolName, toolArgsJson, port, host };
|
|
355
|
+
}
|
|
356
|
+
async function cmdInitExtension(extensionName, pathOpt, scope) {
|
|
357
|
+
try {
|
|
358
|
+
const parentDir = pathOpt ? path2__default.resolve(process.cwd(), pathOpt) : void 0;
|
|
359
|
+
const { targetPath, filesCreated } = await initExtension({
|
|
360
|
+
extensionName,
|
|
361
|
+
parentDir: parentDir || process.cwd(),
|
|
362
|
+
scope: scope || void 0
|
|
363
|
+
});
|
|
364
|
+
process.stdout.write(
|
|
365
|
+
`Extension scaffold at ${targetPath}
|
|
366
|
+
Created: ${filesCreated.join(", ")}
|
|
367
|
+
Next: cd ${path2__default.basename(targetPath)} && npm install && npm run build
|
|
368
|
+
`
|
|
369
|
+
);
|
|
370
|
+
return 0;
|
|
371
|
+
} catch (err) {
|
|
372
|
+
process.stderr.write(`Init extension failed: ${err instanceof Error ? err.message : String(err)}
|
|
373
|
+
`);
|
|
374
|
+
return 1;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function cmdInit(pathOpt) {
|
|
378
|
+
try {
|
|
379
|
+
const { targetPath, filesCreated } = await initProject({ targetPath: pathOpt || void 0 });
|
|
380
|
+
process.stdout.write(`Initialized project at ${targetPath}
|
|
381
|
+
Created: ${filesCreated.join(", ")}
|
|
382
|
+
Next: npm install && npm run build
|
|
383
|
+
`);
|
|
384
|
+
return 0;
|
|
385
|
+
} catch (err) {
|
|
386
|
+
process.stderr.write(`Init failed: ${err instanceof Error ? err.message : String(err)}
|
|
387
|
+
`);
|
|
388
|
+
return 1;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async function cmdBuild(pathOpt, outDir, include, includeN8n) {
|
|
392
|
+
try {
|
|
393
|
+
const result = await buildMCPPackage({
|
|
394
|
+
projectPath: pathOpt || void 0,
|
|
395
|
+
outDir: outDir || void 0,
|
|
396
|
+
include: include.length > 0 ? include : void 0,
|
|
397
|
+
includeN8n: includeN8n || void 0
|
|
398
|
+
});
|
|
399
|
+
process.stdout.write(
|
|
400
|
+
`Built ${result.toolCount} tool(s) -> ${result.outDir}
|
|
401
|
+
Entry: ${result.entryPath}
|
|
402
|
+
mcp.json: ${result.mcpJsonPath}
|
|
403
|
+
`
|
|
404
|
+
);
|
|
405
|
+
return 0;
|
|
406
|
+
} catch (err) {
|
|
407
|
+
process.stderr.write(`Build failed: ${err instanceof Error ? err.message : String(err)}
|
|
408
|
+
`);
|
|
409
|
+
return 1;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
async function cmdServe(pathOpt) {
|
|
413
|
+
try {
|
|
414
|
+
const { process: child } = await runMCPServer({ path: pathOpt || void 0 });
|
|
415
|
+
child.stdin?.pipe(process.stdin);
|
|
416
|
+
child.stdout?.pipe(process.stdout);
|
|
417
|
+
process.stdin?.unref();
|
|
418
|
+
const exit = new Promise((resolve2) => {
|
|
419
|
+
child.on("close", (code) => resolve2(code ?? 0));
|
|
420
|
+
});
|
|
421
|
+
return exit;
|
|
422
|
+
} catch (err) {
|
|
423
|
+
process.stderr.write(`Serve failed: ${err instanceof Error ? err.message : String(err)}
|
|
424
|
+
`);
|
|
425
|
+
return 1;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
var LS_DESC_MAX = 72;
|
|
429
|
+
function formatLsOutput(specs) {
|
|
430
|
+
const rows = specs.map((spec) => {
|
|
431
|
+
const { name } = parseToolName(spec.name);
|
|
432
|
+
const scope = getDisplayScope(spec.name, spec.kind, spec.version);
|
|
433
|
+
const desc = (spec.description ?? "").replace(/\n/g, " ").trim().slice(0, LS_DESC_MAX);
|
|
434
|
+
return { scope, name, description: desc || "(no description)" };
|
|
435
|
+
});
|
|
436
|
+
const scopeW = Math.max(6, ...rows.map((r) => r.scope.length));
|
|
437
|
+
const nameW = Math.max(4, ...rows.map((r) => r.name.length));
|
|
438
|
+
const sep = `${"\u2500".repeat(scopeW)}\u252C${"\u2500".repeat(nameW)}\u252C${"\u2500".repeat(LS_DESC_MAX + 2)}`;
|
|
439
|
+
const header = [
|
|
440
|
+
"SCOPE".padEnd(scopeW),
|
|
441
|
+
"NAME".padEnd(nameW),
|
|
442
|
+
"DESCRIPTION"
|
|
443
|
+
].join(" \u2502 ");
|
|
444
|
+
const lines = [
|
|
445
|
+
header,
|
|
446
|
+
sep,
|
|
447
|
+
...rows.map(
|
|
448
|
+
(r) => [
|
|
449
|
+
r.scope.padEnd(scopeW),
|
|
450
|
+
r.name.padEnd(nameW),
|
|
451
|
+
r.description
|
|
452
|
+
].join(" \u2502 ")
|
|
453
|
+
)
|
|
454
|
+
];
|
|
455
|
+
return lines.join("\n");
|
|
456
|
+
}
|
|
457
|
+
function formatDescribeOutput(spec) {
|
|
458
|
+
const { name: localName } = parseToolName(spec.name);
|
|
459
|
+
const scope = getDisplayScope(spec.name, spec.kind, spec.version);
|
|
460
|
+
const sections = [];
|
|
461
|
+
sections.push("\u250C\u2500 Tool");
|
|
462
|
+
sections.push(`\u2502 name: ${spec.name}`);
|
|
463
|
+
sections.push(`\u2502 scope: ${scope}`);
|
|
464
|
+
sections.push(`\u2502 localName: ${localName}`);
|
|
465
|
+
sections.push(`\u2502 version: ${spec.version}`);
|
|
466
|
+
sections.push(`\u2502 kind: ${spec.kind}`);
|
|
467
|
+
sections.push("\u251C\u2500 Description");
|
|
468
|
+
sections.push(`\u2502 ${(spec.description ?? "(none)").replace(/\n/g, "\n\u2502 ")}`);
|
|
469
|
+
sections.push("\u251C\u2500 Tags");
|
|
470
|
+
sections.push(`\u2502 ${spec.tags?.length ? spec.tags.join(", ") : "(none)"}`);
|
|
471
|
+
sections.push("\u251C\u2500 Capabilities");
|
|
472
|
+
sections.push(`\u2502 ${spec.capabilities.join(", ")}`);
|
|
473
|
+
if (spec._meta?.hitl?.sideEffect) {
|
|
474
|
+
sections.push("\u251C\u2500 HITL");
|
|
475
|
+
sections.push(`\u2502 sideEffect: ${spec._meta.hitl.sideEffect}`);
|
|
476
|
+
}
|
|
477
|
+
sections.push("\u251C\u2500 Input schema");
|
|
478
|
+
sections.push(
|
|
479
|
+
"\u2502 " + JSON.stringify(spec.inputSchema, null, 2).replace(/\n/g, "\n\u2502 ")
|
|
480
|
+
);
|
|
481
|
+
sections.push("\u2514\u2500 Output schema");
|
|
482
|
+
sections.push(
|
|
483
|
+
" " + JSON.stringify(spec.outputSchema, null, 2).replace(/\n/g, "\n ")
|
|
484
|
+
);
|
|
485
|
+
return sections.join("\n");
|
|
486
|
+
}
|
|
487
|
+
async function cmdLs(pathOpt, verbose = false) {
|
|
488
|
+
try {
|
|
489
|
+
const { registry } = await getRuntimeWithTools(pathOpt, verbose);
|
|
490
|
+
const specs = registry.snapshot();
|
|
491
|
+
if (specs.length === 0) {
|
|
492
|
+
process.stdout.write("No tools registered.\n");
|
|
493
|
+
const cwd = process.cwd();
|
|
494
|
+
const searchDir = path2__default.resolve(cwd, pathOpt ?? ".");
|
|
495
|
+
const config = findAndLoadToolConfig(searchDir);
|
|
496
|
+
const hasNpmTools = getToolSourceDescriptors(config).some((t) => typeof t === "string" && t.startsWith("npm:"));
|
|
497
|
+
if (hasNpmTools) {
|
|
498
|
+
process.stdout.write(
|
|
499
|
+
"Tip: Install builtin tools in this directory so 'agent-tool ls' finds them: npm init -y && npm install @botbotgo/kit-builtin\n"
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
return 0;
|
|
503
|
+
}
|
|
504
|
+
specs.sort((a, b) => a.name.localeCompare(b.name));
|
|
505
|
+
process.stdout.write(formatLsOutput(specs) + "\n");
|
|
506
|
+
return 0;
|
|
507
|
+
} catch (err) {
|
|
508
|
+
process.stderr.write(`ls failed: ${err instanceof Error ? err.message : String(err)}
|
|
509
|
+
`);
|
|
510
|
+
return 1;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async function cmdDescribe(toolName, pathOpt, verbose = false) {
|
|
514
|
+
if (!toolName.trim()) {
|
|
515
|
+
process.stderr.write("Usage: agent-tool describe <tool path>\n");
|
|
516
|
+
return 1;
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
const { registry } = await getRuntimeWithTools(pathOpt, verbose);
|
|
520
|
+
const registryName = resolveToolDescriptor(toolName.trim());
|
|
521
|
+
const spec = registry.get(registryName);
|
|
522
|
+
if (!spec) {
|
|
523
|
+
process.stderr.write(`Tool not found: ${toolName}
|
|
524
|
+
`);
|
|
525
|
+
return 1;
|
|
526
|
+
}
|
|
527
|
+
process.stdout.write(formatDescribeOutput(enrichSpecWithCanonicalSchema(spec)) + "\n");
|
|
528
|
+
return 0;
|
|
529
|
+
} catch (err) {
|
|
530
|
+
process.stderr.write(`describe failed: ${err instanceof Error ? err.message : String(err)}
|
|
531
|
+
`);
|
|
532
|
+
return 1;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function defaultExecContext() {
|
|
536
|
+
return {
|
|
537
|
+
requestId: `cli-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
538
|
+
taskId: `task-${Date.now()}`,
|
|
539
|
+
permissions: [
|
|
540
|
+
"read:web",
|
|
541
|
+
"read:fs",
|
|
542
|
+
"write:fs",
|
|
543
|
+
"read:db",
|
|
544
|
+
"write:db",
|
|
545
|
+
"network",
|
|
546
|
+
"workflow",
|
|
547
|
+
"danger:destructive",
|
|
548
|
+
"exec"
|
|
549
|
+
]
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
async function cmdRun(toolName, toolArgsJson, pathOpt, verbose = false) {
|
|
553
|
+
if (!toolName.trim()) {
|
|
554
|
+
process.stderr.write("Usage: agent-tool run <tool path> [<json params>]\n");
|
|
555
|
+
return 1;
|
|
556
|
+
}
|
|
557
|
+
let args = {};
|
|
558
|
+
if (toolArgsJson.trim()) {
|
|
559
|
+
try {
|
|
560
|
+
args = JSON.parse(toolArgsJson);
|
|
561
|
+
} catch {
|
|
562
|
+
process.stderr.write(`Invalid JSON for parameters. Example: '{"path":"README.md"}'
|
|
563
|
+
`);
|
|
564
|
+
return 1;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
try {
|
|
568
|
+
const { runtime, registry } = await getRuntimeWithTools(pathOpt, verbose);
|
|
569
|
+
const registryName = resolveToolDescriptor(toolName.trim());
|
|
570
|
+
if (!registry.get(registryName)) {
|
|
571
|
+
process.stderr.write(`Tool not found: ${toolName}
|
|
572
|
+
`);
|
|
573
|
+
return 1;
|
|
574
|
+
}
|
|
575
|
+
const ctx = defaultExecContext();
|
|
576
|
+
const result = await runtime.invoke(
|
|
577
|
+
{ tool: registryName, args, purpose: "cli" },
|
|
578
|
+
ctx
|
|
579
|
+
);
|
|
580
|
+
if (result.ok) {
|
|
581
|
+
process.stdout.write(JSON.stringify(result.result, null, 2) + "\n");
|
|
582
|
+
return 0;
|
|
583
|
+
}
|
|
584
|
+
process.stderr.write(`Tool error: ${result.error?.kind ?? "unknown"} - ${result.error?.message ?? ""}
|
|
585
|
+
`);
|
|
586
|
+
return 1;
|
|
587
|
+
} catch (err) {
|
|
588
|
+
process.stderr.write(`Run failed: ${err instanceof Error ? err.message : String(err)}
|
|
589
|
+
`);
|
|
590
|
+
return 1;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
async function cmdStartMcp(pathOpt, verbose = false, stdio = false, port = 3e3, host = "127.0.0.1") {
|
|
594
|
+
try {
|
|
595
|
+
const { runtime } = await getRuntimeWithTools(pathOpt, verbose);
|
|
596
|
+
if (stdio) {
|
|
597
|
+
await runMCPServerOverStdio(runtime);
|
|
598
|
+
return 0;
|
|
599
|
+
}
|
|
600
|
+
const streamable = await createMCPServerStreamableHttp(runtime, { port, host, path: "/mcp" });
|
|
601
|
+
const { url } = await streamable.listen(port, host);
|
|
602
|
+
process.stdout.write(`MCP Streamable HTTP: ${url}
|
|
603
|
+
`);
|
|
604
|
+
await new Promise(() => {
|
|
605
|
+
});
|
|
606
|
+
return 0;
|
|
607
|
+
} catch (err) {
|
|
608
|
+
process.stderr.write(`start mcp failed: ${err instanceof Error ? err.message : String(err)}
|
|
609
|
+
`);
|
|
610
|
+
return 1;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async function cmdStartHttp(port, host, pathOpt, verbose = false) {
|
|
614
|
+
try {
|
|
615
|
+
const { runtime } = await getRuntimeWithTools(pathOpt, verbose);
|
|
616
|
+
const http = await createHttpService(runtime);
|
|
617
|
+
const { port: actualPort, host: actualHost } = await http.listen({ port, host });
|
|
618
|
+
const base = `http://${actualHost}:${actualPort}`;
|
|
619
|
+
process.stdout.write(`API: ${base}/invoke (POST), ${base}/tools (GET)
|
|
620
|
+
`);
|
|
621
|
+
process.stdout.write(`Swagger UI: ${base}/ (spec: ${base}/openapi.json)
|
|
622
|
+
`);
|
|
623
|
+
await new Promise(() => {
|
|
624
|
+
});
|
|
625
|
+
return 0;
|
|
626
|
+
} catch (err) {
|
|
627
|
+
process.stderr.write(`start http failed: ${err instanceof Error ? err.message : String(err)}
|
|
628
|
+
`);
|
|
629
|
+
return 1;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
async function main(argv = process.argv) {
|
|
633
|
+
const { command, startSub, help, verbose, mcpStdio, pathOpt, extensionName, scope, outDir, include, includeN8n, toolName, toolArgsJson, port, host } = parseArgv(argv);
|
|
634
|
+
if (help || command === "help") {
|
|
635
|
+
printHelp();
|
|
636
|
+
return 0;
|
|
637
|
+
}
|
|
638
|
+
if (command === "init") {
|
|
639
|
+
if (extensionName) return cmdInitExtension(extensionName, pathOpt, scope);
|
|
640
|
+
return cmdInit(pathOpt);
|
|
641
|
+
}
|
|
642
|
+
if (command === "build") return cmdBuild(pathOpt, outDir, include, includeN8n);
|
|
643
|
+
if (command === "serve") return cmdServe(pathOpt);
|
|
644
|
+
if (command === "ls" || command === "list") return cmdLs(pathOpt, verbose);
|
|
645
|
+
if (command === "describe" || command === "show") return cmdDescribe(toolName, pathOpt, verbose);
|
|
646
|
+
if (command === "run") return cmdRun(toolName, toolArgsJson, pathOpt, verbose);
|
|
647
|
+
if (command === "start") {
|
|
648
|
+
if (startSub === "mcp") return cmdStartMcp(pathOpt, verbose, mcpStdio, port, host);
|
|
649
|
+
if (startSub === "http") return cmdStartHttp(port, host, pathOpt, verbose);
|
|
650
|
+
process.stderr.write("Usage: agent-tool start mcp | agent-tool start http [--port 3000] [--host 127.0.0.1]\n");
|
|
651
|
+
return 1;
|
|
652
|
+
}
|
|
653
|
+
printHelp();
|
|
654
|
+
return 1;
|
|
655
|
+
}
|
|
656
|
+
async function run(argv) {
|
|
657
|
+
return main(argv);
|
|
658
|
+
}
|
|
659
|
+
var scriptPath = fileURLToPath(import.meta.url);
|
|
660
|
+
var invokedPath = process.argv[1];
|
|
661
|
+
var isMain = typeof process !== "undefined" && invokedPath !== void 0 && invokedPath === scriptPath;
|
|
662
|
+
if (!isMain && invokedPath) {
|
|
663
|
+
try {
|
|
664
|
+
isMain = realpathSync(invokedPath) === realpathSync(scriptPath);
|
|
665
|
+
} catch {
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (isMain) {
|
|
669
|
+
main().then((code) => process.exit(code)).catch((err) => {
|
|
670
|
+
process.stderr.write(String(err?.message ?? err) + "\n");
|
|
671
|
+
process.exit(1);
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export { run };
|
|
676
|
+
//# sourceMappingURL=index.js.map
|
|
677
|
+
//# sourceMappingURL=index.js.map
|