@superblocksteam/vite-plugin-file-sync 2.0.180-next.3 → 2.0.183-next.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/dist/agent-tool-executor/claude-file-tools.d.ts +72 -10
- package/dist/agent-tool-executor/claude-file-tools.d.ts.map +1 -1
- package/dist/agent-tool-executor/claude-sandbox.d.ts +15 -1
- package/dist/agent-tool-executor/claude-sandbox.d.ts.map +1 -1
- package/dist/agent-tool-executor/claude-shell.d.ts +36 -4
- package/dist/agent-tool-executor/claude-shell.d.ts.map +1 -1
- package/dist/agent-tool-executor/claude-tool-server.js +2 -2
- package/dist/agent-tool-executor/claude-tool-server.js.map +1 -1
- package/dist/agent-tool-executor/codex-exec-server.d.ts.map +1 -1
- package/dist/agent-tool-executor/codex-exec-server.js +4 -6
- package/dist/agent-tool-executor/codex-exec-server.js.map +1 -1
- package/dist/agent-tool-executor/codex-execution-policy.js +2 -2
- package/dist/agent-tool-executor/codex-execution-policy.js.map +1 -1
- package/dist/agent-tool-executor/native-draft-service.d.ts +2 -5
- package/dist/agent-tool-executor/native-draft-service.d.ts.map +1 -1
- package/dist/agent-tool-executor/native-tool-environment.js +1 -1
- package/dist/agent-tool-executor/native-tool-environment.js.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts +0 -2
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +2 -9
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/tools/branching/branch-tools.d.ts +2 -2
- package/dist/ai-service/agent/tools/branching/branch-tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/branching/branch-tools.js +1 -1
- package/dist/ai-service/agent/tools/branching/branch-tools.js.map +1 -1
- package/dist/ai-service/agent/tools/build-copy-utils.d.ts +44 -13
- package/dist/ai-service/agent/tools/build-copy-utils.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-debug.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-debug.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-delete-file.d.ts +0 -1
- package/dist/ai-service/agent/tools/build-delete-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-delete-file.js +0 -3
- package/dist/ai-service/agent/tools/build-delete-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.d.ts +0 -2
- package/dist/ai-service/agent/tools/build-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.js +0 -7
- package/dist/ai-service/agent/tools/build-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.js +1 -5
- package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
- package/dist/ai-service/agent/tools/build-list-files.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts +0 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.js +0 -3
- package/dist/ai-service/agent/tools/build-multi-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.js +2 -2
- package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.d.ts +0 -1
- package/dist/ai-service/agent/tools/build-write-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.js +0 -3
- package/dist/ai-service/agent/tools/build-write-file.js.map +1 -1
- package/dist/ai-service/agent/tools/clear-error-cache.d.ts +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts +185 -39
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.js +13 -35
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tools.d.ts +2 -2
- package/dist/ai-service/agent/tools/get-security-findings.d.ts +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +342 -47
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.js +4 -4
- package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/integration-setup.d.ts +2 -2
- package/dist/ai-service/agent/tools/integrations/integration-setup.js +3 -3
- package/dist/ai-service/agent/tools/integrations/integration-setup.js.map +1 -1
- package/dist/ai-service/agent/tools/report-security-findings.d.ts +112 -25
- package/dist/ai-service/agent/tools/report-security-findings.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +0 -1
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/bash.d.ts +2 -2
- package/dist/ai-service/agent/tools2/tools/list-tasks.d.ts +1 -1
- package/dist/ai-service/agent/tools2/types.d.ts +1 -1
- package/dist/ai-service/agent/tools2/types.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/types.js.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.d.ts +10 -20
- package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.js +73 -109
- package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
- package/dist/ai-service/app-interface/shell.d.ts +4 -14
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
- package/dist/ai-service/app-interface/shell.js +30 -45
- package/dist/ai-service/app-interface/shell.js.map +1 -1
- package/dist/ai-service/builder-conversation.d.ts +3 -44
- package/dist/ai-service/builder-conversation.d.ts.map +1 -1
- package/dist/ai-service/builder-conversation.js +47 -353
- package/dist/ai-service/builder-conversation.js.map +1 -1
- package/dist/ai-service/builder-core-prompt.d.ts +1 -1
- package/dist/ai-service/builder-core-prompt.d.ts.map +1 -1
- package/dist/ai-service/builder-core-prompt.js +12 -7
- package/dist/ai-service/builder-core-prompt.js.map +1 -1
- package/dist/ai-service/builder-runtime-auth.d.ts.map +1 -1
- package/dist/ai-service/builder-runtime-auth.js +2 -6
- package/dist/ai-service/builder-runtime-auth.js.map +1 -1
- package/dist/ai-service/builder-runtime.d.ts +237 -103
- package/dist/ai-service/builder-runtime.d.ts.map +1 -1
- package/dist/ai-service/builder-runtime.js +62 -370
- package/dist/ai-service/builder-runtime.js.map +1 -1
- package/dist/ai-service/builder-session-store.d.ts +7 -1
- package/dist/ai-service/builder-session-store.d.ts.map +1 -1
- package/dist/ai-service/builder-session-store.js +1 -1
- package/dist/ai-service/builder-session-store.js.map +1 -1
- package/dist/ai-service/builder-tool-callbacks.d.ts +0 -5
- package/dist/ai-service/builder-tool-callbacks.d.ts.map +1 -1
- package/dist/ai-service/builder-tool-callbacks.js +2 -5
- package/dist/ai-service/builder-tool-callbacks.js.map +1 -1
- package/dist/ai-service/builder-tools.d.ts +4 -26
- package/dist/ai-service/builder-tools.d.ts.map +1 -1
- package/dist/ai-service/builder-tools.js +29 -156
- package/dist/ai-service/builder-tools.js.map +1 -1
- package/dist/ai-service/builder-workspace.d.ts +0 -1
- package/dist/ai-service/builder-workspace.d.ts.map +1 -1
- package/dist/ai-service/builder-workspace.js +6 -15
- package/dist/ai-service/builder-workspace.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts +2 -2
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +8 -25
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/demo-agents/load-agents.d.ts +2 -5
- package/dist/ai-service/demo-agents/load-agents.d.ts.map +1 -1
- package/dist/ai-service/demo-agents/load-agents.js +49 -43
- package/dist/ai-service/demo-agents/load-agents.js.map +1 -1
- package/dist/ai-service/demo-agents/run-agent.js +2 -2
- package/dist/ai-service/demo-agents/run-agent.js.map +1 -1
- package/dist/ai-service/demo-agents/system-prompt.d.ts +5 -6
- package/dist/ai-service/demo-agents/system-prompt.d.ts.map +1 -1
- package/dist/ai-service/demo-agents/system-prompt.js +26 -18
- package/dist/ai-service/demo-agents/system-prompt.js.map +1 -1
- package/dist/ai-service/demo-agents/types.d.ts +56 -1
- package/dist/ai-service/demo-agents/types.d.ts.map +1 -1
- package/dist/ai-service/demo-agents/types.js +7 -0
- package/dist/ai-service/demo-agents/types.js.map +1 -1
- package/dist/ai-service/dev-database-file-sync.d.ts +1 -2
- package/dist/ai-service/dev-database-file-sync.d.ts.map +1 -1
- package/dist/ai-service/dev-database-file-sync.js.map +1 -1
- package/dist/ai-service/features.d.ts +8 -20
- package/dist/ai-service/features.d.ts.map +1 -1
- package/dist/ai-service/index.d.ts +7 -100
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +108 -549
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/judge/tools/playwright-action.d.ts +5 -5
- package/dist/ai-service/judge/tools/playwright-action.d.ts.map +1 -1
- package/dist/ai-service/judge/tools/playwright-action.js +1 -4
- package/dist/ai-service/judge/tools/playwright-action.js.map +1 -1
- package/dist/ai-service/llm/context-v2/storage/event-types.d.ts +110 -45
- package/dist/ai-service/llm/context-v2/storage/event-types.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/storage/event-types.js +3 -3
- package/dist/ai-service/llm/context-v2/storage/event-types.js.map +1 -1
- package/dist/ai-service/llm/interaction/adapters/vercel.d.ts.map +1 -1
- package/dist/ai-service/llm/interaction/adapters/vercel.js +1 -6
- package/dist/ai-service/llm/interaction/adapters/vercel.js.map +1 -1
- package/dist/ai-service/mcp/adapter/json-schema-to-zod.d.ts.map +1 -1
- package/dist/ai-service/mcp/adapter/json-schema-to-zod.js.map +1 -1
- package/dist/ai-service/mcp/embedded-playwright-mcp-server.d.ts +0 -2
- package/dist/ai-service/mcp/embedded-playwright-mcp-server.d.ts.map +1 -1
- package/dist/ai-service/mcp/embedded-playwright-mcp-server.js +0 -28
- package/dist/ai-service/mcp/embedded-playwright-mcp-server.js.map +1 -1
- package/dist/ai-service/mcp/playwright-server.d.ts +0 -2
- package/dist/ai-service/mcp/playwright-server.d.ts.map +1 -1
- package/dist/ai-service/mcp/playwright-server.js +0 -1
- package/dist/ai-service/mcp/playwright-server.js.map +1 -1
- package/dist/ai-service/migration-prompt-gating.d.ts +0 -2
- package/dist/ai-service/migration-prompt-gating.d.ts.map +1 -1
- package/dist/ai-service/migration-prompt-gating.js +0 -3
- package/dist/ai-service/migration-prompt-gating.js.map +1 -1
- package/dist/ai-service/prompt-builder-service/types.d.ts +1 -3
- package/dist/ai-service/prompt-builder-service/types.d.ts.map +1 -1
- package/dist/ai-service/security/vulnerability-triage.d.ts +30 -12
- package/dist/ai-service/security/vulnerability-triage.d.ts.map +1 -1
- package/dist/ai-service/skills/system/_registry.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/_registry.generated.js +0 -6
- package/dist/ai-service/skills/system/_registry.generated.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +7 -10
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/stable-peer.d.ts +0 -2
- package/dist/ai-service/state-machine/helpers/stable-peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/stable-peer.js +2 -9
- package/dist/ai-service/state-machine/helpers/stable-peer.js.map +1 -1
- package/dist/ai-service/tasks/task-store.d.ts.map +1 -1
- package/dist/ai-service/tasks/task-store.js +1 -1
- package/dist/ai-service/tasks/task-store.js.map +1 -1
- package/dist/ai-service/tasks/types.d.ts +1 -5
- package/dist/ai-service/tasks/types.d.ts.map +1 -1
- package/dist/ai-service/util/inference-jwt.d.ts +0 -5
- package/dist/ai-service/util/inference-jwt.d.ts.map +1 -1
- package/dist/ai-service/util/inference-jwt.js +0 -17
- package/dist/ai-service/util/inference-jwt.js.map +1 -1
- package/dist/ai-service/workspace-mirror.d.ts +0 -2
- package/dist/ai-service/workspace-mirror.d.ts.map +1 -1
- package/dist/ai-service/workspace-mirror.js +0 -21
- package/dist/ai-service/workspace-mirror.js.map +1 -1
- package/dist/dev-server-ws-smoke-client.d.ts.map +1 -1
- package/dist/dev-server-ws-smoke-client.js +0 -1
- package/dist/dev-server-ws-smoke-client.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts +1 -3
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +11 -19
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-manager.d.ts.map +1 -1
- package/dist/file-system-manager.js +13 -11
- package/dist/file-system-manager.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/lock-service/index.d.ts +0 -36
- package/dist/lock-service/index.d.ts.map +1 -1
- package/dist/lock-service/index.js +0 -59
- package/dist/lock-service/index.js.map +1 -1
- package/dist/plugin-options.d.ts +1 -9
- package/dist/plugin-options.d.ts.map +1 -1
- package/dist/plugin-options.js.map +1 -1
- package/dist/policy-gate-runner.d.ts +9 -1
- package/dist/policy-gate-runner.d.ts.map +1 -1
- package/dist/project-manifest.d.ts +108 -8
- package/dist/project-manifest.d.ts.map +1 -1
- package/dist/project-manifest.js +115 -28
- package/dist/project-manifest.js.map +1 -1
- package/dist/server-rpc/index.d.ts +0 -6
- package/dist/server-rpc/index.d.ts.map +1 -1
- package/dist/server-rpc/index.js +1 -13
- package/dist/server-rpc/index.js.map +1 -1
- package/dist/socket-manager.d.ts +1 -3
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +65 -115
- package/dist/socket-manager.js.map +1 -1
- package/dist/sync-service/draft-mutation.d.ts +2 -6
- package/dist/sync-service/draft-mutation.d.ts.map +1 -1
- package/dist/sync-service/draft-mutation.js +33 -20
- package/dist/sync-service/draft-mutation.js.map +1 -1
- package/dist/sync-service/index.d.ts +6 -6
- package/dist/sync-service/index.d.ts.map +1 -1
- package/dist/sync-service/index.js +61 -29
- package/dist/sync-service/index.js.map +1 -1
- package/dist/sync-service/native-draft-session.d.ts +3 -0
- package/dist/sync-service/native-draft-session.d.ts.map +1 -0
- package/dist/sync-service/native-draft-session.js +4 -0
- package/dist/sync-service/native-draft-session.js.map +1 -0
- package/dist/workspace-sync-methods.d.ts +20 -5
- package/dist/workspace-sync-methods.d.ts.map +1 -1
- package/package.json +13 -17
- package/dist/ai-service/agent/tools/project-agent-feedback.d.ts +0 -17
- package/dist/ai-service/agent/tools/project-agent-feedback.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/project-agent-feedback.js +0 -87
- package/dist/ai-service/agent/tools/project-agent-feedback.js.map +0 -1
- package/dist/ai-service/app-interface/invalid-lockfile-error.d.ts +0 -11
- package/dist/ai-service/app-interface/invalid-lockfile-error.d.ts.map +0 -1
- package/dist/ai-service/app-interface/invalid-lockfile-error.js +0 -27
- package/dist/ai-service/app-interface/invalid-lockfile-error.js.map +0 -1
- package/dist/ai-service/app-interface/npm-lockfile-sources.d.ts +0 -13
- package/dist/ai-service/app-interface/npm-lockfile-sources.d.ts.map +0 -1
- package/dist/ai-service/app-interface/npm-lockfile-sources.js +0 -129
- package/dist/ai-service/app-interface/npm-lockfile-sources.js.map +0 -1
- package/dist/ai-service/app-interface/registry-lockfile-preparer.d.ts +0 -46
- package/dist/ai-service/app-interface/registry-lockfile-preparer.d.ts.map +0 -1
- package/dist/ai-service/app-interface/registry-lockfile-preparer.js +0 -88
- package/dist/ai-service/app-interface/registry-lockfile-preparer.js.map +0 -1
- package/dist/ai-service/builder-binding-error.d.ts +0 -5
- package/dist/ai-service/builder-binding-error.d.ts.map +0 -1
- package/dist/ai-service/builder-binding-error.js +0 -8
- package/dist/ai-service/builder-binding-error.js.map +0 -1
- package/dist/ai-service/skills/system/project-agents/references/errors.generated.d.ts +0 -2
- package/dist/ai-service/skills/system/project-agents/references/errors.generated.d.ts.map +0 -1
- package/dist/ai-service/skills/system/project-agents/references/errors.generated.js +0 -25
- package/dist/ai-service/skills/system/project-agents/references/errors.generated.js.map +0 -1
- package/dist/ai-service/skills/system/project-agents/references/fields.generated.d.ts +0 -2
- package/dist/ai-service/skills/system/project-agents/references/fields.generated.d.ts.map +0 -1
- package/dist/ai-service/skills/system/project-agents/references/fields.generated.js +0 -55
- package/dist/ai-service/skills/system/project-agents/references/fields.generated.js.map +0 -1
- package/dist/ai-service/skills/system/project-agents/skill.generated.d.ts +0 -2
- package/dist/ai-service/skills/system/project-agents/skill.generated.d.ts.map +0 -1
- package/dist/ai-service/skills/system/project-agents/skill.generated.js +0 -73
- package/dist/ai-service/skills/system/project-agents/skill.generated.js.map +0 -1
- package/dist/ai-service/tool-input-schema.d.ts +0 -14
- package/dist/ai-service/tool-input-schema.d.ts.map +0 -1
- package/dist/ai-service/tool-input-schema.js +0 -23
- package/dist/ai-service/tool-input-schema.js.map +0 -1
- package/dist/ai-service/workspace-package-registry.d.ts +0 -3
- package/dist/ai-service/workspace-package-registry.d.ts.map +0 -1
- package/dist/ai-service/workspace-package-registry.js +0 -87
- package/dist/ai-service/workspace-package-registry.js.map +0 -1
- package/dist/ai-service/workspace-package-state.d.ts +0 -12
- package/dist/ai-service/workspace-package-state.d.ts.map +0 -1
- package/dist/ai-service/workspace-package-state.js +0 -47
- package/dist/ai-service/workspace-package-state.js.map +0 -1
- package/dist/ai-service/workspace-packages.d.ts +0 -234
- package/dist/ai-service/workspace-packages.d.ts.map +0 -1
- package/dist/ai-service/workspace-packages.js +0 -466
- package/dist/ai-service/workspace-packages.js.map +0 -1
- package/dist/project-agents.d.ts +0 -31
- package/dist/project-agents.d.ts.map +0 -1
- package/dist/project-agents.js +0 -50
- package/dist/project-agents.js.map +0 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/** Runs native builder turns and coordinates their editor callbacks and recovery. */
|
|
2
1
|
import { randomBytes } from "node:crypto";
|
|
3
|
-
import { context,
|
|
2
|
+
import { context, trace } from "@opentelemetry/api";
|
|
4
3
|
import { asSchema, tool } from "ai";
|
|
5
4
|
import { z } from "zod";
|
|
6
|
-
import { NATIVE_BUILDER_PROVIDERS, } from "@superblocksteam/library-shared/types";
|
|
7
5
|
import { NativeBuilderModel, } from "@superblocksteam/shared";
|
|
8
6
|
import { BUILDER_RUNTIME_ENDPOINT_HEADER, BUILDER_RUNTIME_INVOCATIONS_PATH, BUILDER_RUNTIME_SESSION_HEADER, BUILDER_RUNTIME_SIGN_GRANT_HEADER, BUILDER_RUNTIME_SIGN_PATH, WORKSPACE_INGRESS_PORT, builderRuntimeEndpointHeaderSchema, deriveWorkspaceEndpointToken, deriveWorkspaceToken, workspaceEndpointSchema, } from "@superblocksteam/workspace-sync/control";
|
|
9
|
-
import { getErrorMeta
|
|
7
|
+
import { getErrorMeta } from "../util/logger.js";
|
|
10
8
|
import { getToolOutput } from "./agent/tool-message-utils.js";
|
|
11
9
|
import { movesEditor } from "./agent/tools/branching/branch-tools.js";
|
|
12
10
|
import { BuilderFailureDrain, } from "./builder-failure-drain.js";
|
|
@@ -15,82 +13,11 @@ import { AgentCoreToolHost } from "./builder-tool-callbacks.js";
|
|
|
15
13
|
import { NativeCallbackOrder } from "./native-callback-order.js";
|
|
16
14
|
import { NativeSecretRedactor } from "./native-secret-redactor.js";
|
|
17
15
|
import { OutboundTraceContext, } from "./outbound-trace-context.js";
|
|
18
|
-
import { toolInputSchema } from "./tool-input-schema.js";
|
|
19
16
|
/** Runtime control calls whose failure to authorize inference stops the turn. */
|
|
20
17
|
const INFERENCE_AUTH_CALLS = new Set([
|
|
21
18
|
"__runtime_redact",
|
|
22
19
|
"__runtime_inference_token",
|
|
23
20
|
]);
|
|
24
|
-
/** Runtime control calls, which never wait on a stream event. */
|
|
25
|
-
const RUNTIME_CONTROL_CALLS = new Set([
|
|
26
|
-
"__runtime_redact",
|
|
27
|
-
"__runtime_skills_token",
|
|
28
|
-
"__runtime_inference_token",
|
|
29
|
-
]);
|
|
30
|
-
/** Error codes with which a runtime declines a `turn.attach`. */
|
|
31
|
-
const ATTACH_REFUSALS = new Set([
|
|
32
|
-
"RUN_NOT_FOUND",
|
|
33
|
-
"RUN_ENDED",
|
|
34
|
-
"ATTACH_GAP",
|
|
35
|
-
"UNSUPPORTED_INVOCATION",
|
|
36
|
-
]);
|
|
37
|
-
const MAX_REATTACH_DELAY_MS = 4_000;
|
|
38
|
-
class AttachRefusedError extends Error {
|
|
39
|
-
code;
|
|
40
|
-
constructor(code) {
|
|
41
|
-
super(`The builder runtime refused to reattach: ${code}`);
|
|
42
|
-
this.code = code;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
class AttachTimeoutError extends Error {
|
|
46
|
-
constructor() {
|
|
47
|
-
super("Reattaching to the builder runtime timed out");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
class StreamEndedError extends Error {
|
|
51
|
-
constructor() {
|
|
52
|
-
super("Native builder stream ended without a finish event");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/** Whether `error` means the connection carrying a runtime stream was lost. */
|
|
56
|
-
function isTransportLoss(error) {
|
|
57
|
-
let current = error;
|
|
58
|
-
for (let depth = 0; current instanceof Error && depth < 5; depth++) {
|
|
59
|
-
const code = "code" in current ? current.code : undefined;
|
|
60
|
-
if (
|
|
61
|
-
// A proxy or a draining server can end the body cleanly mid-turn.
|
|
62
|
-
current instanceof StreamEndedError ||
|
|
63
|
-
current.message === "terminated" ||
|
|
64
|
-
current.message === "fetch failed" ||
|
|
65
|
-
current.message.includes("other side closed") ||
|
|
66
|
-
code === "UND_ERR_SOCKET" ||
|
|
67
|
-
code === "ECONNRESET" ||
|
|
68
|
-
code === "ECONNREFUSED")
|
|
69
|
-
return true;
|
|
70
|
-
current = current.cause;
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
function parseSeq(value) {
|
|
75
|
-
if (!/^[1-9][0-9]{0,15}$/.test(value))
|
|
76
|
-
return undefined;
|
|
77
|
-
const seq = Number(value);
|
|
78
|
-
return Number.isSafeInteger(seq) ? seq : undefined;
|
|
79
|
-
}
|
|
80
|
-
function delay(ms, signal) {
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
signal.throwIfAborted();
|
|
83
|
-
const onAbort = () => {
|
|
84
|
-
clearTimeout(timer);
|
|
85
|
-
reject(signal.reason);
|
|
86
|
-
};
|
|
87
|
-
const timer = setTimeout(() => {
|
|
88
|
-
signal.removeEventListener("abort", onAbort);
|
|
89
|
-
resolve();
|
|
90
|
-
}, ms);
|
|
91
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
21
|
const executionDescriptorSchema = z
|
|
95
22
|
.object({
|
|
96
23
|
token: z.string().min(32).max(4096),
|
|
@@ -140,8 +67,6 @@ const workspaceFinishSchema = z.object({
|
|
|
140
67
|
dbfsHash: z.string().min(1).optional(),
|
|
141
68
|
rehydrate: z.enum(["fresh", "resumed", "replayed", "reloaded"]).optional(),
|
|
142
69
|
filesChanged: z.boolean().optional(),
|
|
143
|
-
/** The AI checkpoint the VM's turn end created; absent when it created none. */
|
|
144
|
-
commitId: z.string().min(1).optional(),
|
|
145
70
|
/**
|
|
146
71
|
* Per-VM-boot credential the AI process presents as an ai-service peer on
|
|
147
72
|
* the VM's `/sb-dev-updates`; `workspace.open` returns it.
|
|
@@ -168,7 +93,7 @@ const runtimeFailureReasonSchema = z.enum([
|
|
|
168
93
|
]);
|
|
169
94
|
const eventSchema = z.discriminatedUnion("type", [
|
|
170
95
|
z.object({ type: z.literal("session"), sessionId: z.string().min(1) }),
|
|
171
|
-
z.object({ type: z.literal("callback-ready"), id: z.
|
|
96
|
+
z.object({ type: z.literal("callback-ready"), id: z.string().uuid() }),
|
|
172
97
|
z.object({ type: z.literal("text-delta"), text: z.string() }),
|
|
173
98
|
z.object({
|
|
174
99
|
type: z.literal("plan"),
|
|
@@ -179,7 +104,7 @@ const eventSchema = z.discriminatedUnion("type", [
|
|
|
179
104
|
type: z.literal("tool-call"),
|
|
180
105
|
toolCallId: z.string(),
|
|
181
106
|
toolName: z.string(),
|
|
182
|
-
input: z.unknown()
|
|
107
|
+
input: z.unknown(),
|
|
183
108
|
// The sub-agent call this call was made inside. Lenient: grouping is a
|
|
184
109
|
// convenience and must not fail the stream parse.
|
|
185
110
|
parentToolCallId: z.string().optional().catch(undefined),
|
|
@@ -188,7 +113,7 @@ const eventSchema = z.discriminatedUnion("type", [
|
|
|
188
113
|
type: z.literal("tool-result"),
|
|
189
114
|
toolCallId: z.string(),
|
|
190
115
|
toolName: z.string(),
|
|
191
|
-
output: z.unknown()
|
|
116
|
+
output: z.unknown(),
|
|
192
117
|
isError: z.boolean().optional(),
|
|
193
118
|
}),
|
|
194
119
|
// Workspace turn-end data rides on `finish` rather than a new event type:
|
|
@@ -197,8 +122,6 @@ const eventSchema = z.discriminatedUnion("type", [
|
|
|
197
122
|
type: z.literal("finish"),
|
|
198
123
|
usage: usageSchema,
|
|
199
124
|
workspace: workspaceFinishSchema.optional(),
|
|
200
|
-
/** On `turn.cancel`, whether a running turn was stopped. */
|
|
201
|
-
cancelled: z.boolean().optional(),
|
|
202
125
|
}),
|
|
203
126
|
z.object({
|
|
204
127
|
type: z.literal("error"),
|
|
@@ -243,7 +166,7 @@ export class BuilderRuntimeError extends Error {
|
|
|
243
166
|
return new BuilderRuntimeError(this.code, this.reason, this.beforeTurn, this.runSubmitted, false, outcome);
|
|
244
167
|
}
|
|
245
168
|
/** Logs the safe failure classification and its invocation-attempt context. */
|
|
246
|
-
static log(error, logger, attempt
|
|
169
|
+
static log(error, logger, attempt) {
|
|
247
170
|
const code = error instanceof BuilderRuntimeError
|
|
248
171
|
? z
|
|
249
172
|
.enum([
|
|
@@ -262,7 +185,6 @@ export class BuilderRuntimeError extends Error {
|
|
|
262
185
|
? runtimeFailureReasonSchema.catch("unknown").parse(error.reason)
|
|
263
186
|
: undefined;
|
|
264
187
|
logger.warn("Native builder operation failed", {
|
|
265
|
-
...context,
|
|
266
188
|
...getErrorMeta(error),
|
|
267
189
|
...(code && { "failure.code": code.success ? code.data : "unknown" }),
|
|
268
190
|
...(reason && { "failure.reason": reason }),
|
|
@@ -341,21 +263,6 @@ export class BuilderRuntime {
|
|
|
341
263
|
});
|
|
342
264
|
}
|
|
343
265
|
toolHost = new AgentCoreToolHost();
|
|
344
|
-
/**
|
|
345
|
-
* How long a cancelled workspace turn's stream stays open for the finish
|
|
346
|
-
* naming its checkpoint before it is closed as for any other turn.
|
|
347
|
-
*/
|
|
348
|
-
cancelFinishTimeoutMs = 30_000;
|
|
349
|
-
reattachOutcomes = metrics
|
|
350
|
-
.getMeter("superblocks.ai_service")
|
|
351
|
-
.createCounter("superblocks.ai_service.builder_reattach", {
|
|
352
|
-
description: "Native builder turns whose lost stream was reattached or given up",
|
|
353
|
-
unit: "1",
|
|
354
|
-
});
|
|
355
|
-
/** How long after a turn's stream is lost it may be reattached. */
|
|
356
|
-
reattachBudgetMs = 15_000;
|
|
357
|
-
/** The first pause before reattaching; it doubles per attempt. */
|
|
358
|
-
reattachDelayMs = 250;
|
|
359
266
|
secrets = new NativeSecretRedactor();
|
|
360
267
|
get model() {
|
|
361
268
|
return this.selectedModel ?? NativeBuilderModel.resolve(this.harness);
|
|
@@ -474,9 +381,8 @@ export class BuilderRuntime {
|
|
|
474
381
|
}),
|
|
475
382
|
});
|
|
476
383
|
}
|
|
477
|
-
/** Resolves provider routing from the shared native harness contract. */
|
|
478
384
|
providerFor(_model) {
|
|
479
|
-
return
|
|
385
|
+
return this.harness === "codex" ? "openai" : "anthropic";
|
|
480
386
|
}
|
|
481
387
|
async invoke(options) {
|
|
482
388
|
if (Object.keys(options.tools).some((name) => name.startsWith("__runtime_")))
|
|
@@ -514,9 +420,10 @@ export class BuilderRuntime {
|
|
|
514
420
|
runId: options.runId,
|
|
515
421
|
concurrentTools: new Set([
|
|
516
422
|
...(options.concurrentTools ?? []),
|
|
517
|
-
|
|
423
|
+
"__runtime_redact",
|
|
424
|
+
"__runtime_skills_token",
|
|
425
|
+
"__runtime_inference_token",
|
|
518
426
|
]),
|
|
519
|
-
unorderedTools: RUNTIME_CONTROL_CALLS,
|
|
520
427
|
tools: {
|
|
521
428
|
...options.tools,
|
|
522
429
|
...options.callbackTools,
|
|
@@ -623,21 +530,7 @@ export class BuilderRuntime {
|
|
|
623
530
|
});
|
|
624
531
|
let mustRevoke = false;
|
|
625
532
|
let failure;
|
|
626
|
-
|
|
627
|
-
// turn's end commits its tree even when cancelled and its finish names
|
|
628
|
-
// that checkpoint: once its stream is open, a cancel stops the turn with
|
|
629
|
-
// `turn.cancel` and keeps reading. Closing the stream is the fallback
|
|
630
|
-
// when that call fails or the finish does not come in time.
|
|
631
|
-
const stream = new AbortController();
|
|
632
|
-
let streaming = false;
|
|
633
|
-
options.signal.addEventListener("abort", () => {
|
|
634
|
-
const close = () => stream.abort(options.signal.reason);
|
|
635
|
-
if (!options.workspaceLocal || !streaming)
|
|
636
|
-
return close();
|
|
637
|
-
const timer = setTimeout(close, this.cancelFinishTimeoutMs);
|
|
638
|
-
stream.signal.addEventListener("abort", () => clearTimeout(timer));
|
|
639
|
-
void this.cancelTurn(options, stream.signal).then((cancelled) => cancelled || close());
|
|
640
|
-
}, { once: true, signal: stream.signal });
|
|
533
|
+
let invoked = false;
|
|
641
534
|
try {
|
|
642
535
|
options.signal.throwIfAborted();
|
|
643
536
|
mustRevoke = !!execution;
|
|
@@ -647,8 +540,7 @@ export class BuilderRuntime {
|
|
|
647
540
|
const tools = await Promise.all(Object.entries(options.tools).map(async ([name, tool]) => ({
|
|
648
541
|
name,
|
|
649
542
|
description: tool.description ?? "",
|
|
650
|
-
inputSchema: await asSchema(
|
|
651
|
-
.jsonSchema,
|
|
543
|
+
inputSchema: await asSchema(tool.inputSchema).jsonSchema,
|
|
652
544
|
...(options.concurrentTools?.has(name) && { readOnly: true }),
|
|
653
545
|
})));
|
|
654
546
|
const payload = JSON.stringify({
|
|
@@ -684,42 +576,31 @@ export class BuilderRuntime {
|
|
|
684
576
|
payload,
|
|
685
577
|
session: options.workspaceSessionKey ? "workspace" : "chat",
|
|
686
578
|
access: options.access,
|
|
687
|
-
signal:
|
|
579
|
+
signal: options.signal,
|
|
688
580
|
});
|
|
689
|
-
|
|
690
|
-
await this.
|
|
581
|
+
invoked = true;
|
|
582
|
+
await this.consume(body, {
|
|
691
583
|
...options,
|
|
692
584
|
onEvent: (event) => {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
!(event.type === "finish" && event.workspace))
|
|
698
|
-
return;
|
|
585
|
+
if (inferenceFailure)
|
|
586
|
+
throw inferenceFailure;
|
|
587
|
+
if (skillsFailure)
|
|
588
|
+
throw skillsFailure;
|
|
699
589
|
return options.onEvent(event);
|
|
700
590
|
},
|
|
701
|
-
}, callbacks, callbackResults
|
|
702
|
-
// A workspace turn still owes the finish naming its committed checkpoint.
|
|
703
|
-
() => !!options.workspaceSessionKey ||
|
|
704
|
-
(!inferenceFailure && !skillsFailure));
|
|
591
|
+
}, callbacks, callbackResults);
|
|
705
592
|
if (inferenceFailure)
|
|
706
593
|
throw inferenceFailure;
|
|
707
594
|
if (skillsFailure)
|
|
708
595
|
throw skillsFailure;
|
|
709
|
-
options.signal.throwIfAborted();
|
|
710
596
|
}
|
|
711
597
|
catch (error) {
|
|
712
598
|
failure = { error: inferenceFailure ?? skillsFailure ?? error };
|
|
713
599
|
}
|
|
714
600
|
finally {
|
|
715
|
-
//
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
// still runs in the VM, since AgentCore keeps an invocation going after
|
|
719
|
-
// its caller hangs up. Before the tools close, so the VM stops instead
|
|
720
|
-
// of failing its next callback.
|
|
721
|
-
if (streaming && options.signal.aborted && !options.workspaceLocal)
|
|
722
|
-
await this.cancelTurn(options, AbortSignal.timeout(5_000), false);
|
|
601
|
+
// Before the tools close, so the VM stops instead of failing its next callback.
|
|
602
|
+
if (invoked && options.signal.aborted)
|
|
603
|
+
await this.cancelTurn(options);
|
|
723
604
|
closeTools();
|
|
724
605
|
callbackResults.clear();
|
|
725
606
|
}
|
|
@@ -734,6 +615,30 @@ export class BuilderRuntime {
|
|
|
734
615
|
if (failure)
|
|
735
616
|
throw failure.error;
|
|
736
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* Tells the VM to stop run `runId`. AgentCore keeps an invocation running
|
|
620
|
+
* after its caller hangs up, so aborting our stream alone leaves the turn
|
|
621
|
+
* going. Best effort: a runtime without `turn.cancel` answers 422.
|
|
622
|
+
*/
|
|
623
|
+
async cancelTurn(options) {
|
|
624
|
+
try {
|
|
625
|
+
const body = await this.invokeRaw({
|
|
626
|
+
payload: JSON.stringify({
|
|
627
|
+
kind: "turn.cancel",
|
|
628
|
+
provider: this.providerFor(this.model),
|
|
629
|
+
runId: options.runId,
|
|
630
|
+
actorId: options.actorId,
|
|
631
|
+
}),
|
|
632
|
+
session: options.workspaceSessionKey ? "workspace" : "chat",
|
|
633
|
+
access: options.access,
|
|
634
|
+
signal: AbortSignal.timeout(5_000),
|
|
635
|
+
});
|
|
636
|
+
await body[Symbol.asyncIterator]().return?.();
|
|
637
|
+
}
|
|
638
|
+
catch {
|
|
639
|
+
// The turn still ends when the VM's next callback finds the run closed.
|
|
640
|
+
}
|
|
641
|
+
}
|
|
737
642
|
/**
|
|
738
643
|
* The workspace edge's base URL (no path) and the token the VM presents to
|
|
739
644
|
* it and accepts from it, for one workspace session. The edge is the
|
|
@@ -874,14 +779,6 @@ export class BuilderRuntime {
|
|
|
874
779
|
* Throws when the stream ends without one or a frame is too large.
|
|
875
780
|
*/
|
|
876
781
|
static async *readEvents(body, signal) {
|
|
877
|
-
for await (const { event } of BuilderRuntime.readFrames(body, signal))
|
|
878
|
-
yield event;
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* {@link readEvents} with each frame's `id:` sequence number. A frame
|
|
882
|
-
* without a valid id has none.
|
|
883
|
-
*/
|
|
884
|
-
static async *readFrames(body, signal) {
|
|
885
782
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
886
783
|
let buffer = "";
|
|
887
784
|
const iterator = body[Symbol.asyncIterator]();
|
|
@@ -904,252 +801,47 @@ export class BuilderRuntime {
|
|
|
904
801
|
throw new Error("Native builder event exceeds size limit");
|
|
905
802
|
const frame = buffer.slice(0, boundary.index);
|
|
906
803
|
buffer = buffer.slice(boundary.index + boundary[0].length);
|
|
907
|
-
const
|
|
908
|
-
|
|
804
|
+
const data = frame
|
|
805
|
+
.split(/\r?\n/)
|
|
909
806
|
.filter((line) => line.startsWith("data:"))
|
|
910
807
|
.map((line) => line.slice(5).trimStart())
|
|
911
808
|
.join("\n");
|
|
912
809
|
if (!data)
|
|
913
810
|
continue;
|
|
914
811
|
const event = eventSchema.parse(JSON.parse(data));
|
|
915
|
-
|
|
916
|
-
const seq = id === undefined ? undefined : parseSeq(id.slice(3).trim());
|
|
917
|
-
yield seq === undefined ? { event } : { event, seq };
|
|
812
|
+
yield event;
|
|
918
813
|
if (event.type === "finish")
|
|
919
814
|
return;
|
|
920
815
|
}
|
|
921
816
|
if (buffer.length > 8_388_608)
|
|
922
817
|
throw new Error("Native builder event exceeds size limit");
|
|
923
818
|
}
|
|
924
|
-
throw new
|
|
819
|
+
throw new Error("Native builder stream ended without a finish event");
|
|
925
820
|
}
|
|
926
821
|
finally {
|
|
927
822
|
signal.removeEventListener("abort", onAbort);
|
|
928
823
|
void iterator.return?.().catch(() => { });
|
|
929
824
|
}
|
|
930
825
|
}
|
|
931
|
-
|
|
932
|
-
* Asks the runtime to stop the turn `options.runId` without closing its
|
|
933
|
-
* stream. AgentCore keeps an invocation running after its caller hangs up,
|
|
934
|
-
* so closing the stream alone leaves the turn going. False when it could
|
|
935
|
-
* not: an older runtime (which answers 422), or no such turn running.
|
|
936
|
-
* Without `awaitReply` it only sends the cancel and reports true.
|
|
937
|
-
*/
|
|
938
|
-
async cancelTurn(options, signal, awaitReply = true) {
|
|
939
|
-
try {
|
|
940
|
-
const body = await this.invokeRaw({
|
|
941
|
-
payload: JSON.stringify({
|
|
942
|
-
kind: "turn.cancel",
|
|
943
|
-
provider: this.providerFor(this.model),
|
|
944
|
-
runId: options.runId,
|
|
945
|
-
actorId: options.actorId,
|
|
946
|
-
}),
|
|
947
|
-
session: options.workspaceSessionKey ? "workspace" : "chat",
|
|
948
|
-
access: options.access,
|
|
949
|
-
signal,
|
|
950
|
-
});
|
|
951
|
-
if (!awaitReply) {
|
|
952
|
-
await body[Symbol.asyncIterator]().return?.();
|
|
953
|
-
return true;
|
|
954
|
-
}
|
|
955
|
-
for await (const event of BuilderRuntime.readEvents(body, signal))
|
|
956
|
-
if (event.type === "finish")
|
|
957
|
-
return event.cancelled === true;
|
|
958
|
-
return false;
|
|
959
|
-
}
|
|
960
|
-
catch {
|
|
961
|
-
return false;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
/**
|
|
965
|
-
* Consumes a turn's stream. When the connection carrying it is lost, the
|
|
966
|
-
* turn is still running in the VM, so this reattaches with `turn.attach`
|
|
967
|
-
* and resumes after the last event it delivered. Each loss may be
|
|
968
|
-
* reattached for {@link reattachBudgetMs}; an attach stream that delivered
|
|
969
|
-
* new events or stayed open that long counts as reconnected, so a later
|
|
970
|
-
* loss gets a new budget. A refused or exhausted reattach fails with the
|
|
971
|
-
* first transport error.
|
|
972
|
-
*/
|
|
973
|
-
async followTurn(first, signal, options, callbacks, callbackResults, canReattach) {
|
|
974
|
-
const cursor = { seq: 0 };
|
|
975
|
-
let body = first;
|
|
976
|
-
let lost;
|
|
977
|
-
let pause = this.reattachDelayMs;
|
|
978
|
-
let attempts = 0;
|
|
979
|
-
let losses = 0;
|
|
980
|
-
// Once per turn whose stream was lost.
|
|
981
|
-
const settle = (outcome, cause) => {
|
|
982
|
-
trace.getSpan(options.traceContext ?? context.active())?.setAttributes({
|
|
983
|
-
"builder.reattach.attempts": attempts,
|
|
984
|
-
"builder.reattach.episodes": losses,
|
|
985
|
-
"builder.reattach.outcome": outcome,
|
|
986
|
-
});
|
|
987
|
-
this.reattachOutcomes.add(1, { "reattach.outcome": outcome });
|
|
988
|
-
const attributes = {
|
|
989
|
-
"builder.run_id": options.runId,
|
|
990
|
-
"builder.reattach.after_seq": cursor.seq,
|
|
991
|
-
"builder.reattach.attempts": attempts,
|
|
992
|
-
"builder.reattach.episodes": losses,
|
|
993
|
-
"builder.reattach.outcome": outcome,
|
|
994
|
-
};
|
|
995
|
-
if (outcome === "recovered") {
|
|
996
|
-
getLogger().info("Native builder turn reattached", attributes);
|
|
997
|
-
return;
|
|
998
|
-
}
|
|
999
|
-
const status = BuilderRuntimeHttpError.statusOf(cause);
|
|
1000
|
-
getLogger().warn("Native builder turn could not be reattached", {
|
|
1001
|
-
...attributes,
|
|
1002
|
-
...(cause !== undefined && getErrorMeta(cause)),
|
|
1003
|
-
...(cause instanceof AttachRefusedError && {
|
|
1004
|
-
"builder.reattach.refusal": cause.code,
|
|
1005
|
-
}),
|
|
1006
|
-
...(status !== undefined && { "builder.reattach.status": status }),
|
|
1007
|
-
});
|
|
1008
|
-
};
|
|
1009
|
-
for (;;) {
|
|
1010
|
-
let opened = false;
|
|
1011
|
-
let openedAt = 0;
|
|
1012
|
-
const seqBefore = cursor.seq;
|
|
1013
|
-
try {
|
|
1014
|
-
if (!body) {
|
|
1015
|
-
if (!lost)
|
|
1016
|
-
throw new Error("Native builder has no stream to read");
|
|
1017
|
-
attempts++;
|
|
1018
|
-
body = await this.attachTurn(options, cursor.seq, signal, lost.until - performance.now());
|
|
1019
|
-
opened = true;
|
|
1020
|
-
openedAt = performance.now();
|
|
1021
|
-
}
|
|
1022
|
-
await this.consume(body, signal, options, callbacks, callbackResults, cursor, lost !== undefined);
|
|
1023
|
-
if (lost)
|
|
1024
|
-
settle("recovered");
|
|
1025
|
-
return;
|
|
1026
|
-
}
|
|
1027
|
-
catch (error) {
|
|
1028
|
-
body = undefined;
|
|
1029
|
-
if (signal.aborted || options.signal.aborted) {
|
|
1030
|
-
if (lost)
|
|
1031
|
-
settle("cancelled", error);
|
|
1032
|
-
throw error;
|
|
1033
|
-
}
|
|
1034
|
-
const transient = isTransportLoss(error) ||
|
|
1035
|
-
error instanceof AttachTimeoutError ||
|
|
1036
|
-
(BuilderRuntimeHttpError.statusOf(error) ?? 0) >= 500;
|
|
1037
|
-
// An attach that drops at once is the same loss, so its retries back off.
|
|
1038
|
-
let newLoss = opened &&
|
|
1039
|
-
(cursor.seq > seqBefore ||
|
|
1040
|
-
performance.now() - openedAt >= this.reattachBudgetMs);
|
|
1041
|
-
if (!lost) {
|
|
1042
|
-
if (!isTransportLoss(error) || !canReattach())
|
|
1043
|
-
throw error;
|
|
1044
|
-
lost = { error, until: 0 };
|
|
1045
|
-
newLoss = true;
|
|
1046
|
-
}
|
|
1047
|
-
else if (error instanceof AttachRefusedError ||
|
|
1048
|
-
(!opened && !transient)) {
|
|
1049
|
-
settle("refused", error);
|
|
1050
|
-
throw lost.error;
|
|
1051
|
-
}
|
|
1052
|
-
else if (!transient) {
|
|
1053
|
-
// The reattached turn itself failed.
|
|
1054
|
-
settle("failed", error);
|
|
1055
|
-
throw error;
|
|
1056
|
-
}
|
|
1057
|
-
if (newLoss) {
|
|
1058
|
-
losses++;
|
|
1059
|
-
lost.until = performance.now() + this.reattachBudgetMs;
|
|
1060
|
-
pause = this.reattachDelayMs;
|
|
1061
|
-
getLogger().warn("Native builder turn stream lost; reattaching", {
|
|
1062
|
-
...getErrorMeta(error),
|
|
1063
|
-
"builder.run_id": options.runId,
|
|
1064
|
-
"builder.reattach.after_seq": cursor.seq,
|
|
1065
|
-
"builder.reattach.episodes": losses,
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
if (performance.now() + pause >= lost.until) {
|
|
1069
|
-
settle("exhausted", error);
|
|
1070
|
-
throw lost.error;
|
|
1071
|
-
}
|
|
1072
|
-
try {
|
|
1073
|
-
await delay(pause, AbortSignal.any([signal, options.signal]));
|
|
1074
|
-
}
|
|
1075
|
-
catch (aborted) {
|
|
1076
|
-
settle("cancelled", aborted);
|
|
1077
|
-
throw aborted;
|
|
1078
|
-
}
|
|
1079
|
-
pause = Math.min(pause * 2, MAX_REATTACH_DELAY_MS);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Opens a `turn.attach` stream replaying the run's events after `afterSeq`.
|
|
1085
|
-
* `timeoutMs` bounds only the request, not the stream it opens.
|
|
1086
|
-
*/
|
|
1087
|
-
async attachTurn(options, afterSeq, signal, timeoutMs) {
|
|
1088
|
-
const request = new AbortController();
|
|
1089
|
-
const timer = setTimeout(() => request.abort(new AttachTimeoutError()), Math.max(timeoutMs, 0));
|
|
1090
|
-
try {
|
|
1091
|
-
return await this.invokeRaw({
|
|
1092
|
-
payload: JSON.stringify({
|
|
1093
|
-
kind: "turn.attach",
|
|
1094
|
-
provider: this.providerFor(this.model),
|
|
1095
|
-
runId: options.runId,
|
|
1096
|
-
actorId: options.actorId,
|
|
1097
|
-
afterSeq,
|
|
1098
|
-
}),
|
|
1099
|
-
session: options.workspaceSessionKey ? "workspace" : "chat",
|
|
1100
|
-
access: options.access,
|
|
1101
|
-
signal: AbortSignal.any([signal, request.signal]),
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
finally {
|
|
1105
|
-
clearTimeout(timer);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
async consume(body, signal, options, callbacks, callbackResults, cursor, attaching) {
|
|
826
|
+
async consume(body, options, callbacks, callbackResults) {
|
|
1109
827
|
let failure;
|
|
1110
|
-
const cleanup = new BuilderFailureDrain(signal);
|
|
828
|
+
const cleanup = new BuilderFailureDrain(options.signal);
|
|
1111
829
|
try {
|
|
1112
|
-
for await (const
|
|
1113
|
-
if (
|
|
1114
|
-
if (seq <= cursor.seq)
|
|
1115
|
-
continue;
|
|
1116
|
-
cursor.seq = seq;
|
|
1117
|
-
}
|
|
1118
|
-
if (attaching &&
|
|
1119
|
-
event.type === "error" &&
|
|
1120
|
-
event.code &&
|
|
1121
|
-
ATTACH_REFUSALS.has(event.code))
|
|
1122
|
-
throw new AttachRefusedError(event.code);
|
|
1123
|
-
if (failure || options.signal.aborted) {
|
|
1124
|
-
// A finish confirms the runtime released its run before another
|
|
1125
|
-
// invocation.
|
|
1126
|
-
if (failure && event.type === "finish")
|
|
1127
|
-
cleanup.finish();
|
|
1128
|
-
// A workspace turn's end commits even when the turn failed or was
|
|
1129
|
-
// cancelled; its finish names that checkpoint.
|
|
1130
|
-
if (event.type === "finish" && event.workspace)
|
|
1131
|
-
await options.onEvent(event);
|
|
1132
|
-
continue;
|
|
1133
|
-
}
|
|
1134
|
-
if (event.type === "error") {
|
|
830
|
+
for await (const event of BuilderRuntime.readEvents(body, cleanup.signal)) {
|
|
831
|
+
if (event.type === "error" && !failure) {
|
|
1135
832
|
failure = new BuilderRuntimeError(event.code ?? "INVOCATION_FAILED", event.reason, event.beforeTurn === true, event.runSubmitted === true);
|
|
1136
833
|
cleanup.start();
|
|
1137
|
-
continue;
|
|
1138
|
-
}
|
|
1139
|
-
try {
|
|
1140
|
-
await this.forwardEvent(event, options, callbacks, callbackResults);
|
|
1141
|
-
}
|
|
1142
|
-
catch (error) {
|
|
1143
|
-
// A cancel stopped this event; a workspace turn's stream is still
|
|
1144
|
-
// read for its finish, and any other stream is closed.
|
|
1145
|
-
if (!options.signal.aborted)
|
|
1146
|
-
throw error;
|
|
1147
834
|
}
|
|
835
|
+
// A finish confirms the runtime released its run before another invocation.
|
|
836
|
+
if (failure && event.type === "finish")
|
|
837
|
+
cleanup.finish();
|
|
838
|
+
if (failure)
|
|
839
|
+
continue;
|
|
840
|
+
await this.forwardEvent(event, options, callbacks, callbackResults);
|
|
1148
841
|
}
|
|
1149
842
|
}
|
|
1150
843
|
catch (error) {
|
|
1151
|
-
|
|
1152
|
-
if (!failure || signal.aborted)
|
|
844
|
+
if (!failure || options.signal.aborted)
|
|
1153
845
|
throw error;
|
|
1154
846
|
throw failure.withUnconfirmedCleanup(cleanup.outcome);
|
|
1155
847
|
}
|