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
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. For Flue,screenshotnow returns a temporary file path and MIME type instead of binary because Flue’s tool loop is text-only.@browserbasehq/stagehand-integrations-example-flue-facade:src/session.tslazily creates and shares one browser, checks health, and cleans up;src/run-agent.tsaborts on SIGINT/SIGTERM and closes the browser and runtime.defineToolinputs withvalibot; inputs are strict (no extra properties) andrunnow requires exactly one ofcodeoractions.src/artifacts.tswrites screenshots to a temp directory and returns{ path, mimeType }.tests/tools.test.tscover input validation, tool wiring, and a full Flue agent loop via a faux provider./v4/integrations/fluewith quickstart and configuration; updates navigation and adds a Flue icon.@flue/runtimeandvalibotto the catalog,@earendil-works/pi-aifor tests, updatespnpm-lock.yaml, and wires typecheck inturbo.json.@browserbasehq/stagehand-integrations@browserbasehq/stagehand-integrations-example-flue-facadestart "Open https://example.com and report the page title."Written for commit cd3b493. Summary will update on new commits.