Assistant: a bottom sheet over the app, microphone first
CI / check (push) Canceled after 0s

Long-press power opened a full-screen window. The assistant is now a sheet
over the current app (see-through window, own dim): half height, drag the
handle up to full, down / Back / a tap outside to close (settle() decides,
unit-tested). Both ways in -- the voice-interaction session and AssistActivity
-- draw the same AssistSheetFrame + AssistSheetContent, the latter from state
alone for the screenshot tests.

- Microphone first: it opens listening (Settings switch), words shown as they
  come. LLeMbas voice input re-transcribes the recording so far every 1.2 s
  and a pause after speech sends it (RMS level + unchanged words; nothing said
  is discarded, never transcribed); the phone's recogniser gives partials
  itself (PhoneRecognizer: on-device, else another app's -- never the default,
  which is LLeMbas's own while it is the assistant; no Google library).
- Model and connection chip: picture, name, instance, online dot; a tap picks
  another model, kept in Prefs.assistantModel.
- Use screen: the AssistStructure text and/or screenshot, sent only with the
  next question after a tap; quick actions Summarise / Translate / Explain.
- Continue the last assistant chat; follow-ups stay in the same chat until
  New chat. Voice reply through the server's TTS (toggle; Read aloud).
- Open in app continues the same chat. A card waiting for an answer says to
  open it in the app.
- Help line: no wake word for a third-party assistant on stock Android.
- Settings: Voice input (LLeMbas = the instance's speech-to-text via the
  server; Phone = the phone's recogniser) with what each does with the
  recording, and "Start listening when the assistant opens".
- The session makes a fresh controller as it hides, so the next invocation's
  screen lands in the controller that shows it.

Screenshots 18-23 (the sheet over a chat), 08-settings at full length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 08:19:21 +00:00
1 parent 6ae5736ffd
commit 21e5de2d73
24 files changed
+2097 -240

No files matched your search

@@ -0,0 +1,76 @@
package eu.llembas.android
import eu.llembas.android.api.LiveReply
import eu.llembas.android.api.Step
import eu.llembas.android.api.Tail
import eu.llembas.android.assist.AssistController
import eu.llembas.android.assist.AssistTurn
import eu.llembas.android.assist.Recorder
import eu.llembas.android.assist.SheetStop
import eu.llembas.android.assist.settle
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class AssistTest {
private val half = 1000f
private val full = 1800f
@Test
fun aSlowReleaseGoesToTheNearestStop() {
assertEquals(SheetStop.Half, settle(1100f, half, full, 0f))
assertEquals(SheetStop.Full, settle(1500f, half, full, 0f))
assertEquals(SheetStop.Half, settle(800f, half, full, 0f))
// Pulled well below the half: it goes.
assertEquals(SheetStop.Gone, settle(500f, half, full, 0f))
}
@Test
fun aFlingDecidesByItsDirection() {
assertEquals(SheetStop.Full, settle(1010f, half, full, -3000f))
// Down from the full height: to the half, not away.
assertEquals(SheetStop.Half, settle(1700f, half, full, 3000f))
// Down from the half: away.
assertEquals(SheetStop.Gone, settle(990f, half, full, 3000f))
}
@Test
fun aTurnShowsWhatIsWrittenThenWhatWasWritten() {
val asked = AssistTurn("Why?")
assertFalse(asked.writing)
val writing = asked.copy(reply = LiveReply("m1", tail = Tail(text = "Because")))
assertTrue(writing.writing)
assertEquals("Because", writing.steps.single().markdown)
val earlier = AssistTurn("Why?", earlier = listOf(Step(kind = "text", markdown = "Because.")))
assertFalse(earlier.writing)
assertEquals("Because.", earlier.steps.single().markdown)
}
@Test
fun aVoiceReadsOnlyTheWords() {
val steps = listOf(
Step(kind = "thinking", text = "Hmm."),
Step(kind = "text", markdown = "**Two** days."),
Step(kind = "tools"),
Step(kind = "text", markdown = "See [this](https://example.org)."),
)
assertEquals("Two days. See this.", AssistController.spokenWords(steps))
}
@Test
fun silenceIsQuietAndAToneIsLoud() {
assertEquals(0f, Recorder.rms(ByteArray(3200), 3200), 0f)
// A full-scale square wave: every sample at +-32767.
val loud = ByteArray(3200) { i ->
if (i % 2 == 0) {
0xFF.toByte()
} else if ((i / 2) % 2 == 0) {
0x7F
} else {
0x80.toByte()
}
}
assertTrue(Recorder.rms(loud, loud.size) > 0.9f)
}
}
@@ -28,6 +28,10 @@ import eu.llembas.android.api.SubagentsOffer
import eu.llembas.android.api.Tail
import eu.llembas.android.api.ToolBlock
import eu.llembas.android.api.ToolCall
import eu.llembas.android.assist.AssistTurn
import eu.llembas.android.assist.AssistUiState
import eu.llembas.android.assist.Connection
import eu.llembas.android.assist.LastAssist
import eu.llembas.android.auth.Instance
import eu.llembas.android.auth.Prefs
import eu.llembas.android.ui.chat.ChatState
@@ -220,6 +224,56 @@ object Fakes {
hasDistributor = true,
version = "1.0.0-beta.3",
selfUpdate = true,
phoneRecognizer = true,
)
// The assistant's sheet, as it opens and as it answers.
private val assistBase = AssistUiState(
instanceName = "Home",
connection = Connection.Online,
models = models,
modelId = models.firstOrNull { it.default }?.id ?: models.firstOrNull()?.id,
canSpeak = true,
)
/** Just opened over an app that handed over its screen: listening, the words coming in. */
val assistListening = assistBase.copy(
listening = true,
heard = "How long does waybread keep if it is wrapped in",
level = 0.4f,
screenText = true,
last = LastAssist("c1", "Packing for the road", 0),
)
/** Opened from the tile, nothing asked yet: the last chat, the help, the microphone. */
val assistOpened = assistBase.copy(last = LastAssist("c1", "Packing for the road", 0), screenText = true, includeScreen = true)
/** A spoken question answered, the answer read aloud. */
val assistAnswered = assistBase.copy(
chatId = "c9",
turns = listOf(AssistTurn(question.text.orEmpty(), earlier = answer.steps)),
speaking = true,
)
/** An answer being written. */
val assistWriting = assistBase.copy(
chatId = "c9",
busy = true,
turns = listOf(
AssistTurn(
"What is on my screen?",
reply = LiveReply("m9", tail = Tail(text = "It is a recipe for waybread: flour, honey and a leaf to wrap it in. The"), status = "Writing…"),
),
),
)
/** The instance cannot be reached. */
val assistOffline = assistBase.copy(
connection = Connection.Offline,
models = emptyList(),
modelId = null,
canSpeak = false,
error = "Home cannot be reached.",
)
// Scheduled: shaped as the server's contract fixtures are (contract/schedule*.json).
@@ -16,6 +16,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import eu.llembas.android.assist.AssistActions
import eu.llembas.android.assist.AssistSheetContent
import eu.llembas.android.assist.AssistSheetFrame
import eu.llembas.android.assist.AssistUiState
import eu.llembas.android.ui.chat.ActivityActions
import eu.llembas.android.ui.chat.ActivityContent
import eu.llembas.android.ui.chat.ChatActions
@@ -49,6 +53,8 @@ private object NoActivityActions : ActivityActions
private object NoSettingsActions : SettingsActions
private object NoAssistActions : AssistActions
/**
* The app's screens with made-up data ([Fakes]), as a phone shows them: each in Shire and
* Moria, at a large phone's size and, where things crowd, a small one's and with large type.
@@ -124,6 +130,8 @@ class ScreenShots {
fun settings() {
shoot("08-settings") { SettingsContent(Fakes.settings, NoSettingsActions) }
shoot("08-settings", Phone.Small) { SettingsContent(Fakes.settings, NoSettingsActions) }
// The whole page: Language, the assistant's switches and Voice input.
shoot("08-settings", Phone.Scroll) { SettingsContent(Fakes.settings, NoSettingsActions) }
}
@Test
@@ -166,6 +174,30 @@ class ScreenShots {
}
}
/**
* The assistant's sheet over an app (a chat stands in for whatever was on screen): at half
* height as it opens, at a small phone's size and with large type too.
*/
@Test
fun assistant() {
val over: (AssistUiState, Boolean) -> @Composable () -> Unit = { state, locked ->
{
Box(Modifier.fillMaxSize()) {
ChatContent(Fakes.transcript, NoChatActions, agent = false)
AssistSheetFrame(onDismiss = {}) { handle, _ -> AssistSheetContent(state, NoAssistActions, locked, handle) }
}
}
}
shoot("18-assistant-listening", content = over(Fakes.assistListening, false))
shoot("18-assistant-listening", Phone.Small, fontScale = 1.5f, content = over(Fakes.assistListening, false))
shoot("19-assistant-opened", content = over(Fakes.assistOpened, false))
shoot("19-assistant-opened", Phone.Small, content = over(Fakes.assistOpened, false))
shoot("20-assistant-answered", content = over(Fakes.assistAnswered, false))
shoot("21-assistant-writing", content = over(Fakes.assistWriting, false))
shoot("22-assistant-locked", content = over(Fakes.assistOpened, true))
shoot("23-assistant-offline", Phone.Small, content = over(Fakes.assistOffline, false))
}
@Test
fun schedulingModels() = shoot("13-scheduling-models") { SchedulingModelsContent(Fakes.schedulingModels) }
}