package com.example.aiapp /** * What a session with no model of its own is called, in the button and in the list it opens. * * One constant rather than a literal in each place, because the two have to agree: a picker whose * options cannot say every state its button can display is one you can leave and not get back to. * It is also the Claude CLI's own word for "whatever is configured". */ const val DEFAULT_MODEL = "default" /** * A model's name as a person reads it. * * Providers answer with their own full identifier -- Claude Code resolves `haiku` to `claude- * haiku-4-5-20251001` and reports that, which is the honest answer to "what is this session using" * and far too long for a button in a row that also holds Stop and Send. * * So the two ends that identify nothing are dropped and nothing else is: the vendor prefix, which * is the same on every model this app can show, and the release date, which distinguishes builds of * one model rather than one model from another. Anything that does not look like that is returned * untouched. * * A llama.cpp session's model is not an identifier at all -- it is `owner/repo/file.gguf`, where * the file was downloaded from -- so what is kept is the file, which is the part that tells two * models apart, and the extension goes with the directories. The model's *own* name is better still * and is not derivable here: it is inside the file, and only the server has ever opened it. Where a * screen has the server's answer it should prefer it; this is the floor under every screen that * does not. * * A display decision, not a correction: the full name is what the session reports. */ fun modelLabel(model: String?): String { val name = model?.takeIf { it.isNotBlank() } ?: return DEFAULT_MODEL if (name.endsWith(GGUF)) { return name.substringAfterLast('/').removeSuffix(GGUF) } return name.removePrefix("claude-").replace(DATED_SUFFIX, "") } /** A trailing `-YYYYMMDD`, which is how these identifiers carry their release date. */ private val DATED_SUFFIX = Regex("""-\d{8}$""") /** What every model a llama.cpp session can run is stored as. */ private const val GGUF = ".gguf"