refactor: unify skills+cli runtime and streamline ag-ui flow
This commit is contained in:
@@ -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