mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Fix Agent controls in the session drawer (#2568)
* Open full agent controls from compact composer * Keep session drawer agent controls keyboard free * Keep agent controls inline beside close * Preserve Agent page Lab ABI compatibility * Open session drawer editor with controls closed * Consume Agent editor focus requests * Keep session editor open during focus transition
This commit is contained in:
1 parent
392562bfae
commit
69b612be1f
2 files changed
+51
-17
No files matched your search
@@ -129,6 +129,18 @@ private const val COMPOSER_SLIDE_MS = 350L
|
||||
@Composable
|
||||
internal fun AgentPage(
|
||||
modifier: Modifier, inputModifier: Modifier = Modifier, visible: Boolean = true, startTyping: Boolean = true, hidesPet: Boolean = true,
|
||||
) = AgentPageContent(modifier, inputModifier, visible, startTyping, hidesPet, showControlsWithoutKeyboard = false)
|
||||
|
||||
@Composable
|
||||
internal fun AgentPageWithControls(
|
||||
modifier: Modifier, inputModifier: Modifier = Modifier, visible: Boolean = true, startTyping: Boolean = true,
|
||||
showControlsWithoutKeyboard: Boolean,
|
||||
) = AgentPageContent(modifier, inputModifier, visible, startTyping, hidesPet = true, showControlsWithoutKeyboard = showControlsWithoutKeyboard)
|
||||
|
||||
@Composable
|
||||
private fun AgentPageContent(
|
||||
modifier: Modifier, inputModifier: Modifier, visible: Boolean, startTyping: Boolean, hidesPet: Boolean,
|
||||
showControlsWithoutKeyboard: Boolean,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val view = LocalView.current
|
||||
@@ -227,7 +239,7 @@ internal fun AgentPage(
|
||||
}
|
||||
}
|
||||
androidx.compose.animation.AnimatedVisibility(!hidden, enter = expandVertically() + fadeIn(), exit = shrinkVertically() + fadeOut()) {
|
||||
AgentComposer(composer, draft, inputModifier, panel, togglePanel) { setup = true }
|
||||
AgentComposer(composer, draft, inputModifier, panel, togglePanel, showControlsWithoutKeyboard) { setup = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,6 +252,7 @@ private class ComposerState(typing: Boolean) {
|
||||
var typing by mutableStateOf(typing)
|
||||
var focusRequests by mutableIntStateOf(0)
|
||||
private set
|
||||
private var consumedFocusRequests by mutableIntStateOf(0)
|
||||
/** Opened and waiting for the text field to take focus; focus passes through nothing on the way. */
|
||||
var opening = false
|
||||
|
||||
@@ -248,6 +261,12 @@ private class ComposerState(typing: Boolean) {
|
||||
opening = true
|
||||
focusRequests++
|
||||
}
|
||||
|
||||
fun hasUnconsumedFocusRequest() = focusRequests > consumedFocusRequests
|
||||
|
||||
fun consumeFocusRequest() {
|
||||
consumedFocusRequests = focusRequests
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -492,12 +511,14 @@ internal fun liveUsed(limit: AgentHost.Limit) = if (limit.resetsAt > 0 && limit.
|
||||
|
||||
@Composable
|
||||
private fun AgentComposer(
|
||||
composer: ComposerState, draftState: MutableState<String>, inputModifier: Modifier, panel: AgentPanel, onPanel: (AgentPanel) -> Unit, onSetup: () -> Unit,
|
||||
composer: ComposerState, draftState: MutableState<String>, inputModifier: Modifier, panel: AgentPanel, onPanel: (AgentPanel) -> Unit,
|
||||
showControlsWithoutKeyboard: Boolean, onSetup: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var draft by draftState
|
||||
var labOpen by rememberSaveable { mutableStateOf(false) }
|
||||
if (AgentHost.lab == null) labOpen = false
|
||||
var controlsOpen by rememberSaveable { mutableStateOf(false) }
|
||||
var hadFocus by remember { mutableStateOf(false) }
|
||||
val send = send@{
|
||||
val text = draft.trim()
|
||||
@@ -538,15 +559,25 @@ private fun AgentComposer(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(top = 8.dp).fillMaxWidth().horizontalScroll(rememberScrollState()),
|
||||
) { AgentActivity(labOpen) { labOpen = !labOpen } }
|
||||
AgentEditor(composer, draftState, inputModifier, panel, onPanel, onSetup, send)
|
||||
} else AgentReadingBar(composer, draft, inputModifier, labOpen, onLab = { labOpen = !labOpen }) { onPanel(AgentPanel.USAGE) }
|
||||
AgentEditor(composer, draftState, inputModifier, panel, onPanel, onSetup, controlsOpen, { controlsOpen = it },
|
||||
highlightControls = showControlsWithoutKeyboard, send = send)
|
||||
} else AgentReadingBar(composer, draft, inputModifier, labOpen, onLab = { labOpen = !labOpen }) {
|
||||
if (showControlsWithoutKeyboard) {
|
||||
controlsOpen = false
|
||||
composer.typing = true
|
||||
composer.opening = true
|
||||
} else {
|
||||
controlsOpen = true
|
||||
composer.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The composer while reading: one line holding what is going on, opened by a press or by Y. */
|
||||
@Composable
|
||||
private fun AgentReadingBar(
|
||||
composer: ComposerState, draft: String, inputModifier: Modifier, labOpen: Boolean, onLab: () -> Unit, onUsage: () -> Unit,
|
||||
composer: ComposerState, draft: String, inputModifier: Modifier, labOpen: Boolean, onLab: () -> Unit, onControls: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
@@ -569,7 +600,7 @@ private fun AgentReadingBar(
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.weight(1f).padding(start = 8.dp).horizontalScroll(rememberScrollState()),
|
||||
) { AgentActivity(labOpen, onLab) }
|
||||
ContextRing("agent-usage-bar", onUsage)
|
||||
HeaderAction(Icons.Outlined.MoreHoriz, stringResource(R.string.agent_more), size = 36.dp, tag = "agent-controls", onClick = onControls)
|
||||
if (working) Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.padding(start = 4.dp).size(36.dp).clip(CircleShape).background(pal.error.copy(alpha = 0.22f))
|
||||
@@ -582,7 +613,7 @@ private fun AgentReadingBar(
|
||||
@Composable
|
||||
private fun AgentEditor(
|
||||
composer: ComposerState, draftState: MutableState<String>, inputModifier: Modifier, panel: AgentPanel, onPanel: (AgentPanel) -> Unit,
|
||||
onSetup: () -> Unit, send: () -> Unit,
|
||||
onSetup: () -> Unit, menu: Boolean, onMenu: (Boolean) -> Unit, highlightControls: Boolean = false, send: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
@@ -608,12 +639,11 @@ private fun AgentEditor(
|
||||
for (path in AgentAttachments.pending.toList()) AttachmentChip(path) { AgentAttachments.pending.remove(path) }
|
||||
}
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
var menu by rememberSaveable { mutableStateOf(false) }
|
||||
val field = remember { FocusRequester() }
|
||||
LaunchedEffect(composer.focusRequests) { if (composer.focusRequests > 0) runCatching { field.requestFocus() } }
|
||||
LaunchedEffect(composer.focusRequests) { if (composer.hasUnconsumedFocusRequest()) runCatching { field.requestFocus() } }
|
||||
Column(
|
||||
Modifier.fillMaxWidth().padding(top = 8.dp).clip(Shape16).background(colors.surface)
|
||||
.border(1.dp, if (focused) pal.primary else pal.line, Shape16).padding(6.dp),
|
||||
.border(if (focused || highlightControls) 2.dp else 1.dp, if (focused || highlightControls) pal.primary else pal.line, Shape16).padding(6.dp),
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().height(36.dp)) {
|
||||
val model = AgentHost.models(context).firstOrNull { it.id == AgentHost.model }?.label ?: AgentHost.model ?: stringResource(R.string.agent_model_default)
|
||||
@@ -631,21 +661,21 @@ private fun AgentEditor(
|
||||
ContextRing("agent-usage", onClick = { onPanel(AgentPanel.USAGE) })
|
||||
}
|
||||
if (menu) {
|
||||
HeaderAction(Icons.Outlined.History, stringResource(R.string.agent_history), size = 32.dp, tag = "agent-history") { menu = false; onPanel(AgentPanel.HISTORY) }
|
||||
HeaderAction(Icons.Outlined.Memory, stringResource(R.string.agent_processes), size = 32.dp, tag = "agent-processes") { menu = false; onPanel(AgentPanel.PROCESSES) }
|
||||
HeaderAction(Icons.Outlined.History, stringResource(R.string.agent_history), size = 32.dp, tag = "agent-history") { onMenu(false); onPanel(AgentPanel.HISTORY) }
|
||||
HeaderAction(Icons.Outlined.Memory, stringResource(R.string.agent_processes), size = 32.dp, tag = "agent-processes") { onMenu(false); onPanel(AgentPanel.PROCESSES) }
|
||||
HeaderAction(Icons.Outlined.Add, stringResource(R.string.agent_new), enabled = !working && AgentHost.entries.isNotEmpty(), size = 32.dp, tag = "agent-new") {
|
||||
menu = false
|
||||
onMenu(false)
|
||||
AgentHost.forget(context)
|
||||
}
|
||||
HeaderAction(Icons.Outlined.Pets, stringResource(R.string.setup_agent_pet), selected = AgentPet.enabled, size = 32.dp, tag = "agent-pet-toggle") {
|
||||
AgentPet.set(context, !AgentPet.enabled)
|
||||
}
|
||||
HeaderAction(Icons.Outlined.Settings, stringResource(R.string.agent_setup_title), enabled = !working, size = 32.dp, tag = "agent-settings") {
|
||||
menu = false
|
||||
onMenu(false)
|
||||
onSetup()
|
||||
}
|
||||
}
|
||||
HeaderAction(if (menu) Icons.Outlined.Close else Icons.Outlined.MoreHoriz, stringResource(R.string.agent_more), size = 32.dp, tag = "agent-menu") { menu = !menu }
|
||||
HeaderAction(if (menu) Icons.Outlined.Close else Icons.Outlined.MoreHoriz, stringResource(R.string.agent_more), size = 32.dp, tag = "agent-menu") { onMenu(!menu) }
|
||||
}
|
||||
Row(verticalAlignment = Alignment.Bottom) {
|
||||
if (LocalActivityResultRegistryOwner.current != null) AttachButton()
|
||||
@@ -658,7 +688,10 @@ private fun AgentEditor(
|
||||
draft, { draft = it },
|
||||
Modifier.fillMaxWidth().focusRequester(field).onFocusChanged {
|
||||
focused = it.isFocused
|
||||
if (it.isFocused) composer.opening = false
|
||||
if (it.isFocused) {
|
||||
composer.consumeFocusRequest()
|
||||
composer.opening = false
|
||||
}
|
||||
}.testTag("agent-input").then(inputModifier),
|
||||
textStyle = TextStyle(fontSize = 16.sp, color = colors.onSurface),
|
||||
cursorBrush = SolidColor(pal.primary),
|
||||
|
||||
@@ -558,11 +558,12 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
tabModifier = { key -> focus.track(page, "glasses-tab-$key").testTag("glasses-tab-$key") },
|
||||
) { selectedGlassesTab = it }
|
||||
// The agent's chat scrolls itself and keeps its composer at the bottom, so it takes the height left.
|
||||
if (page == SessionDrawerPage.AGENT) AgentPage(
|
||||
if (page == SessionDrawerPage.AGENT) AgentPageWithControls(
|
||||
Modifier.weight(1f).fillMaxWidth().padding(top = 8.dp, start = 14.dp, end = 14.dp),
|
||||
inputModifier = focus.track(page, "agent-input"),
|
||||
visible = open,
|
||||
startTyping = false,
|
||||
showControlsWithoutKeyboard = true,
|
||||
) else Column(
|
||||
modifier = Modifier.weight(1f).fillMaxWidth().verticalScroll(pageScroll.getValue(page)),
|
||||
) { CompositionLocalProvider(LocalChipMinWidth provides 96.dp, LocalCompactSettings provides true) {
|
||||
|
||||
Reference in new issue
Block a user