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

@shuttle-ai/render-react

v0.0.17

Published

Shuttle AI web端智能体react渲染库

Readme

@shuttle-ai/render-react

Shuttle AI Web 端智能体 React 渲染库,提供完整的智能体对话界面组件和 Hooks(仅在浏览器环境运行)。

安装

npm install @shuttle-ai/render-react

核心功能

  • 智能体工作流渲染 - 完整的对话界面组件,支持用户消息、AI 消息、工具调用等
  • Context Provider - 提供智能体工作的上下文环境
  • Hooks API - 灵活的 hooks 用于获取状态和消息
  • Markdown 渲染 - 支持 GFM 的 Markdown 渲染组件
  • 工具渲染组件 - 内置工具的渲染组件(如待办事项)

组件

AgentWorkProvider

智能体工作流的 Provider 组件,用于包裹整个应用并提供上下文环境。

import { AgentWorkProvider } from '@shuttle-ai/render-react'

function App() {
  return (
    <AgentWorkProvider context={{} as any} agentId="your-agent-id">
      <YourApp />
    </AgentWorkProvider>
  )
}

AgentWorkRender

智能体工作流的主渲染组件,包含完整的对话界面(消息列表 + 输入区域)。

import { AgentWorkProvider, AgentWorkRender } from '@shuttle-ai/render-react'

function App() {
  return (
    <AgentWorkProvider context={{} as any} agentId="your-agent-id">
      <div style={{ height: '500px' }}>
        <AgentWorkRender />
      </div>
    </AgentWorkProvider>
  )
}

MarkdownRender

Markdown 渲染组件,支持 GFM (GitHub Flavored Markdown)。

import { MarkdownRender } from '@shuttle-ai/render-react'

function MyComponent() {
  const markdown = `
# 标题

- 列表项 1
- 列表项 2

**粗体** 和 *斜体*

[链接](https://example.com)
  `

  return <MarkdownRender>{markdown}</MarkdownRender>
}

Hooks

useWorkStatus

获取智能体工作状态。

import { useWorkStatus, useWork } from '@shuttle-ai/render-react'

function MyComponent() {
  const work = useWork()
  const status = useWorkStatus(work)

  console.log('当前状态:', status)
  // 返回值: 'idle' | 'running' | 'stopped'
}

useRootAgent

获取根 Agent 实例。

import { useRootAgent, useWork } from '@shuttle-ai/render-react'

function MyComponent() {
  const work = useWork()
  const rootAgent = useRootAgent(work)

  if (rootAgent) {
    console.log('根 Agent:', rootAgent.name)
  }
}

useAgentMessages

获取指定 Agent 的消息列表。

import {
  useAgentMessages,
  useRootAgent,
  useWork,
} from '@shuttle-ai/render-react'

function MessageList() {
  const work = useWork()
  const rootAgent = useRootAgent(work)
  const messages = useAgentMessages(rootAgent!)

  return (
    <div>
      {messages.map((msg) => (
        <div key={msg.id}>
          {msg.role}: {msg.content}
        </div>
      ))}
    </div>
  )
}

useAgentStatus

获取 Agent 状态。

import { useAgentStatus, useRootAgent, useWork } from '@shuttle-ai/render-react'

function StatusIndicator() {
  const work = useWork()
  const rootAgent = useRootAgent(work)
  const status = useAgentStatus(rootAgent!)

  console.log('Agent 状态:', status)
  // 返回值: 'idle' | 'running' | 'waitRevoke' | 'waitConfirm' | 'waitInput'
}

useWorkAutoRunScope

获取或设置工具自动执行范围。

import { useWorkAutoRunScope, useWork } from '@shuttle-ai/render-react'

function AutoRunControl() {
  const work = useWork()
  const scope = useWorkAutoRunScope(work)

  const handleChange = (value: 'always' | 'read' | 'none') => {
    work.setAutoRunScope(value)
  }
}

完整示例

import React from 'react'
import { AgentWorkProvider, AgentWorkRender } from '@shuttle-ai/render-react'

export default function ChatApp() {
  return (
    <AgentWorkProvider context={{} as any} agentId="your-agent-id">
      <div style={{ height: '600px', width: '100%' }}>
        <AgentWorkRender />
      </div>
    </AgentWorkProvider>
  )
}

导出概览

// 组件
export { AgentWorkProvider } from './context'
export { AgentWorkRender } from './agentWork'
export { MarkdownRender } from './markdownRender'

// 渲染组件
export { AiMessageRender } from './agentWork'
export { UserMessageRender } from './agentWork'
export { ToolRender } from './agentWork'
export { ToolConfirmRender } from './agentWork'
export { CatchResultError } from './agentWork'

// Hooks
export { useWork } from './context'
export { useWorkStatus } from './hooks'
export { useWorkAutoRunScope } from './hooks'
export { useRootAgent } from './hooks'
export { useAgentMessages } from './hooks'
export { useAgentStatus } from './hooks'
export { useToolMessage } from './hooks'
export { useAiMessage } from './hooks'

// 工具渲染
export { writeTodosTool } from './tools'

依赖

  • @shuttle-ai/type: Shuttle AI 类型定义
  • @shuttle-ai/client: Shuttle AI 客户端
  • zod: 数据验证库