Files
Ken Chung e8a3df3f0e refactor: replace raw API calls with heygen CLI as tier-2 fallback (#50)
* refactor: replace raw API calls with heygen CLI as tier-2 fallback

PR #47 mislabeled raw curl-to-api.heygen.com as "CLI fallback" — but the
actual CLI is the `heygen` binary (github.com/heygen-com/heygen-cli). This
aligns the skills with the real two-tier model:

1. MCP (preferred) — mcp__heygen__* tools, OAuth, plan credits
2. HeyGen CLI (fallback) — `heygen <noun> <verb>`, auth via
   `heygen auth login` or `HEYGEN_API_KEY`

Changes:
- All curl examples replaced with heygen CLI commands
- Dropped X-Api-Key / X-HeyGen-Source / User-Agent header story
- Dropped ~/.heygen/config persistence in favor of ~/.heygen/credentials
- `auto_proceed` payload removed — CLI handles internally
- Polling replaced with `--wait --timeout` flags
- Video delivery now uses `heygen video download <video_id>`
- Mapping tables restructured: "MCP Tool | CLI Command | Purpose"
- Frame Check / asset routing / avatar discovery updated end-to-end

No behavioral changes for MCP users. CLI users now invoke a single binary
instead of hand-rolling curl requests.

* review: address inline comments on PR #50

- Consolidate "never curl api.heygen.com" directive: keep STOP block in
  SKILL.md + canonical mention in api-reference.md; remove 4 redundant
  copies from sub-skills (reviewer: repetition burns context tokens).
- setup: add `heygen --version` + `heygen auth status` as non-blocking
  validation steps so agents can see CLI version and auth health.
- INSTALL.md: add `heygen --version` after install as defense-in-depth.
- heygen-video/SKILL.md: call out that CLI `--wait` default timeout is
  20m but Video Agent jobs take 20-45m — always pair with `--timeout 45m`.
- platforms/nanoclaw: note that `--timeout 10m` is sized for ≤60s videos,
  bump to 45m for longer clips.

Review: https://github.com/heygen-com/skills/pull/50#pullrequestreview-4126204767

---------

Co-authored-by: Ken <ken@heygen.com>
2026-04-16 22:12:22 -07:00

151 lines
5.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# heygen-skills setup — first-time installation for Claude Code and OpenClaw users.
# Idempotent: safe to run multiple times.
set -euo pipefail
# ─── Colors (degrade gracefully) ─────────────────────────────
if [ -t 1 ] && command -v tput &>/dev/null && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) RED=$(tput setaf 1) BOLD=$(tput bold) RESET=$(tput sgr0)
else
GREEN="" YELLOW="" RED="" BOLD="" RESET=""
fi
ok() { echo "${GREEN}✓${RESET} $1"; }
warn() { echo "${YELLOW}!${RESET} $1"; }
err() { echo "${RED}✗${RESET} $1"; }
# ─── Locate repo root ────────────────────────────────────────
SKILL_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ ! -f "$SKILL_DIR/SKILL.md" ]; then
err "Cannot find SKILL.md — run this script from the heygen-skills repo root."
exit 1
fi
# ─── Parse flags ────────────────────────────────────────────
HOST_OVERRIDE=""
while [ $# -gt 0 ]; do
case "$1" in
--host)
shift
if [ $# -eq 0 ]; then
err "--host requires a value: claude or openclaw"
exit 1
fi
case "$1" in
claude|claude-code) HOST_OVERRIDE="claude-code" ;;
openclaw) HOST_OVERRIDE="openclaw" ;;
*)
err "Unknown host agent: $1 (expected: claude or openclaw)"
exit 1
;;
esac
shift
;;
--host=*)
val="${1#--host=}"
case "$val" in
claude|claude-code) HOST_OVERRIDE="claude-code" ;;
openclaw) HOST_OVERRIDE="openclaw" ;;
*)
err "Unknown host agent: $val (expected: claude or openclaw)"
exit 1
;;
esac
shift
;;
*)
warn "Unknown flag: $1"
shift
;;
esac
done
# ─── Detect host agent ───────────────────────────────────────
# Priority: 1) --host flag, 2) script path, 3) directory existence fallback
AGENT="unknown"
SKILLS_DIR=""
if [ -n "$HOST_OVERRIDE" ]; then
# Explicit --host flag takes highest priority
AGENT="$HOST_OVERRIDE"
elif [[ "$SKILL_DIR" == *"/.openclaw/workspace/skills/"* ]]; then
AGENT="openclaw"
elif [[ "$SKILL_DIR" == *"/.claude/skills/"* ]]; then
AGENT="claude-code"
elif [ -d "$HOME/.openclaw" ] && [ -d "$HOME/.claude" ]; then
# Both installed — path was ambiguous, warn and ask for --host
warn "Both Claude Code and OpenClaw detected. Cannot auto-detect host agent."
warn "Re-run with: ./setup --host claude OR ./setup --host openclaw"
elif [ -d "$HOME/.claude" ]; then
AGENT="claude-code"
elif [ -d "$HOME/.openclaw" ]; then
AGENT="openclaw"
fi
# Set skills directory based on detected agent
case "$AGENT" in
claude-code) SKILLS_DIR="$HOME/.claude/skills" ;;
openclaw) SKILLS_DIR="$HOME/.openclaw/workspace/skills" ;;
esac
echo ""
echo "${BOLD}HeyGen Skills Setup${RESET}"
echo "─────────────────────────────"
if [ "$AGENT" = "unknown" ]; then
warn "Could not detect Claude Code or OpenClaw. See INSTALL.md for manual setup."
else
ok "Detected host agent: ${BOLD}${AGENT}${RESET}"
fi
# ─── Create skill symlinks ───────────────────────────────────
SKILLS=(heygen-avatar heygen-video)
if [ -n "$SKILLS_DIR" ]; then
INSTALL_DIR="$SKILLS_DIR/heygen-skills"
mkdir -p "$INSTALL_DIR"
for skill in "${SKILLS[@]}"; do
src="$SKILL_DIR/$skill/SKILL.md"
[ ! -f "$src" ] && { warn "Skipping $skill — SKILL.md not found"; continue; }
mkdir -p "$INSTALL_DIR/$skill" "$SKILLS_DIR/$skill"
ln -sf "$src" "$INSTALL_DIR/$skill/SKILL.md"
ln -sf "$src" "$SKILLS_DIR/$skill/SKILL.md"
done
ln -sf "$SKILL_DIR/SKILL.md" "$INSTALL_DIR/SKILL.md"
[ -d "$SKILL_DIR/references" ] && ln -sfn "$SKILL_DIR/references" "$INSTALL_DIR/references"
ok "Skill symlinks created in ${SKILLS_DIR}"
for skill in "${SKILLS[@]}"; do echo " ${skill}/SKILL.md"; done
fi
# ─── Auth guidance ───────────────────────────────────────────
echo ""
echo "${BOLD}Auth:${RESET}"
echo " The skills prefer HeyGen Remote MCP (OAuth, no API key needed)."
echo " If MCP isn't connected, install and use the HeyGen CLI:"
echo " ${BOLD}curl -fsSL https://static.heygen.ai/cli/install.sh | bash${RESET}"
echo " ${BOLD}heygen auth login${RESET} # or: export HEYGEN_API_KEY=<your-key>"
echo " ${BOLD}heygen auth status${RESET} # verify"
if command -v heygen &>/dev/null; then
HEYGEN_VERSION="$(heygen --version 2>/dev/null | head -n1 || echo 'unknown')"
ok "heygen CLI detected: ${HEYGEN_VERSION}"
if heygen auth status &>/dev/null; then
ok "heygen auth OK"
else
warn "heygen not authenticated — run: heygen auth login (or export HEYGEN_API_KEY=<key>)"
fi
else
warn "heygen CLI not found on PATH (optional — only needed if MCP isn't connected)"
fi
# ─── Summary ─────────────────────────────────────────────────
echo ""
echo "${BOLD}Installed skills:${RESET}"
for skill in "${SKILLS[@]}"; do
echo " - $skill"
done
echo ""
echo "${BOLD}Next step:${RESET}"
echo " Ask your agent: \"Create my HeyGen avatar\""
echo ""