@@ -59,6 +59,40 @@ export type GooseInspectorToolState = StreamToolState;
5959
6060export type GooseStreamStateMaps = StreamStateMaps < GooseInspectorToolState > ;
6161
62+ function resolveGooseToolResponseId ( block : {
63+ id ?: string ;
64+ tool_use_id ?: string ;
65+ } ) : string {
66+ if ( typeof block . id === "string" && block . id . trim ( ) ) {
67+ return block . id ;
68+ }
69+ if ( typeof block . tool_use_id === "string" && block . tool_use_id . trim ( ) ) {
70+ return block . tool_use_id ;
71+ }
72+ return "" ;
73+ }
74+
75+ function extractGooseToolResponseText ( value : unknown ) : string {
76+ if ( typeof value === "string" ) {
77+ return value . trim ( ) ;
78+ }
79+ if ( ! Array . isArray ( value ) ) {
80+ return "" ;
81+ }
82+ return value
83+ . filter ( ( entry ) => entry && typeof entry === "object" )
84+ . map ( ( entry ) => {
85+ const record = entry as { type ?: string ; text ?: string } ;
86+ if ( record . type === "text" && typeof record . text === "string" ) {
87+ return record . text ;
88+ }
89+ return "" ;
90+ } )
91+ . filter ( ( text ) => text . length > 0 )
92+ . join ( "\n" )
93+ . trim ( ) ;
94+ }
95+
6296function parseTodosFromGooseToolInput ( toolName : string , input : Record < string , unknown > | undefined ) : SessionTodo [ ] | undefined {
6397 const direct = parseTodosFromToolInput ( toolName , input ) ;
6498 if ( direct ) return direct ;
@@ -97,6 +131,9 @@ export function applyGooseRecordToState(
97131 const blocks = record . message ?. content ?? [ ] ;
98132
99133 if ( role === "assistant" ) {
134+ const messageCreatedAtMs = typeof record . message ?. created === "number"
135+ ? record . message . created * 1000
136+ : Date . now ( ) ;
100137 for ( const block of blocks ) {
101138 if ( block ?. type === "text" ) {
102139 const chunk = typeof block . text === "string" ? block . text : "" ;
@@ -138,7 +175,12 @@ export function applyGooseRecordToState(
138175 output : existing ?. output ,
139176 error : existing ?. error ,
140177 title : existing ?. title ,
141- metadata : existing ?. metadata ,
178+ metadata : {
179+ ...( existing ?. metadata ?? { } ) ,
180+ startedAtMs : typeof existing ?. metadata ?. startedAtMs === "number"
181+ ? existing . metadata . startedAtMs
182+ : messageCreatedAtMs ,
183+ } ,
142184 } ;
143185 toolById . set ( callId , tool ) ;
144186 updateTool ( state , tool ) ;
@@ -150,16 +192,12 @@ export function applyGooseRecordToState(
150192 if ( role === "user" ) {
151193 for ( const block of blocks ) {
152194 if ( block ?. type !== "toolResponse" ) continue ;
153- const callId = typeof block . id === "string" && block . id . trim ( ) ? block . id : "" ;
195+ const callId = resolveGooseToolResponseId ( block ) ;
154196 if ( ! callId ) continue ;
155197 const existing = toolById . get ( callId ) ;
156198 if ( ! existing ) continue ;
157199 const result = block . toolResult ?. value ;
158- const output = ( result ?. content ?? [ ] )
159- . filter ( ( entry ) => entry ?. type === "text" )
160- . map ( ( entry ) => entry . text ?? "" )
161- . join ( "\n" )
162- . trim ( ) ;
200+ const output = extractGooseToolResponseText ( result ?. content ) ;
163201 const hasError = result ?. isError === true || block . toolResult ?. status === "error" ;
164202 const updated : GooseInspectorToolState = {
165203 ...existing ,
0 commit comments