agent-bundle 0.1.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/LICENSE +21 -0
- package/README.md +161 -0
- package/dist/agent/agent.d.ts +32 -0
- package/dist/agent/agent.js +241 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/agent.test-helpers.d.ts +63 -0
- package/dist/agent/agent.test-helpers.js +170 -0
- package/dist/agent/agent.test-helpers.js.map +1 -0
- package/dist/agent/define-agent.d.ts +2 -0
- package/dist/agent/define-agent.js +18 -0
- package/dist/agent/define-agent.js.map +1 -0
- package/dist/agent/dependencies.d.ts +15 -0
- package/dist/agent/dependencies.js +14 -0
- package/dist/agent/dependencies.js.map +1 -0
- package/dist/agent/index.d.ts +4 -0
- package/dist/agent/index.js +5 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/internals.d.ts +28 -0
- package/dist/agent/internals.js +160 -0
- package/dist/agent/internals.js.map +1 -0
- package/dist/agent/session.d.ts +4 -0
- package/dist/agent/session.js +2 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/types.d.ts +52 -0
- package/dist/agent/types.js +2 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent-loop/agent-loop.d.ts +27 -0
- package/dist/agent-loop/agent-loop.js +2 -0
- package/dist/agent-loop/agent-loop.js.map +1 -0
- package/dist/agent-loop/index.d.ts +4 -0
- package/dist/agent-loop/index.js +5 -0
- package/dist/agent-loop/index.js.map +1 -0
- package/dist/agent-loop/pi-mono/events.d.ts +3 -0
- package/dist/agent-loop/pi-mono/events.js +73 -0
- package/dist/agent-loop/pi-mono/events.js.map +1 -0
- package/dist/agent-loop/pi-mono/index.d.ts +1 -0
- package/dist/agent-loop/pi-mono/index.js +2 -0
- package/dist/agent-loop/pi-mono/index.js.map +1 -0
- package/dist/agent-loop/pi-mono/input.d.ts +6 -0
- package/dist/agent-loop/pi-mono/input.js +120 -0
- package/dist/agent-loop/pi-mono/input.js.map +1 -0
- package/dist/agent-loop/pi-mono/model.d.ts +7 -0
- package/dist/agent-loop/pi-mono/model.js +72 -0
- package/dist/agent-loop/pi-mono/model.js.map +1 -0
- package/dist/agent-loop/pi-mono/pi-mono-loop.d.ts +11 -0
- package/dist/agent-loop/pi-mono/pi-mono-loop.js +167 -0
- package/dist/agent-loop/pi-mono/pi-mono-loop.js.map +1 -0
- package/dist/agent-loop/pi-mono/pi-mono-loop.test-helpers.d.ts +28 -0
- package/dist/agent-loop/pi-mono/pi-mono-loop.test-helpers.js +76 -0
- package/dist/agent-loop/pi-mono/pi-mono-loop.test-helpers.js.map +1 -0
- package/dist/agent-loop/pi-mono/queue.d.ts +9 -0
- package/dist/agent-loop/pi-mono/queue.js +37 -0
- package/dist/agent-loop/pi-mono/queue.js.map +1 -0
- package/dist/agent-loop/pi-mono/tools.d.ts +4 -0
- package/dist/agent-loop/pi-mono/tools.js +164 -0
- package/dist/agent-loop/pi-mono/tools.js.map +1 -0
- package/dist/agent-loop/pi-mono/utils.d.ts +14 -0
- package/dist/agent-loop/pi-mono/utils.js +83 -0
- package/dist/agent-loop/pi-mono/utils.js.map +1 -0
- package/dist/agent-loop/system-prompt/fill.d.ts +1 -0
- package/dist/agent-loop/system-prompt/fill.js +19 -0
- package/dist/agent-loop/system-prompt/fill.js.map +1 -0
- package/dist/agent-loop/system-prompt/generate.d.ts +11 -0
- package/dist/agent-loop/system-prompt/generate.js +21 -0
- package/dist/agent-loop/system-prompt/generate.js.map +1 -0
- package/dist/agent-loop/system-prompt/index.d.ts +2 -0
- package/dist/agent-loop/system-prompt/index.js +3 -0
- package/dist/agent-loop/system-prompt/index.js.map +1 -0
- package/dist/agent-loop/types.d.ts +77 -0
- package/dist/agent-loop/types.js +2 -0
- package/dist/agent-loop/types.js.map +1 -0
- package/dist/cli/build/build.d.ts +35 -0
- package/dist/cli/build/build.js +174 -0
- package/dist/cli/build/build.js.map +1 -0
- package/dist/cli/build/build.test-helpers.d.ts +9 -0
- package/dist/cli/build/build.test-helpers.js +50 -0
- package/dist/cli/build/build.test-helpers.js.map +1 -0
- package/dist/cli/build/codegen-commands.d.ts +16 -0
- package/dist/cli/build/codegen-commands.js +81 -0
- package/dist/cli/build/codegen-commands.js.map +1 -0
- package/dist/cli/build/codegen.d.ts +55 -0
- package/dist/cli/build/codegen.js +212 -0
- package/dist/cli/build/codegen.js.map +1 -0
- package/dist/cli/build/e2b-template.d.ts +38 -0
- package/dist/cli/build/e2b-template.js +210 -0
- package/dist/cli/build/e2b-template.js.map +1 -0
- package/dist/cli/build/e2b-template.test-helpers.d.ts +19 -0
- package/dist/cli/build/e2b-template.test-helpers.js +80 -0
- package/dist/cli/build/e2b-template.test-helpers.js.map +1 -0
- package/dist/cli/build/sandbox-image.d.ts +35 -0
- package/dist/cli/build/sandbox-image.js +57 -0
- package/dist/cli/build/sandbox-image.js.map +1 -0
- package/dist/cli/build-codegen.d.ts +41 -0
- package/dist/cli/build-codegen.js +168 -0
- package/dist/cli/build-codegen.js.map +1 -0
- package/dist/cli/build-e2b-template.d.ts +38 -0
- package/dist/cli/build-e2b-template.js +223 -0
- package/dist/cli/build-e2b-template.js.map +1 -0
- package/dist/cli/build-e2b-template.test-helpers.d.ts +19 -0
- package/dist/cli/build-e2b-template.test-helpers.js +80 -0
- package/dist/cli/build-e2b-template.test-helpers.js.map +1 -0
- package/dist/cli/build-sandbox-image.d.ts +35 -0
- package/dist/cli/build-sandbox-image.js +57 -0
- package/dist/cli/build-sandbox-image.js.map +1 -0
- package/dist/cli/build.d.ts +30 -0
- package/dist/cli/build.js +151 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/build.test-helpers.d.ts +9 -0
- package/dist/cli/build.test-helpers.js +50 -0
- package/dist/cli/build.test-helpers.js.map +1 -0
- package/dist/cli/config/load-bundle-config.d.ts +2 -0
- package/dist/cli/config/load-bundle-config.js +20 -0
- package/dist/cli/config/load-bundle-config.js.map +1 -0
- package/dist/cli/config/resolve-project-root.d.ts +1 -0
- package/dist/cli/config/resolve-project-root.js +19 -0
- package/dist/cli/config/resolve-project-root.js.map +1 -0
- package/dist/cli/deploy/aws-cli.d.ts +42 -0
- package/dist/cli/deploy/aws-cli.js +95 -0
- package/dist/cli/deploy/aws-cli.js.map +1 -0
- package/dist/cli/deploy/aws-ecr.d.ts +20 -0
- package/dist/cli/deploy/aws-ecr.js +97 -0
- package/dist/cli/deploy/aws-ecr.js.map +1 -0
- package/dist/cli/deploy/aws-ecs-infra.d.ts +39 -0
- package/dist/cli/deploy/aws-ecs-infra.js +169 -0
- package/dist/cli/deploy/aws-ecs-infra.js.map +1 -0
- package/dist/cli/deploy/aws-ecs-role.d.ts +9 -0
- package/dist/cli/deploy/aws-ecs-role.js +114 -0
- package/dist/cli/deploy/aws-ecs-role.js.map +1 -0
- package/dist/cli/deploy/aws-ecs-service.d.ts +37 -0
- package/dist/cli/deploy/aws-ecs-service.js +207 -0
- package/dist/cli/deploy/aws-ecs-service.js.map +1 -0
- package/dist/cli/deploy/aws-ecs-shared.d.ts +59 -0
- package/dist/cli/deploy/aws-ecs-shared.js +30 -0
- package/dist/cli/deploy/aws-ecs-shared.js.map +1 -0
- package/dist/cli/deploy/aws-ecs.d.ts +3 -0
- package/dist/cli/deploy/aws-ecs.js +141 -0
- package/dist/cli/deploy/aws-ecs.js.map +1 -0
- package/dist/cli/deploy/aws-prerequisites.d.ts +16 -0
- package/dist/cli/deploy/aws-prerequisites.js +28 -0
- package/dist/cli/deploy/aws-prerequisites.js.map +1 -0
- package/dist/cli/deploy/aws-teardown.d.ts +13 -0
- package/dist/cli/deploy/aws-teardown.js +204 -0
- package/dist/cli/deploy/aws-teardown.js.map +1 -0
- package/dist/cli/deploy/deploy.d.ts +36 -0
- package/dist/cli/deploy/deploy.js +209 -0
- package/dist/cli/deploy/deploy.js.map +1 -0
- package/dist/cli/error.d.ts +1 -0
- package/dist/cli/error.js +4 -0
- package/dist/cli/error.js.map +1 -0
- package/dist/cli/generate/generate.d.ts +37 -0
- package/dist/cli/generate/generate.js +121 -0
- package/dist/cli/generate/generate.js.map +1 -0
- package/dist/cli/generate.d.ts +32 -0
- package/dist/cli/generate.js +102 -0
- package/dist/cli/generate.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +182 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/load-bundle-config.d.ts +2 -0
- package/dist/cli/load-bundle-config.js +20 -0
- package/dist/cli/load-bundle-config.js.map +1 -0
- package/dist/cli/resolve-project-root.d.ts +1 -0
- package/dist/cli/resolve-project-root.js +19 -0
- package/dist/cli/resolve-project-root.js.map +1 -0
- package/dist/cli/serve/dev.d.ts +6 -0
- package/dist/cli/serve/dev.js +73 -0
- package/dist/cli/serve/dev.js.map +1 -0
- package/dist/cli/serve/http.d.ts +12 -0
- package/dist/cli/serve/http.js +123 -0
- package/dist/cli/serve/http.js.map +1 -0
- package/dist/cli/serve/init.d.ts +42 -0
- package/dist/cli/serve/init.js +110 -0
- package/dist/cli/serve/init.js.map +1 -0
- package/dist/cli/serve/runtime.d.ts +25 -0
- package/dist/cli/serve/runtime.js +142 -0
- package/dist/cli/serve/runtime.js.map +1 -0
- package/dist/cli/serve/serve.d.ts +7 -0
- package/dist/cli/serve/serve.js +63 -0
- package/dist/cli/serve/serve.js.map +1 -0
- package/dist/cli/serve/serve.test-helpers.d.ts +36 -0
- package/dist/cli/serve/serve.test-helpers.js +205 -0
- package/dist/cli/serve/serve.test-helpers.js.map +1 -0
- package/dist/cli/serve/worktree-port.d.ts +36 -0
- package/dist/cli/serve/worktree-port.js +124 -0
- package/dist/cli/serve/worktree-port.js.map +1 -0
- package/dist/cli/serve-http.d.ts +12 -0
- package/dist/cli/serve-http.js +112 -0
- package/dist/cli/serve-http.js.map +1 -0
- package/dist/cli/serve-runtime.d.ts +16 -0
- package/dist/cli/serve-runtime.js +122 -0
- package/dist/cli/serve-runtime.js.map +1 -0
- package/dist/cli/serve.d.ts +33 -0
- package/dist/cli/serve.js +150 -0
- package/dist/cli/serve.js.map +1 -0
- package/dist/cli/serve.test-helpers.d.ts +30 -0
- package/dist/cli/serve.test-helpers.js +145 -0
- package/dist/cli/serve.test-helpers.js.map +1 -0
- package/dist/code-formatter/bundle.json +41 -0
- package/dist/code-formatter/index.ts +26 -0
- package/dist/code-formatter/package.json +10 -0
- package/dist/code-formatter/types.ts +2 -0
- package/dist/code-formatter-e2b/bundle.json +40 -0
- package/dist/code-formatter-e2b/index.ts +25 -0
- package/dist/code-formatter-e2b/package.json +10 -0
- package/dist/code-formatter-e2b/types.ts +2 -0
- package/dist/coding-assistant-ollama/bundle.json +43 -0
- package/dist/coding-assistant-ollama/index.ts +28 -0
- package/dist/coding-assistant-ollama/package.json +10 -0
- package/dist/coding-assistant-ollama/types.ts +2 -0
- package/dist/commands/find.d.ts +8 -0
- package/dist/commands/find.js +11 -0
- package/dist/commands/find.js.map +1 -0
- package/dist/commands/loader.d.ts +13 -0
- package/dist/commands/loader.js +163 -0
- package/dist/commands/loader.js.map +1 -0
- package/dist/commands/types.d.ts +7 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/with-commands.d.ts +6 -0
- package/dist/commands/with-commands.js +19 -0
- package/dist/commands/with-commands.js.map +1 -0
- package/dist/data-analyst/bundle.json +40 -0
- package/dist/data-analyst/index.ts +25 -0
- package/dist/data-analyst/package.json +10 -0
- package/dist/data-analyst/types.ts +2 -0
- package/dist/financial-analyst/bundle.json +40 -0
- package/dist/financial-analyst/index.ts +25 -0
- package/dist/financial-analyst/package.json +10 -0
- package/dist/financial-analyst/types.ts +2 -0
- package/dist/mcp/client-manager.d.ts +26 -0
- package/dist/mcp/client-manager.js +101 -0
- package/dist/mcp/client-manager.js.map +1 -0
- package/dist/mcp/connect-server.d.ts +21 -0
- package/dist/mcp/connect-server.js +170 -0
- package/dist/mcp/connect-server.js.map +1 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/sandbox-stdio-transport.d.ts +32 -0
- package/dist/mcp/sandbox-stdio-transport.js +199 -0
- package/dist/mcp/sandbox-stdio-transport.js.map +1 -0
- package/dist/observability/hooks.d.ts +10 -0
- package/dist/observability/hooks.js +97 -0
- package/dist/observability/hooks.js.map +1 -0
- package/dist/observability/index.d.ts +6 -0
- package/dist/observability/index.js +7 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/metrics.d.ts +31 -0
- package/dist/observability/metrics.js +61 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/middleware.d.ts +12 -0
- package/dist/observability/middleware.js +45 -0
- package/dist/observability/middleware.js.map +1 -0
- package/dist/observability/otel-harness.test-util.d.ts +37 -0
- package/dist/observability/otel-harness.test-util.js +96 -0
- package/dist/observability/otel-harness.test-util.js.map +1 -0
- package/dist/observability/provider.d.ts +8 -0
- package/dist/observability/provider.js +19 -0
- package/dist/observability/provider.js.map +1 -0
- package/dist/observability/tracing.d.ts +14 -0
- package/dist/observability/tracing.js +40 -0
- package/dist/observability/tracing.js.map +1 -0
- package/dist/observability/types.d.ts +39 -0
- package/dist/observability/types.js +31 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/personalized-recommend/bundle.json +64 -0
- package/dist/personalized-recommend/index.ts +41 -0
- package/dist/personalized-recommend/package.json +10 -0
- package/dist/personalized-recommend/types.ts +2 -0
- package/dist/plugins/loader.d.ts +11 -0
- package/dist/plugins/loader.js +100 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/merge.d.ts +10 -0
- package/dist/plugins/merge.js +22 -0
- package/dist/plugins/merge.js.map +1 -0
- package/dist/plugins/parse.d.ts +10 -0
- package/dist/plugins/parse.js +139 -0
- package/dist/plugins/parse.js.map +1 -0
- package/dist/plugins/types.d.ts +28 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/urls.d.ts +7 -0
- package/dist/plugins/urls.js +40 -0
- package/dist/plugins/urls.js.map +1 -0
- package/dist/runtime.d.ts +5 -0
- package/dist/runtime.js +3 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sandbox/factory.d.ts +2 -0
- package/dist/sandbox/factory.js +27 -0
- package/dist/sandbox/factory.js.map +1 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/providers/e2b.d.ts +28 -0
- package/dist/sandbox/providers/e2b.js +294 -0
- package/dist/sandbox/providers/e2b.js.map +1 -0
- package/dist/sandbox/providers/kubernetes-command-run.d.ts +8 -0
- package/dist/sandbox/providers/kubernetes-command-run.js +195 -0
- package/dist/sandbox/providers/kubernetes-command-run.js.map +1 -0
- package/dist/sandbox/providers/kubernetes-helpers.d.ts +31 -0
- package/dist/sandbox/providers/kubernetes-helpers.js +152 -0
- package/dist/sandbox/providers/kubernetes-helpers.js.map +1 -0
- package/dist/sandbox/providers/kubernetes-kubeconfig.d.ts +7 -0
- package/dist/sandbox/providers/kubernetes-kubeconfig.js +51 -0
- package/dist/sandbox/providers/kubernetes-kubeconfig.js.map +1 -0
- package/dist/sandbox/providers/kubernetes-spawn.d.ts +2 -0
- package/dist/sandbox/providers/kubernetes-spawn.js +42 -0
- package/dist/sandbox/providers/kubernetes-spawn.js.map +1 -0
- package/dist/sandbox/providers/kubernetes-spawn.utils.d.ts +32 -0
- package/dist/sandbox/providers/kubernetes-spawn.utils.js +249 -0
- package/dist/sandbox/providers/kubernetes-spawn.utils.js.map +1 -0
- package/dist/sandbox/providers/kubernetes.constants.d.ts +3 -0
- package/dist/sandbox/providers/kubernetes.constants.js +4 -0
- package/dist/sandbox/providers/kubernetes.constants.js.map +1 -0
- package/dist/sandbox/providers/kubernetes.d.ts +37 -0
- package/dist/sandbox/providers/kubernetes.js +258 -0
- package/dist/sandbox/providers/kubernetes.js.map +1 -0
- package/dist/sandbox/types.d.ts +57 -0
- package/dist/sandbox/types.js +2 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/sandbox/utils.d.ts +1 -0
- package/dist/sandbox/utils.js +4 -0
- package/dist/sandbox/utils.js.map +1 -0
- package/dist/schema/bundle.d.ts +143 -0
- package/dist/schema/bundle.js +203 -0
- package/dist/schema/bundle.js.map +1 -0
- package/dist/service/command-routes.d.ts +8 -0
- package/dist/service/command-routes.js +44 -0
- package/dist/service/command-routes.js.map +1 -0
- package/dist/service/create-server.d.ts +9 -0
- package/dist/service/create-server.js +113 -0
- package/dist/service/create-server.js.map +1 -0
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +2 -0
- package/dist/service/index.js.map +1 -0
- package/dist/skills/index.d.ts +1 -0
- package/dist/skills/index.js +2 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loader.d.ts +18 -0
- package/dist/skills/loader.js +142 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/summaries.d.ts +8 -0
- package/dist/skills/summaries.js +9 -0
- package/dist/skills/summaries.js.map +1 -0
- package/dist/test-helpers/env.d.ts +2 -0
- package/dist/test-helpers/env.js +20 -0
- package/dist/test-helpers/env.js.map +1 -0
- package/dist/test-helpers/mock-agent.d.ts +56 -0
- package/dist/test-helpers/mock-agent.js +180 -0
- package/dist/test-helpers/mock-agent.js.map +1 -0
- package/dist/test-helpers/mock-sandbox.d.ts +33 -0
- package/dist/test-helpers/mock-sandbox.js +200 -0
- package/dist/test-helpers/mock-sandbox.js.map +1 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +3 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/tui/render.d.ts +8 -0
- package/dist/tui/render.js +40 -0
- package/dist/tui/render.js.map +1 -0
- package/dist/tui/tui.d.ts +19 -0
- package/dist/tui/tui.js +133 -0
- package/dist/tui/tui.js.map +1 -0
- package/dist/webui/create-webui-server.d.ts +22 -0
- package/dist/webui/create-webui-server.js +293 -0
- package/dist/webui/create-webui-server.js.map +1 -0
- package/dist/webui/event-bus.d.ts +16 -0
- package/dist/webui/event-bus.js +24 -0
- package/dist/webui/event-bus.js.map +1 -0
- package/dist/webui/index.d.ts +2 -0
- package/dist/webui/index.js +3 -0
- package/dist/webui/index.js.map +1 -0
- package/dist/webui/public/app.js +847 -0
- package/dist/webui/public/file-transfer.js +114 -0
- package/dist/webui/public/index.html +166 -0
- package/dist/webui/public/styles.css +1678 -0
- package/package.json +99 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { bashTool as piBashTool, editTool as piEditTool, readTool as piReadTool, writeTool as piWriteTool, } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { isRecord, readNumberField, requireStringField, toInputRecord, toToolOutputText, } from "./utils.js";
|
|
3
|
+
function toBundleToolName(toolName) {
|
|
4
|
+
const normalized = toolName.trim().toLowerCase();
|
|
5
|
+
if (normalized === "read") {
|
|
6
|
+
return "Read";
|
|
7
|
+
}
|
|
8
|
+
if (normalized === "write") {
|
|
9
|
+
return "Write";
|
|
10
|
+
}
|
|
11
|
+
if (normalized === "edit") {
|
|
12
|
+
return "Edit";
|
|
13
|
+
}
|
|
14
|
+
if (normalized === "bash") {
|
|
15
|
+
return "Bash";
|
|
16
|
+
}
|
|
17
|
+
return toolName;
|
|
18
|
+
}
|
|
19
|
+
function createTool(name, description, parameters, toHandlerInput, toolHandler) {
|
|
20
|
+
return {
|
|
21
|
+
name,
|
|
22
|
+
label: name,
|
|
23
|
+
description,
|
|
24
|
+
parameters,
|
|
25
|
+
execute: async (toolCallId, rawInput) => {
|
|
26
|
+
const input = toHandlerInput(toInputRecord(rawInput));
|
|
27
|
+
const toolResult = await toolHandler({
|
|
28
|
+
id: toolCallId,
|
|
29
|
+
name: toBundleToolName(name),
|
|
30
|
+
input,
|
|
31
|
+
});
|
|
32
|
+
if (toolResult.isError) {
|
|
33
|
+
throw new Error(toToolOutputText(toolResult.output));
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
content: [{ type: "text", text: toToolOutputText(toolResult.output) }],
|
|
37
|
+
details: toolResult.output,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function toAgentToolParameters(inputSchema) {
|
|
43
|
+
// pi-agent-core models tool parameters as TypeBox schemas, while MCP tool discovery returns
|
|
44
|
+
// JSON Schema objects. Runtime consumers in pi-mono read JSON Schema-compatible fields, so
|
|
45
|
+
// we keep the schema object unchanged when bridging discovered MCP tools.
|
|
46
|
+
return inputSchema;
|
|
47
|
+
}
|
|
48
|
+
function createExternalTool(tool, toolHandler) {
|
|
49
|
+
return {
|
|
50
|
+
name: tool.name,
|
|
51
|
+
label: tool.name,
|
|
52
|
+
description: tool.description,
|
|
53
|
+
parameters: toAgentToolParameters(tool.inputSchema),
|
|
54
|
+
execute: async (toolCallId, rawInput) => {
|
|
55
|
+
const toolResult = await toolHandler({
|
|
56
|
+
id: toolCallId,
|
|
57
|
+
name: tool.name,
|
|
58
|
+
input: toInputRecord(rawInput),
|
|
59
|
+
});
|
|
60
|
+
if (toolResult.isError) {
|
|
61
|
+
throw new Error(toToolOutputText(toolResult.output));
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
content: [{ type: "text", text: toToolOutputText(toolResult.output) }],
|
|
65
|
+
details: toolResult.output,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function toReadOutputText(output) {
|
|
71
|
+
if (typeof output === "string") {
|
|
72
|
+
return output;
|
|
73
|
+
}
|
|
74
|
+
if (isRecord(output) && typeof output.content === "string") {
|
|
75
|
+
return output.content;
|
|
76
|
+
}
|
|
77
|
+
throw new Error("Read tool returned non-text output. Edit requires full text file content.");
|
|
78
|
+
}
|
|
79
|
+
function replaceTextExactlyOnce(fileContent, oldText, newText, path) {
|
|
80
|
+
if (!fileContent.includes(oldText)) {
|
|
81
|
+
throw new Error(`Could not find the exact text in ${path}. The old text must match exactly including whitespace and newlines.`);
|
|
82
|
+
}
|
|
83
|
+
const occurrences = fileContent.split(oldText).length - 1;
|
|
84
|
+
if (occurrences > 1) {
|
|
85
|
+
throw new Error(`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`);
|
|
86
|
+
}
|
|
87
|
+
const index = fileContent.indexOf(oldText);
|
|
88
|
+
const updatedContent = fileContent.substring(0, index)
|
|
89
|
+
+ newText
|
|
90
|
+
+ fileContent.substring(index + oldText.length);
|
|
91
|
+
if (updatedContent === fileContent) {
|
|
92
|
+
throw new Error(`No changes made to ${path}. The replacement produced identical content.`);
|
|
93
|
+
}
|
|
94
|
+
return updatedContent;
|
|
95
|
+
}
|
|
96
|
+
function createEditTool(toolHandler) {
|
|
97
|
+
return {
|
|
98
|
+
name: "edit",
|
|
99
|
+
label: "edit",
|
|
100
|
+
description: piEditTool.description,
|
|
101
|
+
parameters: piEditTool.parameters,
|
|
102
|
+
execute: async (toolCallId, rawInput) => {
|
|
103
|
+
const input = toInputRecord(rawInput);
|
|
104
|
+
const path = requireStringField(input, "path", "edit");
|
|
105
|
+
const oldText = requireStringField(input, "oldText", "edit");
|
|
106
|
+
const newText = requireStringField(input, "newText", "edit");
|
|
107
|
+
const readResult = await toolHandler({
|
|
108
|
+
id: `${toolCallId}:read`,
|
|
109
|
+
name: "Read",
|
|
110
|
+
input: { path },
|
|
111
|
+
});
|
|
112
|
+
if (readResult.isError) {
|
|
113
|
+
throw new Error(toToolOutputText(readResult.output));
|
|
114
|
+
}
|
|
115
|
+
const fileContent = toReadOutputText(readResult.output);
|
|
116
|
+
const updatedContent = replaceTextExactlyOnce(fileContent, oldText, newText, path);
|
|
117
|
+
const writeResult = await toolHandler({
|
|
118
|
+
id: `${toolCallId}:write`,
|
|
119
|
+
name: "Write",
|
|
120
|
+
input: {
|
|
121
|
+
path,
|
|
122
|
+
content: updatedContent,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
if (writeResult.isError) {
|
|
126
|
+
throw new Error(toToolOutputText(writeResult.output));
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
content: [{
|
|
130
|
+
type: "text",
|
|
131
|
+
text: `Successfully replaced text in ${path}. Changed ${oldText.length} characters to ${newText.length} characters.`,
|
|
132
|
+
}],
|
|
133
|
+
details: {
|
|
134
|
+
oldLength: fileContent.length,
|
|
135
|
+
newLength: updatedContent.length,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function createPiTools(toolHandler, externalTools = []) {
|
|
142
|
+
const builtInTools = [
|
|
143
|
+
createTool("read", piReadTool.description, piReadTool.parameters, (input) => ({
|
|
144
|
+
path: requireStringField(input, "path", "read"),
|
|
145
|
+
offset: readNumberField(input, "offset"),
|
|
146
|
+
limit: readNumberField(input, "limit"),
|
|
147
|
+
}), toolHandler),
|
|
148
|
+
createTool("write", piWriteTool.description, piWriteTool.parameters, (input) => ({
|
|
149
|
+
path: requireStringField(input, "path", "write"),
|
|
150
|
+
content: requireStringField(input, "content", "write"),
|
|
151
|
+
}), toolHandler),
|
|
152
|
+
createEditTool(toolHandler),
|
|
153
|
+
createTool("bash", piBashTool.description, piBashTool.parameters, (input) => ({
|
|
154
|
+
command: requireStringField(input, "command", "bash"),
|
|
155
|
+
timeout: readNumberField(input, "timeout"),
|
|
156
|
+
}), toolHandler),
|
|
157
|
+
];
|
|
158
|
+
const dynamicTools = externalTools.map((tool) => createExternalTool(tool, toolHandler));
|
|
159
|
+
return [...builtInTools, ...dynamicTools];
|
|
160
|
+
}
|
|
161
|
+
export function toBundleToolCallName(toolName) {
|
|
162
|
+
return toBundleToolName(toolName);
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/agent-loop/pi-mono/tools.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,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AAC,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,YAAY,EAAE,GAAG,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACnD,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TokenUsage } from "../types.js";
|
|
2
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
3
|
+
export declare function toErrorMessage(error: unknown): string;
|
|
4
|
+
export declare function stringifyUnknown(value: unknown): string;
|
|
5
|
+
export declare function toToolOutputText(output: unknown): string;
|
|
6
|
+
export declare function toToolContent(output: unknown, fallbackText: string): string;
|
|
7
|
+
export declare function toTokenUsage(usage: {
|
|
8
|
+
input: number;
|
|
9
|
+
output: number;
|
|
10
|
+
totalTokens: number;
|
|
11
|
+
} | undefined): TokenUsage | undefined;
|
|
12
|
+
export declare function toInputRecord(value: unknown): Record<string, unknown>;
|
|
13
|
+
export declare function requireStringField(input: Record<string, unknown>, fieldName: string, toolName: string): string;
|
|
14
|
+
export declare function readNumberField(input: Record<string, unknown>, fieldName: string): number | undefined;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export function isRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
export function toErrorMessage(error) {
|
|
5
|
+
if (error instanceof Error) {
|
|
6
|
+
return error.message;
|
|
7
|
+
}
|
|
8
|
+
return String(error);
|
|
9
|
+
}
|
|
10
|
+
function isExecResultLike(value) {
|
|
11
|
+
if (!isRecord(value)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return (typeof value.stdout === "string"
|
|
15
|
+
&& typeof value.stderr === "string"
|
|
16
|
+
&& typeof value.exitCode === "number");
|
|
17
|
+
}
|
|
18
|
+
export function stringifyUnknown(value) {
|
|
19
|
+
if (typeof value === "string") {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
if (value === null || value === undefined) {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
if (isExecResultLike(value)) {
|
|
26
|
+
const sections = [
|
|
27
|
+
`exitCode: ${value.exitCode}`,
|
|
28
|
+
value.stdout.length > 0 ? `stdout:\n${value.stdout}` : "stdout: (empty)",
|
|
29
|
+
value.stderr.length > 0 ? `stderr:\n${value.stderr}` : "stderr: (empty)",
|
|
30
|
+
];
|
|
31
|
+
return sections.join("\n\n");
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(value, null, 2);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return String(value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function toToolOutputText(output) {
|
|
41
|
+
const text = stringifyUnknown(output).trim();
|
|
42
|
+
return text.length > 0 ? text : "Tool completed with no output.";
|
|
43
|
+
}
|
|
44
|
+
export function toToolContent(output, fallbackText) {
|
|
45
|
+
const text = stringifyUnknown(output).trim();
|
|
46
|
+
if (text.length > 0) {
|
|
47
|
+
return text;
|
|
48
|
+
}
|
|
49
|
+
return fallbackText.trim().length > 0 ? fallbackText : "(empty tool result)";
|
|
50
|
+
}
|
|
51
|
+
export function toTokenUsage(usage) {
|
|
52
|
+
if (!usage) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (!Number.isFinite(usage.input)
|
|
56
|
+
|| !Number.isFinite(usage.output)
|
|
57
|
+
|| !Number.isFinite(usage.totalTokens)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
inputTokens: usage.input,
|
|
62
|
+
outputTokens: usage.output,
|
|
63
|
+
totalTokens: usage.totalTokens,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function toInputRecord(value) {
|
|
67
|
+
if (!isRecord(value)) {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
return Object.fromEntries(Object.entries(value));
|
|
71
|
+
}
|
|
72
|
+
export function requireStringField(input, fieldName, toolName) {
|
|
73
|
+
const value = input[fieldName];
|
|
74
|
+
if (typeof value !== "string") {
|
|
75
|
+
throw new Error(`Invalid ${toolName} tool input: field \"${fieldName}\" must be a string.`);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
export function readNumberField(input, fieldName) {
|
|
80
|
+
const value = input[fieldName];
|
|
81
|
+
return typeof value === "number" ? value : undefined;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/agent-loop/pi-mono/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IAKtC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;WAC7B,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;WAChC,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,CACtC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAA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CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fillSystemPrompt(template: string, variables: Record<string, string>): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const PLACEHOLDER_PATTERN = /{{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*}}/g;
|
|
2
|
+
function collectRequiredVariables(template) {
|
|
3
|
+
const required = new Set();
|
|
4
|
+
for (const match of template.matchAll(PLACEHOLDER_PATTERN)) {
|
|
5
|
+
required.add(match[1]);
|
|
6
|
+
}
|
|
7
|
+
return [...required];
|
|
8
|
+
}
|
|
9
|
+
export function fillSystemPrompt(template, variables) {
|
|
10
|
+
const missingVariables = collectRequiredVariables(template).filter((name) => !Object.hasOwn(variables, name));
|
|
11
|
+
if (missingVariables.length > 0) {
|
|
12
|
+
const missingText = missingVariables.sort().join(", ");
|
|
13
|
+
throw new Error(`Missing required prompt variables: ${missingText}`);
|
|
14
|
+
}
|
|
15
|
+
return template.replace(PLACEHOLDER_PATTERN, (_match, key) => {
|
|
16
|
+
return variables[key];
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=fill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fill.js","sourceRoot":"","sources":["../../../src/agent-loop/system-prompt/fill.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAElE,SAAS,wBAAwB,CAAC,QAAgB;IAChD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC3D,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,QAAgB,EAChB,SAAiC;IAEjC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC,MAAM,CAChE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAC1C,CAAC;IAEF,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,sCAAsC,WAAW,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,MAAM,EAAE,GAAW,EAAE,EAAE;QACnE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type SkillSummary = {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
sourcePath: string;
|
|
5
|
+
content?: string;
|
|
6
|
+
};
|
|
7
|
+
export type GenerateSystemPromptInput = {
|
|
8
|
+
basePrompt: string;
|
|
9
|
+
skills: SkillSummary[];
|
|
10
|
+
};
|
|
11
|
+
export declare function generateSystemPromptTemplate(input: GenerateSystemPromptInput): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function formatSkillsSection(skills) {
|
|
2
|
+
const sections = skills.map((skill) => {
|
|
3
|
+
if (skill.content) {
|
|
4
|
+
return `### ${skill.name}\n${skill.content.trim()}`;
|
|
5
|
+
}
|
|
6
|
+
const location = skill.sourcePath.trim();
|
|
7
|
+
if (location.length === 0) {
|
|
8
|
+
throw new Error(`Skill "${skill.name}" is missing sourcePath.`);
|
|
9
|
+
}
|
|
10
|
+
return `- ${skill.name}: ${skill.description} (${location})`;
|
|
11
|
+
});
|
|
12
|
+
return ["## Skills", ...sections].join("\n\n");
|
|
13
|
+
}
|
|
14
|
+
export function generateSystemPromptTemplate(input) {
|
|
15
|
+
const trimmedBasePrompt = input.basePrompt.trim();
|
|
16
|
+
if (input.skills.length === 0) {
|
|
17
|
+
return trimmedBasePrompt;
|
|
18
|
+
}
|
|
19
|
+
return [trimmedBasePrompt, formatSkillsSection(input.skills)].join("\n\n");
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/agent-loop/system-prompt/generate.ts"],"names":[],"mappings":"AAYA,SAAS,mBAAmB,CAAC,MAAsB;IACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,OAAO,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QACtD,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,IAAI,0BAA0B,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,WAAW,KAAK,QAAQ,GAAG,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAAgC;IAC3E,MAAM,iBAAiB,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAClD,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent-loop/system-prompt/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export type ModelProvider = "anthropic" | "openai" | "gemini" | "ollama" | "openrouter";
|
|
2
|
+
export type ModelConfig = {
|
|
3
|
+
provider: ModelProvider;
|
|
4
|
+
model: string;
|
|
5
|
+
ollama?: {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
contextWindow?: number;
|
|
8
|
+
maxTokens?: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type ToolCall = {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
export type ToolResult = {
|
|
17
|
+
toolCallId: string;
|
|
18
|
+
output: unknown;
|
|
19
|
+
isError?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type ResponseInputMessage = {
|
|
22
|
+
role: "system" | "user";
|
|
23
|
+
content: string;
|
|
24
|
+
} | {
|
|
25
|
+
role: "assistant";
|
|
26
|
+
content: string;
|
|
27
|
+
tool_calls?: ToolCall[];
|
|
28
|
+
} | {
|
|
29
|
+
role: "tool";
|
|
30
|
+
content: string;
|
|
31
|
+
tool_results: ToolResult[];
|
|
32
|
+
};
|
|
33
|
+
export type ResponseInput = ResponseInputMessage[];
|
|
34
|
+
export type TokenUsage = {
|
|
35
|
+
inputTokens: number;
|
|
36
|
+
outputTokens: number;
|
|
37
|
+
totalTokens: number;
|
|
38
|
+
};
|
|
39
|
+
export type ResponseOutput = {
|
|
40
|
+
id: string;
|
|
41
|
+
output: string;
|
|
42
|
+
usage?: TokenUsage;
|
|
43
|
+
};
|
|
44
|
+
export type ResponseCreatedEvent = {
|
|
45
|
+
type: "response.created";
|
|
46
|
+
responseId: string;
|
|
47
|
+
};
|
|
48
|
+
export type ResponseOutputTextDeltaEvent = {
|
|
49
|
+
type: "response.output_text.delta";
|
|
50
|
+
delta: string;
|
|
51
|
+
};
|
|
52
|
+
export type ResponseOutputTextDoneEvent = {
|
|
53
|
+
type: "response.output_text.done";
|
|
54
|
+
text: string;
|
|
55
|
+
};
|
|
56
|
+
export type ResponseToolCallCreatedEvent = {
|
|
57
|
+
type: "response.tool_call.created";
|
|
58
|
+
toolCall: ToolCall;
|
|
59
|
+
};
|
|
60
|
+
export type ResponseToolCallDoneEvent = {
|
|
61
|
+
type: "response.tool_call.done";
|
|
62
|
+
result: ToolResult;
|
|
63
|
+
};
|
|
64
|
+
export type ToolExecutionUpdateEvent = {
|
|
65
|
+
type: "tool_execution_update";
|
|
66
|
+
toolCallId: string;
|
|
67
|
+
chunk: string;
|
|
68
|
+
};
|
|
69
|
+
export type ResponseCompletedEvent = {
|
|
70
|
+
type: "response.completed";
|
|
71
|
+
output: ResponseOutput;
|
|
72
|
+
};
|
|
73
|
+
export type ResponseErrorEvent = {
|
|
74
|
+
type: "response.error";
|
|
75
|
+
error: string;
|
|
76
|
+
};
|
|
77
|
+
export type ResponseEvent = ResponseCreatedEvent | ResponseOutputTextDeltaEvent | ResponseOutputTextDoneEvent | ResponseToolCallCreatedEvent | ResponseToolCallDoneEvent | ToolExecutionUpdateEvent | ResponseCompletedEvent | ResponseErrorEvent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent-loop/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import type { Writable } from "node:stream";
|
|
3
|
+
import { generateSystemPromptTemplate } from "../../agent-loop/system-prompt/generate.js";
|
|
4
|
+
import { loadAllCommands } from "../../commands/loader.js";
|
|
5
|
+
import { loadAllPlugins, type LoadPluginOptions } from "../../plugins/loader.js";
|
|
6
|
+
import { loadAllSkills } from "../../skills/loader.js";
|
|
7
|
+
import { type ResolvedBundleConfig } from "./codegen.js";
|
|
8
|
+
import { buildE2BTemplate } from "./e2b-template.js";
|
|
9
|
+
import { buildSandboxImage } from "./sandbox-image.js";
|
|
10
|
+
import { loadBundleConfig } from "../config/load-bundle-config.js";
|
|
11
|
+
export declare const DEFAULT_OUTPUT_DIR = "dist";
|
|
12
|
+
export type RunBuildOptions = {
|
|
13
|
+
configPath: string;
|
|
14
|
+
outputDir?: string;
|
|
15
|
+
stdout?: Writable;
|
|
16
|
+
stderr?: Writable;
|
|
17
|
+
};
|
|
18
|
+
export type RunBuildResult = {
|
|
19
|
+
outputDir: string;
|
|
20
|
+
resolvedConfig: ResolvedBundleConfig;
|
|
21
|
+
};
|
|
22
|
+
type BuildDependencies = {
|
|
23
|
+
loadConfig?: typeof loadBundleConfig;
|
|
24
|
+
loadSkills?: typeof loadAllSkills;
|
|
25
|
+
loadCommands?: typeof loadAllCommands;
|
|
26
|
+
loadPlugins?: typeof loadAllPlugins;
|
|
27
|
+
generateSystemPrompt?: typeof generateSystemPromptTemplate;
|
|
28
|
+
buildSandbox?: typeof buildSandboxImage;
|
|
29
|
+
buildE2B?: typeof buildE2BTemplate;
|
|
30
|
+
writeFileImpl?: typeof writeFile;
|
|
31
|
+
mkdirImpl?: typeof mkdir;
|
|
32
|
+
pluginOptions?: LoadPluginOptions;
|
|
33
|
+
};
|
|
34
|
+
export declare function runBuildCommand(options: RunBuildOptions, dependencies?: BuildDependencies): Promise<RunBuildResult>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { generateSystemPromptTemplate } from "../../agent-loop/system-prompt/generate.js";
|
|
4
|
+
import { loadAllCommands } from "../../commands/loader.js";
|
|
5
|
+
import { loadAllPlugins } from "../../plugins/loader.js";
|
|
6
|
+
import { mergePluginComponents } from "../../plugins/merge.js";
|
|
7
|
+
import { loadAllSkills } from "../../skills/loader.js";
|
|
8
|
+
import { toSkillSummaries } from "../../skills/summaries.js";
|
|
9
|
+
import { createResolvedBundleConfig, generateSources, toCommandSummaries, } from "./codegen.js";
|
|
10
|
+
import { buildE2BTemplate } from "./e2b-template.js";
|
|
11
|
+
import { buildSandboxImage } from "./sandbox-image.js";
|
|
12
|
+
import { writeGeneratedFiles } from "../generate/generate.js";
|
|
13
|
+
import { loadBundleConfig } from "../config/load-bundle-config.js";
|
|
14
|
+
export const DEFAULT_OUTPUT_DIR = "dist";
|
|
15
|
+
function ensureKubernetesImage(config) {
|
|
16
|
+
const image = config.sandbox.kubernetes?.image;
|
|
17
|
+
if (!image) {
|
|
18
|
+
throw new Error("sandbox.kubernetes.image is required when sandbox provider is kubernetes.");
|
|
19
|
+
}
|
|
20
|
+
return image;
|
|
21
|
+
}
|
|
22
|
+
function ensureE2BTemplate(config) {
|
|
23
|
+
const template = config.sandbox.e2b?.template;
|
|
24
|
+
if (!template) {
|
|
25
|
+
throw new Error("sandbox.e2b.template is required when sandbox provider is e2b.");
|
|
26
|
+
}
|
|
27
|
+
return template;
|
|
28
|
+
}
|
|
29
|
+
function ensureE2BDockerfile(config) {
|
|
30
|
+
const dockerfile = config.sandbox.e2b?.build?.dockerfile;
|
|
31
|
+
if (!dockerfile) {
|
|
32
|
+
throw new Error("sandbox.e2b.build.dockerfile is required when sandbox provider is e2b.");
|
|
33
|
+
}
|
|
34
|
+
return dockerfile;
|
|
35
|
+
}
|
|
36
|
+
async function buildKubernetesSandboxImage(input) {
|
|
37
|
+
const imageTag = ensureKubernetesImage(input.config);
|
|
38
|
+
const buildConfig = input.config.sandbox.kubernetes?.build;
|
|
39
|
+
if (!buildConfig) {
|
|
40
|
+
input.stdout.write(`Skipping docker build and using configured image: ${imageTag}\n`);
|
|
41
|
+
return {
|
|
42
|
+
provider: "kubernetes",
|
|
43
|
+
ref: imageTag,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
input.stdout.write(`Building sandbox image with Docker: ${imageTag}\n`);
|
|
47
|
+
const buildResult = await input.buildSandbox({
|
|
48
|
+
bundleDir: input.bundleDir,
|
|
49
|
+
dockerfile: buildConfig.dockerfile,
|
|
50
|
+
context: buildConfig.context,
|
|
51
|
+
imageTag,
|
|
52
|
+
stdout: input.stdout,
|
|
53
|
+
stderr: input.stderr,
|
|
54
|
+
});
|
|
55
|
+
return toKubernetesSandboxImageRef(buildResult);
|
|
56
|
+
}
|
|
57
|
+
async function buildE2BSandboxImage(input) {
|
|
58
|
+
const template = ensureE2BTemplate(input.config);
|
|
59
|
+
const dockerfile = ensureE2BDockerfile(input.config);
|
|
60
|
+
input.stdout.write(`Building sandbox template with E2B: ${template}\n`);
|
|
61
|
+
const buildResult = await input.buildE2B({
|
|
62
|
+
bundleDir: input.bundleDir,
|
|
63
|
+
template,
|
|
64
|
+
skills: input.skills,
|
|
65
|
+
dockerfile: resolve(input.bundleDir, dockerfile),
|
|
66
|
+
stdout: input.stdout,
|
|
67
|
+
stderr: input.stderr,
|
|
68
|
+
});
|
|
69
|
+
return toE2BSandboxImageRef(buildResult);
|
|
70
|
+
}
|
|
71
|
+
function toKubernetesSandboxImageRef(result) {
|
|
72
|
+
if (result.exitCode !== 0) {
|
|
73
|
+
throw new Error(`docker build failed with exit code ${result.exitCode}.`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
provider: "kubernetes",
|
|
77
|
+
ref: result.imageTag,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function toE2BSandboxImageRef(result) {
|
|
81
|
+
if (result.exitCode !== 0) {
|
|
82
|
+
throw new Error(`e2b template build failed with exit code ${result.exitCode}.`);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
provider: "e2b",
|
|
86
|
+
ref: result.templateRef,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function resolveSandboxImageRef(input) {
|
|
90
|
+
if (input.config.sandbox.provider === "kubernetes") {
|
|
91
|
+
return await buildKubernetesSandboxImage({
|
|
92
|
+
config: input.config,
|
|
93
|
+
bundleDir: input.bundleDir,
|
|
94
|
+
buildSandbox: input.buildSandbox,
|
|
95
|
+
stdout: input.stdout,
|
|
96
|
+
stderr: input.stderr,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return await buildE2BSandboxImage({
|
|
100
|
+
config: input.config,
|
|
101
|
+
bundleDir: input.bundleDir,
|
|
102
|
+
skills: input.skills,
|
|
103
|
+
buildE2B: input.buildE2B,
|
|
104
|
+
stdout: input.stdout,
|
|
105
|
+
stderr: input.stderr,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export async function runBuildCommand(options, dependencies = {}) {
|
|
109
|
+
const loadConfigImpl = dependencies.loadConfig ?? loadBundleConfig;
|
|
110
|
+
const loadSkillsImpl = dependencies.loadSkills ?? loadAllSkills;
|
|
111
|
+
const loadCommandsImpl = dependencies.loadCommands ?? loadAllCommands;
|
|
112
|
+
const loadPluginsImpl = dependencies.loadPlugins ?? loadAllPlugins;
|
|
113
|
+
const promptGenerator = dependencies.generateSystemPrompt ?? generateSystemPromptTemplate;
|
|
114
|
+
const buildSandboxImpl = dependencies.buildSandbox ?? buildSandboxImage;
|
|
115
|
+
const buildE2BImpl = dependencies.buildE2B ?? buildE2BTemplate;
|
|
116
|
+
const writeFileImpl = dependencies.writeFileImpl ?? writeFile;
|
|
117
|
+
const mkdirImpl = dependencies.mkdirImpl ?? mkdir;
|
|
118
|
+
const stdout = options.stdout ?? process.stdout;
|
|
119
|
+
const stderr = options.stderr ?? process.stderr;
|
|
120
|
+
const configPath = resolve(options.configPath);
|
|
121
|
+
const bundleDir = dirname(configPath);
|
|
122
|
+
const config = await loadConfigImpl(configPath);
|
|
123
|
+
stdout.write(`Building bundle "${config.name}" from ${configPath}\n`);
|
|
124
|
+
const baseSkills = await loadSkillsImpl(config.skills, bundleDir);
|
|
125
|
+
const baseCommands = config.commands
|
|
126
|
+
? await loadCommandsImpl(config.commands, bundleDir)
|
|
127
|
+
: [];
|
|
128
|
+
const pluginResults = config.plugins
|
|
129
|
+
? await loadPluginsImpl(config.plugins, dependencies.pluginOptions)
|
|
130
|
+
: [];
|
|
131
|
+
const existingMcpServers = config.mcp?.servers ?? [];
|
|
132
|
+
const merged = mergePluginComponents(baseSkills, baseCommands, existingMcpServers, pluginResults);
|
|
133
|
+
const skillSummaries = toSkillSummaries(merged.skills);
|
|
134
|
+
const commandSummaries = toCommandSummaries(merged.commands);
|
|
135
|
+
const configWithMergedMcp = merged.mcpServers.length > 0
|
|
136
|
+
? { ...config, mcp: { servers: merged.mcpServers } }
|
|
137
|
+
: config;
|
|
138
|
+
const sandboxImage = await resolveSandboxImageRef({
|
|
139
|
+
config: configWithMergedMcp,
|
|
140
|
+
bundleDir,
|
|
141
|
+
skills: merged.skills,
|
|
142
|
+
buildSandbox: buildSandboxImpl,
|
|
143
|
+
buildE2B: buildE2BImpl,
|
|
144
|
+
stdout,
|
|
145
|
+
stderr,
|
|
146
|
+
});
|
|
147
|
+
const systemPrompt = promptGenerator({
|
|
148
|
+
basePrompt: config.prompt.system,
|
|
149
|
+
skills: skillSummaries,
|
|
150
|
+
});
|
|
151
|
+
const resolvedConfig = createResolvedBundleConfig({
|
|
152
|
+
config: configWithMergedMcp,
|
|
153
|
+
skills: skillSummaries,
|
|
154
|
+
commands: commandSummaries,
|
|
155
|
+
systemPrompt,
|
|
156
|
+
sandboxImage,
|
|
157
|
+
});
|
|
158
|
+
const commandContents = new Map(merged.commands.map((cmd) => [cmd.name, cmd.content]));
|
|
159
|
+
const sources = generateSources(resolvedConfig, commandContents);
|
|
160
|
+
const outputRoot = resolve(options.outputDir ?? DEFAULT_OUTPUT_DIR);
|
|
161
|
+
const outputDir = join(outputRoot, config.name);
|
|
162
|
+
await writeGeneratedFiles({
|
|
163
|
+
outputDir,
|
|
164
|
+
sources,
|
|
165
|
+
mkdirImpl,
|
|
166
|
+
writeFileImpl,
|
|
167
|
+
});
|
|
168
|
+
stdout.write(`Build completed: ${outputDir}\n`);
|
|
169
|
+
return {
|
|
170
|
+
outputDir,
|
|
171
|
+
resolvedConfig,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=build.js.map
|