Skip to content

Commit b9a1cb1

Browse files
committed
fix(anthropic): encode opaque content blocks without opening an unused keyed container
1 parent 0ad0585 commit b9a1cb1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Sources/AgentRunKit/LLM/AnthropicClientTypes.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ enum AnthropicContentBlock: Encodable {
106106
}
107107

108108
func encode(to encoder: any Encoder) throws {
109+
if case let .opaque(raw) = self {
110+
try raw.encode(to: encoder)
111+
return
112+
}
109113
var container = encoder.container(keyedBy: CodingKeys.self)
110114
switch self {
111115
case let .text(text, cacheControl):
@@ -144,8 +148,8 @@ enum AnthropicContentBlock: Encodable {
144148
try sourceContainer.encode(mediaType, forKey: .mediaType)
145149
try sourceContainer.encode(data, forKey: .data)
146150
try container.encodeIfPresent(cacheControl, forKey: .cacheControl)
147-
case let .opaque(raw):
148-
try raw.encode(to: encoder)
151+
case .opaque:
152+
break
149153
}
150154
}
151155
}

0 commit comments

Comments
 (0)