Repository navigation
🐬 type consolidation - #1117
🐬 type consolidation#1117
Conversation
|
There was a problem hiding this comment.
Greptile Overview
Summary
This PR implements a comprehensive type consolidation effort that reorganizes Stagehand's v3 type system from a monolithic `types.ts` file into a structured `types/` directory with domain-specific modules. The refactoring breaks out type definitions into logical groupings:- methods.ts: Act, extract, and observe method interfaces (
ActOptions,ExtractOptions,ObserveOptions,Action, etc.) - agent.ts: Agent configuration and execution types (
AgentConfig,AgentExecuteOptions,AgentResult) - logs.ts: Logging infrastructure (
LogLine,LogLevel,Logger) - sdkErrors.ts: SDK-specific error classes (renamed from
stagehandErrors.ts) - apiErrors.ts: API error classes (renamed from
stagehandApiErrors.ts) - internal.ts: Internal implementation types (
EncodedId,ZodPathSegments,InitState) - model.ts: Model and LLM provider types, now includes AISDK types previously in
llm.ts - page.ts: Browser page abstractions (
AnyPage,GotoOptions,LoadState) - metrics.ts: Performance tracking interface (
V3Metrics)
The reorganization includes creating a centralized types/index.ts that barrel-exports all type modules, updating 40+ files with new import paths, and removing now-empty type files (act.ts, llm.ts, playwright.ts, context.ts). The changes maintain full backward compatibility through proper re-exports while significantly improving code organization and maintainability.
Changed Files
| Filename | Score | Overview |
|---|---|---|
lib/inferenceLogUtils.ts |
5/5 | Minor import reordering for alphabetical consistency |
lib/v3/agent/AnthropicCUAClient.ts |
5/5 | Updates imports to new consolidated type structure |
lib/v3/handlers/handlerUtils/actHandlerUtils.ts |
5/5 | Moves StagehandClickError import to sdkErrors module |
lib/v3/llm/aisdk.ts |
5/5 | Updates LogLine import path from log to logs |
evals/tasks/observe_iframes2.ts |
5/5 | Moves Action type import to methods module |
lib/v3/handlers/observeHandler.ts |
5/5 | Reorganizes EncodedId and Action type imports |
lib/inference.ts |
5/5 | Updates LogLine import to use new logs module |
lib/v3/types/apiErrors.ts |
5/5 | Renames and consolidates API error classes |
lib/utils.ts |
5/5 | Updates imports and moves ID_PATTERN to local constant |
lib/v3/llm/AnthropicClient.ts |
5/5 | Updates import paths for logs and SDK errors |
lib/v3/llm/GoogleClient.ts |
5/5 | Reorganizes imports to match new type structure |
lib/v3/agent/tools/v3-extract.ts |
5/5 | Simple import path update for LogLine type |
.gitignore |
5/5 | Updates ignored paths for v3 architecture |
lib/v3/types/api.ts |
5/5 | Updates LogLine import to logs module |
lib/v3/types/model.ts |
4/5 | Consolidates model types, removes Zod validation for plain unions |
lib/v3/types/internal.ts |
5/5 | New file for internal implementation types |
lib/v3/types/metrics.ts |
5/5 | Extracts V3Metrics interface to dedicated module |
lib/logger.ts |
5/5 | Simple import path update for LogLine |
lib/v3/llm/LLMClient.ts |
5/5 | Reorganizes LLMTool and LogLine imports |
lib/v3/agent/OpenAICUAClient.ts |
5/5 | Updates imports for new type organization |
lib/v3/logger.ts |
4/5 | Implements sophisticated instance-based logging system |
lib/v3/llm/CerebrasClient.ts |
5/5 | Updates imports for logs and SDK errors |
lib/v3/types/sdkErrors.ts |
5/5 | Renames from stagehandErrors for better organization |
lib/v3/agent/tools/index.ts |
5/5 | Updates LogLine import to logs module |
lib/v3/agent/tools/v3-act.ts |
5/5 | Moves Action type import to methods module |
lib/v3/tests/v3.config.ts |
5/5 | Simple import path update for LogLine |
lib/v3/mcp/connection.ts |
5/5 | Updates MCPConnectionError import location |
lib/v3/handlers/extractHandler.ts |
5/5 | Consolidates EncodedId and ZodPathSegments imports |
lib/v3/llm/OpenAIClient.ts |
5/5 | Updates import paths for logs and SDK errors |
lib/v3/types/agent.ts |
4/5 | Consolidates agent types, adds Google provider support |
lib/v3/agent/StagehandAgent.ts |
5/5 | Simple import path update for LogLine |
lib/v3/handlers/v3CuaAgentHandler.ts |
5/5 | Updates LogLine and Action imports |
evals/logger.ts |
5/5 | Updates LogLine import to logs module |
lib/v3/tests/shadow-iframe.spec.ts |
5/5 | Moves Action import to methods module |
lib/v3/types/act.ts |
5/5 | File removed, types moved to methods.ts |
lib/v3/llm/GroqClient.ts |
5/5 | Updates imports for type consolidation |
lib/v3/types/llm.ts |
5/5 | File removed, types moved to model.ts |
lib/v3/types/playwright.ts |
5/5 | File emptied, types moved to page.ts |
lib/api.ts |
5/5 | Comprehensive import reorganization for new structure |
lib/v3/types/logs.ts |
5/5 | Renames from log.ts for consistency |
lib/v3/v3.ts |
5/5 | Updates imports for consolidated type structure |
lib/v3/agent/tools/v3-fillform.ts |
5/5 | Updates Action import to methods module |
lib/v3/handlers/actHandler.ts |
5/5 | Reorganizes imports for new type structure |
lib/v3/types/methods.ts |
1/5 | New consolidated file with critical duplicate definitions |
lib/v3/types/cache.ts |
5/5 | Updates Action import to methods module |
lib/v3/handlers/v3AgentHandler.ts |
5/5 | Simple LogLine import update |
lib/v3/llm/LLMProvider.ts |
5/5 | Updates imports for new type organization |
lib/v3/types/stagehand.ts |
4/5 | Major refactor removing all type definitions |
lib/v3/agent/AgentProvider.ts |
5/5 | Consolidates imports and renames AgentType |
lib/v3/types/evals.ts |
5/5 | Updates imports for consolidated structure |
evals/tasks/no_js_click.ts |
5/5 | Updates Action import to methods module |
lib/v3/types/index.ts |
4/5 | Creates central barrel export for all types |
lib/v3/types/page.ts |
5/5 | New file for page-related type definitions |
lib/v3/types/context.ts |
5/5 | File removed, types moved to internal.ts |
evals/tasks/google_flights.ts |
5/5 | Updates Action import to methods module |
lib/v3/index.ts |
5/5 | Simplifies exports using barrel export pattern |
lib/v3/types/options.ts |
4/5 | Extracts option types with extensive TODOs |
Confidence score: 2/5
- This PR contains serious structural issues that could break existing functionality, particularly duplicate interface definitions in methods.ts
- Score lowered due to critical problems in the core methods.ts file that consolidates essential type definitions
- Pay close attention to lib/v3/types/methods.ts which has duplicate ObserveOptions and HistoryEntry definitions that must be resolved
Sequence Diagram
sequenceDiagram
participant User as Developer
participant V3 as V3 Class
participant Types as Types Module (Old)
participant NewTypes as Types Folder (New)
participant ActHandler as ActHandler
participant ExtractHandler as ExtractHandler
participant ObserveHandler as ObserveHandler
Note over User, ObserveHandler: Type consolidation refactoring
User->>V3: Import V3 from "@/lib/v3/v3"
V3->>NewTypes: Import types from "./types/options"
V3->>NewTypes: Import types from "./types/methods"
V3->>NewTypes: Import types from "./types/agent"
V3->>NewTypes: Import types from "./types/logs"
V3->>NewTypes: Import types from "./types/internal"
Note over Types, NewTypes: Breaking out types.ts into structured modules
Types--xNewTypes: types.ts (deprecated)
NewTypes->>NewTypes: Create options.ts
NewTypes->>NewTypes: Create methods.ts
NewTypes->>NewTypes: Create agent.ts
NewTypes->>NewTypes: Create logs.ts
NewTypes->>NewTypes: Create internal.ts
NewTypes->>NewTypes: Create apiErrors.ts
NewTypes->>NewTypes: Create sdkErrors.ts
NewTypes->>NewTypes: Create evals.ts
NewTypes->>NewTypes: Create cache.ts
NewTypes->>NewTypes: Create metrics.ts
NewTypes->>NewTypes: Create model.ts
NewTypes->>NewTypes: Create page.ts
NewTypes->>NewTypes: Create index.ts (re-exports)
User->>V3: new V3(options)
V3->>ActHandler: Create ActHandler with types
ActHandler->>NewTypes: Import ActHandlerParams from "./types/methods"
V3->>ExtractHandler: Create ExtractHandler with types
ExtractHandler->>NewTypes: Import ExtractHandlerParams from "./types/methods"
V3->>ObserveHandler: Create ObserveHandler with types
ObserveHandler->>NewTypes: Import ObserveHandlerParams from "./types/methods"
User->>V3: Call v3.act(), v3.extract(), v3.observe()
V3->>ActHandler: Forward with properly typed parameters
V3->>ExtractHandler: Forward with properly typed parameters
V3->>ObserveHandler: Forward with properly typed parameters
Note over User, ObserveHandler: All type imports now reference organized modules
Context used:
Rule from dashboard - All PRs that make code changes must include a changeset to document the version bump and changes. (source)
57 files reviewed, 2 comments
| export interface ObserveOptions { | ||
| instruction?: string; | ||
| model?: ModelConfiguration; | ||
| domSettleTimeoutMs?: number; | ||
| returnAction?: boolean; | ||
| selector?: string; | ||
| /** | ||
| * @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions. | ||
| */ | ||
| onlyVisible?: boolean; | ||
| drawOverlay?: boolean; | ||
| iframes?: boolean; | ||
| frameId?: string; | ||
| } |
There was a problem hiding this comment.
logic: ObserveOptions is defined twice in this file (lines 28-41 and 99-104) with different properties. The second definition is missing several properties including instruction, domSettleTimeoutMs, returnAction, onlyVisible, drawOverlay, iframes, and frameId.
| export interface ObserveOptions { | |
| instruction?: string; | |
| model?: ModelConfiguration; | |
| domSettleTimeoutMs?: number; | |
| returnAction?: boolean; | |
| selector?: string; | |
| /** | |
| * @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions. | |
| */ | |
| onlyVisible?: boolean; | |
| drawOverlay?: boolean; | |
| iframes?: boolean; | |
| frameId?: string; | |
| } | |
| export interface ObserveOptions { | |
| instruction?: string; | |
| model?: ModelConfiguration; | |
| domSettleTimeoutMs?: number; | |
| returnAction?: boolean; | |
| selector?: string; | |
| /** | |
| * @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions. | |
| */ | |
| onlyVisible?: boolean; | |
| drawOverlay?: boolean; | |
| iframes?: boolean; | |
| frameId?: string; | |
| timeout?: number; | |
| page?: PlaywrightPage | PuppeteerPage | PatchrightPage | Page; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/v3/types/methods.ts
Line: 28:41
Comment:
**logic:** ObserveOptions is defined twice in this file (lines 28-41 and 99-104) with different properties. The second definition is missing several properties including instruction, domSettleTimeoutMs, returnAction, onlyVisible, drawOverlay, iframes, and frameId.
```suggestion
export interface ObserveOptions {
instruction?: string;
model?: ModelConfiguration;
domSettleTimeoutMs?: number;
returnAction?: boolean;
selector?: string;
/**
* @deprecated The `onlyVisible` parameter has no effect in this version of Stagehand and will be removed in later versions.
*/
onlyVisible?: boolean;
drawOverlay?: boolean;
iframes?: boolean;
frameId?: string;
timeout?: number;
page?: PlaywrightPage | PuppeteerPage | PatchrightPage | Page;
}
```
How can I resolve this? If you propose a fix, please make it concise.# why Type definitions are currently unorganized, this makes code more readable and easier to maintain. # what changed Broke out `types.ts` into a types folder with a structured distribution of the interfaces. # test plan
why
Type definitions are currently unorganized, this makes code more readable and easier to maintain.
what changed
Broke out
types.tsinto a types folder with a structured distribution of the interfaces.test plan