@ eigenpal/ sdk
从TypeScript中触发并检查Eigenpal自动化.
安装
npm i @eigenpal/sdk
需要 TypeScript-aware 运行时间: Bun, Deno, Node 22+(本地 TS), tsx下个J,Vite,或者任何现代的组合。 平面 node script.js 将无法工作;见 配置。 。 。 .
获取 API 密钥 sudio.eigenpal.com - > (中文(简体) ). 设置 - > API 密钥。 。 。 .
快速启动
import { EigenpalClient } from '@eigenpal/sdk';
const client = new EigenpalClient({ apiKey: process.env.EIGENPAL_API_KEY });
const result = await client.run(
'workflows.extract-invoice',
{ contract_document: file },
{ waitForCompletion: 60 }
);
if (result.finished) {
console.log(result.output);
}
target 接受空工作流程ID, 如 wf_abc,或键入目标,例如 workflows.<id-or-slug> 或者说 agents.<slug>. Slugs需要前缀,因为工作流程和代理流可以重叠.
自动化
工作流程和代理被曝光为自动化.
const { data } = await client.automations.list({ search: 'invoice', folderId: 'fldr_…' });
const automation = await client.automations.get('workflows.extract-invoice');
await client.automations.move('workflows.extract-invoice', { folderPath: 'billing/invoices' });
await client.automations.delete('workflows.extract-invoice');
list({ folderId: 'null' }) 返回租户根上未存档的 YAML 工作流程。 代理自动化器没有文件夹模型.
Workflow 删除自动化父文档并保存执行历史. 代理删除删除代理执行和历史,匹配仪表板,并有最佳的剩余存储清理.
文件夹
工作流程和模板树是一等资源. Git 中的 Nested代理目录仅是源组织.
const tree = await client.folders.list({ type: 'workflow', tree: 'true' });
const folder = await client.folders.create({ name: 'invoices', type: 'workflow' });
await client.folders.update(folder.id, { name: 'billing' });
await client.folders.delete(folder.id); // unfiles workflows; does not delete them
运行
const { id } = await client.run('agents.invoice-agent', { invoice: file });
const run = await client.runs.get(id, { expand: ['usage', 'execution'] });
const usage = await client.runs.usage(id);
const steps = await client.runs.steps(id);
const events = await client.runs.events(id);
const trace = await client.runs.trace.get(id);
await client.runs.cancel(id);
await client.rerun(id, { waitForCompletion: 60 });
列表呼叫在工作流程,代理,手动运行和eval运行中使用相同的运行 API:
const recentFailures = await client.runs.list({
type: 'workflow',
status: 'failed,cancelled',
limit: 50,
});
文件与艺术
使用 client.files 用于重用上传的第一个blobs。 当通过运行输入引用时,Eigenpal将文件快照到运行范围文物.
const uploaded = await client.files.upload(file);
const started = await client.run('workflows.extract-invoice', {
contract_document: { $fileId: uploaded.id },
});
const artifacts = await client.runs.artifacts.list(started.id);
const pdf = await client.runs.artifacts.download(started.id, artifacts.artifacts[0].path);
也可以通过一个 File, (中文(简体) ), Blob,或 { content, filename, mimeType } 直接转到 client.run; SDK 自动发送多段形式数据. 持久运行输入和数据集实例存储范围d { "$file": "input/..." } 文物在摄入后会反射.
错误
每个非-2xx响应都投出一个打入的子类: EigenpalError数字 :
| HTTP 密码 | 类 |
|---|---|
| 400个 | EigenpalValidationError |
| 401 (中文(简体) ) | EigenpalAuthError |
| 403 (韩语) | EigenpalForbiddenError |
| 404 (韩语) | EigenpalNotFoundError |
| 429个 | EigenpalRateLimitError |
| 5 (简体中文) | EigenpalServerError |
| 超时/ 中止 | EigenpalTimeoutError |
参考文献
| 专题 | 里面有什么东西 |
|---|---|
| 自动化 | 列表,检查,移动,删除,版本,触发器,文件夹. |
| 运行 | 开始,民意调查,取消,再运行,使用,步骤,事件,痕迹,审查. |
| 文件输入 | 从文件, Blob, 缓冲, 或路径上传多段 . |
| 错误 | 已打出例外,复试,请求代号. |
| 配置 | API 密钥, BaseUrl , 超时, 标题 . |
| 完整 API 参考 | 每一种方法,均由OpenAPI生成. |
许可证
阿帕奇2.0 (英语).