git.iko.soy/opencode-android
on c0621ff help sign in
65 lines 2.4 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 val id: String,
11 val parentID: String? = null,
12 val title: String? = null,
13 val version: String? = null,
14 val time: TimeInfo? = null,
15 // The absolute worktree/directory the agent runs in for this session. Set server-side
16 // from the `directory` query param at creation; persisted per session so the client
17 // needn't re-send it on follow-up calls (see OpencodeApiClient.createSession).
18 val directory: String? = null,
19 val projectID: String? = null,
20 // Present only while the session is shared (POST /session/:id/share); cleared on unshare.
21 val share: Share? = null,
22 // Present only while a revert checkpoint is active (POST /session/:id/revert); cleared on unrevert.
23 val revert: Revert? = null,
24) {
25 val displayTitle: String get() = title?.takeIf { it.isNotBlank() } ?: "Untitled session"
27 /** A compact form of [directory] for list/subtitle display: the last path segment,
28 * or the full path when it has no separators. Null/blank when no directory is set. */
29 val displayDirectory: String?
30 get() = directory?.takeIf { it.isNotBlank() }?.trimEnd('/')?.substringAfterLast('/')?.takeIf { it.isNotBlank() }
32 /** True while the session has an active public share link. */
33 val isShared: Boolean get() = !share?.url.isNullOrBlank()
35 /** True while a revert checkpoint is active (messages after it are hidden server-side). */
36 val isReverted: Boolean get() = revert != null
38 /** Public share link for the session, from `POST /session/:id/share`. */
39 @Immutable
40 @Serializable
41 data class Share(val url: String = "")
43 /** The active revert checkpoint, from `POST /session/:id/revert`. */
44 @Immutable
45 @Serializable
46 data class Revert(
47 val messageID: String = "",
48 val partID: String? = null,
49 val snapshot: String? = null,
50 val diff: String? = null,
51 )
54/** Body for `POST /session`. */
55@Serializable
56data class CreateSessionRequest(
57 val parentID: String? = null,
58 val title: String? = null,
61/** Body for `PATCH /session/:id`. */
62@Serializable
63data class UpdateSessionRequest(
64 val title: String? = null,