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-server-fastify

v0.1.0

Published

Fastify adapter for agent-remote.

Readme

agent-remote-server-fastify

语言:English | 简体中文

agent-remote-server-fastify 提供 Fastify plugin,用于注册 Agent Remote 的 SSE 和 HTTP POST 路由。

安装

npm install agent-remote-server-fastify agent-remote-server-core fastify

fastify 是 peer dependency,要求 fastify >=4.0.0

基础用法

import Fastify from "fastify";
import { AgentEngine, InMemoryStore, LocalBroker, SessionManager } from "agent-remote-server-core";
import { createFastifyAgentPlugin } from "agent-remote-server-fastify";

const fastify = Fastify();
const sessionManager = new SessionManager(new InMemoryStore(), new LocalBroker());
const engine = new AgentEngine({
  llmClient,
  sessionManager
});

await fastify.register(createFastifyAgentPlugin(engine, {
  heartbeatIntervalMs: 30_000
}));

await fastify.listen({ port: 3000 });

默认路由

  • GET /sse?session_id=<id>: 建立 SSE 连接。
  • POST /api/register_tools: 注册浏览器工具。
  • POST /api/chat: 发送用户消息。
  • POST /api/tool_result: 返回工具执行结果。

自定义路由

await fastify.register(createFastifyAgentPlugin(engine, {
  routes: {
    sse: "/agent/sse",
    registerTools: "/agent/register-tools",
    chat: "/agent/chat",
    toolResult: "/agent/tool-result"
  }
}));

浏览器端 SSE client 的 URL 配置需要与自定义路由一致。

会话认证

await fastify.register(createFastifyAgentPlugin(engine, {
  sessionAuth: {
    async verifySession({ sessionId, token }) {
      return sessionId.length > 0 && token === process.env.AGENT_REMOTE_SESSION_TOKEN;
    }
  }
}));

token 可以来自:

  • Authorization: Bearer <token>
  • 查询参数 tokensession_token
  • 请求体 sessionTokensession_token

配置项

  • routes: 覆盖默认路由。
  • sessionAuth: 在 SSE 和 POST 请求前验证 session。
  • heartbeatIntervalMs: SSE heartbeat 间隔,默认 30_000

请求要求

  • SSE 请求必须提供 session_idsessionId 查询参数。
  • POST body 必须是 JSON object,并包含 sessionIdsession_id
  • Fastify reply 需要可访问 reply.raw,因为 SSE 使用底层 raw stream。
  • 如果 engine 没有 sessionManager,SSE 路由会返回 501

注意事项

  • plugin 会在 SSE 响应中调用 reply.hijack?.()
  • 客户端断开时 plugin 会清理 heartbeat 并 detach transport。
  • route handler 会把已知请求错误转换为 JSON 错误响应。