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

@opentiny/tiny-robot-kit

v0.5.0

Published

AI大模型请求与数据处理工具包

Readme

tiny-robot-kit

@opentiny/tiny-robot-kit 是 TinyRobot 提供的数据层工具包,用于统一处理 AI 大模型调用、消息状态与多会话管理。 它帮助你在任意 UI 上快速实现聊天、流式响应和会话持久化等常见 AI 交互能力。

功能概览

  • 消息管理useMessage 管理消息状态与模型交互流程。
  • 会话管理useConversation 在 useMessage 之上提供多会话能力。
  • 工具函数(Utils):处理 SSE、消息格式与响应解析。

完整 API 请参考文档:

安装

pnpm add @opentiny/tiny-robot-kit
# 或
npm install @opentiny/tiny-robot-kit
yarn add @opentiny/tiny-robot-kit

基本用法

useMessage —— 管理 AI 消息

useMessage 管理消息列表、请求/处理状态、流式响应、插件体系以及工具调用逻辑,而真正的 HTTP 请求由你提供的 responseProvider 负责。

import { useMessage } from '@opentiny/tiny-robot-kit'

const message = useMessage({
  // responseProvider 负责调用你的后端 / 模型接口
  async responseProvider(requestBody, abortSignal) {
    const res = await fetch('/api/chat', {
      method: 'POST',
      body: JSON.stringify(requestBody),
      signal: abortSignal,
      headers: { 'Content-Type': 'application/json' },
    })

    return await res.json()
  },
})

更多进阶用法(流式响应、插件、自定义分块(chunk)处理、工具调用等),请查看 https://docs.opentiny.design/tiny-robot/tools/message

useConversation —— 管理多会话

useConversation 基于 useMessage 之上,提供多会话管理能力,并支持多种存储策略(LocalStorage、IndexedDB、自定义等)。

import { useConversation } from '@opentiny/tiny-robot-kit'

const { conversations, activeConversation, createConversation, switchConversation } = useConversation({
  useMessageOptions: {
    async responseProvider(requestBody, abortSignal) {
      const res = await fetch('/api/chat', {
        method: 'POST',
        body: JSON.stringify(requestBody),
        signal: abortSignal,
        headers: { 'Content-Type': 'application/json' },
      })
      return await res.json()
    },
  },
})

例如 localStorageStrategyFactoryindexedDBStorageStrategyFactory 等存储策略的详细用法,请参考 https://docs.opentiny.design/tiny-robot/tools/conversation

工具函数 Utils —— 处理 SSE 与响应

Utils 模块提供了一些与 useMessage 搭配使用的常用工具函数:

  • sseStreamToGenerator:把 SSE Response 转换为异步生成器。
  • formatMessages:将多种形式的消息统一为 ChatMessage[]
  • extractTextFromResponse:从大模型响应中提取纯文本内容。
  • handleSSEStream:通过回调方式消费 SSE 流式响应。

详细函数签名与行为说明,请查看 https://docs.opentiny.design/tiny-robot/tools/utils