( currentIterations: IterationData[], historicalSessions: AgentSession[], options: ExportOptions )
| 418 | |
| 419 | // Main export function |
| 420 | export const exportData = async ( |
| 421 | currentIterations: IterationData[], |
| 422 | historicalSessions: AgentSession[], |
| 423 | options: ExportOptions |
| 424 | ): Promise<void> => { |
| 425 | let exportData: ExportData; |
| 426 | let filename: string; |
| 427 | |
| 428 | // Prepare data based on session type |
| 429 | switch (options.sessionType) { |
| 430 | case 'current': |
| 431 | exportData = { |
| 432 | agentId: options.agentId, |
| 433 | exportDate: new Date().toISOString(), |
| 434 | sessionType: 'current', |
| 435 | currentSession: currentIterations, |
| 436 | totalIterations: currentIterations.length |
| 437 | }; |
| 438 | filename = `observer-${options.agentId}-current-${new Date().toISOString().split('T')[0]}`; |
| 439 | break; |
| 440 | |
| 441 | case 'historical': |
| 442 | const selectedSession = historicalSessions.find(s => s.sessionId === options.sessionId); |
| 443 | if (!selectedSession) { |
| 444 | throw new Error('Selected historical session not found'); |
| 445 | } |
| 446 | exportData = { |
| 447 | agentId: options.agentId, |
| 448 | exportDate: new Date().toISOString(), |
| 449 | sessionType: 'historical', |
| 450 | historicalSessions: [selectedSession], |
| 451 | totalIterations: selectedSession.iterations.length |
| 452 | }; |
| 453 | filename = `observer-${options.agentId}-session-${selectedSession.sessionId.slice(-8)}-${new Date().toISOString().split('T')[0]}`; |
| 454 | break; |
| 455 | |
| 456 | case 'all': |
| 457 | default: |
| 458 | exportData = { |
| 459 | agentId: options.agentId, |
| 460 | exportDate: new Date().toISOString(), |
| 461 | sessionType: 'all', |
| 462 | currentSession: currentIterations.length > 0 ? currentIterations : undefined, |
| 463 | historicalSessions: historicalSessions.length > 0 ? historicalSessions : undefined, |
| 464 | totalIterations: currentIterations.length + historicalSessions.reduce((sum, s) => sum + s.iterations.length, 0) |
| 465 | }; |
| 466 | filename = `observer-${options.agentId}-all-${new Date().toISOString().split('T')[0]}`; |
| 467 | break; |
| 468 | } |
| 469 | |
| 470 | // Generate content based on format |
| 471 | let content: string; |
| 472 | let mimeType: string; |
| 473 | let extension: string; |
| 474 | |
| 475 | switch (options.format) { |
| 476 | case 'json': |
| 477 | content = exportAsJSON(exportData, options); |
no test coverage detected