@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
|
@@ -1109,7 +1109,7 @@ function buildPushElements(component, remote, identity) {
|
|
|
1109
1109
|
throw new Error(errors.join('; '));
|
|
1110
1110
|
const remoteElementsByKey = new Map((remote.elements || []).map((element) => [element.key, element]));
|
|
1111
1111
|
return (component.elements || []).map((element) => {
|
|
1112
|
-
const targetElementId = identity.mode === 'stableKey'
|
|
1112
|
+
const targetElementId = identity.mode === 'stableKey' || element.key === '@default'
|
|
1113
1113
|
? remoteElementsByKey.get(element.key)?.componentElementId
|
|
1114
1114
|
: element.componentElementId;
|
|
1115
1115
|
return {
|
|
@@ -1181,6 +1181,9 @@ async function pushSingleComponent(context, manifestPath, remoteCatalog) {
|
|
|
1181
1181
|
const configurationErrors = componentSourceConfigurationErrors(component);
|
|
1182
1182
|
if (configurationErrors.length)
|
|
1183
1183
|
throw new Error(`Cannot push ${targetPath}: ${configurationErrors.join('; ')}`);
|
|
1184
|
+
const updateError = remote ? componentUpdateValidationError(component, remote) : null;
|
|
1185
|
+
if (updateError)
|
|
1186
|
+
throw new Error(`Cannot push ${targetPath}: ${updateError}`);
|
|
1184
1187
|
const activationError = componentActivationValidationError(component);
|
|
1185
1188
|
if (activationError)
|
|
1186
1189
|
throw new Error(`Cannot push ${targetPath}: ${activationError}`);
|
|
@@ -3,13 +3,18 @@ import { readProjectStableKeyName } from "../project.js";
|
|
|
3
3
|
import { resolveResourceTarget } from "../resource-target.js";
|
|
4
4
|
import { buildDatabaseSchemasPlan, pullDatabaseSchemasToWorkspace, pushDatabaseSchemas } from "../resource-syncs/database-table-sync.js";
|
|
5
5
|
import { planValueChanges, printSyncPlan, printSyncStatus, printSyncSummary } from "../sync-output.js";
|
|
6
|
-
import { readBoolFlag } from "../utils.js";
|
|
6
|
+
import { readBoolFlag, readFlag } from "../utils.js";
|
|
7
7
|
export async function handleDatabaseTablesCommand(context) {
|
|
8
8
|
const subcommand = context.args._[1] || '';
|
|
9
9
|
if (subcommand !== 'pull' && subcommand !== 'plan' && subcommand !== 'push') {
|
|
10
10
|
throw new Error('Unknown database-tables command. Usage: revo database-tables <pull|plan|push> --all [--env <name>]');
|
|
11
11
|
}
|
|
12
12
|
const selectedStableKey = context.args._[2];
|
|
13
|
+
if (readFlag(context.args, ['idempotency-key']) && !selectedStableKey)
|
|
14
|
+
throw new Error('--idempotency-key requires one explicit Database Table Stable Key.');
|
|
15
|
+
const asyncExecution = readBoolFlag(context.args, ['async']);
|
|
16
|
+
if (asyncExecution && subcommand !== 'push')
|
|
17
|
+
throw new Error('--async is supported only for Database Table push.');
|
|
13
18
|
const all = readBoolFlag(context.args, ['all', 'a']);
|
|
14
19
|
const skipPartitions = readBoolFlag(context.args, ['skip-partitions']);
|
|
15
20
|
const pruneOrphans = readBoolFlag(context.args, ['prune-orphans']);
|
|
@@ -48,13 +53,15 @@ export async function handleDatabaseTablesCommand(context) {
|
|
|
48
53
|
prunePartitionsConfirmed: confirmed,
|
|
49
54
|
pruneOrphans,
|
|
50
55
|
pruneOrphansConfirmed: confirmed,
|
|
56
|
+
async: asyncExecution,
|
|
57
|
+
idempotencyKey: readFlag(context.args, ['idempotency-key']),
|
|
51
58
|
});
|
|
52
59
|
if (readBoolFlag(context.args, ['json'])) {
|
|
53
60
|
context.print(result);
|
|
54
61
|
}
|
|
55
62
|
else {
|
|
56
63
|
for (const item of result.results) {
|
|
57
|
-
const label = item.status === 'deployed'
|
|
64
|
+
const label = item.status === 'accepted' ? 'Accepted' : item.status === 'deployed'
|
|
58
65
|
? 'Deployed'
|
|
59
66
|
: item.status === 'failed'
|
|
60
67
|
? 'Failed'
|
|
@@ -68,7 +75,7 @@ export async function handleDatabaseTablesCommand(context) {
|
|
|
68
75
|
reason: item.error || item.reason,
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
|
-
printSyncSummary(context.println, 'Deployed', result.results, Date.now() - startedAt);
|
|
78
|
+
printSyncSummary(context.println, asyncExecution ? 'Accepted' : 'Deployed', result.results, Date.now() - startedAt);
|
|
72
79
|
}
|
|
73
80
|
const failed = result.results.filter((item) => item.status === 'failed');
|
|
74
81
|
const unverifiedWrites = result.results.filter((item) => item.status === 'write-unverified');
|
|
@@ -577,6 +577,8 @@ function printRunResult(context, result, showPlan = true) {
|
|
|
577
577
|
context.println(`Final verdict: ${result.verdict}.`);
|
|
578
578
|
}
|
|
579
579
|
export async function handleDeployCommand(context) {
|
|
580
|
+
if (readBoolFlag(context.args, ['async']))
|
|
581
|
+
throw new Error('Full deploy waits for schema readiness and verified readback before dependent phases; use database-tables push <stableKey> --async for admission only.');
|
|
580
582
|
if (readBoolFlag(context.args, ['changed']) || readFlag(context.args, ['base']) || readValues(context.args, ['resources', 'resource']).length > 0) {
|
|
581
583
|
throw new Error('Repository deployment evaluates all tracked resources; select resources in .revoengine/revo.json.');
|
|
582
584
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type KeyObject } from 'node:crypto';
|
|
2
|
+
import type { BrowserContext } from 'playwright-core';
|
|
3
|
+
import { type BrowserProfileKeyScope, type BrowserProfileSealedKey } from './terminal-browser-profile-crypto.ts';
|
|
4
|
+
type ProfileState = Awaited<ReturnType<BrowserContext['storageState']>>;
|
|
5
|
+
export type CentralBrowserProfileGrant = {
|
|
6
|
+
scope: BrowserProfileKeyScope;
|
|
7
|
+
sealedKey: BrowserProfileSealedKey;
|
|
8
|
+
revision: number;
|
|
9
|
+
leaseRemainingMs: number;
|
|
10
|
+
digest?: string;
|
|
11
|
+
};
|
|
12
|
+
export type CentralBrowserProfileTransport = {
|
|
13
|
+
read(): Promise<Buffer | null>;
|
|
14
|
+
readback?(expectedRevision: number): Promise<{
|
|
15
|
+
revision: number;
|
|
16
|
+
keyVersion: string;
|
|
17
|
+
ciphertext: Buffer;
|
|
18
|
+
digest: string;
|
|
19
|
+
}>;
|
|
20
|
+
save(input: {
|
|
21
|
+
operationId: string;
|
|
22
|
+
expectedRevision: number;
|
|
23
|
+
keyVersion: string;
|
|
24
|
+
ciphertext: Buffer;
|
|
25
|
+
digest: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
revision: number;
|
|
28
|
+
}>;
|
|
29
|
+
renew(): Promise<{
|
|
30
|
+
leaseRemainingMs: number;
|
|
31
|
+
}>;
|
|
32
|
+
release(): Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
/** Cross-platform in-memory profile lease. No local catalog, cookie file, passcode or OS keychain. */
|
|
35
|
+
export declare class CentralBrowserProfileLease {
|
|
36
|
+
private key;
|
|
37
|
+
private currentState?;
|
|
38
|
+
private revision;
|
|
39
|
+
private stateDigest?;
|
|
40
|
+
private closed;
|
|
41
|
+
private deadline;
|
|
42
|
+
private expiry?;
|
|
43
|
+
private renewal?;
|
|
44
|
+
private saves;
|
|
45
|
+
private queuedSaves;
|
|
46
|
+
private releaseRequest?;
|
|
47
|
+
private readonly grant;
|
|
48
|
+
private readonly transport;
|
|
49
|
+
private readonly onExpired;
|
|
50
|
+
private constructor();
|
|
51
|
+
static open(grant: CentralBrowserProfileGrant, privateKey: KeyObject, transport: CentralBrowserProfileTransport, onExpired: () => void | Promise<void>): Promise<CentralBrowserProfileLease>;
|
|
52
|
+
get state(): ProfileState | undefined;
|
|
53
|
+
get currentRevision(): number;
|
|
54
|
+
private assertActive;
|
|
55
|
+
private arm;
|
|
56
|
+
private scheduleRenewal;
|
|
57
|
+
private renew;
|
|
58
|
+
private expire;
|
|
59
|
+
save(state: ProfileState): Promise<void>;
|
|
60
|
+
/** An explicit migration proof, not an extra download on every ordinary checkpoint. */
|
|
61
|
+
verifySavedState(): Promise<ProfileState>;
|
|
62
|
+
private dispose;
|
|
63
|
+
release(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { BROWSER_PROFILE_STATE_MAX_BYTES, decryptBrowserProfileState, encryptBrowserProfileState, openBrowserProfileKey } from "./terminal-browser-profile-crypto.js";
|
|
3
|
+
/** Cross-platform in-memory profile lease. No local catalog, cookie file, passcode or OS keychain. */
|
|
4
|
+
export class CentralBrowserProfileLease {
|
|
5
|
+
key;
|
|
6
|
+
currentState;
|
|
7
|
+
revision;
|
|
8
|
+
stateDigest;
|
|
9
|
+
closed = false;
|
|
10
|
+
deadline = 0;
|
|
11
|
+
expiry;
|
|
12
|
+
renewal;
|
|
13
|
+
saves = Promise.resolve();
|
|
14
|
+
queuedSaves = 0;
|
|
15
|
+
releaseRequest;
|
|
16
|
+
grant;
|
|
17
|
+
transport;
|
|
18
|
+
onExpired;
|
|
19
|
+
constructor(grant, transport, onExpired, key) {
|
|
20
|
+
this.grant = grant;
|
|
21
|
+
this.transport = transport;
|
|
22
|
+
this.onExpired = onExpired;
|
|
23
|
+
this.key = key;
|
|
24
|
+
this.revision = grant.revision;
|
|
25
|
+
}
|
|
26
|
+
static async open(grant, privateKey, transport, onExpired) {
|
|
27
|
+
const lease = new CentralBrowserProfileLease(grant, transport, onExpired, openBrowserProfileKey(grant.sealedKey, privateKey, grant.scope));
|
|
28
|
+
try {
|
|
29
|
+
lease.arm(grant.leaseRemainingMs);
|
|
30
|
+
const encrypted = await transport.read();
|
|
31
|
+
lease.assertActive();
|
|
32
|
+
if (encrypted) {
|
|
33
|
+
if (!grant.digest || createHash('sha256').update(encrypted).digest('hex') !== grant.digest)
|
|
34
|
+
throw new Error('browser_profile_state_unavailable');
|
|
35
|
+
const plaintext = decryptBrowserProfileState(encrypted, lease.key, { ...grant.scope, revision: grant.revision });
|
|
36
|
+
try {
|
|
37
|
+
const state = JSON.parse(plaintext.toString('utf8'));
|
|
38
|
+
if (!state || !Array.isArray(state.cookies) || !Array.isArray(state.origins))
|
|
39
|
+
throw new Error();
|
|
40
|
+
lease.currentState = state;
|
|
41
|
+
lease.stateDigest = createHash('sha256').update(plaintext).digest('hex');
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
plaintext.fill(0);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (grant.digest)
|
|
48
|
+
throw new Error('browser_profile_state_unavailable');
|
|
49
|
+
lease.scheduleRenewal();
|
|
50
|
+
return lease;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
await lease.release().catch(() => undefined);
|
|
54
|
+
throw new Error('browser_profile_state_unavailable');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
get state() { this.assertActive(); return this.currentState ? structuredClone(this.currentState) : undefined; }
|
|
58
|
+
get currentRevision() { return this.revision; }
|
|
59
|
+
assertActive() {
|
|
60
|
+
if (this.closed || performance.now() >= this.deadline)
|
|
61
|
+
throw new Error('browser_profile_lease_expired');
|
|
62
|
+
}
|
|
63
|
+
arm(remainingMs) {
|
|
64
|
+
if (!Number.isFinite(remainingMs) || remainingMs < 1 || remainingMs > 45_000)
|
|
65
|
+
throw new Error('browser_profile_lease_expired');
|
|
66
|
+
this.deadline = performance.now() + remainingMs;
|
|
67
|
+
if (this.expiry)
|
|
68
|
+
clearTimeout(this.expiry);
|
|
69
|
+
this.expiry = setTimeout(() => { void this.expire(); }, remainingMs);
|
|
70
|
+
this.expiry.unref();
|
|
71
|
+
}
|
|
72
|
+
scheduleRenewal() {
|
|
73
|
+
if (this.closed)
|
|
74
|
+
return;
|
|
75
|
+
this.renewal = setTimeout(() => { void this.renew(); }, Math.max(1, Math.min(10_000, (this.deadline - performance.now()) / 3)));
|
|
76
|
+
this.renewal.unref();
|
|
77
|
+
}
|
|
78
|
+
async renew() {
|
|
79
|
+
try {
|
|
80
|
+
this.assertActive();
|
|
81
|
+
const next = await this.transport.renew();
|
|
82
|
+
// A late response may not resurrect an expired context.
|
|
83
|
+
this.assertActive();
|
|
84
|
+
this.arm(next.leaseRemainingMs);
|
|
85
|
+
this.scheduleRenewal();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
await this.expire();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async expire() {
|
|
92
|
+
if (this.closed)
|
|
93
|
+
return;
|
|
94
|
+
this.dispose();
|
|
95
|
+
try {
|
|
96
|
+
await this.onExpired();
|
|
97
|
+
}
|
|
98
|
+
catch { /* Closing a crashed browser does not renew its lease. */ }
|
|
99
|
+
}
|
|
100
|
+
save(state) {
|
|
101
|
+
this.assertActive();
|
|
102
|
+
if (this.queuedSaves >= 2)
|
|
103
|
+
return Promise.reject(new Error('browser_profile_save_busy'));
|
|
104
|
+
// Take the snapshot now; later caller mutations cannot change an already queued save.
|
|
105
|
+
const serialized = Buffer.from(JSON.stringify(state));
|
|
106
|
+
if (serialized.length > BROWSER_PROFILE_STATE_MAX_BYTES) {
|
|
107
|
+
serialized.fill(0);
|
|
108
|
+
return Promise.reject(new Error('browser_profile_state_too_large'));
|
|
109
|
+
}
|
|
110
|
+
this.queuedSaves++;
|
|
111
|
+
const run = this.saves.then(async () => {
|
|
112
|
+
try {
|
|
113
|
+
this.assertActive();
|
|
114
|
+
const stateDigest = createHash('sha256').update(serialized).digest('hex');
|
|
115
|
+
if (stateDigest === this.stateDigest)
|
|
116
|
+
return;
|
|
117
|
+
const expectedRevision = this.revision;
|
|
118
|
+
const ciphertext = encryptBrowserProfileState(serialized, this.key, { ...this.grant.scope, revision: expectedRevision + 1 });
|
|
119
|
+
const result = await this.transport.save({ operationId: randomUUID(), expectedRevision, keyVersion: this.grant.scope.keyVersion,
|
|
120
|
+
ciphertext, digest: createHash('sha256').update(ciphertext).digest('hex') });
|
|
121
|
+
this.assertActive();
|
|
122
|
+
if (result.revision !== expectedRevision + 1)
|
|
123
|
+
throw new Error();
|
|
124
|
+
this.revision = result.revision;
|
|
125
|
+
this.stateDigest = stateDigest;
|
|
126
|
+
this.currentState = JSON.parse(serialized.toString('utf8'));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// An uncertain mutation is never replayed automatically with a different revision.
|
|
130
|
+
await this.expire();
|
|
131
|
+
throw new Error('browser_profile_save_failed');
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
serialized.fill(0);
|
|
135
|
+
this.queuedSaves--;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.saves = run.catch(() => undefined);
|
|
139
|
+
return run;
|
|
140
|
+
}
|
|
141
|
+
/** An explicit migration proof, not an extra download on every ordinary checkpoint. */
|
|
142
|
+
verifySavedState() {
|
|
143
|
+
this.assertActive();
|
|
144
|
+
const run = this.saves.then(async () => {
|
|
145
|
+
let ciphertext;
|
|
146
|
+
let plaintext;
|
|
147
|
+
try {
|
|
148
|
+
this.assertActive();
|
|
149
|
+
if (!this.transport.readback || !this.stateDigest)
|
|
150
|
+
throw new Error();
|
|
151
|
+
const revision = this.revision;
|
|
152
|
+
const expectedDigest = this.stateDigest;
|
|
153
|
+
const source = await this.transport.readback(revision);
|
|
154
|
+
ciphertext = source.ciphertext;
|
|
155
|
+
this.assertActive();
|
|
156
|
+
if (source.revision !== revision || this.revision !== revision || source.keyVersion !== this.grant.scope.keyVersion
|
|
157
|
+
|| !Buffer.isBuffer(ciphertext) || ciphertext.length > BROWSER_PROFILE_STATE_MAX_BYTES + 28
|
|
158
|
+
|| createHash('sha256').update(ciphertext).digest('hex') !== source.digest)
|
|
159
|
+
throw new Error();
|
|
160
|
+
plaintext = decryptBrowserProfileState(ciphertext, this.key, { ...this.grant.scope, revision });
|
|
161
|
+
if (createHash('sha256').update(plaintext).digest('hex') !== expectedDigest)
|
|
162
|
+
throw new Error();
|
|
163
|
+
const state = JSON.parse(plaintext.toString('utf8'));
|
|
164
|
+
if (!state || !Array.isArray(state.cookies) || !Array.isArray(state.origins))
|
|
165
|
+
throw new Error();
|
|
166
|
+
return state;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
await this.expire();
|
|
170
|
+
throw new Error('browser_profile_readback_failed');
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
ciphertext?.fill(0);
|
|
174
|
+
plaintext?.fill(0);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
this.saves = run.then(() => undefined, () => undefined);
|
|
178
|
+
return run;
|
|
179
|
+
}
|
|
180
|
+
dispose() {
|
|
181
|
+
this.closed = true;
|
|
182
|
+
this.key.fill(0);
|
|
183
|
+
this.currentState = undefined;
|
|
184
|
+
this.stateDigest = undefined;
|
|
185
|
+
if (this.expiry)
|
|
186
|
+
clearTimeout(this.expiry);
|
|
187
|
+
if (this.renewal)
|
|
188
|
+
clearTimeout(this.renewal);
|
|
189
|
+
}
|
|
190
|
+
async release() {
|
|
191
|
+
// Do not save during shutdown/revocation. The last confirmed cloud revision remains usable.
|
|
192
|
+
this.dispose();
|
|
193
|
+
if (!this.releaseRequest) {
|
|
194
|
+
// A disconnected transport must not hold browser shutdown forever. Server expiry remains authoritative.
|
|
195
|
+
let deadline;
|
|
196
|
+
const remote = Promise.resolve().then(() => this.transport.release()).catch(() => undefined);
|
|
197
|
+
const bounded = new Promise(resolve => { deadline = setTimeout(resolve, 2000); deadline.unref(); });
|
|
198
|
+
this.releaseRequest = Promise.race([remote, bounded]).finally(() => { if (deadline)
|
|
199
|
+
clearTimeout(deadline); });
|
|
200
|
+
}
|
|
201
|
+
await this.releaseRequest;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -8,4 +8,6 @@ export type HumanInputScope = {
|
|
|
8
8
|
agentTerminalWorkspaceId?: string;
|
|
9
9
|
connectionId: string;
|
|
10
10
|
};
|
|
11
|
-
export declare function decryptBrowserHumanInput(frame: BrowserLiveControl, scope: HumanInputScope, identity: SecureBrowserIdentity): BrowserInteraction
|
|
11
|
+
export declare function decryptBrowserHumanInput(frame: BrowserLiveControl, scope: HumanInputScope, identity: SecureBrowserIdentity): BrowserInteraction & {
|
|
12
|
+
focusId?: string;
|
|
13
|
+
};
|
|
@@ -29,7 +29,9 @@ export function decryptBrowserHumanInput(frame, scope, identity) {
|
|
|
29
29
|
throw new Error();
|
|
30
30
|
plaintext = Buffer.concat([cipher.update(ciphertext), cipher.final()]);
|
|
31
31
|
const interaction = JSON.parse(plaintext.toString('utf8'));
|
|
32
|
-
|
|
32
|
+
const { focusId, ...ordinary } = interaction;
|
|
33
|
+
if (!validBrowserInteraction(ordinary) || ordinary.observationId !== input.observationId
|
|
34
|
+
|| focusId !== undefined && (ordinary.kind !== 'text' || typeof focusId !== 'string' || !/^[a-f0-9-]{36}$/iu.test(focusId)))
|
|
33
35
|
throw new Error();
|
|
34
36
|
return interaction;
|
|
35
37
|
}
|
|
@@ -33,7 +33,7 @@ export function validBrowserInteraction(value) {
|
|
|
33
33
|
if (item.button !== undefined && !['left', 'right', 'middle'].includes(item.button))
|
|
34
34
|
return false;
|
|
35
35
|
const point = (x, y) => Number.isInteger(x) && Number.isInteger(y)
|
|
36
|
-
&& x >= 0 && x <
|
|
36
|
+
&& x >= 0 && x < 3840 && y >= 0 && y < 2160;
|
|
37
37
|
if (['click', 'move', 'drag'].includes(item.kind) && !point(item.x, item.y))
|
|
38
38
|
return false;
|
|
39
39
|
if (item.kind === 'drag' && !point(item.toX, item.toY))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
export declare const BROWSER_LIVE_PROTOCOL = 1;
|
|
3
|
-
export declare const BROWSER_LIVE_MAX_FPS =
|
|
3
|
+
export declare const BROWSER_LIVE_MAX_FPS = 30;
|
|
4
4
|
export declare const BROWSER_LIVE_MAX_FRAME_BYTES: number;
|
|
5
5
|
export declare const BROWSER_LIVE_BUFFER_LIMIT: number;
|
|
6
6
|
export declare const BROWSER_LIVE_INPUT_INFO = "revo-browser-human-input-v1";
|
|
@@ -39,7 +39,13 @@ export type BrowserLiveControl = {
|
|
|
39
39
|
requestId: string;
|
|
40
40
|
liveSessionId: string;
|
|
41
41
|
controlEpoch: number;
|
|
42
|
-
action: 'start' | 'stop' | 'takeover' | 'release' | 'input' | 'refresh' | 'profile' | 'recording' | 'select_tab';
|
|
42
|
+
action: 'start' | 'stop' | 'takeover' | 'release' | 'input' | 'refresh' | 'profile' | 'recording' | 'select_tab' | 'settings' | 'navigate';
|
|
43
|
+
settings?: {
|
|
44
|
+
fps: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|
|
48
|
+
navigation?: 'back' | 'forward' | 'reload';
|
|
43
49
|
tabId?: string;
|
|
44
50
|
private?: boolean;
|
|
45
51
|
privateInput?: BrowserLivePrivateInput;
|
|
@@ -67,6 +73,11 @@ export type BrowserLiveFrameMetadata = {
|
|
|
67
73
|
imageHeight: number;
|
|
68
74
|
format: 'jpeg';
|
|
69
75
|
private: boolean;
|
|
76
|
+
scroll?: {
|
|
77
|
+
top: number;
|
|
78
|
+
height: number;
|
|
79
|
+
viewport: number;
|
|
80
|
+
};
|
|
70
81
|
};
|
|
71
82
|
export type BrowserLiveReady = BrowserLiveTarget & {
|
|
72
83
|
type: 'ready';
|
|
@@ -85,6 +96,16 @@ export type BrowserLiveReady = BrowserLiveTarget & {
|
|
|
85
96
|
deviceName: string;
|
|
86
97
|
workspaceName: string;
|
|
87
98
|
profile: BrowserLiveProfile;
|
|
99
|
+
profiles: BrowserLiveProfile[];
|
|
100
|
+
browserObservation?: {
|
|
101
|
+
id: string;
|
|
102
|
+
tabId: string;
|
|
103
|
+
width: number;
|
|
104
|
+
height: number;
|
|
105
|
+
};
|
|
106
|
+
recording?: {
|
|
107
|
+
mode: 'off' | 'local' | 'storage' | 'both';
|
|
108
|
+
};
|
|
88
109
|
tabs: Array<{
|
|
89
110
|
tabId: string;
|
|
90
111
|
title: string;
|
|
@@ -132,6 +153,17 @@ export declare function safeBrowserLiveState(value: any): {
|
|
|
132
153
|
recording: {
|
|
133
154
|
mode: any;
|
|
134
155
|
} | undefined;
|
|
156
|
+
settings: {
|
|
157
|
+
fps: any;
|
|
158
|
+
width: any;
|
|
159
|
+
height: any;
|
|
160
|
+
} | undefined;
|
|
161
|
+
recordingState: {
|
|
162
|
+
status: any;
|
|
163
|
+
elapsedMs: any;
|
|
164
|
+
} | undefined;
|
|
165
|
+
focusEditable: boolean;
|
|
166
|
+
focusId: string | undefined;
|
|
135
167
|
pageUrl: string | undefined;
|
|
136
168
|
frameSequence: any;
|
|
137
169
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// Mirrored from platform-shared terminal-browser-live.protocol.ts.
|
|
2
1
|
import { Buffer } from 'node:buffer';
|
|
3
2
|
export const BROWSER_LIVE_PROTOCOL = 1;
|
|
4
|
-
export const BROWSER_LIVE_MAX_FPS =
|
|
3
|
+
export const BROWSER_LIVE_MAX_FPS = 30;
|
|
5
4
|
export const BROWSER_LIVE_MAX_FRAME_BYTES = 2 * 1024 * 1024;
|
|
6
5
|
export const BROWSER_LIVE_BUFFER_LIMIT = BROWSER_LIVE_MAX_FRAME_BYTES;
|
|
7
6
|
export const BROWSER_LIVE_INPUT_INFO = 'revo-browser-human-input-v1';
|
|
@@ -23,8 +22,8 @@ export function validBrowserLiveOpen(value) {
|
|
|
23
22
|
export function validBrowserLiveControl(value) {
|
|
24
23
|
if (value?.type !== 'browser_live_control' || value.protocol !== 1 || !validLiveId(value.requestId)
|
|
25
24
|
|| !validLiveId(value.liveSessionId) || !integer(value.controlEpoch, 0, Number.MAX_SAFE_INTEGER)
|
|
26
|
-
|| !['start', 'stop', 'takeover', 'release', 'input', 'refresh', 'profile', 'recording', 'select_tab'].includes(value.action)
|
|
27
|
-
|| Object.keys(value).some(key => !['type', 'protocol', 'requestId', 'liveSessionId', 'controlEpoch', 'action', 'tabId', 'private', 'privateInput', 'profile', 'recording'].includes(key)))
|
|
25
|
+
|| !['start', 'stop', 'takeover', 'release', 'input', 'refresh', 'profile', 'recording', 'select_tab', 'settings', 'navigate'].includes(value.action)
|
|
26
|
+
|| Object.keys(value).some(key => !['type', 'protocol', 'requestId', 'liveSessionId', 'controlEpoch', 'action', 'tabId', 'private', 'privateInput', 'profile', 'recording', 'settings', 'navigation'].includes(key)))
|
|
28
27
|
return false;
|
|
29
28
|
if (value.action === 'select_tab' ? !validLiveId(value.tabId) : value.tabId !== undefined)
|
|
30
29
|
return false;
|
|
@@ -35,7 +34,7 @@ export function validBrowserLiveControl(value) {
|
|
|
35
34
|
if (!input || !/^[a-f0-9]{64}$/u.test(input.keyId) || !base64(input.ephemeralPublicKey, 40, 128)
|
|
36
35
|
|| !base64(input.iv, 12, 12) || !base64(input.tag, 16, 16) || !base64(input.ciphertext, 1, 16384)
|
|
37
36
|
|| !integer(input.expiresAt, Date.now() + 1, Date.now() + 60000)
|
|
38
|
-
|| typeof input.observationId !== 'string' ||
|
|
37
|
+
|| typeof input.observationId !== 'string' || !/^[a-z0-9_-]{1,128}$/iu.test(input.observationId)
|
|
39
38
|
|| Object.keys(input).some(key => !['keyId', 'ephemeralPublicKey', 'iv', 'ciphertext', 'tag', 'expiresAt', 'observationId'].includes(key)))
|
|
40
39
|
return false;
|
|
41
40
|
}
|
|
@@ -44,7 +43,7 @@ export function validBrowserLiveControl(value) {
|
|
|
44
43
|
if (value.action === 'profile') {
|
|
45
44
|
const profile = value.profile;
|
|
46
45
|
if (!profile || (profile.create === true ? profile.id !== undefined : !validBrowserSessionId(profile.id)) || typeof profile.name !== 'string'
|
|
47
|
-
||
|
|
46
|
+
|| !/^[a-z0-9][a-z0-9 ._-]{0,63}$/iu.test(profile.name) || profile.name !== profile.name.trim() || typeof profile.persistent !== 'boolean'
|
|
48
47
|
|| typeof profile.default !== 'boolean' || profile.reset !== undefined && typeof profile.reset !== 'boolean'
|
|
49
48
|
|| profile.create !== undefined && (typeof profile.create !== 'boolean' || profile.create && (!profile.persistent || profile.reset === true))
|
|
50
49
|
|| Object.keys(profile).some(key => !['id', 'name', 'persistent', 'default', 'reset', 'create'].includes(key)))
|
|
@@ -59,6 +58,16 @@ export function validBrowserLiveControl(value) {
|
|
|
59
58
|
}
|
|
60
59
|
else if (value.recording !== undefined)
|
|
61
60
|
return false;
|
|
61
|
+
if (value.action === 'settings') {
|
|
62
|
+
const settings = value.settings;
|
|
63
|
+
if (!settings || !integer(settings.fps, 5, 60) || !integer(settings.width, 320, 3840)
|
|
64
|
+
|| !integer(settings.height, 480, 2160) || Object.keys(settings).some(key => !['fps', 'width', 'height'].includes(key)))
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
else if (value.settings !== undefined)
|
|
68
|
+
return false;
|
|
69
|
+
if (value.action === 'navigate' ? !['back', 'forward', 'reload'].includes(value.navigation) : value.navigation !== undefined)
|
|
70
|
+
return false;
|
|
62
71
|
return true;
|
|
63
72
|
}
|
|
64
73
|
export function browserLiveInputAad(input) {
|
|
@@ -78,8 +87,9 @@ export function parseBrowserLiveFrame(value) {
|
|
|
78
87
|
|| !integer(metadata.sequence, 1, Number.MAX_SAFE_INTEGER) || !integer(metadata.timestamp, 0, Date.now() + 30000)
|
|
79
88
|
|| ![metadata.width, metadata.imageWidth].every(value => integer(value, 1, 3840))
|
|
80
89
|
|| ![metadata.height, metadata.imageHeight].every(value => integer(value, 1, 2160))
|
|
90
|
+
|| metadata.scroll !== undefined && (!metadata.scroll || !integer(metadata.scroll.top, 0, 100000000) || !integer(metadata.scroll.height, 1, 100000000) || !integer(metadata.scroll.viewport, 1, 2160))
|
|
81
91
|
|| metadata.format !== 'jpeg' || typeof metadata.private !== 'boolean'
|
|
82
|
-
|| typeof metadata.observationId !== 'string' ||
|
|
92
|
+
|| typeof metadata.observationId !== 'string' || !/^[a-z0-9_-]{1,128}$/iu.test(metadata.observationId))
|
|
83
93
|
throw new Error('invalid_browser_live_metadata');
|
|
84
94
|
const jpeg = value.subarray(4 + length);
|
|
85
95
|
if (jpeg.length < 4 || jpeg[0] !== 0xff || jpeg[1] !== 0xd8 || jpeg[jpeg.length - 2] !== 0xff || jpeg[jpeg.length - 1] !== 0xd9)
|
|
@@ -120,14 +130,15 @@ export function safeBrowserLiveState(value) {
|
|
|
120
130
|
|| !integer(observation.width, 1, 3840) || !integer(observation.height, 1, 2160)))
|
|
121
131
|
throw new Error('invalid_browser_live_observation');
|
|
122
132
|
const profile = value?.profile || value?.browserProfile;
|
|
123
|
-
if (profile !== undefined && (!validBrowserSessionId(profile.id) || typeof profile.name !== 'string'
|
|
124
|
-
|| !profile.name || profile.name.length > 64 || typeof profile.persistent !== 'boolean'
|
|
133
|
+
if (profile !== undefined && (!(validBrowserSessionId(profile.id) || validLiveId(profile.id)) || typeof profile.name !== 'string'
|
|
134
|
+
|| !profile.name || profile.name.length > (validLiveId(profile.id) ? 160 : 64) || typeof profile.persistent !== 'boolean'
|
|
125
135
|
|| typeof profile.default !== 'boolean'))
|
|
126
136
|
throw new Error('invalid_browser_live_profile');
|
|
127
137
|
if (value?.profiles !== undefined && (!Array.isArray(value.profiles) || value.profiles.length > 32))
|
|
128
138
|
throw new Error('invalid_browser_live_profile');
|
|
129
139
|
const profiles = value?.profiles?.map((item) => {
|
|
130
|
-
if (!validBrowserSessionId(item.id) || typeof item.name !== 'string' || !item.name
|
|
140
|
+
if (!(validBrowserSessionId(item.id) || validLiveId(item.id)) || typeof item.name !== 'string' || !item.name
|
|
141
|
+
|| item.name.length > (validLiveId(item.id) ? 160 : 64)
|
|
131
142
|
|| typeof item.persistent !== 'boolean' || typeof item.default !== 'boolean')
|
|
132
143
|
throw new Error('invalid_browser_live_profile');
|
|
133
144
|
return { id: item.id, name: item.name, persistent: item.persistent, default: item.default };
|
|
@@ -146,7 +157,7 @@ export function safeBrowserLiveState(value) {
|
|
|
146
157
|
throw new Error('invalid_browser_live_tabs');
|
|
147
158
|
origin = url.origin === 'null' ? '' : url.origin;
|
|
148
159
|
}
|
|
149
|
-
return { tabId: id, title: tab.title, origin, isActive: tab.isActive === true || tab.active === true };
|
|
160
|
+
return { tabId: id, title: tab.title, origin, popup: tab.popup === true, isActive: tab.isActive === true || tab.active === true };
|
|
150
161
|
});
|
|
151
162
|
let pageUrl;
|
|
152
163
|
if (value?.pageUrl) {
|
|
@@ -159,7 +170,12 @@ export function safeBrowserLiveState(value) {
|
|
|
159
170
|
profile: profile ? { id: profile.id, name: profile.name, persistent: profile.persistent, default: profile.default } : undefined,
|
|
160
171
|
profiles, tabs: safeTabs, private: typeof value?.private === 'boolean' ? value.private : undefined,
|
|
161
172
|
recording: ['off', 'local', 'storage', 'both'].includes(value?.recording?.mode) ? { mode: value.recording.mode } : undefined,
|
|
162
|
-
|
|
173
|
+
settings: value?.settings && integer(value.settings.fps, 5, 60) && integer(value.settings.width, 320, 3840) && integer(value.settings.height, 480, 2160)
|
|
174
|
+
? { fps: value.settings.fps, width: value.settings.width, height: value.settings.height } : undefined,
|
|
175
|
+
recordingState: value?.recordingState && ['off', 'recording', 'paused'].includes(value.recordingState.status)
|
|
176
|
+
&& integer(value.recordingState.elapsedMs, 0, Number.MAX_SAFE_INTEGER)
|
|
177
|
+
? { status: value.recordingState.status, elapsedMs: value.recordingState.elapsedMs } : undefined,
|
|
178
|
+
focusEditable: value?.focusEditable === true, focusId: validLiveId(value?.focusId) ? value.focusId : undefined, pageUrl, frameSequence };
|
|
163
179
|
}
|
|
164
180
|
export function safeBrowserScreenshotTransform(value) {
|
|
165
181
|
const finiteCss = (number, min, max) => typeof number === 'number' && Number.isFinite(number) && number >= min && number <= max;
|
|
@@ -18,6 +18,7 @@ export type BrowserLiveAttachment = {
|
|
|
18
18
|
mode: 'observe' | 'human' | 'blocked';
|
|
19
19
|
private: boolean;
|
|
20
20
|
networkAccess: 'local' | 'full';
|
|
21
|
+
browserSettings?: BrowserLiveOptions['browserSettings'];
|
|
21
22
|
};
|
|
22
23
|
export declare function browserLiveRelayUrl(runnerUrl: string): string;
|
|
23
24
|
export declare function validBrowserLiveAttachment(frame: unknown): frame is BrowserLiveAttachment;
|
|
@@ -21,7 +21,11 @@ export function validBrowserLiveAttachment(frame) {
|
|
|
21
21
|
&& /^[a-f0-9]{64}$/u.test(item.browserSessionId) && /^[A-Za-z0-9_-]{43}$/u.test(item.attachmentToken)
|
|
22
22
|
&& Number.isSafeInteger(item.revision) && item.revision >= 0 && Number.isSafeInteger(item.controlEpoch) && item.controlEpoch >= 0
|
|
23
23
|
&& ['observe', 'human', 'blocked'].includes(item.mode) && typeof item.private === 'boolean'
|
|
24
|
-
&& ['local', 'full'].includes(item.networkAccess)
|
|
24
|
+
&& ['local', 'full'].includes(item.networkAccess)
|
|
25
|
+
&& (item.browserSettings === undefined || !!item.browserSettings && Number.isInteger(item.browserSettings.fps) && item.browserSettings.fps >= 5 && item.browserSettings.fps <= 60
|
|
26
|
+
&& Number.isInteger(item.browserSettings.width) && item.browserSettings.width >= 320 && item.browserSettings.width <= 3840
|
|
27
|
+
&& Number.isInteger(item.browserSettings.height) && item.browserSettings.height >= 480 && item.browserSettings.height <= 2160
|
|
28
|
+
&& typeof item.browserSettings.alwaysRecord === 'boolean' && ['local', 'storage', 'both'].includes(item.browserSettings.recordingMode));
|
|
25
29
|
}
|
|
26
30
|
/** Media has its own socket and buffer. No attachment token, input or signed URL is logged. */
|
|
27
31
|
export class TerminalBrowserLiveTransport {
|
|
@@ -46,7 +50,7 @@ export class TerminalBrowserLiveTransport {
|
|
|
46
50
|
let controlInFlight = false;
|
|
47
51
|
let mediaReady = false, latestFrame, lastSentAt = 0;
|
|
48
52
|
const flushFrame = () => {
|
|
49
|
-
if (Date.now() - lastSentAt >=
|
|
53
|
+
if (Date.now() - lastSentAt >= (handle?.frameInterval ?? 1000 / 15) && mediaReady && latestFrame && !closed && this.options.authorized(frame)
|
|
50
54
|
&& socket.readyState === WebSocket.OPEN && socket.bufferedAmount < 2 * 1024 * 1024) {
|
|
51
55
|
const length = latestFrame.readUInt32BE(0);
|
|
52
56
|
const metadata = JSON.parse(latestFrame.subarray(4, 4 + length).toString());
|
|
@@ -61,7 +65,7 @@ export class TerminalBrowserLiveTransport {
|
|
|
61
65
|
const uploads = new Map();
|
|
62
66
|
const send = (message) => { if (!closed && socket.readyState === WebSocket.OPEN)
|
|
63
67
|
socket.send(JSON.stringify(message)); };
|
|
64
|
-
const framePump = setInterval(flushFrame,
|
|
68
|
+
const framePump = setInterval(flushFrame, 1000 / 30);
|
|
65
69
|
framePump.unref();
|
|
66
70
|
const close = () => {
|
|
67
71
|
if (closed)
|
|
@@ -126,7 +130,7 @@ export class TerminalBrowserLiveTransport {
|
|
|
126
130
|
if (message.action !== 'start' || message.controlEpoch !== frame.controlEpoch)
|
|
127
131
|
throw new Error('browser_live_scope_invalid');
|
|
128
132
|
const settings = this.options.options(frame);
|
|
129
|
-
handle = await (this.options.attach || attachBrowserLive)({ ...settings,
|
|
133
|
+
handle = await (this.options.attach || attachBrowserLive)({ ...settings, browserSettings: frame.browserSettings,
|
|
130
134
|
isAuthorized: () => !closed && this.options.authorized(frame) && settings.isAuthorized(),
|
|
131
135
|
onFailure: (code, controlEpoch) => {
|
|
132
136
|
console.warn(JSON.stringify({ event: 'browser_live_capture_failure', timestamp: new Date().toISOString(),
|
|
@@ -152,7 +156,7 @@ export class TerminalBrowserLiveTransport {
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
const control = Object.fromEntries(Object.entries(message).filter(([key]) => ['type', 'protocol', 'requestId',
|
|
155
|
-
'liveSessionId', 'controlEpoch', 'action', 'private', 'privateInput', 'profile', 'recording', 'tabId'].includes(key)));
|
|
159
|
+
'liveSessionId', 'controlEpoch', 'action', 'private', 'privateInput', 'profile', 'recording', 'tabId', 'settings', 'navigation'].includes(key)));
|
|
156
160
|
send(await handle.control(control));
|
|
157
161
|
controlInFlight = false;
|
|
158
162
|
return;
|