feat: embed a Flutter G4F client with Cronet, cookie jar, and origin WebView

Port the Oracle off the Python g4f container onto on-device providers: Chromium HTTP via Cronet, a shared cookie session, IterList retry, hosted OpenAI-compat aggregators, and same-origin WebView fallbacks instead of CORS fetch.
This commit is contained in:
Alma Alexyz
2026-09-01 22:05:38 +05:00
parent f3e7412cf9
commit fbf04d90db
49 changed files with 4856 additions and 92 deletions
+63
View File
@@ -0,0 +1,63 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../http_client.dart';
import '../models.dart';
import 'base_provider.dart';
class AiChatOs extends BaseProvider {
@override
String get name => 'AiChatOs';
@override
bool get working => true;
@override
List<String> get models => [G4FModels.gpt4];
@override
String get defaultModel => G4FModels.gpt4;
@override
Stream<String> createAsyncGenerator(
String model,
List<Message> messages, {
bool stream = false,
}) async* {
final url = Uri.parse('https://api.aichatos.cloud/api/generateStream');
final userId = '#/chat/${DateTime.now().millisecondsSinceEpoch}';
final systemMessage = extractSystemMessage(messages);
final formattedPrompt = formatPrompt(messages);
final req = http.Request('POST', url);
req.headers.addAll({
'Content-Type': 'application/json',
'Origin': 'https://chat.aichatos.top',
'Referer': 'https://chat.aichatos.top/',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
});
req.body = jsonEncode({
'prompt': formattedPrompt,
'userId': userId,
'network': true,
'system': systemMessage,
'withoutContext': false,
'stream': stream,
});
final response = await g4fHttp.send(req);
if (response.statusCode == 200) {
final resBytes = await response.stream.toBytes();
final fullText = utf8.decode(resBytes).trim();
if (fullText.isNotEmpty && !fullText.startsWith('<!DOCTYPE') && !fullText.contains('Error:')) {
yield fullText;
} else {
throw Exception('$name unusable body');
}
} else {
throw Exception('$name returned status ${response.statusCode}');
}
}
}