diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b84179ab..fe1fef5a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -90,18 +90,19 @@ jobs: APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }} # 分析服务 APTABASE_APP_KEY: ${{ secrets.APTABASE_APP_KEY }} - run: pnpm build && pnpm exec electron-builder --mac --${{ matrix.arch }} --config electron-builder.yml -p never + working-directory: apps/desktop + run: pnpm run build && pnpm exec electron-builder --mac --${{ matrix.arch }} --config electron-builder.yml -p never - name: Upload macOS artifacts (${{ matrix.arch }}) uses: actions/upload-artifact@v6 with: name: ChatLab-mac-${{ matrix.arch }} path: | - dist/*.dmg - dist/*.zip - dist/*.yml - dist/*.json - dist/*.blockmap + apps/desktop/dist/*.dmg + apps/desktop/dist/*.zip + apps/desktop/dist/*.yml + apps/desktop/dist/*.json + apps/desktop/dist/*.blockmap if-no-files-found: warn retention-days: 1 # 只保留1天,Release后会上传到GitHub Releases @@ -153,17 +154,18 @@ jobs: GH_TOKEN: ${{ secrets.GH_TOKEN }} # 分析服务 APTABASE_APP_KEY: ${{ secrets.APTABASE_APP_KEY }} - run: pnpm build:win + working-directory: apps/desktop + run: pnpm run build && pnpm exec electron-builder --win --config electron-builder.yml -p never - name: Upload Windows artifacts uses: actions/upload-artifact@v6 with: name: ChatLab-win path: | - dist/*.exe - dist/*.yml - dist/*.json - dist/*.blockmap + apps/desktop/dist/*.exe + apps/desktop/dist/*.yml + apps/desktop/dist/*.json + apps/desktop/dist/*.blockmap if-no-files-found: warn retention-days: 1 # 只保留1天,Release后会上传到GitHub Releases @@ -221,11 +223,13 @@ jobs: env: GH_TOKEN: ${{ secrets.GH_TOKEN }} APTABASE_APP_KEY: ${{ secrets.APTABASE_APP_KEY }} + working-directory: apps/desktop run: | + pnpm run build if [ "${{ matrix.arch }}" = "arm64" ]; then - pnpm run build && pnpm exec electron-builder --linux deb --arm64 --config electron-builder.yml -p never + pnpm exec electron-builder --linux deb --arm64 --config electron-builder.yml -p never else - pnpm build:linux + pnpm exec electron-builder --linux --config electron-builder.yml -p never fi - name: Upload Linux artifacts (${{ matrix.arch }}) @@ -233,11 +237,11 @@ jobs: with: name: ChatLab-linux-${{ matrix.arch }} path: | - dist/*.AppImage - dist/*.deb - dist/*.tar.gz - dist/*.yml - dist/*.json + apps/desktop/dist/*.AppImage + apps/desktop/dist/*.deb + apps/desktop/dist/*.tar.gz + apps/desktop/dist/*.yml + apps/desktop/dist/*.json if-no-files-found: warn retention-days: 1 @@ -254,34 +258,34 @@ jobs: uses: actions/download-artifact@v8 with: name: ChatLab-mac-x64 - path: dist + path: release-dist - name: Download macOS artifacts (arm64) uses: actions/download-artifact@v8 with: name: ChatLab-mac-arm64 - path: dist + path: release-dist - name: Download Windows artifacts uses: actions/download-artifact@v8 with: name: ChatLab-win - path: dist + path: release-dist - name: Download Linux artifacts uses: actions/download-artifact@v8 with: name: ChatLab-linux-x64 - path: dist + path: release-dist - name: Download Linux artifacts (arm64) uses: actions/download-artifact@v8 with: name: ChatLab-linux-arm64 - path: dist + path: release-dist - name: List files - run: ls -la dist/ + run: ls -la release-dist/ - name: Generate Release Notes id: release_notes @@ -297,8 +301,8 @@ jobs: echo "Current version: $CURRENT_VERSION" # 从 changelog JSON 中提取最新版本的 summary - EN_SUMMARY=$(jq -r '.[0].summary' docs/public/changelogs/en.json) - CN_SUMMARY=$(jq -r '.[0].summary' docs/public/changelogs/cn.json) + EN_SUMMARY=$(jq -r '.[0].summary' docs/public/changelogs/en.json 2>/dev/null || echo "See changelog for details") + CN_SUMMARY=$(jq -r '.[0].summary' docs/public/changelogs/cn.json 2>/dev/null || echo "详见更新日志") echo "EN summary: $EN_SUMMARY" echo "CN summary: $CN_SUMMARY" @@ -339,14 +343,14 @@ jobs: name: ChatLab ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }} body_path: release_notes.md files: | - dist/*.exe - dist/*.dmg - dist/*.zip - dist/*.AppImage - dist/*.deb - dist/*.tar.gz - dist/*.yml - dist/*.blockmap + release-dist/*.exe + release-dist/*.dmg + release-dist/*.zip + release-dist/*.AppImage + release-dist/*.deb + release-dist/*.tar.gz + release-dist/*.yml + release-dist/*.blockmap env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -380,7 +384,7 @@ jobs: r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} r2-bucket: ${{ secrets.R2_BUCKET_NAME }} - source-dir: dist + source-dir: release-dist destination-dir: releases/download/${{ steps.version.outputs.tag }} # 准备 yml 文件用于根目录上传 @@ -392,7 +396,7 @@ jobs: VERSION_TAG="${{ steps.version.outputs.tag }}" # 处理所有 yml 文件 - for yml_file in dist/*.yml; do + for yml_file in release-dist/*.yml; do filename=$(basename "$yml_file") echo "Processing $filename..." diff --git a/build/entitlements.mac.plist b/apps/desktop/build/entitlements.mac.plist similarity index 100% rename from build/entitlements.mac.plist rename to apps/desktop/build/entitlements.mac.plist diff --git a/build/icon.icns b/apps/desktop/build/icon.icns similarity index 100% rename from build/icon.icns rename to apps/desktop/build/icon.icns diff --git a/build/icon.ico b/apps/desktop/build/icon.ico similarity index 100% rename from build/icon.ico rename to apps/desktop/build/icon.ico diff --git a/build/icon.png b/apps/desktop/build/icon.png similarity index 100% rename from build/icon.png rename to apps/desktop/build/icon.png diff --git a/build/installer-dpi.nsh b/apps/desktop/build/installer-dpi.nsh similarity index 100% rename from build/installer-dpi.nsh rename to apps/desktop/build/installer-dpi.nsh diff --git a/electron-builder.yml b/apps/desktop/electron-builder.yml similarity index 97% rename from electron-builder.yml rename to apps/desktop/electron-builder.yml index 508c4f04..c9553f84 100644 --- a/electron-builder.yml +++ b/apps/desktop/electron-builder.yml @@ -14,11 +14,10 @@ directories: files: - out/**/* - '!**/.vscode/*' - - '!src/*' - '!electron.vite.config.{js,ts,mjs,cjs}' - '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,CHANGELOG.md,README.md}' - '!{.env,.env.*,.npmrc,pnpm-lock.yaml}' - - '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}' + - '!{tsconfig.json,tsconfig.node.json}' # jieba 词库文件已改为启动时远程下载,无需打包内置 - '!node_modules/@node-rs/jieba/dict.txt' - '!node_modules/@node-rs/jieba/idf.txt' diff --git a/electron.vite.config.ts b/apps/desktop/electron.vite.config.ts similarity index 79% rename from electron.vite.config.ts rename to apps/desktop/electron.vite.config.ts index a0a4e31a..66ddb1c2 100644 --- a/electron.vite.config.ts +++ b/apps/desktop/electron.vite.config.ts @@ -3,13 +3,15 @@ import { defineConfig, externalizeDepsPlugin } from 'electron-vite' import vue from '@vitejs/plugin-vue' import ui from '@nuxt/ui/vite' +const rootDir = resolve(__dirname, '../..') + export default defineConfig(() => { return { main: { plugins: [externalizeDepsPlugin()], resolve: { alias: { - '@openchatlab': resolve('packages'), + '@openchatlab': resolve(rootDir, 'packages'), }, }, define: { @@ -21,8 +23,8 @@ export default defineConfig(() => { build: { rollupOptions: { input: { - index: resolve(__dirname, 'electron/main/index.ts'), - 'worker/dbWorker': resolve(__dirname, 'electron/main/worker/dbWorker.ts'), + index: resolve(__dirname, 'main/index.ts'), + 'worker/dbWorker': resolve(__dirname, 'main/worker/dbWorker.ts'), }, }, }, @@ -31,13 +33,13 @@ export default defineConfig(() => { plugins: [externalizeDepsPlugin()], resolve: { alias: { - '@openchatlab': resolve('packages'), + '@openchatlab': resolve(rootDir, 'packages'), }, }, build: { rollupOptions: { input: { - index: resolve(__dirname, 'electron/preload/index.ts'), + index: resolve(__dirname, 'preload/index.ts'), }, }, }, @@ -45,9 +47,10 @@ export default defineConfig(() => { renderer: { resolve: { alias: { - '@': resolve('src/'), - '~': resolve('src/'), - '@openchatlab': resolve('packages'), + '@': resolve(rootDir, 'src/'), + '~': resolve(rootDir, 'src/'), + '@openchatlab': resolve(rootDir, 'packages'), + '@electron': resolve(__dirname), }, }, define: { @@ -64,12 +67,12 @@ export default defineConfig(() => { }, }), ], - root: 'src/', + root: resolve(rootDir, 'src/'), build: { sourcemap: false, rollupOptions: { input: { - index: resolve(__dirname, 'src/index.html'), + index: resolve(rootDir, 'src/index.html'), }, output: { manualChunks(id) { diff --git a/electron/main/ai/agent/index.ts b/apps/desktop/main/ai/agent/index.ts similarity index 100% rename from electron/main/ai/agent/index.ts rename to apps/desktop/main/ai/agent/index.ts diff --git a/electron/main/ai/agent/prompt-builder.ts b/apps/desktop/main/ai/agent/prompt-builder.ts similarity index 100% rename from electron/main/ai/agent/prompt-builder.ts rename to apps/desktop/main/ai/agent/prompt-builder.ts diff --git a/electron/main/ai/agent/types.ts b/apps/desktop/main/ai/agent/types.ts similarity index 100% rename from electron/main/ai/agent/types.ts rename to apps/desktop/main/ai/agent/types.ts diff --git a/electron/main/ai/assistant/builtinTools.ts b/apps/desktop/main/ai/assistant/builtinTools.ts similarity index 100% rename from electron/main/ai/assistant/builtinTools.ts rename to apps/desktop/main/ai/assistant/builtinTools.ts diff --git a/electron/main/ai/assistant/builtins/general_cn.md b/apps/desktop/main/ai/assistant/builtins/general_cn.md similarity index 100% rename from electron/main/ai/assistant/builtins/general_cn.md rename to apps/desktop/main/ai/assistant/builtins/general_cn.md diff --git a/electron/main/ai/assistant/builtins/general_en.md b/apps/desktop/main/ai/assistant/builtins/general_en.md similarity index 100% rename from electron/main/ai/assistant/builtins/general_en.md rename to apps/desktop/main/ai/assistant/builtins/general_en.md diff --git a/electron/main/ai/assistant/builtins/general_ja.md b/apps/desktop/main/ai/assistant/builtins/general_ja.md similarity index 100% rename from electron/main/ai/assistant/builtins/general_ja.md rename to apps/desktop/main/ai/assistant/builtins/general_ja.md diff --git a/electron/main/ai/assistant/defaultGeneral.ts b/apps/desktop/main/ai/assistant/defaultGeneral.ts similarity index 100% rename from electron/main/ai/assistant/defaultGeneral.ts rename to apps/desktop/main/ai/assistant/defaultGeneral.ts diff --git a/electron/main/ai/assistant/index.ts b/apps/desktop/main/ai/assistant/index.ts similarity index 100% rename from electron/main/ai/assistant/index.ts rename to apps/desktop/main/ai/assistant/index.ts diff --git a/electron/main/ai/assistant/manager.ts b/apps/desktop/main/ai/assistant/manager.ts similarity index 100% rename from electron/main/ai/assistant/manager.ts rename to apps/desktop/main/ai/assistant/manager.ts diff --git a/electron/main/ai/assistant/types.ts b/apps/desktop/main/ai/assistant/types.ts similarity index 100% rename from electron/main/ai/assistant/types.ts rename to apps/desktop/main/ai/assistant/types.ts diff --git a/electron/main/ai/conversations.ts b/apps/desktop/main/ai/conversations.ts similarity index 100% rename from electron/main/ai/conversations.ts rename to apps/desktop/main/ai/conversations.ts diff --git a/electron/main/ai/llm/custom-model-store.ts b/apps/desktop/main/ai/llm/custom-model-store.ts similarity index 100% rename from electron/main/ai/llm/custom-model-store.ts rename to apps/desktop/main/ai/llm/custom-model-store.ts diff --git a/electron/main/ai/llm/custom-provider-store.ts b/apps/desktop/main/ai/llm/custom-provider-store.ts similarity index 100% rename from electron/main/ai/llm/custom-provider-store.ts rename to apps/desktop/main/ai/llm/custom-provider-store.ts diff --git a/electron/main/ai/llm/index.ts b/apps/desktop/main/ai/llm/index.ts similarity index 100% rename from electron/main/ai/llm/index.ts rename to apps/desktop/main/ai/llm/index.ts diff --git a/electron/main/ai/llm/model-types.ts b/apps/desktop/main/ai/llm/model-types.ts similarity index 100% rename from electron/main/ai/llm/model-types.ts rename to apps/desktop/main/ai/llm/model-types.ts diff --git a/electron/main/ai/llm/types.ts b/apps/desktop/main/ai/llm/types.ts similarity index 100% rename from electron/main/ai/llm/types.ts rename to apps/desktop/main/ai/llm/types.ts diff --git a/electron/main/ai/logger.ts b/apps/desktop/main/ai/logger.ts similarity index 100% rename from electron/main/ai/logger.ts rename to apps/desktop/main/ai/logger.ts diff --git a/electron/main/ai/rag/index.ts b/apps/desktop/main/ai/rag/index.ts similarity index 100% rename from electron/main/ai/rag/index.ts rename to apps/desktop/main/ai/rag/index.ts diff --git a/electron/main/ai/serialize-error.ts b/apps/desktop/main/ai/serialize-error.ts similarity index 100% rename from electron/main/ai/serialize-error.ts rename to apps/desktop/main/ai/serialize-error.ts diff --git a/electron/main/ai/skills/index.ts b/apps/desktop/main/ai/skills/index.ts similarity index 100% rename from electron/main/ai/skills/index.ts rename to apps/desktop/main/ai/skills/index.ts diff --git a/electron/main/ai/skills/manager.ts b/apps/desktop/main/ai/skills/manager.ts similarity index 100% rename from electron/main/ai/skills/manager.ts rename to apps/desktop/main/ai/skills/manager.ts diff --git a/electron/main/ai/skills/types.ts b/apps/desktop/main/ai/skills/types.ts similarity index 100% rename from electron/main/ai/skills/types.ts rename to apps/desktop/main/ai/skills/types.ts diff --git a/electron/main/ai/summary/index.ts b/apps/desktop/main/ai/summary/index.ts similarity index 100% rename from electron/main/ai/summary/index.ts rename to apps/desktop/main/ai/summary/index.ts diff --git a/electron/main/ai/tools/definitions/index.ts b/apps/desktop/main/ai/tools/definitions/index.ts similarity index 100% rename from electron/main/ai/tools/definitions/index.ts rename to apps/desktop/main/ai/tools/definitions/index.ts diff --git a/electron/main/ai/tools/index.ts b/apps/desktop/main/ai/tools/index.ts similarity index 100% rename from electron/main/ai/tools/index.ts rename to apps/desktop/main/ai/tools/index.ts diff --git a/electron/main/ai/tools/shared-tool-adapter.ts b/apps/desktop/main/ai/tools/shared-tool-adapter.ts similarity index 100% rename from electron/main/ai/tools/shared-tool-adapter.ts rename to apps/desktop/main/ai/tools/shared-tool-adapter.ts diff --git a/electron/main/ai/tools/types.ts b/apps/desktop/main/ai/tools/types.ts similarity index 100% rename from electron/main/ai/tools/types.ts rename to apps/desktop/main/ai/tools/types.ts diff --git a/electron/main/ai/tools/worker-data-provider.ts b/apps/desktop/main/ai/tools/worker-data-provider.ts similarity index 100% rename from electron/main/ai/tools/worker-data-provider.ts rename to apps/desktop/main/ai/tools/worker-data-provider.ts diff --git a/electron/main/analytics.ts b/apps/desktop/main/analytics.ts similarity index 100% rename from electron/main/analytics.ts rename to apps/desktop/main/analytics.ts diff --git a/electron/main/api/adapters.ts b/apps/desktop/main/api/adapters.ts similarity index 100% rename from electron/main/api/adapters.ts rename to apps/desktop/main/api/adapters.ts diff --git a/electron/main/api/auth.ts b/apps/desktop/main/api/auth.ts similarity index 100% rename from electron/main/api/auth.ts rename to apps/desktop/main/api/auth.ts diff --git a/electron/main/api/errors.ts b/apps/desktop/main/api/errors.ts similarity index 100% rename from electron/main/api/errors.ts rename to apps/desktop/main/api/errors.ts diff --git a/electron/main/api/index.ts b/apps/desktop/main/api/index.ts similarity index 100% rename from electron/main/api/index.ts rename to apps/desktop/main/api/index.ts diff --git a/electron/main/api/logger.ts b/apps/desktop/main/api/logger.ts similarity index 100% rename from electron/main/api/logger.ts rename to apps/desktop/main/api/logger.ts diff --git a/electron/main/api/routes/import.ts b/apps/desktop/main/api/routes/import.ts similarity index 100% rename from electron/main/api/routes/import.ts rename to apps/desktop/main/api/routes/import.ts diff --git a/electron/main/api/routes/sessions.ts b/apps/desktop/main/api/routes/sessions.ts similarity index 100% rename from electron/main/api/routes/sessions.ts rename to apps/desktop/main/api/routes/sessions.ts diff --git a/electron/main/api/routes/system.ts b/apps/desktop/main/api/routes/system.ts similarity index 100% rename from electron/main/api/routes/system.ts rename to apps/desktop/main/api/routes/system.ts diff --git a/electron/main/api/server.ts b/apps/desktop/main/api/server.ts similarity index 100% rename from electron/main/api/server.ts rename to apps/desktop/main/api/server.ts diff --git a/electron/main/database/core.ts b/apps/desktop/main/database/core.ts similarity index 99% rename from electron/main/database/core.ts rename to apps/desktop/main/database/core.ts index ec76a39c..85480fa0 100644 --- a/electron/main/database/core.ts +++ b/apps/desktop/main/database/core.ts @@ -13,7 +13,7 @@ import { renameSession as coreRenameSession, } from '@openchatlab/core' import { BetterSqliteAdapter, writeParseResultToDb } from '@openchatlab/node-runtime' -import type { ParseResult } from '../../../src/types/base' +import type { ParseResult } from '../../../../src/types/base' import { migrateDatabase, needsMigration, CURRENT_SCHEMA_VERSION } from './migrations' import { getPathProvider } from '../path-context' import { ensureDir } from '../paths' diff --git a/electron/main/database/migrations.ts b/apps/desktop/main/database/migrations.ts similarity index 100% rename from electron/main/database/migrations.ts rename to apps/desktop/main/database/migrations.ts diff --git a/electron/main/electron-path-provider.ts b/apps/desktop/main/electron-path-provider.ts similarity index 100% rename from electron/main/electron-path-provider.ts rename to apps/desktop/main/electron-path-provider.ts diff --git a/electron/main/env.d.ts b/apps/desktop/main/env.d.ts similarity index 100% rename from electron/main/env.d.ts rename to apps/desktop/main/env.d.ts diff --git a/electron/main/i18n/index.ts b/apps/desktop/main/i18n/index.ts similarity index 100% rename from electron/main/i18n/index.ts rename to apps/desktop/main/i18n/index.ts diff --git a/electron/main/i18n/locales/en-US.ts b/apps/desktop/main/i18n/locales/en-US.ts similarity index 100% rename from electron/main/i18n/locales/en-US.ts rename to apps/desktop/main/i18n/locales/en-US.ts diff --git a/electron/main/i18n/locales/ja-JP.ts b/apps/desktop/main/i18n/locales/ja-JP.ts similarity index 100% rename from electron/main/i18n/locales/ja-JP.ts rename to apps/desktop/main/i18n/locales/ja-JP.ts diff --git a/electron/main/i18n/locales/zh-CN.ts b/apps/desktop/main/i18n/locales/zh-CN.ts similarity index 100% rename from electron/main/i18n/locales/zh-CN.ts rename to apps/desktop/main/i18n/locales/zh-CN.ts diff --git a/electron/main/i18n/locales/zh-TW.ts b/apps/desktop/main/i18n/locales/zh-TW.ts similarity index 100% rename from electron/main/i18n/locales/zh-TW.ts rename to apps/desktop/main/i18n/locales/zh-TW.ts diff --git a/electron/main/index.ts b/apps/desktop/main/index.ts similarity index 100% rename from electron/main/index.ts rename to apps/desktop/main/index.ts diff --git a/electron/main/ipc/ai.ts b/apps/desktop/main/ipc/ai.ts similarity index 100% rename from electron/main/ipc/ai.ts rename to apps/desktop/main/ipc/ai.ts diff --git a/electron/main/ipc/api.ts b/apps/desktop/main/ipc/api.ts similarity index 100% rename from electron/main/ipc/api.ts rename to apps/desktop/main/ipc/api.ts diff --git a/electron/main/ipc/cache.ts b/apps/desktop/main/ipc/cache.ts similarity index 100% rename from electron/main/ipc/cache.ts rename to apps/desktop/main/ipc/cache.ts diff --git a/electron/main/ipc/chat.ts b/apps/desktop/main/ipc/chat.ts similarity index 100% rename from electron/main/ipc/chat.ts rename to apps/desktop/main/ipc/chat.ts diff --git a/electron/main/ipc/demo.ts b/apps/desktop/main/ipc/demo.ts similarity index 100% rename from electron/main/ipc/demo.ts rename to apps/desktop/main/ipc/demo.ts diff --git a/electron/main/ipc/merge.ts b/apps/desktop/main/ipc/merge.ts similarity index 98% rename from electron/main/ipc/merge.ts rename to apps/desktop/main/ipc/merge.ts index b093d684..47714381 100644 --- a/electron/main/ipc/merge.ts +++ b/apps/desktop/main/ipc/merge.ts @@ -7,7 +7,7 @@ import * as worker from '../worker/workerManager' import * as merger from '../merger' import { deleteTempDatabase, cleanupAllTempDatabases } from '../merger/tempCache' import type { ParseProgress } from '../parser' -import type { MergeParams } from '../../../src/types/format' +import type { MergeParams } from '../../../../src/types/format' import type { IpcContext } from './types' // ==================== 临时数据库缓存 ==================== diff --git a/electron/main/ipc/messages.ts b/apps/desktop/main/ipc/messages.ts similarity index 100% rename from electron/main/ipc/messages.ts rename to apps/desktop/main/ipc/messages.ts diff --git a/electron/main/ipc/network.ts b/apps/desktop/main/ipc/network.ts similarity index 100% rename from electron/main/ipc/network.ts rename to apps/desktop/main/ipc/network.ts diff --git a/electron/main/ipc/nlp.ts b/apps/desktop/main/ipc/nlp.ts similarity index 100% rename from electron/main/ipc/nlp.ts rename to apps/desktop/main/ipc/nlp.ts diff --git a/electron/main/ipc/types.ts b/apps/desktop/main/ipc/types.ts similarity index 100% rename from electron/main/ipc/types.ts rename to apps/desktop/main/ipc/types.ts diff --git a/electron/main/ipc/window.ts b/apps/desktop/main/ipc/window.ts similarity index 100% rename from electron/main/ipc/window.ts rename to apps/desktop/main/ipc/window.ts diff --git a/electron/main/ipcMain.ts b/apps/desktop/main/ipcMain.ts similarity index 100% rename from electron/main/ipcMain.ts rename to apps/desktop/main/ipcMain.ts diff --git a/electron/main/logger.ts b/apps/desktop/main/logger.ts similarity index 100% rename from electron/main/logger.ts rename to apps/desktop/main/logger.ts diff --git a/electron/main/merger/index.ts b/apps/desktop/main/merger/index.ts similarity index 98% rename from electron/main/merger/index.ts rename to apps/desktop/main/merger/index.ts index 9675b654..af60577d 100644 --- a/electron/main/merger/index.ts +++ b/apps/desktop/main/merger/index.ts @@ -11,14 +11,14 @@ import type { ChatLabOutput } from '@openchatlab/node-runtime' import { importData } from '../database/core' import { TempDbReader } from './tempCache' import { getPathProvider } from '../path-context' -import type { ChatPlatform, ChatType } from '../../../src/types/base' +import type { ChatPlatform, ChatType } from '../../../../src/types/base' import type { ChatLabFormat, ChatLabMessage, ConflictCheckResult, MergeParams, MergeResult, -} from '../../../src/types/format' +} from '../../../../src/types/format' function getDefaultOutputDir(): string { return getPathProvider().getDownloadsDir() diff --git a/electron/main/merger/tempCache.ts b/apps/desktop/main/merger/tempCache.ts similarity index 100% rename from electron/main/merger/tempCache.ts rename to apps/desktop/main/merger/tempCache.ts diff --git a/electron/main/network/index.ts b/apps/desktop/main/network/index.ts similarity index 100% rename from electron/main/network/index.ts rename to apps/desktop/main/network/index.ts diff --git a/electron/main/network/proxy.ts b/apps/desktop/main/network/proxy.ts similarity index 100% rename from electron/main/network/proxy.ts rename to apps/desktop/main/network/proxy.ts diff --git a/electron/main/nlp/dictManager.ts b/apps/desktop/main/nlp/dictManager.ts similarity index 100% rename from electron/main/nlp/dictManager.ts rename to apps/desktop/main/nlp/dictManager.ts diff --git a/electron/main/parser/index.ts b/apps/desktop/main/parser/index.ts similarity index 100% rename from electron/main/parser/index.ts rename to apps/desktop/main/parser/index.ts diff --git a/electron/main/path-context.ts b/apps/desktop/main/path-context.ts similarity index 100% rename from electron/main/path-context.ts rename to apps/desktop/main/path-context.ts diff --git a/electron/main/paths.ts b/apps/desktop/main/paths.ts similarity index 100% rename from electron/main/paths.ts rename to apps/desktop/main/paths.ts diff --git a/electron/main/update.ts b/apps/desktop/main/update.ts similarity index 100% rename from electron/main/update.ts rename to apps/desktop/main/update.ts diff --git a/electron/main/utils/httpHeaders.ts b/apps/desktop/main/utils/httpHeaders.ts similarity index 100% rename from electron/main/utils/httpHeaders.ts rename to apps/desktop/main/utils/httpHeaders.ts diff --git a/electron/main/utils/pathUtils.ts b/apps/desktop/main/utils/pathUtils.ts similarity index 100% rename from electron/main/utils/pathUtils.ts rename to apps/desktop/main/utils/pathUtils.ts diff --git a/electron/main/worker/core/dbCore.ts b/apps/desktop/main/worker/core/dbCore.ts similarity index 100% rename from electron/main/worker/core/dbCore.ts rename to apps/desktop/main/worker/core/dbCore.ts diff --git a/electron/main/worker/core/index.ts b/apps/desktop/main/worker/core/index.ts similarity index 100% rename from electron/main/worker/core/index.ts rename to apps/desktop/main/worker/core/index.ts diff --git a/electron/main/worker/core/perfLogger.ts b/apps/desktop/main/worker/core/perfLogger.ts similarity index 100% rename from electron/main/worker/core/perfLogger.ts rename to apps/desktop/main/worker/core/perfLogger.ts diff --git a/electron/main/worker/dbWorker.ts b/apps/desktop/main/worker/dbWorker.ts similarity index 100% rename from electron/main/worker/dbWorker.ts rename to apps/desktop/main/worker/dbWorker.ts diff --git a/electron/main/worker/import/incrementalImport.ts b/apps/desktop/main/worker/import/incrementalImport.ts similarity index 100% rename from electron/main/worker/import/incrementalImport.ts rename to apps/desktop/main/worker/import/incrementalImport.ts diff --git a/electron/main/worker/import/index.ts b/apps/desktop/main/worker/import/index.ts similarity index 100% rename from electron/main/worker/import/index.ts rename to apps/desktop/main/worker/import/index.ts diff --git a/electron/main/worker/import/streamImport.ts b/apps/desktop/main/worker/import/streamImport.ts similarity index 100% rename from electron/main/worker/import/streamImport.ts rename to apps/desktop/main/worker/import/streamImport.ts diff --git a/electron/main/worker/import/tempDb.test.ts b/apps/desktop/main/worker/import/tempDb.test.ts similarity index 100% rename from electron/main/worker/import/tempDb.test.ts rename to apps/desktop/main/worker/import/tempDb.test.ts diff --git a/electron/main/worker/import/tempDb.ts b/apps/desktop/main/worker/import/tempDb.ts similarity index 100% rename from electron/main/worker/import/tempDb.ts rename to apps/desktop/main/worker/import/tempDb.ts diff --git a/electron/main/worker/import/utils.ts b/apps/desktop/main/worker/import/utils.ts similarity index 100% rename from electron/main/worker/import/utils.ts rename to apps/desktop/main/worker/import/utils.ts diff --git a/electron/main/worker/query/advanced/index.ts b/apps/desktop/main/worker/query/advanced/index.ts similarity index 100% rename from electron/main/worker/query/advanced/index.ts rename to apps/desktop/main/worker/query/advanced/index.ts diff --git a/electron/main/worker/query/advanced/languagePreference.ts b/apps/desktop/main/worker/query/advanced/languagePreference.ts similarity index 100% rename from electron/main/worker/query/advanced/languagePreference.ts rename to apps/desktop/main/worker/query/advanced/languagePreference.ts diff --git a/electron/main/worker/query/advanced/relationship.ts b/apps/desktop/main/worker/query/advanced/relationship.ts similarity index 100% rename from electron/main/worker/query/advanced/relationship.ts rename to apps/desktop/main/worker/query/advanced/relationship.ts diff --git a/electron/main/worker/query/advanced/repeat.ts b/apps/desktop/main/worker/query/advanced/repeat.ts similarity index 100% rename from electron/main/worker/query/advanced/repeat.ts rename to apps/desktop/main/worker/query/advanced/repeat.ts diff --git a/electron/main/worker/query/advanced/social.ts b/apps/desktop/main/worker/query/advanced/social.ts similarity index 100% rename from electron/main/worker/query/advanced/social.ts rename to apps/desktop/main/worker/query/advanced/social.ts diff --git a/electron/main/worker/query/basic.ts b/apps/desktop/main/worker/query/basic.ts similarity index 100% rename from electron/main/worker/query/basic.ts rename to apps/desktop/main/worker/query/basic.ts diff --git a/electron/main/worker/query/fts.ts b/apps/desktop/main/worker/query/fts.ts similarity index 100% rename from electron/main/worker/query/fts.ts rename to apps/desktop/main/worker/query/fts.ts diff --git a/electron/main/worker/query/index.ts b/apps/desktop/main/worker/query/index.ts similarity index 100% rename from electron/main/worker/query/index.ts rename to apps/desktop/main/worker/query/index.ts diff --git a/electron/main/worker/query/messages.ts b/apps/desktop/main/worker/query/messages.ts similarity index 100% rename from electron/main/worker/query/messages.ts rename to apps/desktop/main/worker/query/messages.ts diff --git a/electron/main/worker/query/nlp.ts b/apps/desktop/main/worker/query/nlp.ts similarity index 100% rename from electron/main/worker/query/nlp.ts rename to apps/desktop/main/worker/query/nlp.ts diff --git a/electron/main/worker/query/session/aiTools.ts b/apps/desktop/main/worker/query/session/aiTools.ts similarity index 100% rename from electron/main/worker/query/session/aiTools.ts rename to apps/desktop/main/worker/query/session/aiTools.ts diff --git a/electron/main/worker/query/session/core.ts b/apps/desktop/main/worker/query/session/core.ts similarity index 100% rename from electron/main/worker/query/session/core.ts rename to apps/desktop/main/worker/query/session/core.ts diff --git a/electron/main/worker/query/session/export.ts b/apps/desktop/main/worker/query/session/export.ts similarity index 100% rename from electron/main/worker/query/session/export.ts rename to apps/desktop/main/worker/query/session/export.ts diff --git a/electron/main/worker/query/session/filter.ts b/apps/desktop/main/worker/query/session/filter.ts similarity index 100% rename from electron/main/worker/query/session/filter.ts rename to apps/desktop/main/worker/query/session/filter.ts diff --git a/electron/main/worker/query/session/index.ts b/apps/desktop/main/worker/query/session/index.ts similarity index 100% rename from electron/main/worker/query/session/index.ts rename to apps/desktop/main/worker/query/session/index.ts diff --git a/electron/main/worker/query/session/sessionIndex.ts b/apps/desktop/main/worker/query/session/sessionIndex.ts similarity index 100% rename from electron/main/worker/query/session/sessionIndex.ts rename to apps/desktop/main/worker/query/session/sessionIndex.ts diff --git a/electron/main/worker/query/session/types.ts b/apps/desktop/main/worker/query/session/types.ts similarity index 100% rename from electron/main/worker/query/session/types.ts rename to apps/desktop/main/worker/query/session/types.ts diff --git a/electron/main/worker/query/sessions.ts b/apps/desktop/main/worker/query/sessions.ts similarity index 100% rename from electron/main/worker/query/sessions.ts rename to apps/desktop/main/worker/query/sessions.ts diff --git a/electron/main/worker/query/sql.ts b/apps/desktop/main/worker/query/sql.ts similarity index 100% rename from electron/main/worker/query/sql.ts rename to apps/desktop/main/worker/query/sql.ts diff --git a/electron/main/worker/workerManager.ts b/apps/desktop/main/worker/workerManager.ts similarity index 100% rename from electron/main/worker/workerManager.ts rename to apps/desktop/main/worker/workerManager.ts diff --git a/apps/desktop/package.json b/apps/desktop/package.json new file mode 100644 index 00000000..fd8614de --- /dev/null +++ b/apps/desktop/package.json @@ -0,0 +1,33 @@ +{ + "name": "@openchatlab/desktop", + "version": "0.19.0", + "private": true, + "description": "ChatLab Desktop — Electron 桌面客户端", + "main": "./out/main/index.js", + "scripts": { + "dev": "electron-vite dev", + "preview": "electron-vite preview", + "build": "electron-vite build", + "build:mac": "pnpm run build && electron-builder --mac --config electron-builder.yml -p never", + "build:win": "pnpm run build && electron-builder --win --config electron-builder.yml -p never", + "build:linux": "pnpm run build && electron-builder --linux --config electron-builder.yml -p never", + "postinstall": "electron-rebuild" + }, + "dependencies": { + "@aptabase/electron": "^0.3.1", + "@electron-toolkit/preload": "^3.0.1", + "@electron-toolkit/utils": "^4.0.0", + "@node-rs/jieba": "^2.0.1", + "better-sqlite3": "^12.4.6", + "electron-updater": "^6.6.2", + "i18next": "^25.8.5" + }, + "devDependencies": { + "@electron-toolkit/tsconfig": "^1.0.1", + "@electron/rebuild": "^4.0.1", + "@types/better-sqlite3": "^7.6.13", + "electron": "^35.0.0", + "electron-builder": "^26.0.12", + "electron-vite": "^3.0.0" + } +} diff --git a/electron/preload/apis/ai.ts b/apps/desktop/preload/apis/ai.ts similarity index 99% rename from electron/preload/apis/ai.ts rename to apps/desktop/preload/apis/ai.ts index a8084bfc..55d7fc56 100644 --- a/electron/preload/apis/ai.ts +++ b/apps/desktop/preload/apis/ai.ts @@ -2,7 +2,7 @@ * AI 相关 API - AI 对话、LLM 服务、Agent、Embedding */ import { ipcRenderer } from 'electron' -import type { ExportProgress } from '../../../src/types/base' +import type { ExportProgress } from '../../../../src/types/base' // ==================== 类型定义 ==================== diff --git a/electron/preload/apis/api-server.ts b/apps/desktop/preload/apis/api-server.ts similarity index 100% rename from electron/preload/apis/api-server.ts rename to apps/desktop/preload/apis/api-server.ts diff --git a/electron/preload/apis/chat.ts b/apps/desktop/preload/apis/chat.ts similarity index 98% rename from electron/preload/apis/chat.ts rename to apps/desktop/preload/apis/chat.ts index 236acd0a..31efc6b4 100644 --- a/electron/preload/apis/chat.ts +++ b/apps/desktop/preload/apis/chat.ts @@ -2,7 +2,7 @@ * 聊天记录 API - 导入、分析、管理聊天记录 */ import { ipcRenderer } from 'electron' -import type { AnalysisSession, MessageType, ImportProgress } from '../../../src/types/base' +import type { AnalysisSession, MessageType, ImportProgress } from '../../../../src/types/base' import type { MemberActivity, MemberNameHistory, @@ -17,9 +17,9 @@ import type { ClusterGraphData, ClusterGraphOptions, RelationshipStats, -} from '../../../src/types/analysis' -import type { LanguagePreferenceResult } from '../../../src/types/quotes/languagePreference' -import type { FileParseInfo, ConflictCheckResult, MergeParams, MergeResult } from '../../../src/types/format' +} from '../../../../src/types/analysis' +import type { LanguagePreferenceResult } from '../../../../src/types/quotes/languagePreference' +import type { FileParseInfo, ConflictCheckResult, MergeParams, MergeResult } from '../../../../src/types/format' // Chat Analysis API export const chatApi = { diff --git a/electron/preload/apis/core.ts b/apps/desktop/preload/apis/core.ts similarity index 100% rename from electron/preload/apis/core.ts rename to apps/desktop/preload/apis/core.ts diff --git a/electron/preload/apis/utils.ts b/apps/desktop/preload/apis/utils.ts similarity index 100% rename from electron/preload/apis/utils.ts rename to apps/desktop/preload/apis/utils.ts diff --git a/electron/preload/index.d.ts b/apps/desktop/preload/index.d.ts similarity index 99% rename from electron/preload/index.d.ts rename to apps/desktop/preload/index.d.ts index 22673e46..af2aac3a 100644 --- a/electron/preload/index.d.ts +++ b/apps/desktop/preload/index.d.ts @@ -1,5 +1,5 @@ import { ElectronAPI } from '@electron-toolkit/preload' -import type { AnalysisSession, MessageType, ImportProgress, ExportProgress } from '../../src/types/base' +import type { AnalysisSession, MessageType, ImportProgress, ExportProgress } from '../../../src/types/base' import type { TokenUsage, AgentRuntimeStatus, SerializedErrorInfo } from '../shared/types' import type { MemberActivity, @@ -15,10 +15,10 @@ import type { ClusterGraphData, ClusterGraphOptions, RelationshipStats, -} from '../../src/types/analysis' -import type { FileParseInfo, ConflictCheckResult, MergeParams, MergeResult } from '../../src/types/format' -import type { LanguagePreferenceResult } from '../../src/types/quotes/languagePreference' -import type { TableSchema, SQLResult } from '../../src/components/analysis/SQLLab/types' +} from '../../../src/types/analysis' +import type { FileParseInfo, ConflictCheckResult, MergeParams, MergeResult } from '../../../src/types/format' +import type { LanguagePreferenceResult } from '../../../src/types/quotes/languagePreference' +import type { TableSchema, SQLResult } from '../../../src/components/analysis/SQLLab/types' import type { TimeFilter } from '@openchatlab/shared-types' diff --git a/electron/preload/index.ts b/apps/desktop/preload/index.ts similarity index 98% rename from electron/preload/index.ts rename to apps/desktop/preload/index.ts index 17e69fa6..166fdcea 100644 --- a/electron/preload/index.ts +++ b/apps/desktop/preload/index.ts @@ -25,7 +25,7 @@ export type { LLMConnectionConfigCompat, ModelUsage, ModelSelectionState, -} from '../../electron/main/ai/llm/model-types' +} from '../main/ai/llm/model-types' // Use `contextBridge` APIs to expose Electron APIs to // renderer only if context isolation is enabled, otherwise diff --git a/electron/shared/types.ts b/apps/desktop/shared/types.ts similarity index 100% rename from electron/shared/types.ts rename to apps/desktop/shared/types.ts diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json new file mode 100644 index 00000000..95a6de83 --- /dev/null +++ b/apps/desktop/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": ["../../src/*"], + "@openchatlab/*": ["../../packages/*"], + "@electron/*": ["./*"] + } + }, + "files": [], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/apps/desktop/tsconfig.node.json b/apps/desktop/tsconfig.node.json new file mode 100644 index 00000000..2a692067 --- /dev/null +++ b/apps/desktop/tsconfig.node.json @@ -0,0 +1,29 @@ +{ + "extends": "@electron-toolkit/tsconfig/tsconfig.node.json", + "include": [ + "electron.vite.config.*", + "main/**/*", + "preload/**/*", + "shared/**/*", + "../../src/types/**/*", + "../../packages/shared-types/**/*", + "../../packages/core/**/*", + "../../packages/node-runtime/**/*", + "../../packages/config/**/*", + "../../packages/parser/**/*", + "../../packages/server/**/*", + "../../packages/tools/**/*", + "../../packages/sync/**/*" + ], + "compilerOptions": { + "composite": true, + "types": ["electron-vite/node"], + "moduleResolution": "bundler", + "baseUrl": ".", + "paths": { + "@/*": ["../../src/*"], + "@electron/*": ["./*"], + "@openchatlab/*": ["../../packages/*"] + } + } +} diff --git a/package.json b/package.json index 02e433bd..3cf74058 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "ChatLab", "version": "0.19.0", + "private": true, "description": "本地化的聊天记录分析工具,通过 SQL 和 AI Agent 回顾你的社交记忆", "repository": { "type": "git", "url": "git+https://github.com/ChatLab/ChatLab.git" }, "author": "digua ", - "main": "./out/main/index.js", "packageManager": "pnpm@9.15.9", "engines": { "node": ">=24 <25", @@ -20,69 +20,51 @@ ] }, "scripts": { - "dev": "electron-vite dev", - "preview": "electron-vite preview", - "format": "prettier --write .", - "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix", - "build": "electron-vite build", - "build:mac": "pnpm run build && electron-builder --mac --config electron-builder.yml -p never", - "build:win": "pnpm run build && electron-builder --win --config electron-builder.yml -p never", - "build:linux": "pnpm run build && electron-builder --linux --config electron-builder.yml -p never", + "dev:desktop": "pnpm --filter @openchatlab/desktop dev", + "build:desktop": "pnpm --filter @openchatlab/desktop build", + "build:mac": "pnpm --filter @openchatlab/desktop build:mac", + "build:win": "pnpm --filter @openchatlab/desktop build:win", + "build:linux": "pnpm --filter @openchatlab/desktop build:linux", "dev:app": "vite --config vite.web.config.mts", - "ensure:server-native": "pnpm --filter chatlab run ensure-native", "dev:serve": "bash scripts/dev-serve.sh", "dev:web": "pnpm run ensure:server-native && CHATLAB_AUTO_SERVE=1 vite --config vite.web.config.mts", + "ensure:server-native": "pnpm --filter chatlab run ensure-native", "build:web": "vite build --config vite.web.config.mts", + "format": "prettier --write .", + "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix", "type-check:web": "vue-tsc --noEmit -p tsconfig.web.json", - "type-check:node": "tsc --noEmit -p tsconfig.node.json", + "type-check:node": "tsc --noEmit -p apps/desktop/tsconfig.node.json", "type-check:all": "pnpm run type-check:web && pnpm run type-check:node", "type-check": "vue-tsc --noEmit -p tsconfig.web.json", - "test:agent-context": "node --experimental-strip-types --test electron/main/ai/context/sessionLog.test.mjs", + "test:agent-context": "node --experimental-strip-types --test apps/desktop/main/ai/context/sessionLog.test.mjs", "test:e2e:launcher": "node --test tests/e2e/helpers/app-launcher.test.js", - "test:e2e:smoke": "node tests/e2e/run-smoke.js", - "postinstall": "electron-rebuild" + "test:e2e:smoke": "node tests/e2e/run-smoke.js" }, "dependencies": { - "@aptabase/electron": "^0.3.1", - "@electron-toolkit/preload": "^3.0.1", - "@electron-toolkit/utils": "^4.0.0", - "@node-rs/jieba": "^2.0.1", "@tanstack/vue-virtual": "^3.13.18", "@zumer/snapdom": "^2.0.1", - "better-sqlite3": "^12.4.6", "echarts": "^6.0.0", "echarts-wordcloud": "^2.1.0", - "electron-updater": "^6.6.2", - "fastify": "^5.8.4", - "gray-matter": "^4.0.3", - "i18next": "^25.8.5", - "js-tiktoken": "^1.0.21", "markdown-it": "^14.1.0", - "stream-json": "^1.9.1", "vue-i18n": "^11.2.8" }, "devDependencies": { - "@electron-toolkit/tsconfig": "^1.0.1", - "@electron/rebuild": "^4.0.1", "@nuxt/ui": "^4.2.1", "@tailwindcss/vite": "^4.0.0", - "@types/better-sqlite3": "^7.6.13", + "@electron-toolkit/tsconfig": "^1.0.1", "@types/markdown-it": "^14.1.2", - "@types/stream-json": "^1.7.8", "@vitejs/plugin-vue": "^5.2.3", "@vue/eslint-config-prettier": "^10.2.0", "@vue/eslint-config-typescript": "^14.6.0", "@vueuse/core": "^13.9.0", "dayjs": "^1.11.19", - "electron": "^35.0.0", - "electron-builder": "^26.0.12", - "electron-vite": "^3.0.0", "eslint": "^9.39.1", "eslint-plugin-vue": "^9.33.0", "pinia": "^3.0.4", "pinia-plugin-persistedstate": "^4.7.1", "prettier": "^3.5.3", "tailwindcss": "^4.0.0", + "typescript": "^5.8.3", "vite": "^6.3.5", "vue": "^3.5.25", "vue-router": "^4.6.3", diff --git a/packages/core/src/query/__tests__/filter.test.ts b/packages/core/src/query/__tests__/filter.test.ts index d572220c..57fe8136 100644 --- a/packages/core/src/query/__tests__/filter.test.ts +++ b/packages/core/src/query/__tests__/filter.test.ts @@ -35,7 +35,9 @@ type LightRow = { id: number; ts: number; senderId: number; content: string | nu function createMockDb(lightRows: LightRow[], fullRows: FullMessageRow[]): DatabaseAdapter { let callCount = 0 return { - exec() {}, + exec() { + /* no-op for test */ + }, prepare(): PreparedStatement { callCount++ const isLightQuery = callCount === 1 @@ -63,7 +65,9 @@ function createMockDb(lightRows: LightRow[], fullRows: FullMessageRow[]): Databa pragma() { return undefined }, - close() {}, + close() { + /* no-op for test */ + }, } } diff --git a/packages/node-runtime/package.json b/packages/node-runtime/package.json index 4821439d..d1704107 100644 --- a/packages/node-runtime/package.json +++ b/packages/node-runtime/package.json @@ -9,7 +9,14 @@ "@mariozechner/pi-agent-core": "0.54.2", "@mariozechner/pi-ai": "0.54.2", "@openchatlab/core": "workspace:*", + "better-sqlite3": "^12.4.6", "gray-matter": "^4.0.3", "js-tiktoken": "^1.0.21" + }, + "optionalDependencies": { + "@node-rs/jieba": "^2.0.1" + }, + "devDependencies": { + "@types/better-sqlite3": "^7.6.13" } } diff --git a/packages/node-runtime/src/ai/compression/adapter-factory.ts b/packages/node-runtime/src/ai/compression/adapter-factory.ts index 1ecd69f4..3a82245c 100644 --- a/packages/node-runtime/src/ai/compression/adapter-factory.ts +++ b/packages/node-runtime/src/ai/compression/adapter-factory.ts @@ -1,8 +1,13 @@ -import { completeSimple, type Model as PiModel, type TextContent as PiTextContent } from '@mariozechner/pi-ai' +import { + completeSimple, + type Model as PiModel, + type Api as PiApi, + type TextContent as PiTextContent, +} from '@mariozechner/pi-ai' import type { CompressionLlmAdapter } from './types' export interface CreateCompressionLlmAdapterOptions { - piModel: PiModel + piModel: PiModel apiKey: string contextWindow?: number onCompressing?: () => void diff --git a/packages/parser/package.json b/packages/parser/package.json index b8e7e840..46bd2037 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -6,6 +6,10 @@ "main": "./src/index.ts", "types": "./src/index.ts", "dependencies": { - "@openchatlab/shared-types": "workspace:*" + "@openchatlab/shared-types": "workspace:*", + "stream-json": "^1.9.1" + }, + "devDependencies": { + "@types/stream-json": "^1.7.8" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 390461f5..efbfb355 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,54 +8,21 @@ importers: .: dependencies: - '@aptabase/electron': - specifier: ^0.3.1 - version: 0.3.1(electron@35.7.5) - '@electron-toolkit/preload': - specifier: ^3.0.1 - version: 3.0.2(electron@35.7.5) - '@electron-toolkit/utils': - specifier: ^4.0.0 - version: 4.0.0(electron@35.7.5) - '@node-rs/jieba': - specifier: ^2.0.1 - version: 2.0.1 '@tanstack/vue-virtual': specifier: ^3.13.18 version: 3.13.18(vue@3.5.27(typescript@5.9.3)) '@zumer/snapdom': specifier: ^2.0.1 version: 2.0.2 - better-sqlite3: - specifier: ^12.4.6 - version: 12.6.2 echarts: specifier: ^6.0.0 version: 6.0.0 echarts-wordcloud: specifier: ^2.1.0 version: 2.1.0(echarts@6.0.0) - electron-updater: - specifier: ^6.6.2 - version: 6.7.3 - fastify: - specifier: ^5.8.4 - version: 5.8.4 - gray-matter: - specifier: ^4.0.3 - version: 4.0.3 - i18next: - specifier: ^25.8.5 - version: 25.8.5(typescript@5.9.3) - js-tiktoken: - specifier: ^1.0.21 - version: 1.0.21 markdown-it: specifier: ^14.1.0 version: 14.1.0 - stream-json: - specifier: ^1.9.1 - version: 1.9.1 vue-i18n: specifier: ^11.2.8 version: 11.2.8(vue@3.5.27(typescript@5.9.3)) @@ -63,24 +30,15 @@ importers: '@electron-toolkit/tsconfig': specifier: ^1.0.1 version: 1.0.1(@types/node@25.2.2) - '@electron/rebuild': - specifier: ^4.0.1 - version: 4.0.3 '@nuxt/ui': specifier: ^4.2.1 version: 4.4.0(@tiptap/extensions@3.19.0(@tiptap/core@3.19.0(@tiptap/pm@3.19.0))(@tiptap/pm@3.19.0))(@tiptap/y-tiptap@3.0.2(prosemirror-model@1.25.4)(prosemirror-state@1.4.4)(prosemirror-view@1.41.6)(y-protocols@1.0.7(yjs@13.6.29))(yjs@13.6.29))(axios@1.13.5)(embla-carousel@8.6.0)(tailwindcss@4.1.18)(typescript@5.9.3)(vite@6.4.1(@types/node@25.2.2)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2))(vue-router@4.6.4(vue@3.5.27(typescript@5.9.3)))(vue@3.5.27(typescript@5.9.3))(yjs@13.6.29)(zod@3.25.76) '@tailwindcss/vite': specifier: ^4.0.0 version: 4.1.18(vite@6.4.1(@types/node@25.2.2)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2)) - '@types/better-sqlite3': - specifier: ^7.6.13 - version: 7.6.13 '@types/markdown-it': specifier: ^14.1.2 version: 14.1.2 - '@types/stream-json': - specifier: ^1.7.8 - version: 1.7.8 '@vitejs/plugin-vue': specifier: ^5.2.3 version: 5.2.4(vite@6.4.1(@types/node@25.2.2)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.27(typescript@5.9.3)) @@ -96,15 +54,6 @@ importers: dayjs: specifier: ^1.11.19 version: 1.11.19 - electron: - specifier: ^35.0.0 - version: 35.7.5 - electron-builder: - specifier: ^26.0.12 - version: 26.7.0(electron-builder-squirrel-windows@26.7.0) - electron-vite: - specifier: ^3.0.0 - version: 3.1.0(vite@6.4.1(@types/node@25.2.2)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2)) eslint: specifier: ^9.39.1 version: 9.39.2(jiti@2.6.1) @@ -123,6 +72,9 @@ importers: tailwindcss: specifier: ^4.0.0 version: 4.1.18 + typescript: + specifier: ^5.8.3 + version: 5.9.3 vite: specifier: ^6.3.5 version: 6.4.1(@types/node@25.2.2)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2) @@ -136,6 +88,49 @@ importers: specifier: ^3.1.1 version: 3.2.6(typescript@5.9.3) + apps/desktop: + dependencies: + '@aptabase/electron': + specifier: ^0.3.1 + version: 0.3.1(electron@35.7.5) + '@electron-toolkit/preload': + specifier: ^3.0.1 + version: 3.0.2(electron@35.7.5) + '@electron-toolkit/utils': + specifier: ^4.0.0 + version: 4.0.0(electron@35.7.5) + '@node-rs/jieba': + specifier: ^2.0.1 + version: 2.0.1 + better-sqlite3: + specifier: ^12.4.6 + version: 12.6.2 + electron-updater: + specifier: ^6.6.2 + version: 6.7.3 + i18next: + specifier: ^25.8.5 + version: 25.8.5(typescript@5.9.3) + devDependencies: + '@electron-toolkit/tsconfig': + specifier: ^1.0.1 + version: 1.0.1(@types/node@25.2.2) + '@electron/rebuild': + specifier: ^4.0.1 + version: 4.0.3 + '@types/better-sqlite3': + specifier: ^7.6.13 + version: 7.6.13 + electron: + specifier: ^35.0.0 + version: 35.7.5 + electron-builder: + specifier: ^26.0.12 + version: 26.7.0(electron-builder-squirrel-windows@26.7.0) + electron-vite: + specifier: ^3.0.0 + version: 3.1.0(vite@6.4.1(@types/node@25.2.2)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2)) + packages/config: dependencies: smol-toml: @@ -158,18 +153,36 @@ importers: '@openchatlab/core': specifier: workspace:* version: link:../core + better-sqlite3: + specifier: ^12.4.6 + version: 12.6.2 gray-matter: specifier: ^4.0.3 version: 4.0.3 js-tiktoken: specifier: ^1.0.21 version: 1.0.21 + optionalDependencies: + '@node-rs/jieba': + specifier: ^2.0.1 + version: 2.0.1 + devDependencies: + '@types/better-sqlite3': + specifier: ^7.6.13 + version: 7.6.13 packages/parser: dependencies: '@openchatlab/shared-types': specifier: workspace:* version: link:../shared-types + stream-json: + specifier: ^1.9.1 + version: 1.9.1 + devDependencies: + '@types/stream-json': + specifier: ^1.7.8 + version: 1.7.8 packages/server: dependencies: @@ -1016,14 +1029,6 @@ packages: resolution: {integrity: sha512-l6e4NZyUgv8VyXXH4DbuucFOBmxLF56C/mqh2tvApbzl2Hrhi1aTDcuv5TKdxzfHYmpO3UB0Cz04fgDT9vszfw==} engines: {node: '>= 16'} - '@isaacs/balanced-match@4.0.1': - resolution: {integrity: sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==} - engines: {node: 20 || >=22} - - '@isaacs/brace-expansion@5.0.1': - resolution: {integrity: sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==} - engines: {node: 20 || >=22} - '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -4044,10 +4049,6 @@ packages: resolution: {integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==} engines: {node: '>=10'} - minimatch@10.1.2: - resolution: {integrity: sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==} - engines: {node: 20 || >=22} - minimatch@10.2.5: resolution: {integrity: sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==} engines: {node: 18 || 20 || >=22} @@ -4090,10 +4091,6 @@ packages: resolution: {integrity: sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==} engines: {node: '>=8'} - minipass@7.1.2: - resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} - engines: {node: '>=16 || 14 >=14.17'} - minipass@7.1.3: resolution: {integrity: sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==} engines: {node: '>=16 || 14 >=14.17'} @@ -6572,12 +6569,6 @@ snapshots: '@intlify/shared@11.2.8': {} - '@isaacs/balanced-match@4.0.1': {} - - '@isaacs/brace-expansion@5.0.1': - dependencies: - '@isaacs/balanced-match': 4.0.1 - '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2 @@ -6589,7 +6580,7 @@ snapshots: '@isaacs/fs-minipass@4.0.1': dependencies: - minipass: 7.1.2 + minipass: 7.1.3 '@jridgewell/gen-mapping@0.3.13': dependencies: @@ -7870,7 +7861,7 @@ snapshots: '@types/yauzl@2.10.3': dependencies: - '@types/node': 22.19.10 + '@types/node': 25.2.2 optional: true '@typescript-eslint/eslint-plugin@8.55.0(@typescript-eslint/parser@8.55.0(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.2(jiti@2.6.1))(typescript@5.9.3)': @@ -8257,7 +8248,7 @@ snapshots: js-yaml: 4.1.1 json5: 2.2.3 lazy-val: 1.0.5 - minimatch: 10.1.2 + minimatch: 10.2.5 plist: 3.1.0 proper-lockfile: 4.1.2 resedit: 1.7.2 @@ -8456,7 +8447,7 @@ snapshots: fs-minipass: 3.0.3 glob: 10.4.5 lru-cache: 10.4.3 - minipass: 7.1.2 + minipass: 7.1.3 minipass-collect: 2.0.1 minipass-flush: 1.0.5 minipass-pipeline: 1.2.4 @@ -9437,7 +9428,7 @@ snapshots: fs-minipass@3.0.3: dependencies: - minipass: 7.1.2 + minipass: 7.1.3 fs.realpath@1.0.0: {} @@ -9529,7 +9520,7 @@ snapshots: foreground-child: 3.3.1 jackspeak: 3.4.3 minimatch: 9.0.5 - minipass: 7.1.2 + minipass: 7.1.3 package-json-from-dist: 1.0.1 path-scurry: 1.11.1 @@ -10045,7 +10036,7 @@ snapshots: '@npmcli/agent': 3.0.0 cacache: 19.0.1 http-cache-semantics: 4.2.0 - minipass: 7.1.2 + minipass: 7.1.3 minipass-fetch: 4.0.1 minipass-flush: 1.0.5 minipass-pipeline: 1.2.4 @@ -10115,10 +10106,6 @@ snapshots: mimic-response@3.1.0: {} - minimatch@10.1.2: - dependencies: - '@isaacs/brace-expansion': 5.0.1 - minimatch@10.2.5: dependencies: brace-expansion: 5.0.6 @@ -10139,11 +10126,11 @@ snapshots: minipass-collect@2.0.1: dependencies: - minipass: 7.1.2 + minipass: 7.1.3 minipass-fetch@4.0.1: dependencies: - minipass: 7.1.2 + minipass: 7.1.3 minipass-sized: 1.0.3 minizlib: 3.1.0 optionalDependencies: @@ -10165,13 +10152,11 @@ snapshots: dependencies: yallist: 4.0.0 - minipass@7.1.2: {} - minipass@7.1.3: {} minizlib@3.1.0: dependencies: - minipass: 7.1.2 + minipass: 7.1.3 mitt@3.0.1: {} @@ -10413,7 +10398,7 @@ snapshots: path-scurry@1.11.1: dependencies: lru-cache: 10.4.3 - minipass: 7.1.2 + minipass: 7.1.3 path-scurry@2.0.2: dependencies: @@ -11046,7 +11031,7 @@ snapshots: ssri@12.0.0: dependencies: - minipass: 7.1.2 + minipass: 7.1.3 stat-mode@1.0.0: {} @@ -11147,7 +11132,7 @@ snapshots: dependencies: '@isaacs/fs-minipass': 4.0.1 chownr: 3.0.0 - minipass: 7.1.2 + minipass: 7.1.3 minizlib: 3.1.0 yallist: 5.0.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 600b4bb4..0864aa40 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,2 +1,3 @@ packages: - 'packages/**' + - 'apps/*' diff --git a/src/App.vue b/src/App.vue index 05eacc1f..e1111cd6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -57,10 +57,10 @@ onMounted(async () => { document.documentElement.classList.add('platform-linux') } - // 初始化语言设置(同步 i18n 和 dayjs,异步加载脱敏规则) - await settingsStore.initLocale() - // 初始化 Service 层(按领域注册 Adapter) + // 初始化 Service 层(按领域注册 Adapter),必须在其他依赖 Adapter 的逻辑之前 await initServices() + // 初始化语言设置(同步 i18n 和 dayjs,异步加载脱敏规则 — 依赖 AI adapter) + await settingsStore.initLocale() // 初始化 LLM 配置(预加载,避免首次使用时延迟) llmStore.init() // 从数据库加载会话列表 diff --git a/src/components/analysis/SQLLabTab.vue b/src/components/analysis/SQLLabTab.vue index b8d9721a..0778c5e4 100644 --- a/src/components/analysis/SQLLabTab.vue +++ b/src/components/analysis/SQLLabTab.vue @@ -243,7 +243,7 @@ async function generateAndRunSQL() { { role: 'user', content: fullPrompt }, ], { temperature: 0.1, maxTokens: 4096 }, - (chunk: LLMChatStreamChunk) => { + (chunk) => { if (chunk.thinking !== undefined) { if (chunk.thinkingDone) { isThinking.value = false diff --git a/tsconfig.json b/tsconfig.json index 3f1c630f..4d87bb2c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,14 @@ "baseUrl": ".", "paths": { "@/*": ["src/*"], - "@electron/*": ["electron/*"], + "@electron/*": ["apps/desktop/*"], "@openchatlab/*": ["packages/*"] } }, "files": [], - "references": [{ "path": "./tsconfig.node.json" }, { "path": "./tsconfig.web.json" }] + "references": [ + { "path": "./tsconfig.node.json" }, + { "path": "./apps/desktop/tsconfig.node.json" }, + { "path": "./tsconfig.web.json" } + ] } diff --git a/tsconfig.node.json b/tsconfig.node.json index 69db896f..86d6b594 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,29 +1,10 @@ { "extends": "@electron-toolkit/tsconfig/tsconfig.node.json", - "include": [ - "electron.vite.config.*", - "vite.config.*", - "electron/main/**/*", - "electron/preload/**/*", - "electron/shared/**/*", - "src/types/**/*", - "packages/shared-types/**/*", - "packages/core/**/*", - "packages/node-runtime/**/*", - "packages/config/**/*", - "packages/parser/**/*", - "packages/server/**/*", - "packages/tools/**/*", - "packages/sync/**/*" - ], "compilerOptions": { "composite": true, - "types": ["electron-vite/node"], "moduleResolution": "bundler", "baseUrl": ".", "paths": { - "@/*": ["src/*"], - "@electron/*": ["electron/*"], "@openchatlab/*": ["packages/*"] } } diff --git a/tsconfig.web.json b/tsconfig.web.json index d1c0a417..dabdecc9 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -1,6 +1,6 @@ { "extends": "@electron-toolkit/tsconfig/tsconfig.web.json", - "include": ["src/env.d.ts", "src/**/*", "electron/preload/**/*.d.ts", "packages/**/*"], + "include": ["src/env.d.ts", "src/**/*", "apps/desktop/preload/**/*.d.ts", "packages/**/*"], "compilerOptions": { "baseUrl": ".", "target": "ESNext", @@ -21,7 +21,7 @@ "forceConsistentCasingInFileNames": true, "paths": { "@/*": ["src/*"], - "@electron/*": ["electron/*"], + "@electron/*": ["apps/desktop/*"], "@openchatlab/*": ["packages/*"] } } diff --git a/vite.web.config.mts b/vite.web.config.mts index bfda98d9..e916d4c7 100644 --- a/vite.web.config.mts +++ b/vite.web.config.mts @@ -6,7 +6,7 @@ * * 与 Electron renderer 构建的关键区别: * - __IS_ELECTRON__ = false(使用 FetchAdapter 而非 window.chatApi) - * - 不包含 electron/preload 和 electron/main + * - 不包含 apps/desktop/preload 和 apps/desktop/main * - 输出目录独立(dist-web/ vs out/renderer/) */ @@ -106,8 +106,8 @@ export default defineConfig({ '@': resolve(__dirname, 'src/'), '~': resolve(__dirname, 'src/'), '@openchatlab': resolve(__dirname, 'packages'), - '@electron/shared': resolve(__dirname, 'electron/shared'), - '@electron/preload': resolve(__dirname, 'electron/preload'), + '@electron/shared': resolve(__dirname, 'apps/desktop/shared'), + '@electron/preload': resolve(__dirname, 'apps/desktop/preload'), }, }, define: {