(sessionId: string)
| 77 | } |
| 78 | |
| 79 | refreshSession(sessionId: string): Session | null { |
| 80 | let stored = this.store.sessions.getSession(sessionId) |
| 81 | if (!stored) { |
| 82 | const existed = this.sessions.delete(sessionId) |
| 83 | this.pendingThinkingUntilBySessionId.delete(sessionId) |
| 84 | this.runtimeConfigUpdatedAtBySessionId.delete(sessionId) |
| 85 | if (existed) { |
| 86 | this.publisher.emit({ type: 'session-removed', sessionId }) |
| 87 | } |
| 88 | return null |
| 89 | } |
| 90 | |
| 91 | const existing = this.sessions.get(sessionId) |
| 92 | |
| 93 | if (stored.todos === null && !this.todoBackfillAttemptedSessionIds.has(sessionId)) { |
| 94 | this.todoBackfillAttemptedSessionIds.add(sessionId) |
| 95 | const messages = this.store.messages.getMessages(sessionId, 200) |
| 96 | for (let i = messages.length - 1; i >= 0; i -= 1) { |
| 97 | const message = messages[i] |
| 98 | const todos = extractTodoWriteTodosFromMessageContent(message.content) |
| 99 | if (todos) { |
| 100 | const updated = this.store.sessions.setSessionTodos(sessionId, todos, message.createdAt, stored.namespace) |
| 101 | if (updated) { |
| 102 | stored = this.store.sessions.getSession(sessionId) ?? stored |
| 103 | } |
| 104 | break |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | const metadata = (() => { |
| 110 | const parsed = MetadataSchema.safeParse(stored.metadata) |
| 111 | return parsed.success ? parsed.data : null |
| 112 | })() |
| 113 | |
| 114 | const agentState = (() => { |
| 115 | const parsed = AgentStateSchema.safeParse(stored.agentState) |
| 116 | return parsed.success ? parsed.data : null |
| 117 | })() |
| 118 | |
| 119 | const todos = (() => { |
| 120 | if (stored.todos === null) return undefined |
| 121 | const parsed = TodosSchema.safeParse(stored.todos) |
| 122 | return parsed.success ? parsed.data : undefined |
| 123 | })() |
| 124 | |
| 125 | const teamState = (() => { |
| 126 | if (stored.teamState === null || stored.teamState === undefined) return undefined |
| 127 | const parsed = TeamStateSchema.safeParse(stored.teamState) |
| 128 | return parsed.success ? parsed.data : undefined |
| 129 | })() |
| 130 | |
| 131 | const session: Session = { |
| 132 | id: stored.id, |
| 133 | namespace: stored.namespace, |
| 134 | seq: stored.seq, |
| 135 | createdAt: stored.createdAt, |
| 136 | updatedAt: stored.updatedAt, |
no test coverage detected