@easynet/agent-tool 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -73
- package/dist/api/adapters/LangChainToolsHub.d.ts +34 -0
- package/dist/api/adapters/LangChainToolsHub.d.ts.map +1 -0
- package/dist/api/createAgentTools.d.ts +24 -0
- package/dist/api/createAgentTools.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.map +1 -0
- package/dist/{codegen → api/expose/mcp-build}/generator.d.ts +3 -3
- 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.map +1 -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 +75 -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 +67 -0
- package/dist/api/expose/openapiHttp.d.ts.map +1 -0
- package/dist/api/main.cjs +56 -0
- package/dist/api/main.cjs.map +1 -0
- package/dist/api/main.d.ts +23 -0
- package/dist/api/main.d.ts.map +1 -0
- package/dist/api/main.js +7 -0
- package/dist/api/main.js.map +1 -0
- package/dist/api/runtimeFromConfig.d.ts +34 -0
- package/dist/api/runtimeFromConfig.d.ts.map +1 -0
- package/dist/canonicalCoreSchemas-CTW6CCFY.cjs +20 -0
- package/dist/canonicalCoreSchemas-CTW6CCFY.cjs.map +1 -0
- package/dist/canonicalCoreSchemas-YLHVHYJZ.js +3 -0
- package/dist/canonicalCoreSchemas-YLHVHYJZ.js.map +1 -0
- package/dist/{chunk-AXUNV4MK.js → chunk-5SWSNVMI.js} +3 -3
- package/dist/chunk-5SWSNVMI.js.map +1 -0
- package/dist/chunk-6F5JHLZ7.cjs +243 -0
- package/dist/chunk-6F5JHLZ7.cjs.map +1 -0
- package/dist/chunk-AE6FSNGY.js +201 -0
- package/dist/chunk-AE6FSNGY.js.map +1 -0
- package/dist/chunk-BZOKPJMP.cjs +120 -0
- package/dist/chunk-BZOKPJMP.cjs.map +1 -0
- package/dist/chunk-FA2ZEICE.cjs +1620 -0
- package/dist/chunk-FA2ZEICE.cjs.map +1 -0
- package/dist/chunk-FR2CXERF.js +239 -0
- package/dist/chunk-FR2CXERF.js.map +1 -0
- package/dist/chunk-MGEQPAHV.cjs +475 -0
- package/dist/chunk-MGEQPAHV.cjs.map +1 -0
- package/dist/{chunk-BM4EVYI5.js → chunk-PJ4RUBZL.js} +836 -122
- package/dist/chunk-PJ4RUBZL.js.map +1 -0
- package/dist/chunk-Q7KPGWC6.js +1584 -0
- package/dist/chunk-Q7KPGWC6.js.map +1 -0
- package/dist/chunk-QVH6IQKQ.js +469 -0
- package/dist/chunk-QVH6IQKQ.js.map +1 -0
- package/dist/{chunk-3YLVPZRJ.cjs → chunk-SOFUWEZ6.cjs} +3 -3
- package/dist/chunk-SOFUWEZ6.cjs.map +1 -0
- package/dist/chunk-TBMWJWQ2.js +116 -0
- package/dist/chunk-TBMWJWQ2.js.map +1 -0
- package/dist/{chunk-Z7TGIG77.cjs → chunk-ZBNRHRGM.cjs} +843 -127
- package/dist/chunk-ZBNRHRGM.cjs.map +1 -0
- package/dist/chunk-ZNJBRLKN.cjs +210 -0
- package/dist/chunk-ZNJBRLKN.cjs.map +1 -0
- package/dist/core/index.cjs +20 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/{core.d.ts → core/index.d.ts} +2 -3
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/core/runtime/Budget.d.ts.map +1 -0
- package/dist/core/runtime/Evidence.d.ts.map +1 -0
- package/dist/{runtime → core/runtime}/PTCRuntime.d.ts +4 -4
- package/dist/core/runtime/PTCRuntime.d.ts.map +1 -0
- package/dist/{runtime → core/runtime}/PTCRuntimeObservability.d.ts +4 -4
- package/dist/core/runtime/PTCRuntimeObservability.d.ts.map +1 -0
- package/dist/{runtime → core/runtime}/PTCRuntimePipeline.d.ts +4 -4
- package/dist/core/runtime/PTCRuntimePipeline.d.ts.map +1 -0
- package/dist/core/runtime/PolicyEngine.d.ts.map +1 -0
- package/dist/core/runtime/Retry.d.ts.map +1 -0
- package/dist/core/runtime/SchemaValidator.d.ts.map +1 -0
- package/dist/core/runtime.cjs +24 -0
- package/dist/core/runtime.cjs.map +1 -0
- package/dist/core/runtime.d.ts +12 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +3 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/types/Events.d.ts.map +1 -0
- package/dist/core/types/ToolIntent.d.ts.map +1 -0
- package/dist/{types → core/types}/ToolResult.d.ts +6 -1
- package/dist/core/types/ToolResult.d.ts.map +1 -0
- package/dist/{types → core/types}/ToolSpec.d.ts +15 -5
- 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/{types → core/types}/index.d.ts +2 -1
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/index.cjs +249 -2749
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +61 -55
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +126 -2688
- package/dist/index.js.map +1 -1
- package/dist/observability/EventLog.d.ts +1 -1
- package/dist/observability/EventLog.d.ts.map +1 -1
- 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/{codegen/scan → tools/function}/scanner.d.ts +5 -2
- package/dist/{codegen/scan → tools/function}/scanner.d.ts.map +1 -1
- package/dist/{codegen/scan → tools/function}/schemaFromTs.d.ts +1 -1
- 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/{discovery/load → tools/langchain}/LangChainLoader.d.ts +1 -1
- 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/{mcp → tools/mcp}/MCPClientAdapter.d.ts +3 -3
- package/dist/tools/mcp/MCPClientAdapter.d.ts.map +1 -0
- package/dist/{discovery/load → tools/mcp}/MCPLoader.d.ts +1 -1
- 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/{mcp → tools/mcp}/connectMCP.d.ts +3 -3
- 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/{mcp → tools/mcp}/index.d.ts +6 -1
- 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/{mcp → tools/mcp}/registerMCPTools.d.ts +2 -2
- 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/types.d.ts +3 -0
- package/dist/tools/mcp/types.d.ts.map +1 -0
- package/dist/{discovery/load → tools/n8n}/N8nLoader.d.ts +3 -3
- 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/{discovery/load → tools/skill}/SkillLoader.d.ts +1 -1
- package/dist/tools/skill/SkillLoader.d.ts.map +1 -0
- package/dist/tools/skill/SkillManifest.d.ts.map +1 -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 +19 -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 +32 -0
- package/dist/tools/util/toolConfig.d.ts.map +1 -0
- package/dist/tools/util/toolDescriptor.d.ts +92 -0
- package/dist/tools/util/toolDescriptor.d.ts.map +1 -0
- package/dist/utils/cli/index.cjs +419 -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 +412 -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/npmCache.d.ts +28 -0
- package/dist/utils/npmCache.d.ts.map +1 -0
- package/package.json +20 -11
- package/dist/chunk-3YLVPZRJ.cjs.map +0 -1
- package/dist/chunk-AXUNV4MK.js.map +0 -1
- package/dist/chunk-BM4EVYI5.js.map +0 -1
- package/dist/chunk-P3UEAZHK.cjs +0 -171
- package/dist/chunk-P3UEAZHK.cjs.map +0 -1
- package/dist/chunk-RPAMQCFH.js +0 -167
- package/dist/chunk-RPAMQCFH.js.map +0 -1
- package/dist/chunk-Z7TGIG77.cjs.map +0 -1
- package/dist/cli.cjs +0 -154
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.ts +0 -10
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -147
- package/dist/cli.js.map +0 -1
- package/dist/codegen/build.d.ts.map +0 -1
- package/dist/codegen/generator.d.ts.map +0 -1
- package/dist/codegen/index.d.ts +0 -21
- package/dist/codegen/index.d.ts.map +0 -1
- package/dist/codegen/init.d.ts.map +0 -1
- package/dist/codegen/run.d.ts.map +0 -1
- package/dist/codegen/scan/scanN8n.d.ts +0 -17
- package/dist/codegen/scan/scanN8n.d.ts.map +0 -1
- package/dist/codegen/scan/scanSkill.d.ts +0 -17
- package/dist/codegen/scan/scanSkill.d.ts.map +0 -1
- package/dist/codegen/scan/scanTools.d.ts +0 -31
- package/dist/codegen/scan/scanTools.d.ts.map +0 -1
- package/dist/codegen/scan/schemaFromTs.d.ts.map +0 -1
- package/dist/codegen/types.d.ts +0 -81
- package/dist/codegen/types.d.ts.map +0 -1
- package/dist/core.cjs +0 -20
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js +0 -3
- package/dist/core.js.map +0 -1
- package/dist/discovery/MCPProcessManager.d.ts +0 -57
- package/dist/discovery/MCPProcessManager.d.ts.map +0 -1
- package/dist/discovery/errors.d.ts +0 -13
- package/dist/discovery/errors.d.ts.map +0 -1
- package/dist/discovery/load/LangChainLoader.d.ts.map +0 -1
- package/dist/discovery/load/MCPLoader.d.ts.map +0 -1
- package/dist/discovery/load/N8nLoader.d.ts.map +0 -1
- package/dist/discovery/load/SkillLoader.d.ts.map +0 -1
- package/dist/discovery/load/SkillManifest.d.ts.map +0 -1
- package/dist/discovery/load/SkillMdParser.d.ts.map +0 -1
- package/dist/discovery/load/index.d.ts +0 -6
- package/dist/discovery/load/index.d.ts.map +0 -1
- package/dist/discovery/load/resolveEntry.d.ts +0 -7
- package/dist/discovery/load/resolveEntry.d.ts.map +0 -1
- package/dist/discovery/scan/DirectoryScanner.d.ts +0 -37
- package/dist/discovery/scan/DirectoryScanner.d.ts.map +0 -1
- package/dist/discovery/scan/scanUtil.d.ts +0 -16
- package/dist/discovery/scan/scanUtil.d.ts.map +0 -1
- package/dist/discovery/types.d.ts +0 -99
- package/dist/discovery/types.d.ts.map +0 -1
- package/dist/llm/AgentLLMAdapter.d.ts +0 -27
- package/dist/llm/AgentLLMAdapter.d.ts.map +0 -1
- package/dist/llm/LangChainToolsHub.d.ts +0 -31
- package/dist/llm/LangChainToolsHub.d.ts.map +0 -1
- package/dist/llm/OpenAICompatibleClient.d.ts +0 -64
- package/dist/llm/OpenAICompatibleClient.d.ts.map +0 -1
- package/dist/llm/ReActAgent.d.ts +0 -35
- package/dist/llm/ReActAgent.d.ts.map +0 -1
- package/dist/llm-export.cjs +0 -20
- package/dist/llm-export.cjs.map +0 -1
- package/dist/llm-export.d.ts +0 -9
- package/dist/llm-export.d.ts.map +0 -1
- package/dist/llm-export.js +0 -3
- package/dist/llm-export.js.map +0 -1
- package/dist/mcp/MCPClientAdapter.d.ts.map +0 -1
- package/dist/mcp/connectMCP.d.ts.map +0 -1
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/registerMCPTools.d.ts.map +0 -1
- package/dist/registry/ToolRegistry.d.ts.map +0 -1
- package/dist/report/AgentReportGenerator.d.ts +0 -53
- package/dist/report/AgentReportGenerator.d.ts.map +0 -1
- package/dist/report/agent-report-template.html +0 -362
- package/dist/report/index.d.ts +0 -3
- package/dist/report/index.d.ts.map +0 -1
- package/dist/report/types.d.ts +0 -101
- package/dist/report/types.d.ts.map +0 -1
- package/dist/runAgent.d.ts +0 -37
- package/dist/runAgent.d.ts.map +0 -1
- package/dist/runtime/Budget.d.ts.map +0 -1
- package/dist/runtime/Evidence.d.ts.map +0 -1
- package/dist/runtime/PTCRuntime.d.ts.map +0 -1
- package/dist/runtime/PTCRuntimeObservability.d.ts.map +0 -1
- package/dist/runtime/PTCRuntimePipeline.d.ts.map +0 -1
- package/dist/runtime/PolicyEngine.d.ts.map +0 -1
- package/dist/runtime/Retry.d.ts.map +0 -1
- package/dist/runtime/SchemaValidator.d.ts.map +0 -1
- package/dist/toolDescriptor.d.ts +0 -38
- package/dist/toolDescriptor.d.ts.map +0 -1
- package/dist/types/Events.d.ts.map +0 -1
- package/dist/types/ToolIntent.d.ts.map +0 -1
- package/dist/types/ToolResult.d.ts.map +0 -1
- package/dist/types/ToolSpec.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/extensions/examples/README.md +0 -40
- package/extensions/examples/scripts/agent-tool-react-stock.mjs +0 -30
- package/extensions/examples/tools/instruction-only/skill/SKILL.md +0 -26
- package/extensions/examples/tools/web-search/mcp/mcp.json +0 -8
- /package/dist/{codegen → api/expose/mcp-build}/build.d.ts +0 -0
- /package/dist/{codegen → api/expose/mcp-build}/init.d.ts +0 -0
- /package/dist/{codegen → api/expose/mcp-build}/run.d.ts +0 -0
- /package/dist/{registry → core/registry}/ToolRegistry.d.ts +0 -0
- /package/dist/{runtime → core/runtime}/Budget.d.ts +0 -0
- /package/dist/{runtime → core/runtime}/Evidence.d.ts +0 -0
- /package/dist/{runtime → core/runtime}/PolicyEngine.d.ts +0 -0
- /package/dist/{runtime → core/runtime}/Retry.d.ts +0 -0
- /package/dist/{runtime → core/runtime}/SchemaValidator.d.ts +0 -0
- /package/dist/{types → core/types}/Events.d.ts +0 -0
- /package/dist/{types → core/types}/ToolIntent.d.ts +0 -0
- /package/dist/{discovery/load → tools/skill}/SkillManifest.d.ts +0 -0
- /package/dist/{discovery/load → tools/skill}/SkillMdParser.d.ts +0 -0
package/dist/api/main.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createAgentTools, createLangChainToolsAsync } from '../chunk-TBMWJWQ2.js';
|
|
2
|
+
export { createHttpService, createMCPServer, createMCPServerStreamableHttp, createMCPStreamableHttpHandler, createHttpService as createOpenAPIServer, runMCPServerOverStdio } from '../chunk-QVH6IQKQ.js';
|
|
3
|
+
export { PTCRuntime, createRuntimeFromConfig, createRuntimeFromConfigSync } from '../chunk-Q7KPGWC6.js';
|
|
4
|
+
import '../chunk-AE6FSNGY.js';
|
|
5
|
+
import '../chunk-FR2CXERF.js';
|
|
6
|
+
//# sourceMappingURL=main.js.map
|
|
7
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"main.js"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create PTCRuntime + ToolRegistry from config (sync or async).
|
|
3
|
+
* Registers core/example adapters only when coreTools/exampleTools options are provided.
|
|
4
|
+
* Use when you need a single runtime for MCP, OpenAPI, and/or LangChain tools.
|
|
5
|
+
*/
|
|
6
|
+
import { ToolRegistry } from "../core/registry/ToolRegistry.js";
|
|
7
|
+
import { PTCRuntime } from "../core/runtime/PTCRuntime.js";
|
|
8
|
+
import type { CoreToolsUserConfig } from "@easynet/agent-tool-builtin-tools";
|
|
9
|
+
import type { ExampleToolsUserConfig } from "@easynet/agent-tool-example-tools";
|
|
10
|
+
export interface CreateRuntimeOptions {
|
|
11
|
+
/** Path to tool.yaml (optional; used by createAgentTools to filter tool list) */
|
|
12
|
+
configFilePath?: string;
|
|
13
|
+
/** Project path for async tool loading (optional; reserved for future use) */
|
|
14
|
+
projectPath?: string;
|
|
15
|
+
/** Sandbox / core tools config; when set, core adapter is registered */
|
|
16
|
+
coreTools?: CoreToolsUserConfig;
|
|
17
|
+
/** Example tools config; when set, example adapter is registered */
|
|
18
|
+
exampleTools?: ExampleToolsUserConfig;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateRuntimeResult {
|
|
21
|
+
runtime: PTCRuntime;
|
|
22
|
+
registry: ToolRegistry;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create runtime and registry synchronously. Registers core/example adapters
|
|
26
|
+
* only when coreTools/exampleTools are provided (opt-in).
|
|
27
|
+
*/
|
|
28
|
+
export declare function createRuntimeFromConfigSync(options?: CreateRuntimeOptions): CreateRuntimeResult;
|
|
29
|
+
/**
|
|
30
|
+
* Create runtime and registry asynchronously. When projectPath is set, can load
|
|
31
|
+
* tools from project (e.g. MCP, skills); for now behaves like sync.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createRuntimeFromConfig(options?: CreateRuntimeOptions): Promise<CreateRuntimeResult>;
|
|
34
|
+
//# sourceMappingURL=runtimeFromConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeFromConfig.d.ts","sourceRoot":"","sources":["../../src/api/runtimeFromConfig.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAG3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,oEAAoE;IACpE,YAAY,CAAC,EAAE,sBAAsB,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CAuBnG;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAE9B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk6F5JHLZ7_cjs = require('./chunk-6F5JHLZ7.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "CORE_TOOL_SCHEMAS", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunk6F5JHLZ7_cjs.CORE_TOOL_SCHEMAS; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "enrichSpecWithCanonicalSchema", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunk6F5JHLZ7_cjs.enrichSpecWithCanonicalSchema; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "isGenericSchema", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunk6F5JHLZ7_cjs.isGenericSchema; }
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=canonicalCoreSchemas-CTW6CCFY.cjs.map
|
|
20
|
+
//# sourceMappingURL=canonicalCoreSchemas-CTW6CCFY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"canonicalCoreSchemas-CTW6CCFY.cjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"canonicalCoreSchemas-YLHVHYJZ.js"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/types/ToolSpec.ts
|
|
1
|
+
// src/core/types/ToolSpec.ts
|
|
2
2
|
var DEFAULT_INPUT_SCHEMA = {
|
|
3
3
|
type: "object",
|
|
4
4
|
additionalProperties: true
|
|
@@ -24,5 +24,5 @@ function createToolSpec(opts) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export { DEFAULT_INPUT_SCHEMA, DEFAULT_OUTPUT_SCHEMA, createToolSpec };
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-5SWSNVMI.js.map
|
|
28
|
+
//# sourceMappingURL=chunk-5SWSNVMI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/types/ToolSpec.ts"],"names":[],"mappings":";AAmFO,IAAM,oBAAA,GAA+B;AAAA,EAC1C,IAAA,EAAM,QAAA;AAAA,EACN,oBAAA,EAAsB;AACxB;AAGO,IAAM,qBAAA,GAAgC;AAAA,EAC3C,IAAA,EAAM,QAAA;AAAA,EACN,oBAAA,EAAsB;AACxB;AA2BO,SAAS,eAAe,IAAA,EAAuC;AACpE,EAAA,MAAM,UAAA,GAAa,KAAK,UAAA,IAAc,MAAA;AACtC,EAAA,OAAO;AAAA,IACL,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,OAAA,EAAS,KAAK,OAAA,IAAW,OAAA;AAAA,IACzB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,aAAa,IAAA,CAAK,WAAA;AAAA,IAClB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,WAAA,EAAa,KAAK,WAAA,IAAe,oBAAA;AAAA,IACjC,YAAA,EAAc,KAAK,YAAA,IAAgB,qBAAA;AAAA,IACnC,cAAc,IAAA,CAAK,YAAA;AAAA,IACnB,WAAW,IAAA,CAAK,SAAA;AAAA,IAChB,KAAA,EAAO,EAAE,IAAA,EAAM,EAAE,YAAW;AAAE,GAChC;AACF","file":"chunk-5SWSNVMI.js","sourcesContent":["/**\n * Unified tool kinds supported by the tools package.\n */\nexport type ToolKind = \"mcp\" | \"langchain\" | \"n8n\" | \"comfyui\" | \"skill\" | \"function\" | \"core\" | \"example\";\n\n/**\n * Capability declarations for tools.\n * Used by PolicyEngine for permission gating.\n */\nexport type Capability =\n | \"read:web\"\n | \"read:fs\"\n | \"write:fs\"\n | \"read:db\"\n | \"write:db\"\n | \"network\"\n | \"gpu\"\n | \"workflow\"\n | \"danger:destructive\"\n | \"exec\";\n\n/**\n * HITL (Human-in-the-Loop) side-effect classification.\n * Used to gate execution: external_write / destructive require human approval when onApprovalRequired is set.\n */\nexport type HitlSideEffect = \"none\" | \"local_write\" | \"external_write\" | \"destructive\";\n\n/**\n * Cost hints for tools, used by Budget and routing.\n */\nexport interface CostHints {\n latencyMsP50?: number;\n latencyMsP95?: number;\n isAsync?: boolean;\n}\n\n/**\n * Unified tool specification.\n * All tool types (MCP, LangChain, n8n, SKILL) are described by this interface.\n *\n * Safety: each tool declares capabilities (permission gating) and _meta.hitl.sideEffect\n * (HITL approval for external_write/destructive). Caller uses these to decide handling.\n */\nexport interface ToolSpec {\n /** Globally unique name, recommended format: namespace/name */\n name: string;\n /** Semver version */\n version: string;\n /** Tool kind determines which adapter handles execution */\n kind: ToolKind;\n\n description?: string;\n tags?: string[];\n\n /** JSON Schema for input validation */\n inputSchema: object;\n /** JSON Schema for output validation */\n outputSchema: object;\n\n /** Required capabilities for this tool (safety: PolicyEngine gates by ExecContext.permissions) */\n capabilities: Capability[];\n costHints?: CostHints;\n\n /** HITL and adapter-specific metadata. Adapters may use _meta.sourcePath, _meta.exportName, _meta.projectPath (function), etc. */\n _meta?: {\n hitl?: { sideEffect?: HitlSideEffect };\n /** Function kind: path to source file relative to projectPath */\n sourcePath?: string;\n /** Function kind: export name of the handler */\n exportName?: string;\n /** Function/skill kind: project root for resolving sourcePath */\n projectPath?: string;\n };\n\n /** Adapter-specific: endpoint URL (MCP/n8n) */\n endpoint?: string;\n /** Adapter-specific: resource identifier (workflowId, promptId, etc.) */\n resourceId?: string;\n /** Adapter-specific: implementation reference (LangChain Tool instance, skill handler) */\n impl?: unknown;\n}\n\n/** Default permissive input schema when not provided (framework supports auto-derived schema). */\nexport const DEFAULT_INPUT_SCHEMA: object = {\n type: \"object\",\n additionalProperties: true,\n};\n\n/** Default permissive output schema when not provided (framework supports auto-derived schema). */\nexport const DEFAULT_OUTPUT_SCHEMA: object = {\n type: \"object\",\n additionalProperties: true,\n};\n\n/**\n * Minimal options to build a ToolSpec. Use with @effect in JSDoc for HITL sideEffect.\n * Framework fills _meta.hitl.sideEffect from the sideEffect parameter (matches @effect annotation).\n * inputSchema/outputSchema are optional: when omitted, permissive defaults are used (framework supports auto-derived schema at build time in scan/mcp-build).\n */\nexport interface CreateToolSpecOptions {\n name: string;\n version?: string;\n kind: ToolKind;\n description?: string;\n tags?: string[];\n /** Optional: when omitted, DEFAULT_INPUT_SCHEMA is used. Codegen can derive from handler params. */\n inputSchema?: object;\n /** Optional: when omitted, DEFAULT_OUTPUT_SCHEMA is used. Codegen can derive from handler return type. */\n outputSchema?: object;\n capabilities: Capability[];\n costHints?: CostHints;\n /** HITL: from @effect annotation (none | local_write | external_write | destructive). Default \"none\". */\n sideEffect?: HitlSideEffect;\n}\n\n/**\n * Build a ToolSpec from minimal options. Use @effect in handler JSDoc as annotation; pass same value as sideEffect.\n * When inputSchema/outputSchema are omitted, permissive defaults are used (schema can be auto-derived at build time).\n */\nexport function createToolSpec(opts: CreateToolSpecOptions): ToolSpec {\n const sideEffect = opts.sideEffect ?? \"none\";\n return {\n name: opts.name,\n version: opts.version ?? \"1.0.0\",\n kind: opts.kind,\n description: opts.description,\n tags: opts.tags,\n inputSchema: opts.inputSchema ?? DEFAULT_INPUT_SCHEMA,\n outputSchema: opts.outputSchema ?? DEFAULT_OUTPUT_SCHEMA,\n capabilities: opts.capabilities,\n costHints: opts.costHints,\n _meta: { hitl: { sideEffect } },\n };\n}\n\n/**\n * Unified adapter interface.\n * Each tool kind has its own invoke path; PTCRuntime looks up adapter by spec.kind and calls adapter.invoke(spec, args, ctx).\n * Implementations: core/example (extensions), mcp (MCPClientAdapter); function/skill/n8n/langchain in-process adapters TBD (see tools/README and ToolTypeHandler).\n */\nexport interface ToolAdapter {\n kind: ToolKind;\n /** Optional: supports dynamic tool discovery */\n listTools?(): Promise<ToolSpec[]>;\n /** Execute the tool with validated args */\n invoke(\n spec: ToolSpec,\n args: unknown,\n ctx: import(\"./ToolIntent.js\").ExecContext,\n ): Promise<{ result: unknown; raw?: unknown }>;\n}\n"]}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/tools/util/canonicalCoreSchemas.ts
|
|
4
|
+
var S = (o) => o;
|
|
5
|
+
var CORE_TOOL_SCHEMAS = {
|
|
6
|
+
"core/fs.readText": {
|
|
7
|
+
inputSchema: S({
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
path: { type: "string", description: "Path to the file (within sandbox)" },
|
|
11
|
+
maxBytes: { type: "number", description: "Max bytes to read (optional)" }
|
|
12
|
+
},
|
|
13
|
+
required: ["path"],
|
|
14
|
+
additionalProperties: false
|
|
15
|
+
}),
|
|
16
|
+
outputSchema: S({
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
result: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
path: { type: "string" },
|
|
23
|
+
text: { type: "string" },
|
|
24
|
+
bytes: { type: "number" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
"core/fs.writeText": {
|
|
31
|
+
inputSchema: S({
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
path: { type: "string", description: "Path to write (within sandbox)" },
|
|
35
|
+
content: { type: "string", description: "UTF-8 content to write" }
|
|
36
|
+
},
|
|
37
|
+
required: ["path", "content"],
|
|
38
|
+
additionalProperties: false
|
|
39
|
+
})
|
|
40
|
+
},
|
|
41
|
+
"core/fs.listDir": {
|
|
42
|
+
inputSchema: S({
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: {
|
|
45
|
+
path: { type: "string", description: "Directory path (within sandbox)" },
|
|
46
|
+
maxEntries: { type: "number", description: "Max entries to return (optional)" }
|
|
47
|
+
},
|
|
48
|
+
required: ["path"],
|
|
49
|
+
additionalProperties: false
|
|
50
|
+
})
|
|
51
|
+
},
|
|
52
|
+
"core/fs.searchText": {
|
|
53
|
+
inputSchema: S({
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
path: { type: "string", description: "Path to file or directory" },
|
|
57
|
+
pattern: { type: "string", description: "Search pattern (regex or literal)" },
|
|
58
|
+
maxMatches: { type: "number", description: "Max matches (optional)" }
|
|
59
|
+
},
|
|
60
|
+
required: ["path", "pattern"],
|
|
61
|
+
additionalProperties: false
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
"core/fs.sha256": {
|
|
65
|
+
inputSchema: S({
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
path: { type: "string", description: "Path to file (within sandbox)" }
|
|
69
|
+
},
|
|
70
|
+
required: ["path"],
|
|
71
|
+
additionalProperties: false
|
|
72
|
+
})
|
|
73
|
+
},
|
|
74
|
+
"core/fs.deletePath": {
|
|
75
|
+
inputSchema: S({
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
path: { type: "string", description: "Path to delete (within sandbox)" }
|
|
79
|
+
},
|
|
80
|
+
required: ["path"],
|
|
81
|
+
additionalProperties: false
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
"core/http.fetchText": {
|
|
85
|
+
inputSchema: S({
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {
|
|
88
|
+
url: { type: "string", description: "URL to fetch" },
|
|
89
|
+
headers: { type: "object", additionalProperties: { type: "string" }, description: "Optional request headers" },
|
|
90
|
+
timeoutMs: { type: "number", description: "Request timeout in ms (optional)" }
|
|
91
|
+
},
|
|
92
|
+
required: ["url"],
|
|
93
|
+
additionalProperties: false
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
"core/http.fetchJson": {
|
|
97
|
+
inputSchema: S({
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
url: { type: "string", description: "URL to fetch" },
|
|
101
|
+
headers: { type: "object", additionalProperties: { type: "string" } }
|
|
102
|
+
},
|
|
103
|
+
required: ["url"],
|
|
104
|
+
additionalProperties: false
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
"core/http.downloadFile": {
|
|
108
|
+
inputSchema: S({
|
|
109
|
+
type: "object",
|
|
110
|
+
properties: {
|
|
111
|
+
url: { type: "string", description: "URL to download" },
|
|
112
|
+
destPath: { type: "string", description: "Destination path (within sandbox)" },
|
|
113
|
+
headers: { type: "object", additionalProperties: { type: "string" } }
|
|
114
|
+
},
|
|
115
|
+
required: ["url", "destPath"],
|
|
116
|
+
additionalProperties: false
|
|
117
|
+
})
|
|
118
|
+
},
|
|
119
|
+
"core/http.head": {
|
|
120
|
+
inputSchema: S({
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: {
|
|
123
|
+
url: { type: "string", description: "URL for HEAD request" }
|
|
124
|
+
},
|
|
125
|
+
required: ["url"],
|
|
126
|
+
additionalProperties: false
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
"core/http.duckduckgoSearch": {
|
|
130
|
+
inputSchema: S({
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: {
|
|
133
|
+
query: { type: "string", description: "Search query" },
|
|
134
|
+
maxResults: { type: "number", description: "Max results (optional)" }
|
|
135
|
+
},
|
|
136
|
+
required: ["query"],
|
|
137
|
+
additionalProperties: false
|
|
138
|
+
})
|
|
139
|
+
},
|
|
140
|
+
"core/http.fetchPageMainContent": {
|
|
141
|
+
inputSchema: S({
|
|
142
|
+
type: "object",
|
|
143
|
+
properties: {
|
|
144
|
+
url: { type: "string", description: "Page URL" },
|
|
145
|
+
maxLength: { type: "number", description: "Max content length (optional)" }
|
|
146
|
+
},
|
|
147
|
+
required: ["url"],
|
|
148
|
+
additionalProperties: false
|
|
149
|
+
})
|
|
150
|
+
},
|
|
151
|
+
"core/util.json.select": {
|
|
152
|
+
inputSchema: S({
|
|
153
|
+
type: "object",
|
|
154
|
+
properties: {
|
|
155
|
+
json: { description: "JSON value (object or string)" },
|
|
156
|
+
selector: { type: "string", description: "JSONPath or selector" }
|
|
157
|
+
},
|
|
158
|
+
required: ["json", "selector"],
|
|
159
|
+
additionalProperties: false
|
|
160
|
+
})
|
|
161
|
+
},
|
|
162
|
+
"core/util.text.truncate": {
|
|
163
|
+
inputSchema: S({
|
|
164
|
+
type: "object",
|
|
165
|
+
properties: {
|
|
166
|
+
text: { type: "string", description: "Text to truncate" },
|
|
167
|
+
maxLength: { type: "number", description: "Max length" }
|
|
168
|
+
},
|
|
169
|
+
required: ["text", "maxLength"],
|
|
170
|
+
additionalProperties: false
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
"core/util.hash.sha256Text": {
|
|
174
|
+
inputSchema: S({
|
|
175
|
+
type: "object",
|
|
176
|
+
properties: {
|
|
177
|
+
text: { type: "string", description: "Text to hash" }
|
|
178
|
+
},
|
|
179
|
+
required: ["text"],
|
|
180
|
+
additionalProperties: false
|
|
181
|
+
})
|
|
182
|
+
},
|
|
183
|
+
"core/util.time.now": {
|
|
184
|
+
inputSchema: S({
|
|
185
|
+
type: "object",
|
|
186
|
+
properties: {
|
|
187
|
+
timezone: { type: "string", description: "IANA timezone (optional)" }
|
|
188
|
+
},
|
|
189
|
+
additionalProperties: false
|
|
190
|
+
})
|
|
191
|
+
},
|
|
192
|
+
"core/util.template.render": {
|
|
193
|
+
inputSchema: S({
|
|
194
|
+
type: "object",
|
|
195
|
+
properties: {
|
|
196
|
+
template: { type: "string", description: "Template string (e.g. Mustache)" },
|
|
197
|
+
data: { type: "object", description: "Data object for template" }
|
|
198
|
+
},
|
|
199
|
+
required: ["template", "data"],
|
|
200
|
+
additionalProperties: false
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
"core/exec.runCommand": {
|
|
204
|
+
inputSchema: S({
|
|
205
|
+
type: "object",
|
|
206
|
+
properties: {
|
|
207
|
+
command: { type: "string", description: "Command to run" },
|
|
208
|
+
args: { type: "array", items: { type: "string" }, description: "Arguments (optional)" },
|
|
209
|
+
cwd: { type: "string", description: "Working directory (optional)" },
|
|
210
|
+
timeoutMs: { type: "number", description: "Timeout in ms (optional)" }
|
|
211
|
+
},
|
|
212
|
+
required: ["command"],
|
|
213
|
+
additionalProperties: false
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
function isGenericSchema(schema) {
|
|
218
|
+
if (schema === null || typeof schema !== "object") return false;
|
|
219
|
+
const s = schema;
|
|
220
|
+
if (s.type !== "object") return false;
|
|
221
|
+
if (s.additionalProperties === true && !s.properties) return true;
|
|
222
|
+
if (s.properties === void 0 && s.required === void 0) return true;
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
function enrichSpecWithCanonicalSchema(spec) {
|
|
226
|
+
if (spec.kind !== "core") return spec;
|
|
227
|
+
const canonical = CORE_TOOL_SCHEMAS[spec.name];
|
|
228
|
+
if (!canonical) return spec;
|
|
229
|
+
const useInput = isGenericSchema(spec.inputSchema) ? canonical.inputSchema : spec.inputSchema;
|
|
230
|
+
const useOutput = canonical.outputSchema && isGenericSchema(spec.outputSchema) ? canonical.outputSchema : spec.outputSchema;
|
|
231
|
+
if (useInput === spec.inputSchema && useOutput === spec.outputSchema) return spec;
|
|
232
|
+
return {
|
|
233
|
+
...spec,
|
|
234
|
+
inputSchema: useInput,
|
|
235
|
+
outputSchema: useOutput
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
exports.CORE_TOOL_SCHEMAS = CORE_TOOL_SCHEMAS;
|
|
240
|
+
exports.enrichSpecWithCanonicalSchema = enrichSpecWithCanonicalSchema;
|
|
241
|
+
exports.isGenericSchema = isGenericSchema;
|
|
242
|
+
//# sourceMappingURL=chunk-6F5JHLZ7.cjs.map
|
|
243
|
+
//# sourceMappingURL=chunk-6F5JHLZ7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools/util/canonicalCoreSchemas.ts"],"names":[],"mappings":";;;AAQA,IAAM,CAAA,GAAI,CAAC,CAAA,KAAc,CAAA;AAGlB,IAAM,iBAAA,GAGT;AAAA,EACF,kBAAA,EAAoB;AAAA,IAClB,aAAa,CAAA,CAAE;AAAA,MACb,IAAA,EAAM,QAAA;AAAA,MACN,UAAA,EAAY;AAAA,QACV,IAAA,EAAM,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,mCAAA,EAAoC;AAAA,QACzE,QAAA,EAAU,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,8BAAA;AAA+B,OAC1E;AAAA,MACA,QAAA,EAAU,C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,YAAA,GACV,IAAA,CAAK,YAAA;AACX,EAAA,IAAI,aAAa,IAAA,CAAK,WAAA,IAAe,SAAA,KAAc,IAAA,CAAK,cAAc,OAAO,IAAA;AAC7E,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,WAAA,EAAa,QAAA;AAAA,IACb,YAAA,EAAc;AAAA,GAChB;AACF","file":"chunk-6F5JHLZ7.cjs","sourcesContent":["/**\n * Canonical input/output schemas for core (builtin) tools.\n * Used when the builtin package registers specs with generic schema\n * (type: object, additionalProperties: true) so CLI describe and OpenAPI show real schemas.\n */\n\nimport type { ToolSpec } from \"../../core/types/ToolSpec.js\";\n\nconst S = (o: object) => o as Record<string, unknown>;\n\n/** Canonical inputSchema (and optional outputSchema) by tool name (e.g. core/fs.readText). */\nexport const CORE_TOOL_SCHEMAS: Record<\n string,\n { inputSchema: object; outputSchema?: object }\n> = {\n \"core/fs.readText\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Path to the file (within sandbox)\" },\n maxBytes: { type: \"number\", description: \"Max bytes to read (optional)\" },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n outputSchema: S({\n type: \"object\",\n properties: {\n result: {\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n text: { type: \"string\" },\n bytes: { type: \"number\" },\n },\n },\n },\n }),\n },\n \"core/fs.writeText\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Path to write (within sandbox)\" },\n content: { type: \"string\", description: \"UTF-8 content to write\" },\n },\n required: [\"path\", \"content\"],\n additionalProperties: false,\n }),\n },\n \"core/fs.listDir\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Directory path (within sandbox)\" },\n maxEntries: { type: \"number\", description: \"Max entries to return (optional)\" },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n },\n \"core/fs.searchText\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Path to file or directory\" },\n pattern: { type: \"string\", description: \"Search pattern (regex or literal)\" },\n maxMatches: { type: \"number\", description: \"Max matches (optional)\" },\n },\n required: [\"path\", \"pattern\"],\n additionalProperties: false,\n }),\n },\n \"core/fs.sha256\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Path to file (within sandbox)\" },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n },\n \"core/fs.deletePath\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Path to delete (within sandbox)\" },\n },\n required: [\"path\"],\n additionalProperties: false,\n }),\n },\n \"core/http.fetchText\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"URL to fetch\" },\n headers: { type: \"object\", additionalProperties: { type: \"string\" }, description: \"Optional request headers\" },\n timeoutMs: { type: \"number\", description: \"Request timeout in ms (optional)\" },\n },\n required: [\"url\"],\n additionalProperties: false,\n }),\n },\n \"core/http.fetchJson\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"URL to fetch\" },\n headers: { type: \"object\", additionalProperties: { type: \"string\" } },\n },\n required: [\"url\"],\n additionalProperties: false,\n }),\n },\n \"core/http.downloadFile\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"URL to download\" },\n destPath: { type: \"string\", description: \"Destination path (within sandbox)\" },\n headers: { type: \"object\", additionalProperties: { type: \"string\" } },\n },\n required: [\"url\", \"destPath\"],\n additionalProperties: false,\n }),\n },\n \"core/http.head\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"URL for HEAD request\" },\n },\n required: [\"url\"],\n additionalProperties: false,\n }),\n },\n \"core/http.duckduckgoSearch\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n query: { type: \"string\", description: \"Search query\" },\n maxResults: { type: \"number\", description: \"Max results (optional)\" },\n },\n required: [\"query\"],\n additionalProperties: false,\n }),\n },\n \"core/http.fetchPageMainContent\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"Page URL\" },\n maxLength: { type: \"number\", description: \"Max content length (optional)\" },\n },\n required: [\"url\"],\n additionalProperties: false,\n }),\n },\n \"core/util.json.select\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n json: { description: \"JSON value (object or string)\" },\n selector: { type: \"string\", description: \"JSONPath or selector\" },\n },\n required: [\"json\", \"selector\"],\n additionalProperties: false,\n }),\n },\n \"core/util.text.truncate\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"Text to truncate\" },\n maxLength: { type: \"number\", description: \"Max length\" },\n },\n required: [\"text\", \"maxLength\"],\n additionalProperties: false,\n }),\n },\n \"core/util.hash.sha256Text\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"Text to hash\" },\n },\n required: [\"text\"],\n additionalProperties: false,\n }),\n },\n \"core/util.time.now\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n timezone: { type: \"string\", description: \"IANA timezone (optional)\" },\n },\n additionalProperties: false,\n }),\n },\n \"core/util.template.render\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n template: { type: \"string\", description: \"Template string (e.g. Mustache)\" },\n data: { type: \"object\", description: \"Data object for template\" },\n },\n required: [\"template\", \"data\"],\n additionalProperties: false,\n }),\n },\n \"core/exec.runCommand\": {\n inputSchema: S({\n type: \"object\",\n properties: {\n command: { type: \"string\", description: \"Command to run\" },\n args: { type: \"array\", items: { type: \"string\" }, description: \"Arguments (optional)\" },\n cwd: { type: \"string\", description: \"Working directory (optional)\" },\n timeoutMs: { type: \"number\", description: \"Timeout in ms (optional)\" },\n },\n required: [\"command\"],\n additionalProperties: false,\n }),\n },\n};\n\n/** True if schema looks like the generic permissive one. */\nexport function isGenericSchema(schema: unknown): boolean {\n if (schema === null || typeof schema !== \"object\") return false;\n const s = schema as Record<string, unknown>;\n if (s.type !== \"object\") return false;\n if (s.additionalProperties === true && !s.properties) return true;\n if (s.properties === undefined && s.required === undefined) return true;\n return false;\n}\n\n/**\n * If spec is a core tool with generic input/output schema, return spec with canonical schema.\n * Otherwise return spec unchanged.\n */\nexport function enrichSpecWithCanonicalSchema(spec: ToolSpec): ToolSpec {\n if (spec.kind !== \"core\") return spec;\n const canonical = CORE_TOOL_SCHEMAS[spec.name];\n if (!canonical) return spec;\n const useInput = isGenericSchema(spec.inputSchema) ? canonical.inputSchema : spec.inputSchema;\n const useOutput =\n canonical.outputSchema && isGenericSchema(spec.outputSchema)\n ? canonical.outputSchema\n : spec.outputSchema;\n if (useInput === spec.inputSchema && useOutput === spec.outputSchema) return spec;\n return {\n ...spec,\n inputSchema: useInput,\n outputSchema: useOutput,\n };\n}\n"]}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import pRetry from 'p-retry';
|
|
2
|
+
|
|
3
|
+
// src/core/registry/ToolRegistry.ts
|
|
4
|
+
var ToolRegistry = class {
|
|
5
|
+
tools = /* @__PURE__ */ new Map();
|
|
6
|
+
tagIndex = /* @__PURE__ */ new Map();
|
|
7
|
+
// tag → tool names
|
|
8
|
+
kindIndex = /* @__PURE__ */ new Map();
|
|
9
|
+
// kind → tool names
|
|
10
|
+
/**
|
|
11
|
+
* Register a single tool spec.
|
|
12
|
+
* Overwrites if same name already exists.
|
|
13
|
+
*/
|
|
14
|
+
register(spec) {
|
|
15
|
+
this.validateSpec(spec);
|
|
16
|
+
this.tools.set(spec.name, spec);
|
|
17
|
+
this.indexTool(spec);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Register multiple tool specs at once.
|
|
21
|
+
*/
|
|
22
|
+
bulkRegister(specs) {
|
|
23
|
+
for (const spec of specs) {
|
|
24
|
+
this.register(spec);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Unregister a tool by name.
|
|
29
|
+
*/
|
|
30
|
+
unregister(name) {
|
|
31
|
+
const spec = this.tools.get(name);
|
|
32
|
+
if (!spec) return false;
|
|
33
|
+
this.tools.delete(name);
|
|
34
|
+
this.deindexTool(spec);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get a tool spec by name.
|
|
39
|
+
*/
|
|
40
|
+
get(name) {
|
|
41
|
+
return this.tools.get(name);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a tool exists.
|
|
45
|
+
*/
|
|
46
|
+
has(name) {
|
|
47
|
+
return this.tools.has(name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Search tools by query.
|
|
51
|
+
*/
|
|
52
|
+
search(query) {
|
|
53
|
+
let candidates;
|
|
54
|
+
if (query.kind) {
|
|
55
|
+
const names = this.kindIndex.get(query.kind);
|
|
56
|
+
if (!names || names.size === 0) return [];
|
|
57
|
+
candidates = [...names].map((n) => this.tools.get(n)).filter((s) => s !== void 0);
|
|
58
|
+
} else {
|
|
59
|
+
candidates = [...this.tools.values()];
|
|
60
|
+
}
|
|
61
|
+
if (query.tags && query.tags.length > 0) {
|
|
62
|
+
candidates = candidates.filter(
|
|
63
|
+
(spec) => query.tags.some((tag) => spec.tags?.includes(tag))
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (query.capabilities && query.capabilities.length > 0) {
|
|
67
|
+
candidates = candidates.filter(
|
|
68
|
+
(spec) => query.capabilities.every((cap) => spec.capabilities.includes(cap))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (query.text) {
|
|
72
|
+
const lower = query.text.toLowerCase();
|
|
73
|
+
candidates = candidates.filter(
|
|
74
|
+
(spec) => spec.name.toLowerCase().includes(lower) || spec.description?.toLowerCase().includes(lower) || spec.tags?.some((t) => t.toLowerCase().includes(lower))
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return candidates;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* List all registered tool names.
|
|
81
|
+
*/
|
|
82
|
+
list() {
|
|
83
|
+
return [...this.tools.keys()];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get count of registered tools.
|
|
87
|
+
*/
|
|
88
|
+
get size() {
|
|
89
|
+
return this.tools.size;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Export a snapshot of all registered tools (for debugging/routing).
|
|
93
|
+
*/
|
|
94
|
+
snapshot() {
|
|
95
|
+
return [...this.tools.values()];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Clear all registered tools.
|
|
99
|
+
*/
|
|
100
|
+
clear() {
|
|
101
|
+
this.tools.clear();
|
|
102
|
+
this.tagIndex.clear();
|
|
103
|
+
this.kindIndex.clear();
|
|
104
|
+
}
|
|
105
|
+
validateSpec(spec) {
|
|
106
|
+
if (!spec.name) throw new Error("ToolSpec.name is required");
|
|
107
|
+
if (!spec.version) throw new Error("ToolSpec.version is required");
|
|
108
|
+
if (!spec.kind) throw new Error("ToolSpec.kind is required");
|
|
109
|
+
if (!spec.inputSchema) throw new Error("ToolSpec.inputSchema is required");
|
|
110
|
+
if (!spec.outputSchema) throw new Error("ToolSpec.outputSchema is required");
|
|
111
|
+
if (!spec.capabilities) throw new Error("ToolSpec.capabilities is required");
|
|
112
|
+
}
|
|
113
|
+
indexTool(spec) {
|
|
114
|
+
let kindSet = this.kindIndex.get(spec.kind);
|
|
115
|
+
if (!kindSet) {
|
|
116
|
+
kindSet = /* @__PURE__ */ new Set();
|
|
117
|
+
this.kindIndex.set(spec.kind, kindSet);
|
|
118
|
+
}
|
|
119
|
+
kindSet.add(spec.name);
|
|
120
|
+
if (spec.tags) {
|
|
121
|
+
for (const tag of spec.tags) {
|
|
122
|
+
let tagSet = this.tagIndex.get(tag);
|
|
123
|
+
if (!tagSet) {
|
|
124
|
+
tagSet = /* @__PURE__ */ new Set();
|
|
125
|
+
this.tagIndex.set(tag, tagSet);
|
|
126
|
+
}
|
|
127
|
+
tagSet.add(spec.name);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
deindexTool(spec) {
|
|
132
|
+
this.kindIndex.get(spec.kind)?.delete(spec.name);
|
|
133
|
+
if (spec.tags) {
|
|
134
|
+
for (const tag of spec.tags) {
|
|
135
|
+
this.tagIndex.get(tag)?.delete(spec.name);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var NON_RETRYABLE_ERRORS = /* @__PURE__ */ new Set([
|
|
141
|
+
"TOOL_NOT_FOUND",
|
|
142
|
+
"INPUT_SCHEMA_INVALID",
|
|
143
|
+
"POLICY_DENIED",
|
|
144
|
+
"HITL_DENIED",
|
|
145
|
+
"OUTPUT_SCHEMA_INVALID",
|
|
146
|
+
"PATH_OUTSIDE_SANDBOX",
|
|
147
|
+
"FILE_TOO_LARGE",
|
|
148
|
+
"HTTP_DISALLOWED_HOST",
|
|
149
|
+
"HTTP_TOO_LARGE",
|
|
150
|
+
"EXEC_INVALID",
|
|
151
|
+
"EXEC_SPAWN_ERROR",
|
|
152
|
+
"DUCKDUCKGO_INVALID"
|
|
153
|
+
]);
|
|
154
|
+
function isRetryable(error) {
|
|
155
|
+
if (error instanceof Error) {
|
|
156
|
+
const kind = error.kind;
|
|
157
|
+
if (kind && NON_RETRYABLE_ERRORS.has(kind)) return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
async function withRetry(fn, options = {}) {
|
|
162
|
+
const {
|
|
163
|
+
maxRetries = 2,
|
|
164
|
+
baseDelayMs = 1e3,
|
|
165
|
+
maxDelayMs = 1e4,
|
|
166
|
+
jitter = 0.1,
|
|
167
|
+
shouldRetry,
|
|
168
|
+
onRetry
|
|
169
|
+
} = options;
|
|
170
|
+
if (maxRetries <= 0) {
|
|
171
|
+
return fn();
|
|
172
|
+
}
|
|
173
|
+
const pRetryOptions = {
|
|
174
|
+
retries: maxRetries,
|
|
175
|
+
minTimeout: baseDelayMs,
|
|
176
|
+
maxTimeout: maxDelayMs,
|
|
177
|
+
randomize: true,
|
|
178
|
+
factor: 2,
|
|
179
|
+
onFailedAttempt: (error) => {
|
|
180
|
+
if (jitter > 0 && error.retriesLeft > 0) ;
|
|
181
|
+
if (shouldRetry && !shouldRetry(error)) {
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
if (!isRetryable(error)) {
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
onRetry?.(error, maxRetries - error.retriesLeft);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
return pRetry(fn, pRetryOptions);
|
|
191
|
+
}
|
|
192
|
+
function createTaggedError(kind, message, details) {
|
|
193
|
+
const error = new Error(message);
|
|
194
|
+
error.kind = kind;
|
|
195
|
+
error.details = details;
|
|
196
|
+
return error;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { ToolRegistry, createTaggedError, isRetryable, withRetry };
|
|
200
|
+
//# sourceMappingURL=chunk-AE6FSNGY.js.map
|
|
201
|
+
//# sourceMappingURL=chunk-AE6FSNGY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/registry/ToolRegistry.ts","../src/core/runtime/Retry.ts"],"names":[],"mappings":";;;AAoBO,IAAM,eAAN,MAAmB;AAAA,EACP,KAAA,uBAAY,GAAA,EAAsB;AAAA,EAClC,QAAA,uBAAe,GAAA,EAAyB;AAAA;AAAA,EACxC,SAAA,uBAAgB,GAAA,EAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM5D,SAAS,IAAA,EAAsB;AAC7B,IAAA,IAAA,CAAK,aAAa,IAAI,CAAA;AACtB,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,IAAA,CAAK,IAAA,EAAM,IAAI,CAAA;AAC9B,IAAA,IAAA,CAAK,UAAU,IAAI,CAAA;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,KAAA,EAAyB;AACpC,IAAA,KAAA,MAAW,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js","sourcesContent":["import type { Capability, ToolKind, ToolSpec } from \"../types/ToolSpec.js\";\n\n/**\n * Search query for tools.\n */\nexport interface ToolSearchQuery {\n /** Text search in name/description/tags */\n text?: string;\n /** Filter by tool kind */\n kind?: ToolKind;\n /** Filter by required capabilities */\n capabilities?: Capability[];\n /** Filter by tags */\n tags?: string[];\n}\n\n/**\n * Tool Registry: manages tool registration, lookup, and search.\n * Supports both static registration and dynamic discovery via adapters.\n */\nexport class ToolRegistry {\n private readonly tools = new Map<string, ToolSpec>();\n private readonly tagIndex = new Map<string, Set<string>>(); // tag → tool names\n private readonly kindIndex = new Map<ToolKind, Set<string>>(); // kind → tool names\n\n /**\n * Register a single tool spec.\n * Overwrites if same name already exists.\n */\n register(spec: ToolSpec): void {\n this.validateSpec(spec);\n this.tools.set(spec.name, spec);\n this.indexTool(spec);\n }\n\n /**\n * Register multiple tool specs at once.\n */\n bulkRegister(specs: ToolSpec[]): void {\n for (const spec of specs) {\n this.register(spec);\n }\n }\n\n /**\n * Unregister a tool by name.\n */\n unregister(name: string): boolean {\n const spec = this.tools.get(name);\n if (!spec) return false;\n this.tools.delete(name);\n this.deindexTool(spec);\n return true;\n }\n\n /**\n * Get a tool spec by name.\n */\n get(name: string): ToolSpec | undefined {\n return this.tools.get(name);\n }\n\n /**\n * Check if a tool exists.\n */\n has(name: string): boolean {\n return this.tools.has(name);\n }\n\n /**\n * Search tools by query.\n */\n search(query: ToolSearchQuery): ToolSpec[] {\n let candidates: ToolSpec[];\n\n // Start with kind filter if specified (uses index)\n if (query.kind) {\n const names = this.kindIndex.get(query.kind);\n if (!names || names.size === 0) return [];\n candidates = [...names]\n .map((n) => this.tools.get(n))\n .filter((s): s is ToolSpec => s !== undefined);\n } else {\n candidates = [...this.tools.values()];\n }\n\n // Filter by tags (uses index for initial candidates if no kind filter)\n if (query.tags && query.tags.length > 0) {\n candidates = candidates.filter((spec) =>\n query.tags!.some((tag) => spec.tags?.includes(tag)),\n );\n }\n\n // Filter by capabilities\n if (query.capabilities && query.capabilities.length > 0) {\n candidates = candidates.filter((spec) =>\n query.capabilities!.every((cap) => spec.capabilities.includes(cap)),\n );\n }\n\n // Filter by text (name, description, tags)\n if (query.text) {\n const lower = query.text.toLowerCase();\n candidates = candidates.filter(\n (spec) =>\n spec.name.toLowerCase().includes(lower) ||\n spec.description?.toLowerCase().includes(lower) ||\n spec.tags?.some((t) => t.toLowerCase().includes(lower)),\n );\n }\n\n return candidates;\n }\n\n /**\n * List all registered tool names.\n */\n list(): string[] {\n return [...this.tools.keys()];\n }\n\n /**\n * Get count of registered tools.\n */\n get size(): number {\n return this.tools.size;\n }\n\n /**\n * Export a snapshot of all registered tools (for debugging/routing).\n */\n snapshot(): ToolSpec[] {\n return [...this.tools.values()];\n }\n\n /**\n * Clear all registered tools.\n */\n clear(): void {\n this.tools.clear();\n this.tagIndex.clear();\n this.kindIndex.clear();\n }\n\n private validateSpec(spec: ToolSpec): void {\n if (!spec.name) throw new Error(\"ToolSpec.name is required\");\n if (!spec.version) throw new Error(\"ToolSpec.version is required\");\n if (!spec.kind) throw new Error(\"ToolSpec.kind is required\");\n if (!spec.inputSchema) throw new Error(\"ToolSpec.inputSchema is required\");\n if (!spec.outputSchema) throw new Error(\"ToolSpec.outputSchema is required\");\n if (!spec.capabilities) throw new Error(\"ToolSpec.capabilities is required\");\n }\n\n private indexTool(spec: ToolSpec): void {\n // Kind index\n let kindSet = this.kindIndex.get(spec.kind);\n if (!kindSet) {\n kindSet = new Set();\n this.kindIndex.set(spec.kind, kindSet);\n }\n kindSet.add(spec.name);\n\n // Tag index\n if (spec.tags) {\n for (const tag of spec.tags) {\n let tagSet = this.tagIndex.get(tag);\n if (!tagSet) {\n tagSet = new Set();\n this.tagIndex.set(tag, tagSet);\n }\n tagSet.add(spec.name);\n }\n }\n }\n\n private deindexTool(spec: ToolSpec): void {\n this.kindIndex.get(spec.kind)?.delete(spec.name);\n if (spec.tags) {\n for (const tag of spec.tags) {\n this.tagIndex.get(tag)?.delete(spec.name);\n }\n }\n }\n}\n","import pRetry, { type Options as PRetryOptions } from \"p-retry\";\n\n/**\n * Retry configuration.\n */\nexport interface RetryOptions {\n /** Maximum number of retries (default: 2) */\n maxRetries?: number;\n /** Base delay in ms for exponential backoff (default: 1000) */\n baseDelayMs?: number;\n /** Maximum delay in ms (default: 10000) */\n maxDelayMs?: number;\n /** Jitter factor 0-1 (default: 0.1) */\n jitter?: number;\n /** Error filter: return true to retry, false to abort */\n shouldRetry?: (error: Error) => boolean;\n /** Callback on each retry attempt */\n onRetry?: (error: Error, attempt: number) => void;\n}\n\n/**\n * Default errors that should NOT be retried (deterministic failures).\n */\nconst NON_RETRYABLE_ERRORS = new Set([\n \"TOOL_NOT_FOUND\",\n \"INPUT_SCHEMA_INVALID\",\n \"POLICY_DENIED\",\n \"HITL_DENIED\",\n \"OUTPUT_SCHEMA_INVALID\",\n \"PATH_OUTSIDE_SANDBOX\",\n \"FILE_TOO_LARGE\",\n \"HTTP_DISALLOWED_HOST\",\n \"HTTP_TOO_LARGE\",\n \"EXEC_INVALID\",\n \"EXEC_SPAWN_ERROR\",\n \"DUCKDUCKGO_INVALID\",\n]);\n\n/**\n * Determine if an error is retryable.\n */\nexport function isRetryable(error: unknown): boolean {\n if (error instanceof Error) {\n const kind = (error as Error & { kind?: string }).kind;\n if (kind && NON_RETRYABLE_ERRORS.has(kind)) return false;\n }\n return true;\n}\n\n/**\n * Execute a function with retry logic using exponential backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: RetryOptions = {},\n): Promise<T> {\n const {\n maxRetries = 2,\n baseDelayMs = 1000,\n maxDelayMs = 10_000,\n jitter = 0.1,\n shouldRetry,\n onRetry,\n } = options;\n\n if (maxRetries <= 0) {\n return fn();\n }\n\n const pRetryOptions: PRetryOptions = {\n retries: maxRetries,\n minTimeout: baseDelayMs,\n maxTimeout: maxDelayMs,\n randomize: true,\n factor: 2,\n onFailedAttempt: (error) => {\n // Apply jitter\n if (jitter > 0 && error.retriesLeft > 0) {\n // jitterMs calculated but p-retry handles backoff internally\n void (Math.random() * jitter * baseDelayMs);\n }\n\n // Check if should retry\n if (shouldRetry && !shouldRetry(error)) {\n throw error; // Abort retry\n }\n\n if (!isRetryable(error)) {\n throw error; // Non-retryable error kind\n }\n\n onRetry?.(error, maxRetries - error.retriesLeft);\n },\n };\n\n return pRetry(fn, pRetryOptions);\n}\n\n/**\n * Create a tagged error with a kind field for retry classification.\n */\nexport function createTaggedError(\n kind: string,\n message: string,\n details?: unknown,\n): Error & { kind: string; details?: unknown } {\n const error = new Error(message) as Error & {\n kind: string;\n details?: unknown;\n };\n error.kind = kind;\n error.details = details;\n return error;\n}\n"]}
|