Generate images from the composer; the picture in its own safe composable
CI / check (push) Canceled after 0s

+ › Generate images (when /me services.images) marks the next message, shown as a chip under
the box; it is sent with force_tool image_generate (the server's only forceable tool) on
POST /chats/{id}/messages. The tool event's `image {id, width, height}` is drawn by
GeneratedPicture: fetched only by attachment id from GET /api/v2/attachments/{id} with the
token (no URL is ever followed), at most 24 MB, decoded to a 1600 px edge, its box sized by the
server's width/height before it loads; a tap shows it whole. Markwon stays image-free.

Chosen over /v1/images/generations (models scope, which sign-in already asks): the in-chat tool
keeps the picture in the chat as the web does. A NEW chat cannot force a tool yet (POST /chats
takes no force_tool), so the option shows in an existing chat only -- server follow-up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 13:54:34 +00:00
1 parent 87d391c352
commit d9654dd23c
20 files changed
+258 -4

No files matched your search

@@ -15,6 +15,21 @@ import org.junit.Test
* cards are in `contract/tool_show.json` and read by `ContractTest`.
*/
class ShowAndServerTest {
@Test
fun aGeneratedPictureIsAnAttachmentIdAndASize() {
// services/images/tool.py: `image: {id, width, height}` on the tool event; no URL at all.
val call = LembasJson.decodeFromString(
ToolCall.serializer(),
"""{"id":"t1","name":"image_generate","status":"ok","attachment_id":"att1",
"image":{"id":"att1","width":1216,"height":832},"block":{"kind":"image","title":"a leaf"}}""",
)
assertEquals("att1", call.image!!.id)
assertEquals(1216, call.image!!.width)
assertEquals(832, call.image!!.height)
assertNull(LembasJson.decodeFromString(ToolCall.serializer(), """{"name":"read"}""").image)
assertEquals("image_generate", eu.llembas.android.ui.chat.IMAGE_TOOL)
}
private fun call(json: String) = LembasJson.decodeFromString(ToolCall.serializer(), json)
@Test
@@ -10,6 +10,7 @@ import eu.llembas.android.api.Chat
import eu.llembas.android.api.ContextPart
import eu.llembas.android.api.DataGroup
import eu.llembas.android.api.Folder
import eu.llembas.android.api.GeneratedImage
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LinkedDevice
import eu.llembas.android.api.LiveReply
@@ -115,6 +116,38 @@ object Fakes {
val chat = Chat(id = "c1", title = "Packing for the road", model = "qwen", updatedAt = "2026-03-10T09:00:00+00:00")
// A picture the instance made, and the composer asking for the next one.
val picture = ChatState(
chat = chat,
models = models,
imagesOffered = true,
draft = Draft(image = true),
messages = listOf(
Message(id = "p1", role = "user", text = "Draw lembas wrapped in a mallorn leaf, on a wooden table."),
Message(
id = "p2",
role = "assistant",
model = "qwen",
steps = listOf(
Step(
index = 0,
kind = "tools",
calls = listOf(
ToolCall(
id = "g1",
name = "image_generate",
status = "ok",
image = GeneratedImage(id = "att-picture", width = 1216, height = 832),
block = ToolBlock(kind = "image", title = "lembas in a mallorn leaf"),
),
),
),
Step(index = 1, kind = "text", markdown = "Here it is: the leaf folded twice, as the elves wrap it."),
),
),
),
)
val newChat = ChatState(models = models)
val newAgentChat = ChatState(
@@ -250,6 +250,13 @@ class ScreenShots {
shoot("27-archived-none") { ArchivedContent(ChatsState(), NoArchivedActions) }
}
@Test
fun picture() {
// The picture's place is its size before it loads (screenshots fetch nothing).
shoot("29-generated-image") { ChatContent(Fakes.picture, NoChatActions, agent = false) }
shoot("29-generated-image", Phone.Small, fontScale = 1.5f) { ChatContent(Fakes.picture, NoChatActions, agent = false) }
}
@Test
fun memory() {
shoot("28-memory") { MemoryContent(Fakes.memory, NoMemoryActions) }