开发者指南

把站点体检接进自己的流水线:认证、轮询、报告结构、CI 门禁和错误处理。


这一页写给要写代码接进来的人。所有能力都在 https://dev.solokit.run 下,免密钥可用,带 Key 额度更高。

认证

方式请求头额度
匿名无少量试用,限流更严
API KeyAuthorization: Bearer dav_xxx 或 x-devassist-key: dav_xxx跟随账号档位

GET /api/me 可以确认当前身份:

curl -s https://dev.solokit.run/api/me -H "Authorization: Bearer dav_xxx"
# {"auth":"key","userId":"...","message":"..."}

异步体检:派发 + 轮询

体检在远端沙箱执行,是异步的。两步:

# 1. 派发
TASK=$(curl -s -X POST https://dev.solokit.run/api/sandbox/dispatch \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer dav_xxx" \
  -d '{"type":"wcag","url":"https://example.com","options":{"aiCommentary":true}}' \
  | python3 -c 'import sys,json;print(json.load(sys.stdin)["taskId"])')

# 2. 轮询
while :; do
  R=$(curl -s "https://dev.solokit.run/api/sandbox/tasks/$TASK")
  S=$(echo "$R" | python3 -c 'import sys,json;print(json.load(sys.stdin)["status"])')
  [ "$S" = "done" ] || [ "$S" = "failed" ] || [ "$S" = "timeout" ] && break
  sleep 3
done
echo "$R"

要点:

  • type 取 site-stability / site-validator / performance / wcag / computer-use。
  • 一次只跑一项。要跑多项就并行派发五个任务,别串行等。
  • 轮询间隔 3–5 秒足够,别用 200ms 猛刷。
  • idempotencyKey 可选,同一个 key 短时间重复派发会复用同一个任务,适合防止重试造成双跑。
  • 单项通常十几秒到一分钟。渲染级检查(wcag / computer-use)比静态检查慢。

报告结构

GET /api/sandbox/tasks/{id} 的 result.report 是统一结构:

{
  "score": 97,
  "grade": "A",
  "sections": [
    { "id": "contrast", "title": "对比度", "score": 100, "weight": 25,
      "passed": ["正文对比度 ≥ 4.5:1"],
      "issues": [{ "impact": "serious", "title": "按钮文字对比度不足",
                   "howToFix": "把前景色加深到 #595959 以下" }] }
  ],
  "passed": ["页面有 lang 属性", "..."],
  "issues": [{ "impact": "moderate", "title": "...", "count": 3 }],
  "environment": [{ "code": "WC-ENV-NO-BROWSER", "weight": 0 }]
}
  • score 0–100,grade 为 A/B/C/D/F。
  • environment 是环境因素,权重为 0,不计入总分。看到 WC-ENV-NO-BROWSER 说明渲染级审计没跑成、降级为静态检查——这时候的分数要打个折扣看。
  • issues[].impact 取 critical / serious / moderate / minor。

综合报告

五个单项各跑完后,可以让服务端合成一份总报告(加权总分 + 优先修复清单 + AI 点评):

curl -s -X POST https://dev.solokit.run/api/checkup/report \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer dav_xxx" \
  -d '{
    "url": "https://example.com",
    "locale": "zh",
    "checks": [
      {"id":"wcag","title":"无障碍","score":97,"grade":"A","passedCount":5,
       "issues":[{"impact":"serious","title":"按钮文字对比度不足","howToFix":"加深前景色","count":1}]},
      {"id":"performance","title":"性能","score":88,"grade":"B","passedCount":4,"issues":[]}
    ]
  }'

权重:site-stability 25、wcag 25、site-validator 20、performance 20、computer-use 10。

只按你实际传的检查归一化——少传几项不会因为缺项被扣分。返回里带 recordId(登录用户),可在 Console 回看。

官网定调(同步)

POST /api/agent/site-tone,一次请求直接返回,不需要轮询:

curl -s -X POST https://dev.solokit.run/api/agent/site-tone \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com","siteType":"developer-tool","locale":"zh"}'
  • siteType:developer-tool / database / saas / research / finance / content / other
  • keepAccent:可选,想保留的品牌色
  • 返回七维分数、overallScore、策略三选一、cursorPrompt 和 commentary

接进 CI

CLI 的退出码反映「检查是否跑成功」,不是分数阈值:

  • 0:所有指定检查都拿到了报告
  • 1:至少一项失败
  • 2:参数错误(URL 不合法、检查项名写错)

要按分数做门禁,直接调 API 拿结构化结果自己判(check 命令没有 JSON 输出,只有 e2e 有 --json):

TASK=$(curl -s -X POST https://dev.solokit.run/api/sandbox/dispatch \
  -H "Content-Type: application/json" -H "Authorization: Bearer $DEVASSIST_KEY" \
  -d "{\"type\":\"wcag\",\"url\":\"$PREVIEW_URL\"}" \
  | python3 -c 'import sys,json;print(json.load(sys.stdin)["taskId"])')

sleep 20

SCORE=$(curl -s "https://dev.solokit.run/api/sandbox/tasks/$TASK" \
  | python3 -c 'import sys,json;r=json.load(sys.stdin);print(r.get("result",{}).get("report",{}).get("score") or 0)')

echo "score=$SCORE"
[ "$SCORE" -ge 85 ] || exit 1

放在 Vercel / GitHub Actions 的部署后钩子里,PR 里贴报告比让人肉眼看截图靠谱。

限流与错误

状态码code含义怎么处理
400—参数不合法(URL 协议、缺字段)修请求,别重试
401—Key 无效或已撤销重新生成 Key
429RATE_LIMITED短时间请求过多按 Retry-After 退避
429QUOTA_EXCEEDED当天不同 URL 额度用尽换天再跑,或升级档位
  • 只有 http: / https: 且公网可达的地址会被接受,localhost、私网 IP、内网域名一律拒绝。
  • 两种 429 靠 code 区分:RATE_LIMITED 是秒级限流,QUOTA_EXCEEDED 是当天额度用完(Retry-After 为 86400)。照 Retry-After 退避即可,别立刻重试。

接下来