Android 1.0 for server 2.0: the file viewer, and older servers refused
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
The show card. A tool call may now carry `show` (event["show"], harness spec 3.0.0): a file's
name, path, kind, line and which copy -- node and version in the chat's tree, or the copy a linked
device sent (shown_id). The transcript draws it as a card with Open; the viewer is a full-screen,
read-only dialog that fetches the text and opens at the named line. Markdown goes through the same
Markwon setup as a reply (rule 4); code, text and Markdown over 200 000 characters are numbered
lines in a lazy list, the number column measured from the file's longest number. HTML is never
rendered: no WebView exists in the app, so it is shown as source, and "Open in the browser" opens
the web UI's viewer, which renders it in its sealed frame. Copy takes the whole file.
The text comes from GET /api/v2/chats/{chat}/show?node=&version= (or ?shown=), plain text, at most
1 MB. That route is the app's half of a contract the server does not have yet: /api/v2 neither
publishes `show` on a tool call nor serves the file to a token. Until it does, the card does not
appear, and a viewer that meets a missing route says so and offers the browser.
Older servers are refused: the discovery document's device-link protocol must be 3 (LLeMbas 2.0),
at sign-in and, for an instance signed in to before, when the chat list opens. The protocol and
not the version string, because the server's dev still says 1.7.x before its first beta.
Also: gen-strings.py takes a server ref like the other two generators, so the strings come from
the same commit as the contract and the tokens rather than from a shared working tree; the
Reports notification channel goes (2.0 has no reports) and is deleted on first start.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
25 files changed
+754
-62
No files matched your search
@@ -227,6 +227,38 @@ 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.
|
||||
*/
|
||||
suspend fun shownText(chatId: String, show: ShowCard): String = withContext(Dispatchers.IO) {
|
||||
val url = "$v2/chats/$chatId/show".toHttpUrl().newBuilder()
|
||||
.apply { show.query.forEach { (k, v) -> addQueryParameter(k, v) } }
|
||||
.build()
|
||||
http.newCall(authed(url.toString()).header("Accept", "text/plain").get().build()).await().use {
|
||||
if (!it.isSuccessful) throw ApiException(it.code, detail(it))
|
||||
val body = it.body!!
|
||||
// The server shows at most 1 MB; anything much larger is not a file it meant.
|
||||
if (body.contentLength() > SHOWN_MAX_BYTES) throw ApiException(413, "")
|
||||
val bytes = body.source().use { source ->
|
||||
source.request(SHOWN_MAX_BYTES + 1)
|
||||
source.buffer.readByteArray(minOf(source.buffer.size, SHOWN_MAX_BYTES + 1))
|
||||
}
|
||||
if (bytes.size > SHOWN_MAX_BYTES) throw ApiException(413, "")
|
||||
bytes.toString(Charsets.UTF_8)
|
||||
}
|
||||
}
|
||||
|
||||
/** 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) } }
|
||||
.apply { if (show.line > 0) addQueryParameter("line", show.line.toString()) }
|
||||
.build()
|
||||
.toString()
|
||||
|
||||
// --- Push --------------------------------------------------------------------------------
|
||||
suspend fun pushKey(): PushKey = get("/push")
|
||||
|
||||
@@ -265,6 +297,9 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
authed("$v2/chats/$chatId/messages/$messageId/stream").header("Accept", "text/event-stream").build()
|
||||
|
||||
companion object {
|
||||
/** 1 MB, the server's own limit on a shown file, with room for a little more. */
|
||||
const val SHOWN_MAX_BYTES = 1_100_000L
|
||||
|
||||
fun emptyBody(): RequestBody = ByteArray(0).toRequestBody(null)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user