A model is named by its ref: twins on two connections are told apart

Contract and strings pinned at the server's dev (6778143); the release re-pins at its tag.

- ModelInfo, SchedulingModel, StartModel and a directory's model carry
  `ref`; `key` (ref, else id) is what is chosen, kept and sent as `model`
  on create, chat update and schedules. `named()` finds a row by ref, else
  the first with that id, so an assistant model saved as an id, a chat's
  `model` and a schedule's still find theirs.
- Pickers show "Name · Connection" where two rows share an id, and key
  their rows by ref.
- An open chat says its model's id only: the ref picked here says which
  twin while the id still fits (ChatState.picked).
- A run's `error.reason` is read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-18 01:16:13 +00:00
1 parent 1d3154cefa
commit efba3aacf4
23 files changed
+212 -41

No files matched your search

@@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
/** The model last used in a directory on the device, as one the person still has. */
@Serializable
data class DirectoryModel(val id: String = "", val name: String = "") {
data class DirectoryModel(val id: String = "", val name: String = "", val ref: String = "") {
/** What to call it: its name, else its id. */
val label: String get() = name.ifBlank { id }
}
@@ -59,4 +59,7 @@ data class DeviceDirectory(
* there) or `default`. The device remembers it; nothing here is kept by the app.
*/
@Serializable
data class StartModel(val model: String = "", val from: String = "")
data class StartModel(val model: String = "", val from: String = "", val ref: String = "") {
/** The model's unambiguous name where the server says one, else its id. */
val key: String get() = ref.ifBlank { model }
}
@@ -119,7 +119,18 @@ data class ModelInfo(
val subagents: SubagentsOffer? = null,
/** On a connection whose terms allow interactive use only: never a schedule's model. */
@SerialName("interactive_only") val interactiveOnly: Boolean = false,
/**
* The model's one unambiguous name, `provider/id` (server 2.0.0-beta.14): two connections may
* serve one [id], which alone names only the first of them. Empty from an older server.
*/
val ref: String = "",
val provider: String = "",
/** The connection's name, for telling two models with one [id] apart. */
val connection: String = "",
) {
/** What this model is chosen, kept and sent by: its [ref], or its [id] from a server without refs. */
val key: String get() = ref.ifBlank { id }
/**
* The levels, for a server that says them; an older one said only `efforts`, offered after
* an `off` that meant "the model's default" -- as the app showed it before.
@@ -154,6 +165,22 @@ data class ModelInfo(
}
}
/**
* The model a name means, in a list: by its `ref`, else the first with that `id` -- which is
* what a bare id names on the server too. So a name kept from before refs (a setting, a chat's
* `model`, a schedule's) still finds its model.
*/
fun List<ModelInfo>.named(name: String?): ModelInfo? {
if (name.isNullOrBlank()) return null
return firstOrNull { it.ref == name } ?: firstOrNull { it.id == name }
}
/** A model's name in a list of [all]: with its connection where another model there shares its id. */
fun ModelInfo.titleAmong(all: List<ModelInfo>): String = twinTitle(name.ifBlank { id }, connection, all.count { it.id == id } > 1)
/** "Name · Connection" for a model one of two that share an id ([twin]), where the connection has a name; else the name. */
fun twinTitle(name: String, connection: String, twin: Boolean): String = if (twin && connection.isNotBlank()) "$name · $connection" else name
@Serializable
data class ModelList(
val models: List<ModelInfo> = emptyList(),
@@ -34,9 +34,13 @@ data class RunTokens(val prompt: Long = 0, val completion: Long = 0)
@Serializable
data class RunCost(val micro: Long = 0, val currency: String = "")
/** Why a run failed or waits: [kind] a class the app may read, [text] the server's own sentence. */
/**
* Why a run failed or waits: [kind] a class the app may read, [text] the sentence to show (the
* server's, or the device's own), and [reason] a narrower word where there is one -- `terminal`:
* the schedule's session was open in a terminal on the computer.
*/
@Serializable
data class RunError(@SerialName("class") val kind: String = "", val text: String = "")
data class RunError(@SerialName("class") val kind: String = "", val text: String = "", val reason: String? = null)
/**
* One run of a schedule: when it was due and how it went. [status] is `running`, `waiting` (no
@@ -192,7 +196,22 @@ data class SchedulingModel(
val free: Boolean = false,
val busy: String? = null,
val chosen: Boolean = true,
)
/** The model's unambiguous name (`provider/id`) and its connection's, as on every model object. */
val ref: String = "",
val connection: String = "",
) {
/** What a schedule's model is chosen and sent by: its [ref], or its [id] from a server without refs. */
val key: String get() = ref.ifBlank { id }
}
/** The scheduling model a name means: by its `ref`, else the first with that `id`. */
fun List<SchedulingModel>.named(name: String?): SchedulingModel? {
if (name.isNullOrBlank()) return null
return firstOrNull { it.ref == name } ?: firstOrNull { it.id == name }
}
/** A scheduling model's name in a list of [all]: with its connection where another there shares its id. */
fun SchedulingModel.titleAmong(all: List<SchedulingModel>): String = twinTitle(name.ifBlank { id }, connection, all.count { it.id == id } > 1)
/** `GET`/`PUT /schedules/models`: the models, the instance's order, and the person's narrowing. */
@Serializable
@@ -19,6 +19,7 @@ import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.Step
import eu.llembas.android.api.StreamClient
import eu.llembas.android.api.named
import eu.llembas.android.lembas
import eu.llembas.android.notify.NotificationAccess
import eu.llembas.android.notify.NotificationReader
@@ -113,7 +114,7 @@ data class AssistUiState(
val held: Boolean get() = waiting.isNotBlank() || waitingRecording
val screenAvailable: Boolean get() = screenText || screenshot != null
val modelInfo: ModelInfo? get() = models.firstOrNull { it.id == modelId }
val modelInfo: ModelInfo? get() = models.named(modelId)
val empty: Boolean get() = turns.isEmpty()
}
@@ -834,8 +835,9 @@ class AssistController(
* account's default, the instance's, or its first.
*/
fun assistantModelFor(chosen: String, accountDefault: String?, models: List<ModelInfo>): String? {
val has = { id: String? -> !id.isNullOrBlank() && models.any { it.id == id } }
return chosen.takeIf(has) ?: accountDefault?.takeIf(has) ?: models.firstOrNull { it.default }?.id ?: models.firstOrNull()?.id
// By ref, or -- a choice saved before refs, the account's default -- by id: either
// way what comes back is the row's own unambiguous name.
return (models.named(chosen) ?: models.named(accountDefault) ?: models.firstOrNull { it.default } ?: models.firstOrNull())?.key
}
/** A reply's words, for a voice: its text steps, without the markup. */
@@ -92,6 +92,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import eu.llembas.android.R
import eu.llembas.android.api.titleAmong
import eu.llembas.android.ui.ModelAvatar
import eu.llembas.android.ui.ProgressStatus
import eu.llembas.android.ui.chat.PhoneCard
@@ -425,15 +426,15 @@ private fun ModelChip(state: AssistUiState, actions: AssistActions) {
state.models.forEach { model ->
DropdownMenuItem(
leadingIcon = { ModelAvatar(model, model.id, size = 24.dp) },
text = { Text(model.name.ifBlank { model.id }, maxLines = 1, overflow = TextOverflow.Ellipsis) },
trailingIcon = if (model.id == state.modelId) {
text = { Text(model.titleAmong(state.models), maxLines = 1, overflow = TextOverflow.Ellipsis) },
trailingIcon = if (model.key == state.modelInfo?.key) {
{ Box(Modifier.size(8.dp).clip(CircleShape).background(palette.accent)) }
} else {
null
},
onClick = {
open = false
actions.pickModel(model.id)
actions.pickModel(model.key)
},
)
}
@@ -16,6 +16,7 @@ import eu.llembas.android.AppLanguage
import eu.llembas.android.MainActivity
import eu.llembas.android.R
import eu.llembas.android.api.ApiException
import eu.llembas.android.api.named
import eu.llembas.android.assist.AssistSheetFrame
import eu.llembas.android.assist.LastAssist
import eu.llembas.android.auth.Prefs
@@ -107,7 +108,7 @@ class ShareActivity :
// The assistant's model while the instance still has it; a model that is
// gone is not asked for (the instance's default answers instead).
val chosen = prefs.assistantModel
val gone = chosen.isNotBlank() && runCatching { api.models() }.getOrNull()?.none { it.id == chosen } == true
val gone = chosen.isNotBlank() && runCatching { api.models() }.getOrNull()?.let { it.named(chosen) == null } == true
val made = api.createChat(message, files, model = chosen.takeIf { it.isNotBlank() && !gone })
store.savePrefs {
it.copy(
@@ -33,6 +33,7 @@ import eu.llembas.android.api.StartModel
import eu.llembas.android.api.StreamClient
import eu.llembas.android.api.SubagentTree
import eu.llembas.android.api.Turn
import eu.llembas.android.api.named
import eu.llembas.android.lembas
import eu.llembas.android.ui.explain
import kotlinx.coroutines.CancellationException
@@ -97,6 +98,8 @@ data class ChatState(
val mentions: List<Mention> = emptyList(),
/** The message this app sent last, by its id: what the transcript shows whoever has scrolled where. */
val lastSent: String? = null,
/** The model picked for this open chat, by its ref: which of two models with one id the chat is on. */
val picked: String? = null,
)
/**
@@ -124,13 +127,24 @@ const val IMAGE_TOOL = "image_generate"
* person picked is never set aside by the folder's.
*/
val ChatState.modelId: String?
get() = chat?.model?.ifBlank { null } ?: draft.model ?: folderModel ?: models.firstOrNull { it.default }?.id ?: models.firstOrNull()?.id
get() = chatModel ?: draft.model ?: folderModel ?: models.firstOrNull { it.default }?.key ?: models.firstOrNull()?.key
/**
* An open chat's model. The chat says its model's id, which two connections may share; the one
* picked here ([ChatState.picked], a ref) says which of them, for as long as the chat is still
* on a model of that id.
*/
val ChatState.chatModel: String?
get() {
val served = chat?.model?.ifBlank { null } ?: return null
return picked?.takeIf { models.named(it)?.id == served } ?: served
}
/** The folder's usual model for a chat not made yet, when it is one of the models offered here. */
val ChatState.folderModel: String?
get() = start?.model?.takeIf { id -> chat == null && id.isNotBlank() && models.any { it.id == id } }
get() = start?.takeIf { chat == null }?.let { models.named(it.key) ?: models.named(it.model) }?.key
val ChatState.modelInfo: ModelInfo? get() = models.firstOrNull { it.id == modelId }
val ChatState.modelInfo: ModelInfo? get() = models.named(modelId)
/** The thinking level in force, by the model's levels; null for a model with no choice. */
val ChatState.level: String?
@@ -545,7 +559,7 @@ class ChatViewModel(app: Application) :
override fun change(key: String, value: String?) = control { api, chat ->
val updated = api.updateChat(chat.id, JsonObject(mapOf(key to JsonPrimitive(value))))
_state.update { it.copy(chat = updated) }
_state.update { it.copy(chat = updated, picked = if (key == "model") value else it.picked) }
// Another model may serve one request at a time, or more: whether a team is offered
// follows it.
if (key == "model") {
@@ -28,6 +28,8 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import eu.llembas.android.R
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.named
import eu.llembas.android.api.titleAmong
import eu.llembas.android.ui.ModelAvatar
import eu.llembas.android.ui.theme.LocalPalette
@@ -99,12 +101,14 @@ fun ModelPickerContent(models: List<ModelInfo>, current: String?, onPick: (Strin
modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp),
)
LazyColumn(Modifier.fillMaxWidth().padding(bottom = 16.dp)) {
items(models, key = { it.id }) { m ->
val chosen = m.id == current
// By its ref: two connections may serve one id, and a row is its own key.
val inUse = models.named(current)?.key
items(models.distinctBy { it.key }, key = { it.key }) { m ->
val chosen = m.key == inUse
Row(
Modifier
.fillMaxWidth()
.clickable { onPick(m.id) }
.clickable { onPick(m.key) }
.heightIn(min = 72.dp)
.padding(horizontal = 24.dp, vertical = 10.dp),
verticalAlignment = Alignment.CenterVertically,
@@ -112,7 +116,7 @@ fun ModelPickerContent(models: List<ModelInfo>, current: String?, onPick: (Strin
ModelAvatar(m, m.id, size = 44.dp)
Spacer(Modifier.width(16.dp))
Column(Modifier.weight(1f)) {
Text(m.name.ifBlank { m.id }, style = MaterialTheme.typography.titleMedium)
Text(m.titleAmong(models), style = MaterialTheme.typography.titleMedium)
modelNotes(m).takeIf { it.isNotEmpty() }?.let {
Text(it, style = MaterialTheme.typography.bodyMedium, color = palette.inkMuted)
}
@@ -99,7 +99,9 @@ import eu.llembas.android.api.WatchCommand
import eu.llembas.android.api.WhereToRun
import eu.llembas.android.api.agentic
import eu.llembas.android.api.computerAway
import eu.llembas.android.api.named
import eu.llembas.android.api.notifyChoice
import eu.llembas.android.api.titleAmong
import eu.llembas.android.lembas
import eu.llembas.android.ui.DirectoryPicker
import eu.llembas.android.ui.explain
@@ -1381,7 +1383,7 @@ private fun OnComputer(state: EditState, onWhere: ((EditState) -> EditState) ->
) {
Column(Modifier.weight(1f)) {
Text(
state.models.firstOrNull { it.id == state.model }?.let { it.name.ifBlank { it.id } }
state.models.named(state.model)?.titleAmong(state.models)
?: state.model.ifBlank { stringResource(R.string.schedule_folder_model) },
style = MaterialTheme.typography.bodyLarge,
)
@@ -1416,10 +1418,12 @@ private fun OnComputer(state: EditState, onWhere: ((EditState) -> EditState) ->
}
ChoiceRow(selected = state.model.isBlank(), title = stringResource(R.string.schedule_folder_model), line = null, onClick = { pick("") })
// The schedule's own model stays offered where the instance no longer lists it: the server says why on Save.
val own = state.model.takeIf { m -> m.isNotBlank() && state.models.none { it.id == m } }
val own = state.model.takeIf { m -> m.isNotBlank() && state.models.named(m) == null }
own?.let { ChoiceRow(selected = true, title = it, line = null, onClick = { pick(it) }) }
state.models.forEach { m ->
ChoiceRow(selected = state.model == m.id, title = m.name.ifBlank { m.id }, line = null, onClick = { pick(m.id) })
// By ref: a schedule read from the instance names its model by id, which still finds it.
val chosen = state.models.named(state.model)?.key
state.models.distinctBy { it.key }.forEach { m ->
ChoiceRow(selected = chosen == m.key, title = m.titleAmong(state.models), line = null, onClick = { pick(m.key) })
}
}
},
@@ -133,7 +133,7 @@ fun SchedulingModelsContent(state: ModelsState, onBack: () -> Unit = {}, onToggl
)
}
state.error?.let { item { Text(it, color = palette.danger, style = MaterialTheme.typography.bodyMedium) } }
items(models, key = { it.id }) { m -> ModelRow(m, onToggle = { onToggle(m) }) }
items(models.distinctBy { it.key }, key = { it.key }) { m -> ModelRow(m, onToggle = { onToggle(m) }) }
}
}
}
@@ -95,6 +95,8 @@ import eu.llembas.android.BuildConfig
import eu.llembas.android.R
import eu.llembas.android.actions.NavApp
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.named
import eu.llembas.android.api.titleAmong
import eu.llembas.android.assist.LembasAssistService
import eu.llembas.android.assist.PhoneRecognizer
import eu.llembas.android.auth.Instance
@@ -1190,11 +1192,11 @@ fun WakeChoices(which: WakeChoice, prefs: Prefs, onPick: ((SettingsActions) -> U
@Composable
private fun assistantModelLabel(state: SettingsState): String {
val chosen = state.prefs.assistantModel
val model = state.assistantModels.firstOrNull { it.id == chosen }
val model = state.assistantModels.named(chosen)
// While the list is not read yet, or could not be: the choice as it was saved.
return when {
chosen.isBlank() -> stringResource(R.string.assistant_model_default)
model != null -> model.name.ifBlank { model.id }
model != null -> model.titleAmong(state.assistantModels)
state.assistantModels.isEmpty() -> chosen
else -> stringResource(R.string.assistant_model_default)
}
@@ -1207,10 +1209,11 @@ private fun assistantModelLabel(state: SettingsState): String {
*/
@Composable
fun AssistantModelChoices(state: SettingsState, onPick: (String) -> Unit) {
val chosen = state.prefs.assistantModel.takeIf { id -> state.assistantModels.any { it.id == id } }.orEmpty()
// A choice saved before models had refs is an id: it still finds its model.
val chosen = state.assistantModels.named(state.prefs.assistantModel)?.key.orEmpty()
val choices = listOf(
Choice(INSTANCE_DEFAULT, stringResource(R.string.assistant_model_default), stringResource(R.string.assistant_model_default_line), chosen.isEmpty()),
) + state.assistantModels.map { Choice(it.id, it.name.ifBlank { it.id }, null, it.id == chosen) }
) + state.assistantModels.distinctBy { it.key }.map { Choice(it.key, it.titleAmong(state.assistantModels), null, it.key == chosen) }
ChoiceList(stringResource(R.string.assistant_model), choices) { id -> onPick(if (id == INSTANCE_DEFAULT) "" else id) }
}