chat-js 1.0.0-alpha.7 → 1.0.0-beta.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/README.md +8 -6
- package/dist/index.js +7487 -6859
- package/package.json +2 -2
- package/templates/chat-app/AGENTS.md +1 -1
- package/templates/chat-app/agent/agent.ts +0 -2
- package/templates/chat-app/agent/hooks/followup-suggestions.ts +1 -1
- package/templates/chat-app/agent/hooks/projects.ts +1 -1
- package/templates/chat-app/agent/hooks/search.ts +1 -1
- package/templates/chat-app/agent/instructions/projects.ts +1 -1
- package/templates/chat-app/agent/tools/mcp.ts +1 -1
- package/templates/chat-app/app/(auth)/device-login/page.tsx +1 -1
- package/templates/chat-app/app/(chat)/api/files/upload/route.ts +1 -1
- package/templates/chat-app/app/(chat)/chat/{[id] → [chatId]}/page.tsx +4 -4
- package/templates/chat-app/app/(chat)/project/[projectId]/chat/[chatId]/page.tsx +1 -1
- package/templates/chat-app/app/(chat)/project/[projectId]/page.tsx +1 -1
- package/templates/chat-app/app/(chat)/settings/connectors/[connectorId]/page.tsx +1 -1
- package/templates/chat-app/app/(chat)/settings/connectors/page.tsx +1 -1
- package/templates/chat-app/app/(chat)/settings/models/page.tsx +1 -1
- package/templates/chat-app/app/(chat)/share/[id]/page.tsx +1 -1
- package/templates/chat-app/app/api/agent-conversations/route.test.ts +5 -5
- package/templates/chat-app/app/api/agent-conversations/route.ts +2 -2
- package/templates/chat-app/app/api/agent-response-groups/route.test.ts +5 -5
- package/templates/chat-app/app/api/agent-response-groups/route.ts +1 -1
- package/templates/chat-app/app/api/eve/[...path]/route.test.ts +133 -4
- package/templates/chat-app/app/api/eve/[...path]/route.ts +175 -49
- package/templates/chat-app/app/api/eve-guest/route.ts +1 -1
- package/templates/chat-app/app/api/mcp/oauth/callback/route.ts +1 -1
- package/templates/chat-app/app/editor.css +0 -6
- package/templates/chat-app/app/layout.tsx +11 -18
- package/templates/chat-app/app/opengraph-image.png +0 -0
- package/templates/chat-app/chat.config.ts +0 -44
- package/templates/chat-app/chatjs/core/chat/compose.ts +4 -4
- package/templates/chat-app/chatjs/core/chat/contracts.ts +6 -6
- package/templates/chat-app/chatjs/core/gateway/runtime.ts +0 -7
- package/templates/chat-app/chatjs/core/installation/contracts.ts +0 -7
- package/templates/chat-app/chatjs/core/ui/slots.tsx +15 -5
- package/templates/chat-app/chatjs/generated/installed-auth-ui.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-auth.ts +4 -2
- package/templates/chat-app/chatjs/generated/installed-billing.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-chat-ui.ts +28 -24
- package/templates/chat-app/chatjs/generated/installed-chat.ts +12 -12
- package/templates/chat-app/chatjs/generated/installed-cleanup.ts +4 -4
- package/templates/chat-app/chatjs/generated/installed-instrumentation.ts +8 -2
- package/templates/chat-app/chatjs/generated/installed-layout.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-model-visibility.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-navigation.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-routers.ts +18 -19
- package/templates/chat-app/chatjs/generated/installed-session-profiles.ts +5 -3
- package/templates/chat-app/chatjs/generated/installed-sign-out.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-signed-out.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed-uploads.ts +2 -2
- package/templates/chat-app/chatjs/generated/installed.ts +2 -0
- package/templates/chat-app/chatjs/plugins/ai-titles/{chat.ts → chat-server.ts} +3 -1
- package/templates/chat-app/chatjs/plugins/ai-titles/generate-title.ts +7 -9
- package/templates/chat-app/chatjs/plugins/ai-titles/{chatjs.json → plugin.json} +3 -4
- package/templates/chat-app/chatjs/plugins/ai-titles/title-queries.ts +4 -4
- package/templates/chat-app/chatjs/plugins/attachment-uploads/{client-plugin.ts → chat-ui.ts} +1 -3
- package/templates/chat-app/chatjs/plugins/attachment-uploads/plugin.json +16 -0
- package/templates/chat-app/chatjs/plugins/credits/billing.ts +3 -1
- package/templates/chat-app/chatjs/plugins/credits/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/credits/{chatjs.json → plugin.json} +4 -13
- package/templates/chat-app/chatjs/plugins/credits/router.ts +4 -2
- package/templates/chat-app/chatjs/plugins/desktop/auth-form.tsx +3 -1
- package/templates/chat-app/chatjs/plugins/desktop/auth-server.ts +3 -1
- package/templates/chat-app/chatjs/plugins/desktop/{client-plugin.ts → layout-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/desktop/navigation.ts +3 -1
- package/templates/chat-app/chatjs/plugins/desktop/{chatjs.json → plugin.json} +4 -16
- package/templates/chat-app/chatjs/plugins/desktop/sign-out.ts +3 -1
- package/templates/chat-app/chatjs/plugins/feedback/chat-server.ts +13 -0
- package/templates/chat-app/chatjs/plugins/feedback/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/feedback/feedback-actions.tsx +4 -4
- package/templates/chat-app/chatjs/plugins/feedback/feedback-queries.ts +11 -11
- package/templates/chat-app/chatjs/plugins/feedback/feedback-schema.ts +2 -2
- package/templates/chat-app/chatjs/plugins/feedback/{chatjs.json → plugin.json} +5 -14
- package/templates/chat-app/chatjs/plugins/feedback/router.ts +9 -7
- package/templates/chat-app/chatjs/plugins/feedback/vote-message.ts +3 -6
- package/templates/chat-app/chatjs/plugins/followup-suggestions/{chat.ts → chat-server.ts} +3 -1
- package/templates/chat-app/chatjs/plugins/followup-suggestions/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/followup-suggestions/followup-queries.ts +2 -2
- package/templates/chat-app/chatjs/plugins/followup-suggestions/{chatjs.json → plugin.json} +5 -17
- package/templates/chat-app/chatjs/plugins/followup-suggestions/router.ts +8 -9
- package/templates/chat-app/chatjs/plugins/followup-suggestions/suggestions.tsx +2 -7
- package/templates/chat-app/chatjs/plugins/followup-suggestions/use-followups.ts +2 -2
- package/templates/chat-app/chatjs/plugins/guest-chat/cleanup.ts +1 -7
- package/templates/chat-app/chatjs/plugins/guest-chat/guest-auth.ts +1 -0
- package/templates/chat-app/chatjs/plugins/guest-chat/instrumentation.ts +6 -0
- package/templates/chat-app/chatjs/plugins/guest-chat/{chatjs.json → plugin.json} +6 -12
- package/templates/chat-app/chatjs/plugins/guest-chat/session-profile.ts +3 -1
- package/templates/chat-app/chatjs/plugins/guest-chat/signed-out.tsx +53 -24
- package/templates/chat-app/chatjs/plugins/image-viewer/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/image-viewer/plugin.json +11 -0
- package/templates/chat-app/chatjs/plugins/mcp/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/db/encrypted-text.ts +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/{chatjs.json → plugin.json} +5 -13
- package/templates/chat-app/chatjs/plugins/mcp/router.ts +4 -2
- package/templates/chat-app/chatjs/plugins/mcp/routes/connectors-page.tsx +4 -1
- package/templates/chat-app/chatjs/plugins/mcp/setup.ts +2 -2
- package/templates/chat-app/chatjs/plugins/mcp/ui/connectors-settings.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/ui/mcp-connect-dialog.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/ui/mcp-create-dialog.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/{mcp-env.ts → validate-env.ts} +2 -1
- package/templates/chat-app/chatjs/plugins/model-preferences/{client-plugin.ts → chat-ui.ts} +1 -3
- package/templates/chat-app/chatjs/plugins/model-preferences/model-row.tsx +3 -0
- package/templates/chat-app/chatjs/plugins/model-preferences/{use-model-preferences.ts → model-visibility.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/model-preferences/models-settings.tsx +1 -0
- package/templates/chat-app/chatjs/plugins/model-preferences/{chatjs.json → plugin.json} +5 -13
- package/templates/chat-app/chatjs/plugins/model-preferences/router.ts +5 -1
- package/templates/chat-app/chatjs/plugins/projects/{chat.ts → chat-server.ts} +3 -1
- package/templates/chat-app/chatjs/plugins/projects/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/projects/conversation-hook.ts +1 -1
- package/templates/chat-app/chatjs/plugins/projects/db/project-queries.ts +2 -2
- package/templates/chat-app/chatjs/plugins/projects/{chatjs.json → plugin.json} +5 -14
- package/templates/chat-app/chatjs/plugins/projects/router.ts +7 -7
- package/templates/chat-app/chatjs/plugins/projects/routes/project-page.tsx +10 -1
- package/templates/chat-app/chatjs/plugins/projects/ui/chat-contributions.tsx +3 -3
- package/templates/chat-app/chatjs/plugins/projects/ui/delete-project-dialog.tsx +0 -3
- package/templates/chat-app/chatjs/plugins/projects/ui/eve-move-project-dialog.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/projects/ui/project-icon-picker.tsx +1 -0
- package/templates/chat-app/chatjs/plugins/projects/ui/sidebar-projects.tsx +12 -11
- package/templates/chat-app/chatjs/plugins/search/{chat.ts → chat-server.ts} +8 -6
- package/templates/chat-app/chatjs/plugins/search/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/search/{chatjs.json → plugin.json} +5 -14
- package/templates/chat-app/chatjs/plugins/search/router.ts +4 -2
- package/templates/chat-app/chatjs/plugins/search/search-backfill.ts +4 -4
- package/templates/chat-app/chatjs/plugins/search/search-chats.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/search/search-hook.ts +2 -2
- package/templates/chat-app/chatjs/plugins/search/search-queries.ts +13 -13
- package/templates/chat-app/chatjs/plugins/search/search-results-view.tsx +2 -2
- package/templates/chat-app/chatjs/plugins/search/search-schema.ts +3 -3
- package/templates/chat-app/chatjs/plugins/sharing/{chat.ts → chat-server.ts} +3 -1
- package/templates/chat-app/chatjs/plugins/sharing/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/sharing/{chatjs.json → plugin.json} +5 -14
- package/templates/chat-app/chatjs/plugins/sharing/router.ts +4 -2
- package/templates/chat-app/chatjs/plugins/sharing/ui/chat-contributions.tsx +9 -11
- package/templates/chat-app/chatjs/plugins/sharing/ui/share-button.tsx +6 -6
- package/templates/chat-app/chatjs/plugins/sharing/ui/share-dialog.tsx +9 -9
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/plugin.json +12 -0
- package/templates/chat-app/chatjs/plugins/streamdown-math/chat-ui.ts +11 -0
- package/templates/chat-app/chatjs/plugins/streamdown-math/plugin.json +6 -0
- package/templates/chat-app/chatjs/plugins/streamdown-mermaid/chat-ui.ts +10 -0
- package/templates/chat-app/chatjs/plugins/streamdown-mermaid/plugin.json +6 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/{client-plugin.ts → chat-ui.ts} +1 -1
- package/templates/chat-app/chatjs/plugins/video-viewer/plugin.json +10 -0
- package/templates/chat-app/chatjs/providers/gateway.ts +49 -55
- package/templates/chat-app/chatjs/tools/attach-workspace-file/tool.ts +2 -2
- package/templates/chat-app/chatjs/tools/generate-image/tool.test.ts +3 -14
- package/templates/chat-app/components/ai-elements/response.tsx +16 -15
- package/templates/chat-app/components/auth-form-view.tsx +35 -43
- package/templates/chat-app/components/chat/chat-composer.tsx +90 -27
- package/templates/chat-app/components/chat/chat-conversation-screen.tsx +3 -3
- package/templates/chat-app/components/chat/chat-navigation.tsx +11 -1
- package/templates/chat-app/components/chat/chat-sidebar.tsx +8 -9
- package/templates/chat-app/components/chat/chat-transcript.tsx +52 -23
- package/templates/chat-app/components/chat-slots.tsx +1 -1
- package/templates/chat-app/components/composer/composer-menu.tsx +5 -4
- package/templates/chat-app/components/composer/prompt-form.tsx +7 -1
- package/templates/chat-app/components/eve/eve-chat-error.tsx +12 -2
- package/templates/chat-app/components/eve/eve-chat-header.tsx +5 -7
- package/templates/chat-app/components/eve/eve-chat-page.tsx +9 -9
- package/templates/chat-app/components/eve/eve-composer.tsx +16 -5
- package/templates/chat-app/components/eve/eve-conversation.tsx +342 -209
- package/templates/chat-app/components/eve/eve-creation-recovery.tsx +53 -3
- package/templates/chat-app/components/eve/eve-deletion-provider.tsx +10 -12
- package/templates/chat-app/components/eve/eve-history-list.tsx +4 -9
- package/templates/chat-app/components/eve/eve-logical-context.tsx +1 -0
- package/templates/chat-app/components/eve/eve-logical-navigation.tsx +3 -3
- package/templates/chat-app/components/eve/eve-message-content.tsx +252 -0
- package/templates/chat-app/components/eve/eve-message-part.tsx +13 -58
- package/templates/chat-app/components/eve/eve-pending-input.tsx +82 -5
- package/templates/chat-app/components/eve/eve-runtime-provider.tsx +74 -15
- package/templates/chat-app/components/eve/use-eve-composer-draft.ts +64 -26
- package/templates/chat-app/components/eve/use-eve-fork.ts +14 -16
- package/templates/chat-app/components/eve/use-logical-commands.ts +3 -3
- package/templates/chat-app/components/eve/use-new-eve-conversation.tsx +42 -7
- package/templates/chat-app/components/model-selection-indicator.tsx +12 -10
- package/templates/chat-app/components/model-selector-view.tsx +211 -186
- package/templates/chat-app/components/new-chat-button.tsx +1 -1
- package/templates/chat-app/components/parallel-responses/model-picker.tsx +5 -1
- package/templates/chat-app/components/parallel-responses/responses.tsx +2 -2
- package/templates/chat-app/components/settings/settings-nav.tsx +1 -1
- package/templates/chat-app/components/settings/settings-navigation-link.tsx +1 -0
- package/templates/chat-app/components/sidebar-top-row.tsx +1 -1
- package/templates/chat-app/components/ui/sidebar.tsx +1 -1
- package/templates/chat-app/components/ui/trace.tsx +1 -1
- package/templates/chat-app/hooks/use-auto-focus.ts +12 -13
- package/templates/chat-app/integrations/routers.ts +1 -1
- package/templates/chat-app/lib/ai/active-gateway.ts +0 -9
- package/templates/chat-app/lib/ai/app-models.test.ts +0 -4
- package/templates/chat-app/lib/ai/app-models.ts +11 -6
- package/templates/chat-app/lib/ai/gateways/registry.ts +4 -31
- package/templates/chat-app/lib/ai/model-catalog.ts +50 -0
- package/templates/chat-app/lib/ai/models.ts +4 -39
- package/templates/chat-app/lib/ai/providers.ts +2 -16
- package/templates/chat-app/lib/chat-after-create.test.ts +1 -1
- package/templates/chat-app/lib/chat-after-create.ts +1 -1
- package/templates/chat-app/lib/config-schema.ts +0 -96
- package/templates/chat-app/lib/db/eve-creation-failure.ts +3 -3
- package/templates/chat-app/lib/db/eve-current-copy.ts +11 -11
- package/templates/chat-app/lib/db/eve-deletion.ts +19 -19
- package/templates/chat-app/lib/db/eve-dispatch.ts +115 -18
- package/templates/chat-app/lib/db/eve-file-purge.ts +4 -4
- package/templates/chat-app/lib/db/eve-files.ts +13 -13
- package/templates/chat-app/lib/db/eve-queries.ts +28 -43
- package/templates/chat-app/lib/db/eve-response-groups.ts +30 -112
- package/templates/chat-app/lib/db/eve-subagents.ts +8 -8
- package/templates/chat-app/lib/db/eve-title.ts +2 -2
- package/templates/chat-app/lib/db/eve-workspace-deletion.ts +3 -3
- package/templates/chat-app/lib/db/eve-workspace-turns.ts +37 -5
- package/templates/chat-app/lib/db/eve-workspaces.ts +3 -3
- package/templates/chat-app/lib/db/migrations/0029_branch_identifiers.sql +23 -0
- package/templates/chat-app/lib/db/migrations/meta/0029_snapshot.json +2547 -0
- package/templates/chat-app/lib/db/migrations/meta/_journal.json +7 -0
- package/templates/chat-app/lib/db/schema.ts +19 -25
- package/templates/chat-app/lib/devtools-disabled.ts +1 -0
- package/templates/chat-app/lib/eve/completed-copy-source.test.ts +12 -2
- package/templates/chat-app/lib/eve/completed-copy-source.ts +5 -2
- package/templates/chat-app/lib/eve/contracts.test.ts +5 -5
- package/templates/chat-app/lib/eve/contracts.ts +1 -1
- package/templates/chat-app/lib/eve/conversation-scope.test.ts +2 -2
- package/templates/chat-app/lib/eve/conversation-scope.ts +4 -4
- package/templates/chat-app/lib/eve/create-conversation-operation.test.ts +1 -1
- package/templates/chat-app/lib/eve/create-response-group.test.ts +3 -3
- package/templates/chat-app/lib/eve/delete-local-conversation.ts +3 -3
- 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/logical-chat.test.ts +17 -17
- package/templates/chat-app/lib/eve/logical-chat.ts +27 -31
- package/templates/chat-app/lib/eve/logical-response-slots.ts +4 -7
- package/templates/chat-app/lib/eve/message-delivery.ts +1 -0
- package/templates/chat-app/lib/eve/model-selection.test.ts +47 -50
- package/templates/chat-app/lib/eve/model-selection.ts +5 -37
- package/templates/chat-app/lib/eve/pending-create.test.ts +46 -7
- package/templates/chat-app/lib/eve/pending-create.ts +36 -4
- package/templates/chat-app/lib/eve/persisted-wire-order.test.ts +2 -2
- package/templates/chat-app/lib/eve/prepare-deletion.ts +3 -3
- package/templates/chat-app/lib/eve/purge-local-resources.ts +3 -3
- package/templates/chat-app/lib/eve/reconcile-workspace-turn.ts +2 -2
- package/templates/chat-app/lib/eve/request-policy.ts +1 -0
- package/templates/chat-app/lib/eve/resolve-creation-request.ts +1 -1
- package/templates/chat-app/lib/eve/response-group-contracts.ts +1 -1
- package/templates/chat-app/lib/eve/response-group-lineage.test.ts +12 -12
- package/templates/chat-app/lib/eve/response-group-lineage.ts +21 -24
- package/templates/chat-app/lib/eve/response-group.test.ts +2 -2
- package/templates/chat-app/lib/eve/response-group.ts +1 -1
- package/templates/chat-app/lib/eve/response-model.ts +11 -1
- package/templates/chat-app/lib/eve/restore-message-attachments.test.ts +1 -1
- package/templates/chat-app/lib/eve/restore-message-attachments.ts +3 -3
- package/templates/chat-app/lib/eve/retire-session.ts +3 -3
- package/templates/chat-app/lib/eve/steer-rejected.ts +7 -0
- package/templates/chat-app/lib/eve/tool-cost.test.ts +18 -6
- package/templates/chat-app/lib/eve/tool-cost.ts +10 -18
- package/templates/chat-app/lib/eve/workspace-turn-evidence.test.ts +27 -0
- package/templates/chat-app/lib/eve/workspace-turn-evidence.ts +20 -13
- package/templates/chat-app/oxfmt.config.ts +0 -2
- package/templates/chat-app/package.json +7 -9
- package/templates/chat-app/playwright.config.ts +5 -1
- package/templates/chat-app/proxy.ts +2 -4
- package/templates/chat-app/scripts/agent-status.ts +6 -19
- package/templates/chat-app/scripts/build-eve.test.ts +56 -0
- package/templates/chat-app/scripts/build-eve.ts +12 -5
- package/templates/chat-app/scripts/check-env.ts +77 -73
- package/templates/chat-app/scripts/environment-validation-report.ts +1 -20
- package/templates/chat-app/scripts/installed-environment-validation.ts +14 -15
- package/templates/chat-app/trpc/init.ts +2 -0
- package/templates/chat-app/trpc/react.tsx +2 -2
- package/templates/chat-app/trpc/routers/_app.test.ts +56 -0
- package/templates/chat-app/trpc/routers/_app.ts +12 -11
- package/templates/chat-app/trpc/routers/eve.router.ts +2 -2
- package/templates/electron/forge.config.ts +1 -19
- package/templates/electron/scripts/write-branding.ts +1 -5
- package/templates/chat-app/app/privacy/page.tsx +0 -153
- package/templates/chat-app/app/terms/page.tsx +0 -270
- package/templates/chat-app/chatjs/core/installation/plugin.ts +0 -13
- package/templates/chat-app/chatjs/plugins/attachment-uploads/chatjs.json +0 -22
- package/templates/chat-app/chatjs/plugins/credits/server-plugin.ts +0 -5
- package/templates/chat-app/chatjs/plugins/feedback/chat.ts +0 -13
- package/templates/chat-app/chatjs/plugins/feedback/server-plugin.ts +0 -8
- package/templates/chat-app/chatjs/plugins/followup-suggestions/server-plugin.ts +0 -8
- package/templates/chat-app/chatjs/plugins/guest-chat/server-plugin.ts +0 -12
- package/templates/chat-app/chatjs/plugins/image-viewer/chatjs.json +0 -17
- package/templates/chat-app/chatjs/plugins/mcp/server-plugin.ts +0 -5
- package/templates/chat-app/chatjs/plugins/model-preferences/server-plugin.ts +0 -8
- package/templates/chat-app/chatjs/plugins/projects/server-plugin.ts +0 -8
- package/templates/chat-app/chatjs/plugins/search/server-plugin.ts +0 -5
- package/templates/chat-app/chatjs/plugins/sharing/server-plugin.ts +0 -5
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/chatjs.json +0 -18
- package/templates/chat-app/chatjs/plugins/video-viewer/chatjs.json +0 -16
- package/templates/chat-app/components/ai-elements/context-hover.radix.tsx +0 -15
- package/templates/chat-app/components/ai-elements/context-hover.tsx +0 -17
- package/templates/chat-app/components/ai-elements/context.tsx +0 -405
- package/templates/chat-app/components/composer/editor.css +0 -96
- package/templates/chat-app/components/lexical-chat-input.tsx +0 -276
- package/templates/chat-app/components/model-selection-indicator.radix.tsx +0 -17
- package/templates/chat-app/components/ui/resizable.tsx +0 -49
- package/templates/chat-app/lib/ai/gateways/fallback-models.ts +0 -29
- package/templates/chat-app/lib/ai/models.generated.ts +0 -4242
- package/templates/chat-app/lib/ai/usage-token-details.test.ts +0 -76
- package/templates/chat-app/lib/ai/usage-token-details.ts +0 -33
- package/templates/chat-app/lib/chat-route.ts +0 -18
- package/templates/chat-app/providers/parse-chat-id-from-pathname.test.ts +0 -126
- package/templates/chat-app/providers/parse-chat-id-from-pathname.ts +0 -51
- package/templates/chat-app/scripts/fetch-models.ts +0 -30
- package/templates/chat-app/scripts/gateway-snapshot-warning.test.ts +0 -9
- /package/templates/chat-app/chatjs/plugins/attachment-uploads/{integration.tsx → uploads.ts} +0 -0
|
@@ -20,16 +20,16 @@ type DeletionTransaction = Readonly<
|
|
|
20
20
|
>;
|
|
21
21
|
/** Select the requested root or joined member while retaining the owner filter.
|
|
22
22
|
* @param {string} ownerId - Owner required for either identity alternative.
|
|
23
|
-
* @param {string}
|
|
23
|
+
* @param {string} branchId - Root chat ID or joined member conversation ID.
|
|
24
24
|
* @returns {ReturnType<typeof and>} Native Drizzle owner-and-identity predicate, with the root alternative evaluated before the member alternative.
|
|
25
25
|
*/
|
|
26
26
|
const ownerVisibleEveIdentityCondition = (
|
|
27
27
|
ownerId: string,
|
|
28
|
-
|
|
28
|
+
branchId: string
|
|
29
29
|
): ReturnType<typeof and> =>
|
|
30
30
|
and(
|
|
31
31
|
eq(eveChat.ownerId, ownerId),
|
|
32
|
-
or(eq(eveChat.id,
|
|
32
|
+
or(eq(eveChat.id, branchId), eq(eveConversation.id, branchId))
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
/** Require an identity before looking up or mutating its conversation family.
|
|
@@ -94,13 +94,13 @@ const readOwnedEveDeletionIdentity = (
|
|
|
94
94
|
/** Read the first owner-visible identity and joined member state for a deletion receipt.
|
|
95
95
|
* @param {Readonly<Pick<typeof db, "select">>} query - Existing select capability, forwarded without cloning or rebinding.
|
|
96
96
|
* @param {string} ownerId - Owner required by the joined identity predicate.
|
|
97
|
-
* @param {string}
|
|
97
|
+
* @param {string} branchId - Root chat ID or joined member conversation ID.
|
|
98
98
|
* @returns {QueryPromise<readonly ({ readonly chatId: typeof eveChat.$inferSelect.id; readonly state: typeof eveConversation.$inferSelect.state | null } | undefined)[]>} Original native query object; an empty result has no first row.
|
|
99
99
|
*/
|
|
100
100
|
const readOwnedEveDeletionReceipt = (
|
|
101
101
|
query: Readonly<Pick<typeof db, "select">>,
|
|
102
102
|
ownerId: string,
|
|
103
|
-
|
|
103
|
+
branchId: string
|
|
104
104
|
): QueryPromise<
|
|
105
105
|
readonly (
|
|
106
106
|
| {
|
|
@@ -121,10 +121,10 @@ const readOwnedEveDeletionReceipt = (
|
|
|
121
121
|
and(
|
|
122
122
|
eq(eveConversation.chatId, eveChat.id),
|
|
123
123
|
eq(eveConversation.ownerId, eveChat.ownerId),
|
|
124
|
-
eq(eveConversation.id,
|
|
124
|
+
eq(eveConversation.id, branchId)
|
|
125
125
|
)
|
|
126
126
|
)
|
|
127
|
-
.where(ownerVisibleEveIdentityCondition(ownerId,
|
|
127
|
+
.where(ownerVisibleEveIdentityCondition(ownerId, branchId))
|
|
128
128
|
.limit(SINGLE_MATCH_LIMIT);
|
|
129
129
|
|
|
130
130
|
/** Read the owner-visible member state when a root receipt has no joined member state.
|
|
@@ -199,9 +199,9 @@ const completeEveConversationDeletion = async (
|
|
|
199
199
|
...contentTables.map((table) =>
|
|
200
200
|
exists(
|
|
201
201
|
tx
|
|
202
|
-
.select({
|
|
202
|
+
.select({ branchId: table.branchId })
|
|
203
203
|
.from(table)
|
|
204
|
-
.where(eq(table.
|
|
204
|
+
.where(eq(table.branchId, eveConversation.id))
|
|
205
205
|
)
|
|
206
206
|
)
|
|
207
207
|
)
|
|
@@ -213,9 +213,9 @@ const completeEveConversationDeletion = async (
|
|
|
213
213
|
}
|
|
214
214
|
await tx
|
|
215
215
|
.delete(eveSubagentSession)
|
|
216
|
-
.where(inArray(eveSubagentSession.
|
|
216
|
+
.where(inArray(eveSubagentSession.branchId, ids));
|
|
217
217
|
await chat.onDeleteConversations(tx, {
|
|
218
|
-
|
|
218
|
+
branchIds: ids,
|
|
219
219
|
sessionIds: family.flatMap((row) =>
|
|
220
220
|
row.sessionId === null ? [] : [row.sessionId]
|
|
221
221
|
),
|
|
@@ -248,12 +248,12 @@ const completeEveConversationDeletion = async (
|
|
|
248
248
|
if (survivor) {
|
|
249
249
|
await tx
|
|
250
250
|
.update(eveChat)
|
|
251
|
-
.set({
|
|
251
|
+
.set({ activeBranchId: survivor.id })
|
|
252
252
|
.where(
|
|
253
253
|
and(
|
|
254
254
|
eq(eveChat.id, identity.chatId),
|
|
255
255
|
eq(eveChat.ownerId, ownerId),
|
|
256
|
-
inArray(eveChat.
|
|
256
|
+
inArray(eveChat.activeBranchId, ids)
|
|
257
257
|
)
|
|
258
258
|
);
|
|
259
259
|
} else {
|
|
@@ -261,7 +261,7 @@ const completeEveConversationDeletion = async (
|
|
|
261
261
|
await tx
|
|
262
262
|
.update(eveChat)
|
|
263
263
|
.set({
|
|
264
|
-
|
|
264
|
+
activeBranchId: null,
|
|
265
265
|
isPinned: false,
|
|
266
266
|
title: "",
|
|
267
267
|
titleStatus: "fallback",
|
|
@@ -279,19 +279,19 @@ interface EveDeletionState {
|
|
|
279
279
|
|
|
280
280
|
/** Read the owner-visible root and native deletion state, including identity tombstones.
|
|
281
281
|
* @param {string} ownerId - Owner required by both identity and member queries.
|
|
282
|
-
* @param {string}
|
|
282
|
+
* @param {string} branchId - Root chat ID or member conversation ID to inspect.
|
|
283
283
|
* @returns {Promise<EveDeletionState | null>} Root identity and state, or no receipt when the owner has no matching identity or member.
|
|
284
284
|
*/
|
|
285
285
|
const getEveDeletionState = async (
|
|
286
286
|
ownerId: string,
|
|
287
|
-
|
|
287
|
+
branchId: string
|
|
288
288
|
): Promise<EveDeletionState | null> => {
|
|
289
|
-
const [row] = await readOwnedEveDeletionReceipt(db, ownerId,
|
|
289
|
+
const [row] = await readOwnedEveDeletionReceipt(db, ownerId, branchId);
|
|
290
290
|
if (!row) {
|
|
291
291
|
return null;
|
|
292
292
|
}
|
|
293
293
|
if (row.state) {
|
|
294
|
-
return { rootId:
|
|
294
|
+
return { rootId: branchId, state: row.state };
|
|
295
295
|
}
|
|
296
296
|
const members = await readOwnedEveDeletionMemberState(db, ownerId, row);
|
|
297
297
|
const states = members.flatMap((member) => (member ? [member.state] : []));
|
|
@@ -303,6 +303,6 @@ const getEveDeletionState = async (
|
|
|
303
303
|
);
|
|
304
304
|
const state =
|
|
305
305
|
active ?? (states.includes("deleting") ? "deleting" : "deleted");
|
|
306
|
-
return { rootId:
|
|
306
|
+
return { rootId: branchId, state };
|
|
307
307
|
};
|
|
308
308
|
export { completeEveConversationDeletion, getEveDeletionState };
|
|
@@ -3,13 +3,19 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
3
3
|
import { and, eq, inArray, isNull, sql } from "drizzle-orm";
|
|
4
4
|
import { db } from "./client";
|
|
5
5
|
import { eveConversation, eveDispatch, eveWorkspace } from "./schema";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
EveWorkspaceBusyError,
|
|
8
|
+
hasUnresolvedWorkspaceSteer,
|
|
9
|
+
lockEveWorkspace,
|
|
10
|
+
} from "./eve-workspace-turns";
|
|
11
|
+
import type { WorkspaceTransaction } from "./eve-workspace-turns";
|
|
7
12
|
import { reconcileEveWorkspaceTurn } from "../eve/reconcile-workspace-turn";
|
|
8
13
|
import { z } from "zod";
|
|
9
14
|
import { frontendToolsSchema } from "@/lib/ai/types";
|
|
10
15
|
import { parseEveCopySeed } from "@/lib/eve/copy-seed";
|
|
11
16
|
import { eveMessageTool } from "@/lib/eve/message-tool-selection";
|
|
12
17
|
import type { EveMessageDisplayReceipt } from "@/lib/eve/message-display";
|
|
18
|
+
import { EveSteerRejectedError } from "@/lib/eve/steer-rejected";
|
|
13
19
|
|
|
14
20
|
const hasRow: (row: unknown) => boolean = Boolean;
|
|
15
21
|
|
|
@@ -29,7 +35,7 @@ export const getEveMessageDisplayReceipts = async (
|
|
|
29
35
|
.innerJoin(
|
|
30
36
|
eveConversation,
|
|
31
37
|
and(
|
|
32
|
-
eq(eveDispatch.
|
|
38
|
+
eq(eveDispatch.branchId, eveConversation.id),
|
|
33
39
|
eq(eveDispatch.ownerId, eveConversation.ownerId)
|
|
34
40
|
)
|
|
35
41
|
)
|
|
@@ -91,7 +97,7 @@ export class EveDispatchUnknownError extends Error {
|
|
|
91
97
|
const readEveDispatch = async (input: {
|
|
92
98
|
readonly ownerId: string;
|
|
93
99
|
readonly operationId: string;
|
|
94
|
-
readonly
|
|
100
|
+
readonly branchId: string;
|
|
95
101
|
readonly kind: "create" | "copy" | "send";
|
|
96
102
|
readonly intent: unknown;
|
|
97
103
|
}): Promise<{ sessionId: string; deliveryId?: string } | undefined> => {
|
|
@@ -110,7 +116,7 @@ const readEveDispatch = async (input: {
|
|
|
110
116
|
// oxlint-disable-next-line unicorn/prefer-structured-clone -- Match JSON persistence semantics, including omission of undefined object fields.
|
|
111
117
|
const intent: unknown = JSON.parse(JSON.stringify(input.intent));
|
|
112
118
|
if (
|
|
113
|
-
existing.
|
|
119
|
+
existing.branchId !== input.branchId ||
|
|
114
120
|
existing.kind !== input.kind ||
|
|
115
121
|
!isDeepStrictEqual(existing.intent, intent)
|
|
116
122
|
) {
|
|
@@ -132,14 +138,43 @@ interface DispatchBinding {
|
|
|
132
138
|
deliveryId?: string;
|
|
133
139
|
}
|
|
134
140
|
|
|
141
|
+
const canSteerActiveDispatch = async (
|
|
142
|
+
tx: Pick<WorkspaceTransaction, "select">,
|
|
143
|
+
activeOperationId: string,
|
|
144
|
+
input: {
|
|
145
|
+
readonly ownerId: string;
|
|
146
|
+
readonly branchId: string;
|
|
147
|
+
readonly kind: "create" | "copy" | "send";
|
|
148
|
+
readonly steerSessionId?: string;
|
|
149
|
+
}
|
|
150
|
+
): Promise<boolean> => {
|
|
151
|
+
if (input.kind !== "send" || !isNonEmptyString(input.steerSessionId)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const [active] = await tx
|
|
155
|
+
.select({ deliveryId: eveDispatch.deliveryId })
|
|
156
|
+
.from(eveDispatch)
|
|
157
|
+
.where(
|
|
158
|
+
and(
|
|
159
|
+
eq(eveDispatch.ownerId, input.ownerId),
|
|
160
|
+
eq(eveDispatch.operationId, activeOperationId),
|
|
161
|
+
eq(eveDispatch.branchId, input.branchId),
|
|
162
|
+
eq(eveDispatch.sessionId, input.steerSessionId),
|
|
163
|
+
inArray(eveDispatch.kind, ["create", "send"])
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
return isNonEmptyString(active?.deliveryId);
|
|
167
|
+
};
|
|
168
|
+
|
|
135
169
|
/** Commits intent before the one allowed dispatch; worker failure leaves it unknown. */
|
|
136
170
|
export const dispatchEveOnce = async (
|
|
137
171
|
input: {
|
|
138
172
|
readonly ownerId: string;
|
|
139
173
|
readonly operationId: string;
|
|
140
|
-
readonly
|
|
174
|
+
readonly branchId: string;
|
|
141
175
|
readonly kind: "create" | "copy" | "send";
|
|
142
176
|
readonly intent: unknown;
|
|
177
|
+
readonly steerSessionId?: string;
|
|
143
178
|
},
|
|
144
179
|
dispatch: (
|
|
145
180
|
saveReceipt: (
|
|
@@ -152,7 +187,7 @@ export const dispatchEveOnce = async (
|
|
|
152
187
|
if (replay) {
|
|
153
188
|
return replay;
|
|
154
189
|
}
|
|
155
|
-
await reconcileEveWorkspaceTurn(input.ownerId, input.
|
|
190
|
+
await reconcileEveWorkspaceTurn(input.ownerId, input.branchId);
|
|
156
191
|
const [conversation] = await db
|
|
157
192
|
.select({
|
|
158
193
|
id: eveConversation.id,
|
|
@@ -161,7 +196,7 @@ export const dispatchEveOnce = async (
|
|
|
161
196
|
.from(eveConversation)
|
|
162
197
|
.where(
|
|
163
198
|
and(
|
|
164
|
-
eq(eveConversation.id, input.
|
|
199
|
+
eq(eveConversation.id, input.branchId),
|
|
165
200
|
eq(eveConversation.ownerId, input.ownerId)
|
|
166
201
|
)
|
|
167
202
|
);
|
|
@@ -194,7 +229,15 @@ export const dispatchEveOnce = async (
|
|
|
194
229
|
if (hasRow(existing)) {
|
|
195
230
|
return [];
|
|
196
231
|
}
|
|
197
|
-
if (
|
|
232
|
+
if (
|
|
233
|
+
workspace.activeOperationId !== null &&
|
|
234
|
+
(!(await canSteerActiveDispatch(
|
|
235
|
+
tx,
|
|
236
|
+
workspace.activeOperationId,
|
|
237
|
+
input
|
|
238
|
+
)) ||
|
|
239
|
+
(await hasUnresolvedWorkspaceSteer(tx, input.ownerId, workspace.id)))
|
|
240
|
+
) {
|
|
198
241
|
throw new EveWorkspaceBusyError();
|
|
199
242
|
}
|
|
200
243
|
const [current] = await tx
|
|
@@ -202,7 +245,7 @@ export const dispatchEveOnce = async (
|
|
|
202
245
|
.from(eveConversation)
|
|
203
246
|
.where(
|
|
204
247
|
and(
|
|
205
|
-
eq(eveConversation.id, input.
|
|
248
|
+
eq(eveConversation.id, input.branchId),
|
|
206
249
|
eq(eveConversation.ownerId, input.ownerId),
|
|
207
250
|
eq(eveConversation.workspaceId, workspace.id)
|
|
208
251
|
)
|
|
@@ -214,24 +257,28 @@ export const dispatchEveOnce = async (
|
|
|
214
257
|
) {
|
|
215
258
|
throw new Error("Conversation is unavailable.");
|
|
216
259
|
}
|
|
260
|
+
const { steerSessionId: _steerSessionId, ...journalInput } = input;
|
|
217
261
|
const inserted = await tx
|
|
218
262
|
.insert(eveDispatch)
|
|
219
|
-
.values({ ...
|
|
263
|
+
.values({ ...journalInput, intent })
|
|
220
264
|
.onConflictDoNothing()
|
|
221
265
|
.returning();
|
|
222
|
-
if (inserted.length
|
|
266
|
+
if (inserted.length === 0) {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
if (workspace.activeOperationId === null) {
|
|
223
270
|
await tx
|
|
224
271
|
.update(eveWorkspace)
|
|
225
272
|
.set({ activeOperationId: input.operationId })
|
|
226
273
|
.where(eq(eveWorkspace.id, workspace.id));
|
|
227
274
|
}
|
|
228
|
-
return
|
|
275
|
+
return [{ previousOperationId: workspace.activeOperationId }];
|
|
229
276
|
});
|
|
230
277
|
const identity = and(
|
|
231
278
|
eq(eveDispatch.ownerId, input.ownerId),
|
|
232
279
|
eq(eveDispatch.operationId, input.operationId)
|
|
233
280
|
);
|
|
234
|
-
if (
|
|
281
|
+
if (claimed === undefined) {
|
|
235
282
|
const existing = await readEveDispatch(input);
|
|
236
283
|
if (existing) {
|
|
237
284
|
return existing;
|
|
@@ -257,11 +304,61 @@ export const dispatchEveOnce = async (
|
|
|
257
304
|
throw new EveDispatchUnknownError();
|
|
258
305
|
}
|
|
259
306
|
};
|
|
307
|
+
const finishSteer = async (
|
|
308
|
+
binding: DispatchBinding | null
|
|
309
|
+
): Promise<void> => {
|
|
310
|
+
await db.transaction(async (tx) => {
|
|
311
|
+
const workspace = await lockEveWorkspace(
|
|
312
|
+
tx,
|
|
313
|
+
input.ownerId,
|
|
314
|
+
conversation.workspaceId
|
|
315
|
+
);
|
|
316
|
+
if (binding === null) {
|
|
317
|
+
await tx
|
|
318
|
+
.delete(eveDispatch)
|
|
319
|
+
.where(and(identity, isNull(eveDispatch.sessionId)));
|
|
320
|
+
if (workspace.activeOperationId === input.operationId) {
|
|
321
|
+
await tx
|
|
322
|
+
.update(eveWorkspace)
|
|
323
|
+
.set({ activeOperationId: null })
|
|
324
|
+
.where(eq(eveWorkspace.id, workspace.id));
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (workspace.activeOperationId !== claimed.previousOperationId) {
|
|
329
|
+
throw new EveDispatchUnknownError();
|
|
330
|
+
}
|
|
331
|
+
await persist(tx, binding);
|
|
332
|
+
await tx
|
|
333
|
+
.update(eveWorkspace)
|
|
334
|
+
.set({ activeOperationId: input.operationId })
|
|
335
|
+
.where(eq(eveWorkspace.id, workspace.id));
|
|
336
|
+
});
|
|
337
|
+
};
|
|
260
338
|
let savedInDispatch = false;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
339
|
+
let binding: DispatchBinding;
|
|
340
|
+
try {
|
|
341
|
+
binding = await dispatch(async (transaction, receipt) => {
|
|
342
|
+
if (claimed.previousOperationId !== null) {
|
|
343
|
+
throw new Error(
|
|
344
|
+
"Steering receipts must be saved with the workspace reservation."
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
await persist(transaction, receipt);
|
|
348
|
+
savedInDispatch = true;
|
|
349
|
+
});
|
|
350
|
+
} catch (error) {
|
|
351
|
+
if (error instanceof EveSteerRejectedError && !savedInDispatch) {
|
|
352
|
+
await finishSteer(null);
|
|
353
|
+
}
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
356
|
+
if (claimed.previousOperationId !== null) {
|
|
357
|
+
// EVE may consume a steer in the next turn. Transfer ownership only after
|
|
358
|
+
// storing the receipt and keep the prior reservation through uncertainty.
|
|
359
|
+
await finishSteer(binding);
|
|
360
|
+
return binding;
|
|
361
|
+
}
|
|
265
362
|
if (!savedInDispatch) {
|
|
266
363
|
await persist(db, binding);
|
|
267
364
|
}
|
|
@@ -288,7 +385,7 @@ export const getEveSendReceipt = async (
|
|
|
288
385
|
.innerJoin(
|
|
289
386
|
eveConversation,
|
|
290
387
|
and(
|
|
291
|
-
eq(eveDispatch.
|
|
388
|
+
eq(eveDispatch.branchId, eveConversation.id),
|
|
292
389
|
eq(eveDispatch.ownerId, eveConversation.ownerId)
|
|
293
390
|
)
|
|
294
391
|
)
|
|
@@ -48,7 +48,7 @@ const purgeCandidate = (tx: FilePurgeReadTransaction, ids: readonly string[]) =>
|
|
|
48
48
|
tx
|
|
49
49
|
.select({ key: eveFileReference.key })
|
|
50
50
|
.from(eveFileReference)
|
|
51
|
-
.where(inArray(eveFileReference.
|
|
51
|
+
.where(inArray(eveFileReference.branchId, ids))
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -72,7 +72,7 @@ const prepareEveFamilyFilePurge = async (
|
|
|
72
72
|
.where(
|
|
73
73
|
and(
|
|
74
74
|
eq(eveFileReference.key, eveStoredFile.key),
|
|
75
|
-
notInArray(eveFileReference.
|
|
75
|
+
notInArray(eveFileReference.branchId, ids)
|
|
76
76
|
)
|
|
77
77
|
);
|
|
78
78
|
const files = await tx
|
|
@@ -139,7 +139,7 @@ const releaseEveFamilyFileReferences = async (
|
|
|
139
139
|
.where(
|
|
140
140
|
and(
|
|
141
141
|
eq(eveFileReference.key, eveStoredFile.key),
|
|
142
|
-
notInArray(eveFileReference.
|
|
142
|
+
notInArray(eveFileReference.branchId, ids)
|
|
143
143
|
)
|
|
144
144
|
);
|
|
145
145
|
const unremovedRows = await tx
|
|
@@ -165,7 +165,7 @@ const releaseEveFamilyFileReferences = async (
|
|
|
165
165
|
.where(
|
|
166
166
|
and(
|
|
167
167
|
eq(eveFileReference.ownerId, ownerId),
|
|
168
|
-
inArray(eveFileReference.
|
|
168
|
+
inArray(eveFileReference.branchId, ids)
|
|
169
169
|
)
|
|
170
170
|
);
|
|
171
171
|
});
|
|
@@ -61,7 +61,7 @@ const canReadEveFile = async (
|
|
|
61
61
|
.from(eveFileReference)
|
|
62
62
|
.innerJoin(
|
|
63
63
|
eveConversation,
|
|
64
|
-
eq(eveConversation.id, eveFileReference.
|
|
64
|
+
eq(eveConversation.id, eveFileReference.branchId)
|
|
65
65
|
)
|
|
66
66
|
.where(
|
|
67
67
|
and(
|
|
@@ -147,12 +147,12 @@ const registerEveStoredFile = async (
|
|
|
147
147
|
/**
|
|
148
148
|
* Claim before dispatch; failed/uncertain sends retain their references safely.
|
|
149
149
|
* @param {string} ownerId - Owner of the conversation and every attachment.
|
|
150
|
-
* @param {string}
|
|
150
|
+
* @param {string} branchId - Conversation that receives durable attachment references.
|
|
151
151
|
* @param {readonly string[]} keys - Storage keys to validate and retain before dispatch.
|
|
152
152
|
*/
|
|
153
153
|
const referenceEveFiles = async (
|
|
154
154
|
ownerId: string,
|
|
155
|
-
|
|
155
|
+
branchId: string,
|
|
156
156
|
keys: readonly string[]
|
|
157
157
|
): Promise<void> => {
|
|
158
158
|
const uniqueKeys = [...new Set(keys)].toSorted();
|
|
@@ -175,7 +175,7 @@ const referenceEveFiles = async (
|
|
|
175
175
|
.from(eveConversation)
|
|
176
176
|
.where(
|
|
177
177
|
and(
|
|
178
|
-
eq(eveConversation.id,
|
|
178
|
+
eq(eveConversation.id, branchId),
|
|
179
179
|
eq(eveConversation.ownerId, ownerId)
|
|
180
180
|
)
|
|
181
181
|
);
|
|
@@ -204,7 +204,7 @@ const referenceEveFiles = async (
|
|
|
204
204
|
}
|
|
205
205
|
await tx
|
|
206
206
|
.insert(eveFileReference)
|
|
207
|
-
.values(uniqueKeys.map((key) => ({
|
|
207
|
+
.values(uniqueKeys.map((key) => ({ branchId, key, ownerId })))
|
|
208
208
|
.onConflictDoNothing();
|
|
209
209
|
});
|
|
210
210
|
};
|
|
@@ -246,12 +246,12 @@ const assertEveFilesOwned = async (
|
|
|
246
246
|
/**
|
|
247
247
|
* Persist the key before storage I/O so a failed upload remains discoverable.
|
|
248
248
|
* @param {string} ownerId - Owner of the bound conversation and generated file.
|
|
249
|
-
* @param {string}
|
|
249
|
+
* @param {string} branchId - Bound conversation that retains the generated file.
|
|
250
250
|
* @param {string} key - Fresh storage key reserved before the upload.
|
|
251
251
|
*/
|
|
252
252
|
const reserveEveGeneratedFile = async (
|
|
253
253
|
ownerId: string,
|
|
254
|
-
|
|
254
|
+
branchId: string,
|
|
255
255
|
key: string
|
|
256
256
|
): Promise<void> => {
|
|
257
257
|
if (!isFileStorageKey(key)) {
|
|
@@ -266,7 +266,7 @@ const reserveEveGeneratedFile = async (
|
|
|
266
266
|
.from(eveConversation)
|
|
267
267
|
.where(
|
|
268
268
|
and(
|
|
269
|
-
eq(eveConversation.id,
|
|
269
|
+
eq(eveConversation.id, branchId),
|
|
270
270
|
eq(eveConversation.ownerId, ownerId),
|
|
271
271
|
eq(eveConversation.state, "bound")
|
|
272
272
|
)
|
|
@@ -276,21 +276,21 @@ const reserveEveGeneratedFile = async (
|
|
|
276
276
|
throw new Error("Conversation is unavailable for generated files.");
|
|
277
277
|
}
|
|
278
278
|
await tx.insert(eveStoredFile).values({ key, ownerId });
|
|
279
|
-
await tx.insert(eveFileReference).values({
|
|
279
|
+
await tx.insert(eveFileReference).values({ branchId, key, ownerId });
|
|
280
280
|
});
|
|
281
281
|
};
|
|
282
282
|
|
|
283
283
|
/**
|
|
284
284
|
* Serialize file access with conversation deletion after validating the active conversation reference.
|
|
285
285
|
* @param {string} ownerId - Owner whose family lock protects file access.
|
|
286
|
-
* @param {string}
|
|
286
|
+
* @param {string} branchId - Bound conversation whose file reference is rechecked.
|
|
287
287
|
* @param {string} key - Active conversation file reference to validate.
|
|
288
288
|
* @param {() => Promise<Result>} access - Storage operation admitted while the deletion fence is locked.
|
|
289
289
|
* @returns {Promise<Result>} The storage operation result after the transaction completes.
|
|
290
290
|
*/
|
|
291
291
|
const withEveConversationFile = async <Result>(
|
|
292
292
|
ownerId: string,
|
|
293
|
-
|
|
293
|
+
branchId: string,
|
|
294
294
|
key: string,
|
|
295
295
|
access: () => Promise<Result>
|
|
296
296
|
): Promise<Result> =>
|
|
@@ -304,13 +304,13 @@ const withEveConversationFile = async <Result>(
|
|
|
304
304
|
.innerJoin(eveStoredFile, eq(eveStoredFile.key, eveFileReference.key))
|
|
305
305
|
.innerJoin(
|
|
306
306
|
eveConversation,
|
|
307
|
-
eq(eveConversation.id, eveFileReference.
|
|
307
|
+
eq(eveConversation.id, eveFileReference.branchId)
|
|
308
308
|
)
|
|
309
309
|
.where(
|
|
310
310
|
and(
|
|
311
311
|
eq(eveFileReference.key, key),
|
|
312
312
|
eq(eveStoredFile.state, "active"),
|
|
313
|
-
eq(eveFileReference.
|
|
313
|
+
eq(eveFileReference.branchId, branchId),
|
|
314
314
|
eq(eveFileReference.ownerId, ownerId),
|
|
315
315
|
eq(eveStoredFile.ownerId, ownerId),
|
|
316
316
|
eq(eveConversation.ownerId, ownerId),
|