git.iko.soy/opencode-android
on master help sign in
Fix health check endpoint and use dedicated /command endpoint for slash-commands
commit0605447ac0d9750763f9fb83d3aa0ef252fa9e7c authoriko <mail@iko.soy> dateMon 29 Jun 2026, 08:20 (3 months ago) parent29f5f6c
4 files changed+27−7
app/src/main/java/soy/iko/opencode/data/model/Prompt.kt+8 app/src/main/java/soy/iko/opencode/data/network/OpencodeApiClient.kt+14−1 app/src/main/java/soy/iko/opencode/data/repo/SessionRepository.kt+3 app/src/main/java/soy/iko/opencode/ui/chat/ChatViewModel.kt+2−6
app/src/main/java/soy/iko/opencode/data/model/Prompt.kt+8
@@ -16,3 +16,11 @@ data class PromptPart(
1616 val type: String = "text",
1717 val text: String,
1818)
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
22
33import soy.iko.opencode.data.model.Agent
44import soy.iko.opencode.data.model.Command
5+import soy.iko.opencode.data.model.CommandRequest
56import soy.iko.opencode.data.model.CreateSessionRequest
67import soy.iko.opencode.data.model.FileContent
78import soy.iko.opencode.data.model.FileNode
@@ -34,7 +35,7 @@ class OpencodeApiClient(private val client: HttpClient) {
3435
3536 /** Lightweight connectivity check used by the connect screen. */
3637 suspend fun ping(): Boolean {
37− client.get("app")
38+ client.get("global/health")
3839 return true
3940 }
4041
@@ -81,6 +82,18 @@ class OpencodeApiClient(private val client: HttpClient) {
8182 client.post("session/$sessionId/abort")
8283 }
8384
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+
8497 suspend fun providers(): ProvidersResponse =
8598 client.get("config/providers").body()
8699
app/src/main/java/soy/iko/opencode/data/repo/SessionRepository.kt+3
@@ -36,6 +36,9 @@ class SessionRepository(
3636 suspend fun sendPrompt(sessionId: String, text: String, model: ModelRef?, agent: String? = null) =
3737 api.sendPrompt(sessionId, text, model, agent)
3838
39+ suspend fun runCommand(sessionId: String, command: String, agent: String? = null) =
40+ api.runCommand(sessionId, command, agent = agent)
41+
3942 /**
4043 * A live, ordered view of [sessionId]'s messages. Begins collecting the event
4144 * 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(
133133 }
134134 }
135135
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. */
137137 fun runCommand(command: Command) {
138138 val conn = connection ?: return
139139 if (_running.value) return
@@ -141,11 +141,7 @@ class ChatViewModel(
141141 _error.value = null
142142 viewModelScope.launch {
143143 runCatching {
144− conn.api.sendPrompt(
145− sessionId,
146− command.template,
147− agent = command.agent,
148− )
144+ conn.repository.runCommand(sessionId, command.name, agent = command.agent)
149145 }.onFailure { _error.value = it.message ?: "Failed to run command" }
150146 _running.value = false
151147 }