chore: clean up legacy tool/UI code paths and remove unused events

This commit is contained in:
qzl
2026-04-22 17:33:12 +08:00
parent 4d55df45ab
commit ef931ee73c
7 changed files with 1 additions and 92 deletions
-24
View File
@@ -9,7 +9,6 @@ class AgUiEventTypeWire {
static const toolCallArgs = 'TOOL_CALL_ARGS';
static const toolCallEnd = 'TOOL_CALL_END';
static const toolCallResult = 'TOOL_CALL_RESULT';
static const toolCallError = 'TOOL_CALL_ERROR';
}
enum AgUiEventType {
@@ -23,7 +22,6 @@ enum AgUiEventType {
toolCallArgs,
toolCallEnd,
toolCallResult,
toolCallError,
unknown,
}
@@ -38,7 +36,6 @@ const _wireToTypeMap = {
AgUiEventTypeWire.toolCallArgs: AgUiEventType.toolCallArgs,
AgUiEventTypeWire.toolCallEnd: AgUiEventType.toolCallEnd,
AgUiEventTypeWire.toolCallResult: AgUiEventType.toolCallResult,
AgUiEventTypeWire.toolCallError: AgUiEventType.toolCallError,
};
const _typeToWireMap = {
@@ -52,7 +49,6 @@ const _typeToWireMap = {
AgUiEventType.toolCallArgs: AgUiEventTypeWire.toolCallArgs,
AgUiEventType.toolCallEnd: AgUiEventTypeWire.toolCallEnd,
AgUiEventType.toolCallResult: AgUiEventTypeWire.toolCallResult,
AgUiEventType.toolCallError: AgUiEventTypeWire.toolCallError,
AgUiEventType.unknown: '',
};
@@ -82,7 +78,6 @@ abstract class AgUiEvent {
AgUiEventType.toolCallArgs => ToolCallArgsEvent.fromJson(json),
AgUiEventType.toolCallEnd => ToolCallEndEvent.fromJson(json),
AgUiEventType.toolCallResult => ToolCallResultEvent.fromJson(json),
AgUiEventType.toolCallError => ToolCallErrorEvent.fromJson(json),
AgUiEventType.unknown => UnknownAgUiEvent(rawJson: json),
};
}
@@ -162,14 +157,12 @@ class TextMessageEndEvent extends AgUiEvent {
required this.answer,
required this.role,
required this.status,
required this.uiSchema,
}) : super(type: AgUiEventType.textMessageEnd);
final String messageId;
final String answer;
final String role;
final String status;
final Map<String, dynamic>? uiSchema;
factory TextMessageEndEvent.fromJson(Map<String, dynamic> json) =>
TextMessageEndEvent(
@@ -177,7 +170,6 @@ class TextMessageEndEvent extends AgUiEvent {
answer: _asString(json['answer']),
role: _asString(json['role'], fallback: 'assistant'),
status: _asString(json['status'], fallback: 'success'),
uiSchema: _asMap(json['ui_schema']),
);
}
@@ -247,22 +239,6 @@ class ToolCallResultEvent extends AgUiEvent {
);
}
class ToolCallErrorEvent extends AgUiEvent {
ToolCallErrorEvent({required this.toolCallId, required this.error, this.code})
: super(type: AgUiEventType.toolCallError);
final String toolCallId;
final String error;
final String? code;
factory ToolCallErrorEvent.fromJson(Map<String, dynamic> json) =>
ToolCallErrorEvent(
toolCallId: _asString(json['toolCallId']),
error: _asString(json['error'], fallback: 'Tool call failed'),
code: json['code'] as String?,
);
}
class HistorySnapshot {
const HistorySnapshot({
required this.scope,
@@ -57,8 +57,6 @@ extension _ChatBlocEvents on ChatBloc {
_handleToolCallEnd(event as ToolCallEndEvent);
case AgUiEventType.toolCallResult:
_handleToolCallResult(event as ToolCallResultEvent);
case AgUiEventType.toolCallError:
_handleToolCallError(event as ToolCallErrorEvent);
case AgUiEventType.unknown:
break;
}
@@ -89,11 +87,6 @@ extension _ChatBlocEvents on ChatBloc {
timestamp,
);
final uiSchema = event.uiSchema;
if (uiSchema != null) {
_upsertUiSchema(items, event.messageId, uiSchema, timestamp);
}
emit(
state.copyWith(
items: _removeToolCallItems(items),
@@ -133,28 +126,6 @@ extension _ChatBlocEvents on ChatBloc {
return result;
}
void _upsertUiSchema(
List<ChatListItem> items,
String messageId,
Map<String, dynamic> uiSchema,
DateTime timestamp,
) {
final uiItemId = '$messageId-ui';
final uiItem = ToolResultItem(
id: uiItemId,
callId: messageId,
uiSchema: uiSchema,
timestamp: timestamp,
sender: MessageSender.ai,
);
final existingIndex = items.indexWhere((item) => item.id == uiItemId);
if (existingIndex >= 0) {
items[existingIndex] = uiItem;
return;
}
items.add(uiItem);
}
void _handleToolCallStart(ToolCallStartEvent event) {
final exists = state.items.any(
(item) => item is ToolCallItem && item.id == event.toolCallId,
@@ -248,22 +219,6 @@ extension _ChatBlocEvents on ChatBloc {
items.add(uiItem);
}
void _handleToolCallError(ToolCallErrorEvent event) {
emit(
state.copyWith(
items: state.items.map((item) {
if (item is ToolCallItem && item.id == event.toolCallId) {
return item.copyWith(
status: ToolCallStatus.error,
errorMessage: event.error,
);
}
return item;
}).toList(),
),
);
}
List<ChatListItem> _removeToolCallItems(List<ChatListItem> items) {
return items.where((item) => item is! ToolCallItem).toList();
}
@@ -419,7 +419,6 @@ void main() {
answer: 'hello',
role: 'assistant',
status: 'success',
uiSchema: null,
),
);