Dexto 客户端 SDK
用于 Dexto 服务器的 TypeScript HTTP 客户端, 并有一个单独的切入点用于认证 Cloud 发现 .
特征
- 🔌 单独出口: 本地服务器和Cloud发现客户端
- 🌐 通用: 在Node.js、浏览器和React Industrial工作
- 📡 HTTP + SSE 软件: 完整 REST API 和实时 SSE 流媒体支持
- 🛡️ 类型脚本: 完全类型安全
- 🔄 自动重试: 内置重试逻辑, 带有指数倒置
- ⚡ 云层合同: 审定的发现请求和答复
安装
npm install @dexto/client-sdk
云的发现
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使用相同的发现客户端:
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> 在发现之前.
快速启动
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);
配置
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)- 连接状态变化
处理错误
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 或本地服务器运行时间 .