# @dexto/client-sdk 中文文档

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

版本：1\.17\.0
npm 元数据更新时间：2026-11-09T21:19:51.240Z
中文译文更新时间：2026-11-12T05:03:47.595Z
软件包许可：未声明

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

原始 npm 页面：https://www.npmjs.com/package/%40dexto/client-sdk
原文对照：https://npmcn.com/package/%40dexto/client-sdk/?lang=original

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

- 包体积（解压后）：1.4 MB，17 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2025-09-25T07:40:37.524Z
- 最新版本发布：2026-11-09T21:19:50.829Z
- 近 30 天下载量：3296（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：107（近 12 个月 95 个）

## 中文简介

用于 Dexto 服务器的 TypeScript HTTP 客户端, 并有一个单独的切入点用于认证 Cloud 发现 .

## 安装

```sh
npm install @dexto/client-sdk
```

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

## README

# Dexto 客户端 SDK

用于 Dexto 服务器的 TypeScript HTTP 客户端, 并有一个单独的切入点用于认证 Cloud 发现 .

## 特征

-   🔌 **单独出口**: 本地服务器和Cloud发现客户端
-   🌐 **通用**: 在Node.js、浏览器和React Industrial工作
-   📡 **HTTP + SSE 软件**: 完整 REST API 和实时 SSE 流媒体支持
-   🛡️ **类型脚本**: 完全类型安全
-   🔄 **自动重试**: 内置重试逻辑, 带有指数倒置
-   ⚡ **云层合同**: 审定的发现请求和答复

## 安装

```bash
npm install @dexto/client-sdk
```

## 云的发现

```typescript
import { createDextoCloudClient } from '@dexto/client-sdk/cloud';

const cloud = createDextoCloudClient({
    origin: 'https://app.dexto.ai',
    token: 'your-dexto-api-key',
    fetch: globalThis.fetch,
});

const sources = await cloud.sources({ limit: 20 });
const matches = await cloud.search({ query: 'web search', limit: 10 });
const description = await cloud.describe('dexto.platform.web_search');
```

使用组织证书 `capabilities:read`. 成果包括计划和执行/可用性元数据;发现不准许援引能力。 Cloud验证当前会员身份和每个请求的证书权限.

CLI使用相同的发现客户端:

```bash
dexto login
dexto cloud sources --json
dexto cloud search "web search" --limit 10 --json
dexto cloud describe dexto.platform.web_search --json
```

搜索返回 `hasMore`, (中文(简体) ), `nextOffset`,以及 `total`。通过 `--offset` 下页。 JSON 失败包含 `error` 以代码 1 为对象并退出 。 人可读出输出为默认.

用于另一个安装, 使用 `dexto login --platform-url <application-origin>`。保存的密钥仍与该来源相联,包括当同一密钥出现在环境中时。 不同的外壳环境 `DEXTO_API_KEY` 可以选择另一个来源 `--platform-url` 或者说 `DEXTO_PLATFORM_URL`。云发现使用明确的外壳环境覆盖,而不是从 `.env` 文档。 没有源代码元数据而保存的遗留密钥需要更新 `dexto login --platform-url <application-origin>` 在发现之前.

## 快速启动

```typescript
import { DextoClient } from '@dexto/client-sdk';

const client = new DextoClient({
    baseUrl: 'https://your-dexto-server.com',
    apiKey: 'optional-api-key',
});

// Connect to Dexto server
await client.connect();

// Send a message
const response = await client.sendMessage({
    content: 'Hello, how can you help me?',
});

console.log(response.response);
```

## 配置

```typescript
const client = new DextoClient(
    {
        baseUrl: 'https://your-dexto-server.com', // Required: Dexto API base URL
        apiKey: 'your-api-key', // Optional: API key for auth
        timeout: 30000, // Optional: Request timeout (ms)
        retries: 3, // Optional: Retry attempts
    },
    {
        reconnect: true, // Optional: Auto-reconnect
        reconnectInterval: 5000, // Optional: Reconnect delay (ms)
        debug: false, // Optional: Debug logging
    }
);
```

## API 方法

### 连接管理

-   `connect()` - 建立与Dexto服务器的连接
-   `disconnect()` - 紧接
-   `isConnected` - 检查连接状态

### 通讯

-   `sendMessage(input)` - 发送消息( HTTP)
-   通过 SSE 流线 `/api/message-stream` 结束点

### 会话管理

-   `listSessions()` - 列出所有会话
-   `createSession(id?)` - 创建新会话
-   `getSession(id)` - 获取会话细节
-   `deleteSession(id)` - 删除会话

### 实时活动

-   `on(eventType, handler)` - 订阅Dexto事件
-   `onConnectionState(handler)` - 连接状态变化

## 处理错误

```typescript
try {
    await client.sendMessage({ content: 'Hello' });
} catch (error) {
    if (error.name === 'ConnectionError') {
        console.log('Failed to connect to Dexto server');
    } else if (error.name === 'HttpError') {
        console.log(`HTTP ${error.status}: ${error.statusText}`);
    }
}
```

## 哲学

代理服务器出口是一个稀疏的打字运输客户端. Cloud出口验证发现请求输入和成功响应合同,报告键入了HTTP,网络,和不兼容响应错误. 服务器端的授权和产品政策仍由服务器负责.

## 依赖关系

已出版的套件使用Hono为代理服务器客户端,Zod为Cloud发现验证. 单独的 Cloud 导出不导入 Core 或本地服务器运行时间 .

## 常见问题

### @dexto/client-sdk 是什么？

用于 Dexto 服务器的 TypeScript HTTP 客户端, 并有一个单独的切入点用于认证 Cloud 发现 \.

### 如何安装 @dexto/client-sdk？

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

### @dexto/client-sdk 支持 TypeScript 吗？

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

### @dexto/client-sdk 支持 ESM 还是 CommonJS？

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

### @dexto/client-sdk 可以商用吗？

@dexto/client-sdk 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @dexto/client-sdk 的下载量有多少？

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

### @dexto/client-sdk 还在维护吗？

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

