通过逆向工程的 Gemini Web API 进行文本和图像生成。
核心能力:
使用时机:
支持功能:
--sessionId 进行多轮对话重要: 所有脚本位于此技能的 scripts/ 子目录中。
Agent 执行说明:
SKILL_DIR${SKILL_DIR}/scripts/<script-name>.ts${SKILL_DIR} 替换为实际路径脚本参考:
| 脚本 | 用途 |
|---|---|
scripts/main.ts |
文本/图像生成的 CLI 入口点 |
scripts/gemini-webapi/* |
gemini_webapi 的 TypeScript 移植版(GeminiClient、类型、工具) |
使用此技能前,必须执行同意检查。
步骤 1: 检查同意文件
# macOS
cat ~/Library/Application\ Support/pw-skills/gemini-web/consent.json 2>/dev/null
# Linux
cat ~/.local/share/pw-skills/gemini-web/consent.json 2>/dev/null
# Windows (PowerShell)
Get-Content "$env:APPDATA\pw-skills\gemini-web\consent.json" 2>$null
步骤 2: 如果同意文件存在且 accepted: true 并匹配 disclaimerVersion: "1.0":
打印警告并继续:
⚠️ 警告: 使用逆向工程的 Gemini Web API(非官方)。接受时间: <acceptedAt 日期>
步骤 3: 如果同意文件不存在或 disclaimerVersion 不匹配:
显示免责声明并询问用户:
⚠️ 免责声明
此工具使用逆向工程的 Gemini Web API,而非官方 Google API。
风险:
- 如果 Google 更改其 API,可能会在没有通知的情况下失效
- 没有官方支持或保证
- 使用风险自负
您是否接受这些条款并希望继续?
使用 AskUserQuestion 工具,选项为:
步骤 4: 接受后,创建同意文件:
# macOS
mkdir -p ~/Library/Application\ Support/pw-skills/gemini-web
cat > ~/Library/Application\ Support/pw-skills/gemini-web/consent.json << 'EOF'
{
"version": 1,
"accepted": true,
"acceptedAt": "<ISO 时间戳>",
"disclaimerVersion": "1.0"
}
EOF
# Linux
mkdir -p ~/.local/share/pw-skills/gemini-web
cat > ~/.local/share/pw-skills/gemini-web/consent.json << 'EOF'
{
"version": 1,
"accepted": true,
"acceptedAt": "<ISO 时间戳>",
"disclaimerVersion": "1.0"
}
EOF
步骤 5: 拒绝后,输出消息并停止:
用户拒绝了免责声明。退出。
npx -y bun ${SKILL_DIR}/scripts/main.ts "你好,Gemini"
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "解释量子计算"
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "一只可爱的猫" --image cat.png
npx -y bun ${SKILL_DIR}/scripts/main.ts --promptfiles system.md content.md --image out.png
# 多轮对话(agent 生成唯一的 sessionId)
npx -y bun ${SKILL_DIR}/scripts/main.ts "记住这个: 42" --sessionId my-unique-id-123
npx -y bun ${SKILL_DIR}/scripts/main.ts "什么数字?" --sessionId my-unique-id-123
# 简单提示(位置参数)
npx -y bun ${SKILL_DIR}/scripts/main.ts "你的提示内容"
# 显式提示标志
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "你的提示内容"
npx -y bun ${SKILL_DIR}/scripts/main.ts -p "你的提示内容"
# 选择模型
npx -y bun ${SKILL_DIR}/scripts/main.ts -p "你好" -m gemini-2.5-pro
# 从标准输入管道
echo "总结这个" | npx -y bun ${SKILL_DIR}/scripts/main.ts
# 使用默认路径生成图像(./generated.png)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "山上的日落" --image
# 使用自定义路径生成图像
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "一个可爱的机器人" --image robot.png
# 简写形式
npx -y bun ${SKILL_DIR}/scripts/main.ts "一条龙" --image=dragon.png
# 文本 + 图像 -> 文本
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "描述这张图片" --reference a.png
# 文本 + 图像 -> 图像
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "生成一个变体" --reference a.png --image out.png
# 纯文本(默认)
npx -y bun ${SKILL_DIR}/scripts/main.ts "你好"
# JSON 输出
npx -y bun ${SKILL_DIR}/scripts/main.ts "你好" --json
--prompt
--prompt "生成一只可爱的猫咪"--promptfiles <files...>
--promptfiles system.md content.md--model
gemini-3-pro (默认): 最新最强模型,推荐使用gemini-2.5-pro: 上一代 pro 版本,稳定性好gemini-2.5-flash: 快速轻量,适合简单任务--model gemini-2.5-flash--image [path]
generated.png (如果只写 --image 不带路径)--image (保存为 generated.png)--image cat.png (保存为 cat.png)--image=/path/to/output.png (使用等号语法)--reference <files...> (别名: --ref)
--reference photo.jpg (单张图片)--reference img1.png img2.png (多张图片)--sessionId
--sessionId task-abc123--list-sessions
--json
{
"text": "生成的文本内容",
"imagePath": "/path/to/image.png",
"sessionId": "task-abc123"
}
--login
--cookie-path
--profile-dir
--help (别名: -h)
gemini-3-pro - 默认,最新模型gemini-2.5-pro - 上一代 pro 版本gemini-2.5-flash - 快速、轻量级首次运行会打开浏览器进行 Google 认证。Cookies 会被缓存以供后续运行使用。
支持的浏览器(按顺序自动检测):
如需要,可使用 GEMINI_WEB_CHROME_PATH 环境变量覆盖。
# 强制刷新 cookie
npx -y bun ${SKILL_DIR}/scripts/main.ts --login
登录说明:
| 变量 | 说明 |
|---|---|
GEMINI_WEB_DATA_DIR |
数据目录 |
GEMINI_WEB_COOKIE_PATH |
Cookie 文件路径 |
GEMINI_WEB_CHROME_PROFILE_DIR |
Chrome 配置文件目录 |
GEMINI_WEB_CHROME_PATH |
Chrome 可执行文件路径 |
如果需要代理访问 Google 服务(例如在中国),请在运行前设置 HTTP_PROXY 和 HTTPS_PROXY 环境变量:
# 使用本地代理的示例
HTTP_PROXY=http://127.0.0.1:7890 HTTPS_PROXY=http://127.0.0.1:7890 npx -y bun ${SKILL_DIR}/scripts/main.ts "你好"
# 使用代理生成图像
HTTP_PROXY=http://127.0.0.1:7890 HTTPS_PROXY=http://127.0.0.1:7890 npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "一只猫" --image cat.png
# 使用代理刷新 cookie
HTTP_PROXY=http://127.0.0.1:7890 HTTPS_PROXY=http://127.0.0.1:7890 npx -y bun ${SKILL_DIR}/scripts/main.ts --login
注意: 环境变量必须与命令内联设置。Shell 配置文件设置(如 .bashrc)可能不会被子进程继承。
npx -y bun ${SKILL_DIR}/scripts/main.ts "法国的首都是什么?"
npx -y bun ${SKILL_DIR}/scripts/main.ts "一张金毛猎犬幼犬的逼真照片" --image puppy.png
npx -y bun ${SKILL_DIR}/scripts/main.ts "你好" --json | jq '.text'
# 将 system.md + content.md 连接作为提示
npx -y bun ${SKILL_DIR}/scripts/main.ts --promptfiles system.md content.md --image output.png
# 使用唯一 ID 开始会话(agent 生成此 ID)
npx -y bun ${SKILL_DIR}/scripts/main.ts "你是一个有帮助的数学导师。" --sessionId task-abc123
# 继续对话(记住上下文)
npx -y bun ${SKILL_DIR}/scripts/main.ts "2+2 等于多少?" --sessionId task-abc123
npx -y bun ${SKILL_DIR}/scripts/main.ts "现在乘以 10" --sessionId task-abc123
# 列出最近的会话(最多 100 个,按更新时间排序)
npx -y bun ${SKILL_DIR}/scripts/main.ts --list-sessions
批量处理最佳实践:
# 为目录生成固定的 session ID(使用目录路径的 hash)
DIR_PATH="/path/to/project"
SESSION_ID=$(echo -n "$DIR_PATH" | md5sum | cut -d' ' -f1)
# 批量处理该目录下的文件,使用同一个 session ID
npx -y bun ${SKILL_DIR}/scripts/main.ts "生成第一张图" --sessionId "$SESSION_ID" --image img1.png
npx -y bun ${SKILL_DIR}/scripts/main.ts "生成第二张图" --sessionId "$SESSION_ID" --image img2.png
npx -y bun ${SKILL_DIR}/scripts/main.ts "生成第三张图" --sessionId "$SESSION_ID" --image img3.png
会话文件存储在 ~/Library/Application Support/pw-skills/gemini-web/sessions/<id>.json 中,包含:
id: 会话 IDmetadata: 用于继续的 Gemini 聊天元数据messages: {role, content, timestamp, error?} 数组createdAt, updatedAt: 时间戳通过 EXTEND.md 进行自定义配置。
检查路径 (优先级顺序):
.pw-skills/pw-danger-gemini-web/EXTEND.md (项目级)~/.pw-skills/pw-danger-gemini-web/EXTEND.md (用户级)如果找到,在工作流之前加载。扩展内容会覆盖默认值。
错误: "Cookie expired" 或 "Authentication failed"
# 重新登录刷新 cookie
npx -y bun ${SKILL_DIR}/scripts/main.ts --login
错误: "Browser not found"
GEMINI_WEB_CHROME_PATH=/path/to/chrome npx -y bun ${SKILL_DIR}/scripts/main.ts --login
错误: "Login timeout" 或登录窗口一直等待
错误: "Connection refused" 或 "Network error"
HTTP_PROXY=http://127.0.0.1:7890 HTTPS_PROXY=http://127.0.0.1:7890 \
npx -y bun ${SKILL_DIR}/scripts/main.ts "你好"
错误: "Rate limit exceeded"
错误: "Failed to save image" 或 "Directory not found"
# 确保目录存在
mkdir -p /path/to/output
npx -y bun ${SKILL_DIR}/scripts/main.ts "一只猫" --image /path/to/output/cat.png
错误: "Image generation failed"
错误: "Reference image not found"
错误: "Session not found"
--list-sessions 查看可用会话错误: "Session corrupted"
# 删除损坏的会话文件
rm ~/Library/Application\ Support/pw-skills/gemini-web/sessions/<session-id>.json
# 或在 Linux 上
rm ~/.local/share/pw-skills/gemini-web/sessions/<session-id>.json
错误: "Bun not found"
npx -y bun 会自动下载 Bun,无需手动安装错误: "Permission denied"
1. Session ID 管理
task-<uuid> 或 project-<hash># 为目录生成固定 session ID
SESSION_ID=$(echo -n "/path/to/project" | md5sum | cut -d' ' -f1)
2. 错误处理
--json 输出便于解析结果if ! output=$(npx -y bun ${SKILL_DIR}/scripts/main.ts "test" --json 2>&1); then
echo "Error: $output"
exit 1
fi
3. 代理配置
# 检测是否需要代理
if [[ $(curl -s -o /dev/null -w "%{http_code}" https://gemini.google.com) != "200" ]]; then
echo "提示: 可能需要配置代理访问 Google 服务"
fi
4. 批量处理
--json 输出便于批量解析for file in *.txt; do
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--promptfiles "$file" \
--sessionId "$SESSION_ID" \
--image "${file%.txt}.png" \
--json
sleep 2 # 避免限流
done
1. 提示词优化
2. 模型选择
gemini-3-progemini-2.5-flashgemini-3-pro3. 参考图像使用
# 基于参考图生成变体
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--prompt "生成一个卡通风格的变体,保持主体不变" \
--reference original.jpg \
--image cartoon.png
1. 上下文管理
# 第一轮: 设置角色
npx -y bun ${SKILL_DIR}/scripts/main.ts \
"你是一个专业的图像描述专家" \
--sessionId img-desc-001
# 后续轮次: 描述图像
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--prompt "描述这张图片" \
--reference photo.jpg \
--sessionId img-desc-001
2. 会话清理
--list-sessions 查看会话列表# macOS
rm ~/Library/Application\ Support/pw-skills/gemini-web/sessions/<id>.json
# Linux
rm ~/.local/share/pw-skills/gemini-web/sessions/<id>.json
1. 减少不必要的请求
--promptfiles 组合多个文件2. 并行处理
3. 缓存策略
1. 凭证管理
2. 内容审查
3. 数据隐私
遇到问题时,按以下顺序检查:
检查网络连接
curl -I https://gemini.google.com
检查认证状态
npx -y bun ${SKILL_DIR}/scripts/main.ts --login
检查浏览器
which chrome || which chromium || which microsoft-edge
检查文件权限
ls -la ~/Library/Application\ Support/pw-skills/gemini-web/
检查输出目录
mkdir -p /path/to/output && ls -la /path/to/output
查看详细错误
npx -y bun ${SKILL_DIR}/scripts/main.ts "test" 2>&1 | tee error.log
测试基本功能
# 测试文本生成
npx -y bun ${SKILL_DIR}/scripts/main.ts "你好"
# 测试图像生成
npx -y bun ${SKILL_DIR}/scripts/main.ts "一只猫" --image test.png
已知限制:
不支持的功能:
性能特征:
查看项目 Git 历史了解最新变更:
cd ${SKILL_DIR}
git log --oneline --decorate