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),
65 // CASE_INSENSITIVE_ORDER compares in place; compareBy { it.x.lowercase() } would
66 // allocate a fresh lowercased string on every comparison (O(N log N) allocations).
67 compareBy<ModelOption, String>(String.CASE_INSENSITIVE_ORDER) { it.providerLabel }
68 .thenBy(String.CASE_INSENSITIVE_ORDER) { it.modelLabel },
71/** The default option to preselect: the server's default for some provider, else the first model. */
72fun ProvidersResponse.defaultOption(options: List<ModelOption> = toOptions()): ModelOption? {
73 default.entries.firstOrNull()?.let { (providerID, modelID) ->
74 options.firstOrNull { it.providerID == providerID && it.modelID == modelID }?.let { return it }
76 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