The monolithic frontend/core/chatCore.js
(1310 lines) has been successfully refactored into modular TypeScript files. This improves maintainability, type safety, and reduces the chance of bugs (like the reasoning persistence issue).
initDb
, AppState
, DexieDatabase
slugifyTitle
utilityloadSessions
/ loadChats
- Load session listloadSession
- Load a single session with tree/branch supportsaveSession
- CRITICAL - Saves session with reasoning persistencecreateNewChat
, selectChat
, deleteChat
, duplicateChat
moveChatToFolder
, baseChats
, chatsInFolder
loadFolders
, createFolder
, toggleFolderCollapsed
startEditingFolder
, commitEditingFolder
, cancelEditingFolder
ensureChatExistsForEdits
- Creates session when neededpersistMessageAtIndex
- Persists individual messagedeleteMessage
, deleteMessagesBelow
rerunFromUser
, rerunAssistant
- Handles branching in sessions modeexportAllData
- Exports entire databaseimportDataReplace
- Replace all data with importimportDataAppend
- Append imported datachatCore.js
JobManager
Session
, Message
, Branch
, SessionTree
, UIMessage
, AppState
messageToUIMessage
, createDefaultSessionTree
, getNextMessageId
, etc.frontend/core/chatCore.js
(replaced by modular TypeScript files)frontend/core/jobManager.js
(converted to .ts
)frontend/core/branchManager.js
(converted to .ts
)frontend/experimental/streaming.js
(converted to .ts
)frontend/chatterApp.js
- Updated imports to use './core/index.ts'
frontend/dataIO.js
- Updated imports to use './core/index.ts'
frontend/types.ts
- Added helper functionsdeno.json
- Updated for TypeScript supportThe refactoring directly addresses the reasoning persistence bug by:
types.ts
saveSession
in sessions.ts
explicitly handle m.reasoning != null ? String(m.reasoning) : undefined
streaming.ts
updates state.messages[idx].reasoning
during streamingloadSession
populate state.messageReasoningMap
from session treechatterApp.js
to TypeScript (1890 lines - large task)