From efba3aacf410eec599fb1b1b548ce39fc765faa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Wed, 18 Nov 2026 01:16:13 +0000 Subject: [PATCH] A model is named by its ref: twins on two connections are told apart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG.md | 4 ++ .../eu/llembas/android/api/Directories.kt | 7 ++- .../java/eu/llembas/android/api/Models.kt | 27 ++++++++ .../java/eu/llembas/android/api/Schedules.kt | 25 +++++++- .../android/assist/AssistController.kt | 8 ++- .../eu/llembas/android/assist/AssistSheet.kt | 7 ++- .../eu/llembas/android/share/ShareActivity.kt | 3 +- .../llembas/android/ui/chat/ChatViewModel.kt | 22 +++++-- .../eu/llembas/android/ui/chat/ModelPicker.kt | 12 ++-- .../android/ui/scheduled/ScheduledScreens.kt | 12 ++-- .../android/ui/scheduled/SchedulingModels.kt | 2 +- .../android/ui/settings/SettingsScreen.kt | 11 ++-- .../java/eu/llembas/android/ChatStateTest.kt | 3 +- .../eu/llembas/android/DirectoriesTest.kt | 61 +++++++++++++++++-- contract/device_directories.json | 2 + contract/device_directories_places.json | 1 + contract/lock.json | 6 +- contract/models.json | 9 +++ contract/models_agent.json | 9 +++ contract/models_agent_directory.json | 10 +++ contract/schedule_models.json | 6 ++ contract/schedule_on_device.json | 3 +- contract/schedule_runs.json | 3 +- 23 files changed, 212 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59097ac..3846f41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,10 @@ Needs LLeMbas 2.0.0-beta.14 for what is new here; with an older instance the app accepts scheduled work, and says so otherwise. A task's page shows its type, computer, folder and model; each run says where it ran and when its model was the folder's usual one, your default or the conversation's own. +- **Two models with the same name on different connections are told apart.** Where an instance + serves one model through two connections, the pickers say *Name · Connection*, and the one + you pick is the one used -- in a chat, as the assistant's model, in a scheduled task. A + model chosen before this still finds its row. - **`@` in the composer.** Type `@` and a few letters at the end of a message: in a chat the list offers your files, what was attached earlier in the chat and a web address, and a tap attaches it; in an agent chat it offers the files in the chat's folder on the computer, and diff --git a/app/src/main/java/eu/llembas/android/api/Directories.kt b/app/src/main/java/eu/llembas/android/api/Directories.kt index c04d3eb..6e830b5 100644 --- a/app/src/main/java/eu/llembas/android/api/Directories.kt +++ b/app/src/main/java/eu/llembas/android/api/Directories.kt @@ -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 } +} diff --git a/app/src/main/java/eu/llembas/android/api/Models.kt b/app/src/main/java/eu/llembas/android/api/Models.kt index 0cf5afd..eede8d6 100644 --- a/app/src/main/java/eu/llembas/android/api/Models.kt +++ b/app/src/main/java/eu/llembas/android/api/Models.kt @@ -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.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): 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 = emptyList(), diff --git a/app/src/main/java/eu/llembas/android/api/Schedules.kt b/app/src/main/java/eu/llembas/android/api/Schedules.kt index 8080fdd..91c1f42 100644 --- a/app/src/main/java/eu/llembas/android/api/Schedules.kt +++ b/app/src/main/java/eu/llembas/android/api/Schedules.kt @@ -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.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): 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 diff --git a/app/src/main/java/eu/llembas/android/assist/AssistController.kt b/app/src/main/java/eu/llembas/android/assist/AssistController.kt index 4f18e02..259d888 100644 --- a/app/src/main/java/eu/llembas/android/assist/AssistController.kt +++ b/app/src/main/java/eu/llembas/android/assist/AssistController.kt @@ -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): 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. */ diff --git a/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt b/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt index d73f143..d3c76eb 100644 --- a/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt +++ b/app/src/main/java/eu/llembas/android/assist/AssistSheet.kt @@ -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) }, ) } diff --git a/app/src/main/java/eu/llembas/android/share/ShareActivity.kt b/app/src/main/java/eu/llembas/android/share/ShareActivity.kt index a9a4081..718f97f 100644 --- a/app/src/main/java/eu/llembas/android/share/ShareActivity.kt +++ b/app/src/main/java/eu/llembas/android/share/ShareActivity.kt @@ -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( diff --git a/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt b/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt index 4e5e82e..7e28c9a 100644 --- a/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt +++ b/app/src/main/java/eu/llembas/android/ui/chat/ChatViewModel.kt @@ -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 = 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") { diff --git a/app/src/main/java/eu/llembas/android/ui/chat/ModelPicker.kt b/app/src/main/java/eu/llembas/android/ui/chat/ModelPicker.kt index 1288885..0972b38 100644 --- a/app/src/main/java/eu/llembas/android/ui/chat/ModelPicker.kt +++ b/app/src/main/java/eu/llembas/android/ui/chat/ModelPicker.kt @@ -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, 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, 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) } diff --git a/app/src/main/java/eu/llembas/android/ui/scheduled/ScheduledScreens.kt b/app/src/main/java/eu/llembas/android/ui/scheduled/ScheduledScreens.kt index 6e9f938..b0f3eee 100644 --- a/app/src/main/java/eu/llembas/android/ui/scheduled/ScheduledScreens.kt +++ b/app/src/main/java/eu/llembas/android/ui/scheduled/ScheduledScreens.kt @@ -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) }) } } }, diff --git a/app/src/main/java/eu/llembas/android/ui/scheduled/SchedulingModels.kt b/app/src/main/java/eu/llembas/android/ui/scheduled/SchedulingModels.kt index 98569a7..aab172f 100644 --- a/app/src/main/java/eu/llembas/android/ui/scheduled/SchedulingModels.kt +++ b/app/src/main/java/eu/llembas/android/ui/scheduled/SchedulingModels.kt @@ -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) }) } } } } diff --git a/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt b/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt index 91d6d57..03d22cf 100644 --- a/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt @@ -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) } } diff --git a/app/src/test/java/eu/llembas/android/ChatStateTest.kt b/app/src/test/java/eu/llembas/android/ChatStateTest.kt index 8de960b..c564077 100644 --- a/app/src/test/java/eu/llembas/android/ChatStateTest.kt +++ b/app/src/test/java/eu/llembas/android/ChatStateTest.kt @@ -37,7 +37,8 @@ class ChatStateTest { @Test fun theModelIsTheChatsThenTheDraftsThenTheDefault() { - assertEquals("qwen", ChatState(models = models).modelId) + // A model is named by its ref; a chat and an older choice still name it by its id. + assertEquals("local/qwen", ChatState(models = models).modelId) assertEquals("gpt-oss", ChatState(models = models, draft = Draft(model = "gpt-oss")).modelId) assertEquals("vision-small", ChatState(models = models, chat = Chat(id = "c", model = "vision-small"), draft = Draft(model = "gpt-oss")).modelId) } diff --git a/app/src/test/java/eu/llembas/android/DirectoriesTest.kt b/app/src/test/java/eu/llembas/android/DirectoriesTest.kt index 7b00ad3..02b8663 100644 --- a/app/src/test/java/eu/llembas/android/DirectoriesTest.kt +++ b/app/src/test/java/eu/llembas/android/DirectoriesTest.kt @@ -5,8 +5,12 @@ import eu.llembas.android.api.Chat import eu.llembas.android.api.DeviceDirectory import eu.llembas.android.api.DeviceList import eu.llembas.android.api.LembasJson +import eu.llembas.android.api.ModelInfo import eu.llembas.android.api.ModelList import eu.llembas.android.api.StartModel +import eu.llembas.android.api.named +import eu.llembas.android.api.titleAmong +import eu.llembas.android.assist.AssistController import eu.llembas.android.ui.PICKER_ENTRIES import eu.llembas.android.ui.PICKER_WORDS import eu.llembas.android.ui.PickerState @@ -17,6 +21,7 @@ import eu.llembas.android.ui.chat.ChatState import eu.llembas.android.ui.chat.Draft import eu.llembas.android.ui.chat.folderModel import eu.llembas.android.ui.chat.modelId +import eu.llembas.android.ui.chat.modelInfo import eu.llembas.android.ui.refusedHere import eu.llembas.android.ui.took import eu.llembas.android.ui.unanswered @@ -181,22 +186,66 @@ class DirectoriesTest { @Test fun aNewAgentChatShowsTheFoldersUsualModelUnlessOneWasPicked() { val list = read("models_agent_directory", ModelList.serializer()) - assertEquals(StartModel(model = "gpt-oss", from = "directory"), list.start) + assertEquals(StartModel(model = "gpt-oss", from = "directory", ref = "local/gpt-oss"), list.start) assertTrue(list.models.none { it.interactiveOnly }) val draft = ChatState(models = list.models, start = list.start) // The default is Qwen; the folder's usual model is shown instead. - assertEquals("qwen", ChatState(models = list.models).modelId) - assertEquals("gpt-oss", draft.modelId) + assertEquals("local/qwen", ChatState(models = list.models).modelId) + assertEquals("local/gpt-oss", draft.modelId) + assertEquals("gpt-oss", draft.modelInfo?.id) // A model the person picked in this draft is never set aside. - assertEquals("vision-small", draft.copy(draft = Draft(model = "vision-small")).modelId) + assertEquals("local/vision-small", draft.copy(draft = Draft(model = "local/vision-small")).modelId) // A model the person no longer has is not shown, and a chat that exists has its own. assertNull(draft.copy(start = StartModel(model = "gone", from = "directory")).folderModel) - assertEquals("qwen", draft.copy(start = StartModel(model = "gone", from = "directory")).modelId) - assertEquals("qwen", draft.copy(chat = Chat(id = "c", model = "qwen")).modelId) + assertEquals("local/qwen", draft.copy(start = StartModel(model = "gone", from = "directory")).modelId) + assertEquals("qwen", draft.copy(chat = Chat(id = "c", model = "qwen")).modelInfo?.id) + // A server before refs says the id alone: it still finds the row. + assertEquals("local/gpt-oss", draft.copy(start = StartModel(model = "gpt-oss", from = "directory")).folderModel) // Without a directory the list says nothing of it. assertNull(read("models_agent", ModelList.serializer()).start) } + @Test + fun twoModelsWithOneIdAreToldApartByTheirRef() { + val home = ModelInfo(id = "qwen", name = "Qwen", ref = "local/qwen", provider = "local", connection = "Local", default = true) + val cloud = ModelInfo(id = "qwen", name = "Qwen", ref = "studio/qwen", provider = "studio", connection = "Model Studio") + val other = ModelInfo(id = "gpt-oss", name = "gpt-oss", ref = "local/gpt-oss", connection = "Local") + val models = listOf(home, cloud, other) + // A ref names its own row; a bare id the first of them, as on the server. + assertEquals(cloud, models.named("studio/qwen")) + assertEquals(home, models.named("qwen")) + assertNull(models.named("gone")) + assertNull(models.named("")) + // The twins say their connection; a model alone with its id does not. + assertEquals("Qwen · Model Studio", cloud.titleAmong(models)) + assertEquals("Qwen · Local", home.titleAmong(models)) + assertEquals("gpt-oss", other.titleAmong(models)) + // The folder's usual model by its ref: the second twin, not the first. + val draft = ChatState(models = models, start = StartModel(model = "qwen", from = "directory", ref = "studio/qwen")) + assertEquals("studio/qwen", draft.modelId) + assertEquals(cloud, draft.modelInfo) + // A pick is kept and sent by its ref. + assertEquals(cloud, draft.copy(start = null, draft = Draft(model = "studio/qwen")).modelInfo) + // An open chat says the id; the ref picked here says which twin, while the id still fits. + val open = ChatState(models = models, chat = Chat(id = "c", model = "qwen")) + assertEquals(home, open.modelInfo) + assertEquals(cloud, open.copy(picked = "studio/qwen").modelInfo) + assertEquals(other, open.copy(chat = Chat(id = "c", model = "gpt-oss"), picked = "studio/qwen").modelInfo) + // A model from a server before refs is its id. + assertEquals("qwen", ModelInfo(id = "qwen").key) + } + + @Test + fun theAssistantsSavedModelStillFindsItsRowAfterRefs() { + val models = read("models", ModelList.serializer()).models + // Saved as an id before refs, or as a ref since: the same model, named by its ref. + assertEquals("local/gpt-oss", AssistController.assistantModelFor("gpt-oss", "qwen", models)) + assertEquals("local/gpt-oss", AssistController.assistantModelFor("local/gpt-oss", "qwen", models)) + // Gone, or "Instance default": the account's default, an id. + assertEquals("local/qwen", AssistController.assistantModelFor("retired", "qwen", models)) + assertEquals("local/qwen", AssistController.assistantModelFor("", null, models)) + } + @Test fun aDeviceSaysWhetherItTakesScheduledWorkAndRemembers() { val (workstation, laptop) = read("devices", DeviceList.serializer()).devices diff --git a/contract/device_directories.json b/contract/device_directories.json index 7a6f210..9ee64a1 100644 --- a/contract/device_directories.json +++ b/contract/device_directories.json @@ -6,6 +6,7 @@ "reason": "", "model": { "id": "qwen", + "ref": "local/qwen", "name": "Qwen" }, "parent": "/home/user", @@ -27,6 +28,7 @@ "reason": "", "model": { "id": "gpt-oss", + "ref": "local/gpt-oss", "name": "gpt-oss" } }, diff --git a/contract/device_directories_places.json b/contract/device_directories_places.json index e024780..98a1021 100644 --- a/contract/device_directories_places.json +++ b/contract/device_directories_places.json @@ -24,6 +24,7 @@ "reason": "", "model": { "id": "qwen", + "ref": "local/qwen", "name": "Qwen" } } diff --git a/contract/lock.json b/contract/lock.json index 7b1ac2f..9969f5d 100644 --- a/contract/lock.json +++ b/contract/lock.json @@ -1,5 +1,5 @@ { - "ref": "a6288a2", - "commit": "a6288a257376d44b6a25983dcb43c9d942870e6c", - "sha256": "f7b9077219b45767ee8cddd7718a18bb00e46f1f7edefd0cc4ed36560bc1c3e5" + "ref": "6778143", + "commit": "6778143859f2986d9eaf5057b782f2502ded2b1c", + "sha256": "208111001ffd502f13d7f6fbc24a232e5ddc0d63c6789afe1636e34f1c737834" } diff --git a/contract/models.json b/contract/models.json index 8ed6c30..4a7d3fa 100644 --- a/contract/models.json +++ b/contract/models.json @@ -2,6 +2,9 @@ "models": [ { "id": "qwen", + "ref": "local/qwen", + "provider": "local", + "connection": "Local", "name": "Qwen", "vision": false, "tools": true, @@ -27,6 +30,9 @@ }, { "id": "gpt-oss", + "ref": "local/gpt-oss", + "provider": "local", + "connection": "Local", "name": "gpt-oss", "vision": false, "tools": true, @@ -55,6 +61,9 @@ }, { "id": "vision-small", + "ref": "local/vision-small", + "provider": "local", + "connection": "Local", "name": "Vision", "vision": true, "tools": false, diff --git a/contract/models_agent.json b/contract/models_agent.json index 0212c2f..dc1d03f 100644 --- a/contract/models_agent.json +++ b/contract/models_agent.json @@ -2,6 +2,9 @@ "models": [ { "id": "qwen", + "ref": "local/qwen", + "provider": "local", + "connection": "Local", "name": "Qwen", "vision": false, "tools": true, @@ -27,6 +30,9 @@ }, { "id": "gpt-oss", + "ref": "local/gpt-oss", + "provider": "local", + "connection": "Local", "name": "gpt-oss", "vision": false, "tools": true, @@ -55,6 +61,9 @@ }, { "id": "vision-small", + "ref": "local/vision-small", + "provider": "local", + "connection": "Local", "name": "Vision", "vision": true, "tools": false, diff --git a/contract/models_agent_directory.json b/contract/models_agent_directory.json index 9c8bf81..f7e8069 100644 --- a/contract/models_agent_directory.json +++ b/contract/models_agent_directory.json @@ -2,6 +2,9 @@ "models": [ { "id": "qwen", + "ref": "local/qwen", + "provider": "local", + "connection": "Local", "name": "Qwen", "vision": false, "tools": true, @@ -27,6 +30,9 @@ }, { "id": "gpt-oss", + "ref": "local/gpt-oss", + "provider": "local", + "connection": "Local", "name": "gpt-oss", "vision": false, "tools": true, @@ -55,6 +61,9 @@ }, { "id": "vision-small", + "ref": "local/vision-small", + "provider": "local", + "connection": "Local", "name": "Vision", "vision": true, "tools": false, @@ -83,6 +92,7 @@ }, "start": { "model": "gpt-oss", + "ref": "local/gpt-oss", "from": "directory" } } diff --git a/contract/schedule_models.json b/contract/schedule_models.json index 7b6111d..0caeaf5 100644 --- a/contract/schedule_models.json +++ b/contract/schedule_models.json @@ -2,6 +2,9 @@ "models": [ { "id": "gpt-oss", + "ref": "local/gpt-oss", + "provider": "local", + "connection": "Local", "name": "gpt-oss", "vision": false, "tools": true, @@ -33,6 +36,9 @@ }, { "id": "qwen", + "ref": "local/qwen", + "provider": "local", + "connection": "Local", "name": "Qwen", "vision": false, "tools": true, diff --git a/contract/schedule_on_device.json b/contract/schedule_on_device.json index f89dfb7..36ca1ab 100644 --- a/contract/schedule_on_device.json +++ b/contract/schedule_on_device.json @@ -92,7 +92,8 @@ "preview": "", "error": { "class": "device_away", - "text": "Waiting for bag-end to be linked." + "text": "Waiting for bag-end to be linked.", + "reason": null }, "notified": false, "notification": null, diff --git a/contract/schedule_runs.json b/contract/schedule_runs.json index 4d3796d..c85dd96 100644 --- a/contract/schedule_runs.json +++ b/contract/schedule_runs.json @@ -38,7 +38,8 @@ "preview": "", "error": { "class": "no_model", - "text": "Waiting for a free model: Qwen: it is answering someone." + "text": "Waiting for a free model: Qwen: it is answering someone.", + "reason": null }, "notified": false, "notification": null,