# @dust-tt/client 中文文档

规范地址：https://npmcn.com/package/%40dust-tt/client/

版本：1\.2\.10
npm 元数据更新时间：2026-11-12T16:45:14.179Z
中文译文更新时间：2026-11-13T00:46:13.984Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40dust-tt/client
原文对照：https://npmcn.com/package/%40dust-tt/client/?lang=original
项目主页：https://github.com/dust-tt/dust-sdk-js
源码仓库：https://github.com/dust-tt/dust

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：10.5 MB，75 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=24\.16\.0
- 运行依赖：5 个
- 首次发布：2024-11-07T08:41:07.410Z
- 最新版本发布：2026-11-12T16:45:13.717Z
- 近 30 天下载量：116871（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：90（近 12 个月 15 个）

## 中文简介

灰尘 API 客户端

## 安装

```sh
npm install @dust-tt/client
```

也可以使用：`pnpm add @dust-tt/client`、`yarn add @dust-tt/client`、`bun add @dust-tt/client`

## README

# JavaScript 的灰尘 SDK

**简单易用客户端 [灰尘 API](https://docs.dust.tt/reference/developer-platform-overview)**

  

![Build status](https://github.com/dust-tt/dust/actions/workflows/deploy-front.yml/badge.svg) [![npm version](https://badge.fury.io/js/%40dust%2Fclient.svg)](https://www.npmjs.com/package/@dust-tt/client)

可用源代码 [这里](https://github.com/dust-tt/dust/tree/main/sdks/js)。 。 。 .

## 安装

```js
npm install @dust-tt/client
```

## 使用量

> 使用灰尘 [尘埃发展平台](https://docs.dust.tt/reference/developer-platform-overview) 开始学习尘埃API.

使用一个 **工作空间 api 密钥** 或 OAuth 证书 **访问令牌** (目前需要和我们谈谈).

注意: 我们使用“结果”模式处理出错( E)[看见更多](https://velocidadescape.com/js/result-pattern-try-catch/)) (中文(简体) ).

### 设置

```js
import { DustAPI } from "@dust-tt/client";

const dustAPI = new DustAPI(
  {
    url: "https://dust.tt",
  },
  {
    workspaceId: "YOUR_WORKSPACE_ID",
    apiKey: "YOUR_API_KEY_OR_ACCESS_TOKEN",
  },
  console
);
```

### 找到所有探员

```js
const r = await dustApi.getAgentConfigurations();

if (r.isErr()) {
  throw new Error(`API Error: ${r.error.message}`);
} else {
  const agents = r.value.filter((agent) => agent.status === "active");
}
```

### 创建对话

```js
const context = {
  timezone: "UTC",
  username: user.firstName,
  email: user.email,
  fullName: user.fullName,
  profilePictureUrl: user.image,
  origin: "api", // Contact us to add more
};

const question = "Hello! What can you do for me ?";

const r = await dustApi.createConversation({
  title: null,
  visibility: "unlisted",
  message: {
    content: question,
    mentions: [
      {
        configurationId: agent.sId,
      },
    ],
    context,
  },
});

if (r.isErr()) {
  throw new Error(r.error.message);
} else {
  const { conversation, message } = r.value;

  try {
    const r = await dustApi.streamAgentAnswerEvents({
      conversation,
      userMessageId: message.sId,
      signal,
    });
    if (r.isErr()) {
      throw new Error(r.error.message);
    } else {
      const { eventStream } = r.value;

      let answer = "";
      let action: AgentActionPublicType | undefined = undefined;
      let chainOfThought = "";

      for await (const event of eventStream) {
        if (!event) {
          continue;
        }
        switch (event.type) {
          case "user_message_error": {
            console.error(
              `User message error: code: ${event.error.code} message: ${event.error.message}`
            );
            return;
          }
          case "agent_error": {
            console.error(
              `Agent message error: code: ${event.error.code} message: ${event.error.message}`
            );
            return;
          }
          case "agent_action_success": {
            action = event.action;
            break;
          }

          case "generation_tokens": {
            if (event.classification === "tokens") {
              answer = (answer + event.text).trim();
            } else if (event.classification === "chain_of_thought") {
              chainOfThought += event.text;
            }
            break;
          }
          case "agent_message_success": {
            answer = event.message.content ?? "";
            break;
          }
          default:
          // Nothing to do on unsupported events
        }
      }
    }
  } catch (error) {
    if (error instanceof Error && error.message.includes("AbortError")) {
      // Stream aborted
    } else {
      // Other error
    }
  }
}
```

## 常见问题

### @dust-tt/client 是什么？

灰尘 API 客户端

### 如何安装 @dust-tt/client？

在项目目录运行 npm install @dust-tt/client，或使用 pnpm add / yarn add / bun add。

### @dust-tt/client 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @dust-tt/client 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @dust-tt/client 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=24\.16\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @dust-tt/client 可以商用吗？

@dust-tt/client 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @dust-tt/client 的下载量有多少？

根据 npm 官方下载统计，@dust-tt/client 在 2026/10/13 – 2026/11/11 这 30 天内被下载 116,871 次，日均约 3,896 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @dust-tt/client 还在维护吗？

最新版本 1\.2\.10 发布于 2026/11/13（今天）；至今共发布 90 个版本，其中过去 12 个月发布了 15 个；首次发布于 2024/11/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

