@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.
Files changed (54) hide show
  1. package/README.md +70 -17
  2. package/dist/src/automation-contract.generated.d.ts +55 -21
  3. package/dist/src/automation-contract.generated.js +67 -25
  4. package/dist/src/client.d.ts +32 -2
  5. package/dist/src/client.js +54 -13
  6. package/dist/src/commands/component.js +4 -1
  7. package/dist/src/commands/database-tables.js +10 -3
  8. package/dist/src/commands/migrate.js +2 -0
  9. package/dist/src/commands/terminal-browser-central-profile.d.ts +65 -0
  10. package/dist/src/commands/terminal-browser-central-profile.js +203 -0
  11. package/dist/src/commands/terminal-browser-human-input.d.ts +3 -1
  12. package/dist/src/commands/terminal-browser-human-input.js +3 -1
  13. package/dist/src/commands/terminal-browser-interaction.js +1 -1
  14. package/dist/src/commands/terminal-browser-live-protocol.d.ts +34 -2
  15. package/dist/src/commands/terminal-browser-live-protocol.js +28 -12
  16. package/dist/src/commands/terminal-browser-live-transport.d.ts +1 -0
  17. package/dist/src/commands/terminal-browser-live-transport.js +9 -5
  18. package/dist/src/commands/terminal-browser-live.d.ts +24 -3
  19. package/dist/src/commands/terminal-browser-live.js +199 -30
  20. package/dist/src/commands/terminal-browser-page-input.d.ts +4 -1
  21. package/dist/src/commands/terminal-browser-page-input.js +46 -1
  22. package/dist/src/commands/terminal-browser-profile-crypto.d.ts +30 -0
  23. package/dist/src/commands/terminal-browser-profile-crypto.js +101 -0
  24. package/dist/src/commands/terminal-browser-profile-import-runner.d.ts +31 -0
  25. package/dist/src/commands/terminal-browser-profile-import-runner.js +112 -0
  26. package/dist/src/commands/terminal-browser-profile-import.d.ts +28 -0
  27. package/dist/src/commands/terminal-browser-profile-import.js +125 -0
  28. package/dist/src/commands/terminal-browser-profile-import.protocol.d.ts +50 -0
  29. package/dist/src/commands/terminal-browser-profile-import.protocol.js +52 -0
  30. package/dist/src/commands/terminal-browser-profile-preferences.d.ts +1 -0
  31. package/dist/src/commands/terminal-browser-profile-preferences.js +16 -0
  32. package/dist/src/commands/terminal-browser-profile-sync.d.ts +14 -0
  33. package/dist/src/commands/terminal-browser-profile-sync.js +169 -0
  34. package/dist/src/commands/terminal-browser-profile-sync.protocol.d.ts +50 -0
  35. package/dist/src/commands/terminal-browser-profile-sync.protocol.js +19 -0
  36. package/dist/src/commands/terminal-browser-profile.d.ts +10 -1
  37. package/dist/src/commands/terminal-browser-profile.js +30 -4
  38. package/dist/src/commands/terminal-browser-recording.d.ts +39 -0
  39. package/dist/src/commands/terminal-browser-recording.js +74 -0
  40. package/dist/src/commands/terminal-browser-recording.protocol.d.ts +49 -0
  41. package/dist/src/commands/terminal-browser-recording.protocol.js +16 -0
  42. package/dist/src/commands/terminal-browser.d.ts +14 -1
  43. package/dist/src/commands/terminal-browser.js +98 -33
  44. package/dist/src/commands/terminal-output-buffer.d.ts +18 -1
  45. package/dist/src/commands/terminal-output-buffer.js +95 -8
  46. package/dist/src/commands/terminal.d.ts +3 -1
  47. package/dist/src/commands/terminal.js +257 -54
  48. package/dist/src/component-lock.js +6 -0
  49. package/dist/src/env-sync.js +3 -0
  50. package/dist/src/resource-syncs/database-table-sync.d.ts +8 -1
  51. package/dist/src/resource-syncs/database-table-sync.js +34 -11
  52. package/dist/src/sync-output.d.ts +3 -3
  53. package/dist/src/ui.js +1 -0
  54. package/package.json +5 -5
@@ -0,0 +1,101 @@
1
+ import { createCipheriv, createDecipheriv, createHash, createPublicKey, diffieHellman, generateKeyPairSync, hkdfSync, randomBytes } from 'node:crypto';
2
+ export const BROWSER_PROFILE_STATE_MAX_BYTES = 8 * 1024 * 1024;
3
+ function decode(value, size) {
4
+ if (typeof value !== 'string' || value.length > 256)
5
+ throw new Error('browser_profile_cipher_invalid');
6
+ const result = Buffer.from(value, 'base64');
7
+ if (result.toString('base64') !== value || size !== undefined && result.length !== size)
8
+ throw new Error('browser_profile_cipher_invalid');
9
+ return result;
10
+ }
11
+ function keyAad(scope) {
12
+ return Buffer.from(JSON.stringify(['revo-browser-profile-key-v1', scope.instanceId, scope.browserProfileId, scope.keyVersion,
13
+ scope.browserSessionId, scope.actorUserId, scope.assistantThreadId, scope.agentTerminalId, scope.agentTerminalWorkspaceId,
14
+ scope.connectionId, scope.generation, scope.keyId]));
15
+ }
16
+ function stateAad(scope) {
17
+ if (!Number.isSafeInteger(scope.revision) || scope.revision < 1)
18
+ throw new Error('browser_profile_cipher_invalid');
19
+ return Buffer.from(JSON.stringify(['revo-browser-profile-state-v1', scope.instanceId, scope.browserProfileId, scope.keyVersion, scope.revision]));
20
+ }
21
+ /** The deployment Vault key never leaves the server; only a per-profile key is sealed to this connection. */
22
+ export function sealBrowserProfileKey(dataKey, recipientPublicKey, scope) {
23
+ if (dataKey.length !== 32)
24
+ throw new Error('browser_profile_cipher_invalid');
25
+ let shared;
26
+ let transportKey;
27
+ try {
28
+ const der = decode(recipientPublicKey);
29
+ if (createHash('sha256').update(der).digest('hex') !== scope.keyId)
30
+ throw new Error();
31
+ const recipient = createPublicKey({ key: der, format: 'der', type: 'spki' });
32
+ if (recipient.asymmetricKeyType !== 'x25519')
33
+ throw new Error();
34
+ const ephemeral = generateKeyPairSync('x25519');
35
+ shared = diffieHellman({ privateKey: ephemeral.privateKey, publicKey: recipient });
36
+ transportKey = Buffer.from(hkdfSync('sha256', shared, keyAad(scope), Buffer.from('revo-browser-profile-transport-v1'), 32));
37
+ const iv = randomBytes(12);
38
+ const cipher = createCipheriv('aes-256-gcm', transportKey, iv);
39
+ cipher.setAAD(keyAad(scope));
40
+ const ciphertext = Buffer.concat([cipher.update(dataKey), cipher.final()]);
41
+ return { ephemeralPublicKey: ephemeral.publicKey.export({ format: 'der', type: 'spki' }).toString('base64'),
42
+ iv: iv.toString('base64'), ciphertext: ciphertext.toString('base64'), tag: cipher.getAuthTag().toString('base64') };
43
+ }
44
+ catch {
45
+ throw new Error('browser_profile_cipher_invalid');
46
+ }
47
+ finally {
48
+ shared?.fill(0);
49
+ transportKey?.fill(0);
50
+ }
51
+ }
52
+ export function openBrowserProfileKey(envelope, privateKey, scope) {
53
+ let shared;
54
+ let transportKey;
55
+ try {
56
+ if (privateKey.asymmetricKeyType !== 'x25519')
57
+ throw new Error();
58
+ const ownDer = createPublicKey(privateKey).export({ format: 'der', type: 'spki' });
59
+ if (createHash('sha256').update(ownDer).digest('hex') !== scope.keyId)
60
+ throw new Error();
61
+ const publicKey = createPublicKey({ key: decode(envelope.ephemeralPublicKey), format: 'der', type: 'spki' });
62
+ if (publicKey.asymmetricKeyType !== 'x25519')
63
+ throw new Error();
64
+ shared = diffieHellman({ privateKey, publicKey });
65
+ transportKey = Buffer.from(hkdfSync('sha256', shared, keyAad(scope), Buffer.from('revo-browser-profile-transport-v1'), 32));
66
+ const decipher = createDecipheriv('aes-256-gcm', transportKey, decode(envelope.iv, 12));
67
+ decipher.setAAD(keyAad(scope));
68
+ decipher.setAuthTag(decode(envelope.tag, 16));
69
+ return Buffer.concat([decipher.update(decode(envelope.ciphertext, 32)), decipher.final()]);
70
+ }
71
+ catch {
72
+ throw new Error('browser_profile_cipher_invalid');
73
+ }
74
+ finally {
75
+ shared?.fill(0);
76
+ transportKey?.fill(0);
77
+ }
78
+ }
79
+ /** Binary opaque object: 12-byte nonce, 16-byte tag, authenticated ciphertext. No browser values in metadata. */
80
+ export function encryptBrowserProfileState(plaintext, dataKey, scope) {
81
+ if (plaintext.length > BROWSER_PROFILE_STATE_MAX_BYTES || dataKey.length !== 32)
82
+ throw new Error('browser_profile_state_too_large');
83
+ const iv = randomBytes(12);
84
+ const cipher = createCipheriv('aes-256-gcm', dataKey, iv);
85
+ cipher.setAAD(stateAad(scope));
86
+ const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
87
+ return Buffer.concat([iv, cipher.getAuthTag(), ciphertext]);
88
+ }
89
+ export function decryptBrowserProfileState(ciphertext, dataKey, scope) {
90
+ if (ciphertext.length < 28 || ciphertext.length > BROWSER_PROFILE_STATE_MAX_BYTES + 28 || dataKey.length !== 32)
91
+ throw new Error('browser_profile_cipher_invalid');
92
+ try {
93
+ const decipher = createDecipheriv('aes-256-gcm', dataKey, ciphertext.subarray(0, 12));
94
+ decipher.setAuthTag(ciphertext.subarray(12, 28));
95
+ decipher.setAAD(stateAad(scope));
96
+ return Buffer.concat([decipher.update(ciphertext.subarray(28)), decipher.final()]);
97
+ }
98
+ catch {
99
+ throw new Error('browser_profile_cipher_invalid');
100
+ }
101
+ }
@@ -0,0 +1,31 @@
1
+ import { type KeyObject } from 'node:crypto';
2
+ import { BrowserProfileRunnerRpc } from './terminal-browser-profile-sync.ts';
3
+ import { LegacyBrowserProfileImporter } from './terminal-browser-profile-import.ts';
4
+ import { type BrowserProfileImportRequest, type BrowserProfileImportReply } from './terminal-browser-profile-import.protocol.ts';
5
+ type Options = {
6
+ connectionId: string;
7
+ instanceId: string;
8
+ terminalId: string;
9
+ keyId: string;
10
+ privateKey: KeyObject;
11
+ baseUrl: string;
12
+ importer: LegacyBrowserProfileImporter;
13
+ rpc: BrowserProfileRunnerRpc;
14
+ authorized(frame: BrowserProfileImportRequest): boolean;
15
+ send(reply: BrowserProfileImportReply): void;
16
+ };
17
+ /** Runs outside the ordinary command queue, so private renewal/readback replies cannot deadlock import. */
18
+ export declare class BrowserProfileImportRunner {
19
+ private readonly options;
20
+ private readonly entries;
21
+ private closed;
22
+ constructor(options: Options);
23
+ accept(value: unknown): void;
24
+ private run;
25
+ private send;
26
+ acceptAck(value: unknown): void;
27
+ revokeProfile(profileId: string): void;
28
+ private finish;
29
+ dispose(): void;
30
+ }
31
+ export {};
@@ -0,0 +1,112 @@
1
+ import fs from 'node:fs';
2
+ import { createHash } from 'node:crypto';
3
+ import { CentralBrowserProfileLease } from "./terminal-browser-central-profile.js";
4
+ import { browserProfileImportError, validBrowserProfileImportRequest } from "./terminal-browser-profile-import.protocol.js";
5
+ /** Runs outside the ordinary command queue, so private renewal/readback replies cannot deadlock import. */
6
+ export class BrowserProfileImportRunner {
7
+ options;
8
+ entries = new Map();
9
+ closed = false;
10
+ constructor(options) { this.options = options; }
11
+ accept(value) {
12
+ if (this.closed || !validBrowserProfileImportRequest(value))
13
+ return;
14
+ const frame = value;
15
+ if (frame.connectionId !== this.options.connectionId || frame.instanceId !== this.options.instanceId
16
+ || frame.scope.agentTerminalId !== this.options.terminalId || frame.scope.keyId !== this.options.keyId)
17
+ return;
18
+ const signature = createHash('sha256').update(JSON.stringify(frame)).digest('hex');
19
+ const existing = this.entries.get(frame.requestId);
20
+ if (existing) {
21
+ if (existing.signature === signature && existing.reply)
22
+ this.send(existing.reply, existing);
23
+ return;
24
+ }
25
+ for (const [id, entry] of this.entries)
26
+ if (entry.reply && !entry.lease && Date.now() - entry.createdAt > 600_000)
27
+ this.entries.delete(id);
28
+ if (this.entries.size >= 64) {
29
+ try {
30
+ this.options.send({ type: 'browser_profile_import_result', requestId: frame.requestId,
31
+ connectionId: this.options.connectionId, ok: false, error: 'browser_profile_import_busy' });
32
+ }
33
+ catch { /* Socket teardown owns cleanup. */ }
34
+ return;
35
+ }
36
+ const entry = { signature, createdAt: Date.now(), controller: new AbortController(), profileId: frame.grant?.profile.id };
37
+ this.entries.set(frame.requestId, entry);
38
+ void this.run(frame, entry);
39
+ }
40
+ async run(frame, entry) {
41
+ const signal = AbortSignal.any([entry.controller.signal, AbortSignal.timeout(frame.remainingMs)]);
42
+ const allowed = () => !this.closed && !signal.aborted && this.options.authorized(frame);
43
+ const assertAllowed = () => { if (!allowed())
44
+ throw new Error('browser_profile_access_denied'); };
45
+ try {
46
+ assertAllowed();
47
+ const workspace = fs.realpathSync(frame.workspace);
48
+ if (workspace !== frame.workspace)
49
+ throw new Error('browser_profile_access_denied');
50
+ const owner = { baseUrl: this.options.baseUrl, instanceId: this.options.instanceId,
51
+ actorUserId: frame.scope.actorUserId, terminalId: this.options.terminalId, workspace };
52
+ if (frame.operation === 'catalog') {
53
+ const profiles = await this.options.importer.catalog(owner);
54
+ assertAllowed();
55
+ entry.reply = { type: 'browser_profile_import_result', requestId: frame.requestId,
56
+ connectionId: this.options.connectionId, ok: true, profiles };
57
+ }
58
+ else {
59
+ const grant = frame.grant;
60
+ entry.lease = await CentralBrowserProfileLease.open(grant, this.options.privateKey, this.options.rpc.transport(grant), () => entry.controller.abort());
61
+ const result = await this.options.importer.importProfile(owner, frame.localProfileId, entry.lease, { signal, isAuthorized: allowed, removeLocalCopy: frame.removeLocalCopy === true });
62
+ assertAllowed();
63
+ entry.reply = { type: 'browser_profile_import_result', requestId: frame.requestId,
64
+ connectionId: this.options.connectionId, ok: true, result };
65
+ }
66
+ }
67
+ catch (error) {
68
+ await entry.lease?.release();
69
+ entry.lease = undefined;
70
+ entry.reply = { type: 'browser_profile_import_result', requestId: frame.requestId,
71
+ connectionId: this.options.connectionId, ok: false, error: browserProfileImportError(error) };
72
+ }
73
+ if (!this.closed)
74
+ this.send(entry.reply, entry);
75
+ }
76
+ send(reply, entry) {
77
+ try {
78
+ this.options.send(reply);
79
+ if (!entry.ackTimeout) {
80
+ entry.ackTimeout = setTimeout(() => this.finish(entry), 10_000);
81
+ entry.ackTimeout.unref();
82
+ }
83
+ }
84
+ catch {
85
+ this.finish(entry);
86
+ }
87
+ }
88
+ acceptAck(value) {
89
+ const frame = value;
90
+ if (!frame || frame.type !== 'browser_profile_import_ack' || frame.connectionId !== this.options.connectionId
91
+ || typeof frame.ok !== 'boolean' || typeof frame.requestId !== 'string')
92
+ return;
93
+ const entry = this.entries.get(frame.requestId);
94
+ if (entry?.reply)
95
+ this.finish(entry);
96
+ }
97
+ revokeProfile(profileId) {
98
+ for (const entry of this.entries.values())
99
+ if (entry.profileId === profileId)
100
+ this.finish(entry);
101
+ }
102
+ finish(entry) {
103
+ if (entry.ackTimeout)
104
+ clearTimeout(entry.ackTimeout);
105
+ entry.ackTimeout = undefined;
106
+ entry.controller.abort();
107
+ void entry.lease?.release();
108
+ entry.lease = undefined;
109
+ }
110
+ dispose() { this.closed = true; for (const entry of this.entries.values())
111
+ this.finish(entry); }
112
+ }
@@ -0,0 +1,28 @@
1
+ import { CentralBrowserProfileLease } from './terminal-browser-central-profile.ts';
2
+ import { BrowserAuthProfileStore, type BrowserProfileState } from './terminal-browser-profile.ts';
3
+ import { type BrowserProfileOwner } from './terminal-browser-profile-preferences.ts';
4
+ import { type BrowserProfileImportResult } from './terminal-browser-profile-import.protocol.ts';
5
+ type Restore = (state: BrowserProfileState, signal: AbortSignal) => Promise<BrowserProfileState>;
6
+ type ImportOptions = {
7
+ removeLocalCopy: boolean;
8
+ signal: AbortSignal;
9
+ isAuthorized(): boolean;
10
+ };
11
+ /** Local legacy keys are touched only after a human migration request, never during connect. */
12
+ export declare class LegacyBrowserProfileImporter {
13
+ private store?;
14
+ private importing;
15
+ private readonly available;
16
+ private readonly createStore;
17
+ private readonly restore;
18
+ constructor(available: boolean, createStore: () => BrowserAuthProfileStore, restore?: Restore);
19
+ private localStore;
20
+ catalog(owner: BrowserProfileOwner): Promise<Array<{
21
+ id: string;
22
+ name: string;
23
+ }>>;
24
+ importProfile(owner: BrowserProfileOwner, localProfileId: string, target: CentralBrowserProfileLease, options: ImportOptions): Promise<BrowserProfileImportResult>;
25
+ }
26
+ /** Reconstruct only browser state. Origin navigations are intercepted; no website receives imported cookies. */
27
+ export declare function restoreBrowserProfileForImport(state: BrowserProfileState, signal: AbortSignal): Promise<BrowserProfileState>;
28
+ export {};
@@ -0,0 +1,125 @@
1
+ import { BrowserProfilePreferences } from "./terminal-browser-profile-preferences.js";
2
+ import { browserProfileImportError } from "./terminal-browser-profile-import.protocol.js";
3
+ /** Local legacy keys are touched only after a human migration request, never during connect. */
4
+ export class LegacyBrowserProfileImporter {
5
+ store;
6
+ importing = false;
7
+ available;
8
+ createStore;
9
+ restore;
10
+ constructor(available, createStore, restore = restoreBrowserProfileForImport) {
11
+ this.available = available;
12
+ this.createStore = createStore;
13
+ this.restore = restore;
14
+ }
15
+ localStore() {
16
+ if (!this.available)
17
+ throw new Error('browser_profile_import_unavailable');
18
+ return this.store ??= this.createStore();
19
+ }
20
+ async catalog(owner) {
21
+ const store = this.localStore();
22
+ return (await new BrowserProfilePreferences(store).allChoicesAsync(owner))
23
+ .filter(choice => choice.persistent && store.has({ ...owner, name: choice.name }))
24
+ .map(({ id, name }) => ({ id, name }));
25
+ }
26
+ async importProfile(owner, localProfileId, target, options) {
27
+ if (this.importing)
28
+ throw new Error('browser_profile_import_busy');
29
+ this.importing = true;
30
+ const authorized = () => {
31
+ if (options.signal.aborted || !options.isAuthorized())
32
+ throw new Error('browser_profile_access_denied');
33
+ };
34
+ try {
35
+ authorized();
36
+ if (!/^[a-f\d]{64}$/u.test(localProfileId) || target.currentRevision !== 0 || target.state !== undefined)
37
+ throw new Error('browser_profile_import_target_changed');
38
+ const selected = (await this.catalog(owner)).find(choice => choice.id === localProfileId);
39
+ if (!selected)
40
+ throw new Error('browser_profile_import_source_unavailable');
41
+ authorized();
42
+ const store = this.localStore();
43
+ const source = await store.openAsync({ ...owner, name: selected.name });
44
+ try {
45
+ authorized();
46
+ if (!source.state)
47
+ throw new Error('browser_profile_import_source_unavailable');
48
+ const portable = await this.restore(source.state, options.signal);
49
+ authorized();
50
+ await target.save(portable);
51
+ const cloud = await target.verifySavedState();
52
+ authorized();
53
+ const restored = await this.restore(cloud, options.signal);
54
+ authorized();
55
+ if (canonicalState(restored) !== canonicalState(portable))
56
+ throw new Error('browser_profile_import_restore_failed');
57
+ let localCopy = 'retained';
58
+ if (options.removeLocalCopy) {
59
+ try {
60
+ await source.forget();
61
+ await new BrowserProfilePreferences(store).removeAsync(owner, selected.name);
62
+ localCopy = 'removed';
63
+ }
64
+ catch {
65
+ localCopy = 'cleanup_unconfirmed';
66
+ }
67
+ }
68
+ return { revision: target.currentRevision, localCopy };
69
+ }
70
+ finally {
71
+ source.release();
72
+ }
73
+ }
74
+ catch (error) {
75
+ throw new Error(browserProfileImportError(error));
76
+ }
77
+ finally {
78
+ this.importing = false;
79
+ }
80
+ }
81
+ }
82
+ /** Reconstruct only browser state. Origin navigations are intercepted; no website receives imported cookies. */
83
+ export async function restoreBrowserProfileForImport(state, signal) {
84
+ const bounded = AbortSignal.any([signal, AbortSignal.timeout(15_000)]);
85
+ bounded.throwIfAborted();
86
+ const { chromium } = await import('playwright-core');
87
+ const browser = await chromium.launch({ channel: 'chromium', headless: true, timeout: 15_000,
88
+ args: ['--disable-background-networking'] });
89
+ const abort = () => { void browser.close(); };
90
+ bounded.addEventListener('abort', abort, { once: true });
91
+ let context;
92
+ try {
93
+ bounded.throwIfAborted();
94
+ context = await browser.newContext({ acceptDownloads: false, serviceWorkers: 'block' });
95
+ await context.route('**/*', route => route.abort('blockedbyclient'));
96
+ await context.setStorageState(state);
97
+ const restored = await context.storageState({ indexedDB: true });
98
+ bounded.throwIfAborted();
99
+ return restored;
100
+ }
101
+ finally {
102
+ bounded.removeEventListener('abort', abort);
103
+ await browser.close();
104
+ }
105
+ }
106
+ // Sort semantic collections while preserving order inside IndexedDB record values and key paths.
107
+ function canonicalState(state) {
108
+ const collections = {
109
+ state: { cookies: 'plain', origins: 'origin' }, origin: { localStorage: 'plain', indexedDB: 'database' },
110
+ database: { stores: 'store' }, store: { indexes: 'plain', records: 'plain' },
111
+ };
112
+ const normalize = (value, kind = 'plain') => {
113
+ if (Array.isArray(value))
114
+ return value.map(item => normalize(item));
115
+ if (!value || typeof value !== 'object')
116
+ return value;
117
+ return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => {
118
+ const child = collections[kind]?.[key];
119
+ return [key, child && Array.isArray(item)
120
+ ? item.map(entry => normalize(entry, child)).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
121
+ : normalize(item)];
122
+ }));
123
+ };
124
+ return JSON.stringify(normalize(state, 'state'));
125
+ }
@@ -0,0 +1,50 @@
1
+ import type { BrowserProfileRunnerGrant } from './terminal-browser-profile-sync.protocol.ts';
2
+ export type BrowserProfileImportScope = {
3
+ actorUserId: string;
4
+ assistantThreadId: string;
5
+ agentTerminalId: string;
6
+ agentTerminalWorkspaceId: string;
7
+ connectionId: string;
8
+ keyId: string;
9
+ };
10
+ export type LegacyBrowserProfileMetadata = {
11
+ id: string;
12
+ name: string;
13
+ };
14
+ export type BrowserProfileImportResult = {
15
+ revision: number;
16
+ localCopy: 'retained' | 'removed' | 'cleanup_unconfirmed';
17
+ };
18
+ export type BrowserProfileImportRequest = {
19
+ type: 'browser_profile_import';
20
+ requestId: string;
21
+ connectionId: string;
22
+ instanceId: string;
23
+ operation: 'catalog' | 'import';
24
+ scope: BrowserProfileImportScope;
25
+ workspace: string;
26
+ grantRevision: number;
27
+ remainingMs: number;
28
+ localProfileId?: string;
29
+ removeLocalCopy?: boolean;
30
+ grant?: BrowserProfileRunnerGrant;
31
+ };
32
+ export type BrowserProfileImportReply = {
33
+ type: 'browser_profile_import_result';
34
+ requestId: string;
35
+ connectionId: string;
36
+ ok: boolean;
37
+ error?: string;
38
+ profiles?: LegacyBrowserProfileMetadata[];
39
+ result?: BrowserProfileImportResult;
40
+ };
41
+ export type BrowserProfileImportAck = {
42
+ type: 'browser_profile_import_ack';
43
+ requestId: string;
44
+ connectionId: string;
45
+ ok: boolean;
46
+ };
47
+ export declare const BROWSER_PROFILE_IMPORT_ERRORS: Set<string>;
48
+ export declare function browserProfileImportError(error: unknown): string;
49
+ export declare function validBrowserProfileImportRequest(value: unknown): value is BrowserProfileImportRequest;
50
+ export declare function validBrowserProfileImportReply(value: unknown): value is BrowserProfileImportReply;
@@ -0,0 +1,52 @@
1
+ export const BROWSER_PROFILE_IMPORT_ERRORS = new Set(['browser_profile_import_failed', 'browser_profile_import_unavailable',
2
+ 'browser_profile_import_busy', 'browser_profile_import_source_unavailable', 'browser_profile_import_target_changed',
3
+ 'browser_profile_import_restore_failed', 'browser_profile_access_denied', 'browser_profile_busy',
4
+ 'browser_profile_session_limit', 'browser_profile_corrupt', 'browser_profile_keystore_unavailable',
5
+ 'browser_profile_readback_failed', 'browser_profile_save_failed', 'browser_profile_lease_expired',
6
+ 'browser_profile_sync_unavailable', 'browser_profile_state_unavailable']);
7
+ export function browserProfileImportError(error) {
8
+ const code = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
9
+ return BROWSER_PROFILE_IMPORT_ERRORS.has(code) ? code : 'browser_profile_import_failed';
10
+ }
11
+ const UUID = /^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/iu;
12
+ const HEX = /^[a-f\d]{64}$/u;
13
+ const keys = (value, allowed) => Object.keys(value).every(key => allowed.includes(key));
14
+ export function validBrowserProfileImportRequest(value) {
15
+ const v = value;
16
+ if (!v || v.type !== 'browser_profile_import' || !UUID.test(v.requestId) || !UUID.test(v.connectionId)
17
+ || !['catalog', 'import'].includes(v.operation) || typeof v.instanceId !== 'string' || !v.instanceId || v.instanceId.length > 256
18
+ || !Number.isSafeInteger(v.grantRevision) || v.grantRevision < 0 || !Number.isSafeInteger(v.remainingMs) || v.remainingMs < 1 || v.remainingMs > 180_000
19
+ || typeof v.workspace !== 'string' || !v.workspace.startsWith('/') || v.workspace.length > 8192 || /[\u0000-\u001f]/u.test(v.workspace))
20
+ return false;
21
+ const s = v.scope;
22
+ if (!s || ![s.actorUserId, s.assistantThreadId, s.agentTerminalId, s.agentTerminalWorkspaceId, s.connectionId].every(id => UUID.test(id))
23
+ || !HEX.test(s.keyId) || s.connectionId !== v.connectionId
24
+ || !keys(s, ['actorUserId', 'assistantThreadId', 'agentTerminalId', 'agentTerminalWorkspaceId', 'connectionId', 'keyId']))
25
+ return false;
26
+ const common = ['type', 'requestId', 'connectionId', 'instanceId', 'operation', 'scope', 'workspace', 'grantRevision', 'remainingMs'];
27
+ if (v.operation === 'catalog')
28
+ return keys(v, common);
29
+ const grant = v.grant;
30
+ return keys(v, [...common, 'localProfileId', 'removeLocalCopy', 'grant']) && HEX.test(v.localProfileId)
31
+ && typeof v.removeLocalCopy === 'boolean' && !!grant && UUID.test(grant.profile?.id)
32
+ && grant.scope?.instanceId === v.instanceId && grant.scope.browserProfileId === grant.profile.id
33
+ && HEX.test(grant.scope.browserSessionId) && grant.revision === 0 && grant.download === null
34
+ && Object.entries(s).every(([key, entry]) => grant.scope[key] === entry);
35
+ }
36
+ export function validBrowserProfileImportReply(value) {
37
+ const v = value;
38
+ if (!v || v.type !== 'browser_profile_import_result' || !UUID.test(v.requestId) || !UUID.test(v.connectionId)
39
+ || typeof v.ok !== 'boolean')
40
+ return false;
41
+ const common = ['type', 'requestId', 'connectionId', 'ok'];
42
+ if (!v.ok)
43
+ return keys(v, [...common, 'error']) && BROWSER_PROFILE_IMPORT_ERRORS.has(v.error);
44
+ if (v.profiles)
45
+ return keys(v, [...common, 'profiles']) && Array.isArray(v.profiles) && v.profiles.length <= 128
46
+ && new Set(v.profiles.map(profile => profile?.id)).size === v.profiles.length
47
+ && v.profiles.every(profile => !!profile && keys(profile, ['id', 'name']) && HEX.test(profile.id)
48
+ && typeof profile.name === 'string' && /^[a-z0-9][a-z0-9 ._-]{0,63}$/iu.test(profile.name));
49
+ return keys(v, [...common, 'result']) && !!v.result && keys(v.result, ['revision', 'localCopy'])
50
+ && Number.isSafeInteger(v.result.revision) && v.result.revision > 0 && v.result.revision < 2147483647
51
+ && ['retained', 'removed', 'cleanup_unconfirmed'].includes(v.result.localCopy);
52
+ }
@@ -18,6 +18,7 @@ export declare class BrowserProfilePreferences {
18
18
  private read;
19
19
  private readAsync;
20
20
  remove(owner: BrowserProfileOwner, name: string): void;
21
+ removeAsync(owner: BrowserProfileOwner, name: string): Promise<void>;
21
22
  validName(name: string): string;
22
23
  private resolved;
23
24
  resolve(owner: BrowserProfileOwner, explicit?: string): ReturnType<BrowserProfilePreferences['resolved']>;
@@ -54,6 +54,22 @@ export class BrowserProfilePreferences {
54
54
  lease.release();
55
55
  }
56
56
  }
57
+ async removeAsync(owner, name) {
58
+ this.validName(name);
59
+ if (!this.store.has(this.scope(owner)))
60
+ return;
61
+ const lease = await this.store.openAsync(this.scope(owner));
62
+ try {
63
+ const previous = this.parse(lease);
64
+ const profileCatalog = { names: previous.names.filter(value => value !== name),
65
+ ...(previous.defaultName && previous.defaultName !== name ? { defaultName: previous.defaultName } : {}) };
66
+ const state = { cookies: [], origins: [], profileCatalog };
67
+ lease.save(state);
68
+ }
69
+ finally {
70
+ lease.release();
71
+ }
72
+ }
57
73
  validName(name) {
58
74
  if (name === INDEX_NAME)
59
75
  throw new Error('browser_profile_name_invalid');
@@ -0,0 +1,14 @@
1
+ import type { BrowserProfileRunnerGrant, BrowserProfileSyncRequest } from './terminal-browser-profile-sync.protocol.ts';
2
+ import type { CentralBrowserProfileTransport } from './terminal-browser-central-profile.ts';
3
+ /** Responses are consumed before the command queue, so a snapshot save cannot deadlock its own reply. */
4
+ export declare class BrowserProfileRunnerRpc {
5
+ private readonly connectionId;
6
+ private readonly send;
7
+ private readonly pending;
8
+ private closed;
9
+ constructor(connectionId: string, send: (request: BrowserProfileSyncRequest) => void);
10
+ accept(value: unknown): void;
11
+ private request;
12
+ transport(grant: BrowserProfileRunnerGrant): CentralBrowserProfileTransport;
13
+ dispose(): void;
14
+ }