Skip to content

feat(aistudio): add Google AI Studio browser automation adapter - #2288

Open
a179-sanae wants to merge 9 commits into
jackwener:mainfrom
a179-sanae:feat/aistudio-adapter
Open

feat(aistudio): add Google AI Studio browser automation adapter#2288
a179-sanae wants to merge 9 commits into
jackwener:mainfrom
a179-sanae:feat/aistudio-adapter

Conversation

@a179-sanae

@a179-sanae a179-sanae commented Aug 16, 2026

Copy link
Copy Markdown

Description

Adds a browser adapter for Google AI Studio to the built-in command set — upstreamed from a user-level adapter that has been running locally:

  • aistudio ask — text & image prompts with full Run settings (temperature, top-p, max tokens, system instruction, structured output, code execution, function calling, Google Search/Maps grounding, URL context, media resolution, stop sequences, safety settings), Markdown-preserving output via Copy-as-Markdown
  • aistudio image — image generation with local saving
  • aistudio models — live model picker discovery with category/availability filtering
  • aistudio status / aistudio whoami / aistudio login — session state and Google login flow helpers

Implementation notes:

  • Drives the real logged-in Chrome via the browser bridge (Strategy.COOKIE, browser: true), reusing the existing daemon/session machinery
  • The platform changes below keep behavior for existing adapters unchanged

Related issue: none

Type of Change

  • 🌐 New site adapter
  • ✨ New feature (browser daemon readiness tweaks)

Checklist

  • I ran the checks relevant to this PR (npx vitest run clis/aistudio/ — 4 files, 96 tests passed, 200+ assertions)
  • I updated tests or docs if needed
  • I included output or screenshots when useful (see below)

Documentation (if adding/modifying an adapter)

  • Added doc page under docs/adapters/docs/adapters/browser/aistudio.md
  • Updated docs/adapters/index.md table
  • Updated sidebar in docs/.vitepress/config.mts
  • Updated README.md / README.zh-CN.md (aistudio row in the built-in command tables)
  • Used positional args for the command's primary subject (prompt is positional in ask / image)
  • Normalized expected adapter failures to CliError subclasses (ArgumentError / EmptyResultError / AuthRequiredError / CommandExecutionError)

Platform changes

  • Soft profile preference (preferredContextId): --profile/OPENCLI_PROFILE remains a hard pin; the config-default profile is now a soft preference threaded through daemon readiness (/status?preferredContextId=). The daemon arbitrates it against live connections — falls back when only one profile is live, errors when multiple are connected and the default is offline — so readiness never hangs on a stale default.
  • CDP allowlist: add Browser.getWindowForTarget, Browser.setWindowBounds, Page.bringToFront so adapters can restore a minimized window before native key input.
  • Page.windowMode exposed for adapter reads.
  • cli-manifest.json registers the aistudio commands; docs in docs/adapters/browser/aistudio.md.

Happy to split the platform changes into a separate PR if preferred.

Screenshots / Output

$ opencli aistudio status
- Status: Connected
  Login: 'Yes'
  Model: null
  Url: https://aistudio.google.com/prompts/new_chat

$ opencli aistudio models
- model: gemini-3.7-flash
  name: Gemini 3.7 Flash
  category: text
  availability: available
- model: gemini-3.5-flash-lite
  name: Gemini 3.5 Flash Lite
  category: text
  availability: available

Browser-driven commands for Google AI Studio: ask (prompt with model/settings control), image (generation with local export), models, status, plus cookie-based login/whoami via the shared site-auth helper. Includes zh-CN DOM fixtures and unit tests. Synced from the runtime copy at ~/.opencli/clis/aistudio; text prompts default to gemini-3.7-flash.
…t, guard toggles

- waitForAIStudioResponse: complete-but-empty shells and still-decoding images are exempt from the 45s stall detector, making the dedicated 60s empty-shell timeout reachable again; streamed thinking text counts as activity so long reasoning phases no longer trip the detector
- empty-shell window restore is skipped in background window mode
- ask: remove --new-chat, which could never continue a conversation (ephemeral site session + model selection always navigates to /prompts/new_chat); every ask is now explicitly a fresh chat
- default text model configurable via OPENCLI_AISTUDIO_MODEL
- image: validate --max-output-tokens as a positive integer
- setAIStudioToggle: only issue the native CDP click when the synthesized click did not flip the switch; an unconditional retry double-toggled MDC switches on current AI Studio builds (found by live testing with the camelia profile)
- dedupe run-settings label i18n maps; fix indentation and whitespace nits

Verified live: status/models/ask (plain, run settings, env model override) and image generation with download; 88 adapter tests pass.
…mon readiness

Introduce preferredContextId alongside the hard contextId pin: the daemon arbitrates the config-default profile against live connections (falls back when only one profile is live, errors when multiple are connected and the default is offline), so readiness never hangs on a stale default.

Also allow adapters to restore a minimized window before native key input via Browser.getWindowForTarget/setWindowBounds and Page.bringToFront in the CDP allowlist, and expose Page.windowMode for adapter reads. Rebuild extension dist.
# Conflicts:
#	src/browser/bridge.ts
#	src/browser/daemon-client.test.ts
#	src/browser/daemon-client.ts
#	src/browser/daemon-transport.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant