chore: clean up legacy tool/UI code paths and remove unused events
This commit is contained in:
@@ -9,7 +9,6 @@ class AgUiEventTypeWire {
|
|||||||
static const toolCallArgs = 'TOOL_CALL_ARGS';
|
static const toolCallArgs = 'TOOL_CALL_ARGS';
|
||||||
static const toolCallEnd = 'TOOL_CALL_END';
|
static const toolCallEnd = 'TOOL_CALL_END';
|
||||||
static const toolCallResult = 'TOOL_CALL_RESULT';
|
static const toolCallResult = 'TOOL_CALL_RESULT';
|
||||||
static const toolCallError = 'TOOL_CALL_ERROR';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AgUiEventType {
|
enum AgUiEventType {
|
||||||
@@ -23,7 +22,6 @@ enum AgUiEventType {
|
|||||||
toolCallArgs,
|
toolCallArgs,
|
||||||
toolCallEnd,
|
toolCallEnd,
|
||||||
toolCallResult,
|
toolCallResult,
|
||||||
toolCallError,
|
|
||||||
unknown,
|
unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +36,6 @@ const _wireToTypeMap = {
|
|||||||
AgUiEventTypeWire.toolCallArgs: AgUiEventType.toolCallArgs,
|
AgUiEventTypeWire.toolCallArgs: AgUiEventType.toolCallArgs,
|
||||||
AgUiEventTypeWire.toolCallEnd: AgUiEventType.toolCallEnd,
|
AgUiEventTypeWire.toolCallEnd: AgUiEventType.toolCallEnd,
|
||||||
AgUiEventTypeWire.toolCallResult: AgUiEventType.toolCallResult,
|
AgUiEventTypeWire.toolCallResult: AgUiEventType.toolCallResult,
|
||||||
AgUiEventTypeWire.toolCallError: AgUiEventType.toolCallError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const _typeToWireMap = {
|
const _typeToWireMap = {
|
||||||
@@ -52,7 +49,6 @@ const _typeToWireMap = {
|
|||||||
AgUiEventType.toolCallArgs: AgUiEventTypeWire.toolCallArgs,
|
AgUiEventType.toolCallArgs: AgUiEventTypeWire.toolCallArgs,
|
||||||
AgUiEventType.toolCallEnd: AgUiEventTypeWire.toolCallEnd,
|
AgUiEventType.toolCallEnd: AgUiEventTypeWire.toolCallEnd,
|
||||||
AgUiEventType.toolCallResult: AgUiEventTypeWire.toolCallResult,
|
AgUiEventType.toolCallResult: AgUiEventTypeWire.toolCallResult,
|
||||||
AgUiEventType.toolCallError: AgUiEventTypeWire.toolCallError,
|
|
||||||
AgUiEventType.unknown: '',
|
AgUiEventType.unknown: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,7 +78,6 @@ abstract class AgUiEvent {
|
|||||||
AgUiEventType.toolCallArgs => ToolCallArgsEvent.fromJson(json),
|
AgUiEventType.toolCallArgs => ToolCallArgsEvent.fromJson(json),
|
||||||
AgUiEventType.toolCallEnd => ToolCallEndEvent.fromJson(json),
|
AgUiEventType.toolCallEnd => ToolCallEndEvent.fromJson(json),
|
||||||
AgUiEventType.toolCallResult => ToolCallResultEvent.fromJson(json),
|
AgUiEventType.toolCallResult => ToolCallResultEvent.fromJson(json),
|
||||||
AgUiEventType.toolCallError => ToolCallErrorEvent.fromJson(json),
|
|
||||||
AgUiEventType.unknown => UnknownAgUiEvent(rawJson: json),
|
AgUiEventType.unknown => UnknownAgUiEvent(rawJson: json),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -162,14 +157,12 @@ class TextMessageEndEvent extends AgUiEvent {
|
|||||||
required this.answer,
|
required this.answer,
|
||||||
required this.role,
|
required this.role,
|
||||||
required this.status,
|
required this.status,
|
||||||
required this.uiSchema,
|
|
||||||
}) : super(type: AgUiEventType.textMessageEnd);
|
}) : super(type: AgUiEventType.textMessageEnd);
|
||||||
|
|
||||||
final String messageId;
|
final String messageId;
|
||||||
final String answer;
|
final String answer;
|
||||||
final String role;
|
final String role;
|
||||||
final String status;
|
final String status;
|
||||||
final Map<String, dynamic>? uiSchema;
|
|
||||||
|
|
||||||
factory TextMessageEndEvent.fromJson(Map<String, dynamic> json) =>
|
factory TextMessageEndEvent.fromJson(Map<String, dynamic> json) =>
|
||||||
TextMessageEndEvent(
|
TextMessageEndEvent(
|
||||||
@@ -177,7 +170,6 @@ class TextMessageEndEvent extends AgUiEvent {
|
|||||||
answer: _asString(json['answer']),
|
answer: _asString(json['answer']),
|
||||||
role: _asString(json['role'], fallback: 'assistant'),
|
role: _asString(json['role'], fallback: 'assistant'),
|
||||||
status: _asString(json['status'], fallback: 'success'),
|
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 {
|
class HistorySnapshot {
|
||||||
const HistorySnapshot({
|
const HistorySnapshot({
|
||||||
required this.scope,
|
required this.scope,
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ extension _ChatBlocEvents on ChatBloc {
|
|||||||
_handleToolCallEnd(event as ToolCallEndEvent);
|
_handleToolCallEnd(event as ToolCallEndEvent);
|
||||||
case AgUiEventType.toolCallResult:
|
case AgUiEventType.toolCallResult:
|
||||||
_handleToolCallResult(event as ToolCallResultEvent);
|
_handleToolCallResult(event as ToolCallResultEvent);
|
||||||
case AgUiEventType.toolCallError:
|
|
||||||
_handleToolCallError(event as ToolCallErrorEvent);
|
|
||||||
case AgUiEventType.unknown:
|
case AgUiEventType.unknown:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -89,11 +87,6 @@ extension _ChatBlocEvents on ChatBloc {
|
|||||||
timestamp,
|
timestamp,
|
||||||
);
|
);
|
||||||
|
|
||||||
final uiSchema = event.uiSchema;
|
|
||||||
if (uiSchema != null) {
|
|
||||||
_upsertUiSchema(items, event.messageId, uiSchema, timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
items: _removeToolCallItems(items),
|
items: _removeToolCallItems(items),
|
||||||
@@ -133,28 +126,6 @@ extension _ChatBlocEvents on ChatBloc {
|
|||||||
return result;
|
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) {
|
void _handleToolCallStart(ToolCallStartEvent event) {
|
||||||
final exists = state.items.any(
|
final exists = state.items.any(
|
||||||
(item) => item is ToolCallItem && item.id == event.toolCallId,
|
(item) => item is ToolCallItem && item.id == event.toolCallId,
|
||||||
@@ -248,22 +219,6 @@ extension _ChatBlocEvents on ChatBloc {
|
|||||||
items.add(uiItem);
|
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) {
|
List<ChatListItem> _removeToolCallItems(List<ChatListItem> items) {
|
||||||
return items.where((item) => item is! ToolCallItem).toList();
|
return items.where((item) => item is! ToolCallItem).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -419,7 +419,6 @@ void main() {
|
|||||||
answer: 'hello',
|
answer: 'hello',
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
status: 'success',
|
status: 'success',
|
||||||
uiSchema: null,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from ag_ui.core import (
|
from ag_ui.core import (
|
||||||
BaseEvent,
|
BaseEvent,
|
||||||
@@ -14,9 +14,6 @@ from ag_ui.core import (
|
|||||||
from core.agentscope.runtime.ui_compiler import compile as compile_ui_hints
|
from core.agentscope.runtime.ui_compiler import compile as compile_ui_hints
|
||||||
from schemas.agent.ui_hints import UiHintsPayload
|
from schemas.agent.ui_hints import UiHintsPayload
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
pass
|
|
||||||
|
|
||||||
_INTERNAL_TO_AGUI: dict[str, EventType] = {
|
_INTERNAL_TO_AGUI: dict[str, EventType] = {
|
||||||
"run.started": EventType.RUN_STARTED,
|
"run.started": EventType.RUN_STARTED,
|
||||||
"run.finished": EventType.RUN_FINISHED,
|
"run.finished": EventType.RUN_FINISHED,
|
||||||
|
|||||||
@@ -165,10 +165,6 @@ class SqlAlchemyEventStore:
|
|||||||
if not isinstance(role_value, str):
|
if not isinstance(role_value, str):
|
||||||
role_value = "assistant"
|
role_value = "assistant"
|
||||||
role = self._resolve_role(role_value)
|
role = self._resolve_role(role_value)
|
||||||
tool_name = self._event_value(event, "tool_name")
|
|
||||||
tool_name_value = (
|
|
||||||
tool_name if isinstance(tool_name, str) and tool_name else None
|
|
||||||
)
|
|
||||||
|
|
||||||
locked_session = await session_repo.lock_session_for_update(
|
locked_session = await session_repo.lock_session_for_update(
|
||||||
session_id=session_id
|
session_id=session_id
|
||||||
@@ -185,7 +181,6 @@ class SqlAlchemyEventStore:
|
|||||||
role=role,
|
role=role,
|
||||||
content=content,
|
content=content,
|
||||||
model_code=model_code if isinstance(model_code, str) else None,
|
model_code=model_code if isinstance(model_code, str) else None,
|
||||||
tool_name=tool_name_value,
|
|
||||||
metadata=metadata_model.model_dump(mode="json", exclude_none=True),
|
metadata=metadata_model.model_dump(mode="json", exclude_none=True),
|
||||||
input_tokens=input_tokens,
|
input_tokens=input_tokens,
|
||||||
output_tokens=output_tokens,
|
output_tokens=output_tokens,
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ class PipelineStageEmitter:
|
|||||||
self._emitted_tool_calls: set[str] = set()
|
self._emitted_tool_calls: set[str] = set()
|
||||||
self._emitted_tool_results: set[str] = set()
|
self._emitted_tool_results: set[str] = set()
|
||||||
self.latest_text_message_id: str | None = None
|
self.latest_text_message_id: str | None = None
|
||||||
self.latest_text: str = ""
|
|
||||||
|
|
||||||
async def handle_print(self, *, msg: Msg, last: bool) -> None:
|
async def handle_print(self, *, msg: Msg, last: bool) -> None:
|
||||||
del last
|
del last
|
||||||
@@ -72,7 +71,6 @@ class PipelineStageEmitter:
|
|||||||
if not text:
|
if not text:
|
||||||
return
|
return
|
||||||
self.latest_text_message_id = str(msg.id)
|
self.latest_text_message_id = str(msg.id)
|
||||||
self.latest_text = text
|
|
||||||
|
|
||||||
async def _emit_tool_events_from_msg(self, msg: Msg) -> None:
|
async def _emit_tool_events_from_msg(self, msg: Msg) -> None:
|
||||||
for block in msg.get_content_blocks("tool_use"):
|
for block in msg.get_content_blocks("tool_use"):
|
||||||
|
|||||||
@@ -71,14 +71,3 @@ def build_toolkit(
|
|||||||
register_tool_middlewares(toolkit=toolkit)
|
register_tool_middlewares(toolkit=toolkit)
|
||||||
|
|
||||||
return toolkit
|
return toolkit
|
||||||
|
|
||||||
|
|
||||||
def build_stage_toolkit(
|
|
||||||
*,
|
|
||||||
enabled_skill_names: set[str] | None = None,
|
|
||||||
enable_hitl: bool | None = None,
|
|
||||||
) -> Any:
|
|
||||||
return build_toolkit(
|
|
||||||
enabled_skill_names=enabled_skill_names,
|
|
||||||
enable_hitl=enable_hitl,
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user