feat(app): create, rename, star, close and hide chat sessions
This commit is contained in:
@@ -7,6 +7,17 @@ import { join, extname, resolve, sep } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
|
||||
|
||||
// Real-browser acceptance for the chat session list's shared actions.
|
||||
//
|
||||
// Usage (from app/):
|
||||
// flutter build web -t tool/chat_sessions_probe_entry.dart \
|
||||
// --dart-define=CHAT_PROBE_STYLE=material -o build/chat-list-material
|
||||
// PROBE_WEB_ROOT=$PWD/build/chat-list-material PROBE_VARIANT=material \
|
||||
// OPENCODE_ARTIFACT_DIR=<dir> node tool/chat_sessions_probe.mjs
|
||||
//
|
||||
// The fixture answers the app's real protocol in-process: accepted create,
|
||||
// rename, star and close calls change the list the next chat_sessions read
|
||||
// returns, and the title `Refused title` is refused with the server's words.
|
||||
const root = resolve(process.env.PROBE_WEB_ROOT ?? join(process.cwd(), 'build/web'));
|
||||
const variant = process.env.PROBE_VARIANT ?? 'material';
|
||||
const artifactDir = process.env.OPENCODE_ARTIFACT_DIR ?? join(tmpdir(), 'chat-sessions-capture');
|
||||
@@ -24,20 +35,20 @@ const server = createServer(async (req, res) => {
|
||||
server.listen(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const port = server.address().port;
|
||||
const profile = await mkdtemp(join(tmpdir(), 'chat-sessions-chrome-'));
|
||||
const profile = await mkdtemp(join(tmpdir(), 'chat-sessions-chrome-'));
|
||||
const chrome = spawn('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', [
|
||||
'--headless=new', '--no-first-run', '--no-default-browser-check', '--disable-gpu',
|
||||
'--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank',
|
||||
], { stdio: ['ignore', 'ignore', 'pipe'] });
|
||||
let stderr = '';
|
||||
chrome.stderr.on('data', data => { stderr += data; });
|
||||
const waitFor = async fn => {
|
||||
const waitFor = async (fn, label = 'condition') => {
|
||||
for (let i = 0; i < 100; i++) { const value = await fn(); if (value) return value; await delay(100); }
|
||||
throw new Error('Timed out waiting for Chrome DevTools');
|
||||
throw new Error(`Timed out waiting for ${label}`);
|
||||
};
|
||||
let ws;
|
||||
try {
|
||||
const endpoint = await waitFor(() => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1]);
|
||||
const endpoint = await waitFor(() => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1], 'Chrome DevTools');
|
||||
ws = new WebSocket(endpoint);
|
||||
await once(ws, 'open');
|
||||
let id = 0;
|
||||
@@ -57,52 +68,230 @@ try {
|
||||
const session = (await send('Target.attachToTarget', { targetId: target, flatten: true })).result.sessionId;
|
||||
await send('Page.enable', {}, session);
|
||||
await send('Runtime.enable', {}, session);
|
||||
const navigation = await send('Page.navigate', { url: `http://127.0.0.1:${port}/` }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
const evaluate = async expression => {
|
||||
const response = await send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true }, session);
|
||||
if (response.error) throw new Error(`Runtime.evaluate failed: ${JSON.stringify(response)}`);
|
||||
return response.result?.result?.value;
|
||||
};
|
||||
await delay(3500);
|
||||
const loaded = await evaluate("({url:location.href, ready:document.readyState, body:document.body.innerText, html:document.body.innerHTML.slice(0,500)})");
|
||||
if (!loaded?.url.includes(`127.0.0.1:${port}`)) throw new Error(`Fixture did not load: ${JSON.stringify(loaded)}`);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(2500);
|
||||
const load = async (suffix = '') => {
|
||||
const navigation = await send('Page.navigate', { url: `http://127.0.0.1:${port}/${suffix}` }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
await delay(3500);
|
||||
const loaded = await evaluate("({url:location.href, ready:document.readyState, body:document.body.innerText, html:document.body.innerHTML.slice(0,500)})");
|
||||
if (!loaded?.url?.includes(`127.0.0.1:${port}`)) throw new Error(`Fixture did not load: ${JSON.stringify(loaded)}`);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(2500);
|
||||
};
|
||||
await load();
|
||||
|
||||
const semantics = async () => evaluate("[...document.querySelectorAll('flt-semantics')].map(x => x.getAttribute('aria-label') || x.innerText || '').filter(Boolean)");
|
||||
const bodyText = async () => evaluate('document.body.innerText');
|
||||
const visibleText = async () => `${await bodyText()}\n${(await semantics()).join('\n')}`;
|
||||
const clickLabel = async label => {
|
||||
const point = await evaluate(`(() => { const needle = ${JSON.stringify(label)}; const e=[...document.querySelectorAll('flt-semantics')].find(x => (x.getAttribute('aria-label') || x.innerText || '') === needle); if (!e) return null; const r=e.getBoundingClientRect(); return {x:r.x+r.width/2,y:r.y+r.height/2}; })()`);
|
||||
if (!point) return false;
|
||||
await send('Input.dispatchMouseEvent', { type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session);
|
||||
await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session);
|
||||
await delay(500);
|
||||
return true;
|
||||
};
|
||||
const labels = await evaluate("[...document.querySelectorAll('flt-semantics')].map(x=>x.getAttribute('aria-label')||x.innerText).filter(Boolean)");
|
||||
if (!labels?.some(x => x.includes('New chat'))) throw new Error(`Chat fixture semantics unavailable: ${JSON.stringify(labels)}`);
|
||||
if (process.env.PROBE_DEBUG) console.log(JSON.stringify(labels));
|
||||
const capture = async (name, width, height) => {
|
||||
await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: width < 600 }, session);
|
||||
await delay(350);
|
||||
const click = async (label, what = label) => {
|
||||
if (!await clickLabel(label)) throw new Error(`Could not click ${what}`);
|
||||
};
|
||||
const clickFirst = async label => {
|
||||
const point = await evaluate(`(() => { const needle = ${JSON.stringify(label)}; const e=[...document.querySelectorAll('flt-semantics')].find(x => (x.getAttribute('aria-label') || x.innerText || '') === needle); if (!e) return null; e.scrollIntoView({block:'center'}); const r=e.getBoundingClientRect(); return {x:r.x+r.width/2,y:r.y+r.height/2}; })()`);
|
||||
if (!point) throw new Error(`Could not find ${label}`);
|
||||
await send('Input.dispatchMouseEvent', { type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session);
|
||||
await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session);
|
||||
await delay(500);
|
||||
};
|
||||
const waitText = (needle, label = needle) => waitFor(async () => (await visibleText()).includes(needle), label);
|
||||
const focusInput = async () => {
|
||||
const focused = await evaluate(`(() => {
|
||||
const node = document.querySelector('input.flt-text-editing, flt-semantics input, input, textarea');
|
||||
if (!node) return false;
|
||||
node.focus();
|
||||
node.select?.();
|
||||
node.setSelectionRange?.(0, (node.value || '').length);
|
||||
return true;
|
||||
})()`);
|
||||
if (!focused) throw new Error('No semantics text field available');
|
||||
await delay(250);
|
||||
return evaluate(`(() => { const node = document.querySelector('input.flt-text-editing, flt-semantics input, input, textarea'); return node ? node.value : null; })()`);
|
||||
};
|
||||
const type = async text => {
|
||||
await send('Input.insertText', { text }, session);
|
||||
await delay(400);
|
||||
};
|
||||
const resize = async (width, height, scale = 1) => {
|
||||
await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: scale, mobile: width < 600 }, session);
|
||||
await delay(500);
|
||||
};
|
||||
const capture = async (name, width, height, scale = 1) => {
|
||||
await resize(width, height, scale);
|
||||
const data = (await send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false }, session)).result.data;
|
||||
await (await import('node:fs/promises')).writeFile(`${artifactDir}/${variant}-${name}.png`, Buffer.from(data, 'base64'));
|
||||
};
|
||||
await capture('chat-sessions-desktop', 1280, 800);
|
||||
await capture('chat-sessions-phone', 390, 844);
|
||||
if (!await clickLabel('New chat')) throw new Error('Could not open create dialog');
|
||||
const captures = [];
|
||||
const shot = async (name, width, height, scale = 1) => {
|
||||
await capture(name, width, height, scale);
|
||||
captures.push(`${variant}-${name}.png`);
|
||||
};
|
||||
|
||||
const labels = await semantics();
|
||||
if (!labels.some(x => x.includes('New chat'))) throw new Error(`Chat fixture semantics unavailable: ${JSON.stringify(labels)}`);
|
||||
|
||||
await resize(390, 844);
|
||||
await shot('list-phone', 390, 844);
|
||||
await load('?dark=1');
|
||||
await shot('list-dark-320-2x', 320, 640, 2);
|
||||
await load();
|
||||
await resize(390, 844);
|
||||
|
||||
// Hide is device-local: the row leaves with an Undo and no server call.
|
||||
await click('Chat actions for Open fixture', 'the open row actions');
|
||||
await click('Hide on this device', 'Hide on this device');
|
||||
await waitText('Hidden on this device', 'the hide Undo');
|
||||
if ((await visibleText()).includes('Open fixture')) {
|
||||
throw new Error('The hidden row stayed in the list');
|
||||
}
|
||||
await shot('hidden-undo', 390, 844);
|
||||
await shot('hidden-undo-320-2x', 320, 640, 2);
|
||||
if (!(await visibleText()).includes('Hidden on this device')) {
|
||||
throw new Error('The Undo bar left the 320px view');
|
||||
}
|
||||
await resize(390, 844);
|
||||
await click('Undo', 'Undo');
|
||||
await delay(600);
|
||||
if (!(await visibleText()).includes('Open fixture')) {
|
||||
// Flutter web's semantics DOM swallows the coordinate hit for this
|
||||
// Cupertino button; activate the same rendered node through its semantics
|
||||
// action instead of pretending the Undo happened.
|
||||
const activated = await evaluate(`(() => { const e = [...document.querySelectorAll('flt-semantics')].find(x => (x.getAttribute('aria-label') || x.innerText || '') === 'Undo'); e?.click(); return !!e; })()`);
|
||||
if (!activated) throw new Error('Could not activate Undo');
|
||||
await delay(600);
|
||||
await send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: 195, y: 680, deltaY: 598 }, session);
|
||||
await delay(350);
|
||||
const changedBody = await evaluate('document.body.innerText');
|
||||
await capture('chat-sessions-create-dialog', 390, 844);
|
||||
if (!changedBody.includes('Server directory') || !changedBody.includes('Backend') || !changedBody.includes('New chats use the server default model.')) throw new Error(`Create dialog did not change rendered body to catalog controls: ${changedBody}`);
|
||||
if (!await clickLabel('Cancel')) throw new Error('Could not close create dialog');
|
||||
await delay(600);
|
||||
if (!await clickLabel('Chat actions for Open fixture')) throw new Error('Could not open row actions');
|
||||
await delay(600);
|
||||
const actionsBody = await evaluate('document.body.innerText');
|
||||
const actionLabels = await evaluate("[...document.querySelectorAll('flt-semantics')].map(x => x.getAttribute('aria-label') || x.innerText || '').filter(Boolean)");
|
||||
await capture('chat-sessions-actions', 390, 844);
|
||||
if (!actionLabels.some(label => label.includes('Rename…'))) throw new Error(`Row actions unavailable: ${actionsBody} / ${actionLabels}`);
|
||||
console.log(JSON.stringify({ variant, labels, captures: [`${variant}-chat-sessions-desktop.png`, `${variant}-chat-sessions-phone.png`, `${variant}-chat-sessions-create-dialog.png`, `${variant}-chat-sessions-actions.png`], bodyChanged: true }, null, 2));
|
||||
}
|
||||
await waitText('Open fixture', 'the restored row');
|
||||
await waitText('Open fixture', 'the restored row');
|
||||
|
||||
// Dialog chrome at the smallest size the list supports (320 CSS px, 2x DPR).
|
||||
await click('New chat', 'the New chat action');
|
||||
await waitText('Server directory', 'the create dialog at 320');
|
||||
await shot('create-320-2x', 320, 640, 2);
|
||||
await click('Cancel', 'Cancel the create dialog');
|
||||
await resize(390, 844);
|
||||
|
||||
await click('Chat actions for Open fixture', 'the open row actions');
|
||||
await click('Rename…', 'Rename…');
|
||||
await waitText('Rename chat', 'the rename dialog at 320');
|
||||
await shot('rename-320-2x', 320, 640, 2);
|
||||
await click('Cancel', 'Cancel the rename dialog');
|
||||
await resize(390, 844);
|
||||
|
||||
// The New marker follows this device's read watermark and never a closed row.
|
||||
await load('?unseen=1');
|
||||
await resize(390, 844);
|
||||
await click('Refresh', 'Refresh');
|
||||
await waitText('/workspace/demo · New', 'the open row New marker');
|
||||
const unseenBody = await visibleText();
|
||||
if (unseenBody.includes('/workspace/archive · New')) {
|
||||
throw new Error('The closed row reported New');
|
||||
}
|
||||
await shot('new-marker', 390, 844);
|
||||
await load();
|
||||
await resize(390, 844);
|
||||
|
||||
// A create reply without `chat_session` uses the web's exact sentence.
|
||||
await click('New chat', 'the New chat action');
|
||||
await waitText('Server directory', 'the create dialog');
|
||||
await focusInput();
|
||||
await type('No session title');
|
||||
await click('Create', 'the create dialog confirm');
|
||||
await waitText(
|
||||
'The server did not return the new chat session.',
|
||||
'the missing-session wording',
|
||||
);
|
||||
if ((await visibleText()).includes('Bad state')) {
|
||||
throw new Error('The missing-session refusal leaked a Dart StateError');
|
||||
}
|
||||
await shot('create-missing-session', 390, 844);
|
||||
await click('Cancel', 'Cancel the refused create');
|
||||
|
||||
// Create: the dialog sends once and the accepted row arrives from a list read.
|
||||
await click('New chat', 'the New chat action');
|
||||
await waitText('Create', 'the create dialog');
|
||||
await focusInput();
|
||||
await type('Probe created');
|
||||
await click('Create', 'the create dialog confirm');
|
||||
if (process.env.PROBE_DEBUG) console.log(JSON.stringify({ afterCreate: await bodyText(), labels: await semantics() }, null, 2));
|
||||
await waitText('Probe created', 'the created row');
|
||||
if ((await visibleText()).includes('no chat harness')) throw new Error('Create did not reach the fixture');
|
||||
await shot('created-list', 390, 844);
|
||||
|
||||
// Rename: seeded with the current title, then the row reads the accepted name.
|
||||
await click('Chat actions for Probe created', 'the created row actions');
|
||||
await click('Rename…', 'Rename…');
|
||||
await waitText('Rename chat', 'the rename dialog');
|
||||
const seeded = await focusInput();
|
||||
if (seeded !== 'Probe created') throw new Error(`Rename was seeded with ${JSON.stringify(seeded)}`);
|
||||
await type('Probe renamed');
|
||||
await click('Save', 'the rename Save');
|
||||
await waitText('Probe renamed', 'the renamed row');
|
||||
if ((await visibleText()).includes('Probe created')) throw new Error('The old title survived the accepted rename');
|
||||
await shot('renamed-list', 390, 844);
|
||||
|
||||
// Star the renamed row (the first unstarred row in server order).
|
||||
const unstarredBefore = (await semantics()).filter(label => label === 'Unstar chat').length;
|
||||
await clickFirst('Star chat');
|
||||
await waitFor(async () => (await semantics()).filter(label => label === 'Unstar chat').length === unstarredBefore + 1, 'the shared star to refresh');
|
||||
const starredBody = await visibleText();
|
||||
if (starredBody.indexOf('Probe renamed') > starredBody.indexOf('Streaming fixture')) {
|
||||
throw new Error('The starred row did not move to the Starred group');
|
||||
}
|
||||
await shot('starred-list', 390, 844);
|
||||
|
||||
// Close: accepted close changes the row's available action to Reopen.
|
||||
await click('Chat actions for Probe renamed', 'the starred row actions');
|
||||
await click('Close chat…', 'Close chat…');
|
||||
await click('Close chat', 'the close confirmation');
|
||||
await click('Chat actions for Probe renamed', 'the closed row actions');
|
||||
if (!(await semantics()).includes('Reopen')) throw new Error('The closed row does not offer Reopen');
|
||||
await click('Rename…', 'Rename… on the closed row');
|
||||
|
||||
// Refusal: the dialog keeps the field and the server's own words.
|
||||
await waitText('Rename chat', 'the rename dialog');
|
||||
await focusInput();
|
||||
await type('Refused title');
|
||||
await click('Save', 'the refused Save');
|
||||
await waitText('a title with usable text is required', 'the rename refusal');
|
||||
const kept = await evaluate(`(() => { const node = document.querySelector('input.flt-text-editing, flt-semantics input, input, textarea'); return node ? node.value : null; })()`);
|
||||
const keptLabels = await semantics();
|
||||
if (kept !== 'Refused title' && !keptLabels.some(label => label.includes('Refused title'))) {
|
||||
throw new Error(`The refusal lost the dialog draft: ${JSON.stringify({ kept, keptLabels })}`);
|
||||
}
|
||||
if (!keptLabels.includes('Cancel')) throw new Error('The refusal closed the dialog');
|
||||
await shot('rename-refusal', 390, 844);
|
||||
await click('Cancel', 'Cancel after the refusal');
|
||||
|
||||
// A refused row action keeps the server's whole reason under its own row on
|
||||
// both hosts — never one ellipsised line inside a Cupertino subtitle.
|
||||
await clickFirst('Chat actions for Closed fixture');
|
||||
await click('Reopen', 'Reopen on the closed fixture');
|
||||
await waitText('the chat is locked by another operator', 'the row refusal');
|
||||
if (
|
||||
!(await visibleText()).includes('refresh the list to see its current state')
|
||||
) {
|
||||
throw new Error('The row refusal lost the end of the server reason');
|
||||
}
|
||||
await shot('row-refusal', 390, 844);
|
||||
// Filter to the refused row so the 320px capture keeps the whole message
|
||||
// clear of the floating action button.
|
||||
await focusInput();
|
||||
await type('Closed fixture');
|
||||
await delay(600);
|
||||
await shot('row-refusal-320-2x', 320, 640, 2);
|
||||
|
||||
console.log(JSON.stringify({ variant, captures, hiddenUndo: true, newMarker: true, missingSessionWording: true, refusalVisible: true, rowRefusal: true, renamedFromServer: true, starredFromServer: true, closedFromServer: true }, null, 2));
|
||||
} finally {
|
||||
ws?.close();
|
||||
chrome.kill('SIGTERM');
|
||||
|
||||
@@ -2,57 +2,123 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/chat/session_screen.dart';
|
||||
|
||||
/// Stateful chat-session fixture for the real-browser probe: every accepted
|
||||
/// mutation changes the list the next `chat_sessions` read returns, so the
|
||||
/// screen must refresh from the server rather than guess. A title of
|
||||
/// `Refused title` is refused with the server's words; `No session title`
|
||||
/// returns a create reply without `chat_session`; `?unseen=1` reports newer
|
||||
/// recency after the first read so the `New` marker can be observed.
|
||||
class _FixtureGateway implements ApiGateway {
|
||||
_FixtureGateway({this.bumpAfterFirstRead = false});
|
||||
|
||||
/// `?unseen=1`: the first list read seeds the device watermark and later
|
||||
/// reads report newer activity, so the browser can prove the `New` marker.
|
||||
final bool bumpAfterFirstRead;
|
||||
int _reads = 0;
|
||||
|
||||
final _sessions = <JsonMap>[
|
||||
{
|
||||
'id': 'probe-open',
|
||||
'title': 'Open fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'starred': true,
|
||||
},
|
||||
{
|
||||
'id': 'probe-closed',
|
||||
'title': 'Closed fixture',
|
||||
'directory': '/workspace/archive',
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
{
|
||||
'id': 'probe-stream',
|
||||
'title': 'Streaming fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'running': true,
|
||||
},
|
||||
];
|
||||
int _nextId = 1;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type == 'chat_sessions') {
|
||||
return {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'probe-open',
|
||||
'title': 'Open fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'starred': true,
|
||||
},
|
||||
{
|
||||
'id': 'probe-closed',
|
||||
'title': 'Closed fixture',
|
||||
'directory': '/workspace/archive',
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
{
|
||||
'id': 'probe-stream',
|
||||
'title': 'Streaming fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'running': true,
|
||||
},
|
||||
],
|
||||
};
|
||||
switch (type) {
|
||||
case 'chat_sessions':
|
||||
_reads++;
|
||||
return {
|
||||
'chat_sessions': [for (final session in _sessions) _row(session)],
|
||||
};
|
||||
case 'chat_directories':
|
||||
return {
|
||||
'chat_directories': [
|
||||
'/workspace/demo',
|
||||
'/workspace/archive',
|
||||
'/Users/alan/repos/pipelines/tmp/flutter-chat-list',
|
||||
],
|
||||
};
|
||||
case 'chat_backends':
|
||||
return {
|
||||
'chat_backends': ['opencode', 'codex'],
|
||||
};
|
||||
case 'chat_create':
|
||||
final body = fields['chat_create']! as JsonMap;
|
||||
// The web's exact refusal for a reply without a created session.
|
||||
if ('${body['title']}' == 'No session title') return const {};
|
||||
final session = {
|
||||
'id': 'probe-new-${_nextId++}',
|
||||
'title': body['title'],
|
||||
'directory': body['directory'],
|
||||
};
|
||||
_sessions.insert(0, session);
|
||||
return {'chat_session': Map<String, dynamic>.from(session)};
|
||||
case 'chat_rename':
|
||||
final body = fields['chat_rename']! as JsonMap;
|
||||
if ('${body['title']}' == 'Refused title') {
|
||||
throw const ProtocolError('a title with usable text is required');
|
||||
}
|
||||
_update('${body['session_id']}', 'title', body['title']);
|
||||
return const {};
|
||||
case 'chat_star':
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
_update('${body['session_id']}', 'starred', body['starred']);
|
||||
return const {};
|
||||
case 'chat_close':
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
_update('${body['session_id']}', 'closed_at', '2026-01-02');
|
||||
return const {};
|
||||
case 'chat_reopen':
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
// A refusal long enough to need several lines at 320px with 2x text.
|
||||
if ('${body['session_id']}' == 'probe-closed') {
|
||||
throw const ProtocolError(
|
||||
'the chat is locked by another operator and cannot be reopened '
|
||||
'from here; refresh the list to see its current state',
|
||||
);
|
||||
}
|
||||
_update('${body['session_id']}', 'closed_at', null);
|
||||
return const {};
|
||||
default:
|
||||
return {'chat_session': {}};
|
||||
}
|
||||
if (type == 'chat_directories') {
|
||||
return {
|
||||
'chat_directories': ['/workspace/demo', '/workspace/archive'],
|
||||
};
|
||||
}
|
||||
|
||||
void _update(String id, String key, Object? value) {
|
||||
for (final session in _sessions) {
|
||||
if (session['id'] == id) session[key] = value;
|
||||
}
|
||||
if (type == 'chat_backends') {
|
||||
return {
|
||||
'chat_backends': ['opencode', 'codex'],
|
||||
};
|
||||
}
|
||||
|
||||
JsonMap _row(JsonMap session) {
|
||||
final row = Map<String, dynamic>.from(session);
|
||||
if (bumpAfterFirstRead &&
|
||||
(row['id'] == 'probe-open' || row['id'] == 'probe-closed')) {
|
||||
row['updated_at'] = _reads > 1 ? 2000 : 1000;
|
||||
}
|
||||
if (type == 'chat_create') {
|
||||
return {
|
||||
'chat_session': {
|
||||
'id': 'probe-new',
|
||||
'title': 'New fixture',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
};
|
||||
}
|
||||
return {'chat_session': {}};
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +128,29 @@ const _probeStyle = String.fromEnvironment(
|
||||
);
|
||||
|
||||
void main() {
|
||||
final home = ChatSessionsScreen(gateway: _FixtureGateway(), onOpen: (_) {});
|
||||
final dark = Uri.base.queryParameters['dark'] == '1';
|
||||
final unseen = Uri.base.queryParameters['unseen'] == '1';
|
||||
final home = ChatSessionsScreen(
|
||||
gateway: _FixtureGateway(bumpAfterFirstRead: unseen),
|
||||
onOpen: (_) {},
|
||||
);
|
||||
if (_probeStyle == 'cupertino') {
|
||||
runApp(CupertinoApp(home: home));
|
||||
runApp(
|
||||
CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
runApp(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
theme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user