fix(web): name only what a chat turn touched in the activity card (UF-050)

The card headline was a fixed "Worked across your memory, web & files".
It is now built from the turn: memory, web and file tools it called and
the memory steps the server reported, or a plain Working / Done.
This commit is contained in:
shumeiko.it
2026-10-27 12:54:45 +01:00
parent 711c37358a
commit 06d267dec8
4 changed files with 101 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import type { ReactNode } from 'react';
import type { ContentBlock, StepContentBlock } from '@/lib/types';
import type { ContentBlock, StepContentBlock, ToolUseContentBlock } from '@/lib/types';
import TextBlock from './TextBlock';
import ToolUseBlock from './ToolUseBlock';
import ModelSwitchBlock from './ModelSwitchBlock';
@@ -11,6 +11,7 @@ import { segmentText } from './capability-request-parser';
import type { RouteProposalConfirmResponse } from '@/lib/route-proposals';
import { ActivityStream, type ActivityStep } from '../../warm';
import { frameSourceLabel } from '@/lib/frame-source';
import { activitySummary } from './activity-summary';
interface BlockRendererProps {
blocks: ContentBlock[];
@@ -66,8 +67,14 @@ function trustedCapabilityProposals(blocks: ContentBlock[]): Map<string, Capabil
* F11: steps that are split by a non-step block (e.g. the auto-recall tool_use
* between the "Recalling…" and "Recalled N…" steps) must still yield exactly
* ONE card per turn — see the single-group anchoring in BlockRenderer below.
* The headline names only what the turn really touched (UF-050).
*/
function renderStepGroup(steps: StepContentBlock[], key: string, isStreaming: boolean): ReactNode {
function renderStepGroup(
steps: StepContentBlock[],
tools: ToolUseContentBlock[],
key: string,
isStreaming: boolean,
): ReactNode {
const anyRunning = steps.some(s => s.status === 'running');
const activitySteps: ActivityStep[] = steps.map(s => {
const sourceLabels = (s.provenance?.sources ?? [])
@@ -89,7 +96,7 @@ function renderStepGroup(steps: StepContentBlock[], key: string, isStreaming: bo
return (
<ActivityStream
key={key}
summary={anyRunning ? 'Working across your memory, web & files' : 'Worked across your memory, web & files'}
summary={activitySummary(steps, tools, anyRunning)}
steps={activitySteps}
defaultOpen={isStreaming || anyRunning}
className="my-1.5"
@@ -107,12 +114,13 @@ const BlockRenderer = ({
// blocks (tool rows, artifacts, text, model_switch, error) keep their order,
// so a tool_use between two steps no longer splits the run into two cards.
const allSteps = blocks.filter((b): b is StepContentBlock => b.type === 'step');
const allTools = blocks.filter((b): b is ToolUseContentBlock => b.type === 'tool_use');
const firstStepIdx = blocks.findIndex(b => b.type === 'step');
const capabilityProposals = trustedCapabilityProposals(blocks);
blocks.forEach((block, i) => {
if (block.type === 'step') {
if (i === firstStepIdx) out.push(renderStepGroup(allSteps, 'activity', !!isStreaming));
if (i === firstStepIdx) out.push(renderStepGroup(allSteps, allTools, 'activity', !!isStreaming));
return;
}
const key = getBlockKey(block, i);

View File

@@ -0,0 +1,56 @@
import type { StepContentBlock, ToolUseContentBlock } from '@/lib/types';
type Area = 'memory' | 'web' | 'files';
const AREA_LABEL: Record<Area, string> = {
memory: 'your memory',
web: 'the web',
files: 'files',
};
const MEMORY_TOOLS = new Set(['auto_recall', 'search_memory', 'save_memory', 'recall_memory', 'memory']);
const WEB_TOOLS = new Set(['web_search', 'web_fetch', 'brave_search', 'tavily_search', 'perplexity_search', 'research']);
const FILE_TOOLS = new Set([
'read_file', 'write_file', 'edit_file', 'multi_edit', 'get_file', 'get_file_metadata', 'list_files',
'list_workspace_files', 'search_files', 'download_file', 'upload_file', 'read_other_workspace_file',
'list_folder', 'create_folder', 'generate_docx', 'generate_pdf', 'generate_pptx', 'generate_xlsx',
]);
// Server steps that report memory work: "Recalling relevant memories...",
// "Recalled 2 relevant memories.", "Auto-saved 3 memories…", "Session summary saved to memory".
const MEMORY_STEP = /\b(recall\w*|saved)\b.*\bmemor(y|ies)\b/i;
function toolArea(name: string): Area | null {
if (MEMORY_TOOLS.has(name)) return 'memory';
if (WEB_TOOLS.has(name) || name.startsWith('browser_')) return 'web';
if (FILE_TOOLS.has(name)) return 'files';
return null;
}
function joinAreas(labels: string[]): string {
if (labels.length <= 1) return labels.join('');
return `${labels.slice(0, -1).join(', ')} & ${labels[labels.length - 1]}`;
}
/**
* The Activity card's headline, built from what the turn actually touched:
* the memory, web and file tools it called and the memory steps the server
* reported. A turn that touched none of them gets a plain "Working" / "Done".
*/
export function activitySummary(
steps: StepContentBlock[],
tools: ToolUseContentBlock[],
running: boolean,
): string {
const areas = new Set<Area>();
for (const step of steps) {
if (step.provenance || MEMORY_STEP.test(step.description)) areas.add('memory');
}
for (const tool of tools) {
const area = toolArea(tool.name);
if (area) areas.add(area);
}
const ordered = (['memory', 'web', 'files'] as const).filter((a) => areas.has(a));
if (ordered.length === 0) return running ? 'Working' : 'Done';
return `${running ? 'Working' : 'Worked'} across ${joinAreas(ordered.map((a) => AREA_LABEL[a]))}`;
}