* 创建新 session
(title?: string)
| 116 | * 创建新 Session |
| 117 | */ |
| 118 | async createSession(title?: string): Promise<SessionMeta> { |
| 119 | const id = this.generateId(); |
| 120 | const now = new Date().toISOString(); |
| 121 | |
| 122 | const meta: SessionMeta = { |
| 123 | id, |
| 124 | title: title || '新对话', |
| 125 | summary: '', |
| 126 | createdAt: now, |
| 127 | updatedAt: now, |
| 128 | messageCount: 0, |
| 129 | isActive: true, |
| 130 | }; |
| 131 | |
| 132 | // 创建空的 Session 文件 |
| 133 | fs.writeFileSync(this.getSessionPath(id), ''); |
| 134 | |
| 135 | // 更新索引 |
| 136 | const index = this.readIndex(); |
| 137 | index.sessions.unshift(meta); |
| 138 | this.writeIndex(index); |
| 139 | |
| 140 | return meta; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * 获取 Session 列表 |
no test coverage detected