@dyyz1993/create-agent 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/__tests__/cli.test.ts +2 -0
- package/src/__tests__/copy.test.ts +110 -122
- package/src/__tests__/create-args.test.ts +113 -0
- package/src/__tests__/templates.test.ts +29 -3
- package/src/__tests__/update.test.ts +129 -0
- package/src/cli.ts +30 -32
- package/src/commands/create.ts +83 -24
- package/src/commands/update.ts +174 -0
- package/src/commands/workspace.ts +26 -6
- package/src/lib/copy.ts +233 -93
- package/src/lib/templates.ts +12 -0
- package/templates/agent/.husky/commit-msg +4 -0
- package/templates/agent/.husky/pre-commit +11 -0
- package/templates/agent/.husky/pre-push +6 -0
- package/templates/agent/.prettierignore +6 -0
- package/templates/agent/.prettierrc +9 -0
- package/templates/agent/CHANGELOG.md +15 -0
- package/templates/agent/commitlint.config.js +8 -0
- package/templates/agent/package.json +19 -4
- package/templates/agent/src/gateway/__tests__/ws-handler-token.test.ts +53 -39
- package/templates/agent/src/mainview/App.tsx +14 -12
- package/templates/agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +194 -190
- package/templates/agent/src/mainview/components/bash/BashPanel.tsx +210 -189
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +45 -20
- package/templates/agent/src/mainview/components/common/ThemeToggle.tsx +41 -21
- package/templates/agent/src/mainview/components/debug/DebugPanel.tsx +181 -114
- package/templates/agent/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +80 -80
- package/templates/agent/src/mainview/components/diff/__tests__/DiffViewerPanel.test.tsx +61 -58
- package/templates/agent/src/mainview/components/feed/FeedPanel.tsx +43 -41
- package/templates/agent/src/mainview/components/file-preview/FilePreviewOverlay.tsx +69 -50
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +31 -18
- package/templates/agent/src/mainview/components/git/GitPanel.tsx +731 -490
- package/templates/agent/src/mainview/components/git/__tests__/GitPanel.test.tsx +157 -139
- package/templates/agent/src/mainview/components/layout/AppLayout.tsx +210 -161
- package/templates/agent/src/mainview/components/layout/__tests__/AppLayout.test.tsx +130 -122
- package/templates/agent/src/mainview/components/rules/RulesPanel.tsx +119 -109
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +123 -117
- package/templates/agent/src/mainview/components/search/__tests__/SearchPanel.test.tsx +64 -44
- package/templates/agent/src/mainview/components/sidebar/__tests__/PinButton.test.tsx +38 -38
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +40 -38
- package/templates/agent/src/mainview/components/todo/__tests__/TodoPanel.test.tsx +72 -72
- package/templates/agent/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/agent/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/agent/src/mainview/stores/use-app-store.ts +96 -86
- package/templates/agent/src/mainview/stores/use-explorer-store.ts +292 -275
- package/templates/agent/src/mainview/types/index.ts +23 -22
- package/templates/agent/src/mainview/utils/file-icon.tsx +17 -21
- package/templates/agent/src/shared/handlers/chat.ts +53 -53
- package/templates/agent/src/shared/handlers/debug.ts +13 -3
- package/templates/browser-agent/.env.example +19 -0
- package/templates/browser-agent/.husky/commit-msg +4 -0
- package/templates/browser-agent/.husky/pre-commit +11 -0
- package/templates/browser-agent/.husky/pre-push +6 -0
- package/templates/browser-agent/.prettierignore +6 -0
- package/templates/browser-agent/.prettierrc +9 -0
- package/templates/browser-agent/AGENTS.md +396 -0
- package/templates/browser-agent/CHANGELOG.md +15 -0
- package/templates/browser-agent/LICENSE +21 -0
- package/templates/browser-agent/README.md +103 -0
- package/templates/browser-agent/commitlint.config.js +8 -0
- package/templates/browser-agent/electrobun.config.ts +27 -0
- package/templates/browser-agent/electron/main.js +46 -0
- package/templates/browser-agent/electron/preload.js +5 -0
- package/templates/browser-agent/electron-builder.json +40 -0
- package/templates/browser-agent/eslint.config.mjs +79 -0
- package/templates/browser-agent/llms.txt +24 -0
- package/templates/browser-agent/package.json +140 -0
- package/templates/browser-agent/postcss.config.js +6 -0
- package/templates/browser-agent/scripts/dev.ts +138 -0
- package/templates/browser-agent/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/browser-agent/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/browser-agent/src/__tests__/server-config.test.ts +59 -0
- package/templates/browser-agent/src/bun/index.ts +130 -0
- package/templates/browser-agent/src/bun/three.d.ts +1 -0
- package/templates/browser-agent/src/gateway/http-routes.ts +1 -0
- package/templates/browser-agent/src/gateway/ipc-transport.ts +68 -0
- package/templates/browser-agent/src/gateway/sse-transport.ts +221 -0
- package/templates/browser-agent/src/mainview/App.tsx +45 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/browser-agent/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/browser-agent/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/browser-agent/src/mainview/__tests__/setup.ts +40 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/browser-agent/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/browser-agent/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/browser-agent/src/mainview/components/assets/AssetsPanel.tsx +139 -0
- package/templates/browser-agent/src/mainview/components/chat/ChatPanel.tsx +219 -0
- package/templates/browser-agent/src/mainview/components/chat/CommandBar.tsx +184 -0
- package/templates/browser-agent/src/mainview/components/chat/MessageBubble.tsx +249 -0
- package/templates/browser-agent/src/mainview/components/chat/ToolPicker.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/browser-agent/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/browser-agent/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/browser-agent/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/browser-agent/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/browser-agent/src/mainview/components/layout/AppLayout.tsx +311 -0
- package/templates/browser-agent/src/mainview/components/onboarding/SetupWizard.tsx +310 -0
- package/templates/browser-agent/src/mainview/components/process/ProcessPanel.tsx +329 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SessionSidebar.tsx +122 -0
- package/templates/browser-agent/src/mainview/components/sidebar/SkillSidebar.tsx +115 -0
- package/templates/browser-agent/src/mainview/components/topbar/TopBar.tsx +350 -0
- package/templates/browser-agent/src/mainview/global.d.ts +13 -0
- package/templates/browser-agent/src/mainview/hooks/__tests__/use-breakpoint.test.ts +151 -0
- package/templates/browser-agent/src/mainview/hooks/use-agent-chat.ts +157 -0
- package/templates/browser-agent/src/mainview/hooks/use-breakpoint.ts +68 -0
- package/templates/browser-agent/src/mainview/hooks/use-rpc-init.ts +71 -0
- package/templates/browser-agent/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/browser-agent/src/mainview/index.css +71 -0
- package/templates/browser-agent/src/mainview/index.html +12 -0
- package/templates/browser-agent/src/mainview/lib/api-client.ts +397 -0
- package/templates/browser-agent/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/browser-agent/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/browser-agent/src/mainview/lib/network-bus.ts +92 -0
- package/templates/browser-agent/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/browser-agent/src/mainview/main.tsx +18 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/browser-agent/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/browser-agent/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/browser-agent/src/mainview/stores/use-asset-store.ts +65 -0
- package/templates/browser-agent/src/mainview/stores/use-chat-store.ts +200 -0
- package/templates/browser-agent/src/mainview/stores/use-connection-store.ts +173 -0
- package/templates/browser-agent/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/browser-agent/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/browser-agent/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/browser-agent/src/mainview/stores/use-record-store.ts +147 -0
- package/templates/browser-agent/src/mainview/stores/use-session-store.ts +151 -0
- package/templates/browser-agent/src/mainview/stores/use-sidebar-store.ts +161 -0
- package/templates/browser-agent/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/browser-agent/src/mainview/stores/use-view-store.ts +20 -0
- package/templates/browser-agent/src/mainview/types/index.ts +6 -0
- package/templates/browser-agent/src/server-config.ts +45 -0
- package/templates/browser-agent/src/server.ts +78 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/browser-agent/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/browser-agent/src/shared/handlers/browser.ts +596 -0
- package/templates/browser-agent/src/shared/handlers/chat.ts +213 -0
- package/templates/browser-agent/src/shared/handlers/file.ts +99 -0
- package/templates/browser-agent/src/shared/handlers/index.ts +7 -0
- package/templates/browser-agent/src/shared/handlers/session.ts +167 -0
- package/templates/browser-agent/src/shared/handlers/system.ts +27 -0
- package/templates/browser-agent/src/shared/handlers/timer.ts +34 -0
- package/templates/browser-agent/src/shared/http-routes.ts +437 -0
- package/templates/browser-agent/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/browser-agent/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/browser-agent/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/browser-agent/src/shared/lib/agent.ts +384 -0
- package/templates/browser-agent/src/shared/lib/cdp.ts +448 -0
- package/templates/browser-agent/src/shared/lib/generate.ts +111 -0
- package/templates/browser-agent/src/shared/lib/logger.ts +152 -0
- package/templates/browser-agent/src/shared/lib/mock-stream.ts +147 -0
- package/templates/browser-agent/src/shared/lib/path-security.ts +38 -0
- package/templates/browser-agent/src/shared/lib/port-registry.ts +103 -0
- package/templates/browser-agent/src/shared/lib/web-server.ts +127 -0
- package/templates/browser-agent/src/shared/lib/xhs-extract.ts +71 -0
- package/templates/browser-agent/src/shared/modules/browser.ts +86 -0
- package/templates/browser-agent/src/shared/modules/chat.ts +20 -0
- package/templates/browser-agent/src/shared/modules/file.ts +40 -0
- package/templates/browser-agent/src/shared/modules/session.ts +55 -0
- package/templates/browser-agent/src/shared/modules/system.ts +8 -0
- package/templates/browser-agent/src/shared/modules/timer.ts +11 -0
- package/templates/browser-agent/src/shared/register-all-handlers.ts +36 -0
- package/templates/browser-agent/src/shared/rpc-schema.ts +34 -0
- package/templates/browser-agent/tailwind.config.js +15 -0
- package/templates/browser-agent/tsconfig.ipc.json +14 -0
- package/templates/browser-agent/tsconfig.json +36 -0
- package/templates/browser-agent/vite.config.ts +3 -0
- package/templates/browser-agent/vitest.config.ts +3 -0
- package/templates/chat/.husky/commit-msg +4 -0
- package/templates/chat/.husky/pre-commit +11 -0
- package/templates/chat/.husky/pre-push +6 -0
- package/templates/chat/CHANGELOG.md +15 -0
- package/templates/chat/commitlint.config.js +8 -0
- package/templates/chat/package.json +19 -4
- package/templates/chat/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/chat/src/mainview/__tests__/setup.ts +32 -29
- package/templates/chat/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/chat/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/chat/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/chat/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/chat/src/shared/handlers/chat.ts +17 -19
- package/templates/chat/src/shared/handlers/debug.ts +12 -2
- package/templates/cowork/.env.example +8 -0
- package/templates/cowork/.prettierignore +6 -0
- package/templates/cowork/.prettierrc +9 -0
- package/templates/cowork/AGENTS.md +236 -0
- package/templates/cowork/CHANGELOG.md +15 -0
- package/templates/cowork/LICENSE +21 -0
- package/templates/cowork/README.md +103 -0
- package/templates/cowork/commitlint.config.js +8 -0
- package/templates/cowork/docs/CODE-VIEW-PLAN.md +637 -0
- package/templates/cowork/docs/CODE-VIEW-V2.md +196 -0
- package/templates/cowork/docs/CODE-VIEW-V4.md +150 -0
- package/templates/cowork/electrobun.config.ts +27 -0
- package/templates/cowork/eslint.config.mjs +79 -0
- package/templates/cowork/llms.txt +24 -0
- package/templates/cowork/package.json +87 -0
- package/templates/cowork/postcss.config.js +6 -0
- package/templates/cowork/scripts/dev.ts +138 -0
- package/templates/cowork/src/__tests__/hybrid-mode.test.ts +126 -0
- package/templates/cowork/src/__tests__/server-config-security.test.ts +55 -0
- package/templates/cowork/src/__tests__/server-config.test.ts +59 -0
- package/templates/cowork/src/bun/index.ts +130 -0
- package/templates/cowork/src/bun/three.d.ts +1 -0
- package/templates/cowork/src/gateway/http-routes.ts +1 -0
- package/templates/cowork/src/gateway/ipc-transport.ts +68 -0
- package/templates/cowork/src/gateway/sse-transport.ts +231 -0
- package/templates/cowork/src/mainview/App.tsx +45 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-rpc-init.test.ts +202 -0
- package/templates/cowork/src/mainview/__tests__/hooks/use-sidebar-resize.test.ts +127 -0
- package/templates/cowork/src/mainview/__tests__/i18n/i18n.test.ts +49 -0
- package/templates/cowork/src/mainview/__tests__/setup.ts +40 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-chat-store.test.ts +73 -0
- package/templates/cowork/src/mainview/__tests__/stores/use-sidebar-store.test.ts +61 -0
- package/templates/cowork/src/mainview/__tests__/theme-variables.test.ts +36 -0
- package/templates/cowork/src/mainview/components/chat/TaskChat.tsx +311 -0
- package/templates/cowork/src/mainview/components/chat/__tests__/localhost-links.test.ts +76 -0
- package/templates/cowork/src/mainview/components/common/ErrorBoundary.tsx +1 -0
- package/templates/cowork/src/mainview/components/common/LanguageSwitcher.tsx +15 -0
- package/templates/cowork/src/mainview/components/common/ThemeToggle.tsx +45 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ErrorBoundary.test.tsx +74 -0
- package/templates/cowork/src/mainview/components/common/__tests__/LanguageSwitcher.test.tsx +44 -0
- package/templates/cowork/src/mainview/components/common/__tests__/ThemeToggle.test.tsx +41 -0
- package/templates/cowork/src/mainview/components/dev/NetworkPanel.tsx +155 -0
- package/templates/cowork/src/mainview/components/layout/AppLayout.tsx +216 -0
- package/templates/cowork/src/mainview/components/right/ArtifactsPanel.tsx +54 -0
- package/templates/cowork/src/mainview/components/right/ContextPanel.tsx +133 -0
- package/templates/cowork/src/mainview/components/right/ElementPicker.tsx +206 -0
- package/templates/cowork/src/mainview/components/right/PreviewBlock.tsx +155 -0
- package/templates/cowork/src/mainview/components/right/ProgressPanel.tsx +85 -0
- package/templates/cowork/src/mainview/components/sidebar/TaskSidebar.tsx +211 -0
- package/templates/cowork/src/mainview/components/topbar/TopBar.tsx +86 -0
- package/templates/cowork/src/mainview/global.d.ts +13 -0
- package/templates/cowork/src/mainview/hooks/__tests__/use-breakpoint.test.ts +123 -0
- package/templates/cowork/src/mainview/hooks/use-breakpoint.ts +53 -0
- package/templates/cowork/src/mainview/hooks/use-rpc-init.ts +26 -0
- package/templates/cowork/src/mainview/hooks/use-sidebar-resize.ts +40 -0
- package/templates/cowork/src/mainview/index.css +89 -0
- package/templates/cowork/src/mainview/index.html +12 -0
- package/templates/cowork/src/mainview/lib/api-client.ts +404 -0
- package/templates/cowork/src/mainview/lib/i18n/index.ts +30 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/en.json +130 -0
- package/templates/cowork/src/mainview/lib/i18n/locales/zh.json +128 -0
- package/templates/cowork/src/mainview/lib/network-bus.ts +92 -0
- package/templates/cowork/src/mainview/lib/rpc-cache.ts +94 -0
- package/templates/cowork/src/mainview/main.tsx +18 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-connection-store.test.ts +26 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-locale-store.test.ts +32 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-log-store.test.ts +28 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-preview-store.test.ts +193 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-sidebar-store.test.ts +81 -0
- package/templates/cowork/src/mainview/stores/__tests__/use-theme-store.test.ts +59 -0
- package/templates/cowork/src/mainview/stores/message-batcher.ts +25 -0
- package/templates/cowork/src/mainview/stores/use-chat-store.ts +198 -0
- package/templates/cowork/src/mainview/stores/use-connection-store.ts +168 -0
- package/templates/cowork/src/mainview/stores/use-context-store.ts +68 -0
- package/templates/cowork/src/mainview/stores/use-locale-store.ts +27 -0
- package/templates/cowork/src/mainview/stores/use-log-store.ts +16 -0
- package/templates/cowork/src/mainview/stores/use-network-panel-store.ts +18 -0
- package/templates/cowork/src/mainview/stores/use-output-store.ts +47 -0
- package/templates/cowork/src/mainview/stores/use-preview-store.ts +97 -0
- package/templates/cowork/src/mainview/stores/use-sidebar-store.ts +272 -0
- package/templates/cowork/src/mainview/stores/use-task-store.ts +86 -0
- package/templates/cowork/src/mainview/stores/use-theme-store.ts +46 -0
- package/templates/cowork/src/mainview/stores/use-view-store.ts +29 -0
- package/templates/cowork/src/mainview/types/index.ts +6 -0
- package/templates/cowork/src/server-config.ts +44 -0
- package/templates/cowork/src/server.ts +78 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-concurrency.test.ts +127 -0
- package/templates/cowork/src/shared/handlers/__tests__/chat-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/__tests__/file-handler.test.ts +100 -0
- package/templates/cowork/src/shared/handlers/__tests__/preview-handler.test.ts +172 -0
- package/templates/cowork/src/shared/handlers/__tests__/system-handler.test.ts +55 -0
- package/templates/cowork/src/shared/handlers/__tests__/timer-handler.test.ts +77 -0
- package/templates/cowork/src/shared/handlers/chat.ts +213 -0
- package/templates/cowork/src/shared/handlers/context.ts +72 -0
- package/templates/cowork/src/shared/handlers/file.ts +99 -0
- package/templates/cowork/src/shared/handlers/index.ts +9 -0
- package/templates/cowork/src/shared/handlers/output.ts +59 -0
- package/templates/cowork/src/shared/handlers/preview.ts +81 -0
- package/templates/cowork/src/shared/handlers/system.ts +27 -0
- package/templates/cowork/src/shared/handlers/task.ts +101 -0
- package/templates/cowork/src/shared/handlers/timer.ts +34 -0
- package/templates/cowork/src/shared/http-routes.ts +444 -0
- package/templates/cowork/src/shared/lib/__tests__/logger.test.ts +92 -0
- package/templates/cowork/src/shared/lib/__tests__/path-security.test.ts +77 -0
- package/templates/cowork/src/shared/lib/__tests__/web-server.test.ts +203 -0
- package/templates/cowork/src/shared/lib/logger.ts +152 -0
- package/templates/cowork/src/shared/lib/path-security.ts +38 -0
- package/templates/cowork/src/shared/lib/port-registry.ts +103 -0
- package/templates/cowork/src/shared/lib/web-server.ts +127 -0
- package/templates/cowork/src/shared/modules/chat.ts +20 -0
- package/templates/cowork/src/shared/modules/context.ts +32 -0
- package/templates/cowork/src/shared/modules/file.ts +40 -0
- package/templates/cowork/src/shared/modules/output.ts +20 -0
- package/templates/cowork/src/shared/modules/preview.ts +44 -0
- package/templates/cowork/src/shared/modules/system.ts +8 -0
- package/templates/cowork/src/shared/modules/task.ts +31 -0
- package/templates/cowork/src/shared/modules/timer.ts +11 -0
- package/templates/cowork/src/shared/register-all-handlers.ts +36 -0
- package/templates/cowork/src/shared/rpc-schema.ts +38 -0
- package/templates/cowork/tailwind.config.js +15 -0
- package/templates/cowork/test-upload.txt +0 -0
- package/templates/cowork/tsconfig.ipc.json +14 -0
- package/templates/cowork/tsconfig.json +36 -0
- package/templates/cowork/vite.config.ts +3 -0
- package/templates/cowork/vitest.config.ts +3 -0
- package/templates/general/.husky/commit-msg +4 -0
- package/templates/general/.husky/pre-commit +11 -0
- package/templates/general/.husky/pre-push +6 -0
- package/templates/general/CHANGELOG.md +15 -0
- package/templates/general/commitlint.config.js +8 -0
- package/templates/general/package.json +19 -4
- package/templates/general/src/mainview/__tests__/hooks/use-input-history.test.ts +125 -0
- package/templates/general/src/mainview/__tests__/setup.ts +32 -29
- package/templates/general/src/mainview/components/chat/ChatPanel.tsx +80 -55
- package/templates/general/src/mainview/components/common/ThemeToggle.tsx +40 -20
- package/templates/general/src/mainview/components/debug/DebugPanel.tsx +170 -156
- package/templates/general/src/mainview/components/debug/__tests__/DebugPanel.test.tsx +169 -0
- package/templates/general/src/mainview/components/explorer/ConfirmDialog.tsx +42 -42
- package/templates/general/src/mainview/components/explorer/ContextMenu.tsx +72 -67
- package/templates/general/src/mainview/components/feed/FeedPanel.tsx +7 -5
- package/templates/general/src/mainview/components/file-preview/FilePreviewOverlay.tsx +64 -45
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +24 -7
- package/templates/general/src/mainview/components/git/GitPanel.tsx +700 -473
- package/templates/general/src/mainview/components/layout/AppLayout.tsx +123 -114
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +15 -19
- package/templates/general/src/mainview/lib/i18n/locales/en.json +175 -155
- package/templates/general/src/mainview/lib/i18n/locales/zh.json +173 -155
- package/templates/general/src/mainview/stores/__tests__/use-explorer-store.test.ts +259 -0
- package/templates/general/src/mainview/stores/__tests__/use-feed-store.test.ts +160 -0
- package/templates/general/src/mainview/stores/__tests__/use-git-store.test.ts +313 -0
- package/templates/general/src/mainview/stores/__tests__/use-notification-store.test.ts +115 -0
- package/templates/general/src/mainview/stores/__tests__/use-sidebar-store.test.ts +120 -0
- package/templates/general/src/mainview/stores/use-explorer-store.ts +277 -260
- package/templates/general/src/mainview/types/index.ts +21 -20
- package/templates/general/src/shared/handlers/chat.ts +1 -1
- package/templates/general/src/shared/handlers/debug.ts +12 -2
- package/templates/shared/components/ErrorBoundary.tsx +0 -1
- package/templates/shared/vite-base.config.ts +8 -7
- /package/templates/{shared → browser-agent}/test-upload.txt +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import type { ContextFolder, Connector, WorkingFile } from "../modules/context";
|
|
5
|
+
|
|
6
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
7
|
+
method: K,
|
|
8
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
9
|
+
) => void;
|
|
10
|
+
|
|
11
|
+
// 内存存储
|
|
12
|
+
const folders: ContextFolder[] = [
|
|
13
|
+
{ path: "/Users/simon/blog-drafts", name: "blog-drafts" },
|
|
14
|
+
];
|
|
15
|
+
const connectors: Connector[] = [
|
|
16
|
+
{ id: "web-search", name: "Web search", type: "web_search", enabled: true },
|
|
17
|
+
{ id: "github-api", name: "GitHub API", type: "api", enabled: false },
|
|
18
|
+
];
|
|
19
|
+
const workingFiles: WorkingFile[] = [
|
|
20
|
+
{ path: "/Users/simon/blog-drafts/llm-digest-october-2025.md", name: "llm-digest-october-2025.md", size: 12400 },
|
|
21
|
+
{ path: "/Users/simon/blog-drafts/tests-not-optional-coding-agents.md", name: "tests-not-optional-coding-agen...", size: 8200 },
|
|
22
|
+
{ path: "/Users/simon/blog-drafts/digest-november-2025.md", name: "digest-november-2025.md", size: 15600 },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
26
|
+
const r: RegisterFn = (method, handler) => {
|
|
27
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
r("context.listFolders", async () => ({ folders: [...folders] }));
|
|
31
|
+
|
|
32
|
+
r("context.addFolder", async (params) => {
|
|
33
|
+
const folder: ContextFolder = {
|
|
34
|
+
path: params.path,
|
|
35
|
+
name: params.path.split("/").pop() ?? params.path,
|
|
36
|
+
};
|
|
37
|
+
folders.push(folder);
|
|
38
|
+
return { folder };
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
r("context.removeFolder", async (params) => {
|
|
42
|
+
const idx = folders.findIndex((f) => f.path === params.path);
|
|
43
|
+
if (idx >= 0) folders.splice(idx, 1);
|
|
44
|
+
return { ok: true };
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
r("context.listConnectors", async () => ({ connectors: [...connectors] }));
|
|
48
|
+
|
|
49
|
+
r("context.toggleConnector", async (params) => {
|
|
50
|
+
const conn = connectors.find((c) => c.id === params.id);
|
|
51
|
+
if (!conn) throw new Error(`Connector not found: ${params.id}`);
|
|
52
|
+
conn.enabled = params.enabled;
|
|
53
|
+
return { connector: conn };
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
r("context.listWorkingFiles", async () => ({ files: [...workingFiles] }));
|
|
57
|
+
|
|
58
|
+
r("context.addWorkingFile", async (params) => {
|
|
59
|
+
const file: WorkingFile = {
|
|
60
|
+
path: params.path,
|
|
61
|
+
name: params.path.split("/").pop() ?? params.path,
|
|
62
|
+
};
|
|
63
|
+
workingFiles.push(file);
|
|
64
|
+
return { file };
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
r("context.removeWorkingFile", async (params) => {
|
|
68
|
+
const idx = workingFiles.findIndex((f) => f.path === params.path);
|
|
69
|
+
if (idx >= 0) workingFiles.splice(idx, 1);
|
|
70
|
+
return { ok: true };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import { readdir, stat, writeFile, readFile, mkdir, rename, rm, cp } from "fs/promises";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { join, dirname } from "path";
|
|
7
|
+
import { createLogger } from "../lib/logger";
|
|
8
|
+
import { validatePath } from "../lib/path-security";
|
|
9
|
+
|
|
10
|
+
const log = createLogger("file");
|
|
11
|
+
|
|
12
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
13
|
+
method: K,
|
|
14
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
15
|
+
) => void;
|
|
16
|
+
|
|
17
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
18
|
+
const r: RegisterFn = (method, handler) => {
|
|
19
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
r("file.findProjectRoot", async () => {
|
|
23
|
+
let dir = process.cwd();
|
|
24
|
+
for (let i = 0; i < 20; i++) {
|
|
25
|
+
if (existsSync(join(dir, "package.json"))) return { path: dir };
|
|
26
|
+
const parent = dirname(dir);
|
|
27
|
+
if (parent === dir) break;
|
|
28
|
+
dir = parent;
|
|
29
|
+
}
|
|
30
|
+
return { path: process.cwd() };
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
r("file.listDir", async (params) => {
|
|
34
|
+
const basePath = validatePath(params.path || process.cwd());
|
|
35
|
+
const entries: { name: string; path: string; type: "file" | "directory"; size?: number }[] = [];
|
|
36
|
+
try {
|
|
37
|
+
const files = await readdir(basePath);
|
|
38
|
+
for (const name of files) {
|
|
39
|
+
const fullPath = join(basePath, name);
|
|
40
|
+
try {
|
|
41
|
+
const s = await stat(fullPath);
|
|
42
|
+
entries.push({
|
|
43
|
+
name,
|
|
44
|
+
path: fullPath,
|
|
45
|
+
type: s.isDirectory() ? "directory" : "file",
|
|
46
|
+
size: s.size,
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
entries.push({ name, path: fullPath, type: "file" });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
log.error("listDir error", { error: err });
|
|
54
|
+
}
|
|
55
|
+
return { entries, basePath };
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
r("file.createFile", async (params) => {
|
|
59
|
+
const dirPath = validatePath(params.dirPath);
|
|
60
|
+
const filePath = join(dirPath, params.name);
|
|
61
|
+
await writeFile(filePath, "");
|
|
62
|
+
return { path: filePath };
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
r("file.createDir", async (params) => {
|
|
66
|
+
const dirPath = validatePath(params.dirPath);
|
|
67
|
+
const fullDirPath = join(dirPath, params.name);
|
|
68
|
+
await mkdir(fullDirPath, { recursive: true });
|
|
69
|
+
return { path: fullDirPath };
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
r("file.rename", async (params) => {
|
|
73
|
+
const oldPath = validatePath(params.oldPath);
|
|
74
|
+
const newPath = join(dirname(oldPath), params.newName);
|
|
75
|
+
await rename(oldPath, newPath);
|
|
76
|
+
return { newPath };
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
r("file.delete", async (params) => {
|
|
80
|
+
const safePath = validatePath(params.path);
|
|
81
|
+
await rm(safePath, { recursive: true, force: true });
|
|
82
|
+
return { ok: true };
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
r("file.copy", async (params) => {
|
|
86
|
+
const srcPath = validatePath(params.srcPath);
|
|
87
|
+
const destDir = validatePath(params.destDir);
|
|
88
|
+
const name = srcPath.split("/").pop() || srcPath;
|
|
89
|
+
const destPath = join(destDir, name);
|
|
90
|
+
await cp(srcPath, destPath, { recursive: true });
|
|
91
|
+
return { path: destPath };
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
r("file.readFile", async (params) => {
|
|
95
|
+
const filePath = validatePath(params.path);
|
|
96
|
+
const content = await readFile(filePath);
|
|
97
|
+
return { content: content.toString(), size: content.length };
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Handler barrel — 新增模块在此加一行 export
|
|
2
|
+
export { register as system } from './system';
|
|
3
|
+
export { register as file } from './file';
|
|
4
|
+
export { register as timer } from './timer';
|
|
5
|
+
export { register as chat } from './chat';
|
|
6
|
+
export { register as task } from './task';
|
|
7
|
+
export { register as context } from './context';
|
|
8
|
+
export { register as output } from './output';
|
|
9
|
+
export { register as preview } from './preview';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import type { Output } from "../modules/output";
|
|
5
|
+
|
|
6
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
7
|
+
method: K,
|
|
8
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
9
|
+
) => void;
|
|
10
|
+
|
|
11
|
+
// 内存存储
|
|
12
|
+
let outputIdCounter = 0;
|
|
13
|
+
const outputs: Map<string, Output> = new Map();
|
|
14
|
+
|
|
15
|
+
// ── Mock 预填充数据 ──
|
|
16
|
+
const mockOutputs: Output[] = [
|
|
17
|
+
{
|
|
18
|
+
id: "output-1",
|
|
19
|
+
name: "publish-encouragement.html",
|
|
20
|
+
kind: "file",
|
|
21
|
+
path: "/Users/simon/blog-drafts/publish-encouragement.html",
|
|
22
|
+
size: 3200,
|
|
23
|
+
taskId: "task-1",
|
|
24
|
+
createdAt: Date.now() - 1800000,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
for (const o of mockOutputs) {
|
|
28
|
+
outputs.set(o.id, o);
|
|
29
|
+
outputIdCounter = Math.max(outputIdCounter, parseInt(o.id.replace("output-", ""), 10));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
33
|
+
const r: RegisterFn = (method, handler) => {
|
|
34
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
r("output.list", async () => ({
|
|
38
|
+
outputs: [...outputs.values()].sort((a, b) => b.createdAt - a.createdAt),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
r("output.add", async (params) => {
|
|
42
|
+
const output: Output = {
|
|
43
|
+
id: `output-${++outputIdCounter}`,
|
|
44
|
+
name: params.name,
|
|
45
|
+
kind: params.kind,
|
|
46
|
+
path: params.path,
|
|
47
|
+
content: params.content,
|
|
48
|
+
taskId: params.taskId,
|
|
49
|
+
createdAt: Date.now(),
|
|
50
|
+
};
|
|
51
|
+
outputs.set(output.id, output);
|
|
52
|
+
return { output };
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
r("output.remove", async (params) => {
|
|
56
|
+
outputs.delete(params.id);
|
|
57
|
+
return { ok: true };
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { RPCServer } from '@dyyz1993/rpc-core';
|
|
2
|
+
import type { MethodParams, MethodResult } from '@dyyz1993/rpc-core';
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from '../rpc-schema';
|
|
4
|
+
import type { PreviewTab } from '../modules/preview';
|
|
5
|
+
|
|
6
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
7
|
+
method: K,
|
|
8
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
9
|
+
) => void;
|
|
10
|
+
|
|
11
|
+
// 内存存储
|
|
12
|
+
const tabs = new Map<string, PreviewTab>();
|
|
13
|
+
const history: string[] = [];
|
|
14
|
+
const MAX_HISTORY = 20;
|
|
15
|
+
|
|
16
|
+
export function register(server: RPCServer, options: HandlerOptions): void {
|
|
17
|
+
const isDesktop = options.platform === 'desktop';
|
|
18
|
+
const r: RegisterFn = (method, handler) => {
|
|
19
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
r('preview.open', async (params) => {
|
|
23
|
+
let tabId =
|
|
24
|
+
params.tabId ??
|
|
25
|
+
`preview-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
26
|
+
// Ensure unique tabId
|
|
27
|
+
while (tabs.has(tabId)) {
|
|
28
|
+
tabId = `preview-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const tab: PreviewTab = {
|
|
32
|
+
id: tabId,
|
|
33
|
+
url: params.url,
|
|
34
|
+
title: params.url,
|
|
35
|
+
state: 'loading',
|
|
36
|
+
canGoBack: false,
|
|
37
|
+
canGoForward: false,
|
|
38
|
+
};
|
|
39
|
+
tabs.set(tabId, tab);
|
|
40
|
+
|
|
41
|
+
// 记录历史(去重,保持最新 20 条)
|
|
42
|
+
if (!history.includes(params.url)) {
|
|
43
|
+
history.unshift(params.url);
|
|
44
|
+
if (history.length > MAX_HISTORY) history.pop();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 模拟加载过程(MVP 阶段先用 iframe 兜底)
|
|
48
|
+
tab.state = 'ready';
|
|
49
|
+
server.emitEvent('preview.navState', tab);
|
|
50
|
+
return { tab, useIframe: !isDesktop };
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
r('preview.navigate', async (params) => {
|
|
54
|
+
const tab = tabs.get(params.tabId);
|
|
55
|
+
if (!tab) throw new Error(`Tab not found: ${params.tabId}`);
|
|
56
|
+
|
|
57
|
+
tab.state = 'loading';
|
|
58
|
+
server.emitEvent('preview.navState', tab);
|
|
59
|
+
|
|
60
|
+
// 模拟导航完成
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
tab.state = 'ready';
|
|
63
|
+
server.emitEvent('preview.navState', tab);
|
|
64
|
+
}, 300);
|
|
65
|
+
|
|
66
|
+
return { ok: true };
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
r('preview.close', async (params) => {
|
|
70
|
+
tabs.delete(params.tabId);
|
|
71
|
+
return { ok: true };
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
r('preview.list', async () => ({
|
|
75
|
+
tabs: [...tabs.values()],
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
r('preview.history', async () => ({
|
|
79
|
+
urls: [...history],
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
|
|
5
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
6
|
+
method: K,
|
|
7
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
8
|
+
) => void;
|
|
9
|
+
|
|
10
|
+
export function register(server: RPCServer, options: HandlerOptions): void {
|
|
11
|
+
const r: RegisterFn = (method, handler) => {
|
|
12
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
r("system.ping", async () => ({
|
|
16
|
+
pong: true,
|
|
17
|
+
timestamp: Date.now(),
|
|
18
|
+
platform: options.platform,
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
r("system.hello", async (params) => ({
|
|
22
|
+
message: `Hello ${params.name || "World"}!`,
|
|
23
|
+
timestamp: Date.now(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
r("system.echo", async (params) => params);
|
|
27
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
import type { Task } from "../modules/task";
|
|
5
|
+
|
|
6
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
7
|
+
method: K,
|
|
8
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
9
|
+
) => void;
|
|
10
|
+
|
|
11
|
+
// 内存存储
|
|
12
|
+
let taskIdCounter = 0;
|
|
13
|
+
const tasks: Map<string, Task> = new Map();
|
|
14
|
+
|
|
15
|
+
// ── Mock 预填充数据 ──
|
|
16
|
+
function initMockData(): void {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
const mockTasks: Task[] = [
|
|
19
|
+
{
|
|
20
|
+
id: "task-1",
|
|
21
|
+
title: "Review unpublished drafts for publication",
|
|
22
|
+
status: "executing",
|
|
23
|
+
progress: {
|
|
24
|
+
steps: [
|
|
25
|
+
{ label: "Scan blog-drafts folder", status: "done", detail: "Found 46 draft files" },
|
|
26
|
+
{ label: "Check publication status", status: "done", detail: "Cross-referenced with simonwillison.net" },
|
|
27
|
+
{ label: "Analyze readiness", status: "running", detail: "Reading content of each draft..." },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
createdAt: now - 3600000,
|
|
31
|
+
updatedAt: now - 1800000,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "task-2",
|
|
35
|
+
title: "Summarize latest AI research papers",
|
|
36
|
+
status: "completed",
|
|
37
|
+
progress: {
|
|
38
|
+
steps: [
|
|
39
|
+
{ label: "Search arxiv for recent papers", status: "done", detail: "Found 12 relevant papers" },
|
|
40
|
+
{ label: "Read and summarize", status: "done", detail: "Generated summaries for all papers" },
|
|
41
|
+
{ label: "Compile into digest", status: "done", detail: "Created llm-digest-october-2025.md" },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
createdAt: now - 86400000,
|
|
45
|
+
updatedAt: now - 72000000,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "task-3",
|
|
49
|
+
title: "Generate monthly newsletter",
|
|
50
|
+
status: "queued",
|
|
51
|
+
createdAt: now - 7200000,
|
|
52
|
+
updatedAt: now - 7200000,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
for (const t of mockTasks) {
|
|
56
|
+
tasks.set(t.id, t);
|
|
57
|
+
taskIdCounter = Math.max(taskIdCounter, parseInt(t.id.replace("task-", ""), 10));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 首次加载时填充 mock 数据
|
|
62
|
+
initMockData();
|
|
63
|
+
|
|
64
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
65
|
+
const r: RegisterFn = (method, handler) => {
|
|
66
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
r("task.list", async () => ({
|
|
70
|
+
tasks: [...tasks.values()].sort((a, b) => b.updatedAt - a.updatedAt),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
r("task.create", async (params) => {
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
const task: Task = {
|
|
76
|
+
id: `task-${++taskIdCounter}`,
|
|
77
|
+
title: params.title,
|
|
78
|
+
status: "queued",
|
|
79
|
+
createdAt: now,
|
|
80
|
+
updatedAt: now,
|
|
81
|
+
};
|
|
82
|
+
tasks.set(task.id, task);
|
|
83
|
+
return { task };
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
r("task.get", async (params) => ({
|
|
87
|
+
task: tasks.get(params.id) ?? null,
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
r("task.update", async (params) => {
|
|
91
|
+
const task = tasks.get(params.id);
|
|
92
|
+
if (!task) throw new Error(`Task not found: ${params.id}`);
|
|
93
|
+
Object.assign(task, params.patch, { updatedAt: Date.now() });
|
|
94
|
+
return { task };
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
r("task.delete", async (params) => {
|
|
98
|
+
tasks.delete(params.id);
|
|
99
|
+
return { ok: true };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
2
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
3
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
4
|
+
|
|
5
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
6
|
+
method: K,
|
|
7
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
8
|
+
) => void;
|
|
9
|
+
|
|
10
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
11
|
+
const r: RegisterFn = (method, handler) => {
|
|
12
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let timerId: ReturnType<typeof setInterval> | null = null;
|
|
16
|
+
|
|
17
|
+
r("timer.start", async () => {
|
|
18
|
+
if (timerId !== null) return { alreadyRunning: true };
|
|
19
|
+
let count = 0;
|
|
20
|
+
timerId = setInterval(() => {
|
|
21
|
+
count++;
|
|
22
|
+
server.emitEvent("timer.tick", { count, timestamp: Date.now() }, { channel: "default" });
|
|
23
|
+
}, 1000);
|
|
24
|
+
return { started: true };
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
r("timer.stop", async () => {
|
|
28
|
+
if (timerId !== null) {
|
|
29
|
+
clearInterval(timerId);
|
|
30
|
+
timerId = null;
|
|
31
|
+
}
|
|
32
|
+
return { stopped: true };
|
|
33
|
+
});
|
|
34
|
+
}
|