portal-agent-cli 3.0.0 → 3.0.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/LICENSE +18 -0
- package/README.md +13 -40
- package/lib/args.mjs +5 -29
- package/lib/browser.mjs +7 -24
- package/lib/config.mjs +20 -27
- package/lib/deepthink.mjs +45 -0
- package/lib/exec.mjs +16 -1
- package/lib/log.mjs +0 -4
- package/lib/parse.mjs +3 -21
- package/lib/paste.mjs +4 -12
- package/lib/providers.mjs +11 -11
- package/lib/repl.mjs +42 -91
- package/lib/safety.mjs +2 -6
- package/lib/send.mjs +33 -26
- package/lib/sessions.mjs +1 -12
- package/lib/system.mjs +17 -11
- package/lib/theme.mjs +1 -11
- package/lib/tools/delete.mjs +4 -9
- package/lib/tools/edit.mjs +8 -13
- package/lib/tools/find.mjs +3 -6
- package/lib/tools/git.mjs +1 -1
- package/lib/tools/grep.mjs +5 -8
- package/lib/tools/index.mjs +14 -14
- package/lib/tools/list.mjs +2 -5
- package/lib/tools/read.mjs +3 -5
- package/lib/tools/shell.mjs +21 -3
- package/lib/tools/walk.mjs +0 -2
- package/lib/tools/write.mjs +3 -14
- package/lib/turn.mjs +17 -36
- package/lib/wait.mjs +8 -15
- package/package.json +3 -5
- package/portal.mjs +3 -16
package/LICENSE
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
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,55 +1,28 @@
|
|
|
1
1
|
# portal-agent
|
|
2
2
|
|
|
3
|
-
Drive
|
|
4
|
-
```
|
|
3
|
+
Drive web AI products from the terminal with local tools.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Supports DeepSeek, ChatGPT, Gemini, and Grok.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Install
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
npm install -g portal-agent-cli
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
## Run
|
|
13
12
|
|
|
14
13
|
portal-agent --workspace F:/projects/my-app
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Or without installing
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
npx portal-agent-cli --workspace F:/projects/my-app
|
|
22
|
-
|
|
23
|
-
```
|
|
15
|
+
## Commands
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
portal-agent --workspace F:/proj exec "list the files here"
|
|
29
|
-
|
|
30
|
-
```
|
|
17
|
+
/help, /cd, /pwd, /provider, /providers, /deepthink,
|
|
18
|
+
/sessions, /queue, /status, /clear, /quit
|
|
31
19
|
|
|
32
20
|
## Tools
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- approval required
|
|
39
|
-
tool: shell
|
|
40
|
-
{
|
|
41
|
-
"command": "npm test"
|
|
42
|
-
}
|
|
43
|
-
allow? yes / always / no:
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Answer
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
portal-tool: {"tool":"read_file","args":{"path":"notes.txt"}}
|
|
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
|
|
51
25
|
|
|
52
|
-
|
|
26
|
+
## License
|
|
53
27
|
|
|
54
|
-
|
|
55
|
-
into the same conversation. This
|
|
28
|
+
MIT
|
package/lib/args.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { theme } from "./theme.mjs";
|
|
4
3
|
|
|
5
4
|
export function parseArgs() {
|
|
6
5
|
const a = process.argv.slice(2);
|
|
7
6
|
const o = {
|
|
8
7
|
ws: null,
|
|
9
8
|
provider: null,
|
|
10
|
-
model: null,
|
|
11
9
|
maxSteps: null,
|
|
12
10
|
timeout: null,
|
|
13
11
|
loginTimeout: null,
|
|
@@ -15,8 +13,7 @@ export function parseArgs() {
|
|
|
15
13
|
verbose: false,
|
|
16
14
|
yolo: false,
|
|
17
15
|
session: null,
|
|
18
|
-
resume: null
|
|
19
|
-
theme: "auto"
|
|
16
|
+
resume: null
|
|
20
17
|
};
|
|
21
18
|
|
|
22
19
|
let i = 0;
|
|
@@ -24,18 +21,16 @@ export function parseArgs() {
|
|
|
24
21
|
const t = a[i];
|
|
25
22
|
if (t === "-w" || t === "--workspace") o.ws = a[++i];
|
|
26
23
|
else if (t === "-p" || t === "--provider") o.provider = a[++i];
|
|
27
|
-
else if (t === "--model") o.model = a[++i];
|
|
28
24
|
else if (t === "--timeout") o.timeout = Number(a[++i]);
|
|
29
25
|
else if (t === "--login-timeout") o.loginTimeout = Number(a[++i]);
|
|
30
26
|
else if (t === "--max-steps") o.maxSteps = Number(a[++i]);
|
|
31
27
|
else if (t === "--session") o.session = a[++i];
|
|
32
28
|
else if (t === "--resume") o.resume = a[++i];
|
|
33
|
-
else if (t === "--theme") o.theme = a[++i];
|
|
34
29
|
else if (t === "--verbose" || t === "-V") o.verbose = true;
|
|
35
30
|
else if (t === "--yolo") o.yolo = true;
|
|
36
31
|
else if (t === "exec") { o.exec = a.slice(i + 1).join(" "); break; }
|
|
37
32
|
else if (t === "--help" || t === "-h") { help(); process.exit(0); }
|
|
38
|
-
else if (t === "--version" || t === "-v") { console.log("
|
|
33
|
+
else if (t === "--version" || t === "-v") { console.log("3.0.2"); process.exit(0); }
|
|
39
34
|
i++;
|
|
40
35
|
}
|
|
41
36
|
|
|
@@ -46,44 +41,25 @@ export function parseArgs() {
|
|
|
46
41
|
process.exit(2);
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
return o;
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
function help() {
|
|
54
|
-
const t = theme;
|
|
55
48
|
console.log("");
|
|
56
|
-
console.log(
|
|
49
|
+
console.log("portal-agent -- drive web AI from the terminal");
|
|
57
50
|
console.log("");
|
|
58
|
-
console.log(t.bold("USAGE"));
|
|
59
51
|
console.log(" portal-agent [options]");
|
|
60
52
|
console.log(" portal-agent [options] exec <task>");
|
|
61
53
|
console.log("");
|
|
62
|
-
console.log(
|
|
54
|
+
console.log("Options:");
|
|
63
55
|
console.log(" -w, --workspace <dir> folder the agent works in");
|
|
64
56
|
console.log(" -p, --provider <name> deepseek | chatgpt | gemini | grok");
|
|
65
|
-
console.log(" --model <name> provider-specific model hint");
|
|
66
57
|
console.log(" --timeout <ms> response timeout (default 180000)");
|
|
67
58
|
console.log(" --login-timeout <ms> login wait (default 600000)");
|
|
68
|
-
console.log(" --max-steps <n> max
|
|
69
|
-
console.log(" --session <name> start or reuse a named session");
|
|
59
|
+
console.log(" --max-steps <n> max steps per turn (default 12)");
|
|
70
60
|
console.log(" --resume <name> resume a saved session");
|
|
71
|
-
console.log(" --theme <name> auto | dark | light");
|
|
72
|
-
console.log(" -V, --verbose print config on startup");
|
|
73
61
|
console.log(" --yolo auto-approve every tool call");
|
|
74
62
|
console.log(" -h, --help show this help");
|
|
75
63
|
console.log(" -v, --version show version");
|
|
76
64
|
console.log("");
|
|
77
|
-
console.log(t.bold("ENVIRONMENT"));
|
|
78
|
-
console.log(" PORTAL_WORKSPACE same as --workspace");
|
|
79
|
-
console.log(" PORTAL_PROVIDER default provider");
|
|
80
|
-
console.log(" PORTAL_BROWSER_PATH explicit browser executable");
|
|
81
|
-
console.log(" PORTAL_DEBUG print stack traces on error");
|
|
82
|
-
console.log(" PORTAL_YOLO same as --yolo");
|
|
83
|
-
console.log("");
|
|
84
|
-
console.log(t.bold("EXAMPLES"));
|
|
85
|
-
console.log(" portal-agent --workspace F:/projects/app");
|
|
86
|
-
console.log(" portal-agent -w . -p chatgpt");
|
|
87
|
-
console.log(" portal-agent exec \"list the files here\"");
|
|
88
|
-
console.log("");
|
|
89
65
|
}
|
package/lib/browser.mjs
CHANGED
|
@@ -11,16 +11,10 @@ const CANDIDATES = [
|
|
|
11
11
|
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
12
12
|
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
|
|
13
13
|
"C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
14
|
-
"C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
15
14
|
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
16
15
|
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
17
|
-
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
|
|
18
|
-
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
19
16
|
"/usr/bin/google-chrome",
|
|
20
|
-
"/usr/bin/
|
|
21
|
-
"/usr/bin/chromium",
|
|
22
|
-
"/usr/bin/chromium-browser",
|
|
23
|
-
"/usr/bin/microsoft-edge"
|
|
17
|
+
"/usr/bin/chromium"
|
|
24
18
|
];
|
|
25
19
|
|
|
26
20
|
export function findBrowser() {
|
|
@@ -30,20 +24,12 @@ export function findBrowser() {
|
|
|
30
24
|
return null;
|
|
31
25
|
}
|
|
32
26
|
|
|
33
|
-
export function
|
|
34
|
-
const found = [];
|
|
35
|
-
for (const p of CANDIDATES) {
|
|
36
|
-
if (p && existsSync(p)) found.push(p);
|
|
37
|
-
}
|
|
38
|
-
return found;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function launch(opts) {
|
|
27
|
+
export async function launch() {
|
|
42
28
|
const exe = findBrowser();
|
|
43
29
|
if (!exe) {
|
|
44
30
|
throw new Error(
|
|
45
|
-
"No Chrome, Chromium, Edge, or Brave found
|
|
46
|
-
"
|
|
31
|
+
"No Chrome, Chromium, Edge, or Brave found. " +
|
|
32
|
+
"Set PORTAL_BROWSER_PATH to your browser executable."
|
|
47
33
|
);
|
|
48
34
|
}
|
|
49
35
|
|
|
@@ -54,12 +40,9 @@ export async function launch(opts) {
|
|
|
54
40
|
const ctx = await chromium.launchPersistentContext(profileDir, {
|
|
55
41
|
executablePath: exe,
|
|
56
42
|
headless: false,
|
|
57
|
-
viewport: { width: 1280, height: 900 }
|
|
58
|
-
args: ["--disable-blink-features=AutomationControlled"]
|
|
43
|
+
viewport: { width: 1280, height: 900 }
|
|
59
44
|
});
|
|
60
45
|
|
|
61
|
-
// Auto-dismiss dialogs (alert, confirm, prompt) so a stray modal cannot
|
|
62
|
-
// freeze the session.
|
|
63
46
|
ctx.on("page", function (page) {
|
|
64
47
|
page.on("dialog", function (d) {
|
|
65
48
|
d.dismiss().catch(function () {});
|
|
@@ -69,9 +52,9 @@ export async function launch(opts) {
|
|
|
69
52
|
return ctx;
|
|
70
53
|
} catch (e) {
|
|
71
54
|
const m = e.message || String(e);
|
|
72
|
-
if (
|
|
55
|
+
if (m.indexOf("ProcessSingleton") >= 0 || m.indexOf("already running") >= 0) {
|
|
73
56
|
throw new Error(
|
|
74
|
-
"Another Chrome window is using the Portal profile
|
|
57
|
+
"Another Chrome window is using the Portal profile. " +
|
|
75
58
|
"Close every Chrome window and try again."
|
|
76
59
|
);
|
|
77
60
|
}
|
package/lib/config.mjs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { resolve, join
|
|
2
|
+
import { resolve, join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
4
|
|
|
6
5
|
const DEFAULTS = {
|
|
7
6
|
provider: "deepseek",
|
|
8
7
|
maxSteps: 12,
|
|
9
8
|
timeout: 180000,
|
|
10
9
|
loginTimeout: 600000,
|
|
11
|
-
theme: "auto",
|
|
12
10
|
yolo: false,
|
|
13
11
|
verbose: false,
|
|
14
|
-
instructions: ["PORTAL.md", "AGENTS.md", ".portal.md"],
|
|
15
12
|
ignored: [
|
|
16
13
|
"node_modules", ".git", ".hg", ".svn", "dist", "build", "out",
|
|
17
14
|
".next", ".nuxt", ".turbo", ".cache", "target", "__pycache__",
|
|
@@ -19,11 +16,11 @@ const DEFAULTS = {
|
|
|
19
16
|
]
|
|
20
17
|
};
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
function configPath() {
|
|
23
20
|
return join(homedir(), ".portal-agent", "config.json");
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
function readGlobal() {
|
|
27
24
|
const p = configPath();
|
|
28
25
|
if (!existsSync(p)) return {};
|
|
29
26
|
try {
|
|
@@ -33,45 +30,41 @@ export function readGlobalConfig() {
|
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
export async function writeGlobalConfig(obj) {
|
|
37
|
-
const p = configPath();
|
|
38
|
-
await mkdir(dirname(p), { recursive: true });
|
|
39
|
-
await writeFile(p, JSON.stringify(obj, null, 2), "utf8");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
33
|
export async function loadConfig(args) {
|
|
43
|
-
const
|
|
34
|
+
const g = readGlobal();
|
|
44
35
|
|
|
45
36
|
const config = {
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
provider: g.provider || DEFAULTS.provider,
|
|
38
|
+
maxSteps: g.maxSteps || DEFAULTS.maxSteps,
|
|
39
|
+
timeout: g.timeout || DEFAULTS.timeout,
|
|
40
|
+
loginTimeout: g.loginTimeout || DEFAULTS.loginTimeout,
|
|
41
|
+
yolo: g.yolo || false,
|
|
42
|
+
verbose: g.verbose || false,
|
|
43
|
+
ignored: g.ignored || DEFAULTS.ignored,
|
|
48
44
|
ws: args.ws || process.env.PORTAL_WORKSPACE || process.cwd(),
|
|
49
|
-
provider: args.provider || process.env.PORTAL_PROVIDER || global.provider || DEFAULTS.provider,
|
|
50
|
-
maxSteps: args.maxSteps || global.maxSteps || DEFAULTS.maxSteps,
|
|
51
|
-
timeout: args.timeout || global.timeout || DEFAULTS.timeout,
|
|
52
|
-
loginTimeout: args.loginTimeout || global.loginTimeout || DEFAULTS.loginTimeout,
|
|
53
|
-
theme: args.theme || global.theme || DEFAULTS.theme,
|
|
54
|
-
yolo: args.yolo || process.env.PORTAL_YOLO === "true" || global.yolo || DEFAULTS.yolo,
|
|
55
|
-
verbose: args.verbose || global.verbose || DEFAULTS.verbose,
|
|
56
45
|
exec: args.exec,
|
|
57
|
-
session: args.session || null,
|
|
58
46
|
resume: args.resume || null
|
|
59
47
|
};
|
|
60
48
|
|
|
49
|
+
if (args.provider) config.provider = args.provider;
|
|
50
|
+
if (process.env.PORTAL_PROVIDER) config.provider = process.env.PORTAL_PROVIDER;
|
|
51
|
+
if (args.maxSteps) config.maxSteps = args.maxSteps;
|
|
52
|
+
if (args.timeout) config.timeout = args.timeout;
|
|
53
|
+
if (args.loginTimeout) config.loginTimeout = args.loginTimeout;
|
|
54
|
+
if (args.yolo || process.env.PORTAL_YOLO === "true") config.yolo = true;
|
|
55
|
+
if (args.verbose) config.verbose = true;
|
|
56
|
+
|
|
61
57
|
config.ws = resolve(config.ws);
|
|
62
58
|
if (!existsSync(config.ws)) {
|
|
63
59
|
throw new Error("workspace does not exist: " + config.ws);
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
// Per-project config file
|
|
67
62
|
const localPath = join(config.ws, "portal.config.json");
|
|
68
63
|
if (existsSync(localPath)) {
|
|
69
64
|
try {
|
|
70
65
|
const local = JSON.parse(readFileSync(localPath, "utf8"));
|
|
71
66
|
Object.assign(config, local);
|
|
72
|
-
} catch (e) {
|
|
73
|
-
// ignore malformed local config
|
|
74
|
-
}
|
|
67
|
+
} catch (e) {}
|
|
75
68
|
}
|
|
76
69
|
|
|
77
70
|
return config;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export async function enableDeepThink(page) {
|
|
2
|
+
if (process.env.PORTAL_DEEPTHINK === "off") return false;
|
|
3
|
+
|
|
4
|
+
const btns = page.locator("button, [role=button], div[role=button]");
|
|
5
|
+
let total = 0;
|
|
6
|
+
try {
|
|
7
|
+
total = await btns.count();
|
|
8
|
+
} catch (e) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (total === 0 || total > 400) return false;
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < total; i++) {
|
|
14
|
+
const b = btns.nth(i);
|
|
15
|
+
let text = "";
|
|
16
|
+
try {
|
|
17
|
+
text = ((await b.textContent()) || "").trim();
|
|
18
|
+
} catch (e) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (!text) continue;
|
|
22
|
+
|
|
23
|
+
const hit = text === "DeepThink" ||
|
|
24
|
+
text === "Deep Think" ||
|
|
25
|
+
text.indexOf("DeepThink") >= 0;
|
|
26
|
+
|
|
27
|
+
if (!hit) continue;
|
|
28
|
+
|
|
29
|
+
let pressed = "";
|
|
30
|
+
let cls = "";
|
|
31
|
+
try { pressed = (await b.getAttribute("aria-pressed")) || ""; } catch (e) {}
|
|
32
|
+
try { cls = (await b.getAttribute("class")) || ""; } catch (e) {}
|
|
33
|
+
|
|
34
|
+
if (pressed === "true" || /active|selected|on\b/i.test(cls)) return true;
|
|
35
|
+
|
|
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
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
package/lib/exec.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { launch } from "./browser.mjs";
|
|
2
2
|
import { getProvider } from "./providers.mjs";
|
|
3
3
|
import { waitForComposer } from "./wait.mjs";
|
|
4
|
+
import { enableDeepThink } from "./deepthink.mjs";
|
|
4
5
|
import { runTurn } from "./turn.mjs";
|
|
5
6
|
import { setWorkspace } from "./tools/path.mjs";
|
|
6
7
|
import { setIgnore } from "./tools/walk.mjs";
|
|
@@ -22,6 +23,8 @@ export async function runExec(config) {
|
|
|
22
23
|
await page.goto(provider.url);
|
|
23
24
|
await waitForComposer(page, provider, config.loginTimeout);
|
|
24
25
|
|
|
26
|
+
if (provider.deepthink) await enableDeepThink(page);
|
|
27
|
+
|
|
25
28
|
const session = {
|
|
26
29
|
id: "exec-" + Date.now(),
|
|
27
30
|
ws: config.ws,
|
|
@@ -29,4 +32,16 @@ export async function runExec(config) {
|
|
|
29
32
|
turns: [],
|
|
30
33
|
approvedAlways: [],
|
|
31
34
|
startedAt: Date.now(),
|
|
32
|
-
|
|
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
|
+
}
|
package/lib/log.mjs
CHANGED
package/lib/parse.mjs
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
// Tool call protocol:
|
|
2
|
-
//
|
|
3
|
-
// portal-tool: {"tool":"name","args":{"key":"value"}}
|
|
4
|
-
//
|
|
5
|
-
// Written as plain text on its own line. The parser scans for the literal
|
|
6
|
-
// string "portal-tool", finds the balanced JSON object that follows, and
|
|
7
|
-
// tries to parse it. If parse fails, common Windows backslash escapes are
|
|
8
|
-
// repaired first (models copy "L:\this\file" and JSON sees \t, \h, \w as
|
|
9
|
-
// escapes that blow up the parse).
|
|
10
|
-
|
|
11
1
|
function findJsonEnd(s, i) {
|
|
12
2
|
let depth = 0;
|
|
13
3
|
let inStr = false;
|
|
@@ -27,9 +17,9 @@ function findJsonEnd(s, i) {
|
|
|
27
17
|
return -1;
|
|
28
18
|
}
|
|
29
19
|
|
|
30
|
-
function
|
|
20
|
+
function repair(raw) {
|
|
31
21
|
let s = raw;
|
|
32
|
-
const bad = ["\\t", "\\h", "\\w", "\\d", "\\p"
|
|
22
|
+
const bad = ["\\t", "\\h", "\\w", "\\d", "\\p"];
|
|
33
23
|
for (const b of bad) s = s.split(b).join("/");
|
|
34
24
|
return s;
|
|
35
25
|
}
|
|
@@ -50,11 +40,7 @@ export function parseCalls(text) {
|
|
|
50
40
|
try {
|
|
51
41
|
out.push(JSON.parse(raw));
|
|
52
42
|
} catch (x) {
|
|
53
|
-
try {
|
|
54
|
-
out.push(JSON.parse(repairBackslashes(raw)));
|
|
55
|
-
} catch (y) {
|
|
56
|
-
// skip malformed
|
|
57
|
-
}
|
|
43
|
+
try { out.push(JSON.parse(repair(raw))); } catch (y) {}
|
|
58
44
|
}
|
|
59
45
|
}
|
|
60
46
|
return out;
|
|
@@ -63,7 +49,3 @@ export function parseCalls(text) {
|
|
|
63
49
|
export function stripCalls(text) {
|
|
64
50
|
return text.replace(/portal-tool[\s\S]*?\n\}/g, "").trim();
|
|
65
51
|
}
|
|
66
|
-
|
|
67
|
-
export function hasToolCall(text) {
|
|
68
|
-
return /portal-tool[:\s]*\{/.test(text);
|
|
69
|
-
}
|
package/lib/paste.mjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { sleep } from "./wait.mjs";
|
|
2
2
|
|
|
3
|
-
// DeepSeek shows a Cancel/Send confirmation bar when a large paste is
|
|
4
|
-
// detected. Find the Cancel button, locate its Send sibling, click that.
|
|
5
3
|
export async function dismissPaste(page) {
|
|
6
4
|
const btns = page.locator("button, [role=button]");
|
|
7
5
|
let total = 0;
|
|
8
6
|
try {
|
|
9
7
|
total = await btns.count();
|
|
10
8
|
} catch (e) {
|
|
11
|
-
return;
|
|
9
|
+
return false;
|
|
12
10
|
}
|
|
13
|
-
if (total === 0 || total > 300) return;
|
|
11
|
+
if (total === 0 || total > 300) return false;
|
|
14
12
|
|
|
15
13
|
for (let i = 0; i < total; i++) {
|
|
16
14
|
const b = btns.nth(i);
|
|
@@ -36,25 +34,19 @@ export async function dismissPaste(page) {
|
|
|
36
34
|
await sib.click({ timeout: 1500 });
|
|
37
35
|
await sleep(200);
|
|
38
36
|
return true;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
// fall through
|
|
41
|
-
}
|
|
37
|
+
} catch (e) {}
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
try {
|
|
46
42
|
await page.keyboard.press("Enter");
|
|
47
43
|
await sleep(150);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
// ignore
|
|
50
|
-
}
|
|
44
|
+
} catch (e) {}
|
|
51
45
|
return true;
|
|
52
46
|
}
|
|
53
47
|
return false;
|
|
54
48
|
}
|
|
55
49
|
|
|
56
|
-
// Poll the composer for emptiness. A thrown inputValue() means the composer
|
|
57
|
-
// is a contenteditable with no inputValue method, so treat that as sent.
|
|
58
50
|
export async function composerEmpty(input, ms) {
|
|
59
51
|
const end = Date.now() + ms;
|
|
60
52
|
while (Date.now() < end) {
|
package/lib/providers.mjs
CHANGED
|
@@ -7,7 +7,7 @@ export const PROVIDERS = {
|
|
|
7
7
|
submit: ["button[aria-label=Send]", "button[data-testid=send-button]"],
|
|
8
8
|
response: ["div.ds-markdown", "div[class*=message]"],
|
|
9
9
|
paste: true,
|
|
10
|
-
|
|
10
|
+
deepthink: true
|
|
11
11
|
},
|
|
12
12
|
chatgpt: {
|
|
13
13
|
id: "chatgpt",
|
|
@@ -15,29 +15,29 @@ export const PROVIDERS = {
|
|
|
15
15
|
url: "https://chatgpt.com/",
|
|
16
16
|
input: ["#prompt-textarea", "div[contenteditable=true][id=prompt-textarea]"],
|
|
17
17
|
submit: ["button[data-testid=send-button]", "button[aria-label*=Send]"],
|
|
18
|
-
response: ["[data-message-author-role=assistant]"
|
|
18
|
+
response: ["[data-message-author-role=assistant]"],
|
|
19
19
|
paste: false,
|
|
20
|
-
|
|
20
|
+
deepthink: false
|
|
21
21
|
},
|
|
22
22
|
gemini: {
|
|
23
23
|
id: "gemini",
|
|
24
24
|
label: "Gemini",
|
|
25
25
|
url: "https://gemini.google.com/app",
|
|
26
|
-
input: ["div[contenteditable=true][role=textbox]"
|
|
27
|
-
submit: ["button[aria-label*=Send]"
|
|
28
|
-
response: ["message-content"
|
|
26
|
+
input: ["div[contenteditable=true][role=textbox]"],
|
|
27
|
+
submit: ["button[aria-label*=Send]"],
|
|
28
|
+
response: ["message-content"],
|
|
29
29
|
paste: false,
|
|
30
|
-
|
|
30
|
+
deepthink: false
|
|
31
31
|
},
|
|
32
32
|
grok: {
|
|
33
33
|
id: "grok",
|
|
34
34
|
label: "Grok",
|
|
35
35
|
url: "https://grok.com/",
|
|
36
36
|
input: ["textarea", "div[contenteditable=true]"],
|
|
37
|
-
submit: ["button[type=submit]"
|
|
38
|
-
response: ["div[class*=message]"
|
|
37
|
+
submit: ["button[type=submit]"],
|
|
38
|
+
response: ["div[class*=message]"],
|
|
39
39
|
paste: false,
|
|
40
|
-
|
|
40
|
+
deepthink: false
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ export function getProvider(id) {
|
|
|
45
45
|
const p = PROVIDERS[id];
|
|
46
46
|
if (!p) {
|
|
47
47
|
const names = Object.keys(PROVIDERS).join(", ");
|
|
48
|
-
throw new Error("unknown provider: " + id + "
|
|
48
|
+
throw new Error("unknown provider: " + id + " | available: " + names);
|
|
49
49
|
}
|
|
50
50
|
return p;
|
|
51
51
|
}
|