git.iko.soy/opencode-android
on e66c7ed help sign in
68 lines 2.7 kB history raw
1package soy.iko.opencode.data.model
3import androidx.compose.runtime.Immutable
4import kotlinx.serialization.Serializable
6/** A session as returned by `GET /session` and `POST /session`. */
7@Immutable
8@Serializable
9data class Session(
10 // Defaulted so one id-less element in GET /session doesn't fail the whole list decode
11 // (emptying the session list) — matches MessageInfo's defaulted id and the resilient-decoding
12 // philosophy. A blank id is degraded but recoverable; a thrown decode is not.
13 val id: String = "",
14 val parentID: String? = null,
15 val title: String? = null,
16 val version: String? = null,
17 val time: TimeInfo? = null,
18 // The absolute worktree/directory the agent runs in for this session. Set server-side
19 // from the `directory` query param at creation; persisted per session so the client
20 // needn't re-send it on follow-up calls (see OpencodeApiClient.createSession).
21 val directory: String? = null,
22 val projectID: String? = null,
23 // Present only while the session is shared (POST /session/:id/share); cleared on unshare.
24 val share: Share? = null,
25 // Present only while a revert checkpoint is active (POST /session/:id/revert); cleared on unrevert.
26 val revert: Revert? = null,
27) {
28 val displayTitle: String get() = title?.takeIf { it.isNotBlank() } ?: "Untitled session"
30 /** A compact form of [directory] for list/subtitle display: the last path segment,
31 * or the full path when it has no separators. Null/blank when no directory is set. */
32 val displayDirectory: String?
33 get() = directory?.takeIf { it.isNotBlank() }?.trimEnd('/')?.substringAfterLast('/')?.takeIf { it.isNotBlank() }
35 /** True while the session has an active public share link. */
36 val isShared: Boolean get() = !share?.url.isNullOrBlank()
38 /** True while a revert checkpoint is active (messages after it are hidden server-side). */
39 val isReverted: Boolean get() = revert != null
41 /** Public share link for the session, from `POST /session/:id/share`. */
42 @Immutable
43 @Serializable
44 data class Share(val url: String = "")
46 /** The active revert checkpoint, from `POST /session/:id/revert`. */
47 @Immutable
48 @Serializable
49 data class Revert(
50 val messageID: String = "",
51 val partID: String? = null,
52 val snapshot: String? = null,
53 val diff: String? = null,
54 )
57/** Body for `POST /session`. */
58@Serializable
59data class CreateSessionRequest(
60 val parentID: String? = null,
61 val title: String? = null,
64/** Body for `PATCH /session/:id`. */
65@Serializable
66data class UpdateSessionRequest(
67 val title: String? = null,