4fa4f13558
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
29 lines
793 B
TypeScript
29 lines
793 B
TypeScript
import type { AgentState } from "@/features/agents/state/store";
|
|
|
|
const normalizedRunId = (value: unknown): string => {
|
|
return typeof value === "string" ? value.trim() : "";
|
|
};
|
|
|
|
export const mergePendingLivePatch = (
|
|
existing: Partial<AgentState> | undefined,
|
|
incoming: Partial<AgentState>
|
|
): Partial<AgentState> => {
|
|
if (!existing) return incoming;
|
|
|
|
const existingRunId = normalizedRunId(existing.runId);
|
|
const incomingRunId = normalizedRunId(incoming.runId);
|
|
|
|
if (incomingRunId && existingRunId && incomingRunId !== existingRunId) {
|
|
return incoming;
|
|
}
|
|
|
|
if (incomingRunId && !existingRunId) {
|
|
const rest = { ...existing };
|
|
delete rest.streamText;
|
|
delete rest.thinkingTrace;
|
|
return { ...rest, ...incoming };
|
|
}
|
|
|
|
return { ...existing, ...incoming };
|
|
};
|