( taskId: string, setAppState: SetAppState, )
| 268 | * Returns the task's accumulated messages, or undefined if task not found. |
| 269 | */ |
| 270 | export function foregroundMainSessionTask( |
| 271 | taskId: string, |
| 272 | setAppState: SetAppState, |
| 273 | ): Message[] | undefined { |
| 274 | let taskMessages: Message[] | undefined |
| 275 | |
| 276 | setAppState(prev => { |
| 277 | const task = prev.tasks[taskId] |
| 278 | if (!task || task.type !== 'local_agent') { |
| 279 | return prev |
| 280 | } |
| 281 | |
| 282 | taskMessages = (task as LocalMainSessionTaskState).messages |
| 283 | |
| 284 | // Restore previous foregrounded task to background if it exists |
| 285 | const prevId = prev.foregroundedTaskId |
| 286 | const prevTask = prevId ? prev.tasks[prevId] : undefined |
| 287 | const restorePrev = |
| 288 | prevId && prevId !== taskId && prevTask?.type === 'local_agent' |
| 289 | |
| 290 | return { |
| 291 | ...prev, |
| 292 | foregroundedTaskId: taskId, |
| 293 | tasks: { |
| 294 | ...prev.tasks, |
| 295 | ...(restorePrev && { [prevId]: { ...prevTask, isBackgrounded: true } }), |
| 296 | [taskId]: { ...task, isBackgrounded: false }, |
| 297 | }, |
| 298 | } |
| 299 | }) |
| 300 | |
| 301 | return taskMessages |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Check if a task is a main session task (vs a regular agent task). |
nothing calls this directly
no test coverage detected