@nimrobo/wand-web 0.1.0

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.
@@ -0,0 +1,73 @@
1
+ import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export class WandStorage {
4
+ root;
5
+ contextDir;
6
+ queueDir;
7
+ tmpDir;
8
+ constructor(projectRoot) {
9
+ this.root = path.join(projectRoot, ".wand");
10
+ this.contextDir = path.join(this.root, "contexts");
11
+ this.queueDir = path.join(this.root, "queue");
12
+ this.tmpDir = path.join(this.root, "tmp");
13
+ }
14
+ async ensure() {
15
+ await Promise.all([
16
+ mkdir(this.contextDir, { recursive: true }),
17
+ mkdir(this.queueDir, { recursive: true }),
18
+ mkdir(this.tmpDir, { recursive: true }),
19
+ ]);
20
+ }
21
+ async persistCapture(capture) {
22
+ await this.ensure();
23
+ const elementHtmlPath = path.join(this.contextDir, `${capture.id}.html`);
24
+ const viewportScreenshotPath = path.join(this.tmpDir, `${capture.id}-viewport.png`);
25
+ const elementScreenshotPath = path.join(this.tmpDir, `${capture.id}-element.png`);
26
+ await Promise.all([
27
+ writeFile(elementHtmlPath, capture.elementHtml, "utf8"),
28
+ writeFile(viewportScreenshotPath, dataUrlToBuffer(capture.viewportDataUrl)),
29
+ writeFile(elementScreenshotPath, dataUrlToBuffer(capture.elementDataUrl)),
30
+ ]);
31
+ const persisted = {
32
+ ...capture,
33
+ contextPath: path.join(this.contextDir, `${capture.id}.json`),
34
+ elementHtmlPath,
35
+ viewportScreenshotPath,
36
+ elementScreenshotPath,
37
+ };
38
+ delete persisted.elementHtml;
39
+ delete persisted.viewportDataUrl;
40
+ delete persisted.elementDataUrl;
41
+ await writeFile(persisted.contextPath, `${JSON.stringify(persisted, null, 2)}\n`, "utf8");
42
+ return persisted;
43
+ }
44
+ async queue(prompt, context) {
45
+ await this.ensure();
46
+ const request = {
47
+ id: context.id,
48
+ createdAt: new Date().toISOString(),
49
+ prompt,
50
+ context,
51
+ };
52
+ await writeFile(path.join(this.queueDir, `${request.id}.json`), `${JSON.stringify(request, null, 2)}\n`, "utf8");
53
+ return request;
54
+ }
55
+ async listQueue() {
56
+ await this.ensure();
57
+ const entries = (await readdir(this.queueDir)).filter((entry) => entry.endsWith(".json"));
58
+ const items = await Promise.all(entries.map(async (entry) => {
59
+ const raw = await readFile(path.join(this.queueDir, entry), "utf8");
60
+ return JSON.parse(raw);
61
+ }));
62
+ return items.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
63
+ }
64
+ async removeQueued(id) {
65
+ await rm(path.join(this.queueDir, `${id}.json`), { force: true });
66
+ }
67
+ }
68
+ function dataUrlToBuffer(dataUrl) {
69
+ const match = dataUrl.match(/^data:image\/png;base64,(.+)$/);
70
+ if (!match)
71
+ throw new Error("Expected a PNG data URL.");
72
+ return Buffer.from(match[1], "base64");
73
+ }
@@ -0,0 +1,50 @@
1
+ import type { AdapterKind } from "@nimrobo/superconnector";
2
+ export type Rect = {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ };
8
+ export type ReactOwnerHint = {
9
+ name: string | null;
10
+ key: string | null;
11
+ source: string | null;
12
+ };
13
+ export type SelectionCapture = {
14
+ id: string;
15
+ createdAt: string;
16
+ url: string;
17
+ route: string;
18
+ title: string;
19
+ selector: string;
20
+ domPath: string[];
21
+ tagName: string;
22
+ text: string;
23
+ attributes: Record<string, string>;
24
+ rect: Rect;
25
+ reactOwnerHints: ReactOwnerHint[];
26
+ elementHtml: string;
27
+ viewportDataUrl: string;
28
+ elementDataUrl: string;
29
+ };
30
+ export type PersistedSelectionCapture = Omit<SelectionCapture, "elementHtml" | "viewportDataUrl" | "elementDataUrl"> & {
31
+ contextPath: string;
32
+ elementHtmlPath: string;
33
+ viewportScreenshotPath: string;
34
+ elementScreenshotPath: string;
35
+ };
36
+ export type QueuedRequest = {
37
+ id: string;
38
+ createdAt: string;
39
+ prompt: string;
40
+ context: PersistedSelectionCapture;
41
+ };
42
+ export type ActiveAgentRun = {
43
+ id: string;
44
+ createdAt: string;
45
+ prompt: string;
46
+ context: PersistedSelectionCapture;
47
+ adapter?: AdapterKind;
48
+ sessionId: string | null;
49
+ latestMessage: unknown | null;
50
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@nimrobo/wand-web",
3
+ "version": "0.1.0",
4
+ "description": "Framework-native dev inspector for web apps.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./runtime": {
14
+ "types": "./dist/runtime/index.d.ts",
15
+ "import": "./dist/runtime/index.js"
16
+ }
17
+ },
18
+ "bin": {
19
+ "wand": "./dist/bin.js"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsc -p tsconfig.json && node scripts/build-client.mjs",
26
+ "prepublishOnly": "npm run build",
27
+ "test": "npm run build && node --import tsx --test test/**/*.test.ts",
28
+ "test:next-production": "npm run build && node scripts/check-next-production.mjs"
29
+ },
30
+ "dependencies": {
31
+ "@nimrobo/superconnector": "^0.1.0",
32
+ "html-to-image": "^1.11.13"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^22.15.18",
36
+ "esbuild": "^0.28.0",
37
+ "jsdom": "^26.1.0",
38
+ "tsx": "^4.19.4",
39
+ "typescript": "^5.8.3"
40
+ },
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "keywords": [
45
+ "nextjs",
46
+ "dev-tool",
47
+ "inspector",
48
+ "overlay",
49
+ "wand"
50
+ ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/Nimrobo/wand-web.git"
54
+ },
55
+ "homepage": "https://github.com/Nimrobo/wand-web#readme",
56
+ "bugs": {
57
+ "url": "https://github.com/Nimrobo/wand-web/issues"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "license": "Apache-2.0"
63
+ }