@@ -17,71 +17,6 @@ export namespace MessageV2 {
1717 } ) ,
1818 )
1919
20- export const ToolStatePending = z
21- . object ( {
22- status : z . literal ( "pending" ) ,
23- } )
24- . meta ( {
25- ref : "ToolStatePending" ,
26- } )
27-
28- export type ToolStatePending = z . infer < typeof ToolStatePending >
29-
30- export const ToolStateRunning = z
31- . object ( {
32- status : z . literal ( "running" ) ,
33- input : z . any ( ) ,
34- title : z . string ( ) . optional ( ) ,
35- metadata : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
36- time : z . object ( {
37- start : z . number ( ) ,
38- } ) ,
39- } )
40- . meta ( {
41- ref : "ToolStateRunning" ,
42- } )
43- export type ToolStateRunning = z . infer < typeof ToolStateRunning >
44-
45- export const ToolStateCompleted = z
46- . object ( {
47- status : z . literal ( "completed" ) ,
48- input : z . record ( z . string ( ) , z . any ( ) ) ,
49- output : z . string ( ) ,
50- title : z . string ( ) ,
51- metadata : z . record ( z . string ( ) , z . any ( ) ) ,
52- time : z . object ( {
53- start : z . number ( ) ,
54- end : z . number ( ) ,
55- compacted : z . number ( ) . optional ( ) ,
56- } ) ,
57- } )
58- . meta ( {
59- ref : "ToolStateCompleted" ,
60- } )
61- export type ToolStateCompleted = z . infer < typeof ToolStateCompleted >
62-
63- export const ToolStateError = z
64- . object ( {
65- status : z . literal ( "error" ) ,
66- input : z . record ( z . string ( ) , z . any ( ) ) ,
67- error : z . string ( ) ,
68- metadata : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
69- time : z . object ( {
70- start : z . number ( ) ,
71- end : z . number ( ) ,
72- } ) ,
73- } )
74- . meta ( {
75- ref : "ToolStateError" ,
76- } )
77- export type ToolStateError = z . infer < typeof ToolStateError >
78-
79- export const ToolState = z
80- . discriminatedUnion ( "status" , [ ToolStatePending , ToolStateRunning , ToolStateCompleted , ToolStateError ] )
81- . meta ( {
82- ref : "ToolState" ,
83- } )
84-
8520 const PartBase = z . object ( {
8621 id : z . string ( ) ,
8722 sessionID : z . string ( ) ,
@@ -134,17 +69,6 @@ export namespace MessageV2 {
13469 } )
13570 export type ReasoningPart = z . infer < typeof ReasoningPart >
13671
137- export const ToolPart = PartBase . extend ( {
138- type : z . literal ( "tool" ) ,
139- callID : z . string ( ) ,
140- tool : z . string ( ) ,
141- state : ToolState ,
142- metadata : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
143- } ) . meta ( {
144- ref : "ToolPart" ,
145- } )
146- export type ToolPart = z . infer < typeof ToolPart >
147-
14872 const FilePartSourceBase = z . object ( {
14973 text : z
15074 . object ( {
@@ -228,6 +152,83 @@ export namespace MessageV2 {
228152 } )
229153 export type StepFinishPart = z . infer < typeof StepFinishPart >
230154
155+ export const ToolStatePending = z
156+ . object ( {
157+ status : z . literal ( "pending" ) ,
158+ } )
159+ . meta ( {
160+ ref : "ToolStatePending" ,
161+ } )
162+
163+ export type ToolStatePending = z . infer < typeof ToolStatePending >
164+
165+ export const ToolStateRunning = z
166+ . object ( {
167+ status : z . literal ( "running" ) ,
168+ input : z . any ( ) ,
169+ title : z . string ( ) . optional ( ) ,
170+ metadata : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
171+ time : z . object ( {
172+ start : z . number ( ) ,
173+ } ) ,
174+ } )
175+ . meta ( {
176+ ref : "ToolStateRunning" ,
177+ } )
178+ export type ToolStateRunning = z . infer < typeof ToolStateRunning >
179+
180+ export const ToolStateCompleted = z
181+ . object ( {
182+ status : z . literal ( "completed" ) ,
183+ input : z . record ( z . string ( ) , z . any ( ) ) ,
184+ output : z . string ( ) ,
185+ title : z . string ( ) ,
186+ metadata : z . record ( z . string ( ) , z . any ( ) ) ,
187+ time : z . object ( {
188+ start : z . number ( ) ,
189+ end : z . number ( ) ,
190+ compacted : z . number ( ) . optional ( ) ,
191+ } ) ,
192+ attachments : FilePart . array ( ) . optional ( ) ,
193+ } )
194+ . meta ( {
195+ ref : "ToolStateCompleted" ,
196+ } )
197+ export type ToolStateCompleted = z . infer < typeof ToolStateCompleted >
198+
199+ export const ToolStateError = z
200+ . object ( {
201+ status : z . literal ( "error" ) ,
202+ input : z . record ( z . string ( ) , z . any ( ) ) ,
203+ error : z . string ( ) ,
204+ metadata : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
205+ time : z . object ( {
206+ start : z . number ( ) ,
207+ end : z . number ( ) ,
208+ } ) ,
209+ } )
210+ . meta ( {
211+ ref : "ToolStateError" ,
212+ } )
213+ export type ToolStateError = z . infer < typeof ToolStateError >
214+
215+ export const ToolState = z
216+ . discriminatedUnion ( "status" , [ ToolStatePending , ToolStateRunning , ToolStateCompleted , ToolStateError ] )
217+ . meta ( {
218+ ref : "ToolState" ,
219+ } )
220+
221+ export const ToolPart = PartBase . extend ( {
222+ type : z . literal ( "tool" ) ,
223+ callID : z . string ( ) ,
224+ tool : z . string ( ) ,
225+ state : ToolState ,
226+ metadata : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
227+ } ) . meta ( {
228+ ref : "ToolPart" ,
229+ } )
230+ export type ToolPart = z . infer < typeof ToolPart >
231+
231232 const Base = z . object ( {
232233 id : z . string ( ) ,
233234 sessionID : z . string ( ) ,
@@ -531,7 +532,25 @@ export namespace MessageV2 {
531532 } ,
532533 ]
533534 if ( part . type === "tool" ) {
534- if ( part . state . status === "completed" )
535+ if ( part . state . status === "completed" ) {
536+ if ( part . state . attachments ?. length ) {
537+ result . push ( {
538+ id : Identifier . ascending ( "message" ) ,
539+ role : "user" ,
540+ parts : [
541+ {
542+ type : "text" ,
543+ text : `Tool ${ part . tool } returned an attachment:` ,
544+ } ,
545+ ...part . state . attachments . map ( ( attachment ) => ( {
546+ type : "file" as const ,
547+ url : attachment . url ,
548+ mediaType : attachment . mime ,
549+ filename : attachment . filename ,
550+ } ) ) ,
551+ ] ,
552+ } )
553+ }
535554 return [
536555 {
537556 type : ( "tool-" + part . tool ) as `tool-${string } `,
@@ -542,6 +561,7 @@ export namespace MessageV2 {
542561 callProviderMetadata : part . metadata ,
543562 } ,
544563 ]
564+ }
545565 if ( part . state . status === "error" )
546566 return [
547567 {
0 commit comments