git.iko.soy/opencode-android
on master help sign in
Fix health check endpoint and use dedicated /command endpoint for slash-commands
0605447iko
app/src/main/java/soy/iko/opencode/data/model/Prompt.kt+8
@@ -16,3 +16,11 @@ data class PromptPart(
16 val type: String = "text",
16 val type: String = "text",
17 val text: String,
17 val text: String,
18)
18)
19+
20+/** Body for `POST /session/:id/command`. */
21+@Serializable
22+data class CommandRequest(
23+ val command: String,
24+ val arguments: String = "",
25+ val agent: String? = null,
26+)
app/src/main/java/soy/iko/opencode/data/network/OpencodeApiClient.kt+14−1
@@ -2,6 +2,7 @@ package soy.iko.opencode.data.network
2
2
3import soy.iko.opencode.data.model.Agent
3import soy.iko.opencode.data.model.Agent
4import soy.iko.opencode.data.model.Command
4import soy.iko.opencode.data.model.Command
5+import soy.iko.opencode.data.model.CommandRequest
5import soy.iko.opencode.data.model.CreateSessionRequest
6import soy.iko.opencode.data.model.CreateSessionRequest
6import soy.iko.opencode.data.model.FileContent
7import soy.iko.opencode.data.model.FileContent
7import soy.iko.opencode.data.model.FileNode
8import soy.iko.opencode.data.model.FileNode
@@ -34,7 +35,7 @@ class OpencodeApiClient(private val client: HttpClient) {
34
35
35 /** Lightweight connectivity check used by the connect screen. */
36 /** Lightweight connectivity check used by the connect screen. */
36 suspend fun ping(): Boolean {
37 suspend fun ping(): Boolean {
37− client.get("app")
38+ client.get("global/health")
38 return true
39 return true
39 }
40 }
40
41
@@ -81,6 +82,18 @@ class OpencodeApiClient(private val client: HttpClient) {
81 client.post("session/$sessionId/abort")
82 client.post("session/$sessionId/abort")
82 }
83 }
83
84
85+ /** Invoke a slash-command by name via `POST /session/:id/command`. */
86+ suspend fun runCommand(
87+ sessionId: String,
88+ command: String,
89+ arguments: String = "",
90+ agent: String? = null,
91+ ): MessageWithParts =
92+ client.post("session/$sessionId/command") {
93+ contentType(ContentType.Application.Json)
94+ setBody(CommandRequest(command = command, arguments = arguments, agent = agent))
95+ }.body()
96+
84 suspend fun providers(): ProvidersResponse =
97 suspend fun providers(): ProvidersResponse =
85 client.get("config/providers").body()
98 client.get("config/providers").body()
86
99
app/src/main/java/soy/iko/opencode/data/repo/SessionRepository.kt+3
@@ -36,6 +36,9 @@ class SessionRepository(
36 suspend fun sendPrompt(sessionId: String, text: String, model: ModelRef?, agent: String? = null) =
36 suspend fun sendPrompt(sessionId: String, text: String, model: ModelRef?, agent: String? = null) =
37 api.sendPrompt(sessionId, text, model, agent)
37 api.sendPrompt(sessionId, text, model, agent)
38
38
39+ suspend fun runCommand(sessionId: String, command: String, agent: String? = null) =
40+ api.runCommand(sessionId, command, agent = agent)
41+
39 /**
42 /**
40 * A live, ordered view of [sessionId]'s messages. Begins collecting the event
43 * A live, ordered view of [sessionId]'s messages. Begins collecting the event
41 * stream before the initial REST load so no streamed part is missed, then reduces
44 * stream before the initial REST load so no streamed part is missed, then reduces
app/src/main/java/soy/iko/opencode/ui/chat/ChatViewModel.kt+2−6
@@ -133,7 +133,7 @@ class ChatViewModel(
133 }
133 }
134 }
134 }
135
135
136− /** Invoke a slash-command: sends the command's template text with the command's agent/model if set. */
136+ /** Invoke a slash-command by name via the server's /command endpoint. */
137 fun runCommand(command: Command) {
137 fun runCommand(command: Command) {
138 val conn = connection ?: return
138 val conn = connection ?: return
139 if (_running.value) return
139 if (_running.value) return
@@ -141,11 +141,7 @@ class ChatViewModel(
141 _error.value = null
141 _error.value = null
142 viewModelScope.launch {
142 viewModelScope.launch {
143 runCatching {
143 runCatching {
144− conn.api.sendPrompt(
145− sessionId,
146− command.template,
147− agent = command.agent,
144+ conn.repository.runCommand(sessionId, command.name, agent = command.agent)
148− )
149 }.onFailure { _error.value = it.message ?: "Failed to run command" }
145 }.onFailure { _error.value = it.message ?: "Failed to run command" }
150 _running.value = false
146 _running.value = false
151 }
147 }