nastechai-desktop 18.1.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/.prettierrc +11 -0
- package/DESIGN.md +167 -0
- package/README.md +141 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/components.json +21 -0
- package/electron/backend-env.cjs +112 -0
- package/electron/backend-env.test.cjs +111 -0
- package/electron/backend-probes.cjs +106 -0
- package/electron/backend-probes.test.cjs +82 -0
- package/electron/backend-ready.cjs +66 -0
- package/electron/bootstrap-platform.cjs +91 -0
- package/electron/bootstrap-platform.test.cjs +111 -0
- package/electron/bootstrap-runner.cjs +720 -0
- package/electron/bootstrap-runner.test.cjs +138 -0
- package/electron/connection-config.cjs +254 -0
- package/electron/connection-config.test.cjs +329 -0
- package/electron/dashboard-token.cjs +99 -0
- package/electron/dashboard-token.test.cjs +142 -0
- package/electron/desktop-uninstall.cjs +232 -0
- package/electron/desktop-uninstall.test.cjs +246 -0
- package/electron/entitlements.mac.inherit.plist +14 -0
- package/electron/entitlements.mac.plist +14 -0
- package/electron/fs-read-dir.cjs +109 -0
- package/electron/fs-read-dir.test.cjs +364 -0
- package/electron/gateway-ws-probe.cjs +188 -0
- package/electron/gateway-ws-probe.test.cjs +122 -0
- package/electron/git-root.cjs +54 -0
- package/electron/git-root.test.cjs +40 -0
- package/electron/git-worktrees.cjs +174 -0
- package/electron/hardening.cjs +184 -0
- package/electron/hardening.test.cjs +116 -0
- package/electron/main.cjs +5762 -0
- package/electron/oauth-net-request.cjs +20 -0
- package/electron/oauth-net-request.test.cjs +34 -0
- package/electron/preload.cjs +135 -0
- package/electron/session-windows.cjs +99 -0
- package/electron/session-windows.test.cjs +177 -0
- package/electron/update-remote.cjs +56 -0
- package/electron/update-remote.test.cjs +78 -0
- package/electron/vscode-marketplace.cjs +331 -0
- package/electron/vscode-marketplace.test.cjs +113 -0
- package/electron/windows-child-process.test.cjs +57 -0
- package/electron/windows-user-env.cjs +76 -0
- package/electron/windows-user-env.test.cjs +90 -0
- package/electron/workspace-cwd.cjs +38 -0
- package/electron/workspace-cwd.test.cjs +45 -0
- package/eslint.config.mjs +122 -0
- package/index.html +17 -0
- package/package.json +254 -0
- package/pr-assets/session-source-folders.png +0 -0
- package/preview-demo.html +65 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/ds-assets/filler-bg0.jpg +0 -0
- package/public/nastech-frames/nastech-frame-0.png +0 -0
- package/public/nastech-frames/nastech-frame-1.png +0 -0
- package/public/nastech-frames/nastech-frame-2.png +0 -0
- package/public/nastech-frames/nastech-frame-3.png +0 -0
- package/public/nastech-frames/nastech-frame-4.png +0 -0
- package/public/nastech-frames/nastech-frame-5.png +0 -0
- package/public/nastech-frames/nastech-frame-6.png +0 -0
- package/public/nastech-frames/nastech-frame-7.png +0 -0
- package/public/nastech-girl.jpg +0 -0
- package/public/nastech-sprite.png +0 -0
- package/public/nastech.png +0 -0
- package/scripts/after-pack.cjs +41 -0
- package/scripts/assert-dist-built.cjs +70 -0
- package/scripts/assert-dist-built.test.cjs +84 -0
- package/scripts/assert-root-install.cjs +13 -0
- package/scripts/before-build.cjs +11 -0
- package/scripts/before-pack.cjs +78 -0
- package/scripts/before-pack.test.cjs +53 -0
- package/scripts/click-session.mjs +51 -0
- package/scripts/dev-no-hmr.mjs +22 -0
- package/scripts/diag-jump.mjs +115 -0
- package/scripts/diag-scroll-reset.mjs +229 -0
- package/scripts/eval.mjs +21 -0
- package/scripts/leak-typing.mjs +222 -0
- package/scripts/measure-jump.mjs +108 -0
- package/scripts/measure-latency.mjs +184 -0
- package/scripts/measure-real-stream.mjs +252 -0
- package/scripts/measure-submit.mjs +179 -0
- package/scripts/measure-synthetic-stream.mjs +322 -0
- package/scripts/notarize-artifact.cjs +77 -0
- package/scripts/notarize.cjs +100 -0
- package/scripts/patch-electron-builder-mac-binary.cjs +59 -0
- package/scripts/probe-renderer.mjs +38 -0
- package/scripts/probe-thread.mjs +40 -0
- package/scripts/profile-long-stream.mjs +191 -0
- package/scripts/profile-real-stream.mjs +137 -0
- package/scripts/profile-synth-stream.mjs +103 -0
- package/scripts/profile-typing-lag.md +381 -0
- package/scripts/profile-typing.mjs +260 -0
- package/scripts/reload-renderer.mjs +25 -0
- package/scripts/reload.mjs +36 -0
- package/scripts/set-exe-identity.cjs +94 -0
- package/scripts/stage-native-deps.cjs +159 -0
- package/scripts/test-desktop.mjs +425 -0
- package/scripts/write-build-stamp.cjs +126 -0
- package/src/app/agents/index.tsx +398 -0
- package/src/app/artifacts/index.test.ts +62 -0
- package/src/app/artifacts/index.tsx +906 -0
- package/src/app/chat/chat-drop-overlay.tsx +48 -0
- package/src/app/chat/chat-swap-overlay.tsx +47 -0
- package/src/app/chat/composer/attachments.tsx +114 -0
- package/src/app/chat/composer/completion-drawer.tsx +63 -0
- package/src/app/chat/composer/context-menu.tsx +172 -0
- package/src/app/chat/composer/controls.tsx +289 -0
- package/src/app/chat/composer/drop-affordance.ts +2 -0
- package/src/app/chat/composer/enter-submit-dom-race.test.tsx +218 -0
- package/src/app/chat/composer/focus.ts +134 -0
- package/src/app/chat/composer/help-hint.tsx +59 -0
- package/src/app/chat/composer/hooks/use-at-completions.ts +141 -0
- package/src/app/chat/composer/hooks/use-live-completion-adapter.ts +119 -0
- package/src/app/chat/composer/hooks/use-mic-recorder.ts +291 -0
- package/src/app/chat/composer/hooks/use-slash-completions.ts +114 -0
- package/src/app/chat/composer/hooks/use-voice-conversation.ts +390 -0
- package/src/app/chat/composer/hooks/use-voice-recorder.ts +116 -0
- package/src/app/chat/composer/ime-composition-dom-repro.test.tsx +108 -0
- package/src/app/chat/composer/index.tsx +1611 -0
- package/src/app/chat/composer/inline-refs.ts +138 -0
- package/src/app/chat/composer/model-pill.tsx +86 -0
- package/src/app/chat/composer/queue-panel.tsx +130 -0
- package/src/app/chat/composer/rich-editor.test.ts +18 -0
- package/src/app/chat/composer/rich-editor.ts +165 -0
- package/src/app/chat/composer/skin-slash-popover.tsx +61 -0
- package/src/app/chat/composer/slash-nav-dom-repro.test.tsx +186 -0
- package/src/app/chat/composer/status-stack/index.tsx +202 -0
- package/src/app/chat/composer/status-stack/status-row.tsx +155 -0
- package/src/app/chat/composer/text-utils.test.ts +77 -0
- package/src/app/chat/composer/text-utils.ts +107 -0
- package/src/app/chat/composer/trigger-popover.test.tsx +42 -0
- package/src/app/chat/composer/trigger-popover.tsx +116 -0
- package/src/app/chat/composer/types.ts +64 -0
- package/src/app/chat/composer/url-dialog.tsx +82 -0
- package/src/app/chat/composer/voice-activity.tsx +252 -0
- package/src/app/chat/hooks/use-composer-actions.test.ts +57 -0
- package/src/app/chat/hooks/use-composer-actions.ts +525 -0
- package/src/app/chat/hooks/use-file-drop-zone.ts +118 -0
- package/src/app/chat/index.tsx +390 -0
- package/src/app/chat/perf-probe.tsx +269 -0
- package/src/app/chat/right-rail/index.ts +1 -0
- package/src/app/chat/right-rail/preview-console-state.ts +82 -0
- package/src/app/chat/right-rail/preview-console.tsx +290 -0
- package/src/app/chat/right-rail/preview-file.tsx +559 -0
- package/src/app/chat/right-rail/preview-pane.test.tsx +43 -0
- package/src/app/chat/right-rail/preview-pane.tsx +657 -0
- package/src/app/chat/right-rail/preview.tsx +171 -0
- package/src/app/chat/scroll-to-bottom-button.test.tsx +67 -0
- package/src/app/chat/scroll-to-bottom-button.tsx +74 -0
- package/src/app/chat/sidebar/cron-jobs-section.tsx +325 -0
- package/src/app/chat/sidebar/index.tsx +1219 -0
- package/src/app/chat/sidebar/load-more-row.tsx +30 -0
- package/src/app/chat/sidebar/order.test.ts +21 -0
- package/src/app/chat/sidebar/order.ts +17 -0
- package/src/app/chat/sidebar/profile-switcher.tsx +516 -0
- package/src/app/chat/sidebar/session-actions-menu.tsx +264 -0
- package/src/app/chat/sidebar/session-row.tsx +257 -0
- package/src/app/chat/sidebar/virtual-session-list.tsx +154 -0
- package/src/app/chat/sidebar/workspace-groups.test.ts +149 -0
- package/src/app/chat/sidebar/workspace-groups.ts +326 -0
- package/src/app/chat/thread-loading.test.ts +34 -0
- package/src/app/chat/thread-loading.ts +26 -0
- package/src/app/command-center/index.tsx +654 -0
- package/src/app/command-palette/index.tsx +513 -0
- package/src/app/command-palette/marketplace-theme-page.tsx +157 -0
- package/src/app/cron/index.tsx +942 -0
- package/src/app/cron/job-state.ts +29 -0
- package/src/app/desktop-controller.tsx +938 -0
- package/src/app/floating-hud.ts +22 -0
- package/src/app/gateway/hooks/use-gateway-boot.test.tsx +265 -0
- package/src/app/gateway/hooks/use-gateway-boot.ts +387 -0
- package/src/app/gateway/hooks/use-gateway-request.ts +138 -0
- package/src/app/hooks/use-keybinds.ts +186 -0
- package/src/app/hooks/use-refresh-hotkey.ts +45 -0
- package/src/app/hooks/use-route-enum-param.ts +38 -0
- package/src/app/index.tsx +1 -0
- package/src/app/layout-constants.ts +13 -0
- package/src/app/messaging/index.tsx +648 -0
- package/src/app/messaging/platform-icon.tsx +93 -0
- package/src/app/model-picker-overlay.tsx +42 -0
- package/src/app/model-visibility-overlay.tsx +31 -0
- package/src/app/overlays/overlay-chrome.tsx +66 -0
- package/src/app/overlays/overlay-search-input.tsx +33 -0
- package/src/app/overlays/overlay-split-layout.tsx +130 -0
- package/src/app/overlays/overlay-view.tsx +91 -0
- package/src/app/page-search-shell.tsx +75 -0
- package/src/app/profiles/create-profile-dialog.tsx +154 -0
- package/src/app/profiles/delete-profile-dialog.tsx +65 -0
- package/src/app/profiles/index.tsx +671 -0
- package/src/app/profiles/rename-profile-dialog.tsx +125 -0
- package/src/app/right-sidebar/files/dnd-manager.ts +27 -0
- package/src/app/right-sidebar/files/ipc.test.ts +100 -0
- package/src/app/right-sidebar/files/ipc.ts +161 -0
- package/src/app/right-sidebar/files/remote-picker.tsx +177 -0
- package/src/app/right-sidebar/files/tree.tsx +224 -0
- package/src/app/right-sidebar/files/use-project-tree.test.ts +190 -0
- package/src/app/right-sidebar/files/use-project-tree.ts +268 -0
- package/src/app/right-sidebar/index.test.tsx +75 -0
- package/src/app/right-sidebar/index.tsx +395 -0
- package/src/app/right-sidebar/store.ts +15 -0
- package/src/app/right-sidebar/terminal/buffer.ts +65 -0
- package/src/app/right-sidebar/terminal/index.tsx +98 -0
- package/src/app/right-sidebar/terminal/persistent.tsx +122 -0
- package/src/app/right-sidebar/terminal/selection.ts +75 -0
- package/src/app/right-sidebar/terminal/use-terminal-session.ts +504 -0
- package/src/app/routes.ts +88 -0
- package/src/app/session/hooks/use-context-suggestions.ts +58 -0
- package/src/app/session/hooks/use-cwd-actions.ts +109 -0
- package/src/app/session/hooks/use-message-stream.ts +957 -0
- package/src/app/session/hooks/use-model-controls.test.tsx +198 -0
- package/src/app/session/hooks/use-model-controls.ts +106 -0
- package/src/app/session/hooks/use-nastech-config.ts +74 -0
- package/src/app/session/hooks/use-preview-routing.test.tsx +168 -0
- package/src/app/session/hooks/use-preview-routing.ts +223 -0
- package/src/app/session/hooks/use-prompt-actions.test.tsx +316 -0
- package/src/app/session/hooks/use-prompt-actions.ts +1030 -0
- package/src/app/session/hooks/use-route-resume.test.tsx +136 -0
- package/src/app/session/hooks/use-route-resume.ts +115 -0
- package/src/app/session/hooks/use-session-actions.test.tsx +119 -0
- package/src/app/session/hooks/use-session-actions.ts +885 -0
- package/src/app/session/hooks/use-session-state-cache.test.tsx +118 -0
- package/src/app/session/hooks/use-session-state-cache.ts +191 -0
- package/src/app/session-picker-overlay.tsx +32 -0
- package/src/app/session-switcher.tsx +107 -0
- package/src/app/settings/about-settings.tsx +173 -0
- package/src/app/settings/appearance-settings.tsx +162 -0
- package/src/app/settings/config-settings.tsx +384 -0
- package/src/app/settings/constants.ts +545 -0
- package/src/app/settings/credential-key-ui.tsx +373 -0
- package/src/app/settings/env-credentials.tsx +198 -0
- package/src/app/settings/env-var-actions-menu.tsx +136 -0
- package/src/app/settings/field-copy.ts +56 -0
- package/src/app/settings/gateway-settings.tsx +620 -0
- package/src/app/settings/helpers.test.ts +138 -0
- package/src/app/settings/helpers.ts +151 -0
- package/src/app/settings/index.tsx +237 -0
- package/src/app/settings/keys-settings.tsx +96 -0
- package/src/app/settings/mcp-settings.tsx +271 -0
- package/src/app/settings/model-settings.test.tsx +157 -0
- package/src/app/settings/model-settings.tsx +559 -0
- package/src/app/settings/notifications-settings.tsx +150 -0
- package/src/app/settings/primitives.tsx +115 -0
- package/src/app/settings/providers-settings.test.tsx +100 -0
- package/src/app/settings/providers-settings.tsx +258 -0
- package/src/app/settings/sessions-settings.tsx +276 -0
- package/src/app/settings/toolset-config-panel.test.tsx +289 -0
- package/src/app/settings/toolset-config-panel.tsx +449 -0
- package/src/app/settings/types.ts +42 -0
- package/src/app/settings/uninstall-section.tsx +185 -0
- package/src/app/settings/use-deep-link-highlight.ts +60 -0
- package/src/app/shell/app-shell.tsx +167 -0
- package/src/app/shell/gateway-menu-panel.tsx +150 -0
- package/src/app/shell/hooks/use-overlay-routing.ts +71 -0
- package/src/app/shell/hooks/use-status-snapshot.ts +57 -0
- package/src/app/shell/hooks/use-statusbar-items.tsx +403 -0
- package/src/app/shell/keybind-panel.tsx +220 -0
- package/src/app/shell/model-edit-submenu.test.tsx +84 -0
- package/src/app/shell/model-edit-submenu.tsx +245 -0
- package/src/app/shell/model-menu-panel.tsx +295 -0
- package/src/app/shell/sidebar-label.tsx +22 -0
- package/src/app/shell/statusbar-controls.tsx +185 -0
- package/src/app/shell/titlebar-controls.tsx +244 -0
- package/src/app/shell/titlebar.test.ts +26 -0
- package/src/app/shell/titlebar.ts +45 -0
- package/src/app/shell/use-group-registry.ts +39 -0
- package/src/app/skills/index.test.tsx +103 -0
- package/src/app/skills/index.tsx +371 -0
- package/src/app/types.ts +99 -0
- package/src/app/updates-overlay.tsx +369 -0
- package/src/components/Backdrop.tsx +114 -0
- package/src/components/assistant-ui/ansi-text.tsx +34 -0
- package/src/components/assistant-ui/clarify-tool.tsx +281 -0
- package/src/components/assistant-ui/directive-text.test.ts +39 -0
- package/src/components/assistant-ui/directive-text.tsx +389 -0
- package/src/components/assistant-ui/markdown-text.test.ts +204 -0
- package/src/components/assistant-ui/markdown-text.tsx +497 -0
- package/src/components/assistant-ui/message-render-boundary.test.tsx +80 -0
- package/src/components/assistant-ui/message-render-boundary.tsx +48 -0
- package/src/components/assistant-ui/streaming.test.tsx +739 -0
- package/src/components/assistant-ui/thread-list.tsx +307 -0
- package/src/components/assistant-ui/thread-virtualizer.tsx +512 -0
- package/src/components/assistant-ui/thread.tsx +1474 -0
- package/src/components/assistant-ui/todo-tool.tsx +109 -0
- package/src/components/assistant-ui/tool-approval-group.test.tsx +158 -0
- package/src/components/assistant-ui/tool-approval.test.tsx +81 -0
- package/src/components/assistant-ui/tool-approval.tsx +209 -0
- package/src/components/assistant-ui/tool-fallback-model.test.ts +66 -0
- package/src/components/assistant-ui/tool-fallback-model.ts +1368 -0
- package/src/components/assistant-ui/tool-fallback.tsx +466 -0
- package/src/components/assistant-ui/tooltip-icon-button.tsx +33 -0
- package/src/components/assistant-ui/user-message-edit.test.tsx +141 -0
- package/src/components/assistant-ui/user-message-text.tsx +150 -0
- package/src/components/boot-failure-overlay.tsx +246 -0
- package/src/components/boot-failure-reauth.test.ts +100 -0
- package/src/components/boot-failure-reauth.ts +81 -0
- package/src/components/brand-mark.tsx +19 -0
- package/src/components/chat/activity-timer-text.tsx +24 -0
- package/src/components/chat/activity-timer.test.tsx +43 -0
- package/src/components/chat/activity-timer.ts +64 -0
- package/src/components/chat/code-card.tsx +78 -0
- package/src/components/chat/compact-markdown.tsx +113 -0
- package/src/components/chat/composer-dock.ts +31 -0
- package/src/components/chat/diff-lines.tsx +54 -0
- package/src/components/chat/disclosure-row.tsx +63 -0
- package/src/components/chat/generated-image-context.tsx +19 -0
- package/src/components/chat/generated-image-result.tsx +174 -0
- package/src/components/chat/image-generation-placeholder.tsx +279 -0
- package/src/components/chat/intro-copy.jsonl +75 -0
- package/src/components/chat/intro.tsx +182 -0
- package/src/components/chat/preview-attachment.tsx +125 -0
- package/src/components/chat/shiki-highlighter.tsx +107 -0
- package/src/components/chat/status-row.tsx +70 -0
- package/src/components/chat/status-section.tsx +42 -0
- package/src/components/chat/terminal-output.tsx +50 -0
- package/src/components/chat/zoomable-image.tsx +177 -0
- package/src/components/desktop-install-overlay.tsx +595 -0
- package/src/components/desktop-onboarding-overlay.test.tsx +100 -0
- package/src/components/desktop-onboarding-overlay.tsx +1286 -0
- package/src/components/error-boundary.tsx +77 -0
- package/src/components/gateway-connecting-overlay.test.tsx +143 -0
- package/src/components/gateway-connecting-overlay.tsx +183 -0
- package/src/components/haptics-provider.tsx +19 -0
- package/src/components/language-switcher.test.tsx +53 -0
- package/src/components/language-switcher.tsx +175 -0
- package/src/components/model-picker.tsx +340 -0
- package/src/components/model-visibility-dialog.tsx +155 -0
- package/src/components/notifications.tsx +196 -0
- package/src/components/page-loader.tsx +34 -0
- package/src/components/pane-shell/context.ts +14 -0
- package/src/components/pane-shell/index.ts +4 -0
- package/src/components/pane-shell/pane-shell.test.tsx +333 -0
- package/src/components/pane-shell/pane-shell.tsx +330 -0
- package/src/components/prompt-overlays.tsx +234 -0
- package/src/components/session-picker.tsx +108 -0
- package/src/components/status-dot.tsx +26 -0
- package/src/components/ui/action-status.tsx +25 -0
- package/src/components/ui/alert.tsx +53 -0
- package/src/components/ui/badge.tsx +35 -0
- package/src/components/ui/braille-spinner.tsx +61 -0
- package/src/components/ui/button.tsx +81 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/codicon.tsx +20 -0
- package/src/components/ui/command.tsx +111 -0
- package/src/components/ui/confirm-dialog.tsx +109 -0
- package/src/components/ui/context-menu.tsx +141 -0
- package/src/components/ui/control.ts +25 -0
- package/src/components/ui/copy-button.test.tsx +36 -0
- package/src/components/ui/copy-button.tsx +229 -0
- package/src/components/ui/dialog.tsx +152 -0
- package/src/components/ui/disclosure-caret.tsx +20 -0
- package/src/components/ui/dropdown-menu.tsx +291 -0
- package/src/components/ui/error-state.tsx +50 -0
- package/src/components/ui/fade-text.tsx +110 -0
- package/src/components/ui/glyph-spinner.tsx +63 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/kbd.tsx +37 -0
- package/src/components/ui/loader.tsx +558 -0
- package/src/components/ui/log-view.tsx +17 -0
- package/src/components/ui/pagination.tsx +114 -0
- package/src/components/ui/popover.tsx +44 -0
- package/src/components/ui/scroll-area.tsx +43 -0
- package/src/components/ui/search-field.tsx +80 -0
- package/src/components/ui/segmented-control.tsx +51 -0
- package/src/components/ui/select.tsx +92 -0
- package/src/components/ui/separator.tsx +26 -0
- package/src/components/ui/sheet.tsx +116 -0
- package/src/components/ui/sidebar.tsx +674 -0
- package/src/components/ui/skeleton.tsx +7 -0
- package/src/components/ui/switch.tsx +49 -0
- package/src/components/ui/tabs.tsx +36 -0
- package/src/components/ui/text-tab.tsx +43 -0
- package/src/components/ui/textarea.tsx +11 -0
- package/src/components/ui/tool-icon.tsx +65 -0
- package/src/components/ui/tooltip.tsx +69 -0
- package/src/fonts/JetBrainsMono-Bold.woff2 +0 -0
- package/src/fonts/JetBrainsMono-Italic.woff2 +0 -0
- package/src/fonts/JetBrainsMono-Regular.woff2 +0 -0
- package/src/global.d.ts +457 -0
- package/src/hooks/use-image-download.ts +85 -0
- package/src/hooks/use-media-query.ts +24 -0
- package/src/hooks/use-mobile.ts +3 -0
- package/src/hooks/use-resize-observer.ts +38 -0
- package/src/hooks/use-worktree-info.ts +68 -0
- package/src/i18n/catalog.ts +12 -0
- package/src/i18n/context.test.tsx +232 -0
- package/src/i18n/context.tsx +183 -0
- package/src/i18n/define-locale.ts +41 -0
- package/src/i18n/en.ts +1779 -0
- package/src/i18n/index.ts +20 -0
- package/src/i18n/ja.ts +1890 -0
- package/src/i18n/languages.test.ts +43 -0
- package/src/i18n/languages.ts +86 -0
- package/src/i18n/runtime.test.ts +75 -0
- package/src/i18n/runtime.ts +53 -0
- package/src/i18n/types.ts +1452 -0
- package/src/i18n/zh-hant.ts +1849 -0
- package/src/i18n/zh.ts +1923 -0
- package/src/lib/ansi.test.ts +123 -0
- package/src/lib/ansi.ts +175 -0
- package/src/lib/chat-messages.test.ts +708 -0
- package/src/lib/chat-messages.ts +885 -0
- package/src/lib/chat-runtime.test.ts +18 -0
- package/src/lib/chat-runtime.ts +335 -0
- package/src/lib/clipboard.ts +28 -0
- package/src/lib/commit-changelog.test.ts +114 -0
- package/src/lib/commit-changelog.ts +177 -0
- package/src/lib/completion-sound.ts +519 -0
- package/src/lib/desktop-fs.test.ts +116 -0
- package/src/lib/desktop-fs.ts +113 -0
- package/src/lib/desktop-slash-commands.test.ts +126 -0
- package/src/lib/desktop-slash-commands.ts +286 -0
- package/src/lib/embedded-images.test.ts +35 -0
- package/src/lib/embedded-images.ts +60 -0
- package/src/lib/external-link.test.tsx +168 -0
- package/src/lib/external-link.tsx +303 -0
- package/src/lib/gateway-events.test.ts +27 -0
- package/src/lib/gateway-events.ts +49 -0
- package/src/lib/gateway-ws-url.test.ts +78 -0
- package/src/lib/gateway-ws-url.ts +91 -0
- package/src/lib/generated-images.test.ts +97 -0
- package/src/lib/generated-images.ts +116 -0
- package/src/lib/haptics.ts +129 -0
- package/src/lib/icons.ts +203 -0
- package/src/lib/incremental-external-store-runtime.ts +188 -0
- package/src/lib/katex-memo.ts +260 -0
- package/src/lib/keybinds/actions.ts +125 -0
- package/src/lib/keybinds/combo.test.ts +86 -0
- package/src/lib/keybinds/combo.ts +169 -0
- package/src/lib/local-preview.ts +126 -0
- package/src/lib/markdown-code.test.ts +23 -0
- package/src/lib/markdown-code.ts +195 -0
- package/src/lib/markdown-preprocess.ts +386 -0
- package/src/lib/media.remote.test.ts +58 -0
- package/src/lib/media.ts +111 -0
- package/src/lib/model-status-label.test.ts +31 -0
- package/src/lib/model-status-label.ts +103 -0
- package/src/lib/mutable-ref.ts +6 -0
- package/src/lib/preview-targets.test.ts +27 -0
- package/src/lib/preview-targets.ts +63 -0
- package/src/lib/profile-color.ts +58 -0
- package/src/lib/provider-setup-errors.test.ts +26 -0
- package/src/lib/provider-setup-errors.ts +12 -0
- package/src/lib/query-client.ts +13 -0
- package/src/lib/remend-tail.test.ts +105 -0
- package/src/lib/remend-tail.ts +108 -0
- package/src/lib/runtime-readiness.test.ts +65 -0
- package/src/lib/runtime-readiness.ts +147 -0
- package/src/lib/session-export.ts +57 -0
- package/src/lib/session-search.test.ts +58 -0
- package/src/lib/session-search.ts +19 -0
- package/src/lib/session-source.ts +62 -0
- package/src/lib/speech-text.ts +35 -0
- package/src/lib/statusbar.ts +91 -0
- package/src/lib/storage.test.ts +25 -0
- package/src/lib/storage.ts +107 -0
- package/src/lib/todos.test.ts +35 -0
- package/src/lib/todos.ts +51 -0
- package/src/lib/tool-result-summary.test.ts +106 -0
- package/src/lib/tool-result-summary.ts +467 -0
- package/src/lib/update-copy.test.ts +38 -0
- package/src/lib/update-copy.ts +44 -0
- package/src/lib/use-enter-animation.ts +100 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/voice-playback.ts +128 -0
- package/src/lib/yolo-session.ts +26 -0
- package/src/main.tsx +43 -0
- package/src/nastech.test.ts +49 -0
- package/src/nastech.ts +718 -0
- package/src/store/activity.ts +100 -0
- package/src/store/boot.ts +91 -0
- package/src/store/clarify.test.ts +81 -0
- package/src/store/clarify.ts +69 -0
- package/src/store/command-palette.ts +20 -0
- package/src/store/compaction.test.ts +53 -0
- package/src/store/compaction.ts +38 -0
- package/src/store/completion-sound.ts +32 -0
- package/src/store/composer-input-history.test.ts +147 -0
- package/src/store/composer-input-history.ts +158 -0
- package/src/store/composer-queue.test.ts +148 -0
- package/src/store/composer-queue.ts +239 -0
- package/src/store/composer-status.test.ts +99 -0
- package/src/store/composer-status.ts +277 -0
- package/src/store/composer.test.ts +106 -0
- package/src/store/composer.ts +184 -0
- package/src/store/cron.ts +19 -0
- package/src/store/gateway.ts +290 -0
- package/src/store/haptics.ts +17 -0
- package/src/store/keybinds.ts +139 -0
- package/src/store/layout.ts +176 -0
- package/src/store/model-presets.test.ts +51 -0
- package/src/store/model-presets.ts +86 -0
- package/src/store/model-visibility.test.ts +37 -0
- package/src/store/model-visibility.ts +108 -0
- package/src/store/native-notifications.test.ts +192 -0
- package/src/store/native-notifications.ts +203 -0
- package/src/store/notifications.ts +165 -0
- package/src/store/onboarding.test.ts +372 -0
- package/src/store/onboarding.ts +866 -0
- package/src/store/panes.test.ts +146 -0
- package/src/store/panes.ts +145 -0
- package/src/store/preview.test.ts +135 -0
- package/src/store/preview.ts +466 -0
- package/src/store/profile.test.ts +89 -0
- package/src/store/profile.ts +365 -0
- package/src/store/prompts.test.ts +121 -0
- package/src/store/prompts.ts +115 -0
- package/src/store/session-switcher.test.ts +115 -0
- package/src/store/session-switcher.ts +128 -0
- package/src/store/session-sync.ts +25 -0
- package/src/store/session.test.ts +131 -0
- package/src/store/session.ts +255 -0
- package/src/store/subagents.test.ts +111 -0
- package/src/store/subagents.ts +260 -0
- package/src/store/thread-scroll.ts +46 -0
- package/src/store/todos.test.ts +47 -0
- package/src/store/todos.ts +64 -0
- package/src/store/tool-diffs.ts +23 -0
- package/src/store/tool-dismiss.ts +45 -0
- package/src/store/tool-view.ts +91 -0
- package/src/store/translucency.ts +38 -0
- package/src/store/updates.test.ts +77 -0
- package/src/store/updates.ts +315 -0
- package/src/store/voice-playback.ts +24 -0
- package/src/store/windows.test.ts +143 -0
- package/src/store/windows.ts +77 -0
- package/src/styles.css +1235 -0
- package/src/themes/color.ts +142 -0
- package/src/themes/context.tsx +339 -0
- package/src/themes/index.ts +3 -0
- package/src/themes/install.test.ts +119 -0
- package/src/themes/install.ts +95 -0
- package/src/themes/presets.test.ts +33 -0
- package/src/themes/presets.ts +293 -0
- package/src/themes/profile-theme.test.ts +41 -0
- package/src/themes/types.ts +66 -0
- package/src/themes/use-skin-command.ts +60 -0
- package/src/themes/user-themes.test.ts +63 -0
- package/src/themes/user-themes.ts +122 -0
- package/src/themes/vscode.test.ts +171 -0
- package/src/themes/vscode.ts +343 -0
- package/src/types/nastech.ts +646 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/vite.config.ts +56 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AppendMessage,
|
|
3
|
+
AssistantRuntimeProvider,
|
|
4
|
+
ExportedMessageRepository,
|
|
5
|
+
type ThreadMessage
|
|
6
|
+
} from '@assistant-ui/react'
|
|
7
|
+
import { useStore } from '@nanostores/react'
|
|
8
|
+
import { useQuery } from '@tanstack/react-query'
|
|
9
|
+
import type * as React from 'react'
|
|
10
|
+
import { Suspense, useCallback, useMemo, useRef } from 'react'
|
|
11
|
+
import { useLocation } from 'react-router-dom'
|
|
12
|
+
|
|
13
|
+
import { Thread } from '@/components/assistant-ui/thread'
|
|
14
|
+
import { Backdrop } from '@/components/Backdrop'
|
|
15
|
+
import { PromptOverlays } from '@/components/prompt-overlays'
|
|
16
|
+
import { Button } from '@/components/ui/button'
|
|
17
|
+
import { Codicon } from '@/components/ui/codicon'
|
|
18
|
+
import { getGlobalModelOptions, type NasTechGateway } from '@/nastech'
|
|
19
|
+
import type { ChatMessage } from '@/lib/chat-messages'
|
|
20
|
+
import { quickModelOptions, sessionTitle, toRuntimeMessage } from '@/lib/chat-runtime'
|
|
21
|
+
import { useIncrementalExternalStoreRuntime } from '@/lib/incremental-external-store-runtime'
|
|
22
|
+
import { cn } from '@/lib/utils'
|
|
23
|
+
import type { ComposerAttachment } from '@/store/composer'
|
|
24
|
+
import { $pinnedSessionIds } from '@/store/layout'
|
|
25
|
+
import { $gatewaySwapTarget } from '@/store/profile'
|
|
26
|
+
import {
|
|
27
|
+
$activeSessionId,
|
|
28
|
+
$awaitingResponse,
|
|
29
|
+
$busy,
|
|
30
|
+
$contextSuggestions,
|
|
31
|
+
$currentCwd,
|
|
32
|
+
$currentModel,
|
|
33
|
+
$currentProvider,
|
|
34
|
+
$freshDraftReady,
|
|
35
|
+
$gatewayState,
|
|
36
|
+
$introPersonality,
|
|
37
|
+
$introSeed,
|
|
38
|
+
$messages,
|
|
39
|
+
$selectedStoredSessionId,
|
|
40
|
+
$sessions,
|
|
41
|
+
sessionPinId
|
|
42
|
+
} from '@/store/session'
|
|
43
|
+
import type { ModelOptionsResponse } from '@/types/nastech'
|
|
44
|
+
|
|
45
|
+
import { routeSessionId } from '../routes'
|
|
46
|
+
import { titlebarHeaderBaseClass, titlebarHeaderShadowClass } from '../shell/titlebar'
|
|
47
|
+
|
|
48
|
+
import { ChatDropOverlay } from './chat-drop-overlay'
|
|
49
|
+
import { ChatSwapOverlay } from './chat-swap-overlay'
|
|
50
|
+
import { ChatBar, ChatBarFallback } from './composer'
|
|
51
|
+
import { requestComposerInsert, requestComposerInsertRefs } from './composer/focus'
|
|
52
|
+
import { droppedFileInlineRef, type SessionDragPayload, sessionInlineRef } from './composer/inline-refs'
|
|
53
|
+
import type { ChatBarState } from './composer/types'
|
|
54
|
+
import type { DroppedFile } from './hooks/use-composer-actions'
|
|
55
|
+
import { useFileDropZone } from './hooks/use-file-drop-zone'
|
|
56
|
+
import { SessionActionsMenu } from './sidebar/session-actions-menu'
|
|
57
|
+
import { lastVisibleMessageIsUser, threadLoadingState } from './thread-loading'
|
|
58
|
+
|
|
59
|
+
interface ChatViewProps extends Omit<React.ComponentProps<'div'>, 'onSubmit'> {
|
|
60
|
+
gateway: NasTechGateway | null
|
|
61
|
+
onToggleSelectedPin: () => void
|
|
62
|
+
onDeleteSelectedSession: () => void
|
|
63
|
+
onCancel: () => Promise<void> | void
|
|
64
|
+
onAddContextRef: (refText: string, label?: string, detail?: string) => void
|
|
65
|
+
onAddUrl: (url: string) => void
|
|
66
|
+
onBranchInNewChat: (messageId: string) => void
|
|
67
|
+
maxVoiceRecordingSeconds?: number
|
|
68
|
+
onAttachImageBlob: (blob: Blob) => Promise<boolean | void> | boolean | void
|
|
69
|
+
onAttachDroppedItems: (candidates: DroppedFile[]) => Promise<boolean | void> | boolean | void
|
|
70
|
+
onPasteClipboardImage: () => void
|
|
71
|
+
onPickFiles: () => void
|
|
72
|
+
onPickFolders: () => void
|
|
73
|
+
onPickImages: () => void
|
|
74
|
+
onRemoveAttachment: (id: string) => void
|
|
75
|
+
onSteer: (text: string) => Promise<boolean> | boolean
|
|
76
|
+
onSubmit: (
|
|
77
|
+
text: string,
|
|
78
|
+
options?: { attachments?: ComposerAttachment[]; fromQueue?: boolean }
|
|
79
|
+
) => Promise<boolean> | boolean
|
|
80
|
+
onThreadMessagesChange: (messages: readonly ThreadMessage[]) => void
|
|
81
|
+
onEdit: (message: AppendMessage) => Promise<void>
|
|
82
|
+
onReload: (parentId: string | null) => Promise<void>
|
|
83
|
+
onTranscribeAudio?: (audio: Blob) => Promise<string>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface ChatHeaderProps {
|
|
87
|
+
activeSessionId: null | string
|
|
88
|
+
isRoutedSessionView: boolean
|
|
89
|
+
onDeleteSelectedSession: () => void
|
|
90
|
+
onToggleSelectedPin: () => void
|
|
91
|
+
selectedSessionId: null | string
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function ChatHeader({
|
|
95
|
+
activeSessionId,
|
|
96
|
+
isRoutedSessionView,
|
|
97
|
+
onDeleteSelectedSession,
|
|
98
|
+
onToggleSelectedPin,
|
|
99
|
+
selectedSessionId
|
|
100
|
+
}: ChatHeaderProps) {
|
|
101
|
+
const sessions = useStore($sessions)
|
|
102
|
+
const pinnedSessionIds = useStore($pinnedSessionIds)
|
|
103
|
+
|
|
104
|
+
const activeStoredSession =
|
|
105
|
+
sessions.find(session => session.id === selectedSessionId || session._lineage_root_id === selectedSessionId) || null
|
|
106
|
+
|
|
107
|
+
const title = activeStoredSession ? sessionTitle(activeStoredSession) : 'New session'
|
|
108
|
+
|
|
109
|
+
// Pins live on the durable lineage-root id, but selectedSessionId is the live
|
|
110
|
+
// (tip) id — resolve through the loaded row so the menu reflects the pin
|
|
111
|
+
// state after auto-compression rotates the id.
|
|
112
|
+
const selectedIsPinned = activeStoredSession
|
|
113
|
+
? pinnedSessionIds.includes(sessionPinId(activeStoredSession))
|
|
114
|
+
: selectedSessionId
|
|
115
|
+
? pinnedSessionIds.includes(selectedSessionId)
|
|
116
|
+
: false
|
|
117
|
+
|
|
118
|
+
// A brand-new session has no session to pin/delete/rename, so the header is
|
|
119
|
+
// just a dead "New session" label + chevron. Drop it (and its border)
|
|
120
|
+
// entirely until there's a real session to act on.
|
|
121
|
+
if (!selectedSessionId && !activeSessionId && !isRoutedSessionView) {
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<header className={cn(titlebarHeaderBaseClass, isRoutedSessionView && titlebarHeaderShadowClass)}>
|
|
127
|
+
<div className="min-w-0 flex-1">
|
|
128
|
+
<SessionActionsMenu
|
|
129
|
+
align="start"
|
|
130
|
+
onDelete={selectedSessionId ? onDeleteSelectedSession : undefined}
|
|
131
|
+
onPin={selectedSessionId ? onToggleSelectedPin : undefined}
|
|
132
|
+
pinned={selectedIsPinned}
|
|
133
|
+
sessionId={selectedSessionId || activeSessionId || ''}
|
|
134
|
+
sideOffset={8}
|
|
135
|
+
title={title}
|
|
136
|
+
>
|
|
137
|
+
<Button
|
|
138
|
+
className="pointer-events-auto h-6 min-w-0 gap-1 border border-transparent bg-transparent px-2 py-0 text-(--ui-text-secondary) hover:border-(--ui-stroke-tertiary) hover:bg-(--ui-control-hover-background) hover:text-foreground data-[state=open]:border-(--ui-stroke-tertiary) data-[state=open]:bg-(--ui-control-active-background) [-webkit-app-region:no-drag]"
|
|
139
|
+
type="button"
|
|
140
|
+
variant="ghost"
|
|
141
|
+
>
|
|
142
|
+
<h2 className="max-w-[52vw] truncate text-[0.75rem] font-medium leading-none">{title}</h2>
|
|
143
|
+
<Codicon className="shrink-0 text-(--ui-text-tertiary)" name="chevron-down" size="0.8125rem" />
|
|
144
|
+
</Button>
|
|
145
|
+
</SessionActionsMenu>
|
|
146
|
+
</div>
|
|
147
|
+
</header>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function ChatView({
|
|
152
|
+
className,
|
|
153
|
+
gateway,
|
|
154
|
+
onToggleSelectedPin,
|
|
155
|
+
onDeleteSelectedSession,
|
|
156
|
+
onCancel,
|
|
157
|
+
onAddContextRef,
|
|
158
|
+
onAddUrl,
|
|
159
|
+
onAttachImageBlob,
|
|
160
|
+
onAttachDroppedItems,
|
|
161
|
+
onBranchInNewChat,
|
|
162
|
+
maxVoiceRecordingSeconds,
|
|
163
|
+
onPasteClipboardImage,
|
|
164
|
+
onPickFiles,
|
|
165
|
+
onPickFolders,
|
|
166
|
+
onPickImages,
|
|
167
|
+
onRemoveAttachment,
|
|
168
|
+
onSteer,
|
|
169
|
+
onSubmit,
|
|
170
|
+
onThreadMessagesChange,
|
|
171
|
+
onEdit,
|
|
172
|
+
onReload,
|
|
173
|
+
onTranscribeAudio
|
|
174
|
+
}: ChatViewProps) {
|
|
175
|
+
const location = useLocation()
|
|
176
|
+
const activeSessionId = useStore($activeSessionId)
|
|
177
|
+
const awaitingResponse = useStore($awaitingResponse)
|
|
178
|
+
const busy = useStore($busy)
|
|
179
|
+
const contextSuggestions = useStore($contextSuggestions)
|
|
180
|
+
const currentCwd = useStore($currentCwd)
|
|
181
|
+
const currentModel = useStore($currentModel)
|
|
182
|
+
const currentProvider = useStore($currentProvider)
|
|
183
|
+
const freshDraftReady = useStore($freshDraftReady)
|
|
184
|
+
const gatewayState = useStore($gatewayState)
|
|
185
|
+
const gatewaySwapTarget = useStore($gatewaySwapTarget)
|
|
186
|
+
const gatewayOpen = gatewayState === 'open'
|
|
187
|
+
const introPersonality = useStore($introPersonality)
|
|
188
|
+
const introSeed = useStore($introSeed)
|
|
189
|
+
const messages = useStore($messages)
|
|
190
|
+
const selectedSessionId = useStore($selectedStoredSessionId)
|
|
191
|
+
const runtimeMessageCacheRef = useRef(new WeakMap<ChatMessage, ThreadMessage>())
|
|
192
|
+
const isRoutedSessionView = Boolean(routeSessionId(location.pathname))
|
|
193
|
+
|
|
194
|
+
const showIntro =
|
|
195
|
+
freshDraftReady && !isRoutedSessionView && !selectedSessionId && !activeSessionId && messages.length === 0
|
|
196
|
+
|
|
197
|
+
// Session is still loading if the route references a session we haven't
|
|
198
|
+
// resumed yet. Once `activeSessionId` is set (runtime has resumed), the
|
|
199
|
+
// session exists — even if it has zero messages (a brand-new routed
|
|
200
|
+
// session). The flicker where `busy` flips true briefly during hydrate
|
|
201
|
+
// is handled by `threadLoadingState`'s last-visible-user gate.
|
|
202
|
+
const loadingSession = isRoutedSessionView && messages.length === 0 && !activeSessionId
|
|
203
|
+
const threadLoading = threadLoadingState(loadingSession, busy, awaitingResponse, lastVisibleMessageIsUser(messages))
|
|
204
|
+
const showChatBar = !loadingSession
|
|
205
|
+
const threadKey = selectedSessionId || activeSessionId || (isRoutedSessionView ? location.pathname : 'new')
|
|
206
|
+
|
|
207
|
+
const modelOptionsQuery = useQuery<ModelOptionsResponse>({
|
|
208
|
+
queryKey: ['model-options', activeSessionId || 'global'],
|
|
209
|
+
queryFn: () => {
|
|
210
|
+
if (!activeSessionId) {
|
|
211
|
+
return getGlobalModelOptions()
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!gateway) {
|
|
215
|
+
throw new Error('NasTech gateway unavailable')
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return gateway.request<ModelOptionsResponse>('model.options', { session_id: activeSessionId })
|
|
219
|
+
},
|
|
220
|
+
enabled: gatewayOpen
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
const quickModels = useMemo(
|
|
224
|
+
() => quickModelOptions(modelOptionsQuery.data, currentProvider, currentModel),
|
|
225
|
+
[currentModel, currentProvider, modelOptionsQuery.data]
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
const chatBarState = useMemo<ChatBarState>(
|
|
229
|
+
() => ({
|
|
230
|
+
model: {
|
|
231
|
+
model: currentModel,
|
|
232
|
+
provider: currentProvider,
|
|
233
|
+
canSwitch: gatewayOpen,
|
|
234
|
+
loading: !gatewayOpen || (!currentModel && !currentProvider),
|
|
235
|
+
quickModels
|
|
236
|
+
},
|
|
237
|
+
tools: {
|
|
238
|
+
enabled: true,
|
|
239
|
+
label: 'Add context',
|
|
240
|
+
suggestions: contextSuggestions
|
|
241
|
+
},
|
|
242
|
+
voice: {
|
|
243
|
+
enabled: true,
|
|
244
|
+
active: false
|
|
245
|
+
}
|
|
246
|
+
}),
|
|
247
|
+
[contextSuggestions, currentModel, currentProvider, gatewayOpen, quickModels]
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
const runtimeMessageRepository = useMemo(() => {
|
|
251
|
+
const items: { message: ThreadMessage; parentId: string | null }[] = []
|
|
252
|
+
const branchParentByGroup = new Map<string, string | null>()
|
|
253
|
+
let visibleParentId: string | null = null
|
|
254
|
+
let headId: string | null = null
|
|
255
|
+
|
|
256
|
+
for (const message of messages) {
|
|
257
|
+
let parentId = visibleParentId
|
|
258
|
+
|
|
259
|
+
if (message.role === 'assistant' && message.branchGroupId) {
|
|
260
|
+
if (!branchParentByGroup.has(message.branchGroupId)) {
|
|
261
|
+
branchParentByGroup.set(message.branchGroupId, visibleParentId)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
parentId = branchParentByGroup.get(message.branchGroupId) ?? null
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const cachedMessage = runtimeMessageCacheRef.current.get(message)
|
|
268
|
+
const runtimeMessage = cachedMessage ?? toRuntimeMessage(message)
|
|
269
|
+
|
|
270
|
+
if (!cachedMessage) {
|
|
271
|
+
runtimeMessageCacheRef.current.set(message, runtimeMessage)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
items.push({ message: runtimeMessage, parentId })
|
|
275
|
+
|
|
276
|
+
if (!message.hidden) {
|
|
277
|
+
visibleParentId = message.id
|
|
278
|
+
headId = message.id
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return ExportedMessageRepository.fromBranchableArray(items, { headId })
|
|
283
|
+
}, [messages])
|
|
284
|
+
|
|
285
|
+
const runtime = useIncrementalExternalStoreRuntime<ThreadMessage>({
|
|
286
|
+
messageRepository: runtimeMessageRepository,
|
|
287
|
+
isRunning: busy,
|
|
288
|
+
setMessages: onThreadMessagesChange,
|
|
289
|
+
onNew: async () => {
|
|
290
|
+
// Submission is handled explicitly by ChatBar.
|
|
291
|
+
// Keeping this no-op avoids duplicate prompt.submit calls.
|
|
292
|
+
},
|
|
293
|
+
onEdit,
|
|
294
|
+
onCancel: async () => onCancel(),
|
|
295
|
+
onReload
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
// Drop files anywhere in the conversation area, not just on the composer
|
|
299
|
+
// input — appending the same inline `@file:` ref chips the composer drop
|
|
300
|
+
// produces (vs. attachment cards) so both surfaces behave identically.
|
|
301
|
+
const onDropFiles = useCallback(
|
|
302
|
+
(candidates: DroppedFile[]) => {
|
|
303
|
+
const refs = candidates
|
|
304
|
+
.map(candidate => droppedFileInlineRef(candidate, currentCwd))
|
|
305
|
+
.filter((ref): ref is string => Boolean(ref))
|
|
306
|
+
|
|
307
|
+
if (refs.length) {
|
|
308
|
+
requestComposerInsert(refs.join(' '), { mode: 'inline', target: 'main' })
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
[currentCwd]
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
// Dropping a sidebar session inserts an @session link the agent can resolve
|
|
315
|
+
// via session_search (carries the source profile, so cross-profile works).
|
|
316
|
+
const onDropSession = useCallback((session: SessionDragPayload) => {
|
|
317
|
+
requestComposerInsertRefs([sessionInlineRef(session)], { target: 'main' })
|
|
318
|
+
}, [])
|
|
319
|
+
|
|
320
|
+
const { dragKind, dropHandlers } = useFileDropZone({ enabled: showChatBar, onDropFiles, onDropSession })
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<div
|
|
324
|
+
className={cn(
|
|
325
|
+
'relative isolate flex h-full min-w-0 flex-col overflow-hidden bg-(--ui-chat-surface-background)',
|
|
326
|
+
className
|
|
327
|
+
)}
|
|
328
|
+
>
|
|
329
|
+
<Backdrop />
|
|
330
|
+
<ChatHeader
|
|
331
|
+
activeSessionId={activeSessionId}
|
|
332
|
+
isRoutedSessionView={isRoutedSessionView}
|
|
333
|
+
onDeleteSelectedSession={onDeleteSelectedSession}
|
|
334
|
+
onToggleSelectedPin={onToggleSelectedPin}
|
|
335
|
+
selectedSessionId={selectedSessionId}
|
|
336
|
+
/>
|
|
337
|
+
|
|
338
|
+
<PromptOverlays />
|
|
339
|
+
|
|
340
|
+
<div
|
|
341
|
+
className="relative min-h-0 max-w-full flex-1 overflow-hidden bg-(--ui-chat-surface-background) contain-[layout_paint]"
|
|
342
|
+
{...dropHandlers}
|
|
343
|
+
>
|
|
344
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
345
|
+
<Thread
|
|
346
|
+
clampToComposer={showChatBar}
|
|
347
|
+
cwd={currentCwd}
|
|
348
|
+
gateway={gateway}
|
|
349
|
+
intro={showIntro ? { personality: introPersonality, seed: introSeed } : undefined}
|
|
350
|
+
loading={threadLoading}
|
|
351
|
+
onBranchInNewChat={onBranchInNewChat}
|
|
352
|
+
onCancel={onCancel}
|
|
353
|
+
sessionId={activeSessionId}
|
|
354
|
+
sessionKey={threadKey}
|
|
355
|
+
/>
|
|
356
|
+
{showChatBar && (
|
|
357
|
+
<Suspense fallback={<ChatBarFallback />}>
|
|
358
|
+
<ChatBar
|
|
359
|
+
busy={busy}
|
|
360
|
+
cwd={currentCwd}
|
|
361
|
+
disabled={!gatewayOpen}
|
|
362
|
+
focusKey={activeSessionId}
|
|
363
|
+
gateway={gateway}
|
|
364
|
+
maxRecordingSeconds={maxVoiceRecordingSeconds}
|
|
365
|
+
onAddContextRef={onAddContextRef}
|
|
366
|
+
onAddUrl={onAddUrl}
|
|
367
|
+
onAttachDroppedItems={onAttachDroppedItems}
|
|
368
|
+
onAttachImageBlob={onAttachImageBlob}
|
|
369
|
+
onCancel={onCancel}
|
|
370
|
+
onPasteClipboardImage={onPasteClipboardImage}
|
|
371
|
+
onPickFiles={onPickFiles}
|
|
372
|
+
onPickFolders={onPickFolders}
|
|
373
|
+
onPickImages={onPickImages}
|
|
374
|
+
onRemoveAttachment={onRemoveAttachment}
|
|
375
|
+
onSteer={onSteer}
|
|
376
|
+
onSubmit={onSubmit}
|
|
377
|
+
onTranscribeAudio={onTranscribeAudio}
|
|
378
|
+
queueSessionKey={selectedSessionId || activeSessionId}
|
|
379
|
+
sessionId={activeSessionId}
|
|
380
|
+
state={chatBarState}
|
|
381
|
+
/>
|
|
382
|
+
</Suspense>
|
|
383
|
+
)}
|
|
384
|
+
</AssistantRuntimeProvider>
|
|
385
|
+
<ChatDropOverlay kind={dragKind} />
|
|
386
|
+
<ChatSwapOverlay profile={gatewaySwapTarget} />
|
|
387
|
+
</div>
|
|
388
|
+
</div>
|
|
389
|
+
)
|
|
390
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Profiler, type ProfilerOnRenderCallback, type ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
import { $messages, setBusy, setMessages } from '@/store/session'
|
|
4
|
+
|
|
5
|
+
type Sample = {
|
|
6
|
+
id: string
|
|
7
|
+
phase: string
|
|
8
|
+
actualDuration: number
|
|
9
|
+
baseDuration: number
|
|
10
|
+
startTime: number
|
|
11
|
+
commitTime: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type SyntheticDriverHandle = { stop: () => void }
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
__PERF_PROBE__?: {
|
|
19
|
+
samples: Sample[]
|
|
20
|
+
enabled: boolean
|
|
21
|
+
clear: () => void
|
|
22
|
+
summary: () => Record<string, { count: number; total: number; max: number; p50: number; p95: number }>
|
|
23
|
+
}
|
|
24
|
+
__PERF_DRIVE__?: {
|
|
25
|
+
/** Inject an assistant message and grow it by `chunk` every `intervalMs`. Returns a stop handle. */
|
|
26
|
+
stream: (opts?: { chunk?: string; intervalMs?: number; totalTokens?: number }) => SyntheticDriverHandle
|
|
27
|
+
reset: () => void
|
|
28
|
+
snapshotMsgs: () => number
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof window !== 'undefined' && !window.__PERF_PROBE__) {
|
|
34
|
+
const samples: Sample[] = []
|
|
35
|
+
window.__PERF_PROBE__ = {
|
|
36
|
+
samples,
|
|
37
|
+
enabled: false,
|
|
38
|
+
clear: () => {
|
|
39
|
+
samples.length = 0
|
|
40
|
+
},
|
|
41
|
+
summary: () => {
|
|
42
|
+
const byId = new Map<string, number[]>()
|
|
43
|
+
|
|
44
|
+
for (const s of samples) {
|
|
45
|
+
const k = `${s.id}:${s.phase}`
|
|
46
|
+
const arr = byId.get(k) ?? []
|
|
47
|
+
arr.push(s.actualDuration)
|
|
48
|
+
byId.set(k, arr)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const out: Record<string, { count: number; total: number; max: number; p50: number; p95: number }> = {}
|
|
52
|
+
|
|
53
|
+
for (const [k, arr] of byId) {
|
|
54
|
+
arr.sort((a, b) => a - b)
|
|
55
|
+
const total = arr.reduce((a, b) => a + b, 0)
|
|
56
|
+
out[k] = {
|
|
57
|
+
count: arr.length,
|
|
58
|
+
total: Math.round(total * 100) / 100,
|
|
59
|
+
max: Math.round(arr[arr.length - 1] * 100) / 100,
|
|
60
|
+
p50: Math.round(arr[Math.floor(arr.length * 0.5)] * 100) / 100,
|
|
61
|
+
p95: Math.round(arr[Math.floor(arr.length * 0.95)] * 100) / 100
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return out
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const onRender: ProfilerOnRenderCallback = (id, phase, actualDuration, baseDuration, startTime, commitTime) => {
|
|
71
|
+
const probe = typeof window !== 'undefined' ? window.__PERF_PROBE__ : undefined
|
|
72
|
+
|
|
73
|
+
if (!probe || !probe.enabled) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
probe.samples.push({ id, phase, actualDuration, baseDuration, startTime, commitTime })
|
|
78
|
+
|
|
79
|
+
if (probe.samples.length > 5000) {
|
|
80
|
+
probe.samples.splice(0, probe.samples.length - 5000)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof window !== 'undefined' && !window.__PERF_DRIVE__) {
|
|
85
|
+
// Synthetic stream driver — pushes tokens through the live $messages atom so the
|
|
86
|
+
// assistant-ui runtime + react tree sees them exactly as a real LLM stream would.
|
|
87
|
+
// Used by scripts/measure-real-stream.mjs when no live LLM credit is available.
|
|
88
|
+
let baseline: ReturnType<typeof $messages.get> | null = null
|
|
89
|
+
let activeHandle: SyntheticDriverHandle | null = null
|
|
90
|
+
|
|
91
|
+
const stop = () => {
|
|
92
|
+
activeHandle = null
|
|
93
|
+
setBusy(false)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
window.__PERF_DRIVE__ = {
|
|
97
|
+
snapshotMsgs: () => $messages.get().length,
|
|
98
|
+
reset: () => {
|
|
99
|
+
activeHandle?.stop()
|
|
100
|
+
|
|
101
|
+
if (baseline) {
|
|
102
|
+
setMessages(baseline)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
baseline = null
|
|
106
|
+
setBusy(false)
|
|
107
|
+
},
|
|
108
|
+
stream: ({
|
|
109
|
+
chunk = 'word ',
|
|
110
|
+
intervalMs = 16,
|
|
111
|
+
totalTokens = 400,
|
|
112
|
+
// Mimic `use-message-stream.scheduleDeltaFlush` — batch token deltas
|
|
113
|
+
// into at-most one $messages update every `flushMinMs` ms, exactly as
|
|
114
|
+
// the real gateway path does. With this on, the synthetic harness's
|
|
115
|
+
// numbers actually reflect what a real LLM stream of the same token
|
|
116
|
+
// rate would feel like. Set to 0 to bypass and apply every token
|
|
117
|
+
// immediately (worst-case).
|
|
118
|
+
flushMinMs = 0
|
|
119
|
+
}: { chunk?: string; intervalMs?: number; totalTokens?: number; flushMinMs?: number } = {}) => {
|
|
120
|
+
activeHandle?.stop()
|
|
121
|
+
const current = $messages.get()
|
|
122
|
+
|
|
123
|
+
if (!baseline) {
|
|
124
|
+
baseline = current
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const msgId = `synthetic-${Date.now()}`
|
|
128
|
+
// Seed an empty assistant message — assistant-ui will see it grow.
|
|
129
|
+
setMessages([
|
|
130
|
+
...current,
|
|
131
|
+
{
|
|
132
|
+
id: msgId,
|
|
133
|
+
role: 'assistant',
|
|
134
|
+
parts: [{ type: 'text', text: '' }],
|
|
135
|
+
timestamp: Date.now(),
|
|
136
|
+
pending: true
|
|
137
|
+
}
|
|
138
|
+
])
|
|
139
|
+
setBusy(true)
|
|
140
|
+
|
|
141
|
+
let pushed = 0
|
|
142
|
+
let pendingDelta = ''
|
|
143
|
+
let lastFlushAt = 0
|
|
144
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
145
|
+
let flushHandle: number | null = null
|
|
146
|
+
|
|
147
|
+
const applyDelta = (delta: string) => {
|
|
148
|
+
if (!delta) {
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setMessages(prev =>
|
|
153
|
+
prev.map(m => {
|
|
154
|
+
if (m.id !== msgId) {
|
|
155
|
+
return m
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const head = m.parts.slice(0, -1)
|
|
159
|
+
const last = m.parts.at(-1)
|
|
160
|
+
const lastText = last && last.type === 'text' ? last.text : ''
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
...m,
|
|
164
|
+
parts: [...head, { type: 'text', text: lastText + delta }]
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const flushNow = () => {
|
|
171
|
+
flushHandle = null
|
|
172
|
+
lastFlushAt = performance.now()
|
|
173
|
+
const delta = pendingDelta
|
|
174
|
+
pendingDelta = ''
|
|
175
|
+
applyDelta(delta)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const scheduleFlush = () => {
|
|
179
|
+
if (flushHandle !== null) {
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (flushMinMs <= 0) {
|
|
184
|
+
flushNow()
|
|
185
|
+
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const since = performance.now() - lastFlushAt
|
|
190
|
+
const wait = Math.max(0, flushMinMs - since)
|
|
191
|
+
flushHandle =
|
|
192
|
+
wait <= 0 && typeof requestAnimationFrame === 'function'
|
|
193
|
+
? requestAnimationFrame(flushNow)
|
|
194
|
+
: (setTimeout(flushNow, wait) as unknown as number)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const handle: SyntheticDriverHandle = {
|
|
198
|
+
stop: () => {
|
|
199
|
+
if (timer) {
|
|
200
|
+
clearTimeout(timer)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
timer = null
|
|
204
|
+
|
|
205
|
+
if (flushHandle !== null) {
|
|
206
|
+
clearTimeout(flushHandle)
|
|
207
|
+
cancelAnimationFrame?.(flushHandle)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
flushHandle = null
|
|
211
|
+
|
|
212
|
+
if (pendingDelta) {
|
|
213
|
+
applyDelta(pendingDelta)
|
|
214
|
+
pendingDelta = ''
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
activeHandle = null
|
|
218
|
+
// Mark message finalized.
|
|
219
|
+
setMessages(prev => prev.map(m => (m.id === msgId ? { ...m, pending: false } : m)))
|
|
220
|
+
setBusy(false)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
activeHandle = handle
|
|
225
|
+
|
|
226
|
+
const tick = () => {
|
|
227
|
+
if (activeHandle !== handle) {
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (pushed >= totalTokens) {
|
|
232
|
+
if (pendingDelta) {
|
|
233
|
+
flushNow()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
handle.stop()
|
|
237
|
+
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
pushed += 1
|
|
242
|
+
|
|
243
|
+
if (flushMinMs > 0) {
|
|
244
|
+
pendingDelta += chunk
|
|
245
|
+
scheduleFlush()
|
|
246
|
+
} else {
|
|
247
|
+
applyDelta(chunk)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
timer = setTimeout(tick, intervalMs)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
timer = setTimeout(tick, intervalMs)
|
|
254
|
+
|
|
255
|
+
return handle
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Suppress dead-import warning.
|
|
260
|
+
void stop
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function PerfProbe({ id, children }: { id: string; children: ReactNode }) {
|
|
264
|
+
return (
|
|
265
|
+
<Profiler id={id} onRender={onRender}>
|
|
266
|
+
{children}
|
|
267
|
+
</Profiler>
|
|
268
|
+
)
|
|
269
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChatPreviewRail, PREVIEW_RAIL_MAX_WIDTH, PREVIEW_RAIL_MIN_WIDTH, PREVIEW_RAIL_PANE_WIDTH } from './preview'
|