template-skill/README.md

62 lines
1.7 KiB
Markdown
Raw Normal View History

# template-skill
新 skill 的基础模版。
## 认证机制auth-cli.ts
每个 skill 内置一份 `src/auth-cli.ts`,它是一个薄 wrapper通过 subprocess 调用 `auth-runtime` CLI`bun run ~/clawd/skills/auth-runtime/src/cli.ts`)。
**不使用 npm 依赖**,避免了 git 包缓存导致的版本不一致问题。
### 工作原理
```
skill/src/index.ts
→ import { createSkillClient } from './auth-cli.ts'
→ auth-cli.ts 通过 spawnSync 调用 bun run cli.ts
→ auth-runtime/src/cli.ts 处理 token/session/request
```
### 使用方式
```typescript
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-runtime`
```bash
git clone http://192.168.0.108:3030/agent-skills/auth-runtime.git ~/clawd/skills/auth-runtime
```
`install.sh` 会检查此目录是否存在。
### 路径解析
默认路径:`~/clawd/skills/auth-runtime`
可通过环境变量覆盖:`AUTH_RUNTIME_DIR=/custom/path bun run scripts/run.ts ...`
### 新建 skill 检查清单
1. 从此模版创建仓库
2. 确认 `src/auth-cli.ts` 已包含(直接从模版继承)
3. `src/index.ts``import { createSkillClient } from './auth-cli.ts'`
4. `package.json`**不要** 添加 `@clawd/auth-runtime` 依赖
5. `install.sh` 中包含 auth-runtime 目录检查