chat-js 1.0.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/index.js +2627 -2667
- package/package.json +10 -4
- package/templates/chat-app/.env.example +2 -8
- package/templates/chat-app/agent/agent.ts +8 -38
- package/templates/chat-app/agent/channels/eve.ts +37 -17
- package/templates/chat-app/agent/hooks/activity.ts +2 -1
- package/templates/chat-app/agent/hooks/billing.ts +11 -8
- package/templates/chat-app/agent/hooks/conversation.ts +2 -2
- package/templates/chat-app/agent/hooks/tool-selection.ts +7 -1
- package/templates/chat-app/agent/instructions/chat.ts +14 -10
- package/templates/chat-app/agent/sandbox.ts +2 -4
- package/templates/chat-app/agent/tools/installed.ts +19 -1
- package/templates/chat-app/app/(chat)/layout.tsx +10 -8
- package/templates/chat-app/app/api/agent-conversations/[id]/route.test.ts +1 -1
- package/templates/chat-app/app/api/agent-conversations/[id]/route.ts +1 -5
- package/templates/chat-app/app/api/agent-conversations/route.test.ts +31 -2
- package/templates/chat-app/app/api/agent-conversations/route.ts +10 -1
- package/templates/chat-app/app/api/agent-workspaces/[id]/route.test.ts +5 -31
- package/templates/chat-app/app/api/agent-workspaces/[id]/route.ts +2 -10
- package/templates/chat-app/app/api/eve/[...path]/route.test.ts +2 -2
- package/templates/chat-app/app/apple-icon.png +0 -0
- package/templates/chat-app/app/favicon.ico +0 -0
- package/templates/chat-app/app/icon.svg +1 -3
- package/templates/chat-app/app/opengraph-image.alt.txt +1 -0
- package/templates/chat-app/app/opengraph-image.png +0 -0
- package/templates/chat-app/chat.config.ts +0 -18
- package/templates/chat-app/chatjs/core/chat/compose.ts +35 -11
- package/templates/chat-app/chatjs/core/chat/contracts.ts +6 -0
- package/templates/chat-app/chatjs/core/installation/contracts.ts +1 -4
- package/templates/chat-app/chatjs/core/session/contracts.ts +19 -4
- package/templates/chat-app/chatjs/generated/composer-tools.ts +5 -12
- package/templates/chat-app/chatjs/generated/installed-chat-ui.ts +11 -5
- package/templates/chat-app/chatjs/generated/installed-config.ts +5 -13
- package/templates/chat-app/chatjs/generated/installed-instrumentation.ts +1 -2
- package/templates/chat-app/chatjs/generated/installed-layout.ts +1 -7
- package/templates/chat-app/chatjs/generated/installed-tools.ts +3 -3
- package/templates/chat-app/chatjs/generated/installed.ts +3 -3
- package/templates/chat-app/chatjs/generated/providers.ts +5 -11
- package/templates/chat-app/chatjs/generated/tool-availability.ts +3 -7
- package/templates/chat-app/chatjs/generated/tool-definitions.ts +3 -4
- package/templates/chat-app/chatjs/generated/tool-requirements.ts +40 -0
- package/templates/chat-app/chatjs/generated/tools.ts +7 -28
- package/templates/chat-app/chatjs/generated/ui.ts +3 -13
- package/templates/chat-app/chatjs/plugins/ai-titles/generate-title.ts +0 -2
- package/templates/chat-app/chatjs/plugins/attachment-uploads/chatjs.json +0 -1
- package/templates/chat-app/chatjs/plugins/guest-chat/session-profile.ts +2 -0
- package/templates/chat-app/chatjs/plugins/guest-chat/signed-out.tsx +70 -34
- package/templates/chat-app/chatjs/plugins/image-viewer/chatjs.json +17 -0
- package/templates/chat-app/chatjs/plugins/image-viewer/client-plugin.ts +9 -0
- package/templates/chat-app/{components → chatjs/plugins/image-viewer}/image-modal.tsx +3 -87
- package/templates/chat-app/chatjs/plugins/image-viewer/viewer-action.tsx +47 -0
- package/templates/chat-app/chatjs/plugins/mcp/composer.tsx +1 -6
- package/templates/chat-app/chatjs/plugins/projects/ui/chat-contributions.tsx +22 -2
- package/templates/chat-app/chatjs/plugins/projects/ui/sidebar-project-item.tsx +48 -33
- package/templates/chat-app/chatjs/plugins/projects/ui/sidebar-projects.tsx +41 -22
- package/templates/chat-app/chatjs/plugins/search/chat.ts +4 -0
- package/templates/chat-app/chatjs/plugins/search/search-chats.tsx +9 -3
- package/templates/chat-app/chatjs/plugins/search/search-hook.ts +5 -6
- package/templates/chat-app/chatjs/plugins/search/search-results-view.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/search/search-text.ts +21 -15
- package/templates/chat-app/chatjs/plugins/search/sidebar-item.tsx +7 -1
- package/templates/chat-app/chatjs/plugins/sharing/ui/share-button.tsx +13 -3
- package/templates/chat-app/chatjs/plugins/sharing/ui/shared-page.tsx +23 -39
- package/templates/chat-app/chatjs/plugins/sharing/ui/transcript-messages.tsx +2 -2
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/chatjs.json +18 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/client-plugin.ts +9 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/load.ts +120 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/preview.tsx +72 -0
- package/templates/chat-app/chatjs/plugins/spreadsheet-viewer/viewer-action.tsx +97 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/chatjs.json +16 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/client-plugin.ts +9 -0
- package/templates/chat-app/chatjs/plugins/video-viewer/viewer-action.tsx +64 -0
- package/templates/chat-app/chatjs/tools/_shared/lib/define-tool-renderer.test.ts +16 -22
- package/templates/chat-app/chatjs/tools/attach-workspace-file/attach-conversation-file.ts +34 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/attach.ts +106 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/chatjs.json +19 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/import.ts +71 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/renderer.tsx +19 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/schemas.ts +51 -0
- package/templates/chat-app/chatjs/tools/attach-workspace-file/tool.ts +62 -0
- package/templates/chat-app/chatjs/tools/deep-research/chatjs.json +18 -4
- package/templates/chat-app/chatjs/tools/deep-research/progress-panel.tsx +2 -31
- package/templates/chat-app/chatjs/tools/deep-research/renderer.tsx +7 -19
- package/templates/chat-app/chatjs/tools/deep-research/schemas.ts +1 -46
- package/templates/chat-app/chatjs/tools/deep-research/task.tsx +0 -41
- package/templates/chat-app/chatjs/tools/deep-research/tasks.tsx +2 -7
- package/templates/chat-app/chatjs/tools/generate-image/chatjs.json +4 -1
- package/templates/chat-app/chatjs/tools/generate-image/image-generation.ts +0 -1
- package/templates/chat-app/chatjs/tools/generate-image/renderer.tsx +39 -51
- package/templates/chat-app/chatjs/tools/generate-video/chatjs.json +4 -1
- package/templates/chat-app/chatjs/tools/generate-video/renderer.tsx +22 -11
- package/templates/chat-app/components/ai-elements/response.tsx +1 -1
- package/templates/chat-app/components/app-sidebar.tsx +26 -86
- package/templates/chat-app/components/artifact-actions.tsx +19 -0
- package/templates/chat-app/components/artifact-download-action.tsx +59 -0
- package/templates/chat-app/components/attachment-card.tsx +15 -9
- package/templates/chat-app/components/chat/chat-account.tsx +189 -0
- package/templates/chat-app/components/{controlled-chat-composer.tsx → chat/chat-composer.tsx} +6 -6
- package/templates/chat-app/components/chat/chat-conversation-screen.tsx +75 -0
- package/templates/chat-app/components/chat/chat-conversation.tsx +35 -0
- package/templates/chat-app/components/chat/chat-header.tsx +52 -0
- package/templates/chat-app/components/chat/chat-message-editor.tsx +24 -0
- package/templates/chat-app/components/chat/chat-navigation.tsx +11 -0
- package/templates/chat-app/components/chat/chat-sidebar.tsx +134 -0
- package/templates/chat-app/components/{eve/eve-messages.tsx → chat/chat-transcript.tsx} +7 -28
- package/templates/chat-app/components/chat/chat-workspace.tsx +19 -0
- package/templates/chat-app/components/chat/connected-chat-sidebar.tsx +8 -0
- package/templates/chat-app/components/chat-header-view.tsx +14 -13
- package/templates/chat-app/components/chat-slots.tsx +13 -3
- package/templates/chat-app/components/composer/active-tool.tsx +3 -1
- package/templates/chat-app/components/composer/composer-menu.tsx +4 -2
- package/templates/chat-app/components/composer/control.ts +4 -1
- package/templates/chat-app/components/composer/prompt-form.tsx +1 -1
- package/templates/chat-app/components/composer/tool-availability.tsx +8 -0
- package/templates/chat-app/components/composer/tool-controls.tsx +17 -50
- package/templates/chat-app/components/composer/tool-display.ts +3 -2
- package/templates/chat-app/components/eve/bash-output.tsx +33 -0
- package/templates/chat-app/components/eve/eve-chat-page.tsx +5 -26
- package/templates/chat-app/components/eve/eve-composer.tsx +11 -8
- package/templates/chat-app/components/eve/eve-conversation.tsx +237 -309
- package/templates/chat-app/components/eve/eve-deletion-provider.tsx +1 -1
- package/templates/chat-app/components/eve/eve-history-list.tsx +7 -3
- package/templates/chat-app/components/eve/eve-message-part.tsx +28 -22
- package/templates/chat-app/components/eve/eve-pending-input.tsx +54 -1
- package/templates/chat-app/components/eve/eve-runtime-provider.tsx +0 -5
- package/templates/chat-app/components/eve/new-conversation-view.tsx +7 -3
- package/templates/chat-app/components/file-artifact-card.tsx +37 -0
- package/templates/chat-app/components/header-actions.tsx +9 -2
- package/templates/chat-app/components/image-actions.tsx +93 -0
- package/templates/chat-app/components/internal-link.tsx +15 -2
- package/templates/chat-app/components/keyboard-shortcuts.tsx +8 -2
- package/templates/chat-app/components/part/tool-activity.tsx +1 -1
- package/templates/chat-app/components/part/tool-data.tsx +1 -1
- package/templates/chat-app/components/sidebar-user-nav.tsx +35 -198
- package/templates/chat-app/components/video-player.tsx +43 -0
- package/templates/chat-app/composer-controls.ts +0 -4
- package/templates/chat-app/docs/guest-sessions.md +1 -1
- package/templates/chat-app/instrumentation.ts +2 -6
- package/templates/chat-app/integrations/chat/models.ts +10 -0
- package/templates/chat-app/integrations/tools/catalog.ts +0 -3
- package/templates/chat-app/lib/ai/app-models.test.ts +13 -1
- package/templates/chat-app/lib/ai/app-models.ts +13 -3
- package/templates/chat-app/lib/ai/tool-context.ts +1 -14
- package/templates/chat-app/lib/ai/tool-renderer-registry.ts +10 -5
- package/templates/chat-app/lib/db/eve-current-copy.ts +13 -95
- package/templates/chat-app/lib/db/eve-deletion.ts +2 -61
- package/templates/chat-app/lib/db/eve-dispatch.ts +64 -18
- package/templates/chat-app/lib/db/eve-file-purge.ts +11 -145
- package/templates/chat-app/lib/db/eve-files.ts +11 -9
- package/templates/chat-app/lib/db/eve-orphaned-files.ts +3 -22
- package/templates/chat-app/lib/db/eve-queries.ts +32 -16
- package/templates/chat-app/lib/db/eve-workspace-deletion.ts +149 -0
- package/templates/chat-app/lib/db/migrate.ts +30 -0
- package/templates/chat-app/lib/db/migrations/0024_abandoned_toxin.sql +67 -0
- package/templates/chat-app/lib/db/migrations/0025_cloudy_thunderbolt.sql +1 -0
- package/templates/chat-app/lib/db/migrations/0026_loving_mesmero.sql +3 -0
- package/templates/chat-app/lib/db/migrations/0027_misty_stephen_strange.sql +1 -0
- package/templates/chat-app/lib/db/migrations/0028_faithful_hannibal_king.sql +12 -0
- package/templates/chat-app/lib/db/migrations/meta/0024_snapshot.json +4119 -0
- package/templates/chat-app/lib/db/migrations/meta/0025_snapshot.json +3988 -0
- package/templates/chat-app/lib/db/migrations/meta/0026_snapshot.json +3686 -0
- package/templates/chat-app/lib/db/migrations/meta/0027_snapshot.json +3596 -0
- package/templates/chat-app/lib/db/migrations/meta/0028_snapshot.json +2554 -0
- package/templates/chat-app/lib/db/migrations/meta/_journal.json +35 -0
- package/templates/chat-app/lib/db/schema.ts +1 -360
- package/templates/chat-app/lib/env-schema.ts +0 -7
- package/templates/chat-app/lib/eve/application-model.ts +56 -0
- package/templates/chat-app/lib/eve/bash-result.ts +22 -0
- package/templates/chat-app/lib/eve/branch-history.test.ts +59 -0
- package/templates/chat-app/lib/eve/branch-history.ts +19 -0
- package/templates/chat-app/lib/eve/channel-files.test.ts +14 -11
- package/templates/chat-app/lib/eve/channel-files.ts +2 -12
- package/templates/chat-app/lib/eve/completed-copy-source.test.ts +81 -17
- package/templates/chat-app/lib/eve/completed-copy-source.ts +2 -6
- package/templates/chat-app/lib/eve/connection-options.ts +7 -7
- package/templates/chat-app/lib/eve/contracts.test.ts +1 -1
- package/templates/chat-app/lib/eve/copy-seed.test.ts +17 -28
- package/templates/chat-app/lib/eve/copy-seed.ts +8 -34
- package/templates/chat-app/lib/eve/copy-transcript.test.ts +143 -47
- package/templates/chat-app/lib/eve/copy-transcript.ts +20 -101
- package/templates/chat-app/lib/eve/create-conversation-operation.test.ts +11 -31
- package/templates/chat-app/lib/eve/create-conversation-operation.ts +0 -10
- package/templates/chat-app/lib/eve/delete-local-conversation.test.ts +12 -20
- package/templates/chat-app/lib/eve/delete-local-conversation.ts +2 -8
- package/templates/chat-app/lib/eve/environment.test.ts +7 -0
- package/templates/chat-app/lib/eve/environment.ts +11 -0
- package/templates/chat-app/lib/eve/execute-conversation-creation.ts +3 -55
- package/templates/chat-app/lib/eve/gateway-auth.test.ts +2 -21
- package/templates/chat-app/lib/eve/gateway-auth.ts +7 -13
- package/templates/chat-app/lib/eve/generated-files.test.ts +1 -1
- package/templates/chat-app/lib/eve/generated-files.ts +2 -2
- package/templates/chat-app/lib/eve/installed-tools.test.ts +16 -9
- package/templates/chat-app/lib/eve/lifecycle/postgres/compatibility.ts +8 -5
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-payload-purge.ts +6 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-queue-fence.ts +2 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-queue-inventory.ts +2 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-queue-purge.ts +3 -2
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-resource-fence.ts +2 -8
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-run-inventory.ts +1 -1
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-stream-positions.ts +9 -4
- package/templates/chat-app/lib/eve/logical-chat.test.ts +4 -3
- package/templates/chat-app/lib/eve/logical-chat.ts +8 -8
- package/templates/chat-app/lib/eve/message-delivery.test.ts +1 -1
- package/templates/chat-app/lib/eve/message-display.test.ts +5 -5
- package/templates/chat-app/lib/eve/message-display.ts +31 -1
- package/templates/chat-app/lib/eve/message-tool-selection.test.ts +2 -2
- package/templates/chat-app/lib/eve/model-accounting.test.ts +28 -45
- package/templates/chat-app/lib/eve/model-accounting.ts +8 -54
- package/templates/chat-app/lib/eve/purge-files.ts +0 -13
- package/templates/chat-app/lib/eve/purge-local-resources.ts +4 -47
- package/templates/chat-app/lib/eve/readonly-message-types.ts +8 -3
- package/templates/chat-app/lib/eve/reconcile-workspace-turn.ts +2 -37
- package/templates/chat-app/lib/eve/response-group-lineage.test.ts +3 -3
- package/templates/chat-app/lib/eve/retire-session.test.ts +25 -8
- package/templates/chat-app/lib/eve/retire-session.ts +10 -4
- package/templates/chat-app/lib/eve/selected-tools.ts +7 -18
- package/templates/chat-app/lib/eve/server.test.ts +29 -3
- package/templates/chat-app/lib/eve/session-profile.test.ts +12 -9
- package/templates/chat-app/lib/eve/session-profile.ts +7 -4
- package/templates/chat-app/lib/eve/shared-messages.test.ts +3 -4
- package/templates/chat-app/lib/eve/shared-messages.ts +5 -2
- package/templates/chat-app/lib/eve/tool-accounting.test.ts +131 -0
- package/templates/chat-app/lib/eve/tool-accounting.ts +96 -0
- package/templates/chat-app/lib/eve/tool-availability.ts +4 -1
- package/templates/chat-app/lib/eve/tool-configuration.ts +29 -0
- package/templates/chat-app/lib/eve/tool-result.ts +1 -1
- package/templates/chat-app/lib/eve/turn-tools.ts +3 -12
- package/templates/chat-app/lib/eve/usage.test.ts +54 -39
- package/templates/chat-app/lib/eve/usage.ts +9 -1
- package/templates/chat-app/lib/eve/workspace-turn-evidence.test.ts +8 -6
- package/templates/chat-app/lib/eve/workspace-turn-evidence.ts +0 -5
- package/templates/chat-app/lib/required-credentials.test.ts +2 -2
- package/templates/chat-app/lib/tool-readiness.test.ts +69 -0
- package/templates/chat-app/lib/tool-readiness.ts +43 -0
- package/templates/chat-app/logo.svg +1 -1
- package/templates/chat-app/next.config.ts +1 -5
- package/templates/chat-app/oxlint.config.ts +3 -6
- package/templates/chat-app/package.json +4 -16
- package/templates/chat-app/providers/chat-models-provider.tsx +3 -3
- package/templates/chat-app/providers/default-model-provider.tsx +4 -4
- package/templates/chat-app/providers/session-context.ts +24 -0
- package/templates/chat-app/providers/session-provider.tsx +4 -21
- package/templates/chat-app/scripts/agent-status.ts +124 -0
- package/templates/chat-app/scripts/check-env.ts +0 -10
- package/templates/chat-app/scripts/dev-supervisor.mts +3 -30
- package/templates/chat-app/scripts/eve-setup.ts +3 -0
- package/templates/chat-app/tests/helpers/eve-dynamic-context.ts +2 -0
- package/templates/chat-app/tools/platform/research-updates-schema.ts +1 -20
- package/templates/chat-app/trpc/context.tsx +8 -0
- package/templates/chat-app/trpc/react.tsx +3 -4
- package/templates/chat-app/trpc/routers/eve.router.ts +2 -74
- package/templates/chat-app/vendor/workflow-world-postgres-5.1.1.tgz +0 -0
- package/templates/electron/icon.png +0 -0
- package/templates/electron/package.json +2 -1
- package/templates/electron/src/application.test.ts +347 -0
- package/templates/electron/src/application.ts +849 -0
- package/templates/electron/src/lib/auth-cookies.ts +1 -1
- package/templates/electron/src/main.test.ts +175 -0
- package/templates/electron/src/main.ts +5 -745
- package/templates/electron/src/squirrel-startup.ts +61 -0
- package/templates/chat-app/agent/hooks/persistent-sandbox.ts +0 -14
- package/templates/chat-app/app/api/agent-conversation-copies/route.test.ts +0 -190
- package/templates/chat-app/app/api/agent-conversation-copies/route.ts +0 -105
- package/templates/chat-app/chatjs/core/documents/compose-views.ts +0 -12
- package/templates/chat-app/chatjs/core/documents/contracts.ts +0 -91
- package/templates/chat-app/chatjs/core/documents/document-definition.test.ts +0 -60
- package/templates/chat-app/chatjs/core/documents/document-definition.ts +0 -55
- package/templates/chat-app/chatjs/core/documents/ui.ts +0 -67
- package/templates/chat-app/chatjs/generated/code-executor.ts +0 -6
- package/templates/chat-app/chatjs/generated/document-run.ts +0 -12
- package/templates/chat-app/chatjs/generated/document-ui.ts +0 -7
- package/templates/chat-app/chatjs/generated/documents.ts +0 -6
- package/templates/chat-app/chatjs/plugins/langfuse/chatjs.json +0 -14
- package/templates/chat-app/chatjs/plugins/langfuse/credentials.ts +0 -22
- package/templates/chat-app/chatjs/plugins/langfuse/instrumentation.ts +0 -22
- package/templates/chat-app/chatjs/plugins/langfuse/server-plugin.ts +0 -5
- package/templates/chat-app/chatjs/plugins/vercel-analytics/chatjs.json +0 -15
- package/templates/chat-app/chatjs/plugins/vercel-analytics/client-plugin.ts +0 -9
- package/templates/chat-app/chatjs/plugins/vercel-analytics/component.tsx +0 -5
- package/templates/chat-app/chatjs/plugins/vercel-speed-insights/chatjs.json +0 -15
- package/templates/chat-app/chatjs/plugins/vercel-speed-insights/client-plugin.ts +0 -9
- package/templates/chat-app/chatjs/plugins/vercel-speed-insights/component.tsx +0 -4
- package/templates/chat-app/chatjs/providers/sandbox/adapter.ts +0 -232
- package/templates/chat-app/chatjs/providers/sandbox/options.ts +0 -13
- package/templates/chat-app/chatjs/providers/sandbox/persistent.ts +0 -258
- package/templates/chat-app/chatjs/providers/sandbox/provider.ts +0 -27
- package/templates/chat-app/chatjs/providers/sandbox/vercel-sandbox-env.ts +0 -22
- package/templates/chat-app/chatjs/tools/_shared/code-execution/code-execution-chart.tsx +0 -83
- package/templates/chat-app/chatjs/tools/_shared/code-execution/interactive-chart-impl.tsx +0 -290
- package/templates/chat-app/chatjs/tools/_shared/code-execution/interactive-charts.tsx +0 -24
- package/templates/chat-app/chatjs/tools/_shared/code-execution/javascript.ts +0 -222
- package/templates/chat-app/chatjs/tools/_shared/code-execution/python.ts +0 -381
- package/templates/chat-app/chatjs/tools/_shared/code-execution/types.ts +0 -27
- package/templates/chat-app/chatjs/tools/code-documents/assistant-actions.ts +0 -16
- package/templates/chat-app/chatjs/tools/code-documents/chatjs.json +0 -20
- package/templates/chat-app/chatjs/tools/code-documents/configuration-schema.ts +0 -7
- package/templates/chat-app/chatjs/tools/code-documents/definition.ts +0 -9
- package/templates/chat-app/chatjs/tools/code-documents/document.tsx +0 -33
- package/templates/chat-app/chatjs/tools/code-documents/editor.tsx +0 -144
- package/templates/chat-app/chatjs/tools/code-documents/guidelines.ts +0 -15
- package/templates/chat-app/chatjs/tools/code-documents/tool.ts +0 -54
- package/templates/chat-app/chatjs/tools/code-execution/chatjs.json +0 -21
- package/templates/chat-app/chatjs/tools/code-execution/python.test.ts +0 -207
- package/templates/chat-app/chatjs/tools/code-execution/renderer.test.tsx +0 -142
- package/templates/chat-app/chatjs/tools/code-execution/renderer.tsx +0 -68
- package/templates/chat-app/chatjs/tools/code-execution/schemas.ts +0 -23
- package/templates/chat-app/chatjs/tools/code-execution/tool.ts +0 -93
- package/templates/chat-app/chatjs/tools/deep-research/agent.ts +0 -18
- package/templates/chat-app/chatjs/tools/deep-research/availability.ts +0 -23
- package/templates/chat-app/chatjs/tools/deep-research/configuration-schema.ts +0 -36
- package/templates/chat-app/chatjs/tools/deep-research/configuration.ts +0 -22
- package/templates/chat-app/chatjs/tools/deep-research/prompts.ts +0 -280
- package/templates/chat-app/chatjs/tools/deep-research/search-updates.ts +0 -76
- package/templates/chat-app/chatjs/tools/deep-research/steps.ts +0 -92
- package/templates/chat-app/chatjs/tools/delete-document/availability.ts +0 -13
- package/templates/chat-app/chatjs/tools/delete-document/chatjs.json +0 -9
- package/templates/chat-app/chatjs/tools/delete-document/execute.ts +0 -78
- package/templates/chat-app/chatjs/tools/delete-document/schemas.ts +0 -18
- package/templates/chat-app/chatjs/tools/delete-document/tool.ts +0 -49
- package/templates/chat-app/chatjs/tools/get-weather/chatjs.json +0 -14
- package/templates/chat-app/chatjs/tools/get-weather/definition.ts +0 -10
- package/templates/chat-app/chatjs/tools/get-weather/renderer.test.tsx +0 -57
- package/templates/chat-app/chatjs/tools/get-weather/renderer.tsx +0 -290
- package/templates/chat-app/chatjs/tools/get-weather/schemas.ts +0 -51
- package/templates/chat-app/chatjs/tools/get-weather/tool.ts +0 -34
- package/templates/chat-app/chatjs/tools/read-document/chatjs.json +0 -8
- package/templates/chat-app/chatjs/tools/read-document/tool.ts +0 -27
- package/templates/chat-app/chatjs/tools/retrieve-url/chatjs.json +0 -11
- package/templates/chat-app/chatjs/tools/retrieve-url/renderer.tsx +0 -200
- package/templates/chat-app/chatjs/tools/retrieve-url/retrieve-url-env.ts +0 -11
- package/templates/chat-app/chatjs/tools/retrieve-url/schemas.ts +0 -24
- package/templates/chat-app/chatjs/tools/retrieve-url/tool.test.ts +0 -144
- package/templates/chat-app/chatjs/tools/retrieve-url/tool.ts +0 -169
- package/templates/chat-app/chatjs/tools/saved-code-execution/chatjs.json +0 -12
- package/templates/chat-app/chatjs/tools/saved-code-execution/document-runs.ts +0 -31
- package/templates/chat-app/chatjs/tools/saved-code-execution/document.tsx +0 -84
- package/templates/chat-app/chatjs/tools/saved-code-execution/execute.ts +0 -126
- package/templates/chat-app/chatjs/tools/saved-code-execution/renderer.tsx +0 -30
- package/templates/chat-app/chatjs/tools/saved-code-execution/result.tsx +0 -42
- package/templates/chat-app/chatjs/tools/saved-code-execution/schemas.ts +0 -82
- package/templates/chat-app/chatjs/tools/saved-code-execution/tool.ts +0 -12
- package/templates/chat-app/chatjs/tools/sheet-documents/assistant-actions.ts +0 -22
- package/templates/chat-app/chatjs/tools/sheet-documents/chatjs.json +0 -20
- package/templates/chat-app/chatjs/tools/sheet-documents/configuration-schema.ts +0 -10
- package/templates/chat-app/chatjs/tools/sheet-documents/definition.ts +0 -9
- package/templates/chat-app/chatjs/tools/sheet-documents/document.tsx +0 -41
- package/templates/chat-app/chatjs/tools/sheet-documents/editor.tsx +0 -180
- package/templates/chat-app/chatjs/tools/sheet-documents/guidelines.ts +0 -5
- package/templates/chat-app/chatjs/tools/sheet-documents/tool.ts +0 -54
- package/templates/chat-app/chatjs/tools/tavily-search/chatjs.json +0 -19
- package/templates/chat-app/chatjs/tools/tavily-search/renderer.tsx +0 -25
- package/templates/chat-app/chatjs/tools/tavily-search/schemas.ts +0 -39
- package/templates/chat-app/chatjs/tools/tavily-search/tavily-search-env.ts +0 -11
- package/templates/chat-app/chatjs/tools/tavily-search/tool.test.ts +0 -114
- package/templates/chat-app/chatjs/tools/tavily-search/tool.ts +0 -143
- package/templates/chat-app/chatjs/tools/text-documents/assistant-actions.ts +0 -12
- package/templates/chat-app/chatjs/tools/text-documents/chatjs.json +0 -20
- package/templates/chat-app/chatjs/tools/text-documents/comparison.tsx +0 -72
- package/templates/chat-app/chatjs/tools/text-documents/configuration-schema.ts +0 -7
- package/templates/chat-app/chatjs/tools/text-documents/definition.ts +0 -9
- package/templates/chat-app/chatjs/tools/text-documents/diffview.tsx +0 -214
- package/templates/chat-app/chatjs/tools/text-documents/document.tsx +0 -46
- package/templates/chat-app/chatjs/tools/text-documents/editor-config.ts +0 -53
- package/templates/chat-app/chatjs/tools/text-documents/editor.tsx +0 -139
- package/templates/chat-app/chatjs/tools/text-documents/guidelines.ts +0 -7
- package/templates/chat-app/chatjs/tools/text-documents/tool.ts +0 -54
- package/templates/chat-app/chatjs/tools/word-count/chatjs.json +0 -14
- package/templates/chat-app/chatjs/tools/word-count/definition.ts +0 -10
- package/templates/chat-app/chatjs/tools/word-count/renderer.tsx +0 -64
- package/templates/chat-app/chatjs/tools/word-count/schemas.ts +0 -13
- package/templates/chat-app/chatjs/tools/word-count/tool.ts +0 -45
- package/templates/chat-app/components/chat/chat-layout.tsx +0 -129
- package/templates/chat-app/components/chat-sidebar-view.tsx +0 -53
- package/templates/chat-app/components/document-skeleton.tsx +0 -33
- package/templates/chat-app/components/eve/eve-artifact-layout.tsx +0 -722
- package/templates/chat-app/components/eve/eve-copy-button.tsx +0 -165
- package/templates/chat-app/components/eve/eve-document-actions.tsx +0 -124
- package/templates/chat-app/components/eve/eve-document-assistant-actions.tsx +0 -157
- package/templates/chat-app/components/eve/eve-document-body.tsx +0 -29
- package/templates/chat-app/components/eve/eve-document-context.tsx +0 -12
- package/templates/chat-app/components/eve/eve-document-preview.tsx +0 -128
- package/templates/chat-app/components/eve/eve-document-tool.tsx +0 -190
- package/templates/chat-app/components/eve/eve-history.tsx +0 -25
- package/templates/chat-app/components/eve/use-document-draft.ts +0 -281
- package/templates/chat-app/components/favicon-group.tsx +0 -50
- package/templates/chat-app/components/part/document-common.tsx +0 -152
- package/templates/chat-app/components/part/web-search.tsx +0 -75
- package/templates/chat-app/components/sandbox.tsx +0 -43
- package/templates/chat-app/components/source-badge.tsx +0 -50
- package/templates/chat-app/components/sources.tsx +0 -140
- package/templates/chat-app/hooks/use-artifact.tsx +0 -180
- package/templates/chat-app/integrations/documents/definitions.ts +0 -4
- package/templates/chat-app/integrations/documents/run.ts +0 -1
- package/templates/chat-app/integrations/documents/ui.ts +0 -4
- package/templates/chat-app/integrations/providers/sandbox.ts +0 -10
- package/templates/chat-app/integrations/tools/code-executor.ts +0 -1
- package/templates/chat-app/lib/ai/telemetry.ts +0 -4
- package/templates/chat-app/lib/artifacts/artifact-kind.ts +0 -8
- package/templates/chat-app/lib/artifacts/types.ts +0 -19
- package/templates/chat-app/lib/db/eve-code-sandboxes.ts +0 -197
- package/templates/chat-app/lib/db/eve-document-retention.ts +0 -36
- package/templates/chat-app/lib/db/eve-documents.ts +0 -700
- package/templates/chat-app/lib/eve/code-executor.ts +0 -32
- package/templates/chat-app/lib/eve/code-sandbox-name.test.ts +0 -60
- package/templates/chat-app/lib/eve/code-sandbox-name.ts +0 -56
- package/templates/chat-app/lib/eve/code-sandbox-ownership.ts +0 -88
- package/templates/chat-app/lib/eve/copy-input.ts +0 -11
- package/templates/chat-app/lib/eve/create-native-copy.ts +0 -38
- package/templates/chat-app/lib/eve/document-assistant-actions.test.ts +0 -48
- package/templates/chat-app/lib/eve/document-assistant-actions.ts +0 -22
- package/templates/chat-app/lib/eve/document-kind-lifecycle.test.ts +0 -148
- package/templates/chat-app/lib/eve/document-tools.ts +0 -164
- package/templates/chat-app/lib/eve/lifecycle/postgres/eve-sandbox-coverage-proof.ts +0 -140
- package/templates/chat-app/lib/eve/persistent-sandbox-store.ts +0 -621
- package/templates/chat-app/lib/eve/persistent-sandbox.test.ts +0 -209
- package/templates/chat-app/lib/eve/persistent-sandbox.ts +0 -328
- package/templates/chat-app/lib/eve/purge-code-sandboxes.test.ts +0 -125
- package/templates/chat-app/lib/eve/purge-code-sandboxes.ts +0 -83
- package/templates/chat-app/lib/eve/request-copy.test.ts +0 -95
- package/templates/chat-app/lib/eve/request-copy.ts +0 -129
- package/templates/chat-app/lib/eve/research-progress.test.ts +0 -95
- package/templates/chat-app/lib/eve/research-progress.ts +0 -42
- package/templates/chat-app/lib/eve/sandbox-environment.test.ts +0 -49
- package/templates/chat-app/lib/eve/sandbox-environment.ts +0 -29
- package/templates/chat-app/lib/eve/save-copy-operation.ts +0 -33
- package/templates/chat-app/lib/eve/save-document.ts +0 -87
- package/templates/chat-app/lib/eve/verify-local-coverage.ts +0 -84
- package/templates/chat-app/lib/eve/workspace-attachments.ts +0 -173
- package/templates/chat-app/lib/sandbox/runtime.ts +0 -12
- package/templates/chat-app/scripts/persistent-sandbox-cleanup.ts +0 -128
- package/templates/chat-app/scripts/stop-persistent-sandboxes.ts +0 -24
- package/templates/chat-app/tests/artifacts.e2e.ts +0 -7
- package/templates/chat-app/tools/platform/documents/types.ts +0 -11
- package/templates/chat-app/tools/platform/search-presentation.ts +0 -138
- package/templates/chat-app/tools/platform/steps/multi-query-web-search.test.ts +0 -45
- package/templates/chat-app/tools/platform/steps/multi-query-web-search.ts +0 -142
- package/templates/chat-app/tools/platform/steps/search-utils.ts +0 -26
- package/templates/chat-app/vendor/workflow-world-postgres-5.0.0-beta.40.tgz +0 -0
|
@@ -0,0 +1,849 @@
|
|
|
1
|
+
import {
|
|
2
|
+
APP_NAME,
|
|
3
|
+
APP_SCHEME,
|
|
4
|
+
APP_URL,
|
|
5
|
+
WINDOW_DEFAULTS,
|
|
6
|
+
ELECTRON_AUTH_COOKIE_PREFIX,
|
|
7
|
+
} from "./config";
|
|
8
|
+
import {
|
|
9
|
+
BrowserWindow,
|
|
10
|
+
Menu,
|
|
11
|
+
Tray,
|
|
12
|
+
app,
|
|
13
|
+
ipcMain,
|
|
14
|
+
nativeImage,
|
|
15
|
+
shell,
|
|
16
|
+
} from "electron";
|
|
17
|
+
import {
|
|
18
|
+
hasSessionCookie,
|
|
19
|
+
isBetterAuthCookieName,
|
|
20
|
+
isSessionTokenCookieName,
|
|
21
|
+
} from "./lib/auth-cookies";
|
|
22
|
+
import type { IpcMainInvokeEvent, MenuItemConstructorOptions } from "electron";
|
|
23
|
+
import { electronAuthClient } from "./lib/auth-client";
|
|
24
|
+
import { parseAuthRequestOptions } from "./auth-request-options";
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
27
|
+
|
|
28
|
+
const APP_ORIGIN = new URL(APP_URL).origin;
|
|
29
|
+
|
|
30
|
+
const AUTH_FLOW_ID_INCREMENT = 1;
|
|
31
|
+
const AUTH_REFRESH_DELAY_MS = 250;
|
|
32
|
+
const AUTH_SESSION_POLL_INTERVAL_MS = 250;
|
|
33
|
+
const AUTH_SESSION_TIMEOUT_MS = 8000;
|
|
34
|
+
const COOKIE_NAME_START_INDEX = 0;
|
|
35
|
+
const COOKIE_SEPARATOR_LENGTH = 1;
|
|
36
|
+
const DEV_ENTRY_ARG_INDEX = 1;
|
|
37
|
+
const DEV_ENTRY_MIN_ARGS = 2;
|
|
38
|
+
const EMPTY_WINDOW_COUNT = 0;
|
|
39
|
+
const SQUIRREL_FIRST_RUN_DELAY_MS = 10_000;
|
|
40
|
+
|
|
41
|
+
// Disable GPU acceleration in WSL / headless environments to prevent D3D12 crashes.
|
|
42
|
+
const isWslOrHeadless =
|
|
43
|
+
(process.env.WSL_DISTRO_NAME ?? "") !== "" ||
|
|
44
|
+
(process.env.WSLENV ?? "") !== "";
|
|
45
|
+
if (isWslOrHeadless) {
|
|
46
|
+
app.disableHardwareAcceleration();
|
|
47
|
+
app.commandLine.appendSwitch("disable-gpu");
|
|
48
|
+
app.commandLine.appendSwitch("disable-software-rasterizer");
|
|
49
|
+
}
|
|
50
|
+
let isQuitting = false;
|
|
51
|
+
let mainWindow: BrowserWindow | null = null;
|
|
52
|
+
let tray: Tray | null = null;
|
|
53
|
+
let pendingAuthRefreshTimer: ReturnType<typeof setTimeout> | null = null;
|
|
54
|
+
let currentAuthOverlayMessage: string | null = null;
|
|
55
|
+
let isAuthFlowInProgress = false;
|
|
56
|
+
let currentAuthFlowId = 0;
|
|
57
|
+
const gotSingleInstanceLock = app.requestSingleInstanceLock();
|
|
58
|
+
|
|
59
|
+
interface AuthOverlayWindow {
|
|
60
|
+
readonly isDestroyed: BrowserWindow["isDestroyed"];
|
|
61
|
+
readonly webContents: {
|
|
62
|
+
readonly executeJavaScript: Electron.WebContents["executeJavaScript"];
|
|
63
|
+
readonly isLoadingMainFrame: Electron.WebContents["isLoadingMainFrame"];
|
|
64
|
+
readonly once: Electron.WebContents["once"];
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface AuthSessionWindow {
|
|
69
|
+
readonly webContents: {
|
|
70
|
+
readonly session: {
|
|
71
|
+
readonly cookies: {
|
|
72
|
+
readonly get: Electron.Cookies["get"];
|
|
73
|
+
readonly remove: Electron.Cookies["remove"];
|
|
74
|
+
readonly set: Electron.Cookies["set"];
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type AuthRendererState =
|
|
81
|
+
| {
|
|
82
|
+
readonly status: "idle";
|
|
83
|
+
readonly message: null;
|
|
84
|
+
}
|
|
85
|
+
| {
|
|
86
|
+
readonly status: "awaiting-browser" | "finishing" | "timed-out" | "error";
|
|
87
|
+
readonly message: string;
|
|
88
|
+
readonly detail?: string | null;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
let currentAuthState: AuthRendererState = {
|
|
92
|
+
message: null,
|
|
93
|
+
status: "idle",
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (!gotSingleInstanceLock) {
|
|
97
|
+
app.quit();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const registerProtocolClient = (): void => {
|
|
101
|
+
if (process.defaultApp) {
|
|
102
|
+
if (
|
|
103
|
+
process.platform === "win32" &&
|
|
104
|
+
process.argv.length >= DEV_ENTRY_MIN_ARGS
|
|
105
|
+
) {
|
|
106
|
+
app.setAsDefaultProtocolClient(APP_SCHEME, process.execPath, [
|
|
107
|
+
path.resolve(process.argv[DEV_ENTRY_ARG_INDEX]),
|
|
108
|
+
]);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.info(
|
|
113
|
+
`[electron-main] skipping ${APP_SCHEME} protocol registration in development on ${process.platform}; packaged builds handle deep links normally.`
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
app.setAsDefaultProtocolClient(APP_SCHEME);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const getAuthErrorDetail = (error: unknown): string => {
|
|
122
|
+
if (error instanceof Error) {
|
|
123
|
+
return error.message;
|
|
124
|
+
}
|
|
125
|
+
return String(error);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const parseWebUrl = (url: string): URL | null => {
|
|
129
|
+
const parsed = URL.parse(url);
|
|
130
|
+
return parsed?.protocol === "https:" || parsed?.protocol === "http:"
|
|
131
|
+
? parsed
|
|
132
|
+
: null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const isAppUrl = (url: string): boolean =>
|
|
136
|
+
parseWebUrl(url)?.origin === APP_ORIGIN;
|
|
137
|
+
|
|
138
|
+
const isAppMainFrame = (
|
|
139
|
+
contents: Electron.WebContents,
|
|
140
|
+
frame: Electron.WebFrameMain | null | undefined
|
|
141
|
+
): boolean =>
|
|
142
|
+
frame !== null &&
|
|
143
|
+
frame !== undefined &&
|
|
144
|
+
frame === contents.mainFrame &&
|
|
145
|
+
frame.origin === APP_ORIGIN &&
|
|
146
|
+
isAppUrl(frame.url);
|
|
147
|
+
|
|
148
|
+
const assertAppAuthSender = ({
|
|
149
|
+
sender,
|
|
150
|
+
senderFrame,
|
|
151
|
+
}: IpcMainInvokeEvent): void => {
|
|
152
|
+
if (
|
|
153
|
+
!mainWindow ||
|
|
154
|
+
mainWindow.isDestroyed() ||
|
|
155
|
+
sender !== mainWindow.webContents ||
|
|
156
|
+
!isAppMainFrame(sender, senderFrame)
|
|
157
|
+
) {
|
|
158
|
+
throw new Error("Untrusted sender for desktop auth IPC");
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const showMainWindow = (): void => {
|
|
163
|
+
if (!mainWindow || mainWindow.isDestroyed()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (mainWindow.isMinimized()) {
|
|
167
|
+
mainWindow.restore();
|
|
168
|
+
}
|
|
169
|
+
mainWindow.show();
|
|
170
|
+
mainWindow.focus();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const broadcastAuthState = (): void => {
|
|
174
|
+
if (!mainWindow || mainWindow.isDestroyed()) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
mainWindow.webContents.send("chatjs:auth-state-changed", currentAuthState);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const setAuthOverlay = async (
|
|
182
|
+
win: AuthOverlayWindow | null,
|
|
183
|
+
options:
|
|
184
|
+
| {
|
|
185
|
+
readonly visible: false;
|
|
186
|
+
}
|
|
187
|
+
| {
|
|
188
|
+
readonly visible: true;
|
|
189
|
+
readonly message: string;
|
|
190
|
+
}
|
|
191
|
+
): Promise<void> => {
|
|
192
|
+
if (!win || win.isDestroyed()) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
currentAuthOverlayMessage = options.visible ? options.message : null;
|
|
197
|
+
|
|
198
|
+
const script = options.visible
|
|
199
|
+
? `
|
|
200
|
+
(() => {
|
|
201
|
+
const message = ${JSON.stringify(options.message)};
|
|
202
|
+
const existing = document.getElementById("chatjs-electron-auth-overlay");
|
|
203
|
+
if (existing) existing.remove();
|
|
204
|
+
const styles = getComputedStyle(document.documentElement);
|
|
205
|
+
const background = styles.getPropertyValue("--background").trim() || "hsl(0 0% 97.0392%)";
|
|
206
|
+
const foreground = styles.getPropertyValue("--foreground").trim() || "hsl(0 0% 20%)";
|
|
207
|
+
const card = styles.getPropertyValue("--card").trim() || "hsl(0 0% 100%)";
|
|
208
|
+
const border = styles.getPropertyValue("--border").trim() || "hsl(220 13% 91%)";
|
|
209
|
+
const mutedForeground =
|
|
210
|
+
styles.getPropertyValue("--muted-foreground").trim() || "hsl(220 8.9362% 46.0784%)";
|
|
211
|
+
const primary = styles.getPropertyValue("--primary").trim() || "hsl(217.2193 91.2195% 59.8039%)";
|
|
212
|
+
const radius = styles.getPropertyValue("--radius").trim() || "0.75rem";
|
|
213
|
+
const overlay = document.createElement("div");
|
|
214
|
+
overlay.id = "chatjs-electron-auth-overlay";
|
|
215
|
+
overlay.style.position = "fixed";
|
|
216
|
+
overlay.style.inset = "0";
|
|
217
|
+
overlay.style.zIndex = "999999";
|
|
218
|
+
overlay.style.display = "flex";
|
|
219
|
+
overlay.style.alignItems = "center";
|
|
220
|
+
overlay.style.justifyContent = "center";
|
|
221
|
+
overlay.style.background = "color-mix(in srgb, " + background + " 82%, transparent)";
|
|
222
|
+
overlay.style.backdropFilter = "blur(10px)";
|
|
223
|
+
overlay.style.webkitBackdropFilter = "blur(10px)";
|
|
224
|
+
overlay.innerHTML = \`
|
|
225
|
+
<div style="display:flex;min-width:320px;max-width:360px;flex-direction:column;align-items:center;gap:14px;padding:28px 32px;border:1px solid \${border};border-radius:calc(\${radius} + 4px);background:\${card};box-shadow:0 18px 50px rgba(15,23,42,0.12);font-family:var(--font-geist, ui-sans-serif, system-ui, sans-serif);color:\${foreground};">
|
|
226
|
+
<div style="width:28px;height:28px;border-radius:9999px;border:3px solid color-mix(in srgb, \${mutedForeground} 28%, transparent);border-top-color:\${primary};animation:chatjs-electron-spin 0.8s linear infinite;"></div>
|
|
227
|
+
<div id="chatjs-electron-auth-overlay-message" style="font-size:15px;font-weight:600;"></div>
|
|
228
|
+
<div style="font-size:13px;color:\${mutedForeground};text-align:center;">You can return here once the browser finishes.</div>
|
|
229
|
+
</div>
|
|
230
|
+
\`;
|
|
231
|
+
overlay.querySelector("#chatjs-electron-auth-overlay-message").textContent = message;
|
|
232
|
+
if (!document.getElementById("chatjs-electron-auth-overlay-style")) {
|
|
233
|
+
const style = document.createElement("style");
|
|
234
|
+
style.id = "chatjs-electron-auth-overlay-style";
|
|
235
|
+
style.textContent = "@keyframes chatjs-electron-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }";
|
|
236
|
+
document.head.appendChild(style);
|
|
237
|
+
}
|
|
238
|
+
document.body.appendChild(overlay);
|
|
239
|
+
})();
|
|
240
|
+
`
|
|
241
|
+
: `
|
|
242
|
+
(() => {
|
|
243
|
+
document.getElementById("chatjs-electron-auth-overlay")?.remove();
|
|
244
|
+
})();
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
if (win.webContents.isLoadingMainFrame()) {
|
|
249
|
+
win.webContents.once("did-finish-load", (): void => {
|
|
250
|
+
if (options.visible && currentAuthOverlayMessage !== options.message) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
void (async (): Promise<void> => {
|
|
254
|
+
try {
|
|
255
|
+
await win.webContents.executeJavaScript(script);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.warn(
|
|
258
|
+
"[electron-main] failed to update auth overlay",
|
|
259
|
+
error
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
})();
|
|
263
|
+
});
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
await win.webContents.executeJavaScript(script);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.warn("[electron-main] failed to update auth overlay", error);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const setAuthState = async (nextState: AuthRendererState): Promise<void> => {
|
|
274
|
+
currentAuthState = nextState;
|
|
275
|
+
broadcastAuthState();
|
|
276
|
+
|
|
277
|
+
if (
|
|
278
|
+
nextState.status === "idle" ||
|
|
279
|
+
nextState.status === "timed-out" ||
|
|
280
|
+
nextState.status === "error"
|
|
281
|
+
) {
|
|
282
|
+
await setAuthOverlay(mainWindow, { visible: false });
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (!mainWindow || mainWindow.isDestroyed()) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Let the renderer-owned shadcn overlay handle normal auth states when the
|
|
291
|
+
// app page is already loaded. Keep the main-process DOM overlay only as a
|
|
292
|
+
// fallback during main-frame loads, where React cannot render yet.
|
|
293
|
+
if (mainWindow.webContents.isLoadingMainFrame()) {
|
|
294
|
+
await setAuthOverlay(mainWindow, {
|
|
295
|
+
message: nextState.message,
|
|
296
|
+
visible: true,
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
await setAuthOverlay(mainWindow, { visible: false });
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const resetAuthFlow = async (): Promise<void> => {
|
|
305
|
+
if (pendingAuthRefreshTimer) {
|
|
306
|
+
clearTimeout(pendingAuthRefreshTimer);
|
|
307
|
+
pendingAuthRefreshTimer = null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
isAuthFlowInProgress = false;
|
|
311
|
+
currentAuthFlowId += AUTH_FLOW_ID_INCREMENT;
|
|
312
|
+
|
|
313
|
+
await setAuthState({
|
|
314
|
+
message: null,
|
|
315
|
+
status: "idle",
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// Configure the SDK before readiness. The application handles deep links and
|
|
320
|
+
// registers its own IPC handlers so every auth invocation checks the sender.
|
|
321
|
+
electronAuthClient.setupMain({
|
|
322
|
+
bridges: false,
|
|
323
|
+
getWindow: () => mainWindow,
|
|
324
|
+
scheme: false,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
registerProtocolClient();
|
|
328
|
+
|
|
329
|
+
ipcMain.handle(
|
|
330
|
+
"better-auth:requestAuth",
|
|
331
|
+
async (event: IpcMainInvokeEvent, options: unknown): Promise<void> => {
|
|
332
|
+
assertAppAuthSender(event);
|
|
333
|
+
|
|
334
|
+
if (isAuthFlowInProgress) {
|
|
335
|
+
showMainWindow();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
isAuthFlowInProgress = true;
|
|
340
|
+
currentAuthFlowId += AUTH_FLOW_ID_INCREMENT;
|
|
341
|
+
|
|
342
|
+
await setAuthState({
|
|
343
|
+
message: "Waiting for sign-in in your browser...",
|
|
344
|
+
status: "awaiting-browser",
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
try {
|
|
348
|
+
await electronAuthClient.requestAuth(parseAuthRequestOptions(options));
|
|
349
|
+
} catch (error) {
|
|
350
|
+
isAuthFlowInProgress = false;
|
|
351
|
+
await setAuthState({
|
|
352
|
+
detail: getAuthErrorDetail(error),
|
|
353
|
+
message: "Couldn't open the browser sign-in flow.",
|
|
354
|
+
status: "error",
|
|
355
|
+
});
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
ipcMain.handle(
|
|
362
|
+
"chatjs:cancel-auth-flow",
|
|
363
|
+
async (event: IpcMainInvokeEvent): Promise<void> => {
|
|
364
|
+
assertAppAuthSender(event);
|
|
365
|
+
await resetAuthFlow();
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
const syncAuthSessionCookies = async (
|
|
369
|
+
win?: AuthSessionWindow | null
|
|
370
|
+
): Promise<void> => {
|
|
371
|
+
const targetWindow = win ?? mainWindow;
|
|
372
|
+
if (!targetWindow) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const targetSession = targetWindow.webContents.session;
|
|
376
|
+
|
|
377
|
+
const url = new URL(APP_URL);
|
|
378
|
+
const existingCookies = await targetSession.cookies.get({ url: url.origin });
|
|
379
|
+
|
|
380
|
+
await Promise.all(
|
|
381
|
+
existingCookies
|
|
382
|
+
.filter((cookie: Readonly<Electron.Cookie>): boolean =>
|
|
383
|
+
isBetterAuthCookieName(cookie.name, ELECTRON_AUTH_COOKIE_PREFIX)
|
|
384
|
+
)
|
|
385
|
+
.map(async (cookie: Readonly<Electron.Cookie>): Promise<void> => {
|
|
386
|
+
await targetSession.cookies.remove(url.origin, cookie.name);
|
|
387
|
+
})
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
const cookieHeader = electronAuthClient.getCookie();
|
|
391
|
+
|
|
392
|
+
if (!cookieHeader) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const cookies = cookieHeader
|
|
397
|
+
.split(/;\s*/u)
|
|
398
|
+
.map((entry: string): Readonly<{ name: string; value: string }> | null => {
|
|
399
|
+
const index = entry.indexOf("=");
|
|
400
|
+
if (index < COOKIE_SEPARATOR_LENGTH) {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return {
|
|
405
|
+
name: entry.slice(COOKIE_NAME_START_INDEX, index),
|
|
406
|
+
value: entry.slice(index + COOKIE_SEPARATOR_LENGTH),
|
|
407
|
+
};
|
|
408
|
+
})
|
|
409
|
+
.filter((cookie) => cookie !== null)
|
|
410
|
+
.filter((cookie: Readonly<{ name: string; value: string }>): boolean =>
|
|
411
|
+
isBetterAuthCookieName(cookie.name, ELECTRON_AUTH_COOKIE_PREFIX)
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
await Promise.all(
|
|
415
|
+
cookies.map(
|
|
416
|
+
async (
|
|
417
|
+
cookie: Readonly<{ name: string; value: string }>
|
|
418
|
+
): Promise<void> => {
|
|
419
|
+
await targetSession.cookies.set({
|
|
420
|
+
httpOnly: isSessionTokenCookieName(cookie.name),
|
|
421
|
+
name: cookie.name,
|
|
422
|
+
path: "/",
|
|
423
|
+
secure: url.protocol === "https:",
|
|
424
|
+
url: url.origin,
|
|
425
|
+
value: cookie.value,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
)
|
|
429
|
+
);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
ipcMain.handle("better-auth:signOut", async (event: IpcMainInvokeEvent) => {
|
|
433
|
+
assertAppAuthSender(event);
|
|
434
|
+
const result = await electronAuthClient.signOut();
|
|
435
|
+
await syncAuthSessionCookies();
|
|
436
|
+
return result;
|
|
437
|
+
});
|
|
438
|
+
ipcMain.handle("better-auth:getUser", async (event: IpcMainInvokeEvent) => {
|
|
439
|
+
assertAppAuthSender(event);
|
|
440
|
+
const sessionResult = await electronAuthClient.getSession();
|
|
441
|
+
const sessionData = sessionResult.data;
|
|
442
|
+
if (!sessionData) {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
return sessionData.user ?? null;
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const getAppAssetPath = (...segments: readonly string[]): string =>
|
|
449
|
+
path.join(app.getAppPath(), ...segments);
|
|
450
|
+
|
|
451
|
+
const authenticateFromDeepLink = async (url: string): Promise<boolean> => {
|
|
452
|
+
try {
|
|
453
|
+
if (!isAuthFlowInProgress) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const parsed = new URL(url);
|
|
458
|
+
if (!parsed.hash.startsWith("#token=")) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const token = parsed.hash.slice("#token=".length);
|
|
463
|
+
if (token === "") {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
await setAuthState({
|
|
468
|
+
message: "Finishing sign-in...",
|
|
469
|
+
status: "finishing",
|
|
470
|
+
});
|
|
471
|
+
await electronAuthClient.authenticate({ token });
|
|
472
|
+
return true;
|
|
473
|
+
} catch (error) {
|
|
474
|
+
console.error("[electron-main] deep link authentication failed", error);
|
|
475
|
+
isAuthFlowInProgress = false;
|
|
476
|
+
await setAuthState({
|
|
477
|
+
detail: getAuthErrorDetail(error),
|
|
478
|
+
message: "We couldn't finish sign-in automatically.",
|
|
479
|
+
status: "error",
|
|
480
|
+
});
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const waitForElectronSession = async (
|
|
486
|
+
timeoutMs = AUTH_SESSION_TIMEOUT_MS
|
|
487
|
+
): Promise<boolean> => {
|
|
488
|
+
const deadline = performance.now() + timeoutMs;
|
|
489
|
+
// Use the same deadline for every request, including response body reads.
|
|
490
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
491
|
+
|
|
492
|
+
while (!signal.aborted && performance.now() < deadline) {
|
|
493
|
+
const cookieHeader = electronAuthClient.getCookie();
|
|
494
|
+
const hasCookie = hasSessionCookie(cookieHeader);
|
|
495
|
+
|
|
496
|
+
try {
|
|
497
|
+
// oxlint-disable-next-line no-await-in-loop -- Poll sequentially until the native cookie and server session agree.
|
|
498
|
+
const sessionResult = await electronAuthClient.getSession({
|
|
499
|
+
fetchOptions: { signal },
|
|
500
|
+
});
|
|
501
|
+
const sessionData = sessionResult.data;
|
|
502
|
+
const hasUser = Boolean(sessionData && sessionData.user);
|
|
503
|
+
|
|
504
|
+
if (hasCookie && hasUser && performance.now() < deadline) {
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
} catch (error) {
|
|
508
|
+
if (signal.aborted) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
console.warn("[electron-main] session check failed while waiting", error);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const remainingMs = deadline - performance.now();
|
|
515
|
+
if (remainingMs <= 0) {
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
// oxlint-disable-next-line no-await-in-loop -- Back off between session polls rather than issue overlapping requests.
|
|
519
|
+
await sleep(Math.min(AUTH_SESSION_POLL_INTERVAL_MS, remainingMs));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return false;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
const scheduleAuthRefresh = (): void => {
|
|
526
|
+
const targetWindow = mainWindow;
|
|
527
|
+
const authFlowId = currentAuthFlowId;
|
|
528
|
+
|
|
529
|
+
if (!targetWindow) {
|
|
530
|
+
console.warn("[electron-main] scheduleAuthRefresh without a window");
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (pendingAuthRefreshTimer) {
|
|
535
|
+
clearTimeout(pendingAuthRefreshTimer);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
targetWindow.show();
|
|
539
|
+
targetWindow.focus();
|
|
540
|
+
|
|
541
|
+
pendingAuthRefreshTimer = setTimeout((): void => {
|
|
542
|
+
void (async (): Promise<void> => {
|
|
543
|
+
try {
|
|
544
|
+
const ready = await waitForElectronSession();
|
|
545
|
+
if (authFlowId !== currentAuthFlowId) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (!ready) {
|
|
550
|
+
isAuthFlowInProgress = false;
|
|
551
|
+
await setAuthState({
|
|
552
|
+
detail: "Please try the browser flow again.",
|
|
553
|
+
message:
|
|
554
|
+
"Still waiting for the desktop app to finish signing in...",
|
|
555
|
+
status: "timed-out",
|
|
556
|
+
});
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
await syncAuthSessionCookies(targetWindow);
|
|
561
|
+
if (authFlowId !== currentAuthFlowId) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
isAuthFlowInProgress = false;
|
|
565
|
+
await setAuthState({
|
|
566
|
+
message: null,
|
|
567
|
+
status: "idle",
|
|
568
|
+
});
|
|
569
|
+
} catch (error) {
|
|
570
|
+
if (authFlowId !== currentAuthFlowId) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
console.error("[electron-main] auth refresh failed", error);
|
|
574
|
+
isAuthFlowInProgress = false;
|
|
575
|
+
await setAuthState({
|
|
576
|
+
detail: getAuthErrorDetail(error),
|
|
577
|
+
message: "Sign-in refresh failed.",
|
|
578
|
+
status: "error",
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
})();
|
|
582
|
+
pendingAuthRefreshTimer = null;
|
|
583
|
+
}, AUTH_REFRESH_DELAY_MS);
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
const createWindow = (): BrowserWindow => {
|
|
587
|
+
const win = new BrowserWindow({
|
|
588
|
+
...WINDOW_DEFAULTS,
|
|
589
|
+
...(process.platform === "darwin" || process.platform === "win32"
|
|
590
|
+
? { titleBarStyle: "default" as const }
|
|
591
|
+
: { titleBarOverlay: true, titleBarStyle: "hidden" as const }),
|
|
592
|
+
webPreferences: {
|
|
593
|
+
contextIsolation: true,
|
|
594
|
+
nodeIntegration: false,
|
|
595
|
+
preload: getAppAssetPath("dist", "preload.js"),
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
if (process.platform === "win32" || process.platform === "linux") {
|
|
600
|
+
win.removeMenu();
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
win.webContents.on("will-navigate", (event) => {
|
|
604
|
+
const destination = parseWebUrl(event.url);
|
|
605
|
+
if (destination?.origin === APP_ORIGIN) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
event.preventDefault();
|
|
609
|
+
|
|
610
|
+
// Connector authorization navigates directly from the app to the provider.
|
|
611
|
+
if (destination && isAppMainFrame(win.webContents, event.initiator)) {
|
|
612
|
+
void (async (): Promise<void> => {
|
|
613
|
+
try {
|
|
614
|
+
await shell.openExternal(destination.href);
|
|
615
|
+
} catch (error) {
|
|
616
|
+
console.warn("[electron-main] failed to open link in browser", error);
|
|
617
|
+
}
|
|
618
|
+
})();
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
win.webContents.on("will-redirect", (event) => {
|
|
622
|
+
if (event.isMainFrame && !isAppUrl(event.url)) {
|
|
623
|
+
event.preventDefault();
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
// Avoid touching encrypted auth storage on app launch. On macOS this can
|
|
628
|
+
// trigger an immediate Keychain prompt before the window even loads, which
|
|
629
|
+
// feels like a crash. Session sync still runs after explicit auth events.
|
|
630
|
+
void win.loadURL(APP_URL);
|
|
631
|
+
|
|
632
|
+
win.webContents.on("did-finish-load", (): void => {
|
|
633
|
+
const overlayMessage = currentAuthOverlayMessage;
|
|
634
|
+
if (overlayMessage !== null && overlayMessage !== "") {
|
|
635
|
+
void setAuthOverlay(win, {
|
|
636
|
+
message: overlayMessage,
|
|
637
|
+
visible: true,
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
// Open all new-window requests (including OAuth popups) in the default browser.
|
|
643
|
+
win.webContents.setWindowOpenHandler(({ url }: Readonly<{ url: string }>) => {
|
|
644
|
+
void shell.openExternal(url);
|
|
645
|
+
return { action: "deny" };
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
// Minimize to tray on close
|
|
649
|
+
win.on("close", (event: Pick<Electron.Event, "preventDefault">): void => {
|
|
650
|
+
if (!isQuitting) {
|
|
651
|
+
event.preventDefault();
|
|
652
|
+
win.hide();
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
if (!app.isPackaged) {
|
|
657
|
+
win.webContents.openDevTools({ mode: "detach" });
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return win;
|
|
661
|
+
};
|
|
662
|
+
const createTray = (): Tray => {
|
|
663
|
+
const iconPath = getAppAssetPath("build", "icon.png");
|
|
664
|
+
const trayIcon = nativeImage.createFromPath(iconPath);
|
|
665
|
+
const trayInstance = new Tray(trayIcon.resize({ height: 16, width: 16 }));
|
|
666
|
+
|
|
667
|
+
const contextMenu = Menu.buildFromTemplate([
|
|
668
|
+
{
|
|
669
|
+
click: (): void => {
|
|
670
|
+
if (mainWindow) {
|
|
671
|
+
mainWindow.show();
|
|
672
|
+
}
|
|
673
|
+
if (mainWindow) {
|
|
674
|
+
mainWindow.focus();
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
label: `Show ${APP_NAME}`,
|
|
678
|
+
},
|
|
679
|
+
{ type: "separator" },
|
|
680
|
+
{
|
|
681
|
+
click: (): void => {
|
|
682
|
+
isQuitting = true;
|
|
683
|
+
app.quit();
|
|
684
|
+
},
|
|
685
|
+
label: "Quit",
|
|
686
|
+
},
|
|
687
|
+
]);
|
|
688
|
+
|
|
689
|
+
trayInstance.setToolTip(APP_NAME);
|
|
690
|
+
trayInstance.setContextMenu(contextMenu);
|
|
691
|
+
|
|
692
|
+
trayInstance.on("click", (): void => {
|
|
693
|
+
if (mainWindow && mainWindow.isVisible()) {
|
|
694
|
+
mainWindow.hide();
|
|
695
|
+
} else {
|
|
696
|
+
if (mainWindow) {
|
|
697
|
+
mainWindow.show();
|
|
698
|
+
}
|
|
699
|
+
if (mainWindow) {
|
|
700
|
+
mainWindow.focus();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
return trayInstance;
|
|
706
|
+
};
|
|
707
|
+
const setupApplicationMenu = (): void => {
|
|
708
|
+
if (process.platform !== "darwin") {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const template: MenuItemConstructorOptions[] = [
|
|
713
|
+
{
|
|
714
|
+
label: APP_NAME,
|
|
715
|
+
submenu: [
|
|
716
|
+
{ role: "about" },
|
|
717
|
+
{ type: "separator" },
|
|
718
|
+
{ role: "services" },
|
|
719
|
+
{ type: "separator" },
|
|
720
|
+
{ role: "hide" },
|
|
721
|
+
{ role: "hideOthers" },
|
|
722
|
+
{ role: "unhide" },
|
|
723
|
+
{ type: "separator" },
|
|
724
|
+
{ role: "quit" },
|
|
725
|
+
],
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
role: "editMenu",
|
|
729
|
+
},
|
|
730
|
+
...(app.isPackaged
|
|
731
|
+
? []
|
|
732
|
+
: ([
|
|
733
|
+
{
|
|
734
|
+
role: "viewMenu",
|
|
735
|
+
submenu: [
|
|
736
|
+
{ role: "reload" },
|
|
737
|
+
{ role: "forceReload" },
|
|
738
|
+
{ type: "separator" },
|
|
739
|
+
{ role: "toggleDevTools" },
|
|
740
|
+
],
|
|
741
|
+
},
|
|
742
|
+
] satisfies MenuItemConstructorOptions[])),
|
|
743
|
+
{
|
|
744
|
+
role: "windowMenu",
|
|
745
|
+
},
|
|
746
|
+
];
|
|
747
|
+
|
|
748
|
+
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
const setupAutoUpdater = async (): Promise<void> => {
|
|
752
|
+
if (!app.isPackaged) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
try {
|
|
757
|
+
if (
|
|
758
|
+
process.platform === "win32" &&
|
|
759
|
+
process.argv.includes("--squirrel-firstrun")
|
|
760
|
+
) {
|
|
761
|
+
// Squirrel holds the updater lock briefly after installation. Only delay
|
|
762
|
+
// the update check; the window and tray have already started normally.
|
|
763
|
+
await sleep(SQUIRREL_FIRST_RUN_DELAY_MS);
|
|
764
|
+
}
|
|
765
|
+
const { updateElectronApp } = await import("update-electron-app");
|
|
766
|
+
|
|
767
|
+
updateElectronApp({
|
|
768
|
+
logger: console,
|
|
769
|
+
notifyUser: true,
|
|
770
|
+
updateInterval: "1 hour",
|
|
771
|
+
});
|
|
772
|
+
} catch (error) {
|
|
773
|
+
console.warn(
|
|
774
|
+
"[electron-main] update-electron-app is unavailable; automatic updates are disabled.",
|
|
775
|
+
error
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
ipcMain.handle(
|
|
781
|
+
"chatjs:sync-auth-session",
|
|
782
|
+
async (event: IpcMainInvokeEvent): Promise<void> => {
|
|
783
|
+
assertAppAuthSender(event);
|
|
784
|
+
await syncAuthSessionCookies();
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
ipcMain.handle("chatjs:get-auth-state", (event: IpcMainInvokeEvent) => {
|
|
788
|
+
assertAppAuthSender(event);
|
|
789
|
+
return currentAuthState;
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
void (async (): Promise<void> => {
|
|
793
|
+
await app.whenReady();
|
|
794
|
+
app.setName(APP_NAME);
|
|
795
|
+
setupApplicationMenu();
|
|
796
|
+
mainWindow = createWindow();
|
|
797
|
+
tray = createTray();
|
|
798
|
+
void setupAutoUpdater();
|
|
799
|
+
|
|
800
|
+
app.on("activate", (): void => {
|
|
801
|
+
if (BrowserWindow.getAllWindows().length === EMPTY_WINDOW_COUNT) {
|
|
802
|
+
mainWindow = createWindow();
|
|
803
|
+
} else if (mainWindow) {
|
|
804
|
+
mainWindow.show();
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
})();
|
|
808
|
+
|
|
809
|
+
app.on("open-url", (_event: unknown, url): void => {
|
|
810
|
+
void (async (): Promise<void> => {
|
|
811
|
+
const didAuthenticate = await authenticateFromDeepLink(url);
|
|
812
|
+
if (didAuthenticate) {
|
|
813
|
+
scheduleAuthRefresh();
|
|
814
|
+
}
|
|
815
|
+
})();
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
app.on(
|
|
819
|
+
"second-instance",
|
|
820
|
+
(_event: unknown, commandLine: readonly string[]): void => {
|
|
821
|
+
const deepLinkUrl = commandLine.find((value): boolean =>
|
|
822
|
+
value.startsWith(`${APP_SCHEME}://`)
|
|
823
|
+
);
|
|
824
|
+
|
|
825
|
+
if (deepLinkUrl === undefined) {
|
|
826
|
+
showMainWindow();
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
void (async (): Promise<void> => {
|
|
831
|
+
const didAuthenticate = await authenticateFromDeepLink(deepLinkUrl);
|
|
832
|
+
if (didAuthenticate) {
|
|
833
|
+
scheduleAuthRefresh();
|
|
834
|
+
}
|
|
835
|
+
})();
|
|
836
|
+
}
|
|
837
|
+
);
|
|
838
|
+
app.on("before-quit", (): void => {
|
|
839
|
+
isQuitting = true;
|
|
840
|
+
if (tray) {
|
|
841
|
+
tray.destroy();
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
app.on("window-all-closed", (): void => {
|
|
846
|
+
if (process.platform !== "darwin") {
|
|
847
|
+
app.quit();
|
|
848
|
+
}
|
|
849
|
+
});
|