110 lines
3.1 KiB
Dart
110 lines
3.1 KiB
Dart
// 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: () {},
|
|
),
|
|
),
|
|
);
|
|
}
|