refactor: unify skills+cli runtime and streamline ag-ui flow
This commit is contained in:
@@ -226,6 +226,7 @@ class ToolCallResultEvent extends AgUiEvent {
|
||||
required this.toolName,
|
||||
required this.resultSummary,
|
||||
required this.status,
|
||||
required this.uiSchema,
|
||||
}) : super(type: AgUiEventType.toolCallResult);
|
||||
|
||||
final String messageId;
|
||||
@@ -233,6 +234,7 @@ class ToolCallResultEvent extends AgUiEvent {
|
||||
final String toolName;
|
||||
final String resultSummary;
|
||||
final String status;
|
||||
final Map<String, dynamic>? uiSchema;
|
||||
|
||||
factory ToolCallResultEvent.fromJson(Map<String, dynamic> json) =>
|
||||
ToolCallResultEvent(
|
||||
@@ -241,6 +243,7 @@ class ToolCallResultEvent extends AgUiEvent {
|
||||
toolName: _asString(json['tool_name']),
|
||||
resultSummary: _asString(json['result']),
|
||||
status: _asString(json['status'], fallback: 'success'),
|
||||
uiSchema: _asMap(json['ui_schema']),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -210,16 +210,42 @@ extension _ChatBlocEvents on ChatBloc {
|
||||
if (_shouldRefreshCalendarForTool(event)) {
|
||||
unawaited(_refreshCalendarAfterToolMutation());
|
||||
}
|
||||
emit(
|
||||
state.copyWith(
|
||||
items: state.items.map((item) {
|
||||
if (item is ToolCallItem && item.id == event.toolCallId) {
|
||||
return item.copyWith(status: ToolCallStatus.completed);
|
||||
}
|
||||
return item;
|
||||
}).toList(),
|
||||
),
|
||||
final timestamp = DateTime.now();
|
||||
final items = state.items.map((item) {
|
||||
if (item is ToolCallItem && item.id == event.toolCallId) {
|
||||
return item.copyWith(status: ToolCallStatus.completed);
|
||||
}
|
||||
return item;
|
||||
}).toList();
|
||||
|
||||
final uiSchema = event.uiSchema;
|
||||
if (uiSchema != null) {
|
||||
_upsertToolResultUi(items, event.toolCallId, uiSchema, timestamp);
|
||||
}
|
||||
|
||||
emit(state.copyWith(items: items));
|
||||
}
|
||||
|
||||
void _upsertToolResultUi(
|
||||
List<ChatListItem> items,
|
||||
String toolCallId,
|
||||
Map<String, dynamic> uiSchema,
|
||||
DateTime timestamp,
|
||||
) {
|
||||
final uiItemId = '$toolCallId-ui';
|
||||
final uiItem = ToolResultItem(
|
||||
id: uiItemId,
|
||||
callId: toolCallId,
|
||||
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 _handleToolCallError(ToolCallErrorEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user