@botbotgo/runtime 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/.github/workflows/ci.yml +46 -0
- package/.github/workflows/release.yml +79 -0
- package/README.md +71 -0
- package/config/examples/memory.yaml +39 -0
- package/config/examples/model.yaml +21 -0
- package/config/examples/runtime.yaml +44 -0
- package/config/examples/skills.yaml +8 -0
- package/config/examples/tool.yaml +16 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +41 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +140 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/resolveRuntimeConfig.d.ts +83 -0
- package/dist/config/resolveRuntimeConfig.d.ts.map +1 -0
- package/dist/config/resolveRuntimeConfig.js +85 -0
- package/dist/config/resolveRuntimeConfig.js.map +1 -0
- package/dist/config/resources.d.ts +112 -0
- package/dist/config/resources.d.ts.map +1 -0
- package/dist/config/resources.js +20 -0
- package/dist/config/resources.js.map +1 -0
- package/dist/config/runtimeConfigLoader.d.ts +28 -0
- package/dist/config/runtimeConfigLoader.d.ts.map +1 -0
- package/dist/config/runtimeConfigLoader.js +38 -0
- package/dist/config/runtimeConfigLoader.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/agentMiddleware.d.ts +3 -0
- package/dist/runtime/agentMiddleware.d.ts.map +1 -0
- package/dist/runtime/agentMiddleware.js +2 -0
- package/dist/runtime/agentMiddleware.js.map +1 -0
- package/dist/runtime/bootstrap/runtimeFactory.d.ts +7 -0
- package/dist/runtime/bootstrap/runtimeFactory.d.ts.map +1 -0
- package/dist/runtime/bootstrap/runtimeFactory.js +139 -0
- package/dist/runtime/bootstrap/runtimeFactory.js.map +1 -0
- package/dist/runtime/bootstrap/runtimeModuleInitializer.d.ts +5 -0
- package/dist/runtime/bootstrap/runtimeModuleInitializer.d.ts.map +1 -0
- package/dist/runtime/bootstrap/runtimeModuleInitializer.js +32 -0
- package/dist/runtime/bootstrap/runtimeModuleInitializer.js.map +1 -0
- package/dist/runtime/context/agentContext.d.ts +5 -0
- package/dist/runtime/context/agentContext.d.ts.map +1 -0
- package/dist/runtime/context/agentContext.js +19 -0
- package/dist/runtime/context/agentContext.js.map +1 -0
- package/dist/runtime/context/globalContext.d.ts +19 -0
- package/dist/runtime/context/globalContext.d.ts.map +1 -0
- package/dist/runtime/context/globalContext.js +47 -0
- package/dist/runtime/context/globalContext.js.map +1 -0
- package/dist/runtime/events/eventPublisher.d.ts +15 -0
- package/dist/runtime/events/eventPublisher.d.ts.map +1 -0
- package/dist/runtime/events/eventPublisher.js +23 -0
- package/dist/runtime/events/eventPublisher.js.map +1 -0
- package/dist/runtime/execution/agentRunExecutor.d.ts +38 -0
- package/dist/runtime/execution/agentRunExecutor.d.ts.map +1 -0
- package/dist/runtime/execution/agentRunExecutor.js +378 -0
- package/dist/runtime/execution/agentRunExecutor.js.map +1 -0
- package/dist/runtime/execution/agentRunExecutor.types.d.ts +37 -0
- package/dist/runtime/execution/agentRunExecutor.types.d.ts.map +1 -0
- package/dist/runtime/execution/agentRunExecutor.types.js +2 -0
- package/dist/runtime/execution/agentRunExecutor.types.js.map +1 -0
- package/dist/runtime/execution/agentRunProgress.d.ts +8 -0
- package/dist/runtime/execution/agentRunProgress.d.ts.map +1 -0
- package/dist/runtime/execution/agentRunProgress.js +46 -0
- package/dist/runtime/execution/agentRunProgress.js.map +1 -0
- package/dist/runtime/execution/agentRunState.d.ts +44 -0
- package/dist/runtime/execution/agentRunState.d.ts.map +1 -0
- package/dist/runtime/execution/agentRunState.js +17 -0
- package/dist/runtime/execution/agentRunState.js.map +1 -0
- package/dist/runtime/execution/policies/runCompletionPolicy.d.ts +5 -0
- package/dist/runtime/execution/policies/runCompletionPolicy.d.ts.map +1 -0
- package/dist/runtime/execution/policies/runCompletionPolicy.js +30 -0
- package/dist/runtime/execution/policies/runCompletionPolicy.js.map +1 -0
- package/dist/runtime/execution/policies/runErrorPolicy.d.ts +7 -0
- package/dist/runtime/execution/policies/runErrorPolicy.d.ts.map +1 -0
- package/dist/runtime/execution/policies/runErrorPolicy.js +40 -0
- package/dist/runtime/execution/policies/runErrorPolicy.js.map +1 -0
- package/dist/runtime/execution/policies/runPromptBuilder.d.ts +10 -0
- package/dist/runtime/execution/policies/runPromptBuilder.d.ts.map +1 -0
- package/dist/runtime/execution/policies/runPromptBuilder.js +34 -0
- package/dist/runtime/execution/policies/runPromptBuilder.js.map +1 -0
- package/dist/runtime/execution/policies/runSummaryFormatter.d.ts +6 -0
- package/dist/runtime/execution/policies/runSummaryFormatter.d.ts.map +1 -0
- package/dist/runtime/execution/policies/runSummaryFormatter.js +47 -0
- package/dist/runtime/execution/policies/runSummaryFormatter.js.map +1 -0
- package/dist/runtime/execution/policies/runtimeDelay.d.ts +4 -0
- package/dist/runtime/execution/policies/runtimeDelay.d.ts.map +1 -0
- package/dist/runtime/execution/policies/runtimeDelay.js +6 -0
- package/dist/runtime/execution/policies/runtimeDelay.js.map +1 -0
- package/dist/runtime/execution/policies/toolConfigReader.d.ts +8 -0
- package/dist/runtime/execution/policies/toolConfigReader.d.ts.map +1 -0
- package/dist/runtime/execution/policies/toolConfigReader.js +91 -0
- package/dist/runtime/execution/policies/toolConfigReader.js.map +1 -0
- package/dist/runtime/human-loop/consoleHumanLoop.d.ts +21 -0
- package/dist/runtime/human-loop/consoleHumanLoop.d.ts.map +1 -0
- package/dist/runtime/human-loop/consoleHumanLoop.js +102 -0
- package/dist/runtime/human-loop/consoleHumanLoop.js.map +1 -0
- package/dist/runtime/human-loop/humanLoop.d.ts +44 -0
- package/dist/runtime/human-loop/humanLoop.d.ts.map +1 -0
- package/dist/runtime/human-loop/humanLoop.js +36 -0
- package/dist/runtime/human-loop/humanLoop.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +6 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/middleware/agentToolMiddleware.d.ts +30 -0
- package/dist/runtime/middleware/agentToolMiddleware.d.ts.map +1 -0
- package/dist/runtime/middleware/agentToolMiddleware.js +259 -0
- package/dist/runtime/middleware/agentToolMiddleware.js.map +1 -0
- package/dist/runtime/middleware/commandPolicy.d.ts +8 -0
- package/dist/runtime/middleware/commandPolicy.d.ts.map +1 -0
- package/dist/runtime/middleware/commandPolicy.js +55 -0
- package/dist/runtime/middleware/commandPolicy.js.map +1 -0
- package/dist/runtime/middleware/frameworkPrompt.d.ts +4 -0
- package/dist/runtime/middleware/frameworkPrompt.d.ts.map +1 -0
- package/dist/runtime/middleware/frameworkPrompt.js +44 -0
- package/dist/runtime/middleware/frameworkPrompt.js.map +1 -0
- package/dist/runtime/middleware/index.d.ts +4 -0
- package/dist/runtime/middleware/index.d.ts.map +1 -0
- package/dist/runtime/middleware/index.js +3 -0
- package/dist/runtime/middleware/index.js.map +1 -0
- package/dist/runtime/middleware/skillPathMap.d.ts +3 -0
- package/dist/runtime/middleware/skillPathMap.d.ts.map +1 -0
- package/dist/runtime/middleware/skillPathMap.js +44 -0
- package/dist/runtime/middleware/skillPathMap.js.map +1 -0
- package/dist/runtime/middleware/toolArgsNormalizer.d.ts +21 -0
- package/dist/runtime/middleware/toolArgsNormalizer.d.ts.map +1 -0
- package/dist/runtime/middleware/toolArgsNormalizer.js +227 -0
- package/dist/runtime/middleware/toolArgsNormalizer.js.map +1 -0
- package/dist/runtime/middleware/toolCallGuard.d.ts +8 -0
- package/dist/runtime/middleware/toolCallGuard.d.ts.map +1 -0
- package/dist/runtime/middleware/toolCallGuard.js +60 -0
- package/dist/runtime/middleware/toolCallGuard.js.map +1 -0
- package/dist/runtime/middleware/toolFsHandlers.d.ts +12 -0
- package/dist/runtime/middleware/toolFsHandlers.d.ts.map +1 -0
- package/dist/runtime/middleware/toolFsHandlers.js +79 -0
- package/dist/runtime/middleware/toolFsHandlers.js.map +1 -0
- package/dist/runtime/middleware/toolRequestParser.d.ts +14 -0
- package/dist/runtime/middleware/toolRequestParser.d.ts.map +1 -0
- package/dist/runtime/middleware/toolRequestParser.js +72 -0
- package/dist/runtime/middleware/toolRequestParser.js.map +1 -0
- package/dist/runtime/middleware/types.d.ts +87 -0
- package/dist/runtime/middleware/types.d.ts.map +1 -0
- package/dist/runtime/middleware/types.js +3 -0
- package/dist/runtime/middleware/types.js.map +1 -0
- package/dist/runtime/providers/backendResolver.d.ts +26 -0
- package/dist/runtime/providers/backendResolver.d.ts.map +1 -0
- package/dist/runtime/providers/backendResolver.js +73 -0
- package/dist/runtime/providers/backendResolver.js.map +1 -0
- package/dist/runtime/providers/index.d.ts +14 -0
- package/dist/runtime/providers/index.d.ts.map +1 -0
- package/dist/runtime/providers/index.js +10 -0
- package/dist/runtime/providers/index.js.map +1 -0
- package/dist/runtime/providers/langchainRuntime.d.ts +11 -0
- package/dist/runtime/providers/langchainRuntime.d.ts.map +1 -0
- package/dist/runtime/providers/langchainRuntime.js +45 -0
- package/dist/runtime/providers/langchainRuntime.js.map +1 -0
- package/dist/runtime/providers/localShellBackend.d.ts +10 -0
- package/dist/runtime/providers/localShellBackend.d.ts.map +1 -0
- package/dist/runtime/providers/localShellBackend.js +23 -0
- package/dist/runtime/providers/localShellBackend.js.map +1 -0
- package/dist/runtime/providers/openaiDeepAgent.d.ts +9 -0
- package/dist/runtime/providers/openaiDeepAgent.d.ts.map +1 -0
- package/dist/runtime/providers/openaiDeepAgent.js +7 -0
- package/dist/runtime/providers/openaiDeepAgent.js.map +1 -0
- package/dist/runtime/providers/openaiLocalAgent.d.ts +17 -0
- package/dist/runtime/providers/openaiLocalAgent.d.ts.map +1 -0
- package/dist/runtime/providers/openaiLocalAgent.js +26 -0
- package/dist/runtime/providers/openaiLocalAgent.js.map +1 -0
- package/dist/runtime/providers/openaiLocalAgentFactory.d.ts +36 -0
- package/dist/runtime/providers/openaiLocalAgentFactory.d.ts.map +1 -0
- package/dist/runtime/providers/openaiLocalAgentFactory.js +139 -0
- package/dist/runtime/providers/openaiLocalAgentFactory.js.map +1 -0
- package/dist/runtime/providers/shared/agentProbe.d.ts +4 -0
- package/dist/runtime/providers/shared/agentProbe.d.ts.map +1 -0
- package/dist/runtime/providers/shared/agentProbe.js +17 -0
- package/dist/runtime/providers/shared/agentProbe.js.map +1 -0
- package/dist/runtime/providers/shared/moduleFallback.d.ts +2 -0
- package/dist/runtime/providers/shared/moduleFallback.d.ts.map +1 -0
- package/dist/runtime/providers/shared/moduleFallback.js +34 -0
- package/dist/runtime/providers/shared/moduleFallback.js.map +1 -0
- package/dist/runtime/providers/shared/resourceCloser.d.ts +6 -0
- package/dist/runtime/providers/shared/resourceCloser.d.ts.map +1 -0
- package/dist/runtime/providers/shared/resourceCloser.js +30 -0
- package/dist/runtime/providers/shared/resourceCloser.js.map +1 -0
- package/dist/runtime/runtimeService.d.ts +109 -0
- package/dist/runtime/runtimeService.d.ts.map +1 -0
- package/dist/runtime/runtimeService.js +90 -0
- package/dist/runtime/runtimeService.js.map +1 -0
- package/dist/runtime/stream/agentMessages.d.ts +40 -0
- package/dist/runtime/stream/agentMessages.d.ts.map +1 -0
- package/dist/runtime/stream/agentMessages.js +44 -0
- package/dist/runtime/stream/agentMessages.js.map +1 -0
- package/dist/runtime/stream/agentStream.d.ts +31 -0
- package/dist/runtime/stream/agentStream.d.ts.map +1 -0
- package/dist/runtime/stream/agentStream.js +106 -0
- package/dist/runtime/stream/agentStream.js.map +1 -0
- package/dist/runtime/stream/messageSummary.d.ts +20 -0
- package/dist/runtime/stream/messageSummary.d.ts.map +1 -0
- package/dist/runtime/stream/messageSummary.js +150 -0
- package/dist/runtime/stream/messageSummary.js.map +1 -0
- package/dist/runtime/stream/runArtifacts.d.ts +9 -0
- package/dist/runtime/stream/runArtifacts.d.ts.map +1 -0
- package/dist/runtime/stream/runArtifacts.js +48 -0
- package/dist/runtime/stream/runArtifacts.js.map +1 -0
- package/dist/state/index.d.ts +7 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +4 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/runState.d.ts +36 -0
- package/dist/state/runState.d.ts.map +1 -0
- package/dist/state/runState.js +51 -0
- package/dist/state/runState.js.map +1 -0
- package/dist/state/todos.d.ts +19 -0
- package/dist/state/todos.d.ts.map +1 -0
- package/dist/state/todos.js +45 -0
- package/dist/state/todos.js.map +1 -0
- package/dist/state/workspaceRunSession.d.ts +32 -0
- package/dist/state/workspaceRunSession.d.ts.map +1 -0
- package/dist/state/workspaceRunSession.js +67 -0
- package/dist/state/workspaceRunSession.js.map +1 -0
- package/dist/state/workspaceState.d.ts +94 -0
- package/dist/state/workspaceState.d.ts.map +1 -0
- package/dist/state/workspaceState.js +119 -0
- package/dist/state/workspaceState.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/example/.tsbuildinfo +1 -0
- package/example/build/.tsbuildinfo +1 -0
- package/example/config/memory.yaml +35 -0
- package/example/config/model.yaml +14 -0
- package/example/config/runtime.yaml +46 -0
- package/example/config/tool.yaml +24 -0
- package/example/index.ts +159 -0
- package/example/package-lock.json +1396 -0
- package/example/package.json +26 -0
- package/example/serve-output.mjs +52 -0
- package/example/tsconfig.json +19 -0
- package/package.json +73 -0
- package/scripts/resolve-deps.js +40 -0
- package/src/config/index.ts +29 -0
- package/src/config/loader.ts +174 -0
- package/src/config/resolveRuntimeConfig.ts +160 -0
- package/src/config/resources.ts +152 -0
- package/src/config/runtimeConfigLoader.ts +68 -0
- package/src/external-modules.d.ts +20 -0
- package/src/index.ts +36 -0
- package/src/runtime/agentMiddleware.ts +6 -0
- package/src/runtime/bootstrap/runtimeFactory.ts +212 -0
- package/src/runtime/bootstrap/runtimeModuleInitializer.ts +34 -0
- package/src/runtime/context/agentContext.ts +24 -0
- package/src/runtime/context/globalContext.ts +70 -0
- package/src/runtime/events/eventPublisher.ts +45 -0
- package/src/runtime/execution/agentRunExecutor.ts +499 -0
- package/src/runtime/execution/agentRunExecutor.types.ts +39 -0
- package/src/runtime/execution/agentRunProgress.ts +67 -0
- package/src/runtime/execution/agentRunState.ts +66 -0
- package/src/runtime/execution/policies/runCompletionPolicy.ts +30 -0
- package/src/runtime/execution/policies/runErrorPolicy.ts +50 -0
- package/src/runtime/execution/policies/runPromptBuilder.ts +39 -0
- package/src/runtime/execution/policies/runSummaryFormatter.ts +57 -0
- package/src/runtime/execution/policies/runtimeDelay.ts +5 -0
- package/src/runtime/execution/policies/toolConfigReader.ts +107 -0
- package/src/runtime/human-loop/consoleHumanLoop.ts +113 -0
- package/src/runtime/human-loop/humanLoop.ts +90 -0
- package/src/runtime/index.ts +36 -0
- package/src/runtime/middleware/agentToolMiddleware.ts +329 -0
- package/src/runtime/middleware/commandPolicy.ts +65 -0
- package/src/runtime/middleware/frameworkPrompt.ts +51 -0
- package/src/runtime/middleware/index.ts +7 -0
- package/src/runtime/middleware/skillPathMap.ts +49 -0
- package/src/runtime/middleware/toolArgsNormalizer.ts +277 -0
- package/src/runtime/middleware/toolCallGuard.ts +73 -0
- package/src/runtime/middleware/toolFsHandlers.ts +94 -0
- package/src/runtime/middleware/toolRequestParser.ts +84 -0
- package/src/runtime/middleware/types.ts +91 -0
- package/src/runtime/providers/backendResolver.ts +127 -0
- package/src/runtime/providers/index.ts +19 -0
- package/src/runtime/providers/langchainRuntime.ts +67 -0
- package/src/runtime/providers/localShellBackend.ts +54 -0
- package/src/runtime/providers/openaiDeepAgent.ts +17 -0
- package/src/runtime/providers/openaiLocalAgent.ts +35 -0
- package/src/runtime/providers/openaiLocalAgentFactory.ts +185 -0
- package/src/runtime/providers/shared/agentProbe.ts +24 -0
- package/src/runtime/providers/shared/moduleFallback.ts +41 -0
- package/src/runtime/providers/shared/resourceCloser.ts +30 -0
- package/src/runtime/runtimeService.ts +205 -0
- package/src/runtime/stream/agentMessages.ts +72 -0
- package/src/runtime/stream/agentStream.ts +168 -0
- package/src/runtime/stream/messageSummary.ts +164 -0
- package/src/runtime/stream/runArtifacts.ts +72 -0
- package/src/state/index.ts +19 -0
- package/src/state/runState.ts +84 -0
- package/src/state/todos.ts +59 -0
- package/src/state/workspaceRunSession.ts +96 -0
- package/src/state/workspaceState.ts +199 -0
- package/src/types/easynet-agent-common.d.ts +62 -0
- package/src/types.ts +1 -0
- package/test/integration/runtime-live.integration.test.ts +30 -0
- package/test/unit/config/loader.test.ts +429 -0
- package/test/unit/runtime/agentContext.test.ts +23 -0
- package/test/unit/runtime/agentRuntime.test.ts +99 -0
- package/test/unit/runtime/consoleHumanLoop.test.ts +52 -0
- package/test/unit/runtime/events.test.ts +11 -0
- package/test/unit/runtime/globalContext.test.ts +34 -0
- package/test/unit/runtime/humanLoop.test.ts +104 -0
- package/test/unit/runtime/toolArgsNormalizer.test.ts +136 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { createAgentEventBus } from "@botbotgo/common/events";
|
|
4
|
+
import { AgentRuntimeEventPublisher } from "../../../src/runtime/events/eventPublisher.ts";
|
|
5
|
+
import { createDefaultHumanLoopToolPolicy } from "../../../src/runtime/human-loop/humanLoop.ts";
|
|
6
|
+
import { AgentToolMiddlewareFactory } from "../../../src/runtime/middleware/agentToolMiddleware.ts";
|
|
7
|
+
|
|
8
|
+
class FakeToolMessage {
|
|
9
|
+
public readonly content: string;
|
|
10
|
+
public readonly tool_call_id: string;
|
|
11
|
+
|
|
12
|
+
public constructor(fields: { content: string; tool_call_id: string }) {
|
|
13
|
+
this.content = fields.content;
|
|
14
|
+
this.tool_call_id = fields.tool_call_id;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createMiddlewareHarness(options: {
|
|
19
|
+
humanLoopDecision?: {
|
|
20
|
+
action: "approve" | "reject" | "revise";
|
|
21
|
+
message?: string;
|
|
22
|
+
revisedArgs?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
}) {
|
|
25
|
+
let capturedRequest: unknown;
|
|
26
|
+
let handlerCalls = 0;
|
|
27
|
+
let handlerArgs: unknown;
|
|
28
|
+
|
|
29
|
+
const middleware = new AgentToolMiddlewareFactory({
|
|
30
|
+
rootDir: "/workspace",
|
|
31
|
+
createMiddleware: (definition) => definition,
|
|
32
|
+
ToolMessage: FakeToolMessage,
|
|
33
|
+
events: new AgentRuntimeEventPublisher(createAgentEventBus()),
|
|
34
|
+
humanLoop: options.humanLoopDecision
|
|
35
|
+
? {
|
|
36
|
+
request: async (request) => {
|
|
37
|
+
capturedRequest = request;
|
|
38
|
+
return options.humanLoopDecision!;
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
humanLoopToolPolicy: options.humanLoopDecision
|
|
43
|
+
? createDefaultHumanLoopToolPolicy({ toolNames: ["execute"] })
|
|
44
|
+
: undefined,
|
|
45
|
+
}).create() as {
|
|
46
|
+
wrapToolCall: (request: unknown, handler: (request: unknown) => unknown) => Promise<unknown>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
middleware,
|
|
51
|
+
getCapturedRequest: () => capturedRequest,
|
|
52
|
+
getHandlerCalls: () => handlerCalls,
|
|
53
|
+
getHandlerArgs: () => handlerArgs,
|
|
54
|
+
run: async () =>
|
|
55
|
+
middleware.wrapToolCall(
|
|
56
|
+
{
|
|
57
|
+
toolCall: {
|
|
58
|
+
id: "call-1",
|
|
59
|
+
name: "execute",
|
|
60
|
+
args: { command: "printf unsafe" },
|
|
61
|
+
},
|
|
62
|
+
configurable: { thread_id: "thread-1" },
|
|
63
|
+
},
|
|
64
|
+
async (request) => {
|
|
65
|
+
handlerCalls += 1;
|
|
66
|
+
handlerArgs = request;
|
|
67
|
+
return { ok: true, request };
|
|
68
|
+
},
|
|
69
|
+
),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
test("human loop reject prevents tool execution", async () => {
|
|
74
|
+
const harness = createMiddlewareHarness({
|
|
75
|
+
humanLoopDecision: {
|
|
76
|
+
action: "reject",
|
|
77
|
+
message: "Denied by reviewer.",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const result = await harness.run();
|
|
82
|
+
|
|
83
|
+
assert.equal(harness.getHandlerCalls(), 0);
|
|
84
|
+
assert.equal((result as FakeToolMessage).content, "Denied by reviewer.");
|
|
85
|
+
assert.match(JSON.stringify(harness.getCapturedRequest()), /"toolName":"execute"/);
|
|
86
|
+
assert.match(JSON.stringify(harness.getCapturedRequest()), /"threadId":"thread-1"/);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("human loop revise updates args before tool execution", async () => {
|
|
90
|
+
const harness = createMiddlewareHarness({
|
|
91
|
+
humanLoopDecision: {
|
|
92
|
+
action: "revise",
|
|
93
|
+
revisedArgs: { command: "printf safe" },
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await harness.run();
|
|
98
|
+
|
|
99
|
+
assert.equal(harness.getHandlerCalls(), 1);
|
|
100
|
+
assert.deepEqual(
|
|
101
|
+
(harness.getHandlerArgs() as { toolCall: { args: unknown } }).toolCall.args,
|
|
102
|
+
{ command: "printf safe" },
|
|
103
|
+
);
|
|
104
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { mkdir, writeFile, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { FrameworkPrompt } from "../../../src/runtime/middleware/frameworkPrompt.ts";
|
|
7
|
+
import { ToolArgsNormalizer } from "../../../src/runtime/middleware/toolArgsNormalizer.ts";
|
|
8
|
+
import { buildSkillPathMap } from "../../../src/runtime/middleware/skillPathMap.ts";
|
|
9
|
+
|
|
10
|
+
test("ToolArgsNormalizer rewrites execute args relative to a unique skill root", async () => {
|
|
11
|
+
const root = join(tmpdir(), `agent-runtime2-skill-path-${Date.now()}`);
|
|
12
|
+
const skillRoot = join(root, ".agent", "cache", "skills", "company-report");
|
|
13
|
+
await mkdir(join(skillRoot, "scripts"), { recursive: true });
|
|
14
|
+
await mkdir(join(skillRoot, "references"), { recursive: true });
|
|
15
|
+
await writeFile(join(skillRoot, "scripts", "merge-report.mjs"), "export {};\n", "utf8");
|
|
16
|
+
await writeFile(join(skillRoot, "references", "company-report.template.html"), "<html></html>\n", "utf8");
|
|
17
|
+
|
|
18
|
+
const normalized = ToolArgsNormalizer.normalizeToolArgs(
|
|
19
|
+
root,
|
|
20
|
+
[skillRoot],
|
|
21
|
+
"execute",
|
|
22
|
+
{
|
|
23
|
+
command: "node scripts/merge-report.mjs output/company-report.json output/company-report.html references/company-report.template.html",
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
assert.equal(
|
|
28
|
+
normalized.command,
|
|
29
|
+
"node .agent/cache/skills/company-report/scripts/merge-report.mjs output/company-report.json output/company-report.html .agent/cache/skills/company-report/references/company-report.template.html",
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
await rm(root, { recursive: true, force: true });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("ToolArgsNormalizer expands WORKSPACE and named SKILL_PATH placeholders across multiple skills", async () => {
|
|
36
|
+
const root = join(tmpdir(), `agent-runtime2-skill-vars-${Date.now()}`);
|
|
37
|
+
const companyReportRoot = join(root, ".agent", "cache", "skills", "company-report");
|
|
38
|
+
const otherSkillRoot = join(root, ".agent", "cache", "skills", "other-skill");
|
|
39
|
+
await mkdir(join(companyReportRoot, "scripts"), { recursive: true });
|
|
40
|
+
await mkdir(join(companyReportRoot, "references"), { recursive: true });
|
|
41
|
+
await mkdir(otherSkillRoot, { recursive: true });
|
|
42
|
+
await writeFile(join(companyReportRoot, "scripts", "merge-report.mjs"), "export {};\n", "utf8");
|
|
43
|
+
await writeFile(join(companyReportRoot, "references", "company-report.template.html"), "<html></html>\n", "utf8");
|
|
44
|
+
|
|
45
|
+
const normalized = ToolArgsNormalizer.normalizeToolArgs(
|
|
46
|
+
root,
|
|
47
|
+
[companyReportRoot, otherSkillRoot],
|
|
48
|
+
"execute",
|
|
49
|
+
{
|
|
50
|
+
command:
|
|
51
|
+
"node ${SKILL_PATH:company-report}/scripts/merge-report.mjs ${WORKSPACE}/output/company-report.json ${WORKSPACE}/output/company-report.html ${SKILL_PATH:company-report}/references/company-report.template.html",
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
assert.equal(
|
|
56
|
+
normalized.command,
|
|
57
|
+
`node ${companyReportRoot.replace(/\\/g, "/")}/scripts/merge-report.mjs ${root.replace(/\\/g, "/")}/output/company-report.json ${root.replace(/\\/g, "/")}/output/company-report.html ${companyReportRoot.replace(/\\/g, "/")}/references/company-report.template.html`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
await rm(root, { recursive: true, force: true });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("FrameworkPrompt includes active skill mapping in framework system prompt", () => {
|
|
64
|
+
const prompt = FrameworkPrompt.build(
|
|
65
|
+
undefined,
|
|
66
|
+
false,
|
|
67
|
+
["yahooFinanceQuote"],
|
|
68
|
+
{
|
|
69
|
+
"company-report": "/cache/skills/company-report",
|
|
70
|
+
"other-skill": "/cache/skills/other-skill",
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
assert.match(prompt, /Active skills for this run:/);
|
|
75
|
+
assert.match(prompt, /company-report => \/cache\/skills\/company-report/);
|
|
76
|
+
assert.match(prompt, /other-skill => \/cache\/skills\/other-skill/);
|
|
77
|
+
assert.match(prompt, /\$\{SKILL_PATH:<skill-id>\}/);
|
|
78
|
+
assert.match(prompt, /\$\{WORKSPACE\}/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("buildSkillPathMap expands skills root directories into named skill paths", async () => {
|
|
82
|
+
const root = join(tmpdir(), `agent-runtime2-skill-map-${Date.now()}`);
|
|
83
|
+
const skillsRoot = join(root, ".agent", "cache", "skills");
|
|
84
|
+
const companyReportRoot = join(skillsRoot, "company-report");
|
|
85
|
+
await mkdir(companyReportRoot, { recursive: true });
|
|
86
|
+
await writeFile(join(companyReportRoot, "SKILL.md"), "# company report\n", "utf8");
|
|
87
|
+
|
|
88
|
+
const skillPathMap = buildSkillPathMap([skillsRoot]);
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(skillPathMap, {
|
|
91
|
+
"company-report": companyReportRoot.replace(/\\/g, "/"),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const normalized = ToolArgsNormalizer.normalizeToolArgs(
|
|
95
|
+
root,
|
|
96
|
+
[skillsRoot],
|
|
97
|
+
"execute",
|
|
98
|
+
{
|
|
99
|
+
command:
|
|
100
|
+
"node ${SKILL_PATH:company-report}/scripts/merge-report.mjs ${WORKSPACE}/output/company-report.json",
|
|
101
|
+
},
|
|
102
|
+
skillPathMap,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
assert.equal(
|
|
106
|
+
normalized.command,
|
|
107
|
+
`node ${companyReportRoot.replace(/\\/g, "/")}/scripts/merge-report.mjs ${root.replace(/\\/g, "/")}/output/company-report.json`,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
await rm(root, { recursive: true, force: true });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("ToolArgsNormalizer expands unnamed SKILL_PATH to the only active skill directory", async () => {
|
|
114
|
+
const root = join(tmpdir(), `agent-runtime2-single-skill-${Date.now()}`);
|
|
115
|
+
const skillsRoot = join(root, ".agent", "cache", "skills");
|
|
116
|
+
const companyReportRoot = join(skillsRoot, "company-report");
|
|
117
|
+
await mkdir(companyReportRoot, { recursive: true });
|
|
118
|
+
await writeFile(join(companyReportRoot, "SKILL.md"), "# company report\n", "utf8");
|
|
119
|
+
|
|
120
|
+
const normalized = ToolArgsNormalizer.normalizeToolArgs(
|
|
121
|
+
root,
|
|
122
|
+
[companyReportRoot],
|
|
123
|
+
"read_file",
|
|
124
|
+
{
|
|
125
|
+
path: "${SKILL_PATH}/SKILL.md",
|
|
126
|
+
},
|
|
127
|
+
buildSkillPathMap([companyReportRoot]),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
assert.equal(
|
|
131
|
+
normalized.path,
|
|
132
|
+
`${companyReportRoot.replace(/\\/g, "/")}/SKILL.md`,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
await rm(root, { recursive: true, force: true });
|
|
136
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"sourceMap": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|