@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
|
@@ -3,29 +3,23 @@ import { setTimeout as delay } from "node:timers/promises";
|
|
|
3
3
|
import { metrics } from "@opentelemetry/api";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { AiGenerationState, AiMode, promptCostTokensFrom, } from "@superblocksteam/library-shared/types";
|
|
6
|
-
import { getAiQuotaPaywallReasonFromMessage,
|
|
7
|
-
import { getErrorMeta, getLogger } from "../util/logger.js";
|
|
6
|
+
import { getAiQuotaPaywallReasonFromMessage, } from "@superblocksteam/shared";
|
|
8
7
|
import { getToolErrorMessage } from "./agent/tool-message-utils.js";
|
|
9
|
-
import { BuilderBindingChangedError } from "./builder-binding-error.js";
|
|
10
8
|
import { BuilderContextUsageSnapshot } from "./builder-context-usage.js";
|
|
11
9
|
import { BuilderFailureNotice } from "./builder-failure-notice.js";
|
|
12
|
-
import { BuilderInferenceAuthError } from "./builder-inference-auth.js";
|
|
13
10
|
import { BuilderSessionStore } from "./builder-session-store.js";
|
|
14
11
|
import { BuilderSubagents } from "./builder-subagents.js";
|
|
15
|
-
import { AnotherQuestionPendingError,
|
|
12
|
+
import { AnotherQuestionPendingError, } from "./builder-tools.js";
|
|
16
13
|
import { RetrySchedule } from "./llm/stream/retry-schedule.js";
|
|
17
14
|
import { NativeCallbackOrder } from "./native-callback-order.js";
|
|
18
15
|
import { NativeTurnFailure } from "./native-turn-failure.js";
|
|
19
16
|
import { RequestDeduplicator } from "./request-deduplicator.js";
|
|
20
17
|
import { paywallStopAdvice } from "./state-machine/helpers/prompt-failure.js";
|
|
21
|
-
import { isPeerUnavailableError } from "./state-machine/helpers/stable-peer.js";
|
|
22
18
|
const toolErrorOutputSchema = z.union([
|
|
23
19
|
z.string(),
|
|
24
20
|
z.object({ message: z.string(), fileName: z.string().optional() }),
|
|
25
21
|
z.object({ error: z.string(), fileName: z.string().optional() }),
|
|
26
22
|
]);
|
|
27
|
-
const MAX_REMEMBERED_FAILURES = 200;
|
|
28
|
-
const SETUP_FAILURE_MESSAGE = "The native builder could not start this request. Send your prompt again.";
|
|
29
23
|
export class BuilderConversation {
|
|
30
24
|
deps;
|
|
31
25
|
/** One initial invocation and at most one retry before submission. */
|
|
@@ -49,23 +43,7 @@ export class BuilderConversation {
|
|
|
49
43
|
description: "Native builder turns re-run after failing before they produced anything",
|
|
50
44
|
unit: "1",
|
|
51
45
|
});
|
|
52
|
-
/**
|
|
53
|
-
* Under the runtime's 10-minute callback deadline, which stops the whole
|
|
54
|
-
* turn. Users who are present answer within about a minute.
|
|
55
|
-
*/
|
|
56
|
-
static USER_WAIT_LIMIT_MS = 7 * 60_000;
|
|
57
|
-
static MAX_EXPIRED_PERMISSIONS = 32;
|
|
58
|
-
userWaits = metrics
|
|
59
|
-
.getMeter("superblocks.ai_service")
|
|
60
|
-
.createHistogram("superblocks.ai_service.builder_user_wait.duration", {
|
|
61
|
-
description: "How long native builder turns waited on the user for a permission or question, by how the wait ended",
|
|
62
|
-
unit: "s",
|
|
63
|
-
});
|
|
64
|
-
/** Permission requests withdrawn unanswered, so a late answer is not an error. */
|
|
65
|
-
expiredPermissions = new Set();
|
|
66
46
|
requests = new RequestDeduplicator();
|
|
67
|
-
/** Prompts whose turn failed after their message was saved, so a re-send gets the same refusal. */
|
|
68
|
-
failedRequests = new Map();
|
|
69
47
|
sessions;
|
|
70
48
|
/** Each failed turn's classification; see `classify`. */
|
|
71
49
|
classifications = new WeakMap();
|
|
@@ -103,12 +81,8 @@ export class BuilderConversation {
|
|
|
103
81
|
}
|
|
104
82
|
async start(request, attachments = []) {
|
|
105
83
|
request = { ...request, requestId: request.requestId ?? randomUUID() };
|
|
106
|
-
if (request.requestId && this.requests.has(request.requestId))
|
|
107
|
-
const failure = this.failedRequests.get(request.requestId);
|
|
108
|
-
if (failure)
|
|
109
|
-
throw failure;
|
|
84
|
+
if (request.requestId && this.requests.has(request.requestId))
|
|
110
85
|
return this.generationId;
|
|
111
|
-
}
|
|
112
86
|
const pendingQuestion = this.pendingQuestion;
|
|
113
87
|
if (request.responseMetadata?.type === "multi_choice_response" &&
|
|
114
88
|
pendingQuestion?.message.id !==
|
|
@@ -175,7 +149,6 @@ export class BuilderConversation {
|
|
|
175
149
|
const turn = {
|
|
176
150
|
id: randomUUID(),
|
|
177
151
|
prompt: request.prompt,
|
|
178
|
-
request,
|
|
179
152
|
controller: new AbortController(),
|
|
180
153
|
completion: Promise.resolve(),
|
|
181
154
|
events: Promise.resolve(),
|
|
@@ -192,6 +165,7 @@ export class BuilderConversation {
|
|
|
192
165
|
state: AiGenerationState.GENERATING,
|
|
193
166
|
generationId: turn.id,
|
|
194
167
|
};
|
|
168
|
+
let userPublished = false;
|
|
195
169
|
try {
|
|
196
170
|
const prepared = await this.deps.prepare(request, turn.controller.signal, turn.id);
|
|
197
171
|
turn.controller.signal.throwIfAborted();
|
|
@@ -209,8 +183,8 @@ export class BuilderConversation {
|
|
|
209
183
|
};
|
|
210
184
|
await this.sessions.set(scope, session);
|
|
211
185
|
}
|
|
212
|
-
|
|
213
|
-
|
|
186
|
+
await this.publishUser(request);
|
|
187
|
+
userPublished = true;
|
|
214
188
|
await this.publishState(AiGenerationState.GENERATING, turn.id);
|
|
215
189
|
const { context, ...tools } = await this.deps.tools.prepare({
|
|
216
190
|
conversationId: session.conversationId,
|
|
@@ -223,7 +197,7 @@ export class BuilderConversation {
|
|
|
223
197
|
}),
|
|
224
198
|
peer: this.deps.peer,
|
|
225
199
|
requestPermission: (permission) => this.requestPermission(permission),
|
|
226
|
-
askUser: (message, signal
|
|
200
|
+
askUser: (message, signal) => this.askUser(turn, message, signal),
|
|
227
201
|
});
|
|
228
202
|
turn.controller.signal.throwIfAborted();
|
|
229
203
|
turn.completion = this.run(turn, {
|
|
@@ -257,21 +231,14 @@ export class BuilderConversation {
|
|
|
257
231
|
prompt: [context, request.prompt].filter(Boolean).join("\n\n"),
|
|
258
232
|
signal: turn.controller.signal,
|
|
259
233
|
onEvent: (event) => {
|
|
260
|
-
|
|
261
|
-
// the checkpoint the turn end committed even so.
|
|
262
|
-
const committed = event.type === "finish" && event.workspace;
|
|
263
|
-
if (this.turn !== turn ||
|
|
264
|
-
(turn.controller.signal.aborted && !committed))
|
|
234
|
+
if (this.turn !== turn || turn.controller.signal.aborted)
|
|
265
235
|
return;
|
|
266
236
|
if (event.type !== "session" && event.type !== "finish")
|
|
267
237
|
turn.progressed = true;
|
|
268
238
|
turn.events = turn.events
|
|
269
239
|
.then(async () => {
|
|
270
|
-
if (turn.controller.signal.aborted)
|
|
271
|
-
if (committed)
|
|
272
|
-
await prepared.onWorkspaceFinish?.(committed);
|
|
240
|
+
if (turn.controller.signal.aborted)
|
|
273
241
|
return;
|
|
274
|
-
}
|
|
275
242
|
if (event.type === "session") {
|
|
276
243
|
if (prepared.saveSession)
|
|
277
244
|
await this.persistSession(turn, prepared.saveSession(event.sessionId));
|
|
@@ -302,7 +269,8 @@ export class BuilderConversation {
|
|
|
302
269
|
? getAiQuotaPaywallReasonFromMessage(error.message)
|
|
303
270
|
: undefined;
|
|
304
271
|
if (paywallReason && !turn.controller.signal.aborted) {
|
|
305
|
-
|
|
272
|
+
if (!userPublished)
|
|
273
|
+
await this.publishUser(request);
|
|
306
274
|
await this.publish({
|
|
307
275
|
role: "assistant",
|
|
308
276
|
type: "text",
|
|
@@ -311,112 +279,11 @@ export class BuilderConversation {
|
|
|
311
279
|
await this.settle(turn, error, paywallReason);
|
|
312
280
|
return turn.id;
|
|
313
281
|
}
|
|
314
|
-
let shown;
|
|
315
|
-
if (turn.controller.signal.aborted) {
|
|
316
|
-
// A cancel during setup saves the prompt in cancel(); a stopped turn keeps it.
|
|
317
|
-
await turn.userSaving?.catch(() => { });
|
|
318
|
-
if (turn.userPublished)
|
|
319
|
-
shown = new PromptFailureShownInChatError("Builder turn cancelled", {
|
|
320
|
-
cause: error,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
shown = await this.showSetupFailure(turn, error);
|
|
325
|
-
}
|
|
326
|
-
if (request.requestId) {
|
|
327
|
-
if (turn.userPublished)
|
|
328
|
-
this.rememberFailure(request.requestId, shown ?? toError(error));
|
|
329
|
-
else
|
|
330
|
-
this.requests.forget(request.requestId);
|
|
331
|
-
}
|
|
332
|
-
await this.settle(turn, error);
|
|
333
|
-
throw shown ?? error;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
rememberFailure(requestId, error) {
|
|
337
|
-
this.failedRequests.set(requestId, error);
|
|
338
|
-
if (this.failedRequests.size > MAX_REMEMBERED_FAILURES) {
|
|
339
|
-
const oldest = this.failedRequests.keys().next().value;
|
|
340
|
-
if (oldest !== undefined)
|
|
341
|
-
this.failedRequests.delete(oldest);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Saves a prompt refused before its turn, without the attachments it was
|
|
346
|
-
* refused for: saved attachments are restored on every later turn.
|
|
347
|
-
*/
|
|
348
|
-
async rejectPrompt(request, error) {
|
|
349
|
-
const original = toError(error);
|
|
350
|
-
const { message } = original;
|
|
351
|
-
const type = request.responseMetadata?.type;
|
|
352
|
-
// A busy conversation would put the rows inside the running turn's output.
|
|
353
|
-
if (this.isBusy ||
|
|
354
|
-
type === "multi_choice_response" ||
|
|
355
|
-
type === "tool_permission_response")
|
|
356
|
-
return original;
|
|
357
|
-
const shown = new PromptFailureShownInChatError(message, { cause: error });
|
|
358
|
-
if (request.requestId && !this.requests.markIfNew(request.requestId))
|
|
359
|
-
return this.failedRequests.get(request.requestId) ?? shown;
|
|
360
|
-
try {
|
|
361
|
-
await this.publishUser({
|
|
362
|
-
...request,
|
|
363
|
-
...(request.promptContext && {
|
|
364
|
-
promptContext: { ...request.promptContext, attachments: undefined },
|
|
365
|
-
}),
|
|
366
|
-
});
|
|
367
|
-
await this.publish({
|
|
368
|
-
role: "assistant",
|
|
369
|
-
type: "error",
|
|
370
|
-
content: message,
|
|
371
|
-
});
|
|
372
|
-
if (request.requestId)
|
|
373
|
-
this.rememberFailure(request.requestId, shown);
|
|
374
|
-
return shown;
|
|
375
|
-
}
|
|
376
|
-
catch (persistError) {
|
|
377
|
-
this.deps.onError?.(persistError, undefined, {
|
|
378
|
-
"builder.request.id": request.requestId,
|
|
379
|
-
"builder.prompt_failure.path": "rejected_prompt",
|
|
380
|
-
"builder.prompt_failure.cause": message,
|
|
381
|
-
});
|
|
382
282
|
if (request.requestId)
|
|
383
283
|
this.requests.forget(request.requestId);
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/** Concurrent callers share one write; the turn counts as published once it lands. */
|
|
388
|
-
publishTurnUser(turn) {
|
|
389
|
-
turn.userSaving ??= this.publishUser(turn.request).then(() => {
|
|
390
|
-
turn.userPublished = true;
|
|
391
|
-
}, (error) => {
|
|
392
|
-
turn.userSaving = undefined;
|
|
284
|
+
await this.settle(turn, error);
|
|
393
285
|
throw error;
|
|
394
|
-
});
|
|
395
|
-
return turn.userSaving;
|
|
396
|
-
}
|
|
397
|
-
async showSetupFailure(turn, error) {
|
|
398
|
-
if (error instanceof BuilderBindingChangedError ||
|
|
399
|
-
error instanceof BuilderInferenceAuthError ||
|
|
400
|
-
isChatChangedElsewhereError(error))
|
|
401
|
-
return undefined;
|
|
402
|
-
const { message } = toError(error);
|
|
403
|
-
try {
|
|
404
|
-
await this.publishTurnUser(turn);
|
|
405
|
-
await this.publish({
|
|
406
|
-
role: "assistant",
|
|
407
|
-
type: "error",
|
|
408
|
-
content: SETUP_FAILURE_MESSAGE,
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
catch (persistError) {
|
|
412
|
-
this.deps.onError?.(persistError, undefined, {
|
|
413
|
-
"builder.request.id": turn.request.requestId,
|
|
414
|
-
"builder.prompt_failure.path": "setup_failure",
|
|
415
|
-
"builder.prompt_failure.cause": message,
|
|
416
|
-
});
|
|
417
|
-
return undefined;
|
|
418
286
|
}
|
|
419
|
-
return new PromptFailureShownInChatError(message, { cause: error });
|
|
420
287
|
}
|
|
421
288
|
async persistSession(turn, saved) {
|
|
422
289
|
const signal = turn.controller.signal;
|
|
@@ -439,47 +306,27 @@ export class BuilderConversation {
|
|
|
439
306
|
}
|
|
440
307
|
async run(turn, invocation) {
|
|
441
308
|
let failure;
|
|
442
|
-
let invokeFailed = false;
|
|
443
309
|
let paywallReason;
|
|
444
310
|
try {
|
|
445
311
|
await this.invoke(turn, invocation);
|
|
446
312
|
}
|
|
447
313
|
catch (error) {
|
|
448
314
|
failure = error;
|
|
449
|
-
|
|
315
|
+
if (!turn.controller.signal.aborted) {
|
|
316
|
+
paywallReason = (await this.reportFailure(turn, error)).paywallReason;
|
|
317
|
+
}
|
|
450
318
|
}
|
|
451
319
|
finally {
|
|
452
|
-
// The chat order is the turn's text, then its checkpoint card, then any
|
|
453
|
-
// error: the latest message must be the error for its Retry button to
|
|
454
|
-
// survive a reload.
|
|
455
320
|
try {
|
|
456
|
-
await turn.events;
|
|
457
|
-
await this.flushText(turn);
|
|
321
|
+
await this.deps.afterRun?.({ events: () => turn.events });
|
|
458
322
|
}
|
|
459
323
|
catch (error) {
|
|
460
324
|
failure ??= error;
|
|
461
325
|
this.deps.onError?.(error);
|
|
462
326
|
}
|
|
463
327
|
try {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
});
|
|
467
|
-
turn.checkpointed = Boolean(after?.checkpointId);
|
|
468
|
-
}
|
|
469
|
-
catch (error) {
|
|
470
|
-
failure ??= error;
|
|
471
|
-
this.deps.onError?.(error);
|
|
472
|
-
}
|
|
473
|
-
if (invokeFailed && !turn.controller.signal.aborted) {
|
|
474
|
-
try {
|
|
475
|
-
paywallReason = (await this.reportFailure(turn, failure))
|
|
476
|
-
.paywallReason;
|
|
477
|
-
}
|
|
478
|
-
catch (error) {
|
|
479
|
-
this.deps.onError?.(error);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
try {
|
|
328
|
+
await turn.events;
|
|
329
|
+
await this.flushText(turn);
|
|
483
330
|
await this.deps.chat.flushPendingPushes();
|
|
484
331
|
}
|
|
485
332
|
catch (error) {
|
|
@@ -601,16 +448,9 @@ export class BuilderConversation {
|
|
|
601
448
|
const turn = this.turn;
|
|
602
449
|
if (!turn)
|
|
603
450
|
return;
|
|
604
|
-
const settingUp = !turn.userPublished;
|
|
605
451
|
turn.stopped = true;
|
|
606
452
|
turn.controller.abort(new DOMException("Builder turn cancelled", "AbortError"));
|
|
607
453
|
this.clearPermission(turn.controller.signal.reason);
|
|
608
|
-
// Saved before settling so a reset or the next prompt lands after it.
|
|
609
|
-
if (settingUp)
|
|
610
|
-
await this.publishTurnUser(turn).catch((error) => this.deps.onError?.(error, undefined, {
|
|
611
|
-
"builder.request.id": turn.request.requestId,
|
|
612
|
-
"builder.prompt_failure.path": "cancel_during_setup",
|
|
613
|
-
}));
|
|
614
454
|
await turn.completion;
|
|
615
455
|
await this.settle(turn, turn.controller.signal.reason);
|
|
616
456
|
}
|
|
@@ -632,14 +472,9 @@ export class BuilderConversation {
|
|
|
632
472
|
await turn.subagents.failRunning();
|
|
633
473
|
if (this.turn === turn) {
|
|
634
474
|
this.turn = undefined;
|
|
635
|
-
// COMPLETED means the turn changed the app, as it does for Clark,
|
|
636
|
-
// whose turns without a draft end IDLE. The editor plays its
|
|
637
|
-
// completion sound on it.
|
|
638
475
|
await this.publishState(failed || cancelled
|
|
639
476
|
? AiGenerationState.CANCELLED
|
|
640
|
-
: turn.
|
|
641
|
-
? AiGenerationState.COMPLETED
|
|
642
|
-
: AiGenerationState.IDLE, turn.id, failed && !cancelled && !paywallReason, paywallReason);
|
|
477
|
+
: AiGenerationState.COMPLETED, turn.id, failed && !cancelled && !paywallReason, paywallReason);
|
|
643
478
|
}
|
|
644
479
|
this.deps.onSettled(turn.id, error, cancelled);
|
|
645
480
|
}
|
|
@@ -663,17 +498,12 @@ export class BuilderConversation {
|
|
|
663
498
|
const turn = this.turn;
|
|
664
499
|
if (!turn || turn.controller.signal.aborted)
|
|
665
500
|
throw new DOMException("Builder turn ended", "AbortError");
|
|
666
|
-
if (turn.userWaitExpired)
|
|
667
|
-
throw this.refuseAfterExpiry(turn, "permission", request.toolCallId);
|
|
668
501
|
if (this.pendingPermission)
|
|
669
502
|
throw new Error("A tool permission request is already pending");
|
|
670
503
|
const result = new Promise((resolve, reject) => {
|
|
671
504
|
this.pendingPermission = { request, resolve, reject };
|
|
672
505
|
});
|
|
673
506
|
void result.catch(() => { });
|
|
674
|
-
this.timeUserWait("permission", true, result, (approved) => approved ? "approved" : "denied");
|
|
675
|
-
const startedAt = performance.now();
|
|
676
|
-
this.expireAfter(result, () => this.expirePermission(turn, request, startedAt));
|
|
677
507
|
await this.flushText(turn);
|
|
678
508
|
await this.publishState(AiGenerationState.AWAITING_USER_INPUT, turn.id);
|
|
679
509
|
await this.deliverPermission(request);
|
|
@@ -683,16 +513,6 @@ export class BuilderConversation {
|
|
|
683
513
|
if (response.requestId && this.requests.has(response.requestId))
|
|
684
514
|
return;
|
|
685
515
|
const pending = this.pendingPermission;
|
|
686
|
-
if (pending?.request.toolCallId !== response.messageId &&
|
|
687
|
-
this.expiredPermissions.has(response.messageId)) {
|
|
688
|
-
getLogger().info("[builder-conversation] Ignored an answer to a permission request withdrawn unanswered", {
|
|
689
|
-
conversationId: this.turn?.conversationId,
|
|
690
|
-
turnId: this.turn?.id,
|
|
691
|
-
toolCallId: response.messageId,
|
|
692
|
-
approved: response.approved,
|
|
693
|
-
});
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
516
|
if (!pending || pending.request.toolCallId !== response.messageId)
|
|
697
517
|
throw new Error("No matching pending tool permission");
|
|
698
518
|
if (!this.turn || this.turn.controller.signal.aborted)
|
|
@@ -719,9 +539,6 @@ export class BuilderConversation {
|
|
|
719
539
|
if (this.pendingQuestion)
|
|
720
540
|
await this.push(() => this.deps.peer.call.aiPushMessage(this.pendingQuestion.message));
|
|
721
541
|
const text = this.turn?.text;
|
|
722
|
-
// The full text below already carries what was still waiting to go out.
|
|
723
|
-
if (this.turn)
|
|
724
|
-
this.turn.unsent = undefined;
|
|
725
542
|
if (text)
|
|
726
543
|
await this.push(() => this.deps.peer.call.aiPushMessage({
|
|
727
544
|
id: text.id,
|
|
@@ -738,79 +555,7 @@ export class BuilderConversation {
|
|
|
738
555
|
return;
|
|
739
556
|
await this.push(() => this.deps.peer.call.aiPushContextUsed(snapshot));
|
|
740
557
|
}
|
|
741
|
-
|
|
742
|
-
return this.deps.userWaitLimitMs ?? BuilderConversation.USER_WAIT_LIMIT_MS;
|
|
743
|
-
}
|
|
744
|
-
/** Records how long a wait on the user lasted and how it ended, once it settles. */
|
|
745
|
-
timeUserWait(kind, expires, result, outcome) {
|
|
746
|
-
const startedAt = performance.now();
|
|
747
|
-
const record = (ended) => this.userWaits.record((performance.now() - startedAt) / 1000, {
|
|
748
|
-
"wait.kind": kind,
|
|
749
|
-
"wait.expires": expires,
|
|
750
|
-
"wait.outcome": ended,
|
|
751
|
-
});
|
|
752
|
-
result.then((value) => record(outcome(value)), (error) => record(error instanceof UserWaitExpiredError ? "expired" : "ended"));
|
|
753
|
-
}
|
|
754
|
-
/** Runs `withdraw` if `result` has not settled within the wait limit. */
|
|
755
|
-
expireAfter(result, withdraw) {
|
|
756
|
-
const timer = setTimeout(() => {
|
|
757
|
-
withdraw().catch((error) => this.deps.onError?.(error));
|
|
758
|
-
}, this.userWaitLimitMs);
|
|
759
|
-
timer.unref?.();
|
|
760
|
-
const clear = () => clearTimeout(timer);
|
|
761
|
-
result.then(clear, clear);
|
|
762
|
-
}
|
|
763
|
-
/** The error for a wait refused, unshown, because an earlier one in the turn went unanswered. */
|
|
764
|
-
refuseAfterExpiry(turn, kind, id) {
|
|
765
|
-
getLogger().info(`[builder-conversation] Refused a ${kind} without showing it because an earlier one in the turn went unanswered`, { conversationId: turn.conversationId, turnId: turn.id, id });
|
|
766
|
-
return new UserWaitExpiredError(this.userWaitLimitMs, { shown: false });
|
|
767
|
-
}
|
|
768
|
-
logExpiry(turn, kind, id, startedAt) {
|
|
769
|
-
getLogger().info(`[builder-conversation] Withdrew a ${kind} the user did not answer in time`, {
|
|
770
|
-
conversationId: turn.conversationId,
|
|
771
|
-
turnId: turn.id,
|
|
772
|
-
id,
|
|
773
|
-
waitedMs: Math.round(performance.now() - startedAt),
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
async expirePermission(turn, request, startedAt) {
|
|
777
|
-
const pending = this.pendingPermission;
|
|
778
|
-
if (pending?.request !== request || pending.responding)
|
|
779
|
-
return;
|
|
780
|
-
this.pendingPermission = undefined;
|
|
781
|
-
turn.userWaitExpired = true;
|
|
782
|
-
this.expiredPermissions.add(request.toolCallId);
|
|
783
|
-
if (this.expiredPermissions.size > BuilderConversation.MAX_EXPIRED_PERMISSIONS) {
|
|
784
|
-
const [oldest] = this.expiredPermissions;
|
|
785
|
-
if (oldest !== undefined)
|
|
786
|
-
this.expiredPermissions.delete(oldest);
|
|
787
|
-
}
|
|
788
|
-
this.logExpiry(turn, "permission", request.toolCallId, startedAt);
|
|
789
|
-
try {
|
|
790
|
-
await this.push(() => this.deps.peer.call.aiClearToolPermission());
|
|
791
|
-
if (this.turn === turn && !turn.controller.signal.aborted)
|
|
792
|
-
await this.publishState(AiGenerationState.GENERATING, turn.id);
|
|
793
|
-
}
|
|
794
|
-
finally {
|
|
795
|
-
pending.reject(new UserWaitExpiredError(this.userWaitLimitMs));
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
async expireQuestion(turn, message, startedAt) {
|
|
799
|
-
const pending = this.pendingQuestion;
|
|
800
|
-
if (pending?.message !== message || pending.responding)
|
|
801
|
-
return;
|
|
802
|
-
this.pendingQuestion = undefined;
|
|
803
|
-
turn.userWaitExpired = true;
|
|
804
|
-
this.logExpiry(turn, "question", message.id, startedAt);
|
|
805
|
-
try {
|
|
806
|
-
if (this.turn === turn && !turn.controller.signal.aborted)
|
|
807
|
-
await this.publishState(AiGenerationState.GENERATING, turn.id);
|
|
808
|
-
}
|
|
809
|
-
finally {
|
|
810
|
-
pending.reject(new UserWaitExpiredError(this.userWaitLimitMs));
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
async askUser(turn, message, signal, options = {}) {
|
|
558
|
+
async askUser(turn, message, signal) {
|
|
814
559
|
// The check and the pendingQuestion assignment below are separated by
|
|
815
560
|
// awaits. That is safe only because every tool that can ask (the
|
|
816
561
|
// integration setup banner tools and __runtime_user_input) runs through
|
|
@@ -818,8 +563,6 @@ export class BuilderConversation {
|
|
|
818
563
|
// questions race here.
|
|
819
564
|
if (this.pendingQuestion)
|
|
820
565
|
throw new AnotherQuestionPendingError();
|
|
821
|
-
if (options.expire && turn.userWaitExpired)
|
|
822
|
-
throw this.refuseAfterExpiry(turn, "question", message.id);
|
|
823
566
|
await turn.events;
|
|
824
567
|
signal.throwIfAborted();
|
|
825
568
|
await this.flushText(turn);
|
|
@@ -828,10 +571,6 @@ export class BuilderConversation {
|
|
|
828
571
|
this.pendingQuestion = { message, resolve, reject };
|
|
829
572
|
});
|
|
830
573
|
void result.catch(() => { });
|
|
831
|
-
this.timeUserWait("question", options.expire === true, result, () => "answered");
|
|
832
|
-
const startedAt = performance.now();
|
|
833
|
-
if (options.expire)
|
|
834
|
-
this.expireAfter(result, () => this.expireQuestion(turn, message, startedAt));
|
|
835
574
|
await this.publishState(AiGenerationState.AWAITING_USER_INPUT, turn.id);
|
|
836
575
|
signal.throwIfAborted();
|
|
837
576
|
await this.publish(message);
|
|
@@ -846,12 +585,13 @@ export class BuilderConversation {
|
|
|
846
585
|
case "text-delta": {
|
|
847
586
|
turn.text ??= { id: randomUUID(), value: "" };
|
|
848
587
|
turn.text.value += event.text;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
turn.
|
|
854
|
-
|
|
588
|
+
await this.push(() => this.deps.peer.call.aiPushMessage({
|
|
589
|
+
id: randomUUID(),
|
|
590
|
+
role: "assistant",
|
|
591
|
+
type: "text-delta",
|
|
592
|
+
textBlockId: turn.text.id,
|
|
593
|
+
content: event.text,
|
|
594
|
+
}));
|
|
855
595
|
break;
|
|
856
596
|
}
|
|
857
597
|
case "plan":
|
|
@@ -958,26 +698,7 @@ export class BuilderConversation {
|
|
|
958
698
|
break;
|
|
959
699
|
}
|
|
960
700
|
}
|
|
961
|
-
/** Pushes `unsent` text until none is left, one push in flight at a time. */
|
|
962
|
-
async sendText(turn) {
|
|
963
|
-
// No abort check: text handled before a cancel still belongs in the
|
|
964
|
-
// sidebar, and once the turn is aborted push() no longer waits for the
|
|
965
|
-
// browser, so the remainder goes out at once.
|
|
966
|
-
while (turn.unsent) {
|
|
967
|
-
const { id, value } = turn.unsent;
|
|
968
|
-
turn.unsent = undefined;
|
|
969
|
-
await this.push(() => this.deps.peer.call.aiPushMessage({
|
|
970
|
-
id: randomUUID(),
|
|
971
|
-
role: "assistant",
|
|
972
|
-
type: "text-delta",
|
|
973
|
-
textBlockId: id,
|
|
974
|
-
content: value,
|
|
975
|
-
}));
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
701
|
async flushText(turn) {
|
|
979
|
-
// Streamed text reaches the browser before whatever follows it.
|
|
980
|
-
await turn.sending;
|
|
981
702
|
const text = turn.text;
|
|
982
703
|
if (!text)
|
|
983
704
|
return;
|
|
@@ -1096,52 +817,35 @@ export class BuilderConversation {
|
|
|
1096
817
|
"item/commandExecution/requestApproval",
|
|
1097
818
|
"item/fileChange/requestApproval",
|
|
1098
819
|
]),
|
|
1099
|
-
params: z.record(z.
|
|
820
|
+
params: z.record(z.unknown()),
|
|
1100
821
|
}),
|
|
1101
822
|
execute: async ({ method, params }, options) => {
|
|
1102
823
|
if (request.mode === AiMode.PLAN)
|
|
1103
824
|
return { decision: "decline" };
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
?
|
|
1110
|
-
:
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
permissions: [],
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
catch (error) {
|
|
1125
|
-
if (!(error instanceof UserWaitExpiredError))
|
|
1126
|
-
throw error;
|
|
1127
|
-
// Codex approvals carry no reason; a decline lets the turn go on
|
|
1128
|
-
// where cancel would end it.
|
|
1129
|
-
getLogger().info("[builder-conversation] Declined a Codex approval the user did not answer", {
|
|
1130
|
-
conversationId: this.turn?.conversationId,
|
|
1131
|
-
turnId: this.turn?.id,
|
|
1132
|
-
toolCallId: options.toolCallId,
|
|
1133
|
-
method,
|
|
1134
|
-
shown: error.shown,
|
|
1135
|
-
});
|
|
1136
|
-
return { decision: "decline" };
|
|
1137
|
-
}
|
|
825
|
+
const approved = await this.requestPermission({
|
|
826
|
+
toolCallId: options.toolCallId,
|
|
827
|
+
toolName: method === "item/fileChange/requestApproval"
|
|
828
|
+
? "apply_patch"
|
|
829
|
+
: typeof params.toolName === "string"
|
|
830
|
+
? params.toolName
|
|
831
|
+
: "exec_command",
|
|
832
|
+
input: params,
|
|
833
|
+
formattedInput: {
|
|
834
|
+
targets: [
|
|
835
|
+
typeof params.command === "string"
|
|
836
|
+
? params.command
|
|
837
|
+
: "Native builder action",
|
|
838
|
+
],
|
|
839
|
+
},
|
|
840
|
+
permissions: [],
|
|
841
|
+
});
|
|
1138
842
|
return { decision: approved ? "accept" : "decline" };
|
|
1139
843
|
},
|
|
1140
844
|
},
|
|
1141
845
|
__runtime_user_input: {
|
|
1142
846
|
inputSchema: z.object({
|
|
1143
847
|
method: z.enum(["item/tool/requestUserInput"]),
|
|
1144
|
-
afterEventId: z.
|
|
848
|
+
afterEventId: z.string().uuid().optional(),
|
|
1145
849
|
params: z
|
|
1146
850
|
.object({
|
|
1147
851
|
questions: z
|
|
@@ -1194,14 +898,7 @@ export class BuilderConversation {
|
|
|
1194
898
|
const signal = this.turn?.controller.signal;
|
|
1195
899
|
const sent = Promise.resolve()
|
|
1196
900
|
.then(send)
|
|
1197
|
-
.catch((error) =>
|
|
1198
|
-
// A dropped editor connection is not a builder failure, and replay()
|
|
1199
|
-
// restores the chat once the editor is back. Clark logs it the same way.
|
|
1200
|
-
if (isPeerUnavailableError(error))
|
|
1201
|
-
getLogger().info("[builder-conversation] Push dropped because the editor peer disconnected or was replaced", getErrorMeta(error));
|
|
1202
|
-
else
|
|
1203
|
-
this.deps.onError?.(error);
|
|
1204
|
-
});
|
|
901
|
+
.catch((error) => this.deps.onError?.(error));
|
|
1205
902
|
if (!signal || signal.aborted) {
|
|
1206
903
|
void sent;
|
|
1207
904
|
return;
|
|
@@ -1223,7 +920,4 @@ export class BuilderConversation {
|
|
|
1223
920
|
}
|
|
1224
921
|
}
|
|
1225
922
|
}
|
|
1226
|
-
function toError(error) {
|
|
1227
|
-
return error instanceof Error ? error : new Error(String(error));
|
|
1228
|
-
}
|
|
1229
923
|
//# sourceMappingURL=builder-conversation.js.map
|