Skip to content

Commit 43c4478

Browse files
Zawwarsami16claude
andcommitted
fix kotlin CI: explicit JsonArray construction for messages
kotlin 2.0+ rejected `json.encodeToJsonElement(messages)` on a List<Map<String,String>> because the generic type doesn't resolve to a SerializationStrategy via reified inference. caught by the new phase 0.7 kotlin CI job — exactly the regression that job exists to catch. fix: build the JsonArray manually from the List<Map<>>. no extra imports, no reified magic, deterministic shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 304cbc3 commit 43c4478

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

kotlin/src/main/kotlin/com/zawwar/zhub/Protocol.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,27 @@ internal fun chatRequestEnvelope(
5757
model: String = "default",
5858
temperature: Double = 0.4,
5959
maxTokens: Int = 4096,
60-
): Envelope = Envelope(
61-
type = "chat-request",
62-
payload = buildJsonObject {
63-
put("messages", json.encodeToJsonElement(messages))
64-
put("model", JsonPrimitive(model))
65-
put("temperature", JsonPrimitive(temperature))
66-
put("max_tokens", JsonPrimitive(maxTokens))
67-
},
68-
)
60+
): Envelope {
61+
// Build the messages array explicitly — generic List<Map<...>> doesn't
62+
// resolve cleanly through Json.encodeToJsonElement on Kotlin 2.0+, and an
63+
// explicit construction avoids the reified-type ambiguity entirely.
64+
val messagesArray = kotlinx.serialization.json.JsonArray(
65+
messages.map { m ->
66+
buildJsonObject {
67+
for ((k, v) in m) put(k, JsonPrimitive(v))
68+
}
69+
}
70+
)
71+
return Envelope(
72+
type = "chat-request",
73+
payload = buildJsonObject {
74+
put("messages", messagesArray)
75+
put("model", JsonPrimitive(model))
76+
put("temperature", JsonPrimitive(temperature))
77+
put("max_tokens", JsonPrimitive(maxTokens))
78+
},
79+
)
80+
}
6981

7082
internal fun invokeResultEnvelope(
7183
requestId: String,

0 commit comments

Comments
 (0)