Skip to content

Commit fa66ab8

Browse files
committed
Request is int
1 parent 8cdded0 commit fa66ab8

File tree

4 files changed

+18
-17
lines changed
  • acp-model/src/commonMain/kotlin/com/agentclientprotocol/rpc
  • acp/src
  • samples/kotlin-acp-client-sample/src/main/kotlin/com/agentclientprotocol/samples/agent

4 files changed

+18
-17
lines changed

acp-model/src/commonMain/kotlin/com/agentclientprotocol/rpc/JsonRpc.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public const val JSONRPC_VERSION: String = "2.0"
1919
*/
2020
@JvmInline
2121
@Serializable
22-
public value class RequestId(public val value: String) {
23-
override fun toString(): String = value
22+
public value class RequestId(public val value: Int) {
23+
override fun toString(): String = value.toString()
2424
}
2525

2626
@JvmInline

acp/src/commonMain/kotlin/com/agentclientprotocol/protocol/Protocol.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.agentclientprotocol.rpc.*
1010
import com.agentclientprotocol.transport.Transport
1111
import com.agentclientprotocol.transport.asMessageChannel
1212
import io.github.oshai.kotlinlogging.KotlinLogging
13+
import kotlinx.atomicfu.AtomicInt
1314
import kotlinx.atomicfu.AtomicLong
1415
import kotlinx.atomicfu.AtomicRef
1516
import kotlinx.atomicfu.atomic
@@ -73,7 +74,7 @@ public class Protocol(
7374
) {
7475
private val scope = CoroutineScope(parentScope.coroutineContext + SupervisorJob(parentScope.coroutineContext[Job]))
7576
private val requestsScope = CoroutineScope(scope.coroutineContext + SupervisorJob(scope.coroutineContext[Job]))
76-
private val requestIdCounter: AtomicLong = atomic(0L)
77+
private val requestIdCounter: AtomicInt = atomic(0)
7778
private val pendingRequests: AtomicRef<PersistentMap<RequestId, CompletableDeferred<JsonElement>>> =
7879
atomic(persistentMapOf())
7980

@@ -121,7 +122,7 @@ public class Protocol(
121122
params: JsonElement? = null,
122123
timeout: Duration = options.requestTimeout
123124
): JsonElement {
124-
val requestId = RequestId(requestIdCounter.incrementAndGet().toString())
125+
val requestId = RequestId(requestIdCounter.incrementAndGet())
125126
val deferred = CompletableDeferred<JsonElement>()
126127

127128
pendingRequests.update { it.put(requestId, deferred) }

acp/src/jvmTest/kotlin/com/agentclientprotocol/transport/StdioTransportTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class StdioTransportTest {
8484
@Test
8585
fun `should read JSON-RPC request from input`(): Unit = runBlocking {
8686
val testMethod = MethodName("test.method")
87-
transport.send(JsonRpcRequest(RequestId("1"), testMethod, JsonPrimitive("value")))
87+
transport.send(JsonRpcRequest(RequestId(1), testMethod, JsonPrimitive("value")))
8888

8989
// Read the message from the transport
9090
val message = messages.receive()
9191

9292
assertTrue(message is JsonRpcRequest)
93-
assertEquals(RequestId("1"), message.id)
93+
assertEquals(RequestId(1), message.id)
9494
assertEquals(testMethod, message.method)
9595
assertNotNull(message.params)
9696
}
@@ -109,13 +109,13 @@ class StdioTransportTest {
109109

110110
@Test
111111
fun `should read JSON-RPC response from input`(): Unit = runBlocking {
112-
transport.send(JsonRpcResponse(RequestId("42"), result = JsonPrimitive("success")))
112+
transport.send(JsonRpcResponse(RequestId(42), result = JsonPrimitive("success")))
113113

114114
// Read the message from the transport
115115
val message = messages.receive()
116116

117117
assertTrue(message is JsonRpcResponse)
118-
assertEquals(RequestId("42"), message.id)
118+
assertEquals(RequestId(42), message.id)
119119
assertEquals(JsonPrimitive("success"), message.result)
120120
}
121121

@@ -124,9 +124,9 @@ class StdioTransportTest {
124124
val method1 = MethodName("method1")
125125
val notification1 = MethodName("notification1")
126126

127-
transport.send(JsonRpcRequest(RequestId("1"), method1))
127+
transport.send(JsonRpcRequest(RequestId(1), method1))
128128
transport.send(JsonRpcNotification(method = notification1))
129-
transport.send(JsonRpcResponse(RequestId("2"), result = JsonPrimitive("ok")))
129+
transport.send(JsonRpcResponse(RequestId(2), result = JsonPrimitive("ok")))
130130

131131
val message1 = messages.receive()
132132
val message2 = messages.receive()
@@ -139,16 +139,16 @@ class StdioTransportTest {
139139
assertEquals(notification1, message2.method)
140140

141141
assertTrue(message3 is JsonRpcResponse)
142-
assertEquals(RequestId("2"), message3.id)
142+
assertEquals(RequestId(2), message3.id)
143143
}
144144

145145
@Test
146146
fun `should skip invalid JSON lines and continue processing`(): Unit = runBlocking {
147147
val firstMethod = MethodName("first")
148148
val secondMethod = MethodName("second")
149149

150-
transport.send(JsonRpcRequest(RequestId("1"), firstMethod))
151-
transport.send(JsonRpcRequest(RequestId("2"), secondMethod))
150+
transport.send(JsonRpcRequest(RequestId(1), firstMethod))
151+
transport.send(JsonRpcRequest(RequestId(2), secondMethod))
152152

153153
val message1 = messages.receive()
154154
assertTrue(message1 is JsonRpcRequest)
@@ -209,7 +209,7 @@ class StdioTransportTest {
209209
launch {
210210
var i = 0
211211
while (transport.state.value != Transport.State.CLOSED) {
212-
transport.send(JsonRpcRequest(RequestId("${i++}"), testMethod))
212+
transport.send(JsonRpcRequest(RequestId(i++), testMethod))
213213
delay(10.milliseconds)
214214
}
215215
}
@@ -221,7 +221,7 @@ class StdioTransportTest {
221221
@Test
222222
fun `should handle end of stream gracefully`(): Unit = runBlocking {
223223
val testMethod = MethodName("test")
224-
transport.send(JsonRpcRequest(RequestId("1"), testMethod))
224+
transport.send(JsonRpcRequest(RequestId(1), testMethod))
225225

226226
val message = messages.receive()
227227
assertTrue(message is JsonRpcRequest)

samples/kotlin-acp-client-sample/src/main/kotlin/com/agentclientprotocol/samples/agent/SimpleAgent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ class SimpleAgent : Agent {
7474
return InitializeResponse(
7575
protocolVersion = LATEST_PROTOCOL_VERSION,
7676
agentCapabilities = AgentCapabilities(
77-
loadSession = true,
77+
loadSession = false,
7878
promptCapabilities = PromptCapabilities(
7979
audio = false,
80-
image = true,
80+
image = false,
8181
embeddedContext = true
8282
)
8383
),

0 commit comments

Comments
 (0)