@bctrl/sdk 1.0.2 → 1.0.4
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 +13 -11
- package/dist/bctrl.d.ts +15 -15
- package/dist/bctrl.js +14 -14
- package/dist/errors.d.ts +14 -14
- package/dist/errors.js +1 -1
- package/dist/files.d.ts +21 -21
- package/dist/files.js +14 -14
- package/dist/http.d.ts +6 -6
- package/dist/http.js +17 -17
- package/dist/index.d.ts +7 -7
- package/dist/index.js +6 -7
- package/dist/invocations.d.ts +78 -16
- package/dist/invocations.js +99 -6
- package/dist/pagination.d.ts +2 -2
- package/dist/pagination.js +1 -1
- package/dist/runs.d.ts +29 -27
- package/dist/runs.js +20 -14
- package/dist/runtimes.d.ts +37 -61
- package/dist/runtimes.js +27 -76
- package/dist/spaces.d.ts +29 -30
- package/dist/spaces.js +22 -22
- package/dist/types.d.ts +124 -118
- package/package.json +4 -4
- package/dist/browsers.d.ts +0 -24
- package/dist/browsers.js +0 -82
package/dist/invocations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class V1InvocationResource {
|
|
2
2
|
http;
|
|
3
3
|
data;
|
|
4
4
|
constructor(http, data) {
|
|
@@ -27,14 +27,14 @@ export class V2InvocationResource {
|
|
|
27
27
|
.then((response) => response.data);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
export class
|
|
30
|
+
export class V1InvocationsClient {
|
|
31
31
|
http;
|
|
32
32
|
constructor(http) {
|
|
33
33
|
this.http = http;
|
|
34
34
|
}
|
|
35
35
|
async get(id) {
|
|
36
36
|
const response = await this.http.request(`/invocations/${encodeURIComponent(id)}`);
|
|
37
|
-
return new
|
|
37
|
+
return new V1InvocationResource(this.http, response.data);
|
|
38
38
|
}
|
|
39
39
|
wait(id, request) {
|
|
40
40
|
return this.http.request(`/invocations/${encodeURIComponent(id)}/wait`, {
|
|
@@ -46,21 +46,114 @@ export class V2InvocationsClient {
|
|
|
46
46
|
const response = await this.http.request(`/invocations/${encodeURIComponent(id)}/cancel`, {
|
|
47
47
|
method: 'POST',
|
|
48
48
|
});
|
|
49
|
-
return new
|
|
49
|
+
return new V1InvocationResource(this.http, response.data);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
export class
|
|
52
|
+
export class V1RuntimeInvocationsClient {
|
|
53
53
|
http;
|
|
54
54
|
runtimeId;
|
|
55
|
+
stagehand;
|
|
56
|
+
browserUse;
|
|
55
57
|
constructor(http, runtimeId) {
|
|
56
58
|
this.http = http;
|
|
57
59
|
this.runtimeId = runtimeId;
|
|
60
|
+
this.stagehand = new V1RuntimeStagehandInvocationsClient(this);
|
|
61
|
+
this.browserUse = new V1RuntimeBrowserUseInvocationsClient(this);
|
|
58
62
|
}
|
|
59
63
|
async create(request) {
|
|
60
64
|
const response = await this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/invocations`, {
|
|
61
65
|
method: 'POST',
|
|
62
66
|
body: request,
|
|
63
67
|
});
|
|
64
|
-
return new
|
|
68
|
+
return new V1InvocationResource(this.http, response.data);
|
|
65
69
|
}
|
|
66
70
|
}
|
|
71
|
+
export class V1RuntimeStagehandInvocationsClient {
|
|
72
|
+
invocations;
|
|
73
|
+
constructor(invocations) {
|
|
74
|
+
this.invocations = invocations;
|
|
75
|
+
}
|
|
76
|
+
act(options) {
|
|
77
|
+
const { instruction, timeoutMs, ...common } = options;
|
|
78
|
+
return this.invocations.create({
|
|
79
|
+
provider: 'stagehand',
|
|
80
|
+
method: 'act',
|
|
81
|
+
...common,
|
|
82
|
+
input: {
|
|
83
|
+
instruction,
|
|
84
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
observe(options) {
|
|
89
|
+
const { instruction, selector, timeoutMs, ...common } = options;
|
|
90
|
+
return this.invocations.create({
|
|
91
|
+
provider: 'stagehand',
|
|
92
|
+
method: 'observe',
|
|
93
|
+
...common,
|
|
94
|
+
input: {
|
|
95
|
+
instruction,
|
|
96
|
+
...(selector !== undefined ? { selector } : {}),
|
|
97
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
extract(options) {
|
|
102
|
+
const { instruction, schema, ...common } = options;
|
|
103
|
+
return this.invocations.create({
|
|
104
|
+
provider: 'stagehand',
|
|
105
|
+
method: 'extract',
|
|
106
|
+
...common,
|
|
107
|
+
input: { instruction },
|
|
108
|
+
...(schema !== undefined ? { outputSchema: toJsonSchemaObject(schema) } : {}),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
agent(options) {
|
|
112
|
+
const { instruction, maxSteps, timeoutMs, variables, config, options: agentOptions, ...common } = options;
|
|
113
|
+
return this.invocations.create({
|
|
114
|
+
provider: 'stagehand',
|
|
115
|
+
method: 'agent',
|
|
116
|
+
...common,
|
|
117
|
+
input: {
|
|
118
|
+
instruction,
|
|
119
|
+
...(maxSteps !== undefined ? { maxSteps } : {}),
|
|
120
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
121
|
+
...(variables !== undefined ? { variables } : {}),
|
|
122
|
+
},
|
|
123
|
+
...(config !== undefined ? { config } : {}),
|
|
124
|
+
...(agentOptions !== undefined ? { options: agentOptions } : {}),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export class V1RuntimeBrowserUseInvocationsClient {
|
|
129
|
+
invocations;
|
|
130
|
+
constructor(invocations) {
|
|
131
|
+
this.invocations = invocations;
|
|
132
|
+
}
|
|
133
|
+
agent(options) {
|
|
134
|
+
const { instruction, maxSteps, config, options: agentOptions, ...common } = options;
|
|
135
|
+
return this.invocations.create({
|
|
136
|
+
provider: 'browserUse',
|
|
137
|
+
method: 'agent',
|
|
138
|
+
...common,
|
|
139
|
+
input: {
|
|
140
|
+
instruction,
|
|
141
|
+
...(maxSteps !== undefined ? { maxSteps } : {}),
|
|
142
|
+
},
|
|
143
|
+
...(config !== undefined ? { config } : {}),
|
|
144
|
+
...(agentOptions !== undefined ? { options: agentOptions } : {}),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function toJsonSchemaObject(schema) {
|
|
149
|
+
const value = typeof schema.toJSONSchema === 'function' ? schema.toJSONSchema() : schema;
|
|
150
|
+
if (!isJsonObject(value)) {
|
|
151
|
+
throw new TypeError('Stagehand extract schema must resolve to a JSON object');
|
|
152
|
+
}
|
|
153
|
+
const { $schema, ...jsonSchema } = value;
|
|
154
|
+
void $schema;
|
|
155
|
+
return jsonSchema;
|
|
156
|
+
}
|
|
157
|
+
function isJsonObject(value) {
|
|
158
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
159
|
+
}
|
package/dist/pagination.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function
|
|
1
|
+
import type { V1ListEnvelope, V1PageQuery } from './types.js';
|
|
2
|
+
export declare function iterateV1Pages<T, Q extends V1PageQuery>(initialQuery: Q, fetchPage: (query: Q) => Promise<V1ListEnvelope<T>>): AsyncGenerator<T, void, undefined>;
|
package/dist/pagination.js
CHANGED
package/dist/runs.d.ts
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
export declare class
|
|
1
|
+
import type { V1HttpClient } from './http.js';
|
|
2
|
+
import { V1RunFilesClient } from './files.js';
|
|
3
|
+
import type { V1ListEnvelope, V1Run, V1RunCommand, V1RunCommandsListQuery, V1RunEvent, V1RunEventsListQuery, V1RunEventsWaitRequest, V1RunEventsWaitResponse, V1RunListQuery, V1RunLiveRequest, V1RunLiveResponse, V1RunRecordingRequest, V1RunRecordingResponse, V1RuntimeStartRun, V1RunUsage } from './types.js';
|
|
4
|
+
export declare class V1RunEventsClient {
|
|
5
5
|
private readonly http;
|
|
6
6
|
private readonly runId;
|
|
7
|
-
constructor(http:
|
|
8
|
-
list(query?:
|
|
9
|
-
iter(query?:
|
|
10
|
-
wait(request?:
|
|
11
|
-
streamUrl(query?: Pick<
|
|
7
|
+
constructor(http: V1HttpClient, runId: string);
|
|
8
|
+
list(query?: V1RunEventsListQuery): Promise<V1ListEnvelope<V1RunEvent>>;
|
|
9
|
+
iter(query?: V1RunEventsListQuery): AsyncGenerator<V1RunEvent, void, undefined>;
|
|
10
|
+
wait(request?: V1RunEventsWaitRequest): Promise<V1RunEventsWaitResponse>;
|
|
11
|
+
streamUrl(query?: Pick<V1RunEventsListQuery, 'type' | 'category' | 'connectionId'>): string;
|
|
12
12
|
}
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class V1RunCommandsClient {
|
|
14
14
|
private readonly http;
|
|
15
15
|
private readonly runId;
|
|
16
|
-
constructor(http:
|
|
17
|
-
list(query?:
|
|
18
|
-
iter(query?:
|
|
16
|
+
constructor(http: V1HttpClient, runId: string);
|
|
17
|
+
list(query?: V1RunCommandsListQuery): Promise<V1ListEnvelope<V1RunCommand>>;
|
|
18
|
+
iter(query?: V1RunCommandsListQuery): AsyncGenerator<V1RunCommand, void, undefined>;
|
|
19
19
|
}
|
|
20
|
-
export declare class
|
|
20
|
+
export declare class V1RunResource {
|
|
21
21
|
private readonly http;
|
|
22
|
-
readonly data:
|
|
23
|
-
readonly events:
|
|
24
|
-
readonly commands:
|
|
25
|
-
readonly files:
|
|
26
|
-
constructor(http:
|
|
22
|
+
readonly data: V1Run | V1RuntimeStartRun;
|
|
23
|
+
readonly events: V1RunEventsClient;
|
|
24
|
+
readonly commands: V1RunCommandsClient;
|
|
25
|
+
readonly files: V1RunFilesClient;
|
|
26
|
+
constructor(http: V1HttpClient, data: V1Run | V1RuntimeStartRun);
|
|
27
27
|
get id(): string;
|
|
28
|
-
refresh(): Promise<
|
|
29
|
-
live(request?:
|
|
30
|
-
recording(request?:
|
|
28
|
+
refresh(): Promise<V1RunResource>;
|
|
29
|
+
live(request?: V1RunLiveRequest): Promise<V1RunLiveResponse>;
|
|
30
|
+
recording(request?: V1RunRecordingRequest): Promise<V1RunRecordingResponse>;
|
|
31
|
+
usage(): Promise<V1RunUsage>;
|
|
31
32
|
}
|
|
32
|
-
export declare class
|
|
33
|
+
export declare class V1RunsClient {
|
|
33
34
|
private readonly http;
|
|
34
|
-
constructor(http:
|
|
35
|
-
list(query?:
|
|
36
|
-
iter(query?:
|
|
37
|
-
get(id: string): Promise<
|
|
35
|
+
constructor(http: V1HttpClient);
|
|
36
|
+
list(query?: V1RunListQuery): Promise<V1ListEnvelope<V1Run>>;
|
|
37
|
+
iter(query?: V1RunListQuery): AsyncGenerator<V1Run, void, undefined>;
|
|
38
|
+
get(id: string): Promise<V1RunResource>;
|
|
39
|
+
usage(id: string): Promise<V1RunUsage>;
|
|
38
40
|
}
|
package/dist/runs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export class
|
|
1
|
+
import { iterateV1Pages } from './pagination.js';
|
|
2
|
+
import { V1RunFilesClient } from './files.js';
|
|
3
|
+
export class V1RunEventsClient {
|
|
4
4
|
http;
|
|
5
5
|
runId;
|
|
6
6
|
constructor(http, runId) {
|
|
@@ -11,7 +11,7 @@ export class V2RunEventsClient {
|
|
|
11
11
|
return this.http.request(`/runs/${encodeURIComponent(this.runId)}/events`, { query });
|
|
12
12
|
}
|
|
13
13
|
iter(query = {}) {
|
|
14
|
-
return
|
|
14
|
+
return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
|
|
15
15
|
}
|
|
16
16
|
wait(request) {
|
|
17
17
|
return this.http.request(`/runs/${encodeURIComponent(this.runId)}/events/wait`, {
|
|
@@ -35,7 +35,7 @@ export class V2RunEventsClient {
|
|
|
35
35
|
return url.toString();
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
export class
|
|
38
|
+
export class V1RunCommandsClient {
|
|
39
39
|
http;
|
|
40
40
|
runId;
|
|
41
41
|
constructor(http, runId) {
|
|
@@ -46,10 +46,10 @@ export class V2RunCommandsClient {
|
|
|
46
46
|
return this.http.request(`/runs/${encodeURIComponent(this.runId)}/commands`, { query });
|
|
47
47
|
}
|
|
48
48
|
iter(query = {}) {
|
|
49
|
-
return
|
|
49
|
+
return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
export class
|
|
52
|
+
export class V1RunResource {
|
|
53
53
|
http;
|
|
54
54
|
data;
|
|
55
55
|
events;
|
|
@@ -58,15 +58,15 @@ export class V2RunResource {
|
|
|
58
58
|
constructor(http, data) {
|
|
59
59
|
this.http = http;
|
|
60
60
|
this.data = data;
|
|
61
|
-
this.events = new
|
|
62
|
-
this.commands = new
|
|
63
|
-
this.files = new
|
|
61
|
+
this.events = new V1RunEventsClient(http, data.id);
|
|
62
|
+
this.commands = new V1RunCommandsClient(http, data.id);
|
|
63
|
+
this.files = new V1RunFilesClient(http, data.id);
|
|
64
64
|
}
|
|
65
65
|
get id() {
|
|
66
66
|
return this.data.id;
|
|
67
67
|
}
|
|
68
68
|
refresh() {
|
|
69
|
-
return new
|
|
69
|
+
return new V1RunsClient(this.http).get(this.id);
|
|
70
70
|
}
|
|
71
71
|
live(request) {
|
|
72
72
|
return this.http.request(`/runs/${encodeURIComponent(this.id)}/live`, {
|
|
@@ -80,8 +80,11 @@ export class V2RunResource {
|
|
|
80
80
|
body: request ?? {},
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
+
usage() {
|
|
84
|
+
return this.http.request(`/runs/${encodeURIComponent(this.id)}/usage`);
|
|
85
|
+
}
|
|
83
86
|
}
|
|
84
|
-
export class
|
|
87
|
+
export class V1RunsClient {
|
|
85
88
|
http;
|
|
86
89
|
constructor(http) {
|
|
87
90
|
this.http = http;
|
|
@@ -90,10 +93,13 @@ export class V2RunsClient {
|
|
|
90
93
|
return this.http.request('/runs', { query });
|
|
91
94
|
}
|
|
92
95
|
iter(query = {}) {
|
|
93
|
-
return
|
|
96
|
+
return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
|
|
94
97
|
}
|
|
95
98
|
async get(id) {
|
|
96
99
|
const run = await this.http.request(`/runs/${encodeURIComponent(id)}`);
|
|
97
|
-
return new
|
|
100
|
+
return new V1RunResource(this.http, run);
|
|
101
|
+
}
|
|
102
|
+
usage(id) {
|
|
103
|
+
return this.http.request(`/runs/${encodeURIComponent(id)}/usage`);
|
|
98
104
|
}
|
|
99
105
|
}
|
package/dist/runtimes.d.ts
CHANGED
|
@@ -1,73 +1,49 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
export
|
|
1
|
+
import type { V1HttpClient } from './http.js';
|
|
2
|
+
import { V1RuntimeInvocationsClient } from './invocations.js';
|
|
3
|
+
import { V1RunResource } from './runs.js';
|
|
4
|
+
import type { V1ListEnvelope, V1File, V1Runtime, V1RuntimeCreateRequest, V1RuntimeFileCollectRequest, V1RuntimeFileStageRequest, V1RuntimeFileUploadRequest, V1RuntimeFileUploadResponse, V1RuntimeStagedFile, V1RuntimeListQuery, V1RuntimeRunListQuery, V1RuntimeStartBrowser, V1RuntimeStartRuntime, V1RunSummary, V1SpaceRuntimeCreateRequest } from './types.js';
|
|
5
|
+
export type V1RuntimeStartResult = {
|
|
6
|
+
runtime: V1RuntimeResource;
|
|
7
|
+
run: V1RunResource;
|
|
8
|
+
browser: V1RuntimeStartBrowser;
|
|
9
|
+
};
|
|
10
|
+
export declare class V1RuntimeRunsClient {
|
|
6
11
|
private readonly http;
|
|
7
12
|
private readonly runtimeId;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
get endpoint(): V2RuntimeConnectionCreateResponse['endpoint'];
|
|
12
|
-
get wsUrl(): string | undefined;
|
|
13
|
-
close(): Promise<V2RuntimeConnection>;
|
|
14
|
-
}
|
|
15
|
-
export declare class V2RuntimeConnectionsClient {
|
|
16
|
-
private readonly http;
|
|
17
|
-
private readonly runtimeId;
|
|
18
|
-
constructor(http: V2HttpClient, runtimeId: string);
|
|
19
|
-
create(request?: V2RuntimeConnectionCreateOptions): Promise<V2RuntimeConnectionResource>;
|
|
20
|
-
list(query?: {
|
|
21
|
-
status?: string | string[];
|
|
22
|
-
limit?: number;
|
|
23
|
-
}): Promise<V2ListEnvelope<V2RuntimeConnection>>;
|
|
24
|
-
delete(connectionId: string): Promise<V2RuntimeConnection>;
|
|
25
|
-
}
|
|
26
|
-
export declare class V2RuntimeRunsClient {
|
|
27
|
-
private readonly http;
|
|
28
|
-
private readonly runtimeId;
|
|
29
|
-
constructor(http: V2HttpClient, runtimeId: string);
|
|
30
|
-
list(query?: V2RuntimeRunListQuery): Promise<V2ListEnvelope<V2RunSummary>>;
|
|
31
|
-
iter(query?: V2RuntimeRunListQuery): AsyncGenerator<V2RunSummary, void, undefined>;
|
|
13
|
+
constructor(http: V1HttpClient, runtimeId: string);
|
|
14
|
+
list(query?: V1RuntimeRunListQuery): Promise<V1ListEnvelope<V1RunSummary>>;
|
|
15
|
+
iter(query?: V1RuntimeRunListQuery): AsyncGenerator<V1RunSummary, void, undefined>;
|
|
32
16
|
}
|
|
33
|
-
export declare class
|
|
17
|
+
export declare class V1RuntimeFilesClient {
|
|
34
18
|
private readonly http;
|
|
35
19
|
private readonly runtimeId;
|
|
36
|
-
constructor(http:
|
|
37
|
-
upload(request:
|
|
38
|
-
stage(request:
|
|
39
|
-
collect(request:
|
|
20
|
+
constructor(http: V1HttpClient, runtimeId: string);
|
|
21
|
+
upload(request: V1RuntimeFileUploadRequest): Promise<V1RuntimeFileUploadResponse>;
|
|
22
|
+
stage(request: V1RuntimeFileStageRequest): Promise<V1RuntimeStagedFile>;
|
|
23
|
+
collect(request: V1RuntimeFileCollectRequest): Promise<V1File>;
|
|
40
24
|
}
|
|
41
|
-
export declare class
|
|
25
|
+
export declare class V1RuntimeResource {
|
|
42
26
|
private readonly http;
|
|
43
|
-
readonly data:
|
|
44
|
-
readonly
|
|
45
|
-
readonly
|
|
46
|
-
readonly
|
|
47
|
-
|
|
48
|
-
constructor(http: V2HttpClient, data: V2Runtime);
|
|
27
|
+
readonly data: V1Runtime | V1RuntimeStartRuntime;
|
|
28
|
+
readonly files: V1RuntimeFilesClient;
|
|
29
|
+
readonly runs: V1RuntimeRunsClient;
|
|
30
|
+
readonly invocations: V1RuntimeInvocationsClient;
|
|
31
|
+
constructor(http: V1HttpClient, data: V1Runtime | V1RuntimeStartRuntime);
|
|
49
32
|
get id(): string;
|
|
50
33
|
get activeRunId(): string | null;
|
|
51
|
-
refresh(): Promise<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
run: V2RunResource;
|
|
56
|
-
}>;
|
|
57
|
-
stop(): Promise<V2Runtime>;
|
|
58
|
-
run(): Promise<V2RunResource>;
|
|
34
|
+
refresh(): Promise<V1RuntimeResource>;
|
|
35
|
+
start(): Promise<V1RuntimeStartResult>;
|
|
36
|
+
stop(): Promise<V1Runtime>;
|
|
37
|
+
run(): Promise<V1RunResource>;
|
|
59
38
|
}
|
|
60
|
-
export declare class
|
|
39
|
+
export declare class V1RuntimesClient {
|
|
61
40
|
private readonly http;
|
|
62
|
-
constructor(http:
|
|
63
|
-
list(query?:
|
|
64
|
-
iter(query?:
|
|
65
|
-
create(request:
|
|
66
|
-
createInSpace(spaceId: string, request:
|
|
67
|
-
get(id: string): Promise<
|
|
68
|
-
stop(id: string): Promise<
|
|
69
|
-
start(id: string): Promise<
|
|
70
|
-
runtime: V2RuntimeResource;
|
|
71
|
-
run: V2RunResource;
|
|
72
|
-
}>;
|
|
41
|
+
constructor(http: V1HttpClient);
|
|
42
|
+
list(query?: V1RuntimeListQuery): Promise<V1ListEnvelope<V1Runtime>>;
|
|
43
|
+
iter(query?: V1RuntimeListQuery): AsyncGenerator<V1Runtime, void, undefined>;
|
|
44
|
+
create(request: V1RuntimeCreateRequest): Promise<V1RuntimeResource>;
|
|
45
|
+
createInSpace(spaceId: string, request: V1SpaceRuntimeCreateRequest): Promise<V1RuntimeResource>;
|
|
46
|
+
get(id: string): Promise<V1RuntimeResource>;
|
|
47
|
+
stop(id: string): Promise<V1Runtime>;
|
|
48
|
+
start(id: string): Promise<V1RuntimeStartResult>;
|
|
73
49
|
}
|
package/dist/runtimes.js
CHANGED
|
@@ -1,54 +1,8 @@
|
|
|
1
1
|
import { BctrlValidationError } from './errors.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export class
|
|
6
|
-
http;
|
|
7
|
-
runtimeId;
|
|
8
|
-
data;
|
|
9
|
-
constructor(http, runtimeId, data) {
|
|
10
|
-
this.http = http;
|
|
11
|
-
this.runtimeId = runtimeId;
|
|
12
|
-
this.data = data;
|
|
13
|
-
}
|
|
14
|
-
get id() {
|
|
15
|
-
return this.data.id;
|
|
16
|
-
}
|
|
17
|
-
get endpoint() {
|
|
18
|
-
return this.data.endpoint;
|
|
19
|
-
}
|
|
20
|
-
get wsUrl() {
|
|
21
|
-
return this.data.endpoint.type === 'websocket' ? this.data.endpoint.url : undefined;
|
|
22
|
-
}
|
|
23
|
-
close() {
|
|
24
|
-
return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/connections/${encodeURIComponent(this.id)}`, { method: 'DELETE' });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export class V2RuntimeConnectionsClient {
|
|
28
|
-
http;
|
|
29
|
-
runtimeId;
|
|
30
|
-
constructor(http, runtimeId) {
|
|
31
|
-
this.http = http;
|
|
32
|
-
this.runtimeId = runtimeId;
|
|
33
|
-
}
|
|
34
|
-
async create(request = {}) {
|
|
35
|
-
const response = await this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/connections`, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
body: {
|
|
38
|
-
protocol: request.protocol ?? 'cdp',
|
|
39
|
-
...request,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
return new V2RuntimeConnectionResource(this.http, this.runtimeId, response);
|
|
43
|
-
}
|
|
44
|
-
list(query = {}) {
|
|
45
|
-
return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/connections`, { query });
|
|
46
|
-
}
|
|
47
|
-
delete(connectionId) {
|
|
48
|
-
return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/connections/${encodeURIComponent(connectionId)}`, { method: 'DELETE' });
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class V2RuntimeRunsClient {
|
|
2
|
+
import { V1RuntimeInvocationsClient } from './invocations.js';
|
|
3
|
+
import { iterateV1Pages } from './pagination.js';
|
|
4
|
+
import { V1RunResource } from './runs.js';
|
|
5
|
+
export class V1RuntimeRunsClient {
|
|
52
6
|
http;
|
|
53
7
|
runtimeId;
|
|
54
8
|
constructor(http, runtimeId) {
|
|
@@ -59,10 +13,10 @@ export class V2RuntimeRunsClient {
|
|
|
59
13
|
return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/runs`, { query });
|
|
60
14
|
}
|
|
61
15
|
iter(query = {}) {
|
|
62
|
-
return
|
|
16
|
+
return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
|
|
63
17
|
}
|
|
64
18
|
}
|
|
65
|
-
export class
|
|
19
|
+
export class V1RuntimeFilesClient {
|
|
66
20
|
http;
|
|
67
21
|
runtimeId;
|
|
68
22
|
constructor(http, runtimeId) {
|
|
@@ -100,38 +54,34 @@ export class V2RuntimeFilesClient {
|
|
|
100
54
|
});
|
|
101
55
|
}
|
|
102
56
|
}
|
|
103
|
-
export class
|
|
57
|
+
export class V1RuntimeResource {
|
|
104
58
|
http;
|
|
105
59
|
data;
|
|
106
|
-
connections;
|
|
107
60
|
files;
|
|
108
61
|
runs;
|
|
109
62
|
invocations;
|
|
110
63
|
constructor(http, data) {
|
|
111
64
|
this.http = http;
|
|
112
65
|
this.data = data;
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
this.invocations = new V2RuntimeInvocationsClient(http, data.id);
|
|
66
|
+
this.files = new V1RuntimeFilesClient(http, data.id);
|
|
67
|
+
this.runs = new V1RuntimeRunsClient(http, data.id);
|
|
68
|
+
this.invocations = new V1RuntimeInvocationsClient(http, data.id);
|
|
117
69
|
}
|
|
118
70
|
get id() {
|
|
119
71
|
return this.data.id;
|
|
120
72
|
}
|
|
121
73
|
get activeRunId() {
|
|
122
|
-
return this.data.activeRunId;
|
|
74
|
+
return 'activeRunId' in this.data ? this.data.activeRunId : null;
|
|
123
75
|
}
|
|
124
76
|
refresh() {
|
|
125
|
-
return new
|
|
126
|
-
}
|
|
127
|
-
async connect(request) {
|
|
128
|
-
return this.connections.create(request);
|
|
77
|
+
return new V1RuntimesClient(this.http).get(this.id);
|
|
129
78
|
}
|
|
130
79
|
async start() {
|
|
131
80
|
const response = await this.http.request(`/runtimes/${encodeURIComponent(this.id)}/start`, { method: 'POST' });
|
|
132
81
|
return {
|
|
133
|
-
runtime: new
|
|
134
|
-
run: new
|
|
82
|
+
runtime: new V1RuntimeResource(this.http, response.runtime),
|
|
83
|
+
run: new V1RunResource(this.http, response.run),
|
|
84
|
+
browser: response.browser,
|
|
135
85
|
};
|
|
136
86
|
}
|
|
137
87
|
stop() {
|
|
@@ -141,28 +91,29 @@ export class V2RuntimeResource {
|
|
|
141
91
|
}
|
|
142
92
|
async run() {
|
|
143
93
|
const runtime = await this.refresh();
|
|
144
|
-
|
|
94
|
+
const activeRunId = runtime.activeRunId;
|
|
95
|
+
if (!activeRunId) {
|
|
145
96
|
throw new BctrlValidationError('Runtime does not have an active run yet', 'runtime.no_active_run', {
|
|
146
97
|
runtimeId: this.id,
|
|
147
98
|
});
|
|
148
99
|
}
|
|
149
|
-
const run = await this.http.request(`/runs/${encodeURIComponent(
|
|
150
|
-
return new
|
|
100
|
+
const run = await this.http.request(`/runs/${encodeURIComponent(activeRunId)}`);
|
|
101
|
+
return new V1RunResource(this.http, run);
|
|
151
102
|
}
|
|
152
103
|
}
|
|
153
104
|
function validateRuntimeCreateRequest(request) {
|
|
154
|
-
const profileBacked = request.config?.
|
|
105
|
+
const profileBacked = request.config?.profile === true;
|
|
155
106
|
if (!profileBacked)
|
|
156
107
|
return;
|
|
157
108
|
if (!request.name?.trim()) {
|
|
158
|
-
throw new BctrlValidationError('name is required when config.
|
|
109
|
+
throw new BctrlValidationError('name is required when config.profile is true', 'runtime.profile_name_required');
|
|
159
110
|
}
|
|
160
111
|
const unsupported = ['stealth', 'proxy', 'fingerprint', 'extensions'].filter((key) => request.config?.[key] !== undefined);
|
|
161
112
|
if (unsupported.length > 0) {
|
|
162
|
-
throw new BctrlValidationError('Only config.
|
|
113
|
+
throw new BctrlValidationError('Only config.profile, config.idleTimeoutMinutes, config.webRtcProxyOnly, and config.forceOpenShadowRoots are supported for profile-backed browser runtimes', 'runtime.profile_config_unsupported', { unsupported });
|
|
163
114
|
}
|
|
164
115
|
}
|
|
165
|
-
export class
|
|
116
|
+
export class V1RuntimesClient {
|
|
166
117
|
http;
|
|
167
118
|
constructor(http) {
|
|
168
119
|
this.http = http;
|
|
@@ -171,7 +122,7 @@ export class V2RuntimesClient {
|
|
|
171
122
|
return this.http.request('/runtimes', { query });
|
|
172
123
|
}
|
|
173
124
|
iter(query = {}) {
|
|
174
|
-
return
|
|
125
|
+
return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
|
|
175
126
|
}
|
|
176
127
|
async create(request) {
|
|
177
128
|
validateRuntimeCreateRequest(request);
|
|
@@ -179,7 +130,7 @@ export class V2RuntimesClient {
|
|
|
179
130
|
method: 'POST',
|
|
180
131
|
body: request,
|
|
181
132
|
});
|
|
182
|
-
return new
|
|
133
|
+
return new V1RuntimeResource(this.http, runtime);
|
|
183
134
|
}
|
|
184
135
|
async createInSpace(spaceId, request) {
|
|
185
136
|
validateRuntimeCreateRequest(request);
|
|
@@ -187,11 +138,11 @@ export class V2RuntimesClient {
|
|
|
187
138
|
method: 'POST',
|
|
188
139
|
body: { ...request, spaceId },
|
|
189
140
|
});
|
|
190
|
-
return new
|
|
141
|
+
return new V1RuntimeResource(this.http, runtime);
|
|
191
142
|
}
|
|
192
143
|
async get(id) {
|
|
193
144
|
const runtime = await this.http.request(`/runtimes/${encodeURIComponent(id)}`);
|
|
194
|
-
return new
|
|
145
|
+
return new V1RuntimeResource(this.http, runtime);
|
|
195
146
|
}
|
|
196
147
|
stop(id) {
|
|
197
148
|
return this.http.request(`/runtimes/${encodeURIComponent(id)}/stop`, {
|