npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

agent-remote-transport-sse

v0.1.0

Published

SSE and HTTP transport package for agent-remote.

Readme

agent-remote-transport-sse

语言:English | 简体中文

agent-remote-transport-sse 提供浏览器端 SSE transport:服务端到客户端的消息通过 SSE 到达,客户端到服务端的消息通过 HTTP POST 发送。

安装

npm install agent-remote-transport-sse agent-remote-core

通常你会通过 agent-remote-client/sse 使用它,而不是直接创建 transport。

基础用法

import { createSseTransport } from "agent-remote-transport-sse";

const transport = createSseTransport({
  kind: "sse",
  sseUrl: "/sse",
  sessionId: "session-1",
  retryAttempts: 1,
  postUrls: {
    registerTools: "/api/register_tools",
    sendMessage: "/api/chat",
    toolResult: "/api/tool_result"
  }
});

transport.onMessage((message) => {
  console.log("Agent Remote message:", message);
});

配置

  • kind: 固定为 "sse"
  • sseUrl: SSE endpoint,例如 /sse
  • sessionId: 当前浏览器会话 ID。
  • retryAttempts: POST 失败后的重试次数,默认 0
  • postUrls.registerTools: 发送 agent_remote:register_tools 的 POST URL。
  • postUrls.sendMessage: 发送 agent_remote:user_message 的 POST URL。
  • postUrls.toolResult: 发送 agent_remote:tool_result 的 POST URL。

createSseTransportConfig 会检查 sseUrlsessionId 和三个 POST URL 是否存在。

发送行为

SSE 是单向下行通道,因此只有以下消息可以通过 send() 转成 POST 请求:

  • agent_remote:register_tools: body 为 { sessionId, tools }
  • agent_remote:user_message: body 为 { sessionId, text, messageId? }
  • agent_remote:tool_result: body 为 { sessionId, result }

其他消息类型调用 send() 会抛出错误。

接收行为

transport 会为 PROTOCOL_MESSAGE_TYPES 中的每个消息类型注册 SSE event listener。收到事件后会解析 JSON,并用 validateProtocolMessage 校验。

依赖注入

const transport = createSseTransport(config, {
  createEventSource(url) {
    return new EventSource(url);
  },
  fetch(url, init) {
    return fetch(url, init);
  },
  onProtocolDrop(event) {
    console.warn("Dropped protocol payload", event);
  }
});
  • createEventSource: 自定义 EventSource 创建函数,常用于测试。
  • fetch: 自定义 fetch 实现。
  • onProtocolDrop: malformed JSON 或无效协议消息回调。

注意事项

  • transport 会把 sessionId 自动追加到 SSE URL 的 session_id 查询参数。
  • 服务端默认路由通常是 /sse/api/register_tools/api/chat/api/tool_result
  • 浏览器环境需要 EventSourcefetch