docs: 添加 AG-UI 协议规则约束到 apps/AGENTS.md
This commit is contained in:
@@ -7,6 +7,7 @@ import '../ai/ai_decision_engine.dart';
|
||||
import '../models/ag_ui_event.dart';
|
||||
import '../models/tool_result.dart';
|
||||
import '../tools/tool_registry.dart';
|
||||
import 'mock_history_service.dart';
|
||||
|
||||
/// Mock ID 前缀常量
|
||||
const _threadIdPrefix = 'thread_';
|
||||
@@ -25,10 +26,12 @@ typedef EventCallback = void Function(AgUiEvent event);
|
||||
class AgUiService {
|
||||
EventCallback onEvent;
|
||||
final AiDecisionEngine _decisionEngine;
|
||||
final MockHistoryService _historyService;
|
||||
|
||||
AgUiService({EventCallback? onEvent})
|
||||
: onEvent = onEvent ?? ((_) {}),
|
||||
_decisionEngine = AiDecisionEngine();
|
||||
_decisionEngine = AiDecisionEngine(),
|
||||
_historyService = MockHistoryService();
|
||||
|
||||
Future<void> sendMessage(String content) async {
|
||||
if (Env.isMockApi) {
|
||||
@@ -38,6 +41,43 @@ class AgUiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadHistory({DateTime? beforeDate}) async {
|
||||
if (Env.isMockApi) {
|
||||
await _mockLoadHistory(beforeDate: beforeDate);
|
||||
} else {
|
||||
throw UnimplementedError('Real API not implemented');
|
||||
}
|
||||
}
|
||||
|
||||
bool hasEarlierHistory(DateTime fromDate) {
|
||||
return _historyService.hasEarlierHistory(fromDate);
|
||||
}
|
||||
|
||||
Future<void> _mockLoadHistory({DateTime? beforeDate}) async {
|
||||
final threadId = '$_threadIdPrefix${DateTime.now().millisecondsSinceEpoch}';
|
||||
final runId = '$_runIdPrefix${DateTime.now().millisecondsSinceEpoch}';
|
||||
|
||||
onEvent(RunStartedEvent(threadId: threadId, runId: runId));
|
||||
|
||||
DateTime targetDate;
|
||||
if (beforeDate != null) {
|
||||
final prevDate = _historyService.getPreviousDay(beforeDate);
|
||||
if (prevDate == null) {
|
||||
onEvent(RunFinishedEvent(threadId: threadId, runId: runId));
|
||||
return;
|
||||
}
|
||||
targetDate = prevDate;
|
||||
} else {
|
||||
targetDate = _historyService.getLatestHistoryDate() ?? DateTime.now();
|
||||
}
|
||||
|
||||
final messages = _historyService.getHistoryForDay(targetDate);
|
||||
|
||||
onEvent(MessagesSnapshotEvent(messages: messages));
|
||||
|
||||
onEvent(RunFinishedEvent(threadId: threadId, runId: runId));
|
||||
}
|
||||
|
||||
Future<void> _mockEventStream(String content) async {
|
||||
final threadId = '$_threadIdPrefix${DateTime.now().millisecondsSinceEpoch}';
|
||||
final runId = '$_runIdPrefix${DateTime.now().millisecondsSinceEpoch}';
|
||||
|
||||
Reference in New Issue
Block a user