@revoengine/cli 1.0.29 → 1.0.30
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 +154 -3
- package/dist/src/automation-contract.generated.d.ts +742 -0
- package/dist/src/automation-contract.generated.js +1021 -0
- package/dist/src/cli.js +9 -1
- package/dist/src/client.d.ts +24 -0
- package/dist/src/client.js +60 -0
- package/dist/src/commands/component.js +52 -22
- package/dist/src/commands/env.js +1 -1
- package/dist/src/commands/index.d.ts +2 -0
- package/dist/src/commands/index.js +2 -0
- package/dist/src/commands/studio.d.ts +3 -0
- package/dist/src/commands/studio.js +114 -0
- package/dist/src/commands/terminal-browser-human-input.d.ts +11 -0
- package/dist/src/commands/terminal-browser-human-input.js +44 -0
- package/dist/src/commands/terminal-browser-interaction.d.ts +25 -0
- package/dist/src/commands/terminal-browser-interaction.js +56 -0
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +151 -0
- package/dist/src/commands/terminal-browser-live-protocol.js +177 -0
- package/dist/src/commands/terminal-browser-live-transport.d.ts +41 -0
- package/dist/src/commands/terminal-browser-live-transport.js +206 -0
- package/dist/src/commands/terminal-browser-live.d.ts +114 -0
- package/dist/src/commands/terminal-browser-live.js +455 -0
- package/dist/src/commands/terminal-browser-observation.d.ts +10 -0
- package/dist/src/commands/terminal-browser-observation.js +27 -0
- package/dist/src/commands/terminal-browser-page-input.d.ts +8 -0
- package/dist/src/commands/terminal-browser-page-input.js +94 -0
- package/dist/src/commands/terminal-browser-profile-preferences.d.ts +37 -0
- package/dist/src/commands/terminal-browser-profile-preferences.js +136 -0
- package/dist/src/commands/terminal-browser-profile.d.ts +52 -0
- package/dist/src/commands/terminal-browser-profile.js +447 -0
- package/dist/src/commands/terminal-browser.d.ts +28 -1
- package/dist/src/commands/terminal-browser.js +401 -55
- package/dist/src/commands/terminal-policy.js +2 -0
- package/dist/src/commands/terminal-public-web-proxy.d.ts +14 -0
- package/dist/src/commands/terminal-public-web-proxy.js +141 -0
- package/dist/src/commands/terminal-public-web.d.ts +11 -0
- package/dist/src/commands/terminal-public-web.js +99 -0
- package/dist/src/commands/terminal.d.ts +1 -0
- package/dist/src/commands/terminal.js +92 -9
- package/dist/src/commands/tests.d.ts +3 -0
- package/dist/src/commands/tests.js +236 -0
- package/dist/src/component-element-validation.d.ts +8 -0
- package/dist/src/component-element-validation.js +79 -0
- package/dist/src/component-lifecycle.d.ts +3 -0
- package/dist/src/component-lifecycle.js +17 -0
- package/dist/src/component-lock.d.ts +17 -12
- package/dist/src/component-lock.js +51 -6
- package/dist/src/component-manifests.js +3 -0
- package/dist/src/component-source-validation.d.ts +5 -0
- package/dist/src/component-source-validation.js +27 -0
- package/dist/src/env-sync.js +64 -9
- package/dist/src/native-tests.d.ts +61 -0
- package/dist/src/native-tests.js +20 -0
- package/dist/src/request-contract.d.ts +39 -0
- package/dist/src/request-contract.js +138 -0
- package/dist/src/resource-syncs/agent-sync.js +47 -7
- package/dist/src/resource-syncs/database-table-sync.js +8 -8
- package/dist/src/resource-syncs/endpoint-sync.js +20 -14
- package/dist/src/resource-syncs/group-sync.js +8 -3
- package/dist/src/resource-syncs/job-template-sync.js +75 -28
- package/dist/src/resource-syncs/role-group-sync.js +8 -0
- package/dist/src/resource-syncs/runtime-definition-validation.d.ts +14 -0
- package/dist/src/resource-syncs/runtime-definition-validation.js +153 -0
- package/dist/src/test-workspace.d.ts +33 -0
- package/dist/src/test-workspace.js +156 -0
- package/dist/src/types.d.ts +1 -0
- package/dist/src/ui.js +12 -0
- package/dist/src/update-notifier.d.ts +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
export declare const BROWSER_LIVE_PROTOCOL = 1;
|
|
3
|
+
export declare const BROWSER_LIVE_MAX_FPS = 5;
|
|
4
|
+
export declare const BROWSER_LIVE_MAX_FRAME_BYTES: number;
|
|
5
|
+
export declare const BROWSER_LIVE_BUFFER_LIMIT: number;
|
|
6
|
+
export declare const BROWSER_LIVE_INPUT_INFO = "revo-browser-human-input-v1";
|
|
7
|
+
export declare const BROWSER_LIVE_VIEWER_PATH = "/browser/v1/ws";
|
|
8
|
+
export declare const BROWSER_LIVE_RUNNER_PATH = "/browser/v1/runner/ws";
|
|
9
|
+
export type BrowserLiveMode = 'observe' | 'human' | 'blocked';
|
|
10
|
+
export type BrowserLiveProfile = {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
persistent: boolean;
|
|
14
|
+
default: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type BrowserLiveTarget = {
|
|
17
|
+
threadId: string;
|
|
18
|
+
agentTerminalId: string;
|
|
19
|
+
agentTerminalWorkspaceId: string;
|
|
20
|
+
browserSessionId: string;
|
|
21
|
+
tabId?: string;
|
|
22
|
+
};
|
|
23
|
+
export type BrowserLiveOpen = BrowserLiveTarget & {
|
|
24
|
+
type: 'open';
|
|
25
|
+
protocol: 1;
|
|
26
|
+
};
|
|
27
|
+
export type BrowserLivePrivateInput = {
|
|
28
|
+
keyId: string;
|
|
29
|
+
ephemeralPublicKey: string;
|
|
30
|
+
iv: string;
|
|
31
|
+
ciphertext: string;
|
|
32
|
+
tag: string;
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
observationId: string;
|
|
35
|
+
};
|
|
36
|
+
export type BrowserLiveControl = {
|
|
37
|
+
type: 'browser_live_control';
|
|
38
|
+
protocol: 1;
|
|
39
|
+
requestId: string;
|
|
40
|
+
liveSessionId: string;
|
|
41
|
+
controlEpoch: number;
|
|
42
|
+
action: 'start' | 'stop' | 'takeover' | 'release' | 'input' | 'refresh' | 'profile' | 'recording' | 'select_tab';
|
|
43
|
+
tabId?: string;
|
|
44
|
+
private?: boolean;
|
|
45
|
+
privateInput?: BrowserLivePrivateInput;
|
|
46
|
+
profile?: Omit<BrowserLiveProfile, 'id'> & {
|
|
47
|
+
id?: string;
|
|
48
|
+
reset?: boolean;
|
|
49
|
+
create?: boolean;
|
|
50
|
+
};
|
|
51
|
+
recording?: {
|
|
52
|
+
mode: 'off' | 'local' | 'storage' | 'both';
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export type BrowserLiveFrameMetadata = {
|
|
56
|
+
protocol: 1;
|
|
57
|
+
liveSessionId: string;
|
|
58
|
+
browserSessionId: string;
|
|
59
|
+
tabId: string;
|
|
60
|
+
epoch: number;
|
|
61
|
+
sequence: number;
|
|
62
|
+
timestamp: number;
|
|
63
|
+
observationId: string;
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
imageWidth: number;
|
|
67
|
+
imageHeight: number;
|
|
68
|
+
format: 'jpeg';
|
|
69
|
+
private: boolean;
|
|
70
|
+
};
|
|
71
|
+
export type BrowserLiveReady = BrowserLiveTarget & {
|
|
72
|
+
type: 'ready';
|
|
73
|
+
protocol: 1;
|
|
74
|
+
liveSessionId: string;
|
|
75
|
+
controlEpoch: number;
|
|
76
|
+
mode: BrowserLiveMode;
|
|
77
|
+
private: boolean;
|
|
78
|
+
expiresAt: number;
|
|
79
|
+
authenticationExpiresAt?: number;
|
|
80
|
+
sessionExpiresAt?: number;
|
|
81
|
+
actorUserId: string;
|
|
82
|
+
connectionId: string;
|
|
83
|
+
secureBrowserPublicKey: string;
|
|
84
|
+
secureBrowserKeyId: string;
|
|
85
|
+
deviceName: string;
|
|
86
|
+
workspaceName: string;
|
|
87
|
+
profile: BrowserLiveProfile;
|
|
88
|
+
tabs: Array<{
|
|
89
|
+
tabId: string;
|
|
90
|
+
title: string;
|
|
91
|
+
origin: string;
|
|
92
|
+
isActive: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
};
|
|
95
|
+
export declare const validLiveId: (value: unknown) => value is string;
|
|
96
|
+
export declare const validBrowserSessionId: (value: unknown) => value is string;
|
|
97
|
+
export declare function validBrowserLiveOpen(value: any): value is BrowserLiveOpen;
|
|
98
|
+
export declare function validBrowserLiveControl(value: any): value is BrowserLiveControl;
|
|
99
|
+
export declare function browserLiveInputAad(input: {
|
|
100
|
+
liveSessionId: string;
|
|
101
|
+
browserSessionId: string;
|
|
102
|
+
actorUserId: string;
|
|
103
|
+
threadId: string;
|
|
104
|
+
agentTerminalWorkspaceId?: string;
|
|
105
|
+
connectionId: string;
|
|
106
|
+
controlEpoch: number;
|
|
107
|
+
requestId: string;
|
|
108
|
+
observationId: string;
|
|
109
|
+
keyId: string;
|
|
110
|
+
expiresAt: number;
|
|
111
|
+
}): Buffer;
|
|
112
|
+
export declare function parseBrowserLiveFrame(value: Buffer): {
|
|
113
|
+
metadata: BrowserLiveFrameMetadata;
|
|
114
|
+
jpeg: Buffer;
|
|
115
|
+
};
|
|
116
|
+
export declare function safeBrowserLiveState(value: any): {
|
|
117
|
+
browserObservation: {
|
|
118
|
+
id: any;
|
|
119
|
+
tabId: any;
|
|
120
|
+
width: any;
|
|
121
|
+
height: any;
|
|
122
|
+
} | undefined;
|
|
123
|
+
profile: {
|
|
124
|
+
id: any;
|
|
125
|
+
name: any;
|
|
126
|
+
persistent: any;
|
|
127
|
+
default: any;
|
|
128
|
+
} | undefined;
|
|
129
|
+
profiles: any;
|
|
130
|
+
tabs: any;
|
|
131
|
+
private: any;
|
|
132
|
+
recording: {
|
|
133
|
+
mode: any;
|
|
134
|
+
} | undefined;
|
|
135
|
+
pageUrl: string | undefined;
|
|
136
|
+
frameSequence: any;
|
|
137
|
+
};
|
|
138
|
+
export declare function safeBrowserScreenshotTransform(value: any): {
|
|
139
|
+
observationId: any;
|
|
140
|
+
imageWidth: any;
|
|
141
|
+
imageHeight: any;
|
|
142
|
+
cssCrop: {
|
|
143
|
+
x: any;
|
|
144
|
+
y: any;
|
|
145
|
+
width: any;
|
|
146
|
+
height: any;
|
|
147
|
+
};
|
|
148
|
+
scaleX: any;
|
|
149
|
+
scaleY: any;
|
|
150
|
+
coordinateSpace: string;
|
|
151
|
+
} | undefined;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Mirrored from platform-shared terminal-browser-live.protocol.ts.
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
export const BROWSER_LIVE_PROTOCOL = 1;
|
|
4
|
+
export const BROWSER_LIVE_MAX_FPS = 5;
|
|
5
|
+
export const BROWSER_LIVE_MAX_FRAME_BYTES = 2 * 1024 * 1024;
|
|
6
|
+
export const BROWSER_LIVE_BUFFER_LIMIT = BROWSER_LIVE_MAX_FRAME_BYTES;
|
|
7
|
+
export const BROWSER_LIVE_INPUT_INFO = 'revo-browser-human-input-v1';
|
|
8
|
+
export const BROWSER_LIVE_VIEWER_PATH = '/browser/v1/ws';
|
|
9
|
+
export const BROWSER_LIVE_RUNNER_PATH = '/browser/v1/runner/ws';
|
|
10
|
+
const UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/iu;
|
|
11
|
+
export const validLiveId = (value) => typeof value === 'string' && UUID.test(value);
|
|
12
|
+
export const validBrowserSessionId = (value) => typeof value === 'string' && /^[a-f0-9]{64}$/u.test(value);
|
|
13
|
+
const integer = (value, min, max) => Number.isSafeInteger(value) && Number(value) >= min && Number(value) <= max;
|
|
14
|
+
const base64 = (value, min, max) => typeof value === 'string'
|
|
15
|
+
&& value.length <= Math.ceil(max / 3) * 4 && /^[a-z0-9+/]+={0,2}$/iu.test(value)
|
|
16
|
+
&& Buffer.from(value, 'base64').length >= min && Buffer.from(value, 'base64').length <= max;
|
|
17
|
+
export function validBrowserLiveOpen(value) {
|
|
18
|
+
return value?.type === 'open' && value.protocol === 1 && validLiveId(value.threadId)
|
|
19
|
+
&& validLiveId(value.agentTerminalId) && validLiveId(value.agentTerminalWorkspaceId)
|
|
20
|
+
&& validBrowserSessionId(value.browserSessionId) && (value.tabId === undefined || validLiveId(value.tabId))
|
|
21
|
+
&& Object.keys(value).every(key => ['type', 'protocol', 'threadId', 'agentTerminalId', 'agentTerminalWorkspaceId', 'browserSessionId', 'tabId'].includes(key));
|
|
22
|
+
}
|
|
23
|
+
export function validBrowserLiveControl(value) {
|
|
24
|
+
if (value?.type !== 'browser_live_control' || value.protocol !== 1 || !validLiveId(value.requestId)
|
|
25
|
+
|| !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)))
|
|
28
|
+
return false;
|
|
29
|
+
if (value.action === 'select_tab' ? !validLiveId(value.tabId) : value.tabId !== undefined)
|
|
30
|
+
return false;
|
|
31
|
+
if (value.private !== undefined && (value.action !== 'takeover' || typeof value.private !== 'boolean'))
|
|
32
|
+
return false;
|
|
33
|
+
if (value.action === 'input') {
|
|
34
|
+
const input = value.privateInput;
|
|
35
|
+
if (!input || !/^[a-f0-9]{64}$/u.test(input.keyId) || !base64(input.ephemeralPublicKey, 40, 128)
|
|
36
|
+
|| !base64(input.iv, 12, 12) || !base64(input.tag, 16, 16) || !base64(input.ciphertext, 1, 16384)
|
|
37
|
+
|| !integer(input.expiresAt, Date.now() + 1, Date.now() + 60000)
|
|
38
|
+
|| typeof input.observationId !== 'string' || !input.observationId || input.observationId.length > 128
|
|
39
|
+
|| Object.keys(input).some(key => !['keyId', 'ephemeralPublicKey', 'iv', 'ciphertext', 'tag', 'expiresAt', 'observationId'].includes(key)))
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
else if (value.privateInput !== undefined)
|
|
43
|
+
return false;
|
|
44
|
+
if (value.action === 'profile') {
|
|
45
|
+
const profile = value.profile;
|
|
46
|
+
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'
|
|
48
|
+
|| typeof profile.default !== 'boolean' || profile.reset !== undefined && typeof profile.reset !== 'boolean'
|
|
49
|
+
|| profile.create !== undefined && (typeof profile.create !== 'boolean' || profile.create && (!profile.persistent || profile.reset === true))
|
|
50
|
+
|| Object.keys(profile).some(key => !['id', 'name', 'persistent', 'default', 'reset', 'create'].includes(key)))
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
else if (value.profile !== undefined)
|
|
54
|
+
return false;
|
|
55
|
+
if (value.action === 'recording') {
|
|
56
|
+
if (!value.recording || !['off', 'local', 'storage', 'both'].includes(value.recording.mode)
|
|
57
|
+
|| Object.keys(value.recording).some(key => key !== 'mode'))
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
else if (value.recording !== undefined)
|
|
61
|
+
return false;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
export function browserLiveInputAad(input) {
|
|
65
|
+
return Buffer.from(JSON.stringify([input.liveSessionId, input.browserSessionId, input.actorUserId,
|
|
66
|
+
input.threadId, input.agentTerminalWorkspaceId ?? null, input.connectionId, input.controlEpoch,
|
|
67
|
+
input.requestId, input.observationId, input.keyId, input.expiresAt]), 'utf8');
|
|
68
|
+
}
|
|
69
|
+
export function parseBrowserLiveFrame(value) {
|
|
70
|
+
if (value.length < 8 || value.length > BROWSER_LIVE_MAX_FRAME_BYTES)
|
|
71
|
+
throw new Error('invalid_browser_live_frame');
|
|
72
|
+
const length = value.readUInt32BE(0);
|
|
73
|
+
if (length < 1 || length > 4096 || value.length <= 4 + length)
|
|
74
|
+
throw new Error('invalid_browser_live_metadata');
|
|
75
|
+
const metadata = JSON.parse(value.subarray(4, 4 + length).toString('utf8'));
|
|
76
|
+
if (metadata.protocol !== 1 || !validLiveId(metadata.liveSessionId) || !validBrowserSessionId(metadata.browserSessionId)
|
|
77
|
+
|| !validLiveId(metadata.tabId) || !integer(metadata.epoch, 0, Number.MAX_SAFE_INTEGER)
|
|
78
|
+
|| !integer(metadata.sequence, 1, Number.MAX_SAFE_INTEGER) || !integer(metadata.timestamp, 0, Date.now() + 30000)
|
|
79
|
+
|| ![metadata.width, metadata.imageWidth].every(value => integer(value, 1, 3840))
|
|
80
|
+
|| ![metadata.height, metadata.imageHeight].every(value => integer(value, 1, 2160))
|
|
81
|
+
|| metadata.format !== 'jpeg' || typeof metadata.private !== 'boolean'
|
|
82
|
+
|| typeof metadata.observationId !== 'string' || !metadata.observationId || metadata.observationId.length > 128)
|
|
83
|
+
throw new Error('invalid_browser_live_metadata');
|
|
84
|
+
const jpeg = value.subarray(4 + length);
|
|
85
|
+
if (jpeg.length < 4 || jpeg[0] !== 0xff || jpeg[1] !== 0xd8 || jpeg[jpeg.length - 2] !== 0xff || jpeg[jpeg.length - 1] !== 0xd9)
|
|
86
|
+
throw new Error('invalid_browser_live_jpeg');
|
|
87
|
+
let offset = 2, dimensions;
|
|
88
|
+
while (offset + 3 < jpeg.length) {
|
|
89
|
+
if (jpeg[offset++] !== 0xff)
|
|
90
|
+
throw new Error('invalid_browser_live_jpeg');
|
|
91
|
+
while (jpeg[offset] === 0xff)
|
|
92
|
+
offset++;
|
|
93
|
+
const marker = jpeg[offset++];
|
|
94
|
+
if (marker === 0xda || marker === 0xd9)
|
|
95
|
+
break;
|
|
96
|
+
if (marker === 0xd8 || marker >= 0xd0 && marker <= 0xd7)
|
|
97
|
+
continue;
|
|
98
|
+
const segment = jpeg.readUInt16BE(offset);
|
|
99
|
+
if (segment < 2 || offset + segment > jpeg.length)
|
|
100
|
+
throw new Error('invalid_browser_live_jpeg');
|
|
101
|
+
if ([0xc0, 0xc1, 0xc2].includes(marker)) {
|
|
102
|
+
if (segment < 8)
|
|
103
|
+
throw new Error('invalid_browser_live_jpeg');
|
|
104
|
+
dimensions = { height: jpeg.readUInt16BE(offset + 3), width: jpeg.readUInt16BE(offset + 5) };
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
offset += segment;
|
|
108
|
+
}
|
|
109
|
+
if (!dimensions || dimensions.width !== metadata.imageWidth || dimensions.height !== metadata.imageHeight)
|
|
110
|
+
throw new Error('invalid_browser_live_jpeg_dimensions');
|
|
111
|
+
return { metadata, jpeg };
|
|
112
|
+
}
|
|
113
|
+
export function safeBrowserLiveState(value) {
|
|
114
|
+
const frameSequence = value?.frameSequence;
|
|
115
|
+
if (frameSequence !== undefined && !integer(frameSequence, 0, Number.MAX_SAFE_INTEGER))
|
|
116
|
+
throw new Error('invalid_browser_live_frame_sequence');
|
|
117
|
+
const observation = value?.browserObservation;
|
|
118
|
+
if (observation !== undefined && (!observation || typeof observation.id !== 'string'
|
|
119
|
+
|| !/^[a-z0-9_-]{1,128}$/iu.test(observation.id) || !validLiveId(observation.tabId)
|
|
120
|
+
|| !integer(observation.width, 1, 3840) || !integer(observation.height, 1, 2160)))
|
|
121
|
+
throw new Error('invalid_browser_live_observation');
|
|
122
|
+
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'
|
|
125
|
+
|| typeof profile.default !== 'boolean'))
|
|
126
|
+
throw new Error('invalid_browser_live_profile');
|
|
127
|
+
if (value?.profiles !== undefined && (!Array.isArray(value.profiles) || value.profiles.length > 32))
|
|
128
|
+
throw new Error('invalid_browser_live_profile');
|
|
129
|
+
const profiles = value?.profiles?.map((item) => {
|
|
130
|
+
if (!validBrowserSessionId(item.id) || typeof item.name !== 'string' || !item.name || item.name.length > 64
|
|
131
|
+
|| typeof item.persistent !== 'boolean' || typeof item.default !== 'boolean')
|
|
132
|
+
throw new Error('invalid_browser_live_profile');
|
|
133
|
+
return { id: item.id, name: item.name, persistent: item.persistent, default: item.default };
|
|
134
|
+
});
|
|
135
|
+
const tabs = value?.tabs;
|
|
136
|
+
if (tabs !== undefined && (!Array.isArray(tabs) || tabs.length > 16))
|
|
137
|
+
throw new Error('invalid_browser_live_tabs');
|
|
138
|
+
const safeTabs = tabs?.map((tab) => {
|
|
139
|
+
const id = tab.tabId || tab.id;
|
|
140
|
+
if (!validLiveId(id) || typeof tab.title !== 'string' || tab.title.length > 512)
|
|
141
|
+
throw new Error('invalid_browser_live_tabs');
|
|
142
|
+
let origin = '';
|
|
143
|
+
if (tab.origin || tab.url) {
|
|
144
|
+
const url = new URL(tab.origin || tab.url);
|
|
145
|
+
if (!['http:', 'https:', 'about:'].includes(url.protocol))
|
|
146
|
+
throw new Error('invalid_browser_live_tabs');
|
|
147
|
+
origin = url.origin === 'null' ? '' : url.origin;
|
|
148
|
+
}
|
|
149
|
+
return { tabId: id, title: tab.title, origin, isActive: tab.isActive === true || tab.active === true };
|
|
150
|
+
});
|
|
151
|
+
let pageUrl;
|
|
152
|
+
if (value?.pageUrl) {
|
|
153
|
+
const url = new URL(value.pageUrl);
|
|
154
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
|
|
155
|
+
throw new Error('invalid_browser_live_page');
|
|
156
|
+
pageUrl = url.origin + url.pathname;
|
|
157
|
+
}
|
|
158
|
+
return { browserObservation: observation ? { id: observation.id, tabId: observation.tabId, width: observation.width, height: observation.height } : undefined,
|
|
159
|
+
profile: profile ? { id: profile.id, name: profile.name, persistent: profile.persistent, default: profile.default } : undefined,
|
|
160
|
+
profiles, tabs: safeTabs, private: typeof value?.private === 'boolean' ? value.private : undefined,
|
|
161
|
+
recording: ['off', 'local', 'storage', 'both'].includes(value?.recording?.mode) ? { mode: value.recording.mode } : undefined,
|
|
162
|
+
pageUrl, frameSequence };
|
|
163
|
+
}
|
|
164
|
+
export function safeBrowserScreenshotTransform(value) {
|
|
165
|
+
const finiteCss = (number, min, max) => typeof number === 'number' && Number.isFinite(number) && number >= min && number <= max;
|
|
166
|
+
if (value === undefined)
|
|
167
|
+
return undefined;
|
|
168
|
+
const crop = value?.cssCrop;
|
|
169
|
+
if (!value || typeof value.observationId !== 'string' || !/^[a-z0-9_-]{1,128}$/iu.test(value.observationId)
|
|
170
|
+
|| value.coordinateSpace !== 'css_viewport' || !integer(value.imageWidth, 1, 8000) || !integer(value.imageHeight, 1, 8000)
|
|
171
|
+
|| !crop || !finiteCss(crop.x, -12000, 12000) || !finiteCss(crop.y, -12000, 12000)
|
|
172
|
+
|| !finiteCss(crop.width, 1, 8000) || !finiteCss(crop.height, 1, 8000)
|
|
173
|
+
|| ![value.scaleX, value.scaleY].every(item => Number.isFinite(item) && item > 0 && item <= 8))
|
|
174
|
+
throw new Error('invalid_browser_screenshot_transform');
|
|
175
|
+
return { observationId: value.observationId, imageWidth: value.imageWidth, imageHeight: value.imageHeight,
|
|
176
|
+
cssCrop: { x: crop.x, y: crop.y, width: crop.width, height: crop.height }, scaleX: value.scaleX, scaleY: value.scaleY, coordinateSpace: 'css_viewport' };
|
|
177
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { attachBrowserLive } from './terminal-browser.ts';
|
|
3
|
+
import { type BrowserLiveOptions } from './terminal-browser-live.ts';
|
|
4
|
+
import { transferWorkspaceFile } from './terminal-file.ts';
|
|
5
|
+
export type BrowserLiveAttachment = {
|
|
6
|
+
type: 'browser_live_attach';
|
|
7
|
+
protocol: 1;
|
|
8
|
+
liveSessionId: string;
|
|
9
|
+
attachmentToken: string;
|
|
10
|
+
actorUserId: string;
|
|
11
|
+
threadId: string;
|
|
12
|
+
agentTerminalId: string;
|
|
13
|
+
agentTerminalWorkspaceId: string;
|
|
14
|
+
browserSessionId: string;
|
|
15
|
+
connectionId: string;
|
|
16
|
+
revision: number;
|
|
17
|
+
controlEpoch: number;
|
|
18
|
+
mode: 'observe' | 'human' | 'blocked';
|
|
19
|
+
private: boolean;
|
|
20
|
+
networkAccess: 'local' | 'full';
|
|
21
|
+
};
|
|
22
|
+
export declare function browserLiveRelayUrl(runnerUrl: string): string;
|
|
23
|
+
export declare function validBrowserLiveAttachment(frame: unknown): frame is BrowserLiveAttachment;
|
|
24
|
+
type Options = {
|
|
25
|
+
runnerUrl: string;
|
|
26
|
+
headers: Record<string, string>;
|
|
27
|
+
options: (frame: BrowserLiveAttachment) => Omit<BrowserLiveOptions, 'onFrame' | 'onRecording' | 'onState'>;
|
|
28
|
+
authorized: (frame: BrowserLiveAttachment) => boolean;
|
|
29
|
+
socket?: (url: string, options: WebSocket.ClientOptions) => WebSocket;
|
|
30
|
+
attach?: typeof attachBrowserLive;
|
|
31
|
+
transfer?: typeof transferWorkspaceFile;
|
|
32
|
+
};
|
|
33
|
+
/** Media has its own socket and buffer. No attachment token, input or signed URL is logged. */
|
|
34
|
+
export declare class TerminalBrowserLiveTransport {
|
|
35
|
+
private readonly connections;
|
|
36
|
+
private readonly options;
|
|
37
|
+
constructor(options: Options);
|
|
38
|
+
connect(value: unknown): void;
|
|
39
|
+
disconnectAll(): void;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
import { attachBrowserLive } from "./terminal-browser.js";
|
|
5
|
+
import { transferWorkspaceFile, validateFileTransfer } from "./terminal-file.js";
|
|
6
|
+
const UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/iu;
|
|
7
|
+
export function browserLiveRelayUrl(runnerUrl) {
|
|
8
|
+
const url = new URL(runnerUrl);
|
|
9
|
+
if (url.username || url.password || url.protocol !== 'wss:' && !(url.protocol === 'ws:' && url.hostname === 'localhost'))
|
|
10
|
+
throw new Error('browser_live_relay_invalid');
|
|
11
|
+
url.pathname = '/browser/v1/runner/ws';
|
|
12
|
+
url.search = '';
|
|
13
|
+
url.hash = '';
|
|
14
|
+
return url.toString();
|
|
15
|
+
}
|
|
16
|
+
export function validBrowserLiveAttachment(frame) {
|
|
17
|
+
const item = frame;
|
|
18
|
+
return !!item && item.type === 'browser_live_attach' && item.protocol === 1
|
|
19
|
+
&& ['liveSessionId', 'actorUserId', 'threadId', 'agentTerminalId', 'agentTerminalWorkspaceId', 'connectionId']
|
|
20
|
+
.every(key => typeof item[key] === 'string' && UUID.test(item[key]))
|
|
21
|
+
&& /^[a-f0-9]{64}$/u.test(item.browserSessionId) && /^[A-Za-z0-9_-]{43}$/u.test(item.attachmentToken)
|
|
22
|
+
&& Number.isSafeInteger(item.revision) && item.revision >= 0 && Number.isSafeInteger(item.controlEpoch) && item.controlEpoch >= 0
|
|
23
|
+
&& ['observe', 'human', 'blocked'].includes(item.mode) && typeof item.private === 'boolean'
|
|
24
|
+
&& ['local', 'full'].includes(item.networkAccess);
|
|
25
|
+
}
|
|
26
|
+
/** Media has its own socket and buffer. No attachment token, input or signed URL is logged. */
|
|
27
|
+
export class TerminalBrowserLiveTransport {
|
|
28
|
+
connections = new Map();
|
|
29
|
+
options;
|
|
30
|
+
constructor(options) { this.options = options; }
|
|
31
|
+
connect(value) {
|
|
32
|
+
if (!validBrowserLiveAttachment(value) || !this.options.authorized(value) || this.connections.has(value.liveSessionId)
|
|
33
|
+
|| this.connections.size >= 8)
|
|
34
|
+
return;
|
|
35
|
+
const frame = value;
|
|
36
|
+
for (const existing of [...this.connections.values()])
|
|
37
|
+
if (existing.browserSessionId === frame.browserSessionId)
|
|
38
|
+
existing.close();
|
|
39
|
+
const url = browserLiveRelayUrl(this.options.runnerUrl); // Never forward auth to a URL supplied by a frame.
|
|
40
|
+
const socket = (this.options.socket || ((url, options) => new WebSocket(url, options)))(url, {
|
|
41
|
+
headers: this.options.headers, handshakeTimeout: 10000, perMessageDeflate: false, maxPayload: 32768,
|
|
42
|
+
});
|
|
43
|
+
const cancel = new AbortController();
|
|
44
|
+
let closed = false, handle;
|
|
45
|
+
let queued = 0, chain = Promise.resolve();
|
|
46
|
+
let controlInFlight = false;
|
|
47
|
+
let mediaReady = false, latestFrame, lastSentAt = 0;
|
|
48
|
+
const flushFrame = () => {
|
|
49
|
+
if (Date.now() - lastSentAt >= 200 && mediaReady && latestFrame && !closed && this.options.authorized(frame)
|
|
50
|
+
&& socket.readyState === WebSocket.OPEN && socket.bufferedAmount < 2 * 1024 * 1024) {
|
|
51
|
+
const length = latestFrame.readUInt32BE(0);
|
|
52
|
+
const metadata = JSON.parse(latestFrame.subarray(4, 4 + length).toString());
|
|
53
|
+
if (metadata.epoch === handle?.controlEpoch) {
|
|
54
|
+
socket.send(latestFrame, { binary: true });
|
|
55
|
+
lastSentAt = Date.now();
|
|
56
|
+
}
|
|
57
|
+
latestFrame = undefined;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const recordings = new Map();
|
|
61
|
+
const uploads = new Map();
|
|
62
|
+
const send = (message) => { if (!closed && socket.readyState === WebSocket.OPEN)
|
|
63
|
+
socket.send(JSON.stringify(message)); };
|
|
64
|
+
const framePump = setInterval(flushFrame, 200);
|
|
65
|
+
framePump.unref();
|
|
66
|
+
const close = () => {
|
|
67
|
+
if (closed)
|
|
68
|
+
return;
|
|
69
|
+
closed = true;
|
|
70
|
+
clearInterval(framePump);
|
|
71
|
+
latestFrame = undefined;
|
|
72
|
+
cancel.abort();
|
|
73
|
+
handle?.disconnect();
|
|
74
|
+
this.connections.delete(frame.liveSessionId);
|
|
75
|
+
if (socket.readyState === WebSocket.CONNECTING)
|
|
76
|
+
socket.terminate();
|
|
77
|
+
else
|
|
78
|
+
socket.close();
|
|
79
|
+
};
|
|
80
|
+
this.connections.set(frame.liveSessionId, { browserSessionId: frame.browserSessionId, close });
|
|
81
|
+
socket.on('open', () => {
|
|
82
|
+
if (!this.options.authorized(frame)) {
|
|
83
|
+
close();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
send({ type: 'attach', protocol: 1, liveSessionId: frame.liveSessionId, attachmentToken: frame.attachmentToken,
|
|
87
|
+
agentTerminalId: frame.agentTerminalId, connectionId: frame.connectionId, browserSessionId: frame.browserSessionId });
|
|
88
|
+
});
|
|
89
|
+
socket.on('message', (raw, binary) => {
|
|
90
|
+
const bytes = Array.isArray(raw) ? Buffer.concat(raw) : Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
|
91
|
+
if (closed || binary || bytes.length > 32768 || ++queued > 32) {
|
|
92
|
+
close();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
chain = chain.then(async () => {
|
|
96
|
+
if (!this.options.authorized(frame)) {
|
|
97
|
+
close();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const message = JSON.parse(bytes.toString());
|
|
101
|
+
if (message.liveSessionId !== frame.liveSessionId)
|
|
102
|
+
throw new Error('browser_live_scope_invalid');
|
|
103
|
+
if (message.type === 'attached')
|
|
104
|
+
return;
|
|
105
|
+
if (message.type === 'control.accepted') {
|
|
106
|
+
if (message.controlEpoch !== handle?.controlEpoch)
|
|
107
|
+
return;
|
|
108
|
+
mediaReady = true;
|
|
109
|
+
flushFrame();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (message.type === 'browser_live_block') {
|
|
113
|
+
if (Number.isSafeInteger(message.controlEpoch))
|
|
114
|
+
handle?.block(message.controlEpoch);
|
|
115
|
+
close();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (message.type === 'browser_live_control') {
|
|
119
|
+
mediaReady = false;
|
|
120
|
+
controlInFlight = true;
|
|
121
|
+
if (message.connectionId !== frame.connectionId || message.browserSessionId !== frame.browserSessionId
|
|
122
|
+
|| message.actorUserId !== frame.actorUserId || message.threadId !== frame.threadId
|
|
123
|
+
|| message.agentTerminalWorkspaceId !== frame.agentTerminalWorkspaceId)
|
|
124
|
+
throw new Error('browser_live_scope_invalid');
|
|
125
|
+
if (!handle) {
|
|
126
|
+
if (message.action !== 'start' || message.controlEpoch !== frame.controlEpoch)
|
|
127
|
+
throw new Error('browser_live_scope_invalid');
|
|
128
|
+
const settings = this.options.options(frame);
|
|
129
|
+
handle = await (this.options.attach || attachBrowserLive)({ ...settings,
|
|
130
|
+
isAuthorized: () => !closed && this.options.authorized(frame) && settings.isAuthorized(),
|
|
131
|
+
onFailure: (code, controlEpoch) => {
|
|
132
|
+
console.warn(JSON.stringify({ event: 'browser_live_capture_failure', timestamp: new Date().toISOString(),
|
|
133
|
+
stage: 'poll_sync', code, controlEpoch, liveSessionId: frame.liveSessionId, browserSessionId: frame.browserSessionId }));
|
|
134
|
+
},
|
|
135
|
+
onFrame: bytes => { latestFrame = bytes; flushFrame(); },
|
|
136
|
+
onState: update => {
|
|
137
|
+
if (!mediaReady || controlInFlight || closed || !this.options.authorized(frame))
|
|
138
|
+
return false;
|
|
139
|
+
send({ type: 'browser.state', protocol: 1, liveSessionId: frame.liveSessionId,
|
|
140
|
+
browserSessionId: frame.browserSessionId, ...update });
|
|
141
|
+
return true;
|
|
142
|
+
},
|
|
143
|
+
onRecording: recording => {
|
|
144
|
+
recordings.set(recording.recordingId, recording);
|
|
145
|
+
send({ type: 'browser_recording_ready', liveSessionId: frame.liveSessionId,
|
|
146
|
+
recordingId: recording.recordingId, mode: recording.mode, mime: 'video/webm',
|
|
147
|
+
size: recording.size, name: recording.name });
|
|
148
|
+
} });
|
|
149
|
+
if (closed) {
|
|
150
|
+
handle.disconnect();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const control = Object.fromEntries(Object.entries(message).filter(([key]) => ['type', 'protocol', 'requestId',
|
|
155
|
+
'liveSessionId', 'controlEpoch', 'action', 'private', 'privateInput', 'profile', 'recording', 'tabId'].includes(key)));
|
|
156
|
+
send(await handle.control(control));
|
|
157
|
+
controlInFlight = false;
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (message.type === 'browser_recording_upload') {
|
|
161
|
+
const recording = recordings.get(message.recordingId);
|
|
162
|
+
const settings = this.options.options(frame);
|
|
163
|
+
if (!recording || frame.networkAccess !== 'full' || !this.options.authorized(frame)
|
|
164
|
+
|| !UUID.test(message.recordingId) || typeof message.storageUploadSessionId !== 'string'
|
|
165
|
+
|| typeof message.namespace !== 'string' || !Number.isSafeInteger(message.expiresAt) || message.expiresAt <= Date.now()
|
|
166
|
+
|| message.expiresAt > Date.now() + 15 * 60000)
|
|
167
|
+
throw new Error('browser_recording_upload_invalid');
|
|
168
|
+
const acknowledgment = () => send({ type: 'browser_recording_uploaded', liveSessionId: frame.liveSessionId,
|
|
169
|
+
recordingId: recording.recordingId, storageUploadSessionId: message.storageUploadSessionId });
|
|
170
|
+
if (uploads.get(recording.recordingId) === 'uploaded') {
|
|
171
|
+
acknowledgment();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (uploads.has(recording.recordingId))
|
|
175
|
+
return; // An uncertain PUT is never replayed.
|
|
176
|
+
const transfer = { path: recording.path, url: message.uploadUrl, headers: message.headers,
|
|
177
|
+
overwrite: false, offset: null, length: null };
|
|
178
|
+
if (!validateFileTransfer(transfer) || path.dirname(recording.path) !== settings.recordingDirectory)
|
|
179
|
+
throw new Error('browser_recording_upload_invalid');
|
|
180
|
+
const file = await fs.promises.lstat(recording.path);
|
|
181
|
+
if (!file.isFile() || file.isSymbolicLink() || file.size !== recording.size)
|
|
182
|
+
throw new Error('browser_recording_source_changed');
|
|
183
|
+
uploads.set(recording.recordingId, 'uploading');
|
|
184
|
+
// Keep clicks and control ACKs independent of a slow upload.
|
|
185
|
+
void (this.options.transfer || transferWorkspaceFile)(settings.recordingDirectory, 'upload_file', transfer, AbortSignal.any([cancel.signal, AbortSignal.timeout(Math.max(1, message.expiresAt - Date.now()))]))
|
|
186
|
+
.then(result => {
|
|
187
|
+
if (!result.complete || !this.options.authorized(frame) || closed)
|
|
188
|
+
throw new Error('browser_recording_upload_unknown');
|
|
189
|
+
uploads.set(recording.recordingId, 'uploaded');
|
|
190
|
+
acknowledgment();
|
|
191
|
+
}).catch(() => {
|
|
192
|
+
uploads.set(recording.recordingId, 'unknown');
|
|
193
|
+
send({ type: 'browser_recording_upload_failed', liveSessionId: frame.liveSessionId,
|
|
194
|
+
recordingId: recording.recordingId, error: 'browser_recording_upload_unconfirmed' });
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
throw new Error('browser_live_protocol_invalid');
|
|
199
|
+
}).catch(close).finally(() => { queued--; });
|
|
200
|
+
});
|
|
201
|
+
socket.on('close', close);
|
|
202
|
+
socket.on('error', close);
|
|
203
|
+
}
|
|
204
|
+
disconnectAll() { for (const connection of [...this.connections.values()])
|
|
205
|
+
connection.close(); }
|
|
206
|
+
}
|