@21st-sdk/节点
服务器侧节点.js SDK 21号特工。在程序上管理沙盒、线条和符号.
安装
npm install @21st-sdk/node
快速启动
import { AgentClient } from "@21st-sdk/node"
const client = new AgentClient({
apiKey: process.env.API_KEY_21ST!, // 21st_sk_...
})
// Create a sandbox for your agent
const sandbox = await client.sandboxes.create({ agent: "my-agent" })
// Create a thread
const thread = await client.threads.create({
sandboxId: sandbox.sandboxId,
name: "Review PR #42",
})
// Generate a short-lived token for browser clients
const { token, expiresAt } = await client.tokens.create({
agent: "my-agent",
expiresIn: "1h",
})
API 密码
new AgentClient(config)
new AgentClient({
apiKey: string // Your 21st_sk_ API key
baseUrl?: string // Default: "https://relay.an.dev"
})
client.sandboxes
| 方法 | 说明 |
create({ agent }) | 为代理创建新沙盒 |
get(sandboxId) | 获取沙盒细节( 状态、 线程、 代理信息) |
delete(sandboxId) | 删除一个沙盒 |
exec({ sandboxId, command, cwd?, envs?, timeoutMs? }) | 在沙盒内运行命令 |
git.clone({ sandboxId, url, path?, token?, depth? }) | 将仓库切入沙盒 |
client.sandboxes.files
| 方法 | 说明 |
write({ sandboxId, files }) | 将一个或多个文本文件写入沙盒 |
read({ sandboxId, path }) | 从沙盒读取一个文件 |
list({ sandboxId, path, depth? }) | 在路径下列出文件和目录 |
getInfo({ sandboxId, path }) | 获取一个文件或目录的元数据 |
exists({ sandboxId, path }) | 检查文件或目录是否存在 |
makeDir({ sandboxId, path }) | 创建目录路径, 返回是否新创建 |
rename({ sandboxId, oldPath, newPath }) | 重命名或移动文件或目录 |
remove({ sandboxId, path }) | 删除文件或目录 |
client.threads
| 方法 | 说明 |
list({ sandboxId }) | 在沙盒中列出所有线索 |
create({ sandboxId, name? }) | 创建新线索 |
get({ sandboxId, threadId }) | 用信件获取线程 |
delete({ sandboxId, threadId }) | 删除线索 |
client.tokens
| 方法 | 说明 |
create({ agent?, userId?, expiresIn? }) | 创建短寿命 JWT( 默认:1h) |
许可证
麻省理工学院