Skip to content

Commit b4544ff

Browse files
committed
Extract shared spawn types into dedicated module
1 parent 9950acd commit b4544ff

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

spawn/shared.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)