From 694e7f46d7cc9564a0a6ffabf8f2943246f3a7fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Thu, 12 Nov 2026 12:33:47 +0000 Subject: [PATCH] Contract at server dev 9ab0818: spec 3.7.0 from the server -- end, ms, always, the builds - Pinned: 75 files, with the spec's display.json (DisplayTest runs its duration and end cases) and progress.json's budget stop. - Not additive: a call's chips no longer carry "exit 0", and an edit's are one "+N -M" (the app draws chips only, so nothing is said twice); block.title follows the spec's key order. - A message's `end {phase, reason, text}` is what a stopped or failed reply is drawn from, so a reloaded one says "Stopped: by you" too; the app writes the line in its own language from the phase and the reason. - A call's time is block.duration (the server's), else made from `ms`; its state is block.state; a call without a title shows block.label. - "Always allow" only when every item of the approval has `always`. - The notifications build's updater takes its file from latest.json, else from GET /apps' `notifications {url, sha256}` of the same version. - ApiClient.mentions and attachFrom with their models and fixtures; the composer does not use them yet. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 5 + .../java/eu/llembas/android/api/ApiClient.kt | 21 + .../java/eu/llembas/android/api/Display.kt | 35 +- .../java/eu/llembas/android/api/Models.kt | 50 +- .../java/eu/llembas/android/ui/chat/Blocks.kt | 8 +- .../java/eu/llembas/android/ui/chat/Cards.kt | 10 +- .../eu/llembas/android/ui/chat/Transcript.kt | 4 +- .../java/eu/llembas/android/update/Updater.kt | 21 +- .../java/eu/llembas/android/ContractTest.kt | 65 +- .../java/eu/llembas/android/DisplayTest.kt | 14 +- .../java/eu/llembas/android/ProgressTest.kt | 2 +- .../eu/llembas/android/SmallThingsTest.kt | 23 + contract/attachment_from.json | 12 + contract/device_commands.json | 17 + contract/device_files.json | 16 + contract/devices.json | 26 + contract/event_ask.json | 4 + contract/event_ask_phone.json | 4 + contract/event_done.json | 11 +- contract/event_done_title_pending.json | 11 +- contract/event_steps.json | 34 +- contract/event_tail.json | 24 +- contract/harness_display.json | 684 ++++++++++++++++++ contract/harness_progress.json | 13 + contract/lock.json | 6 +- contract/me.json | 7 +- contract/mentions.json | 16 + contract/mentions_url.json | 10 + contract/message_assistant.json | 11 +- contract/message_failed.json | 87 +++ contract/message_stopped.json | 40 + contract/python_call.json | 18 + contract/python_result.json | 11 + contract/python_state.json | 16 + contract/terminal_ready.json | 11 + contract/terminal_refused.json | 14 + contract/terminals.json | 20 + contract/tool_show.json | 10 +- 38 files changed, 1343 insertions(+), 48 deletions(-) create mode 100644 contract/attachment_from.json create mode 100644 contract/device_commands.json create mode 100644 contract/device_files.json create mode 100644 contract/devices.json create mode 100644 contract/harness_display.json create mode 100644 contract/mentions.json create mode 100644 contract/mentions_url.json create mode 100644 contract/message_failed.json create mode 100644 contract/message_stopped.json create mode 100644 contract/python_call.json create mode 100644 contract/python_result.json create mode 100644 contract/python_state.json create mode 100644 contract/terminal_ready.json create mode 100644 contract/terminal_refused.json create mode 100644 contract/terminals.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 0398219..5f82796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,11 @@ is in alpha and releases come off `main`. - The approval card offers the spec's four actions: *Allow once*, *Always allow*, *Deny*, and *Deny, and say why*. The plan card approves together with the mode to continue in -- *Approve, continue in Edit* or *Approve, continue in Manual* -- and *Revise*. +- With LLeMbas 2.0.0-beta.11: a reply that was stopped or failed says so with its reason after a + reload too (the instance stores how it ended); *Always allow* is offered only where the request + offers it; a tool call's time is the instance's own; a call without a title is named as the + instance names its tool. The notifications build can take its own file from the instance's + recommendation of the same release when the website's manifest names none. - **A reply ends when it is saved, and the chat's name follows** (with a server that sends `done` first: LLeMbas 2.0.0-beta.11). The app treats `done` as the end -- the transcript, a spoken answer and a queued prompt no longer wait for a model to name a new chat -- and takes the name diff --git a/app/src/main/java/eu/llembas/android/api/ApiClient.kt b/app/src/main/java/eu/llembas/android/api/ApiClient.kt index 6d4f883..90ae77a 100644 --- a/app/src/main/java/eu/llembas/android/api/ApiClient.kt +++ b/app/src/main/java/eu/llembas/android/api/ApiClient.kt @@ -174,6 +174,27 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli /** The app releases this server recommends; 404 from a server older than the route. */ suspend fun apps(): AppsInfo = get("/apps") + /** What `@` offers from the server for [q]: the chat's earlier attachments, files of the tree, a web address. */ + suspend fun mentions(q: String, chatId: String? = null): Mentions = get("/mentions?q=${segment(q)}" + (chatId?.let { "&chat=${segment(it)}" } ?: "")) + + /** + * Attach without uploading: a copy of an earlier attachment, a file of the tree as it is now, + * or a web page's text -- whichever [mention] is. 404 for what cannot be reached, 400 for a + * page that cannot be fetched. + */ + suspend fun attachFrom(mention: Mention, chatId: String? = null): Attachment = send( + "POST", + "/attachments/from", + buildJsonObject { + when (mention.kind) { + "attachment" -> put("attachment", mention.id) + "url" -> put("url", mention.url) + else -> put("path", mention.path) + } + chatId?.let { put("chat", it) } + }, + ).attachment + /** The web's search in JSON: chats by their words (and meaning, where indexed), files, memories. */ suspend fun search(q: String, within: String = "all", limit: Int = 20): SearchResults = get("/search?q=${segment(q)}&in=${segment(within)}&limit=$limit") diff --git a/app/src/main/java/eu/llembas/android/api/Display.kt b/app/src/main/java/eu/llembas/android/api/Display.kt index 4c1491e..651c658 100644 --- a/app/src/main/java/eu/llembas/android/api/Display.kt +++ b/app/src/main/java/eu/llembas/android/api/Display.kt @@ -32,12 +32,31 @@ const val TITLE_MAX = 80 * what `/api/v2` says of it. */ fun ToolCall.state(): String = when { + // The server's own word, from spec 3.7.0; an older one leaves it to what the call carries. + block.state in CALL_STATES -> block.state + status == "denied" -> "denied" + status == "error" || !error.isNullOrEmpty() -> "failed" + status == "running" || status == "pending" -> "running" + else -> "done" } +private val CALL_STATES = setOf("running", "done", "failed", "denied") + +/** + * What is written after a call's title for its time: the server's own [ToolBlock.duration] where + * it sends one (it measured the call), else made from the call's `ms`; nothing for a call that is + * running or was denied. + */ +fun ToolCall.took(): String? { + val state = state() + if (state == "running" || state == "denied") return null + return block.duration.ifBlank { null } ?: callDuration(state, ms) +} + /** * How long a finished call took (`display.md` §2): tenths under a minute (`0.4s`), then * `1m 05s`, then `2h 03m`. None for a call that is running or was denied, or whose time was not @@ -59,16 +78,24 @@ fun callDuration(state: String, ms: Long?): String? { /** * How a reply ended, when it did not finish (`display.md` §4): the `stopped` or `failed` progress - * whose line stays on it. From the end the stream said (kept on the message as its `progress`, - * with the reason: by you, step limit, budget), else from what the stored row knows -- that it - * was stopped, or its error, of which the first line is the reason. Null for a reply that + * whose line stays on it. From the row's own `end` (spec 3.7.0: the phase and the reason, stored + * with the reply); from an older server, the end the stream said (kept on the message as its + * `progress`), else what the row knows -- that it was stopped, or its error, of which the first + * line is the reason. Null for a reply that * finished, a user's message, or one still queued. */ -fun Message.end(): Progress? = when { +fun Message.ending(): Progress? = when { role != "assistant" -> null + + // What the server stored with the reply (spec 3.7.0): it stays true after a reload. + end?.phase in END_PHASES -> Progress(phase = end?.phase.orEmpty(), reason = end?.reason?.ifBlank { null }) + progress?.phase in END_PHASES -> progress + !error.isNullOrBlank() -> Progress(phase = "failed", reason = error.lineSequence().firstOrNull { it.isNotBlank() }?.trim()) + stopped -> Progress(phase = "stopped") + else -> null } 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 d9f96e5..694bbb3 100644 --- a/app/src/main/java/eu/llembas/android/api/Models.kt +++ b/app/src/main/java/eu/llembas/android/api/Models.kt @@ -222,7 +222,26 @@ data class SearchResults( /** One app release the server recommends (`GET /api/v2/apps`), with the page its files are on. */ @Serializable -data class AppRelease(val version: String = "", val tag: String = "", val channel: String = "", val page: String = "") +data class AppRelease( + val version: String = "", + val tag: String = "", + val channel: String = "", + val page: String = "", + /** The release's other builds, for an updater that installs its own kind: `{url, sha256}` each, where the server knows them. */ + val notifications: AppBuild? = null, + val fdroid: AppBuild? = null, +) + +/** One APK of a release: where it is and its SHA-256. */ +@Serializable +data class AppBuild(val url: String = "", val sha256: String = "") + +/** What `@` offers from the server (`GET /api/v2/mentions`): an earlier `attachment` by [id], a `file` of the tree by [path], or a `url`. */ +@Serializable +data class Mention(val kind: String = "", val id: String = "", val path: String = "", val url: String = "", val name: String = "", val detail: String = "") + +@Serializable +data class Mentions(val items: List = emptyList()) @Serializable data class ServerChannel(val version: String = "", val channel: String = "") @@ -355,8 +374,23 @@ data class Metrics( @SerialName("tok_s") val tokPerSecond: Double = 0.0, ) +/** + * How a call is drawn (`display.md`): its [kind], the one short [title], the facts after it as + * [chips] (an edit's `+N −M`, a non-zero `exit N`, the hits), and from spec 3.7.0 its [state] + * (running, done, failed, denied), the [duration] of a finished call as the spec writes it, and + * the tool's name as a person reads it ([label]). The last three are empty from an older server. + */ @Serializable -data class ToolBlock(val kind: String = "tool", val title: String = "", val chips: List = emptyList(), val added: Int = 0, val removed: Int = 0) +data class ToolBlock( + val kind: String = "tool", + val title: String = "", + val chips: List = emptyList(), + val added: Int = 0, + val removed: Int = 0, + val state: String = "", + val duration: String = "", + val label: String = "", +) /** One tool call. What the tool wrote varies by tool, so the free-form parts stay JSON. */ @Serializable @@ -491,6 +525,14 @@ data class Step( val messages: List = emptyList(), ) +/** + * A reply's end when it did not finish: `stopped` with `person`, `steps`, `budget` or no reason, + * or `failed` with the error's first line. [text] is the line in the account's language; the app + * writes its own from [phase] and [reason], in the app's language. + */ +@Serializable +data class MessageEnd(val phase: String = "", val reason: String = "", val text: String = "") + @Serializable data class Message( val id: String, @@ -499,6 +541,8 @@ data class Message( val complete: Boolean = true, val stopped: Boolean = false, val error: String? = null, + /** How a reply that did not finish ended (spec 3.7.0); null for one that finished, or from an older server. */ + val end: MessageEnd? = null, val queued: Boolean = false, val machine: Boolean = false, val origin: String = "", @@ -540,6 +584,8 @@ data class CardItem( val options: List