feat: surface load secrets from integrations#130
Conversation
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…ructure in postCreateProfile
… fix Lets the enterprise autologin runner own the browser session and drive the agent against it, instead of relying on the model to emit createProfile. - Thread x-browserless-session-id (header) / browserlessSessionId (query) through hybridAuthenticate → ToolRunContext → agent tool as attachSessionId; the agent opens /chromium/agent?sessionId=<id> to attach to the runner's pre-created profile session. - Open-only fast-path: a createProfile call with no command opens the session and returns without hitting the agent route's id/method check. - autonomous-login skill: a signed-in account's visible display name usually won't equal the typed email/username — that is not a failure; judge success only by URL change / password-field absence / authed element, never by identity mismatch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…Session functions
WalkthroughAdds an ChangesattachSessionId Session Attachment
loadSecret Command Schema
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/lib/agent-client.ts (1)
234-246:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAlign attach-mode session keying with attach-mode behavior.
When
attachSessionIdis present,getOrCreateSessionskipscreateProfile, butgetSessionKeystill includescreateProfileand rawattachSessionId. That can fragment cache keys for the same attached session, hurt reuse/cleanup targeting, and leak raw session-id material into key space.Suggested fix
const getSessionKey = ( mcpSessionId: string | undefined, token: string, proxy?: ProxyOptions, profile?: string, createProfile?: CreateProfileParams, attachSessionId?: string, ): string => (mcpSessionId ?? `stdio:${hashToken(token)}`) + proxyFingerprint(proxy) + (profile ? KEY_SEP + 'profile#' + hashToken(profile) : '') + - (createProfile ? KEY_SEP + 'create#' + hashToken(createProfile.name) : '') + - (attachSessionId ? KEY_SEP + 'attach#' + attachSessionId : ''); + (!attachSessionId && createProfile + ? KEY_SEP + 'create#' + hashToken(createProfile.name) + : '') + + (attachSessionId + ? KEY_SEP + 'attach#' + hashToken(attachSessionId) + : '');Also applies to: 639-651
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/agent-client.ts` around lines 234 - 246, The getSessionKey function includes both createProfile and raw attachSessionId in the key, but this misaligns with how getOrCreateSession actually behaves—it skips createProfile when attachSessionId is present. This causes cache key fragmentation and leaks raw session ID material. Fix this by conditionally excluding createProfile from the key when attachSessionId is provided, and hash the attachSessionId value instead of including it raw (similar to how token, profile, and createProfile.name are hashed), so the key generation logic matches the actual session creation behavior.
🧹 Nitpick comments (1)
test/tools/schemas.spec.ts (1)
245-285: ⚡ Quick winAdd empty/whitespace
refnegative cases to this block.This suite checks missing
ref, but notref: ''or whitespace-only input. Adding both cases will harden the command contract and prevent silent regressions.Suggested tests
describe('loadSecret command', () => { @@ it('rejects a loadSecret command missing ref', () => { @@ expect(result.success).to.equal(false); }); + + it('rejects an empty ref', () => { + const result = AgentParamsSchema.safeParse({ + commands: [{ method: 'loadSecret', params: { ref: '' } }], + }); + expect(result.success).to.equal(false); + }); + + it('rejects a whitespace-only ref', () => { + const result = AgentParamsSchema.safeParse({ + commands: [{ method: 'loadSecret', params: { ref: ' ' } }], + }); + expect(result.success).to.equal(false); + }); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/tools/schemas.spec.ts` around lines 245 - 285, The loadSecret command test suite in the describe block currently only tests the case where ref is completely missing, but does not test cases where ref is present but empty or contains only whitespace. Add two additional test cases after the existing negative test: one that uses safeParse to verify AgentParamsSchema rejects a loadSecret command with ref set to an empty string, and another that verifies it rejects a loadSecret command with ref set to a whitespace-only string (such as spaces or tabs). Both tests should expect result.success to equal false to ensure the schema contract prevents silent regressions from invalid ref values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tools/agent.ts`:
- Around line 239-241: The text assignment logic currently prioritizes
createProfile over attachSessionId, but attach mode should take precedence
during session creation. Modify the ternary operator to check for
attachSessionId first before evaluating createProfile. When attachSessionId is
set, the text should return the generic browser session message or
attach-specific guidance instead of the profile-creation message, ensuring that
in mixed-input scenarios the correct guidance is provided based on which session
mode actually takes precedence.
In `@src/tools/schemas.ts`:
- Around line 168-178: Add validation to both the `ref` and `selector` fields to
prevent empty or whitespace-only strings. In the `ref` field definition, chain
`.trim().min(1)` after the `.describe()` method. In the `selector` field
definition, chain `.trim().min(1)` before the `.optional()` method so the
validation applies to non-empty trimmed strings when the field is provided. This
ensures both fields reject empty values and whitespace-only strings during
schema validation.
---
Outside diff comments:
In `@src/lib/agent-client.ts`:
- Around line 234-246: The getSessionKey function includes both createProfile
and raw attachSessionId in the key, but this misaligns with how
getOrCreateSession actually behaves—it skips createProfile when attachSessionId
is present. This causes cache key fragmentation and leaks raw session ID
material. Fix this by conditionally excluding createProfile from the key when
attachSessionId is provided, and hash the attachSessionId value instead of
including it raw (similar to how token, profile, and createProfile.name are
hashed), so the key generation logic matches the actual session creation
behavior.
---
Nitpick comments:
In `@test/tools/schemas.spec.ts`:
- Around line 245-285: The loadSecret command test suite in the describe block
currently only tests the case where ref is completely missing, but does not test
cases where ref is present but empty or contains only whitespace. Add two
additional test cases after the existing negative test: one that uses safeParse
to verify AgentParamsSchema rejects a loadSecret command with ref set to an
empty string, and another that verifies it rejects a loadSecret command with ref
set to a whitespace-only string (such as spaces or tabs). Both tests should
expect result.success to equal false to ensure the schema contract prevents
silent regressions from invalid ref values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6f4d666d-c882-41ad-8201-e9b30e5dc878
📒 Files selected for processing (8)
src/@types/types.d.tssrc/index.tssrc/lib/agent-client.tssrc/lib/define-tool.tssrc/skills/autonomous-login.mdsrc/tools/agent.tssrc/tools/schemas.tstest/tools/schemas.spec.ts
Summary by CodeRabbit
Release Notes
New Features
loadSecretcommand: Automatically inject stored credentials into form inputs during agent operations.Documentation