git.iko.soy/opencode-android
on e66c7ed help sign in
62 lines 1.6 kB history raw
1package soy.iko.opencode.data.model
3import androidx.compose.runtime.Immutable
4import kotlinx.serialization.SerialName
5import kotlinx.serialization.Serializable
6import kotlinx.serialization.json.JsonElement
7import kotlinx.serialization.json.JsonClassDiscriminator
9/**
10 * The state machine of a tool call, discriminated on `status`.
11 * pending -> running -> completed | error
12 */
13@OptIn(kotlinx.serialization.ExperimentalSerializationApi::class)
14@Serializable
15@JsonClassDiscriminator("status")
16sealed interface ToolState
18@Serializable
19@SerialName("pending")
20data object ToolPending : ToolState
22@Immutable
23@Serializable
24@SerialName("running")
25data class ToolRunning(
26 val input: JsonElement? = null,
27 val title: String? = null,
28 val time: PartTimeInfo? = null,
29) : ToolState
31@Immutable
32@Serializable
33@SerialName("completed")
34data class ToolCompleted(
35 val input: JsonElement? = null,
36 val output: String? = null,
37 val title: String? = null,
38 val time: PartTimeInfo? = null,
39) : ToolState
41@Immutable
42@Serializable
43@SerialName("error")
44data class ToolError(
45 val input: JsonElement? = null,
46 val error: String? = null,
47 val time: PartTimeInfo? = null,
48) : ToolState
50/** Fallback for an unrecognized `status`. */
51@Serializable
52@SerialName("__unknown")
53data object ToolUnknown : ToolState
55/** The raw input arguments carried by a tool call, present on the running/completed/error
56 * states (pending/unknown carry none). */
57fun ToolState.inputElement(): JsonElement? = when (this) {
58 is ToolRunning -> input
59 is ToolCompleted -> input
60 is ToolError -> input
61 else -> null