Show an animated assistant bubble before response tokens

This commit is contained in:
2026-10-25 17:38:56 +00:00
parent a58d820d43
commit 18d43cadc3
12 changed files with 676 additions and 3 deletions
+109
View File
@@ -0,0 +1,109 @@
// Device-only fixture: exercises the real thread without a server or real chat.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
void main() => runApp(const _FixtureApp());
class _FixtureGateway implements ApiGateway {
final events = StreamController<JsonMap>.broadcast();
@override
Stream<JsonMap> get frames => events.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
if (type == 'chat_messages') {
return {
'chat_history': {'messages': [], 'next_cursor': '', 'has_more': false},
};
}
if (type == 'chat_prompt') return {'chat_queued': false};
return {};
}
void emit(JsonMap body) => events.add({
'type': 'chat_event',
'chat_event': {'session_id': 'fixture', ...body},
});
}
class _FixtureApp extends StatefulWidget {
const _FixtureApp();
@override
State<_FixtureApp> createState() => _FixtureAppState();
}
class _FixtureAppState extends State<_FixtureApp> {
final gateway = _FixtureGateway();
final drafts = MemoryChatDraftStore();
@override
void dispose() {
unawaited(gateway.events.close());
super.dispose();
}
@override
Widget build(BuildContext context) => MaterialApp(
theme: appLightTheme(),
darkTheme: appDarkTheme(),
home: Scaffold(
appBar: AppBar(
title: const Text('Response fixture — no server'),
actions: [
IconButton(
tooltip: 'Fixture tool only',
icon: const Icon(Icons.build),
onPressed: () {
gateway.emit({
'kind': 'step',
'step': {'status': 'running', 'turn_id': 'fixture-turn'},
});
gateway.emit({
'kind': 'tool',
'message_id': 'fixture-answer',
'part': {
'type': 'tool',
'id': 'tool',
'name': 'read',
'state': {'status': 'completed'},
},
});
},
),
IconButton(
tooltip: 'Fixture answer text',
icon: const Icon(Icons.text_fields),
onPressed: () => gateway.emit({
'kind': 'text',
'message_id': 'fixture-answer',
'part': {'type': 'text', 'id': 'text'},
'delta': 'The answer replaces the animated dots.',
}),
),
IconButton(
tooltip: 'Fixture finish',
icon: const Icon(Icons.done),
onPressed: () => gateway.emit({
'kind': 'step',
'step': {'status': 'ended', 'turn_id': 'fixture-turn'},
}),
),
],
),
body: ChatThreadView(
gateway: gateway,
sessionId: 'fixture',
title: 'Fixture chat',
drafts: drafts,
onBack: () {},
),
),
);
}
+86
View File
@@ -0,0 +1,86 @@
// Real-browser Send -> pending bubble -> tools -> answer, against loopback data.
import assert from 'node:assert/strict';
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
import { once } from 'node:events';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { startFixture } from './runs_probe_server.mjs';
import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
import { axNodes, enableSemantics, waitFor, capture, click, clickAt } from './pipelines_probe_cdp_input.mjs';
const platform = process.env.PROBE_PLATFORM ?? 'material';
const output = resolve(process.argv[3] ?? `build/chat-response-pending-${platform}`);
await mkdir(output, { recursive: true });
const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: [] });
const profile = await mkdtemp(join(tmpdir(), 'chat-response-pending-'));
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
const log = { platform, checks: [], captures: [] };
let c;
const names = async () => (await axNodes(c)).map(n => n.name?.value ?? '');
const pending = async () => (await axNodes(c)).find(n => n.name?.value === 'Assistant is responding' && n.backendDOMNodeId);
const emit = async body => {
const response = await fetch(fixture.url + '/fixture/chat-event', { method: 'POST', body: JSON.stringify(body) });
assert.ok(response.ok);
};
try {
c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl);
await c.send('Page.enable');
if (platform === 'material') await c.send('Emulation.setUserAgentOverride', {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36', platform: 'Win32',
});
await c.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false });
await c.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-reduced-motion', value: 'no-preference' }] });
await c.send('Page.navigate', { url: fixture.url + '/chat/ses_probechat' });
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
await enableSemantics(c);
const field = await waitFor(async () => (await axNodes(c)).find(n => n.role?.value === 'textbox' && n.backendDOMNodeId), 30000);
assert.ok(field, 'composer field');
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: field.backendDOMNodeId });
const [x1, y1, , , x3, y3] = model.content;
await clickAt(c, (x1 + x3) / 2, (y1 + y3) / 2);
await c.send('Input.insertText', { text: 'Fixture prompt before any response tokens.' });
await sleep(150);
await click(c, 'Send');
assert.ok(await waitFor(pending, 10000), 'assistant bubble before a server response frame');
await sleep(500); // The accepted prompt still has no assistant frames.
await capture(c, output, log, '01-before-first-frame');
log.checks.push('normal assistant response bubble before any frames or tokens');
const node = await pending();
const { model: dots } = await c.send('DOM.getBoxModel', { backendNodeId: node.backendDOMNodeId });
const [dx1, dy1, , , dx3, dy3] = dots.content;
const clip = { x: dx1, y: dy1, width: dx3 - dx1, height: dy3 - dy1, scale: 1 };
const first = await c.send('Page.captureScreenshot', { format: 'png', clip });
await sleep(250);
const second = await c.send('Page.captureScreenshot', { format: 'png', clip });
assert.notEqual(first.data, second.data, 'ellipsis pixels animate without response events');
log.checks.push('ellipsis visibly animates independently of the transcript');
await emit({ kind: 'step', step: { status: 'running', turn_id: 'fixture-turn' } });
await emit({ kind: 'tool', message_id: 'answer', part: {
type: 'tool', id: 'tool', name: 'read', state: { status: 'completed' },
} });
assert.ok(await waitFor(async () => (await names()).some(name => name.startsWith('1 tool call')), 10000));
assert.ok(await pending(), 'response bubble remains above tool-only activity');
await capture(c, output, log, '02-tool-only-response');
log.checks.push('tool-only response retains its pending answer bubble');
await emit({ kind: 'text', message_id: 'answer', part: { type: 'text', id: 'text' }, delta: 'The first answer tokens replace the dots.' });
await emit({ kind: 'step', step: { status: 'ended', turn_id: 'fixture-turn' } });
assert.ok(await waitFor(async () => (await names()).includes('The first answer tokens replace the dots.'), 10000));
assert.equal(await pending(), undefined);
await capture(c, output, log, '03-answer-text');
log.checks.push('answer text replaces the dots; finished turn has no pending animation');
console.log(JSON.stringify(log, null, 2));
} catch (error) {
if (c) {
await capture(c, output, log, 'failure');
await writeFile(join(output, 'failure-ax.json'), JSON.stringify(await axNodes(c), null, 2));
}
throw error;
} finally {
await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2));
c?.close();
const exited = once(chrome, 'exit'); chrome.kill(); await exited;
await fixture.close();
}