History

fix: avoid duplicating streamed assistant completion text (#465)

James committed 8 months ago

Commit 57aa6bf1 parent 40a7f4b2 files · +6 −1Browse files

Unified · Split

2 files
  1. apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts +1 −0
  2. apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts +5 −1
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts+1−0
@@ -834,6 +834,7 @@ describe("ProviderRuntimeIngestion", () => { · 833 unmodified lines
834834 payload: {
835835 itemType: "assistant_message",
836836 status: "completed",
837+ detail: "hello live",
837838 },
838839 });
839840
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts+5−1
@@ -951,6 +951,10 @@ const make = Effect.gen(function* () { · 950 unmodified lines
951951 if (assistantCompletion) {
952952 const assistantMessageId = assistantCompletion.messageId;
953953 const turnId = toTurnId(event.turnId);
954+ const existingAssistantMessage = thread.messages.find((entry) => entry.id === assistantMessageId);
955+ const shouldApplyFallbackCompletionText =
956+ !existingAssistantMessage ||
957+ existingAssistantMessage.text.length === 0;
954958 if (turnId) {
955959 yield* rememberAssistantMessageId(thread.id, turnId, assistantMessageId);
956960 }
@@ -963,7 +967,7 @@ const make = Effect.gen(function* () { · 6 unmodified lines
963967 createdAt: now,
964968 commandTag: "assistant-complete",
965969 finalDeltaCommandTag: "assistant-delta-finalize",
966− ...(assistantCompletion.fallbackText !== undefined
970+ ...(assistantCompletion.fallbackText !== undefined && shouldApplyFallbackCompletionText
967971 ? { fallbackText: assistantCompletion.fallbackText }
968972 : {}),
969973 });