1package soy.iko.opencode.data.model
3import kotlinx.serialization.Serializable
5/** Response of `GET /config/providers`. */
7data class ProvidersResponse(
8 val providers: List<Provider> = emptyList(),
9 val default: Map<String, String> = emptyMap(),
15 val name: String? = null,
16 val models: Map<String, ModelInfo> = emptyMap(),
18 val displayName: String get() = name?.takeIf { it.isNotBlank() } ?: id
23 val id: String? = null,
24 val name: String? = null,
26 fun displayName(modelKey: String): String =
27 name?.takeIf { it.isNotBlank() } ?: id ?: modelKey
30/** A flattened provider/model selection used by the prompt body and the model picker. */
33 val providerID: String,
37/** A single selectable entry in the model picker, flattened from [ProvidersResponse]. */
38data class ModelOption(
39 val providerID: String,
41 val providerLabel: String,
42 val modelLabel: String,
44 val ref: ModelRef get() = ModelRef(providerID, modelID)
47/** Flatten providers into a sorted list of pickable options. */
48fun ProvidersResponse.toOptions(): List<ModelOption> =
49 providers.flatMap { provider ->
50 provider.models.map { (modelKey, info) ->
52 providerID = provider.id,
53 modelID = info.id ?: modelKey,
54 providerLabel = provider.displayName,
55 modelLabel = info.displayName(modelKey),
58 }.sortedWith(compareBy({ it.providerLabel.lowercase() }, { it.modelLabel.lowercase() }))
60/** The default option to preselect: the server's default for some provider, else the first model. */
61fun ProvidersResponse.defaultOption(options: List<ModelOption> = toOptions()): ModelOption? {
62 default.entries.firstOrNull()?.let { (providerID, modelID) ->
63 options.firstOrNull { it.providerID == providerID && it.modelID == modelID }?.let { return it }
65 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