@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
@@ -0,0 +1,53 @@
1
+ import { iterateV1Pages } from './pagination.js';
2
+ function browserExtensionFileName(file) {
3
+ const name = file.name;
4
+ return typeof name === 'string' && name.trim() ? name : 'extension.crx';
5
+ }
6
+ export class V1BrowserExtensionsClient {
7
+ http;
8
+ constructor(http) {
9
+ this.http = http;
10
+ }
11
+ list(query = {}) {
12
+ return this.http.request('/browser-extensions', {
13
+ query,
14
+ });
15
+ }
16
+ iter(query = {}) {
17
+ return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
18
+ }
19
+ get(extensionId) {
20
+ return this.http.request(`/browser-extensions/${encodeURIComponent(extensionId)}`);
21
+ }
22
+ upload(request) {
23
+ const form = new FormData();
24
+ form.set('file', request.file, browserExtensionFileName(request.file));
25
+ if (request.name) {
26
+ form.set('name', request.name);
27
+ }
28
+ if (request.subaccountId) {
29
+ form.set('subaccountId', request.subaccountId);
30
+ }
31
+ return this.http.request('/browser-extensions/upload', {
32
+ method: 'POST',
33
+ body: form,
34
+ });
35
+ }
36
+ import(request) {
37
+ return this.http.request('/browser-extensions/import', {
38
+ method: 'POST',
39
+ body: request,
40
+ });
41
+ }
42
+ update(extensionId, request) {
43
+ return this.http.request(`/browser-extensions/${encodeURIComponent(extensionId)}`, {
44
+ method: 'PATCH',
45
+ body: request,
46
+ });
47
+ }
48
+ delete(extensionId) {
49
+ return this.http.request(`/browser-extensions/${encodeURIComponent(extensionId)}`, {
50
+ method: 'DELETE',
51
+ });
52
+ }
53
+ }
package/dist/files.d.ts CHANGED
@@ -1,31 +1,13 @@
1
1
  import type { V1HttpClient } from './http.js';
2
- import type { V1File, V1FileDeleteResponse, V1FilesListQuery, V1FileUpdateRequest, V1FileUploadRequest, V1ListEnvelope, V1RunFilesExportRequest, V1RunFilesListQuery } from './types.js';
3
- export declare class V1FileResource {
4
- private readonly http;
5
- readonly data: V1File;
6
- constructor(http: V1HttpClient, data: V1File);
7
- get id(): string;
8
- refresh(): Promise<V1FileResource>;
9
- content(): Promise<Response>;
10
- update(request: V1FileUpdateRequest): Promise<V1FileResource>;
11
- delete(): Promise<V1FileDeleteResponse>;
12
- }
2
+ import type { V1File, V1FileDeleteResponse, V1FilesListQuery, V1FileUpdateRequest, V1FileUploadRequest, V1ListEnvelope } from './types.js';
13
3
  export declare class V1FilesClient {
14
4
  private readonly http;
15
5
  constructor(http: V1HttpClient);
16
- list(query: V1FilesListQuery): Promise<V1ListEnvelope<V1File>>;
17
- iter(query: V1FilesListQuery): AsyncGenerator<V1File, void, undefined>;
18
- get(id: string): Promise<V1FileResource>;
19
- update(id: string, request: V1FileUpdateRequest): Promise<V1FileResource>;
6
+ list(query?: V1FilesListQuery): Promise<V1ListEnvelope<V1File>>;
7
+ iter(query?: V1FilesListQuery): AsyncGenerator<V1File, void, undefined>;
8
+ get(id: string): Promise<V1File>;
9
+ update(id: string, request: V1FileUpdateRequest): Promise<V1File>;
20
10
  content(id: string): Promise<Response>;
21
11
  delete(id: string): Promise<V1FileDeleteResponse>;
22
- upload(request: V1FileUploadRequest): Promise<V1FileResource>;
23
- }
24
- export declare class V1RunFilesClient {
25
- private readonly http;
26
- private readonly runId;
27
- constructor(http: V1HttpClient, runId: string);
28
- list(query?: V1RunFilesListQuery): Promise<V1ListEnvelope<V1File>>;
29
- iter(query?: V1RunFilesListQuery): AsyncGenerator<V1File, void, undefined>;
30
- export(request: V1RunFilesExportRequest): Promise<V1FileResource>;
12
+ upload(request: V1FileUploadRequest): Promise<V1File>;
31
13
  }
package/dist/files.js CHANGED
@@ -1,48 +1,23 @@
1
1
  import { iterateV1Pages } from './pagination.js';
2
- export class V1FileResource {
3
- http;
4
- data;
5
- constructor(http, data) {
6
- this.http = http;
7
- this.data = data;
8
- }
9
- get id() {
10
- return this.data.id;
11
- }
12
- refresh() {
13
- return new V1FilesClient(this.http).get(this.id);
14
- }
15
- async content() {
16
- return new V1FilesClient(this.http).content(this.id);
17
- }
18
- async update(request) {
19
- return new V1FilesClient(this.http).update(this.id, request);
20
- }
21
- delete() {
22
- return new V1FilesClient(this.http).delete(this.id);
23
- }
24
- }
25
2
  export class V1FilesClient {
26
3
  http;
27
4
  constructor(http) {
28
5
  this.http = http;
29
6
  }
30
- list(query) {
7
+ list(query = {}) {
31
8
  return this.http.request('/files', { query });
32
9
  }
33
- iter(query) {
10
+ iter(query = {}) {
34
11
  return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
35
12
  }
36
- async get(id) {
37
- const file = await this.http.request(`/files/${encodeURIComponent(id)}`);
38
- return new V1FileResource(this.http, file);
13
+ get(id) {
14
+ return this.http.request(`/files/${encodeURIComponent(id)}`);
39
15
  }
40
- async update(id, request) {
41
- const file = await this.http.request(`/files/${encodeURIComponent(id)}`, {
16
+ update(id, request) {
17
+ return this.http.request(`/files/${encodeURIComponent(id)}`, {
42
18
  method: 'PATCH',
43
19
  body: request,
44
20
  });
45
- return new V1FileResource(this.http, file);
46
21
  }
47
22
  content(id) {
48
23
  return this.http.raw(`/files/${encodeURIComponent(id)}/content`);
@@ -52,7 +27,7 @@ export class V1FilesClient {
52
27
  method: 'DELETE',
53
28
  });
54
29
  }
55
- async upload(request) {
30
+ upload(request) {
56
31
  const form = new FormData();
57
32
  if (request.name) {
58
33
  form.set('file', request.file, request.name);
@@ -66,32 +41,10 @@ export class V1FilesClient {
66
41
  form.set('path', request.path);
67
42
  if (request.metadata)
68
43
  form.set('metadata', JSON.stringify(request.metadata));
69
- const file = await this.http.request('/files', {
44
+ return this.http.request('/files', {
70
45
  method: 'POST',
71
- query: { spaceId: request.spaceId },
46
+ query: request.spaceId ? { spaceId: request.spaceId } : undefined,
72
47
  body: form,
73
48
  });
74
- return new V1FileResource(this.http, file);
75
- }
76
- }
77
- export class V1RunFilesClient {
78
- http;
79
- runId;
80
- constructor(http, runId) {
81
- this.http = http;
82
- this.runId = runId;
83
- }
84
- list(query = {}) {
85
- return this.http.request(`/runs/${encodeURIComponent(this.runId)}/files`, { query });
86
- }
87
- iter(query = {}) {
88
- return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
89
- }
90
- async export(request) {
91
- const file = await this.http.request(`/runs/${encodeURIComponent(this.runId)}/files/export`, {
92
- method: 'POST',
93
- body: request,
94
- });
95
- return new V1FileResource(this.http, file);
96
49
  }
97
50
  }
package/dist/help.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { V1HttpClient } from './http.js';
2
+ import type { V1HelpRequest, V1HelpResponse } from './types.js';
3
+ export declare class V1HelpClient {
4
+ private readonly http;
5
+ constructor(http: V1HttpClient);
6
+ get(request?: V1HelpRequest): Promise<V1HelpResponse>;
7
+ }
package/dist/help.js ADDED
@@ -0,0 +1,9 @@
1
+ export class V1HelpClient {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ get(request = {}) {
7
+ return this.http.request('/help', { query: request });
8
+ }
9
+ }
package/dist/http.d.ts CHANGED
@@ -1,18 +1,29 @@
1
1
  export interface V1ClientOptions {
2
2
  apiKey?: string;
3
3
  baseUrl?: string;
4
+ timeoutMs?: number;
5
+ maxRetries?: number;
6
+ fetch?: typeof fetch;
4
7
  }
5
8
  export interface V1RequestOptions {
6
- method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
9
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
7
10
  query?: object;
8
11
  body?: unknown;
9
12
  headers?: Record<string, string>;
10
13
  timeoutMs?: number;
14
+ signal?: AbortSignal;
15
+ }
16
+ export interface V1IdempotencyOptions {
17
+ idempotencyKey?: string;
11
18
  }
12
19
  export declare class V1HttpClient {
13
20
  readonly baseUrl: string;
14
21
  readonly apiKey: string;
22
+ private readonly timeoutMs?;
23
+ private readonly maxRetries;
24
+ private readonly fetchImpl;
15
25
  constructor(options: V1ClientOptions);
16
26
  request<T>(path: string, options?: V1RequestOptions): Promise<T>;
17
27
  raw(path: string, options?: V1RequestOptions): Promise<Response>;
18
28
  }
29
+ export declare function v1IdempotencyHeaders(options?: V1IdempotencyOptions): Record<string, string> | undefined;
package/dist/http.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BctrlNetworkError, createV1HttpError } from './errors.js';
2
- import { BCTRL_PRODUCTION_ORIGIN, fetchWithTimeout, resolveApiKey, stripTrailingSlash, } from './utils.js';
2
+ import { BCTRL_PRODUCTION_ORIGIN, abortableSleep, fetchWithTimeout, resolveApiKey, stripTrailingSlash, } from './utils.js';
3
3
  import { SDK_VERSION } from './version.js';
4
4
  const API_PREFIX = '/v1';
5
5
  function resolveV1ApiBaseUrl(baseUrl) {
@@ -43,9 +43,7 @@ function parseResponseBody(text) {
43
43
  }
44
44
  }
45
45
  function responseRequestId(response) {
46
- return (response.headers.get('x-request-id') ??
47
- response.headers.get('x-bctrl-request-id') ??
48
- undefined);
46
+ return (response.headers.get('x-request-id') ?? response.headers.get('x-bctrl-request-id') ?? undefined);
49
47
  }
50
48
  function isRecord(value) {
51
49
  return Boolean(value && typeof value === 'object' && !Array.isArray(value));
@@ -73,9 +71,15 @@ function isBodyInit(value) {
73
71
  export class V1HttpClient {
74
72
  baseUrl;
75
73
  apiKey;
74
+ timeoutMs;
75
+ maxRetries;
76
+ fetchImpl;
76
77
  constructor(options) {
77
78
  this.baseUrl = resolveV1ApiBaseUrl(options.baseUrl);
78
79
  this.apiKey = resolveV1ApiKey(options.apiKey);
80
+ this.timeoutMs = options.timeoutMs;
81
+ this.maxRetries = options.maxRetries ?? 2;
82
+ this.fetchImpl = options.fetch ?? fetch;
79
83
  }
80
84
  async request(path, options = {}) {
81
85
  const response = await this.raw(path, options);
@@ -95,8 +99,9 @@ export class V1HttpClient {
95
99
  'User-Agent': `@bctrl/sdk/${SDK_VERSION} v1`,
96
100
  ...options.headers,
97
101
  };
102
+ const method = options.method ?? 'GET';
98
103
  const init = {
99
- method: options.method ?? 'GET',
104
+ method,
100
105
  headers,
101
106
  };
102
107
  if (options.body !== undefined) {
@@ -109,12 +114,32 @@ export class V1HttpClient {
109
114
  }
110
115
  }
111
116
  let response;
112
- try {
113
- response = await fetchWithTimeout(url.toString(), init, options.timeoutMs);
117
+ let lastNetworkError;
118
+ const maxAttempts = canRetryRequest(method, headers) ? Math.max(1, this.maxRetries + 1) : 1;
119
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
120
+ try {
121
+ response = await fetchWithTimeout(url.toString(), { ...init, signal: options.signal }, options.timeoutMs ?? this.timeoutMs, this.fetchImpl);
122
+ }
123
+ catch (error) {
124
+ lastNetworkError = error;
125
+ if (attempt < maxAttempts && isRetryableNetworkError(error)) {
126
+ await abortableSleep(retryDelayMs(attempt), options.signal);
127
+ continue;
128
+ }
129
+ if (error instanceof Error) {
130
+ throw new BctrlNetworkError(error.message, { cause: error });
131
+ }
132
+ throw new BctrlNetworkError('Network request failed');
133
+ }
134
+ if (response.ok || !isRetryableStatus(response.status) || attempt >= maxAttempts) {
135
+ break;
136
+ }
137
+ await response.body?.cancel().catch(() => undefined);
138
+ await abortableSleep(retryAfterMs(response) ?? retryDelayMs(attempt), options.signal);
114
139
  }
115
- catch (error) {
116
- if (error instanceof Error) {
117
- throw new BctrlNetworkError(error.message, { cause: error });
140
+ if (!response) {
141
+ if (lastNetworkError instanceof Error) {
142
+ throw new BctrlNetworkError(lastNetworkError.message, { cause: lastNetworkError });
118
143
  }
119
144
  throw new BctrlNetworkError('Network request failed');
120
145
  }
@@ -133,3 +158,41 @@ export class V1HttpClient {
133
158
  return response;
134
159
  }
135
160
  }
161
+ function isRetryableStatus(status) {
162
+ return status === 408 || status === 429 || status >= 500;
163
+ }
164
+ function canRetryRequest(method, headers) {
165
+ const normalized = method.toUpperCase();
166
+ if (normalized === 'GET' || normalized === 'HEAD' || normalized === 'OPTIONS') {
167
+ return true;
168
+ }
169
+ return hasHeader(headers, 'Idempotency-Key');
170
+ }
171
+ function hasHeader(headers, name) {
172
+ const expected = name.toLowerCase();
173
+ return Object.entries(headers).some(([key, value]) => key.toLowerCase() === expected && value.trim().length > 0);
174
+ }
175
+ function isRetryableNetworkError(error) {
176
+ if (!(error instanceof Error))
177
+ return false;
178
+ return error.name === 'AbortError' || error.name === 'TimeoutError';
179
+ }
180
+ function retryAfterMs(response) {
181
+ const raw = response.headers.get('retry-after');
182
+ if (!raw)
183
+ return undefined;
184
+ const seconds = Number(raw);
185
+ if (Number.isFinite(seconds))
186
+ return Math.max(0, seconds * 1000);
187
+ const date = Date.parse(raw);
188
+ if (Number.isFinite(date))
189
+ return Math.max(0, date - Date.now());
190
+ return undefined;
191
+ }
192
+ function retryDelayMs(attempt) {
193
+ return Math.min(2000, 250 * 2 ** Math.max(0, attempt - 1));
194
+ }
195
+ export function v1IdempotencyHeaders(options) {
196
+ const key = options?.idempotencyKey?.trim();
197
+ return key ? { 'Idempotency-Key': key } : undefined;
198
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,20 @@
1
1
  export { Bctrl, BctrlV1, type BctrlV1Options } from './bctrl.js';
2
+ export { V1AccountClient, V1ApiKeysClient, V1AuthClient, V1SubaccountsClient, V1SubaccountUsageClient, V1UsageClient, } from './account.js';
3
+ export { V1AiProvidersClient } from './aiProviders.js';
4
+ export { V1BrowserExtensionsClient } from './browserExtensions.js';
2
5
  export { BctrlError, BctrlApiError, BctrlAuthenticationError, BctrlConflictError, BctrlNetworkError, BctrlNotFoundError, BctrlNotReadyError, BctrlPermissionError, BctrlRateLimitError, BctrlUnsupportedError, BctrlValidationError, isControllerBusy, } from './errors.js';
3
- export { V1FileResource, V1FilesClient, V1RunFilesClient } from './files.js';
4
- export { V1InvocationsClient, V1InvocationResource, V1RuntimeBrowserUseInvocationsClient, V1RuntimeInvocationsClient, V1RuntimeStagehandInvocationsClient, } from './invocations.js';
5
- export type { BrowserUseAgentOptions, StagehandActOptions, StagehandAgentOptions, StagehandExtractOptions, StagehandObserveOptions, StagehandVariablePrimitive, StagehandVariableValue, StagehandVariables, } from './invocations.js';
6
- export { V1RuntimeConnectionResource, V1RuntimeConnectionsClient, V1RuntimeFilesClient, V1RuntimeResource, V1RuntimeRunsClient, V1RuntimesClient, } from './runtimes.js';
7
- export { V1RunCommandsClient, V1RunEventsClient, V1RunResource, V1RunsClient, } from './runs.js';
8
- export { V1SpaceEnvironmentClient, V1SpaceResource, V1SpaceRuntimesClient, V1SpacesClient, } from './spaces.js';
6
+ export { V1FilesClient } from './files.js';
7
+ export { V1HelpClient } from './help.js';
8
+ export { V1RuntimeBrowserUseInvocationsNamespaceClient, V1RuntimeInvocationsNamespaceClient, V1RuntimeStagehandInvocationsNamespaceClient, } from './invocations.js';
9
+ export type { BrowserUseAgentOptions, V1InvocationCreateAndWaitOptions, V1InvocationWaitOptions, V1RuntimeInvocationCreateInput, StagehandActOptions, StagehandAgentOptions, StagehandExtractOptions, StagehandObserveOptions, StagehandVariablePrimitive, StagehandVariableValue, StagehandVariables, } from './invocations.js';
10
+ export { V1RuntimeFilesNamespaceClient, V1RuntimeRunsNamespaceClient, V1RuntimesClient, } from './runtimes.js';
11
+ export { V1ProxiesClient, V1ProxyPoolsClient } from './proxies.js';
12
+ export { V1RunActivityNamespaceClient, V1RunEventsNamespaceClient, V1RunFilesNamespaceClient, V1RunInvocationsNamespaceClient, V1RunsClient, } from './runs.js';
13
+ export { toOutputSchema, type JsonSchemaLike, type JsonSchemaObject } from './schemas.js';
14
+ export { V1SpaceEnvironmentNamespaceClient, V1SpaceRuntimesNamespaceClient, V1SpacesClient, } from './spaces.js';
15
+ export { V1ToolCallsClient } from './toolCalls.js';
16
+ export { passthroughJsonSchema, V1ToolsClient } from './tools.js';
17
+ export { V1ToolsetsClient } from './toolsets.js';
18
+ export { V1VaultClient } from './vault.js';
9
19
  export type * from './types.js';
20
+ export type * from './browserExtensionTypes.js';
package/dist/index.js CHANGED
@@ -1,7 +1,17 @@
1
1
  export { Bctrl, BctrlV1 } from './bctrl.js';
2
+ export { V1AccountClient, V1ApiKeysClient, V1AuthClient, V1SubaccountsClient, V1SubaccountUsageClient, V1UsageClient, } from './account.js';
3
+ export { V1AiProvidersClient } from './aiProviders.js';
4
+ export { V1BrowserExtensionsClient } from './browserExtensions.js';
2
5
  export { BctrlError, BctrlApiError, BctrlAuthenticationError, BctrlConflictError, BctrlNetworkError, BctrlNotFoundError, BctrlNotReadyError, BctrlPermissionError, BctrlRateLimitError, BctrlUnsupportedError, BctrlValidationError, isControllerBusy, } from './errors.js';
3
- export { V1FileResource, V1FilesClient, V1RunFilesClient } from './files.js';
4
- export { V1InvocationsClient, V1InvocationResource, V1RuntimeBrowserUseInvocationsClient, V1RuntimeInvocationsClient, V1RuntimeStagehandInvocationsClient, } from './invocations.js';
5
- export { V1RuntimeConnectionResource, V1RuntimeConnectionsClient, V1RuntimeFilesClient, V1RuntimeResource, V1RuntimeRunsClient, V1RuntimesClient, } from './runtimes.js';
6
- export { V1RunCommandsClient, V1RunEventsClient, V1RunResource, V1RunsClient, } from './runs.js';
7
- export { V1SpaceEnvironmentClient, V1SpaceResource, V1SpaceRuntimesClient, V1SpacesClient, } from './spaces.js';
6
+ export { V1FilesClient } from './files.js';
7
+ export { V1HelpClient } from './help.js';
8
+ export { V1RuntimeBrowserUseInvocationsNamespaceClient, V1RuntimeInvocationsNamespaceClient, V1RuntimeStagehandInvocationsNamespaceClient, } from './invocations.js';
9
+ export { V1RuntimeFilesNamespaceClient, V1RuntimeRunsNamespaceClient, V1RuntimesClient, } from './runtimes.js';
10
+ export { V1ProxiesClient, V1ProxyPoolsClient } from './proxies.js';
11
+ export { V1RunActivityNamespaceClient, V1RunEventsNamespaceClient, V1RunFilesNamespaceClient, V1RunInvocationsNamespaceClient, V1RunsClient, } from './runs.js';
12
+ export { toOutputSchema } from './schemas.js';
13
+ export { V1SpaceEnvironmentNamespaceClient, V1SpaceRuntimesNamespaceClient, V1SpacesClient, } from './spaces.js';
14
+ export { V1ToolCallsClient } from './toolCalls.js';
15
+ export { passthroughJsonSchema, V1ToolsClient } from './tools.js';
16
+ export { V1ToolsetsClient } from './toolsets.js';
17
+ export { V1VaultClient } from './vault.js';
@@ -1,8 +1,6 @@
1
- import type { V1HttpClient } from './http.js';
2
- import type { JsonObject, V1Invocation, V1RuntimeInvocationCreateRequest, V1RuntimeInvocationFileInput, V1InvocationWaitRequest, V1InvocationWaitResponse } from './types.js';
3
- type JsonSchemaLike = JsonObject | {
4
- toJSONSchema: () => unknown;
5
- };
1
+ import { type V1HttpClient, type V1IdempotencyOptions } from './http.js';
2
+ import { type JsonSchemaLike } from './schemas.js';
3
+ import type { JsonObject, V1Invocation, V1InvocationPage, V1RuntimeInvocationCreateRequest, V1RuntimeInvocationFileInput, V1InvocationWaitRequest, V1InvocationWaitResponse } from './types.js';
6
4
  export type StagehandVariablePrimitive = string | number | boolean;
7
5
  export type StagehandVariableValue = StagehandVariablePrimitive | {
8
6
  value: StagehandVariablePrimitive;
@@ -10,77 +8,117 @@ export type StagehandVariableValue = StagehandVariablePrimitive | {
10
8
  };
11
9
  export type StagehandVariables = Record<string, StagehandVariableValue>;
12
10
  interface RuntimeInvocationCommonOptions {
13
- target?: JsonObject;
14
- idempotencyKey?: string;
11
+ page?: V1InvocationPage;
15
12
  metadata?: JsonObject;
16
13
  }
17
14
  interface RuntimeAgentCommonOptions extends RuntimeInvocationCommonOptions {
18
15
  toolsetId?: string;
16
+ toolIds?: string[];
19
17
  files?: V1RuntimeInvocationFileInput[];
18
+ schema?: JsonSchemaLike;
20
19
  outputSchema?: JsonObject;
20
+ timeoutMs?: number;
21
21
  }
22
- export interface StagehandActOptions extends RuntimeInvocationCommonOptions {
22
+ interface AiSelectionOptions {
23
+ aiProviderId?: string;
24
+ model?: string;
25
+ temperature?: number;
26
+ }
27
+ export interface StagehandActOptions extends RuntimeInvocationCommonOptions, AiSelectionOptions {
23
28
  instruction: string;
29
+ stagehandAction?: JsonObject;
24
30
  timeoutMs?: number;
25
31
  }
26
- export interface StagehandObserveOptions extends RuntimeInvocationCommonOptions {
32
+ export interface StagehandObserveOptions extends RuntimeInvocationCommonOptions, AiSelectionOptions {
27
33
  instruction: string;
28
34
  selector?: string;
29
35
  timeoutMs?: number;
30
36
  }
31
- export type StagehandExtractOptions<TSchema extends JsonSchemaLike | undefined = undefined> = RuntimeInvocationCommonOptions & {
32
- instruction: string;
37
+ export type StagehandExtractOptions<TSchema extends JsonSchemaLike | undefined = undefined> = RuntimeInvocationCommonOptions & AiSelectionOptions & {
38
+ instruction?: string;
39
+ selector?: string;
33
40
  schema?: TSchema;
41
+ timeoutMs?: number;
34
42
  };
35
- export interface StagehandAgentOptions extends RuntimeAgentCommonOptions {
43
+ export interface StagehandAgentOptions extends RuntimeAgentCommonOptions, AiSelectionOptions {
36
44
  instruction: string;
37
45
  maxSteps?: number;
38
- timeoutMs?: number;
39
46
  variables?: StagehandVariables;
40
- config?: JsonObject;
41
- options?: JsonObject;
47
+ executionAiProviderId?: string;
48
+ systemPrompt?: string;
49
+ highlightCursor?: boolean;
42
50
  }
43
- export interface BrowserUseAgentOptions extends RuntimeAgentCommonOptions {
51
+ export interface BrowserUseAgentOptions extends RuntimeAgentCommonOptions, AiSelectionOptions {
44
52
  instruction: string;
45
53
  maxSteps?: number;
46
- config?: JsonObject;
47
- options?: JsonObject;
54
+ extractionAiProviderId?: string;
55
+ fallbackAiProviderId?: string;
56
+ useVision?: boolean | 'auto';
57
+ visionDetailLevel?: 'low' | 'high' | 'auto';
58
+ flashMode?: boolean;
59
+ enablePlanning?: boolean;
60
+ maxFailures?: number;
61
+ stepTimeoutMs?: number;
62
+ maxActionsPerStep?: number;
63
+ maxHistoryItems?: number | null;
64
+ useThinking?: boolean;
65
+ directlyOpenUrl?: boolean;
66
+ includeAttributes?: string[];
67
+ overrideSystemMessage?: string;
68
+ extendSystemMessage?: string;
69
+ sensitiveData?: Record<string, string | Record<string, string>>;
48
70
  }
49
- export declare class V1InvocationResource {
50
- private readonly http;
51
- readonly data: V1Invocation;
52
- constructor(http: V1HttpClient, data: V1Invocation);
53
- get id(): string;
54
- refresh(): Promise<V1Invocation>;
55
- wait(request?: V1InvocationWaitRequest): Promise<V1InvocationWaitResponse>;
56
- cancel(): Promise<V1Invocation>;
71
+ type InvocationCreateWithSchema<T extends V1RuntimeInvocationCreateRequest> = Omit<T, 'outputSchema'> & {
72
+ schema?: JsonSchemaLike;
73
+ outputSchema?: JsonObject;
74
+ };
75
+ type ExtractInvocationCreateRequest = Extract<V1RuntimeInvocationCreateRequest, {
76
+ action: 'extract';
77
+ }>;
78
+ type StagehandAgentInvocationCreateRequest = Extract<V1RuntimeInvocationCreateRequest, {
79
+ action: 'stagehandAgent';
80
+ }>;
81
+ type BrowserUseInvocationCreateRequest = Extract<V1RuntimeInvocationCreateRequest, {
82
+ action: 'browserUse';
83
+ }>;
84
+ type InvocationCreateSchemaInput = InvocationCreateWithSchema<ExtractInvocationCreateRequest> | InvocationCreateWithSchema<StagehandAgentInvocationCreateRequest> | InvocationCreateWithSchema<BrowserUseInvocationCreateRequest>;
85
+ export type V1RuntimeInvocationCreateInput = Exclude<V1RuntimeInvocationCreateRequest, ExtractInvocationCreateRequest | StagehandAgentInvocationCreateRequest | BrowserUseInvocationCreateRequest> | InvocationCreateSchemaInput;
86
+ export interface V1InvocationWaitOptions extends V1InvocationWaitRequest {
87
+ signal?: AbortSignal;
57
88
  }
58
- export declare class V1InvocationsClient {
59
- private readonly http;
60
- constructor(http: V1HttpClient);
61
- get(id: string): Promise<V1InvocationResource>;
62
- wait(id: string, request?: V1InvocationWaitRequest): Promise<V1InvocationWaitResponse>;
63
- cancel(id: string): Promise<V1InvocationResource>;
89
+ export interface V1InvocationCreateAndWaitOptions extends V1IdempotencyOptions {
90
+ /**
91
+ * Overall client-side wait budget across repeated long-poll requests.
92
+ * The server-side invocation timeout still belongs in the invocation body.
93
+ */
94
+ timeoutMs?: number;
95
+ /**
96
+ * Per-request long-poll timeout sent to the wait endpoint.
97
+ */
98
+ pollTimeoutMs?: number;
99
+ signal?: AbortSignal;
64
100
  }
65
- export declare class V1RuntimeInvocationsClient {
101
+ export declare class V1RuntimeInvocationsNamespaceClient {
66
102
  private readonly http;
67
- private readonly runtimeId;
68
- readonly stagehand: V1RuntimeStagehandInvocationsClient;
69
- readonly browserUse: V1RuntimeBrowserUseInvocationsClient;
70
- constructor(http: V1HttpClient, runtimeId: string);
71
- create(request: V1RuntimeInvocationCreateRequest): Promise<V1InvocationResource>;
103
+ readonly stagehand: V1RuntimeStagehandInvocationsNamespaceClient;
104
+ readonly browserUse: V1RuntimeBrowserUseInvocationsNamespaceClient;
105
+ constructor(http: V1HttpClient);
106
+ create(runtimeId: string, request: V1RuntimeInvocationCreateInput, options?: V1IdempotencyOptions): Promise<V1Invocation>;
107
+ wait(runtimeId: string, invocationId: string, request?: V1InvocationWaitOptions): Promise<V1InvocationWaitResponse>;
108
+ cancel(runtimeId: string, invocationId: string): Promise<V1Invocation>;
109
+ createAndWait(runtimeId: string, request: V1RuntimeInvocationCreateInput, options?: V1InvocationCreateAndWaitOptions): Promise<V1Invocation>;
72
110
  }
73
- export declare class V1RuntimeStagehandInvocationsClient {
111
+ export declare class V1RuntimeStagehandInvocationsNamespaceClient {
74
112
  private readonly invocations;
75
- constructor(invocations: V1RuntimeInvocationsClient);
76
- act(options: StagehandActOptions): Promise<V1InvocationResource>;
77
- observe(options: StagehandObserveOptions): Promise<V1InvocationResource>;
78
- extract<TSchema extends JsonSchemaLike | undefined = undefined>(options: StagehandExtractOptions<TSchema>): Promise<V1InvocationResource>;
79
- agent(options: StagehandAgentOptions): Promise<V1InvocationResource>;
113
+ constructor(invocations: V1RuntimeInvocationsNamespaceClient);
114
+ act(runtimeId: string, options: StagehandActOptions): Promise<V1Invocation>;
115
+ observe(runtimeId: string, options: StagehandObserveOptions): Promise<V1Invocation>;
116
+ extract<TSchema extends JsonSchemaLike | undefined = undefined>(runtimeId: string, options: StagehandExtractOptions<TSchema>): Promise<V1Invocation>;
117
+ agent(runtimeId: string, options: StagehandAgentOptions): Promise<V1Invocation>;
80
118
  }
81
- export declare class V1RuntimeBrowserUseInvocationsClient {
119
+ export declare class V1RuntimeBrowserUseInvocationsNamespaceClient {
82
120
  private readonly invocations;
83
- constructor(invocations: V1RuntimeInvocationsClient);
84
- agent(options: BrowserUseAgentOptions): Promise<V1InvocationResource>;
121
+ constructor(invocations: V1RuntimeInvocationsNamespaceClient);
122
+ agent(runtimeId: string, options: BrowserUseAgentOptions): Promise<V1Invocation>;
85
123
  }
86
124
  export {};