Pin the server contract, tokens and strings to server dev a25db24; app API 2

The contract moves from f5b3dbb to the server's dev at a25db24971a0: version.json says
{"app_api": 2}, and the server now writes its own show cards (tool_show.json: one from the tree,
one from a device) and the files routes (files_listing.json, file_content.json,
file_content_withheld.json). Tokens from the same commit change only in the header; the strings
regenerate unchanged.

- APP_API is 2, and it is now the floor as well as the ceiling: a protocol-3 server that still
  says app API 1 is a 2.0 build from before the show route and the files, and is refused as too
  old, as 1.x is.
- The files routes are modelled (FileEntry, FileListing, FileContent, Withheld) and ApiClient
  reads them: files(path), fileContent(path), and webFile(path) for the web UI's /files/view.
- shownText is documented against the server's real route, GET /api/v2/chats/{chat}/show with
  ?node=&version= or ?shown=, plain text up to 1 MB, 413 / 415 / 404; ClientTest pins the paths.
- The hand-written show cards leave ShowAndServerTest; ContractTest reads the server's.

Nothing in the app reads /api/v2/devices for its own token (devices() has no caller), so apps no
longer being listed there changes nothing here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-03 14:48:03 +00:00
1 parent ac0c1c58e0
commit 0c5aa4d45f
15 files changed
+302 -57

No files matched your search

@@ -230,9 +230,13 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
// --- What a `show` card opens -------------------------------------------------------------
/**
* The text of a file a `show` card named, as the chat sees it now: the server rebuilds the
* chat's view and checks the path again, so a grant taken away since takes the file away too.
* Always plain text -- the app never asks for a page to render.
* The text of a file a `show` card named, as the chat sees it now:
* `GET /api/v2/chats/{chat}/show?node=<node_id>&version=<version_id>` for a file in the tree,
* `?shown=<shown_id>` for the copy a linked device sent ([ShowCard.query]). The server rebuilds
* the chat's view and checks the path again, so a grant taken away since takes the file away
* too (404, in the server's words). `text/plain; charset=utf-8`, at most 1 MB: above it a 413,
* and a 415 for a file that is not text. Always plain text -- an HTML file is its source, and
* the app never asks for a page to render.
*/
suspend fun shownText(chatId: String, show: ShowCard): String = withContext(Dispatchers.IO) {
val url = "$v2/chats/$chatId/show".toHttpUrl().newBuilder()
@@ -252,6 +256,26 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
}
}
// --- The person's files ------------------------------------------------------------------
/** A directory, as the person may see it (no chat's grants): `GET /api/v2/files?path=`. */
suspend fun files(path: String = "/"): FileListing {
val url = "$v2/files".toHttpUrl().newBuilder().addQueryParameter("path", path).build()
return call(authed(url.toString()).get().build(), FileListing.serializer())
}
/**
* A file's text: `GET /api/v2/files/content?path=`. A file the server will not hand over as
* text (not text, over 1 MB) is not an error: it comes back with `withheld` saying why.
*/
suspend fun fileContent(path: String): FileContent {
val url = "$v2/files/content".toHttpUrl().newBuilder().addQueryParameter("path", path).build()
return call(authed(url.toString()).get().build(), FileContent.serializer())
}
/** A file of the tree in the web UI's own viewer (`/files/view`), for what the app does not draw. */
fun webFile(path: String): String = "$base/files/view".toHttpUrl().newBuilder().addQueryParameter("path", path).build().toString()
/** The same file in the web UI's viewer, which renders HTML in its sealed frame. */
fun webViewer(chatId: String, show: ShowCard): String = "$base/chat/$chatId/show".toHttpUrl().newBuilder()
.apply { show.query.forEach { (k, v) -> addQueryParameter(k, v) } }
@@ -1,7 +1,12 @@
package eu.llembas.android.api
/** The newest app API this app reads. A server with a newer one is told about, not guessed at. */
const val APP_API = 1
/**
* The app API this app reads: 2, the server's 2.0 (no canvas, no `knowledge_bases`, the `show`
* card and its route, and the person's files). A server with a newer one is told about, not
* guessed at; one with an older one is refused, because 1 has neither the show route nor the
* files this app opens -- a 2.0 `dev` server from before the files routes still said 1.
*/
const val APP_API = 2
/**
* The device-link protocol of LLeMbas 2.0. This app is built for 2.0 -- the file tree, the
@@ -19,7 +24,7 @@ fun fit(found: Discovery): ServerFit {
val protocol = maxOf(found.protocol, found.protocols.maxOrNull() ?: 0)
return when {
found.service != "lembas" -> ServerFit.NOT_LEMBAS
protocol < MIN_PROTOCOL || found.appApi < 1 || "app" !in found.scopes -> ServerFit.TOO_OLD
protocol < MIN_PROTOCOL || found.appApi < APP_API || "app" !in found.scopes -> ServerFit.TOO_OLD
found.appApi > APP_API -> ServerFit.TOO_NEW
else -> ServerFit.FITS
}
@@ -233,6 +233,50 @@ data class ShowCard(
}
}
// --- The person's files (`GET /files`, `GET /files/content`) ----------------------------------
/** One entry of a directory: `kind` is `file`, `dir` or `mount`. */
@Serializable
data class FileEntry(
val name: String = "",
val path: String = "",
val kind: String = "file",
val size: Long = 0,
val mime: String = "",
@SerialName("updated_at") val updatedAt: String? = null,
) {
/** A directory or a mount: something to open as a listing, not in the viewer. */
val isFolder: Boolean get() = kind == "dir" || kind == "mount"
}
/** A directory, through the person's own access. `parent` is null at `/`. */
@Serializable
data class FileListing(val path: String = "/", val parent: String? = null, val entries: List<FileEntry> = emptyList())
/** Why a file's text did not come: `reason` is `not_text` or `too_large`; `message` says it. */
@Serializable
data class Withheld(val reason: String = "", val message: String = "")
/**
* A file's text, as the explorer's viewer reads it. An HTML file is its source, never rendered;
* a file that is not text or is over 1 MB has an empty [text] and says why in [withheld].
*/
@Serializable
data class FileContent(
val path: String = "",
val name: String = "",
val size: Long = 0,
val mime: String = "",
val kind: String = "text",
val language: String = "",
val sha: String = "",
val text: String = "",
val withheld: Withheld? = null,
) {
/** The kind the viewer draws, by the `show` card's rule: anything unknown is plain text. */
val viewKind: String get() = if (kind in ShowCard.VIEW_KINDS) kind else "text"
}
@Serializable
data class SteerNote(val id: String = "", val text: String = "")
@@ -1,4 +1,4 @@
// Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at f5b3dbb965823ade56d57bf5e1d09900eb5946f2. Do not edit.
// Generated by scripts/fetch-tokens.py from the LLeMbas server's tokens.css at a25db24971a07823bda9f8dbaf517f15960536a7. Do not edit.
package eu.llembas.android.ui.theme
import androidx.compose.ui.graphics.Color