@dyyz1993/create-agent 1.9.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/package.json +25 -0
- package/src/__tests__/cli.test.ts +85 -0
- package/src/__tests__/copy.test.ts +168 -0
- package/src/__tests__/templates.test.ts +87 -0
- package/src/cli.ts +65 -0
- package/src/commands/create.ts +49 -0
- package/src/commands/list.ts +12 -0
- package/src/commands/status.ts +85 -0
- package/src/commands/workspace.ts +129 -0
- package/src/lib/copy.ts +285 -0
- package/src/lib/templates.ts +57 -0
- package/src/lib/types.ts +6 -0
- package/templates/agent/.env.example +7 -0
- package/templates/agent/LICENSE +21 -0
- package/templates/agent/README.md +87 -0
- package/templates/agent/bun.lock +1279 -0
- package/templates/agent/electrobun.config.ts +27 -0
- package/templates/agent/eslint.config.mjs +63 -0
- package/templates/agent/llms.txt +24 -0
- package/templates/agent/package-lock.json +3670 -0
- package/templates/agent/package.json +59 -0
- package/templates/agent/postcss.config.js +6 -0
- package/templates/agent/scripts/dev.ts +138 -0
- package/templates/agent/src/__tests__/server-config.test.ts +59 -0
- package/templates/agent/src/bun/index.ts +73 -0
- package/templates/agent/src/gateway/__tests__/ws-handler.test.ts +48 -0
- package/templates/agent/src/gateway/http-routes.ts +1 -0
- package/templates/agent/src/gateway/ipc-transport.ts +68 -0
- package/templates/agent/src/gateway/ws-handler.ts +86 -0
- package/templates/agent/src/mainview/App.tsx +41 -0
- package/templates/agent/src/mainview/__tests__/components/ChatPanel.test.tsx +114 -0
- package/templates/agent/src/mainview/__tests__/components/ExplorerSidebar.test.tsx +141 -0
- package/templates/agent/src/mainview/__tests__/components/MessageBubble.test.tsx +72 -0
- package/templates/agent/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +217 -0
- package/templates/agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/agent/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
- package/templates/agent/src/mainview/__tests__/setup.ts +37 -0
- package/templates/agent/src/mainview/__tests__/stores/use-chat-store.test.ts +83 -0
- package/templates/agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +85 -0
- package/templates/agent/src/mainview/components/activity-bar/ActivityBar.tsx +36 -0
- package/templates/agent/src/mainview/components/activity-bar/MobileTabBar.tsx +36 -0
- package/templates/agent/src/mainview/components/activity-bar/__tests__/ActivityBar.test.tsx +44 -0
- package/templates/agent/src/mainview/components/activity-bar/__tests__/MobileTabBar.test.tsx +44 -0
- package/templates/agent/src/mainview/components/bash/BashPanel.tsx +206 -0
- package/templates/agent/src/mainview/components/bash/__tests__/BashPanel.test.tsx +103 -0
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +102 -0
- package/templates/agent/src/mainview/components/chat/MessageBubble.tsx +86 -0
- package/templates/agent/src/mainview/components/common/ErrorBoundary.tsx +58 -0
- package/templates/agent/src/mainview/components/common/LanguageSwitcher.tsx +14 -0
- package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +24 -0
- package/templates/agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +120 -0
- package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +102 -0
- package/templates/agent/src/mainview/components/diff/DiffViewerPanel.tsx +106 -0
- package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +73 -0
- package/templates/agent/src/mainview/components/explorer/ConfirmDialog.tsx +53 -0
- package/templates/agent/src/mainview/components/explorer/ContextMenu.tsx +82 -0
- package/templates/agent/src/mainview/components/explorer/ExplorerSidebar.tsx +221 -0
- package/templates/agent/src/mainview/components/explorer/InlineInput.tsx +55 -0
- package/templates/agent/src/mainview/components/explorer/TreeNodeItem.tsx +121 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/ConfirmDialog.test.tsx +37 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/ContextMenu.test.tsx +49 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/InlineInput.test.tsx +48 -0
- package/templates/agent/src/mainview/components/explorer/__tests__/TreeNodeItem.test.tsx +146 -0
- package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +239 -0
- package/templates/agent/src/mainview/components/feed/__tests__/FeedPanel.test.tsx +108 -0
- package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +56 -0
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +99 -0
- package/templates/agent/src/mainview/components/file-preview/__tests__/FilePreviewOverlay.test.tsx +96 -0
- package/templates/agent/src/mainview/components/file-preview/__tests__/VirtualizedCodeView.test.tsx +58 -0
- package/templates/agent/src/mainview/components/git/GitBranchSelector.tsx +98 -0
- package/templates/agent/src/mainview/components/git/GitCommitInput.tsx +60 -0
- package/templates/agent/src/mainview/components/git/GitPanel.tsx +528 -0
- package/templates/agent/src/mainview/components/git/__tests__/GitBranchSelector.test.tsx +76 -0
- package/templates/agent/src/mainview/components/git/__tests__/GitCommitInput.test.tsx +91 -0
- package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +174 -0
- package/templates/agent/src/mainview/components/layout/AppLayout.tsx +170 -0
- package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +163 -0
- package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +117 -0
- package/templates/agent/src/mainview/components/rules/__tests__/RulesPanel.test.tsx +91 -0
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +404 -0
- package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +50 -0
- package/templates/agent/src/mainview/components/sidebar/PinButton.tsx +20 -0
- package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +48 -0
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +141 -0
- package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +91 -0
- package/templates/agent/src/mainview/global.d.ts +13 -0
- package/templates/agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +147 -0
- package/templates/agent/src/mainview/hooks/use-breakpoint.ts +34 -0
- package/templates/agent/src/mainview/hooks/use-input-history.ts +84 -0
- package/templates/agent/src/mainview/hooks/use-rpc-init.ts +61 -0
- package/templates/agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/agent/src/mainview/index.css +61 -0
- package/templates/agent/src/mainview/index.html +12 -0
- package/templates/agent/src/mainview/lib/api-client.ts +192 -0
- package/templates/agent/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/agent/src/mainview/lib/i18n/locales/en.json +157 -0
- package/templates/agent/src/mainview/lib/i18n/locales/zh.json +157 -0
- package/templates/agent/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/agent/src/mainview/main.tsx +24 -0
- package/templates/agent/src/mainview/stores/__tests__/use-app-store.test.ts +86 -0
- package/templates/agent/src/mainview/stores/__tests__/use-bash-store.test.ts +99 -0
- package/templates/agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/agent/src/mainview/stores/__tests__/use-explorer-store.test.ts +130 -0
- package/templates/agent/src/mainview/stores/__tests__/use-feed-store.test.ts +132 -0
- package/templates/agent/src/mainview/stores/__tests__/use-git-store.test.ts +161 -0
- package/templates/agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/agent/src/mainview/stores/__tests__/use-notification-store.test.ts +102 -0
- package/templates/agent/src/mainview/stores/__tests__/use-rules-store.test.ts +75 -0
- package/templates/agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/agent/src/mainview/stores/__tests__/use-todo-store.test.ts +75 -0
- package/templates/agent/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/agent/src/mainview/stores/use-app-store.ts +99 -0
- package/templates/agent/src/mainview/stores/use-bash-store.ts +93 -0
- package/templates/agent/src/mainview/stores/use-chat-store.ts +37 -0
- package/templates/agent/src/mainview/stores/use-connection-store.ts +42 -0
- package/templates/agent/src/mainview/stores/use-explorer-store.ts +320 -0
- package/templates/agent/src/mainview/stores/use-feed-store.ts +129 -0
- package/templates/agent/src/mainview/stores/use-git-store.ts +291 -0
- package/templates/agent/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/agent/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/agent/src/mainview/stores/use-notification-store.ts +82 -0
- package/templates/agent/src/mainview/stores/use-rules-store.ts +54 -0
- package/templates/agent/src/mainview/stores/use-sidebar-store.ts +99 -0
- package/templates/agent/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/agent/src/mainview/stores/use-todo-store.ts +54 -0
- package/templates/agent/src/mainview/types/index.ts +33 -0
- package/templates/agent/src/mainview/utils/constants.ts +1 -0
- package/templates/agent/src/mainview/utils/drop-handler.ts +150 -0
- package/templates/agent/src/mainview/utils/file-icon.tsx +24 -0
- package/templates/agent/src/mainview/utils/file-utils.ts +35 -0
- package/templates/agent/src/server-config.ts +43 -0
- package/templates/agent/src/server.ts +89 -0
- package/templates/agent/src/shared/handlers/__tests__/bash-handler.test.ts +135 -0
- package/templates/agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/agent/src/shared/handlers/__tests__/feed-handler.test.ts +108 -0
- package/templates/agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/agent/src/shared/handlers/bash.ts +89 -0
- package/templates/agent/src/shared/handlers/chat.ts +179 -0
- package/templates/agent/src/shared/handlers/feed.ts +53 -0
- package/templates/agent/src/shared/handlers/file.ts +99 -0
- package/templates/agent/src/shared/handlers/git.ts +263 -0
- package/templates/agent/src/shared/handlers/index.ts +10 -0
- package/templates/agent/src/shared/handlers/rules.ts +45 -0
- package/templates/agent/src/shared/handlers/system.ts +27 -0
- package/templates/agent/src/shared/handlers/timer.ts +34 -0
- package/templates/agent/src/shared/handlers/todo.ts +45 -0
- package/templates/agent/src/shared/lib/__tests__/bash-security.test.ts +125 -0
- package/templates/agent/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/agent/src/shared/lib/bash-security.ts +64 -0
- package/templates/agent/src/shared/lib/logger.ts +130 -0
- package/templates/agent/src/shared/lib/path-security.ts +38 -0
- package/templates/agent/src/shared/lib/port-registry.ts +103 -0
- package/templates/agent/src/shared/modules/bash.ts +19 -0
- package/templates/agent/src/shared/modules/chat.ts +20 -0
- package/templates/agent/src/shared/modules/feed.ts +30 -0
- package/templates/agent/src/shared/modules/file.ts +40 -0
- package/templates/agent/src/shared/modules/git.ts +81 -0
- package/templates/agent/src/shared/modules/rules.ts +25 -0
- package/templates/agent/src/shared/modules/system.ts +8 -0
- package/templates/agent/src/shared/modules/timer.ts +11 -0
- package/templates/agent/src/shared/modules/todo.ts +27 -0
- package/templates/agent/src/shared/register-all-handlers.ts +36 -0
- package/templates/agent/src/shared/rpc-schema.ts +35 -0
- package/templates/agent/tailwind.config.js +15 -0
- package/templates/agent/tsconfig.json +26 -0
- package/templates/agent/vite.config.ts +3 -0
- package/templates/agent/vitest.config.ts +3 -0
- package/templates/chat/.env.example +6 -0
- package/templates/chat/LICENSE +21 -0
- package/templates/chat/README.md +56 -0
- package/templates/chat/bun.lock +1203 -0
- package/templates/chat/electrobun.config.ts +27 -0
- package/templates/chat/eslint.config.mjs +56 -0
- package/templates/chat/llms.txt +24 -0
- package/templates/chat/package-lock.json +3670 -0
- package/templates/chat/package.json +58 -0
- package/templates/chat/postcss.config.js +6 -0
- package/templates/chat/scripts/dev.ts +138 -0
- package/templates/chat/src/__tests__/server-config.test.ts +59 -0
- package/templates/chat/src/bun/index.ts +72 -0
- package/templates/chat/src/gateway/__tests__/ws-handler.test.ts +48 -0
- package/templates/chat/src/gateway/http-routes.ts +1 -0
- package/templates/chat/src/gateway/ipc-transport.ts +68 -0
- package/templates/chat/src/gateway/ws-handler.ts +86 -0
- package/templates/chat/src/mainview/App.tsx +108 -0
- package/templates/chat/src/mainview/__tests__/components/ChatPanel.test.tsx +76 -0
- package/templates/chat/src/mainview/__tests__/components/MessageBubble.test.tsx +48 -0
- package/templates/chat/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
- package/templates/chat/src/mainview/__tests__/setup-verify.test.ts +8 -0
- package/templates/chat/src/mainview/__tests__/setup.ts +37 -0
- package/templates/chat/src/mainview/__tests__/stores/use-app-store.test.ts +46 -0
- package/templates/chat/src/mainview/__tests__/stores/use-chat-store.test.ts +104 -0
- package/templates/chat/src/mainview/__tests__/stores/use-connection-store.test.ts +35 -0
- package/templates/chat/src/mainview/__tests__/stores/use-log-store.test.ts +45 -0
- package/templates/chat/src/mainview/__tests__/stores/use-notification-store.test.ts +102 -0
- package/templates/chat/src/mainview/__tests__/stores/use-sidebar-store.test.ts +89 -0
- package/templates/chat/src/mainview/components/activity-bar/ActivityBar.tsx +26 -0
- package/templates/chat/src/mainview/components/activity-bar/MobileTabBar.tsx +20 -0
- package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +66 -0
- package/templates/chat/src/mainview/components/chat/MessageBubble.tsx +85 -0
- package/templates/chat/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +24 -0
- package/templates/chat/src/mainview/components/sidebar/PinButton.tsx +20 -0
- package/templates/chat/src/mainview/global.d.ts +13 -0
- package/templates/chat/src/mainview/hooks/use-breakpoint.ts +34 -0
- package/templates/chat/src/mainview/hooks/use-input-history.ts +84 -0
- package/templates/chat/src/mainview/index.css +61 -0
- package/templates/chat/src/mainview/index.html +12 -0
- package/templates/chat/src/mainview/lib/api-client.ts +175 -0
- package/templates/chat/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/chat/src/mainview/lib/i18n/locales/en.json +157 -0
- package/templates/chat/src/mainview/lib/i18n/locales/zh.json +157 -0
- package/templates/chat/src/mainview/main.tsx +20 -0
- package/templates/chat/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/chat/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/chat/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/chat/src/mainview/stores/use-app-store.ts +50 -0
- package/templates/chat/src/mainview/stores/use-chat-store.ts +37 -0
- package/templates/chat/src/mainview/stores/use-connection-store.ts +42 -0
- package/templates/chat/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/chat/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/chat/src/mainview/stores/use-notification-store.ts +82 -0
- package/templates/chat/src/mainview/stores/use-sidebar-store.ts +98 -0
- package/templates/chat/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/chat/src/mainview/types/index.ts +8 -0
- package/templates/chat/src/mainview/utils/constants.ts +1 -0
- package/templates/chat/src/server-config.ts +42 -0
- package/templates/chat/src/server.ts +89 -0
- package/templates/chat/src/shared/__tests__/chat-handler.test.ts +71 -0
- package/templates/chat/src/shared/__tests__/system-handler.test.ts +70 -0
- package/templates/chat/src/shared/handlers/chat.ts +186 -0
- package/templates/chat/src/shared/handlers/index.ts +2 -0
- package/templates/chat/src/shared/handlers/system.ts +27 -0
- package/templates/chat/src/shared/lib/logger.ts +130 -0
- package/templates/chat/src/shared/lib/path-security.ts +38 -0
- package/templates/chat/src/shared/lib/port-registry.ts +103 -0
- package/templates/chat/src/shared/modules/chat.ts +20 -0
- package/templates/chat/src/shared/modules/system.ts +8 -0
- package/templates/chat/src/shared/register-all-handlers.ts +36 -0
- package/templates/chat/src/shared/rpc-schema.ts +11 -0
- package/templates/chat/tailwind.config.js +15 -0
- package/templates/chat/tsconfig.json +26 -0
- package/templates/chat/vite.config.ts +3 -0
- package/templates/chat/vitest.config.ts +3 -0
- package/templates/general/.env.example +7 -0
- package/templates/general/LICENSE +21 -0
- package/templates/general/README.md +113 -0
- package/templates/general/bun.lock +1266 -0
- package/templates/general/electrobun.config.ts +27 -0
- package/templates/general/eslint.config.mjs +56 -0
- package/templates/general/llms.txt +24 -0
- package/templates/general/package-lock.json +3670 -0
- package/templates/general/package.json +59 -0
- package/templates/general/postcss.config.js +6 -0
- package/templates/general/scripts/dev.ts +138 -0
- package/templates/general/src/__tests__/server-config.test.ts +59 -0
- package/templates/general/src/bun/index.ts +72 -0
- package/templates/general/src/gateway/http-routes.ts +1 -0
- package/templates/general/src/gateway/ipc-transport.ts +68 -0
- package/templates/general/src/gateway/ws-handler.ts +86 -0
- package/templates/general/src/mainview/App.tsx +40 -0
- package/templates/general/src/mainview/__tests__/components/ChatPanel.test.tsx +82 -0
- package/templates/general/src/mainview/__tests__/components/FeedPanel.test.tsx +109 -0
- package/templates/general/src/mainview/__tests__/components/GitPanel.test.tsx +151 -0
- package/templates/general/src/mainview/__tests__/i18n/i18n.test.ts +48 -0
- package/templates/general/src/mainview/__tests__/setup-verify.test.ts +8 -0
- package/templates/general/src/mainview/__tests__/setup.ts +37 -0
- package/templates/general/src/mainview/components/activity-bar/ActivityBar.tsx +40 -0
- package/templates/general/src/mainview/components/activity-bar/MobileTabBar.tsx +29 -0
- package/templates/general/src/mainview/components/chat/ChatPanel.tsx +66 -0
- package/templates/general/src/mainview/components/chat/MessageBubble.tsx +85 -0
- package/templates/general/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/general/src/mainview/components/common/ThemeToggle.tsx +24 -0
- package/templates/general/src/mainview/components/debug/DebugPanel.tsx +176 -0
- package/templates/general/src/mainview/components/diff/DiffViewerPanel.tsx +108 -0
- package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +52 -0
- package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +82 -0
- package/templates/general/src/mainview/components/explorer/ExplorerSidebar.tsx +225 -0
- package/templates/general/src/mainview/components/explorer/InlineInput.tsx +55 -0
- package/templates/general/src/mainview/components/explorer/TreeNodeItem.tsx +121 -0
- package/templates/general/src/mainview/components/feed/FeedPanel.tsx +248 -0
- package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +55 -0
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +99 -0
- package/templates/general/src/mainview/components/git/GitBranchSelector.tsx +93 -0
- package/templates/general/src/mainview/components/git/GitCommitInput.tsx +60 -0
- package/templates/general/src/mainview/components/git/GitPanel.tsx +533 -0
- package/templates/general/src/mainview/components/layout/AppLayout.tsx +146 -0
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +405 -0
- package/templates/general/src/mainview/components/sidebar/PinButton.tsx +20 -0
- package/templates/general/src/mainview/global.d.ts +13 -0
- package/templates/general/src/mainview/hooks/use-breakpoint.ts +34 -0
- package/templates/general/src/mainview/hooks/use-input-history.ts +84 -0
- package/templates/general/src/mainview/hooks/use-rpc-init.ts +61 -0
- package/templates/general/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/general/src/mainview/index.css +61 -0
- package/templates/general/src/mainview/index.html +12 -0
- package/templates/general/src/mainview/lib/api-client.ts +175 -0
- package/templates/general/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/general/src/mainview/lib/i18n/locales/en.json +157 -0
- package/templates/general/src/mainview/lib/i18n/locales/zh.json +157 -0
- package/templates/general/src/mainview/main.tsx +20 -0
- package/templates/general/src/mainview/stores/__tests__/use-chat-store.test.ts +104 -0
- package/templates/general/src/mainview/stores/__tests__/use-connection-store.test.ts +35 -0
- package/templates/general/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/general/src/mainview/stores/__tests__/use-log-store.test.ts +45 -0
- package/templates/general/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/general/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/general/src/mainview/stores/use-app-store.ts +104 -0
- package/templates/general/src/mainview/stores/use-chat-store.ts +37 -0
- package/templates/general/src/mainview/stores/use-connection-store.ts +42 -0
- package/templates/general/src/mainview/stores/use-explorer-store.ts +315 -0
- package/templates/general/src/mainview/stores/use-feed-store.ts +129 -0
- package/templates/general/src/mainview/stores/use-git-store.ts +284 -0
- package/templates/general/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/general/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/general/src/mainview/stores/use-notification-store.ts +82 -0
- package/templates/general/src/mainview/stores/use-sidebar-store.ts +99 -0
- package/templates/general/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/general/src/mainview/types/index.ts +33 -0
- package/templates/general/src/mainview/utils/constants.ts +1 -0
- package/templates/general/src/mainview/utils/drop-handler.ts +150 -0
- package/templates/general/src/mainview/utils/file-icon.tsx +24 -0
- package/templates/general/src/mainview/utils/file-utils.ts +35 -0
- package/templates/general/src/server-config.ts +42 -0
- package/templates/general/src/server.ts +89 -0
- package/templates/general/src/shared/handlers/__tests__/chat.test.ts +183 -0
- package/templates/general/src/shared/handlers/__tests__/system.test.ts +94 -0
- package/templates/general/src/shared/handlers/__tests__/timer.test.ts +113 -0
- package/templates/general/src/shared/handlers/chat.ts +179 -0
- package/templates/general/src/shared/handlers/feed.ts +53 -0
- package/templates/general/src/shared/handlers/file.ts +99 -0
- package/templates/general/src/shared/handlers/git.ts +263 -0
- package/templates/general/src/shared/handlers/index.ts +7 -0
- package/templates/general/src/shared/handlers/system.ts +27 -0
- package/templates/general/src/shared/handlers/timer.ts +34 -0
- package/templates/general/src/shared/lib/logger.ts +130 -0
- package/templates/general/src/shared/lib/path-security.ts +38 -0
- package/templates/general/src/shared/lib/port-registry.ts +103 -0
- package/templates/general/src/shared/modules/chat.ts +20 -0
- package/templates/general/src/shared/modules/feed.ts +30 -0
- package/templates/general/src/shared/modules/file.ts +40 -0
- package/templates/general/src/shared/modules/git.ts +81 -0
- package/templates/general/src/shared/modules/system.ts +8 -0
- package/templates/general/src/shared/modules/timer.ts +11 -0
- package/templates/general/src/shared/register-all-handlers.ts +36 -0
- package/templates/general/src/shared/rpc-schema.ts +31 -0
- package/templates/general/tailwind.config.js +15 -0
- package/templates/general/tsconfig.json +26 -0
- package/templates/general/vite.config.ts +3 -0
- package/templates/general/vitest.config.ts +3 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": {
|
|
3
|
+
"title": "Pi Agent",
|
|
4
|
+
"connecting": "正在连接 RPC 服务器...",
|
|
5
|
+
"mode": {
|
|
6
|
+
"desktop": "桌面 (IPC)",
|
|
7
|
+
"web": "Web (WebSocket)"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"sidebar": {
|
|
11
|
+
"explorer": "资源管理器",
|
|
12
|
+
"git": "源代码管理",
|
|
13
|
+
"search": "搜索",
|
|
14
|
+
"rules": "规则"
|
|
15
|
+
},
|
|
16
|
+
"tabs": {
|
|
17
|
+
"chat": "聊天",
|
|
18
|
+
"feed": "动态 + 订阅",
|
|
19
|
+
"bash": "终端",
|
|
20
|
+
"todo": "待办",
|
|
21
|
+
"debug": "调试"
|
|
22
|
+
},
|
|
23
|
+
"chat": {
|
|
24
|
+
"title": "消息",
|
|
25
|
+
"placeholder": "输入消息...",
|
|
26
|
+
"send": "发送",
|
|
27
|
+
"empty": "开始对话..."
|
|
28
|
+
},
|
|
29
|
+
"explorer": {
|
|
30
|
+
"title": "资源管理器",
|
|
31
|
+
"pathPlaceholder": "路径",
|
|
32
|
+
"refresh": "刷新",
|
|
33
|
+
"listDirectory": "列出目录",
|
|
34
|
+
"newFile": "新建文件",
|
|
35
|
+
"newFolder": "新建文件夹",
|
|
36
|
+
"rename": "重命名",
|
|
37
|
+
"delete": "删除",
|
|
38
|
+
"copyPath": "复制路径",
|
|
39
|
+
"confirmDelete": "确认删除",
|
|
40
|
+
"confirmDeleteMessage": "确定要删除 \"{{name}}\" 吗?此操作无法撤销。",
|
|
41
|
+
"emptyHint": "输入路径并点击刷新"
|
|
42
|
+
},
|
|
43
|
+
"git": {
|
|
44
|
+
"title": "源代码管理",
|
|
45
|
+
"staged": "已暂存更改",
|
|
46
|
+
"changes": "更改",
|
|
47
|
+
"untracked": "未跟踪",
|
|
48
|
+
"noChanges": "未检测到更改",
|
|
49
|
+
"commits": "提交记录",
|
|
50
|
+
"noCommits": "暂无提交",
|
|
51
|
+
"noFiles": "暂无文件",
|
|
52
|
+
"loadingFiles": "加载文件中...",
|
|
53
|
+
"commitPlaceholder": "提交信息 (Ctrl+Enter 提交)",
|
|
54
|
+
"committing": "提交中...",
|
|
55
|
+
"commit": "提交",
|
|
56
|
+
"openDiff": "打开差异",
|
|
57
|
+
"openFile": "打开文件",
|
|
58
|
+
"copyHash": "复制哈希",
|
|
59
|
+
"copyMessage": "复制信息",
|
|
60
|
+
"copyPath": "复制路径",
|
|
61
|
+
"pull": "拉取",
|
|
62
|
+
"push": "推送",
|
|
63
|
+
"refresh": "刷新",
|
|
64
|
+
"stage": "暂存",
|
|
65
|
+
"unstage": "取消暂存",
|
|
66
|
+
"stageAll": "全部暂存",
|
|
67
|
+
"unstageAll": "全部取消暂存",
|
|
68
|
+
"worktrees": "工作树",
|
|
69
|
+
"close": "关闭",
|
|
70
|
+
"justNow": "刚刚",
|
|
71
|
+
"minutesAgo": "{{count}}分钟前",
|
|
72
|
+
"hoursAgo": "{{count}}小时前",
|
|
73
|
+
"daysAgo": "{{count}}天前"
|
|
74
|
+
},
|
|
75
|
+
"feed": {
|
|
76
|
+
"title": "动态 + 订阅",
|
|
77
|
+
"newPost": "新动态",
|
|
78
|
+
"authorPlaceholder": "作者",
|
|
79
|
+
"post": "发布",
|
|
80
|
+
"postPlaceholder": "写点什么...",
|
|
81
|
+
"subscribeWithFilter": "带过滤器订阅",
|
|
82
|
+
"filterPlaceholder": "过滤器 JSON,如 {\"category\":\"tech\"}",
|
|
83
|
+
"subscribe": "订阅",
|
|
84
|
+
"unsubscribe": "取消订阅",
|
|
85
|
+
"noFilter": "无过滤",
|
|
86
|
+
"eventStream": "事件流",
|
|
87
|
+
"live": "直播",
|
|
88
|
+
"noPostsYet": "暂无动态,在上方创建一条!"
|
|
89
|
+
},
|
|
90
|
+
"todo": {
|
|
91
|
+
"title": "待办",
|
|
92
|
+
"add": "添加待办",
|
|
93
|
+
"placeholder": "需要做什么?",
|
|
94
|
+
"save": "添加",
|
|
95
|
+
"empty": "暂无任务",
|
|
96
|
+
"emptyHint": "点击\"添加待办\"来创建",
|
|
97
|
+
"status": "状态:",
|
|
98
|
+
"statusPending": "待处理",
|
|
99
|
+
"statusInProgress": "进行中",
|
|
100
|
+
"statusCompleted": "已完成"
|
|
101
|
+
},
|
|
102
|
+
"rules": {
|
|
103
|
+
"title": "规则",
|
|
104
|
+
"add": "添加规则",
|
|
105
|
+
"namePlaceholder": "规则名称",
|
|
106
|
+
"patternPlaceholder": "Glob 匹配模式 (如 **/*.ts)",
|
|
107
|
+
"save": "保存",
|
|
108
|
+
"empty": "暂无规则",
|
|
109
|
+
"emptyHint": "点击\"添加规则\"来创建",
|
|
110
|
+
"pattern": "模式:"
|
|
111
|
+
},
|
|
112
|
+
"bash": {
|
|
113
|
+
"title": "终端",
|
|
114
|
+
"enterCommand": "输入命令...",
|
|
115
|
+
"run": "运行",
|
|
116
|
+
"processRunning": "进程运行中... (PID: {{pid}})",
|
|
117
|
+
"waitingOutput": "等待输出...",
|
|
118
|
+
"exit": "退出码: {{code}}",
|
|
119
|
+
"noActiveProcess": "无活动进程",
|
|
120
|
+
"getStarted": "运行命令开始",
|
|
121
|
+
"kill": "终止",
|
|
122
|
+
"exited": "已退出({{code}})"
|
|
123
|
+
},
|
|
124
|
+
"diff": {
|
|
125
|
+
"lineByLine": "逐行对比",
|
|
126
|
+
"sideBySide": "并排对比",
|
|
127
|
+
"loading": "加载差异...",
|
|
128
|
+
"before": "修改前",
|
|
129
|
+
"after": "修改后"
|
|
130
|
+
},
|
|
131
|
+
"debug": {
|
|
132
|
+
"rpcCalls": "RPC 调用",
|
|
133
|
+
"call": "调用",
|
|
134
|
+
"subscriptions": "订阅",
|
|
135
|
+
"subscribe": "订阅",
|
|
136
|
+
"unsubscribe": "取消订阅",
|
|
137
|
+
"events": "{{count}} 个事件",
|
|
138
|
+
"noEvents": "暂无事件",
|
|
139
|
+
"logs": "日志"
|
|
140
|
+
},
|
|
141
|
+
"theme": {
|
|
142
|
+
"light": "浅色",
|
|
143
|
+
"dark": "深色",
|
|
144
|
+
"toggle": "切换主题"
|
|
145
|
+
},
|
|
146
|
+
"locale": {
|
|
147
|
+
"en": "English",
|
|
148
|
+
"zh": "中文"
|
|
149
|
+
},
|
|
150
|
+
"common": {
|
|
151
|
+
"loading": "加载中...",
|
|
152
|
+
"cancel": "取消",
|
|
153
|
+
"confirm": "确认",
|
|
154
|
+
"save": "保存",
|
|
155
|
+
"delete": "删除"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./lib/i18n";
|
|
2
|
+
import { StrictMode } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { apiClient } from "./lib/api-client";
|
|
5
|
+
import "./index.css";
|
|
6
|
+
import App from "./App";
|
|
7
|
+
|
|
8
|
+
const isElectrobun = typeof window !== "undefined" && !!window.__electrobunBunBridge;
|
|
9
|
+
|
|
10
|
+
if (isElectrobun) {
|
|
11
|
+
// 桌面端:同步初始化 IPC(Electrobun 要求桥接在页面加载时同步设置)
|
|
12
|
+
apiClient.initSyncForDesktop();
|
|
13
|
+
}
|
|
14
|
+
// Web 端 WS 初始化由 App.tsx 统一管理,避免竞争
|
|
15
|
+
|
|
16
|
+
createRoot(document.getElementById("root")!).render(
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<App />
|
|
19
|
+
</StrictMode>
|
|
20
|
+
);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { useChatStore } from "../use-chat-store";
|
|
3
|
+
import { act } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
vi.mock("../../lib/api-client", () => ({
|
|
6
|
+
apiClient: {
|
|
7
|
+
call: vi.fn().mockResolvedValue({ ok: true }),
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
vi.mock("../use-log-store", () => ({
|
|
12
|
+
useLogStore: {
|
|
13
|
+
getState: () => ({ addLog: vi.fn() }),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe("useChatStore", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
act(() => {
|
|
20
|
+
useChatStore.setState({
|
|
21
|
+
messages: [],
|
|
22
|
+
inputText: "",
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("initial state", () => {
|
|
28
|
+
const state = useChatStore.getState();
|
|
29
|
+
expect(state.messages).toEqual([]);
|
|
30
|
+
expect(state.inputText).toBe("");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("setInputText", () => {
|
|
34
|
+
act(() => {
|
|
35
|
+
useChatStore.getState().setInputText("hello");
|
|
36
|
+
});
|
|
37
|
+
expect(useChatStore.getState().inputText).toBe("hello");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("addMessage", () => {
|
|
41
|
+
const msg = {
|
|
42
|
+
id: "1",
|
|
43
|
+
role: "user" as const,
|
|
44
|
+
content: "hi",
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
};
|
|
47
|
+
act(() => {
|
|
48
|
+
useChatStore.getState().addMessage(msg);
|
|
49
|
+
});
|
|
50
|
+
expect(useChatStore.getState().messages).toHaveLength(1);
|
|
51
|
+
expect(useChatStore.getState().messages[0].content).toBe("hi");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("setMessages", () => {
|
|
55
|
+
const msgs = [
|
|
56
|
+
{ id: "1", role: "user" as const, content: "a", timestamp: 1000 },
|
|
57
|
+
{ id: "2", role: "assistant" as const, content: "b", timestamp: 2000 },
|
|
58
|
+
];
|
|
59
|
+
act(() => {
|
|
60
|
+
useChatStore.getState().setMessages(msgs);
|
|
61
|
+
});
|
|
62
|
+
expect(useChatStore.getState().messages).toHaveLength(2);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("addMessage appends to existing", () => {
|
|
66
|
+
act(() => {
|
|
67
|
+
useChatStore.getState().setMessages([
|
|
68
|
+
{ id: "1", role: "user", content: "a", timestamp: 1000 },
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
act(() => {
|
|
72
|
+
useChatStore.getState().addMessage({
|
|
73
|
+
id: "2",
|
|
74
|
+
role: "assistant",
|
|
75
|
+
content: "b",
|
|
76
|
+
timestamp: 2000,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
const msgs = useChatStore.getState().messages;
|
|
80
|
+
expect(msgs).toHaveLength(2);
|
|
81
|
+
expect(msgs[1].content).toBe("b");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("sendMessage clears inputText after sending", async () => {
|
|
85
|
+
act(() => {
|
|
86
|
+
useChatStore.getState().setInputText("hello world");
|
|
87
|
+
});
|
|
88
|
+
await act(async () => {
|
|
89
|
+
await useChatStore.getState().sendMessage();
|
|
90
|
+
});
|
|
91
|
+
expect(useChatStore.getState().inputText).toBe("");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("sendMessage does nothing with empty input", async () => {
|
|
95
|
+
act(() => {
|
|
96
|
+
useChatStore.getState().setInputText(" ");
|
|
97
|
+
});
|
|
98
|
+
const { apiClient } = await import("../../lib/api-client");
|
|
99
|
+
const callSpy = vi.mocked(apiClient.call);
|
|
100
|
+
callSpy.mockClear();
|
|
101
|
+
await useChatStore.getState().sendMessage();
|
|
102
|
+
expect(callSpy).not.toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useConnectionStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should have initial state", async () => {
|
|
9
|
+
const { useConnectionStore } = await import("../use-connection-store");
|
|
10
|
+
const state = useConnectionStore.getState();
|
|
11
|
+
expect(state.mode).toBe("web");
|
|
12
|
+
expect(state.ready).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should set ready state", async () => {
|
|
16
|
+
const { useConnectionStore } = await import("../use-connection-store");
|
|
17
|
+
useConnectionStore.getState().setReady(true);
|
|
18
|
+
expect(useConnectionStore.getState().ready).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should set mode", async () => {
|
|
22
|
+
const { useConnectionStore } = await import("../use-connection-store");
|
|
23
|
+
useConnectionStore.getState().setMode("desktop");
|
|
24
|
+
expect(useConnectionStore.getState().mode).toBe("desktop");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should toggle mode between web and desktop", async () => {
|
|
28
|
+
const { useConnectionStore } = await import("../use-connection-store");
|
|
29
|
+
expect(useConnectionStore.getState().mode).toBe("web");
|
|
30
|
+
useConnectionStore.getState().setMode("desktop");
|
|
31
|
+
expect(useConnectionStore.getState().mode).toBe("desktop");
|
|
32
|
+
useConnectionStore.getState().setMode("web");
|
|
33
|
+
expect(useConnectionStore.getState().mode).toBe("web");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useLocaleStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
localStorage.clear();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should default to English", async () => {
|
|
10
|
+
const { useLocaleStore } = await import("../use-locale-store");
|
|
11
|
+
expect(useLocaleStore.getState().locale).toBe("en");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should change locale", async () => {
|
|
15
|
+
const { useLocaleStore } = await import("../use-locale-store");
|
|
16
|
+
useLocaleStore.getState().setLocale("zh");
|
|
17
|
+
expect(useLocaleStore.getState().locale).toBe("zh");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should persist locale to localStorage", async () => {
|
|
21
|
+
const { useLocaleStore } = await import("../use-locale-store");
|
|
22
|
+
useLocaleStore.getState().setLocale("zh");
|
|
23
|
+
expect(localStorage.getItem("locale")).toBe("zh");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should restore locale from localStorage", async () => {
|
|
27
|
+
localStorage.setItem("locale", "zh");
|
|
28
|
+
vi.resetModules();
|
|
29
|
+
const { useLocaleStore } = await import("../use-locale-store");
|
|
30
|
+
expect(useLocaleStore.getState().locale).toBe("zh");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useLogStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should start with empty logs", async () => {
|
|
9
|
+
const { useLogStore } = await import("../use-log-store");
|
|
10
|
+
expect(useLogStore.getState().logs).toEqual([]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should add log entries", async () => {
|
|
14
|
+
const { useLogStore } = await import("../use-log-store");
|
|
15
|
+
useLogStore.getState().addLog("test message");
|
|
16
|
+
const logs = useLogStore.getState().logs;
|
|
17
|
+
expect(logs).toHaveLength(1);
|
|
18
|
+
expect(logs[0]).toContain("test message");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should prepend timestamp to log entries", async () => {
|
|
22
|
+
const { useLogStore } = await import("../use-log-store");
|
|
23
|
+
useLogStore.getState().addLog("hello");
|
|
24
|
+
const log = useLogStore.getState().logs[0];
|
|
25
|
+
expect(log).toMatch(/^\[\d{2}:\d{2}:\d{2}\] hello$/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should limit log entries to MAX_LOGS", async () => {
|
|
29
|
+
const { useLogStore } = await import("../use-log-store");
|
|
30
|
+
for (let i = 0; i < 200; i++) {
|
|
31
|
+
useLogStore.getState().addLog(`log ${i}`);
|
|
32
|
+
}
|
|
33
|
+
expect(useLogStore.getState().logs.length).toBeLessThanOrEqual(100);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should keep most recent logs when exceeding limit", async () => {
|
|
37
|
+
const { useLogStore } = await import("../use-log-store");
|
|
38
|
+
for (let i = 0; i < 150; i++) {
|
|
39
|
+
useLogStore.getState().addLog(`log ${i}`);
|
|
40
|
+
}
|
|
41
|
+
const logs = useLogStore.getState().logs;
|
|
42
|
+
expect(logs.length).toBeLessThanOrEqual(100);
|
|
43
|
+
expect(logs[logs.length - 1]).toContain("log 149");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("useThemeStore", () => {
|
|
4
|
+
beforeEach(async () => {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
localStorage.clear();
|
|
7
|
+
document.documentElement.classList.remove("dark");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should default to dark theme", async () => {
|
|
11
|
+
const { useThemeStore } = await import("../use-theme-store");
|
|
12
|
+
const state = useThemeStore.getState();
|
|
13
|
+
expect(state.theme).toBe("dark");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should toggle between light and dark", async () => {
|
|
17
|
+
const { useThemeStore } = await import("../use-theme-store");
|
|
18
|
+
const store = useThemeStore.getState();
|
|
19
|
+
|
|
20
|
+
expect(store.theme).toBe("dark");
|
|
21
|
+
store.toggleTheme();
|
|
22
|
+
expect(useThemeStore.getState().theme).toBe("light");
|
|
23
|
+
|
|
24
|
+
useThemeStore.getState().toggleTheme();
|
|
25
|
+
expect(useThemeStore.getState().theme).toBe("dark");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should set theme explicitly", async () => {
|
|
29
|
+
const { useThemeStore } = await import("../use-theme-store");
|
|
30
|
+
useThemeStore.getState().setTheme("light");
|
|
31
|
+
expect(useThemeStore.getState().theme).toBe("light");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should persist theme to localStorage", async () => {
|
|
35
|
+
const { useThemeStore } = await import("../use-theme-store");
|
|
36
|
+
useThemeStore.getState().setTheme("light");
|
|
37
|
+
|
|
38
|
+
expect(localStorage.getItem("theme")).toBe("light");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should restore theme from localStorage", async () => {
|
|
42
|
+
localStorage.setItem("theme", "light");
|
|
43
|
+
|
|
44
|
+
vi.resetModules();
|
|
45
|
+
const { useThemeStore } = await import("../use-theme-store");
|
|
46
|
+
|
|
47
|
+
expect(useThemeStore.getState().theme).toBe("light");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should apply dark class to document element", async () => {
|
|
51
|
+
const { useThemeStore } = await import("../use-theme-store");
|
|
52
|
+
useThemeStore.getState().setTheme("dark");
|
|
53
|
+
|
|
54
|
+
expect(document.documentElement.classList.contains("dark")).toBe(true);
|
|
55
|
+
|
|
56
|
+
useThemeStore.getState().setTheme("light");
|
|
57
|
+
expect(document.documentElement.classList.contains("dark")).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Update = { sessionId: string; apply: () => void };
|
|
2
|
+
|
|
3
|
+
let queue: Update[] = [];
|
|
4
|
+
let rafId: number | null = null;
|
|
5
|
+
|
|
6
|
+
function flush() {
|
|
7
|
+
rafId = null;
|
|
8
|
+
const batch = queue;
|
|
9
|
+
queue = [];
|
|
10
|
+
for (const u of batch) u.apply();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function batchMessageUpdate(sessionId: string, apply: () => void) {
|
|
14
|
+
queue.push({ sessionId, apply });
|
|
15
|
+
if (!rafId) {
|
|
16
|
+
rafId = requestAnimationFrame(flush);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function flushNow() {
|
|
21
|
+
if (rafId) {
|
|
22
|
+
cancelAnimationFrame(rafId);
|
|
23
|
+
flush();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { apiClient } from "../lib/api-client";
|
|
3
|
+
import type { RPCMethods } from "../lib/api-client";
|
|
4
|
+
import type { MethodResult } from "@dyyz1993/rpc-core";
|
|
5
|
+
import type { DemoMethod } from "../types";
|
|
6
|
+
import { useLogStore } from "./use-log-store";
|
|
7
|
+
|
|
8
|
+
type DemoResult = MethodResult<RPCMethods, "system.ping">
|
|
9
|
+
| MethodResult<RPCMethods, "system.hello">
|
|
10
|
+
| MethodResult<RPCMethods, "system.echo">
|
|
11
|
+
| MethodResult<RPCMethods, "chat.send">;
|
|
12
|
+
|
|
13
|
+
interface AppState {
|
|
14
|
+
method: DemoMethod;
|
|
15
|
+
result: DemoResult | null;
|
|
16
|
+
tickEvents: string[];
|
|
17
|
+
tickCount: number;
|
|
18
|
+
subscriptionId: string | null;
|
|
19
|
+
timerRunning: boolean;
|
|
20
|
+
|
|
21
|
+
setMethod: (method: DemoMethod) => void;
|
|
22
|
+
callRPC: (inputText: string) => Promise<void>;
|
|
23
|
+
handleSubscribe: () => Promise<void>;
|
|
24
|
+
handleUnsubscribe: () => Promise<void>;
|
|
25
|
+
clearDebug: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const useAppStore = create<AppState>((set, get) => ({
|
|
29
|
+
method: "system.ping",
|
|
30
|
+
result: null,
|
|
31
|
+
tickEvents: [],
|
|
32
|
+
tickCount: 0,
|
|
33
|
+
subscriptionId: null,
|
|
34
|
+
timerRunning: false,
|
|
35
|
+
|
|
36
|
+
setMethod: (method) => set({ method }),
|
|
37
|
+
|
|
38
|
+
callRPC: async (inputText: string) => {
|
|
39
|
+
const { method } = get();
|
|
40
|
+
const addLog = useLogStore.getState().addLog;
|
|
41
|
+
addLog(`RPC call: ${method}`);
|
|
42
|
+
try {
|
|
43
|
+
addLog(`Calling: ${method}...`);
|
|
44
|
+
let res: DemoResult;
|
|
45
|
+
if (method === "system.ping") {
|
|
46
|
+
res = await apiClient.call("system.ping", {});
|
|
47
|
+
} else if (method === "system.hello") {
|
|
48
|
+
res = await apiClient.call("system.hello", {});
|
|
49
|
+
} else if (method === "system.echo") {
|
|
50
|
+
res = await apiClient.call("system.echo", {});
|
|
51
|
+
} else if (method === "chat.send") {
|
|
52
|
+
const content = inputText.trim() || "Hello from RPC";
|
|
53
|
+
res = await apiClient.call("chat.send", { content });
|
|
54
|
+
}
|
|
55
|
+
set({ result: res });
|
|
56
|
+
addLog(`Result: ${JSON.stringify(res)}`);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
addLog(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
handleSubscribe: async () => {
|
|
63
|
+
const addLog = useLogStore.getState().addLog;
|
|
64
|
+
try {
|
|
65
|
+
addLog("Subscribing to tick events...");
|
|
66
|
+
await apiClient.call("timer.start", {});
|
|
67
|
+
set({ timerRunning: true });
|
|
68
|
+
addLog("Timer started");
|
|
69
|
+
|
|
70
|
+
const subId = await apiClient.subscribe("timer.tick", (payload) => {
|
|
71
|
+
const time = new Date(payload.timestamp).toLocaleTimeString();
|
|
72
|
+
set((s) => ({
|
|
73
|
+
tickEvents: [...s.tickEvents.slice(-19), `#${payload.count} @ ${time}`],
|
|
74
|
+
tickCount: s.tickCount + 1,
|
|
75
|
+
}));
|
|
76
|
+
}, {});
|
|
77
|
+
set({ subscriptionId: subId });
|
|
78
|
+
addLog(`Subscribed: ${subId}`);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
addLog(`Subscribe error: ${err instanceof Error ? err.message : String(err)}`);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
handleUnsubscribe: async () => {
|
|
85
|
+
const { subscriptionId } = get();
|
|
86
|
+
const addLog = useLogStore.getState().addLog;
|
|
87
|
+
try {
|
|
88
|
+
if (subscriptionId) {
|
|
89
|
+
apiClient.unsubscribe(subscriptionId);
|
|
90
|
+
set({ subscriptionId: null });
|
|
91
|
+
addLog("Unsubscribed");
|
|
92
|
+
}
|
|
93
|
+
await apiClient.call("timer.stop", {});
|
|
94
|
+
set({ timerRunning: false });
|
|
95
|
+
addLog("Timer stopped");
|
|
96
|
+
} catch (err) {
|
|
97
|
+
addLog(`Unsubscribe error: ${err instanceof Error ? err.message : String(err)}`);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
clearDebug: () => {
|
|
102
|
+
set({ result: null, tickEvents: [], tickCount: 0 });
|
|
103
|
+
},
|
|
104
|
+
}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import type { ChatMessage } from "../types";
|
|
3
|
+
import { apiClient } from "../lib/api-client";
|
|
4
|
+
import { useLogStore } from "./use-log-store";
|
|
5
|
+
|
|
6
|
+
interface ChatState {
|
|
7
|
+
messages: ChatMessage[];
|
|
8
|
+
inputText: string;
|
|
9
|
+
|
|
10
|
+
setInputText: (text: string) => void;
|
|
11
|
+
sendMessage: () => Promise<void>;
|
|
12
|
+
addMessage: (msg: ChatMessage) => void;
|
|
13
|
+
setMessages: (msgs: ChatMessage[]) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const useChatStore = create<ChatState>((set, get) => ({
|
|
17
|
+
messages: [],
|
|
18
|
+
inputText: "",
|
|
19
|
+
|
|
20
|
+
setInputText: (text) => set({ inputText: text }),
|
|
21
|
+
|
|
22
|
+
sendMessage: async () => {
|
|
23
|
+
const { inputText } = get();
|
|
24
|
+
if (!inputText.trim()) return;
|
|
25
|
+
const text = inputText.trim();
|
|
26
|
+
set({ inputText: "" });
|
|
27
|
+
try {
|
|
28
|
+
await apiClient.call("chat.send", { content: text });
|
|
29
|
+
} catch (err) {
|
|
30
|
+
useLogStore.getState().addLog(`Chat error: ${err instanceof Error ? err.message : String(err)}`);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
addMessage: (msg) => set((s) => ({ messages: [...s.messages, msg] })),
|
|
35
|
+
|
|
36
|
+
setMessages: (msgs) => set({ messages: msgs }),
|
|
37
|
+
}));
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { apiClient } from "../lib/api-client";
|
|
3
|
+
import { useLogStore } from "./use-log-store";
|
|
4
|
+
|
|
5
|
+
interface ConnectionState {
|
|
6
|
+
mode: "web" | "desktop";
|
|
7
|
+
ready: boolean;
|
|
8
|
+
setReady: (ready: boolean) => void;
|
|
9
|
+
setMode: (mode: "web" | "desktop") => void;
|
|
10
|
+
initializeConnection: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const useConnectionStore = create<ConnectionState>((set) => ({
|
|
14
|
+
mode: "web",
|
|
15
|
+
ready: false,
|
|
16
|
+
setReady: (ready) => set({ ready }),
|
|
17
|
+
setMode: (mode) => set({ mode }),
|
|
18
|
+
|
|
19
|
+
initializeConnection: () => {
|
|
20
|
+
const MAX_RETRIES = 5;
|
|
21
|
+
let retries = 0;
|
|
22
|
+
const init = async () => {
|
|
23
|
+
try {
|
|
24
|
+
await apiClient.initialize();
|
|
25
|
+
const transport = apiClient.getTransport();
|
|
26
|
+
set({
|
|
27
|
+
mode: transport === "ipc" ? "desktop" : "web",
|
|
28
|
+
ready: true,
|
|
29
|
+
});
|
|
30
|
+
useLogStore.getState().addLog(`${transport === "ipc" ? "Desktop" : "Web"} mode - ${transport.toUpperCase()}`);
|
|
31
|
+
} catch {
|
|
32
|
+
retries++;
|
|
33
|
+
if (retries < MAX_RETRIES) {
|
|
34
|
+
setTimeout(init, 1000);
|
|
35
|
+
} else {
|
|
36
|
+
useLogStore.getState().addLog(`Failed to connect after ${MAX_RETRIES} retries`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
init();
|
|
41
|
+
},
|
|
42
|
+
}));
|