@dyyz1993/create-agent 2.1.0 → 2.1.2
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/package.json +5 -4
- package/src/__tests__/cli.test.ts +2 -0
- package/src/__tests__/copy.test.ts +110 -122
- package/src/__tests__/create-args.test.ts +113 -0
- package/src/__tests__/templates.test.ts +29 -3
- package/src/__tests__/update.test.ts +129 -0
- package/src/cli.ts +30 -32
- package/src/commands/create.ts +83 -24
- package/src/commands/update.ts +174 -0
- package/src/commands/workspace.ts +26 -6
- package/src/lib/copy.ts +233 -93
- package/src/lib/templates.ts +12 -0
- package/templates/agent/.husky/commit-msg +4 -0
- package/templates/agent/.husky/pre-commit +11 -0
- package/templates/agent/.husky/pre-push +6 -0
- package/templates/agent/.prettierignore +6 -0
- package/templates/agent/.prettierrc +9 -0
- package/templates/agent/CHANGELOG.md +15 -0
- package/templates/agent/commitlint.config.js +8 -0
- package/templates/agent/package.json +19 -4
- package/templates/agent/src/gateway/__tests__/ws-handler-token.test.ts +53 -39
- package/templates/agent/src/mainview/App.tsx +14 -12
- package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +194 -190
- package/templates/agent/src/mainview/components/bash/BashPanel.tsx +210 -189
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +45 -20
- package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +41 -21
- package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +181 -114
- package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +80 -80
- package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +61 -58
- package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +43 -41
- package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +69 -50
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +31 -18
- package/templates/agent/src/mainview/components/git/GitPanel.tsx +731 -490
- package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +157 -139
- package/templates/agent/src/mainview/components/layout/AppLayout.tsx +210 -161
- package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +130 -122
- package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +119 -109
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +123 -117
- package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +64 -44
- package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +38 -38
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +40 -38
- package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +72 -72
- package/templates/agent/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/agent/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/agent/src/mainview/stores/use-app-store.ts +96 -86
- package/templates/agent/src/mainview/stores/use-explorer-store.ts +292 -275
- package/templates/agent/src/mainview/types/index.ts +23 -22
- package/templates/agent/src/mainview/utils/file-icon.tsx +17 -21
- package/templates/agent/src/shared/handlers/chat.ts +53 -53
- package/templates/agent/src/shared/handlers/debug.ts +13 -3
- package/templates/browser-agent/.env.example +19 -0
- package/templates/browser-agent/.husky/commit-msg +4 -0
- package/templates/browser-agent/.husky/pre-commit +11 -0
- package/templates/browser-agent/.husky/pre-push +6 -0
- package/templates/browser-agent/.prettierignore +6 -0
- package/templates/browser-agent/.prettierrc +9 -0
- package/templates/browser-agent/AGENTS.md +396 -0
- package/templates/browser-agent/CHANGELOG.md +15 -0
- package/templates/browser-agent/LICENSE +21 -0
- package/templates/browser-agent/README.md +103 -0
- package/templates/browser-agent/commitlint.config.js +8 -0
- package/templates/browser-agent/electrobun.config.ts +27 -0
- package/templates/browser-agent/electron/main.js +46 -0
- package/templates/browser-agent/electron/preload.js +5 -0
- package/templates/browser-agent/electron-builder.json +40 -0
- package/templates/browser-agent/eslint.config.mjs +79 -0
- package/templates/browser-agent/llms.txt +24 -0
- package/templates/browser-agent/package.json +140 -0
- package/templates/browser-agent/postcss.config.js +6 -0
- package/templates/browser-agent/scripts/dev.ts +138 -0
- package/templates/browser-agent/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/browser-agent/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/browser-agent/src/__tests__/server-config.test.ts +59 -0
- package/templates/browser-agent/src/bun/index.ts +130 -0
- package/templates/browser-agent/src/bun/three.d.ts +1 -0
- package/templates/browser-agent/src/gateway/http-routes.ts +1 -0
- package/templates/browser-agent/src/gateway/ipc-transport.ts +68 -0
- package/templates/browser-agent/src/gateway/sse-transport.ts +221 -0
- package/templates/browser-agent/src/mainview/App.tsx +45 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/browser-agent/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/browser-agent/src/mainview/__tests__/setup.ts +40 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/browser-agent/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/browser-agent/src/mainview/components/assets/AssetsPanel.tsx +139 -0
- package/templates/browser-agent/src/mainview/components/chat/ChatPanel.tsx +219 -0
- package/templates/browser-agent/src/mainview/components/chat/CommandBar.tsx +184 -0
- package/templates/browser-agent/src/mainview/components/chat/MessageBubble.tsx +249 -0
- package/templates/browser-agent/src/mainview/components/chat/ToolPicker.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/browser-agent/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/browser-agent/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/browser-agent/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/browser-agent/src/mainview/components/layout/AppLayout.tsx +311 -0
- package/templates/browser-agent/src/mainview/components/onboarding/SetupWizard.tsx +310 -0
- package/templates/browser-agent/src/mainview/components/process/ProcessPanel.tsx +329 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SessionSidebar.tsx +122 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SkillSidebar.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/topbar/TopBar.tsx +350 -0
- package/templates/browser-agent/src/mainview/global.d.ts +13 -0
- package/templates/browser-agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +151 -0
- package/templates/browser-agent/src/mainview/hooks/use-agent-chat.ts +157 -0
- package/templates/browser-agent/src/mainview/hooks/use-breakpoint.ts +68 -0
- package/templates/browser-agent/src/mainview/hooks/use-rpc-init.ts +71 -0
- package/templates/browser-agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/browser-agent/src/mainview/index.css +71 -0
- package/templates/browser-agent/src/mainview/index.html +12 -0
- package/templates/browser-agent/src/mainview/lib/api-client.ts +397 -0
- package/templates/browser-agent/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/browser-agent/src/mainview/lib/network-bus.ts +92 -0
- package/templates/browser-agent/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/browser-agent/src/mainview/main.tsx +18 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/browser-agent/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/browser-agent/src/mainview/stores/use-asset-store.ts +65 -0
- package/templates/browser-agent/src/mainview/stores/use-chat-store.ts +200 -0
- package/templates/browser-agent/src/mainview/stores/use-connection-store.ts +173 -0
- package/templates/browser-agent/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/browser-agent/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/browser-agent/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/browser-agent/src/mainview/stores/use-record-store.ts +147 -0
- package/templates/browser-agent/src/mainview/stores/use-session-store.ts +151 -0
- package/templates/browser-agent/src/mainview/stores/use-sidebar-store.ts +161 -0
- package/templates/browser-agent/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/browser-agent/src/mainview/stores/use-view-store.ts +20 -0
- package/templates/browser-agent/src/mainview/types/index.ts +6 -0
- package/templates/browser-agent/src/server-config.ts +45 -0
- package/templates/browser-agent/src/server.ts +78 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/browser.ts +596 -0
- package/templates/browser-agent/src/shared/handlers/chat.ts +213 -0
- package/templates/browser-agent/src/shared/handlers/file.ts +99 -0
- package/templates/browser-agent/src/shared/handlers/index.ts +7 -0
- package/templates/browser-agent/src/shared/handlers/session.ts +167 -0
- package/templates/browser-agent/src/shared/handlers/system.ts +27 -0
- package/templates/browser-agent/src/shared/handlers/timer.ts +34 -0
- package/templates/browser-agent/src/shared/http-routes.ts +437 -0
- package/templates/browser-agent/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/browser-agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/browser-agent/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/browser-agent/src/shared/lib/agent.ts +384 -0
- package/templates/browser-agent/src/shared/lib/cdp.ts +448 -0
- package/templates/browser-agent/src/shared/lib/generate.ts +111 -0
- package/templates/browser-agent/src/shared/lib/logger.ts +152 -0
- package/templates/browser-agent/src/shared/lib/mock-stream.ts +147 -0
- package/templates/browser-agent/src/shared/lib/path-security.ts +38 -0
- package/templates/browser-agent/src/shared/lib/port-registry.ts +103 -0
- package/templates/browser-agent/src/shared/lib/web-server.ts +127 -0
- package/templates/browser-agent/src/shared/lib/xhs-extract.ts +71 -0
- package/templates/browser-agent/src/shared/modules/browser.ts +86 -0
- package/templates/browser-agent/src/shared/modules/chat.ts +20 -0
- package/templates/browser-agent/src/shared/modules/file.ts +40 -0
- package/templates/browser-agent/src/shared/modules/session.ts +55 -0
- package/templates/browser-agent/src/shared/modules/system.ts +8 -0
- package/templates/browser-agent/src/shared/modules/timer.ts +11 -0
- package/templates/browser-agent/src/shared/register-all-handlers.ts +36 -0
- package/templates/browser-agent/src/shared/rpc-schema.ts +34 -0
- package/templates/browser-agent/tailwind.config.js +15 -0
- package/templates/browser-agent/tsconfig.ipc.json +14 -0
- package/templates/browser-agent/tsconfig.json +36 -0
- package/templates/browser-agent/vite.config.ts +3 -0
- package/templates/browser-agent/vitest.config.ts +3 -0
- package/templates/chat/.husky/commit-msg +4 -0
- package/templates/chat/.husky/pre-commit +11 -0
- package/templates/chat/.husky/pre-push +6 -0
- package/templates/chat/CHANGELOG.md +15 -0
- package/templates/chat/commitlint.config.js +8 -0
- package/templates/chat/package.json +19 -4
- package/templates/chat/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/chat/src/mainview/__tests__/setup.ts +32 -29
- package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/chat/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/chat/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/chat/src/shared/handlers/chat.ts +17 -19
- package/templates/chat/src/shared/handlers/debug.ts +12 -2
- package/templates/cowork/.env.example +8 -0
- package/templates/cowork/.prettierignore +6 -0
- package/templates/cowork/.prettierrc +9 -0
- package/templates/cowork/AGENTS.md +236 -0
- package/templates/cowork/CHANGELOG.md +15 -0
- package/templates/cowork/LICENSE +21 -0
- package/templates/cowork/README.md +103 -0
- package/templates/cowork/commitlint.config.js +8 -0
- package/templates/cowork/docs/CODE-VIEW-PLAN.md +637 -0
- package/templates/cowork/docs/CODE-VIEW-V2.md +196 -0
- package/templates/cowork/docs/CODE-VIEW-V4.md +150 -0
- package/templates/cowork/electrobun.config.ts +27 -0
- package/templates/cowork/eslint.config.mjs +79 -0
- package/templates/cowork/llms.txt +24 -0
- package/templates/cowork/package.json +87 -0
- package/templates/cowork/postcss.config.js +6 -0
- package/templates/cowork/scripts/dev.ts +138 -0
- package/templates/cowork/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/cowork/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/cowork/src/__tests__/server-config.test.ts +59 -0
- package/templates/cowork/src/bun/index.ts +130 -0
- package/templates/cowork/src/bun/three.d.ts +1 -0
- package/templates/cowork/src/gateway/http-routes.ts +1 -0
- package/templates/cowork/src/gateway/ipc-transport.ts +68 -0
- package/templates/cowork/src/gateway/sse-transport.ts +231 -0
- package/templates/cowork/src/mainview/App.tsx +45 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/cowork/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/cowork/src/mainview/__tests__/setup.ts +40 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/cowork/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/cowork/src/mainview/components/chat/TaskChat.tsx +311 -0
- package/templates/cowork/src/mainview/components/chat/__tests__/localhost-links.test.ts +76 -0
- package/templates/cowork/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/cowork/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/cowork/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/cowork/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/cowork/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/cowork/src/mainview/components/layout/AppLayout.tsx +216 -0
- package/templates/cowork/src/mainview/components/right/ArtifactsPanel.tsx +54 -0
- package/templates/cowork/src/mainview/components/right/ContextPanel.tsx +133 -0
- package/templates/cowork/src/mainview/components/right/ElementPicker.tsx +206 -0
- package/templates/cowork/src/mainview/components/right/PreviewBlock.tsx +155 -0
- package/templates/cowork/src/mainview/components/right/ProgressPanel.tsx +85 -0
- package/templates/cowork/src/mainview/components/sidebar/TaskSidebar.tsx +211 -0
- package/templates/cowork/src/mainview/components/topbar/TopBar.tsx +86 -0
- package/templates/cowork/src/mainview/global.d.ts +13 -0
- package/templates/cowork/src/mainview/hooks/__tests__/use-breakpoint.test.ts +123 -0
- package/templates/cowork/src/mainview/hooks/use-breakpoint.ts +53 -0
- package/templates/cowork/src/mainview/hooks/use-rpc-init.ts +26 -0
- package/templates/cowork/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/cowork/src/mainview/index.css +89 -0
- package/templates/cowork/src/mainview/index.html +12 -0
- package/templates/cowork/src/mainview/lib/api-client.ts +404 -0
- package/templates/cowork/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/cowork/src/mainview/lib/network-bus.ts +92 -0
- package/templates/cowork/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/cowork/src/mainview/main.tsx +18 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-preview-store.test.ts +193 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-sidebar-store.test.ts +81 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/cowork/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/cowork/src/mainview/stores/use-chat-store.ts +198 -0
- package/templates/cowork/src/mainview/stores/use-connection-store.ts +168 -0
- package/templates/cowork/src/mainview/stores/use-context-store.ts +68 -0
- package/templates/cowork/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/cowork/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/cowork/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/cowork/src/mainview/stores/use-output-store.ts +47 -0
- package/templates/cowork/src/mainview/stores/use-preview-store.ts +97 -0
- package/templates/cowork/src/mainview/stores/use-sidebar-store.ts +272 -0
- package/templates/cowork/src/mainview/stores/use-task-store.ts +86 -0
- package/templates/cowork/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/cowork/src/mainview/stores/use-view-store.ts +29 -0
- package/templates/cowork/src/mainview/types/index.ts +6 -0
- package/templates/cowork/src/server-config.ts +44 -0
- package/templates/cowork/src/server.ts +78 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/cowork/src/shared/handlers/__tests__/preview-handler.test.ts +172 -0
- package/templates/cowork/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/cowork/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/chat.ts +213 -0
- package/templates/cowork/src/shared/handlers/context.ts +72 -0
- package/templates/cowork/src/shared/handlers/file.ts +99 -0
- package/templates/cowork/src/shared/handlers/index.ts +9 -0
- package/templates/cowork/src/shared/handlers/output.ts +59 -0
- package/templates/cowork/src/shared/handlers/preview.ts +81 -0
- package/templates/cowork/src/shared/handlers/system.ts +27 -0
- package/templates/cowork/src/shared/handlers/task.ts +101 -0
- package/templates/cowork/src/shared/handlers/timer.ts +34 -0
- package/templates/cowork/src/shared/http-routes.ts +444 -0
- package/templates/cowork/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/cowork/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/cowork/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/cowork/src/shared/lib/logger.ts +152 -0
- package/templates/cowork/src/shared/lib/path-security.ts +38 -0
- package/templates/cowork/src/shared/lib/port-registry.ts +103 -0
- package/templates/cowork/src/shared/lib/web-server.ts +127 -0
- package/templates/cowork/src/shared/modules/chat.ts +20 -0
- package/templates/cowork/src/shared/modules/context.ts +32 -0
- package/templates/cowork/src/shared/modules/file.ts +40 -0
- package/templates/cowork/src/shared/modules/output.ts +20 -0
- package/templates/cowork/src/shared/modules/preview.ts +44 -0
- package/templates/cowork/src/shared/modules/system.ts +8 -0
- package/templates/cowork/src/shared/modules/task.ts +31 -0
- package/templates/cowork/src/shared/modules/timer.ts +11 -0
- package/templates/cowork/src/shared/register-all-handlers.ts +36 -0
- package/templates/cowork/src/shared/rpc-schema.ts +38 -0
- package/templates/cowork/tailwind.config.js +15 -0
- package/templates/cowork/test-upload.txt +0 -0
- package/templates/cowork/tsconfig.ipc.json +14 -0
- package/templates/cowork/tsconfig.json +36 -0
- package/templates/cowork/vite.config.ts +3 -0
- package/templates/cowork/vitest.config.ts +3 -0
- package/templates/general/.husky/commit-msg +4 -0
- package/templates/general/.husky/pre-commit +11 -0
- package/templates/general/.husky/pre-push +6 -0
- package/templates/general/CHANGELOG.md +15 -0
- package/templates/general/commitlint.config.js +8 -0
- package/templates/general/package.json +19 -4
- package/templates/general/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/general/src/mainview/__tests__/setup.ts +32 -29
- package/templates/general/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/general/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/general/src/mainview/components/debug/DebugPanel.tsx +170 -156
- package/templates/general/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +169 -0
- package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +42 -42
- package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +72 -67
- package/templates/general/src/mainview/components/feed/FeedPanel.tsx +7 -5
- package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +64 -45
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +24 -7
- package/templates/general/src/mainview/components/git/GitPanel.tsx +700 -473
- package/templates/general/src/mainview/components/layout/AppLayout.tsx +123 -114
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +15 -19
- package/templates/general/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/general/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/general/src/mainview/stores/__tests__/use-explorer-store.test.ts +259 -0
- package/templates/general/src/mainview/stores/__tests__/use-feed-store.test.ts +160 -0
- package/templates/general/src/mainview/stores/__tests__/use-git-store.test.ts +313 -0
- package/templates/general/src/mainview/stores/__tests__/use-notification-store.test.ts +115 -0
- package/templates/general/src/mainview/stores/__tests__/use-sidebar-store.test.ts +120 -0
- package/templates/general/src/mainview/stores/use-explorer-store.ts +277 -260
- package/templates/general/src/mainview/types/index.ts +21 -20
- package/templates/general/src/shared/handlers/chat.ts +1 -1
- package/templates/general/src/shared/handlers/debug.ts +12 -2
- package/templates/shared/components/ErrorBoundary.tsx +0 -1
- package/templates/shared/vite-base.config.ts +8 -7
- /package/templates/{shared → browser-agent}/test-upload.txt +0 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 顶栏 — Logo、连接状态、标签页选择器、插件、版本号
|
|
3
|
+
*
|
|
4
|
+
* 对应 PRD §5.2 Topbar 职责
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useState, useEffect, useRef } from "react";
|
|
8
|
+
import { Monitor, Wifi, WifiOff, ChevronDown, RefreshCw, Globe, Puzzle, PanelLeft, PanelLeftOpen, PanelRight, Circle, Square } from "lucide-react";
|
|
9
|
+
import { useTranslation } from "react-i18next";
|
|
10
|
+
import { useConnectionStore } from "../../stores/use-connection-store";
|
|
11
|
+
import { useSidebarStore, useAssetsPanelStore } from "../../stores/use-sidebar-store";
|
|
12
|
+
import { ThemeToggle } from "../common/ThemeToggle";
|
|
13
|
+
import { LanguageSwitcher } from "../common/LanguageSwitcher";
|
|
14
|
+
import { NetworkToggleButton } from "../dev/NetworkPanel";
|
|
15
|
+
import { SetupWizard } from "../onboarding/SetupWizard";
|
|
16
|
+
import { useRecordStore } from "../../stores/use-record-store";
|
|
17
|
+
import { useViewStore } from "../../stores/use-view-store";
|
|
18
|
+
|
|
19
|
+
export function TopBar() {
|
|
20
|
+
const { t } = useTranslation();
|
|
21
|
+
const mode = useConnectionStore((s) => s.mode);
|
|
22
|
+
const browserStatus = useConnectionStore((s) => s.browserStatus);
|
|
23
|
+
const tabs = useConnectionStore((s) => s.tabs);
|
|
24
|
+
const selectedTabIndex = useConnectionStore((s) => s.selectedTabIndex);
|
|
25
|
+
const activeTabIndex = useConnectionStore((s) => s.activeTabIndex);
|
|
26
|
+
const selectTab = useConnectionStore((s) => s.selectTab);
|
|
27
|
+
const loadTabs = useConnectionStore((s) => s.loadTabs);
|
|
28
|
+
const plugins = useConnectionStore((s) => s.plugins);
|
|
29
|
+
const activePlugins = useConnectionStore((s) => s.activePlugins);
|
|
30
|
+
const toggleActivePlugin = useConnectionStore((s) => s.toggleActivePlugin);
|
|
31
|
+
|
|
32
|
+
const isOnline = browserStatus === "online";
|
|
33
|
+
const [tabDropdownOpen, setTabDropdownOpen] = useState(false);
|
|
34
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
35
|
+
const [showSetup, setShowSetup] = useState(false);
|
|
36
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
|
|
38
|
+
// 面板状态
|
|
39
|
+
const sbSidebarMode = useSidebarStore((s) => s.sidebarMode);
|
|
40
|
+
const sbCycleMode = useSidebarStore((s) => s.cycleSidebarMode);
|
|
41
|
+
const sbDrawerOpen = useSidebarStore((s) => s.drawerOpen);
|
|
42
|
+
const sbSetDrawerOpen = useSidebarStore((s) => s.setDrawerOpen);
|
|
43
|
+
const sbBreakpoint = useSidebarStore((s) => s.breakpoint);
|
|
44
|
+
const apVisible = useAssetsPanelStore((s) => s.assetsVisible);
|
|
45
|
+
const apSetVisible = useAssetsPanelStore((s) => s.setAssetsVisible);
|
|
46
|
+
const apDrawerOpen = useAssetsPanelStore((s) => s.assetsDrawerOpen);
|
|
47
|
+
const apSetDrawerOpen = useAssetsPanelStore((s) => s.setAssetsDrawerOpen);
|
|
48
|
+
|
|
49
|
+
// 侧栏是否当前可见(full/icon 档位 或 移动端抽屉)
|
|
50
|
+
const sidebarActive = sbSidebarMode !== "hidden" || sbDrawerOpen;
|
|
51
|
+
// 资源面板是否当前可见
|
|
52
|
+
const assetsActive = apVisible || apDrawerOpen;
|
|
53
|
+
|
|
54
|
+
// 侧栏循环切换:桌面端走三态,移动端走抽屉开关
|
|
55
|
+
const handleSidebarToggle = (): void => {
|
|
56
|
+
if (sbBreakpoint === "mobile" || sbBreakpoint === "tablet") {
|
|
57
|
+
sbSetDrawerOpen(!sbDrawerOpen);
|
|
58
|
+
} else {
|
|
59
|
+
sbCycleMode();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// 录制状态
|
|
64
|
+
const isRecording = useRecordStore((s) => s.isRecording);
|
|
65
|
+
const actionCount = useRecordStore((s) => s.actionCount);
|
|
66
|
+
const startRecording = useRecordStore((s) => s.startRecording);
|
|
67
|
+
const stopRecording = useRecordStore((s) => s.stopRecording);
|
|
68
|
+
const setActiveView = useViewStore((s) => s.setActiveView);
|
|
69
|
+
|
|
70
|
+
const handleToggleRecord = async (): Promise<void> => {
|
|
71
|
+
if (isRecording) {
|
|
72
|
+
await stopRecording();
|
|
73
|
+
// 停止后切到加工 Tab,查看录制结果
|
|
74
|
+
setActiveView("process");
|
|
75
|
+
} else {
|
|
76
|
+
const ok = await startRecording();
|
|
77
|
+
if (ok) {
|
|
78
|
+
// 开始录制后切到加工 Tab,让用户看到录制状态
|
|
79
|
+
setActiveView("process");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// 点击外部关闭下拉
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const handler = (e: MouseEvent): void => {
|
|
87
|
+
if (dropdownRef.current && !dropdownRef.current.contains(e.target as Node)) {
|
|
88
|
+
setTabDropdownOpen(false);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
document.addEventListener("mousedown", handler);
|
|
92
|
+
return () => document.removeEventListener("mousedown", handler);
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const handleRefreshTabs = async (): Promise<void> => {
|
|
96
|
+
setRefreshing(true);
|
|
97
|
+
await loadTabs();
|
|
98
|
+
setTimeout(() => setRefreshing(false), 500);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const effectiveTab = selectedTabIndex ?? activeTabIndex;
|
|
102
|
+
const currentTab = tabs[effectiveTab];
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div className="h-10 bg-[var(--color-bg-secondary)] flex items-center px-3 text-xs border-b border-[var(--color-border-primary)] flex-shrink-0 gap-3">
|
|
106
|
+
{/* Logo */}
|
|
107
|
+
<div className="flex items-center gap-2">
|
|
108
|
+
<span className="text-base">◈</span>
|
|
109
|
+
<span className="font-semibold text-sm">Browser Agent</span>
|
|
110
|
+
<span className="text-[var(--color-text-tertiary)]">v0.4.0</span>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
{/* 分割线 */}
|
|
114
|
+
<div className="w-px h-4 bg-[var(--color-border-primary)]" />
|
|
115
|
+
|
|
116
|
+
{/* 侧栏切换(三态循环:full → icon → hidden) */}
|
|
117
|
+
<button
|
|
118
|
+
onClick={handleSidebarToggle}
|
|
119
|
+
title={
|
|
120
|
+
sbBreakpoint === "mobile" || sbBreakpoint === "tablet"
|
|
121
|
+
? sbDrawerOpen ? "收起侧栏" : "展开侧栏"
|
|
122
|
+
: sbSidebarMode === "full" ? "折叠为图标条"
|
|
123
|
+
: sbSidebarMode === "icon" ? "完全隐藏侧栏"
|
|
124
|
+
: "展开侧栏"
|
|
125
|
+
}
|
|
126
|
+
className={`text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)] transition-colors p-1 rounded hover:bg-[var(--color-bg-hover)] ${
|
|
127
|
+
sidebarActive ? "text-[var(--color-text-accent)]" : ""
|
|
128
|
+
}`}
|
|
129
|
+
>
|
|
130
|
+
{sbSidebarMode === "hidden" && !sbDrawerOpen ? (
|
|
131
|
+
<PanelLeftOpen className="w-4 h-4" />
|
|
132
|
+
) : (
|
|
133
|
+
<PanelLeft className="w-4 h-4" />
|
|
134
|
+
)}
|
|
135
|
+
</button>
|
|
136
|
+
|
|
137
|
+
{/* 模式标签 */}
|
|
138
|
+
<span
|
|
139
|
+
className={`px-2 py-0.5 rounded flex items-center gap-1 ${
|
|
140
|
+
mode === "desktop" ? "bg-green-600" : "bg-blue-600"
|
|
141
|
+
}`}
|
|
142
|
+
>
|
|
143
|
+
{mode === "desktop" ? (
|
|
144
|
+
<Monitor className="w-3 h-3" />
|
|
145
|
+
) : (
|
|
146
|
+
<Wifi className="w-3 h-3" />
|
|
147
|
+
)}
|
|
148
|
+
{mode === "desktop" ? t("app.mode.desktop") : t("app.mode.web")}
|
|
149
|
+
</span>
|
|
150
|
+
|
|
151
|
+
{/* 连接状态指示器 */}
|
|
152
|
+
<span
|
|
153
|
+
className={`flex items-center gap-1.5 px-2 py-0.5 rounded ${
|
|
154
|
+
isOnline
|
|
155
|
+
? "bg-[var(--color-text-success)]/10 text-[var(--color-text-success)]"
|
|
156
|
+
: "bg-[var(--color-text-error)]/10 text-[var(--color-text-error)]"
|
|
157
|
+
}`}
|
|
158
|
+
>
|
|
159
|
+
{isOnline ? (
|
|
160
|
+
<>
|
|
161
|
+
<span className="relative flex w-2 h-2">
|
|
162
|
+
<span className="absolute inline-flex w-full h-full rounded-full bg-[var(--color-text-success)] opacity-60 animate-ping" />
|
|
163
|
+
<span className="relative inline-flex w-2 h-2 rounded-full bg-[var(--color-text-success)]" />
|
|
164
|
+
</span>
|
|
165
|
+
<Wifi className="w-3 h-3" />
|
|
166
|
+
已连接
|
|
167
|
+
{tabs.length > 0 && (
|
|
168
|
+
<span className="text-[var(--color-text-tertiary)]">· {tabs.length} 标签</span>
|
|
169
|
+
)}
|
|
170
|
+
</>
|
|
171
|
+
) : (
|
|
172
|
+
<>
|
|
173
|
+
<span className="relative flex w-2 h-2">
|
|
174
|
+
<span className="relative inline-flex w-2 h-2 rounded-full bg-[var(--color-text-error)]" />
|
|
175
|
+
</span>
|
|
176
|
+
<WifiOff className="w-3 h-3" />
|
|
177
|
+
未连接
|
|
178
|
+
</>
|
|
179
|
+
)}
|
|
180
|
+
</span>
|
|
181
|
+
|
|
182
|
+
{/* 未连接时的安装入口 */}
|
|
183
|
+
{!isOnline && (
|
|
184
|
+
<button
|
|
185
|
+
onClick={() => setShowSetup(true)}
|
|
186
|
+
className="flex items-center gap-1.5 px-2.5 py-1 text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded transition-colors text-white font-medium"
|
|
187
|
+
>
|
|
188
|
+
<Puzzle className="w-3 h-3" />
|
|
189
|
+
安装扩展
|
|
190
|
+
</button>
|
|
191
|
+
)}
|
|
192
|
+
|
|
193
|
+
{/* 标签页选择器(仅在线时显示) */}
|
|
194
|
+
{isOnline && tabs.length > 0 && (
|
|
195
|
+
<div className="relative" ref={dropdownRef}>
|
|
196
|
+
<button
|
|
197
|
+
onClick={() => setTabDropdownOpen(!tabDropdownOpen)}
|
|
198
|
+
className="flex items-center gap-1 px-2 py-0.5 rounded border border-[var(--color-border-primary)] hover:bg-[var(--color-bg-hover)] max-w-xs"
|
|
199
|
+
title="选择操作的目标标签页"
|
|
200
|
+
>
|
|
201
|
+
<Globe className="w-3 h-3 flex-shrink-0" />
|
|
202
|
+
<span className="truncate max-w-[120px]">
|
|
203
|
+
{currentTab ? currentTab.title || currentTab.url : `标签 #${effectiveTab}`}
|
|
204
|
+
</span>
|
|
205
|
+
<span className="text-[var(--color-text-tertiary)]">#{effectiveTab}</span>
|
|
206
|
+
<ChevronDown className="w-3 h-3 flex-shrink-0" />
|
|
207
|
+
</button>
|
|
208
|
+
|
|
209
|
+
{tabDropdownOpen && (
|
|
210
|
+
<div className="absolute top-full left-0 mt-1 w-80 bg-[var(--color-bg-sidebar)] border border-[var(--color-border-primary)] rounded shadow-lg z-50 max-h-96 overflow-auto">
|
|
211
|
+
{/* 活跃标签页选项(默认) */}
|
|
212
|
+
<button
|
|
213
|
+
onClick={() => {
|
|
214
|
+
selectTab(null);
|
|
215
|
+
setTabDropdownOpen(false);
|
|
216
|
+
}}
|
|
217
|
+
className={`w-full text-left px-3 py-2 hover:bg-[var(--color-bg-hover)] flex items-center gap-2 border-b border-[var(--color-border-secondary)] ${
|
|
218
|
+
selectedTabIndex === null ? "bg-[var(--color-accent)]/10" : ""
|
|
219
|
+
}`}
|
|
220
|
+
>
|
|
221
|
+
<span className="text-[var(--color-text-tertiary)] flex-shrink-0">★</span>
|
|
222
|
+
<div className="flex-1 min-w-0">
|
|
223
|
+
<div className="text-[var(--color-text-primary)]">活跃标签页(自动)</div>
|
|
224
|
+
<div className="text-[var(--color-text-tertiary)] truncate text-[10px]">
|
|
225
|
+
{tabs[activeTabIndex]?.url || "—"}
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
</button>
|
|
229
|
+
|
|
230
|
+
{/* 所有标签页 */}
|
|
231
|
+
{tabs.map((tab) => (
|
|
232
|
+
<button
|
|
233
|
+
key={tab.index}
|
|
234
|
+
onClick={() => {
|
|
235
|
+
selectTab(tab.index);
|
|
236
|
+
setTabDropdownOpen(false);
|
|
237
|
+
}}
|
|
238
|
+
className={`w-full text-left px-3 py-2 hover:bg-[var(--color-bg-hover)] flex items-center gap-2 ${
|
|
239
|
+
selectedTabIndex === tab.index ? "bg-[var(--color-accent)]/10" : ""
|
|
240
|
+
}`}
|
|
241
|
+
>
|
|
242
|
+
<span className="text-[var(--color-text-tertiary)] flex-shrink-0">
|
|
243
|
+
#{tab.index}
|
|
244
|
+
</span>
|
|
245
|
+
<div className="flex-1 min-w-0">
|
|
246
|
+
<div className="text-[var(--color-text-primary)] truncate text-xs">
|
|
247
|
+
{tab.title || "(无标题)"}
|
|
248
|
+
</div>
|
|
249
|
+
<div className="text-[var(--color-text-tertiary)] truncate text-[10px]">
|
|
250
|
+
{tab.url}
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
253
|
+
{tab.active && (
|
|
254
|
+
<span className="text-[var(--color-text-success)] text-[10px] flex-shrink-0">
|
|
255
|
+
活跃
|
|
256
|
+
</span>
|
|
257
|
+
)}
|
|
258
|
+
</button>
|
|
259
|
+
))}
|
|
260
|
+
|
|
261
|
+
{/* 刷新按钮 */}
|
|
262
|
+
<button
|
|
263
|
+
onClick={handleRefreshTabs}
|
|
264
|
+
className="w-full text-left px-3 py-2 hover:bg-[var(--color-bg-hover)] flex items-center gap-2 border-t border-[var(--color-border-secondary)] text-[var(--color-text-secondary)]"
|
|
265
|
+
>
|
|
266
|
+
<RefreshCw className={`w-3 h-3 ${refreshing ? "animate-spin" : ""}`} />
|
|
267
|
+
刷新标签页列表
|
|
268
|
+
</button>
|
|
269
|
+
</div>
|
|
270
|
+
)}
|
|
271
|
+
</div>
|
|
272
|
+
)}
|
|
273
|
+
|
|
274
|
+
{/* 弹性间距 */}
|
|
275
|
+
<div className="flex-1" />
|
|
276
|
+
|
|
277
|
+
{/* 插件选择器 */}
|
|
278
|
+
<div className="flex items-center gap-1 max-w-md overflow-x-auto">
|
|
279
|
+
{activePlugins.map((name) => (
|
|
280
|
+
<button
|
|
281
|
+
key={name}
|
|
282
|
+
onClick={() => toggleActivePlugin(name)}
|
|
283
|
+
className="px-2 py-0.5 rounded-full bg-[var(--color-accent)]/20 text-[var(--color-text-accent)] text-xs hover:bg-[var(--color-accent)]/30 whitespace-nowrap"
|
|
284
|
+
>
|
|
285
|
+
{name} ✕
|
|
286
|
+
</button>
|
|
287
|
+
))}
|
|
288
|
+
{plugins.length > 0 && (
|
|
289
|
+
<select
|
|
290
|
+
onChange={(e) => {
|
|
291
|
+
if (e.target.value) toggleActivePlugin(e.target.value);
|
|
292
|
+
e.target.value = "";
|
|
293
|
+
}}
|
|
294
|
+
className="bg-transparent border border-[var(--color-border-primary)] rounded px-1 py-0.5 text-xs cursor-pointer"
|
|
295
|
+
defaultValue=""
|
|
296
|
+
>
|
|
297
|
+
<option value="">+ 插件</option>
|
|
298
|
+
{plugins
|
|
299
|
+
.filter((p) => !activePlugins.includes(p.name))
|
|
300
|
+
.map((p) => (
|
|
301
|
+
<option key={p.name} value={p.name}>
|
|
302
|
+
{p.name}
|
|
303
|
+
</option>
|
|
304
|
+
))}
|
|
305
|
+
</select>
|
|
306
|
+
)}
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
{/* 右侧工具 */}
|
|
310
|
+
<div className="flex items-center gap-1">
|
|
311
|
+
<button
|
|
312
|
+
onClick={() => {
|
|
313
|
+
if (assetsActive) {
|
|
314
|
+
if (apVisible) apSetVisible(false);
|
|
315
|
+
if (apDrawerOpen) apSetDrawerOpen(false);
|
|
316
|
+
} else {
|
|
317
|
+
apSetDrawerOpen(true);
|
|
318
|
+
}
|
|
319
|
+
}}
|
|
320
|
+
title={assetsActive ? "收起资源面板" : "展开资源面板"}
|
|
321
|
+
className={`text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)] transition-colors p-1 rounded hover:bg-[var(--color-bg-hover)] ${
|
|
322
|
+
assetsActive ? "text-[var(--color-text-accent)]" : ""
|
|
323
|
+
}`}
|
|
324
|
+
>
|
|
325
|
+
<PanelRight className="w-4 h-4" />
|
|
326
|
+
</button>
|
|
327
|
+
{/* 录制按钮 */}
|
|
328
|
+
<button
|
|
329
|
+
onClick={handleToggleRecord}
|
|
330
|
+
disabled={!isOnline}
|
|
331
|
+
title={isRecording ? `停止录制 (${actionCount} 操作)` : "开始录制浏览器操作"}
|
|
332
|
+
className={`flex items-center gap-1 px-2 py-1 text-xs rounded transition-colors disabled:opacity-30 ${
|
|
333
|
+
isRecording
|
|
334
|
+
? "bg-red-500/20 text-red-400 animate-pulse"
|
|
335
|
+
: "text-[var(--color-text-placeholder)] hover:text-red-400 hover:bg-[var(--color-bg-hover)]"
|
|
336
|
+
}`}
|
|
337
|
+
>
|
|
338
|
+
{isRecording ? <Square className="w-3 h-3 fill-current" /> : <Circle className="w-3 h-3 fill-current" />}
|
|
339
|
+
{isRecording ? `${actionCount}` : ""}
|
|
340
|
+
</button>
|
|
341
|
+
<NetworkToggleButton />
|
|
342
|
+
<LanguageSwitcher />
|
|
343
|
+
<ThemeToggle />
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
{/* 安装向导 Modal */}
|
|
347
|
+
{showSetup && <SetupWizard onClose={() => setShowSetup(false)} />}
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
__electrobun?: {
|
|
4
|
+
receiveMessageFromBun: (msg: unknown) => void;
|
|
5
|
+
};
|
|
6
|
+
__electrobunBunBridge?: {
|
|
7
|
+
postMessage: (msg: string) => void;
|
|
8
|
+
};
|
|
9
|
+
/** Desktop IPC receiver: Bun calls this via executeJavascript */
|
|
10
|
+
__piAgentIPC?: (msg: unknown) => void;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
const mockSetBreakpoint = vi.fn();
|
|
5
|
+
const mockSetPinned = vi.fn();
|
|
6
|
+
const mockSetDrawerOpen = vi.fn();
|
|
7
|
+
const mockSetAssetsVisible = vi.fn();
|
|
8
|
+
const mockSetAssetsDrawerOpen = vi.fn();
|
|
9
|
+
|
|
10
|
+
vi.mock("../../stores/use-sidebar-store", () => ({
|
|
11
|
+
useSidebarStore: {
|
|
12
|
+
getState: () => ({
|
|
13
|
+
breakpoint: "desktop",
|
|
14
|
+
isPinned: true,
|
|
15
|
+
_setBreakpoint: mockSetBreakpoint,
|
|
16
|
+
setPinned: mockSetPinned,
|
|
17
|
+
setDrawerOpen: mockSetDrawerOpen,
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
useAssetsPanelStore: {
|
|
21
|
+
getState: () => ({
|
|
22
|
+
assetsVisible: true,
|
|
23
|
+
assetsDrawerOpen: false,
|
|
24
|
+
setAssetsVisible: mockSetAssetsVisible,
|
|
25
|
+
setAssetsDrawerOpen: mockSetAssetsDrawerOpen,
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
describe("useBreakpointSync", () => {
|
|
31
|
+
let observerCallback: ResizeObserverCallback;
|
|
32
|
+
let mockObserve: ReturnType<typeof vi.fn>;
|
|
33
|
+
let mockDisconnect: ReturnType<typeof vi.fn>;
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
vi.resetModules();
|
|
37
|
+
vi.clearAllMocks();
|
|
38
|
+
|
|
39
|
+
mockObserve = vi.fn();
|
|
40
|
+
mockDisconnect = vi.fn();
|
|
41
|
+
|
|
42
|
+
class MockResizeObserver {
|
|
43
|
+
constructor(cb: ResizeObserverCallback) {
|
|
44
|
+
observerCallback = cb;
|
|
45
|
+
}
|
|
46
|
+
observe = mockObserve;
|
|
47
|
+
disconnect = mockDisconnect;
|
|
48
|
+
unobserve = vi.fn();
|
|
49
|
+
}
|
|
50
|
+
globalThis.ResizeObserver = MockResizeObserver as any;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should create ResizeObserver and observe documentElement", async () => {
|
|
54
|
+
const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
|
|
55
|
+
renderHook(() => useBreakpointSync());
|
|
56
|
+
expect(mockObserve).toHaveBeenCalledWith(document.documentElement);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should set mobile breakpoint for width < 768", async () => {
|
|
60
|
+
const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
|
|
61
|
+
renderHook(() => useBreakpointSync());
|
|
62
|
+
|
|
63
|
+
act(() => {
|
|
64
|
+
observerCallback(
|
|
65
|
+
[
|
|
66
|
+
{
|
|
67
|
+
target: document.documentElement,
|
|
68
|
+
contentRect: { width: 500, height: 800 } as DOMRectReadOnly,
|
|
69
|
+
borderBoxSize: [] as any,
|
|
70
|
+
contentBoxSize: [] as any,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
{} as ResizeObserver,
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
78
|
+
expect(mockSetBreakpoint).toHaveBeenCalledWith("mobile");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should set tablet breakpoint for 768 <= width < 1024", async () => {
|
|
82
|
+
const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
|
|
83
|
+
renderHook(() => useBreakpointSync());
|
|
84
|
+
|
|
85
|
+
act(() => {
|
|
86
|
+
observerCallback(
|
|
87
|
+
[
|
|
88
|
+
{
|
|
89
|
+
target: document.documentElement,
|
|
90
|
+
contentRect: { width: 900, height: 600 } as DOMRectReadOnly,
|
|
91
|
+
borderBoxSize: [] as any,
|
|
92
|
+
contentBoxSize: [] as any,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
{} as ResizeObserver,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
100
|
+
expect(mockSetBreakpoint).toHaveBeenCalledWith("tablet");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should set wide breakpoint for width >= 1280", async () => {
|
|
104
|
+
vi.doMock("../../stores/use-sidebar-store", () => ({
|
|
105
|
+
useSidebarStore: {
|
|
106
|
+
getState: () => ({
|
|
107
|
+
breakpoint: "desktop",
|
|
108
|
+
isPinned: true,
|
|
109
|
+
_setBreakpoint: mockSetBreakpoint,
|
|
110
|
+
setPinned: mockSetPinned,
|
|
111
|
+
setDrawerOpen: mockSetDrawerOpen,
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
useAssetsPanelStore: {
|
|
115
|
+
getState: () => ({
|
|
116
|
+
assetsVisible: false,
|
|
117
|
+
assetsDrawerOpen: false,
|
|
118
|
+
setAssetsVisible: mockSetAssetsVisible,
|
|
119
|
+
setAssetsDrawerOpen: mockSetAssetsDrawerOpen,
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
122
|
+
}));
|
|
123
|
+
|
|
124
|
+
const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
|
|
125
|
+
renderHook(() => useBreakpointSync());
|
|
126
|
+
|
|
127
|
+
act(() => {
|
|
128
|
+
observerCallback(
|
|
129
|
+
[
|
|
130
|
+
{
|
|
131
|
+
target: document.documentElement,
|
|
132
|
+
contentRect: { width: 1400, height: 900 } as DOMRectReadOnly,
|
|
133
|
+
borderBoxSize: [] as any,
|
|
134
|
+
contentBoxSize: [] as any,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
{} as ResizeObserver,
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
142
|
+
expect(mockSetBreakpoint).toHaveBeenCalledWith("wide");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("should disconnect observer on unmount", async () => {
|
|
146
|
+
const { useBreakpointSync } = await import("../../hooks/use-breakpoint");
|
|
147
|
+
const { unmount } = renderHook(() => useBreakpointSync());
|
|
148
|
+
unmount();
|
|
149
|
+
expect(mockDisconnect).toHaveBeenCalled();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAgentChat — Agent 流式对话 hook
|
|
3
|
+
*
|
|
4
|
+
* 封装 ChatPanel 和 SkillSidebar 共用的流式订阅逻辑:
|
|
5
|
+
* 1. 订阅 browser.agentStart → 获取后端分配的 messageId
|
|
6
|
+
* 2. 用正确的 messageId 订阅其余 5 个事件
|
|
7
|
+
* 3. 触发 browser.agentChat
|
|
8
|
+
* 4. 完成后自动清理订阅
|
|
9
|
+
*
|
|
10
|
+
* 关键修复:前端不自己生成 messageId,而是等后端 browser.agentStart
|
|
11
|
+
* 返回实际的 messageId 后,再用它过滤后续事件。之前前后端 messageId
|
|
12
|
+
* 格式不同导致 `evt.messageId === messageId` 永远 false。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useCallback } from "react";
|
|
16
|
+
import { apiClient } from "../lib/api-client";
|
|
17
|
+
import { useChatStore } from "../stores/use-chat-store";
|
|
18
|
+
import { useSessionStore } from "../stores/use-session-store";
|
|
19
|
+
|
|
20
|
+
export function useAgentChat() {
|
|
21
|
+
const addUserMessage = useChatStore((s) => s.addUserMessage);
|
|
22
|
+
const addAgentPlaceholder = useChatStore((s) => s.addAgentPlaceholder);
|
|
23
|
+
const pushToolCall = useChatStore((s) => s.pushToolCall);
|
|
24
|
+
const updateToolCall = useChatStore((s) => s.updateToolCall);
|
|
25
|
+
const appendThinking = useChatStore((s) => s.appendThinking);
|
|
26
|
+
const appendText = useChatStore((s) => s.appendText);
|
|
27
|
+
const markTurnDone = useChatStore((s) => s.markTurnDone);
|
|
28
|
+
const patchLastAgent = useChatStore((s) => s.patchLastAgent);
|
|
29
|
+
const setRunning = useSessionStore((s) => s.setRunning);
|
|
30
|
+
const loadSession = useSessionStore((s) => s.loadSession);
|
|
31
|
+
const refreshSessions = useSessionStore((s) => s.refreshSessions);
|
|
32
|
+
|
|
33
|
+
const chat = useCallback(
|
|
34
|
+
async (message: string, sessionId: string, activePlugins?: string[]): Promise<void> => {
|
|
35
|
+
// 1. 添加用户消息(不创建 Agent 占位——等后端 browser.agentStart 确认 messageId)
|
|
36
|
+
addUserMessage(message);
|
|
37
|
+
setRunning(true);
|
|
38
|
+
|
|
39
|
+
const subs: string[] = [];
|
|
40
|
+
let backendMessageId: string | null = null;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// 2. 先订阅 browser.agentStart(获取后端 messageId)
|
|
44
|
+
subs.push(
|
|
45
|
+
await apiClient.subscribe("browser.agentStart", (evt: any) => {
|
|
46
|
+
console.debug("[Chat] browser.agentStart", evt);
|
|
47
|
+
if (!backendMessageId && evt.messageId) {
|
|
48
|
+
backendMessageId = evt.messageId;
|
|
49
|
+
addAgentPlaceholder(evt.messageId);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// 3. 等 agentStart 注册完成
|
|
55
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
56
|
+
|
|
57
|
+
// 4. 订阅其余 5 个事件(用 backendMessageId 过滤)
|
|
58
|
+
subs.push(
|
|
59
|
+
await apiClient.subscribe("browser.toolCall", (evt: any) => {
|
|
60
|
+
console.debug("[Chat] browser.toolCall", evt);
|
|
61
|
+
if (backendMessageId && evt.messageId === backendMessageId) {
|
|
62
|
+
pushToolCall(evt.toolCall);
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
subs.push(
|
|
67
|
+
await apiClient.subscribe("browser.toolResult", (evt: any) => {
|
|
68
|
+
console.debug("[Chat] browser.toolResult", evt);
|
|
69
|
+
if (backendMessageId && evt.messageId === backendMessageId) {
|
|
70
|
+
updateToolCall(evt.toolCallId, evt.output);
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
subs.push(
|
|
75
|
+
await apiClient.subscribe("browser.thinking", (evt: any) => {
|
|
76
|
+
console.debug("[Chat] browser.thinking", evt);
|
|
77
|
+
if (backendMessageId && evt.messageId === backendMessageId) {
|
|
78
|
+
appendThinking(evt.delta);
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
subs.push(
|
|
83
|
+
await apiClient.subscribe("browser.textDelta", (evt: any) => {
|
|
84
|
+
console.debug("[Chat] browser.textDelta", evt);
|
|
85
|
+
if (backendMessageId && evt.messageId === backendMessageId) {
|
|
86
|
+
appendText(evt.delta);
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
subs.push(
|
|
91
|
+
await apiClient.subscribe("browser.turn", (evt: any) => {
|
|
92
|
+
console.debug("[Chat] browser.turn", evt);
|
|
93
|
+
if (backendMessageId && evt.messageId === backendMessageId) {
|
|
94
|
+
markTurnDone(evt.turn);
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
subs.push(
|
|
99
|
+
await apiClient.subscribe("browser.done", async (evt: any) => {
|
|
100
|
+
console.debug("[Chat] browser.done", evt);
|
|
101
|
+
if (backendMessageId && evt.messageId === backendMessageId) {
|
|
102
|
+
patchLastAgent({ text: evt.reply, steps: evt.steps });
|
|
103
|
+
setRunning(false);
|
|
104
|
+
if (refreshSessions) await refreshSessions();
|
|
105
|
+
if (sessionId) await loadSession(sessionId);
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// 5. 等所有 subscribe 注册完成
|
|
111
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
112
|
+
|
|
113
|
+
// 6. 触发 Agent
|
|
114
|
+
console.log("[useAgentChat] Calling browser.agentChat...");
|
|
115
|
+
const agentResult = await apiClient.call("browser.agentChat", {
|
|
116
|
+
message,
|
|
117
|
+
sessionId,
|
|
118
|
+
activePlugins,
|
|
119
|
+
});
|
|
120
|
+
console.log("[useAgentChat] agentChat returned:", JSON.stringify(agentResult).slice(0, 200));
|
|
121
|
+
|
|
122
|
+
// 7. Fallback:如果 browser.agentStart 事件没到(没创建占位),用 RPC 响应直接创建
|
|
123
|
+
if (!backendMessageId && agentResult?.messageId) {
|
|
124
|
+
backendMessageId = agentResult.messageId;
|
|
125
|
+
addAgentPlaceholder(agentResult.messageId);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 8. Fallback:用 RPC 响应填充 Agent 文本(即使流式事件没到)
|
|
129
|
+
if (agentResult?.text) {
|
|
130
|
+
patchLastAgent({ text: agentResult.text, steps: agentResult.steps || [] });
|
|
131
|
+
setRunning(false);
|
|
132
|
+
}
|
|
133
|
+
} catch (err: any) {
|
|
134
|
+
console.error("[useAgentChat] Error:", err);
|
|
135
|
+
patchLastAgent({ error: err.message || "Agent 执行失败" });
|
|
136
|
+
setRunning(false);
|
|
137
|
+
} finally {
|
|
138
|
+
subs.forEach((id) => apiClient.unsubscribe(id));
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
[
|
|
142
|
+
addUserMessage,
|
|
143
|
+
addAgentPlaceholder,
|
|
144
|
+
pushToolCall,
|
|
145
|
+
updateToolCall,
|
|
146
|
+
appendThinking,
|
|
147
|
+
appendText,
|
|
148
|
+
markTurnDone,
|
|
149
|
+
patchLastAgent,
|
|
150
|
+
setRunning,
|
|
151
|
+
loadSession,
|
|
152
|
+
refreshSessions,
|
|
153
|
+
],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
return { chat };
|
|
157
|
+
}
|