瀏覽代碼

fix(llm): stabilize anthropic tool result typecheck (#28909)

Aiden Cline 4 月之前
父節點
當前提交
14c511e380
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      packages/llm/src/protocols/anthropic-messages.ts

+ 3 - 1
packages/llm/src/protocols/anthropic-messages.ts

@@ -335,7 +335,9 @@ const lowerToolResultContent = Effect.fn("AnthropicMessages.lowerToolResultConte
   // Text / json / error results stay as a string for backward compatibility
   // Text / json / error results stay as a string for backward compatibility
   // with existing cassettes and provider expectations.
   // with existing cassettes and provider expectations.
   if (part.result.type !== "content") return ProviderShared.toolResultText(part)
   if (part.result.type !== "content") return ProviderShared.toolResultText(part)
-  return yield* Effect.forEach(part.result.value, lowerToolResultContentItem)
+  // Preserve the narrowed array element type when compiled through a consumer package.
+  const content: ReadonlyArray<ToolResultContentPart> = part.result.value
+  return yield* Effect.forEach(content, lowerToolResultContentItem)
 })
 })
 
 
 const lowerMessages = Effect.fn("AnthropicMessages.lowerMessages")(function* (
 const lowerMessages = Effect.fn("AnthropicMessages.lowerMessages")(function* (