接入指南
更新时间 2026-05-09 17:04:42
最近更新时间: 2026-05-09 17:04:42
本文说明 AIuse 云电脑 SDK 的接入配置、运行环境和基础使用方式。SDK 适合在 Node.js 服务端或可信 Node.js 运行环境中调用。
环境要求
| 项目 | 要求 |
|---|---|
| 语言 | TypeScript 或 JavaScript |
| Node.js | Node.js 18 或以上版本,建议使用维护期内 LTS 版本 |
| 包管理器 | npm、yarn 或 pnpm |
| 网络 | 可访问 AIuse 云电脑服务地址 |
| 凭证 | 已获取 AccessKey ID 和 AccessKey Secret |
| 资源 | 已获取目标云电脑 desktopCode |
不建议在浏览器前端直接使用 SDK 保存和调用 AccessKey Secret。生产环境应在服务端或可信执行环境中调用 SDK。
Node.js 安装方式如下:
打开 Node.js 官网下载页面
选择维护期内的 LTS 版本安装包
按安装向导完成安装
安装完成后重新打开终端
依次执行 node -v 和 npx -v,确认命令可正常使用
如果本地已安装 Node.js,但仍无法执行 npx,请检查:
Node.js 是否安装完整
当前终端是否已重新打开
Node.js 安装目录是否已加入系统 PATH
安装
使用 npm:
npm install @ctyun/desktop-agent-sdk使用 yarn:
yarn add @ctyun/desktop-agent-sdk使用 pnpm:
pnpm add @ctyun/desktop-agent-sdk创建 Client
import Client from '@ctyun/desktop-agent-sdk';
const client = new Client({
apiKey: process.env.AIUSE_API_KEY,
apiSecret: process.env.AIUSE_API_SECRET,
desktopCode: process.env.AIUSE_DESKTOP_CODE,
serviceURL: process.env.AIUSE_SERVICE_URL || 'https://desk.ctyun.cn:8816'
});参数说明:
| 参数 | 是否必填 | 说明 |
|---|---|---|
| apiKey | 是 | 控制台创建的 AccessKey ID |
| apiSecret | 是 | 控制台创建的 AccessKey Secret |
| desktopCode | 是 | 云电脑桌面编码 |
| serviceURL | 否 | 服务地址,不传时使用 SDK 默认值 |
创建会话
const session = await client.createSession();
console.log('sessionId:', session.sessionId);会话对象包含:
| 属性 | 说明 |
|---|---|
| sessionId | 会话唯一标识 |
| computer | Computer Use 方法集合 |
| filesystem | FileSystem 方法集合 |
| close | 关闭会话方法 |
调用 Computer Use
await session.computer.move_mouse({ x: 500, y: 300 });
await session.computer.click_mouse({ x: 500, y: 300, clickMode: 'left' });
await session.computer.type_text({ text: 'Hello from AIuse' });
const screenshot = await session.computer.screen_shot();调用 FileSystem
await session.filesystem.create_directory({ path: 'C:/ai-user-test' });
await session.filesystem.write_file({
path: 'C:/ai-user-test/hello.txt',
content: 'Hello from AIuse SDK',
mode: 'overwrite'
});
const result = await session.filesystem.read_file({
path: 'C:/ai-user-test/hello.txt',
offset: 0,
length: 0
});
console.log(result.data);关闭会话
任务完成后应主动关闭会话:
await session.close();推荐在 finally 中关闭:
let session;
try {
session = await client.createSession();
await session.computer.screen_shot();
} finally {
if (session) {
await session.close();
}
}安全建议
AccessKey Secret 只应保存在服务端或可信密钥管理系统中。
日志中不要输出完整 AccessKey Secret。
每个项目或环境建议使用独立 AccessKey。
AccessKey 应只关联必要的云电脑资源。