- ModelInfo.subagents, ModelList.subagents_cap, Chat.subagents {offered, named_only, cap},
Activity.subagents_offered, ContextUse.auto_compact/until_compact/compactable: all
optional, so an older server still parses and the app falls back to its old guess.
- The Subagents setting: shown by offered, the one-request note when named_only, sliders
from 1 to the cap (ticks up to 8), none at a cap of 1.
- Compact disabled when the server says there is nothing to compact yet.
- The context's number columns widen with the type (they touched at 1.5x).
- SubagentsTest; shots 07-tune-one-at-a-time and a tall 411x2000 for the activity sheet.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
22 files changed
+248
-41
No files matched your search
@@ -60,9 +60,13 @@ object ActivityLogic {
|
||||
/**
|
||||
* How many tokens are left before the chat compacts itself: the window's [ContextUse.threshold]
|
||||
* per cent, less what is used. Null when it never will -- the threshold is 0 (off) or 100,
|
||||
* or the window is unknown -- since a count against an unknown window is a guess.
|
||||
* or the window is unknown -- since a count against an unknown window is a guess. The
|
||||
* server's [ContextUse.untilCompact] and [ContextUse.autoCompact] win where it says them.
|
||||
*/
|
||||
fun untilAutoCompact(context: ContextUse): Int? {
|
||||
// The server's own count, where it gives one.
|
||||
if (context.autoCompact == false) return null
|
||||
context.untilCompact?.let { return it.coerceAtLeast(0) }
|
||||
if (context.limit <= 0 || context.threshold !in 1..99) return null
|
||||
return (context.limit.toLong() * context.threshold / 100 - context.used).toInt().coerceAtLeast(0)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,10 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
// --- Account -----------------------------------------------------------------------------
|
||||
suspend fun me(): Me = get("/me")
|
||||
|
||||
suspend fun models(chatId: String? = null): List<ModelInfo> = get<ModelList>(if (chatId != null) "/models?chat=$chatId" else "/models").models
|
||||
suspend fun models(chatId: String? = null): List<ModelInfo> = modelList(chatId).models
|
||||
|
||||
/** The models with the instance's subagent cap; with [chatId], whether each is offered subagents on that chat. */
|
||||
suspend fun modelList(chatId: String? = null): ModelList = get(if (chatId != null) "/models?chat=$chatId" else "/models")
|
||||
|
||||
suspend fun folders(): List<Folder> = get<FolderList>("/folders").folders
|
||||
|
||||
|
||||
@@ -95,6 +95,8 @@ data class ModelInfo(
|
||||
/** The picture's path on the instance (`/api/v2/models/images/…`), read with the token. */
|
||||
val image: String? = null,
|
||||
val default: Boolean = false,
|
||||
/** Whether a new chat on this model is offered subagents (server 2.0.0-beta.7); null from an older one. */
|
||||
val subagents: SubagentsOffer? = null,
|
||||
) {
|
||||
/**
|
||||
* The levels, for a server that says them; an older one said only `efforts`, offered after
|
||||
@@ -118,12 +120,12 @@ data class ModelInfo(
|
||||
val onLevel: String get() = offered.firstOrNull { it != "off" } ?: effort
|
||||
|
||||
/**
|
||||
* Whether a new chat on this model may have a team, as far as the app can tell: the model
|
||||
* serves two requests at once (`parallel` ≥ 2, or no stated limit) and takes tools. The
|
||||
* server also needs subagents on, which only an existing chat's activity says
|
||||
* (`team_offered`); a setting it does not use is kept and does nothing.
|
||||
* Whether a new chat on this model is offered subagents: the server's word
|
||||
* (`subagents.offered`) when it says it. An older server did not, and then the app guesses
|
||||
* from the model alone: it serves two requests at once (`parallel` ≥ 2, or no stated
|
||||
* limit) and takes tools.
|
||||
*/
|
||||
val mayHaveTeam: Boolean get() = tools && (parallel == null || parallel >= 2)
|
||||
val mayHaveTeam: Boolean get() = subagents?.offered ?: (tools && (parallel == null || parallel >= 2))
|
||||
|
||||
companion object {
|
||||
val CONTROLS = setOf("none", "switch", "slider")
|
||||
@@ -131,7 +133,20 @@ data class ModelInfo(
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ModelList(val models: List<ModelInfo> = emptyList())
|
||||
data class ModelList(
|
||||
val models: List<ModelInfo> = emptyList(),
|
||||
/** The instance's cap on a chat's subagents (server 2.0.0-beta.7); null from an older one. */
|
||||
@SerialName("subagents_cap") val subagentsCap: Int? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
* Whether subagents are offered (harness spec 3.3.0, `subagents.md` §4): [offered] when
|
||||
* subagents are on and at least one model could serve; [namedOnly] when only a model the person
|
||||
* names in the chat could -- the chat's own serves one request at a time -- and the setting then
|
||||
* says so. [cap] is the instance's most, on a chat (not on a model).
|
||||
*/
|
||||
@Serializable
|
||||
data class SubagentsOffer(val offered: Boolean = false, @SerialName("named_only") val namedOnly: Boolean = false, val cap: Int? = null)
|
||||
|
||||
@Serializable
|
||||
data class Folder(val id: String, val name: String = "", @SerialName("parent_id") val parentId: String? = null, val kind: String = "", val position: Int = 0)
|
||||
@@ -172,6 +187,8 @@ data class Chat(
|
||||
val plan: JsonObject? = null,
|
||||
/** The team's size: how many agents, its own included, the chat may have. */
|
||||
val agents: AgentsSetting? = null,
|
||||
/** Whether this chat is offered subagents, and the cap (server 2.0.0-beta.7); null from an older one. */
|
||||
val subagents: SubagentsOffer? = null,
|
||||
) {
|
||||
val isAgent: Boolean get() = kind == "agent"
|
||||
}
|
||||
@@ -588,6 +605,14 @@ data class ContextUse(
|
||||
val percent: Double? = null,
|
||||
val measured: Boolean = false,
|
||||
val threshold: Int = 0,
|
||||
/**
|
||||
* The compaction facts (server 2.0.0-beta.7): whether the chat compacts by itself, how many
|
||||
* tokens before it does (null: never, or not known), and whether Compact can run now.
|
||||
* Null from an older server; the app then works the first two out from [threshold].
|
||||
*/
|
||||
@SerialName("auto_compact") val autoCompact: Boolean? = null,
|
||||
@SerialName("until_compact") val untilCompact: Int? = null,
|
||||
val compactable: Boolean? = null,
|
||||
@SerialName("tools_count") val toolsCount: Int = 0,
|
||||
@SerialName("mcp_count") val mcpCount: Int = 0,
|
||||
val categories: List<ContextPart> = emptyList(),
|
||||
@@ -613,6 +638,8 @@ data class Activity(
|
||||
val agents: List<ActivityAgent> = emptyList(),
|
||||
val team: ActivityTeam? = null,
|
||||
@SerialName("team_offered") val teamOffered: Boolean = false,
|
||||
/** The same fact by the word a person reads (server 2.0.0-beta.7). */
|
||||
@SerialName("subagents_offered") val subagentsOffered: Boolean? = null,
|
||||
val context: ContextUse? = null,
|
||||
val outputs: List<Output> = emptyList(),
|
||||
val plan: JsonObject? = null,
|
||||
|
||||
@@ -63,6 +63,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -373,7 +374,7 @@ private fun Empty(text: String) {
|
||||
@Composable
|
||||
private fun ContextSection(context: ContextUse?, canCompact: Boolean, compacting: Boolean, onCompact: () -> Unit) {
|
||||
val palette = LocalPalette.current
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
if (context == null) {
|
||||
Empty(stringResource(R.string.activity_not_measured))
|
||||
} else {
|
||||
@@ -405,9 +406,12 @@ private fun ContextSection(context: ContextUse?, canCompact: Boolean, compacting
|
||||
}
|
||||
}
|
||||
// Each row a fixed grid: swatch, the name that gives, two number columns of their own
|
||||
// width -- the numbers line up whatever the names say in which language.
|
||||
// width -- the numbers line up whatever the names say in which language. The columns
|
||||
// are as wide as five of their own figures, so large type widens them with it.
|
||||
val figures = MaterialTheme.typography.bodySmall.fontSize * 4.6f
|
||||
val column = with(LocalDensity.current) { figures.toDp() }
|
||||
context.categories.forEach { part ->
|
||||
Row(Modifier.fillMaxWidth().heightIn(min = 24.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Row(Modifier.fillMaxWidth().heightIn(min = 22.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(Modifier.size(10.dp).clip(RoundedCornerShape(2.dp)).background(categoryColour(palette, part.key)))
|
||||
Text(
|
||||
categoryName(part.key),
|
||||
@@ -420,14 +424,16 @@ private fun ContextSection(context: ContextUse?, canCompact: Boolean, compacting
|
||||
ActivityLogic.compactTokens(part.tokens),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
textAlign = TextAlign.End,
|
||||
modifier = Modifier.width(56.dp),
|
||||
maxLines = 1,
|
||||
modifier = Modifier.width(column),
|
||||
)
|
||||
Text(
|
||||
part.percent?.let { "${ActivityLogic.percent(it)}%" } ?: "—",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = palette.inkMuted,
|
||||
textAlign = TextAlign.End,
|
||||
modifier = Modifier.width(56.dp),
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(start = 4.dp).width(column),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -446,14 +452,16 @@ private fun ContextSection(context: ContextUse?, canCompact: Boolean, compacting
|
||||
when {
|
||||
context == null -> ""
|
||||
until != null -> stringResource(R.string.activity_until_compact, ActivityLogic.compactTokens(until))
|
||||
context.threshold <= 0 -> stringResource(R.string.activity_compact_off)
|
||||
context.autoCompact == false || context.threshold <= 0 -> stringResource(R.string.activity_compact_off)
|
||||
else -> ""
|
||||
},
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = palette.inkMuted,
|
||||
modifier = Modifier.weight(1f).padding(end = 8.dp),
|
||||
)
|
||||
OutlinedButton(onClick = onCompact, enabled = canCompact && !compacting && context != null) {
|
||||
// The server says when there is nothing to summarise yet (`compactable`); an older
|
||||
// one does not, and then its refusal says it in words.
|
||||
OutlinedButton(onClick = onCompact, enabled = canCompact && !compacting && context != null && context.compactable != false) {
|
||||
if (compacting) {
|
||||
CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
|
||||
@@ -61,8 +61,10 @@ data class ChatState(
|
||||
val activityAt: Long = 0,
|
||||
/** The strip's counts, from the events route (or the first read). */
|
||||
val summary: ActivitySummary? = null,
|
||||
/** Whether this chat may have a team: the server's word for a chat that exists. */
|
||||
/** Whether this chat is offered subagents: the activity's word for a chat that exists. */
|
||||
val teamOffered: Boolean = false,
|
||||
/** The instance's cap on a chat's subagents, from the models list; null from an older server. */
|
||||
val modelsCap: Int? = null,
|
||||
/** Whether the events route is followed; without it an open panel polls. */
|
||||
val activityLive: Boolean = false,
|
||||
/** A Compact asked for from the activity sheet and not answered yet. */
|
||||
@@ -95,8 +97,22 @@ val ChatState.modelInfo: ModelInfo? get() = models.firstOrNull { it.id == modelI
|
||||
val ChatState.level: String?
|
||||
get() = modelInfo?.takeIf { it.levelControl != "none" }?.level(if (chat == null) draft.effort else chat.effort?.ifBlank { null })
|
||||
|
||||
/** Whether a team may be asked for: the server's word for a chat that exists, the model's facts for a new one. */
|
||||
fun ChatState.offersTeam(agent: Boolean): Boolean = if (chat != null) teamOffered else !agent && modelInfo?.mayHaveTeam == true
|
||||
/**
|
||||
* Whether the Subagents setting is shown (plan rule 4): the chat's own word for a chat that
|
||||
* exists (`subagents.offered`, else the activity's), the model's for a new one.
|
||||
*/
|
||||
fun ChatState.offersTeam(agent: Boolean): Boolean = if (chat != null) chat.subagents?.offered ?: teamOffered else !agent && modelInfo?.mayHaveTeam == true
|
||||
|
||||
/**
|
||||
* Whether subagents need a model the person names in the chat: the chat's own serves one
|
||||
* request at a time. The setting then says so; there is no default to fall back on.
|
||||
*/
|
||||
val ChatState.subagentsNamedOnly: Boolean
|
||||
get() = (if (chat != null) chat.subagents?.namedOnly else modelInfo?.subagents?.namedOnly) ?: false
|
||||
|
||||
/** The most subagents a chat may have here: the chat's cap, else the instance's, else the spec's. */
|
||||
val ChatState.subagentsCap: Int
|
||||
get() = (chat?.subagents?.cap ?: modelsCap ?: AgentsSetting.CAP).coerceAtLeast(1)
|
||||
|
||||
/** The team's size in force. */
|
||||
val ChatState.agents: AgentsSetting get() = chat?.agents ?: draft.agents ?: AgentsSetting()
|
||||
@@ -170,7 +186,9 @@ class ChatViewModel(app: Application) :
|
||||
try {
|
||||
val client = api()
|
||||
_state.update { it.copy(loading = chatId != null || agent, error = null) }
|
||||
val models = runCatching { client.models(chatId) }.getOrDefault(emptyList())
|
||||
val list = runCatching { client.modelList(chatId) }.getOrNull()
|
||||
val models = list?.models.orEmpty()
|
||||
_state.update { it.copy(modelsCap = list?.subagentsCap) }
|
||||
if (chatId == null) {
|
||||
val devices = if (agent) client.devices() else emptyList()
|
||||
_state.update { it.copy(models = models, devices = devices, loading = false) }
|
||||
@@ -184,7 +202,7 @@ class ChatViewModel(app: Application) :
|
||||
// Whether a team is offered and what runs in the background: the cheap read,
|
||||
// without the context count. A server without the panel has no answer.
|
||||
runCatching { client.activity(chatId, context = false) }.onSuccess { a ->
|
||||
_state.update { it.copy(teamOffered = a.teamOffered, summary = a.summary) }
|
||||
_state.update { it.copy(teamOffered = a.subagentsOffered ?: a.teamOffered, summary = a.summary) }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
fail(e)
|
||||
@@ -348,7 +366,9 @@ class ChatViewModel(app: Application) :
|
||||
// Another model may serve one request at a time, or more: whether a team is offered
|
||||
// follows it.
|
||||
if (key == "model") {
|
||||
runCatching { api.activity(chat.id, context = false) }.onSuccess { r -> _state.update { it.copy(teamOffered = r.teamOffered) } }
|
||||
runCatching { api.activity(chat.id, context = false) }.onSuccess { r ->
|
||||
_state.update { it.copy(teamOffered = r.subagentsOffered ?: r.teamOffered) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +392,7 @@ class ChatViewModel(app: Application) :
|
||||
if (_state.value.summary == null) {
|
||||
// A chat its first message just made: whether a team is offered, read once.
|
||||
runCatching { client.activity(chat.id, context = false) }.onSuccess { a ->
|
||||
_state.update { it.copy(teamOffered = a.teamOffered, summary = a.summary) }
|
||||
_state.update { it.copy(teamOffered = a.subagentsOffered ?: a.teamOffered, summary = a.summary) }
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -410,7 +430,7 @@ class ChatViewModel(app: Application) :
|
||||
activity = if (context) read else read.copy(context = s.activity?.context),
|
||||
activityAt = SystemClock.elapsedRealtime(),
|
||||
summary = read.summary,
|
||||
teamOffered = read.teamOffered,
|
||||
teamOffered = read.subagentsOffered ?: read.teamOffered,
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -429,13 +429,26 @@ fun TuneContent(state: ChatState, actions: ChatActions, agent: Boolean, modifier
|
||||
color = palette.inkMuted,
|
||||
modifier = Modifier.padding(horizontal = 24.dp),
|
||||
)
|
||||
val now = state.agents
|
||||
Column(Modifier.padding(horizontal = 24.dp)) {
|
||||
AgentsSlider(stringResource(R.string.team_fewest), now.min) { v ->
|
||||
setTeam(actions, chat == null, AgentsSetting(v, maxOf(v, now.max)))
|
||||
}
|
||||
AgentsSlider(stringResource(R.string.team_most), now.max) { v ->
|
||||
setTeam(actions, chat == null, AgentsSetting(minOf(now.min, v), v))
|
||||
if (state.subagentsNamedOnly) {
|
||||
// The chat's model serves one request at a time: no default to fall back on.
|
||||
Text(
|
||||
stringResource(R.string.subagents_named_only),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = palette.warning,
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
val cap = state.subagentsCap
|
||||
val now = state.agents.let { AgentsSetting(it.min.coerceIn(1, cap), it.max.coerceIn(1, cap)) }
|
||||
// An instance that allows only one has nothing to choose between.
|
||||
if (cap > 1) {
|
||||
Column(Modifier.padding(horizontal = 24.dp)) {
|
||||
AgentsSlider(stringResource(R.string.team_fewest), now.min, cap) { v ->
|
||||
setTeam(actions, chat == null, AgentsSetting(v, maxOf(v, now.max)))
|
||||
}
|
||||
AgentsSlider(stringResource(R.string.team_most), now.max, cap) { v ->
|
||||
setTeam(actions, chat == null, AgentsSetting(minOf(now.min, v), v))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -560,11 +573,11 @@ private fun DeviceChoices(devices: List<LinkedDevice>, current: LinkedDevice?, o
|
||||
}
|
||||
|
||||
/**
|
||||
* One end of the team's size: its label and value on a row of their own, so the two sliders
|
||||
* line up whatever the words, and the slider under them.
|
||||
* One end of the Subagents setting: its label and value on a row of their own, so the two
|
||||
* sliders line up whatever the words, and the slider under them, from 1 to the instance's [cap].
|
||||
*/
|
||||
@Composable
|
||||
fun AgentsSlider(label: String, value: Int, onChange: (Int) -> Unit) {
|
||||
fun AgentsSlider(label: String, value: Int, cap: Int, onChange: (Int) -> Unit) {
|
||||
var shown by remember(value) { mutableStateOf(value.toFloat()) }
|
||||
Column(Modifier.padding(top = 8.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
@@ -574,9 +587,11 @@ fun AgentsSlider(label: String, value: Int, onChange: (Int) -> Unit) {
|
||||
Slider(
|
||||
value = shown,
|
||||
onValueChange = { shown = it },
|
||||
onValueChangeFinished = { onChange(Math.round(shown).coerceIn(1, AgentsSetting.CAP)) },
|
||||
valueRange = 1f..AgentsSetting.CAP.toFloat(),
|
||||
// Continuous: 31 tick marks would be noise, and the value is rounded anyway.
|
||||
onValueChangeFinished = { onChange(Math.round(shown).coerceIn(1, cap)) },
|
||||
valueRange = 1f..cap.toFloat(),
|
||||
// Up to the instance's cap: a tick per value for a few, continuous past that, where
|
||||
// tick marks would be noise (the value is rounded anyway).
|
||||
steps = if (cap <= 8) cap - 2 else 0,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user