Skip to content

Commit 5732405

Browse files
fix(openai/anthropic): extend tool schema for computer use
1 parent 4d7dd31 commit 5732405

File tree

6 files changed

+317
-190
lines changed

6 files changed

+317
-190
lines changed

libs/providers/langchain-anthropic/src/tools/computer.ts

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,12 @@ import type {
55
Computer20251124Action,
66
Computer20250124Action,
77
} from "./types.js";
8+
import {
9+
Computer20251124ActionSchema,
10+
Computer20250124ActionSchema,
11+
} from "./types.js";
812

913
const TOOL_NAME = "computer";
10-
const BASE_COMMANDS = [
11-
"screenshot",
12-
"left_click",
13-
"right_click",
14-
"middle_click",
15-
"double_click",
16-
"triple_click",
17-
"left_click_drag",
18-
"left_mouse_down",
19-
"left_mouse_up",
20-
"scroll",
21-
"type",
22-
"key",
23-
"mouse_move",
24-
"hold_key",
25-
"wait",
26-
];
2714

2815
/**
2916
* Options for the computer use tool (Claude Opus 4.5 only version).
@@ -122,16 +109,7 @@ export function computer_20251124(
122109
) => string | Promise<string>,
123110
{
124111
name,
125-
schema: {
126-
type: "object",
127-
properties: {
128-
action: {
129-
type: "string",
130-
enum: [...BASE_COMMANDS, "zoom"],
131-
},
132-
},
133-
required: ["action"],
134-
},
112+
schema: Computer20251124ActionSchema,
135113
}
136114
);
137115

@@ -247,16 +225,7 @@ export function computer_20250124(
247225
) => string | Promise<string>,
248226
{
249227
name,
250-
schema: {
251-
type: "object",
252-
properties: {
253-
action: {
254-
type: "string",
255-
enum: BASE_COMMANDS,
256-
},
257-
},
258-
required: ["action"],
259-
},
228+
schema: Computer20250124ActionSchema,
260229
}
261230
);
262231

libs/providers/langchain-anthropic/src/tools/tests/computer.test.ts

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,24 @@ describe("Anthropic Computer Use Tool Unit Tests", () => {
6262
displayHeightPx: 768,
6363
});
6464

65-
expect(computer.schema).toMatchInlineSnapshot(`
66-
{
67-
"properties": {
68-
"action": {
69-
"enum": [
70-
"screenshot",
71-
"left_click",
72-
"right_click",
73-
"middle_click",
74-
"double_click",
75-
"triple_click",
76-
"left_click_drag",
77-
"left_mouse_down",
78-
"left_mouse_up",
79-
"scroll",
80-
"type",
81-
"key",
82-
"mouse_move",
83-
"hold_key",
84-
"wait",
85-
"zoom",
86-
],
87-
"type": "string",
88-
},
89-
},
90-
"required": [
91-
"action",
92-
],
93-
"type": "object",
94-
}
95-
`);
65+
expect(computer.schema).toMatchObject({
66+
type: "object",
67+
oneOf: expect.arrayContaining([
68+
expect.objectContaining({
69+
properties: expect.objectContaining({
70+
action: expect.objectContaining({ const: "screenshot" }),
71+
}),
72+
}),
73+
expect.objectContaining({
74+
properties: expect.objectContaining({
75+
action: expect.objectContaining({ const: "zoom" }),
76+
}),
77+
}),
78+
]),
79+
});
80+
// Verify all action types are present
81+
const oneOf = (computer.schema as { oneOf: unknown[] }).oneOf;
82+
expect(oneOf).toHaveLength(16); // 15 base actions + zoom
9683
});
9784
});
9885

@@ -154,36 +141,34 @@ describe("Anthropic Computer Use Tool Unit Tests", () => {
154141
displayHeightPx: 768,
155142
});
156143

157-
expect(computer.schema).toMatchInlineSnapshot(`
158-
{
159-
"properties": {
160-
"action": {
161-
"enum": [
162-
"screenshot",
163-
"left_click",
164-
"right_click",
165-
"middle_click",
166-
"double_click",
167-
"triple_click",
168-
"left_click_drag",
169-
"left_mouse_down",
170-
"left_mouse_up",
171-
"scroll",
172-
"type",
173-
"key",
174-
"mouse_move",
175-
"hold_key",
176-
"wait",
177-
],
178-
"type": "string",
179-
},
180-
},
181-
"required": [
182-
"action",
183-
],
184-
"type": "object",
185-
}
186-
`);
144+
expect(computer.schema).toMatchObject({
145+
type: "object",
146+
oneOf: expect.arrayContaining([
147+
expect.objectContaining({
148+
properties: expect.objectContaining({
149+
action: expect.objectContaining({ const: "screenshot" }),
150+
}),
151+
}),
152+
]),
153+
});
154+
// Verify all action types are present (no zoom)
155+
const oneOf = (computer.schema as { oneOf: unknown[] }).oneOf;
156+
expect(oneOf).toHaveLength(15); // 15 base actions, no zoom
157+
// Verify zoom is not present
158+
const hasZoom = oneOf.some(
159+
(item: unknown) =>
160+
typeof item === "object" &&
161+
item !== null &&
162+
"properties" in item &&
163+
typeof item.properties === "object" &&
164+
item.properties !== null &&
165+
"action" in item.properties &&
166+
typeof item.properties.action === "object" &&
167+
item.properties.action !== null &&
168+
"const" in item.properties.action &&
169+
item.properties.action.const === "zoom"
170+
);
171+
expect(hasZoom).toBe(false);
187172
});
188173
});
189174
});

0 commit comments

Comments
 (0)