qazen-cli 0.1.4 → 0.1.5
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/dist/commands/visionScout.js +16 -2
- package/dist/lib/api.js +16 -0
- package/dist/lib/visionNavigator.js +7 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import ora from "ora";
|
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import Anthropic from "@anthropic-ai/sdk";
|
|
5
5
|
import { getConfig, isConfigured } from "../lib/config.js";
|
|
6
|
-
import { fetchProjects, uploadVisionDiscovery } from "../lib/api.js";
|
|
6
|
+
import { fetchProjects, uploadVisionDiscovery, fetchProjectAuthSession } from "../lib/api.js";
|
|
7
7
|
import { VisionNavigator } from "../lib/visionNavigator.js";
|
|
8
8
|
export async function visionScoutCommand(options) {
|
|
9
9
|
if (!isConfigured()) {
|
|
@@ -73,8 +73,22 @@ export async function visionScoutCommand(options) {
|
|
|
73
73
|
console.log(chalk.gray("\n Cancelled.\n"));
|
|
74
74
|
process.exit(0);
|
|
75
75
|
}
|
|
76
|
+
let storedSession = null;
|
|
77
|
+
try {
|
|
78
|
+
storedSession = await fetchProjectAuthSession(config.apiUrl, config.cliToken, project.id);
|
|
79
|
+
if (storedSession) {
|
|
80
|
+
console.log(chalk.green(" ✓ Loaded stored auth session"));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log(chalk.yellow(" ⚠ No stored session — browser will start unauthenticated"));
|
|
84
|
+
console.log(chalk.gray(" Tip: Run qazen record first to capture a session"));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
console.log(chalk.gray(" No stored session found"));
|
|
89
|
+
}
|
|
76
90
|
const anthropic = new Anthropic({ apiKey: anthropicKey });
|
|
77
|
-
const navigator = new VisionNavigator(anthropic, targetUrl, maxPages);
|
|
91
|
+
const navigator = new VisionNavigator(anthropic, targetUrl, maxPages, storedSession || undefined);
|
|
78
92
|
console.log("\n " + chalk.hex("#6366F1")("Starting Vision Scout...") + "\n");
|
|
79
93
|
try {
|
|
80
94
|
const result = await navigator.explore((event) => {
|
package/dist/lib/api.js
CHANGED
|
@@ -32,6 +32,22 @@ export async function uploadSession(apiUrl, cliToken, projectId, storageState, d
|
|
|
32
32
|
throw new Error(`Upload failed (HTTP ${res.status}): ${text}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
export async function fetchProjectAuthSession(apiUrl, cliToken, projectId) {
|
|
36
|
+
const response = await fetch(`${apiUrl}/api/cli/projects/${projectId}/session`, {
|
|
37
|
+
headers: authHeaders(cliToken),
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok)
|
|
40
|
+
return null;
|
|
41
|
+
const data = (await response.json());
|
|
42
|
+
if (!data.storageState)
|
|
43
|
+
return null;
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(data.storageState);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
35
51
|
export async function uploadVisionDiscovery(apiUrl, cliToken, projectId, result) {
|
|
36
52
|
const appMap = {
|
|
37
53
|
baseUrl: result.pages[0]?.url ?? "",
|
|
@@ -23,10 +23,13 @@ export class VisionNavigator {
|
|
|
23
23
|
browserContext;
|
|
24
24
|
page;
|
|
25
25
|
screenshotDir;
|
|
26
|
-
|
|
26
|
+
storageState;
|
|
27
|
+
constructor(anthropic, baseUrl, maxPages = 20, storageState) {
|
|
27
28
|
this.anthropic = anthropic;
|
|
28
29
|
this.baseUrl = baseUrl;
|
|
29
30
|
this.maxPages = maxPages;
|
|
31
|
+
if (storageState)
|
|
32
|
+
this.storageState = storageState;
|
|
30
33
|
this.screenshotDir = fs.mkdtempSync(path.join(os.tmpdir(), "qazen-vision-"));
|
|
31
34
|
}
|
|
32
35
|
async explore(onEvent) {
|
|
@@ -44,6 +47,9 @@ export class VisionNavigator {
|
|
|
44
47
|
viewport: { width: 1280, height: 720 },
|
|
45
48
|
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
|
46
49
|
ignoreHTTPSErrors: true,
|
|
50
|
+
...(this.storageState
|
|
51
|
+
? { storageState: this.storageState }
|
|
52
|
+
: {}),
|
|
47
53
|
});
|
|
48
54
|
await this.browserContext.addInitScript(() => {
|
|
49
55
|
Object.defineProperty(navigator, "webdriver", { get: () => false });
|