@crewhaus/tool-screen-capture 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -14
- package/src/index.test.ts +49 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-screen-capture",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Screenshot tool — returns Anthropic image content block for the BROW agent (Section 25 BROW)",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"test": "bun test src"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@crewhaus/computer-use-driver": "0.1.
|
|
16
|
-
"@crewhaus/errors": "0.1.
|
|
17
|
-
"@crewhaus/tool-builder": "0.1.
|
|
18
|
-
"@crewhaus/tool-catalog": "0.1.
|
|
15
|
+
"@crewhaus/computer-use-driver": "0.1.2",
|
|
16
|
+
"@crewhaus/errors": "0.1.2",
|
|
17
|
+
"@crewhaus/tool-builder": "0.1.2",
|
|
18
|
+
"@crewhaus/tool-catalog": "0.1.2",
|
|
19
19
|
"zod": "^3.23.8"
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"author": {
|
|
23
23
|
"name": "Max Meier",
|
|
24
|
-
"email": "max@
|
|
25
|
-
"url": "https://
|
|
24
|
+
"email": "max@crewhaus.ai",
|
|
25
|
+
"url": "https://crewhaus.ai"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
@@ -34,12 +34,7 @@
|
|
|
34
34
|
"url": "https://github.com/crewhaus/factory/issues"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
|
-
"access": "
|
|
37
|
+
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"files": [
|
|
40
|
-
"src",
|
|
41
|
-
"README.md",
|
|
42
|
-
"LICENSE",
|
|
43
|
-
"NOTICE"
|
|
44
|
-
]
|
|
39
|
+
"files": ["src", "README.md", "LICENSE", "NOTICE"]
|
|
45
40
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import type { Driver } from "@crewhaus/computer-use-driver";
|
|
3
|
-
import {
|
|
3
|
+
import { CrewhausError } from "@crewhaus/errors";
|
|
4
|
+
import { ScreenCaptureError, createScreenshotTool } from "./index.js";
|
|
4
5
|
|
|
5
6
|
function stubDriver(pngBytes: Uint8Array): Driver {
|
|
6
7
|
return {
|
|
@@ -48,4 +49,51 @@ describe("createScreenshotTool", () => {
|
|
|
48
49
|
expect(tool.classifyOutput).toBe(false);
|
|
49
50
|
expect(tool.name).toBe("Screenshot");
|
|
50
51
|
});
|
|
52
|
+
|
|
53
|
+
test("empty PNG still yields a well-formed image block with empty base64 data", async () => {
|
|
54
|
+
const driver = stubDriver(new Uint8Array(0));
|
|
55
|
+
const tool = createScreenshotTool({ driver });
|
|
56
|
+
const result = await tool.execute({}, {});
|
|
57
|
+
if (!Array.isArray(result)) throw new Error("expected ToolResultContent array");
|
|
58
|
+
const block = result[0];
|
|
59
|
+
if (block?.type !== "image") throw new Error("expected image block");
|
|
60
|
+
expect(block.source.data).toBe("");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("downscalePercent option is accepted (v0 ships verbatim PNG)", async () => {
|
|
64
|
+
const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
65
|
+
const driver = stubDriver(png);
|
|
66
|
+
const tool = createScreenshotTool({ driver, downscalePercent: 50 });
|
|
67
|
+
const result = await tool.execute({}, {});
|
|
68
|
+
if (!Array.isArray(result)) throw new Error("expected ToolResultContent array");
|
|
69
|
+
const block = result[0];
|
|
70
|
+
if (block?.type !== "image") throw new Error("expected image block");
|
|
71
|
+
// Still the original bytes — downscale is exposed but unimplemented in v0.
|
|
72
|
+
expect(Array.from(Buffer.from(block.source.data, "base64"))).toEqual(Array.from(png));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("ScreenCaptureError", () => {
|
|
77
|
+
test("carries the 'tool' error code, a stable name, and the message", () => {
|
|
78
|
+
const err = new ScreenCaptureError("driver lost the page");
|
|
79
|
+
expect(err).toBeInstanceOf(ScreenCaptureError);
|
|
80
|
+
expect(err).toBeInstanceOf(CrewhausError);
|
|
81
|
+
expect(err).toBeInstanceOf(Error);
|
|
82
|
+
expect(err.name).toBe("ScreenCaptureError");
|
|
83
|
+
expect(err.code).toBe("tool");
|
|
84
|
+
expect(err.message).toBe("driver lost the page");
|
|
85
|
+
expect(err.cause).toBeUndefined();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("forwards an underlying cause and serializes it via toJSON()", () => {
|
|
89
|
+
const root = new Error("ETIMEDOUT");
|
|
90
|
+
const err = new ScreenCaptureError("screenshot failed", root);
|
|
91
|
+
expect(err.cause).toBe(root);
|
|
92
|
+
expect(err.toJSON()).toEqual({
|
|
93
|
+
name: "ScreenCaptureError",
|
|
94
|
+
code: "tool",
|
|
95
|
+
message: "screenshot failed",
|
|
96
|
+
cause: { name: "Error", message: "ETIMEDOUT" },
|
|
97
|
+
});
|
|
98
|
+
});
|
|
51
99
|
});
|