zames_pro 2.7.0 → 2.8.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.
- package/README.md +21 -0
- package/dist/agent-loop.js +24 -2
- package/dist/attachments.js +267 -0
- package/dist/browser.js +99 -9
- package/dist/i18n.js +20 -0
- package/dist/index.js +144 -20
- package/dist/input.js +155 -6
- package/dist/system-prompt.js +6 -2
- package/dist/xml-toolcall.js +75 -0
- package/package.json +1 -1
- package/scripts/postinstall.mjs +78 -51
package/scripts/postinstall.mjs
CHANGED
|
@@ -1,67 +1,94 @@
|
|
|
1
|
-
// Automatically install the Chromium build and system dependencies
|
|
2
|
-
// that Playwright needs.
|
|
3
|
-
//
|
|
4
|
-
// Runs when the zames package is installed so the user does not have to run
|
|
5
|
-
// "npx playwright install chromium" / "install-deps chromium" by hand.
|
|
6
|
-
//
|
|
7
|
-
// On Linux (including WSL) the browser binary also needs system libraries.
|
|
8
|
-
// They are installed via "install-deps", which requires root (sudo).
|
|
9
|
-
// If we are not root and sudo is not passwordless, we skip it and tell the
|
|
10
|
-
// user the exact command to run.
|
|
11
|
-
//
|
|
12
|
-
// Install failure is NOT fatal: without network access (or in CI) the
|
|
13
|
-
// package install must still succeed.
|
|
14
|
-
|
|
15
1
|
import { spawnSync } from 'node:child_process'
|
|
16
2
|
|
|
3
|
+
const NL = String.fromCharCode(10)
|
|
17
4
|
const isWin = process.platform === 'win32'
|
|
5
|
+
const isMac = process.platform === 'darwin'
|
|
6
|
+
const isLinux = process.platform === 'linux'
|
|
7
|
+
|
|
8
|
+
function run(cmd, args, opts) {
|
|
9
|
+
return spawnSync(cmd, args, Object.assign({ stdio: 'inherit', shell: isWin }, opts || {}))
|
|
10
|
+
}
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
function has(cmd) {
|
|
13
|
+
if (isWin) {
|
|
14
|
+
const r = spawnSync('where', [cmd], { stdio: 'ignore' })
|
|
15
|
+
return !r.error && r.status === 0
|
|
16
|
+
}
|
|
17
|
+
const r = spawnSync('sh', ['-c', 'command -v "$1"', 'sh', cmd], { stdio: 'ignore' })
|
|
18
|
+
return !r.error && r.status === 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isRoot() {
|
|
22
|
+
return typeof process.getuid === 'function' && process.getuid() === 0
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
function canSudo() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
if (isRoot()) return true
|
|
27
|
+
const r = spawnSync('sudo', ['-n', 'true'], { stdio: 'ignore' })
|
|
28
|
+
return !r.error && r.status === 0
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const MANAGERS = [
|
|
32
|
+
{ bin: 'apt-get', args: (p) => ['install', '-y', p], update: ['update'] },
|
|
33
|
+
{ bin: 'dnf', args: (p) => ['install', '-y', p] },
|
|
34
|
+
{ bin: 'yum', args: (p) => ['install', '-y', p] },
|
|
35
|
+
{ bin: 'pacman', args: (p) => ['-S', '--noconfirm', p] },
|
|
36
|
+
{ bin: 'zypper', args: (p) => ['install', '-y', p] },
|
|
37
|
+
{ bin: 'apk', args: (p) => ['add', p] },
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
function asRoot(cmd, args) {
|
|
41
|
+
if (isRoot()) return run(cmd, args)
|
|
42
|
+
return run('sudo', [cmd].concat(args))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function installPackages(pkgs) {
|
|
46
|
+
const mgr = MANAGERS.find((m) => has(m.bin))
|
|
47
|
+
if (!mgr) return false
|
|
48
|
+
if (mgr.update) asRoot(mgr.bin, mgr.update)
|
|
49
|
+
let any = false
|
|
50
|
+
for (const p of pkgs) {
|
|
51
|
+
const r = asRoot(mgr.bin, mgr.args(p))
|
|
52
|
+
if (!r.error && r.status === 0) any = true
|
|
53
|
+
}
|
|
54
|
+
return any
|
|
35
55
|
}
|
|
36
56
|
|
|
37
|
-
// 1) Browser binary for this Playwright version.
|
|
38
57
|
const browser = run('playwright', ['install', 'chromium'])
|
|
39
58
|
if (browser.error || browser.status !== 0) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
console.warn(NL + 'zames: could not install Chromium for Playwright automatically.' + NL +
|
|
60
|
+
' Run it manually: npx playwright install chromium' + NL)
|
|
61
|
+
process.exit(0)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (isLinux) {
|
|
65
|
+
if (canSudo()) {
|
|
66
|
+
const deps = run('playwright', ['install-deps', 'chromium'])
|
|
67
|
+
if (deps.error || deps.status !== 0) {
|
|
68
|
+
console.warn(NL + 'zames: could not install Chromium system dependencies automatically.' + NL +
|
|
69
|
+
' Run it manually: sudo npx playwright install-deps chromium' + NL)
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
console.warn(NL + 'zames: on Linux/WSL Chromium needs system libraries (sudo required).' + NL +
|
|
73
|
+
' Run it once manually: sudo npx playwright install-deps chromium' + NL)
|
|
74
|
+
}
|
|
45
75
|
}
|
|
46
76
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
}
|
|
77
|
+
if (isLinux) {
|
|
78
|
+
const haveXclip = has('xclip') || has('xsel')
|
|
79
|
+
const haveWayland = has('wl-paste')
|
|
80
|
+
if (!haveXclip || !haveWayland) {
|
|
81
|
+
if (!canSudo()) {
|
|
82
|
+
console.warn(NL + 'zames: pasting images from the clipboard needs a clipboard tool.' + NL +
|
|
83
|
+
' Install one (root required), e.g.:' + NL +
|
|
84
|
+
' sudo apt install xclip # X11 (Debian/Ubuntu)' + NL +
|
|
85
|
+
' sudo apt install wl-clipboard # Wayland' + NL +
|
|
86
|
+
' Without it, paste a file path or use the attach button in the browser.' + NL)
|
|
87
|
+
} else if (!installPackages(['xclip', 'wl-clipboard'])) {
|
|
88
|
+
console.warn(NL + 'zames: could not install a clipboard tool automatically.' + NL +
|
|
89
|
+
' Install xclip (X11) or wl-clipboard (Wayland) manually.' + NL)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
64
92
|
}
|
|
65
93
|
|
|
66
|
-
// Never fail the package install because of a browser download.
|
|
67
94
|
process.exit(0)
|