* Gets recent runs for an agent from IterationStore * @param agentId Agent ID * @param count Number of recent runs to fetch * @returns Array of recent iteration data
(agentId: string, count: number)
| 234 | * @returns Array of recent iteration data |
| 235 | */ |
| 236 | async function getRecentAgentRuns(agentId: string, count: number): Promise<IterationData[]> { |
| 237 | // Get current session runs |
| 238 | const currentRuns = IterationStore.getIterationsForAgent(agentId); |
| 239 | |
| 240 | // Get historical runs if we need more |
| 241 | if (currentRuns.length >= count) { |
| 242 | return currentRuns.slice(-count); // Get last N runs |
| 243 | } |
| 244 | |
| 245 | // Need to get historical data |
| 246 | const historicalSessions = await IterationStore.getHistoricalSessions(agentId); |
| 247 | const allRuns: IterationData[] = [...currentRuns]; |
| 248 | |
| 249 | // Add runs from most recent sessions until we have enough |
| 250 | for (const session of historicalSessions) { |
| 251 | const needed = count - allRuns.length; |
| 252 | const sessionRuns = session.iterations.slice(-needed); // Take LAST needed iterations |
| 253 | allRuns.unshift(...sessionRuns); |
| 254 | |
| 255 | if (allRuns.length >= count) break; |
| 256 | } |
| 257 | |
| 258 | return allRuns.slice(-count); // Return last N runs |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Fetches complete agent reference data |
no test coverage detected