@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,20 @@
|
|
|
1
|
+
import { useTranslation } from "react-i18next";
|
|
2
|
+
import { items } from "./ActivityBar";
|
|
3
|
+
|
|
4
|
+
export function MobileTabBar() {
|
|
5
|
+
const { t } = useTranslation();
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div className="h-14 bg-[var(--color-bg-primary)] border-t border-[var(--color-border-primary)] flex items-center justify-around flex-shrink-0">
|
|
9
|
+
{items.map(({ id, icon: Icon, labelKey }) => (
|
|
10
|
+
<button
|
|
11
|
+
key={id}
|
|
12
|
+
className="flex flex-col items-center justify-center gap-0.5 px-3 py-1 rounded transition-colors text-[var(--color-text-accent)]"
|
|
13
|
+
>
|
|
14
|
+
<Icon className="w-5 h-5" />
|
|
15
|
+
<span className="text-[10px]">{t(labelKey)}</span>
|
|
16
|
+
</button>
|
|
17
|
+
))}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { MessageSquare, Send } from "lucide-react";
|
|
3
|
+
import { useTranslation } from "react-i18next";
|
|
4
|
+
import { useChatStore } from "../../stores/use-chat-store";
|
|
5
|
+
import { MessageBubble } from "./MessageBubble";
|
|
6
|
+
|
|
7
|
+
export function ChatPanel() {
|
|
8
|
+
const { t } = useTranslation();
|
|
9
|
+
const messages = useChatStore((s) => s.messages);
|
|
10
|
+
const inputText = useChatStore((s) => s.inputText);
|
|
11
|
+
const setInputText = useChatStore((s) => s.setInputText);
|
|
12
|
+
const sendMessage = useChatStore((s) => s.sendMessage);
|
|
13
|
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
17
|
+
}, [messages]);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className="flex-1 flex flex-col overflow-hidden relative">
|
|
21
|
+
{/* Chat header */}
|
|
22
|
+
<div className="px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex items-center justify-between flex-shrink-0">
|
|
23
|
+
<h2 className="text-sm font-semibold flex items-center gap-1.5">
|
|
24
|
+
<MessageSquare className="w-4 h-4 text-[var(--color-text-accent)]" />
|
|
25
|
+
{t("chat.title")}
|
|
26
|
+
{messages.length > 0 && (
|
|
27
|
+
<span className="ml-1 px-2 py-0.5 bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] rounded text-[10px]">
|
|
28
|
+
{messages.length}
|
|
29
|
+
</span>
|
|
30
|
+
)}
|
|
31
|
+
</h2>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
{/* Messages list */}
|
|
35
|
+
<div className="flex-1 overflow-y-auto p-4 space-y-3">
|
|
36
|
+
{messages.length === 0 ? (
|
|
37
|
+
<div className="flex items-center justify-center h-full text-[var(--color-text-placeholder)] text-sm">
|
|
38
|
+
{t("chat.empty")}
|
|
39
|
+
</div>
|
|
40
|
+
) : (
|
|
41
|
+
messages.map((msg) => <MessageBubble key={msg.id} message={msg} />)
|
|
42
|
+
)}
|
|
43
|
+
<div ref={messagesEndRef} />
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
{/* Input bar */}
|
|
47
|
+
<div className="px-4 py-3 bg-[var(--color-bg-secondary)] border-t border-[var(--color-border-primary)] flex gap-2 flex-shrink-0">
|
|
48
|
+
<input
|
|
49
|
+
type="text"
|
|
50
|
+
value={inputText}
|
|
51
|
+
onChange={(e) => setInputText(e.target.value)}
|
|
52
|
+
onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && sendMessage()}
|
|
53
|
+
placeholder={t("chat.placeholder")}
|
|
54
|
+
className="flex-1 px-3 py-2 text-sm bg-[var(--color-bg-tertiary)] rounded-lg text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
|
|
55
|
+
/>
|
|
56
|
+
<button
|
|
57
|
+
onClick={sendMessage}
|
|
58
|
+
className="px-4 py-2 text-sm bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded-lg transition-colors flex items-center gap-1.5"
|
|
59
|
+
>
|
|
60
|
+
<Send className="w-4 h-4" />
|
|
61
|
+
{t("chat.send")}
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Bot } from "lucide-react";
|
|
2
|
+
import ReactMarkdown from "react-markdown";
|
|
3
|
+
import remarkGfm from "remark-gfm";
|
|
4
|
+
import { Highlight, themes } from "prism-react-renderer";
|
|
5
|
+
import type { ChatMessage } from "../../types";
|
|
6
|
+
|
|
7
|
+
interface MessageBubbleProps {
|
|
8
|
+
message: ChatMessage;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function formatTime(ts: number): string {
|
|
12
|
+
const d = new Date(ts);
|
|
13
|
+
const hh = d.getHours().toString().padStart(2, "0");
|
|
14
|
+
const mm = d.getMinutes().toString().padStart(2, "0");
|
|
15
|
+
return `${hh}:${mm}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function CodeBlock({ children, className }: { children: string; className?: string }) {
|
|
19
|
+
const language = className?.replace(/language-/, "") || "text";
|
|
20
|
+
return (
|
|
21
|
+
<Highlight theme={themes.nightOwl} code={children.trimEnd()} language={language}>
|
|
22
|
+
{({ style, tokens, getLineProps, getTokenProps }) => (
|
|
23
|
+
<pre
|
|
24
|
+
className="rounded-md p-3 my-2 overflow-x-auto text-xs leading-relaxed"
|
|
25
|
+
style={{ ...style, background: "#1e1e2e" }}
|
|
26
|
+
>
|
|
27
|
+
{tokens.map((line, i) => (
|
|
28
|
+
<div key={i} {...getLineProps({ line })}>
|
|
29
|
+
{line.map((token, key) => (
|
|
30
|
+
<span key={key} {...getTokenProps({ token })} />
|
|
31
|
+
))}
|
|
32
|
+
</div>
|
|
33
|
+
))}
|
|
34
|
+
</pre>
|
|
35
|
+
)}
|
|
36
|
+
</Highlight>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function MessageBubble({ message }: MessageBubbleProps) {
|
|
41
|
+
const isUser = message.role === "user";
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={`flex ${isUser ? "justify-end" : "justify-start"} items-start gap-2`}>
|
|
45
|
+
{!isUser && (
|
|
46
|
+
<div className="flex-shrink-0 mt-1">
|
|
47
|
+
<Bot className="w-4 h-4 text-[var(--color-text-accent)]" />
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
<div
|
|
51
|
+
className={`max-w-[85%] px-3 py-2 rounded-lg text-sm break-words ${
|
|
52
|
+
isUser
|
|
53
|
+
? "bg-[var(--color-accent)] text-[var(--color-text-primary)]"
|
|
54
|
+
: "bg-[var(--color-bg-tertiary)] text-[var(--color-text-secondary)]"
|
|
55
|
+
}`}
|
|
56
|
+
>
|
|
57
|
+
{isUser ? (
|
|
58
|
+
<span className="whitespace-pre-wrap">{message.content}</span>
|
|
59
|
+
) : (
|
|
60
|
+
<div className="markdown-body prose prose-invert prose-sm max-w-none [&_p]:mb-2 [&_p:last-child]:mb-0 [&_ul]:list-disc [&_ul]:pl-4 [&_ol]:list-decimal [&_ol]:pl-4 [&_li]:mb-1 [&_h1]:text-base [&_h1]:font-bold [&_h1]:mb-2 [&_h2]:text-sm [&_h2]:font-bold [&_h2]:mb-1 [&_blockquote]:border-l-2 [&_blockquote]:border-[var(--color-text-accent)] [&_blockquote]:pl-3 [&_blockquote]:text-[var(--color-text-tertiary)] [&_a]:text-[var(--color-text-accent)] [&_a]:underline [&_code:not(pre_code)]:bg-[var(--color-bg-input)] [&_code:not(pre_code)]:px-1 [&_code:not(pre_code)]:rounded [&_code:not(pre_code)]:text-xs [&_table]:border-collapse [&_th]:border [&_th]:border-[var(--color-border-secondary)] [&_th]:px-2 [&_th]:py-1 [&_td]:border [&_td]:border-[var(--color-border-secondary)] [&_td]:px-2 [&_td]:py-1">
|
|
61
|
+
<ReactMarkdown
|
|
62
|
+
remarkPlugins={[remarkGfm]}
|
|
63
|
+
components={{
|
|
64
|
+
code({ className, children, ...props }) {
|
|
65
|
+
const isBlock = className?.startsWith("language-") || String(children).includes("\n");
|
|
66
|
+
if (isBlock) {
|
|
67
|
+
return <CodeBlock className={className}>{String(children)}</CodeBlock>;
|
|
68
|
+
}
|
|
69
|
+
return <code className={className} {...props}>{children}</code>;
|
|
70
|
+
},
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{message.content}
|
|
74
|
+
</ReactMarkdown>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
{message.timestamp && (
|
|
79
|
+
<span className="text-[10px] text-[var(--color-text-tertiary)] ml-2 flex-shrink-0">
|
|
80
|
+
{formatTime(message.timestamp)}
|
|
81
|
+
</span>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useLocaleStore } from "../../stores/use-locale-store";
|
|
2
|
+
|
|
3
|
+
export function LanguageSwitcher() {
|
|
4
|
+
const { locale, setLocale } = useLocaleStore();
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<button
|
|
8
|
+
onClick={() => setLocale(locale === "en" ? "zh" : "en")}
|
|
9
|
+
className="px-1.5 py-0.5 rounded text-xs hover:bg-[var(--color-bg-hover)] transition-colors text-[var(--color-text-secondary)]"
|
|
10
|
+
title={locale === "en" ? "切换到中文" : "Switch to English"}
|
|
11
|
+
>
|
|
12
|
+
{locale === "en" ? "中" : "EN"}
|
|
13
|
+
</button>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useThemeStore } from "../../stores/use-theme-store";
|
|
2
|
+
|
|
3
|
+
export function ThemeToggle() {
|
|
4
|
+
const theme = useThemeStore((s) => s.theme);
|
|
5
|
+
const toggleTheme = useThemeStore((s) => s.toggleTheme);
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<button
|
|
9
|
+
onClick={toggleTheme}
|
|
10
|
+
className="p-1.5 rounded-md hover:bg-[var(--color-bg-hover)] transition-colors"
|
|
11
|
+
title={theme === "dark" ? "Switch to light mode" : "Switch to dark mode"}
|
|
12
|
+
>
|
|
13
|
+
{theme === "dark" ? (
|
|
14
|
+
<svg className="w-4 h-4 text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
15
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" />
|
|
16
|
+
</svg>
|
|
17
|
+
) : (
|
|
18
|
+
<svg className="w-4 h-4 text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
19
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" />
|
|
20
|
+
</svg>
|
|
21
|
+
)}
|
|
22
|
+
</button>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Pin, PinOff } from "lucide-react";
|
|
2
|
+
import { useSidebarStore } from "../../stores/use-sidebar-store";
|
|
3
|
+
|
|
4
|
+
export function PinButton() {
|
|
5
|
+
const isPinned = useSidebarStore((s) => s.isPinned);
|
|
6
|
+
const setPinned = useSidebarStore((s) => s.setPinned);
|
|
7
|
+
const isMobile = useSidebarStore((s) => s.breakpoint) === "mobile";
|
|
8
|
+
|
|
9
|
+
if (isMobile) return null;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<button
|
|
13
|
+
onClick={() => setPinned(!isPinned)}
|
|
14
|
+
title={isPinned ? "Unpin sidebar" : "Pin sidebar"}
|
|
15
|
+
className="text-[var(--color-text-placeholder)] hover:text-[var(--color-text-primary)] transition-colors"
|
|
16
|
+
>
|
|
17
|
+
{isPinned ? <PinOff className="w-3 h-3" /> : <Pin className="w-3 h-3" />}
|
|
18
|
+
</button>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -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,34 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useSidebarStore, type Breakpoint } from "../stores/use-sidebar-store";
|
|
3
|
+
|
|
4
|
+
function getBreakpoint(width: number): Breakpoint {
|
|
5
|
+
if (width < 768) return "mobile";
|
|
6
|
+
if (width < 1024) return "tablet";
|
|
7
|
+
return "desktop";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 单一 ResizeObserver,同步 breakpoint 到 sidebar store。
|
|
12
|
+
* 组件通过 useSidebarStore(s => s.breakpoint) 读取。
|
|
13
|
+
*/
|
|
14
|
+
export function useBreakpointSync() {
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
17
|
+
const obs = new ResizeObserver((entries) => {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
timer = setTimeout(() => {
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
const bp = getBreakpoint(entry.contentRect.width);
|
|
22
|
+
if (bp !== useSidebarStore.getState().breakpoint) {
|
|
23
|
+
useSidebarStore.getState()._setBreakpoint(bp);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, 100);
|
|
27
|
+
});
|
|
28
|
+
obs.observe(document.documentElement);
|
|
29
|
+
return () => {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
obs.disconnect();
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useState, useCallback, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
const HISTORY_KEY = "pi-input-history";
|
|
4
|
+
const MAX_ITEMS = 10;
|
|
5
|
+
|
|
6
|
+
function getStorageKey(sessionId: string): string {
|
|
7
|
+
return `${HISTORY_KEY}:${sessionId}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function readHistory(sessionId: string): string[] {
|
|
11
|
+
try {
|
|
12
|
+
const raw = localStorage.getItem(getStorageKey(sessionId));
|
|
13
|
+
if (!raw) return [];
|
|
14
|
+
const parsed = JSON.parse(raw);
|
|
15
|
+
if (Array.isArray(parsed)) return parsed.slice(0, MAX_ITEMS);
|
|
16
|
+
} catch { /* ignore */ }
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function writeHistory(sessionId: string, items: string[]) {
|
|
21
|
+
try {
|
|
22
|
+
localStorage.setItem(getStorageKey(sessionId), JSON.stringify(items.slice(0, MAX_ITEMS)));
|
|
23
|
+
} catch { /* ignore */ }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useInputHistory(sessionId: string) {
|
|
27
|
+
const historyRef = useRef<string[]>(readHistory(sessionId));
|
|
28
|
+
const indexRef = useRef(-1);
|
|
29
|
+
const [, forceUpdate] = useState(0);
|
|
30
|
+
|
|
31
|
+
const hasPrev = historyRef.current.length > 0 && indexRef.current < historyRef.current.length - 1;
|
|
32
|
+
const hasNext = indexRef.current > 0;
|
|
33
|
+
|
|
34
|
+
const saveToHistory = useCallback((text: string) => {
|
|
35
|
+
const trimmed = text.trim();
|
|
36
|
+
if (!trimmed) return;
|
|
37
|
+
const h = historyRef.current;
|
|
38
|
+
const filtered = h.filter((item) => item !== trimmed);
|
|
39
|
+
const updated = [trimmed, ...filtered].slice(0, MAX_ITEMS);
|
|
40
|
+
historyRef.current = updated;
|
|
41
|
+
writeHistory(sessionId, updated);
|
|
42
|
+
indexRef.current = -1;
|
|
43
|
+
forceUpdate((n) => n + 1);
|
|
44
|
+
}, [sessionId]);
|
|
45
|
+
|
|
46
|
+
const navigatePrev = useCallback((): string | null => {
|
|
47
|
+
const h = historyRef.current;
|
|
48
|
+
if (h.length === 0) return null;
|
|
49
|
+
const nextIdx = Math.min(indexRef.current + 1, h.length - 1);
|
|
50
|
+
indexRef.current = nextIdx;
|
|
51
|
+
forceUpdate((n) => n + 1);
|
|
52
|
+
return h[nextIdx];
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
const navigateNext = useCallback((): string | null => {
|
|
56
|
+
const h = historyRef.current;
|
|
57
|
+
if (h.length === 0) return null;
|
|
58
|
+
const nextIdx = indexRef.current - 1;
|
|
59
|
+
if (nextIdx < 0) {
|
|
60
|
+
indexRef.current = -1;
|
|
61
|
+
forceUpdate((n) => n + 1);
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
indexRef.current = nextIdx;
|
|
65
|
+
forceUpdate((n) => n + 1);
|
|
66
|
+
return h[nextIdx];
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
const clearHistory = useCallback(() => {
|
|
70
|
+
historyRef.current = [];
|
|
71
|
+
indexRef.current = -1;
|
|
72
|
+
try {
|
|
73
|
+
localStorage.removeItem(getStorageKey(sessionId));
|
|
74
|
+
} catch { /* ignore */ }
|
|
75
|
+
forceUpdate((n) => n + 1);
|
|
76
|
+
}, [sessionId]);
|
|
77
|
+
|
|
78
|
+
const resetIndex = useCallback(() => {
|
|
79
|
+
indexRef.current = -1;
|
|
80
|
+
forceUpdate((n) => n + 1);
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
return { saveToHistory, navigatePrev, navigateNext, clearHistory, resetIndex, hasPrev, hasNext };
|
|
84
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
:root {
|
|
6
|
+
--color-bg-primary: #ffffff;
|
|
7
|
+
--color-bg-secondary: #f3f4f6;
|
|
8
|
+
--color-bg-tertiary: #e5e7eb;
|
|
9
|
+
--color-bg-input: #f9fafb;
|
|
10
|
+
--color-bg-hover: #e5e7eb;
|
|
11
|
+
--color-bg-active: #d1d5db;
|
|
12
|
+
--color-bg-sidebar: #f3f4f6;
|
|
13
|
+
--color-bg-overlay: rgba(0, 0, 0, 0.5);
|
|
14
|
+
|
|
15
|
+
--color-text-primary: #111827;
|
|
16
|
+
--color-text-secondary: #4b5563;
|
|
17
|
+
--color-text-tertiary: #9ca3af;
|
|
18
|
+
--color-text-placeholder: #6b7280;
|
|
19
|
+
--color-text-accent: #4f46e5;
|
|
20
|
+
--color-text-success: #16a34a;
|
|
21
|
+
--color-text-error: #dc2626;
|
|
22
|
+
--color-text-info: #0891b2;
|
|
23
|
+
|
|
24
|
+
--color-border-primary: #d1d5db;
|
|
25
|
+
--color-border-secondary: #e5e7eb;
|
|
26
|
+
|
|
27
|
+
--color-accent: #4f46e5;
|
|
28
|
+
--color-accent-hover: #4338ca;
|
|
29
|
+
|
|
30
|
+
--color-badge-bg: #e0e7ff;
|
|
31
|
+
--color-badge-text: #3730a3;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.dark {
|
|
35
|
+
--color-bg-primary: #111827;
|
|
36
|
+
--color-bg-secondary: #1f2937;
|
|
37
|
+
--color-bg-tertiary: #374151;
|
|
38
|
+
--color-bg-input: #374151;
|
|
39
|
+
--color-bg-hover: #4b5563;
|
|
40
|
+
--color-bg-active: #6b7280;
|
|
41
|
+
--color-bg-sidebar: #1f2937;
|
|
42
|
+
--color-bg-overlay: rgba(0, 0, 0, 0.7);
|
|
43
|
+
|
|
44
|
+
--color-text-primary: #ffffff;
|
|
45
|
+
--color-text-secondary: #d1d5db;
|
|
46
|
+
--color-text-tertiary: #6b7280;
|
|
47
|
+
--color-text-placeholder: #9ca3af;
|
|
48
|
+
--color-text-accent: #818cf8;
|
|
49
|
+
--color-text-success: #4ade80;
|
|
50
|
+
--color-text-error: #f87171;
|
|
51
|
+
--color-text-info: #22d3ee;
|
|
52
|
+
|
|
53
|
+
--color-border-primary: #374151;
|
|
54
|
+
--color-border-secondary: #4b5563;
|
|
55
|
+
|
|
56
|
+
--color-accent: #6366f1;
|
|
57
|
+
--color-accent-hover: #4f46e5;
|
|
58
|
+
|
|
59
|
+
--color-badge-bg: #312e81;
|
|
60
|
+
--color-badge-text: #a5b4fc;
|
|
61
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>React + Tailwind + Vite</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="./main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { createTypedClient, WebSocketTransport, IPCTransport } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { TypedClient, MethodParams, MethodResult, EventPayload, EventMetadata } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, RPCEvents } from "../../shared/rpc-schema";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Token 来源优先级:
|
|
7
|
+
* 1. URL query ?token=xxx(部署时注入)
|
|
8
|
+
* 2. localStorage "rpc-auth-token"
|
|
9
|
+
* 3. 默认值(开发用)
|
|
10
|
+
*/
|
|
11
|
+
function resolveAuthToken(): string {
|
|
12
|
+
if (typeof window !== "undefined") {
|
|
13
|
+
const fromQuery = new URLSearchParams(window.location.search).get("token");
|
|
14
|
+
if (fromQuery) return fromQuery;
|
|
15
|
+
const fromStorage = localStorage.getItem("rpc-auth-token");
|
|
16
|
+
if (fromStorage) return fromStorage;
|
|
17
|
+
}
|
|
18
|
+
return "pi-agent-template-token";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const AUTH_TOKEN = resolveAuthToken();
|
|
22
|
+
|
|
23
|
+
class APIClientImpl {
|
|
24
|
+
private client: TypedClient<RPCMethods, RPCEvents> | null = null;
|
|
25
|
+
private initPromise: Promise<void> | null = null;
|
|
26
|
+
private _transport: "ipc" | "websocket" = "websocket";
|
|
27
|
+
private _baseUrl: string | null = null;
|
|
28
|
+
private wsTransport: WebSocketTransport | null = null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 桌面端同步初始化:通过 executeJavascript 接收 + __electrobunBunBridge 发送
|
|
32
|
+
*/
|
|
33
|
+
initSyncForDesktop(): void {
|
|
34
|
+
if (this.client) return;
|
|
35
|
+
|
|
36
|
+
const ipcTransport = new IPCTransport();
|
|
37
|
+
this._transport = "ipc";
|
|
38
|
+
this._baseUrl = null; // 桌面端不走 HTTP
|
|
39
|
+
this.client = createTypedClient<RPCMethods, RPCEvents>(ipcTransport);
|
|
40
|
+
this.setupElectrobunBridge(ipcTransport);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 异步初始化:Web 端使用(连接 WebSocket)
|
|
45
|
+
*/
|
|
46
|
+
async initialize(): Promise<void> {
|
|
47
|
+
// 已连接且 transport 正常 → 直接返回
|
|
48
|
+
if (this.client && (this._transport === "ipc" || this.wsTransport?.isConnected())) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// client 存在但 WS 断开了 → 清理后重连
|
|
53
|
+
if (this.client && this.wsTransport && !this.wsTransport.isConnected()) {
|
|
54
|
+
this.wsTransport.close();
|
|
55
|
+
this.wsTransport = null;
|
|
56
|
+
this.client = null;
|
|
57
|
+
this.initPromise = null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (this.initPromise) return this.initPromise;
|
|
61
|
+
|
|
62
|
+
this.initPromise = (async () => {
|
|
63
|
+
const env = this.detectEnvironment();
|
|
64
|
+
|
|
65
|
+
if (env === "electrobun") {
|
|
66
|
+
// 不应走到这里,桌面端应通过 initSyncForDesktop() 初始化
|
|
67
|
+
this.initSyncForDesktop();
|
|
68
|
+
} else {
|
|
69
|
+
this._transport = "websocket";
|
|
70
|
+
const wsUrl = this.getWebSocketUrl();
|
|
71
|
+
this.wsTransport = new WebSocketTransport(wsUrl);
|
|
72
|
+
await this.wsTransport.connect();
|
|
73
|
+
this.client = createTypedClient<RPCMethods, RPCEvents>(this.wsTransport);
|
|
74
|
+
|
|
75
|
+
const wsUrlObj = new URL(wsUrl);
|
|
76
|
+
this._baseUrl = `http://${wsUrlObj.host}`;
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
|
|
80
|
+
return this.initPromise;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private detectEnvironment(): "electrobun" | "browser" {
|
|
84
|
+
if (typeof window === "undefined") return "browser";
|
|
85
|
+
if (window.__electrobunBunBridge) return "electrobun";
|
|
86
|
+
return "browser";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private getWebSocketUrl(): string {
|
|
90
|
+
if (typeof window === "undefined") return `ws://localhost:3100?token=${AUTH_TOKEN}`;
|
|
91
|
+
const customUrl = (
|
|
92
|
+
new URLSearchParams(window.location.search).get("ws") ||
|
|
93
|
+
localStorage.getItem("rpc-websocket-url")
|
|
94
|
+
);
|
|
95
|
+
if (customUrl) return customUrl.includes("token=") ? customUrl : `${customUrl}?token=${AUTH_TOKEN}`;
|
|
96
|
+
return `ws://${window.location.host}/ws?token=${AUTH_TOKEN}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 桌面端 IPC 桥接:
|
|
101
|
+
* - Bun → Browser: 通过 executeJavascript 调用 window.__piAgentIPC()
|
|
102
|
+
* - Browser → Bun: 通过 __electrobunBunBridge.postMessage 发送 Electrobun 消息格式
|
|
103
|
+
*/
|
|
104
|
+
private setupElectrobunBridge(ipcTransport: IPCTransport): void {
|
|
105
|
+
if (typeof window === "undefined") return;
|
|
106
|
+
|
|
107
|
+
const win = window;
|
|
108
|
+
|
|
109
|
+
// 1. 注册接收函数:Bun 通过 executeJavascript 调用此函数发送消息到 Browser
|
|
110
|
+
win.__piAgentIPC = (msg: unknown) => {
|
|
111
|
+
ipcTransport.simulateMessage(msg);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// 2. 覆写 send:将 RPC-core 消息包装成 Electrobun 消息格式,通过原生桥接发送
|
|
115
|
+
const bridge = win.__electrobunBunBridge;
|
|
116
|
+
|
|
117
|
+
if (bridge) {
|
|
118
|
+
ipcTransport.send = async (message: unknown) => {
|
|
119
|
+
// 包装成 Electrobun message packet,bun 端 defineRPC 注册了 "rpc-message" handler
|
|
120
|
+
const electrobunPacket = {
|
|
121
|
+
type: "message",
|
|
122
|
+
id: "rpc-message",
|
|
123
|
+
payload: JSON.stringify(message),
|
|
124
|
+
};
|
|
125
|
+
bridge.postMessage(JSON.stringify(electrobunPacket));
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getTransport(): "ipc" | "websocket" {
|
|
131
|
+
return this._transport;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Web 端 HTTP 基础 URL(如 http://localhost:3100),桌面端返回 null */
|
|
135
|
+
getBaseUrl(): string | null {
|
|
136
|
+
return this._baseUrl;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 获取当前 auth token(用于需要直接调 HTTP 的场景) */
|
|
140
|
+
getAuthToken(): string {
|
|
141
|
+
return AUTH_TOKEN;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async call<K extends keyof RPCMethods>(
|
|
145
|
+
method: K,
|
|
146
|
+
params: MethodParams<RPCMethods, K>
|
|
147
|
+
): Promise<MethodResult<RPCMethods, K>> {
|
|
148
|
+
await this.initialize();
|
|
149
|
+
return this.client!.call(method, params);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async subscribe<K extends keyof RPCEvents>(
|
|
153
|
+
eventType: K,
|
|
154
|
+
handler: (payload: EventPayload<RPCEvents[K]>, metadata: EventMetadata<RPCEvents[K]>) => void,
|
|
155
|
+
filter?: Record<string, unknown>
|
|
156
|
+
): Promise<string> {
|
|
157
|
+
await this.initialize();
|
|
158
|
+
return this.client!.subscribe(eventType, handler, filter);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
unsubscribe(subscriptionId: string): void {
|
|
162
|
+
this.client?.unsubscribe(subscriptionId);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
isConnected(): boolean {
|
|
166
|
+
return this.client !== null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
close(): void {
|
|
170
|
+
this.client?.close();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export const apiClient = new APIClientImpl();
|
|
175
|
+
export type { APIClientImpl, RPCMethods, RPCEvents };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import i18n from "i18next";
|
|
2
|
+
import { initReactI18next } from "react-i18next";
|
|
3
|
+
import LanguageDetector from "i18next-browser-languagedetector";
|
|
4
|
+
import en from "./locales/en.json";
|
|
5
|
+
import zh from "./locales/zh.json";
|
|
6
|
+
|
|
7
|
+
export const supportedLocales = ["en", "zh"] as const;
|
|
8
|
+
export type Locale = (typeof supportedLocales)[number];
|
|
9
|
+
|
|
10
|
+
i18n
|
|
11
|
+
.use(LanguageDetector)
|
|
12
|
+
.use(initReactI18next)
|
|
13
|
+
.init({
|
|
14
|
+
resources: {
|
|
15
|
+
en: { translation: en },
|
|
16
|
+
zh: { translation: zh },
|
|
17
|
+
},
|
|
18
|
+
fallbackLng: "en",
|
|
19
|
+
supportedLngs: [...supportedLocales],
|
|
20
|
+
interpolation: {
|
|
21
|
+
escapeValue: false,
|
|
22
|
+
},
|
|
23
|
+
detection: {
|
|
24
|
+
order: ["localStorage", "navigator"],
|
|
25
|
+
lookupLocalStorage: "locale",
|
|
26
|
+
caches: ["localStorage"],
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default i18n;
|