@easynet/agent-tool 1.0.0
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 +103 -0
- package/dist/chunk-3YLVPZRJ.cjs +32 -0
- package/dist/chunk-3YLVPZRJ.cjs.map +1 -0
- package/dist/chunk-AXUNV4MK.js +28 -0
- package/dist/chunk-AXUNV4MK.js.map +1 -0
- package/dist/chunk-BM4EVYI5.js +1069 -0
- package/dist/chunk-BM4EVYI5.js.map +1 -0
- package/dist/chunk-P3UEAZHK.cjs +171 -0
- package/dist/chunk-P3UEAZHK.cjs.map +1 -0
- package/dist/chunk-RPAMQCFH.js +167 -0
- package/dist/chunk-RPAMQCFH.js.map +1 -0
- package/dist/chunk-Z7TGIG77.cjs +1108 -0
- package/dist/chunk-Z7TGIG77.cjs.map +1 -0
- package/dist/cli.cjs +154 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +147 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen/build.d.ts +23 -0
- package/dist/codegen/build.d.ts.map +1 -0
- package/dist/codegen/generator.d.ts +15 -0
- package/dist/codegen/generator.d.ts.map +1 -0
- package/dist/codegen/index.d.ts +21 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/init.d.ts +17 -0
- package/dist/codegen/init.d.ts.map +1 -0
- package/dist/codegen/run.d.ts +19 -0
- package/dist/codegen/run.d.ts.map +1 -0
- package/dist/codegen/scan/scanN8n.d.ts +17 -0
- package/dist/codegen/scan/scanN8n.d.ts.map +1 -0
- package/dist/codegen/scan/scanSkill.d.ts +17 -0
- package/dist/codegen/scan/scanSkill.d.ts.map +1 -0
- package/dist/codegen/scan/scanTools.d.ts +31 -0
- package/dist/codegen/scan/scanTools.d.ts.map +1 -0
- package/dist/codegen/scan/scanner.d.ts +26 -0
- package/dist/codegen/scan/scanner.d.ts.map +1 -0
- package/dist/codegen/scan/schemaFromTs.d.ts +16 -0
- package/dist/codegen/scan/schemaFromTs.d.ts.map +1 -0
- package/dist/codegen/types.d.ts +81 -0
- package/dist/codegen/types.d.ts.map +1 -0
- package/dist/core.cjs +20 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +8 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/discovery/MCPProcessManager.d.ts +57 -0
- package/dist/discovery/MCPProcessManager.d.ts.map +1 -0
- package/dist/discovery/errors.d.ts +13 -0
- package/dist/discovery/errors.d.ts.map +1 -0
- package/dist/discovery/load/LangChainLoader.d.ts +7 -0
- package/dist/discovery/load/LangChainLoader.d.ts.map +1 -0
- package/dist/discovery/load/MCPLoader.d.ts +8 -0
- package/dist/discovery/load/MCPLoader.d.ts.map +1 -0
- package/dist/discovery/load/N8nLoader.d.ts +25 -0
- package/dist/discovery/load/N8nLoader.d.ts.map +1 -0
- package/dist/discovery/load/SkillLoader.d.ts +20 -0
- package/dist/discovery/load/SkillLoader.d.ts.map +1 -0
- package/dist/discovery/load/SkillManifest.d.ts +79 -0
- package/dist/discovery/load/SkillManifest.d.ts.map +1 -0
- package/dist/discovery/load/SkillMdParser.d.ts +31 -0
- package/dist/discovery/load/SkillMdParser.d.ts.map +1 -0
- package/dist/discovery/load/index.d.ts +6 -0
- package/dist/discovery/load/index.d.ts.map +1 -0
- package/dist/discovery/load/resolveEntry.d.ts +7 -0
- package/dist/discovery/load/resolveEntry.d.ts.map +1 -0
- package/dist/discovery/scan/DirectoryScanner.d.ts +37 -0
- package/dist/discovery/scan/DirectoryScanner.d.ts.map +1 -0
- package/dist/discovery/scan/scanUtil.d.ts +16 -0
- package/dist/discovery/scan/scanUtil.d.ts.map +1 -0
- package/dist/discovery/types.d.ts +99 -0
- package/dist/discovery/types.d.ts.map +1 -0
- package/dist/index.cjs +3014 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2778 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/AgentLLMAdapter.d.ts +27 -0
- package/dist/llm/AgentLLMAdapter.d.ts.map +1 -0
- package/dist/llm/LangChainToolsHub.d.ts +31 -0
- package/dist/llm/LangChainToolsHub.d.ts.map +1 -0
- package/dist/llm/OpenAICompatibleClient.d.ts +64 -0
- package/dist/llm/OpenAICompatibleClient.d.ts.map +1 -0
- package/dist/llm/ReActAgent.d.ts +35 -0
- package/dist/llm/ReActAgent.d.ts.map +1 -0
- package/dist/llm-export.cjs +20 -0
- package/dist/llm-export.cjs.map +1 -0
- package/dist/llm-export.d.ts +9 -0
- package/dist/llm-export.d.ts.map +1 -0
- package/dist/llm-export.js +3 -0
- package/dist/llm-export.js.map +1 -0
- package/dist/mcp/MCPClientAdapter.d.ts +34 -0
- package/dist/mcp/MCPClientAdapter.d.ts.map +1 -0
- package/dist/mcp/connectMCP.d.ts +47 -0
- package/dist/mcp/connectMCP.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/registerMCPTools.d.ts +24 -0
- package/dist/mcp/registerMCPTools.d.ts.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/registry/ToolRegistry.d.ts +68 -0
- package/dist/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/report/AgentReportGenerator.d.ts +53 -0
- package/dist/report/AgentReportGenerator.d.ts.map +1 -0
- package/dist/report/agent-report-template.html +362 -0
- package/dist/report/index.d.ts +3 -0
- package/dist/report/index.d.ts.map +1 -0
- package/dist/report/types.d.ts +101 -0
- package/dist/report/types.d.ts.map +1 -0
- package/dist/runAgent.d.ts +37 -0
- package/dist/runAgent.d.ts.map +1 -0
- package/dist/runtime/Budget.d.ts +63 -0
- package/dist/runtime/Budget.d.ts.map +1 -0
- package/dist/runtime/Evidence.d.ts +19 -0
- package/dist/runtime/Evidence.d.ts.map +1 -0
- package/dist/runtime/PTCRuntime.d.ts +115 -0
- package/dist/runtime/PTCRuntime.d.ts.map +1 -0
- package/dist/runtime/PTCRuntimeObservability.d.ts +26 -0
- package/dist/runtime/PTCRuntimeObservability.d.ts.map +1 -0
- package/dist/runtime/PTCRuntimePipeline.d.ts +62 -0
- package/dist/runtime/PTCRuntimePipeline.d.ts.map +1 -0
- package/dist/runtime/PolicyEngine.d.ts +67 -0
- package/dist/runtime/PolicyEngine.d.ts.map +1 -0
- package/dist/runtime/Retry.d.ts +33 -0
- package/dist/runtime/Retry.d.ts.map +1 -0
- package/dist/runtime/SchemaValidator.d.ts +42 -0
- package/dist/runtime/SchemaValidator.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/toolDescriptor.d.ts +38 -0
- package/dist/toolDescriptor.d.ts.map +1 -0
- package/dist/types/Events.d.ts +99 -0
- package/dist/types/Events.d.ts.map +1 -0
- package/dist/types/ToolIntent.d.ts +40 -0
- package/dist/types/ToolIntent.d.ts.map +1 -0
- package/dist/types/ToolResult.d.ts +30 -0
- package/dist/types/ToolResult.d.ts.map +1 -0
- package/dist/types/ToolSpec.d.ts +99 -0
- package/dist/types/ToolSpec.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/extensions/examples/README.md +40 -0
- package/extensions/examples/scripts/agent-tool-react-stock.mjs +30 -0
- package/extensions/examples/tools/instruction-only/skill/SKILL.md +26 -0
- package/extensions/examples/tools/web-search/mcp/mcp.json +8 -0
- package/package.json +122 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { ToolAdapter, ToolSpec } from "../types/ToolSpec.js";
|
|
2
|
+
import type { ExecContext, ToolIntent } from "../types/ToolIntent.js";
|
|
3
|
+
import type { ToolResult } from "../types/ToolResult.js";
|
|
4
|
+
import { ToolRegistry } from "../registry/ToolRegistry.js";
|
|
5
|
+
import { SchemaValidator } from "./SchemaValidator.js";
|
|
6
|
+
import { PolicyEngine } from "./PolicyEngine.js";
|
|
7
|
+
import { BudgetManager } from "./Budget.js";
|
|
8
|
+
import { EventLog } from "../observability/EventLog.js";
|
|
9
|
+
import type { DebugOptions } from "../observability/Logger.js";
|
|
10
|
+
import { Metrics } from "../observability/Metrics.js";
|
|
11
|
+
import { Tracing } from "../observability/Tracing.js";
|
|
12
|
+
import type { PolicyConfig } from "./PolicyEngine.js";
|
|
13
|
+
import type { BudgetOptions } from "./Budget.js";
|
|
14
|
+
/**
|
|
15
|
+
* PTC Runtime configuration.
|
|
16
|
+
*/
|
|
17
|
+
export interface PTCRuntimeConfig {
|
|
18
|
+
policy?: PolicyConfig;
|
|
19
|
+
budget?: BudgetOptions;
|
|
20
|
+
/** Include raw response in ToolResult (default: true, disable in production) */
|
|
21
|
+
includeRaw?: boolean;
|
|
22
|
+
/** Maximum retries if not specified in context (default: 2) */
|
|
23
|
+
defaultMaxRetries?: number;
|
|
24
|
+
/** Debug/logging configuration */
|
|
25
|
+
debug?: DebugOptions;
|
|
26
|
+
/** HITL: when set, tools with sideEffect external_write/destructive require human approval before execute; callback returns true/void to approve, false to deny */
|
|
27
|
+
onApprovalRequired?: (spec: import("../types/ToolSpec.js").ToolSpec, args: unknown, ctx: import("../types/ToolIntent.js").ExecContext) => Promise<boolean | void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* PTC Runtime: the unified execution kernel for all tool invocations.
|
|
31
|
+
*
|
|
32
|
+
* Enforces the mandatory 9-step pipeline:
|
|
33
|
+
* 1. Resolve (Registry lookup)
|
|
34
|
+
* 2. Input Validate (AJV)
|
|
35
|
+
* 3. Defaults Enrich
|
|
36
|
+
* 4. Policy Gate
|
|
37
|
+
* 5. Budget check
|
|
38
|
+
* 6. HITL approval (if onApprovalRequired set and tool sideEffect external_write/destructive)
|
|
39
|
+
* 7. Execute (adapter.invoke())
|
|
40
|
+
* 8. Output Validate (AJV)
|
|
41
|
+
* 9. Evidence Build
|
|
42
|
+
* 10. Audit & Metrics
|
|
43
|
+
*
|
|
44
|
+
* Never throws to callers - always returns ToolResult.
|
|
45
|
+
*/
|
|
46
|
+
export declare class PTCRuntime {
|
|
47
|
+
private readonly registry;
|
|
48
|
+
private readonly adapters;
|
|
49
|
+
private readonly validator;
|
|
50
|
+
private readonly policy;
|
|
51
|
+
private readonly budget;
|
|
52
|
+
private readonly eventLog;
|
|
53
|
+
private readonly metrics;
|
|
54
|
+
private readonly tracing;
|
|
55
|
+
private readonly config;
|
|
56
|
+
private readonly logger;
|
|
57
|
+
constructor(options?: {
|
|
58
|
+
registry?: ToolRegistry;
|
|
59
|
+
validator?: SchemaValidator;
|
|
60
|
+
policy?: PolicyEngine;
|
|
61
|
+
budget?: BudgetManager;
|
|
62
|
+
eventLog?: EventLog;
|
|
63
|
+
metrics?: Metrics;
|
|
64
|
+
tracing?: Tracing;
|
|
65
|
+
config?: PTCRuntimeConfig;
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Register an adapter for a tool kind.
|
|
69
|
+
*/
|
|
70
|
+
registerAdapter(adapter: ToolAdapter): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get an adapter by kind (e.g. "mcp"). Use to set MCP client via adapter.setClient().
|
|
73
|
+
*/
|
|
74
|
+
getAdapter(kind: string): ToolAdapter | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Get the tool registry.
|
|
77
|
+
*/
|
|
78
|
+
getRegistry(): ToolRegistry;
|
|
79
|
+
/**
|
|
80
|
+
* Get the event log.
|
|
81
|
+
*/
|
|
82
|
+
getEventLog(): EventLog;
|
|
83
|
+
/**
|
|
84
|
+
* Get the metrics collector.
|
|
85
|
+
*/
|
|
86
|
+
getMetrics(): Metrics;
|
|
87
|
+
/**
|
|
88
|
+
* Get the tracing system.
|
|
89
|
+
*/
|
|
90
|
+
getTracing(): Tracing;
|
|
91
|
+
/**
|
|
92
|
+
* Invoke a tool through the PTC pipeline.
|
|
93
|
+
* Never throws - always returns a structured ToolResult.
|
|
94
|
+
*/
|
|
95
|
+
invoke(intent: ToolIntent, ctx: ExecContext): Promise<ToolResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Search for tools in the registry.
|
|
98
|
+
*/
|
|
99
|
+
searchTools(query: string, filters?: {
|
|
100
|
+
kind?: string;
|
|
101
|
+
capabilities?: string[];
|
|
102
|
+
tags?: string[];
|
|
103
|
+
}): ToolSpec[];
|
|
104
|
+
/**
|
|
105
|
+
* Get the schema for a tool.
|
|
106
|
+
*/
|
|
107
|
+
getToolSchema(toolName: string): {
|
|
108
|
+
input: object;
|
|
109
|
+
output: object;
|
|
110
|
+
} | undefined;
|
|
111
|
+
private getPipelineDeps;
|
|
112
|
+
private getObservabilityDeps;
|
|
113
|
+
private buildDryRunResult;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=PTCRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PTCRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/PTCRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EA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AAe;IAgBvB,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,iBAAiB;CA8B1B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ToolSpec } from "../types/ToolSpec.js";
|
|
2
|
+
import type { ExecContext, ToolIntent } from "../types/ToolIntent.js";
|
|
3
|
+
import type { Evidence, ToolResult } from "../types/ToolResult.js";
|
|
4
|
+
import { EventLog } from "../observability/EventLog.js";
|
|
5
|
+
import { Metrics } from "../observability/Metrics.js";
|
|
6
|
+
import { Tracing } from "../observability/Tracing.js";
|
|
7
|
+
import type { Logger } from "../observability/Logger.js";
|
|
8
|
+
export interface ObservabilityDependencies {
|
|
9
|
+
eventLog: EventLog;
|
|
10
|
+
metrics: Metrics;
|
|
11
|
+
tracing: Tracing;
|
|
12
|
+
logger: Logger;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Emit TOOL_CALLED event.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitToolCalled(intent: ToolIntent, ctx: ExecContext, deps: ObservabilityDependencies): void;
|
|
18
|
+
/**
|
|
19
|
+
* Record successful tool invocation.
|
|
20
|
+
*/
|
|
21
|
+
export declare function recordSuccess(spec: ToolSpec, durationMs: number, _evidence: Evidence[], spanId: string, deps: ObservabilityDependencies): void;
|
|
22
|
+
/**
|
|
23
|
+
* Handle error and return ToolResult.
|
|
24
|
+
*/
|
|
25
|
+
export declare function handleError(error: unknown, intent: ToolIntent, ctx: ExecContext, durationMs: number, spanId: string, deps: ObservabilityDependencies): ToolResult;
|
|
26
|
+
//# sourceMappingURL=PTCRuntimeObservability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PTCRuntimeObservability.d.ts","sourceRoot":"","sources":["../../src/runtime/PTCRuntimeObservability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKnE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,yBAAyB,GAC9B,IAAI,CAcN;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,QAAQ,EAAE,EACrB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,yBAAyB,GAC9B,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,yBAAyB,GAC9B,UAAU,CAkDZ"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ToolSpec } from "../types/ToolSpec.js";
|
|
2
|
+
import type { ExecContext } from "../types/ToolIntent.js";
|
|
3
|
+
import type { ToolAdapter } from "../types/ToolSpec.js";
|
|
4
|
+
import { SchemaValidator } from "./SchemaValidator.js";
|
|
5
|
+
import { PolicyEngine } from "./PolicyEngine.js";
|
|
6
|
+
import { BudgetManager } from "./Budget.js";
|
|
7
|
+
import { EventLog } from "../observability/EventLog.js";
|
|
8
|
+
import { Metrics } from "../observability/Metrics.js";
|
|
9
|
+
import { Tracing } from "../observability/Tracing.js";
|
|
10
|
+
import type { Logger } from "../observability/Logger.js";
|
|
11
|
+
/** Called when tool has sideEffect external_write/destructive; return true/void to approve, false to deny. */
|
|
12
|
+
export type OnApprovalRequired = (spec: ToolSpec, args: unknown, ctx: ExecContext) => Promise<boolean | void>;
|
|
13
|
+
export interface PipelineDependencies {
|
|
14
|
+
registry: {
|
|
15
|
+
get(name: string): ToolSpec | undefined;
|
|
16
|
+
snapshot(): ToolSpec[];
|
|
17
|
+
};
|
|
18
|
+
adapters: Map<string, ToolAdapter>;
|
|
19
|
+
validator: SchemaValidator;
|
|
20
|
+
policy: PolicyEngine;
|
|
21
|
+
budget: BudgetManager;
|
|
22
|
+
eventLog: EventLog;
|
|
23
|
+
metrics: Metrics;
|
|
24
|
+
tracing: Tracing;
|
|
25
|
+
logger: Logger;
|
|
26
|
+
defaultMaxRetries?: number;
|
|
27
|
+
/** HITL: when set, tools with sideEffect external_write/destructive require human approval before execute */
|
|
28
|
+
onApprovalRequired?: OnApprovalRequired;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Pipeline step: Resolve tool from registry.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveTool(toolName: string, registry: PipelineDependencies["registry"]): ToolSpec;
|
|
34
|
+
/**
|
|
35
|
+
* Pipeline step: Validate input against schema.
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateInput(spec: ToolSpec, args: unknown, validator: SchemaValidator): unknown;
|
|
38
|
+
/**
|
|
39
|
+
* Pipeline step: Enrich args with defaults from schema.
|
|
40
|
+
*/
|
|
41
|
+
export declare function enrichDefaults(spec: ToolSpec, args: unknown, validator: SchemaValidator): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Pipeline step: Enforce policy checks.
|
|
44
|
+
*/
|
|
45
|
+
export declare function enforcePolicy(spec: ToolSpec, args: unknown, ctx: ExecContext, deps: Pick<PipelineDependencies, "policy" | "eventLog" | "metrics" | "tracing">): void;
|
|
46
|
+
/**
|
|
47
|
+
* Pipeline step: Human-in-the-loop approval for external_write/destructive tools.
|
|
48
|
+
* When onApprovalRequired is set, waits for callback resolve(true/void) before continuing; resolve(false) or reject throws HITL_DENIED.
|
|
49
|
+
*/
|
|
50
|
+
export declare function requireHumanApproval(spec: ToolSpec, args: unknown, ctx: ExecContext, deps: Pick<PipelineDependencies, "onApprovalRequired" | "eventLog" | "logger">): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Pipeline step: Execute tool with budget, retry, and timeout.
|
|
53
|
+
*/
|
|
54
|
+
export declare function executeWithBudget(spec: ToolSpec, args: unknown, ctx: ExecContext, spanId: string, deps: PipelineDependencies): Promise<{
|
|
55
|
+
result: unknown;
|
|
56
|
+
raw?: unknown;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Pipeline step: Validate output against schema.
|
|
60
|
+
*/
|
|
61
|
+
export declare function validateOutput(spec: ToolSpec, result: unknown, validator: SchemaValidator): unknown;
|
|
62
|
+
//# sourceMappingURL=PTCRuntimePipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PTCRuntimePipeline.d.ts","sourceRoot":"","sources":["../../src/runtime/PTCRuntimePipeline.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAyB,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAU5C,OAAO,EAAE,QAAQ,EAAE,MAAM,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ACzB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,IAAI,CACR,oBAAoB,EACpB,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAC9C,GACA,IAAI,CAsBN;AAID;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,oBAAoB,GAAG,UAAU,GAAG,QAAQ,CAAC,GAC7E,OAAO,CAAC,IAAI,CAAC,CAwDf;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAqE7C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,eAAe,GACzB,OAAO,CAeT"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Capability, ToolSpec } from "../types/ToolSpec.js";
|
|
2
|
+
import type { ExecContext } from "../types/ToolIntent.js";
|
|
3
|
+
/**
|
|
4
|
+
* Policy configuration for the engine.
|
|
5
|
+
*/
|
|
6
|
+
export interface PolicyConfig {
|
|
7
|
+
/** File system sandbox paths (allowed write directories) */
|
|
8
|
+
sandboxPaths?: string[];
|
|
9
|
+
/** Allowed URL patterns (regex strings) */
|
|
10
|
+
urlAllowlist?: string[];
|
|
11
|
+
/** Denied URL patterns (regex strings) */
|
|
12
|
+
urlDenylist?: string[];
|
|
13
|
+
/** SQL patterns that are denied (e.g., DROP, TRUNCATE) */
|
|
14
|
+
deniedSqlPatterns?: string[];
|
|
15
|
+
/** Network allowed domains */
|
|
16
|
+
allowedDomains?: string[];
|
|
17
|
+
/** Whether to require explicit permission for danger:destructive */
|
|
18
|
+
requireExplicitDangerPermission?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result of a policy check.
|
|
22
|
+
*/
|
|
23
|
+
export interface PolicyCheckResult {
|
|
24
|
+
allowed: boolean;
|
|
25
|
+
reason?: string;
|
|
26
|
+
missingCapabilities?: Capability[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Policy engine for capability gating, parameter security, and access control.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PolicyEngine {
|
|
32
|
+
private readonly config;
|
|
33
|
+
constructor(config?: PolicyConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Enforce all policy checks. Throws PolicyDeniedError if denied.
|
|
36
|
+
*/
|
|
37
|
+
enforce(spec: ToolSpec, args: unknown, ctx: ExecContext): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check all policies without throwing.
|
|
40
|
+
*/
|
|
41
|
+
check(spec: ToolSpec, args: unknown, ctx: ExecContext): PolicyCheckResult;
|
|
42
|
+
/**
|
|
43
|
+
* Check that context permissions cover tool capabilities.
|
|
44
|
+
*/
|
|
45
|
+
private checkCapabilities;
|
|
46
|
+
/**
|
|
47
|
+
* Check parameter-level security constraints.
|
|
48
|
+
*/
|
|
49
|
+
private checkParameters;
|
|
50
|
+
private checkFilePaths;
|
|
51
|
+
private checkUrls;
|
|
52
|
+
private checkSql;
|
|
53
|
+
private checkDomains;
|
|
54
|
+
/**
|
|
55
|
+
* Extract string values from args matching given key patterns.
|
|
56
|
+
*/
|
|
57
|
+
private extractStringValues;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Error thrown when policy denies execution.
|
|
61
|
+
*/
|
|
62
|
+
export declare class PolicyDeniedError extends Error {
|
|
63
|
+
readonly missingCapabilities?: Capability[] | undefined;
|
|
64
|
+
readonly kind = "POLICY_DENIED";
|
|
65
|
+
constructor(message: string, missingCapabilities?: Capability[] | undefined);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=PolicyEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolicyEngine.d.ts","sourceRoot":"","sources":["../../src/runtime/PolicyEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,0DAA0D;IAC1D,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,8BAA8B;IAC9B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oEAAoE;IACpE,+BAA+B,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,UAAU,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,MAAM,GAAE,YAAiB;IAQrC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI;IAU9D;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,iBAAiB;IAazE;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA+BzB;;OAEG;IACH,OAAO,CAAC,eAAe;IAsCvB,OAAO,CAAC,cAAc;IAyBtB,OAAO,CAAC,SAAS;IA8BjB,OAAO,CAAC,QAAQ;IAiBhB,OAAO,CAAC,YAAY;IAyBpB;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAqB5B;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;aAKxB,mBAAmB,CAAC,EAAE,UAAU,EAAE;IAJpD,SAAgB,IAAI,mBAAmB;gBAGrC,OAAO,EAAE,MAAM,EACC,mBAAmB,CAAC,EAAE,UAAU,EAAE,YAAA;CAKrD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry configuration.
|
|
3
|
+
*/
|
|
4
|
+
export interface RetryOptions {
|
|
5
|
+
/** Maximum number of retries (default: 2) */
|
|
6
|
+
maxRetries?: number;
|
|
7
|
+
/** Base delay in ms for exponential backoff (default: 1000) */
|
|
8
|
+
baseDelayMs?: number;
|
|
9
|
+
/** Maximum delay in ms (default: 10000) */
|
|
10
|
+
maxDelayMs?: number;
|
|
11
|
+
/** Jitter factor 0-1 (default: 0.1) */
|
|
12
|
+
jitter?: number;
|
|
13
|
+
/** Error filter: return true to retry, false to abort */
|
|
14
|
+
shouldRetry?: (error: Error) => boolean;
|
|
15
|
+
/** Callback on each retry attempt */
|
|
16
|
+
onRetry?: (error: Error, attempt: number) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Determine if an error is retryable.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isRetryable(error: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Execute a function with retry logic using exponential backoff.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a tagged error with a kind field for retry classification.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createTaggedError(kind: string, message: string, details?: unknown): Error & {
|
|
30
|
+
kind: string;
|
|
31
|
+
details?: unknown;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=Retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Retry.d.ts","sourceRoot":"","sources":["../../src/runtime/Retry.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;IACxC,qCAAqC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACnD;AAiBD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMnD;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,CAAC,CAAC,CAyCZ;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO,GAChB,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAQ7C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ErrorObject } from "ajv";
|
|
2
|
+
/**
|
|
3
|
+
* Schema validation result.
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidationResult {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
errors?: ErrorObject[];
|
|
8
|
+
data?: unknown;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* AJV-based JSON Schema validator with coercion and default enrichment.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SchemaValidator {
|
|
14
|
+
private readonly ajv;
|
|
15
|
+
private readonly cache;
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Validate data against a JSON Schema.
|
|
19
|
+
* Coerces types and applies defaults in-place.
|
|
20
|
+
*/
|
|
21
|
+
validate(schema: object, data: unknown): ValidationResult;
|
|
22
|
+
/**
|
|
23
|
+
* Validate and return coerced data, or throw a descriptive error.
|
|
24
|
+
*/
|
|
25
|
+
validateOrThrow(schema: object, data: unknown, context: string): unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Apply default values from schema to data without full validation.
|
|
28
|
+
*/
|
|
29
|
+
enrichDefaults(schema: object, data: unknown): unknown;
|
|
30
|
+
private getOrCompile;
|
|
31
|
+
/** Ensure schema is AJV-compatible (required = string[], nullable handled via type). */
|
|
32
|
+
private normalizeSchema;
|
|
33
|
+
private normalizeSchemaRec;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown on schema validation failure.
|
|
37
|
+
*/
|
|
38
|
+
export declare class SchemaValidationError extends Error {
|
|
39
|
+
readonly errors: ErrorObject[];
|
|
40
|
+
constructor(message: string, errors: ErrorObject[]);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=SchemaValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaValidator.d.ts","sourceRoot":"","sources":["../../src/runtime/SchemaValidator.ts"],"names":[],"mappings":"AAAA,OAAY,EAAyB,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAGnE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAM;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;;IAa7D;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB;IAezD;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAcxE;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO;IAOtD,OAAO,CAAC,YAAY;IAWpB,wFAAwF;IACxF,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,kBAAkB;CAiE3B;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;aAG5B,MAAM,EAAE,WAAW,EAAE;gBADrC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,WAAW,EAAE;CAKxC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated MCP server entrypoint. Start with: npx tsx mcp-server.ts
|
|
3
|
+
* Listens on stdio for MCP protocol. Supports function, skill, and n8n tools.
|
|
4
|
+
*/
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
|
+
import { getHandler } from "./tool-index.js";
|
|
11
|
+
import { getSkillInvoker } from "./skill-invoker.js";
|
|
12
|
+
import { getN8nInvoker } from "./n8n-invoker.js";
|
|
13
|
+
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const toolSpecs = require(join(__dirname, "tool-specs.json"));
|
|
17
|
+
|
|
18
|
+
const server = new McpServer({ name: "function-tools", version: "1.0.0" });
|
|
19
|
+
|
|
20
|
+
for (const spec of toolSpecs) {
|
|
21
|
+
server.registerTool(
|
|
22
|
+
spec.name,
|
|
23
|
+
{
|
|
24
|
+
description: spec.description,
|
|
25
|
+
inputSchema: spec.inputSchema,
|
|
26
|
+
_meta: spec._meta,
|
|
27
|
+
},
|
|
28
|
+
async (args, _extra) => {
|
|
29
|
+
let result;
|
|
30
|
+
if (spec.kind === "function") {
|
|
31
|
+
const handler = await getHandler(spec.name);
|
|
32
|
+
result = await handler(args);
|
|
33
|
+
} else if (spec.kind === "skill") {
|
|
34
|
+
const invoker = await getSkillInvoker(spec.name);
|
|
35
|
+
result = await invoker(args);
|
|
36
|
+
} else if (spec.kind === "n8n") {
|
|
37
|
+
const invoker = await getN8nInvoker(spec.name);
|
|
38
|
+
result = await invoker(args);
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error("Unknown tool kind: " + (spec.kind ?? "undefined"));
|
|
41
|
+
}
|
|
42
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const transport = new StdioServerTransport();
|
|
48
|
+
await server.connect(transport);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated n8n invoker: name -> (args) => result. POSTs to webhook URL.
|
|
3
|
+
*/
|
|
4
|
+
export async function getN8nInvoker(name: string): Promise<(args: Record<string, unknown>) => Promise<unknown>> {
|
|
5
|
+
return async (args) => {
|
|
6
|
+
switch (name) {
|
|
7
|
+
{{CASES}}
|
|
8
|
+
{{DEFAULT_CASE}}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated skill invoker: name -> (args) => result. Loads handler from project.
|
|
3
|
+
*/
|
|
4
|
+
export async function getSkillInvoker(name: string): Promise<(args: Record<string, unknown>) => Promise<unknown>> {
|
|
5
|
+
return async (args) => {
|
|
6
|
+
switch (name) {
|
|
7
|
+
{{CASES}}
|
|
8
|
+
{{DEFAULT_CASE}}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated tool index: name -> handler (function tools only).
|
|
3
|
+
*/
|
|
4
|
+
export async function getHandler(name: string): Promise<(args: Record<string, unknown>) => Promise<unknown>> {
|
|
5
|
+
switch (name) {
|
|
6
|
+
{{CASES}}
|
|
7
|
+
default: throw new Error("Unknown tool: " + name);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool descriptor format: npm:@scope/package#toolPath
|
|
3
|
+
* Example: npm:@easynet/agent-tool-builtin-tools#fs.readText → core/fs.readText
|
|
4
|
+
*/
|
|
5
|
+
export interface NpmToolDescriptor {
|
|
6
|
+
/** Full package id, e.g. @easynet/agent-tool-builtin-tools */
|
|
7
|
+
fullPackage: string;
|
|
8
|
+
/** Tool path after #, e.g. fs.readText or core/fs.readText */
|
|
9
|
+
toolPath: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if a string is an npm tool descriptor (npm:@scope/package#path).
|
|
13
|
+
*/
|
|
14
|
+
export declare function isNpmToolDescriptor(descriptor: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Parse npm tool descriptor into { fullPackage, toolPath } or null.
|
|
17
|
+
* Format: npm:@scope/packageName#toolPath
|
|
18
|
+
* Example: npm:@easynet/agent-tool-builtin-tools#fs.readText
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseNpmToolDescriptor(descriptor: string): NpmToolDescriptor | null;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve an npm tool descriptor to the registry tool name.
|
|
23
|
+
* For known packages we map package + toolPath to the registered name (e.g. core/fs.readText).
|
|
24
|
+
* If toolPath already starts with the package prefix, it is used as-is; otherwise prefix is prepended.
|
|
25
|
+
* Returns null for unknown packages (caller may try dynamic require in the future).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveNpmToolDescriptor(descriptor: string): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve a single tool descriptor to a tool name.
|
|
30
|
+
* If it is an npm descriptor, resolve it; otherwise return the string as-is (plain tool name).
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveToolDescriptor(descriptor: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Normalize a list of tool descriptors (plain names or npm:@scope/package#path) to tool names.
|
|
35
|
+
* Deduplicates and preserves order.
|
|
36
|
+
*/
|
|
37
|
+
export declare function normalizeToolList(descriptors: string[]): string[];
|
|
38
|
+
//# sourceMappingURL=toolDescriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolDescriptor.d.ts","sourceRoot":"","sources":["../src/toolDescriptor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAKnF;AAUD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ1E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKhE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAYjE"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Evidence, ToolError } from "./ToolResult.js";
|
|
2
|
+
/**
|
|
3
|
+
* Event types emitted by PTCRuntime and observability layer.
|
|
4
|
+
*/
|
|
5
|
+
export type ToolEventType = "TOOL_CALLED" | "TOOL_RESULT" | "POLICY_DENIED" | "HITL_APPROVAL_REQUESTED" | "HITL_APPROVAL_GRANTED" | "HITL_APPROVAL_DENIED" | "RETRY" | "TIMEOUT" | "BUDGET_EXCEEDED" | "JOB_SUBMITTED" | "JOB_COMPLETED" | "JOB_FAILED";
|
|
6
|
+
/**
|
|
7
|
+
* Base event structure for all tool events.
|
|
8
|
+
*/
|
|
9
|
+
export interface ToolEvent {
|
|
10
|
+
type: ToolEventType;
|
|
11
|
+
timestamp: string;
|
|
12
|
+
requestId: string;
|
|
13
|
+
taskId: string;
|
|
14
|
+
toolName: string;
|
|
15
|
+
traceId?: string;
|
|
16
|
+
userId?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Emitted when a tool is called.
|
|
20
|
+
*/
|
|
21
|
+
export interface ToolCalledEvent extends ToolEvent {
|
|
22
|
+
type: "TOOL_CALLED";
|
|
23
|
+
argsSummary: string;
|
|
24
|
+
purpose: string;
|
|
25
|
+
idempotencyKey?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Emitted when a tool returns a result.
|
|
29
|
+
*/
|
|
30
|
+
export interface ToolResultEvent extends ToolEvent {
|
|
31
|
+
type: "TOOL_RESULT";
|
|
32
|
+
ok: boolean;
|
|
33
|
+
durationMs: number;
|
|
34
|
+
resultSummary: string;
|
|
35
|
+
evidence: Evidence[];
|
|
36
|
+
error?: ToolError;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Emitted when policy denies a tool invocation.
|
|
40
|
+
*/
|
|
41
|
+
export interface PolicyDeniedEvent extends ToolEvent {
|
|
42
|
+
type: "POLICY_DENIED";
|
|
43
|
+
reason: string;
|
|
44
|
+
missingCapabilities?: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Emitted on retry.
|
|
48
|
+
*/
|
|
49
|
+
export interface RetryEvent extends ToolEvent {
|
|
50
|
+
type: "RETRY";
|
|
51
|
+
attempt: number;
|
|
52
|
+
maxRetries: number;
|
|
53
|
+
reason: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Emitted when human approval is requested (before execute for external_write/destructive).
|
|
57
|
+
*/
|
|
58
|
+
export interface HitlApprovalRequestedEvent extends ToolEvent {
|
|
59
|
+
type: "HITL_APPROVAL_REQUESTED";
|
|
60
|
+
sideEffect: string;
|
|
61
|
+
argsSummary?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Emitted when human approves the tool invocation.
|
|
65
|
+
*/
|
|
66
|
+
export interface HitlApprovalGrantedEvent extends ToolEvent {
|
|
67
|
+
type: "HITL_APPROVAL_GRANTED";
|
|
68
|
+
sideEffect: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Emitted when human denies the tool invocation.
|
|
72
|
+
*/
|
|
73
|
+
export interface HitlApprovalDeniedEvent extends ToolEvent {
|
|
74
|
+
type: "HITL_APPROVAL_DENIED";
|
|
75
|
+
sideEffect: string;
|
|
76
|
+
reason?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Async job events.
|
|
80
|
+
*/
|
|
81
|
+
export interface JobSubmittedEvent extends ToolEvent {
|
|
82
|
+
type: "JOB_SUBMITTED";
|
|
83
|
+
jobId: string;
|
|
84
|
+
}
|
|
85
|
+
export interface JobCompletedEvent extends ToolEvent {
|
|
86
|
+
type: "JOB_COMPLETED";
|
|
87
|
+
jobId: string;
|
|
88
|
+
durationMs: number;
|
|
89
|
+
}
|
|
90
|
+
export interface JobFailedEvent extends ToolEvent {
|
|
91
|
+
type: "JOB_FAILED";
|
|
92
|
+
jobId: string;
|
|
93
|
+
error: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Union type of all tool events.
|
|
97
|
+
*/
|
|
98
|
+
export type AnyToolEvent = ToolCalledEvent | ToolResultEvent | PolicyDeniedEvent | HitlApprovalRequestedEvent | HitlApprovalGrantedEvent | HitlApprovalDeniedEvent | RetryEvent | JobSubmittedEvent | JobCompletedEvent | JobFailedEvent;
|
|
99
|
+
//# sourceMappingURL=Events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Events.d.ts","sourceRoot":"","sources":["../../src/types/Events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,aAAa,GACb,eAAe,GACf,yBAAyB,GACzB,uBAAuB,GACvB,sBAAsB,GACtB,OAAO,GACP,SAAS,GACT,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,YAAY,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAChD,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB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;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,eAAe,GACf,eAAe,GACf,iBAAiB,GACjB,0BAA0B,GAC1B,wBAAwB,GACxB,uBAAuB,GACvB,UAAU,GACV,iBAAiB,GACjB,iBAAiB,GACjB,cAAc,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Capability } from "./ToolSpec.js";
|
|
2
|
+
/**
|
|
3
|
+
* Budget constraints for a tool invocation.
|
|
4
|
+
*/
|
|
5
|
+
export interface BudgetConfig {
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
maxToolCalls?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Execution context passed from agent-orchestra.
|
|
12
|
+
* Contains permissions, budget, and observability context.
|
|
13
|
+
*/
|
|
14
|
+
export interface ExecContext {
|
|
15
|
+
requestId: string;
|
|
16
|
+
taskId: string;
|
|
17
|
+
/** Allowed capabilities for this invocation */
|
|
18
|
+
permissions: Capability[];
|
|
19
|
+
budget?: BudgetConfig;
|
|
20
|
+
/** OpenTelemetry-compatible trace ID */
|
|
21
|
+
traceId?: string;
|
|
22
|
+
userId?: string;
|
|
23
|
+
/** Optional: enable dry-run mode for two-phase commit */
|
|
24
|
+
dryRun?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Tool invocation intent from agent-orchestra.
|
|
28
|
+
* Represents what the agent wants to do (untrusted input).
|
|
29
|
+
*/
|
|
30
|
+
export interface ToolIntent {
|
|
31
|
+
/** ToolSpec.name reference */
|
|
32
|
+
tool: string;
|
|
33
|
+
/** Untrusted input arguments */
|
|
34
|
+
args: unknown;
|
|
35
|
+
/** Human-readable purpose for audit trail */
|
|
36
|
+
purpose: string;
|
|
37
|
+
/** Idempotency key: recommended format requestId:taskId:tool */
|
|
38
|
+
idempotencyKey?: string;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ToolIntent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolIntent.d.ts","sourceRoot":"","sources":["../../src/types/ToolIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IAEf,+CAA+C;IAC/C,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,yDAAyD;IACzD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
|