关于 ops-integrate
ops-integrate 是用于将外部服务接入 OPS 的集成管理技能,适合配置 API 的用户。它可发现 API 信息、检查凭据并在本地登记集成。
主要功能
- 01发现 API 文档与认证方式
- 02收集并本地保存凭据
- 03执行健康检查
- 04登记及列出集成
适用场景
- 01接入新的第三方 API
- 02查看已登记的服务
- 03验证 API 凭据是否可用
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ davepoon/ buildwithclaude --skill ops-integrate安装后在 Claude Code 中输入/ops-integrate确认已加载。
详细介绍
运行时上下文
PREFS="${CLAUDE_PLUGIN_DATA_DIR:-$HOME/.claude/plugins/data/ops-ops-marketplace}/preferences.json"
PARTNER_REGISTRY=$(jq '.partner_registry // {}' "$PREFS" 2>/dev/null || echo '{}')
解析 $ARGUMENTS:
- 包含
--list→ 执行列出已注册的集成,然后退出 - 否则 → 使用服务名称作为第一个位置参数,执行引导流程
OPS ► 集成
列出已注册的集成(--list)
jq -r '.partner_registry // {} | to_entries[] | "\(.key): \(.value.base_url) [\(.value.auth_type)]"' "$PREFS" 2>/dev/null
以表格形式显示:
Registered integrations:
hubspot https://api.hubapi.com [bearer]
stripe https://api.stripe.com [bearer]
sendgrid https://api.sendgrid.com [api-key]
如果尚未注册任何集成:No integrations registered yet. Run /ops:integrate <service-name> to add one.
引导流程(5 个步骤)
步骤 1 — 查找 API 详情
如果未提供 --url,使用 WebSearch 查找:
- 官方 API 文档 URL
- API 基础 URL
- 身份验证方式(bearer token / api-key header / basic auth / oauth2)
- API 密钥生成 URL(用户获取凭据的位置)
- 健康检查/测试端点(例如,/healthz、/v1/ping、/me)
步骤 2 — 与用户确认
通过 AskUserQuestion 呈现查找结果(≤4 个选项):
Found: <service-name> API — Base URL: <url> — Auth: <auth-type>
[Looks correct — continue] [Change base URL] [Change auth type] [Cancel]
如果选择“更改基础 URL”:通过 AskUserQuestion 以自由文本形式询问新 URL。
如果选择“更改身份验证类型”:通过 AskUserQuestion 提供选项(≤4 个):[bearer] [api-key] [basic] [oauth2]
步骤 3 — 收集凭据
Paste your <service-name> <auth-type> credential (it will be stored locally only)
[Paste now] [Configure later]
如果选择“立即粘贴”:通过 AskUserQuestion 以自由文本形式收集凭据。生成密钥名称:<lowercase_service_name>_api_key
通过原子临时文件替换写入 preferences.json:
tmp=$(mktemp)
jq --arg k "$KEY_NAME" --arg v "$CREDENTIAL" '.[$k] = $v' "$PREFS" > "$tmp" && mv "$tmp" "$PREFS"
步骤 4 — 健康检查
使用凭据对健康检查/测试端点执行 Curl:
# Bearer token
curl -sf -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer ${CREDENTIAL}" \
"${BASE_URL}${HEALTH_ENDPOINT}"
# API key header (X-Api-Key)
curl -sf -o /dev/null -w "%{http_code}" \
-H "X-Api-Key: ${CREDENTIAL}" \
"${BASE_URL}${HEALTH_ENDPOINT}"
# Basic auth
curl -sf -o /dev/null -w "%{http_code}" \
-u "${CREDENTIAL}:" \
"${BASE_URL}${HEALTH_ENDPOINT}"
报告:HTTP 状态为 200-299 时显示 ✅,否则显示 ⚠️ 和状态代码。如果尚未配置凭据,则跳过健康检查并报告 ⬜ health check skipped — credential not configured。
步骤 5 — 在合作伙伴注册表中注册
tmp=$(mktemp)
jq --arg name "${SERVICE_NAME}" \
--arg url "${BASE_URL}" \
--arg auth "${AUTH_TYPE}" \
--arg key_name "${KEY_NAME}" \
--arg health "${HEALTH_ENDPOINT}" \
'.partner_registry[$name] = {base_url: $url, auth_type: $auth, credential_key: $key_name, health_endpoint: $health, added: (now | todate)}' \
"$PREFS" > "$tmp" && mv "$tmp" "$PREFS"
确认输出:
✅ <service-name> registered in partner registry
Auth: <auth-type>
Health: <base-url><health-endpoint>
Credential key: <key-name>
Access via: jq '.partner_registry["<service-name>"]' $PREFS
CLI/API 参考
# List all registered integrations
jq '.partner_registry' "${CLAUDE_PLUGIN_DATA_DIR:-$HOME/.claude/plugins/data/ops-ops-marketplace}/preferences.json"
# Look up a specific integration
jq '.partner_registry["hubspot"]' "$PREFS"
# Read a credential for a registered integration
jq -r ".$KEY_NAME" "$PREFS"
# Remove an integration from the registry
jq 'del(.partner_registry["<service-name>"])' "$PREFS" > tmp && mv tmp "$PREFS"
评论
支持 Markdown