fix(ci): tighten thinking recovery stream types

This commit is contained in:
Vincent Koc
2026-04-02 19:47:39 +09:00
parent 8bdca2323d
commit 707f5485b9
2 changed files with 9 additions and 5 deletions

View File

@@ -10,6 +10,8 @@ import {
wrapAnthropicStreamWithRecovery,
} from "./thinking.js";
type AssistantMessage = Extract<AgentMessage, { role: "assistant" }>;
function dropSingleAssistantContent(content: Array<Record<string, unknown>>) {
const messages: AgentMessage[] = [
castAgentMessage({
@@ -260,7 +262,7 @@ describe("wrapAnthropicStreamWithRecovery", () => {
});
it("preserves result() for synchronous event streams", async () => {
const finalMessage = {
const finalMessage = castAgentMessage({
role: "assistant",
content: [{ type: "text", text: "done" }],
api: "anthropic-messages",
@@ -276,7 +278,7 @@ describe("wrapAnthropicStreamWithRecovery", () => {
},
stopReason: "stop",
timestamp: Date.now(),
} as const;
}) as AssistantMessage;
const wrapped = wrapAnthropicStreamWithRecovery(
(() => {

View File

@@ -236,7 +236,7 @@ async function pumpStreamWithRecovery(
stream: ReturnType<StreamFn>,
sessionMeta: RecoverySessionMeta,
retry: () => ReturnType<StreamFn>,
): Promise<unknown> {
): Promise<AssistantMessage> {
let yieldedChunk = false;
try {
const resolved = stream instanceof Promise ? await stream : stream;
@@ -244,7 +244,8 @@ async function pumpStreamWithRecovery(
yieldedChunk = true;
outer.push(chunk as Parameters<typeof outer.push>[0]);
}
return await (resolved as { result?: () => Promise<unknown> }).result?.();
const result = await (resolved as { result?: () => Promise<AssistantMessage> }).result?.();
return result as AssistantMessage;
} catch (error: unknown) {
if (!shouldRecoverAnthropicThinkingError(error, sessionMeta)) {
throw error;
@@ -264,7 +265,8 @@ async function pumpStreamWithRecovery(
for await (const chunk of resolvedRetry as AsyncIterable<unknown>) {
outer.push(chunk as Parameters<typeof outer.push>[0]);
}
return await (resolvedRetry as { result?: () => Promise<unknown> }).result?.();
const result = await (resolvedRetry as { result?: () => Promise<AssistantMessage> }).result?.();
return result as AssistantMessage;
}
}