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

@moora/agent-service

v0.1.2

Published

Agent service implementation based on ElysiaJS

Readme

@moora/agent-service

基于 ElysiaJS 的 Agent Service 实现

概述

这个包提供了一个基于 ElysiaJS 的 Agent Service,包含三个主要路由:

  • GET /agent - SSE 接口,推送 PerspectiveOfUser 的变化
  • POST /send - 接收用户输入并驱动 Agent 状态机
  • GET /streams/:messageId - SSE 接口,推送流式消息的 chunk

功能特性

  • SSE 推送:通过 Server-Sent Events 实时推送 PerspectiveOfUser 的变化
  • RFC6902 Patch:使用 JSON Patch 格式高效传输状态变化
  • OpenAI 集成:自动调用 OpenAI API 生成 LLM 回复
  • ReAct Loop:支持工具调用的 ReAct 循环
  • 状态管理:基于 @moora/agent 的状态机实现

使用方法

import { createService } from '@moora/agent-service';

const app = createService({
  openai: {
    endpoint: {
      url: 'https://api.openai.com/v1',
      key: process.env.OPENAI_API_KEY!,
    },
    model: 'gpt-4',
  },
  prompt: 'You are a helpful assistant.',
  // Optional: Tavily API key for web search tool
  tavilyApiKey: process.env.TAVILY_API_KEY,
});

app.listen(3000);

架构

该服务使用 @moora/agent 的内置 reaction 工厂函数:

import {
  createAgent,
  createReaction,
  createUserReaction,
  createLlmReaction,
  createToolkitReaction,
} from '@moora/agent';

const reaction = createReaction({
  user: createUserReaction({
    notifyUser: (perspective) => {
      // 发送 RFC6902 patch 到客户端
    },
  }),
  llm: createLlmReaction({
    callLlm: async (context, callbacks) => {
      // 调用 OpenAI API
    },
  }),
  toolkit: createToolkitReaction({
    callTool: async (request) => {
      // 执行工具调用
    },
  }),
});

const agent = createAgent(reaction);

API

GET /agent

SSE 接口,连接时发送当前全量的 PerspectiveOfUser,之后通过 RFC6902 patch 推送变化。

响应格式

// 初始全量数据
{
  "type": "full",
  "data": {
    "userMessages": [...],
    "assiMessages": [...]
  }
}

// 后续 patch
{
  "type": "patch",
  "patches": [...]
}

POST /send

接收用户消息并驱动 Agent 状态机。

请求体

{
  "content": "Hello, world!"
}

响应

{
  "id": "message-id",
  "timestamp": 1234567890
}

GET /streams/:messageId

SSE 接口,订阅特定消息的流式内容。

响应格式

// 流式 chunk
{ "type": "chunk", "content": "Hello" }

// 流结束
{ "type": "end", "content": "Hello, how can I help you?" }

开发

# 安装依赖
bun install

# 运行测试
bun test