44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
package com.easyagents.agui;
|
|
|
|
import io.agentscope.core.agui.event.AguiEvent;
|
|
import io.agentscope.core.agui.model.AguiMessage;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* {@link AguiProtocolEventEncoder} 的线级协议测试。
|
|
*/
|
|
public class AguiProtocolEventEncoderTest {
|
|
|
|
private final AguiProtocolEventEncoder encoder = new AguiProtocolEventEncoder();
|
|
|
|
/**
|
|
* 验证 AgentScope 官方事件保留 AG-UI type 字段。
|
|
*/
|
|
@Test
|
|
public void shouldEncodeOfficialEvent() {
|
|
String json = encoder.encodeToJson(new AguiEvent.RunStarted("thread-1", "run-1"));
|
|
|
|
Assert.assertTrue(json.contains("\"type\":\"RUN_STARTED\""));
|
|
Assert.assertTrue(json.contains("\"threadId\":\"thread-1\""));
|
|
}
|
|
|
|
/**
|
|
* 验证补充的失败和消息快照事件使用现代 AG-UI 标准事件名。
|
|
*/
|
|
@Test
|
|
public void shouldEncodeExtendedStandardEvents() {
|
|
String error = encoder.encodeToJson(
|
|
new AguiExtendedEvent.RunError("thread-1", "run-1", "boom", "FAILED"));
|
|
String snapshot = encoder.encodeToJson(new AguiExtendedEvent.MessagesSnapshot(
|
|
"thread-1", "run-1", List.of(AguiMessage.userMessage("message-1", "hello"))));
|
|
|
|
Assert.assertTrue(error.contains("\"type\":\"RUN_ERROR\""));
|
|
Assert.assertTrue(error.contains("\"code\":\"FAILED\""));
|
|
Assert.assertTrue(snapshot.contains("\"type\":\"MESSAGES_SNAPSHOT\""));
|
|
Assert.assertTrue(snapshot.contains("\"role\":\"user\""));
|
|
}
|
|
}
|