From b20cc15c2cbf6b2fdbf5322eb719544d9d2a2fae Mon Sep 17 00:00:00 2001 From: Link Dupont Date: Thu, 26 Mar 2026 21:31:00 -0400 Subject: [PATCH] fix: Decode parts if present in Gemini responses --- Sources/AgentRunKit/LLM/GeminiClientTypes.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/AgentRunKit/LLM/GeminiClientTypes.swift b/Sources/AgentRunKit/LLM/GeminiClientTypes.swift index ede47b1..19ce2d8 100644 --- a/Sources/AgentRunKit/LLM/GeminiClientTypes.swift +++ b/Sources/AgentRunKit/LLM/GeminiClientTypes.swift @@ -47,7 +47,20 @@ struct GeminiRequest: Encodable { struct GeminiContent: Codable { let role: String? + /// Optional during decoding — Gemini may omit `parts` for blocked or empty responses. + /// Defaults to `[]` when absent. Always populated for outgoing requests. let parts: [GeminiPart] + + init(role: String?, parts: [GeminiPart]) { + self.role = role + self.parts = parts + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + role = try container.decodeIfPresent(String.self, forKey: .role) + parts = try container.decodeIfPresent([GeminiPart].self, forKey: .parts) ?? [] + } } struct GeminiPart: Codable {