1688-logistics-scraper/README.md

1.8 KiB
Raw Blame History

template-skill

新 skill 的基础模版。

认证机制auth-cli.ts

每个 skill 内置一份 src/auth-cli.ts,它是一个薄 wrapper通过 subprocess 调用 auth-rt 二进制。

不使用 npm 依赖auth-runtime 更新时只需重新编译二进制,不需要改动任何 skill。

工作原理

skill/src/index.ts
  → import { createSkillClient } from './auth-cli.ts'
  → auth-cli.ts 通过 spawnSync 调用 auth-rt 二进制
  → auth-rt 处理 token/session/request

使用方式

import { createSkillClient } from './auth-cli.ts';

const client = createSkillClient({
  apiBase: process.env.API_BASE,  // 可选
  dryRun: false,                  // 可选dry-run 模式返回模拟数据
});

// API 调用
const res = await client.post('/ecom/your/endpoint', { param: 'value' });
// res = { status: 200, body: '...' }

// 获取 session
const session = await client.session();
// session = { accessToken: '...', expiresIn: 900 }

前置条件

每台运行 skill 的机器上必须安装 auth-rt 二进制:

git clone http://192.168.0.108:3030/agent-skills/auth-runtime.git ~/clawd/skills/auth-runtime
cd ~/clawd/skills/auth-runtime && ./install.sh
# 安装到 ~/.openclaw/bin/auth-rt

确保 ~/.openclaw/bin 在 PATH 中,或通过 AUTH_RT_BIN 环境变量指定路径。

auth-runtime 更新流程

auth-runtime 代码变更后:

cd ~/clawd/skills/auth-runtime && git pull && ./install.sh

重新编译即可,无需改动任何 skill 代码

新建 skill 检查清单

  1. 从此模版创建仓库
  2. 确认 src/auth-cli.ts 已包含(直接从模版继承)
  3. src/index.tsimport { createSkillClient } from './auth-cli.ts'
  4. package.json不要 添加 @clawd/auth-runtime 依赖
  5. install.sh 中包含 auth-rt 二进制检查