1package soy.iko.opencode.data.model
3import androidx.compose.runtime.Immutable
4import kotlinx.serialization.Serializable
6/** Response of `GET /config/providers`. */
9data class ProvidersResponse(
10 val providers: List<Provider> = emptyList(),
11 val default: Map<String, String> = emptyMap(),
18 val name: String? = null,
19 val models: Map<String, ModelInfo> = emptyMap(),
21 val displayName: String get() = name?.takeIf { it.isNotBlank() } ?: id
27 val id: String? = null,
28 val name: String? = null,
30 fun displayName(modelKey: String): String =
31 name?.takeIf { it.isNotBlank() } ?: id ?: modelKey
34/** A flattened provider/model selection used by the prompt body and the model picker. */
38 val providerID: String,
42/** A single selectable entry in the model picker, flattened from [ProvidersResponse]. */
44data class ModelOption(
45 val providerID: String,
47 val providerLabel: String,
48 val modelLabel: String,
50 val ref: ModelRef get() = ModelRef(providerID, modelID)
53/** Flatten providers into a sorted list of pickable options. */
54fun ProvidersResponse.toOptions(): List<ModelOption> =
55 providers.flatMap { provider ->
56 provider.models.map { (modelKey, info) ->
58 providerID = provider.id,
59 modelID = info.id ?: modelKey,
60 providerLabel = provider.displayName,
61 modelLabel = info.displayName(modelKey),
64 }.sortedWith(compareBy({ it.providerLabel.lowercase() }, { it.modelLabel.lowercase() }))
66/** The default option to preselect: the server's default for some provider, else the first model. */
67fun ProvidersResponse.defaultOption(options: List<ModelOption> = toOptions()): ModelOption? {
68 default.entries.firstOrNull()?.let { (providerID, modelID) ->
69 options.firstOrNull { it.providerID == providerID && it.modelID == modelID }?.let { return it }
71 return options.firstOrNull()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list