@ agentplat/ 流线
用于规范化的服务器- 事件助手 AgentStreamEvent 流经. 这个
软件包取决于Web 标准和小结构节点响应类型; 它
不依赖于 Next.js, Express 或者Hono.
安装( 开发者预览)
明确安装协调预览 :
npm install @agentplat/streaming@next
全部留着 @agentplat/* 软件包在同一版本中。 npm 的默认
latest 标记可以指向更古老的预览。 见
释放通道
用于发行状态和版本选择.
Next.js App路由器
import { toNextSseResponse } from "@agentplat/streaming";
return toNextSseResponse(request, (signal) =>
session.stream({ input: scenario, signal }),
);
网页 Response (霍诺和其他与获取兼容的框架)
import { streamToSSE } from "@agentplat/streaming";
return streamToSSE(runtime.stream(agent, input, context), {
signal: request.signal,
});
快速响应
import { pipeSSE } from "@agentplat/streaming";
await pipeSSE(runtime.stream(agent, input, context), response);
浏览器解析器
import type { MultiAgentSessionEvent } from "@agentplat/framework";
import { parseAgentSseStream } from "@agentplat/streaming";
for await (const envelope of parseAgentSseStream<MultiAgentSessionEvent>(
response.body,
{ signal },
)) {
// Envelope v1 is parsed and its sequence is validated.
}
接线信封为版本并包含单音序号. 这样做 不在运行时流事件有效载荷中发送证书或秘密.
对于回调式的 UI 集成, 使用 subscribeAgentSse(response, { onEvent, onError, signal })。它使用相同的解析器并重投错误或失败
引用后流出 onError。 。 。 .