feat(integrations): add Flue integration - #2774
Conversation
|
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
All reported issues were addressed across 20 files
Architecture diagram
sequenceDiagram
participant CLI as User CLI
participant Runner as run-agent.ts
participant Flue as @flue/runtime
participant Agent as agent/agent.ts
participant Tools as Flue Tool Adapters
participant Facade as StagehandFacadeTools
participant Browser as Browser Session
participant FS as Temp Filesystem
Note over CLI,FS: NEW: Flue Integration Runtime Flow
CLI->>Runner: pnpm start "Open https://example.com..."
Runner->>Runner: parse task from argv
Runner->>Flue: start({ agents: [StagehandAgent] })
Flue-->>Runner: flue runtime instance
Runner->>Flue: init(StagehandAgent, { id })
Flue-->>Runner: agent instance
Runner->>Flue: agent.dispatch(task)
Flue->>Agent: StagehandAgent() instructions
Note over Agent: Returns FLUE_STAGEHAND_INSTRUCTIONS<br/>(includes FACADE_AGENT_INSTRUCTIONS)
Flue->>Tools: run tool call (code)
Tools->>Tools: validate with Zod facade schema
Tools->>Facade: getFacadeTools()
Facade->>Facade: lazy init session if needed
Facade->>Browser: launch (local or browserbase)
Browser-->>Facade: browser instance
Facade->>Facade: Stagehand.create()
Facade-->>Tools: tools: { run, snapshot, screenshot }
Tools->>Facade: tools.run(code)
Facade->>Browser: execute JavaScript
Browser-->>Facade: result
Facade-->>Tools: result object
Tools->>Tools: stringifyResult()
Tools-->>Flue: string response
alt Screenshot tool
Flue->>Tools: screenshot tool call
Tools->>Tools: validate with Zod facade schema
Tools->>Facade: tools.screenshot(input)
Facade->>Browser: capture page
Browser-->>Facade: { data: base64, mimeType }
Facade-->>Tools: image data
Tools->>FS: writeScreenshotArtifact()
FS-->>Tools: { path, mimeType }
Tools-->>Flue: { output: { path, mimeType } }
end
alt Unhealthy browser detected
Tools->>Facade: discardFacadeToolsIfUnhealthy()
Facade->>Facade: check browser health
alt Browser closed or unreachable
Facade->>Facade: discardFacadeTools()
Facade->>Facade: schedule closeResources()
end
end
Flue-->>Runner: agent.read(receipt)
Runner->>Runner: output reply.text
Note over Runner: SIGINT/SIGTERM handling
alt Interrupt received
Runner->>Flue: agent.abort()
end
Runner->>Agent: agent.abort()
Runner->>Facade: closeFacadeSession()
Facade->>Browser: stagehand.close()
Facade->>Browser: browser.close()
Runner->>Flue: flue.stop()
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
1 existing issue remains and no new issues found across 5 files (changes from recent commits).
Confidence score: 3/5
- In
packages/integrations/flue/agent/tools/screenshot.ts, suppliedqualityvalues can be fractional andtype: "png"can be accepted even though the facade rounds or ignores them, creating inconsistent screenshot behavior; require integer quality andtype: "jpeg"whenever quality is present in both validation paths.
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Re-trigger cubic
Resolve overview.mdx conflicts to include both Flue and fx entries. Drop the BROWSERBASE_PROJECT_ID row from the Flue README per browserbase#2777 (project ID is optional everywhere).
Why
Add a Flue example alongside the existing Eve and Pi native integrations, giving a Flue agent persistent Stagehand browser tools in-process without an MCP bridge.
What changed
Adds a runnable
@flue/runtimeintegration using Flue's Nodestart/init/dispatch/readloop.Binds the Stagehand facade as native
run,snapshot, andscreenshottools on one shared browser session.Validates tool arguments with the canonical facade Zod schemas; Flue's Valibot
inputis only the host adapterdefineToolrequires.Writes screenshots to a temporary file because Flue's tool loop is text-only.
Aborts the Flue submission on SIGINT and SIGTERM, then closes the browser and stops the runtime.
Adds unit tests, setup documentation, an integration guide, navigation, and a Flue icon.
Summary by cubic
Adds a native Flue integration that exposes Stagehand’s
run,snapshot, andscreenshottools over one persistent browser session without an MCP bridge. In Flue,screenshotnow returns a temporary file path and MIME type instead of image bytes because Flue’s tool loop is text-only.@browserbasehq/stagehand-integrations-example-flue-facade: one lazily created shared browser (src/session.ts), graceful cleanup on SIGINT/SIGTERM (src/run-agent.ts), and Flue’sstart/init/dispatch/readloop.valibotand are strict (no extra properties).runrequires exactly one ofcodeoractions. Screenshots are written to a temp file viasrc/artifacts.tsand returned as{ path, mimeType }.tests/tools.test.ts) cover input validation, tool routing, screenshot artifact writing, and a full Flue agent loop via a faux provider./v4/integrations/flue, icon, and links from overview/best-practices; resolves overview conflicts to include both Flue and fx; notes that CrewAI and Flue return screenshot file paths.@flue/runtime,valibot, and@earendil-works/pi-aito the catalog; wires the new package intopnpm-workspace.yaml,turbo.json, and updatespnpm-lock.yaml.FLUE_STAGEHAND_MODELselects the agent model (defaults toopenai/gpt-5.6-luna); choose the browser withSTAGEHAND_BROWSERand optionalBROWSERBASE_API_KEY. RemovedBROWSERBASE_PROJECT_IDmention from the Flue README (project ID is optional everywhere).Written for commit 942ad1e. Summary will update on new commits.