@proagentstore/cli 0.1.0 → 0.1.1
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
1
3
|
import { mkdirSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
3
5
|
import { pathToFileURL } from "node:url";
|
|
4
6
|
import { RunnerStore } from "./store.js";
|
|
5
7
|
const CAPABILITIES = [
|
|
@@ -10,12 +12,14 @@ const CAPABILITIES = [
|
|
|
10
12
|
"human.approval",
|
|
11
13
|
];
|
|
12
14
|
const APPROVAL_REQUIRED_TASKS = new Set(["browser.open"]);
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
13
16
|
export class RunnerInputError extends Error {
|
|
14
17
|
status = 400;
|
|
15
18
|
}
|
|
16
19
|
export class LocalRunner {
|
|
17
20
|
config;
|
|
18
21
|
browserContext = null;
|
|
22
|
+
chromiumInstallChecked = false;
|
|
19
23
|
store;
|
|
20
24
|
constructor(config) {
|
|
21
25
|
this.config = config;
|
|
@@ -167,6 +171,7 @@ export class LocalRunner {
|
|
|
167
171
|
async getBrowserContext() {
|
|
168
172
|
if (this.browserContext)
|
|
169
173
|
return this.browserContext;
|
|
174
|
+
this.ensureChromiumInstalled();
|
|
170
175
|
const profileDir = join(this.config.dataDir, "browser-profile");
|
|
171
176
|
const downloadsPath = join(this.config.dataDir, "downloads");
|
|
172
177
|
mkdirSync(profileDir, { recursive: true });
|
|
@@ -181,6 +186,21 @@ export class LocalRunner {
|
|
|
181
186
|
});
|
|
182
187
|
return this.browserContext;
|
|
183
188
|
}
|
|
189
|
+
ensureChromiumInstalled() {
|
|
190
|
+
if (this.chromiumInstallChecked)
|
|
191
|
+
return;
|
|
192
|
+
this.chromiumInstallChecked = true;
|
|
193
|
+
if (process.env.PAGS_SKIP_PLAYWRIGHT_INSTALL === "1")
|
|
194
|
+
return;
|
|
195
|
+
const cli = join(dirname(require.resolve("playwright")), "cli.js");
|
|
196
|
+
const result = spawnSync(process.execPath, [cli, "install", "chromium"], {
|
|
197
|
+
stdio: "inherit",
|
|
198
|
+
env: process.env,
|
|
199
|
+
});
|
|
200
|
+
if (result.status !== 0) {
|
|
201
|
+
throw new Error("Unable to install Playwright Chromium. Run `npx playwright install chromium` and retry.");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
184
204
|
}
|
|
185
205
|
function isRecord(value) {
|
|
186
206
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|