Skip to content

Commit 53889d4

Browse files
authored
fixed anthropic open operator (#598)
1 parent c57dc19 commit 53889d4

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

Diff for: .changeset/puny-garlics-join.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Fix the open operator handler to work with anthropic

Diff for: lib/handlers/operatorHandler.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,20 @@ export class StagehandOperatorHandler {
8585
type: "text",
8686
text: messageText,
8787
},
88-
{
89-
type: "image_url",
90-
image_url: { url: `data:image/png;base64,${base64Image}` },
91-
},
88+
this.llmClient.type === "anthropic"
89+
? {
90+
type: "image",
91+
source: {
92+
type: "base64",
93+
media_type: "image/png",
94+
data: base64Image,
95+
},
96+
text: "the screenshot of the current page",
97+
}
98+
: {
99+
type: "image_url",
100+
image_url: { url: `data:image/png;base64,${base64Image}` },
101+
},
92102
],
93103
});
94104
}

Diff for: lib/llm/LLMClient.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ export type ChatMessageContent =
1313
| (ChatMessageImageContent | ChatMessageTextContent)[];
1414

1515
export interface ChatMessageImageContent {
16-
type: "image_url";
17-
image_url: { url: string };
16+
type: string;
17+
image_url?: { url: string };
1818
text?: string;
19+
source?: {
20+
type: string;
21+
media_type: string;
22+
data: string;
23+
};
1924
}
2025

2126
export interface ChatMessageTextContent {

0 commit comments

Comments
 (0)