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
+47
View File
@@ -0,0 +1,47 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:words999/g4f/http_util.dart';
import 'package:words999/g4f/sse.dart';
void main() {
test('splitSseLines reassembles lines split across chunks', () async {
final lines = await splitSseLines(Stream.fromIterable([
'data: {"message":"Hel',
'lo"}\n',
'data: {"message":"!"}\n',
'data: [DONE]\n',
])).toList();
expect(lines, [
'data: {"message":"Hello"}',
'data: {"message":"!"}',
'data: [DONE]',
]);
});
test('extractSseContent reads OpenAI deltas and Duck messages', () {
expect(
extractSseContent('{"choices":[{"delta":{"content":"Привет"}}]}'),
'Привет',
);
expect(
extractSseContent('{"message":"знак","action":"success"}'),
'знак',
);
expect(extractSseContent('[DONE]'), isNull);
});
test('extractOpenAiMessage reads a non-stream body', () {
const body =
'{"choices":[{"message":{"role":"assistant","content":"OK"}}]}';
expect(extractOpenAiMessage(body), 'OK');
});
test('looksLikeGarbage detects WAF and error pages', () {
expect(looksLikeGarbage('<!DOCTYPE html><html>'), isTrue);
expect(looksLikeGarbage('Just a moment...'), isTrue);
expect(looksLikeGarbage('Оракул видит знак ВЕТЕР'), isFalse);
expect(looksLikeModelOutput('OK'), isFalse);
expect(looksLikeModelOutput('{}'), isFalse);
expect(looksLikeGarbage('No cake credits'), isTrue);
expect(looksLikeModelOutput('Оракул видит знак ВЕТЕР'), isTrue);
});
}