@steerable/agent-shell-web 0.14.2 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,12 @@ import { t } from '@/i18n';
17
17
  import { Markdown } from './Markdown';
18
18
  import { ExecutedActionsCard, type ExecutedAction } from './ExecutedActionsCard';
19
19
  import type { ChildInfo } from './OrchestrationChildrenCard';
20
- import { collectTurnParticipants, extractMentionedAgentIds } from './executed-actions-model';
20
+ import {
21
+ collectTurnParticipants,
22
+ extractMentionedAgentIds,
23
+ filterRedundantPresentFiles,
24
+ shouldShowTurnAgentBadges,
25
+ } from './executed-actions-model';
21
26
  import type { InspectTaskInput } from './executed-actions-model';
22
27
  import { StreamingStatus } from './StreamingStatus';
23
28
  import { classifyErrorMessage } from '@steerable/agent-protocol';
@@ -514,12 +519,26 @@ export function AssistantMessage({
514
519
  ...(executedActions ?? []),
515
520
  ...blocks.flatMap((block) => (block.type === 'tools' ? block.actions : [])),
516
521
  ];
522
+ const mentionedAgentIds = extractMentionedAgentIds(previousUser, agents);
517
523
  const participants = collectTurnParticipants(displayAgent, {
518
524
  agents,
519
525
  children: orchestrationChildren,
520
526
  actions: toolActions,
521
- mentionedAgentIds: extractMentionedAgentIds(previousUser, agents),
527
+ mentionedAgentIds,
528
+ });
529
+ const showTurnAgentBadges = shouldShowTurnAgentBadges({
530
+ participants,
531
+ currentAgent,
532
+ mentionedAgentIds,
522
533
  });
534
+ const deliveredFilePaths =
535
+ !isStreaming && turnFiles && turnFiles.length > 0
536
+ ? new Set(turnFiles.map((file) => file.path))
537
+ : null;
538
+ const legacyVisibleActions =
539
+ executedActions && executedActions.length > 0
540
+ ? filterRedundantPresentFiles(executedActions, deliveredFilePaths)
541
+ : [];
523
542
  const now = useLiveNow(Boolean(isStreaming && llmSpeed?.live));
524
543
  const tokenSpeed = formatTokenSpeed(
525
544
  llmSpeed?.tokens ?? 0,
@@ -540,9 +559,9 @@ export function AssistantMessage({
540
559
  transition={{ duration: 0.25 }}
541
560
  >
542
561
  <div className="mx-auto w-full max-w-[var(--chat-input-box-width)] px-1">
543
- {(participants.length > 0 || isPlanMode) && (
562
+ {(showTurnAgentBadges || isPlanMode) && (
544
563
  <div className="mb-1 flex min-h-4 items-center justify-between gap-2">
545
- {participants.length > 0 ? (
564
+ {showTurnAgentBadges ? (
546
565
  <div
547
566
  data-testid="turn-agent-badges"
548
567
  className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1"
@@ -572,6 +591,7 @@ export function AssistantMessage({
572
591
  <TurnProcessGroup
573
592
  blocks={blocks}
574
593
  isStreaming={isStreaming}
594
+ turnFailed={Boolean(failure)}
575
595
  startedAtMs={startedAtMs}
576
596
  durationMs={durationMs}
577
597
  agents={agents}
@@ -582,6 +602,7 @@ export function AssistantMessage({
582
602
  turnUsage={turnUsage}
583
603
  onContinueChild={onContinueChild}
584
604
  onStopChild={onStopChild}
605
+ deliveredFilePaths={deliveredFilePaths}
585
606
  emptyFallback={
586
607
  failure ? (
587
608
  wrapContinued(
@@ -648,9 +669,9 @@ export function AssistantMessage({
648
669
  </>
649
670
  ) : (
650
671
  <>
651
- {executedActions && executedActions.length > 0 && (
672
+ {legacyVisibleActions.length > 0 && (
652
673
  <ExecutedActionsCard
653
- actions={executedActions}
674
+ actions={legacyVisibleActions}
654
675
  agents={agents}
655
676
  chatId={chatId}
656
677
  onInspectTask={onInspectTask}
@@ -2366,59 +2366,41 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
2366
2366
  {/* shrink-0:发送键是固定尺寸圆钮,窄容器下不允许被压扁;
2367
2367
  收缩量由左侧可截断的选择器吸收。 */}
2368
2368
  <div className="flex shrink-0 items-center gap-2">
2369
- {/* 快捷键提示:空间不足时优先隐藏(测量逻辑见上方 effect) */}
2370
- <div
2371
- ref={hintRef}
2372
- className={`${hintsSuppressed ? 'hidden' : 'block'} text-[11px] text-agent-muted-foreground/80`}
2373
- >
2374
- {isStreaming ? (
2375
- <>
2376
- {onFollowUp && (
2377
- <span className="ml-2">
2378
- <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2379
- Enter
2380
- </kbd>
2381
- <span className="ml-1">{t('Queue')}</span>
2382
- </span>
2383
- )}
2384
- {onSteer && (
2385
- <span className="ml-2">
2386
- <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2387
- {MOD_KEY_LABEL}
2388
- </kbd>
2389
- <span className="mx-0.5">+</span>
2390
- <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2391
- Enter
2392
- </kbd>
2393
- <span className="ml-1">{t('Interject')}</span>
2394
- </span>
2395
- )}
2369
+ {/* 快捷键提示:空闲态隐藏常规 Enter/Shift+Enter 教程以降噪;
2370
+ 仅在流式期间提示低频高价值的排队/插队/停止,空间不足时优先收起 */}
2371
+ {isStreaming && (
2372
+ <div
2373
+ ref={hintRef}
2374
+ className={`${hintsSuppressed ? 'hidden' : 'block'} text-[11px] text-agent-muted-foreground/80`}
2375
+ >
2376
+ {onFollowUp && (
2396
2377
  <span className="ml-2">
2397
2378
  <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2398
- Esc
2379
+ Enter
2399
2380
  </kbd>
2400
- <span className="ml-1">{t('Stop')}</span>
2381
+ <span className="ml-1">{t('Queue')}</span>
2401
2382
  </span>
2402
- </>
2403
- ) : (
2404
- <>
2405
- <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2406
- Enter
2407
- </kbd>
2408
- <span className="ml-1">{t('Send')}</span>
2383
+ )}
2384
+ {onSteer && (
2409
2385
  <span className="ml-2">
2410
2386
  <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2411
- Shift
2387
+ {MOD_KEY_LABEL}
2412
2388
  </kbd>
2413
2389
  <span className="mx-0.5">+</span>
2414
2390
  <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2415
2391
  Enter
2416
2392
  </kbd>
2417
- <span className="ml-1">{t('New line')}</span>
2393
+ <span className="ml-1">{t('Interject')}</span>
2418
2394
  </span>
2419
- </>
2420
- )}
2421
- </div>
2395
+ )}
2396
+ <span className="ml-2">
2397
+ <kbd className="rounded border border-agent-border bg-agent-muted px-1 font-sans text-[10px]">
2398
+ Esc
2399
+ </kbd>
2400
+ <span className="ml-1">{t('Stop')}</span>
2401
+ </span>
2402
+ </div>
2403
+ )}
2422
2404
  <button
2423
2405
  ref={sendButtonRef}
2424
2406
  type="button"
@@ -43,7 +43,7 @@ function BadgeButton({
43
43
  title,
44
44
  }: {
45
45
  label: string;
46
- /** true = 已关联/已选中项目(实心图标);false = 未选择(虚线感 + Plus 图标)。 */
46
+ /** true = 已关联/已选中项目(实心图标);false = 未选择(轻态无边框 + Plus 图标)。 */
47
47
  active: boolean;
48
48
  open: boolean;
49
49
  busy: boolean;
@@ -56,10 +56,10 @@ function BadgeButton({
56
56
  onClick={onClick}
57
57
  disabled={busy}
58
58
  title={title}
59
- className={`flex max-w-full items-center gap-1.5 rounded-full px-2 py-0.5 text-[11px] transition-colors disabled:opacity-60 ${
59
+ className={`inline-flex max-w-full items-center gap-1.5 rounded-full px-2 py-0.5 text-[11px] transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:opacity-60 ${
60
60
  active
61
- ? 'text-agent-muted-foreground/80 hover:bg-agent-foreground/5 hover:text-agent-foreground'
62
- : 'border border-dashed border-agent-border text-agent-muted-foreground/70 hover:border-agent-muted-foreground/50 hover:text-agent-foreground'
61
+ ? 'text-agent-muted-foreground/85'
62
+ : 'text-agent-muted-foreground/65'
63
63
  }`}
64
64
  >
65
65
  {busy ? (
@@ -1,5 +1,4 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { LuMinimize2 } from 'react-icons/lu';
3
2
  import { t } from '@/i18n';
4
3
  import { hasHostBridge } from '@/lib/host-bridge';
5
4
  import {
@@ -14,7 +13,7 @@ export interface ContextUsagePillProps {
14
13
  chatId: string;
15
14
  messageCount: number;
16
15
  isStreaming: boolean;
17
- /** Optional latest in-memory turn usage when streaming just finished. */
16
+ /** Optional latest in-memory turn usage (note: `promptTokens` is cumulative across rounds). */
18
17
  livePromptTokens?: number;
19
18
  liveCachedPromptTokens?: number;
20
19
  onCompacted?: (result: CompactChatResult) => void;
@@ -30,6 +29,41 @@ function formatMegabytes(bytes: number): string {
30
29
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
31
30
  }
32
31
 
32
+ function ContextRing({ ratio }: { ratio: number }) {
33
+ const clamped = Math.max(0, Math.min(1, ratio));
34
+ const radius = 4.5;
35
+ const circumference = 2 * Math.PI * radius;
36
+ const dashOffset = circumference * (1 - clamped);
37
+ return (
38
+ <svg
39
+ viewBox="0 0 12 12"
40
+ aria-hidden="true"
41
+ className="h-3 w-3 shrink-0 -rotate-90"
42
+ >
43
+ <circle
44
+ cx="6"
45
+ cy="6"
46
+ r={radius}
47
+ fill="none"
48
+ stroke="currentColor"
49
+ strokeWidth="1.5"
50
+ className="opacity-25"
51
+ />
52
+ <circle
53
+ cx="6"
54
+ cy="6"
55
+ r={radius}
56
+ fill="none"
57
+ stroke="currentColor"
58
+ strokeWidth="1.5"
59
+ strokeLinecap="round"
60
+ strokeDasharray={circumference}
61
+ strokeDashoffset={dashOffset}
62
+ />
63
+ </svg>
64
+ );
65
+ }
66
+
33
67
  export function ContextUsagePill({
34
68
  chatId,
35
69
  messageCount,
@@ -81,35 +115,53 @@ export function ContextUsagePill({
81
115
  return () => window.removeEventListener('pointerdown', handlePointerDown);
82
116
  }, [open, refreshStatus]);
83
117
 
84
- if (!hasHostBridge() || messageCount === 0) {
118
+ if (!hasHostBridge() || messageCount === 0 || !status) {
85
119
  return null;
86
120
  }
87
121
 
88
- const maxTokens = status?.maxContextTokens ?? 131_072;
89
- const estTokens = Math.max(status?.estimatedTokens ?? 0, livePromptTokens ?? 0);
90
- const maxBytes = status?.maxRequestBytes ?? 4_194_304;
91
- const estBytes = status?.estimatedBytes ?? 0;
92
- const promptTokens = livePromptTokens ?? status?.promptTokens ?? 0;
93
- const cachedTokens = liveCachedPromptTokens ?? status?.cachedPromptTokens ?? 0;
122
+ const maxTokens = status.maxContextTokens || 131_072;
123
+ // Always use single-window `estimatedTokens` from `context-status`.
124
+ // `livePromptTokens` / `status.promptTokens` come from `TurnUsage.promptTokens`,
125
+ // which sums prompt tokens across every tool-loop round in the turn (e.g. 4.6M).
126
+ const estTokens = Math.max(0, status.estimatedTokens ?? 0);
127
+ const maxBytes = status.maxRequestBytes || 4_194_304;
128
+ const estBytes = Math.max(0, status.estimatedBytes ?? 0);
129
+ const rawPromptTokens = livePromptTokens ?? status.promptTokens ?? 0;
130
+ const cachedTokens = liveCachedPromptTokens ?? status.cachedPromptTokens ?? 0;
131
+ const singleStepPromptTokens =
132
+ rawPromptTokens > maxTokens
133
+ ? Math.max(estTokens, cachedTokens)
134
+ : rawPromptTokens;
94
135
  const cacheHitPct =
95
- promptTokens > 0 ? Math.min(100, Math.round((cachedTokens / promptTokens) * 100)) : null;
136
+ singleStepPromptTokens > 0 && cachedTokens <= singleStepPromptTokens
137
+ ? Math.min(100, Math.round((cachedTokens / singleStepPromptTokens) * 100))
138
+ : null;
96
139
 
97
140
  const tokenRatio = maxTokens > 0 ? Math.min(1, estTokens / maxTokens) : 0;
98
141
  const byteRatio = maxBytes > 0 ? Math.min(1, estBytes / maxBytes) : 0;
99
- const dominantRatio = Math.max(tokenRatio, byteRatio);
100
- const dominantPct = Math.round(dominantRatio * 100);
142
+ const isByteDominant = byteRatio > tokenRatio;
143
+ const dominantRatio = isByteDominant ? byteRatio : tokenRatio;
144
+ const rawPct = Math.round(dominantRatio * 100);
145
+ const dominantPct = estTokens > 0 || estBytes > 0 ? Math.max(1, rawPct) : 0;
146
+ const isElevated = dominantRatio >= 0.7;
147
+ const dominantSummary = isByteDominant
148
+ ? formatMegabytes(estBytes)
149
+ : formatCompactCount(estTokens);
150
+ const tooltipDetail = isByteDominant
151
+ ? `${formatCompactCount(estTokens)} / ${formatCompactCount(maxTokens)} · ${formatMegabytes(estBytes)} / ${formatMegabytes(maxBytes)}`
152
+ : `${formatCompactCount(estTokens)} / ${formatCompactCount(maxTokens)}`;
101
153
 
102
154
  const toneClass =
103
155
  dominantRatio >= 0.85
104
- ? 'border-red-500/40 bg-red-500/10 text-red-600 dark:text-red-400'
105
- : dominantRatio >= 0.7
106
- ? 'border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-400'
107
- : 'border-agent-border/60 bg-agent-muted/40 text-agent-muted-foreground hover:text-agent-foreground';
156
+ ? 'border-red-500/40 bg-red-500/10 px-2 text-red-600 dark:text-red-400'
157
+ : isElevated
158
+ ? 'border-amber-500/40 bg-amber-500/10 px-2 text-amber-600 dark:text-amber-400'
159
+ : 'border-transparent bg-transparent px-1.5 text-agent-muted-foreground/80 hover:bg-agent-foreground/5 hover:text-agent-foreground';
108
160
 
109
161
  const barColor =
110
162
  dominantRatio >= 0.85
111
163
  ? 'bg-red-500'
112
- : dominantRatio >= 0.7
164
+ : isElevated
113
165
  ? 'bg-amber-500'
114
166
  : 'bg-agent-primary';
115
167
 
@@ -144,12 +196,12 @@ export function ContextUsagePill({
144
196
  type="button"
145
197
  data-testid="context-usage-pill"
146
198
  onClick={() => setOpen((prev) => !prev)}
147
- title={t('Context window and payload usage')}
148
- className={`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] leading-tight transition-colors ${toneClass}`}
199
+ title={`${t('Context window and payload usage')} (${tooltipDetail})`}
200
+ className={`inline-flex h-6 items-center gap-1 rounded-full border text-[11px] leading-tight tabular-nums transition-colors ${toneClass}`}
149
201
  >
150
- <LuMinimize2 className="h-3 w-3 shrink-0 opacity-80" />
202
+ <ContextRing ratio={dominantRatio} />
151
203
  <span>
152
- {formatCompactCount(estTokens)} · {dominantPct}%
204
+ {isElevated ? `${dominantSummary} · ${dominantPct}%` : `${dominantPct}%`}
153
205
  </span>
154
206
  </button>
155
207
 
@@ -67,10 +67,10 @@ export function ExecPolicyPicker({
67
67
  title={t(current.description)}
68
68
  onClick={() => setOpen((next) => !next)}
69
69
  className={[
70
- 'inline-flex h-6 max-w-[140px] items-center gap-1 rounded-full border px-1.5 text-[12px] leading-[1.45] transition-colors disabled:cursor-not-allowed disabled:opacity-70',
70
+ 'inline-flex h-6 max-w-[140px] items-center gap-1 rounded-full border px-2 text-[12px] leading-[1.45] transition-colors disabled:cursor-not-allowed disabled:opacity-70',
71
71
  isFull
72
72
  ? 'border-amber-400/50 bg-amber-400/10 text-amber-700 dark:text-amber-400'
73
- : 'border-agent-border bg-agent-canvas text-agent-foreground hover:bg-agent-foreground/5',
73
+ : 'border-transparent bg-transparent text-agent-muted-foreground hover:bg-agent-foreground/5 hover:text-agent-foreground',
74
74
  ].join(' ')}
75
75
  >
76
76
  {isFull ? (