refactor: unify skills+cli runtime and streamline ag-ui flow
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:social_app/core/chat/ag_ui_event.dart';
|
||||
|
||||
void main() {
|
||||
group('ToolCallResultEvent', () {
|
||||
test('parses ui_schema from json', () {
|
||||
final json = <String, dynamic>{
|
||||
'type': 'TOOL_CALL_RESULT',
|
||||
'messageId': 'msg_1',
|
||||
'tool_call_id': 'call_1',
|
||||
'tool_name': 'calendar_read',
|
||||
'result': '{"total": 5}',
|
||||
'status': 'success',
|
||||
'ui_schema': {
|
||||
'version': '2.0',
|
||||
'status': 'success',
|
||||
'root': {
|
||||
'type': 'stack',
|
||||
'children': [],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
final event = ToolCallResultEvent.fromJson(json);
|
||||
|
||||
expect(event.messageId, 'msg_1');
|
||||
expect(event.toolCallId, 'call_1');
|
||||
expect(event.toolName, 'calendar_read');
|
||||
expect(event.status, 'success');
|
||||
expect(event.uiSchema, isNotNull);
|
||||
expect(event.uiSchema!['version'], '2.0');
|
||||
expect(event.uiSchema!['status'], 'success');
|
||||
});
|
||||
|
||||
test('handles missing ui_schema gracefully', () {
|
||||
final json = <String, dynamic>{
|
||||
'type': 'TOOL_CALL_RESULT',
|
||||
'messageId': 'msg_1',
|
||||
'tool_call_id': 'call_1',
|
||||
'tool_name': 'calendar_read',
|
||||
'result': '{"total": 5}',
|
||||
'status': 'success',
|
||||
};
|
||||
|
||||
final event = ToolCallResultEvent.fromJson(json);
|
||||
|
||||
expect(event.uiSchema, isNull);
|
||||
});
|
||||
|
||||
test('parses partial status', () {
|
||||
final json = <String, dynamic>{
|
||||
'type': 'TOOL_CALL_RESULT',
|
||||
'messageId': 'msg_1',
|
||||
'tool_call_id': 'call_1',
|
||||
'tool_name': 'calendar_write',
|
||||
'result': '{"success": 1, "failed": 1}',
|
||||
'status': 'partial',
|
||||
'ui_schema': {
|
||||
'version': '2.0',
|
||||
'status': 'partial',
|
||||
'root': {'type': 'stack', 'children': []},
|
||||
},
|
||||
};
|
||||
|
||||
final event = ToolCallResultEvent.fromJson(json);
|
||||
|
||||
expect(event.status, 'partial');
|
||||
expect(event.uiSchema!['status'], 'partial');
|
||||
});
|
||||
});
|
||||
|
||||
group('TextMessageEndEvent', () {
|
||||
test('no longer includes ui_schema field', () {
|
||||
final json = <String, dynamic>{
|
||||
'type': 'TEXT_MESSAGE_END',
|
||||
'messageId': 'msg_1',
|
||||
'answer': '日程查询完成',
|
||||
'role': 'assistant',
|
||||
'status': 'success',
|
||||
};
|
||||
|
||||
final event = TextMessageEndEvent.fromJson(json);
|
||||
|
||||
expect(event.messageId, 'msg_1');
|
||||
expect(event.answer, '日程查询完成');
|
||||
});
|
||||
|
||||
test('ignores legacy ui_schema if present', () {
|
||||
final json = <String, dynamic>{
|
||||
'type': 'TEXT_MESSAGE_END',
|
||||
'messageId': 'msg_1',
|
||||
'answer': '日程查询完成',
|
||||
'role': 'assistant',
|
||||
'status': 'success',
|
||||
'ui_schema': {'version': '2.0'},
|
||||
};
|
||||
|
||||
final event = TextMessageEndEvent.fromJson(json);
|
||||
|
||||
expect(event.answer, '日程查询完成');
|
||||
});
|
||||
});
|
||||
|
||||
group('HistoryMessage', () {
|
||||
test('parses uiSchema from tool message metadata', () {
|
||||
final json = <String, dynamic>{
|
||||
'id': 'm1',
|
||||
'seq': 1,
|
||||
'role': 'tool',
|
||||
'content': '{"total": 5}',
|
||||
'timestamp': '2026-04-21T10:00:00+08:00',
|
||||
'attachments': const [],
|
||||
'ui_schema': {
|
||||
'version': '2.0',
|
||||
'status': 'success',
|
||||
'root': {
|
||||
'type': 'stack',
|
||||
'children': [
|
||||
{'type': 'text', 'content': '找到 5 个日程', 'role': 'body'},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
final message = HistoryMessage.fromJson(json);
|
||||
|
||||
expect(message.uiSchema, isNotNull);
|
||||
expect(message.uiSchema!['version'], '2.0');
|
||||
});
|
||||
|
||||
test('handles missing uiSchema gracefully', () {
|
||||
final json = <String, dynamic>{
|
||||
'id': 'm1',
|
||||
'seq': 1,
|
||||
'role': 'assistant',
|
||||
'content': 'hello',
|
||||
'timestamp': '2026-04-21T10:00:00+08:00',
|
||||
'attachments': const [],
|
||||
};
|
||||
|
||||
final message = HistoryMessage.fromJson(json);
|
||||
|
||||
expect(message.uiSchema, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user