Skip to content

Conversation

@tkattkat
Copy link
Collaborator

why

currently when importing zod vrom zod/v3, and extracting a non object, it will throw an error "def is undefined"

what changed

replace static z.object with factory.object, to ensure we always wrap it in correct zod versions schema

test plan

tested locally

@tkattkat tkattkat added act These changes pertain to the act function extract These changes pertain to the extract function labels Nov 20, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2025

🦋 Changeset detected

Latest commit: 2fb7c42

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

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Patch
@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

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 20, 2025

Greptile Overview

Greptile Summary

Fixed zod v3/v4 compatibility issue when extracting non-object schemas by using getZFactory instead of static z.object to wrap schemas with the correct zod version.

  • Exported getZFactory from utils.ts to make it available to extractHandler.ts
  • Modified extractHandler.ts to use the factory pattern for wrapping non-object schemas, preventing "def is undefined" errors when using zod v3
  • The fix ensures that when a non-object schema is passed to extract(), it gets wrapped in an object using the same zod version as the original schema

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is minimal, focused, and follows the existing pattern used throughout utils.ts for handling zod v3/v4 compatibility. The function was already being used internally in 5 other locations in the same file, and exporting it is a safe change.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/core/lib/utils.ts 5/5 Exports getZFactory to enable correct zod version detection for schema operations
packages/core/lib/v3/handlers/extractHandler.ts 5/5 Uses getZFactory instead of static z.object to handle non-object schema wrapping with correct zod version

Sequence Diagram

sequenceDiagram
    participant User
    participant ExtractHandler
    participant getZFactory
    participant ZodFactory
    participant transformSchema

    User->>ExtractHandler: extract(params with non-object schema)
    ExtractHandler->>ExtractHandler: check if schema is object
    alt Schema is not object
        ExtractHandler->>getZFactory: getZFactory(baseSchema)
        getZFactory->>getZFactory: check isZod4Schema(schema)
        alt Zod v4
            getZFactory-->>ExtractHandler: return zFactories.v4
        else Zod v3
            getZFactory-->>ExtractHandler: return zFactories.v3
        end
        ExtractHandler->>ZodFactory: factory.object({ value: baseSchema })
        ZodFactory-->>ExtractHandler: wrapped object schema
    else Schema is object
        ExtractHandler->>ExtractHandler: use baseSchema directly
    end
    ExtractHandler->>transformSchema: transformUrlStringsToNumericIds(objectSchema)
    transformSchema-->>ExtractHandler: [transformedSchema, urlFieldPaths]
    ExtractHandler->>User: return extracted data
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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@tkattkat tkattkat merged commit 91a1ca0 into main Nov 20, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act These changes pertain to the act function extract These changes pertain to the extract function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants