portal-agent-cli 3.0.3 → 3.0.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/LICENSE +0 -15
- package/README.md +0 -27
- package/lib/args.mjs +3 -12
- package/lib/browser.mjs +5 -20
- package/lib/config.mjs +3 -17
- package/lib/deepthink.mjs +4 -25
- package/lib/exec.mjs +1 -46
- package/lib/instructions.mjs +2 -32
- package/lib/log.mjs +5 -24
- package/lib/parse.mjs +4 -12
- package/lib/paste.mjs +6 -29
- package/lib/providers.mjs +11 -22
- package/lib/repl.mjs +1 -236
- package/lib/safety.mjs +36 -37
- package/lib/send.mjs +15 -24
- package/lib/sessions.mjs +1 -64
- package/lib/system.mjs +1 -40
- package/lib/theme.mjs +1 -5
- package/lib/tools/delete.mjs +1 -24
- package/lib/tools/edit.mjs +1 -46
- package/lib/tools/find.mjs +1 -38
- package/lib/tools/git.mjs +1 -49
- package/lib/tools/grep.mjs +1 -41
- package/lib/tools/index.mjs +1 -51
- package/lib/tools/list.mjs +1 -34
- package/lib/tools/path.mjs +1 -18
- package/lib/tools/read.mjs +1 -31
- package/lib/tools/shell.mjs +1 -59
- package/lib/tools/walk.mjs +1 -27
- package/lib/tools/write.mjs +1 -34
- package/lib/turn.mjs +1 -98
- package/lib/wait.mjs +2 -7
- package/package.json +1 -13
- package/portal.mjs +0 -4
package/LICENSE
CHANGED
|
@@ -4,18 +4,3 @@ Copyright (c) 2026
|
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
1
|
# portal-agent
|
|
2
|
-
|
|
3
|
-
Drive web AI products from the terminal with local tools.
|
|
4
|
-
|
|
5
|
-
Supports DeepSeek, ChatGPT, Gemini, and Grok.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
npm install -g portal-agent-cli
|
|
10
|
-
|
|
11
|
-
## Run
|
|
12
|
-
|
|
13
|
-
portal-agent --workspace F:/projects/my-app
|
|
14
|
-
|
|
15
|
-
## Commands
|
|
16
|
-
|
|
17
|
-
/help, /cd, /pwd, /provider, /providers, /deepthink,
|
|
18
|
-
/sessions, /queue, /status, /clear, /quit
|
|
19
|
-
|
|
20
|
-
## Tools
|
|
21
|
-
|
|
22
|
-
read_file, write_file, edit_file, append_file, undo_file,
|
|
23
|
-
list_files, find_files, grep_search, delete_file, move_file,
|
|
24
|
-
shell, git_status, git_diff, git_log
|
|
25
|
-
|
|
26
|
-
## License
|
|
27
|
-
|
|
28
|
-
MIT
|
package/lib/args.mjs
CHANGED
|
@@ -4,15 +4,8 @@ import { resolve } from "node:path";
|
|
|
4
4
|
export function parseArgs() {
|
|
5
5
|
const a = process.argv.slice(2);
|
|
6
6
|
const o = {
|
|
7
|
-
ws: null,
|
|
8
|
-
|
|
9
|
-
maxSteps: null,
|
|
10
|
-
timeout: null,
|
|
11
|
-
loginTimeout: null,
|
|
12
|
-
exec: null,
|
|
13
|
-
verbose: false,
|
|
14
|
-
yolo: false,
|
|
15
|
-
session: null,
|
|
7
|
+
ws: null, provider: null, maxSteps: null, timeout: null,
|
|
8
|
+
loginTimeout: null, exec: null, verbose: false, yolo: false,
|
|
16
9
|
resume: null
|
|
17
10
|
};
|
|
18
11
|
|
|
@@ -24,13 +17,12 @@ export function parseArgs() {
|
|
|
24
17
|
else if (t === "--timeout") o.timeout = Number(a[++i]);
|
|
25
18
|
else if (t === "--login-timeout") o.loginTimeout = Number(a[++i]);
|
|
26
19
|
else if (t === "--max-steps") o.maxSteps = Number(a[++i]);
|
|
27
|
-
else if (t === "--session") o.session = a[++i];
|
|
28
20
|
else if (t === "--resume") o.resume = a[++i];
|
|
29
21
|
else if (t === "--verbose" || t === "-V") o.verbose = true;
|
|
30
22
|
else if (t === "--yolo") o.yolo = true;
|
|
31
23
|
else if (t === "exec") { o.exec = a.slice(i + 1).join(" "); break; }
|
|
32
24
|
else if (t === "--help" || t === "-h") { help(); process.exit(0); }
|
|
33
|
-
else if (t === "--version" || t === "-v") { console.log("3.0.
|
|
25
|
+
else if (t === "--version" || t === "-v") { console.log("3.0.4"); process.exit(0); }
|
|
34
26
|
i++;
|
|
35
27
|
}
|
|
36
28
|
|
|
@@ -51,7 +43,6 @@ function help() {
|
|
|
51
43
|
console.log(" portal-agent [options]");
|
|
52
44
|
console.log(" portal-agent [options] exec <task>");
|
|
53
45
|
console.log("");
|
|
54
|
-
console.log("Options:");
|
|
55
46
|
console.log(" -w, --workspace <dir> folder the agent works in");
|
|
56
47
|
console.log(" -p, --provider <name> deepseek | chatgpt | gemini | grok");
|
|
57
48
|
console.log(" --timeout <ms> response timeout (default 180000)");
|
package/lib/browser.mjs
CHANGED
|
@@ -18,45 +18,30 @@ const CANDIDATES = [
|
|
|
18
18
|
];
|
|
19
19
|
|
|
20
20
|
export function findBrowser() {
|
|
21
|
-
for (const p of CANDIDATES)
|
|
22
|
-
if (p && existsSync(p)) return p;
|
|
23
|
-
}
|
|
21
|
+
for (const p of CANDIDATES) if (p && existsSync(p)) return p;
|
|
24
22
|
return null;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export async function launch() {
|
|
28
26
|
const exe = findBrowser();
|
|
29
|
-
if (!exe)
|
|
30
|
-
throw new Error(
|
|
31
|
-
"No Chrome, Chromium, Edge, or Brave found. " +
|
|
32
|
-
"Set PORTAL_BROWSER_PATH to your browser executable."
|
|
33
|
-
);
|
|
34
|
-
}
|
|
27
|
+
if (!exe) throw new Error("No Chrome found. Set PORTAL_BROWSER_PATH.");
|
|
35
28
|
|
|
36
29
|
const profileDir = join(homedir(), ".portal-agent", "browser");
|
|
37
30
|
await mkdir(profileDir, { recursive: true });
|
|
38
31
|
|
|
39
32
|
try {
|
|
40
33
|
const ctx = await chromium.launchPersistentContext(profileDir, {
|
|
41
|
-
executablePath: exe,
|
|
42
|
-
headless: false,
|
|
34
|
+
executablePath: exe, headless: false,
|
|
43
35
|
viewport: { width: 1280, height: 900 }
|
|
44
36
|
});
|
|
45
|
-
|
|
46
37
|
ctx.on("page", function (page) {
|
|
47
|
-
page.on("dialog", function (d) {
|
|
48
|
-
d.dismiss().catch(function () {});
|
|
49
|
-
});
|
|
38
|
+
page.on("dialog", function (d) { d.dismiss().catch(function () {}); });
|
|
50
39
|
});
|
|
51
|
-
|
|
52
40
|
return ctx;
|
|
53
41
|
} catch (e) {
|
|
54
42
|
const m = e.message || String(e);
|
|
55
43
|
if (m.indexOf("ProcessSingleton") >= 0 || m.indexOf("already running") >= 0) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
"Another Chrome window is using the Portal profile. " +
|
|
58
|
-
"Close every Chrome window and try again."
|
|
59
|
-
);
|
|
44
|
+
throw new Error("Another Chrome window is using the Portal profile.");
|
|
60
45
|
}
|
|
61
46
|
throw new Error("Failed to launch Chromium: " + m);
|
|
62
47
|
}
|
package/lib/config.mjs
CHANGED
|
@@ -8,7 +8,6 @@ const DEFAULTS = {
|
|
|
8
8
|
timeout: 180000,
|
|
9
9
|
loginTimeout: 600000,
|
|
10
10
|
yolo: false,
|
|
11
|
-
verbose: false,
|
|
12
11
|
ignored: [
|
|
13
12
|
"node_modules", ".git", ".hg", ".svn", "dist", "build", "out",
|
|
14
13
|
".next", ".nuxt", ".turbo", ".cache", "target", "__pycache__",
|
|
@@ -23,23 +22,17 @@ function configPath() {
|
|
|
23
22
|
function readGlobal() {
|
|
24
23
|
const p = configPath();
|
|
25
24
|
if (!existsSync(p)) return {};
|
|
26
|
-
try {
|
|
27
|
-
return JSON.parse(readFileSync(p, "utf8"));
|
|
28
|
-
} catch (e) {
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
25
|
+
try { return JSON.parse(readFileSync(p, "utf8")); } catch (e) { return {}; }
|
|
31
26
|
}
|
|
32
27
|
|
|
33
28
|
export async function loadConfig(args) {
|
|
34
29
|
const g = readGlobal();
|
|
35
|
-
|
|
36
30
|
const config = {
|
|
37
31
|
provider: g.provider || DEFAULTS.provider,
|
|
38
32
|
maxSteps: g.maxSteps || DEFAULTS.maxSteps,
|
|
39
33
|
timeout: g.timeout || DEFAULTS.timeout,
|
|
40
34
|
loginTimeout: g.loginTimeout || DEFAULTS.loginTimeout,
|
|
41
35
|
yolo: g.yolo || false,
|
|
42
|
-
verbose: g.verbose || false,
|
|
43
36
|
ignored: g.ignored || DEFAULTS.ignored,
|
|
44
37
|
ws: args.ws || process.env.PORTAL_WORKSPACE || process.cwd(),
|
|
45
38
|
exec: args.exec,
|
|
@@ -52,20 +45,13 @@ export async function loadConfig(args) {
|
|
|
52
45
|
if (args.timeout) config.timeout = args.timeout;
|
|
53
46
|
if (args.loginTimeout) config.loginTimeout = args.loginTimeout;
|
|
54
47
|
if (args.yolo || process.env.PORTAL_YOLO === "true") config.yolo = true;
|
|
55
|
-
if (args.verbose) config.verbose = true;
|
|
56
48
|
|
|
57
49
|
config.ws = resolve(config.ws);
|
|
58
|
-
if (!existsSync(config.ws))
|
|
59
|
-
throw new Error("workspace does not exist: " + config.ws);
|
|
60
|
-
}
|
|
50
|
+
if (!existsSync(config.ws)) throw new Error("workspace does not exist: " + config.ws);
|
|
61
51
|
|
|
62
52
|
const localPath = join(config.ws, "portal.config.json");
|
|
63
53
|
if (existsSync(localPath)) {
|
|
64
|
-
try {
|
|
65
|
-
const local = JSON.parse(readFileSync(localPath, "utf8"));
|
|
66
|
-
Object.assign(config, local);
|
|
67
|
-
} catch (e) {}
|
|
54
|
+
try { Object.assign(config, JSON.parse(readFileSync(localPath, "utf8"))); } catch (e) {}
|
|
68
55
|
}
|
|
69
|
-
|
|
70
56
|
return config;
|
|
71
57
|
}
|
package/lib/deepthink.mjs
CHANGED
|
@@ -1,45 +1,24 @@
|
|
|
1
1
|
export async function enableDeepThink(page) {
|
|
2
2
|
if (process.env.PORTAL_DEEPTHINK === "off") return false;
|
|
3
|
-
|
|
4
3
|
const btns = page.locator("button, [role=button], div[role=button]");
|
|
5
4
|
let total = 0;
|
|
6
|
-
try {
|
|
7
|
-
total = await btns.count();
|
|
8
|
-
} catch (e) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
5
|
+
try { total = await btns.count(); } catch (e) { return false; }
|
|
11
6
|
if (total === 0 || total > 400) return false;
|
|
12
7
|
|
|
13
8
|
for (let i = 0; i < total; i++) {
|
|
14
9
|
const b = btns.nth(i);
|
|
15
10
|
let text = "";
|
|
16
|
-
try {
|
|
17
|
-
text = ((await b.textContent()) || "").trim();
|
|
18
|
-
} catch (e) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
11
|
+
try { text = ((await b.textContent()) || "").trim(); } catch (e) { continue; }
|
|
21
12
|
if (!text) continue;
|
|
22
|
-
|
|
23
|
-
const hit = text === "DeepThink" ||
|
|
24
|
-
text === "Deep Think" ||
|
|
25
|
-
text.indexOf("DeepThink") >= 0;
|
|
26
|
-
|
|
27
|
-
if (!hit) continue;
|
|
13
|
+
if (text.indexOf("DeepThink") < 0 && text.indexOf("Deep Think") < 0) continue;
|
|
28
14
|
|
|
29
15
|
let pressed = "";
|
|
30
16
|
let cls = "";
|
|
31
17
|
try { pressed = (await b.getAttribute("aria-pressed")) || ""; } catch (e) {}
|
|
32
18
|
try { cls = (await b.getAttribute("class")) || ""; } catch (e) {}
|
|
33
|
-
|
|
34
19
|
if (pressed === "true" || /active|selected|on\b/i.test(cls)) return true;
|
|
35
20
|
|
|
36
|
-
try {
|
|
37
|
-
await b.click({ timeout: 2000 });
|
|
38
|
-
await new Promise(function (r) { setTimeout(r, 400); });
|
|
39
|
-
return true;
|
|
40
|
-
} catch (e) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
21
|
+
try { await b.click({ timeout: 2000 }); await new Promise(function (r) { setTimeout(r, 400); }); return true; } catch (e) { return false; }
|
|
43
22
|
}
|
|
44
23
|
return false;
|
|
45
24
|
}
|
package/lib/exec.mjs
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
1
|
import { launch } from "./browser.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { waitForComposer } from "./wait.mjs";
|
|
4
|
-
import { enableDeepThink } from "./deepthink.mjs";
|
|
5
|
-
import { runTurn } from "./turn.mjs";
|
|
6
|
-
import { setWorkspace } from "./tools/path.mjs";
|
|
7
|
-
import { setIgnore } from "./tools/walk.mjs";
|
|
8
|
-
import { loadInstructions } from "./instructions.mjs";
|
|
9
|
-
import { info, error } from "./log.mjs";
|
|
10
|
-
|
|
11
|
-
export async function runExec(config) {
|
|
12
|
-
const provider = getProvider(config.provider);
|
|
13
|
-
setWorkspace(config.ws);
|
|
14
|
-
setIgnore(config.ignored);
|
|
15
|
-
|
|
16
|
-
config.instructionsText = await loadInstructions(config.ws);
|
|
17
|
-
|
|
18
|
-
const ctx = await launch();
|
|
19
|
-
const page = await ctx.newPage();
|
|
20
|
-
page.setDefaultTimeout(30000);
|
|
21
|
-
|
|
22
|
-
info("opening " + provider.label + "...");
|
|
23
|
-
await page.goto(provider.url);
|
|
24
|
-
await waitForComposer(page, provider, config.loginTimeout);
|
|
25
|
-
|
|
26
|
-
if (provider.deepthink) await enableDeepThink(page);
|
|
27
|
-
|
|
28
|
-
const session = {
|
|
29
|
-
id: "exec-" + Date.now(),
|
|
30
|
-
ws: config.ws,
|
|
31
|
-
provider: config.provider,
|
|
32
|
-
turns: [],
|
|
33
|
-
approvedAlways: [],
|
|
34
|
-
startedAt: Date.now(),
|
|
35
|
-
updatedAt: Date.now()
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
await runTurn(page, provider, config.exec, config, session);
|
|
40
|
-
process.exitCode = 0;
|
|
41
|
-
} catch (e) {
|
|
42
|
-
error(e.message || String(e));
|
|
43
|
-
process.exitCode = 1;
|
|
44
|
-
} finally {
|
|
45
|
-
await ctx.close().catch(function () {});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
2
|
+
import { get
|
package/lib/instructions.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
4
|
const FILENAMES = ["PORTAL.md", "AGENTS.md", ".portal.md", "CLAUDE.md"];
|
|
5
|
-
|
|
6
5
|
let cache = null;
|
|
7
6
|
let cacheKey = "";
|
|
8
7
|
|
|
@@ -10,35 +9,6 @@ export async function loadInstructions(ws) {
|
|
|
10
9
|
for (const name of FILENAMES) {
|
|
11
10
|
const path = join(ws, name);
|
|
12
11
|
let info;
|
|
13
|
-
try {
|
|
14
|
-
info = await stat(path);
|
|
15
|
-
} catch (e) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
|
|
12
|
+
try { info = await stat(path); } catch (e) { continue; }
|
|
19
13
|
const key = path + ":" + info.mtimeMs;
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const content = await readFile(path, "utf8");
|
|
24
|
-
const trimmed = content.trim();
|
|
25
|
-
if (!trimmed) return null;
|
|
26
|
-
cache = [
|
|
27
|
-
"# Project instructions",
|
|
28
|
-
"",
|
|
29
|
-
"The user placed these instructions in " + name + ". Follow them.",
|
|
30
|
-
"",
|
|
31
|
-
trimmed
|
|
32
|
-
].join("\n");
|
|
33
|
-
cacheKey = key;
|
|
34
|
-
return cache;
|
|
35
|
-
} catch (e) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function activeInstructionFile() {
|
|
43
|
-
return cacheKey ? cacheKey.split(":")[0] : null;
|
|
44
|
-
}
|
|
14
|
+
if (
|
package/lib/log.mjs
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import { theme } from "./theme.mjs";
|
|
2
2
|
|
|
3
|
-
export function info(s) {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function
|
|
8
|
-
process.stdout.write(theme.warn("! " + s) + "\n");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function error(s) {
|
|
12
|
-
process.stderr.write(theme.error("x " + s) + "\n");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function ok(s) {
|
|
16
|
-
process.stdout.write(theme.ok("+ " + s) + "\n");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function status(s) {
|
|
20
|
-
process.stdout.write(theme.dim(" " + s) + "\n");
|
|
21
|
-
}
|
|
3
|
+
export function info(s) { process.stdout.write(theme.dim(s) + "\n"); }
|
|
4
|
+
export function warn(s) { process.stdout.write(theme.warn("! " + s) + "\n"); }
|
|
5
|
+
export function error(s) { process.stderr.write(theme.error("x " + s) + "\n"); }
|
|
6
|
+
export function ok(s) { process.stdout.write(theme.ok("+ " + s) + "\n"); }
|
|
7
|
+
export function status(s) { process.stdout.write(theme.dim(" " + s) + "\n"); }
|
|
22
8
|
|
|
23
9
|
export function tool(name, args) {
|
|
24
10
|
const preview = args ? JSON.stringify(args).slice(0, 140) : "";
|
|
@@ -30,8 +16,3 @@ export function toolResult(text, isError) {
|
|
|
30
16
|
const prefix = isError ? theme.red(" x ") : theme.dim(" ");
|
|
31
17
|
process.stdout.write(prefix + body + "\n");
|
|
32
18
|
}
|
|
33
|
-
|
|
34
|
-
export function reply(text) {
|
|
35
|
-
if (!text) return;
|
|
36
|
-
process.stdout.write("\n" + theme.cyan("* ") + text + "\n");
|
|
37
|
-
}
|
package/lib/parse.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
function findJsonEnd(s, i) {
|
|
2
|
-
let depth = 0;
|
|
3
|
-
let inStr = false;
|
|
4
|
-
let esc = false;
|
|
2
|
+
let depth = 0, inStr = false, esc = false;
|
|
5
3
|
for (let j = i; j < s.length; j++) {
|
|
6
4
|
const c = s[j];
|
|
7
5
|
if (esc) { esc = false; continue; }
|
|
@@ -9,10 +7,7 @@ function findJsonEnd(s, i) {
|
|
|
9
7
|
if (c === String.fromCharCode(34)) { inStr = !inStr; continue; }
|
|
10
8
|
if (inStr) continue;
|
|
11
9
|
if (c === "{") depth++;
|
|
12
|
-
else if (c === "}") {
|
|
13
|
-
depth--;
|
|
14
|
-
if (!depth) return j + 1;
|
|
15
|
-
}
|
|
10
|
+
else if (c === "}") { depth--; if (!depth) return j + 1; }
|
|
16
11
|
}
|
|
17
12
|
return -1;
|
|
18
13
|
}
|
|
@@ -37,11 +32,8 @@ export function parseCalls(text) {
|
|
|
37
32
|
const raw = text.slice(b, e);
|
|
38
33
|
if (seen.has(raw)) continue;
|
|
39
34
|
seen.add(raw);
|
|
40
|
-
try {
|
|
41
|
-
|
|
42
|
-
} catch (x) {
|
|
43
|
-
try { out.push(JSON.parse(repair(raw))); } catch (y) {}
|
|
44
|
-
}
|
|
35
|
+
try { out.push(JSON.parse(raw)); }
|
|
36
|
+
catch (x) { try { out.push(JSON.parse(repair(raw))); } catch (y) {} }
|
|
45
37
|
}
|
|
46
38
|
return out;
|
|
47
39
|
}
|
package/lib/paste.mjs
CHANGED
|
@@ -3,45 +3,26 @@ import { sleep } from "./wait.mjs";
|
|
|
3
3
|
export async function dismissPaste(page) {
|
|
4
4
|
const btns = page.locator("button, [role=button]");
|
|
5
5
|
let total = 0;
|
|
6
|
-
try {
|
|
7
|
-
total = await btns.count();
|
|
8
|
-
} catch (e) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
6
|
+
try { total = await btns.count(); } catch (e) { return false; }
|
|
11
7
|
if (total === 0 || total > 300) return false;
|
|
12
8
|
|
|
13
9
|
for (let i = 0; i < total; i++) {
|
|
14
10
|
const b = btns.nth(i);
|
|
15
11
|
let text = "";
|
|
16
|
-
try {
|
|
17
|
-
text = ((await b.textContent()) || "").trim();
|
|
18
|
-
} catch (e) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
12
|
+
try { text = ((await b.textContent()) || "").trim(); } catch (e) { continue; }
|
|
21
13
|
if (text !== "Cancel") continue;
|
|
22
14
|
|
|
23
15
|
for (let j = 0; j < total; j++) {
|
|
24
16
|
if (j === i) continue;
|
|
25
17
|
const sib = btns.nth(j);
|
|
26
18
|
let st = "";
|
|
27
|
-
try {
|
|
28
|
-
st = ((await sib.textContent()) || "").trim();
|
|
29
|
-
} catch (e) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
19
|
+
try { st = ((await sib.textContent()) || "").trim(); } catch (e) { continue; }
|
|
32
20
|
if (st === "Send") {
|
|
33
|
-
try {
|
|
34
|
-
await sib.click({ timeout: 1500 });
|
|
35
|
-
await sleep(200);
|
|
36
|
-
return true;
|
|
37
|
-
} catch (e) {}
|
|
21
|
+
try { await sib.click({ timeout: 1500 }); await sleep(200); return true; } catch (e) {}
|
|
38
22
|
}
|
|
39
23
|
}
|
|
40
24
|
|
|
41
|
-
try {
|
|
42
|
-
await page.keyboard.press("Enter");
|
|
43
|
-
await sleep(150);
|
|
44
|
-
} catch (e) {}
|
|
25
|
+
try { await page.keyboard.press("Enter"); await sleep(150); } catch (e) {}
|
|
45
26
|
return true;
|
|
46
27
|
}
|
|
47
28
|
return false;
|
|
@@ -51,11 +32,7 @@ export async function composerEmpty(input, ms) {
|
|
|
51
32
|
const end = Date.now() + ms;
|
|
52
33
|
while (Date.now() < end) {
|
|
53
34
|
let v = "";
|
|
54
|
-
try {
|
|
55
|
-
v = await input.inputValue();
|
|
56
|
-
} catch (e) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
35
|
+
try { v = await input.inputValue(); } catch (e) { return true; }
|
|
59
36
|
if (!v || v.length === 0) return true;
|
|
60
37
|
await sleep(150);
|
|
61
38
|
}
|
package/lib/providers.mjs
CHANGED
|
@@ -1,52 +1,41 @@
|
|
|
1
1
|
export const PROVIDERS = {
|
|
2
2
|
deepseek: {
|
|
3
|
-
id: "deepseek",
|
|
4
|
-
label: "DeepSeek",
|
|
3
|
+
id: "deepseek", label: "DeepSeek",
|
|
5
4
|
url: "https://chat.deepseek.com/",
|
|
6
5
|
input: ["textarea#chat-input", "textarea", "[contenteditable=true]"],
|
|
7
6
|
submit: ["button[aria-label=Send]", "button[data-testid=send-button]"],
|
|
8
7
|
response: ["div.ds-markdown", "div[class*=message]"],
|
|
9
|
-
paste: true,
|
|
10
|
-
deepthink: true
|
|
8
|
+
paste: true, deepthink: true
|
|
11
9
|
},
|
|
12
10
|
chatgpt: {
|
|
13
|
-
id: "chatgpt",
|
|
14
|
-
label: "ChatGPT",
|
|
11
|
+
id: "chatgpt", label: "ChatGPT",
|
|
15
12
|
url: "https://chatgpt.com/",
|
|
16
|
-
input: ["#prompt-textarea"
|
|
17
|
-
submit: ["button[data-testid=send-button]"
|
|
13
|
+
input: ["#prompt-textarea"],
|
|
14
|
+
submit: ["button[data-testid=send-button]"],
|
|
18
15
|
response: ["[data-message-author-role=assistant]"],
|
|
19
|
-
paste: false,
|
|
20
|
-
deepthink: false
|
|
16
|
+
paste: false, deepthink: false
|
|
21
17
|
},
|
|
22
18
|
gemini: {
|
|
23
|
-
id: "gemini",
|
|
24
|
-
label: "Gemini",
|
|
19
|
+
id: "gemini", label: "Gemini",
|
|
25
20
|
url: "https://gemini.google.com/app",
|
|
26
21
|
input: ["div[contenteditable=true][role=textbox]"],
|
|
27
22
|
submit: ["button[aria-label*=Send]"],
|
|
28
23
|
response: ["message-content"],
|
|
29
|
-
paste: false,
|
|
30
|
-
deepthink: false
|
|
24
|
+
paste: false, deepthink: false
|
|
31
25
|
},
|
|
32
26
|
grok: {
|
|
33
|
-
id: "grok",
|
|
34
|
-
label: "Grok",
|
|
27
|
+
id: "grok", label: "Grok",
|
|
35
28
|
url: "https://grok.com/",
|
|
36
29
|
input: ["textarea", "div[contenteditable=true]"],
|
|
37
30
|
submit: ["button[type=submit]"],
|
|
38
31
|
response: ["div[class*=message]"],
|
|
39
|
-
paste: false,
|
|
40
|
-
deepthink: false
|
|
32
|
+
paste: false, deepthink: false
|
|
41
33
|
}
|
|
42
34
|
};
|
|
43
35
|
|
|
44
36
|
export function getProvider(id) {
|
|
45
37
|
const p = PROVIDERS[id];
|
|
46
|
-
if (!p)
|
|
47
|
-
const names = Object.keys(PROVIDERS).join(", ");
|
|
48
|
-
throw new Error("unknown provider: " + id + " | available: " + names);
|
|
49
|
-
}
|
|
38
|
+
if (!p) throw new Error("unknown provider: " + id);
|
|
50
39
|
return p;
|
|
51
40
|
}
|
|
52
41
|
|