Shared auth runtime for OpenClaw skills
- JavaScript 52.9%
- TypeScript 47.1%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| dist | ||
| src | ||
| tests | ||
| .gitignore | ||
| bun.lock | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
@clawd/auth-runtime
Codex Skill 运行时授权库。它只负责消费 runtime auth 文件并调用业务 API,不负责登录、SkillHub 分发授权或 CI 注册。
当前模型支持两种授权文件位置:
<workspace>/.yuanwei/auth.json
~/.yuanwei/auth.json
运行时会优先从当前工作目录向上查找 <workspace>/.yuanwei/auth.json,用于 Web / server-side Codex 工作区;找不到时再读取 ~/.yuanwei/auth.json,用于桌面 Codex 客户端。
不读取 ~/.codex/auth.json、旧的 ~/.codex/yuanwei/session.json、环境变量业务 token、浏览器 cookie、client key 或 skreg_* registry token,也不做 token 缓存。
配置文件
{
"businessApiKey": "better-auth-session-token",
"apiBase": "https://api-gw.yuanwei-lnc.com",
"apiKey": "optional-model-key",
"modelBase": "https://ai.yuanwei-lnc.com/v1"
}
auth-runtime 每次业务请求前都会重新读取这个文件。
businessApiKey: 业务 API 请求 token,get/post/...使用它。apiBase: 业务 API 网关地址。apiKey: 可选模型网关 key,只有modelConfig()使用它。modelBase: 可选模型网关地址;纯业务 API skill 不需要模型配置。modelBase: 模型 OpenAI-compatible 地址。
使用
import { createSkillClient } from '@clawd/auth-runtime';
const client = createSkillClient();
const result = await client.post('/ecom/tasks/scrape', {
url: 'https://detail.1688.com/offer/123.html',
});
const model = client.modelConfig();
console.log(result.status, model.baseURL);
业务 API 请求会自动带:
Authorization: Bearer <businessApiKey>
模型调用才要求 apiKey 和 modelBase;纯业务 API Skill 只要求 businessApiKey 和 apiBase。
构建
bun run build