| 90 | |
| 91 | // Save current session state |
| 92 | save(messages, metadata = {}) { |
| 93 | if (!this.current) return; |
| 94 | this.current.messages = messages; |
| 95 | this.current.updatedAt = new Date().toISOString(); |
| 96 | if (metadata.tokens) this.current.tokens = metadata.tokens; |
| 97 | if (metadata.cost) this.current.cost = metadata.cost; |
| 98 | if (metadata.toolCalls) this.current.toolCalls = metadata.toolCalls; |
| 99 | if (metadata.title) this.current.title = metadata.title; |
| 100 | this._save(this.current); |
| 101 | } |
| 102 | |
| 103 | // Auto-title from first user message |
| 104 | autoTitle(messages) { |