@bctrl/sdk 1.0.1 → 1.0.2
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 +24 -29
- package/dist/bctrl.d.ts +22 -36
- package/dist/bctrl.js +40 -75
- package/dist/browsers.d.ts +24 -0
- package/dist/browsers.js +82 -0
- package/dist/errors.d.ts +49 -43
- package/dist/errors.js +83 -120
- package/dist/files.d.ts +31 -0
- package/dist/files.js +97 -0
- package/dist/http.d.ts +18 -0
- package/dist/http.js +135 -0
- package/dist/index.d.ts +9 -12
- package/dist/index.js +8 -23
- package/dist/invocations.d.ts +24 -0
- package/dist/invocations.js +66 -0
- package/dist/pagination.d.ts +2 -0
- package/dist/pagination.js +13 -0
- package/dist/runs.d.ts +38 -0
- package/dist/runs.js +99 -0
- package/dist/runtimes.d.ts +73 -0
- package/dist/runtimes.js +205 -0
- package/dist/spaces.d.ts +41 -0
- package/dist/spaces.js +96 -0
- package/dist/types.d.ts +386 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +27 -0
- package/dist/version.js +2 -2
- package/package.json +12 -31
- package/dist/agents/browser-use/index.d.ts +0 -1
- package/dist/agents/browser-use/index.js +0 -9
- package/dist/agents/browser-use/namespace.d.ts +0 -39
- package/dist/agents/browser-use/namespace.js +0 -93
- package/dist/agents/index.d.ts +0 -2
- package/dist/agents/index.js +0 -17
- package/dist/agents/stagehand/core.d.ts +0 -93
- package/dist/agents/stagehand/core.js +0 -144
- package/dist/agents/stagehand/index.d.ts +0 -3
- package/dist/agents/stagehand/index.js +0 -24
- package/dist/agents/stagehand/namespace.d.ts +0 -51
- package/dist/agents/stagehand/namespace.js +0 -65
- package/dist/ai-credentials/client.d.ts +0 -12
- package/dist/ai-credentials/client.js +0 -70
- package/dist/ai-credentials/index.d.ts +0 -1
- package/dist/ai-credentials/index.js +0 -1
- package/dist/base/event-binding.d.ts +0 -7
- package/dist/base/event-binding.js +0 -23
- package/dist/base/types.d.ts +0 -109
- package/dist/base/types.js +0 -4
- package/dist/browser-extensions/client.d.ts +0 -15
- package/dist/browser-extensions/client.js +0 -72
- package/dist/browser-extensions/index.d.ts +0 -2
- package/dist/browser-extensions/index.js +0 -1
- package/dist/browser-profiles/client.d.ts +0 -11
- package/dist/browser-profiles/client.js +0 -63
- package/dist/browser-profiles/index.d.ts +0 -1
- package/dist/browser-profiles/index.js +0 -1
- package/dist/captcha/index.d.ts +0 -1
- package/dist/captcha/index.js +0 -1
- package/dist/captcha/namespace.d.ts +0 -34
- package/dist/captcha/namespace.js +0 -41
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +0 -1
- package/dist/client/rpc.d.ts +0 -83
- package/dist/client/rpc.js +0 -354
- package/dist/config.d.ts +0 -5
- package/dist/config.js +0 -28
- package/dist/constants/browser.d.ts +0 -2
- package/dist/constants/browser.js +0 -1
- package/dist/contracts/agent-tools.d.ts +0 -45
- package/dist/contracts/agent-tools.js +0 -31
- package/dist/contracts/automation.d.ts +0 -265
- package/dist/contracts/automation.js +0 -109
- package/dist/contracts/browser-management.d.ts +0 -179
- package/dist/contracts/browser-management.js +0 -95
- package/dist/contracts/browser-use.d.ts +0 -136
- package/dist/contracts/browser-use.js +0 -93
- package/dist/contracts/captcha.d.ts +0 -114
- package/dist/contracts/captcha.js +0 -40
- package/dist/contracts/desktop.d.ts +0 -223
- package/dist/contracts/desktop.js +0 -121
- package/dist/contracts/drivers/playwright.d.ts +0 -2008
- package/dist/contracts/drivers/playwright.js +0 -2033
- package/dist/contracts/drivers/puppeteer.d.ts +0 -1221
- package/dist/contracts/drivers/puppeteer.js +0 -941
- package/dist/contracts/drivers/selenium.d.ts +0 -156
- package/dist/contracts/drivers/selenium.js +0 -61
- package/dist/contracts/drivers/stagehand.d.ts +0 -155
- package/dist/contracts/drivers/stagehand.js +0 -7
- package/dist/contracts/extensions.d.ts +0 -13
- package/dist/contracts/extensions.js +0 -9
- package/dist/contracts/index.d.ts +0 -13
- package/dist/contracts/index.js +0 -13
- package/dist/contracts/public-api.d.ts +0 -360
- package/dist/contracts/public-api.js +0 -17
- package/dist/contracts/runtime.d.ts +0 -81
- package/dist/contracts/runtime.js +0 -16
- package/dist/contracts/stagehand.d.ts +0 -253
- package/dist/contracts/stagehand.js +0 -145
- package/dist/contracts/storage.d.ts +0 -51
- package/dist/contracts/storage.js +0 -56
- package/dist/contracts/vault.d.ts +0 -119
- package/dist/contracts/vault.js +0 -112
- package/dist/contracts/version.d.ts +0 -3
- package/dist/contracts/version.js +0 -16
- package/dist/desktop.d.ts +0 -2
- package/dist/desktop.js +0 -3
- package/dist/drivers/desktop/index.d.ts +0 -65
- package/dist/drivers/desktop/index.js +0 -68
- package/dist/drivers/desktop/session.d.ts +0 -313
- package/dist/drivers/desktop/session.js +0 -432
- package/dist/drivers/playwright/event-emitter.d.ts +0 -160
- package/dist/drivers/playwright/event-emitter.js +0 -297
- package/dist/drivers/playwright/generated/api-request-context.d.ts +0 -137
- package/dist/drivers/playwright/generated/api-request-context.js +0 -154
- package/dist/drivers/playwright/generated/api-response.d.ts +0 -119
- package/dist/drivers/playwright/generated/api-response.js +0 -123
- package/dist/drivers/playwright/generated/browser-context.d.ts +0 -284
- package/dist/drivers/playwright/generated/browser-context.js +0 -458
- package/dist/drivers/playwright/generated/browser.d.ts +0 -120
- package/dist/drivers/playwright/generated/browser.js +0 -151
- package/dist/drivers/playwright/generated/clock.d.ts +0 -80
- package/dist/drivers/playwright/generated/clock.js +0 -94
- package/dist/drivers/playwright/generated/console-message.d.ts +0 -94
- package/dist/drivers/playwright/generated/console-message.js +0 -89
- package/dist/drivers/playwright/generated/coverage.d.ts +0 -57
- package/dist/drivers/playwright/generated/coverage.js +0 -66
- package/dist/drivers/playwright/generated/dialog.d.ts +0 -79
- package/dist/drivers/playwright/generated/dialog.js +0 -80
- package/dist/drivers/playwright/generated/element-handle.d.ts +0 -399
- package/dist/drivers/playwright/generated/element-handle.js +0 -501
- package/dist/drivers/playwright/generated/frame-locator.d.ts +0 -34
- package/dist/drivers/playwright/generated/frame-locator.js +0 -63
- package/dist/drivers/playwright/generated/frame.d.ts +0 -557
- package/dist/drivers/playwright/generated/frame.js +0 -634
- package/dist/drivers/playwright/generated/js-handle.d.ts +0 -72
- package/dist/drivers/playwright/generated/js-handle.js +0 -92
- package/dist/drivers/playwright/generated/keyboard.d.ts +0 -103
- package/dist/drivers/playwright/generated/keyboard.js +0 -113
- package/dist/drivers/playwright/generated/locator.d.ts +0 -795
- package/dist/drivers/playwright/generated/locator.js +0 -974
- package/dist/drivers/playwright/generated/mouse.d.ts +0 -97
- package/dist/drivers/playwright/generated/mouse.js +0 -109
- package/dist/drivers/playwright/generated/page.d.ts +0 -762
- package/dist/drivers/playwright/generated/page.js +0 -988
- package/dist/drivers/playwright/generated/touchscreen.d.ts +0 -34
- package/dist/drivers/playwright/generated/touchscreen.js +0 -37
- package/dist/drivers/playwright/generated/tracing.d.ts +0 -78
- package/dist/drivers/playwright/generated/tracing.js +0 -80
- package/dist/drivers/playwright/generated/worker.d.ts +0 -53
- package/dist/drivers/playwright/generated/worker.js +0 -59
- package/dist/drivers/playwright/index.d.ts +0 -19
- package/dist/drivers/playwright/index.js +0 -20
- package/dist/drivers/playwright/remote-base.d.ts +0 -62
- package/dist/drivers/playwright/remote-base.js +0 -86
- package/dist/drivers/playwright/types.d.ts +0 -148
- package/dist/drivers/playwright/types.js +0 -8
- package/dist/drivers/puppeteer/errors.d.ts +0 -50
- package/dist/drivers/puppeteer/errors.js +0 -71
- package/dist/drivers/puppeteer/event-emitter.d.ts +0 -145
- package/dist/drivers/puppeteer/event-emitter.js +0 -259
- package/dist/drivers/puppeteer/generated/accessibility.d.ts +0 -77
- package/dist/drivers/puppeteer/generated/accessibility.js +0 -74
- package/dist/drivers/puppeteer/generated/browser-context.d.ts +0 -116
- package/dist/drivers/puppeteer/generated/browser-context.js +0 -168
- package/dist/drivers/puppeteer/generated/browser.d.ts +0 -169
- package/dist/drivers/puppeteer/generated/browser.js +0 -246
- package/dist/drivers/puppeteer/generated/console-message.d.ts +0 -54
- package/dist/drivers/puppeteer/generated/console-message.js +0 -69
- package/dist/drivers/puppeteer/generated/coverage.d.ts +0 -49
- package/dist/drivers/puppeteer/generated/coverage.js +0 -57
- package/dist/drivers/puppeteer/generated/dialog.d.ts +0 -46
- package/dist/drivers/puppeteer/generated/dialog.js +0 -60
- package/dist/drivers/puppeteer/generated/element-handle.d.ts +0 -261
- package/dist/drivers/puppeteer/generated/element-handle.js +0 -341
- package/dist/drivers/puppeteer/generated/file-chooser.d.ts +0 -34
- package/dist/drivers/puppeteer/generated/file-chooser.js +0 -43
- package/dist/drivers/puppeteer/generated/frame.d.ts +0 -221
- package/dist/drivers/puppeteer/generated/frame.js +0 -302
- package/dist/drivers/puppeteer/generated/http-request.d.ts +0 -195
- package/dist/drivers/puppeteer/generated/http-request.js +0 -243
- package/dist/drivers/puppeteer/generated/http-response.d.ts +0 -142
- package/dist/drivers/puppeteer/generated/http-response.js +0 -169
- package/dist/drivers/puppeteer/generated/js-handle.d.ts +0 -104
- package/dist/drivers/puppeteer/generated/js-handle.js +0 -125
- package/dist/drivers/puppeteer/generated/keyboard.d.ts +0 -79
- package/dist/drivers/puppeteer/generated/keyboard.js +0 -89
- package/dist/drivers/puppeteer/generated/locator.d.ts +0 -141
- package/dist/drivers/puppeteer/generated/locator.js +0 -164
- package/dist/drivers/puppeteer/generated/mouse.d.ts +0 -74
- package/dist/drivers/puppeteer/generated/mouse.js +0 -94
- package/dist/drivers/puppeteer/generated/page.d.ts +0 -604
- package/dist/drivers/puppeteer/generated/page.js +0 -776
- package/dist/drivers/puppeteer/generated/target.d.ts +0 -105
- package/dist/drivers/puppeteer/generated/target.js +0 -123
- package/dist/drivers/puppeteer/generated/touchscreen.d.ts +0 -87
- package/dist/drivers/puppeteer/generated/touchscreen.js +0 -103
- package/dist/drivers/puppeteer/generated/tracing.d.ts +0 -38
- package/dist/drivers/puppeteer/generated/tracing.js +0 -43
- package/dist/drivers/puppeteer/generated/web-worker.d.ts +0 -63
- package/dist/drivers/puppeteer/generated/web-worker.js +0 -73
- package/dist/drivers/puppeteer/index.d.ts +0 -21
- package/dist/drivers/puppeteer/index.js +0 -23
- package/dist/drivers/puppeteer/remote-base.d.ts +0 -57
- package/dist/drivers/puppeteer/remote-base.js +0 -79
- package/dist/drivers/puppeteer/types.d.ts +0 -178
- package/dist/drivers/puppeteer/types.js +0 -8
- package/dist/drivers/selenium/driver.d.ts +0 -28
- package/dist/drivers/selenium/driver.js +0 -169
- package/dist/drivers/selenium/element.d.ts +0 -34
- package/dist/drivers/selenium/element.js +0 -73
- package/dist/drivers/selenium/index.d.ts +0 -3
- package/dist/drivers/selenium/index.js +0 -5
- package/dist/drivers/selenium/types.d.ts +0 -2
- package/dist/drivers/selenium/types.js +0 -12
- package/dist/drivers/stagehand/generated/context.d.ts +0 -127
- package/dist/drivers/stagehand/generated/context.js +0 -153
- package/dist/drivers/stagehand/generated/locator.d.ts +0 -324
- package/dist/drivers/stagehand/generated/locator.js +0 -368
- package/dist/drivers/stagehand/generated/page.d.ts +0 -377
- package/dist/drivers/stagehand/generated/page.js +0 -439
- package/dist/drivers/stagehand/generated/response.d.ts +0 -197
- package/dist/drivers/stagehand/generated/response.js +0 -232
- package/dist/drivers/stagehand/index.d.ts +0 -5
- package/dist/drivers/stagehand/index.js +0 -8
- package/dist/drivers/stagehand/types.d.ts +0 -1
- package/dist/drivers/stagehand/types.js +0 -7
- package/dist/extensions/client.d.ts +0 -47
- package/dist/extensions/client.js +0 -154
- package/dist/extensions/index.d.ts +0 -1
- package/dist/extensions/index.js +0 -1
- package/dist/internal/dev-client.d.ts +0 -5
- package/dist/internal/dev-client.js +0 -9
- package/dist/internal/rpc-targets.d.ts +0 -17
- package/dist/internal/rpc-targets.js +0 -58
- package/dist/internal/serialization.d.ts +0 -32
- package/dist/internal/serialization.js +0 -42
- package/dist/internal/transport.d.ts +0 -24
- package/dist/internal/transport.js +0 -29
- package/dist/playwright.d.ts +0 -1
- package/dist/playwright.js +0 -2
- package/dist/puppeteer.d.ts +0 -1
- package/dist/puppeteer.js +0 -2
- package/dist/selenium.d.ts +0 -1
- package/dist/selenium.js +0 -2
- package/dist/stagehand.d.ts +0 -1
- package/dist/stagehand.js +0 -2
- package/dist/storage/client.d.ts +0 -151
- package/dist/storage/client.js +0 -329
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/index.js +0 -4
- package/dist/telemetry.d.ts +0 -18
- package/dist/telemetry.js +0 -93
- package/dist/updates/client.d.ts +0 -8
- package/dist/updates/client.js +0 -128
- package/dist/updates/index.d.ts +0 -1
- package/dist/updates/index.js +0 -1
- package/dist/utils/http.d.ts +0 -39
- package/dist/utils/http.js +0 -88
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.js +0 -4
- package/dist/utils/logger.d.ts +0 -27
- package/dist/utils/logger.js +0 -74
- package/dist/utils/schema.d.ts +0 -17
- package/dist/utils/schema.js +0 -31
- package/dist/utils/url.d.ts +0 -5
- package/dist/utils/url.js +0 -7
- package/dist/vault/client.d.ts +0 -43
- package/dist/vault/client.js +0 -123
- package/dist/vault/index.d.ts +0 -1
- package/dist/vault/index.js +0 -1
- package/dist/workspaces/browser-runtime.d.ts +0 -251
- package/dist/workspaces/browser-runtime.js +0 -1025
- package/dist/workspaces/client.d.ts +0 -48
- package/dist/workspaces/client.js +0 -222
- package/dist/workspaces/index.d.ts +0 -2
- package/dist/workspaces/index.js +0 -2
- package/dist/workspaces/runtime-event-pump.d.ts +0 -65
- package/dist/workspaces/runtime-event-pump.js +0 -716
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { fetchWithTimeout, parseErrorDetails, parseJsonResponse } from '../utils/http.js';
|
|
2
|
-
import { SDK_VERSION } from '../version.js';
|
|
3
|
-
function buildHeaders(apiKey) {
|
|
4
|
-
return {
|
|
5
|
-
'x-sdk-version': SDK_VERSION,
|
|
6
|
-
Authorization: `Bearer ${apiKey}`,
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
function buildJsonHeaders(apiKey) {
|
|
10
|
-
return {
|
|
11
|
-
...buildHeaders(apiKey),
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
async function expectJson(response, context) {
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
const details = parseErrorDetails(await response.text());
|
|
18
|
-
throw new Error(`${context}: ${details.message}`);
|
|
19
|
-
}
|
|
20
|
-
return parseJsonResponse(response, context);
|
|
21
|
-
}
|
|
22
|
-
function toBlob(data) {
|
|
23
|
-
if (data instanceof Blob)
|
|
24
|
-
return data;
|
|
25
|
-
return new Blob([new Uint8Array(data)]);
|
|
26
|
-
}
|
|
27
|
-
export class BrowserExtensionsClient {
|
|
28
|
-
baseUrl;
|
|
29
|
-
apiKey;
|
|
30
|
-
constructor(baseUrl, apiKey) {
|
|
31
|
-
this.baseUrl = baseUrl;
|
|
32
|
-
this.apiKey = apiKey;
|
|
33
|
-
}
|
|
34
|
-
async list() {
|
|
35
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-extensions`, {
|
|
36
|
-
headers: buildHeaders(this.apiKey),
|
|
37
|
-
});
|
|
38
|
-
const data = await expectJson(response, 'List browser extensions');
|
|
39
|
-
return data.extensions;
|
|
40
|
-
}
|
|
41
|
-
async upload(request) {
|
|
42
|
-
const formData = new FormData();
|
|
43
|
-
formData.append('file', toBlob(request.file), request.filename);
|
|
44
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-extensions/upload`, {
|
|
45
|
-
method: 'POST',
|
|
46
|
-
headers: buildHeaders(this.apiKey),
|
|
47
|
-
body: formData,
|
|
48
|
-
});
|
|
49
|
-
return expectJson(response, 'Upload browser extension');
|
|
50
|
-
}
|
|
51
|
-
async importFromUrl(request) {
|
|
52
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-extensions/import-url`, {
|
|
53
|
-
method: 'POST',
|
|
54
|
-
headers: buildJsonHeaders(this.apiKey),
|
|
55
|
-
body: JSON.stringify(request),
|
|
56
|
-
});
|
|
57
|
-
return expectJson(response, 'Import browser extension');
|
|
58
|
-
}
|
|
59
|
-
async get(id) {
|
|
60
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-extensions/${encodeURIComponent(id)}`, {
|
|
61
|
-
headers: buildHeaders(this.apiKey),
|
|
62
|
-
});
|
|
63
|
-
return expectJson(response, 'Get browser extension');
|
|
64
|
-
}
|
|
65
|
-
async delete(id) {
|
|
66
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-extensions/${encodeURIComponent(id)}`, {
|
|
67
|
-
method: 'DELETE',
|
|
68
|
-
headers: buildHeaders(this.apiKey),
|
|
69
|
-
});
|
|
70
|
-
return expectJson(response, 'Delete browser extension');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BrowserExtensionsClient } from './client.js';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { BrowserProfile, BrowserProfileCreateRequest, BrowserProfileDeleteResponse, BrowserProfileDetail, BrowserProfileUpdateRequest } from '../contracts/public-api.js';
|
|
2
|
-
export declare class BrowserProfilesClient {
|
|
3
|
-
private readonly baseUrl;
|
|
4
|
-
private readonly apiKey;
|
|
5
|
-
constructor(baseUrl: string, apiKey: string);
|
|
6
|
-
list(): Promise<BrowserProfile[]>;
|
|
7
|
-
create(request: BrowserProfileCreateRequest): Promise<BrowserProfileDetail>;
|
|
8
|
-
get(id: string): Promise<BrowserProfileDetail>;
|
|
9
|
-
update(id: string, request: BrowserProfileUpdateRequest): Promise<BrowserProfileDetail>;
|
|
10
|
-
delete(id: string): Promise<BrowserProfileDeleteResponse>;
|
|
11
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { fetchWithTimeout, parseErrorDetails, parseJsonResponse } from '../utils/http.js';
|
|
2
|
-
import { SDK_VERSION } from '../version.js';
|
|
3
|
-
function buildHeaders(apiKey, withJsonBody = false) {
|
|
4
|
-
const headers = {
|
|
5
|
-
'x-sdk-version': SDK_VERSION,
|
|
6
|
-
Authorization: `Bearer ${apiKey}`,
|
|
7
|
-
};
|
|
8
|
-
if (withJsonBody) {
|
|
9
|
-
headers['Content-Type'] = 'application/json';
|
|
10
|
-
}
|
|
11
|
-
return headers;
|
|
12
|
-
}
|
|
13
|
-
async function expectJson(response, context) {
|
|
14
|
-
if (!response.ok) {
|
|
15
|
-
const details = parseErrorDetails(await response.text());
|
|
16
|
-
throw new Error(`${context}: ${details.message}`);
|
|
17
|
-
}
|
|
18
|
-
return parseJsonResponse(response, context);
|
|
19
|
-
}
|
|
20
|
-
export class BrowserProfilesClient {
|
|
21
|
-
baseUrl;
|
|
22
|
-
apiKey;
|
|
23
|
-
constructor(baseUrl, apiKey) {
|
|
24
|
-
this.baseUrl = baseUrl;
|
|
25
|
-
this.apiKey = apiKey;
|
|
26
|
-
}
|
|
27
|
-
async list() {
|
|
28
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-profiles`, {
|
|
29
|
-
headers: buildHeaders(this.apiKey),
|
|
30
|
-
});
|
|
31
|
-
const data = await expectJson(response, 'List browser profiles');
|
|
32
|
-
return data.profiles;
|
|
33
|
-
}
|
|
34
|
-
async create(request) {
|
|
35
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-profiles`, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
headers: buildHeaders(this.apiKey, true),
|
|
38
|
-
body: JSON.stringify(request),
|
|
39
|
-
});
|
|
40
|
-
return expectJson(response, 'Create browser profile');
|
|
41
|
-
}
|
|
42
|
-
async get(id) {
|
|
43
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-profiles/${encodeURIComponent(id)}`, {
|
|
44
|
-
headers: buildHeaders(this.apiKey),
|
|
45
|
-
});
|
|
46
|
-
return expectJson(response, 'Get browser profile');
|
|
47
|
-
}
|
|
48
|
-
async update(id, request) {
|
|
49
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-profiles/${encodeURIComponent(id)}`, {
|
|
50
|
-
method: 'PATCH',
|
|
51
|
-
headers: buildHeaders(this.apiKey, true),
|
|
52
|
-
body: JSON.stringify(request),
|
|
53
|
-
});
|
|
54
|
-
return expectJson(response, 'Update browser profile');
|
|
55
|
-
}
|
|
56
|
-
async delete(id) {
|
|
57
|
-
const response = await fetchWithTimeout(`${this.baseUrl}/browser-profiles/${encodeURIComponent(id)}`, {
|
|
58
|
-
method: 'DELETE',
|
|
59
|
-
headers: buildHeaders(this.apiKey),
|
|
60
|
-
});
|
|
61
|
-
return expectJson(response, 'Delete browser profile');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BrowserProfilesClient } from './client.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BrowserProfilesClient } from './client.js';
|
package/dist/captcha/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CaptchaNamespace } from './namespace.js';
|
package/dist/captcha/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CaptchaNamespace } from './namespace.js';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CaptchaNamespace — SDK methods for captcha detection and solving
|
|
3
|
-
*
|
|
4
|
-
* Provides `detect()` and `solve()` methods that send RPC calls
|
|
5
|
-
* to the browser-host via the page target.
|
|
6
|
-
*/
|
|
7
|
-
import type { CaptchaDetectArgs, CaptchaDetectResult, CaptchaSolveArgs, CaptchaSolveResult } from '../contracts/captcha.js';
|
|
8
|
-
import type { RpcSender } from '../internal/transport.js';
|
|
9
|
-
export declare class CaptchaNamespace {
|
|
10
|
-
private sendRpc;
|
|
11
|
-
private getActivePageId;
|
|
12
|
-
constructor(sendRpc: RpcSender, getActivePageId: () => string | undefined);
|
|
13
|
-
/**
|
|
14
|
-
* Detect captchas on the current page.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const result = await session.captcha.detect();
|
|
18
|
-
* if (result.found) {
|
|
19
|
-
* console.log('Found captchas:', result.captchas);
|
|
20
|
-
* }
|
|
21
|
-
*/
|
|
22
|
-
detect(options?: CaptchaDetectArgs): Promise<CaptchaDetectResult>;
|
|
23
|
-
/**
|
|
24
|
-
* Detect and solve a captcha on the current page.
|
|
25
|
-
* Detects the captcha type, sends to solver backend, and injects the token.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* const result = await session.captcha.solve();
|
|
29
|
-
* if (result.success) {
|
|
30
|
-
* console.log(`Solved ${result.type} in ${result.duration}ms`);
|
|
31
|
-
* }
|
|
32
|
-
*/
|
|
33
|
-
solve(options?: CaptchaSolveArgs): Promise<CaptchaSolveResult>;
|
|
34
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CaptchaNamespace — SDK methods for captcha detection and solving
|
|
3
|
-
*
|
|
4
|
-
* Provides `detect()` and `solve()` methods that send RPC calls
|
|
5
|
-
* to the browser-host via the page target.
|
|
6
|
-
*/
|
|
7
|
-
export class CaptchaNamespace {
|
|
8
|
-
sendRpc;
|
|
9
|
-
getActivePageId;
|
|
10
|
-
constructor(sendRpc, getActivePageId) {
|
|
11
|
-
this.sendRpc = sendRpc;
|
|
12
|
-
this.getActivePageId = getActivePageId;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Detect captchas on the current page.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* const result = await session.captcha.detect();
|
|
19
|
-
* if (result.found) {
|
|
20
|
-
* console.log('Found captchas:', result.captchas);
|
|
21
|
-
* }
|
|
22
|
-
*/
|
|
23
|
-
async detect(options) {
|
|
24
|
-
const pageId = this.getActivePageId();
|
|
25
|
-
return this.sendRpc('page', 'captcha.detect', [options ?? {}], { pageId });
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Detect and solve a captcha on the current page.
|
|
29
|
-
* Detects the captcha type, sends to solver backend, and injects the token.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* const result = await session.captcha.solve();
|
|
33
|
-
* if (result.success) {
|
|
34
|
-
* console.log(`Solved ${result.type} in ${result.duration}ms`);
|
|
35
|
-
* }
|
|
36
|
-
*/
|
|
37
|
-
async solve(options) {
|
|
38
|
-
const pageId = this.getActivePageId();
|
|
39
|
-
return this.sendRpc('page', 'captcha.solve', [options ?? {}], { pageId });
|
|
40
|
-
}
|
|
41
|
-
}
|
package/dist/client/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './rpc.js';
|
package/dist/client/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './rpc.js';
|
package/dist/client/rpc.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { RpcTarget } from '../internal/transport.js';
|
|
2
|
-
import type { BrowserDriver } from '../contracts/runtime.js';
|
|
3
|
-
import type { VaultSessionPolicy } from '../contracts/vault.js';
|
|
4
|
-
import type { SessionStoragePolicy } from '../contracts/storage.js';
|
|
5
|
-
/**
|
|
6
|
-
* RPC call to control-plane
|
|
7
|
-
* @param endpoint - Full URL of the endpoint
|
|
8
|
-
* @param body - Request body
|
|
9
|
-
* @param timeout - Optional timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
10
|
-
*/
|
|
11
|
-
export declare function rpc<T>(endpoint: string, body: Record<string, unknown>, timeout?: number): Promise<T>;
|
|
12
|
-
/**
|
|
13
|
-
* Start an ephemeral browser session through the API gateway (no driver connected).
|
|
14
|
-
* @param baseUrl - Versioned API base URL of the gateway (e.g., 'http://localhost:8787/v1')
|
|
15
|
-
* @param options - Session start options
|
|
16
|
-
*/
|
|
17
|
-
export declare function startSession(baseUrl: string, options?: {
|
|
18
|
-
apiKey?: string;
|
|
19
|
-
humanize?: boolean;
|
|
20
|
-
humanizePersonaId?: number;
|
|
21
|
-
proxy?: {
|
|
22
|
-
type: 'http' | 'socks5';
|
|
23
|
-
host: string;
|
|
24
|
-
port: number;
|
|
25
|
-
username?: string;
|
|
26
|
-
password?: string;
|
|
27
|
-
} | null;
|
|
28
|
-
storage?: SessionStoragePolicy;
|
|
29
|
-
solveCaptchas?: boolean;
|
|
30
|
-
vault?: VaultSessionPolicy;
|
|
31
|
-
}): Promise<{
|
|
32
|
-
id: string;
|
|
33
|
-
status: 'active' | 'stopped';
|
|
34
|
-
storageWorkspace?: string;
|
|
35
|
-
}>;
|
|
36
|
-
/**
|
|
37
|
-
* Connect a driver to an existing started session on the control-plane.
|
|
38
|
-
*/
|
|
39
|
-
export declare function connectSessionDriver(baseUrl: string, sessionId: string, driver: BrowserDriver, apiKey?: string): Promise<{
|
|
40
|
-
id: string;
|
|
41
|
-
currentDriver: BrowserDriver;
|
|
42
|
-
defaultContextId?: string;
|
|
43
|
-
defaultPageId?: string;
|
|
44
|
-
storageWorkspace?: string;
|
|
45
|
-
}>;
|
|
46
|
-
/**
|
|
47
|
-
* Stop a session on the control-plane
|
|
48
|
-
* @param baseUrl - Versioned API base URL of the control-plane
|
|
49
|
-
* @param sessionId - Session ID to stop
|
|
50
|
-
* @param apiKey - Optional API key
|
|
51
|
-
*/
|
|
52
|
-
export declare function stopSession(baseUrl: string, sessionId: string, apiKey?: string): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Send RPC/EXECUTE command through the canonical automation endpoint.
|
|
55
|
-
* @param baseUrl - Versioned API base URL of the control-plane
|
|
56
|
-
* @param sessionId - Session ID
|
|
57
|
-
* @param command - RPC or EXECUTE command
|
|
58
|
-
* @param timeout - Optional timeout in milliseconds
|
|
59
|
-
*/
|
|
60
|
-
type SendCommandInput = {
|
|
61
|
-
type: 'RPC';
|
|
62
|
-
correlationId?: string;
|
|
63
|
-
target: RpcTarget;
|
|
64
|
-
method: string;
|
|
65
|
-
args: unknown[];
|
|
66
|
-
contextId?: string;
|
|
67
|
-
pageId?: string;
|
|
68
|
-
handleId?: string;
|
|
69
|
-
} | {
|
|
70
|
-
type: 'EXECUTE';
|
|
71
|
-
correlationId?: string;
|
|
72
|
-
code: string;
|
|
73
|
-
args?: Record<string, unknown>;
|
|
74
|
-
pageId?: string;
|
|
75
|
-
options?: {
|
|
76
|
-
timeoutMs?: number;
|
|
77
|
-
logs?: 'off' | 'capture';
|
|
78
|
-
scriptId?: string;
|
|
79
|
-
scriptName?: string;
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
export declare function sendCommand<T>(baseUrl: string, sessionId: string, command: SendCommandInput, apiKey?: string, timeout?: number): Promise<T>;
|
|
83
|
-
export {};
|
package/dist/client/rpc.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// RPC Client - HTTP calls to control-plane
|
|
3
|
-
// ============================================================================
|
|
4
|
-
import { parseJsonResponse, fetchWithTimeout, DEFAULT_TIMEOUT_MS, LONG_TIMEOUT_MS, } from '../utils/http.js';
|
|
5
|
-
import { fromErrorResponse, AuthenticationError, SessionError, TimeoutError, } from '../errors.js';
|
|
6
|
-
import * as telemetry from '../telemetry.js';
|
|
7
|
-
import { SDK_VERSION } from '../version.js';
|
|
8
|
-
import { CONTEXT_REF_TARGETS, HANDLE_TARGETS, PAGE_REF_TARGETS, } from '../internal/rpc-targets.js';
|
|
9
|
-
/**
|
|
10
|
-
* Map an HTTP status code + response text to a typed BctrlError.
|
|
11
|
-
*/
|
|
12
|
-
function httpStatusToError(status, text, fallbackMessage) {
|
|
13
|
-
if (status === 401 || status === 403)
|
|
14
|
-
return new AuthenticationError(`Authentication failed: ${text}`);
|
|
15
|
-
if (status === 404)
|
|
16
|
-
return new SessionError(`Not found: ${text}`, 'NOT_FOUND');
|
|
17
|
-
if (status === 504)
|
|
18
|
-
return new TimeoutError(`Gateway timeout: ${text}`);
|
|
19
|
-
if (status === 503)
|
|
20
|
-
return new SessionError(`Service unavailable: ${text}`, 'CONNECTION_ERROR');
|
|
21
|
-
return fromErrorResponse(fallbackMessage ?? `HTTP ${status}: ${text}`);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Extract timeout (ms) from an RPC method options argument if present.
|
|
25
|
-
* Many automation APIs use the last arg as an options object with `timeout`.
|
|
26
|
-
*/
|
|
27
|
-
function getRpcOptionsTimeoutMs(args) {
|
|
28
|
-
if (!Array.isArray(args) || args.length === 0)
|
|
29
|
-
return undefined;
|
|
30
|
-
const lastArg = args[args.length - 1];
|
|
31
|
-
if (!lastArg || typeof lastArg !== 'object' || Array.isArray(lastArg))
|
|
32
|
-
return undefined;
|
|
33
|
-
const timeoutRaw = lastArg.timeout;
|
|
34
|
-
if (typeof timeoutRaw !== 'number' || !Number.isFinite(timeoutRaw) || timeoutRaw <= 0) {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
return Math.floor(timeoutRaw);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Methods that are expected to wait on browser state and may run longer than 30s.
|
|
41
|
-
*/
|
|
42
|
-
function isLongRunningRpcMethod(method) {
|
|
43
|
-
return (method.startsWith('wait') ||
|
|
44
|
-
method === 'goto' ||
|
|
45
|
-
method === 'reload' ||
|
|
46
|
-
method === 'setContent');
|
|
47
|
-
}
|
|
48
|
-
const AGENT_RPC_TIMEOUT_MS = 5 * 60 * 1000;
|
|
49
|
-
function isLongRunningAgentRpc(target, method) {
|
|
50
|
-
if (target === 'browserUse') {
|
|
51
|
-
return method === 'agent.execute' || method === 'codeAgent.execute';
|
|
52
|
-
}
|
|
53
|
-
if (target === 'stagehand') {
|
|
54
|
-
return method === 'agent.execute';
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
function trimTrailingUndefined(args) {
|
|
59
|
-
if (!Array.isArray(args))
|
|
60
|
-
return args;
|
|
61
|
-
let end = args.length;
|
|
62
|
-
while (end > 0 && args[end - 1] === undefined) {
|
|
63
|
-
end -= 1;
|
|
64
|
-
}
|
|
65
|
-
return end === args.length ? args : args.slice(0, end);
|
|
66
|
-
}
|
|
67
|
-
function parseAutomationEnvelope(text) {
|
|
68
|
-
if (!text)
|
|
69
|
-
return null;
|
|
70
|
-
try {
|
|
71
|
-
const parsed = JSON.parse(text);
|
|
72
|
-
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function buildAutomationError(error, fallbackMessage) {
|
|
79
|
-
const message = error?.message || fallbackMessage;
|
|
80
|
-
const hint = error?.hint;
|
|
81
|
-
const diagnostic = error?.diagnostic;
|
|
82
|
-
const context = {};
|
|
83
|
-
if (hint)
|
|
84
|
-
context.hint = hint;
|
|
85
|
-
if (diagnostic)
|
|
86
|
-
context.diagnostic = diagnostic;
|
|
87
|
-
return fromErrorResponse(hint ? `${message} (${hint})` : message, error?.code, Object.keys(context).length > 0 ? context : undefined);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* RPC call to control-plane
|
|
91
|
-
* @param endpoint - Full URL of the endpoint
|
|
92
|
-
* @param body - Request body
|
|
93
|
-
* @param timeout - Optional timeout in milliseconds (default: DEFAULT_TIMEOUT_MS)
|
|
94
|
-
*/
|
|
95
|
-
export async function rpc(endpoint, body, timeout) {
|
|
96
|
-
const response = await fetchWithTimeout(endpoint, {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: {
|
|
99
|
-
'Content-Type': 'application/json',
|
|
100
|
-
'x-sdk-version': SDK_VERSION,
|
|
101
|
-
},
|
|
102
|
-
body: JSON.stringify(body),
|
|
103
|
-
}, timeout ?? DEFAULT_TIMEOUT_MS);
|
|
104
|
-
// Read request ID from response for error context
|
|
105
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
106
|
-
if (!response.ok) {
|
|
107
|
-
const text = await response.text();
|
|
108
|
-
const err = httpStatusToError(response.status, text);
|
|
109
|
-
telemetry.captureError(err, {
|
|
110
|
-
endpoint,
|
|
111
|
-
method: 'POST',
|
|
112
|
-
statusCode: response.status,
|
|
113
|
-
errorCode: err.code,
|
|
114
|
-
requestId,
|
|
115
|
-
});
|
|
116
|
-
throw err;
|
|
117
|
-
}
|
|
118
|
-
const data = await parseJsonResponse(response, `RPC ${endpoint}`);
|
|
119
|
-
if (data.status === 'error') {
|
|
120
|
-
const err = fromErrorResponse(data.error || 'Unknown error', data.errorCode, data.errorContext);
|
|
121
|
-
telemetry.captureError(err, {
|
|
122
|
-
endpoint,
|
|
123
|
-
method: 'POST',
|
|
124
|
-
statusCode: response.status,
|
|
125
|
-
errorCode: data.errorCode,
|
|
126
|
-
requestId,
|
|
127
|
-
});
|
|
128
|
-
throw err;
|
|
129
|
-
}
|
|
130
|
-
return data.result;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Start an ephemeral browser session through the API gateway (no driver connected).
|
|
134
|
-
* @param baseUrl - Versioned API base URL of the gateway (e.g., 'http://localhost:8787/v1')
|
|
135
|
-
* @param options - Session start options
|
|
136
|
-
*/
|
|
137
|
-
export async function startSession(baseUrl, options = {}) {
|
|
138
|
-
const headers = {
|
|
139
|
-
'Content-Type': 'application/json',
|
|
140
|
-
'x-sdk-version': SDK_VERSION,
|
|
141
|
-
};
|
|
142
|
-
if (options.apiKey) {
|
|
143
|
-
headers['Authorization'] = `Bearer ${options.apiKey}`;
|
|
144
|
-
}
|
|
145
|
-
const response = await fetchWithTimeout(`${baseUrl}/sessions`, {
|
|
146
|
-
method: 'POST',
|
|
147
|
-
headers,
|
|
148
|
-
body: JSON.stringify({
|
|
149
|
-
humanize: options.humanize,
|
|
150
|
-
humanizePersonaId: options.humanizePersonaId,
|
|
151
|
-
proxy: options.proxy,
|
|
152
|
-
storage: options.storage,
|
|
153
|
-
solveCaptchas: options.solveCaptchas,
|
|
154
|
-
vault: options.vault,
|
|
155
|
-
}),
|
|
156
|
-
});
|
|
157
|
-
if (!response.ok) {
|
|
158
|
-
const text = await response.text();
|
|
159
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
160
|
-
const err = httpStatusToError(response.status, text, `Failed to start session: ${text}`);
|
|
161
|
-
telemetry.captureError(err, {
|
|
162
|
-
endpoint: `${baseUrl}/sessions`,
|
|
163
|
-
method: 'POST',
|
|
164
|
-
statusCode: response.status,
|
|
165
|
-
errorCode: err.code,
|
|
166
|
-
requestId,
|
|
167
|
-
});
|
|
168
|
-
throw err;
|
|
169
|
-
}
|
|
170
|
-
const data = await parseJsonResponse(response, 'Start session');
|
|
171
|
-
return {
|
|
172
|
-
id: data.id,
|
|
173
|
-
status: data.status,
|
|
174
|
-
storageWorkspace: data.storageWorkspace,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Connect a driver to an existing started session on the control-plane.
|
|
179
|
-
*/
|
|
180
|
-
export async function connectSessionDriver(baseUrl, sessionId, driver, apiKey) {
|
|
181
|
-
const headers = {
|
|
182
|
-
'Content-Type': 'application/json',
|
|
183
|
-
'x-sdk-version': SDK_VERSION,
|
|
184
|
-
};
|
|
185
|
-
if (apiKey) {
|
|
186
|
-
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
187
|
-
}
|
|
188
|
-
const response = await fetchWithTimeout(`${baseUrl}/sessions/${sessionId}/connect`, {
|
|
189
|
-
method: 'POST',
|
|
190
|
-
headers,
|
|
191
|
-
body: JSON.stringify({ driver }),
|
|
192
|
-
});
|
|
193
|
-
if (!response.ok) {
|
|
194
|
-
const text = await response.text();
|
|
195
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
196
|
-
const err = httpStatusToError(response.status, text, `Failed to connect session driver: ${text}`);
|
|
197
|
-
telemetry.captureError(err, {
|
|
198
|
-
endpoint: `${baseUrl}/sessions/${sessionId}/connect`,
|
|
199
|
-
method: 'POST',
|
|
200
|
-
statusCode: response.status,
|
|
201
|
-
errorCode: err.code,
|
|
202
|
-
requestId,
|
|
203
|
-
});
|
|
204
|
-
throw err;
|
|
205
|
-
}
|
|
206
|
-
return parseJsonResponse(response, 'Connect session driver');
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Stop a session on the control-plane
|
|
210
|
-
* @param baseUrl - Versioned API base URL of the control-plane
|
|
211
|
-
* @param sessionId - Session ID to stop
|
|
212
|
-
* @param apiKey - Optional API key
|
|
213
|
-
*/
|
|
214
|
-
export async function stopSession(baseUrl, sessionId, apiKey) {
|
|
215
|
-
const headers = {
|
|
216
|
-
'Content-Type': 'application/json',
|
|
217
|
-
'x-sdk-version': SDK_VERSION,
|
|
218
|
-
};
|
|
219
|
-
if (apiKey) {
|
|
220
|
-
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
221
|
-
}
|
|
222
|
-
const response = await fetchWithTimeout(`${baseUrl}/sessions/${sessionId}/stop`, {
|
|
223
|
-
method: 'POST',
|
|
224
|
-
headers,
|
|
225
|
-
body: JSON.stringify({}),
|
|
226
|
-
});
|
|
227
|
-
if (!response.ok) {
|
|
228
|
-
const text = await response.text();
|
|
229
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
230
|
-
const err = httpStatusToError(response.status, text, `Failed to stop session: ${text}`);
|
|
231
|
-
telemetry.captureError(err, {
|
|
232
|
-
endpoint: `${baseUrl}/sessions/${sessionId}/stop`,
|
|
233
|
-
method: 'POST',
|
|
234
|
-
statusCode: response.status,
|
|
235
|
-
errorCode: err.code,
|
|
236
|
-
requestId,
|
|
237
|
-
});
|
|
238
|
-
throw err;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
async function sendCommandInternal(baseUrl, sessionId, command, apiKey, timeout) {
|
|
242
|
-
const executeTimeoutMs = command.type === 'EXECUTE' &&
|
|
243
|
-
typeof command.options?.timeoutMs === 'number' &&
|
|
244
|
-
Number.isFinite(command.options.timeoutMs) &&
|
|
245
|
-
command.options.timeoutMs > 0
|
|
246
|
-
? Math.floor(command.options.timeoutMs)
|
|
247
|
-
: undefined;
|
|
248
|
-
const rpcOptionsTimeoutMs = command.type === 'RPC'
|
|
249
|
-
? getRpcOptionsTimeoutMs(command.args)
|
|
250
|
-
: undefined;
|
|
251
|
-
const rpcTimeoutHint = command.type === 'RPC'
|
|
252
|
-
? rpcOptionsTimeoutMs !== undefined
|
|
253
|
-
? Math.max(DEFAULT_TIMEOUT_MS, rpcOptionsTimeoutMs + 5000)
|
|
254
|
-
: isLongRunningRpcMethod(command.method)
|
|
255
|
-
? LONG_TIMEOUT_MS
|
|
256
|
-
: undefined
|
|
257
|
-
: undefined;
|
|
258
|
-
const aiRpcTimeoutHint = command.type === 'RPC' &&
|
|
259
|
-
'target' in command &&
|
|
260
|
-
(command.target === 'stagehand' || command.target === 'browserUse') &&
|
|
261
|
-
rpcOptionsTimeoutMs !== undefined
|
|
262
|
-
? Math.max(isLongRunningAgentRpc(command.target, command.method) ? AGENT_RPC_TIMEOUT_MS : LONG_TIMEOUT_MS, rpcOptionsTimeoutMs + 5000)
|
|
263
|
-
: undefined;
|
|
264
|
-
// Use longer timeout for potentially slow AI operations (stagehand, browserUse, execute)
|
|
265
|
-
const defaultTimeout = command.type === 'EXECUTE' ||
|
|
266
|
-
('target' in command && (command.target === 'stagehand' || command.target === 'browserUse'))
|
|
267
|
-
? command.type === 'EXECUTE' && executeTimeoutMs !== undefined
|
|
268
|
-
? Math.max(LONG_TIMEOUT_MS, executeTimeoutMs + 5000)
|
|
269
|
-
: (aiRpcTimeoutHint ??
|
|
270
|
-
('target' in command && isLongRunningAgentRpc(command.target, command.method)
|
|
271
|
-
? AGENT_RPC_TIMEOUT_MS
|
|
272
|
-
: LONG_TIMEOUT_MS))
|
|
273
|
-
: (rpcTimeoutHint ?? DEFAULT_TIMEOUT_MS);
|
|
274
|
-
let call;
|
|
275
|
-
let ref;
|
|
276
|
-
let args;
|
|
277
|
-
let options;
|
|
278
|
-
if (command.type === 'RPC') {
|
|
279
|
-
call = `${command.target}.${command.method}`;
|
|
280
|
-
args = trimTrailingUndefined(command.args);
|
|
281
|
-
if (HANDLE_TARGETS.has(command.target)) {
|
|
282
|
-
ref = command.handleId;
|
|
283
|
-
}
|
|
284
|
-
else if (CONTEXT_REF_TARGETS.has(command.target)) {
|
|
285
|
-
ref = command.contextId;
|
|
286
|
-
}
|
|
287
|
-
else if (PAGE_REF_TARGETS.has(command.target)) {
|
|
288
|
-
ref = command.pageId;
|
|
289
|
-
}
|
|
290
|
-
if (rpcOptionsTimeoutMs !== undefined) {
|
|
291
|
-
options = { timeoutMs: rpcOptionsTimeoutMs };
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
call = 'execute';
|
|
296
|
-
args = [command.code];
|
|
297
|
-
if (command.args !== undefined) {
|
|
298
|
-
args.push(command.args);
|
|
299
|
-
}
|
|
300
|
-
ref = command.pageId;
|
|
301
|
-
options = command.options;
|
|
302
|
-
}
|
|
303
|
-
const endpoint = `${baseUrl}/sessions/${encodeURIComponent(sessionId)}/automation`;
|
|
304
|
-
const response = await fetchWithTimeout(endpoint, {
|
|
305
|
-
method: 'POST',
|
|
306
|
-
headers: {
|
|
307
|
-
'Content-Type': 'application/json',
|
|
308
|
-
'x-sdk-version': SDK_VERSION,
|
|
309
|
-
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
310
|
-
},
|
|
311
|
-
body: JSON.stringify({
|
|
312
|
-
call,
|
|
313
|
-
...(ref ? { ref } : {}),
|
|
314
|
-
...(args ? { args } : {}),
|
|
315
|
-
...(options ? { options } : {}),
|
|
316
|
-
}),
|
|
317
|
-
}, timeout ?? defaultTimeout);
|
|
318
|
-
const requestId = response.headers.get('x-request-id') ?? undefined;
|
|
319
|
-
if (!response.ok) {
|
|
320
|
-
const text = await response.text();
|
|
321
|
-
const parsed = parseAutomationEnvelope(text);
|
|
322
|
-
const err = parsed && parsed.ok === false
|
|
323
|
-
? buildAutomationError(parsed.error, text || `Automation ${call} failed`)
|
|
324
|
-
: httpStatusToError(response.status, text);
|
|
325
|
-
const telemetryErrorCode = parsed?.error?.code ||
|
|
326
|
-
err.code;
|
|
327
|
-
telemetry.captureError(err, {
|
|
328
|
-
endpoint,
|
|
329
|
-
method: 'POST',
|
|
330
|
-
statusCode: response.status,
|
|
331
|
-
errorCode: telemetryErrorCode,
|
|
332
|
-
commandType: command.type,
|
|
333
|
-
requestId,
|
|
334
|
-
});
|
|
335
|
-
throw err;
|
|
336
|
-
}
|
|
337
|
-
const data = await parseJsonResponse(response, `Automation ${call}`);
|
|
338
|
-
if (data.ok !== true) {
|
|
339
|
-
const err = buildAutomationError(data.error, 'Unknown error');
|
|
340
|
-
telemetry.captureError(err, {
|
|
341
|
-
endpoint,
|
|
342
|
-
method: 'POST',
|
|
343
|
-
statusCode: response.status,
|
|
344
|
-
errorCode: data.error?.code,
|
|
345
|
-
commandType: command.type,
|
|
346
|
-
requestId,
|
|
347
|
-
});
|
|
348
|
-
throw err;
|
|
349
|
-
}
|
|
350
|
-
return data.result;
|
|
351
|
-
}
|
|
352
|
-
export async function sendCommand(baseUrl, sessionId, command, apiKey, timeout) {
|
|
353
|
-
return sendCommandInternal(baseUrl, sessionId, command, apiKey, timeout);
|
|
354
|
-
}
|