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-assistant-sdk

v1.0.0

Published

坐席辅助SDK - 提供音频协商和SSE连接功能

Readme

坐席辅助SDK (Agent Assistant SDK)

一个用于坐席辅助功能的JavaScript SDK,支持音频协商和SSE连接功能。

功能特性

  • 音频协商 API
  • SSE (Server-Sent Events) 连接
  • 自动认证头生成
  • 模块化设计,支持多种环境

安装

npm install @xinyao/agent-assistant-sdk
# 或
pnpm add @xinyao/agent-assistant-sdk

使用方法

ES6 模块

import AgentAssistantSDK from '@xinyao/agent-assistant-sdk';

const vm = new AgentAssistantSDK({
  // 配置项...
});

CommonJS

// 在支持ES模块的环境中(当package.json包含"type": "module"时)
import AgentAssistantSDK from '@xinyao/agent-assistant-sdk/dist/agent-assistant-sdk.js';

// 或者使用动态导入
const { default: AgentAssistantSDK } = await import('@xinyao/agent-assistant-sdk/dist/agent-assistant-sdk.js');
import AgentAssistantSDK from '@xinyao/agent-assistant-sdk';

const vm = new AgentAssistantSDK({
  url: 'https://dev.xinyaoai.com',
  app_key: 'your_app_key',
  app_secret: 'your_app_secret',
  onMessage: (data) => {
    console.log('服务器消息', data.data || data);
  },
  onError: (error) => {
    console.log('SSE连接错误:', error.message || error);
  },
  onOpen: () => {
    console.log('SSE连接已建立');
  },
  onAudioData: (audioData) => {
    console.log('收到音频数据:', audioData);
  }
});

CommonJS

const AgentAssistantSDK = require('@xinyao/agent-assistant-sdk');

const vm = new AgentAssistantSDK({
  // 配置项...
});

浏览器中使用

<script src="https://unpkg.com/@xinyao/agent-assistant-sdk/dist/agent-assistant-sdk.umd.js"></script>
<script>
  const vm = new AgentAssistantSDK({
    // 配置项...
  });
</script>

注意:在UMD构建中,构造函数直接导出为AgentAssistantSDK,不需要使用.default属性。

API

构造函数选项

  • url: API服务器地址
  • app_key: 应用密钥
  • app_secret: 应用密钥
  • onMessage: 服务器消息回调
  • onError: 错误回调
  • onOpen: 连接建立回调
  • onAudioData: 音频数据回调
  • onAudioNegotiationSuccess: 音频协商成功回调
  • onConnectSSE: 连接SSE回调

方法

post(endpoint, data)

通用POST请求方法,可用于向指定端点发送数据。

参数:

  • endpoint (string): API端点路径
  • data (object): 要发送的数据

audioNegotiation(data)

执行音频协商请求(内部使用post方法)。

connectSSEWithNegotiationResult()

根据音频协商结果连接SSE。此方法需要在音频协商成功后手动调用,会使用协商结果中的sse_addr和client_id来建立SSE连接。

connectSSEWithURL(sseUrl)

使用指定URL连接SSE(辅助方法)。

参数:

  • sseUrl (string): SSE连接的完整URL

参数:

  • data (object):
    • app_id (string, required): 租户ID
    • audio_format (string, required): 音频格式
    • audio_sample (string, required): 音频采样率 (8k/16k)
    • user_agent (string, required): 客户端标识

connectSSE()

建立SSE连接。注意:SDK会自动在请求头中添加认证信息。

disconnectSSE()

断开SSE连接。

认证

SDK会自动在每个请求中添加认证头,格式为: Authorization: {app_key}:{timestamp}:{md5(app_secret:timestamp)}

开发

# 安装依赖
pnpm install

# 构建
pnpm run build

# 开发模式(监听文件变化)
pnpm run dev

# 运行测试
pnpm run test

项目使用 Vite 进行构建,支持多格式输出 (ESM, CJS, UMD)。

发布到npm

npm publish