@revoengine/cli 1.0.31 → 1.0.34

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 (113) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +152 -24
  3. package/dist/src/argument-contract.d.ts +17 -0
  4. package/dist/src/argument-contract.js +359 -0
  5. package/dist/src/automation-contract.generated.d.ts +56 -22
  6. package/dist/src/automation-contract.generated.js +68 -26
  7. package/dist/src/cli.js +15 -13
  8. package/dist/src/client.d.ts +34 -2
  9. package/dist/src/client.js +76 -13
  10. package/dist/src/commands/agents.js +5 -1
  11. package/dist/src/commands/auth.js +2 -0
  12. package/dist/src/commands/component.js +34 -17
  13. package/dist/src/commands/database-tables.js +15 -4
  14. package/dist/src/commands/database-views.js +5 -1
  15. package/dist/src/commands/endpoints.js +5 -1
  16. package/dist/src/commands/env.js +5 -1
  17. package/dist/src/commands/events.js +5 -1
  18. package/dist/src/commands/groups.js +5 -1
  19. package/dist/src/commands/info.js +2 -0
  20. package/dist/src/commands/job-templates.js +5 -1
  21. package/dist/src/commands/metadata.js +2 -0
  22. package/dist/src/commands/migrate.d.ts +2 -2
  23. package/dist/src/commands/migrate.js +33 -7
  24. package/dist/src/commands/project.js +19 -14
  25. package/dist/src/commands/request.js +2 -0
  26. package/dist/src/commands/role-groups.js +5 -1
  27. package/dist/src/commands/schedules.js +5 -1
  28. package/dist/src/commands/search.js +2 -0
  29. package/dist/src/commands/service-accounts.js +5 -1
  30. package/dist/src/commands/studio.js +2 -0
  31. package/dist/src/commands/terminal-browser-central-profile.d.ts +65 -0
  32. package/dist/src/commands/terminal-browser-central-profile.js +203 -0
  33. package/dist/src/commands/terminal-browser-human-input.d.ts +3 -1
  34. package/dist/src/commands/terminal-browser-human-input.js +3 -1
  35. package/dist/src/commands/terminal-browser-interaction.js +1 -1
  36. package/dist/src/commands/terminal-browser-live-protocol.d.ts +34 -2
  37. package/dist/src/commands/terminal-browser-live-protocol.js +28 -12
  38. package/dist/src/commands/terminal-browser-live-transport.d.ts +1 -0
  39. package/dist/src/commands/terminal-browser-live-transport.js +9 -5
  40. package/dist/src/commands/terminal-browser-live.d.ts +24 -3
  41. package/dist/src/commands/terminal-browser-live.js +199 -30
  42. package/dist/src/commands/terminal-browser-page-input.d.ts +4 -1
  43. package/dist/src/commands/terminal-browser-page-input.js +46 -1
  44. package/dist/src/commands/terminal-browser-profile-crypto.d.ts +30 -0
  45. package/dist/src/commands/terminal-browser-profile-crypto.js +101 -0
  46. package/dist/src/commands/terminal-browser-profile-import-runner.d.ts +31 -0
  47. package/dist/src/commands/terminal-browser-profile-import-runner.js +112 -0
  48. package/dist/src/commands/terminal-browser-profile-import.d.ts +28 -0
  49. package/dist/src/commands/terminal-browser-profile-import.js +125 -0
  50. package/dist/src/commands/terminal-browser-profile-import.protocol.d.ts +50 -0
  51. package/dist/src/commands/terminal-browser-profile-import.protocol.js +52 -0
  52. package/dist/src/commands/terminal-browser-profile-preferences.d.ts +1 -0
  53. package/dist/src/commands/terminal-browser-profile-preferences.js +16 -0
  54. package/dist/src/commands/terminal-browser-profile-sync.d.ts +14 -0
  55. package/dist/src/commands/terminal-browser-profile-sync.js +169 -0
  56. package/dist/src/commands/terminal-browser-profile-sync.protocol.d.ts +50 -0
  57. package/dist/src/commands/terminal-browser-profile-sync.protocol.js +19 -0
  58. package/dist/src/commands/terminal-browser-profile.d.ts +10 -1
  59. package/dist/src/commands/terminal-browser-profile.js +30 -4
  60. package/dist/src/commands/terminal-browser-recording.d.ts +39 -0
  61. package/dist/src/commands/terminal-browser-recording.js +74 -0
  62. package/dist/src/commands/terminal-browser-recording.protocol.d.ts +49 -0
  63. package/dist/src/commands/terminal-browser-recording.protocol.js +16 -0
  64. package/dist/src/commands/terminal-browser.d.ts +14 -1
  65. package/dist/src/commands/terminal-browser.js +98 -33
  66. package/dist/src/commands/terminal-file-descriptor.d.ts +9 -0
  67. package/dist/src/commands/terminal-file-descriptor.js +39 -0
  68. package/dist/src/commands/terminal-file.js +41 -6
  69. package/dist/src/commands/terminal-image.js +3 -31
  70. package/dist/src/commands/terminal-output-buffer.d.ts +18 -1
  71. package/dist/src/commands/terminal-output-buffer.js +95 -8
  72. package/dist/src/commands/terminal-process-group.d.ts +25 -0
  73. package/dist/src/commands/terminal-process-group.js +144 -0
  74. package/dist/src/commands/terminal.d.ts +3 -1
  75. package/dist/src/commands/terminal.js +366 -80
  76. package/dist/src/commands/tests.js +2 -0
  77. package/dist/src/component-lock.d.ts +15 -1
  78. package/dist/src/component-lock.js +96 -10
  79. package/dist/src/env-sync.js +12 -6
  80. package/dist/src/migration.d.ts +7 -0
  81. package/dist/src/migration.js +39 -21
  82. package/dist/src/planning-snapshot.d.ts +3 -0
  83. package/dist/src/planning-snapshot.js +60 -2
  84. package/dist/src/project.d.ts +1 -0
  85. package/dist/src/project.js +7 -8
  86. package/dist/src/resource-syncs/agent-sync.js +76 -24
  87. package/dist/src/resource-syncs/database-table-sync.d.ts +8 -1
  88. package/dist/src/resource-syncs/database-table-sync.js +66 -32
  89. package/dist/src/resource-syncs/database-view-sync.js +41 -28
  90. package/dist/src/resource-syncs/endpoint-sync.js +90 -18
  91. package/dist/src/resource-syncs/event-sync.js +33 -14
  92. package/dist/src/resource-syncs/group-sync.js +21 -11
  93. package/dist/src/resource-syncs/job-template-sync.js +98 -37
  94. package/dist/src/resource-syncs/role-group-sync.js +22 -11
  95. package/dist/src/resource-syncs/schedule-sync.js +26 -11
  96. package/dist/src/resource-syncs/service-account-sync.js +22 -11
  97. package/dist/src/reviewed-plan.js +3 -0
  98. package/dist/src/runtime-view.js +2 -18
  99. package/dist/src/sync-omit-command.d.ts +6 -0
  100. package/dist/src/sync-omit-command.js +49 -0
  101. package/dist/src/sync-omit-write-fence.d.ts +10 -0
  102. package/dist/src/sync-omit-write-fence.js +134 -0
  103. package/dist/src/sync-omit.d.ts +59 -0
  104. package/dist/src/sync-omit.js +469 -0
  105. package/dist/src/sync-output.d.ts +3 -3
  106. package/dist/src/ui.js +11 -5
  107. package/dist/src/update-notifier.d.ts +1 -1
  108. package/dist/src/update-notifier.js +2 -1
  109. package/dist/src/utils.js +46 -17
  110. package/dist/src/workspace-prune.js +11 -3
  111. package/dist/src/workspace-write-lock.d.ts +7 -0
  112. package/dist/src/workspace-write-lock.js +144 -0
  113. package/package.json +6 -5
@@ -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
- if (!validBrowserInteraction(interaction) || interaction.observationId !== input.observationId)
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 < 1920 && y >= 0 && y < 1080;
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 = 5;
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 = 5;
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' || !input.observationId || input.observationId.length > 128
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
- || !profile.name.trim() || profile.name.length > 64 || typeof profile.persistent !== 'boolean'
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' || !metadata.observationId || metadata.observationId.length > 128)
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 || item.name.length > 64
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
- pageUrl, frameSequence };
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 >= 200 && mediaReady && latestFrame && !closed && this.options.authorized(frame)
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, 200);
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;
@@ -16,6 +16,14 @@ export type BrowserLiveOptions = HumanInputScope & {
16
16
  identity: SecureBrowserIdentity;
17
17
  profilePreferences?: BrowserProfilePreferences;
18
18
  profileOwner?: BrowserProfileOwner;
19
+ sessionOwned?: boolean;
20
+ browserSettings?: {
21
+ fps: number;
22
+ width: number;
23
+ height: number;
24
+ alwaysRecord: boolean;
25
+ recordingMode: 'local' | 'storage' | 'both';
26
+ };
19
27
  initialControl?: {
20
28
  controlEpoch: number;
21
29
  mode: BrowserLiveMode;
@@ -24,7 +32,7 @@ export type BrowserLiveOptions = HumanInputScope & {
24
32
  recordingDirectory: string;
25
33
  isAuthorized: () => boolean;
26
34
  onFrame: (frame: Buffer) => void;
27
- onRecording: (recording: BrowserLiveRecording) => void;
35
+ onRecording: (recording: BrowserLiveRecording) => boolean | void;
28
36
  onFailure?: (code: string, controlEpoch: number) => void;
29
37
  onState?: (update: {
30
38
  controlEpoch: number;
@@ -70,11 +78,23 @@ export declare function jpegDimensions(jpeg: Buffer): {
70
78
  };
71
79
  export declare function browserAuthPage(value: string): boolean;
72
80
  export declare class BrowserLiveHandle {
73
- private readonly options;
81
+ private baseOptions;
82
+ private viewerOptions?;
83
+ private get options();
84
+ get sessionOwned(): boolean;
85
+ refreshRecordingAuthority(options: BrowserLiveOptions): void;
86
+ attachViewer(options: BrowserLiveOptions): void;
87
+ resumeRecordingIfPublic(): Promise<void>;
74
88
  private readonly port;
75
89
  private page?;
76
90
  private segment?;
77
91
  private recordingMode;
92
+ private fps;
93
+ private settingsApplied;
94
+ private elapsedMs;
95
+ private segmentStartedAt?;
96
+ private scroll?;
97
+ get frameInterval(): number;
78
98
  private sequence;
79
99
  private lastFrameAt;
80
100
  private generation;
@@ -98,7 +118,7 @@ export declare class BrowserLiveHandle {
98
118
  private capture;
99
119
  private stopCapture;
100
120
  private stopCaptureInner;
101
- pauseRecording(): Promise<void>;
121
+ pauseRecording(restartPreview?: boolean): Promise<void>;
102
122
  private syncing?;
103
123
  private sync;
104
124
  private publishCurrentState;
@@ -111,4 +131,5 @@ export declare class BrowserLiveHandle {
111
131
  block(epoch?: number): void;
112
132
  settled(): Promise<void>;
113
133
  disconnect(): void;
134
+ close(): void;
114
135
  }