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
|
@@ -59,7 +59,7 @@ type ConversationListItem = Pick<
|
|
|
59
59
|
ChatRow,
|
|
60
60
|
"createdAt" | "id" | "isPinned" | "title" | "titleStatus"
|
|
61
61
|
> & {
|
|
62
|
-
|
|
62
|
+
branchId: string;
|
|
63
63
|
href: string;
|
|
64
64
|
parentHref: string;
|
|
65
65
|
state: Exclude<ConversationRow["state"], "deleted">;
|
|
@@ -81,7 +81,7 @@ type ConversationBranch = Pick<
|
|
|
81
81
|
| "id"
|
|
82
82
|
| "initialModelId"
|
|
83
83
|
| "operationId"
|
|
84
|
-
| "
|
|
84
|
+
| "parentBranchId"
|
|
85
85
|
| "sessionId"
|
|
86
86
|
> & {
|
|
87
87
|
groupCandidates: typeof eveResponseGroup.$inferSelect.candidates | null;
|
|
@@ -117,23 +117,18 @@ const getBoundEveConversationForSession = async (
|
|
|
117
117
|
/**
|
|
118
118
|
* Internal mapping lookup includes tombstones so deletion cannot look like pending delivery.
|
|
119
119
|
* @param {Readonly<{ reservationId: string } | { sessionId: string }>} identity Exact reservation or native session whose durable mapping is inspected.
|
|
120
|
-
* @returns {Promise<Pick<ConversationRow, "creationKind" | "id" | "ownerId" | "sessionId" | "state" | "
|
|
120
|
+
* @returns {Promise<Pick<ConversationRow, "creationKind" | "id" | "ownerId" | "sessionId" | "state" | "parentBranchId"> | null>} The durable identity and state, including tombstones, or null when no mapping exists.
|
|
121
121
|
*/
|
|
122
122
|
const readEveSessionMapping = async (
|
|
123
123
|
identity: Readonly<{ reservationId: string } | { sessionId: string }>
|
|
124
124
|
): Promise<Pick<
|
|
125
125
|
ConversationRow,
|
|
126
|
-
| "
|
|
127
|
-
| "id"
|
|
128
|
-
| "ownerId"
|
|
129
|
-
| "sessionId"
|
|
130
|
-
| "state"
|
|
131
|
-
| "parentConversationId"
|
|
126
|
+
"creationKind" | "id" | "ownerId" | "sessionId" | "state" | "parentBranchId"
|
|
132
127
|
> | null> => {
|
|
133
128
|
const [row] = await db
|
|
134
129
|
.select({
|
|
135
130
|
creationKind: eveConversation.creationKind,
|
|
136
|
-
|
|
131
|
+
parentBranchId: eveConversation.parentBranchId,
|
|
137
132
|
id: eveConversation.id,
|
|
138
133
|
ownerId: eveConversation.ownerId,
|
|
139
134
|
sessionId: eveConversation.sessionId,
|
|
@@ -169,9 +164,9 @@ const listEveConversations = async (
|
|
|
169
164
|
const updatedAt = sql<string>`to_char(${eveChat.updatedAt}, 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"')`;
|
|
170
165
|
// Qualify correlated references explicitly: Drizzle strips column qualifiers
|
|
171
166
|
// from selected SQL expressions when the outer query has only one table.
|
|
172
|
-
const
|
|
167
|
+
const routeBranchId = sql<string>`coalesce((
|
|
173
168
|
select active."id" from "EveConversation" active
|
|
174
|
-
where active."id" = ${eveChat}."
|
|
169
|
+
where active."id" = ${eveChat}."activeBranchId"
|
|
175
170
|
and active."chatId" = ${eveChat}."id"
|
|
176
171
|
and active."ownerId" = ${ownerId}
|
|
177
172
|
and active."state" in ('creating', 'bound', 'uncertain', 'deleting')
|
|
@@ -213,7 +208,7 @@ const listEveConversations = async (
|
|
|
213
208
|
const escapedSearch = search.replaceAll(/[\\%_]/gu, String.raw`\$&`);
|
|
214
209
|
const rows = await db
|
|
215
210
|
.select({
|
|
216
|
-
|
|
211
|
+
branchId: routeBranchId,
|
|
217
212
|
createdAt: eveChat.createdAt,
|
|
218
213
|
id: eveChat.id,
|
|
219
214
|
isPinned: eveChat.isPinned,
|
|
@@ -319,18 +314,15 @@ const getEveChatPageConversation = async (
|
|
|
319
314
|
return exact;
|
|
320
315
|
}
|
|
321
316
|
const [logical] = await db
|
|
322
|
-
.select({
|
|
317
|
+
.select({ activeBranchId: eveChat.activeBranchId })
|
|
323
318
|
.from(eveChat)
|
|
324
319
|
.where(and(eq(eveChat.id, routeId), eq(eveChat.ownerId, ownerId)))
|
|
325
320
|
.limit(SINGLE_MATCH_LIMIT);
|
|
326
321
|
if (!hasQueryRow(logical)) {
|
|
327
322
|
return null;
|
|
328
323
|
}
|
|
329
|
-
if (isNonemptyString(logical.
|
|
330
|
-
const active = await getEveConversation(
|
|
331
|
-
ownerId,
|
|
332
|
-
logical.activeConversationId
|
|
333
|
-
);
|
|
324
|
+
if (isNonemptyString(logical.activeBranchId)) {
|
|
325
|
+
const active = await getEveConversation(ownerId, logical.activeBranchId);
|
|
334
326
|
if (active?.chatId === routeId) {
|
|
335
327
|
return active;
|
|
336
328
|
}
|
|
@@ -474,7 +466,7 @@ const resolveCreationChat = async (
|
|
|
474
466
|
.from(eveConversation)
|
|
475
467
|
.where(
|
|
476
468
|
and(
|
|
477
|
-
eq(eveConversation.id, fork.
|
|
469
|
+
eq(eveConversation.id, fork.branchId),
|
|
478
470
|
eq(eveConversation.ownerId, value.ownerId),
|
|
479
471
|
eq(eveConversation.state, "bound")
|
|
480
472
|
)
|
|
@@ -494,7 +486,7 @@ const resolveCreationChat = async (
|
|
|
494
486
|
and(
|
|
495
487
|
eq(eveResponseGroup.ownerId, value.ownerId),
|
|
496
488
|
eq(eveResponseGroup.deleted, false),
|
|
497
|
-
isNull(eveResponseGroup.
|
|
489
|
+
isNull(eveResponseGroup.sourceBranchId),
|
|
498
490
|
sql`${value.operationId}::uuid = ANY(${eveResponseGroup.candidateOperationIds})`
|
|
499
491
|
)
|
|
500
492
|
)
|
|
@@ -562,12 +554,10 @@ const reserveEveConversation = async (
|
|
|
562
554
|
chatId,
|
|
563
555
|
workspaceId,
|
|
564
556
|
forkKind: value.forkKind,
|
|
565
|
-
|
|
557
|
+
parentBranchId: fork?.branchId,
|
|
566
558
|
forkMessageId: fork?.beforeMessageId,
|
|
567
|
-
|
|
568
|
-
source === undefined
|
|
569
|
-
? undefined
|
|
570
|
-
: (source.rootConversationId ?? source.id),
|
|
559
|
+
rootBranchId:
|
|
560
|
+
source === undefined ? undefined : (source.rootBranchId ?? source.id),
|
|
571
561
|
})
|
|
572
562
|
.onConflictDoNothing()
|
|
573
563
|
.returning();
|
|
@@ -643,20 +633,18 @@ const beginEveConversationDeletion = async (
|
|
|
643
633
|
// call. A creating/deleting row with no journal/binding can skip native cleanup,
|
|
644
634
|
// but remains deleting through resource cleanup. Dispatched uncertainty stays fenced.
|
|
645
635
|
const dispatched = await tx
|
|
646
|
-
.select({
|
|
636
|
+
.select({ branchId: eveDispatch.branchId })
|
|
647
637
|
.from(eveDispatch)
|
|
648
638
|
.where(
|
|
649
639
|
and(
|
|
650
640
|
eq(eveDispatch.ownerId, ownerId),
|
|
651
641
|
inArray(
|
|
652
|
-
eveDispatch.
|
|
642
|
+
eveDispatch.branchId,
|
|
653
643
|
family.map((row) => row.id)
|
|
654
644
|
)
|
|
655
645
|
)
|
|
656
646
|
);
|
|
657
|
-
const dispatchedIds = new Set(
|
|
658
|
-
dispatched.map((row) => row.conversationId)
|
|
659
|
-
);
|
|
647
|
+
const dispatchedIds = new Set(dispatched.map((row) => row.branchId));
|
|
660
648
|
const undispatched = new Set(
|
|
661
649
|
family
|
|
662
650
|
.filter(
|
|
@@ -712,7 +700,7 @@ const beginEveConversationDeletion = async (
|
|
|
712
700
|
const matchesEveFork = (
|
|
713
701
|
existing: Pick<
|
|
714
702
|
typeof eveConversation.$inferSelect,
|
|
715
|
-
| "
|
|
703
|
+
| "parentBranchId"
|
|
716
704
|
| "forkTurnId"
|
|
717
705
|
| "forkMessageId"
|
|
718
706
|
| "forkCheckpointId"
|
|
@@ -721,7 +709,7 @@ const matchesEveFork = (
|
|
|
721
709
|
fork: EveForkInput | undefined,
|
|
722
710
|
forkKind: typeof eveConversation.$inferSelect.forkKind
|
|
723
711
|
): boolean =>
|
|
724
|
-
existing.
|
|
712
|
+
existing.parentBranchId === (fork?.branchId ?? null) &&
|
|
725
713
|
existing.forkKind === forkKind &&
|
|
726
714
|
existing.forkMessageId === (fork?.beforeMessageId ?? null);
|
|
727
715
|
|
|
@@ -787,7 +775,7 @@ const bindConversationSession = async (
|
|
|
787
775
|
await tx
|
|
788
776
|
.update(eveChat)
|
|
789
777
|
.set({
|
|
790
|
-
|
|
778
|
+
activeBranchId: sql`coalesce(${eveChat.activeBranchId}, ${bound.id}::uuid)`,
|
|
791
779
|
updatedAt: new Date(),
|
|
792
780
|
})
|
|
793
781
|
.where(and(eq(eveChat.id, bound.chatId), eq(eveChat.ownerId, ownerId)));
|
|
@@ -905,7 +893,7 @@ const createEveConversation = async (
|
|
|
905
893
|
and(
|
|
906
894
|
eq(eveDispatch.ownerId, ownerId),
|
|
907
895
|
eq(eveDispatch.operationId, matching.id),
|
|
908
|
-
eq(eveDispatch.
|
|
896
|
+
eq(eveDispatch.branchId, matching.id),
|
|
909
897
|
eq(eveDispatch.sessionId, binding.sessionId),
|
|
910
898
|
eq(eveDispatch.kind, "create")
|
|
911
899
|
)
|
|
@@ -928,7 +916,7 @@ const createEveConversation = async (
|
|
|
928
916
|
{
|
|
929
917
|
ownerId,
|
|
930
918
|
operationId: reservation.id,
|
|
931
|
-
|
|
919
|
+
branchId: reservation.id,
|
|
932
920
|
kind: "create",
|
|
933
921
|
intent: reservation.initialRequest ?? {
|
|
934
922
|
message,
|
|
@@ -1074,16 +1062,13 @@ const recordEveConversationActivity = async (
|
|
|
1074
1062
|
|
|
1075
1063
|
const listEveConversationBranches = async (
|
|
1076
1064
|
ownerId: string,
|
|
1077
|
-
|
|
1065
|
+
branchId: string
|
|
1078
1066
|
): Promise<ConversationBranchListing | undefined> => {
|
|
1079
|
-
const conversation = await getEveChatPageConversation(
|
|
1080
|
-
ownerId,
|
|
1081
|
-
conversationId
|
|
1082
|
-
);
|
|
1067
|
+
const conversation = await getEveChatPageConversation(ownerId, branchId);
|
|
1083
1068
|
if (!conversation) {
|
|
1084
1069
|
return undefined;
|
|
1085
1070
|
}
|
|
1086
|
-
const rootId = conversation.
|
|
1071
|
+
const rootId = conversation.rootBranchId ?? conversation.id;
|
|
1087
1072
|
const branches = await db
|
|
1088
1073
|
.select({
|
|
1089
1074
|
createdAt: eveConversation.createdAt,
|
|
@@ -1095,7 +1080,7 @@ const listEveConversationBranches = async (
|
|
|
1095
1080
|
id: eveConversation.id,
|
|
1096
1081
|
initialModelId: eveConversation.initialModelId,
|
|
1097
1082
|
operationId: eveConversation.operationId,
|
|
1098
|
-
|
|
1083
|
+
parentBranchId: eveConversation.parentBranchId,
|
|
1099
1084
|
responseGroupId: eveResponseGroup.id,
|
|
1100
1085
|
responseGroupIndex: sql<
|
|
1101
1086
|
number | null
|
|
@@ -16,7 +16,7 @@ import { eveResponseGroupResult } from "@/lib/eve/response-group-contracts";
|
|
|
16
16
|
import { resolveEveResponseGroupLineage } from "@/lib/eve/response-group-lineage";
|
|
17
17
|
|
|
18
18
|
import { db } from "./client";
|
|
19
|
-
import { eveConversation, eveResponseGroup
|
|
19
|
+
import { eveConversation, eveResponseGroup } from "./schema";
|
|
20
20
|
import type { z } from "zod";
|
|
21
21
|
|
|
22
22
|
const hasQueryRow: (row: unknown) => boolean = Boolean;
|
|
@@ -26,13 +26,12 @@ const isNonemptyString = (value: string | null | undefined): value is string =>
|
|
|
26
26
|
|
|
27
27
|
const FIRST_PARAMETER_INDEX = 0;
|
|
28
28
|
const EMPTY_FAMILY_SIZE = 0;
|
|
29
|
-
const SINGLE_MATCH_LIMIT = 1;
|
|
30
29
|
|
|
31
30
|
type ResponseGroupTransaction = Parameters<
|
|
32
31
|
Parameters<typeof db.transaction>[typeof FIRST_PARAMETER_INDEX]
|
|
33
32
|
>[typeof FIRST_PARAMETER_INDEX];
|
|
34
33
|
type ResponseGroupTombstoneTransaction = Readonly<
|
|
35
|
-
Pick<ResponseGroupTransaction, "
|
|
34
|
+
Pick<ResponseGroupTransaction, "update">
|
|
36
35
|
>;
|
|
37
36
|
type ResponseGroupWriteTransaction = Readonly<
|
|
38
37
|
Pick<ResponseGroupTransaction, "select" | "execute" | "insert" | "update">
|
|
@@ -46,62 +45,18 @@ type ReservedResponseGroup = ReadonlyNativeSurface<
|
|
|
46
45
|
}
|
|
47
46
|
>;
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
createHash("sha256").update(JSON.stringify(request)).digest("hex");
|
|
48
|
+
type GroupInput = ReadonlyNativeSurface<z.infer<typeof eveResponseGroupInput>>;
|
|
51
49
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
ownerId: string,
|
|
55
|
-
existing: ReadonlyNativeSurface<ResponseGroupRow>,
|
|
56
|
-
input: ReadonlyNativeSurface<z.infer<typeof eveResponseGroupInput>>,
|
|
57
|
-
coreInput: Readonly<Record<string, unknown>>
|
|
58
|
-
): Promise<string> => {
|
|
59
|
-
// Upgrade legacy hashes only after proving every non-plugin input matches.
|
|
60
|
-
// The first candidate's pending request or dispatch journal retains its original assignment.
|
|
61
|
-
const [original] = await tx
|
|
62
|
-
.select({
|
|
63
|
-
request: eveConversation.initialRequest,
|
|
64
|
-
intent: eveDispatch.intent,
|
|
65
|
-
})
|
|
66
|
-
.from(eveConversation)
|
|
67
|
-
.leftJoin(
|
|
68
|
-
eveDispatch,
|
|
69
|
-
and(
|
|
70
|
-
eq(eveDispatch.conversationId, eveConversation.id),
|
|
71
|
-
eq(eveDispatch.kind, "create")
|
|
72
|
-
)
|
|
73
|
-
)
|
|
74
|
-
.where(
|
|
75
|
-
and(
|
|
76
|
-
eq(eveConversation.ownerId, ownerId),
|
|
77
|
-
eq(
|
|
78
|
-
eveConversation.operationId,
|
|
79
|
-
existing.candidateOperationIds[0] ?? input.operationId
|
|
80
|
-
)
|
|
81
|
-
)
|
|
82
|
-
);
|
|
83
|
-
const originalInput = original?.request ?? original?.intent;
|
|
84
|
-
const restored =
|
|
85
|
-
originalInput !== null && typeof originalInput === "object"
|
|
86
|
-
? eveResponseGroupInput.parse({
|
|
87
|
-
...coreInput,
|
|
88
|
-
projectId:
|
|
89
|
-
"projectId" in originalInput ? originalInput.projectId : undefined,
|
|
90
|
-
})
|
|
91
|
-
: input;
|
|
92
|
-
return hash(restored);
|
|
93
|
-
};
|
|
50
|
+
const hash = (request: GroupInput): string =>
|
|
51
|
+
createHash("sha256").update(JSON.stringify(request)).digest("hex");
|
|
94
52
|
|
|
95
53
|
const reserveGroupRow = async (
|
|
96
54
|
tx: ResponseGroupWriteTransaction,
|
|
97
55
|
ownerId: string,
|
|
98
|
-
value:
|
|
56
|
+
value: GroupInput
|
|
99
57
|
): Promise<ResponseGroupRow | undefined> => {
|
|
100
58
|
const input = eveResponseGroupInput.parse(value);
|
|
101
|
-
const
|
|
102
|
-
Object.entries(input).filter(([key]) => key !== "projectId")
|
|
103
|
-
);
|
|
104
|
-
const inputHash = hash(coreInput);
|
|
59
|
+
const inputHash = hash({ ...input, projectId: undefined });
|
|
105
60
|
await tx.execute(
|
|
106
61
|
sql`select pg_advisory_xact_lock(hashtextextended(${`eve-family:${ownerId}`}, 0))`
|
|
107
62
|
);
|
|
@@ -114,19 +69,12 @@ const reserveGroupRow = async (
|
|
|
114
69
|
throw new Error("This response group has been deleted.");
|
|
115
70
|
}
|
|
116
71
|
if (hasQueryRow(existing) && existing.inputHash !== inputHash) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
"This response group already has a different message, model order, tool selection, or source."
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
await tx.update(eveResponseGroup).set({ inputHash }).where(condition);
|
|
126
|
-
existing.inputHash = inputHash;
|
|
72
|
+
throw new Error(
|
|
73
|
+
"This response group already has a different message, model order, tool selection, or source."
|
|
74
|
+
);
|
|
127
75
|
}
|
|
128
76
|
|
|
129
|
-
const sourceId = input.fork?.
|
|
77
|
+
const sourceId = input.fork?.branchId ?? null;
|
|
130
78
|
const [source] =
|
|
131
79
|
typeof sourceId === "string" && sourceId !== ""
|
|
132
80
|
? await tx
|
|
@@ -142,14 +90,6 @@ const reserveGroupRow = async (
|
|
|
142
90
|
if (typeof sourceId === "string" && sourceId !== "" && !hasQueryRow(source)) {
|
|
143
91
|
throw new Error("Source conversation not found.");
|
|
144
92
|
}
|
|
145
|
-
// An exact replay can recover the missing association of a pre-contract group.
|
|
146
|
-
// Commit it even when the source has since retired, so deletion can find it.
|
|
147
|
-
if (hasQueryRow(existing) && !existing.sourceIdentityKnown) {
|
|
148
|
-
await tx
|
|
149
|
-
.update(eveResponseGroup)
|
|
150
|
-
.set({ sourceConversationId: sourceId, sourceIdentityKnown: true })
|
|
151
|
-
.where(condition);
|
|
152
|
-
}
|
|
153
93
|
if (hasQueryRow(source) && source.state !== "bound") {
|
|
154
94
|
return undefined;
|
|
155
95
|
}
|
|
@@ -171,8 +111,7 @@ const reserveGroupRow = async (
|
|
|
171
111
|
inputHash,
|
|
172
112
|
operationId: input.operationId,
|
|
173
113
|
ownerId,
|
|
174
|
-
|
|
175
|
-
sourceIdentityKnown: true,
|
|
114
|
+
sourceBranchId: sourceId,
|
|
176
115
|
})
|
|
177
116
|
.returning();
|
|
178
117
|
return group;
|
|
@@ -202,7 +141,7 @@ const requireGroup = (
|
|
|
202
141
|
*/
|
|
203
142
|
const reserveEveResponseGroup = async (
|
|
204
143
|
ownerId: string,
|
|
205
|
-
value:
|
|
144
|
+
value: GroupInput
|
|
206
145
|
): Promise<ReservedResponseGroup> => {
|
|
207
146
|
const result = await db.transaction(
|
|
208
147
|
async (tx: ResponseGroupWriteTransaction) =>
|
|
@@ -225,23 +164,6 @@ const tombstoneEveResponseGroups = async (
|
|
|
225
164
|
operationId: string;
|
|
226
165
|
}>[]
|
|
227
166
|
): Promise<void> => {
|
|
228
|
-
const [unknown] = await tx
|
|
229
|
-
.select({ id: eveResponseGroup.id })
|
|
230
|
-
.from(eveResponseGroup)
|
|
231
|
-
.where(
|
|
232
|
-
and(
|
|
233
|
-
eq(eveResponseGroup.ownerId, ownerId),
|
|
234
|
-
eq(eveResponseGroup.sourceIdentityKnown, false),
|
|
235
|
-
eq(eveResponseGroup.deleted, false)
|
|
236
|
-
)
|
|
237
|
-
)
|
|
238
|
-
.limit(SINGLE_MATCH_LIMIT);
|
|
239
|
-
const hasUnknownSource = hasQueryRow(unknown);
|
|
240
|
-
if (hasUnknownSource) {
|
|
241
|
-
throw new Error(
|
|
242
|
-
"Recover saved response group requests before deleting conversations."
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
167
|
const operations = sql`ARRAY[${sql.join(
|
|
246
168
|
family.map((row) => sql`${row.operationId}::uuid`),
|
|
247
169
|
sql`, `
|
|
@@ -254,7 +176,7 @@ const tombstoneEveResponseGroups = async (
|
|
|
254
176
|
eq(eveResponseGroup.ownerId, ownerId),
|
|
255
177
|
or(
|
|
256
178
|
inArray(
|
|
257
|
-
eveResponseGroup.
|
|
179
|
+
eveResponseGroup.sourceBranchId,
|
|
258
180
|
family.map((row) => row.id)
|
|
259
181
|
),
|
|
260
182
|
sql`${eveResponseGroup.candidateOperationIds} && ${operations}`
|
|
@@ -344,7 +266,7 @@ const getEveResponseGroup = async (
|
|
|
344
266
|
.select({
|
|
345
267
|
...getTableColumns(eveConversation),
|
|
346
268
|
dispatched: sql<boolean>`exists (
|
|
347
|
-
select 1 from "EveDispatch" dispatch where dispatch."
|
|
269
|
+
select 1 from "EveDispatch" dispatch where dispatch."branchId" = ${eveConversation.id}
|
|
348
270
|
and dispatch."ownerId" = ${ownerId}
|
|
349
271
|
)`,
|
|
350
272
|
})
|
|
@@ -381,7 +303,7 @@ const getEveResponseGroup = async (
|
|
|
381
303
|
if (row?.state === "bound" && isNonemptyString(row.sessionId)) {
|
|
382
304
|
return {
|
|
383
305
|
...identity,
|
|
384
|
-
|
|
306
|
+
branchId: row.id,
|
|
385
307
|
sessionId: row.sessionId,
|
|
386
308
|
state: "bound",
|
|
387
309
|
};
|
|
@@ -410,17 +332,17 @@ const getEveResponseGroup = async (
|
|
|
410
332
|
|
|
411
333
|
const getEveResponseGroupForConversation = async (
|
|
412
334
|
ownerId: string,
|
|
413
|
-
|
|
335
|
+
branchId: string
|
|
414
336
|
): Promise<z.output<typeof eveResponseGroupResult> | undefined> => {
|
|
415
337
|
const [conversation] = await db
|
|
416
338
|
.select({
|
|
417
339
|
id: eveConversation.id,
|
|
418
|
-
|
|
340
|
+
rootBranchId: eveConversation.rootBranchId,
|
|
419
341
|
})
|
|
420
342
|
.from(eveConversation)
|
|
421
343
|
.where(
|
|
422
344
|
and(
|
|
423
|
-
eq(eveConversation.id,
|
|
345
|
+
eq(eveConversation.id, branchId),
|
|
424
346
|
eq(eveConversation.ownerId, ownerId),
|
|
425
347
|
eq(eveConversation.state, "bound")
|
|
426
348
|
)
|
|
@@ -428,7 +350,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
428
350
|
if (!hasQueryRow(conversation)) {
|
|
429
351
|
return undefined;
|
|
430
352
|
}
|
|
431
|
-
const rootId = conversation.
|
|
353
|
+
const rootId = conversation.rootBranchId ?? conversation.id;
|
|
432
354
|
const family = await db
|
|
433
355
|
.select({
|
|
434
356
|
createdAt: eveConversation.createdAt,
|
|
@@ -437,7 +359,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
437
359
|
forkTurnId: eveConversation.forkTurnId,
|
|
438
360
|
id: eveConversation.id,
|
|
439
361
|
operationId: eveConversation.operationId,
|
|
440
|
-
|
|
362
|
+
parentBranchId: eveConversation.parentBranchId,
|
|
441
363
|
sessionId: eveConversation.sessionId,
|
|
442
364
|
})
|
|
443
365
|
.from(eveConversation)
|
|
@@ -447,7 +369,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
447
369
|
eq(eveConversation.state, "bound"),
|
|
448
370
|
or(
|
|
449
371
|
eq(eveConversation.id, rootId),
|
|
450
|
-
eq(eveConversation.
|
|
372
|
+
eq(eveConversation.rootBranchId, rootId)
|
|
451
373
|
)
|
|
452
374
|
)
|
|
453
375
|
);
|
|
@@ -481,9 +403,9 @@ const getEveResponseGroupForConversation = async (
|
|
|
481
403
|
eq(eveResponseGroup.deleted, false),
|
|
482
404
|
sql`${eveResponseGroup.candidateOperationIds} && ${operationIds}`,
|
|
483
405
|
or(
|
|
484
|
-
isNull(eveResponseGroup.
|
|
406
|
+
isNull(eveResponseGroup.sourceBranchId),
|
|
485
407
|
inArray(
|
|
486
|
-
eveResponseGroup.
|
|
408
|
+
eveResponseGroup.sourceBranchId,
|
|
487
409
|
boundFamily.map(
|
|
488
410
|
(member: ReadonlyNativeSurface<(typeof boundFamily)[number]>) =>
|
|
489
411
|
member.id
|
|
@@ -492,11 +414,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
492
414
|
)
|
|
493
415
|
)
|
|
494
416
|
);
|
|
495
|
-
const lineage = resolveEveResponseGroupLineage(
|
|
496
|
-
conversationId,
|
|
497
|
-
boundFamily,
|
|
498
|
-
groups
|
|
499
|
-
);
|
|
417
|
+
const lineage = resolveEveResponseGroupLineage(branchId, boundFamily, groups);
|
|
500
418
|
if (!lineage) {
|
|
501
419
|
return undefined;
|
|
502
420
|
}
|
|
@@ -510,7 +428,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
510
428
|
const candidateConversations = await db
|
|
511
429
|
.select({
|
|
512
430
|
id: eveConversation.id,
|
|
513
|
-
|
|
431
|
+
rootBranchId: eveConversation.rootBranchId,
|
|
514
432
|
})
|
|
515
433
|
.from(eveConversation)
|
|
516
434
|
.where(
|
|
@@ -524,7 +442,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
524
442
|
...new Set(
|
|
525
443
|
candidateConversations.map(
|
|
526
444
|
(candidate: Readonly<(typeof candidateConversations)[number]>) =>
|
|
527
|
-
candidate.
|
|
445
|
+
candidate.rootBranchId ?? candidate.id
|
|
528
446
|
)
|
|
529
447
|
),
|
|
530
448
|
];
|
|
@@ -539,7 +457,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
539
457
|
forkTurnId: eveConversation.forkTurnId,
|
|
540
458
|
id: eveConversation.id,
|
|
541
459
|
operationId: eveConversation.operationId,
|
|
542
|
-
|
|
460
|
+
parentBranchId: eveConversation.parentBranchId,
|
|
543
461
|
sessionId: eveConversation.sessionId,
|
|
544
462
|
})
|
|
545
463
|
.from(eveConversation)
|
|
@@ -549,7 +467,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
549
467
|
eq(eveConversation.state, "bound"),
|
|
550
468
|
or(
|
|
551
469
|
inArray(eveConversation.id, candidateRootIds),
|
|
552
|
-
inArray(eveConversation.
|
|
470
|
+
inArray(eveConversation.rootBranchId, candidateRootIds)
|
|
553
471
|
)
|
|
554
472
|
)
|
|
555
473
|
);
|
|
@@ -562,7 +480,7 @@ const getEveResponseGroupForConversation = async (
|
|
|
562
480
|
}
|
|
563
481
|
);
|
|
564
482
|
const groupLineage = resolveEveResponseGroupLineage(
|
|
565
|
-
|
|
483
|
+
branchId,
|
|
566
484
|
boundGroupFamilies,
|
|
567
485
|
[lineageGroup]
|
|
568
486
|
);
|
|
@@ -9,7 +9,7 @@ const hasQueryRow: (row: unknown) => boolean = Boolean;
|
|
|
9
9
|
|
|
10
10
|
type EveSubagentBinding = Pick<
|
|
11
11
|
typeof eveSubagentSession.$inferSelect,
|
|
12
|
-
| "
|
|
12
|
+
| "branchId"
|
|
13
13
|
| "parentSessionId"
|
|
14
14
|
| "rootTurnId"
|
|
15
15
|
| "sessionId"
|
|
@@ -22,7 +22,7 @@ const getEveSubagent = async (
|
|
|
22
22
|
): Promise<EveSubagentBinding | null> => {
|
|
23
23
|
const [binding] = await db
|
|
24
24
|
.select({
|
|
25
|
-
|
|
25
|
+
branchId: eveSubagentSession.branchId,
|
|
26
26
|
parentSessionId: eveSubagentSession.parentSessionId,
|
|
27
27
|
rootSessionId: eveConversation.sessionId,
|
|
28
28
|
rootTurnId: eveSubagentSession.rootTurnId,
|
|
@@ -33,7 +33,7 @@ const getEveSubagent = async (
|
|
|
33
33
|
.innerJoin(
|
|
34
34
|
eveConversation,
|
|
35
35
|
and(
|
|
36
|
-
eq(eveConversation.id, eveSubagentSession.
|
|
36
|
+
eq(eveConversation.id, eveSubagentSession.branchId),
|
|
37
37
|
eq(eveConversation.ownerId, eveSubagentSession.ownerId)
|
|
38
38
|
)
|
|
39
39
|
)
|
|
@@ -77,10 +77,10 @@ const registerEveSubagent = async (
|
|
|
77
77
|
const parent = hasQueryRow(root)
|
|
78
78
|
? undefined
|
|
79
79
|
: await getEveSubagent(ownerId, parentSessionId);
|
|
80
|
-
const
|
|
80
|
+
const branchId = root?.id ?? parent?.branchId;
|
|
81
81
|
const rootTurnId = hasQueryRow(root) ? parentTurnId : parent?.rootTurnId;
|
|
82
82
|
if (
|
|
83
|
-
!
|
|
83
|
+
!branchId ||
|
|
84
84
|
typeof rootTurnId !== "string" ||
|
|
85
85
|
rootTurnId === "" ||
|
|
86
86
|
sessionId === parentSessionId
|
|
@@ -89,12 +89,12 @@ const registerEveSubagent = async (
|
|
|
89
89
|
}
|
|
90
90
|
await db
|
|
91
91
|
.insert(eveSubagentSession)
|
|
92
|
-
.values({
|
|
92
|
+
.values({ branchId, ownerId, parentSessionId, rootTurnId, sessionId })
|
|
93
93
|
.onConflictDoNothing();
|
|
94
94
|
const bound = await getEveSubagent(ownerId, sessionId);
|
|
95
95
|
if (
|
|
96
96
|
bound === null ||
|
|
97
|
-
bound.
|
|
97
|
+
bound.branchId !== branchId ||
|
|
98
98
|
bound.parentSessionId !== parentSessionId ||
|
|
99
99
|
bound.rootTurnId !== rootTurnId
|
|
100
100
|
) {
|
|
@@ -125,7 +125,7 @@ const listEveSubagents = async (
|
|
|
125
125
|
.innerJoin(
|
|
126
126
|
eveConversation,
|
|
127
127
|
and(
|
|
128
|
-
eq(eveConversation.id, eveSubagentSession.
|
|
128
|
+
eq(eveConversation.id, eveSubagentSession.branchId),
|
|
129
129
|
eq(eveConversation.ownerId, eveSubagentSession.ownerId)
|
|
130
130
|
)
|
|
131
131
|
)
|
|
@@ -4,7 +4,7 @@ import { eveChat, eveConversation } from "./schema";
|
|
|
4
4
|
|
|
5
5
|
export const settleEveRootFallbackTitle = async (
|
|
6
6
|
ownerId: string,
|
|
7
|
-
|
|
7
|
+
branchId: string,
|
|
8
8
|
fallbackTitle: string
|
|
9
9
|
): Promise<boolean> => {
|
|
10
10
|
const [row] = await db
|
|
@@ -13,7 +13,7 @@ export const settleEveRootFallbackTitle = async (
|
|
|
13
13
|
.from(eveConversation)
|
|
14
14
|
.where(
|
|
15
15
|
and(
|
|
16
|
-
eq(eveConversation.id,
|
|
16
|
+
eq(eveConversation.id, branchId),
|
|
17
17
|
eq(eveConversation.ownerId, ownerId),
|
|
18
18
|
eq(eveConversation.state, "bound"),
|
|
19
19
|
eq(eveChat.id, eveConversation.chatId),
|
|
@@ -87,7 +87,7 @@ export const cleanupRetiredEveWorkspaces = async (
|
|
|
87
87
|
/** Finalization retains ownership and pending-operation checks for application workspaces. */
|
|
88
88
|
export const checkDeletedWorkspaceMemberships = async (
|
|
89
89
|
ownerId: string,
|
|
90
|
-
|
|
90
|
+
branchIds: readonly string[],
|
|
91
91
|
transaction?: Readonly<Pick<Transaction, "execute" | "select">>
|
|
92
92
|
): Promise<void> => {
|
|
93
93
|
const check = async (
|
|
@@ -99,11 +99,11 @@ export const checkDeletedWorkspaceMemberships = async (
|
|
|
99
99
|
.where(
|
|
100
100
|
and(
|
|
101
101
|
eq(eveConversation.ownerId, ownerId),
|
|
102
|
-
inArray(eveConversation.id, [...
|
|
102
|
+
inArray(eveConversation.id, [...branchIds])
|
|
103
103
|
)
|
|
104
104
|
);
|
|
105
105
|
if (
|
|
106
|
-
conversations.length !== new Set(
|
|
106
|
+
conversations.length !== new Set(branchIds).size ||
|
|
107
107
|
conversations.some(
|
|
108
108
|
(member) => !["deleting", "deleted"].includes(member.state)
|
|
109
109
|
)
|