@superblocksteam/vite-plugin-file-sync 2.0.174 → 2.0.175-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/codex-drafts.d.ts +12 -0
- package/dist/agent-tool-executor/codex-drafts.d.ts.map +1 -0
- package/dist/agent-tool-executor/codex-drafts.js +48 -0
- package/dist/agent-tool-executor/codex-drafts.js.map +1 -0
- package/dist/agent-tool-executor/codex-exec-server.d.ts +42 -0
- package/dist/agent-tool-executor/codex-exec-server.d.ts.map +1 -0
- package/dist/agent-tool-executor/codex-exec-server.js +405 -0
- package/dist/agent-tool-executor/codex-exec-server.js.map +1 -0
- package/dist/agent-tool-executor/codex-execution-policy.d.ts +12 -0
- package/dist/agent-tool-executor/codex-execution-policy.d.ts.map +1 -0
- package/dist/agent-tool-executor/codex-execution-policy.js +201 -0
- package/dist/agent-tool-executor/codex-execution-policy.js.map +1 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts +12 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.d.ts.map +1 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.js +74 -0
- package/dist/agent-tool-executor/native-dotenv-watch-scope.js.map +1 -0
- package/dist/ai-service/agent/middleware.d.ts.map +1 -1
- package/dist/ai-service/agent/middleware.js +45 -0
- package/dist/ai-service/agent/middleware.js.map +1 -1
- 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 +17 -2
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/prompts/build-security-scan-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-security-scan-prompt.js +106 -11
- package/dist/ai-service/agent/prompts/build-security-scan-prompt.js.map +1 -1
- package/dist/ai-service/agent/security-scan-tools.d.ts +12 -0
- package/dist/ai-service/agent/security-scan-tools.d.ts.map +1 -0
- package/dist/ai-service/agent/security-scan-tools.js +44 -0
- package/dist/ai-service/agent/security-scan-tools.js.map +1 -0
- package/dist/ai-service/agent/tool-permission-delivery-metrics.d.ts +1 -1
- package/dist/ai-service/agent/tool-permission-delivery-metrics.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-permission-delivery-metrics.js +1 -1
- package/dist/ai-service/agent/tool-permission-delivery-metrics.js.map +1 -1
- package/dist/ai-service/agent/tool-permission-delivery.d.ts +2 -0
- package/dist/ai-service/agent/tool-permission-delivery.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-permission-delivery.js +7 -0
- package/dist/ai-service/agent/tool-permission-delivery.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts +3 -3
- package/dist/ai-service/agent/tools/apis/test-api.d.ts +78 -13
- package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/test-api.js +80 -58
- package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/write-api.d.ts +2 -2
- package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts +11 -3
- package/dist/ai-service/agent/tools/build-capture-screenshot.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-capture-screenshot.js +13 -8
- package/dist/ai-service/agent/tools/build-capture-screenshot.js.map +1 -1
- package/dist/ai-service/agent/tools/build-delete-file.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.d.ts +6 -0
- package/dist/ai-service/agent/tools/build-navigate-preview.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-navigate-preview.js +5 -4
- package/dist/ai-service/agent/tools/build-navigate-preview.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts +4 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js +6 -3
- package/dist/ai-service/agent/tools/databases/destructive-migration-prompt.js.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tasks.d.ts +11 -4
- 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 +21 -3
- 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.map +1 -1
- package/dist/ai-service/agent/tools/databases/dev-database-tools.js +32 -5
- package/dist/ai-service/agent/tools/databases/dev-database-tools.js.map +1 -1
- package/dist/ai-service/agent/tools/get-logs.d.ts +5 -2
- package/dist/ai-service/agent/tools/get-logs.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/get-logs.js +6 -3
- package/dist/ai-service/agent/tools/get-logs.js.map +1 -1
- package/dist/ai-service/agent/tools/get-runtime-errors.d.ts +2 -0
- package/dist/ai-service/agent/tools/get-runtime-errors.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/get-runtime-errors.js +3 -2
- package/dist/ai-service/agent/tools/get-runtime-errors.js.map +1 -1
- package/dist/ai-service/agent/tools/get-security-findings.js +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.js +28 -3
- package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/managed-app-database.d.ts +28 -0
- package/dist/ai-service/agent/tools/integrations/managed-app-database.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/managed-app-database.js +30 -1
- package/dist/ai-service/agent/tools/integrations/managed-app-database.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts +6 -3
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/integrations/metadata.js +34 -17
- package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -1
- package/dist/ai-service/agent/tools/report-security-findings.d.ts +3 -3
- package/dist/ai-service/agent/tools/report-security-findings.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/report-security-findings.js +6 -4
- package/dist/ai-service/agent/tools/report-security-findings.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts +1 -5
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +7 -42
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts +4 -3
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js +4 -2
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep.js +27 -5
- package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -1
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +12 -8
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/app-interface/file-system-interface.d.ts +1 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts +2 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.d.ts.map +1 -1
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js +9 -2
- package/dist/ai-service/app-interface/filesystem/handlers/skill-handler.js.map +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts +1 -0
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.d.ts.map +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.js +1 -1
- package/dist/ai-service/app-interface/filesystem/virtual-file-system.js.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.d.ts +1 -0
- package/dist/ai-service/app-interface/npm-registry.d.ts.map +1 -1
- package/dist/ai-service/app-interface/npm-registry.js +45 -6
- package/dist/ai-service/app-interface/npm-registry.js.map +1 -1
- package/dist/ai-service/app-interface/shell.d.ts +7 -1
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
- package/dist/ai-service/app-interface/shell.js +84 -30
- package/dist/ai-service/app-interface/shell.js.map +1 -1
- package/dist/ai-service/builder-conversation.d.ts +70 -0
- package/dist/ai-service/builder-conversation.d.ts.map +1 -0
- package/dist/ai-service/builder-conversation.js +660 -0
- package/dist/ai-service/builder-conversation.js.map +1 -0
- package/dist/ai-service/builder-inference-auth.d.ts +11 -0
- package/dist/ai-service/builder-inference-auth.d.ts.map +1 -0
- package/dist/ai-service/builder-inference-auth.js +48 -0
- package/dist/ai-service/builder-inference-auth.js.map +1 -0
- package/dist/ai-service/builder-runtime.d.ts +181 -0
- package/dist/ai-service/builder-runtime.d.ts.map +1 -0
- package/dist/ai-service/builder-runtime.js +337 -0
- package/dist/ai-service/builder-runtime.js.map +1 -0
- package/dist/ai-service/builder-session-store.d.ts +26 -0
- package/dist/ai-service/builder-session-store.d.ts.map +1 -0
- package/dist/ai-service/builder-session-store.js +66 -0
- package/dist/ai-service/builder-session-store.js.map +1 -0
- package/dist/ai-service/builder-tool-callbacks.d.ts +26 -0
- package/dist/ai-service/builder-tool-callbacks.d.ts.map +1 -0
- package/dist/ai-service/builder-tool-callbacks.js +114 -0
- package/dist/ai-service/builder-tool-callbacks.js.map +1 -0
- package/dist/ai-service/builder-tools.d.ts +46 -0
- package/dist/ai-service/builder-tools.d.ts.map +1 -0
- package/dist/ai-service/builder-tools.js +181 -0
- package/dist/ai-service/builder-tools.js.map +1 -0
- package/dist/ai-service/chat/chat-session-store.d.ts +10 -1
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +30 -1
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/chat/switch-chat-seed.d.ts +8 -0
- package/dist/ai-service/chat/switch-chat-seed.d.ts.map +1 -0
- package/dist/ai-service/chat/switch-chat-seed.js +47 -0
- package/dist/ai-service/chat/switch-chat-seed.js.map +1 -0
- package/dist/ai-service/dev-database-client.d.ts +1 -0
- package/dist/ai-service/dev-database-client.d.ts.map +1 -1
- package/dist/ai-service/dev-database-client.js +1 -0
- package/dist/ai-service/dev-database-client.js.map +1 -1
- package/dist/ai-service/dev-database-file-sync.d.ts +3 -1
- 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/edit-after-clark.d.ts.map +1 -1
- package/dist/ai-service/edit-after-clark.js +10 -5
- package/dist/ai-service/edit-after-clark.js.map +1 -1
- package/dist/ai-service/features.d.ts +15 -8
- package/dist/ai-service/features.d.ts.map +1 -1
- package/dist/ai-service/features.js +15 -8
- package/dist/ai-service/features.js.map +1 -1
- package/dist/ai-service/index.d.ts +47 -19
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +564 -743
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/integrations/store.d.ts +5 -1
- package/dist/ai-service/integrations/store.d.ts.map +1 -1
- package/dist/ai-service/integrations/store.js +8 -0
- package/dist/ai-service/integrations/store.js.map +1 -1
- package/dist/ai-service/llm/context-v2/context-metrics.js +2 -2
- package/dist/ai-service/llm/context-v2/manager.d.ts +3 -1
- package/dist/ai-service/llm/context-v2/manager.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/manager.js +5 -0
- package/dist/ai-service/llm/context-v2/manager.js.map +1 -1
- package/dist/ai-service/llm/context-v2/types.d.ts +1 -1
- package/dist/ai-service/llm/context-v2/types.d.ts.map +1 -1
- package/dist/ai-service/llm/context-v2/types.js.map +1 -1
- package/dist/ai-service/llm/error.d.ts.map +1 -1
- package/dist/ai-service/llm/error.js +17 -3
- package/dist/ai-service/llm/error.js.map +1 -1
- package/dist/ai-service/llm/request-settings.d.ts +6 -0
- package/dist/ai-service/llm/request-settings.d.ts.map +1 -0
- package/dist/ai-service/llm/request-settings.js +21 -0
- package/dist/ai-service/llm/request-settings.js.map +1 -0
- package/dist/ai-service/llm/stream/config.d.ts +1 -1
- package/dist/ai-service/llm/stream/config.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/config.js.map +1 -1
- package/dist/ai-service/llm/stream/errors.d.ts +4 -1
- package/dist/ai-service/llm/stream/errors.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/errors.js +8 -2
- package/dist/ai-service/llm/stream/errors.js.map +1 -1
- package/dist/ai-service/llm/stream/observers/llmobs.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/observers/llmobs.js +5 -2
- package/dist/ai-service/llm/stream/observers/llmobs.js.map +1 -1
- package/dist/ai-service/llm/stream/orchestrator.d.ts.map +1 -1
- package/dist/ai-service/llm/stream/orchestrator.js +3 -6
- package/dist/ai-service/llm/stream/orchestrator.js.map +1 -1
- package/dist/ai-service/llmobs/otel-exporter.d.ts.map +1 -1
- package/dist/ai-service/llmobs/otel-exporter.js +4 -0
- package/dist/ai-service/llmobs/otel-exporter.js.map +1 -1
- package/dist/ai-service/llmobs/tracer.d.ts.map +1 -1
- package/dist/ai-service/llmobs/tracer.js +4 -21
- package/dist/ai-service/llmobs/tracer.js.map +1 -1
- package/dist/ai-service/managed-native-db-availability.d.ts +1 -1
- package/dist/ai-service/managed-native-db-availability.d.ts.map +1 -1
- package/dist/ai-service/managed-native-db-availability.js +4 -2
- package/dist/ai-service/managed-native-db-availability.js.map +1 -1
- package/dist/ai-service/native-callback-order.d.ts +7 -0
- package/dist/ai-service/native-callback-order.d.ts.map +1 -0
- package/dist/ai-service/native-callback-order.js +39 -0
- package/dist/ai-service/native-callback-order.js.map +1 -0
- package/dist/ai-service/native-secret-redactor.d.ts +4 -0
- package/dist/ai-service/native-secret-redactor.d.ts.map +1 -0
- package/dist/ai-service/native-secret-redactor.js +34 -0
- package/dist/ai-service/native-secret-redactor.js.map +1 -0
- package/dist/ai-service/policy-agent-metrics.d.ts +1 -1
- package/dist/ai-service/policy-agent-metrics.d.ts.map +1 -1
- package/dist/ai-service/policy-agent-metrics.js +1 -0
- package/dist/ai-service/policy-agent-metrics.js.map +1 -1
- package/dist/ai-service/policy-gate-error.d.ts.map +1 -1
- package/dist/ai-service/policy-gate-error.js +34 -3
- package/dist/ai-service/policy-gate-error.js.map +1 -1
- package/dist/ai-service/policy-gate-remediation-usage.d.ts +2 -1
- package/dist/ai-service/policy-gate-remediation-usage.d.ts.map +1 -1
- package/dist/ai-service/policy-gate-remediation-usage.js +2 -1
- package/dist/ai-service/policy-gate-remediation-usage.js.map +1 -1
- package/dist/ai-service/policy-gate-review.d.ts +42 -0
- package/dist/ai-service/policy-gate-review.d.ts.map +1 -0
- package/dist/ai-service/policy-gate-review.js +664 -0
- package/dist/ai-service/policy-gate-review.js.map +1 -0
- package/dist/ai-service/skills/system/materialized.d.ts +3 -1
- package/dist/ai-service/skills/system/materialized.d.ts.map +1 -1
- package/dist/ai-service/skills/system/materialized.js +3 -3
- package/dist/ai-service/skills/system/materialized.js.map +1 -1
- package/dist/ai-service/skills/system/native.d.ts +7 -0
- package/dist/ai-service/skills/system/native.d.ts.map +1 -0
- package/dist/ai-service/skills/system/native.js +25 -0
- package/dist/ai-service/skills/system/native.js.map +1 -0
- package/dist/ai-service/skills/system/paths.d.ts +2 -0
- package/dist/ai-service/skills/system/paths.d.ts.map +1 -0
- package/dist/ai-service/skills/system/paths.js +2 -0
- package/dist/ai-service/skills/system/paths.js.map +1 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +31 -8
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.js +5 -4
- package/dist/ai-service/state-machine/helpers/peer.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js +2 -1
- package/dist/ai-service/state-machine/helpers/policy-gate-usage-metrics.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/stable-peer.d.ts +2 -0
- package/dist/ai-service/state-machine/helpers/stable-peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/stable-peer.js +29 -4
- package/dist/ai-service/state-machine/helpers/stable-peer.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/user-response-message.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/user-response-message.js +4 -2
- package/dist/ai-service/state-machine/helpers/user-response-message.js.map +1 -1
- package/dist/ai-service/types.d.ts +3 -0
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/ai-service/types.js.map +1 -1
- package/dist/ai-service/util/rpc-timeout.d.ts +2 -0
- package/dist/ai-service/util/rpc-timeout.d.ts.map +1 -1
- package/dist/ai-service/util/rpc-timeout.js +2 -0
- package/dist/ai-service/util/rpc-timeout.js.map +1 -1
- package/dist/ai-service/util/stop-condition.d.ts +8 -0
- package/dist/ai-service/util/stop-condition.d.ts.map +1 -1
- package/dist/ai-service/util/stop-condition.js +15 -0
- package/dist/ai-service/util/stop-condition.js.map +1 -1
- package/dist/extract-api-integrations.d.ts +52 -87
- package/dist/extract-api-integrations.d.ts.map +1 -1
- package/dist/extract-api-integrations.js +512 -473
- package/dist/extract-api-integrations.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +53 -5
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-helpers.d.ts +2 -0
- package/dist/file-system-helpers.d.ts.map +1 -1
- package/dist/file-system-helpers.js +7 -3
- package/dist/file-system-helpers.js.map +1 -1
- package/dist/git-service/credential-scope.d.ts +16 -0
- package/dist/git-service/credential-scope.d.ts.map +1 -0
- package/dist/git-service/credential-scope.js +91 -0
- package/dist/git-service/credential-scope.js.map +1 -0
- package/dist/git-service/index.d.ts +1 -0
- package/dist/git-service/index.d.ts.map +1 -1
- package/dist/git-service/index.js +11 -32
- package/dist/git-service/index.js.map +1 -1
- package/dist/git-service/managed-excludes.d.ts.map +1 -1
- package/dist/git-service/managed-excludes.js +2 -0
- package/dist/git-service/managed-excludes.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/injected-index.d.ts +1 -3
- package/dist/injected-index.d.ts.map +1 -1
- package/dist/injected-index.js +3 -8
- package/dist/injected-index.js.map +1 -1
- package/dist/lock-service/index.d.ts +3 -0
- package/dist/lock-service/index.d.ts.map +1 -1
- package/dist/lock-service/index.js +7 -0
- package/dist/lock-service/index.js.map +1 -1
- package/dist/migration/get-fullstack-template-dir.d.ts +2 -5
- package/dist/migration/get-fullstack-template-dir.d.ts.map +1 -1
- package/dist/migration/get-fullstack-template-dir.js +5 -8
- package/dist/migration/get-fullstack-template-dir.js.map +1 -1
- package/dist/migration-templates/app-fullstack/client/components/hooks/use-mobile.ts +9 -14
- package/dist/migration-templates/app-fullstack/package.json +43 -43
- package/dist/plugin-options.d.ts +1 -1
- package/dist/plugin-options.d.ts.map +1 -1
- package/dist/policy-gate-runner.d.ts +32 -7
- package/dist/policy-gate-runner.d.ts.map +1 -1
- package/dist/policy-gate-runner.js +23 -6
- package/dist/policy-gate-runner.js.map +1 -1
- package/dist/review-runner.d.ts +25 -0
- package/dist/review-runner.d.ts.map +1 -0
- package/dist/review-runner.js +196 -0
- package/dist/review-runner.js.map +1 -0
- package/dist/socket-manager.d.ts +9 -2
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +160 -19
- package/dist/socket-manager.js.map +1 -1
- package/dist/sync-service/download.d.ts +22 -0
- package/dist/sync-service/download.d.ts.map +1 -1
- package/dist/sync-service/download.js +154 -1
- package/dist/sync-service/download.js.map +1 -1
- package/dist/sync-service/draft-helpers.d.ts +23 -3
- package/dist/sync-service/draft-helpers.d.ts.map +1 -1
- package/dist/sync-service/draft-helpers.js +196 -72
- package/dist/sync-service/draft-helpers.js.map +1 -1
- package/dist/sync-service/draft-mutation.d.ts +11 -0
- package/dist/sync-service/draft-mutation.d.ts.map +1 -0
- package/dist/sync-service/draft-mutation.js +121 -0
- package/dist/sync-service/draft-mutation.js.map +1 -0
- package/dist/sync-service/draft-state-report-metrics.d.ts +3 -0
- package/dist/sync-service/draft-state-report-metrics.d.ts.map +1 -1
- package/dist/sync-service/draft-state-report-metrics.js +9 -0
- package/dist/sync-service/draft-state-report-metrics.js.map +1 -1
- package/dist/sync-service/index.d.ts +29 -1
- package/dist/sync-service/index.d.ts.map +1 -1
- package/dist/sync-service/index.js +241 -10
- package/dist/sync-service/index.js.map +1 -1
- package/dist/sync-service/list-dir.d.ts +3 -1
- package/dist/sync-service/list-dir.d.ts.map +1 -1
- package/dist/sync-service/list-dir.js +9 -2
- package/dist/sync-service/list-dir.js.map +1 -1
- package/dist/sync-service/native-draft-session.d.ts +22 -0
- package/dist/sync-service/native-draft-session.d.ts.map +1 -0
- package/dist/sync-service/native-draft-session.js +229 -0
- package/dist/sync-service/native-draft-session.js.map +1 -0
- package/dist/sync-service/safe-directory-reader.d.ts +24 -0
- package/dist/sync-service/safe-directory-reader.d.ts.map +1 -0
- package/dist/sync-service/safe-directory-reader.js +124 -0
- package/dist/sync-service/safe-directory-reader.js.map +1 -0
- package/dist/util/log-sanitizer.d.ts +4 -0
- package/dist/util/log-sanitizer.d.ts.map +1 -1
- package/dist/util/log-sanitizer.js +7 -0
- package/dist/util/log-sanitizer.js.map +1 -1
- package/package.json +57 -52
- package/dist/migration-templates/app-fullstack/.gitignore +0 -50
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { AiGenerationState, AiMode, promptCostTokensFrom, } from "@superblocksteam/library-shared/types";
|
|
4
|
+
import { getAiQuotaPaywallReasonFromMessage, } from "@superblocksteam/shared";
|
|
5
|
+
import { BuilderRuntimeError, } from "./builder-runtime.js";
|
|
6
|
+
import { BuilderSessionStore } from "./builder-session-store.js";
|
|
7
|
+
import { NativeCallbackOrder } from "./native-callback-order.js";
|
|
8
|
+
import { RequestDeduplicator } from "./request-deduplicator.js";
|
|
9
|
+
import { paywallStopAdvice } from "./state-machine/helpers/prompt-failure.js";
|
|
10
|
+
export class BuilderConversation {
|
|
11
|
+
deps;
|
|
12
|
+
requests = new RequestDeduplicator();
|
|
13
|
+
sessions;
|
|
14
|
+
turn;
|
|
15
|
+
completion = Promise.resolve();
|
|
16
|
+
snapshot = {
|
|
17
|
+
state: AiGenerationState.IDLE,
|
|
18
|
+
};
|
|
19
|
+
pendingPermission;
|
|
20
|
+
pendingQuestion;
|
|
21
|
+
constructor(deps) {
|
|
22
|
+
this.deps = deps;
|
|
23
|
+
this.sessions = deps.sessionStore ?? new BuilderSessionStore();
|
|
24
|
+
}
|
|
25
|
+
get isBusy() {
|
|
26
|
+
return this.turn !== undefined;
|
|
27
|
+
}
|
|
28
|
+
get generationId() {
|
|
29
|
+
return this.snapshot.generationId;
|
|
30
|
+
}
|
|
31
|
+
get state() {
|
|
32
|
+
return this.snapshot;
|
|
33
|
+
}
|
|
34
|
+
get activeInteractiveMessage() {
|
|
35
|
+
return this.pendingQuestion?.message;
|
|
36
|
+
}
|
|
37
|
+
hasRequest(requestId) {
|
|
38
|
+
return requestId !== undefined && this.requests.has(requestId);
|
|
39
|
+
}
|
|
40
|
+
get isAwaitingUser() {
|
|
41
|
+
return (this.snapshot.state === AiGenerationState.AWAITING_USER_INPUT ||
|
|
42
|
+
this.snapshot.state === AiGenerationState.COMPLETED);
|
|
43
|
+
}
|
|
44
|
+
async start(request) {
|
|
45
|
+
if (request.requestId && this.requests.has(request.requestId))
|
|
46
|
+
return this.generationId;
|
|
47
|
+
if (request.responseMetadata?.type === "multi_choice_response") {
|
|
48
|
+
const pending = this.pendingQuestion;
|
|
49
|
+
if (!pending ||
|
|
50
|
+
pending.message.id !== request.responseMetadata.responseToMessageId)
|
|
51
|
+
throw new Error("No matching pending native question");
|
|
52
|
+
const answers = request.responseMetadata.selectedChoiceIndices.map((index) => {
|
|
53
|
+
const choice = pending.message.choices[index];
|
|
54
|
+
if (choice === undefined)
|
|
55
|
+
throw new Error("Invalid native question answer");
|
|
56
|
+
return typeof choice === "string" ? choice : choice.text;
|
|
57
|
+
});
|
|
58
|
+
if (request.prompt.trim())
|
|
59
|
+
answers.push(request.prompt.trim());
|
|
60
|
+
if (!answers.length)
|
|
61
|
+
throw new Error("An answer is required");
|
|
62
|
+
const turn = this.turn;
|
|
63
|
+
if (!turn || turn.controller.signal.aborted)
|
|
64
|
+
throw new DOMException("Builder turn ended", "AbortError");
|
|
65
|
+
if (pending.responding)
|
|
66
|
+
throw new Error("Question response is already being applied");
|
|
67
|
+
pending.responding = true;
|
|
68
|
+
if (request.requestId)
|
|
69
|
+
this.requests.markIfNew(request.requestId);
|
|
70
|
+
await this.publish({
|
|
71
|
+
role: "user",
|
|
72
|
+
type: "multi_choice_response",
|
|
73
|
+
content: request.prompt,
|
|
74
|
+
responseToMessageId: pending.message.id,
|
|
75
|
+
selectedChoiceIndices: request.responseMetadata.selectedChoiceIndices,
|
|
76
|
+
});
|
|
77
|
+
turn.controller.signal.throwIfAborted();
|
|
78
|
+
await this.publishState(AiGenerationState.GENERATING, turn.id);
|
|
79
|
+
turn.controller.signal.throwIfAborted();
|
|
80
|
+
this.pendingQuestion = undefined;
|
|
81
|
+
pending.resolve(answers);
|
|
82
|
+
return this.generationId;
|
|
83
|
+
}
|
|
84
|
+
if (request.responseMetadata?.type === "tool_permission_response") {
|
|
85
|
+
await this.respondToPermission({
|
|
86
|
+
messageId: request.responseMetadata.responseToMessageId,
|
|
87
|
+
approved: request.responseMetadata.approved === true,
|
|
88
|
+
requestId: request.requestId,
|
|
89
|
+
});
|
|
90
|
+
return this.generationId;
|
|
91
|
+
}
|
|
92
|
+
if (this.turn)
|
|
93
|
+
throw new Error("Service is busy");
|
|
94
|
+
if (request.promptContext?.attachments?.length)
|
|
95
|
+
throw new Error("Native builder does not yet support image or file attachments");
|
|
96
|
+
if (request.requestId)
|
|
97
|
+
this.requests.markIfNew(request.requestId);
|
|
98
|
+
const turn = {
|
|
99
|
+
id: randomUUID(),
|
|
100
|
+
controller: new AbortController(),
|
|
101
|
+
completion: Promise.resolve(),
|
|
102
|
+
events: Promise.resolve(),
|
|
103
|
+
calls: new Set(),
|
|
104
|
+
results: new Set(),
|
|
105
|
+
plans: new Set(),
|
|
106
|
+
startedAt: new Date().toISOString(),
|
|
107
|
+
model: this.deps.runtime.model,
|
|
108
|
+
callbacks: new NativeCallbackOrder(),
|
|
109
|
+
};
|
|
110
|
+
this.turn = turn;
|
|
111
|
+
this.snapshot = {
|
|
112
|
+
state: AiGenerationState.GENERATING,
|
|
113
|
+
generationId: turn.id,
|
|
114
|
+
};
|
|
115
|
+
let userPublished = false;
|
|
116
|
+
try {
|
|
117
|
+
const prepared = await this.deps.prepare(request, turn.controller.signal, turn.id);
|
|
118
|
+
turn.controller.signal.throwIfAborted();
|
|
119
|
+
const provider = this.deps.runtime.providerFor(this.deps.runtime.model);
|
|
120
|
+
const scope = `${prepared.scope}:${provider}:${this.deps.runtime.model}`;
|
|
121
|
+
let session = prepared.conversationId
|
|
122
|
+
? {
|
|
123
|
+
conversationId: prepared.conversationId,
|
|
124
|
+
sessionId: prepared.nativeSessionId,
|
|
125
|
+
}
|
|
126
|
+
: await this.sessions.get(scope);
|
|
127
|
+
if (!session) {
|
|
128
|
+
session = {
|
|
129
|
+
conversationId: prepared.conversationId ?? BuilderSessionStore.identity(scope),
|
|
130
|
+
};
|
|
131
|
+
await this.sessions.set(scope, session);
|
|
132
|
+
}
|
|
133
|
+
await this.publishUser(request);
|
|
134
|
+
userPublished = true;
|
|
135
|
+
await this.publishState(AiGenerationState.GENERATING, turn.id);
|
|
136
|
+
const tools = await this.deps.tools.prepare({
|
|
137
|
+
provider,
|
|
138
|
+
request,
|
|
139
|
+
abortSignal: turn.controller.signal,
|
|
140
|
+
peer: this.deps.peer,
|
|
141
|
+
requestPermission: (permission) => this.requestPermission(permission),
|
|
142
|
+
});
|
|
143
|
+
turn.controller.signal.throwIfAborted();
|
|
144
|
+
turn.completion = this.run(turn, {
|
|
145
|
+
...tools,
|
|
146
|
+
callbackTools: this.callbackTools(turn, request),
|
|
147
|
+
mode: request.mode === AiMode.PLAN ? "plan" : "build",
|
|
148
|
+
runId: request.requestId
|
|
149
|
+
? BuilderSessionStore.identity(`${session.conversationId}:${request.requestId}`)
|
|
150
|
+
: turn.id,
|
|
151
|
+
conversationId: session.conversationId,
|
|
152
|
+
actorId: prepared.actorId,
|
|
153
|
+
inference: prepared.inference,
|
|
154
|
+
sessionId: session.sessionId,
|
|
155
|
+
model: this.deps.runtime.model,
|
|
156
|
+
prompt: request.prompt,
|
|
157
|
+
signal: turn.controller.signal,
|
|
158
|
+
onEvent: (event) => {
|
|
159
|
+
if (this.turn !== turn || turn.controller.signal.aborted)
|
|
160
|
+
return;
|
|
161
|
+
turn.events = turn.events
|
|
162
|
+
.then(async () => {
|
|
163
|
+
if (turn.controller.signal.aborted)
|
|
164
|
+
return;
|
|
165
|
+
if (event.type === "session") {
|
|
166
|
+
if (prepared.saveSession)
|
|
167
|
+
await this.persistSession(turn, prepared.saveSession(event.sessionId));
|
|
168
|
+
session.sessionId = event.sessionId;
|
|
169
|
+
await this.sessions.set(scope, session);
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
await this.event(turn, event);
|
|
173
|
+
})
|
|
174
|
+
.catch((error) => {
|
|
175
|
+
turn.controller.abort(error);
|
|
176
|
+
this.deps.onError?.(error);
|
|
177
|
+
});
|
|
178
|
+
return turn.events;
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
this.completion = turn.completion;
|
|
182
|
+
return turn.id;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
const paywallReason = error instanceof Error
|
|
186
|
+
? getAiQuotaPaywallReasonFromMessage(error.message)
|
|
187
|
+
: undefined;
|
|
188
|
+
if (paywallReason && !turn.controller.signal.aborted) {
|
|
189
|
+
if (!userPublished)
|
|
190
|
+
await this.publishUser(request);
|
|
191
|
+
await this.publish({
|
|
192
|
+
role: "assistant",
|
|
193
|
+
type: "text",
|
|
194
|
+
content: paywallStopAdvice(paywallReason),
|
|
195
|
+
});
|
|
196
|
+
await this.settle(turn, error, paywallReason);
|
|
197
|
+
return turn.id;
|
|
198
|
+
}
|
|
199
|
+
if (request.requestId)
|
|
200
|
+
this.requests.forget(request.requestId);
|
|
201
|
+
await this.settle(turn, error);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async persistSession(turn, saved) {
|
|
206
|
+
const signal = turn.controller.signal;
|
|
207
|
+
signal.throwIfAborted();
|
|
208
|
+
let onAbort = () => { };
|
|
209
|
+
let timeout;
|
|
210
|
+
const interrupted = new Promise((_, reject) => {
|
|
211
|
+
onAbort = () => reject(signal.reason);
|
|
212
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
213
|
+
timeout = setTimeout(() => reject(new Error("Native session persistence timed out")), 30_000);
|
|
214
|
+
timeout.unref();
|
|
215
|
+
});
|
|
216
|
+
try {
|
|
217
|
+
await Promise.race([saved, interrupted]);
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
signal.removeEventListener("abort", onAbort);
|
|
221
|
+
clearTimeout(timeout);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async run(turn, invocation) {
|
|
225
|
+
let failure;
|
|
226
|
+
try {
|
|
227
|
+
await this.deps.runtime.invoke(invocation);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
failure = error;
|
|
231
|
+
if (!turn.controller.signal.aborted) {
|
|
232
|
+
this.deps.onError?.(error);
|
|
233
|
+
await this.publish({
|
|
234
|
+
role: "assistant",
|
|
235
|
+
type: "error",
|
|
236
|
+
content: error instanceof BuilderRuntimeError
|
|
237
|
+
? error.message
|
|
238
|
+
: "The native builder stopped before completing this request. Its outcome may be incomplete; inspect the app before sending another prompt.",
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
try {
|
|
244
|
+
await this.deps.afterRun?.();
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
failure ??= error;
|
|
248
|
+
this.deps.onError?.(error);
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
await turn.events;
|
|
252
|
+
await this.flushText(turn);
|
|
253
|
+
await this.deps.chat.flushPendingPushes();
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
failure ??= error;
|
|
257
|
+
this.deps.onError?.(error);
|
|
258
|
+
}
|
|
259
|
+
this.clearPermission(new DOMException("Builder turn ended", "AbortError"));
|
|
260
|
+
await this.settle(turn, failure);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async cancel() {
|
|
264
|
+
const turn = this.turn;
|
|
265
|
+
if (!turn)
|
|
266
|
+
return;
|
|
267
|
+
turn.controller.abort(new DOMException("Builder turn cancelled", "AbortError"));
|
|
268
|
+
this.clearPermission(turn.controller.signal.reason);
|
|
269
|
+
await turn.completion;
|
|
270
|
+
await this.settle(turn, turn.controller.signal.reason);
|
|
271
|
+
}
|
|
272
|
+
async settle(turn, failure, paywallReason) {
|
|
273
|
+
if (turn.settled)
|
|
274
|
+
return;
|
|
275
|
+
turn.settled = true;
|
|
276
|
+
if (this.turn === turn) {
|
|
277
|
+
this.turn = undefined;
|
|
278
|
+
await this.publishState(failure || turn.controller.signal.aborted
|
|
279
|
+
? AiGenerationState.CANCELLED
|
|
280
|
+
: AiGenerationState.COMPLETED, turn.id, !!failure && !turn.controller.signal.aborted && !paywallReason, paywallReason);
|
|
281
|
+
}
|
|
282
|
+
this.deps.onSettled(turn.id, failure ?? turn.controller.signal.reason);
|
|
283
|
+
}
|
|
284
|
+
waitForCompletion() {
|
|
285
|
+
return this.completion;
|
|
286
|
+
}
|
|
287
|
+
async reset() {
|
|
288
|
+
await this.cancel();
|
|
289
|
+
await this.deps.chat.newChat();
|
|
290
|
+
await this.sessions.clear();
|
|
291
|
+
this.snapshot = { state: AiGenerationState.IDLE, chatSessionReset: true };
|
|
292
|
+
await this.push(() => this.deps.peer.call.aiSetGenerationState(this.snapshot));
|
|
293
|
+
}
|
|
294
|
+
async requestPermission(request) {
|
|
295
|
+
const turn = this.turn;
|
|
296
|
+
if (!turn || turn.controller.signal.aborted)
|
|
297
|
+
throw new DOMException("Builder turn ended", "AbortError");
|
|
298
|
+
if (this.pendingPermission)
|
|
299
|
+
throw new Error("A tool permission request is already pending");
|
|
300
|
+
const result = new Promise((resolve, reject) => {
|
|
301
|
+
this.pendingPermission = { request, resolve, reject };
|
|
302
|
+
});
|
|
303
|
+
void result.catch(() => { });
|
|
304
|
+
await this.flushText(turn);
|
|
305
|
+
await this.publishState(AiGenerationState.AWAITING_USER_INPUT, turn.id);
|
|
306
|
+
await this.deliverPermission(request);
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
async respondToPermission(response) {
|
|
310
|
+
if (response.requestId && this.requests.has(response.requestId))
|
|
311
|
+
return;
|
|
312
|
+
const pending = this.pendingPermission;
|
|
313
|
+
if (!pending || pending.request.toolCallId !== response.messageId)
|
|
314
|
+
throw new Error("No matching pending tool permission");
|
|
315
|
+
if (!this.turn || this.turn.controller.signal.aborted)
|
|
316
|
+
throw new Error("Builder turn ended");
|
|
317
|
+
const turn = this.turn;
|
|
318
|
+
if (pending.responding)
|
|
319
|
+
throw new Error("Permission response is already being applied");
|
|
320
|
+
pending.responding = true;
|
|
321
|
+
if (response.requestId)
|
|
322
|
+
this.requests.markIfNew(response.requestId);
|
|
323
|
+
await this.push(() => this.deps.peer.call.aiClearToolPermission());
|
|
324
|
+
turn.controller.signal.throwIfAborted();
|
|
325
|
+
await this.publishState(AiGenerationState.GENERATING, turn.id);
|
|
326
|
+
turn.controller.signal.throwIfAborted();
|
|
327
|
+
this.pendingPermission = undefined;
|
|
328
|
+
pending.resolve(response.approved);
|
|
329
|
+
}
|
|
330
|
+
async replay() {
|
|
331
|
+
await this.push(() => this.deps.peer.call.aiSetGenerationState(this.snapshot));
|
|
332
|
+
if (this.pendingPermission)
|
|
333
|
+
await this.deliverPermission(this.pendingPermission.request);
|
|
334
|
+
else
|
|
335
|
+
await this.push(() => this.deps.peer.call.aiClearToolPermission());
|
|
336
|
+
if (this.pendingQuestion)
|
|
337
|
+
await this.push(() => this.deps.peer.call.aiPushMessage(this.pendingQuestion.message));
|
|
338
|
+
const text = this.turn?.text;
|
|
339
|
+
if (text)
|
|
340
|
+
await this.push(() => this.deps.peer.call.aiPushMessage({
|
|
341
|
+
id: text.id,
|
|
342
|
+
role: "assistant",
|
|
343
|
+
type: "text",
|
|
344
|
+
textBlockId: text.id,
|
|
345
|
+
content: text.value,
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
async event(turn, event) {
|
|
349
|
+
switch (event.type) {
|
|
350
|
+
case "callback-ready":
|
|
351
|
+
await this.flushText(turn);
|
|
352
|
+
turn.callbacks.arrive(event.id);
|
|
353
|
+
break;
|
|
354
|
+
case "text-delta": {
|
|
355
|
+
turn.text ??= { id: randomUUID(), value: "" };
|
|
356
|
+
turn.text.value += event.text;
|
|
357
|
+
await this.push(() => this.deps.peer.call.aiPushMessage({
|
|
358
|
+
id: randomUUID(),
|
|
359
|
+
role: "assistant",
|
|
360
|
+
type: "text-delta",
|
|
361
|
+
textBlockId: turn.text.id,
|
|
362
|
+
content: event.text,
|
|
363
|
+
}));
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
case "plan":
|
|
367
|
+
if (turn.plans.has(event.id))
|
|
368
|
+
return;
|
|
369
|
+
turn.plans.add(event.id);
|
|
370
|
+
await this.flushText(turn);
|
|
371
|
+
await this.publish({
|
|
372
|
+
role: "assistant",
|
|
373
|
+
type: "plan",
|
|
374
|
+
content: event.text,
|
|
375
|
+
title: "Plan",
|
|
376
|
+
streaming: false,
|
|
377
|
+
});
|
|
378
|
+
break;
|
|
379
|
+
case "tool-call":
|
|
380
|
+
if (turn.calls.has(event.toolCallId))
|
|
381
|
+
return;
|
|
382
|
+
turn.calls.add(event.toolCallId);
|
|
383
|
+
await this.flushText(turn);
|
|
384
|
+
await this.publish({
|
|
385
|
+
role: "assistant",
|
|
386
|
+
type: "tool",
|
|
387
|
+
tool: event.toolName,
|
|
388
|
+
args: event.input,
|
|
389
|
+
toolCallId: event.toolCallId,
|
|
390
|
+
content: "",
|
|
391
|
+
id: event.toolCallId,
|
|
392
|
+
});
|
|
393
|
+
break;
|
|
394
|
+
case "tool-result":
|
|
395
|
+
if (turn.results.has(event.toolCallId))
|
|
396
|
+
return;
|
|
397
|
+
turn.results.add(event.toolCallId);
|
|
398
|
+
await this.flushText(turn);
|
|
399
|
+
await this.publish(event.isError
|
|
400
|
+
? {
|
|
401
|
+
role: "assistant",
|
|
402
|
+
type: "tool-error",
|
|
403
|
+
toolCallId: event.toolCallId,
|
|
404
|
+
toolName: event.toolName,
|
|
405
|
+
error: String(event.output),
|
|
406
|
+
content: "",
|
|
407
|
+
}
|
|
408
|
+
: {
|
|
409
|
+
role: "assistant",
|
|
410
|
+
type: "tool-result",
|
|
411
|
+
toolCallId: event.toolCallId,
|
|
412
|
+
toolName: event.toolName,
|
|
413
|
+
output: event.output,
|
|
414
|
+
content: "",
|
|
415
|
+
});
|
|
416
|
+
break;
|
|
417
|
+
case "finish":
|
|
418
|
+
if (turn.usageRecorded)
|
|
419
|
+
return;
|
|
420
|
+
turn.usageRecorded = true;
|
|
421
|
+
await this.push(() => this.deps.peer.call.aiPushTokenUsage({
|
|
422
|
+
requestId: turn.id,
|
|
423
|
+
inputTokens: event.usage.inputTokens,
|
|
424
|
+
outputTokens: event.usage.outputTokens,
|
|
425
|
+
totalTokens: event.usage.inputTokens + event.usage.outputTokens,
|
|
426
|
+
cachedInputTokens: event.usage.cacheReadTokens,
|
|
427
|
+
model: turn.model,
|
|
428
|
+
startTime: turn.startedAt,
|
|
429
|
+
endTime: new Date().toISOString(),
|
|
430
|
+
}));
|
|
431
|
+
try {
|
|
432
|
+
await this.deps.onUsage?.(turn.id, {
|
|
433
|
+
model: turn.model,
|
|
434
|
+
provider: this.deps.runtime.providerFor(turn.model),
|
|
435
|
+
...promptCostTokensFrom({
|
|
436
|
+
inputTokens: event.usage.inputTokens,
|
|
437
|
+
outputTokens: event.usage.outputTokens,
|
|
438
|
+
inputTokenDetails: {
|
|
439
|
+
cacheReadTokens: event.usage.cacheReadTokens,
|
|
440
|
+
cacheWriteTokens: event.usage.cacheWriteTokens,
|
|
441
|
+
},
|
|
442
|
+
}),
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
this.deps.onError?.(error);
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
case "session":
|
|
450
|
+
case "error":
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
async flushText(turn) {
|
|
455
|
+
const text = turn.text;
|
|
456
|
+
if (!text)
|
|
457
|
+
return;
|
|
458
|
+
turn.text = undefined;
|
|
459
|
+
await this.deps.chat.recordAssistant({
|
|
460
|
+
id: text.id,
|
|
461
|
+
role: "assistant",
|
|
462
|
+
type: "text",
|
|
463
|
+
textBlockId: text.id,
|
|
464
|
+
content: text.value,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
async publish(message) {
|
|
468
|
+
const payload = {
|
|
469
|
+
...message,
|
|
470
|
+
id: message.id ?? randomUUID(),
|
|
471
|
+
timestamp: message.timestamp ?? Date.now(),
|
|
472
|
+
};
|
|
473
|
+
await this.deps.chat.recordAssistant(payload);
|
|
474
|
+
await this.push(() => this.deps.peer.call.aiPushMessage(payload));
|
|
475
|
+
}
|
|
476
|
+
async publishUser(request) {
|
|
477
|
+
const response = request.responseMetadata;
|
|
478
|
+
const message = {
|
|
479
|
+
id: request.requestId ?? randomUUID(),
|
|
480
|
+
role: "user",
|
|
481
|
+
content: request.prompt,
|
|
482
|
+
mode: request.mode,
|
|
483
|
+
timestamp: Date.now(),
|
|
484
|
+
...(response?.type === "plan_response"
|
|
485
|
+
? {
|
|
486
|
+
type: response.type,
|
|
487
|
+
responseToMessageId: response.responseToMessageId,
|
|
488
|
+
approved: response.approved ?? true,
|
|
489
|
+
enableTesting: response.enableTesting,
|
|
490
|
+
}
|
|
491
|
+
: { type: "text" }),
|
|
492
|
+
};
|
|
493
|
+
if (response?.type === "plan_response") {
|
|
494
|
+
await this.deps.chat.recordUserResponse(request.prompt, response.type, {
|
|
495
|
+
mode: request.mode,
|
|
496
|
+
messageId: message.id,
|
|
497
|
+
responseToMessageId: response.responseToMessageId,
|
|
498
|
+
approved: response.approved ?? true,
|
|
499
|
+
enableTesting: response.enableTesting,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
await this.deps.chat.recordUser(request.prompt, {
|
|
504
|
+
mode: request.mode,
|
|
505
|
+
messageId: message.id,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
await this.push(() => this.deps.peer.call.aiPushMessage(message));
|
|
509
|
+
}
|
|
510
|
+
async publishState(state, generationId, hasError = false, paywallReason) {
|
|
511
|
+
this.snapshot = {
|
|
512
|
+
state,
|
|
513
|
+
generationId,
|
|
514
|
+
...(hasError ? { hasError: true } : {}),
|
|
515
|
+
...(paywallReason ? { paywallReason } : {}),
|
|
516
|
+
};
|
|
517
|
+
await this.push(() => this.deps.peer.call.aiSetGenerationState(this.snapshot));
|
|
518
|
+
}
|
|
519
|
+
deliverPermission(request) {
|
|
520
|
+
return this.push(() => this.deps.peer.call.aiRequestToolPermission({
|
|
521
|
+
messageId: request.toolCallId,
|
|
522
|
+
toolName: request.toolName,
|
|
523
|
+
actionName: request.actionName,
|
|
524
|
+
formattedInput: request.formattedInput,
|
|
525
|
+
rawInput: request.input,
|
|
526
|
+
permissions: request.permissions,
|
|
527
|
+
}));
|
|
528
|
+
}
|
|
529
|
+
clearPermission(error) {
|
|
530
|
+
const pending = this.pendingPermission;
|
|
531
|
+
this.pendingPermission = undefined;
|
|
532
|
+
pending?.reject(error);
|
|
533
|
+
this.pendingQuestion?.reject(error);
|
|
534
|
+
this.pendingQuestion = undefined;
|
|
535
|
+
if (pending)
|
|
536
|
+
void this.push(() => this.deps.peer.call.aiClearToolPermission());
|
|
537
|
+
}
|
|
538
|
+
callbackTools(turn, request) {
|
|
539
|
+
return {
|
|
540
|
+
__runtime_approval: {
|
|
541
|
+
inputSchema: z.object({
|
|
542
|
+
method: z.enum([
|
|
543
|
+
"item/commandExecution/requestApproval",
|
|
544
|
+
"item/fileChange/requestApproval",
|
|
545
|
+
]),
|
|
546
|
+
params: z.record(z.unknown()),
|
|
547
|
+
}),
|
|
548
|
+
execute: async ({ method, params }, options) => {
|
|
549
|
+
if (request.mode === AiMode.PLAN)
|
|
550
|
+
return { decision: "decline" };
|
|
551
|
+
const approved = await this.requestPermission({
|
|
552
|
+
toolCallId: options.toolCallId,
|
|
553
|
+
toolName: method === "item/fileChange/requestApproval"
|
|
554
|
+
? "apply_patch"
|
|
555
|
+
: typeof params.toolName === "string"
|
|
556
|
+
? params.toolName
|
|
557
|
+
: "exec_command",
|
|
558
|
+
input: params,
|
|
559
|
+
formattedInput: {
|
|
560
|
+
targets: [
|
|
561
|
+
typeof params.command === "string"
|
|
562
|
+
? params.command
|
|
563
|
+
: "Native builder action",
|
|
564
|
+
],
|
|
565
|
+
},
|
|
566
|
+
permissions: [],
|
|
567
|
+
});
|
|
568
|
+
return { decision: approved ? "accept" : "decline" };
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
__runtime_user_input: {
|
|
572
|
+
inputSchema: z.object({
|
|
573
|
+
method: z.enum(["item/tool/requestUserInput"]),
|
|
574
|
+
afterEventId: z.string().uuid().optional(),
|
|
575
|
+
params: z
|
|
576
|
+
.object({
|
|
577
|
+
questions: z
|
|
578
|
+
.array(z.object({
|
|
579
|
+
id: z.string().optional(),
|
|
580
|
+
question: z.string(),
|
|
581
|
+
header: z.string().optional(),
|
|
582
|
+
multiSelect: z.boolean().optional(),
|
|
583
|
+
options: z
|
|
584
|
+
.array(z.object({
|
|
585
|
+
label: z.string(),
|
|
586
|
+
description: z.string().optional(),
|
|
587
|
+
}))
|
|
588
|
+
.optional(),
|
|
589
|
+
}))
|
|
590
|
+
.min(1),
|
|
591
|
+
})
|
|
592
|
+
.passthrough(),
|
|
593
|
+
}),
|
|
594
|
+
execute: async ({ params, afterEventId }, options) => {
|
|
595
|
+
const signal = options.abortSignal ?? turn.controller.signal;
|
|
596
|
+
if (afterEventId) {
|
|
597
|
+
if (afterEventId !== options.toolCallId)
|
|
598
|
+
throw new Error("Native callback does not match its event");
|
|
599
|
+
await turn.callbacks.wait(afterEventId, signal);
|
|
600
|
+
}
|
|
601
|
+
const answers = {};
|
|
602
|
+
for (const [index, question] of params.questions.entries()) {
|
|
603
|
+
await turn.events;
|
|
604
|
+
signal.throwIfAborted();
|
|
605
|
+
await this.flushText(turn);
|
|
606
|
+
signal.throwIfAborted();
|
|
607
|
+
const message = {
|
|
608
|
+
role: "assistant",
|
|
609
|
+
type: "multi_choice",
|
|
610
|
+
content: question.question,
|
|
611
|
+
subtitle: question.header,
|
|
612
|
+
id: `${options.toolCallId}:${index}`,
|
|
613
|
+
choices: question.options?.map((option) => ({
|
|
614
|
+
text: option.label,
|
|
615
|
+
subText: option.description,
|
|
616
|
+
})) ?? [],
|
|
617
|
+
selectionType: question.multiSelect ? "multiple" : "single",
|
|
618
|
+
};
|
|
619
|
+
const result = new Promise((resolve, reject) => {
|
|
620
|
+
this.pendingQuestion = { message, resolve, reject };
|
|
621
|
+
});
|
|
622
|
+
void result.catch(() => { });
|
|
623
|
+
await this.publishState(AiGenerationState.AWAITING_USER_INPUT, turn.id);
|
|
624
|
+
signal.throwIfAborted();
|
|
625
|
+
await this.publish(message);
|
|
626
|
+
const values = await result;
|
|
627
|
+
answers[question.id ?? String(index)] = { answers: values };
|
|
628
|
+
}
|
|
629
|
+
return { answers };
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
async push(send) {
|
|
635
|
+
const signal = this.turn?.controller.signal;
|
|
636
|
+
const sent = Promise.resolve()
|
|
637
|
+
.then(send)
|
|
638
|
+
.catch((error) => this.deps.onError?.(error));
|
|
639
|
+
if (!signal || signal.aborted) {
|
|
640
|
+
void sent;
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
let onAbort;
|
|
644
|
+
let timeout;
|
|
645
|
+
const interrupted = new Promise((resolve) => {
|
|
646
|
+
onAbort = resolve;
|
|
647
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
648
|
+
timeout = setTimeout(resolve, 5_000);
|
|
649
|
+
timeout.unref();
|
|
650
|
+
});
|
|
651
|
+
try {
|
|
652
|
+
await Promise.race([sent, interrupted]);
|
|
653
|
+
}
|
|
654
|
+
finally {
|
|
655
|
+
signal.removeEventListener("abort", onAbort);
|
|
656
|
+
clearTimeout(timeout);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
//# sourceMappingURL=builder-conversation.js.map
|