Jelajahi Sumber

fix: ensure truncation handling applies to mcp servers too

Aiden Cline 1 bulan lalu
induk
melakukan
0d49df46ef
1 mengubah file dengan 10 tambahan dan 2 penghapusan
  1. 10 2
      packages/opencode/src/session/prompt.ts

+ 10 - 2
packages/opencode/src/session/prompt.ts

@@ -44,6 +44,7 @@ import { SessionStatus } from "./status"
 import { LLM } from "./llm"
 import { LLM } from "./llm"
 import { iife } from "@/util/iife"
 import { iife } from "@/util/iife"
 import { Shell } from "@/shell/shell"
 import { Shell } from "@/shell/shell"
+import { Truncate } from "@/tool/truncation"
 
 
 // @ts-ignore
 // @ts-ignore
 globalThis.AI_SDK_LOG_WARNINGS = false
 globalThis.AI_SDK_LOG_WARNINGS = false
@@ -801,10 +802,17 @@ export namespace SessionPrompt {
           }
           }
         }
         }
 
 
+        const truncated = await Truncate.output(textParts.join("\n\n"), {}, input.agent)
+        const metadata = {
+          ...(result.metadata ?? {}),
+          truncated: truncated.truncated,
+          ...(truncated.truncated && { outputPath: truncated.outputPath }),
+        }
+
         return {
         return {
           title: "",
           title: "",
-          metadata: result.metadata ?? {},
-          output: textParts.join("\n\n"),
+          metadata,
+          output: truncated.content,
           attachments,
           attachments,
           content: result.content, // directly return content to preserve ordering when outputting to model
           content: result.content, // directly return content to preserve ordering when outputting to model
         }
         }