mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(gateway): dedupe assistant delta parsing
This commit is contained in:
7
src/gateway/agent-event-assistant-text.ts
Normal file
7
src/gateway/agent-event-assistant-text.ts
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user