(agentId: AgentId)
| 4188 | * or null if not found |
| 4189 | */ |
| 4190 | export async function getAgentTranscript(agentId: AgentId): Promise<{ |
| 4191 | messages: Message[] |
| 4192 | contentReplacements: ContentReplacementRecord[] |
| 4193 | } | null> { |
| 4194 | const agentFile = getAgentTranscriptPath(agentId) |
| 4195 | |
| 4196 | try { |
| 4197 | const { messages, agentContentReplacements } = |
| 4198 | await loadTranscriptFile(agentFile) |
| 4199 | |
| 4200 | // Find messages with matching agentId |
| 4201 | const agentMessages = Array.from(messages.values()).filter( |
| 4202 | msg => msg.agentId === agentId && msg.isSidechain, |
| 4203 | ) |
| 4204 | |
| 4205 | if (agentMessages.length === 0) { |
| 4206 | return null |
| 4207 | } |
| 4208 | |
| 4209 | // Find the most recent leaf message with this agentId |
| 4210 | const parentUuids = new Set(agentMessages.map(msg => msg.parentUuid)) |
| 4211 | const leafMessage = findLatestMessage( |
| 4212 | agentMessages, |
| 4213 | msg => !parentUuids.has(msg.uuid), |
| 4214 | ) |
| 4215 | |
| 4216 | if (!leafMessage) { |
| 4217 | return null |
| 4218 | } |
| 4219 | |
| 4220 | // Build the conversation chain |
| 4221 | const transcript = buildConversationChain(messages, leafMessage) |
| 4222 | |
| 4223 | // Filter to only include messages with this agentId |
| 4224 | const agentTranscript = transcript.filter(msg => msg.agentId === agentId) |
| 4225 | |
| 4226 | return { |
| 4227 | // Convert TranscriptMessage[] to Message[] |
| 4228 | messages: agentTranscript.map( |
| 4229 | ({ isSidechain, parentUuid, ...msg }) => msg, |
| 4230 | ), |
| 4231 | contentReplacements: agentContentReplacements.get(agentId) ?? [], |
| 4232 | } |
| 4233 | } catch { |
| 4234 | return null |
| 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | /** |
| 4239 | * Extract agent IDs from progress messages in the conversation. |
no test coverage detected