chat-js 1.0.0-alpha.2 → 1.0.0-alpha.4
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/README.md +6 -4
- package/dist/index.js +2627 -2667
- package/package.json +10 -4
- package/templates/chat-app/.env.example +2 -8
- package/templates/chat-app/agent/agent.ts +8 -38
- package/templates/chat-app/agent/channels/eve.ts +37 -17
- package/templates/chat-app/agent/hooks/activity.ts +2 -1
- package/templates/chat-app/agent/hooks/billing.ts +11 -8
- package/templates/chat-app/agent/hooks/conversation.ts +2 -2
- package/templates/chat-app/agent/hooks/tool-selection.ts +7 -1
- package/templates/chat-app/agent/instructions/chat.ts +14 -10
- package/templates/chat-app/agent/sandbox.ts +2 -4
- package/templates/chat-app/agent/tools/installed.ts +19 -1
- package/templates/chat-app/app/(chat)/layout.tsx +10 -8
- package/templates/chat-app/app/api/agent-conversations/[id]/route.test.ts +1 -1
- package/templates/chat-app/app/api/agent-conversations/[id]/route.ts +1 -5
- package/templates/chat-app/app/api/agent-conversations/route.test.ts +31 -2
- package/templates/chat-app/app/api/agent-conversations/route.ts +10 -1
- package/templates/chat-app/app/api/agent-workspaces/[id]/route.test.ts +5 -31
- package/templates/chat-app/app/api/agent-workspaces/[id]/route.ts +2 -10
- package/templates/chat-app/app/api/eve/[...path]/route.test.ts +2 -2
- package/templates/chat-app/app/apple-icon.png +0 -0
- package/templates/chat-app/app/favicon.ico +0 -0
- package/templates/chat-app/app/icon.svg +1 -3
- package/templates/chat-app/app/opengraph-image.alt.txt +1 -0
- package/templates/chat-app/app/opengraph-image.png +0 -0
- package/templates/chat-app/chat.config.ts +0 -18
- package/templates/chat-app/chatjs/core/chat/compose.ts +35 -11
- package/templates/chat-app/chatjs/core/chat/contracts.ts +6 -0
- package/templates/chat-app/chatjs/core/installation/contracts.ts +1 -4
- package/templates/chat-app/chatjs/core/session/contracts.ts +19 -4
- package/templates/chat-app/chatjs/generated/composer-tools.ts +5 -12
- package/templates/chat-app/chatjs/generated/installed-chat-ui.ts +11 -5
- package/templates/chat-app/chatjs/generated/installed-config.ts +5 -13
- package/templates/chat-app/chatjs/generated/installed-instrumentation.ts +1 -2
- package/templates/chat-app/chatjs/generated/installed-layout.ts +1 -7
- package/templates/chat-app/chatjs/generated/installed-tools.ts +3 -3
- package/templates/chat-app/chatjs/generated/installed.ts +3 -3
- package/templates/chat-app/chatjs/generated/providers.ts +5 -11
- package/templates/chat-app/chatjs/generated/tool-availability.ts +3 -7
- package/templates/chat-app/chatjs/generated/tool-definitions.ts +3 -4
- package/templates/chat-app/chatjs/generated/tool-requirements.ts +40 -0
- package/templates/chat-app/chatjs/generated/tools.ts +7 -28
- package/templates/chat-app/chatjs/generated/ui.ts +3 -13
- package/templates/chat-app/chatjs/plugins/ai-titles/generate-title.ts +0 -2
- package/templates/chat-app/chatjs/plugins/attachment-uploads/chatjs.json +0 -1
- package/templates/chat-app/chatjs/plugins/guest-chat/session-profile.ts +2 -0
- package/templates/chat-app/chatjs/plugins/guest-chat/signed-out.tsx +70 -34
- package/templates/chat-app/chatjs/plugins/image-viewer/chatjs.json +17 -0
- package/templates/chat-app/chatjs/plugins/image-viewer/client-plugin.ts +9 -0
- package/templates/chat-app/{components → chatjs/plugins/image-viewer}/image-modal.tsx +3 -87
- package/templates/chat-app/chatjs/plugins/image-viewer/viewer-action.tsx +47 -0
- package/templates/chat-app/chatjs/plugins/mcp/composer.tsx +1 -6
- package/templates/chat-app/chatjs/plugins/projects/ui/chat-contributions.tsx +22 -2
- package/templates/chat-app/chatjs/plugins/projects/ui/sidebar-project-item.tsx +48 -33
- package/templates/chat-app/chatjs/plugins/projects/ui/sidebar-projects.tsx +41 -22
- package/templates/chat-app/chatjs/plugins/search/chat.ts +4 -0
- package/templates/chat-app/chatjs/plugins/search/search-chats.tsx +9 -3
- package/templates/chat-app/chatjs/plugins/search/search-hook.ts +5 -6
- package/templates/chat-app/chatjs/plugins/search/search-results-view.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/search/search-text.ts +21 -15
- package/templates/chat-app/chatjs/plugins/search/sidebar-item.tsx +7 -1
- package/templates/chat-app/chatjs/plugins/sharing/ui/share-button.tsx +13 -3
- package/templates/chat-app/chatjs/plugins/sharing/ui/shared-page.tsx +23 -39
- package/templates/chat-app/chatjs/plugins/sharing/ui/transcript-messages.tsx +2 -2
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/chatjs.json +18 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/client-plugin.ts +9 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/load.ts +120 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/preview.tsx +72 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/viewer-action.tsx +97 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/chatjs.json +16 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/client-plugin.ts +9 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/viewer-action.tsx +64 -0
- package/templates/chat-app/chatjs/tools/_shared/lib/define-tool-renderer.test.ts +16 -22
- package/templates/chat-app/chatjs/tools/attach-workspace-file/attach-conversation-file.ts +34 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/attach.ts +106 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/chatjs.json +19 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/import.ts +71 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/renderer.tsx +19 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/schemas.ts +51 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/tool.ts +62 -0
- package/templates/chat-app/chatjs/tools/deep-research/chatjs.json +18 -4
- package/templates/chat-app/chatjs/tools/deep-research/progress-panel.tsx +2 -31
- package/templates/chat-app/chatjs/tools/deep-research/renderer.tsx +7 -19
- package/templates/chat-app/chatjs/tools/deep-research/schemas.ts +1 -46
- package/templates/chat-app/chatjs/tools/deep-research/task.tsx +0 -41
- package/templates/chat-app/chatjs/tools/deep-research/tasks.tsx +2 -7
- package/templates/chat-app/chatjs/tools/generate-image/chatjs.json +4 -1
- package/templates/chat-app/chatjs/tools/generate-image/image-generation.ts +0 -1
- package/templates/chat-app/chatjs/tools/generate-image/renderer.tsx +39 -51
- package/templates/chat-app/chatjs/tools/generate-video/chatjs.json +4 -1
- package/templates/chat-app/chatjs/tools/generate-video/renderer.tsx +22 -11
- package/templates/chat-app/components/ai-elements/response.tsx +1 -1
- package/templates/chat-app/components/app-sidebar.tsx +26 -86
- package/templates/chat-app/components/artifact-actions.tsx +19 -0
- package/templates/chat-app/components/artifact-download-action.tsx +59 -0
- package/templates/chat-app/components/attachment-card.tsx +15 -9
- package/templates/chat-app/components/chat/chat-account.tsx +189 -0
- package/templates/chat-app/components/{controlled-chat-composer.tsx → chat/chat-composer.tsx} +6 -6
- package/templates/chat-app/components/chat/chat-conversation-screen.tsx +75 -0
- package/templates/chat-app/components/chat/chat-conversation.tsx +35 -0
- package/templates/chat-app/components/chat/chat-header.tsx +52 -0
- package/templates/chat-app/components/chat/chat-message-editor.tsx +24 -0
- package/templates/chat-app/components/chat/chat-navigation.tsx +11 -0
- package/templates/chat-app/components/chat/chat-sidebar.tsx +134 -0
- package/templates/chat-app/components/{eve/eve-messages.tsx → chat/chat-transcript.tsx} +7 -28
- package/templates/chat-app/components/chat/chat-workspace.tsx +19 -0
- package/templates/chat-app/components/chat/connected-chat-sidebar.tsx +8 -0
- package/templates/chat-app/components/chat-header-view.tsx +14 -13
- package/templates/chat-app/components/chat-slots.tsx +13 -3
- package/templates/chat-app/components/composer/active-tool.tsx +3 -1
- package/templates/chat-app/components/composer/composer-menu.tsx +4 -2
- package/templates/chat-app/components/composer/control.ts +4 -1
- package/templates/chat-app/components/composer/prompt-form.tsx +1 -1
- package/templates/chat-app/components/composer/tool-availability.tsx +8 -0
- package/templates/chat-app/components/composer/tool-controls.tsx +17 -50
- package/templates/chat-app/components/composer/tool-display.ts +3 -2
- package/templates/chat-app/components/eve/bash-output.tsx +33 -0
- package/templates/chat-app/components/eve/eve-chat-page.tsx +5 -26
- package/templates/chat-app/components/eve/eve-composer.tsx +11 -8
- package/templates/chat-app/components/eve/eve-conversation.tsx +237 -309
- package/templates/chat-app/components/eve/eve-deletion-provider.tsx +1 -1
- package/templates/chat-app/components/eve/eve-history-list.tsx +7 -3
- package/templates/chat-app/components/eve/eve-message-part.tsx +28 -22
- package/templates/chat-app/components/eve/eve-pending-input.tsx +54 -1
- package/templates/chat-app/components/eve/eve-runtime-provider.tsx +0 -5
- package/templates/chat-app/components/eve/new-conversation-view.tsx +7 -3
- package/templates/chat-app/components/file-artifact-card.tsx +37 -0
- package/templates/chat-app/components/header-actions.tsx +9 -2
- package/templates/chat-app/components/image-actions.tsx +93 -0
- package/templates/chat-app/components/internal-link.tsx +15 -2
- package/templates/chat-app/components/keyboard-shortcuts.tsx +8 -2
- package/templates/chat-app/components/part/tool-activity.tsx +1 -1
- package/templates/chat-app/components/part/tool-data.tsx +1 -1
- package/templates/chat-app/components/sidebar-user-nav.tsx +35 -198
- package/templates/chat-app/components/video-player.tsx +43 -0
- package/templates/chat-app/composer-controls.ts +0 -4
- package/templates/chat-app/docs/guest-sessions.md +1 -1
- package/templates/chat-app/instrumentation.ts +2 -6
- package/templates/chat-app/integrations/chat/models.ts +10 -0
- package/templates/chat-app/integrations/tools/catalog.ts +0 -3
- package/templates/chat-app/lib/ai/app-models.test.ts +13 -1
- package/templates/chat-app/lib/ai/app-models.ts +13 -3
- package/templates/chat-app/lib/ai/tool-context.ts +1 -14
- package/templates/chat-app/lib/ai/tool-renderer-registry.ts +10 -5
- package/templates/chat-app/lib/db/eve-current-copy.ts +13 -95
- package/templates/chat-app/lib/db/eve-deletion.ts +2 -61
- package/templates/chat-app/lib/db/eve-dispatch.ts +64 -18
- package/templates/chat-app/lib/db/eve-file-purge.ts +11 -145
- package/templates/chat-app/lib/db/eve-files.ts +11 -9
- package/templates/chat-app/lib/db/eve-orphaned-files.ts +3 -22
- package/templates/chat-app/lib/db/eve-queries.ts +32 -16
- package/templates/chat-app/lib/db/eve-workspace-deletion.ts +149 -0
- package/templates/chat-app/lib/db/migrate.ts +30 -0
- package/templates/chat-app/lib/db/migrations/0024_abandoned_toxin.sql +67 -0
- package/templates/chat-app/lib/db/migrations/0025_cloudy_thunderbolt.sql +1 -0
- package/templates/chat-app/lib/db/migrations/0026_loving_mesmero.sql +3 -0
- package/templates/chat-app/lib/db/migrations/0027_misty_stephen_strange.sql +1 -0
- package/templates/chat-app/lib/db/migrations/0028_faithful_hannibal_king.sql +12 -0
- package/templates/chat-app/lib/db/migrations/meta/0024_snapshot.json +4119 -0
- package/templates/chat-app/lib/db/migrations/meta/0025_snapshot.json +3988 -0
- package/templates/chat-app/lib/db/migrations/meta/0026_snapshot.json +3686 -0
- package/templates/chat-app/lib/db/migrations/meta/0027_snapshot.json +3596 -0
- package/templates/chat-app/lib/db/migrations/meta/0028_snapshot.json +2554 -0
- package/templates/chat-app/lib/db/migrations/meta/_journal.json +35 -0
- package/templates/chat-app/lib/db/schema.ts +1 -360
- package/templates/chat-app/lib/env-schema.ts +0 -7
- package/templates/chat-app/lib/eve/application-model.ts +56 -0
- package/templates/chat-app/lib/eve/bash-result.ts +22 -0
- package/templates/chat-app/lib/eve/branch-history.test.ts +59 -0
- package/templates/chat-app/lib/eve/branch-history.ts +19 -0
- package/templates/chat-app/lib/eve/channel-files.test.ts +14 -11
- package/templates/chat-app/lib/eve/channel-files.ts +2 -12
- package/templates/chat-app/lib/eve/completed-copy-source.test.ts +81 -17
- package/templates/chat-app/lib/eve/completed-copy-source.ts +2 -6
- package/templates/chat-app/lib/eve/connection-options.ts +7 -7
- package/templates/chat-app/lib/eve/contracts.test.ts +1 -1
- package/templates/chat-app/lib/eve/copy-seed.test.ts +17 -28
- package/templates/chat-app/lib/eve/copy-seed.ts +8 -34
- package/templates/chat-app/lib/eve/copy-transcript.test.ts +143 -47
- package/templates/chat-app/lib/eve/copy-transcript.ts +20 -101
- package/templates/chat-app/lib/eve/create-conversation-operation.test.ts +11 -31
- package/templates/chat-app/lib/eve/create-conversation-operation.ts +0 -10
- package/templates/chat-app/lib/eve/delete-local-conversation.test.ts +12 -20
- package/templates/chat-app/lib/eve/delete-local-conversation.ts +2 -8
- package/templates/chat-app/lib/eve/environment.test.ts +7 -0
- package/templates/chat-app/lib/eve/environment.ts +11 -0
- package/templates/chat-app/lib/eve/execute-conversation-creation.ts +3 -55
- package/templates/chat-app/lib/eve/gateway-auth.test.ts +2 -21
- package/templates/chat-app/lib/eve/gateway-auth.ts +7 -13
- package/templates/chat-app/lib/eve/generated-files.test.ts +1 -1
- package/templates/chat-app/lib/eve/generated-files.ts +2 -2
- package/templates/chat-app/lib/eve/installed-tools.test.ts +16 -9
- package/templates/chat-app/lib/eve/lifecycle/postgres/compatibility.ts +8 -5
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-payload-purge.ts +6 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-queue-fence.ts +2 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-queue-inventory.ts +2 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-queue-purge.ts +3 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-resource-fence.ts +2 -8
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-run-inventory.ts +1 -1
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-stream-positions.ts +9 -4
- package/templates/chat-app/lib/eve/logical-chat.test.ts +4 -3
- package/templates/chat-app/lib/eve/logical-chat.ts +8 -8
- package/templates/chat-app/lib/eve/message-delivery.test.ts +1 -1
- package/templates/chat-app/lib/eve/message-display.test.ts +5 -5
- package/templates/chat-app/lib/eve/message-display.ts +31 -1
- package/templates/chat-app/lib/eve/message-tool-selection.test.ts +2 -2
- package/templates/chat-app/lib/eve/model-accounting.test.ts +28 -45
- package/templates/chat-app/lib/eve/model-accounting.ts +8 -54
- package/templates/chat-app/lib/eve/purge-files.ts +0 -13
- package/templates/chat-app/lib/eve/purge-local-resources.ts +4 -47
- package/templates/chat-app/lib/eve/readonly-message-types.ts +8 -3
- package/templates/chat-app/lib/eve/reconcile-workspace-turn.ts +2 -37
- package/templates/chat-app/lib/eve/response-group-lineage.test.ts +3 -3
- package/templates/chat-app/lib/eve/retire-session.test.ts +25 -8
- package/templates/chat-app/lib/eve/retire-session.ts +10 -4
- package/templates/chat-app/lib/eve/selected-tools.ts +7 -18
- package/templates/chat-app/lib/eve/server.test.ts +29 -3
- package/templates/chat-app/lib/eve/session-profile.test.ts +12 -9
- package/templates/chat-app/lib/eve/session-profile.ts +7 -4
- package/templates/chat-app/lib/eve/shared-messages.test.ts +3 -4
- package/templates/chat-app/lib/eve/shared-messages.ts +5 -2
- package/templates/chat-app/lib/eve/tool-accounting.test.ts +131 -0
- package/templates/chat-app/lib/eve/tool-accounting.ts +96 -0
- package/templates/chat-app/lib/eve/tool-availability.ts +4 -1
- package/templates/chat-app/lib/eve/tool-configuration.ts +29 -0
- package/templates/chat-app/lib/eve/tool-result.ts +1 -1
- package/templates/chat-app/lib/eve/turn-tools.ts +3 -12
- package/templates/chat-app/lib/eve/usage.test.ts +54 -39
- package/templates/chat-app/lib/eve/usage.ts +9 -1
- package/templates/chat-app/lib/eve/workspace-turn-evidence.test.ts +8 -6
- package/templates/chat-app/lib/eve/workspace-turn-evidence.ts +0 -5
- package/templates/chat-app/lib/required-credentials.test.ts +2 -2
- package/templates/chat-app/lib/tool-readiness.test.ts +69 -0
- package/templates/chat-app/lib/tool-readiness.ts +43 -0
- package/templates/chat-app/logo.svg +1 -1
- package/templates/chat-app/next.config.ts +1 -5
- package/templates/chat-app/oxlint.config.ts +3 -6
- package/templates/chat-app/package.json +4 -16
- package/templates/chat-app/providers/chat-models-provider.tsx +3 -3
- package/templates/chat-app/providers/default-model-provider.tsx +4 -4
- package/templates/chat-app/providers/session-context.ts +24 -0
- package/templates/chat-app/providers/session-provider.tsx +4 -21
- package/templates/chat-app/scripts/agent-status.ts +124 -0
- package/templates/chat-app/scripts/check-env.ts +0 -10
- package/templates/chat-app/scripts/dev-supervisor.mts +3 -30
- package/templates/chat-app/scripts/eve-setup.ts +3 -0
- package/templates/chat-app/tests/helpers/eve-dynamic-context.ts +2 -0
- package/templates/chat-app/tools/platform/research-updates-schema.ts +1 -20
- package/templates/chat-app/trpc/context.tsx +8 -0
- package/templates/chat-app/trpc/react.tsx +3 -4
- package/templates/chat-app/trpc/routers/eve.router.ts +2 -74
- package/templates/chat-app/vendor/workflow-world-postgres-5.1.1.tgz +0 -0
- package/templates/electron/icon.png +0 -0
- package/templates/electron/package.json +2 -1
- package/templates/electron/src/application.test.ts +347 -0
- package/templates/electron/src/application.ts +849 -0
- package/templates/electron/src/lib/auth-cookies.ts +1 -1
- package/templates/electron/src/main.test.ts +175 -0
- package/templates/electron/src/main.ts +5 -745
- package/templates/electron/src/squirrel-startup.ts +61 -0
- package/templates/chat-app/agent/hooks/persistent-sandbox.ts +0 -14
- package/templates/chat-app/app/api/agent-conversation-copies/route.test.ts +0 -190
- package/templates/chat-app/app/api/agent-conversation-copies/route.ts +0 -105
- package/templates/chat-app/chatjs/core/documents/compose-views.ts +0 -12
- package/templates/chat-app/chatjs/core/documents/contracts.ts +0 -91
- package/templates/chat-app/chatjs/core/documents/document-definition.test.ts +0 -60
- package/templates/chat-app/chatjs/core/documents/document-definition.ts +0 -55
- package/templates/chat-app/chatjs/core/documents/ui.ts +0 -67
- package/templates/chat-app/chatjs/generated/code-executor.ts +0 -6
- package/templates/chat-app/chatjs/generated/document-run.ts +0 -12
- package/templates/chat-app/chatjs/generated/document-ui.ts +0 -7
- package/templates/chat-app/chatjs/generated/documents.ts +0 -6
- package/templates/chat-app/chatjs/plugins/langfuse/chatjs.json +0 -14
- package/templates/chat-app/chatjs/plugins/langfuse/credentials.ts +0 -22
- package/templates/chat-app/chatjs/plugins/langfuse/instrumentation.ts +0 -22
- package/templates/chat-app/chatjs/plugins/langfuse/server-plugin.ts +0 -5
- package/templates/chat-app/chatjs/plugins/vercel-analytics/chatjs.json +0 -15
- package/templates/chat-app/chatjs/plugins/vercel-analytics/client-plugin.ts +0 -9
- package/templates/chat-app/chatjs/plugins/vercel-analytics/component.tsx +0 -5
- package/templates/chat-app/chatjs/plugins/vercel-speed-insights/chatjs.json +0 -15
- package/templates/chat-app/chatjs/plugins/vercel-speed-insights/client-plugin.ts +0 -9
- package/templates/chat-app/chatjs/plugins/vercel-speed-insights/component.tsx +0 -4
- package/templates/chat-app/chatjs/providers/sandbox/adapter.ts +0 -232
- package/templates/chat-app/chatjs/providers/sandbox/options.ts +0 -13
- package/templates/chat-app/chatjs/providers/sandbox/persistent.ts +0 -258
- package/templates/chat-app/chatjs/providers/sandbox/provider.ts +0 -27
- package/templates/chat-app/chatjs/providers/sandbox/vercel-sandbox-env.ts +0 -22
- package/templates/chat-app/chatjs/tools/_shared/code-execution/code-execution-chart.tsx +0 -83
- package/templates/chat-app/chatjs/tools/_shared/code-execution/interactive-chart-impl.tsx +0 -290
- package/templates/chat-app/chatjs/tools/_shared/code-execution/interactive-charts.tsx +0 -24
- package/templates/chat-app/chatjs/tools/_shared/code-execution/javascript.ts +0 -222
- package/templates/chat-app/chatjs/tools/_shared/code-execution/python.ts +0 -381
- package/templates/chat-app/chatjs/tools/_shared/code-execution/types.ts +0 -27
- package/templates/chat-app/chatjs/tools/code-documents/assistant-actions.ts +0 -16
- package/templates/chat-app/chatjs/tools/code-documents/chatjs.json +0 -20
- package/templates/chat-app/chatjs/tools/code-documents/configuration-schema.ts +0 -7
- package/templates/chat-app/chatjs/tools/code-documents/definition.ts +0 -9
- package/templates/chat-app/chatjs/tools/code-documents/document.tsx +0 -33
- package/templates/chat-app/chatjs/tools/code-documents/editor.tsx +0 -144
- package/templates/chat-app/chatjs/tools/code-documents/guidelines.ts +0 -15
- package/templates/chat-app/chatjs/tools/code-documents/tool.ts +0 -54
- package/templates/chat-app/chatjs/tools/code-execution/chatjs.json +0 -21
- package/templates/chat-app/chatjs/tools/code-execution/python.test.ts +0 -207
- package/templates/chat-app/chatjs/tools/code-execution/renderer.test.tsx +0 -142
- package/templates/chat-app/chatjs/tools/code-execution/renderer.tsx +0 -68
- package/templates/chat-app/chatjs/tools/code-execution/schemas.ts +0 -23
- package/templates/chat-app/chatjs/tools/code-execution/tool.ts +0 -93
- package/templates/chat-app/chatjs/tools/deep-research/agent.ts +0 -18
- package/templates/chat-app/chatjs/tools/deep-research/availability.ts +0 -23
- package/templates/chat-app/chatjs/tools/deep-research/configuration-schema.ts +0 -36
- package/templates/chat-app/chatjs/tools/deep-research/configuration.ts +0 -22
- package/templates/chat-app/chatjs/tools/deep-research/prompts.ts +0 -280
- package/templates/chat-app/chatjs/tools/deep-research/search-updates.ts +0 -76
- package/templates/chat-app/chatjs/tools/deep-research/steps.ts +0 -92
- package/templates/chat-app/chatjs/tools/delete-document/availability.ts +0 -13
- package/templates/chat-app/chatjs/tools/delete-document/chatjs.json +0 -9
- package/templates/chat-app/chatjs/tools/delete-document/execute.ts +0 -78
- package/templates/chat-app/chatjs/tools/delete-document/schemas.ts +0 -18
- package/templates/chat-app/chatjs/tools/delete-document/tool.ts +0 -49
- package/templates/chat-app/chatjs/tools/get-weather/chatjs.json +0 -14
- package/templates/chat-app/chatjs/tools/get-weather/definition.ts +0 -10
- package/templates/chat-app/chatjs/tools/get-weather/renderer.test.tsx +0 -57
- package/templates/chat-app/chatjs/tools/get-weather/renderer.tsx +0 -290
- package/templates/chat-app/chatjs/tools/get-weather/schemas.ts +0 -51
- package/templates/chat-app/chatjs/tools/get-weather/tool.ts +0 -34
- package/templates/chat-app/chatjs/tools/read-document/chatjs.json +0 -8
- package/templates/chat-app/chatjs/tools/read-document/tool.ts +0 -27
- package/templates/chat-app/chatjs/tools/retrieve-url/chatjs.json +0 -11
- package/templates/chat-app/chatjs/tools/retrieve-url/renderer.tsx +0 -200
- package/templates/chat-app/chatjs/tools/retrieve-url/retrieve-url-env.ts +0 -11
- package/templates/chat-app/chatjs/tools/retrieve-url/schemas.ts +0 -24
- package/templates/chat-app/chatjs/tools/retrieve-url/tool.test.ts +0 -144
- package/templates/chat-app/chatjs/tools/retrieve-url/tool.ts +0 -169
- package/templates/chat-app/chatjs/tools/saved-code-execution/chatjs.json +0 -12
- package/templates/chat-app/chatjs/tools/saved-code-execution/document-runs.ts +0 -31
- package/templates/chat-app/chatjs/tools/saved-code-execution/document.tsx +0 -84
- package/templates/chat-app/chatjs/tools/saved-code-execution/execute.ts +0 -126
- package/templates/chat-app/chatjs/tools/saved-code-execution/renderer.tsx +0 -30
- package/templates/chat-app/chatjs/tools/saved-code-execution/result.tsx +0 -42
- package/templates/chat-app/chatjs/tools/saved-code-execution/schemas.ts +0 -82
- package/templates/chat-app/chatjs/tools/saved-code-execution/tool.ts +0 -12
- package/templates/chat-app/chatjs/tools/sheet-documents/assistant-actions.ts +0 -22
- package/templates/chat-app/chatjs/tools/sheet-documents/chatjs.json +0 -20
- package/templates/chat-app/chatjs/tools/sheet-documents/configuration-schema.ts +0 -10
- package/templates/chat-app/chatjs/tools/sheet-documents/definition.ts +0 -9
- package/templates/chat-app/chatjs/tools/sheet-documents/document.tsx +0 -41
- package/templates/chat-app/chatjs/tools/sheet-documents/editor.tsx +0 -180
- package/templates/chat-app/chatjs/tools/sheet-documents/guidelines.ts +0 -5
- package/templates/chat-app/chatjs/tools/sheet-documents/tool.ts +0 -54
- package/templates/chat-app/chatjs/tools/tavily-search/chatjs.json +0 -19
- package/templates/chat-app/chatjs/tools/tavily-search/renderer.tsx +0 -25
- package/templates/chat-app/chatjs/tools/tavily-search/schemas.ts +0 -39
- package/templates/chat-app/chatjs/tools/tavily-search/tavily-search-env.ts +0 -11
- package/templates/chat-app/chatjs/tools/tavily-search/tool.test.ts +0 -114
- package/templates/chat-app/chatjs/tools/tavily-search/tool.ts +0 -143
- package/templates/chat-app/chatjs/tools/text-documents/assistant-actions.ts +0 -12
- package/templates/chat-app/chatjs/tools/text-documents/chatjs.json +0 -20
- package/templates/chat-app/chatjs/tools/text-documents/comparison.tsx +0 -72
- package/templates/chat-app/chatjs/tools/text-documents/configuration-schema.ts +0 -7
- package/templates/chat-app/chatjs/tools/text-documents/definition.ts +0 -9
- package/templates/chat-app/chatjs/tools/text-documents/diffview.tsx +0 -214
- package/templates/chat-app/chatjs/tools/text-documents/document.tsx +0 -46
- package/templates/chat-app/chatjs/tools/text-documents/editor-config.ts +0 -53
- package/templates/chat-app/chatjs/tools/text-documents/editor.tsx +0 -139
- package/templates/chat-app/chatjs/tools/text-documents/guidelines.ts +0 -7
- package/templates/chat-app/chatjs/tools/text-documents/tool.ts +0 -54
- package/templates/chat-app/chatjs/tools/word-count/chatjs.json +0 -14
- package/templates/chat-app/chatjs/tools/word-count/definition.ts +0 -10
- package/templates/chat-app/chatjs/tools/word-count/renderer.tsx +0 -64
- package/templates/chat-app/chatjs/tools/word-count/schemas.ts +0 -13
- package/templates/chat-app/chatjs/tools/word-count/tool.ts +0 -45
- package/templates/chat-app/components/chat/chat-layout.tsx +0 -129
- package/templates/chat-app/components/chat-sidebar-view.tsx +0 -53
- package/templates/chat-app/components/document-skeleton.tsx +0 -33
- package/templates/chat-app/components/eve/eve-artifact-layout.tsx +0 -722
- package/templates/chat-app/components/eve/eve-copy-button.tsx +0 -165
- package/templates/chat-app/components/eve/eve-document-actions.tsx +0 -124
- package/templates/chat-app/components/eve/eve-document-assistant-actions.tsx +0 -157
- package/templates/chat-app/components/eve/eve-document-body.tsx +0 -29
- package/templates/chat-app/components/eve/eve-document-context.tsx +0 -12
- package/templates/chat-app/components/eve/eve-document-preview.tsx +0 -128
- package/templates/chat-app/components/eve/eve-document-tool.tsx +0 -190
- package/templates/chat-app/components/eve/eve-history.tsx +0 -25
- package/templates/chat-app/components/eve/use-document-draft.ts +0 -281
- package/templates/chat-app/components/favicon-group.tsx +0 -50
- package/templates/chat-app/components/part/document-common.tsx +0 -152
- package/templates/chat-app/components/part/web-search.tsx +0 -75
- package/templates/chat-app/components/sandbox.tsx +0 -43
- package/templates/chat-app/components/source-badge.tsx +0 -50
- package/templates/chat-app/components/sources.tsx +0 -140
- package/templates/chat-app/hooks/use-artifact.tsx +0 -180
- package/templates/chat-app/integrations/documents/definitions.ts +0 -4
- package/templates/chat-app/integrations/documents/run.ts +0 -1
- package/templates/chat-app/integrations/documents/ui.ts +0 -4
- package/templates/chat-app/integrations/providers/sandbox.ts +0 -10
- package/templates/chat-app/integrations/tools/code-executor.ts +0 -1
- package/templates/chat-app/lib/ai/telemetry.ts +0 -4
- package/templates/chat-app/lib/artifacts/artifact-kind.ts +0 -8
- package/templates/chat-app/lib/artifacts/types.ts +0 -19
- package/templates/chat-app/lib/db/eve-code-sandboxes.ts +0 -197
- package/templates/chat-app/lib/db/eve-document-retention.ts +0 -36
- package/templates/chat-app/lib/db/eve-documents.ts +0 -700
- package/templates/chat-app/lib/eve/code-executor.ts +0 -32
- package/templates/chat-app/lib/eve/code-sandbox-name.test.ts +0 -60
- package/templates/chat-app/lib/eve/code-sandbox-name.ts +0 -56
- package/templates/chat-app/lib/eve/code-sandbox-ownership.ts +0 -88
- package/templates/chat-app/lib/eve/copy-input.ts +0 -11
- package/templates/chat-app/lib/eve/create-native-copy.ts +0 -38
- package/templates/chat-app/lib/eve/document-assistant-actions.test.ts +0 -48
- package/templates/chat-app/lib/eve/document-assistant-actions.ts +0 -22
- package/templates/chat-app/lib/eve/document-kind-lifecycle.test.ts +0 -148
- package/templates/chat-app/lib/eve/document-tools.ts +0 -164
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-sandbox-coverage-proof.ts +0 -140
- package/templates/chat-app/lib/eve/persistent-sandbox-store.ts +0 -621
- package/templates/chat-app/lib/eve/persistent-sandbox.test.ts +0 -209
- package/templates/chat-app/lib/eve/persistent-sandbox.ts +0 -328
- package/templates/chat-app/lib/eve/purge-code-sandboxes.test.ts +0 -125
- package/templates/chat-app/lib/eve/purge-code-sandboxes.ts +0 -83
- package/templates/chat-app/lib/eve/request-copy.test.ts +0 -95
- package/templates/chat-app/lib/eve/request-copy.ts +0 -129
- package/templates/chat-app/lib/eve/research-progress.test.ts +0 -95
- package/templates/chat-app/lib/eve/research-progress.ts +0 -42
- package/templates/chat-app/lib/eve/sandbox-environment.test.ts +0 -49
- package/templates/chat-app/lib/eve/sandbox-environment.ts +0 -29
- package/templates/chat-app/lib/eve/save-copy-operation.ts +0 -33
- package/templates/chat-app/lib/eve/save-document.ts +0 -87
- package/templates/chat-app/lib/eve/verify-local-coverage.ts +0 -84
- package/templates/chat-app/lib/eve/workspace-attachments.ts +0 -173
- package/templates/chat-app/lib/sandbox/runtime.ts +0 -12
- package/templates/chat-app/scripts/persistent-sandbox-cleanup.ts +0 -128
- package/templates/chat-app/scripts/stop-persistent-sandboxes.ts +0 -24
- package/templates/chat-app/tests/artifacts.e2e.ts +0 -7
- package/templates/chat-app/tools/platform/documents/types.ts +0 -11
- package/templates/chat-app/tools/platform/search-presentation.ts +0 -138
- package/templates/chat-app/tools/platform/steps/multi-query-web-search.test.ts +0 -45
- package/templates/chat-app/tools/platform/steps/multi-query-web-search.ts +0 -142
- package/templates/chat-app/tools/platform/steps/search-utils.ts +0 -26
- package/templates/chat-app/vendor/workflow-world-postgres-5.0.0-beta.40.tgz +0 -0
|
@@ -1,621 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { and, eq, inArray, ne, sql } from "drizzle-orm";
|
|
3
|
-
import type { PersistentSandboxProvider } from "@chat-js/sandboxes/persistent";
|
|
4
|
-
import type { SandboxScope } from "@chat-js/sandboxes/provider";
|
|
5
|
-
import { drizzle } from "drizzle-orm/postgres-js";
|
|
6
|
-
import postgres from "postgres";
|
|
7
|
-
import { databaseConnection } from "../db/connection";
|
|
8
|
-
import { eveDeletionScope } from "../db/eve-deletion-scope";
|
|
9
|
-
import { env } from "../env";
|
|
10
|
-
import {
|
|
11
|
-
eveConversation,
|
|
12
|
-
eveWorkspace,
|
|
13
|
-
evePersistentSandbox,
|
|
14
|
-
eveSandboxSession,
|
|
15
|
-
} from "../db/schema";
|
|
16
|
-
|
|
17
|
-
// Remote operations hold their fence until settled; isolate them from app queries.
|
|
18
|
-
const connection = databaseConnection(env);
|
|
19
|
-
const db = drizzle(postgres(connection.url, { ...connection.options, max: 2 }));
|
|
20
|
-
|
|
21
|
-
interface SessionIdentity {
|
|
22
|
-
sessionId: string;
|
|
23
|
-
rootSessionId: string;
|
|
24
|
-
conversationId: string;
|
|
25
|
-
workspaceId: string;
|
|
26
|
-
ownerId: string;
|
|
27
|
-
devRunId?: string;
|
|
28
|
-
}
|
|
29
|
-
type ResolvePersistentProvider = () => {
|
|
30
|
-
scope: SandboxScope;
|
|
31
|
-
persistent: Pick<
|
|
32
|
-
PersistentSandboxProvider,
|
|
33
|
-
"stop" | "deleteAndConfirmAbsent"
|
|
34
|
-
>;
|
|
35
|
-
};
|
|
36
|
-
type Transaction = Parameters<Parameters<typeof db.transaction>[0]>[0];
|
|
37
|
-
type Resource = typeof evePersistentSandbox.$inferSelect;
|
|
38
|
-
const lock = async (
|
|
39
|
-
tx: Readonly<Pick<Transaction, "execute">>,
|
|
40
|
-
root: string
|
|
41
|
-
): Promise<void> => {
|
|
42
|
-
await tx.execute(
|
|
43
|
-
sql`select pg_advisory_xact_lock(hashtextextended(${`chatjs-workspace:${root}`}, 0))`
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
const assertScope = (resource: Resource, scope: SandboxScope): void => {
|
|
47
|
-
if (
|
|
48
|
-
resource.providerId !== scope.providerId ||
|
|
49
|
-
resource.accountId !== scope.accountId ||
|
|
50
|
-
resource.scopeId !== scope.scopeId
|
|
51
|
-
) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
"Persistent sandbox provider scope changed; reconcile before access."
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
export const assertActiveWorkspaceMembership = async (
|
|
58
|
-
tx: Transaction,
|
|
59
|
-
identity: SessionIdentity
|
|
60
|
-
): Promise<void> => {
|
|
61
|
-
const [workspace] = await tx
|
|
62
|
-
.select()
|
|
63
|
-
.from(eveWorkspace)
|
|
64
|
-
.where(
|
|
65
|
-
and(
|
|
66
|
-
eq(eveWorkspace.id, identity.workspaceId),
|
|
67
|
-
eq(eveWorkspace.ownerId, identity.ownerId)
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
|
-
const [conversation] = await tx
|
|
71
|
-
.select()
|
|
72
|
-
.from(eveConversation)
|
|
73
|
-
.where(
|
|
74
|
-
and(
|
|
75
|
-
eq(eveConversation.id, identity.conversationId),
|
|
76
|
-
eq(eveConversation.ownerId, identity.ownerId),
|
|
77
|
-
eq(eveConversation.workspaceId, identity.workspaceId)
|
|
78
|
-
)
|
|
79
|
-
);
|
|
80
|
-
if (
|
|
81
|
-
workspace?.state !== "active" ||
|
|
82
|
-
conversation === undefined ||
|
|
83
|
-
!["creating", "bound", "uncertain"].includes(conversation.state)
|
|
84
|
-
) {
|
|
85
|
-
throw new Error("Workspace membership is unavailable or retired.");
|
|
86
|
-
}
|
|
87
|
-
for (const sessionId of new Set([
|
|
88
|
-
identity.rootSessionId,
|
|
89
|
-
identity.sessionId,
|
|
90
|
-
])) {
|
|
91
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Validate root and child under the same allocation fence.
|
|
92
|
-
const rowRows = await tx
|
|
93
|
-
.select()
|
|
94
|
-
.from(eveSandboxSession)
|
|
95
|
-
.where(eq(eveSandboxSession.sessionId, sessionId));
|
|
96
|
-
const row = rowRows.at(0);
|
|
97
|
-
if (
|
|
98
|
-
!row ||
|
|
99
|
-
row.ownerId !== identity.ownerId ||
|
|
100
|
-
row.rootSessionId !== identity.rootSessionId ||
|
|
101
|
-
row.conversationId !== identity.conversationId ||
|
|
102
|
-
row.workspaceId !== identity.workspaceId ||
|
|
103
|
-
row.state !== "active"
|
|
104
|
-
) {
|
|
105
|
-
throw new Error(
|
|
106
|
-
"Persistent sandbox session is retired or ownership changed."
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
export const registerPersistentSession = async (
|
|
112
|
-
identity: SessionIdentity
|
|
113
|
-
): Promise<void> => {
|
|
114
|
-
await db.transaction(async (tx) => {
|
|
115
|
-
await lock(tx, identity.workspaceId);
|
|
116
|
-
for (const sessionId of new Set([
|
|
117
|
-
identity.rootSessionId,
|
|
118
|
-
identity.sessionId,
|
|
119
|
-
])) {
|
|
120
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Establish app ownership before resources can be allocated.
|
|
121
|
-
await tx
|
|
122
|
-
.insert(eveSandboxSession)
|
|
123
|
-
.values({ ...identity, sessionId, state: "active" })
|
|
124
|
-
.onConflictDoNothing();
|
|
125
|
-
}
|
|
126
|
-
await assertActiveWorkspaceMembership(tx, identity);
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/** Commit intent before any remote allocation; a pending record never authorizes another create. */
|
|
131
|
-
export const reservePersistentSandbox = async (
|
|
132
|
-
identity: SessionIdentity,
|
|
133
|
-
scope: SandboxScope
|
|
134
|
-
): Promise<{ name: string; create: boolean }> => {
|
|
135
|
-
const name = `chatjs-files-${createHash("sha256")
|
|
136
|
-
.update(JSON.stringify([scope, identity.ownerId, identity.workspaceId]))
|
|
137
|
-
.digest("hex")
|
|
138
|
-
.slice(0, 48)}`;
|
|
139
|
-
return await db.transaction(async (tx) => {
|
|
140
|
-
await lock(tx, identity.workspaceId);
|
|
141
|
-
for (const sessionId of new Set([
|
|
142
|
-
identity.rootSessionId,
|
|
143
|
-
identity.sessionId,
|
|
144
|
-
])) {
|
|
145
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Register root and child atomically before allocation.
|
|
146
|
-
await tx
|
|
147
|
-
.insert(eveSandboxSession)
|
|
148
|
-
.values({ ...identity, sessionId, state: "active" })
|
|
149
|
-
.onConflictDoNothing();
|
|
150
|
-
}
|
|
151
|
-
await assertActiveWorkspaceMembership(tx, identity);
|
|
152
|
-
const existingRows = await tx
|
|
153
|
-
.select()
|
|
154
|
-
.from(evePersistentSandbox)
|
|
155
|
-
.where(eq(evePersistentSandbox.name, name));
|
|
156
|
-
const existing = existingRows.at(0);
|
|
157
|
-
if (existing) {
|
|
158
|
-
assertScope(existing, scope);
|
|
159
|
-
if (existing.state !== "ready") {
|
|
160
|
-
throw new Error(
|
|
161
|
-
"Persistent sandbox allocation is unresolved or deleted; automatic recreation is forbidden."
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
return { name, create: false };
|
|
165
|
-
}
|
|
166
|
-
// A changed provider must not create an alternative allocation for this session.
|
|
167
|
-
const previous = await tx
|
|
168
|
-
.select()
|
|
169
|
-
.from(evePersistentSandbox)
|
|
170
|
-
.where(eq(evePersistentSandbox.workspaceId, identity.workspaceId));
|
|
171
|
-
if (previous.length > 0) {
|
|
172
|
-
throw new Error(
|
|
173
|
-
"Persistent sandbox provider replacement requires reconciliation."
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
await tx.insert(evePersistentSandbox).values({
|
|
177
|
-
name,
|
|
178
|
-
workspaceId: identity.workspaceId,
|
|
179
|
-
...scope,
|
|
180
|
-
state: "pending",
|
|
181
|
-
});
|
|
182
|
-
return { name, create: true };
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
/** Serialize provider access against retirement; provider calls must have bounded deadlines. */
|
|
186
|
-
export const accessPersistentSandbox = async <T>(
|
|
187
|
-
identity: SessionIdentity,
|
|
188
|
-
scope: SandboxScope,
|
|
189
|
-
name: string,
|
|
190
|
-
operation: () => Promise<T>,
|
|
191
|
-
creating = false
|
|
192
|
-
): Promise<T> =>
|
|
193
|
-
await db.transaction(async (tx) => {
|
|
194
|
-
await lock(tx, identity.workspaceId);
|
|
195
|
-
await assertActiveWorkspaceMembership(tx, identity);
|
|
196
|
-
const resourceRows = await tx
|
|
197
|
-
.select()
|
|
198
|
-
.from(evePersistentSandbox)
|
|
199
|
-
.where(eq(evePersistentSandbox.name, name));
|
|
200
|
-
const resource = resourceRows.at(0);
|
|
201
|
-
if (
|
|
202
|
-
!resource ||
|
|
203
|
-
resource.workspaceId !== identity.workspaceId ||
|
|
204
|
-
resource.state !== (creating ? "pending" : "ready")
|
|
205
|
-
) {
|
|
206
|
-
throw new Error("Persistent sandbox allocation is not available.");
|
|
207
|
-
}
|
|
208
|
-
assertScope(resource, scope);
|
|
209
|
-
if (identity.devRunId !== undefined) {
|
|
210
|
-
await tx
|
|
211
|
-
.update(eveSandboxSession)
|
|
212
|
-
.set({ devRunId: identity.devRunId })
|
|
213
|
-
.where(eq(eveSandboxSession.sessionId, identity.sessionId));
|
|
214
|
-
}
|
|
215
|
-
const result = await operation();
|
|
216
|
-
if (creating) {
|
|
217
|
-
await tx
|
|
218
|
-
.update(evePersistentSandbox)
|
|
219
|
-
.set({ state: "ready" })
|
|
220
|
-
.where(eq(evePersistentSandbox.name, name));
|
|
221
|
-
}
|
|
222
|
-
return result;
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
export const readPersistentIdentity = async (
|
|
226
|
-
sessionId: string
|
|
227
|
-
): Promise<SessionIdentity | null> => {
|
|
228
|
-
const rowRows = await db
|
|
229
|
-
.select()
|
|
230
|
-
.from(eveSandboxSession)
|
|
231
|
-
.where(eq(eveSandboxSession.sessionId, sessionId));
|
|
232
|
-
const row = rowRows.at(0);
|
|
233
|
-
return row ? { ...row, devRunId: row.devRunId ?? undefined } : null;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/** Retain a tombstone even if this session never allocated a filesystem. */
|
|
237
|
-
export const retirePersistentSession = async (
|
|
238
|
-
identity: SessionIdentity
|
|
239
|
-
): Promise<void> => {
|
|
240
|
-
await db.transaction(async (tx) => {
|
|
241
|
-
await lock(tx, identity.workspaceId);
|
|
242
|
-
const rowRows = await tx
|
|
243
|
-
.select()
|
|
244
|
-
.from(eveSandboxSession)
|
|
245
|
-
.where(eq(eveSandboxSession.sessionId, identity.sessionId));
|
|
246
|
-
const row = rowRows.at(0);
|
|
247
|
-
if (
|
|
248
|
-
row &&
|
|
249
|
-
(row.ownerId !== identity.ownerId ||
|
|
250
|
-
row.rootSessionId !== identity.rootSessionId ||
|
|
251
|
-
row.workspaceId !== identity.workspaceId ||
|
|
252
|
-
row.conversationId !== identity.conversationId)
|
|
253
|
-
) {
|
|
254
|
-
throw new Error("Persistent sandbox retirement owner mismatch.");
|
|
255
|
-
}
|
|
256
|
-
await tx
|
|
257
|
-
.insert(eveSandboxSession)
|
|
258
|
-
.values({ ...identity, state: "retired" })
|
|
259
|
-
.onConflictDoUpdate({
|
|
260
|
-
target: eveSandboxSession.sessionId,
|
|
261
|
-
set: { state: "retired" },
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
/** Explicit deletion is permitted only after all conversations were retired. */
|
|
266
|
-
export const cleanupWorkspaceIfUnused = async (
|
|
267
|
-
ownerId: string,
|
|
268
|
-
workspaceId: string,
|
|
269
|
-
resolveProvider: ResolvePersistentProvider,
|
|
270
|
-
explicit = false
|
|
271
|
-
): Promise<void> => {
|
|
272
|
-
await db.transaction(async (tx) => {
|
|
273
|
-
await lock(tx, workspaceId);
|
|
274
|
-
const [workspace] = await tx
|
|
275
|
-
.select()
|
|
276
|
-
.from(eveWorkspace)
|
|
277
|
-
.where(
|
|
278
|
-
and(eq(eveWorkspace.id, workspaceId), eq(eveWorkspace.ownerId, ownerId))
|
|
279
|
-
);
|
|
280
|
-
if (workspace === undefined) {
|
|
281
|
-
throw new Error("Workspace ownership is unavailable.");
|
|
282
|
-
}
|
|
283
|
-
if (workspace.state === "deleted") {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
const members = await tx
|
|
287
|
-
.select({ id: eveConversation.id })
|
|
288
|
-
.from(eveConversation)
|
|
289
|
-
.where(
|
|
290
|
-
and(
|
|
291
|
-
eq(eveConversation.workspaceId, workspaceId),
|
|
292
|
-
ne(eveConversation.state, "deleted"),
|
|
293
|
-
ne(eveConversation.state, "deleting")
|
|
294
|
-
)
|
|
295
|
-
)
|
|
296
|
-
.limit(1);
|
|
297
|
-
if (members.length > 0) {
|
|
298
|
-
if (explicit) {
|
|
299
|
-
throw new Error(
|
|
300
|
-
"Delete attached conversations before deleting this workspace."
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
if (workspace.activeOperationId !== null) {
|
|
306
|
-
throw new Error("Workspace turn retirement is incomplete.");
|
|
307
|
-
}
|
|
308
|
-
const writers = await tx
|
|
309
|
-
.select({ id: eveSandboxSession.sessionId })
|
|
310
|
-
.from(eveSandboxSession)
|
|
311
|
-
.where(
|
|
312
|
-
and(
|
|
313
|
-
eq(eveSandboxSession.workspaceId, workspaceId),
|
|
314
|
-
eq(eveSandboxSession.state, "active")
|
|
315
|
-
)
|
|
316
|
-
)
|
|
317
|
-
.limit(1);
|
|
318
|
-
if (writers.length > 0) {
|
|
319
|
-
throw new Error("Workspace writers must be retired before deletion.");
|
|
320
|
-
}
|
|
321
|
-
const resources = await tx
|
|
322
|
-
.select()
|
|
323
|
-
.from(evePersistentSandbox)
|
|
324
|
-
.where(eq(evePersistentSandbox.workspaceId, workspaceId));
|
|
325
|
-
await tx
|
|
326
|
-
.update(eveWorkspace)
|
|
327
|
-
.set({ state: "deleting" })
|
|
328
|
-
.where(eq(eveWorkspace.id, workspaceId));
|
|
329
|
-
for (const resource of resources) {
|
|
330
|
-
if (resource.state === "pending") {
|
|
331
|
-
throw new Error(
|
|
332
|
-
"Resolve uncertain persistent sandbox allocation before deletion."
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
if (resource.state === "deleted") {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
const provider = resolveProvider();
|
|
339
|
-
assertScope(resource, provider.scope);
|
|
340
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Confirm exact provider absence before committing workspace tombstones.
|
|
341
|
-
await provider.persistent.deleteAndConfirmAbsent(resource.name);
|
|
342
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Retain unresolved ownership if deletion fails.
|
|
343
|
-
await tx
|
|
344
|
-
.update(evePersistentSandbox)
|
|
345
|
-
.set({ state: "deleted" })
|
|
346
|
-
.where(eq(evePersistentSandbox.name, resource.name));
|
|
347
|
-
}
|
|
348
|
-
await tx
|
|
349
|
-
.update(eveWorkspace)
|
|
350
|
-
.set({ state: "deleted" })
|
|
351
|
-
.where(eq(eveWorkspace.id, workspaceId));
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
/** Includes never-dispatched members, which have no native session to trigger resource cleanup. */
|
|
356
|
-
export const cleanupRetiredEveWorkspaces = async (
|
|
357
|
-
ownerId: string,
|
|
358
|
-
routeId: string,
|
|
359
|
-
resolveProvider: ResolvePersistentProvider
|
|
360
|
-
): Promise<void> => {
|
|
361
|
-
const members = await db
|
|
362
|
-
.select({ workspaceId: eveConversation.workspaceId })
|
|
363
|
-
.from(eveConversation)
|
|
364
|
-
.where(
|
|
365
|
-
and(
|
|
366
|
-
eveDeletionScope(ownerId, routeId),
|
|
367
|
-
inArray(eveConversation.state, ["deleted", "deleting"])
|
|
368
|
-
)
|
|
369
|
-
);
|
|
370
|
-
for (const workspaceId of new Set(
|
|
371
|
-
members.map((member) => member.workspaceId)
|
|
372
|
-
)) {
|
|
373
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Each workspace cleanup checks remaining writers and confirms its own provider resources.
|
|
374
|
-
await cleanupWorkspaceIfUnused(ownerId, workspaceId, resolveProvider);
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
/** Detachment never deletes a workspace retained by another conversation. */
|
|
379
|
-
export const cleanupPersistentSession = async (
|
|
380
|
-
identity: SessionIdentity,
|
|
381
|
-
resolveProvider: ResolvePersistentProvider
|
|
382
|
-
): Promise<void> => {
|
|
383
|
-
await cleanupWorkspaceIfUnused(
|
|
384
|
-
identity.ownerId,
|
|
385
|
-
identity.workspaceId,
|
|
386
|
-
resolveProvider
|
|
387
|
-
);
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
/** Session completion is not workspace deletion, and cannot stop another conversation's active turn. */
|
|
391
|
-
export const stopPersistentWorkspace = async (
|
|
392
|
-
identity: SessionIdentity,
|
|
393
|
-
resolveProvider: ResolvePersistentProvider
|
|
394
|
-
): Promise<void> => {
|
|
395
|
-
await db.transaction(async (tx) => {
|
|
396
|
-
await lock(tx, identity.workspaceId);
|
|
397
|
-
await assertActiveWorkspaceMembership(tx, identity);
|
|
398
|
-
const [workspace] = await tx
|
|
399
|
-
.select()
|
|
400
|
-
.from(eveWorkspace)
|
|
401
|
-
.where(eq(eveWorkspace.id, identity.workspaceId));
|
|
402
|
-
if (workspace?.activeOperationId !== null) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
const resources = await tx
|
|
406
|
-
.select()
|
|
407
|
-
.from(evePersistentSandbox)
|
|
408
|
-
.where(eq(evePersistentSandbox.workspaceId, identity.workspaceId));
|
|
409
|
-
for (const resource of resources) {
|
|
410
|
-
if (resource.state !== "ready") {
|
|
411
|
-
continue;
|
|
412
|
-
}
|
|
413
|
-
const provider = resolveProvider();
|
|
414
|
-
assertScope(resource, provider.scope);
|
|
415
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Stop only exact owned allocations under the shared workspace fence.
|
|
416
|
-
await provider.persistent.stop(resource.name);
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
/** Called only after this development run's workers are terminated. Durable dispatch fences survive shutdown. */
|
|
422
|
-
export const stopDevelopmentPersistentSandboxes = async (
|
|
423
|
-
devRunId: string,
|
|
424
|
-
resolveProvider: ResolvePersistentProvider
|
|
425
|
-
): Promise<{ deferredWorkspaceIds: string[] }> => {
|
|
426
|
-
const sessions = await db
|
|
427
|
-
.select()
|
|
428
|
-
.from(eveSandboxSession)
|
|
429
|
-
.where(eq(eveSandboxSession.devRunId, devRunId));
|
|
430
|
-
const failures: unknown[] = [];
|
|
431
|
-
const deferredWorkspaceIds = new Set<string>();
|
|
432
|
-
for (const identity of sessions) {
|
|
433
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Stop one exact development owner's allocation at a time; keep failed ownership for retry.
|
|
434
|
-
await db
|
|
435
|
-
.transaction(async (tx) => {
|
|
436
|
-
await lock(tx, identity.workspaceId);
|
|
437
|
-
const currentRows = await tx
|
|
438
|
-
.select()
|
|
439
|
-
.from(eveSandboxSession)
|
|
440
|
-
.where(eq(eveSandboxSession.sessionId, identity.sessionId));
|
|
441
|
-
const current = currentRows.at(0);
|
|
442
|
-
if (current?.devRunId !== devRunId) {
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
const [workspace] = await tx
|
|
446
|
-
.select()
|
|
447
|
-
.from(eveWorkspace)
|
|
448
|
-
.where(eq(eveWorkspace.id, identity.workspaceId));
|
|
449
|
-
if (workspace?.activeOperationId !== null) {
|
|
450
|
-
// The server is already stopped, so native evidence cannot be read here.
|
|
451
|
-
// Keep the shared allocation and dispatch fence for restarted workers;
|
|
452
|
-
// neither a known-but-unreconciled send nor unknown delivery authorizes redispatch.
|
|
453
|
-
await tx
|
|
454
|
-
.update(eveSandboxSession)
|
|
455
|
-
.set({ devRunId: null })
|
|
456
|
-
.where(eq(eveSandboxSession.sessionId, identity.sessionId));
|
|
457
|
-
deferredWorkspaceIds.add(identity.workspaceId);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
const resources = await tx
|
|
461
|
-
.select()
|
|
462
|
-
.from(evePersistentSandbox)
|
|
463
|
-
.where(eq(evePersistentSandbox.workspaceId, identity.workspaceId));
|
|
464
|
-
for (const resource of resources) {
|
|
465
|
-
if (resource.state === "pending") {
|
|
466
|
-
throw new Error(
|
|
467
|
-
"Uncertain persistent allocation needs reconciliation before shutdown is confirmed."
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
if (resource.state === "deleted") {
|
|
471
|
-
continue;
|
|
472
|
-
}
|
|
473
|
-
const provider = resolveProvider();
|
|
474
|
-
assertScope(resource, provider.scope);
|
|
475
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Provider stop must finish before detaching this development lease.
|
|
476
|
-
await provider.persistent.stop(resource.name);
|
|
477
|
-
}
|
|
478
|
-
await tx
|
|
479
|
-
.update(eveSandboxSession)
|
|
480
|
-
.set({ devRunId: null })
|
|
481
|
-
.where(eq(eveSandboxSession.sessionId, identity.sessionId));
|
|
482
|
-
})
|
|
483
|
-
.catch((error: unknown) => {
|
|
484
|
-
failures.push(error);
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
if (failures.length > 0) {
|
|
488
|
-
throw new AggregateError(
|
|
489
|
-
failures,
|
|
490
|
-
`Persistent sandbox shutdown is incomplete: ${failures.map(String).join("; ")}`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
return { deferredWorkspaceIds: [...deferredWorkspaceIds].toSorted() };
|
|
494
|
-
};
|
|
495
|
-
export type { SessionIdentity };
|
|
496
|
-
|
|
497
|
-
/** Resolve only trusted native lineage or the gateway-authenticated creation reservation. */
|
|
498
|
-
export const resolvePersistentIdentity = async (input: {
|
|
499
|
-
sessionId: string;
|
|
500
|
-
rootSessionId: string;
|
|
501
|
-
ownerId?: string;
|
|
502
|
-
reservationId?: string;
|
|
503
|
-
devRunId?: string;
|
|
504
|
-
}): Promise<SessionIdentity> => {
|
|
505
|
-
const saved = await readPersistentIdentity(input.sessionId);
|
|
506
|
-
if (saved) {
|
|
507
|
-
if (
|
|
508
|
-
(input.ownerId !== undefined && saved.ownerId !== input.ownerId) ||
|
|
509
|
-
saved.rootSessionId !== input.rootSessionId
|
|
510
|
-
) {
|
|
511
|
-
throw new Error("Persistent sandbox owner or native lineage changed.");
|
|
512
|
-
}
|
|
513
|
-
return { ...saved, devRunId: input.devRunId };
|
|
514
|
-
}
|
|
515
|
-
const [conversation] = await db
|
|
516
|
-
.select()
|
|
517
|
-
.from(eveConversation)
|
|
518
|
-
.where(
|
|
519
|
-
input.reservationId === undefined
|
|
520
|
-
? eq(eveConversation.sessionId, input.rootSessionId)
|
|
521
|
-
: eq(eveConversation.id, input.reservationId)
|
|
522
|
-
);
|
|
523
|
-
if (
|
|
524
|
-
conversation === undefined ||
|
|
525
|
-
input.ownerId !== conversation.ownerId ||
|
|
526
|
-
!["creating", "bound", "uncertain", "deleting"].includes(
|
|
527
|
-
conversation.state
|
|
528
|
-
) ||
|
|
529
|
-
(conversation.sessionId !== null &&
|
|
530
|
-
conversation.sessionId !== input.rootSessionId)
|
|
531
|
-
) {
|
|
532
|
-
throw new Error(
|
|
533
|
-
"Persistent sandbox conversation ownership is unavailable."
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
...input,
|
|
538
|
-
ownerId: conversation.ownerId,
|
|
539
|
-
workspaceId: conversation.workspaceId,
|
|
540
|
-
conversationId: conversation.id,
|
|
541
|
-
};
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
/** Finalization requires retired native members; shared resources may survive only for other live conversations. */
|
|
545
|
-
export const checkDeletedWorkspaceMemberships = async (
|
|
546
|
-
ownerId: string,
|
|
547
|
-
conversationIds: readonly string[],
|
|
548
|
-
transaction?: Readonly<Pick<Transaction, "execute" | "select">>
|
|
549
|
-
): Promise<void> => {
|
|
550
|
-
const check = async (
|
|
551
|
-
tx: Readonly<Pick<Transaction, "execute" | "select">>
|
|
552
|
-
): Promise<void> => {
|
|
553
|
-
const conversations = await tx
|
|
554
|
-
.select()
|
|
555
|
-
.from(eveConversation)
|
|
556
|
-
.where(
|
|
557
|
-
and(
|
|
558
|
-
eq(eveConversation.ownerId, ownerId),
|
|
559
|
-
inArray(eveConversation.id, [...conversationIds])
|
|
560
|
-
)
|
|
561
|
-
);
|
|
562
|
-
if (
|
|
563
|
-
conversations.length !== new Set(conversationIds).size ||
|
|
564
|
-
conversations.some(
|
|
565
|
-
(member) => !["deleting", "deleted"].includes(member.state)
|
|
566
|
-
)
|
|
567
|
-
) {
|
|
568
|
-
throw new Error("Workspace membership deletion is not authorized.");
|
|
569
|
-
}
|
|
570
|
-
for (const workspaceId of [
|
|
571
|
-
...new Set(conversations.map((member) => member.workspaceId)),
|
|
572
|
-
].toSorted()) {
|
|
573
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Consistent workspace order serializes finalization with provider operations.
|
|
574
|
-
await lock(tx, workspaceId);
|
|
575
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Every retired member must be fenced before finalization.
|
|
576
|
-
const writers = await tx
|
|
577
|
-
.select({ id: eveSandboxSession.sessionId })
|
|
578
|
-
.from(eveSandboxSession)
|
|
579
|
-
.where(
|
|
580
|
-
and(
|
|
581
|
-
inArray(eveSandboxSession.conversationId, [...conversationIds]),
|
|
582
|
-
eq(eveSandboxSession.workspaceId, workspaceId),
|
|
583
|
-
eq(eveSandboxSession.state, "active")
|
|
584
|
-
)
|
|
585
|
-
)
|
|
586
|
-
.limit(1);
|
|
587
|
-
if (writers.length > 0) {
|
|
588
|
-
throw new Error("Workspace session retirement is incomplete.");
|
|
589
|
-
}
|
|
590
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Read cleanup eligibility under the same workspace lock.
|
|
591
|
-
const live = await tx
|
|
592
|
-
.select({ id: eveConversation.id })
|
|
593
|
-
.from(eveConversation)
|
|
594
|
-
.where(
|
|
595
|
-
and(
|
|
596
|
-
eq(eveConversation.workspaceId, workspaceId),
|
|
597
|
-
ne(eveConversation.state, "deleted"),
|
|
598
|
-
ne(eveConversation.state, "deleting")
|
|
599
|
-
)
|
|
600
|
-
)
|
|
601
|
-
.limit(1);
|
|
602
|
-
if (live.length > 0) {
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
// oxlint-disable-next-line eslint/no-await-in-loop -- Last-member cleanup must have committed its workspace tombstone.
|
|
606
|
-
const [workspace] = await tx
|
|
607
|
-
.select()
|
|
608
|
-
.from(eveWorkspace)
|
|
609
|
-
.where(
|
|
610
|
-
and(
|
|
611
|
-
eq(eveWorkspace.id, workspaceId),
|
|
612
|
-
eq(eveWorkspace.ownerId, ownerId)
|
|
613
|
-
)
|
|
614
|
-
);
|
|
615
|
-
if (workspace?.state !== "deleted") {
|
|
616
|
-
throw new Error("Workspace cleanup is incomplete.");
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
await (transaction ? check(transaction) : db.transaction(check));
|
|
621
|
-
};
|