@revoengine/cli 1.0.30 → 1.0.33
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 +70 -17
- package/dist/src/automation-contract.generated.d.ts +55 -21
- package/dist/src/automation-contract.generated.js +67 -25
- package/dist/src/client.d.ts +32 -2
- package/dist/src/client.js +54 -13
- package/dist/src/commands/component.js +4 -1
- package/dist/src/commands/database-tables.js +10 -3
- package/dist/src/commands/migrate.js +2 -0
- package/dist/src/commands/terminal-browser-central-profile.d.ts +65 -0
- package/dist/src/commands/terminal-browser-central-profile.js +203 -0
- package/dist/src/commands/terminal-browser-human-input.d.ts +3 -1
- package/dist/src/commands/terminal-browser-human-input.js +3 -1
- package/dist/src/commands/terminal-browser-interaction.js +1 -1
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +34 -2
- package/dist/src/commands/terminal-browser-live-protocol.js +28 -12
- package/dist/src/commands/terminal-browser-live-transport.d.ts +1 -0
- package/dist/src/commands/terminal-browser-live-transport.js +9 -5
- package/dist/src/commands/terminal-browser-live.d.ts +24 -3
- package/dist/src/commands/terminal-browser-live.js +199 -30
- package/dist/src/commands/terminal-browser-page-input.d.ts +4 -1
- package/dist/src/commands/terminal-browser-page-input.js +46 -1
- package/dist/src/commands/terminal-browser-profile-crypto.d.ts +30 -0
- package/dist/src/commands/terminal-browser-profile-crypto.js +101 -0
- package/dist/src/commands/terminal-browser-profile-import-runner.d.ts +31 -0
- package/dist/src/commands/terminal-browser-profile-import-runner.js +112 -0
- package/dist/src/commands/terminal-browser-profile-import.d.ts +28 -0
- package/dist/src/commands/terminal-browser-profile-import.js +125 -0
- package/dist/src/commands/terminal-browser-profile-import.protocol.d.ts +50 -0
- package/dist/src/commands/terminal-browser-profile-import.protocol.js +52 -0
- package/dist/src/commands/terminal-browser-profile-preferences.d.ts +1 -0
- package/dist/src/commands/terminal-browser-profile-preferences.js +16 -0
- package/dist/src/commands/terminal-browser-profile-sync.d.ts +14 -0
- package/dist/src/commands/terminal-browser-profile-sync.js +169 -0
- package/dist/src/commands/terminal-browser-profile-sync.protocol.d.ts +50 -0
- package/dist/src/commands/terminal-browser-profile-sync.protocol.js +19 -0
- package/dist/src/commands/terminal-browser-profile.d.ts +10 -1
- package/dist/src/commands/terminal-browser-profile.js +30 -4
- package/dist/src/commands/terminal-browser-recording.d.ts +39 -0
- package/dist/src/commands/terminal-browser-recording.js +74 -0
- package/dist/src/commands/terminal-browser-recording.protocol.d.ts +49 -0
- package/dist/src/commands/terminal-browser-recording.protocol.js +16 -0
- package/dist/src/commands/terminal-browser.d.ts +14 -1
- package/dist/src/commands/terminal-browser.js +98 -33
- package/dist/src/commands/terminal-output-buffer.d.ts +18 -1
- package/dist/src/commands/terminal-output-buffer.js +95 -8
- package/dist/src/commands/terminal.d.ts +3 -1
- package/dist/src/commands/terminal.js +257 -54
- package/dist/src/component-lock.js +6 -0
- package/dist/src/env-sync.js +3 -0
- package/dist/src/resource-syncs/database-table-sync.d.ts +8 -1
- package/dist/src/resource-syncs/database-table-sync.js +34 -11
- package/dist/src/sync-output.d.ts +3 -3
- package/dist/src/ui.js +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { BROWSER_PROFILE_STATE_MAX_BYTES } from "./terminal-browser-profile-crypto.js";
|
|
3
|
+
const UUID = /^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/iu;
|
|
4
|
+
const errors = new Set(['browser_profile_access_denied', 'browser_profile_busy', 'browser_profile_session_limit',
|
|
5
|
+
'browser_profile_lease_expired', 'browser_profile_revision_conflict', 'browser_profile_upload_incomplete',
|
|
6
|
+
'browser_profile_state_unavailable', 'browser_profile_sync_busy']);
|
|
7
|
+
/** Responses are consumed before the command queue, so a snapshot save cannot deadlock its own reply. */
|
|
8
|
+
export class BrowserProfileRunnerRpc {
|
|
9
|
+
connectionId;
|
|
10
|
+
send;
|
|
11
|
+
pending = new Map();
|
|
12
|
+
closed = false;
|
|
13
|
+
constructor(connectionId, send) {
|
|
14
|
+
if (!UUID.test(connectionId))
|
|
15
|
+
throw new Error('browser_profile_sync_invalid');
|
|
16
|
+
this.connectionId = connectionId;
|
|
17
|
+
this.send = send;
|
|
18
|
+
}
|
|
19
|
+
accept(value) {
|
|
20
|
+
const frame = value;
|
|
21
|
+
if (!frame || frame.type !== 'browser_profile_sync_result' || frame.connectionId !== this.connectionId
|
|
22
|
+
|| typeof frame.requestId !== 'string' || typeof frame.ok !== 'boolean')
|
|
23
|
+
return;
|
|
24
|
+
const pending = this.pending.get(frame.requestId);
|
|
25
|
+
if (!pending)
|
|
26
|
+
return;
|
|
27
|
+
clearTimeout(pending.timer);
|
|
28
|
+
this.pending.delete(frame.requestId);
|
|
29
|
+
if (frame.ok)
|
|
30
|
+
pending.resolve(frame);
|
|
31
|
+
else
|
|
32
|
+
pending.reject(new Error(errors.has(frame.error || '') ? frame.error : 'browser_profile_sync_unavailable'));
|
|
33
|
+
}
|
|
34
|
+
request(browserSessionId, operation, body = {}) {
|
|
35
|
+
if (this.closed)
|
|
36
|
+
return Promise.reject(new Error('browser_profile_lease_expired'));
|
|
37
|
+
if (this.pending.size >= 32)
|
|
38
|
+
return Promise.reject(new Error('browser_profile_sync_busy'));
|
|
39
|
+
const request = { ...body, type: 'browser_profile_sync', connectionId: this.connectionId,
|
|
40
|
+
requestId: body.requestId || randomUUID(), browserSessionId, operation };
|
|
41
|
+
if (this.pending.has(request.requestId))
|
|
42
|
+
return Promise.reject(new Error('browser_profile_sync_busy'));
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const timer = setTimeout(() => { this.pending.delete(request.requestId); reject(new Error('browser_profile_sync_timeout')); }, 10_000);
|
|
45
|
+
timer.unref();
|
|
46
|
+
this.pending.set(request.requestId, { resolve, reject, timer });
|
|
47
|
+
try {
|
|
48
|
+
this.send(request);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
this.pending.delete(request.requestId);
|
|
53
|
+
reject(new Error('browser_profile_sync_unavailable'));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
transport(grant) {
|
|
58
|
+
if (grant.scope.connectionId !== this.connectionId)
|
|
59
|
+
throw new Error('browser_profile_lease_expired');
|
|
60
|
+
const browserSessionId = grant.scope.browserSessionId;
|
|
61
|
+
return {
|
|
62
|
+
read: async () => grant.download ? downloadProfile(grant.download) : null,
|
|
63
|
+
readback: async (expectedRevision) => {
|
|
64
|
+
const result = await this.request(browserSessionId, 'readback', { expectedRevision });
|
|
65
|
+
if (result.revision !== expectedRevision || result.keyVersion !== grant.scope.keyVersion || !result.download)
|
|
66
|
+
throw new Error('browser_profile_revision_conflict');
|
|
67
|
+
const ciphertext = await downloadProfile(result.download);
|
|
68
|
+
return { revision: expectedRevision, keyVersion: result.keyVersion, ciphertext, digest: result.download.digest };
|
|
69
|
+
},
|
|
70
|
+
save: async (input) => {
|
|
71
|
+
const provisioned = await this.request(browserSessionId, 'upload', { requestId: input.operationId,
|
|
72
|
+
expectedRevision: input.expectedRevision, size: input.ciphertext.length, digest: input.digest });
|
|
73
|
+
const target = provisioned.upload;
|
|
74
|
+
if (!target || !UUID.test(target.uploadId) || !['PUT', 'POST'].includes(target.method))
|
|
75
|
+
throw new Error('browser_profile_sync_invalid');
|
|
76
|
+
await uploadProfile(target, input.ciphertext);
|
|
77
|
+
const result = await this.request(browserSessionId, 'commit', { uploadId: target.uploadId });
|
|
78
|
+
if (!Number.isSafeInteger(result.revision) || result.revision !== input.expectedRevision + 1)
|
|
79
|
+
throw new Error('browser_profile_revision_conflict');
|
|
80
|
+
return { revision: result.revision };
|
|
81
|
+
},
|
|
82
|
+
renew: async () => {
|
|
83
|
+
const result = await this.request(browserSessionId, 'renew');
|
|
84
|
+
if (!Number.isSafeInteger(result.leaseRemainingMs) || result.leaseRemainingMs < 1 || result.leaseRemainingMs > 45_000)
|
|
85
|
+
throw new Error('browser_profile_sync_invalid');
|
|
86
|
+
return { leaseRemainingMs: result.leaseRemainingMs };
|
|
87
|
+
},
|
|
88
|
+
release: async () => { await this.request(browserSessionId, 'release'); },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
dispose() {
|
|
92
|
+
this.closed = true;
|
|
93
|
+
for (const pending of this.pending.values()) {
|
|
94
|
+
clearTimeout(pending.timer);
|
|
95
|
+
pending.reject(new Error('browser_profile_lease_expired'));
|
|
96
|
+
}
|
|
97
|
+
this.pending.clear();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function transferUrl(value) {
|
|
101
|
+
try {
|
|
102
|
+
const url = new URL(value);
|
|
103
|
+
if (url.protocol !== 'https:' || url.hostname !== 'storage.googleapis.com' || url.port || url.username || url.password || url.hash)
|
|
104
|
+
throw new Error();
|
|
105
|
+
return url.toString();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Direct bounded ciphertext transfer intentionally bypasses the CLI API/HTTP trace and its auth headers. */
|
|
112
|
+
async function downloadProfile(source) {
|
|
113
|
+
if (!Number.isSafeInteger(source.size) || source.size < 28 || source.size > BROWSER_PROFILE_STATE_MAX_BYTES + 28)
|
|
114
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetch(transferUrl(source.url), { method: 'GET', credentials: 'omit', redirect: 'error', cache: 'no-store',
|
|
117
|
+
referrerPolicy: 'no-referrer', signal: AbortSignal.timeout(15_000) });
|
|
118
|
+
if (!response.ok || !response.body)
|
|
119
|
+
throw new Error();
|
|
120
|
+
const length = response.headers.get('content-length');
|
|
121
|
+
if (length !== null && Number(length) !== source.size) {
|
|
122
|
+
await response.body.cancel();
|
|
123
|
+
throw new Error();
|
|
124
|
+
}
|
|
125
|
+
const reader = response.body.getReader();
|
|
126
|
+
const chunks = [];
|
|
127
|
+
let size = 0;
|
|
128
|
+
try {
|
|
129
|
+
while (true) {
|
|
130
|
+
const part = await reader.read();
|
|
131
|
+
if (part.done)
|
|
132
|
+
break;
|
|
133
|
+
size += part.value.length;
|
|
134
|
+
if (size > source.size)
|
|
135
|
+
throw new Error();
|
|
136
|
+
chunks.push(Buffer.from(part.value));
|
|
137
|
+
}
|
|
138
|
+
if (size !== source.size)
|
|
139
|
+
throw new Error();
|
|
140
|
+
return Buffer.concat(chunks, size);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
await reader.cancel().catch(() => undefined);
|
|
144
|
+
reader.releaseLock();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
throw new Error('browser_profile_transfer_failed');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function uploadProfile(target, ciphertext) {
|
|
152
|
+
if (ciphertext.length < 28 || ciphertext.length > BROWSER_PROFILE_STATE_MAX_BYTES + 28)
|
|
153
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
154
|
+
const headers = { 'Content-Type': 'application/octet-stream' };
|
|
155
|
+
for (const [key, value] of Object.entries(target.headers || {})) {
|
|
156
|
+
if (key.toLowerCase() !== 'content-type' || value !== 'application/octet-stream')
|
|
157
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetch(transferUrl(target.url), { method: target.method, headers, body: new Uint8Array(ciphertext),
|
|
161
|
+
credentials: 'omit', redirect: 'error', cache: 'no-store', referrerPolicy: 'no-referrer', signal: AbortSignal.timeout(30_000) });
|
|
162
|
+
await response.body?.cancel();
|
|
163
|
+
if (!response.ok)
|
|
164
|
+
throw new Error();
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
throw new Error('browser_profile_transfer_failed');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BrowserProfileKeyScope, BrowserProfileSealedKey } from './terminal-browser-profile-crypto.ts';
|
|
2
|
+
/** Private runner channel only. Never forward grants, keys or transfer URLs into execution output. */
|
|
3
|
+
export type BrowserProfileRunnerGrant = {
|
|
4
|
+
profile: {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
scope: BrowserProfileKeyScope;
|
|
9
|
+
sealedKey: BrowserProfileSealedKey;
|
|
10
|
+
revision: number;
|
|
11
|
+
leaseRemainingMs: number;
|
|
12
|
+
download: {
|
|
13
|
+
url: string;
|
|
14
|
+
size: number;
|
|
15
|
+
digest: string;
|
|
16
|
+
} | null;
|
|
17
|
+
};
|
|
18
|
+
export type BrowserProfileSyncRequest = {
|
|
19
|
+
type: 'browser_profile_sync';
|
|
20
|
+
requestId: string;
|
|
21
|
+
connectionId: string;
|
|
22
|
+
browserSessionId: string;
|
|
23
|
+
operation: 'renew' | 'upload' | 'commit' | 'readback' | 'release';
|
|
24
|
+
expectedRevision?: number;
|
|
25
|
+
size?: number;
|
|
26
|
+
digest?: string;
|
|
27
|
+
uploadId?: string;
|
|
28
|
+
};
|
|
29
|
+
export type BrowserProfileSyncResult = {
|
|
30
|
+
type: 'browser_profile_sync_result';
|
|
31
|
+
requestId: string;
|
|
32
|
+
connectionId: string;
|
|
33
|
+
ok: boolean;
|
|
34
|
+
error?: string;
|
|
35
|
+
leaseRemainingMs?: number;
|
|
36
|
+
revision?: number;
|
|
37
|
+
keyVersion?: string;
|
|
38
|
+
download?: {
|
|
39
|
+
url: string;
|
|
40
|
+
size: number;
|
|
41
|
+
digest: string;
|
|
42
|
+
} | null;
|
|
43
|
+
upload?: {
|
|
44
|
+
uploadId: string;
|
|
45
|
+
url: string;
|
|
46
|
+
method: 'PUT' | 'POST';
|
|
47
|
+
headers: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare function validBrowserProfileSyncRequest(value: unknown): value is BrowserProfileSyncRequest;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const UUID = /^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/iu;
|
|
2
|
+
const HEX = /^[a-f\d]{64}$/u;
|
|
3
|
+
export function validBrowserProfileSyncRequest(value) {
|
|
4
|
+
const v = value;
|
|
5
|
+
if (!v || v.type !== 'browser_profile_sync' || !UUID.test(v.requestId) || !UUID.test(v.connectionId)
|
|
6
|
+
|| !HEX.test(v.browserSessionId) || !['renew', 'upload', 'commit', 'readback', 'release'].includes(v.operation))
|
|
7
|
+
return false;
|
|
8
|
+
const base = ['type', 'requestId', 'connectionId', 'browserSessionId', 'operation'];
|
|
9
|
+
if (v.operation === 'upload')
|
|
10
|
+
return Object.keys(v).every(key => [...base, 'expectedRevision', 'size', 'digest'].includes(key))
|
|
11
|
+
&& Number.isSafeInteger(v.expectedRevision) && v.expectedRevision >= 0 && v.expectedRevision < 2147483647
|
|
12
|
+
&& Number.isSafeInteger(v.size) && v.size >= 28 && v.size <= 8388636 && HEX.test(v.digest);
|
|
13
|
+
if (v.operation === 'commit')
|
|
14
|
+
return UUID.test(v.uploadId) && Object.keys(v).every(key => [...base, 'uploadId'].includes(key));
|
|
15
|
+
if (v.operation === 'readback')
|
|
16
|
+
return Number.isSafeInteger(v.expectedRevision) && v.expectedRevision >= 0
|
|
17
|
+
&& v.expectedRevision < 2147483647 && Object.keys(v).every(key => [...base, 'expectedRevision'].includes(key));
|
|
18
|
+
return Object.keys(v).every(key => base.includes(key));
|
|
19
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
2
|
import type { BrowserContext } from 'playwright-core';
|
|
3
3
|
export type BrowserProfileState = Awaited<ReturnType<BrowserContext['storageState']>>;
|
|
4
|
+
export interface BrowserProfilePersistenceLease {
|
|
5
|
+
readonly state?: BrowserProfileState;
|
|
6
|
+
save(state: BrowserProfileState): void | Promise<void>;
|
|
7
|
+
release(): void | Promise<void>;
|
|
8
|
+
}
|
|
4
9
|
export type BrowserProfileScope = {
|
|
5
10
|
name: string;
|
|
6
11
|
baseUrl: string;
|
|
@@ -24,6 +29,7 @@ type KeychainExec = typeof spawnSync;
|
|
|
24
29
|
export declare function macOSBrowserProfileKeyStore(platform?: NodeJS.Platform, execute?: KeychainExec, executeAsync?: typeof spawn): BrowserProfileKeyStore;
|
|
25
30
|
export declare class BrowserProfileLease {
|
|
26
31
|
private released;
|
|
32
|
+
private forgotten;
|
|
27
33
|
readonly state: BrowserProfileState | undefined;
|
|
28
34
|
private revision;
|
|
29
35
|
private readonly file;
|
|
@@ -31,10 +37,13 @@ export declare class BrowserProfileLease {
|
|
|
31
37
|
private readonly key;
|
|
32
38
|
private readonly releaseLock;
|
|
33
39
|
private readonly assertLock;
|
|
34
|
-
|
|
40
|
+
private readonly removeKey?;
|
|
41
|
+
constructor(file: string, scopeId: string, key: Buffer, releaseLock: () => void, assertLock: () => void, removeKey?: () => Promise<void>);
|
|
35
42
|
private aad;
|
|
36
43
|
private read;
|
|
37
44
|
save(state: BrowserProfileState): void;
|
|
45
|
+
/** Explicit migration cleanup while the imported source still owns its writer lock. */
|
|
46
|
+
forget(): Promise<void>;
|
|
38
47
|
release(): void;
|
|
39
48
|
}
|
|
40
49
|
export declare class BrowserAuthProfileStore {
|
|
@@ -137,6 +137,7 @@ function snapshotFiles(file) {
|
|
|
137
137
|
}
|
|
138
138
|
export class BrowserProfileLease {
|
|
139
139
|
released = false;
|
|
140
|
+
forgotten = false;
|
|
140
141
|
state;
|
|
141
142
|
revision = 0;
|
|
142
143
|
file;
|
|
@@ -144,12 +145,14 @@ export class BrowserProfileLease {
|
|
|
144
145
|
key;
|
|
145
146
|
releaseLock;
|
|
146
147
|
assertLock;
|
|
147
|
-
|
|
148
|
+
removeKey;
|
|
149
|
+
constructor(file, scopeId, key, releaseLock, assertLock, removeKey) {
|
|
148
150
|
this.file = file;
|
|
149
151
|
this.scopeId = scopeId;
|
|
150
152
|
this.key = key;
|
|
151
153
|
this.releaseLock = releaseLock;
|
|
152
154
|
this.assertLock = assertLock;
|
|
155
|
+
this.removeKey = removeKey;
|
|
153
156
|
const snapshot = this.read();
|
|
154
157
|
if (snapshot) {
|
|
155
158
|
this.revision = snapshot.revision;
|
|
@@ -202,7 +205,7 @@ export class BrowserProfileLease {
|
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
save(state) {
|
|
205
|
-
if (this.released)
|
|
208
|
+
if (this.released || this.forgotten)
|
|
206
209
|
throw new Error('browser_profile_closed');
|
|
207
210
|
this.assertLock();
|
|
208
211
|
if ((this.read()?.revision ?? 0) !== this.revision)
|
|
@@ -247,6 +250,19 @@ export class BrowserProfileLease {
|
|
|
247
250
|
fs.rmSync(temp, { force: true });
|
|
248
251
|
}
|
|
249
252
|
}
|
|
253
|
+
/** Explicit migration cleanup while the imported source still owns its writer lock. */
|
|
254
|
+
async forget() {
|
|
255
|
+
if (this.released || this.forgotten || !this.removeKey)
|
|
256
|
+
throw new Error('browser_profile_closed');
|
|
257
|
+
this.assertLock();
|
|
258
|
+
if ((this.read()?.revision ?? 0) !== this.revision)
|
|
259
|
+
throw new Error('browser_profile_changed');
|
|
260
|
+
this.forgotten = true;
|
|
261
|
+
for (const snapshot of snapshotFiles(this.file))
|
|
262
|
+
fs.unlinkSync(snapshot.file);
|
|
263
|
+
await this.removeKey();
|
|
264
|
+
this.assertLock();
|
|
265
|
+
}
|
|
250
266
|
release() {
|
|
251
267
|
if (this.released)
|
|
252
268
|
return;
|
|
@@ -362,7 +378,12 @@ export class BrowserAuthProfileStore {
|
|
|
362
378
|
}
|
|
363
379
|
if (key.length !== 32)
|
|
364
380
|
throw new Error('browser_profile_keystore_unavailable');
|
|
365
|
-
return new BrowserProfileLease(file, id, key, lock.release, lock.assert)
|
|
381
|
+
return new BrowserProfileLease(file, id, key, lock.release, lock.assert, async () => {
|
|
382
|
+
if (this.keys.removeAsync)
|
|
383
|
+
await this.keys.removeAsync(id);
|
|
384
|
+
else
|
|
385
|
+
this.keys.remove(id);
|
|
386
|
+
});
|
|
366
387
|
}
|
|
367
388
|
catch (error) {
|
|
368
389
|
key?.fill(0);
|
|
@@ -393,7 +414,12 @@ export class BrowserAuthProfileStore {
|
|
|
393
414
|
lock.assert();
|
|
394
415
|
if (key.length !== 32)
|
|
395
416
|
throw new Error('browser_profile_keystore_unavailable');
|
|
396
|
-
return new BrowserProfileLease(file, id, key, lock.release, lock.assert)
|
|
417
|
+
return new BrowserProfileLease(file, id, key, lock.release, lock.assert, async () => {
|
|
418
|
+
if (this.keys.removeAsync)
|
|
419
|
+
await this.keys.removeAsync(id);
|
|
420
|
+
else
|
|
421
|
+
this.keys.remove(id);
|
|
422
|
+
});
|
|
397
423
|
}
|
|
398
424
|
catch (error) {
|
|
399
425
|
key?.fill(0);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BrowserLiveRecording } from './terminal-browser-live.ts';
|
|
2
|
+
import type { BrowserSessionRecordingGrant } from './terminal-browser-recording.protocol.ts';
|
|
3
|
+
import { transferWorkspaceFile } from './terminal-file.ts';
|
|
4
|
+
type Descriptor = {
|
|
5
|
+
uploadUrl?: string;
|
|
6
|
+
headers?: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}>;
|
|
10
|
+
expiresAt?: number;
|
|
11
|
+
storageEntryId?: string;
|
|
12
|
+
};
|
|
13
|
+
type Options = {
|
|
14
|
+
grant: BrowserSessionRecordingGrant;
|
|
15
|
+
terminalId: string;
|
|
16
|
+
directory: string;
|
|
17
|
+
isAuthorized: () => boolean;
|
|
18
|
+
request: (route: string, token: string, body: {
|
|
19
|
+
size: number;
|
|
20
|
+
}) => Promise<Descriptor>;
|
|
21
|
+
onStatus: (status: 'saved' | 'failed' | 'backpressure', recordingId: string) => void;
|
|
22
|
+
transfer?: typeof transferWorkspaceFile;
|
|
23
|
+
};
|
|
24
|
+
/** Session-owned single-attempt PUT queue. No viewer/socket, transcript payload, cookies or raw credentials. */
|
|
25
|
+
export declare class BrowserSessionRecordingSink {
|
|
26
|
+
private chain;
|
|
27
|
+
private pending;
|
|
28
|
+
private pendingBytes;
|
|
29
|
+
private failed;
|
|
30
|
+
private readonly options;
|
|
31
|
+
constructor(options: Options);
|
|
32
|
+
get authorized(): boolean;
|
|
33
|
+
refresh(grant: BrowserSessionRecordingGrant, isAuthorized: () => boolean): void;
|
|
34
|
+
accept(recording: BrowserLiveRecording): boolean;
|
|
35
|
+
settled(): Promise<void>;
|
|
36
|
+
private assertAuthorized;
|
|
37
|
+
private save;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { transferWorkspaceFile, validateFileTransfer } from "./terminal-file.js";
|
|
4
|
+
/** Session-owned single-attempt PUT queue. No viewer/socket, transcript payload, cookies or raw credentials. */
|
|
5
|
+
export class BrowserSessionRecordingSink {
|
|
6
|
+
chain = Promise.resolve();
|
|
7
|
+
pending = 0;
|
|
8
|
+
pendingBytes = 0;
|
|
9
|
+
failed = false;
|
|
10
|
+
options;
|
|
11
|
+
constructor(options) { this.options = options; }
|
|
12
|
+
get authorized() { return this.options.isAuthorized() && this.options.grant.expiresAt > Date.now(); }
|
|
13
|
+
refresh(grant, isAuthorized) {
|
|
14
|
+
if (grant.browserSessionId !== this.options.grant.browserSessionId)
|
|
15
|
+
throw new Error('browser_recording_scope_invalid');
|
|
16
|
+
this.options.grant = grant;
|
|
17
|
+
this.options.isAuthorized = isAuthorized;
|
|
18
|
+
}
|
|
19
|
+
accept(recording) {
|
|
20
|
+
if (recording.mode === 'local')
|
|
21
|
+
return true;
|
|
22
|
+
if (this.failed)
|
|
23
|
+
return false;
|
|
24
|
+
if (this.pending >= 4 || this.pendingBytes + recording.size > 256 * 1024 * 1024) {
|
|
25
|
+
this.options.onStatus('backpressure', recording.recordingId);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
this.pending++;
|
|
29
|
+
this.pendingBytes += recording.size;
|
|
30
|
+
this.chain = this.chain.then(() => this.save(recording)).catch(() => {
|
|
31
|
+
this.failed = true;
|
|
32
|
+
this.options.onStatus('failed', recording.recordingId);
|
|
33
|
+
}).finally(() => { this.pending--; this.pendingBytes -= recording.size; });
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
async settled() { await this.chain; }
|
|
37
|
+
assertAuthorized() {
|
|
38
|
+
if (!this.authorized)
|
|
39
|
+
throw new Error('browser_recording_scope_expired');
|
|
40
|
+
}
|
|
41
|
+
async save(recording) {
|
|
42
|
+
this.assertAuthorized();
|
|
43
|
+
if (path.dirname(recording.path) !== this.options.directory)
|
|
44
|
+
throw new Error('browser_recording_path_invalid');
|
|
45
|
+
const source = await fs.lstat(recording.path);
|
|
46
|
+
if (!source.isFile() || source.isSymbolicLink() || source.size !== recording.size)
|
|
47
|
+
throw new Error('browser_recording_source_changed');
|
|
48
|
+
const { grant, terminalId, request } = this.options;
|
|
49
|
+
const route = `/agents/terminals/${terminalId}/browser-recording-runner/${grant.grantId}/${recording.recordingId}`;
|
|
50
|
+
const descriptor = await request(`${route}/provision`, grant.token, { size: recording.size });
|
|
51
|
+
this.assertAuthorized();
|
|
52
|
+
if (!descriptor.storageEntryId) {
|
|
53
|
+
if (!descriptor.expiresAt || descriptor.expiresAt > grant.expiresAt || descriptor.expiresAt <= Date.now())
|
|
54
|
+
throw new Error('browser_recording_upload_invalid');
|
|
55
|
+
const transfer = { path: recording.path, url: descriptor.uploadUrl, headers: descriptor.headers, overwrite: false, offset: null, length: null };
|
|
56
|
+
if (!validateFileTransfer(transfer))
|
|
57
|
+
throw new Error('browser_recording_upload_invalid');
|
|
58
|
+
// A transport failure may mean the provider accepted the PUT. Check finalization, never repeat it.
|
|
59
|
+
try {
|
|
60
|
+
const result = await (this.options.transfer || transferWorkspaceFile)(this.options.directory, 'upload_file', transfer, AbortSignal.timeout(Math.max(1, descriptor.expiresAt - Date.now())));
|
|
61
|
+
if (!result.complete)
|
|
62
|
+
throw new Error('browser_recording_upload_unconfirmed');
|
|
63
|
+
}
|
|
64
|
+
catch { /* Exact-size provider verification below resolves an uncertain PUT without replay. */ }
|
|
65
|
+
this.assertAuthorized();
|
|
66
|
+
const finalized = await request(`${route}/finalize`, grant.token, { size: recording.size });
|
|
67
|
+
if (!finalized.storageEntryId)
|
|
68
|
+
throw new Error('browser_recording_upload_unconfirmed');
|
|
69
|
+
}
|
|
70
|
+
this.options.onStatus('saved', recording.recordingId);
|
|
71
|
+
if (recording.mode === 'storage')
|
|
72
|
+
await fs.unlink(recording.path);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Backend-owned destination. Not accepted from the runner or model. */
|
|
2
|
+
export type BrowserRecordingStorageScope = {
|
|
3
|
+
kind: 'private';
|
|
4
|
+
namespace: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'agent';
|
|
7
|
+
namespace: 'agents' | 'explorer';
|
|
8
|
+
agentId: string;
|
|
9
|
+
agentRunId: string;
|
|
10
|
+
rootStorageEntryId: string;
|
|
11
|
+
};
|
|
12
|
+
/** Private execute channel only. Tokens and signed upload targets must never enter model output or logs. */
|
|
13
|
+
export type BrowserSessionRecordingGrant = {
|
|
14
|
+
grantId: string;
|
|
15
|
+
token: string;
|
|
16
|
+
browserSessionId: string;
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
settings: {
|
|
19
|
+
fps: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
alwaysRecord: boolean;
|
|
23
|
+
recordingMode: 'local' | 'storage' | 'both';
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type BrowserSessionRecordingAuthority = Omit<BrowserSessionRecordingGrant, 'token'> & {
|
|
27
|
+
/** Older personal grants may omit this; Agent uploads always require a pinned scope. */
|
|
28
|
+
storageScope?: BrowserRecordingStorageScope;
|
|
29
|
+
tokenHash: string;
|
|
30
|
+
instanceId: string;
|
|
31
|
+
actorUserId: string;
|
|
32
|
+
threadId: string;
|
|
33
|
+
agentTerminalId: string;
|
|
34
|
+
agentTerminalWorkspaceId: string;
|
|
35
|
+
connectionId: string;
|
|
36
|
+
grantRevision: number;
|
|
37
|
+
connectionRevision: number;
|
|
38
|
+
browserProfileId?: string;
|
|
39
|
+
executionId: string;
|
|
40
|
+
network?: {
|
|
41
|
+
source: 'once' | 'lease' | 'thread';
|
|
42
|
+
authorizationId: string;
|
|
43
|
+
expiresAt: number | null;
|
|
44
|
+
access: 'local' | 'full';
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export declare const browserRecordingAuthorityKey: (id: string) => string;
|
|
48
|
+
export declare const browserRecordingConsentKey: (id: string) => string;
|
|
49
|
+
export declare function validBrowserRecordingGrant(value: unknown): value is BrowserSessionRecordingGrant;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const browserRecordingAuthorityKey = (id) => `terminal:browser-recording-authority:${id}`;
|
|
2
|
+
export const browserRecordingConsentKey = (id) => `terminal:browser-recording-consent:${id}`;
|
|
3
|
+
export function validBrowserRecordingGrant(value) {
|
|
4
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
5
|
+
return false;
|
|
6
|
+
const grant = value, settings = grant.settings;
|
|
7
|
+
return /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/iu.test(grant.grantId)
|
|
8
|
+
&& /^[A-Za-z0-9_-]{43}$/u.test(grant.token) && /^[a-f0-9]{64}$/iu.test(grant.browserSessionId)
|
|
9
|
+
&& Number.isSafeInteger(grant.expiresAt) && grant.expiresAt > Date.now() && grant.expiresAt <= Date.now() + 65 * 60000
|
|
10
|
+
&& !!settings && typeof settings === 'object' && !Array.isArray(settings)
|
|
11
|
+
&& Number.isInteger(settings.fps) && settings.fps >= 5 && settings.fps <= 60
|
|
12
|
+
&& Number.isInteger(settings.width) && settings.width >= 320 && settings.width <= 3840
|
|
13
|
+
&& Number.isInteger(settings.height) && settings.height >= 480 && settings.height <= 2160
|
|
14
|
+
&& typeof settings.alwaysRecord === 'boolean'
|
|
15
|
+
&& ['local', 'storage', 'both'].includes(settings.recordingMode);
|
|
16
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BrowserAuthProfileStore, type BrowserProfileScope } from './terminal-browser-profile.ts';
|
|
1
|
+
import { type BrowserAuthProfileStore, type BrowserProfilePersistenceLease, type BrowserProfileScope } from './terminal-browser-profile.ts';
|
|
2
2
|
import { type BrowserInteraction, type BrowserObservation } from './terminal-browser-interaction.ts';
|
|
3
3
|
import { BrowserLiveHandle, type BrowserLiveOptions } from './terminal-browser-live.ts';
|
|
4
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';
|
|
@@ -42,6 +42,16 @@ export type BrowserActionInput = {
|
|
|
42
42
|
store: BrowserAuthProfileStore;
|
|
43
43
|
scope: BrowserProfileScope;
|
|
44
44
|
};
|
|
45
|
+
centralProfile?: {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
lease: BrowserProfilePersistenceLease;
|
|
49
|
+
};
|
|
50
|
+
recording?: {
|
|
51
|
+
options: BrowserLiveOptions;
|
|
52
|
+
networkAccessExpiresAt: number | null;
|
|
53
|
+
policyGrantRevision: number;
|
|
54
|
+
};
|
|
45
55
|
resolveAuthProfile?: () => BrowserActionInput['authProfile'] | Promise<BrowserActionInput['authProfile']>;
|
|
46
56
|
};
|
|
47
57
|
export type BrowserTab = {
|
|
@@ -49,6 +59,7 @@ export type BrowserTab = {
|
|
|
49
59
|
title: string;
|
|
50
60
|
url: string;
|
|
51
61
|
active: boolean;
|
|
62
|
+
popup?: boolean;
|
|
52
63
|
};
|
|
53
64
|
export type BrowserActionResult = {
|
|
54
65
|
dom: string;
|
|
@@ -90,6 +101,8 @@ export declare function threadBrowserScopes(): Array<{
|
|
|
90
101
|
export declare function closeThreadBrowserSession(browserSessionId: string): Promise<void>;
|
|
91
102
|
export declare function browserSessionIds(): string[];
|
|
92
103
|
export declare function hasBrowserSessions(): boolean;
|
|
104
|
+
/** Revocation closes only this central context and never checkpoints its authentication. */
|
|
105
|
+
export declare function revokeBrowserProfileSession(browserSessionId: string, profileId: string): Promise<void>;
|
|
93
106
|
export declare function writePrivateScreenshot(file: string, bytes: Buffer): void;
|
|
94
107
|
export declare function runBrowserAction(input: BrowserActionInput): Promise<BrowserActionResult>;
|
|
95
108
|
export declare function fillBrowserSecret(input: {
|