Skip to content

Using 'mode' enum instead of old 'cua' boolean#1611

Merged
monadoid merged 5 commits intomainfrom
replace_cua_with_mode_enum
Jan 26, 2026
Merged

Using 'mode' enum instead of old 'cua' boolean#1611
monadoid merged 5 commits intomainfrom
replace_cua_with_mode_enum

Conversation

@monadoid
Copy link
Contributor

@monadoid monadoid commented Jan 26, 2026

why

Discord user reported that the mode property isn't typed in the Python SDK, which was due to the OpenAPI spec being out of date

what changed

Replaced cua boolean field with mode enum in zod objects + regenerated openapi spec.

test plan


Summary by cubic

Updated agent config to use a mode enum (dom, hybrid, cua) instead of the old cua boolean, and regenerated the OpenAPI spec. Kept cua for backward compatibility but deprecated; mode takes precedence if both are set.

  • Migration
    • Use agentConfig.mode; cua is deprecated but still accepted. If both are set, mode overrides cua.
    • Valid values: dom, hybrid, cua.

Written for commit 9efc0db. Summary will update on new commits. Review in cubic

@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2026

🦋 Changeset detected

Latest commit: 9efc0db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand-server Minor
@browserbasehq/stagehand Minor
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

✱ Stainless preview builds

This PR will update the stagehand SDKs with the following commit message.

feat: Using 'mode' enum instead of old 'cua' boolean

Edit this comment to update it. It will appear in the SDK's changelogs.

stagehand-typescript studio · code · diff

Your SDK built successfully.
generate ✅build ✅lint ✅test ❗

npm install https://pkg.stainless.com/s/stagehand-typescript/285063f1febf32c08dce84fa3b3fad23bc275a96/dist.tar.gz
stagehand-kotlin studio · code · diff

Your SDK built successfully.
generate ✅lint ✅test ✅

stagehand-ruby studio · code · diff

Your SDK built successfully.
generate ✅lint ✅test ✅

stagehand-php studio · code · diff

Your SDK built successfully.
generate ✅lint ✅test ✅

stagehand-java studio · code · diff

Your SDK built successfully.
generate ⚠️lint ❗test ❗

stagehand-csharp studio · code · diff

Your SDK built successfully.
generate ⚠️lint ❗test ✅

stagehand-openapi studio · code · diff

generate ✅lint ⏳test ⏳

stagehand-go studio · code · diff

Your SDK built successfully.
generate ✅lint ✅test ✅

go get github.com/stainless-sdks/stagehand-go@27929eb4fb9ae5d026bdfcd674779af3fc867e53
stagehand-python studio · conflict

⏳ These are partial results; builds are still running.


This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push.
If you push custom code to the preview branch, re-run this workflow to update the comment.
Last updated: 2026-01-26 22:54:45 UTC

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

This PR updates the OpenAPI spec to replace the deprecated cua boolean field with a mode enum that accepts "dom", "hybrid", or "cua" values. This change aligns the API spec with the SDK implementation and fixes the missing mode type in the Python SDK.

Key changes:

  • Replaced agentConfig.cua: boolean with agentConfig.mode: enum["dom", "hybrid", "cua"] in the zod schema
  • Updated the API client to send mode instead of cua when making agent execute requests
  • Regenerated the OpenAPI spec with the new mode field in both AgentConfig and AgentConfigOutput schemas
  • Added changeset documenting this as a minor version bump

Backward compatibility:
The SDK implementation at packages/core/lib/v3/v3.ts:1737 maintains backward compatibility by accepting both mode: "cua" and the deprecated cua: true option, with deprecation warnings for the latter. However, the OpenAPI spec itself no longer defines the cua field, which means API clients generated from this spec will only support the mode field.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are straightforward and well-executed. The SDK layer maintains backward compatibility for existing users, while the OpenAPI spec is properly updated to reflect the new enum-based approach. All changed files are schema definitions and client code that correctly propagate the mode field. No logic errors or security issues detected.
  • No files require special attention

Important Files Changed

Filename Overview
.changeset/shy-clouds-type.md Changeset file documenting the minor version bump for replacing cua boolean with mode enum in OpenAPI spec
packages/core/lib/v3/api.ts Updated API client to send mode field instead of cua when making agent execute requests
packages/core/lib/v3/types/public/api.ts Changed AgentConfig schema from cua: boolean to mode: enum["dom", "hybrid", "cua"] with proper metadata
packages/server/openapi.v3.yaml Updated both AgentConfig and AgentConfigOutput schemas to use mode enum instead of cua boolean

Sequence Diagram

sequenceDiagram
    participant Client as SDK Client
    participant APIClient as StagehandAPIClient
    participant Server as Server API
    participant Agent as Agent Instance
    
    Client->>APIClient: agent({ mode: "cua" })
    Note over Client,APIClient: AgentConfig with mode enum
    
    APIClient->>APIClient: prepareModelConfig()
    APIClient->>APIClient: Build wireAgentConfig
    Note over APIClient: wireAgentConfig.mode = agentConfig.mode
    
    APIClient->>Server: POST /sessions/:id/agentExecute
    Note over APIClient,Server: AgentExecuteRequest with mode field
    
    Server->>Server: Validate AgentExecuteRequestSchema
    Note over Server: Schema expects mode: "dom" | "hybrid" | "cua"
    
    Server->>Agent: stagehand.agent(normalizedAgentConfig)
    Note over Agent: Agent created with mode field
    
    Agent->>Agent: Determine isCuaMode
    Note over Agent: mode === "cua" || cua === true
    
    Agent-->>Server: AgentResult
    Server-->>APIClient: AgentExecuteResponse
    APIClient-->>Client: Result
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@@ -0,0 +1,6 @@
---
"@browserbasehq/stagehand-server": minor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirming -- is this minor b/c we're updating the API contract? If so, makes sense to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Confidence score: 3/5

  • There’s a concrete risk of user-facing regression: packages/server/openapi.v3.yaml introduces a breaking API change (replacing cua boolean with mode) without the required integration test coverage.
  • Score reflects a medium risk change to the REST API surface; without tests, downstream clients could break unexpectedly.
  • Pay close attention to packages/server/openapi.v3.yaml - breaking API change needs integration test coverage under packages/server/test.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/server/openapi.v3.yaml">

<violation number="1" location="packages/server/openapi.v3.yaml:666">
P1: Rule violated: **Any breaking changes to Stagehand REST API client / server implementation must be covered by an integration test under packages/server/test**

Breaking API change (replacing `cua` boolean with `mode` enum) is not covered by an integration test under packages/server/test/**, violating the API test coverage rule.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant User as Client Code
    participant SDK as StagehandAPIClient
    participant Zod as AgentConfigSchema
    participant Server as Stagehand API

    Note over User,SDK: Flow: Agent Configuration & Execution

    User->>SDK: execute({ ..., mode: "dom" | "hybrid" | "cua" })
    
    SDK->>Zod: Validate Config
    Note right of Zod: CHANGED: Validates 'mode' enum<br/>instead of 'cua' boolean
    
    alt Invalid Configuration
        Zod-->>SDK: Error
        SDK-->>User: Throw Validation Error
    else Valid Configuration
        Zod-->>SDK: Validated Object
    end

    SDK->>SDK: NEW: Assign 'mode' to wireAgentConfig
    
    SDK->>Server: POST /v1/agent/execute
    Note right of SDK: Payload JSON:<br/>{ "mode": "cua", ... }
    
    alt Success
        Server-->>SDK: 200 OK (AgentAction)
        SDK-->>User: Return Result
    else Schema Mismatch
        Server-->>SDK: 400 Bad Request
        Note right of Server: Server OpenAPI spec<br/>now expects 'mode'
        SDK-->>User: Throw API Error
    end
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/core/lib/v3/api.ts">

<violation number="1" location="packages/core/lib/v3/api.ts:364">
P2: Legacy `cua` configs are forwarded without mapping to the new `mode` enum, so `agentConfig.cua = true` will send no `mode` and can silently fall back to the default mode on the updated API. Map the deprecated boolean to `mode: "cua"` when `mode` is undefined to preserve legacy behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@monadoid
Copy link
Contributor Author

@cubic-dev-ai

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Jan 26, 2026

@cubic-dev-ai

@monadoid I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 10 files

Confidence score: 3/5

  • The main risk is an API schema change adding a new mode enum in packages/core/lib/v3/types/public/api.ts without the required integration test, so regressions in client/server compatibility could slip through.
  • Given the medium severity (6/10) and high confidence, there’s some user-facing risk if consumers depend on the previous schema.
  • Pay close attention to packages/core/lib/v3/types/public/api.ts - ensure the new enum field is covered by an integration test under packages/server/test.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/core/lib/v3/types/public/api.ts">

<violation number="1" location="packages/core/lib/v3/types/public/api.ts:608">
P2: Rule violated: **Any breaking changes to Stagehand REST API client / server implementation must be covered by an integration test under packages/server/test**

This API schema change adds a new `mode` enum field but lacks integration test coverage in `packages/server/test/**`. The rule requires that changes to shared request/response shapes in `packages/core/**/types/public/api.ts` be covered by integration tests.

Consider adding tests that verify:
1. Server accepts valid `mode` values (`'dom'`, `'hybrid'`, `'cua'`)
2. Server rejects invalid `mode` values
3. `mode` correctly takes precedence over deprecated `cua` when both are set</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Client as User Code
    participant SDK as StagehandAPIClient
    participant Server as V3 Server/Agent
    participant Utils as Validation & Cache

    Note over Client,Utils: Runtime Config Resolution: 'mode' vs 'cua'

    Client->>SDK: execute({ mode: "dom", cua: true })
    Note right of Client: Mixed Config (Transition State)

    SDK->>SDK: CHANGED: Normalization Logic
    Note right of SDK: If mode is set, use it.<br/>If only cua=true, fill mode="cua".

    SDK->>Server: POST /agentExecute
    Note right of SDK: Payload includes updated 'mode'<br/>and deprecated 'cua'

    Server->>Server: CHANGED: Resolve 'isCuaMode'
    alt agentConfig.mode is defined
        Server->>Server: Evaluate mode (e.g. "dom")
        Note right of Server: PRECEDENCE: "dom" overrides<br/>cua=true. isCuaMode=false.
    else mode undefined
        Server->>Server: Fallback to agentConfig.cua
    end

    Server->>Utils: validateExperimentalFeatures(isCuaMode)
    alt isCuaMode == true
        Utils->>Utils: Enforce CUA strict validation
    else isCuaMode == false (DOM/Hybrid)
        Utils-->>Server: Validation OK
    end

    Server->>Utils: AgentCache.get(config)
    Utils->>Utils: CHANGED: Generate key using resolved mode
    Note right of Utils: Cache key now relies on<br/>enum value rather than boolean
    Utils-->>Server: Cache result/miss

    Server-->>Client: Agent Result
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@monadoid monadoid merged commit 8a3c066 into main Jan 26, 2026
29 checks passed
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.

2 participants