mcpField
B
baoyu-gemini-web

baoyu-gemini-web

github.com/zsyggg创意与媒体1.4k95 次安装22 周前更新
代码仓库

关于 baoyu-gemini-web

baoyu-gemini-web 是通过 Gemini 网页端进行文本和图像生成的 Skill,适合需要命令行或程序化调用的用户。它支持多轮会话、参考图像输入,并提供实验性视频生成接口。

主要功能

  1. 01生成文本和图像
  2. 02上传参考图像用于视觉任务
  3. 03通过会话 ID 延续多轮对话
  4. 04提供实验性视频生成接口
  5. 05支持命令行与 Executor API

适用场景

  1. 01通过命令行获取 Gemini 文本回复
  2. 02根据提示词生成并保存图像
  3. 03在连续对话中保留上下文
  4. 04上传图像进行视觉任务

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/zsyggg/paper-craft-skills --skill baoyu-gemini-web

安装后在 Claude Code 中输入/baoyu-gemini-web确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

scripts/
index.ts
get-cookie.ts
paths.ts
types.ts
main.ts
chrome-auth.ts
executor.ts
session-store.ts
client.ts
cookie-store.ts

详细介绍

Gemini Web 客户端

支持:

  • 文本生成
  • 图像生成(下载并保存)
  • 上传参考图像(附加图像以执行视觉任务)
  • 在同一执行器实例中进行多轮对话(keepSession)
  • 实验性视频生成(generateVideo)——Gemini 可能返回异步占位内容;下载可能需要通过 Gemini 网页界面完成

快速开始

npx -y bun scripts/main.ts "Hello, Gemini"
npx -y bun scripts/main.ts --prompt "Explain quantum computing"
npx -y bun scripts/main.ts --prompt "A cute cat" --image cat.png
npx -y bun scripts/main.ts --promptfiles system.md content.md --image out.png

# Multi-turn conversation (agent generates unique sessionId)
npx -y bun scripts/main.ts "Remember this: 42" --sessionId my-unique-id-123
npx -y bun scripts/main.ts "What number?" --sessionId my-unique-id-123

执行器选项(以编程方式使用)

此技能通常通过 createGeminiWebExecutor(geminiOptions) 使用(参见 scripts/executor.ts)。

GeminiWebOptions 中的关键选项:

  • referenceImages?: string | string[] 上传本地图像作为参考图像(视觉输入)。
  • keepSession?: boolean 重用 Gemini 的 chatMetadata,以便在多次调用之间继续同一对话(如果希望参考图像在多条消息之间保留,则必须启用)。
  • generateVideo?: string 生成视频并尽力下载到指定路径。Gemini 可能会返回 video_gen_chip(异步);这种情况下,必须打开 Gemini 网页界面下载结果。

注意:

  • generateVideo 不能与 generateImage / editImage 组合使用。
  • 当 keepSession=true 且设置了 referenceImages 时,每个执行器实例只会上传一次参考图像。

命令

文本生成
# Simple prompt (positional)
npx -y bun scripts/main.ts "Your prompt here"

# Explicit prompt flag
npx -y bun scripts/main.ts --prompt "Your prompt here"
npx -y bun scripts/main.ts -p "Your prompt here"

# With model selection
npx -y bun scripts/main.ts -p "Hello" -m gemini-2.5-pro

# Pipe from stdin
echo "Summarize this" | npx -y bun scripts/main.ts
图像生成
# Generate image with default path (./generated.png)
npx -y bun scripts/main.ts --prompt "A sunset over mountains" --image

# Generate image with custom path
npx -y bun scripts/main.ts --prompt "A cute robot" --image robot.png

# Shorthand
npx -y bun scripts/main.ts "A dragon" --image=dragon.png
输出格式
# Plain text (default)
npx -y bun scripts/main.ts "Hello"

# JSON output
npx -y bun scripts/main.ts "Hello" --json

选项

选项描述
--prompt <text>、-p提示词文本
--promptfiles <files...>从文件读取提示词(按顺序拼接)
--model <id>、-m模型:gemini-3-pro(默认)、gemini-2.5-pro、gemini-2.5-flash
--image [path]生成图像并保存到指定路径(默认:generated.png)
--sessionId <id>多轮对话的会话 ID(Agent 会生成唯一 ID)
--list-sessions列出已保存的会话(最多 100 个,按更新时间排序)
--json以 JSON 格式输出
--login仅刷新 Cookie,然后退出
--cookie-path <path>自定义 Cookie 文件路径
--profile-dir <path>Chrome 配置文件目录
--help、-h显示帮助

CLI 说明:scripts/main.ts 支持文本生成、图像生成,以及通过 --sessionId 进行多轮对话。参考图像和视频生成功能通过执行器 API 提供。

模型

  • gemini-3-pro - 默认模型,最新版本
  • gemini-2.5-pro - 上一代专业版模型
  • gemini-2.5-flash - 快速、轻量

身份验证

首次运行时会打开 Chrome,以便通过 Google 进行身份验证。Cookie 会缓存起来,供后续运行使用。

# Force cookie refresh
npx -y bun scripts/main.ts --login

环境变量

变量描述
GEMINI_WEB_DATA_DIR数据目录
GEMINI_WEB_COOKIE_PATHCookie 文件路径
GEMINI_WEB_CHROME_PROFILE_DIRChrome 配置文件目录
GEMINI_WEB_CHROME_PATHChrome 可执行文件路径

示例

生成文本回复
npx -y bun scripts/main.ts "What is the capital of France?"
生成图像
npx -y bun scripts/main.ts "A photorealistic image of a golden retriever puppy" --image puppy.png
获取 JSON 输出以供解析
npx -y bun scripts/main.ts "Hello" --json | jq '.text'
根据提示词文件生成图像
# Concatenate system.md + content.md as prompt
npx -y bun scripts/main.ts --promptfiles system.md content.md --image output.png
多轮对话
# Start a session with unique ID (agent generates this)
npx -y bun scripts/main.ts "You are a helpful math tutor." --sessionId task-abc123

# Continue the conversation (remembers context)
npx -y bun scripts/main.ts "What is 2+2?" --sessionId task-abc123
npx -y bun scripts/main.ts "Now multiply that by 10" --sessionId task-abc123

# List recent sessions (max 100, sorted by update time)
npx -y bun scripts/main.ts --list-sessions

会话文件存储在 ~/Library/Application Support/baoyu-skills/gemini-web/sessions/<id>.json 中,包含:

  • id:会话 ID
  • metadata:用于继续对话的 Gemini 聊天元数据
  • messages:{role, content, timestamp, error?} 数组
  • createdAt、updatedAt:时间戳

评论

支持 Markdown