import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/screen.dart'; /// Browser fixture for the C2 markdown wiring: the real Chat destination and /// the real thread render one server-shaped conversation whose assistant text /// is formatted markdown and whose user text must stay byte-exact. /// /// Material and Cupertino hosts are the same fixture built with /// `CHAT_MARKDOWN_WIRE_PROBE_STYLE`. class _FixtureGateway implements ApiGateway { final _frames = StreamController.broadcast(); @override Stream get frames => _frames.stream; @override Future call(String type, [JsonMap fields = const {}]) async { switch (type) { case 'chat_sessions': return { 'chat_sessions': [ { 'id': 'probe-markdown', 'title': 'Markdown wire', 'directory': '/workspace/demo', }, ], }; case 'chat_subscribe': return {}; case 'chat_messages': return { 'chat_history': { 'messages': [ { 'id': 'u-markdown', 'role': 'user', 'parts': [ { 'type': 'text', 'text': 'Keep **this** exactly: [link](javascript:alert).', }, ], }, { 'id': 'a-markdown', 'role': 'assistant', 'parts': [ { 'type': 'reasoning', 'text': 'Reasoning stays plain **text**.', }, {'type': 'text', 'text': _answer}, ], }, ], 'next_cursor': '', 'has_more': false, }, }; } return {}; } } const String _answer = '## Quarterly status\n' '\n' 'The **release** is ready, with `gateway` passing.\n' '\n' '- build verified\n' '- review pending\n' '\n' '| Step | State |\n' '| --- | --- |\n' '| build | ok |\n' '\n' '```dart\n' 'final count = 3;\n' '```\n' '\n' 'Literal markup and [unsafe](javascript:alert) stay visible.'; const _style = String.fromEnvironment( 'CHAT_MARKDOWN_WIRE_PROBE_STYLE', defaultValue: 'material', ); void main() { final screen = ChatScreen( gateway: _FixtureGateway(), onSessionSelected: null, ); if (_style == 'cupertino') { runApp( CupertinoApp( theme: const CupertinoThemeData(brightness: Brightness.dark), home: CupertinoPageScaffold( navigationBar: const CupertinoNavigationBar(middle: Text('Chat')), child: SafeArea(child: screen), ), ), ); return; } runApp( MaterialApp( theme: ThemeData( brightness: Brightness.dark, platform: TargetPlatform.android, ), home: Scaffold( appBar: AppBar(title: const Text('Chat')), body: screen, ), ), ); }