mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 23:30:21 +00:00
fix(ci): tighten thinking recovery stream types
This commit is contained in:
@@ -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(
|
||||
(() => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user