1- import type { ToolCallContent , ToolCallLocation , ToolKind } from "@agentclientprotocol/sdk"
1+ import type { ToolCall , ToolCallContent , ToolCallLocation , ToolCallUpdate , ToolKind } from "@agentclientprotocol/sdk"
22
33export type ToolInput = Record < string , unknown >
44
@@ -16,6 +16,19 @@ export type CompletedToolState = {
1616 readonly attachments ?: ReadonlyArray < ToolAttachment >
1717}
1818
19+ export type RunningToolState = {
20+ readonly status : "running"
21+ readonly input : ToolInput
22+ readonly title ?: string
23+ }
24+
25+ export type ErrorToolState = {
26+ readonly status : "error"
27+ readonly input : ToolInput
28+ readonly error : string
29+ readonly metadata ?: unknown
30+ }
31+
1932export type ImageAttachment = {
2033 readonly mimeType : string
2134 readonly data : string
@@ -100,6 +113,104 @@ export function completedToolContent(toolName: string, state: CompletedToolState
100113 return content
101114}
102115
116+ export function pendingToolCall ( input : { readonly toolCallId : string ; readonly toolName : string } ) : ToolCall {
117+ return {
118+ toolCallId : input . toolCallId ,
119+ title : input . toolName ,
120+ kind : toToolKind ( input . toolName ) ,
121+ status : "pending" ,
122+ locations : [ ] ,
123+ rawInput : { } ,
124+ }
125+ }
126+
127+ export function runningToolUpdate ( input : {
128+ readonly toolCallId : string
129+ readonly toolName : string
130+ readonly state : RunningToolState
131+ readonly output ?: string
132+ } ) : ToolCallUpdate {
133+ const content = input . output
134+ ? [
135+ {
136+ type : "content" as const ,
137+ content : {
138+ type : "text" as const ,
139+ text : input . output ,
140+ } ,
141+ } ,
142+ ]
143+ : undefined
144+
145+ return {
146+ toolCallId : input . toolCallId ,
147+ status : "in_progress" ,
148+ kind : toToolKind ( input . toolName ) ,
149+ title : input . state . title ?? input . toolName ,
150+ locations : toLocations ( input . toolName , input . state . input ) ,
151+ rawInput : input . state . input ,
152+ ...( content ? { content } : { } ) ,
153+ }
154+ }
155+
156+ export function duplicateRunningToolUpdate ( input : {
157+ readonly toolCallId : string
158+ readonly toolName : string
159+ readonly state : RunningToolState
160+ } ) : ToolCallUpdate {
161+ return {
162+ toolCallId : input . toolCallId ,
163+ status : "in_progress" ,
164+ kind : toToolKind ( input . toolName ) ,
165+ title : input . state . title ?? input . toolName ,
166+ locations : toLocations ( input . toolName , input . state . input ) ,
167+ rawInput : input . state . input ,
168+ }
169+ }
170+
171+ export function completedToolUpdate ( input : {
172+ readonly toolCallId : string
173+ readonly toolName : string
174+ readonly state : CompletedToolState & { readonly title : string }
175+ } ) : ToolCallUpdate {
176+ return {
177+ toolCallId : input . toolCallId ,
178+ status : "completed" ,
179+ kind : toToolKind ( input . toolName ) ,
180+ title : input . state . title ,
181+ content : completedToolContent ( input . toolName , input . state ) ,
182+ rawInput : input . state . input ,
183+ rawOutput : completedToolRawOutput ( input . state ) ,
184+ }
185+ }
186+
187+ export function errorToolUpdate ( input : {
188+ readonly toolCallId : string
189+ readonly toolName : string
190+ readonly state : ErrorToolState
191+ } ) : ToolCallUpdate {
192+ return {
193+ toolCallId : input . toolCallId ,
194+ status : "failed" ,
195+ kind : toToolKind ( input . toolName ) ,
196+ title : input . toolName ,
197+ rawInput : input . state . input ,
198+ content : [
199+ {
200+ type : "content" ,
201+ content : {
202+ type : "text" ,
203+ text : input . state . error ,
204+ } ,
205+ } ,
206+ ] ,
207+ rawOutput : {
208+ error : input . state . error ,
209+ metadata : input . state . metadata ,
210+ } ,
211+ }
212+ }
213+
103214export function completedToolRawOutput ( state : CompletedToolState ) {
104215 return {
105216 output : state . output ,
@@ -138,6 +249,11 @@ export const extractLocations = toLocations
138249export const buildCompletedToolContent = completedToolContent
139250export const buildCompletedRawOutput = completedToolRawOutput
140251export const extractShellOutputSnapshot = shellOutputSnapshot
252+ export const buildPendingToolCall = pendingToolCall
253+ export const buildRunningToolUpdate = runningToolUpdate
254+ export const buildDuplicateRunningToolUpdate = duplicateRunningToolUpdate
255+ export const buildCompletedToolUpdate = completedToolUpdate
256+ export const buildErrorToolUpdate = errorToolUpdate
141257
142258function locationFrom ( value : unknown ) : ToolCallLocation [ ] {
143259 const path = stringValue ( value )
0 commit comments