Skip to content

Align the Kotlin SDK with agent-client-protocol pr 576 that flattens type and value at the top level#81

Merged
nerzhulart merged 2 commits intoagentclientprotocol:masterfrom
fscarponi:fabrizio.scarponi/align-boolean-config-option-schema-with-type-and-flatten-structure
Mar 11, 2026
Merged

Align the Kotlin SDK with agent-client-protocol pr 576 that flattens type and value at the top level#81
nerzhulart merged 2 commits intoagentclientprotocol:masterfrom
fscarponi:fabrizio.scarponi/align-boolean-config-option-schema-with-type-and-flatten-structure

Conversation

@fscarponi
Copy link
Copy Markdown
Contributor

Aligns the Kotlin SDK with agent-client-protocol#576 (commit 2aca527).

What changed

Replaced the auto-generated serializer for SetSessionConfigOptionRequest with a custom
SetSessionConfigOptionRequestSerializer that flattens type and value at the top level
of the JSON object.

Serialization format

Option type JSON format
Boolean {"sessionId":"…","configId":"…","type":"boolean","value":true}
Select (string) {"sessionId":"…","configId":"…","value":"model-1"}
Unknown (future) Preserved as raw JSON via UnknownValue

The string/select format is intentionally unchanged to maintain backward compatibility.

Files changed

  • Requests.kt — switched to @Serializable(with = SetSessionConfigOptionRequestSerializer::class)
  • SessionConfig.kt — added SetSessionConfigOptionRequestSerializer with custom serialize/deserialize logic
  • acp-model.api — regenerated via apiDump (removed synthetic $$serializer class)
  • SessionConfigSelectOptionsSerializerTest.kt — updated and added tests for boolean, string, unknown type, and backward-compatible deserialization

Testing

All 340 tests in acp-model pass. No breaking changes for existing consumers.

@fscarponi fscarponi changed the title Aligns the Kotlin SDK with agent-client-protocol pr 576 that flattens type and value at the top level Align the Kotlin SDK with agent-client-protocol pr 576 that flattens type and value at the top level Mar 11, 2026
@fscarponi fscarponi marked this pull request as ready for review March 11, 2026 10:29
Align with agentclientprotocol/agent-client-protocol#576 by introducing
a custom serializer that uses a "type" discriminator field for boolean
config options while preserving backward compatibility for select/string
values.

- Boolean values serialize as {"type":"boolean","value":true}
- String values serialize as {"value":"..."} (no type field, unchanged)
- Unknown types fall back to UnknownValue for forward compatibility
@fscarponi fscarponi force-pushed the fabrizio.scarponi/align-boolean-config-option-schema-with-type-and-flatten-structure branch from 368f631 to 0226c30 Compare March 11, 2026 10:36
@nerzhulart nerzhulart requested a review from Copilot March 11, 2026 14:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns the Kotlin acp-model SDK’s SetSessionConfigOptionRequest JSON shape with agent-client-protocol#576 by introducing a custom serializer that flattens type/value to the top level (while keeping string/select values untyped for backward compatibility).

Changes:

  • Bumped SDK version from 0.16.5 to 0.16.6.
  • Switched SetSessionConfigOptionRequest to a custom KSerializer that emits top-level type for boolean values.
  • Updated API dump and expanded serializer tests for boolean/string/unknown/backward-compat cases.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
build.gradle.kts Version bump to publish the protocol-alignment change.
acp-model/src/commonMain/kotlin/com/agentclientprotocol/model/Requests.kt Routes SetSessionConfigOptionRequest through the new custom serializer.
acp-model/src/commonMain/kotlin/com/agentclientprotocol/model/SessionConfig.kt Implements SetSessionConfigOptionRequestSerializer flattening logic.
acp-model/src/commonTest/kotlin/com/agentclientprotocol/model/SessionConfigSelectOptionsSerializerTest.kt Updates/extends tests around request serialization/deserialization formats.
acp-model/api/acp-model.api Reflects regenerated public API surface (removes synthetic serializer class).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…d compat

- Deserialize boolean primitives without type field as BoolValue (backward compat)

- Preserve both type and value in UnknownValue for unknown types (forward compat)

- Add regression tests for boolean-without-type and unknown-type round-trip

Co-authored-by: Junie <junie@jetbrains.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +362 to +366
?: throw SerializationException("Expected boolean primitive for type 'boolean'")
if (primitive.booleanOrNull != null) {
SessionConfigOptionValue.BoolValue(primitive.boolean)
} else {
SessionConfigOptionValue.UnknownValue(rawValue)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the type == "boolean" branch, if value is not a JSON boolean (e.g., a string/number/object), the code either throws (non-JsonPrimitive) or falls back to UnknownValue(rawValue) which drops the original type field. That makes payloads like {...,"type":"boolean","value":"false"} impossible to round-trip and reduces forward/robust compatibility.

Consider avoiding the hard throw and, on any non-boolean value, preserving both fields by storing an UnknownValue wrapper object containing the original type and value (similar to the unknown-type branch).

Suggested change
?: throw SerializationException("Expected boolean primitive for type 'boolean'")
if (primitive.booleanOrNull != null) {
SessionConfigOptionValue.BoolValue(primitive.boolean)
} else {
SessionConfigOptionValue.UnknownValue(rawValue)
if (primitive?.booleanOrNull != null) {
SessionConfigOptionValue.BoolValue(primitive.boolean)
} else {
// Preserve both type and value for non-boolean or non-primitive values
val unknownWrapper = buildJsonObject {
put("type", JsonPrimitive("boolean"))
put("value", rawValue)
}
SessionConfigOptionValue.UnknownValue(unknownWrapper)

Copilot uses AI. Check for mistakes.
@nerzhulart nerzhulart merged commit eb2f162 into agentclientprotocol:master Mar 11, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants