forked from sanbuphy/learn-coding-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdkProgress.ts
More file actions
36 lines (35 loc) · 1.13 KB
/
sdkProgress.ts
File metadata and controls
36 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { SdkWorkflowProgress } from '../../types/tools.js'
import { enqueueSdkEvent } from '../sdkEventQueue.js'
/**
* Emit a `task_progress` SDK event. Shared by background agents (per tool_use
* in runAsyncAgentLifecycle) and workflows (per flushProgress batch). Accepts
* already-computed primitives so callers can derive them from their own state
* shapes (ProgressTracker for agents, LocalWorkflowTaskState for workflows).
*/
export function emitTaskProgress(params: {
taskId: string
toolUseId: string | undefined
description: string
startTime: number
totalTokens: number
toolUses: number
lastToolName?: string
summary?: string
workflowProgress?: SdkWorkflowProgress[]
}): void {
enqueueSdkEvent({
type: 'system',
subtype: 'task_progress',
task_id: params.taskId,
tool_use_id: params.toolUseId,
description: params.description,
usage: {
total_tokens: params.totalTokens,
tool_uses: params.toolUses,
duration_ms: Date.now() - params.startTime,
},
last_tool_name: params.lastToolName,
summary: params.summary,
workflow_progress: params.workflowProgress,
})
}