@dyyz1993/create-agent 2.1.1 → 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 +127 -91
- 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/CHANGELOG.md +15 -0
- package/templates/agent/package.json +3 -3
- 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,213 @@
|
|
|
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 { readFile, writeFile, mkdir } from 'fs/promises';
|
|
5
|
+
import { existsSync } from 'fs';
|
|
6
|
+
import { join, dirname } from 'path';
|
|
7
|
+
import { homedir } from 'os';
|
|
8
|
+
import { createLogger } from '../lib/logger';
|
|
9
|
+
|
|
10
|
+
const log = createLogger('chat');
|
|
11
|
+
|
|
12
|
+
type Platform = 'desktop' | 'web';
|
|
13
|
+
|
|
14
|
+
export function getStoragePathFor(platform: Platform): string {
|
|
15
|
+
const dir = join(homedir(), '.pi-agent');
|
|
16
|
+
if (platform === 'desktop') {
|
|
17
|
+
return join(dir, 'chat-history-desktop.json');
|
|
18
|
+
}
|
|
19
|
+
const sessionId = Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8);
|
|
20
|
+
return join(dir, `chat-history-web-${sessionId}.json`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type ChatMessage = { id: string; role: 'user' | 'assistant'; content: string; timestamp: number };
|
|
24
|
+
|
|
25
|
+
function createMessageStore(filePath: string) {
|
|
26
|
+
async function load(): Promise<ChatMessage[]> {
|
|
27
|
+
try {
|
|
28
|
+
if (!existsSync(filePath)) {
|
|
29
|
+
log.info(`No history file at ${filePath}`);
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const raw = await readFile(filePath, 'utf-8');
|
|
33
|
+
const msgs = JSON.parse(raw) as ChatMessage[];
|
|
34
|
+
log.info(`Loaded ${msgs.length} messages from ${filePath}`);
|
|
35
|
+
return msgs;
|
|
36
|
+
} catch (err) {
|
|
37
|
+
log.error('Failed to load history', { error: err });
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function save(messages: ChatMessage[]): Promise<void> {
|
|
43
|
+
const dir = dirname(filePath);
|
|
44
|
+
try {
|
|
45
|
+
if (!existsSync(dir)) {
|
|
46
|
+
await mkdir(dir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
await writeFile(filePath, JSON.stringify(messages, null, 2), 'utf-8');
|
|
49
|
+
log.info(`Saved ${messages.length} messages to ${filePath}`);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
log.error('Failed to save history', { error: err });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { load, save };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
59
|
+
method: K,
|
|
60
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
61
|
+
) => void;
|
|
62
|
+
|
|
63
|
+
export function generateReply(input: string): string {
|
|
64
|
+
const lower = input.toLowerCase().trim();
|
|
65
|
+
|
|
66
|
+
if (/^(hi|hello|hey|howdy|hola|yo|sup)\b/i.test(lower)) {
|
|
67
|
+
const greetings = [
|
|
68
|
+
'Hey there! How can I help you today?',
|
|
69
|
+
'Hello! Great to see you. What would you like to know?',
|
|
70
|
+
"Hi! I'm your desktop assistant. Ask me anything!",
|
|
71
|
+
];
|
|
72
|
+
return greetings[Math.floor(Math.random() * greetings.length)]!;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
/what('?s| is) the (time|date|day)|current (time|date)|what time|today'?s date/i.test(lower)
|
|
77
|
+
) {
|
|
78
|
+
const now = new Date();
|
|
79
|
+
const date = now.toLocaleDateString('en-US', {
|
|
80
|
+
weekday: 'long',
|
|
81
|
+
year: 'numeric',
|
|
82
|
+
month: 'long',
|
|
83
|
+
day: 'numeric',
|
|
84
|
+
});
|
|
85
|
+
const time = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
|
|
86
|
+
return `It's currently **${time}** on **${date}**.`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const mathMatch = lower.match(
|
|
90
|
+
/(?:what(?:'s| is)\s+)?(\d+(?:\.\d+)?)\s*([+\-*/x×÷^])\s*(\d+(?:\.\d+)?)/,
|
|
91
|
+
);
|
|
92
|
+
if (mathMatch) {
|
|
93
|
+
const a = parseFloat(mathMatch[1]!);
|
|
94
|
+
const op = mathMatch[2]!;
|
|
95
|
+
const b = parseFloat(mathMatch[3]!);
|
|
96
|
+
let result: number;
|
|
97
|
+
switch (op) {
|
|
98
|
+
case '+':
|
|
99
|
+
result = a + b;
|
|
100
|
+
break;
|
|
101
|
+
case '-':
|
|
102
|
+
result = a - b;
|
|
103
|
+
break;
|
|
104
|
+
case '*':
|
|
105
|
+
case 'x':
|
|
106
|
+
case '×':
|
|
107
|
+
result = a * b;
|
|
108
|
+
break;
|
|
109
|
+
case '/':
|
|
110
|
+
case '÷':
|
|
111
|
+
result = b !== 0 ? a / b : NaN;
|
|
112
|
+
break;
|
|
113
|
+
case '^':
|
|
114
|
+
result = Math.pow(a, b);
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
result = NaN;
|
|
118
|
+
}
|
|
119
|
+
if (isNaN(result)) {
|
|
120
|
+
return "Hmm, I couldn't calculate that. Did you try dividing by zero?";
|
|
121
|
+
}
|
|
122
|
+
const niceResult = Number.isInteger(result)
|
|
123
|
+
? result.toString()
|
|
124
|
+
: result.toFixed(4).replace(/0+$/, '').replace(/\.$/, '');
|
|
125
|
+
return `That would be **${niceResult}**! Need help with anything else?`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (/file|folder|directory|browse|explorer|open file|read file/i.test(lower)) {
|
|
129
|
+
return (
|
|
130
|
+
'To browse and manage files, use the **File Explorer** panel on the left sidebar. ' +
|
|
131
|
+
'You can navigate directories, preview files, and open them for editing. ' +
|
|
132
|
+
'Try typing a file path or asking me about a specific directory!'
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (/git|commit|branch|push|pull|merge|status|diff|log/i.test(lower)) {
|
|
137
|
+
return (
|
|
138
|
+
'The **Git Panel** gives you full source control right inside the app. ' +
|
|
139
|
+
'You can view changes, stage files, commit, switch branches, push/pull, and see the commit log. ' +
|
|
140
|
+
'Look for the source control icon in the sidebar to get started.'
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (/^(help|commands|what can you|what do you|capabilities|features)/i.test(lower)) {
|
|
145
|
+
return (
|
|
146
|
+
"Here's what I can help with:\n\n" +
|
|
147
|
+
"- **Greetings** - Say hi and I'll say hi back!\n" +
|
|
148
|
+
'- **Time & Date** - Ask "what time is it?" or "what\'s today\'s date?"\n' +
|
|
149
|
+
'- **Math** - Give me an expression like "12 * 8" or "what is 100 / 4"\n' +
|
|
150
|
+
"- **Files** - Ask about file browsing and I'll explain the File Explorer\n" +
|
|
151
|
+
"- **Git** - Ask about version control and I'll walk you through it\n" +
|
|
152
|
+
'- **Help** - Show this message anytime!\n\n' +
|
|
153
|
+
'This is a demo assistant - try different things to see what sticks!'
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const defaults = [
|
|
158
|
+
"That's an interesting question! I'm a demo assistant, so my knowledge is limited - but try asking about **time**, **math**, **files**, or **git**.",
|
|
159
|
+
"I wish I could help with that! For now I can answer questions about time, do simple math, and explain the app's features. Type **help** to see what I can do.",
|
|
160
|
+
"Hmm, I'm not sure about that one. But I *can* do math, tell you the time, and explain features. Give it a shot!",
|
|
161
|
+
];
|
|
162
|
+
return defaults[Math.floor(Math.random() * defaults.length)]!;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function register(server: RPCServer, options: HandlerOptions): void {
|
|
166
|
+
const storagePath = getStoragePathFor(options.platform);
|
|
167
|
+
const store = createMessageStore(storagePath);
|
|
168
|
+
|
|
169
|
+
const r: RegisterFn = (method, handler) => {
|
|
170
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
r('chat.list', async (params) => {
|
|
174
|
+
const all = await store.load();
|
|
175
|
+
const limit = params.limit ?? 50;
|
|
176
|
+
const messages = all.slice(-limit);
|
|
177
|
+
return {
|
|
178
|
+
messages,
|
|
179
|
+
hasMore: all.length > limit,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
r('chat.send', async (params) => {
|
|
184
|
+
const all = await store.load();
|
|
185
|
+
|
|
186
|
+
const userMsg: ChatMessage = {
|
|
187
|
+
id: `msg-${Date.now()}-user`,
|
|
188
|
+
role: 'user',
|
|
189
|
+
content: params.content,
|
|
190
|
+
timestamp: Date.now(),
|
|
191
|
+
};
|
|
192
|
+
all.push(userMsg);
|
|
193
|
+
|
|
194
|
+
server.emitEvent('chat.message', userMsg, { role: userMsg.role });
|
|
195
|
+
|
|
196
|
+
const thinkDelay = 200 + Math.floor(Math.random() * 300);
|
|
197
|
+
await new Promise((r) => setTimeout(r, thinkDelay));
|
|
198
|
+
|
|
199
|
+
const reply: ChatMessage = {
|
|
200
|
+
id: `msg-${Date.now()}-assistant`,
|
|
201
|
+
role: 'assistant',
|
|
202
|
+
content: generateReply(params.content),
|
|
203
|
+
timestamp: Date.now(),
|
|
204
|
+
};
|
|
205
|
+
all.push(reply);
|
|
206
|
+
|
|
207
|
+
server.emitEvent('chat.message', reply, { role: reply.role });
|
|
208
|
+
|
|
209
|
+
await store.save(all);
|
|
210
|
+
|
|
211
|
+
return { ok: true };
|
|
212
|
+
});
|
|
213
|
+
}
|
|
@@ -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,7 @@
|
|
|
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 browser } from "./browser";
|
|
7
|
+
export { register as session } from "./session";
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Handler — 会话 CRUD、消息、资源管理
|
|
3
|
+
*
|
|
4
|
+
* 对应 PRD §8 数据模型
|
|
5
|
+
* 使用内存存储(符合 PRD §10.1 "会话不持久化" 已知问题,预留 SQLite 接口)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { RPCServer } from "@dyyz1993/rpc-core";
|
|
9
|
+
import type { MethodParams, MethodResult } from "@dyyz1993/rpc-core";
|
|
10
|
+
import type { RPCMethods, HandlerOptions } from "../rpc-schema";
|
|
11
|
+
|
|
12
|
+
// ===== 类型定义 =====
|
|
13
|
+
|
|
14
|
+
type SessionStatus = "idle" | "running" | "done" | "error";
|
|
15
|
+
|
|
16
|
+
interface Message {
|
|
17
|
+
id: string;
|
|
18
|
+
role: "user" | "agent";
|
|
19
|
+
text: string;
|
|
20
|
+
steps?: { label: string; status: string; detail?: string }[];
|
|
21
|
+
toolCalls?: { tool: string; input: string; output: string; status: string }[];
|
|
22
|
+
summary?: { noteCount: number; imageCount: number; successRate: string; durationMs: number };
|
|
23
|
+
error?: string;
|
|
24
|
+
at: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Asset {
|
|
28
|
+
id: string;
|
|
29
|
+
kind: string;
|
|
30
|
+
name: string;
|
|
31
|
+
size?: number;
|
|
32
|
+
mime: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
url?: string;
|
|
35
|
+
source: { sessionId: string; taskId: string; createdAt: number };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Session {
|
|
39
|
+
id: string;
|
|
40
|
+
title: string;
|
|
41
|
+
messages: Message[];
|
|
42
|
+
assets: Asset[];
|
|
43
|
+
createdAt: number;
|
|
44
|
+
status: SessionStatus;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ===== 内存存储 =====
|
|
48
|
+
|
|
49
|
+
class SessionStore {
|
|
50
|
+
private sessions = new Map<string, Session>();
|
|
51
|
+
private seq = 0;
|
|
52
|
+
|
|
53
|
+
private genId(prefix: string): string {
|
|
54
|
+
this.seq += 1;
|
|
55
|
+
return `${prefix}_${Date.now().toString(36)}${this.seq.toString(36)}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
create(title?: string): Session {
|
|
59
|
+
const id = this.genId("sess");
|
|
60
|
+
const session: Session = {
|
|
61
|
+
id,
|
|
62
|
+
title: title || "新会话",
|
|
63
|
+
messages: [],
|
|
64
|
+
assets: [],
|
|
65
|
+
createdAt: Date.now(),
|
|
66
|
+
status: "idle",
|
|
67
|
+
};
|
|
68
|
+
this.sessions.set(id, session);
|
|
69
|
+
return session;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get(id: string): Session | undefined {
|
|
73
|
+
return this.sessions.get(id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
list(): Session[] {
|
|
77
|
+
return Array.from(this.sessions.values()).sort((a, b) => b.createdAt - a.createdAt);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
addMessage(sessionId: string, msg: Omit<Message, "id" | "at"> & { id?: string }): Message | null {
|
|
81
|
+
const s = this.sessions.get(sessionId);
|
|
82
|
+
if (!s) return null;
|
|
83
|
+
const full: Message = { ...msg, id: msg.id || this.genId("msg"), at: Date.now() };
|
|
84
|
+
s.messages.push(full);
|
|
85
|
+
return full;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
updateLastAgentMessage(sessionId: string, patch: Partial<Message>): boolean {
|
|
89
|
+
const s = this.sessions.get(sessionId);
|
|
90
|
+
if (!s) return false;
|
|
91
|
+
for (let i = s.messages.length - 1; i >= 0; i--) {
|
|
92
|
+
if (s.messages[i]?.role === "agent") {
|
|
93
|
+
s.messages[i] = { ...s.messages[i]!, ...patch };
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setStatus(sessionId: string, status: SessionStatus): void {
|
|
101
|
+
const s = this.sessions.get(sessionId);
|
|
102
|
+
if (s) s.status = status;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const store = new SessionStore();
|
|
107
|
+
|
|
108
|
+
// ===== Handler 注册 =====
|
|
109
|
+
|
|
110
|
+
type RegisterFn = <K extends keyof RPCMethods & string>(
|
|
111
|
+
method: K,
|
|
112
|
+
handler: (params: MethodParams<RPCMethods, K>) => Promise<MethodResult<RPCMethods, K>>,
|
|
113
|
+
) => void;
|
|
114
|
+
|
|
115
|
+
export function register(server: RPCServer, _options: HandlerOptions): void {
|
|
116
|
+
const r: RegisterFn = (method, handler) => {
|
|
117
|
+
server.register(method, handler as (params: unknown) => Promise<unknown>);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
r("session.create", async (params) => {
|
|
121
|
+
const session = store.create(params.title);
|
|
122
|
+
return { id: session.id, title: session.title, createdAt: session.createdAt };
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
r("session.get", async (params) => {
|
|
126
|
+
const s = store.get(params.id);
|
|
127
|
+
if (!s) return null;
|
|
128
|
+
return { ...s };
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
r("session.list", async () => {
|
|
132
|
+
const sessions = store.list().map((s) => ({
|
|
133
|
+
id: s.id,
|
|
134
|
+
title: s.title,
|
|
135
|
+
createdAt: s.createdAt,
|
|
136
|
+
status: s.status,
|
|
137
|
+
messageCount: s.messages.length,
|
|
138
|
+
assetCount: s.assets.length,
|
|
139
|
+
}));
|
|
140
|
+
return { sessions };
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
r("session.addMessage", async (params) => {
|
|
144
|
+
const msg = store.addMessage(params.sessionId, params.message as any);
|
|
145
|
+
return msg ? { id: msg.id } : null;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
r("session.updateLastMessage", async (params) => {
|
|
149
|
+
const ok = store.updateLastAgentMessage(params.sessionId, params.patch);
|
|
150
|
+
return { ok };
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
r("session.setStatus", async (params) => {
|
|
154
|
+
store.setStatus(params.sessionId, params.status as SessionStatus);
|
|
155
|
+
return { ok: true };
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
r("session.getMessages", async (_params) => {
|
|
159
|
+
// 由 Agent handler 管理,此处返回空
|
|
160
|
+
return { messages: [] };
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
r("session.disposeAgent", async (_params) => {
|
|
164
|
+
// 清理由 browser handler 处理
|
|
165
|
+
return { ok: true };
|
|
166
|
+
});
|
|
167
|
+
}
|
|
@@ -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,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
|
+
}
|