ai-director

Original🇨🇳 Chinese
Translated
6 scripts

Full workflow of AI short drama generation: account management, scriptwriting, video production. Integrated with X2C billing system, suitable for commercial deployment. It includes three core modules: ad-account-manager (account management), ad-writer (scriptwriting prompts), ad-producer (video production).

2installs
Added on

NPX Install

npx skill4agent add giggle-official/skills ai-director

SKILL.md Content (Chinese)

View Translation Comparison →

AI Director - Full Workflow of AI Short Drama Generation

A complete AI short drama generation solution, from idea to finished video, integrated with X2C platform account management and billing.

👥 Multi-user Support

This Skill supports multi-user device sharing, each user has independent X2C account and configuration.
User credential storage path:
credentials/{USER_ID}.json
You need to set the
USER_ID
or
TELEGRAM_USER_ID
environment variable when calling the script:
bash
USER_ID=5470522468 node scripts/ad-account-manager.js check-binding
OpenClaw will automatically pass the user ID when calling from chat.

🎯 Module Overview

1. Ad Account Manager

  • Function: X2C platform account binding, verification
  • Script:
    scripts/ad-account-manager.js
  • Independent use: ✅ Can be called separately

2. Ad Writer

  • Function: Generate complete short drama scripts from creative ideas
  • Type: Prompt engineering (generated after Agent reads the guide)
  • Document:
    references/AD-WRITER-GUIDE.md
  • Dependency: ⚠️ X2C account binding required first

3. Ad Producer

  • Function: Generate complete video from script
  • Script:
    scripts/ad-producer.js
  • Dependency: ⚠️ X2C account binding required first

🚀 Quick Start

Step 1: Get X2C API Key

Users must complete the following steps by themselves:
  1. Open https://www.x2creel.ai to register/login
  2. Go to Personal Center → API Management → Create/Copy API Key
  3. Send the API Key to the assistant
Sample conversation:
User: I want to generate a video
Assistant: Okay, you need to bind your X2C account first. Please open https://www.x2creel.ai to log in, then get the API Key in the personal center and send it to me.
User: x2c_sk_xxx...
Assistant: Verification passed! Your account has been bound, you can start generating videos now~

Step 2: Verify API Key (automatically executed by Agent)

After the Agent receives the API Key, it calls
ad-account-manager.js verify-key
to verify validity:
bash
node scripts/ad-account-manager.js verify-key x2c_sk_xxx
After successful verification, the key is saved to
credentials/{USER_ID}.json

Step 3: View configuration and pricing

bash
node scripts/ad-producer.js config

Step 4: Generate short drama

Option A - Scriptwriting only (Agent mode): Agent reads
references/AD-WRITER-GUIDE.md
and generates scripts based on user ideas.
Option B - Full workflow (script + video):
bash
node scripts/ad-producer.js full-workflow "A programmer travels back to ancient times to be the prime minister" --duration 120 --wait

⚠️ Important Rules

Before the user provides a valid X2C API Key, it is forbidden to perform any video generation or script generation operations!
If the user requests to generate a video but has not bound an account:
  1. Guide the user to visit https://www.x2creel.ai
  2. Inform the steps to get the API Key
  3. Only enter the production process after receiving a valid key

📦 Ad Account Manager

Command List

bash
# Send verification code
node scripts/ad-account-manager.js send-code user@example.com

# Verify and get API Key
node scripts/ad-account-manager.js verify user@example.com 123456

# Check binding status
node scripts/ad-account-manager.js check-binding

# View configuration options
node scripts/ad-account-manager.js config

# Unbind account
node scripts/ad-account-manager.js unbind

# Help
node scripts/ad-account-manager.js help

Direct binding (if you already have an API Key)

bash
node scripts/ad-account-manager.js bind --key "x2c_sk_<REDACTED>xxx"

🎭 Ad Character Manager

Manage custom characters that can be used as protagonists in video production. During production, the system will automatically match characters with the characters in the script according to gender.
Note: Each user can have up to 5 characters.

Command List

bash
# Query character list
node scripts/ad-character-manager.js list

# Create character
node scripts/ad-character-manager.js create <name> <gender> <image_url>

# Delete character
node scripts/ad-character-manager.js delete <character_id>

# Help
node scripts/ad-character-manager.js help

Parameter Description

ParameterDescriptionRequiredOptions
nameCharacter display name-
genderGendermale, female, other
image_urlPublic URL of character image (max 10MB)-

Usage Example

bash
# View current characters
node scripts/ad-character-manager.js list

# Create female character
node scripts/ad-character-manager.js create Alice female https://example.com/alice.png

# Create male character
node scripts/ad-character-manager.js create Bob male https://example.com/bob.png

# Delete character
node scripts/ad-character-manager.js delete <uuid>

API Interface

ActionDescription
character/listQuery character list
character/createCreate character
character/deleteDelete character

✍️ Ad Writer

This is a prompt engineering module, the AI Agent generates the script by itself after reading the guide.

Features

  • Spielberg style: Warm humanity, visual poetry, emotional resonance
  • Three parallel storylines: current storyline, pre-history line, villain/external factor line
  • Industrial process: Strictly follow the physical production limits of the short drama market
  • **Complete script structure: drama name, synopsis, character biography, outline, episode breakdown, full script

Usage

Agent workflow:
  1. Read
    references/AD-WRITER-GUIDE.md
    (complete scriptwriting guide)
  2. Generate the script according to the user's idea and the guide
  3. Output the complete script in six parts
Sample user instruction:
Write me a short drama script: a programmer accidentally saves the CEO, but doesn't know the other person's real identity

Output Content

  1. Drama name
  2. One-sentence synopsis
  3. Character biography
  4. Story outline
  5. Episode overview (1-30 episodes)
  6. Full script (complete lines and shot descriptions)

🎬 Ad Producer

Command List

bash
# View configuration and pricing
node scripts/ad-producer.js config

# Generate script
node scripts/ad-producer.js generate-script "your idea" --wait

# Query script status
node scripts/ad-producer.js script-status <project_id>

# Produce video
node scripts/ad-producer.js produce-video <project_id> 1 --wait

# Query video progress
node scripts/ad-producer.js video-status <project_id> 1

# Full workflow (recommended)
node scripts/ad-producer.js full-workflow "idea description" --duration 120

Generation Options

ParameterDescriptionDefault Value
--modeshort_video / short_dramashort_video
--duration60 / 120 / 180 / 300120
--ratio9:16 / 16:99:16
--styleStyle name-
--episodesNumber of episodes (fixed value, cannot be customized by users)short_video=1, short_drama=10
--languagezh / enzh
--character-idsArray of character UUIDs (comma separated), used as protagonists-
--waitWait for completionfalse

Cost

ItemCreditsUSD
Script (short_video)10$0.1
Script (short_drama)100$1
Video 60s299$2.99
Video 120s599$5.99
Video 180s799$7.99
Video 300s999$9.99

🔄 Complete Workflow

Option A: Step-by-step execution

bash
# 1. Bind account (first use)
node scripts/ad-account-manager.js send-code your@email.com
node scripts/ad-account-manager.js verify your@email.com 123456

# 2. View pricing
node scripts/ad-producer.js config

# 3. Generate script
node scripts/ad-producer.js generate-script "A programmer travels back to ancient times" --wait
# → Get project_id

# 4. Produce video
node scripts/ad-producer.js produce-video <project_id> 1 --wait

Option B: One-click automation

bash
node scripts/ad-producer.js full-workflow "A programmer travels back to ancient times to be the prime minister" \
  --mode short_video \
  --duration 120 \
  --ratio 9:16

⚙️ Configuration File

config.json
:
json
{
  "x2cApiKey": "x2c_sk_<REDACTED>your_api_key_here",
  "x2cEmail": "your@email.com",
  "x2cUserId": "user-uuid"
}

🛡️ Security & Privacy

  • API keys are stored locally in
    config.json
  • Automatic desensitization when displayed
  • All API calls use HTTPS

🔧 Troubleshooting

Account not bound

❌ X2C Account Not Bound
Solution:
bash
node scripts/ad-account-manager.js send-code your@email.com
node scripts/ad-account-manager.js verify your@email.com <code>

Insufficient credits

❌ Error: Insufficient credits
Solution: Visit https://x2creel.ai to recharge

Invalid API Key

❌ Error: Invalid or missing API key
Solution:
bash
node scripts/ad-account-manager.js unbind
node scripts/ad-account-manager.js send-code your@email.com

📊 X2C Open API

Base URL:
https://eumfmgwxwjyagsvqloac.supabase.co/functions/v1/open-api

Interface List

ActionDescription
auth/send-codeSend verification code
auth/verifyVerify to get API Key
config/get-optionsGet configuration options
character/listQuery character list
character/createCreate character
character/deleteDelete character
script/generateGenerate script
script/queryQuery script status
video/produceProduce video
video/queryQuery video progress
For detailed API documentation, see
references/X2C-OPEN-API.md

📚 Document Reference

  • Scriptwriting Guide:
    references/AD-WRITER-GUIDE.md
  • Script Example:
    references/example.md
  • X2C API:
    references/X2C-OPEN-API.md

🎓 Best Practices

Cost Optimization

  1. Test with short_video first
    • 60s video cost is low (299 credits)
    • Confirm the style is satisfactory before making long videos
  2. Choose the appropriate duration
    • 60s: Short promotional video
    • 120s: Standard short drama (recommended)
    • 180s-300s: Complete plot

Improve Success Rate

  1. Clear and specific ideas
    • Clear protagonist, background, conflict
    • Avoid too abstract descriptions
  2. Choose the right style
    • Use the
      config
      command to view available styles
    • 3D ancient style, modern urban, etc.

Applicable scenarios: Commercial deployment, paid short drama generation service, B-side creation tools

🔍 Quality Evaluator

Use Gemini 2.0 Flash to analyze video quality and score according to standards.

Evaluation Dimensions

Dimension 1: Single clip quality (100 points)
IndicatorWeightDescription
Spatio-temporal consistency35%Subject characteristics remain stable in the shot
Dynamic dynamics30%Motion conforms to physical laws, no frame skipping
Visual purity20%Clear texture, no AI noise
Light and shadow interaction15%Shadows change synchronously with object movement
Dimension 2: Composite video quality (100 points)
IndicatorWeightDescription
Visual flow consistency30%Color tone matching between shots
Editing rhythm25%Natural transitions, matching BGM
Narrative matching degree25%Accurately convey the script plot
Audio and video synchronization rate20%Sound effects fit the vision

Usage

bash
# Evaluate a single video
node scripts/quality-evaluator.js <video_url> --prompt "original prompt"

# JSON output
node scripts/quality-evaluator.js <video_url> --json

Output Example

json
{
  "total_score": 75,
  "pass": false,
  "issues": ["Inconsistent character faces", "Unnatural light and shadow"],
  "suggestions": ["Simplify character description", "Clarify light source direction"],
  "prompt_improvements": "Improved prompt..."
}

🔄 Auto-Iterate

Automatic evaluation + prompt improvement + re-generation until the quality meets the standard.

Rules

  • Pass line: 80 points
  • Maximum iterations: 5 times
  • Each iteration: generate → evaluate → if failed, improve the prompt and try again

Usage

bash
node scripts/auto-iterate.js "your idea" \
  --duration 60 \
  --style "Ghibli" \
  --threshold 80 \
  --max-iterations 5

Configuration Requirements

config.json
needs to include:
json
{
  "x2cApiKey": "x2c_sk_<REDACTED>xxx",
  "geminiApiKey": "your_gemini_api_key"
}

Applicable scenarios: Commercial deployment, paid short drama generation service, B-side creation tools

📋 User Parameter Confirmation Format (Mandatory)

When a user requests to create a video, you must use text to let the user directly reply to the option to confirm the parameters. You must wait for the user to confirm all parameters before starting generation:
📋 Parameter Confirmation

Please reply with your choice:

🎬 Mode: Short drama (10 episodes) or Short video (1 episode)

⏱️ Duration/Price: 60s/299, 120s/599, 180s/799, 300s/999

📐 Ratio: Vertical (9:16) or Horizontal (16:9)

🎨 Style: 3D ancient style / 2D comic drama / Ghibli / Pixar / Realistic / Anime / Chinese ink wash

📂 Category: Fantasy / Suspense / Sci-fi / Urban / Popular / CEO romance / Xianxia

Example: "Short drama, 180s, vertical, 3D ancient style, Xianxia"

**Language**: Chinese / English

## ⚡ Asynchronous Task Processing (Important!)

When a user requests to generate a video, you must use **asynchronous mode**, do not wait for completion!

### Process:

1. **Start the task, do not wait**
```bash
# Start video generation, return project_id
USER_ID=$USER_ID node scripts/ad-producer.js full-workflow "theme" --mode short_video --duration 60 --style "style" --language zh
  1. Add task to tracking list (Mandatory!)
bash
# Immediately call after the video starts generating:
/opt/storyclaw/add-video-task.sh "$USER_ID" "$project_id" "$CHAT_ID"
# Parameters: user_id, project_id, chat_id (Telegram user ID)
  1. Automatic notification after completion
  • Cron job checks /tmp/active-video-tasks.json every 2 minutes
  • Automatically send a message to notify the user after completion

Key points:

  • Do not use --wait parameter, it will block
  • Return "Generating, please wait" immediately after starting the task
  • Must call add-video-task.sh to add the task to the tracking list
  • Create a cron job to monitor progress
  • Notify users through the corresponding channel after completion
When a user creates a short drama, the following 5 parameters can only be selected from the configuration options, custom values are not allowed:
  1. Mode:
    short_video
    or
    short_drama
  2. Duration:
    60
    /
    120
    /
    180
    /
    300
  3. Ratio:
    9:16
    or
    16:9
  4. Style:
    3D ancient style
    /
    2D comic drama
    /
    Ghibli
    /
    Pixar
    /
    Realistic
    /
    Anime
    /
    Chinese ink wash
  5. Category:
    • Chinese:
      Fantasy power
      /
      Suspense thriller
      /
      Sci-fi apocalypse
      /
      Urban revenge
      /
      Popular comprehensive
      /
      CEO romance
      /
      Xianxia ancient costume
    • English:
      Werewolf & Shifter
      /
      Suspense & Horror
      /
      Power & Revenge
      /
      Sweet & CEO
      /
      Magic & Fantasy
      /
      AI Drama Lab
If any item provided by the user is not in the configuration list, you must prompt the user to reselect from the list, and you are not allowed to replace or ignore it yourself.
Episode rule (Mandatory):
  • short_video
    → Fixed 1 episode, do not ask the user
  • short_drama
    → Fixed 10 episodes, do not ask the user
  • Users are not allowed to customize the number of episodes, and the episode option is not displayed in the guidance process

🎬 Video Production Process (Mandatory)

Important rule: Only one production can be initiated for the same episode

Only one
produce-video
command can be submitted per episode!
  • ✅ Can query
    video-status
    multiple times
  • ❌ Cannot submit
    produce-video
    repeatedly
If the task fails, wait for the third-party system to fix it, do not submit repeatedly.

short_video (1 episode)

1. Generate script
2. Video generation → Notify user after completion

short_drama (10 episodes) - Must be produced episode by episode

1. Generate script (10 episodes)
2. Wait for script completion
3. EP1 video generation → Wait for completion
4. EP2 video generation → Wait for completion
5. EP3 video generation → Wait for completion
...
10. EP10 video generation → Wait for completion
11. All completed → Notify user
Key points:
  • Must wait for the previous episode to complete before starting the next one, cannot be parallel
  • Record status after each episode is generated
  • Notify the user uniformly after all 10 episodes are completed
Call the
config/get-options
API to get the latest configuration list (styles and categories may be updated).

⚠️ Agent Output Specification

  1. Links must be output completely, not truncated (video URLs with signatures are very long, but must be complete)
  2. Use code blocks ``` to wrap long links to avoid being truncated by chat software
  3. Key information (Project ID, Video URL) must be clearly displayed

📢 Video Completion Notification Rule

In short drama (10 episodes) mode, you must ask the user whether to continue producing the next episode after the current episode is completed!
When an episode video is generated:
  1. Display the video link
  2. Display the credit consumption of this episode
  3. Ask the user whether to continue producing the next episode
Sample reply:
🎉 Video generation completed!

📊 Credit consumption: 599 credits

Continue to produce the next episode?
- Yes, continue EP3
- Pause for now
Note:
  • No need to ask for short_video (1 episode)
  • Must ask for short drama mode
  • After the user selects "Yes", initiate the production of the next episode

⚠️ Video Failure Handling Rule

After video generation fails, automatic retry generation is prohibited!
Reason: Each generation will deduct user credits, automatic retry will lead to additional deductions.
Handling process:
  1. Query the failure reason (view status and progress through the
    video-status
    command)
  2. Inform the user of the failure reason
  3. Wait for the user's instruction to retry or adjust parameters
Sample reply:
❌ Video generation failed
Reason: Character generation failed (character step failed at 14%)
Current balance: 20,013 credits

Please choose:
- Retry generation (corresponding credits will be deducted from the balance)
- Retry after changing style/parameters
- Cancel task

🔄 Multi-episode Short Drama Production Rule (short_drama)

Videos must be produced episode by episode, multiple episodes cannot be started at the same time. Process:
  1. Must pass the
    total_episodes
    parameter when generating the script (e.g.
    "total_episodes": 10
    ), otherwise only 1 episode will be generated
  2. Call
    video/produce
    to start the production of the first episode video
  3. Poll the status of the first episode, wait for completion
  4. After the first episode is completed, call
    video/produce
    to start the second episode
  5. Repeat until all episodes are completed
  6. Notify the user of the progress after each episode is completed (e.g. "EP3/10 completed")
  7. Send a total credit report after all are completed

🎬 Video Playback Optimization

The video URL returned by CDN has
&response-content-disposition=attachment
at the end, which will cause the browser to force download instead of playing.
Rule: After getting the video URL, you must remove the
&response-content-disposition=attachment
parameter, then it can be played directly in the browser without downloading to the local.
Process:
  1. Get the video URL (from the
    video-status
    command)
  2. Remove
    &response-content-disposition=attachment
  3. Directly
    browser navigate
    to the cleaned URL → can be played
  4. Ask the user if they need to download the video (no download by default, only play)
  5. If the user wants to download/send to Telegram: download + compress to below 16MB (480p, crf 32) before sending

📱 WebChat Message Push

WebChat is the web chat channel of StoryClaw devices, which pushes messages through the
webchat-stream-ws.sh
script.

Script Location

/opt/storyclaw/webchat-stream-ws.sh

Usage

bash
# Send new message (INSERT mode)
webchat-stream-ws.sh <user_id> --file <message_file> <agent_id>

# Update existing message (UPDATE mode)
webchat-stream-ws.sh <user_id> --update <message_id> --file <message_file> <agent_id>

Parameter Description

ParameterDescription
user_idWebChat user ID (32-bit hex)
message_idExisting message ID, used for update
message_fileFile path containing message content (must be passed with --file to avoid loss of $ symbol)
agent_idTarget agent ID (e.g.
director
)

Example

bash
# 1. Send confirmation message and get message_id
echo "Generating video..." > /tmp/msg.txt
MSG_ID=$(webchat-stream-ws.sh "180d08e23cdac976b4" --file /tmp/msg.txt "director")
echo "Message ID: $MSG_ID"

# 2. Update message after task completion
echo "✅ Video generation completed!" > /tmp/result.txt
webchat-stream-ws.sh "180d08e23cdac976b4" --update "$MSG_ID" --file /tmp/result.txt "director"

Notes

  1. Must use --file mode — passing text directly will cause loss of
    $
    symbol
  2. message_id is used for in-place update — avoid generating multiple messages
  3. Cooperate with asynchronous tasks — for long tasks such as video generation, send a "processing" message first, then update after the task is completed

Video Task Progress Push

When using
add-video-task.sh
to add a task, the chat_id format determines the notification channel:
bash
# WebChat push (chat_id format: webchat:<user_id>:<agent_id>)
add-video-task.sh "180d08e23cdac976b4" "project-id" "webchat:180d08e23cdac976b4:director"

# Telegram push (chat_id is pure number)
add-video-task.sh "5470522468" "project-id" "5470522468"
check-video-tasks.sh
will check the task status every 2 minutes, and automatically select the push channel according to the chat_id format.

Version: 2.1.2 (X2C Open API + WebChat push support)