feat: add MCP support (#1471)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 20:21:39 +08:00
1 parent 39cd9034cd
commit f2145de571
83 files changed
+3119 -363

No files matched your search

@@ -8,7 +8,9 @@ class RestGopeedTransport implements GopeedTransport {
RestGopeedTransport(GopeedTransportConfig config)
: _dio = Dio(
BaseOptions(
baseUrl: '${Uri.base.origin}/',
// Keep release requests relative so deployments under a reverse
// proxy path continue to work, matching the legacy Web client.
baseUrl: webTransportBaseUrl(config.address, Uri.base),
contentType: Headers.jsonContentType,
sendTimeout: const Duration(seconds: 5),
connectTimeout: const Duration(seconds: 5),
@@ -1,4 +1,5 @@
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'entry/gopeed_transport_stub.dart'
if (dart.library.html) 'entry/gopeed_transport_web.dart'
@@ -18,6 +19,44 @@ class GopeedTransportConfig {
final void Function()? onUnauthorized;
}
const defaultWebApiPort = 9999;
/// Resolves the API base URL used by Flutter Web.
///
/// This preserves the legacy behavior: debug builds connect to the local
/// backend on port 9999, while release builds use the page's server origin.
String webApiBaseUrl(Uri pageUri, {bool? debugMode}) {
final useDebugPort = debugMode ?? kDebugMode;
if (useDebugPort) return 'http://127.0.0.1:$defaultWebApiPort/';
return '${pageUri.origin}/';
}
/// Returns the Dio base URL, preserving relative requests in release builds.
String webTransportBaseUrl(String address, Uri pageUri, {bool? debugMode}) {
final useDebugPort = debugMode ?? kDebugMode;
return useDebugPort ? normalizeWebApiBaseUrl(address, pageUri) : '';
}
/// Normalizes either an absolute API URL or a host:port address.
String normalizeWebApiBaseUrl(String address, Uri pageUri) {
var value = address.trim();
if (value.isEmpty) return '${pageUri.origin}/';
final parsed = Uri.tryParse(value);
if (parsed != null && parsed.hasScheme && parsed.host.isNotEmpty) {
value = Uri(
scheme: parsed.scheme,
userInfo: parsed.userInfo,
host: parsed.host,
port: parsed.hasPort ? parsed.port : null,
path: parsed.path,
).toString();
} else {
value = '${pageUri.scheme}://${value.replaceAll(RegExp(r'/+$'), '')}';
}
return value.endsWith('/') ? value : '$value/';
}
abstract interface class GopeedTransport {
Future<dynamic> request(String path, {String method = 'GET', dynamic data, Map<String, dynamic>? queryParameters});