docs: 添加 AG-UI 协议规则约束到 apps/AGENTS.md

This commit is contained in:
qzl
2026-03-02 11:17:20 +08:00
parent 99d540a18d
commit 87b8727ca4
5 changed files with 279 additions and 1 deletions
@@ -61,6 +61,7 @@ const _typeToWireMap = {
AgUiEventType.toolCallEnd: AgUiEventTypeWire.toolCallEnd,
AgUiEventType.toolCallResult: AgUiEventTypeWire.toolCallResult,
AgUiEventType.toolCallError: AgUiEventTypeWire.toolCallError,
AgUiEventType.messagesSnapshot: AgUiEventTypeWire.messagesSnapshot,
AgUiEventType.unknown: '',
};
@@ -102,6 +103,8 @@ class AgUiEvent {
return ToolCallResultEvent.fromJson(json);
case AgUiEventType.toolCallError:
return ToolCallErrorEvent.fromJson(json);
case AgUiEventType.messagesSnapshot:
return MessagesSnapshotEvent.fromJson(json);
case AgUiEventType.unknown:
return UnknownAgUiEvent.fromJson(json);
}
@@ -297,3 +300,39 @@ class ToolCallErrorEvent extends AgUiEvent {
@override
Map<String, dynamic> toJson() => _$ToolCallErrorEventToJson(this);
}
@JsonSerializable()
class MessagesSnapshotEvent extends AgUiEvent {
final List<SnapshotMessage> messages;
MessagesSnapshotEvent({required this.messages})
: super(type: AgUiEventType.messagesSnapshot);
factory MessagesSnapshotEvent.fromJson(Map<String, dynamic> json) =>
_$MessagesSnapshotEventFromJson(json);
@override
Map<String, dynamic> toJson() => _$MessagesSnapshotEventToJson(this);
}
@JsonSerializable()
class SnapshotMessage {
final String id;
final String role;
final String? content;
final String? toolCallId;
final UiCard? ui;
SnapshotMessage({
required this.id,
required this.role,
this.content,
this.toolCallId,
this.ui,
});
factory SnapshotMessage.fromJson(Map<String, dynamic> json) =>
_$SnapshotMessageFromJson(json);
Map<String, dynamic> toJson() => _$SnapshotMessageToJson(this);
}