fix(chat): make context meter strictly backend-reported
Remove misleading local/cumulative token fallback in ContextDetailSheet and hide 0% badge when context used is unknown.
This commit is contained in:
1 parent
107701077d
commit
6fe62f9646
5 files changed
+23
-13
No files matched your search
@@ -51,12 +51,12 @@ fun ContextDetailSheet(
|
|||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
) {
|
) {
|
||||||
val full = fullTokens ?: 0L
|
val full = fullTokens ?: 0L
|
||||||
val used = usedTokens ?: breakdown.inputTokens
|
val fraction = if (full > 0L && usedTokens != null) min(1f, usedTokens.toFloat() / full.toFloat()) else 0f
|
||||||
val fraction = if (full > 0L) min(1f, used.toFloat() / full.toFloat()) else 0f
|
|
||||||
val pct = (fraction * 100).toInt()
|
val pct = (fraction * 100).toInt()
|
||||||
val statusColors = LocalHermesStatusColors.current
|
val statusColors = LocalHermesStatusColors.current
|
||||||
val barColor =
|
val barColor =
|
||||||
when {
|
when {
|
||||||
|
usedTokens == null -> MaterialTheme.colorScheme.primary
|
||||||
pct >= 90 -> statusColors.error
|
pct >= 90 -> statusColors.error
|
||||||
pct >= 70 -> statusColors.warning
|
pct >= 70 -> statusColors.warning
|
||||||
else -> MaterialTheme.colorScheme.primary
|
else -> MaterialTheme.colorScheme.primary
|
||||||
@@ -83,7 +83,7 @@ fun ContextDetailSheet(
|
|||||||
verticalAlignment = Alignment.Bottom,
|
verticalAlignment = Alignment.Bottom,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = formatTokens(used),
|
text = if (usedTokens != null) formatTokens(usedTokens) else "—",
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = barColor,
|
color = barColor,
|
||||||
@@ -115,7 +115,12 @@ fun ContextDetailSheet(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = "$pct% of context window used",
|
text =
|
||||||
|
if (usedTokens != null) {
|
||||||
|
"$pct% of context window used"
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.context_window_usage_unavailable)
|
||||||
|
},
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ fun ContextUsageChip(
|
|||||||
val full = fullTokens
|
val full = fullTokens
|
||||||
if (full == null || full <= 0L) return
|
if (full == null || full <= 0L) return
|
||||||
|
|
||||||
val used = usedTokens ?: 0L
|
val fraction = if (usedTokens != null) min(1f, usedTokens.toFloat() / full.toFloat()) else 0f
|
||||||
val fraction = min(1f, used.toFloat() / full.toFloat())
|
|
||||||
val pct = (fraction * 100).toInt()
|
val pct = (fraction * 100).toInt()
|
||||||
val statusColors = LocalHermesStatusColors.current
|
val statusColors = LocalHermesStatusColors.current
|
||||||
val barColor =
|
val barColor =
|
||||||
when {
|
when {
|
||||||
|
usedTokens == null -> MaterialTheme.colorScheme.primary
|
||||||
pct >= 90 -> statusColors.error
|
pct >= 90 -> statusColors.error
|
||||||
pct >= 70 -> statusColors.warning
|
pct >= 70 -> statusColors.warning
|
||||||
else -> MaterialTheme.colorScheme.primary
|
else -> MaterialTheme.colorScheme.primary
|
||||||
@@ -90,7 +90,7 @@ fun ContextUsageChip(
|
|||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
if (usedTokens != null) {
|
if (usedTokens != null) {
|
||||||
"${formatTokens(used)} / ${formatTokens(full)} context"
|
"${formatTokens(usedTokens)} / ${formatTokens(full)} context"
|
||||||
} else {
|
} else {
|
||||||
"— / ${formatTokens(full)} context"
|
"— / ${formatTokens(full)} context"
|
||||||
},
|
},
|
||||||
@@ -111,12 +111,14 @@ fun ContextUsageChip(
|
|||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text(
|
if (usedTokens != null) {
|
||||||
text = "$pct%",
|
Text(
|
||||||
style = MaterialTheme.typography.labelSmall,
|
text = "$pct%",
|
||||||
color = barColor,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
maxLines = 1,
|
color = barColor,
|
||||||
)
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Box(
|
Box(
|
||||||
|
|||||||
@@ -1310,6 +1310,7 @@
|
|||||||
<string name="context_prompt_input">المطالبة (المدخلات)</string>
|
<string name="context_prompt_input">المطالبة (المدخلات)</string>
|
||||||
<string name="context_tokens_note">تعكس رموز المطالبة إجمالي السياق المستخدم في هذه الجلسة حتى الآن.</string>
|
<string name="context_tokens_note">تعكس رموز المطالبة إجمالي السياق المستخدم في هذه الجلسة حتى الآن.</string>
|
||||||
<string name="context_window">نافذة السياق</string>
|
<string name="context_window">نافذة السياق</string>
|
||||||
|
<string name="context_window_usage_unavailable">استخدام نافذة السياق غير متوفر</string>
|
||||||
<string name="gif_play">تشغيل GIF</string>
|
<string name="gif_play">تشغيل GIF</string>
|
||||||
<string name="kanban_filter_placeholder">تصفية المهام حسب العنوان أو الحالة أو المسؤول...</string>
|
<string name="kanban_filter_placeholder">تصفية المهام حسب العنوان أو الحالة أو المسؤول...</string>
|
||||||
<string name="logs_clipboard_label">سجلات Hermes</string>
|
<string name="logs_clipboard_label">سجلات Hermes</string>
|
||||||
|
|||||||
@@ -1277,6 +1277,7 @@
|
|||||||
<string name="context_prompt_input">提示词(输入)</string>
|
<string name="context_prompt_input">提示词(输入)</string>
|
||||||
<string name="context_tokens_note">提示词 token 反映此会话迄今使用的总上下文。</string>
|
<string name="context_tokens_note">提示词 token 反映此会话迄今使用的总上下文。</string>
|
||||||
<string name="context_window">上下文窗口</string>
|
<string name="context_window">上下文窗口</string>
|
||||||
|
<string name="context_window_usage_unavailable">上下文窗口使用量不可用</string>
|
||||||
<string name="gif_play">播放 GIF</string>
|
<string name="gif_play">播放 GIF</string>
|
||||||
<string name="kanban_filter_placeholder">按标题、状态或负责人筛选任务…</string>
|
<string name="kanban_filter_placeholder">按标题、状态或负责人筛选任务…</string>
|
||||||
<string name="logs_clipboard_label">Hermes 日志</string>
|
<string name="logs_clipboard_label">Hermes 日志</string>
|
||||||
|
|||||||
@@ -1437,6 +1437,7 @@
|
|||||||
<string name="context_prompt_input">Prompt (input)</string>
|
<string name="context_prompt_input">Prompt (input)</string>
|
||||||
<string name="context_tokens_note">Prompt tokens reflect total context used by this session so far.</string>
|
<string name="context_tokens_note">Prompt tokens reflect total context used by this session so far.</string>
|
||||||
<string name="context_window">Context window</string>
|
<string name="context_window">Context window</string>
|
||||||
|
<string name="context_window_usage_unavailable">Context window usage unavailable</string>
|
||||||
<string name="gif_play">Play GIF</string>
|
<string name="gif_play">Play GIF</string>
|
||||||
<string name="kanban_filter_placeholder">Filter tasks by title, status, or assignee...</string>
|
<string name="kanban_filter_placeholder">Filter tasks by title, status, or assignee...</string>
|
||||||
<string name="logs_clipboard_label">Hermes Logs</string>
|
<string name="logs_clipboard_label">Hermes Logs</string>
|
||||||
|
|||||||
Reference in new issue
Block a user