(taskId: string, summary: string, setAppState: SetAppState)
| 357 | * Called by the periodic summarization service to store a 1-2 sentence progress summary. |
| 358 | */ |
| 359 | export function updateAgentSummary(taskId: string, summary: string, setAppState: SetAppState): void { |
| 360 | let captured: { |
| 361 | tokenCount: number; |
| 362 | toolUseCount: number; |
| 363 | startTime: number; |
| 364 | toolUseId: string | undefined; |
| 365 | } | null = null; |
| 366 | updateTaskState<LocalAgentTaskState>(taskId, setAppState, task => { |
| 367 | if (task.status !== 'running') { |
| 368 | return task; |
| 369 | } |
| 370 | captured = { |
| 371 | tokenCount: task.progress?.tokenCount ?? 0, |
| 372 | toolUseCount: task.progress?.toolUseCount ?? 0, |
| 373 | startTime: task.startTime, |
| 374 | toolUseId: task.toolUseId |
| 375 | }; |
| 376 | return { |
| 377 | ...task, |
| 378 | progress: { |
| 379 | ...task.progress, |
| 380 | toolUseCount: task.progress?.toolUseCount ?? 0, |
| 381 | tokenCount: task.progress?.tokenCount ?? 0, |
| 382 | summary |
| 383 | } |
| 384 | }; |
| 385 | }); |
| 386 | |
| 387 | // Emit summary to SDK consumers (e.g. VS Code subagent panel). No-op in TUI. |
| 388 | // Gate on the SDK option so coordinator-mode sessions without the flag don't |
| 389 | // leak summary events to consumers who didn't opt in. |
| 390 | if (captured && getSdkAgentProgressSummariesEnabled()) { |
| 391 | const { |
| 392 | tokenCount, |
| 393 | toolUseCount, |
| 394 | startTime, |
| 395 | toolUseId |
| 396 | } = captured; |
| 397 | emitTaskProgress({ |
| 398 | taskId, |
| 399 | toolUseId, |
| 400 | description: summary, |
| 401 | startTime, |
| 402 | totalTokens: tokenCount, |
| 403 | toolUses: toolUseCount, |
| 404 | summary |
| 405 | }); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Complete an agent task with result. |
no test coverage detected