git.iko.soy/opencode-android
on 8bc2cce help sign in
49 lines 1.7 kB history raw
1package soy.iko.opencode.data.model
3import androidx.compose.runtime.Immutable
4import kotlinx.serialization.Serializable
5import kotlinx.serialization.json.JsonElement
6import kotlinx.serialization.json.JsonObject
7import kotlinx.serialization.json.JsonArray
8import kotlinx.serialization.json.JsonPrimitive
10/**
11 * A permission request from `permission.updated`. The tool detail lives in [type] +
12 * [pattern] + [metadata]; [pattern] is a string or array of strings on the wire, so
13 * it's kept as a [JsonElement] and flattened for display.
14 */
15@Immutable
16@Serializable
17data class Permission(
18 val id: String,
19 val sessionID: String = "",
20 val type: String? = null,
21 val pattern: JsonElement? = null,
22 val messageID: String? = null,
23 val callID: String? = null,
24 val title: String? = null,
25 val metadata: JsonObject? = null,
26 val time: TimeInfo? = null,
27) {
28 val patternText: String?
29 get() = when (val p = pattern) {
30 null -> null
31 is JsonPrimitive -> p.content
32 // Only a JSON array is flattened; any other shape (e.g. an object) would make
33 // the previous unguarded `p.jsonArray` throw during composition, so treat it
34 // as "no displayable pattern" instead.
35 is JsonArray -> p.mapNotNull { (it as? JsonPrimitive)?.content }.joinToString(", ").ifEmpty { null }
36 else -> null
37 }
40/** Allowed values for the permission response body. */
41enum class PermissionResponse(val wire: String) {
42 ONCE("once"),
43 ALWAYS("always"),
44 REJECT("reject"),
47/** Body for `POST /session/:id/permissions/:permissionID`. */
48@Serializable
49data class PermissionReplyBody(val response: String)