(projectCwd: string)
| 59 | * Must be called before the server starts. |
| 60 | */ |
| 61 | export function initSession(projectCwd: string): void { |
| 62 | _projectCwd = projectCwd; |
| 63 | const filePath = sessionPath(); |
| 64 | if (!filePath || !existsSync(filePath)) return; |
| 65 | try { |
| 66 | const raw = readFileSync(filePath, 'utf-8'); |
| 67 | const persisted: PersistedSession = JSON.parse(raw); |
| 68 | if (persisted.modelId && persisted.modelProvider && Array.isArray(persisted.messages)) { |
| 69 | const { provider } = resolveProvider(persisted.modelId, persisted.modelProvider); |
| 70 | session = { |
| 71 | modelId: persisted.modelId, |
| 72 | modelProvider: persisted.modelProvider, |
| 73 | provider, |
| 74 | messages: persisted.messages, |
| 75 | }; |
| 76 | } |
| 77 | } catch { |
| 78 | // Corrupt file — start fresh |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the existing session if the model matches, otherwise creates a new |
no test coverage detected