mirror of https://github.com/openclaw/openclaw.git
refactor(gateway): dedupe assistant delta parsing
This commit is contained in:
parent
5248b759fe
commit
a2ceadcc2a
|
|
@ -0,0 +1,7 @@
|
|||
import type { AgentEventPayload } from "../infra/agent-events.js";
|
||||
|
||||
export function resolveAssistantStreamDeltaText(evt: AgentEventPayload): string {
|
||||
const delta = evt.data.delta;
|
||||
const text = evt.data.text;
|
||||
return typeof delta === "string" ? delta : typeof text === "string" ? text : "";
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import { agentCommand } from "../commands/agent.js";
|
|||
import { emitAgentEvent, onAgentEvent } from "../infra/agent-events.js";
|
||||
import { logWarn } from "../logger.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { resolveAssistantStreamDeltaText } from "./agent-event-assistant-text.js";
|
||||
import {
|
||||
buildAgentMessageFromConversationEntries,
|
||||
type ConversationEntry,
|
||||
|
|
@ -243,9 +244,7 @@ export async function handleOpenAiHttpRequest(
|
|||
}
|
||||
|
||||
if (evt.stream === "assistant") {
|
||||
const delta = evt.data?.delta;
|
||||
const text = evt.data?.text;
|
||||
const content = typeof delta === "string" ? delta : typeof text === "string" ? text : "";
|
||||
const content = resolveAssistantStreamDeltaText(evt);
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import {
|
|||
type InputImageSource,
|
||||
} from "../media/input-files.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { resolveAssistantStreamDeltaText } from "./agent-event-assistant-text.js";
|
||||
import {
|
||||
buildAgentMessageFromConversationEntries,
|
||||
type ConversationEntry,
|
||||
|
|
@ -727,9 +728,7 @@ export async function handleOpenResponsesHttpRequest(
|
|||
}
|
||||
|
||||
if (evt.stream === "assistant") {
|
||||
const delta = evt.data?.delta;
|
||||
const text = evt.data?.text;
|
||||
const content = typeof delta === "string" ? delta : typeof text === "string" ? text : "";
|
||||
const content = resolveAssistantStreamDeltaText(evt);
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue