Browse Source

fix: avoid duplicate ACP text chunks

alvinreal 2 months ago
parent
commit
7542e7fd8d
1 changed files with 8 additions and 6 deletions
  1. 8 6
      src/tools/acp-run.ts

+ 8 - 6
src/tools/acp-run.ts

@@ -409,10 +409,12 @@ function selectPermissionOption(
 
 function collectText(update: Record<string, unknown>, chunks: string[]): void {
   if (update.sessionUpdate !== 'agent_message_chunk') return;
-  for (const key of ['content', 'delta']) {
-    const value = update[key];
-    if (typeof value === 'string') chunks.push(value);
-    if (isRecord(value) && typeof value.text === 'string')
-      chunks.push(value.text);
-  }
+  const text = readText(update.delta) ?? readText(update.content);
+  if (text) chunks.push(text);
+}
+
+function readText(value: unknown): string | undefined {
+  if (typeof value === 'string') return value;
+  if (isRecord(value) && typeof value.text === 'string') return value.text;
+  return undefined;
 }