git.iko.soy/opencode-android
on 325e359 help sign in
45 lines 1.4 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.JsonPrimitive
8import kotlinx.serialization.json.jsonArray
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 else -> p.jsonArray.mapNotNull { (it as? JsonPrimitive)?.content }.joinToString(", ").ifEmpty { null }
33 }
36/** Allowed values for the permission response body. */
37enum class PermissionResponse(val wire: String) {
38 ONCE("once"),
39 ALWAYS("always"),
40 REJECT("reject"),
43/** Body for `POST /session/:id/permissions/:permissionID`. */
44@Serializable
45data class PermissionReplyBody(val response: String)