核心概念(1) 本文介绍 AIuse 云电脑 SDK 中的核心对象和调用模型,帮助开发者理解 SDK 接入时的基本概念。 Client Client 是 SDK 的入口对象,用于保存服务地址、AccessKey、桌面编码等连接配置,并负责创建会话。 创建 Client 时通常需要传入以下参数: 参数 说明 apiKey 控制台 AccessKey ID apiSecret 控制台 AccessKey Secret desktopCode 云电脑桌面编码 serviceURL 服务地址,可选 示例: plaintext import Client from '@ctyun/desktopagentsdk'; const client new Client({ apiKey: process.env.AIUSEAPIKEY, apiSecret: process.env.AIUSEAPISECRET, desktopCode: process.env.AIUSEDESKTOPCODE }); Session Session 表示一次与云电脑的操作会话。创建会话后,可以通过会话对象调用 Computer Use 或 FileSystem 能力。 plaintext const session await client.createSession(); 任务结束后,应主动关闭会话: plaintext await session.close(); ComputerAPI ComputerAPI 用于执行 GUI 操作,典型方法包括: movemouse clickmouse pressmouse releasemouse dragmouse scroll presskey typetext screenshot getcursorposition FileSystemAPI FileSystemAPI 用于执行文件操作,当前版本开放的接口包括: createdirectory readfile writefile movefile searchfiles 会话生命周期 推荐的会话生命周期如下: 1. 创建 Client。 2. 创建 Session。 3. 调用工具方法。 4. 捕获并处理异常。 5. 在 finally 中关闭 Session。 plaintext let session; try { session await client.createSession(); await session.computer.typetext({ text: 'hello' }); } finally { if (session) { await session.close(); } }
来自: