@bctrl/sdk 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +5 -8
  2. package/dist/account.d.ts +43 -0
  3. package/dist/account.js +100 -0
  4. package/dist/accountTypes.d.ts +126 -0
  5. package/dist/accountTypes.js +1 -0
  6. package/dist/aiProviderTypes.d.ts +58 -0
  7. package/dist/aiProviderTypes.js +1 -0
  8. package/dist/aiProviders.d.ts +13 -0
  9. package/dist/aiProviders.js +36 -0
  10. package/dist/bctrl.d.ts +35 -3
  11. package/dist/bctrl.js +74 -6
  12. package/dist/browserExtensionTypes.d.ts +45 -0
  13. package/dist/browserExtensionTypes.js +1 -0
  14. package/dist/browserExtensions.d.ts +14 -0
  15. package/dist/browserExtensions.js +53 -0
  16. package/dist/files.d.ts +6 -24
  17. package/dist/files.js +9 -56
  18. package/dist/help.d.ts +7 -0
  19. package/dist/help.js +9 -0
  20. package/dist/http.d.ts +12 -1
  21. package/dist/http.js +73 -10
  22. package/dist/index.d.ts +17 -6
  23. package/dist/index.js +15 -5
  24. package/dist/invocations.d.ts +85 -47
  25. package/dist/invocations.js +144 -102
  26. package/dist/node.d.ts +12 -0
  27. package/dist/node.js +11 -0
  28. package/dist/proxies.d.ts +21 -0
  29. package/dist/proxies.js +55 -0
  30. package/dist/proxyTypes.d.ts +114 -0
  31. package/dist/proxyTypes.js +1 -0
  32. package/dist/runs.d.ts +35 -31
  33. package/dist/runs.js +95 -38
  34. package/dist/runtimes.d.ts +26 -62
  35. package/dist/runtimes.js +65 -112
  36. package/dist/schemas.d.ts +7 -0
  37. package/dist/schemas.js +36 -0
  38. package/dist/spaces.d.ts +20 -32
  39. package/dist/spaces.js +48 -36
  40. package/dist/toolCallTypes.d.ts +41 -0
  41. package/dist/toolCallTypes.js +1 -0
  42. package/dist/toolCalls.d.ts +9 -0
  43. package/dist/toolCalls.js +16 -0
  44. package/dist/tools.d.ts +23 -0
  45. package/dist/tools.js +49 -0
  46. package/dist/toolsetTypes.d.ts +32 -0
  47. package/dist/toolsetTypes.js +1 -0
  48. package/dist/toolsets.d.ts +12 -0
  49. package/dist/toolsets.js +31 -0
  50. package/dist/types.d.ts +509 -186
  51. package/dist/utils.d.ts +2 -1
  52. package/dist/utils.js +28 -3
  53. package/dist/vault.d.ts +14 -0
  54. package/dist/vault.js +37 -0
  55. package/dist/vaultTypes.d.ts +73 -0
  56. package/dist/vaultTypes.js +1 -0
  57. package/package.json +8 -1
package/dist/runs.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { v1IdempotencyHeaders } from './http.js';
1
2
  import { iterateV1Pages } from './pagination.js';
2
- import { V1RunFilesClient } from './files.js';
3
- export class V1RunEventsClient {
3
+ class V1RunEventsClient {
4
4
  http;
5
5
  runId;
6
6
  constructor(http, runId) {
@@ -13,12 +13,6 @@ export class V1RunEventsClient {
13
13
  iter(query = {}) {
14
14
  return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
15
15
  }
16
- wait(request) {
17
- return this.http.request(`/runs/${encodeURIComponent(this.runId)}/events/wait`, {
18
- method: 'POST',
19
- body: request ?? {},
20
- });
21
- }
22
16
  streamUrl(query = {}) {
23
17
  const url = new URL(`${this.http.baseUrl}/runs/${encodeURIComponent(this.runId)}/events/stream`);
24
18
  for (const [key, value] of Object.entries(query)) {
@@ -35,7 +29,7 @@ export class V1RunEventsClient {
35
29
  return url.toString();
36
30
  }
37
31
  }
38
- export class V1RunCommandsClient {
32
+ class V1RunActivityClient {
39
33
  http;
40
34
  runId;
41
35
  constructor(http, runId) {
@@ -43,63 +37,126 @@ export class V1RunCommandsClient {
43
37
  this.runId = runId;
44
38
  }
45
39
  list(query = {}) {
46
- return this.http.request(`/runs/${encodeURIComponent(this.runId)}/commands`, { query });
40
+ return this.http.request(`/runs/${encodeURIComponent(this.runId)}/activity`, { query });
47
41
  }
48
42
  iter(query = {}) {
49
43
  return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
50
44
  }
45
+ streamUrl(query = {}) {
46
+ const url = new URL(`${this.http.baseUrl}/runs/${encodeURIComponent(this.runId)}/activity/stream`);
47
+ for (const [key, value] of Object.entries(query)) {
48
+ if (value === undefined)
49
+ continue;
50
+ if (Array.isArray(value)) {
51
+ for (const item of value)
52
+ url.searchParams.append(key, String(item));
53
+ }
54
+ else {
55
+ url.searchParams.set(key, String(value));
56
+ }
57
+ }
58
+ return url.toString();
59
+ }
51
60
  }
52
- export class V1RunResource {
61
+ export class V1RunsClient {
53
62
  http;
54
- data;
55
63
  events;
56
- commands;
64
+ activity;
57
65
  files;
58
- constructor(http, data) {
66
+ invocations;
67
+ constructor(http) {
59
68
  this.http = http;
60
- this.data = data;
61
- this.events = new V1RunEventsClient(http, data.id);
62
- this.commands = new V1RunCommandsClient(http, data.id);
63
- this.files = new V1RunFilesClient(http, data.id);
69
+ this.events = new V1RunEventsNamespaceClient(http);
70
+ this.activity = new V1RunActivityNamespaceClient(http);
71
+ this.files = new V1RunFilesNamespaceClient(http);
72
+ this.invocations = new V1RunInvocationsNamespaceClient(http);
73
+ }
74
+ list(query = {}) {
75
+ return this.http.request('/runs', { query });
76
+ }
77
+ iter(query = {}) {
78
+ return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
64
79
  }
65
- get id() {
66
- return this.data.id;
80
+ get(id) {
81
+ return this.http.request(`/runs/${encodeURIComponent(id)}`);
67
82
  }
68
- refresh() {
69
- return new V1RunsClient(this.http).get(this.id);
83
+ usage(id) {
84
+ return this.http.request(`/runs/${encodeURIComponent(id)}/usage`);
70
85
  }
71
- live(request) {
72
- return this.http.request(`/runs/${encodeURIComponent(this.id)}/live`, {
86
+ live(id, request) {
87
+ return this.http.request(`/runs/${encodeURIComponent(id)}/live`, {
73
88
  method: 'POST',
74
89
  body: request ?? {},
75
90
  });
76
91
  }
77
- recording(request) {
78
- return this.http.request(`/runs/${encodeURIComponent(this.id)}/recording`, {
92
+ recording(id, request) {
93
+ return this.http.request(`/runs/${encodeURIComponent(id)}/recording`, {
79
94
  method: 'POST',
80
95
  body: request ?? {},
81
96
  });
82
97
  }
83
- usage() {
84
- return this.http.request(`/runs/${encodeURIComponent(this.id)}/usage`);
98
+ }
99
+ export class V1RunEventsNamespaceClient {
100
+ http;
101
+ constructor(http) {
102
+ this.http = http;
103
+ }
104
+ list(runId, query = {}) {
105
+ return new V1RunEventsClient(this.http, runId).list(query);
106
+ }
107
+ iter(runId, query = {}) {
108
+ return new V1RunEventsClient(this.http, runId).iter(query);
109
+ }
110
+ streamUrl(runId, query = {}) {
111
+ return new V1RunEventsClient(this.http, runId).streamUrl(query);
85
112
  }
86
113
  }
87
- export class V1RunsClient {
114
+ export class V1RunActivityNamespaceClient {
88
115
  http;
89
116
  constructor(http) {
90
117
  this.http = http;
91
118
  }
92
- list(query = {}) {
93
- return this.http.request('/runs', { query });
119
+ list(runId, query = {}) {
120
+ return new V1RunActivityClient(this.http, runId).list(query);
94
121
  }
95
- iter(query = {}) {
96
- return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
122
+ iter(runId, query = {}) {
123
+ return new V1RunActivityClient(this.http, runId).iter(query);
97
124
  }
98
- async get(id) {
99
- const run = await this.http.request(`/runs/${encodeURIComponent(id)}`);
100
- return new V1RunResource(this.http, run);
125
+ streamUrl(runId, query = {}) {
126
+ return new V1RunActivityClient(this.http, runId).streamUrl(query);
101
127
  }
102
- usage(id) {
103
- return this.http.request(`/runs/${encodeURIComponent(id)}/usage`);
128
+ }
129
+ export class V1RunFilesNamespaceClient {
130
+ http;
131
+ constructor(http) {
132
+ this.http = http;
133
+ }
134
+ list(runId, query = {}) {
135
+ return this.http.request(`/runs/${encodeURIComponent(runId)}/files`, { query });
136
+ }
137
+ iter(runId, query = {}) {
138
+ return iterateV1Pages(query, (pageQuery) => this.list(runId, pageQuery));
139
+ }
140
+ export(runId, request = {}, options) {
141
+ return this.http.request(`/runs/${encodeURIComponent(runId)}/files/export`, {
142
+ method: 'POST',
143
+ body: request,
144
+ headers: v1IdempotencyHeaders(options),
145
+ });
146
+ }
147
+ }
148
+ export class V1RunInvocationsNamespaceClient {
149
+ http;
150
+ constructor(http) {
151
+ this.http = http;
152
+ }
153
+ list(runId, query = {}) {
154
+ return this.http.request(`/runs/${encodeURIComponent(runId)}/invocations`, { query });
155
+ }
156
+ iter(runId, query = {}) {
157
+ return iterateV1Pages(query, (pageQuery) => this.list(runId, pageQuery));
158
+ }
159
+ get(runId, invocationId) {
160
+ return this.http.request(`/runs/${encodeURIComponent(runId)}/invocations/${encodeURIComponent(invocationId)}`);
104
161
  }
105
162
  }
@@ -1,69 +1,33 @@
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, V1RuntimeConnection, V1RuntimeConnectionCreateOptions, V1RuntimeConnectionCreateResponse, V1RuntimeCreateRequest, V1RuntimeFileCollectRequest, V1RuntimeFileStageRequest, V1RuntimeFileUploadRequest, V1RuntimeFileUploadResponse, V1RuntimeStagedFile, V1RuntimeListQuery, V1RuntimeRunListQuery, V1RunSummary, V1SpaceRuntimeCreateRequest } from './types.js';
5
- export declare class V1RuntimeConnectionResource {
6
- private readonly http;
7
- private readonly runtimeId;
8
- readonly data: V1RuntimeConnectionCreateResponse;
9
- constructor(http: V1HttpClient, runtimeId: string, data: V1RuntimeConnectionCreateResponse);
10
- get id(): string;
11
- get endpoint(): V1RuntimeConnectionCreateResponse['endpoint'];
12
- get wsUrl(): string | undefined;
13
- close(): Promise<V1RuntimeConnection>;
14
- }
15
- export declare class V1RuntimeConnectionsClient {
16
- private readonly http;
17
- private readonly runtimeId;
18
- constructor(http: V1HttpClient, runtimeId: string);
19
- create(request?: V1RuntimeConnectionCreateOptions): Promise<V1RuntimeConnectionResource>;
20
- delete(connectionId: string): Promise<V1RuntimeConnection>;
21
- }
22
- export declare class V1RuntimeRunsClient {
23
- private readonly http;
24
- private readonly runtimeId;
25
- constructor(http: V1HttpClient, runtimeId: string);
26
- list(query?: V1RuntimeRunListQuery): Promise<V1ListEnvelope<V1RunSummary>>;
27
- iter(query?: V1RuntimeRunListQuery): AsyncGenerator<V1RunSummary, void, undefined>;
28
- }
29
- export declare class V1RuntimeFilesClient {
1
+ import { type V1HttpClient, type V1IdempotencyOptions } from './http.js';
2
+ import { V1RuntimeInvocationsNamespaceClient } from './invocations.js';
3
+ import type { V1ListEnvelope, V1File, V1Runtime, V1RuntimeCreateRequest, V1RuntimeFileCollectRequest, V1RuntimeFilesListQuery, V1RuntimeFileStageRequest, V1RuntimeFileUploadRequest, V1RuntimeStagedFile, V1RuntimeListQuery, V1RuntimeRunListQuery, V1RuntimeStartResponse, V1RuntimeStopResponse, V1RunSummary, V1SpaceRuntimeCreateRequest } from './types.js';
4
+ export type V1RuntimeStartResult = V1RuntimeStartResponse;
5
+ export declare class V1RuntimesClient {
30
6
  private readonly http;
31
- private readonly runtimeId;
32
- constructor(http: V1HttpClient, runtimeId: string);
33
- upload(request: V1RuntimeFileUploadRequest): Promise<V1RuntimeFileUploadResponse>;
34
- stage(request: V1RuntimeFileStageRequest): Promise<V1RuntimeStagedFile>;
35
- collect(request: V1RuntimeFileCollectRequest): Promise<V1File>;
7
+ readonly files: V1RuntimeFilesNamespaceClient;
8
+ readonly runs: V1RuntimeRunsNamespaceClient;
9
+ readonly invocations: V1RuntimeInvocationsNamespaceClient;
10
+ constructor(http: V1HttpClient);
11
+ list(query?: V1RuntimeListQuery): Promise<V1ListEnvelope<V1Runtime>>;
12
+ iter(query?: V1RuntimeListQuery): AsyncGenerator<V1Runtime, void, undefined>;
13
+ create(request: V1RuntimeCreateRequest): Promise<V1Runtime>;
14
+ createInSpace(spaceId: string, request: V1SpaceRuntimeCreateRequest): Promise<V1Runtime>;
15
+ get(id: string): Promise<V1Runtime>;
16
+ stop(id: string): Promise<V1RuntimeStopResponse>;
17
+ start(id: string, options?: V1IdempotencyOptions): Promise<V1RuntimeStartResult>;
36
18
  }
37
- export declare class V1RuntimeResource {
19
+ export declare class V1RuntimeRunsNamespaceClient {
38
20
  private readonly http;
39
- readonly data: V1Runtime;
40
- readonly connections: V1RuntimeConnectionsClient;
41
- readonly files: V1RuntimeFilesClient;
42
- readonly runs: V1RuntimeRunsClient;
43
- readonly invocations: V1RuntimeInvocationsClient;
44
- constructor(http: V1HttpClient, data: V1Runtime);
45
- get id(): string;
46
- get activeRunId(): string | null;
47
- refresh(): Promise<V1RuntimeResource>;
48
- connect(request?: V1RuntimeConnectionCreateOptions): Promise<V1RuntimeConnectionResource>;
49
- start(): Promise<{
50
- runtime: V1RuntimeResource;
51
- run: V1RunResource;
52
- }>;
53
- stop(): Promise<V1Runtime>;
54
- run(): Promise<V1RunResource>;
21
+ constructor(http: V1HttpClient);
22
+ list(runtimeId: string, query?: V1RuntimeRunListQuery): Promise<V1ListEnvelope<V1RunSummary>>;
23
+ iter(runtimeId: string, query?: V1RuntimeRunListQuery): AsyncGenerator<V1RunSummary, void, undefined>;
55
24
  }
56
- export declare class V1RuntimesClient {
25
+ export declare class V1RuntimeFilesNamespaceClient {
57
26
  private readonly http;
58
27
  constructor(http: V1HttpClient);
59
- list(query?: V1RuntimeListQuery): Promise<V1ListEnvelope<V1Runtime>>;
60
- iter(query?: V1RuntimeListQuery): AsyncGenerator<V1Runtime, void, undefined>;
61
- create(request: V1RuntimeCreateRequest): Promise<V1RuntimeResource>;
62
- createInSpace(spaceId: string, request: V1SpaceRuntimeCreateRequest): Promise<V1RuntimeResource>;
63
- get(id: string): Promise<V1RuntimeResource>;
64
- stop(id: string): Promise<V1Runtime>;
65
- start(id: string): Promise<{
66
- runtime: V1RuntimeResource;
67
- run: V1RunResource;
68
- }>;
28
+ list(runtimeId: string, query?: V1RuntimeFilesListQuery): Promise<V1ListEnvelope<V1File>>;
29
+ iter(runtimeId: string, query?: V1RuntimeFilesListQuery): AsyncGenerator<V1File, void, undefined>;
30
+ upload(runtimeId: string, request: V1RuntimeFileUploadRequest): Promise<V1RuntimeStagedFile>;
31
+ stage(runtimeId: string, request: V1RuntimeFileStageRequest): Promise<V1RuntimeStagedFile>;
32
+ collect(runtimeId: string, request: V1RuntimeFileCollectRequest): Promise<V1File>;
69
33
  }
package/dist/runtimes.js CHANGED
@@ -1,51 +1,22 @@
1
1
  import { BctrlValidationError } from './errors.js';
2
- import { V1RuntimeInvocationsClient } from './invocations.js';
2
+ import { v1IdempotencyHeaders } from './http.js';
3
+ import { V1RuntimeInvocationsNamespaceClient } from './invocations.js';
3
4
  import { iterateV1Pages } from './pagination.js';
4
- import { V1RunResource } from './runs.js';
5
- export class V1RuntimeConnectionResource {
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 V1RuntimeConnectionsClient {
5
+ class V1RuntimeRunsClient {
28
6
  http;
29
7
  runtimeId;
30
8
  constructor(http, runtimeId) {
31
9
  this.http = http;
32
10
  this.runtimeId = runtimeId;
33
11
  }
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 V1RuntimeConnectionResource(this.http, this.runtimeId, response);
12
+ list(query = {}) {
13
+ return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/runs`, { query });
43
14
  }
44
- delete(connectionId) {
45
- return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/connections/${encodeURIComponent(connectionId)}`, { method: 'DELETE' });
15
+ iter(query = {}) {
16
+ return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
46
17
  }
47
18
  }
48
- export class V1RuntimeRunsClient {
19
+ class V1RuntimeFilesClient {
49
20
  http;
50
21
  runtimeId;
51
22
  constructor(http, runtimeId) {
@@ -53,19 +24,11 @@ export class V1RuntimeRunsClient {
53
24
  this.runtimeId = runtimeId;
54
25
  }
55
26
  list(query = {}) {
56
- return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/runs`, { query });
27
+ return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/files`, { query });
57
28
  }
58
29
  iter(query = {}) {
59
30
  return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
60
31
  }
61
- }
62
- export class V1RuntimeFilesClient {
63
- http;
64
- runtimeId;
65
- constructor(http, runtimeId) {
66
- this.http = http;
67
- this.runtimeId = runtimeId;
68
- }
69
32
  async upload(request) {
70
33
  const form = new FormData();
71
34
  if (request.name) {
@@ -75,8 +38,10 @@ export class V1RuntimeFilesClient {
75
38
  else {
76
39
  form.set('file', request.file);
77
40
  }
78
- if (request.storagePath)
79
- form.set('storagePath', request.storagePath);
41
+ if (request.destinationPath)
42
+ form.set('destinationPath', request.destinationPath);
43
+ if (request.runtimePath)
44
+ form.set('runtimePath', request.runtimePath);
80
45
  if (request.metadata)
81
46
  form.set('metadata', JSON.stringify(request.metadata));
82
47
  return this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/files/upload`, {
@@ -97,72 +62,28 @@ export class V1RuntimeFilesClient {
97
62
  });
98
63
  }
99
64
  }
100
- export class V1RuntimeResource {
101
- http;
102
- data;
103
- connections;
104
- files;
105
- runs;
106
- invocations;
107
- constructor(http, data) {
108
- this.http = http;
109
- this.data = data;
110
- this.connections = new V1RuntimeConnectionsClient(http, data.id);
111
- this.files = new V1RuntimeFilesClient(http, data.id);
112
- this.runs = new V1RuntimeRunsClient(http, data.id);
113
- this.invocations = new V1RuntimeInvocationsClient(http, data.id);
114
- }
115
- get id() {
116
- return this.data.id;
117
- }
118
- get activeRunId() {
119
- return this.data.activeRunId;
120
- }
121
- refresh() {
122
- return new V1RuntimesClient(this.http).get(this.id);
123
- }
124
- async connect(request) {
125
- return this.connections.create(request);
126
- }
127
- async start() {
128
- const response = await this.http.request(`/runtimes/${encodeURIComponent(this.id)}/start`, { method: 'POST' });
129
- return {
130
- runtime: new V1RuntimeResource(this.http, response.runtime),
131
- run: new V1RunResource(this.http, response.run),
132
- };
133
- }
134
- stop() {
135
- return this.http.request(`/runtimes/${encodeURIComponent(this.id)}/stop`, {
136
- method: 'POST',
137
- });
138
- }
139
- async run() {
140
- const runtime = await this.refresh();
141
- if (!runtime.activeRunId) {
142
- throw new BctrlValidationError('Runtime does not have an active run yet', 'runtime.no_active_run', {
143
- runtimeId: this.id,
144
- });
145
- }
146
- const run = await this.http.request(`/runs/${encodeURIComponent(runtime.activeRunId)}`);
147
- return new V1RunResource(this.http, run);
148
- }
149
- }
150
65
  function validateRuntimeCreateRequest(request) {
151
- const profileBacked = request.config?.browser?.profile === true;
66
+ const profileBacked = request.config?.profile === true;
152
67
  if (!profileBacked)
153
68
  return;
154
69
  if (!request.name?.trim()) {
155
- throw new BctrlValidationError('name is required when config.browser.profile is true', 'runtime.profile_name_required');
70
+ throw new BctrlValidationError('name is required when config.profile is true', 'runtime.profile_name_required');
156
71
  }
157
- const unsupported = ['stealth', 'proxy', 'fingerprint', 'extensions'].filter((key) => request.config?.[key] !== undefined);
72
+ const unsupported = ['stealth', 'proxy', 'fingerprint', 'extensionIds'].filter((key) => request.config?.[key] !== undefined);
158
73
  if (unsupported.length > 0) {
159
- throw new BctrlValidationError('Only config.browser.profile and config.lifecycle are supported for profile-backed browser runtimes', 'runtime.profile_config_unsupported', { unsupported });
74
+ throw new BctrlValidationError('Only config.profile, config.idleTimeoutMinutes, config.webRtcProxyOnly, config.forceOpenShadowRoots, and config.networkTraffic are supported for profile-backed browser runtimes', 'runtime.profile_config_unsupported', { unsupported });
160
75
  }
161
76
  }
162
77
  export class V1RuntimesClient {
163
78
  http;
79
+ files;
80
+ runs;
81
+ invocations;
164
82
  constructor(http) {
165
83
  this.http = http;
84
+ this.files = new V1RuntimeFilesNamespaceClient(http);
85
+ this.runs = new V1RuntimeRunsNamespaceClient(http);
86
+ this.invocations = new V1RuntimeInvocationsNamespaceClient(http);
166
87
  }
167
88
  list(query = {}) {
168
89
  return this.http.request('/runtimes', { query });
@@ -172,31 +93,63 @@ export class V1RuntimesClient {
172
93
  }
173
94
  async create(request) {
174
95
  validateRuntimeCreateRequest(request);
175
- const runtime = await this.http.request('/runtimes', {
96
+ return this.http.request('/runtimes', {
176
97
  method: 'POST',
177
98
  body: request,
178
99
  });
179
- return new V1RuntimeResource(this.http, runtime);
180
100
  }
181
101
  async createInSpace(spaceId, request) {
182
102
  validateRuntimeCreateRequest(request);
183
- const runtime = await this.http.request('/runtimes', {
103
+ return this.http.request('/runtimes', {
184
104
  method: 'POST',
185
105
  body: { ...request, spaceId },
186
106
  });
187
- return new V1RuntimeResource(this.http, runtime);
188
107
  }
189
- async get(id) {
190
- const runtime = await this.http.request(`/runtimes/${encodeURIComponent(id)}`);
191
- return new V1RuntimeResource(this.http, runtime);
108
+ get(id) {
109
+ return this.http.request(`/runtimes/${encodeURIComponent(id)}`);
192
110
  }
193
111
  stop(id) {
194
112
  return this.http.request(`/runtimes/${encodeURIComponent(id)}/stop`, {
195
113
  method: 'POST',
196
114
  });
197
115
  }
198
- async start(id) {
199
- const runtime = await this.get(id);
200
- return runtime.start();
116
+ async start(id, options) {
117
+ return this.http.request(`/runtimes/${encodeURIComponent(id)}/start`, {
118
+ method: 'POST',
119
+ headers: v1IdempotencyHeaders(options),
120
+ });
121
+ }
122
+ }
123
+ export class V1RuntimeRunsNamespaceClient {
124
+ http;
125
+ constructor(http) {
126
+ this.http = http;
127
+ }
128
+ list(runtimeId, query = {}) {
129
+ return new V1RuntimeRunsClient(this.http, runtimeId).list(query);
130
+ }
131
+ iter(runtimeId, query = {}) {
132
+ return new V1RuntimeRunsClient(this.http, runtimeId).iter(query);
133
+ }
134
+ }
135
+ export class V1RuntimeFilesNamespaceClient {
136
+ http;
137
+ constructor(http) {
138
+ this.http = http;
139
+ }
140
+ list(runtimeId, query = {}) {
141
+ return new V1RuntimeFilesClient(this.http, runtimeId).list(query);
142
+ }
143
+ iter(runtimeId, query = {}) {
144
+ return new V1RuntimeFilesClient(this.http, runtimeId).iter(query);
145
+ }
146
+ upload(runtimeId, request) {
147
+ return new V1RuntimeFilesClient(this.http, runtimeId).upload(request);
148
+ }
149
+ stage(runtimeId, request) {
150
+ return new V1RuntimeFilesClient(this.http, runtimeId).stage(request);
151
+ }
152
+ collect(runtimeId, request) {
153
+ return new V1RuntimeFilesClient(this.http, runtimeId).collect(request);
201
154
  }
202
155
  }
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ import type { JsonObject } from './types.js';
3
+ export type JsonSchemaObject = JsonObject;
4
+ export type JsonSchemaLike = JsonSchemaObject | {
5
+ toJSONSchema: () => unknown;
6
+ } | z.ZodType;
7
+ export declare function toOutputSchema(schema: JsonSchemaLike, label?: string): JsonSchemaObject;
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ export function toOutputSchema(schema, label = 'schema') {
3
+ const value = resolveSchema(schema);
4
+ if (!isJsonObject(value)) {
5
+ throw new TypeError(`${label} must resolve to a JSON Schema object`);
6
+ }
7
+ const { $schema, ...jsonSchema } = value;
8
+ void $schema;
9
+ return jsonSchema;
10
+ }
11
+ function resolveSchema(schema) {
12
+ if (hasToJSONSchema(schema)) {
13
+ return schema.toJSONSchema();
14
+ }
15
+ const zodJsonSchema = tryZodToJsonSchema(schema);
16
+ if (zodJsonSchema !== undefined)
17
+ return zodJsonSchema;
18
+ return schema;
19
+ }
20
+ function hasToJSONSchema(value) {
21
+ return Boolean(value &&
22
+ typeof value === 'object' &&
23
+ 'toJSONSchema' in value &&
24
+ typeof value.toJSONSchema === 'function');
25
+ }
26
+ function tryZodToJsonSchema(value) {
27
+ try {
28
+ return z.toJSONSchema(value);
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ }
34
+ function isJsonObject(value) {
35
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
36
+ }
package/dist/spaces.d.ts CHANGED
@@ -1,40 +1,28 @@
1
1
  import type { V1HttpClient } from './http.js';
2
- import { V1RuntimeResource, V1RuntimesClient } from './runtimes.js';
3
- import type { V1ListEnvelope, V1RuntimeListQuery, V1Space, V1SpaceCreateRequest, V1SpaceEnvironment, V1SpaceEnvironmentUpdateRequest, V1SpaceRuntimeCreateRequest, V1SpaceUpdateRequest } from './types.js';
4
- export declare class V1SpaceEnvironmentClient {
5
- private readonly http;
6
- private readonly spaceId;
7
- constructor(http: V1HttpClient, spaceId: string);
8
- get(): Promise<V1SpaceEnvironment>;
9
- update(request: V1SpaceEnvironmentUpdateRequest): Promise<V1SpaceEnvironment>;
10
- }
11
- export declare class V1SpaceRuntimesClient {
2
+ import { V1RuntimesClient } from './runtimes.js';
3
+ import type { V1ListEnvelope, V1Runtime, V1RuntimeListQuery, V1Space, V1SpaceCreateRequest, V1SpaceDeleteResponse, V1SpaceEnvironment, V1SpaceEnvironmentUpdateRequest, V1SpaceListQuery, V1SpaceRuntimeCreateRequest, V1SpaceUpdateRequest } from './types.js';
4
+ export declare class V1SpacesClient {
12
5
  private readonly http;
13
- private readonly spaceId;
14
- constructor(http: V1HttpClient, spaceId: string);
15
- list(query?: Omit<V1RuntimeListQuery, 'spaceId'>): ReturnType<V1RuntimesClient['list']>;
16
- iter(query?: Omit<V1RuntimeListQuery, 'spaceId'>): ReturnType<V1RuntimesClient['iter']>;
17
- create(request: V1SpaceRuntimeCreateRequest): Promise<V1RuntimeResource>;
18
- get(runtimeId: string): Promise<V1RuntimeResource>;
19
- stop(runtimeId: string): ReturnType<V1RuntimesClient['stop']>;
20
- start(runtimeId: string): ReturnType<V1RuntimesClient['start']>;
6
+ readonly environment: V1SpaceEnvironmentNamespaceClient;
7
+ readonly runtimes: V1SpaceRuntimesNamespaceClient;
8
+ constructor(http: V1HttpClient);
9
+ list(query?: V1SpaceListQuery): Promise<V1ListEnvelope<V1Space>>;
10
+ iter(query?: V1SpaceListQuery): AsyncGenerator<V1Space, void, undefined>;
11
+ create(request: V1SpaceCreateRequest): Promise<V1Space>;
12
+ get(id: string): Promise<V1Space>;
13
+ update(id: string, request: V1SpaceUpdateRequest): Promise<V1Space>;
14
+ delete(id: string): Promise<V1SpaceDeleteResponse>;
21
15
  }
22
- export declare class V1SpaceResource {
16
+ export declare class V1SpaceEnvironmentNamespaceClient {
23
17
  private readonly http;
24
- readonly data: V1Space;
25
- readonly environment: V1SpaceEnvironmentClient;
26
- readonly runtimes: V1SpaceRuntimesClient;
27
- constructor(http: V1HttpClient, data: V1Space);
28
- get id(): string;
29
- refresh(): Promise<V1SpaceResource>;
30
- update(request: V1SpaceUpdateRequest): Promise<V1SpaceResource>;
18
+ constructor(http: V1HttpClient);
19
+ get(spaceId: string): Promise<V1SpaceEnvironment>;
20
+ update(spaceId: string, request: V1SpaceEnvironmentUpdateRequest): Promise<V1SpaceEnvironment>;
31
21
  }
32
- export declare class V1SpacesClient {
22
+ export declare class V1SpaceRuntimesNamespaceClient {
33
23
  private readonly http;
34
24
  constructor(http: V1HttpClient);
35
- list(): Promise<V1ListEnvelope<V1Space>>;
36
- iter(): AsyncGenerator<V1Space, void, undefined>;
37
- create(request: V1SpaceCreateRequest): Promise<V1SpaceResource>;
38
- get(id: string): Promise<V1SpaceResource>;
39
- update(id: string, request: V1SpaceUpdateRequest): Promise<V1SpaceResource>;
25
+ list(spaceId: string, query?: Omit<V1RuntimeListQuery, 'spaceId'>): ReturnType<V1RuntimesClient['list']>;
26
+ iter(spaceId: string, query?: Omit<V1RuntimeListQuery, 'spaceId'>): ReturnType<V1RuntimesClient['iter']>;
27
+ create(spaceId: string, request: V1SpaceRuntimeCreateRequest): Promise<V1Runtime>;
40
28
  }