feat: AUTO-247 stamp x-browserless-client marker on agent WS upgrades#177
feat: AUTO-247 stamp x-browserless-client marker on agent WS upgrades#177devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Sean Yang <sean@browserless.io>
Original prompt from Sean Yang
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
WalkthroughAdds client-source attribution to authentication, agent session context, WebSocket upgrade headers, reconnects, and tests. The default ChangesClient source attribution
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AgentTool as browserless_agent
participant Session as getOrCreateSession
participant Connect as connect
participant WS as WebSocket
AgentTool->>Session: Pass clientSource
Session->>Connect: Create session with clientSource
Connect->>WS: Send x-browserless-client headers
Session->>Session: Store clientSource on ActiveSession
Session->>Connect: Reuse clientSource on reconnect
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
x-browserless-clientheader on every/chromium/agentWebSocket upgrade so enterprise Amplitude can distinguish agent traffic that comes through the MCP server from direct WS clients.mcp, but forward a recognized inbound sub-source (currentlyscript_generator) end-to-end so the Script Generator's traffic is attributable separately.Related issues
Changes
src/lib/agent-client.ts: addbuildClientHeaders(clientSource?)and pass it as theheadersoption on the singlenew WebSocket(...)call, so the normal,sessionId-attach, profile-create and reconnect flows all carry the marker. Also advertisesx-browserless-client-name/x-browserless-client-versionfrompackage.json(best-effort; failures just omit them).getOrCreateSessionaccepts aclientSource, stores it on theActiveSession, and replays it on reconnect.src/lib/http-auth.ts: read inboundx-browserless-client, normalizing it — onlyscript_generatoris forwarded verbatim; anything else (including missing/untrusted values) collapses tomcp, so a raw client can't impersonate an arbitrary source at the MCP boundary.src/index.ts,src/lib/define-tool.ts,src/tools/agent.ts,src/@types/types.d.ts: thread the resolved source through request → auth → session →ToolRunContext→ agent tool →getOrCreateSession→connect.mcpmarker lands on a normal connect, thatscript_generatoris forwarded verbatim, and that thesessionIdattach flow also carries the marker (withsessionIdstill in the URL).Enterprise reads this header on the agent endpoint and maps it to a
source(mcp|script_generator|direct) dimension on its AmplitudeBrowser Session Endedevents (separate PR inbrowserless/enterprise, plus a smallbrowserless/serverevent-type change).Test plan
npm testpasses locally (459 passing, incl. 3 new marker tests)npm run lintpasses locallynpm run coveragethresholds still metChecklist
Link to Devin session: https://app.devin.ai/sessions/e83e8132735c4677b42f3a470a8090fe
Requested by: @xsvfat
Summary by CodeRabbit
x-browserless-clientheader.script_generatorclient marker while defaulting other connections tomcp.