@revoengine/cli 1.0.29 → 1.0.31
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 +156 -3
- package/dist/src/automation-contract.generated.d.ts +742 -0
- package/dist/src/automation-contract.generated.js +1021 -0
- package/dist/src/cli.js +9 -1
- package/dist/src/client.d.ts +24 -0
- package/dist/src/client.js +60 -0
- package/dist/src/commands/component.js +56 -23
- package/dist/src/commands/env.js +1 -1
- package/dist/src/commands/index.d.ts +2 -0
- package/dist/src/commands/index.js +2 -0
- package/dist/src/commands/studio.d.ts +3 -0
- package/dist/src/commands/studio.js +114 -0
- package/dist/src/commands/terminal-browser-human-input.d.ts +11 -0
- package/dist/src/commands/terminal-browser-human-input.js +44 -0
- package/dist/src/commands/terminal-browser-interaction.d.ts +25 -0
- package/dist/src/commands/terminal-browser-interaction.js +56 -0
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +151 -0
- package/dist/src/commands/terminal-browser-live-protocol.js +177 -0
- package/dist/src/commands/terminal-browser-live-transport.d.ts +41 -0
- package/dist/src/commands/terminal-browser-live-transport.js +206 -0
- package/dist/src/commands/terminal-browser-live.d.ts +114 -0
- package/dist/src/commands/terminal-browser-live.js +455 -0
- package/dist/src/commands/terminal-browser-observation.d.ts +10 -0
- package/dist/src/commands/terminal-browser-observation.js +27 -0
- package/dist/src/commands/terminal-browser-page-input.d.ts +8 -0
- package/dist/src/commands/terminal-browser-page-input.js +94 -0
- package/dist/src/commands/terminal-browser-profile-preferences.d.ts +37 -0
- package/dist/src/commands/terminal-browser-profile-preferences.js +136 -0
- package/dist/src/commands/terminal-browser-profile.d.ts +52 -0
- package/dist/src/commands/terminal-browser-profile.js +447 -0
- package/dist/src/commands/terminal-browser.d.ts +28 -1
- package/dist/src/commands/terminal-browser.js +401 -55
- package/dist/src/commands/terminal-policy.js +2 -0
- package/dist/src/commands/terminal-public-web-proxy.d.ts +14 -0
- package/dist/src/commands/terminal-public-web-proxy.js +141 -0
- package/dist/src/commands/terminal-public-web.d.ts +11 -0
- package/dist/src/commands/terminal-public-web.js +99 -0
- package/dist/src/commands/terminal.d.ts +1 -0
- package/dist/src/commands/terminal.js +92 -9
- package/dist/src/commands/tests.d.ts +3 -0
- package/dist/src/commands/tests.js +236 -0
- package/dist/src/component-element-validation.d.ts +8 -0
- package/dist/src/component-element-validation.js +79 -0
- package/dist/src/component-lifecycle.d.ts +3 -0
- package/dist/src/component-lifecycle.js +17 -0
- package/dist/src/component-lock.d.ts +17 -12
- package/dist/src/component-lock.js +57 -6
- package/dist/src/component-manifests.js +3 -0
- package/dist/src/component-source-validation.d.ts +5 -0
- package/dist/src/component-source-validation.js +27 -0
- package/dist/src/env-sync.js +67 -9
- package/dist/src/native-tests.d.ts +61 -0
- package/dist/src/native-tests.js +20 -0
- package/dist/src/request-contract.d.ts +39 -0
- package/dist/src/request-contract.js +138 -0
- package/dist/src/resource-syncs/agent-sync.js +47 -7
- package/dist/src/resource-syncs/database-table-sync.js +8 -8
- package/dist/src/resource-syncs/endpoint-sync.js +20 -14
- package/dist/src/resource-syncs/group-sync.js +8 -3
- package/dist/src/resource-syncs/job-template-sync.js +75 -28
- package/dist/src/resource-syncs/role-group-sync.js +8 -0
- package/dist/src/resource-syncs/runtime-definition-validation.d.ts +14 -0
- package/dist/src/resource-syncs/runtime-definition-validation.js +153 -0
- package/dist/src/test-workspace.d.ts +33 -0
- package/dist/src/test-workspace.js +156 -0
- package/dist/src/types.d.ts +1 -0
- package/dist/src/ui.js +12 -0
- package/dist/src/update-notifier.d.ts +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes, randomUUID } from 'node:crypto';
|
|
4
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
5
|
+
const SERVICE = 'com.revoengine.cli.browser-profiles.v1';
|
|
6
|
+
const MAX_BYTES = 8 * 1024 * 1024;
|
|
7
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
8
|
+
export function validateBrowserProfileName(value) {
|
|
9
|
+
if (!/^[a-z0-9][a-z0-9 ._-]{0,63}$/iu.test(value) || value !== value.trim())
|
|
10
|
+
throw new Error('browser_profile_name_invalid');
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export function browserProfileScopeId(scope) {
|
|
14
|
+
validateBrowserProfileName(scope.name);
|
|
15
|
+
const url = new URL(scope.baseUrl);
|
|
16
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password
|
|
17
|
+
|| !UUID.test(scope.instanceId) || !UUID.test(scope.actorUserId) || !UUID.test(scope.terminalId)
|
|
18
|
+
|| !path.isAbsolute(scope.workspace))
|
|
19
|
+
throw new Error('browser_profile_scope_invalid');
|
|
20
|
+
return createHash('sha256').update(JSON.stringify([1, scope.name, url.toString(),
|
|
21
|
+
scope.instanceId.toLowerCase(), scope.actorUserId.toLowerCase(), scope.terminalId.toLowerCase(),
|
|
22
|
+
fs.realpathSync(scope.workspace)])).digest('hex');
|
|
23
|
+
}
|
|
24
|
+
/** Password material is passed on stdin, never in process argv or a plaintext file. */
|
|
25
|
+
export function macOSBrowserProfileKeyStore(platform = process.platform, execute = spawnSync, executeAsync = spawn) {
|
|
26
|
+
if (platform !== 'darwin')
|
|
27
|
+
throw new Error('browser_profile_keystore_unsupported');
|
|
28
|
+
const run = (args, input) => {
|
|
29
|
+
const result = execute('/usr/bin/security', args, { encoding: 'utf8', input,
|
|
30
|
+
timeout: 15_000, maxBuffer: 16_384, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
31
|
+
if (result.error || result.signal)
|
|
32
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
const accountCheck = (account) => {
|
|
36
|
+
if (!/^[a-f0-9]{64}$/u.test(account))
|
|
37
|
+
throw new Error('browser_profile_scope_invalid');
|
|
38
|
+
};
|
|
39
|
+
const runAsync = (args, input) => new Promise((resolve, reject) => {
|
|
40
|
+
const child = executeAsync('/usr/bin/security', args, { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
41
|
+
let stdout = '';
|
|
42
|
+
let failed = false;
|
|
43
|
+
const timer = setTimeout(() => { failed = true; child.kill(); }, 15_000);
|
|
44
|
+
timer.unref();
|
|
45
|
+
child.stdout.on('data', chunk => { stdout += chunk.toString('utf8'); if (stdout.length > 16_384) {
|
|
46
|
+
failed = true;
|
|
47
|
+
child.kill();
|
|
48
|
+
} });
|
|
49
|
+
child.stderr.resume();
|
|
50
|
+
child.stdin.on('error', () => { failed = true; });
|
|
51
|
+
child.on('error', () => { clearTimeout(timer); reject(new Error('browser_profile_keystore_unavailable')); });
|
|
52
|
+
child.on('close', (status, signal) => {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
if (failed || signal || status === null)
|
|
55
|
+
reject(new Error('browser_profile_keystore_unavailable'));
|
|
56
|
+
else
|
|
57
|
+
resolve({ status, stdout });
|
|
58
|
+
});
|
|
59
|
+
child.stdin.end(input);
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
async getAsync(account) {
|
|
63
|
+
accountCheck(account);
|
|
64
|
+
const result = await runAsync(['find-generic-password', '-a', account, '-s', SERVICE, '-w']);
|
|
65
|
+
if (result.status === 44)
|
|
66
|
+
return null;
|
|
67
|
+
if (result.status !== 0 || !/^[a-f0-9]{64}\n?$/u.test(result.stdout))
|
|
68
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
69
|
+
return Buffer.from(result.stdout.trim(), 'hex');
|
|
70
|
+
},
|
|
71
|
+
async createAsync(account, key) {
|
|
72
|
+
accountCheck(account);
|
|
73
|
+
if (key.length !== 32)
|
|
74
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
75
|
+
const result = await runAsync(['-i'], `add-generic-password -a ${account} -s ${SERVICE} -w ${key.toString('hex')}\n`);
|
|
76
|
+
if (result.status !== 0)
|
|
77
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
78
|
+
const confirmed = await this.getAsync(account);
|
|
79
|
+
try {
|
|
80
|
+
if (!confirmed?.equals(key))
|
|
81
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
confirmed?.fill(0);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
async removeAsync(account) {
|
|
88
|
+
accountCheck(account);
|
|
89
|
+
const result = await runAsync(['delete-generic-password', '-a', account, '-s', SERVICE]);
|
|
90
|
+
if (result.status !== 0 && result.status !== 44)
|
|
91
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
92
|
+
},
|
|
93
|
+
get(account) {
|
|
94
|
+
accountCheck(account);
|
|
95
|
+
const result = run(['find-generic-password', '-a', account, '-s', SERVICE, '-w']);
|
|
96
|
+
if (result.status === 44)
|
|
97
|
+
return null;
|
|
98
|
+
if (result.status !== 0 || typeof result.stdout !== 'string' || !/^[a-f0-9]{64}\n?$/u.test(result.stdout))
|
|
99
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
100
|
+
return Buffer.from(result.stdout.trim(), 'hex');
|
|
101
|
+
},
|
|
102
|
+
create(account, key) {
|
|
103
|
+
accountCheck(account);
|
|
104
|
+
if (key.length !== 32)
|
|
105
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
106
|
+
const result = run(['-i'], `add-generic-password -a ${account} -s ${SERVICE} -w ${key.toString('hex')}\n`);
|
|
107
|
+
if (result.status !== 0)
|
|
108
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
109
|
+
const confirmed = this.get(account);
|
|
110
|
+
try {
|
|
111
|
+
if (!confirmed?.equals(key))
|
|
112
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
confirmed?.fill(0);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
remove(account) {
|
|
119
|
+
accountCheck(account);
|
|
120
|
+
const result = run(['delete-generic-password', '-a', account, '-s', SERVICE]);
|
|
121
|
+
if (result.status !== 0 && result.status !== 44)
|
|
122
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function snapshotFiles(file) {
|
|
127
|
+
const prefix = path.basename(file, '.json') + '.';
|
|
128
|
+
return fs.readdirSync(path.dirname(file)).flatMap(name => {
|
|
129
|
+
if (!name.startsWith(prefix) || !name.endsWith('.json'))
|
|
130
|
+
return [];
|
|
131
|
+
const suffix = name.slice(prefix.length, -5);
|
|
132
|
+
const revision = Number(suffix);
|
|
133
|
+
if (!/^[1-9][0-9]*$/u.test(suffix) || !Number.isSafeInteger(revision))
|
|
134
|
+
throw new Error('browser_profile_corrupt');
|
|
135
|
+
return [{ file: path.join(path.dirname(file), name), revision }];
|
|
136
|
+
}).sort((a, b) => b.revision - a.revision);
|
|
137
|
+
}
|
|
138
|
+
export class BrowserProfileLease {
|
|
139
|
+
released = false;
|
|
140
|
+
state;
|
|
141
|
+
revision = 0;
|
|
142
|
+
file;
|
|
143
|
+
scopeId;
|
|
144
|
+
key;
|
|
145
|
+
releaseLock;
|
|
146
|
+
assertLock;
|
|
147
|
+
constructor(file, scopeId, key, releaseLock, assertLock) {
|
|
148
|
+
this.file = file;
|
|
149
|
+
this.scopeId = scopeId;
|
|
150
|
+
this.key = key;
|
|
151
|
+
this.releaseLock = releaseLock;
|
|
152
|
+
this.assertLock = assertLock;
|
|
153
|
+
const snapshot = this.read();
|
|
154
|
+
if (snapshot) {
|
|
155
|
+
this.revision = snapshot.revision;
|
|
156
|
+
try {
|
|
157
|
+
const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(snapshot.iv, 'base64'));
|
|
158
|
+
decipher.setAAD(this.aad(snapshot.revision));
|
|
159
|
+
decipher.setAuthTag(Buffer.from(snapshot.tag, 'base64'));
|
|
160
|
+
const plaintext = Buffer.concat([decipher.update(Buffer.from(snapshot.ciphertext, 'base64')), decipher.final()]);
|
|
161
|
+
try {
|
|
162
|
+
const state = JSON.parse(plaintext.toString('utf8'));
|
|
163
|
+
if (!state || !Array.isArray(state.cookies) || !Array.isArray(state.origins))
|
|
164
|
+
throw new Error('invalid state');
|
|
165
|
+
this.state = state;
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
plaintext.fill(0);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
throw new Error('browser_profile_corrupt');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
aad(revision) { return Buffer.from(JSON.stringify([1, this.scopeId, revision])); }
|
|
177
|
+
read() {
|
|
178
|
+
let fd;
|
|
179
|
+
try {
|
|
180
|
+
const latest = snapshotFiles(this.file)[0];
|
|
181
|
+
if (!latest)
|
|
182
|
+
return undefined;
|
|
183
|
+
fd = fs.openSync(latest.file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
184
|
+
const stat = fs.fstatSync(fd);
|
|
185
|
+
if (!stat.isFile() || stat.size > MAX_BYTES * 2 || (stat.mode & 0o077) !== 0)
|
|
186
|
+
throw new Error('browser_profile_corrupt');
|
|
187
|
+
const value = JSON.parse(fs.readFileSync(fd, 'utf8'));
|
|
188
|
+
if (value.version !== 1 || value.revision !== latest.revision
|
|
189
|
+
|| ![value.iv, value.ciphertext, value.tag].every((item) => typeof item === 'string')
|
|
190
|
+
|| Buffer.from(value.iv, 'base64').length !== 12 || Buffer.from(value.tag, 'base64').length !== 16)
|
|
191
|
+
throw new Error('browser_profile_corrupt');
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (error.code === 'ENOENT')
|
|
196
|
+
return undefined;
|
|
197
|
+
throw new Error('browser_profile_corrupt');
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
if (fd !== undefined)
|
|
201
|
+
fs.closeSync(fd);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
save(state) {
|
|
205
|
+
if (this.released)
|
|
206
|
+
throw new Error('browser_profile_closed');
|
|
207
|
+
this.assertLock();
|
|
208
|
+
if ((this.read()?.revision ?? 0) !== this.revision)
|
|
209
|
+
throw new Error('browser_profile_changed');
|
|
210
|
+
const plaintext = Buffer.from(JSON.stringify(state));
|
|
211
|
+
const temp = `${this.file}.${randomUUID()}.tmp`;
|
|
212
|
+
try {
|
|
213
|
+
if (plaintext.length > MAX_BYTES)
|
|
214
|
+
throw new Error('browser_profile_too_large');
|
|
215
|
+
const revision = this.revision + 1;
|
|
216
|
+
if (!Number.isSafeInteger(revision))
|
|
217
|
+
throw new Error('browser_profile_corrupt');
|
|
218
|
+
const iv = randomBytes(12);
|
|
219
|
+
const cipher = createCipheriv('aes-256-gcm', this.key, iv);
|
|
220
|
+
cipher.setAAD(this.aad(revision));
|
|
221
|
+
const snapshot = { version: 1, revision, iv: iv.toString('base64'),
|
|
222
|
+
ciphertext: Buffer.concat([cipher.update(plaintext), cipher.final()]).toString('base64'),
|
|
223
|
+
tag: cipher.getAuthTag().toString('base64') };
|
|
224
|
+
const fd = fs.openSync(temp, 'wx', 0o600);
|
|
225
|
+
try {
|
|
226
|
+
fs.writeFileSync(fd, JSON.stringify(snapshot));
|
|
227
|
+
fs.fsyncSync(fd);
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
fs.closeSync(fd);
|
|
231
|
+
}
|
|
232
|
+
this.assertLock();
|
|
233
|
+
try {
|
|
234
|
+
fs.linkSync(temp, this.file.replace(/\.json$/u, `.${revision}.json`));
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
if (error.code === 'EEXIST')
|
|
238
|
+
throw new Error('browser_profile_changed');
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
this.revision = revision;
|
|
242
|
+
for (const older of snapshotFiles(this.file).slice(2))
|
|
243
|
+
fs.unlinkSync(older.file);
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
plaintext.fill(0);
|
|
247
|
+
fs.rmSync(temp, { force: true });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
release() {
|
|
251
|
+
if (this.released)
|
|
252
|
+
return;
|
|
253
|
+
this.released = true;
|
|
254
|
+
this.key.fill(0);
|
|
255
|
+
this.releaseLock();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
export class BrowserAuthProfileStore {
|
|
259
|
+
directory;
|
|
260
|
+
keys;
|
|
261
|
+
constructor(directory, keys) {
|
|
262
|
+
this.directory = path.resolve(directory);
|
|
263
|
+
this.keys = keys;
|
|
264
|
+
}
|
|
265
|
+
prepare() {
|
|
266
|
+
fs.mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
267
|
+
if (!fs.lstatSync(this.directory).isDirectory())
|
|
268
|
+
throw new Error('browser_profile_directory_invalid');
|
|
269
|
+
this.directory = fs.realpathSync(this.directory);
|
|
270
|
+
fs.chmodSync(this.directory, 0o700);
|
|
271
|
+
}
|
|
272
|
+
lock(id) {
|
|
273
|
+
this.prepare();
|
|
274
|
+
const file = path.join(this.directory, `${id}.lock`);
|
|
275
|
+
const nonce = randomUUID();
|
|
276
|
+
let fd;
|
|
277
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
278
|
+
try {
|
|
279
|
+
fd = fs.openSync(file, 'wx', 0o600);
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
if (error.code !== 'EEXIST')
|
|
284
|
+
throw error;
|
|
285
|
+
const stat = fs.lstatSync(file);
|
|
286
|
+
if (!stat.isFile())
|
|
287
|
+
throw new Error('browser_profile_busy');
|
|
288
|
+
let owner = 0;
|
|
289
|
+
try {
|
|
290
|
+
owner = Number(JSON.parse(fs.readFileSync(file, 'utf8')).pid);
|
|
291
|
+
}
|
|
292
|
+
catch { /* Only an abandoned incomplete lock can be recovered after five seconds. */ }
|
|
293
|
+
if (Number.isSafeInteger(owner) && owner > 0) {
|
|
294
|
+
try {
|
|
295
|
+
process.kill(owner, 0);
|
|
296
|
+
throw new Error('browser_profile_busy');
|
|
297
|
+
}
|
|
298
|
+
catch (probe) {
|
|
299
|
+
if (probe.code !== 'ESRCH')
|
|
300
|
+
throw new Error('browser_profile_busy');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (Date.now() - stat.mtimeMs < 5_000)
|
|
304
|
+
throw new Error('browser_profile_busy');
|
|
305
|
+
const current = fs.lstatSync(file);
|
|
306
|
+
if (current.ino !== stat.ino || current.dev !== stat.dev)
|
|
307
|
+
throw new Error('browser_profile_busy');
|
|
308
|
+
fs.unlinkSync(file);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (fd === undefined)
|
|
312
|
+
throw new Error('browser_profile_busy');
|
|
313
|
+
try {
|
|
314
|
+
fs.writeFileSync(fd, JSON.stringify({ pid: process.pid, nonce }));
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
fs.closeSync(fd);
|
|
318
|
+
fs.unlinkSync(file);
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
const inode = fs.fstatSync(fd).ino;
|
|
322
|
+
const assert = () => {
|
|
323
|
+
try {
|
|
324
|
+
const stat = fs.lstatSync(file);
|
|
325
|
+
if (!stat.isFile() || stat.ino !== inode || JSON.parse(fs.readFileSync(file, 'utf8')).nonce !== nonce)
|
|
326
|
+
throw new Error('changed');
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
throw new Error('browser_profile_changed');
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const release = () => {
|
|
333
|
+
fs.closeSync(fd);
|
|
334
|
+
try {
|
|
335
|
+
if (fs.lstatSync(file).isFile() && fs.lstatSync(file).ino === inode
|
|
336
|
+
&& JSON.parse(fs.readFileSync(file, 'utf8')).nonce === nonce)
|
|
337
|
+
fs.unlinkSync(file);
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
if (error.code !== 'ENOENT')
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
return { release, assert };
|
|
345
|
+
}
|
|
346
|
+
open(scope) {
|
|
347
|
+
const id = browserProfileScopeId(scope);
|
|
348
|
+
const lock = this.lock(id);
|
|
349
|
+
let key = null;
|
|
350
|
+
try {
|
|
351
|
+
const file = path.join(this.directory, `${id}.json`);
|
|
352
|
+
const existing = snapshotFiles(file);
|
|
353
|
+
for (const snapshot of existing)
|
|
354
|
+
if (!fs.lstatSync(snapshot.file).isFile())
|
|
355
|
+
throw new Error('browser_profile_corrupt');
|
|
356
|
+
key = this.keys.get(id);
|
|
357
|
+
if (!key) {
|
|
358
|
+
if (existing.length)
|
|
359
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
360
|
+
key = randomBytes(32);
|
|
361
|
+
this.keys.create(id, key);
|
|
362
|
+
}
|
|
363
|
+
if (key.length !== 32)
|
|
364
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
365
|
+
return new BrowserProfileLease(file, id, key, lock.release, lock.assert);
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
key?.fill(0);
|
|
369
|
+
lock.release();
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
async openAsync(scope) {
|
|
374
|
+
const id = browserProfileScopeId(scope);
|
|
375
|
+
const lock = this.lock(id);
|
|
376
|
+
let key = null;
|
|
377
|
+
try {
|
|
378
|
+
const file = path.join(this.directory, `${id}.json`);
|
|
379
|
+
const existing = snapshotFiles(file);
|
|
380
|
+
for (const snapshot of existing)
|
|
381
|
+
if (!fs.lstatSync(snapshot.file).isFile())
|
|
382
|
+
throw new Error('browser_profile_corrupt');
|
|
383
|
+
key = this.keys.getAsync ? await this.keys.getAsync(id) : this.keys.get(id);
|
|
384
|
+
if (!key) {
|
|
385
|
+
if (existing.length)
|
|
386
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
387
|
+
key = randomBytes(32);
|
|
388
|
+
if (this.keys.createAsync)
|
|
389
|
+
await this.keys.createAsync(id, key);
|
|
390
|
+
else
|
|
391
|
+
this.keys.create(id, key);
|
|
392
|
+
}
|
|
393
|
+
lock.assert();
|
|
394
|
+
if (key.length !== 32)
|
|
395
|
+
throw new Error('browser_profile_keystore_unavailable');
|
|
396
|
+
return new BrowserProfileLease(file, id, key, lock.release, lock.assert);
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
key?.fill(0);
|
|
400
|
+
lock.release();
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async forgetAsync(scope) {
|
|
405
|
+
const id = browserProfileScopeId(scope);
|
|
406
|
+
const lock = this.lock(id);
|
|
407
|
+
try {
|
|
408
|
+
lock.assert();
|
|
409
|
+
for (const snapshot of snapshotFiles(path.join(this.directory, `${id}.json`)))
|
|
410
|
+
fs.rmSync(snapshot.file, { force: true });
|
|
411
|
+
if (this.keys.removeAsync)
|
|
412
|
+
await this.keys.removeAsync(id);
|
|
413
|
+
else
|
|
414
|
+
this.keys.remove(id);
|
|
415
|
+
lock.assert();
|
|
416
|
+
}
|
|
417
|
+
finally {
|
|
418
|
+
lock.release();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
has(scope) {
|
|
422
|
+
const id = browserProfileScopeId(scope);
|
|
423
|
+
try {
|
|
424
|
+
if (!fs.lstatSync(this.directory).isDirectory())
|
|
425
|
+
throw new Error('browser_profile_directory_invalid');
|
|
426
|
+
return snapshotFiles(path.join(this.directory, `${id}.json`)).length > 0;
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
if (error.code === 'ENOENT')
|
|
430
|
+
return false;
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
forget(scope) {
|
|
435
|
+
const id = browserProfileScopeId(scope);
|
|
436
|
+
const lock = this.lock(id);
|
|
437
|
+
try {
|
|
438
|
+
lock.assert();
|
|
439
|
+
for (const snapshot of snapshotFiles(path.join(this.directory, `${id}.json`)))
|
|
440
|
+
fs.rmSync(snapshot.file, { force: true });
|
|
441
|
+
this.keys.remove(id);
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
lock.release();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type BrowserAuthProfileStore, type BrowserProfileScope } from './terminal-browser-profile.ts';
|
|
2
|
+
import { type BrowserInteraction, type BrowserObservation } from './terminal-browser-interaction.ts';
|
|
3
|
+
import { BrowserLiveHandle, type BrowserLiveOptions } from './terminal-browser-live.ts';
|
|
4
|
+
export type BrowserAction = 'navigate' | 'dom' | 'click' | 'fill' | 'check' | 'select' | 'press' | 'scroll' | 'interact' | 'wait_for' | 'screenshot' | 'tabs' | 'new_tab' | 'select_tab' | 'close_tab' | 'close' | 'read_public';
|
|
2
5
|
export type BrowserCapture = 'viewport' | 'full_page' | 'element' | 'crop';
|
|
3
6
|
export type BrowserClip = {
|
|
4
7
|
x: number;
|
|
@@ -20,6 +23,7 @@ export type BrowserActionInput = {
|
|
|
20
23
|
checked?: boolean;
|
|
21
24
|
key?: string;
|
|
22
25
|
deltaY?: number;
|
|
26
|
+
interaction?: BrowserInteraction;
|
|
23
27
|
state?: 'visible' | 'hidden';
|
|
24
28
|
waitTimeoutMs?: number;
|
|
25
29
|
actionTimeoutMs?: number;
|
|
@@ -34,6 +38,11 @@ export type BrowserActionInput = {
|
|
|
34
38
|
policyGrantRevision?: number;
|
|
35
39
|
signal?: AbortSignal;
|
|
36
40
|
onActionAttempt?: () => void;
|
|
41
|
+
authProfile?: {
|
|
42
|
+
store: BrowserAuthProfileStore;
|
|
43
|
+
scope: BrowserProfileScope;
|
|
44
|
+
};
|
|
45
|
+
resolveAuthProfile?: () => BrowserActionInput['authProfile'] | Promise<BrowserActionInput['authProfile']>;
|
|
37
46
|
};
|
|
38
47
|
export type BrowserTab = {
|
|
39
48
|
id: string;
|
|
@@ -49,6 +58,22 @@ export type BrowserActionResult = {
|
|
|
49
58
|
activeTabId: string | null;
|
|
50
59
|
tabs: BrowserTab[];
|
|
51
60
|
sessionCreated: boolean;
|
|
61
|
+
browserObservation?: BrowserObservation;
|
|
62
|
+
browserProfile?: {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
persistent: boolean;
|
|
66
|
+
default: boolean;
|
|
67
|
+
};
|
|
68
|
+
screenshotTransform?: {
|
|
69
|
+
observationId: string;
|
|
70
|
+
imageWidth: number;
|
|
71
|
+
imageHeight: number;
|
|
72
|
+
cssCrop: BrowserClip;
|
|
73
|
+
scaleX: number;
|
|
74
|
+
scaleY: number;
|
|
75
|
+
coordinateSpace: 'css_viewport';
|
|
76
|
+
};
|
|
52
77
|
};
|
|
53
78
|
export declare function browserUrl(value: string): string;
|
|
54
79
|
export declare function localBrowserUrl(value: string): string;
|
|
@@ -76,3 +101,5 @@ export declare function fillBrowserSecret(input: {
|
|
|
76
101
|
expiresAt: number;
|
|
77
102
|
isAuthorized?: () => boolean;
|
|
78
103
|
}): Promise<void>;
|
|
104
|
+
/** Media and model operations share the same queue; transitions fence the model before awaiting it. */
|
|
105
|
+
export declare function attachBrowserLive(options: BrowserLiveOptions): Promise<BrowserLiveHandle>;
|