Move AI-related translations (tools, agent prompts, LLM, summary) from
Electron-specific locale files into @openchatlab/node-runtime, enabling
single-source maintenance across Electron and Server.
- Add packages/node-runtime/src/ai/i18n/ with createAiTranslate() and
bundled locale data (zh-CN, en-US, ja-JP, zh-TW)
- Electron locale files now compose: Electron-specific keys + shared AI
translations from node-runtime
- Server agent.ts switches to shared buildSystemPrompt with evidence
policy, data snapshot injection, ownerInfo and mentionedMembers support
- Server route fetches dataSnapshot from getChatOverview before agent run
- Extract JSON cache CRUD + overview/members compute to node-runtime/cache
- Functions now accept DatabaseAdapter instead of better-sqlite3 Database
- Electron sessionCache.ts becomes pure re-export
- Updated all Electron callers to wrap DB with BetterSqliteAdapter
- Extract migration definitions (v1-v4) to shared getChatDbMigrations() with DI for tokenizer
- DatabaseManager.openWritable() auto-runs pending migrations
- Electron migrations.ts becomes thin wrapper delegating to shared definitions
After streaming or incremental import, automatically generate the
session index (chat_session table) so the frontend does not show
the "generate index" prompt when entering a conversation.
- Replace buffered import with high-performance streaming pipeline
- Add POST /_web/sessions/:id/import/incremental (SSE)
- Add POST /_web/sessions/:id/import/incremental/analyze
- Add POST /_web/import/analyze (dry-run)
- CLI import now reports diagnostics from StreamingImporter
Platform-agnostic temp DB management for merge operations using
DatabaseAdapter. Includes TempDbWriter (streaming write), TempDbReader
(streaming read + MergerDataSource adapter), exportSessionToJson,
and cleanup helpers.
Platform-agnostic incremental import with dual-path dedup
(platformMessageId + content hash), member upsert, meta patching,
FTS sync, and injectable dependencies (IncrementalImportDeps).
Platform-agnostic streaming import with batched transactions, deferred
indexes, nickname history tracking, FTS indexing, and format fallback.
All Electron-specific dependencies replaced with injectable interfaces
(StreamImportDeps, ImportLogger, ImportProgressCallback).
encryptApiKey/decryptApiKey and device key management have zero
importers — legacy functionality already handled by
@openchatlab/config/migrations/crypto-legacy. Removes ~278 lines.
Move the entire RAG module (~2458 lines) from electron/main/ai/rag/ to
@openchatlab/node-runtime. Includes chunking, embedding, vector store,
and semantic pipeline.
Key changes:
- Config operations use injected aiDataDir instead of getAiDataDir()
- Logger uses injectable RagLogger interface
- LLM config provided via getLLMConfig/getAssistantConfig callbacks
- Deduplicated cosineSimilarity into shared utils.ts
- Electron rag/index.ts is now a thin wrapper (~128 lines)
Replace ~120 lines of inline SQL in server stream-import.ts and ~60 lines
in importer.ts fullImport with calls to shared writeParseResultToDb from
@openchatlab/node-runtime. Server imports now gain name history tracking
that was previously Electron-only.
Move performance logging from electron/main/worker/core/perfLogger.ts to
@openchatlab/node-runtime. Log directory is now caller-provided instead
of derived from Electron paths. Electron wrapper provides the path.
Reduces Electron perfLogger from ~181 lines to ~28 lines.
Move core FTS operations (create, build, rebuild, insert, search) to
@openchatlab/node-runtime working with DatabaseAdapter. Electron fts.ts
becomes a thin adapter that adds session-level DB connection management.
Reduces Electron fts.ts from ~207 lines to ~90 lines of pure wrappers.
Move pure SQL session CRUD operations (owner_id update, rename) to the
shared core package as DatabaseAdapter functions. Electron wrappers now
delegate to core, keeping only connection management and error handling.
Move the core data writing logic (meta/member/message insertion with
member_name_history tracking) from electron/main/database/core.ts to
@openchatlab/node-runtime. Electron importData() now delegates to the
shared function via BetterSqliteAdapter, reducing ~130 lines to ~10.
This enables both Electron and Server to share the same import logic
including name history tracking.
Replace Electron's independent migration runner with core's runMigrations
engine. Migration scripts stay in Electron layer (they depend on NLP
tokenizer and i18n), but execution logic (version check, transaction,
version bump) is now delegated to the shared framework.
- Re-export CURRENT_SCHEMA_VERSION from @openchatlab/core
- Wrap better-sqlite3 Database in BetterSqliteAdapter for core compat
- Convert migration up() signatures to accept DatabaseAdapter
- Remove ~100 lines of duplicated migration infrastructure
Remove ~76 lines of duplicated CREATE TABLE/INDEX/FTS SQL from
database/core.ts createDatabase(), delegating to CHAT_DB_SCHEMA and
FTS_TABLE_SCHEMA from @openchatlab/core — the single source of truth.
The generateMessageKey function used crypto.createHash (Node.js only),
causing Vite browser externalization error. Replaced with pure-JS FNV-1a
64-bit hash that works in both Node.js and browser environments.
Co-authored-by: Cursor <cursoragent@cursor.com>
Platform-agnostic skill CRUD manager with dependency injection for file
system ops, builtin skill resources, and content hashing. Supports init,
CRUD, builtin import/reimport, cloud markdown import, and AI skill menu
generation.
Co-authored-by: Cursor <cursoragent@cursor.com>
Platform-agnostic AssistantManager with dependency injection for file
system ops, builtin configs, and ID generation. Supports init, CRUD,
builtin import/reimport/reset, and cloud markdown import.
Co-authored-by: Cursor <cursoragent@cursor.com>
Introduce ConfigStorage abstraction and LLMConfigStore class with
dependency injection for i18n, UUID generation, and auth profile hooks.
All CRUD operations (add/update/delete/slots) are platform-agnostic.
Electron can implement ConfigStorage with fs + getAiDataDir.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move platform ID collision detection, normalization, conflict detection,
member merge, and message dedup-sort from electron/main/merger to a
shared package with zero Node.js dependencies.
Also fix pre-existing unused-variable TS errors in summary test.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move session summary generation (573 lines) to shared package with
SummaryDeps injection for DB/LLM/i18n. Pure algorithms (isValidMessage,
filterValidMessages, splitIntoSegments, prompt builders) are now shared.
Electron summary/index.ts implements SummaryDeps and delegates.
Added 14 unit tests covering message filtering, segmentation,
summary generation, and eligibility checks.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move AgentEventHandler, TokenUsage, AgentRuntimeStatus, AgentStreamChunk
to packages/node-runtime/src/ai/agent/event-handler.ts.
Token estimation and event-to-chunk mapping are now shared.
Electron agent/types.ts re-exports from node-runtime.
Added 8 unit tests covering token estimation, tool tracking, usage cloning.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move buildSystemPrompt from electron/main/ai/agent/ to shared package.
i18n t() is now injected via BuildSystemPromptOptions parameter.
Types OwnerInfo, MentionedMember, SkillContext are shared.
Electron prompt-builder.ts injects its own t() and delegates.
Added 8 unit tests with mock translation function.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move mergeMembers, deleteMember, updateMemberAliases, ensureAliasesColumn,
ensureAvatarColumn to packages/core/src/query/member-ops.ts.
All functions accept DatabaseAdapter. Electron basic.ts now wraps raw
Database with BetterSqliteAdapter and delegates to core.
Added 8 unit tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move filterMessagesWithContext and getMultipleSessionsMessages to
packages/core/src/query/filter.ts. Functions now accept DatabaseAdapter
instead of raw better-sqlite3 Database. Types FilterMessage, ContextBlock,
PaginationInfo, FilterResultWithPagination moved to core.
Electron filter.ts is now a thin wrapper that opens DB and delegates.
Added 6 unit tests with mock DatabaseAdapter.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move tokenizeForFts and tokenizeQueryForFts from electron/main/nlp/ to
packages/node-runtime/src/nlp/fts-tokenizer.ts. Uses the already-shared
getJieba() internally. Electron ftsTokenizer.ts now re-exports.
Added 9 unit tests.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move extractThinkingContent and stripToolCallTags (pure string algorithms
with zero deps) from electron/main/ai/agent/ to packages/core/src/ai/.
Electron agent now imports from @openchatlab/core.
Added 12 unit tests covering all parsing paths.
Co-authored-by: Cursor <cursoragent@cursor.com>
All analysis queries have been migrated to @openchatlab/core and are
consumed via Worker query modules and Server routes. This file had
zero imports and was fully superseded.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move remote LLM API operations into shared module with optional
headers and logger injection. Electron wraps with UA headers and
aiLogger; server re-exports directly.
Co-authored-by: Cursor <cursoragent@cursor.com>
Move URL normalization helpers and PiModel construction into a shared
llm-builder module. Electron and server both delegate to the core
builder, with Electron adding optional headers and provider validation.
Co-authored-by: Cursor <cursoragent@cursor.com>
Eliminate duplicate buildMemberIdMap in server importer and
stream-import. Core function uses DatabaseAdapter interface.
Co-authored-by: Cursor <cursoragent@cursor.com>
Extract canonical generateMessageKey (SHA-256 + base64url) into core.
Electron tempDb, merger, and server importer now share the same
algorithm, eliminating the server's divergent hex-truncated variant.
Co-authored-by: Cursor <cursoragent@cursor.com>
Split CHAT_DB_SCHEMA into CHAT_DB_TABLES and CHAT_DB_INDEXES constants.
Electron import utils now uses core definitions, eliminating schema drift.
Co-authored-by: Cursor <cursoragent@cursor.com>
Align searchSessions and getSessionMessages in @openchatlab/core with
Electron's richer return shape and FTS support:
- Add senderId, senderPlatformId to SessionPreviewMessage type and SQL
- Add optional ftsMatchExpression param to searchSessions for FTS path
- Electron aiTools.ts: delegates to core with FTS tokenization at edge
- Electron types.ts: re-export SessionSearchResultItem/SessionMessagesResult from core
- workerManager.ts: remove duplicate type definitions, re-export from session module
Co-authored-by: Cursor <cursoragent@cursor.com>
Extract duplicated member list/pagination logic from electron/main/worker/query/basic.ts
and packages/server/src/http/routes/web.ts into shared core functions.
- Add getMembersPaginated with search, sort, pagination to core
- Extend MemberWithAliases type with avatar field
- Extend getMembersWithAliases with avatar column detection
- Electron basic.ts: getMemberNameHistory, getMembers, getMembersPaginated delegate to core
- Server web.ts: /_web/members and /_web/members/paginated both delegate to core
- Retain Electron-only schema migrations and member DML operations
- Add 14 unit tests covering aliases/avatar presence, pagination, search, sort, system filter
Co-authored-by: Cursor <cursoragent@cursor.com>
Extract duplicated 12-column message SELECT, types, and row mapper into
@openchatlab/core/query/message-sql.ts as single source of truth.
Migrate Electron worker, CLI Web FetchMessageAdapter, filter.ts, and
core hydrateMessagesByIds to use shared FULL_MSG_SELECT + mapMessageRow.
Remove DbMessageRow, sanitizeMessageRow, and all inline SQL duplicates.