Skip to content

Commit df9a79f

Browse files
author
Michal Wysocki
committed
Passing the whole ClientOptions into CUA
1 parent 5229258 commit df9a79f

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

lib/agent/AgentProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
UnsupportedModelError,
88
UnsupportedModelProviderError,
99
} from "@/types/stagehandErrors";
10+
import { ClientOptions } from "@/types/model";
1011

1112
// Map model names to their provider types
1213
const modelToAgentProviderMap: Record<string, AgentType> = {
@@ -32,7 +33,7 @@ export class AgentProvider {
3233

3334
getClient(
3435
modelName: string,
35-
clientOptions?: Record<string, unknown>,
36+
clientOptions?: ClientOptions & Record<string, unknown>,
3637
userProvidedInstructions?: string,
3738
): AgentClient {
3839
const type = AgentProvider.getAgentProvider(modelName);

lib/agent/AnthropicCUAClient.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import Anthropic from "@anthropic-ai/sdk";
1+
import Anthropic, {
2+
type ClientOptions as AnthropicClientOptions,
3+
} from "@anthropic-ai/sdk";
24
import { LogLine } from "@/types/log";
35
import {
46
AgentAction,
@@ -35,7 +37,7 @@ export class AnthropicCUAClient extends AgentClient {
3537
type: AgentType,
3638
modelName: string,
3739
userProvidedInstructions?: string,
38-
clientOptions?: Record<string, unknown>,
40+
clientOptions?: AnthropicClientOptions & Record<string, unknown>,
3941
) {
4042
super(type, modelName, userProvidedInstructions);
4143

@@ -53,13 +55,7 @@ export class AnthropicCUAClient extends AgentClient {
5355
}
5456

5557
// Store client options for reference
56-
this.clientOptions = {
57-
apiKey: this.apiKey,
58-
};
59-
60-
if (this.baseURL) {
61-
this.clientOptions.baseUrl = this.baseURL;
62-
}
58+
this.clientOptions = clientOptions;
6359

6460
// Initialize the Anthropic client
6561
this.client = new Anthropic(this.clientOptions);

lib/agent/OpenAICUAClient.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import OpenAI from "openai";
1+
import OpenAI, { type ClientOptions as OpenAIClientOptions } from "openai";
22
import { LogLine } from "../../types/log";
33
import {
44
AgentAction,
@@ -34,7 +34,7 @@ export class OpenAICUAClient extends AgentClient {
3434
type: AgentType,
3535
modelName: string,
3636
userProvidedInstructions?: string,
37-
clientOptions?: Record<string, unknown>,
37+
clientOptions?: OpenAIClientOptions & Record<string, unknown>,
3838
) {
3939
super(type, modelName, userProvidedInstructions);
4040

@@ -54,9 +54,7 @@ export class OpenAICUAClient extends AgentClient {
5454
}
5555

5656
// Store client options for reference
57-
this.clientOptions = {
58-
apiKey: this.apiKey,
59-
};
57+
this.clientOptions = clientOptions;
6058

6159
if (this.baseURL) {
6260
this.clientOptions.baseURL = this.baseURL;

types/agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LogLine } from "./log";
2+
import { ClientOptions } from "@/types/model";
23

34
export interface AgentAction {
45
type: string;
@@ -44,7 +45,7 @@ export interface AgentExecutionOptions {
4445

4546
export interface AgentHandlerOptions {
4647
modelName: string;
47-
clientOptions?: Record<string, unknown>;
48+
clientOptions?: ClientOptions & Record<string, unknown>;
4849
userProvidedInstructions?: string;
4950
agentType: AgentType;
5051
}

types/stagehand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export interface AgentConfig {
255255
/**
256256
* Additional options to pass to the agent client
257257
*/
258-
options?: Record<string, unknown>;
258+
options?: ClientOptions & Record<string, unknown>;
259259
}
260260

261261
export enum StagehandFunctionName {

0 commit comments

Comments
 (0)