File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export type ThinkingValue = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" ;
2+ export type SpawnOutcome = "running" | "success" | "aborted" | "error" ;
3+
4+ export type SpawnResultDetails = {
5+ depth : number ;
6+ model : string ;
7+ thinking : ThinkingValue ;
8+ truncated : boolean ;
9+ outcome : SpawnOutcome ;
10+ stats ?: Record < string , number > ;
11+ statsUnavailable ?: boolean ;
12+ } ;
13+
14+ type AssistantMessageLike = {
15+ role : string ;
16+ content ?: { type : string ; text ?: string } [ ] ;
17+ } ;
18+
19+ /**
20+ * Returns all text blocks from the last assistant message, joined by newlines.
21+ */
22+ export function getLastAssistantText ( messages : AssistantMessageLike [ ] ) : string {
23+ for ( let i = messages . length - 1 ; i >= 0 ; i -- ) {
24+ const msg = messages [ i ] ;
25+ if ( msg . role !== "assistant" ) continue ;
26+ const text = ( msg . content ?? [ ] )
27+ . filter ( ( block ) => block . type === "text" && typeof block . text === "string" )
28+ . map ( ( block ) => block . text ?? "" )
29+ . join ( "\n" )
30+ . trim ( ) ;
31+ if ( text ) return text ;
32+ }
33+ return "" ;
34+ }
You can’t perform that action at this time.
0 commit comments