refactor(apps): simplify API layer by removing redundant wrapper classes
- Remove ApiClientWrapper and MockApiClientWrapper - Simplify IApiClient interface - Update dependency injection configuration - Optimize calendar service and AG-UI chat models
This commit is contained in:
@@ -89,7 +89,7 @@ final _typeToFactory = {
|
||||
AgUiEventType.unknown: UnknownAgUiEvent.fromJson,
|
||||
};
|
||||
|
||||
@JsonSerializable()
|
||||
@JsonSerializable(createFactory: false)
|
||||
class AgUiEvent {
|
||||
final AgUiEventType type;
|
||||
|
||||
@@ -104,7 +104,7 @@ class AgUiEvent {
|
||||
Map<String, dynamic> toJson() => _$AgUiEventToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@JsonSerializable(createFactory: false, createToJson: false)
|
||||
class UnknownAgUiEvent extends AgUiEvent {
|
||||
final Map<String, dynamic> rawJson;
|
||||
|
||||
|
||||
@@ -6,9 +6,6 @@ part of 'ag_ui_event.dart';
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
AgUiEvent _$AgUiEventFromJson(Map<String, dynamic> json) =>
|
||||
AgUiEvent(type: $enumDecode(_$AgUiEventTypeEnumMap, json['type']));
|
||||
|
||||
Map<String, dynamic> _$AgUiEventToJson(AgUiEvent instance) => <String, dynamic>{
|
||||
'type': _$AgUiEventTypeEnumMap[instance.type]!,
|
||||
};
|
||||
@@ -29,12 +26,6 @@ const _$AgUiEventTypeEnumMap = {
|
||||
AgUiEventType.unknown: 'unknown',
|
||||
};
|
||||
|
||||
UnknownAgUiEvent _$UnknownAgUiEventFromJson(Map<String, dynamic> json) =>
|
||||
UnknownAgUiEvent(rawJson: json['rawJson'] as Map<String, dynamic>);
|
||||
|
||||
Map<String, dynamic> _$UnknownAgUiEventToJson(UnknownAgUiEvent instance) =>
|
||||
<String, dynamic>{'rawJson': instance.rawJson};
|
||||
|
||||
RunStartedEvent _$RunStartedEventFromJson(Map<String, dynamic> json) =>
|
||||
RunStartedEvent(
|
||||
threadId: json['threadId'] as String,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:social_app/core/config/env.dart';
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
|
||||
import '../ai/ai_decision_engine.dart';
|
||||
import '../models/ag_ui_event.dart';
|
||||
@@ -24,27 +24,29 @@ const _textChunkSize = 10;
|
||||
typedef EventCallback = void Function(AgUiEvent event);
|
||||
|
||||
class AgUiService {
|
||||
final IApiClient? _apiClient;
|
||||
EventCallback onEvent;
|
||||
final AiDecisionEngine _decisionEngine;
|
||||
final MockHistoryService _historyService;
|
||||
|
||||
AgUiService({EventCallback? onEvent})
|
||||
AgUiService({EventCallback? onEvent, IApiClient? apiClient})
|
||||
: onEvent = onEvent ?? ((_) {}),
|
||||
_apiClient = apiClient,
|
||||
_decisionEngine = AiDecisionEngine(),
|
||||
_historyService = MockHistoryService();
|
||||
|
||||
Future<void> sendMessage(String content) async {
|
||||
if (Env.isMockApi) {
|
||||
await _mockEventStream(content);
|
||||
} else {
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
await _mockEventStream(content);
|
||||
}
|
||||
|
||||
Future<void> loadHistory({DateTime? beforeDate}) async {
|
||||
if (Env.isMockApi) {
|
||||
await _mockLoadHistory(beforeDate: beforeDate);
|
||||
if (_apiClient != null) {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
await _mockLoadHistory(beforeDate: beforeDate);
|
||||
}
|
||||
|
||||
bool hasEarlierHistory(DateTime fromDate) {
|
||||
|
||||
Reference in New Issue
Block a user