feat: 标准化 Agent AG-UI 与审批运行时
- 新增 AG-UI 事件投影与协议编码模块 - 支持 Turn 级审批作用域和受信任动态审批策略
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.easyagents.agui;
|
||||
|
||||
import io.agentscope.core.agui.AguiException;
|
||||
import io.agentscope.core.util.JsonException;
|
||||
import io.agentscope.core.util.JsonUtils;
|
||||
|
||||
/**
|
||||
* 将 AG-UI 事件编码为 JSON 或 SSE 数据帧。
|
||||
*
|
||||
* <p>编码器无可变状态,可安全跨请求复用。</p>
|
||||
*/
|
||||
public final class AguiProtocolEventEncoder {
|
||||
|
||||
/**
|
||||
* 编码为 JSON。
|
||||
*
|
||||
* @param event AG-UI 官方事件或补充标准事件
|
||||
* @return JSON 文本
|
||||
* @throws AguiException.EncodingException 序列化失败时抛出
|
||||
*/
|
||||
public String encodeToJson(Object event) {
|
||||
try {
|
||||
return JsonUtils.getJsonCodec().toJson(event);
|
||||
} catch (JsonException exception) {
|
||||
throw new AguiException.EncodingException("Failed to encode AG-UI event", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码为 SSE data 帧。
|
||||
*
|
||||
* @param event AG-UI 官方事件或补充标准事件
|
||||
* @return 完整 SSE data 帧
|
||||
* @throws AguiException.EncodingException 序列化失败时抛出
|
||||
*/
|
||||
public String encode(Object event) {
|
||||
return "data: " + encodeToJson(event) + "\n\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user