@bctrl/sdk 1.0.4 → 1.0.6

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 +72 -72
  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/ai.d.ts +23 -0
  7. package/dist/ai.js +51 -0
  8. package/dist/aiTypes.d.ts +97 -0
  9. package/dist/aiTypes.js +1 -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 +83 -48
  25. package/dist/invocations.js +141 -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 +119 -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 +41 -40
  35. package/dist/runtimes.js +115 -61
  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 +586 -167
  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 +46 -37
@@ -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, V1RuntimeInvocationCreateRequest, V1RuntimeInvocationFileInput, V1RuntimeTargetSelector, V1InvocationWaitRequest, V1InvocationWaitResponse, V1AiModelSelection } from './types.js';
6
4
  export type StagehandVariablePrimitive = string | number | boolean;
7
5
  export type StagehandVariableValue = StagehandVariablePrimitive | {
8
6
  value: StagehandVariablePrimitive;
@@ -10,77 +8,114 @@ 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
+ target?: V1RuntimeTargetSelector;
15
12
  metadata?: JsonObject;
16
13
  }
17
14
  interface RuntimeAgentCommonOptions extends RuntimeInvocationCommonOptions {
18
15
  toolsetId?: string;
16
+ toolIds?: string[];
19
17
  files?: V1RuntimeInvocationFileInput[];
20
- outputSchema?: JsonObject;
18
+ schema?: JsonSchemaLike;
19
+ timeoutMs?: number;
21
20
  }
22
- export interface StagehandActOptions extends RuntimeInvocationCommonOptions {
21
+ interface AiSelectionOptions {
22
+ model?: V1AiModelSelection;
23
+ temperature?: number;
24
+ }
25
+ export interface StagehandActOptions extends RuntimeInvocationCommonOptions, AiSelectionOptions {
23
26
  instruction: string;
27
+ stagehandAction?: JsonObject;
24
28
  timeoutMs?: number;
25
29
  }
26
- export interface StagehandObserveOptions extends RuntimeInvocationCommonOptions {
30
+ export interface StagehandObserveOptions extends RuntimeInvocationCommonOptions, AiSelectionOptions {
27
31
  instruction: string;
28
32
  selector?: string;
29
33
  timeoutMs?: number;
30
34
  }
31
- export type StagehandExtractOptions<TSchema extends JsonSchemaLike | undefined = undefined> = RuntimeInvocationCommonOptions & {
32
- instruction: string;
35
+ export type StagehandExtractOptions<TSchema extends JsonSchemaLike | undefined = undefined> = RuntimeInvocationCommonOptions & AiSelectionOptions & {
36
+ instruction?: string;
37
+ selector?: string;
33
38
  schema?: TSchema;
39
+ timeoutMs?: number;
34
40
  };
35
- export interface StagehandAgentOptions extends RuntimeAgentCommonOptions {
41
+ export interface StagehandAgentOptions extends RuntimeAgentCommonOptions, AiSelectionOptions {
36
42
  instruction: string;
37
43
  maxSteps?: number;
38
- timeoutMs?: number;
39
44
  variables?: StagehandVariables;
40
- config?: JsonObject;
41
- options?: JsonObject;
45
+ executionModel?: V1AiModelSelection;
46
+ systemPrompt?: string;
47
+ highlightCursor?: boolean;
42
48
  }
43
- export interface BrowserUseAgentOptions extends RuntimeAgentCommonOptions {
49
+ export interface BrowserUseAgentOptions extends RuntimeAgentCommonOptions, AiSelectionOptions {
44
50
  instruction: string;
45
51
  maxSteps?: number;
46
- config?: JsonObject;
47
- options?: JsonObject;
52
+ extractionModel?: V1AiModelSelection;
53
+ fallbackModel?: V1AiModelSelection;
54
+ useVision?: boolean | 'auto';
55
+ visionDetailLevel?: 'low' | 'high' | 'auto';
56
+ flashMode?: boolean;
57
+ enablePlanning?: boolean;
58
+ maxFailures?: number;
59
+ stepTimeoutMs?: number;
60
+ maxActionsPerStep?: number;
61
+ maxHistoryItems?: number | null;
62
+ useThinking?: boolean;
63
+ directlyOpenUrl?: boolean;
64
+ includeAttributes?: string[];
65
+ overrideSystemMessage?: string;
66
+ extendSystemMessage?: string;
67
+ sensitiveData?: Record<string, string | Record<string, string>>;
48
68
  }
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>;
69
+ type InvocationCreateWithSchema<T extends V1RuntimeInvocationCreateRequest> = Omit<T, 'outputSchema'> & {
70
+ schema?: JsonSchemaLike;
71
+ };
72
+ type ExtractInvocationCreateRequest = Extract<V1RuntimeInvocationCreateRequest, {
73
+ action: 'extract';
74
+ }>;
75
+ type StagehandAgentInvocationCreateRequest = Extract<V1RuntimeInvocationCreateRequest, {
76
+ action: 'stagehandAgent';
77
+ }>;
78
+ type BrowserUseInvocationCreateRequest = Extract<V1RuntimeInvocationCreateRequest, {
79
+ action: 'browserUse';
80
+ }>;
81
+ type InvocationCreateSchemaInput = InvocationCreateWithSchema<ExtractInvocationCreateRequest> | InvocationCreateWithSchema<StagehandAgentInvocationCreateRequest> | InvocationCreateWithSchema<BrowserUseInvocationCreateRequest>;
82
+ export type V1RuntimeInvocationCreateInput = Exclude<V1RuntimeInvocationCreateRequest, ExtractInvocationCreateRequest | StagehandAgentInvocationCreateRequest | BrowserUseInvocationCreateRequest> | InvocationCreateSchemaInput;
83
+ export interface V1InvocationWaitOptions extends V1InvocationWaitRequest {
84
+ signal?: AbortSignal;
57
85
  }
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>;
86
+ export interface V1InvocationCreateAndWaitOptions extends V1IdempotencyOptions {
87
+ /**
88
+ * Overall client-side wait budget across repeated long-poll requests.
89
+ * The server-side invocation timeout still belongs in the invocation body.
90
+ */
91
+ timeoutMs?: number;
92
+ /**
93
+ * Per-request long-poll timeout sent to the wait endpoint.
94
+ */
95
+ pollTimeoutMs?: number;
96
+ signal?: AbortSignal;
64
97
  }
65
- export declare class V1RuntimeInvocationsClient {
98
+ export declare class V1RuntimeInvocationsNamespaceClient {
66
99
  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>;
100
+ readonly stagehand: V1RuntimeStagehandInvocationsNamespaceClient;
101
+ readonly browserUse: V1RuntimeBrowserUseInvocationsNamespaceClient;
102
+ constructor(http: V1HttpClient);
103
+ create(runtimeId: string, request: V1RuntimeInvocationCreateInput, options?: V1IdempotencyOptions): Promise<V1Invocation>;
104
+ wait(runtimeId: string, invocationId: string, request?: V1InvocationWaitOptions): Promise<V1InvocationWaitResponse>;
105
+ cancel(runtimeId: string, invocationId: string): Promise<V1Invocation>;
106
+ createAndWait(runtimeId: string, request: V1RuntimeInvocationCreateInput, options?: V1InvocationCreateAndWaitOptions): Promise<V1Invocation>;
72
107
  }
73
- export declare class V1RuntimeStagehandInvocationsClient {
108
+ export declare class V1RuntimeStagehandInvocationsNamespaceClient {
74
109
  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>;
110
+ constructor(invocations: V1RuntimeInvocationsNamespaceClient);
111
+ act(runtimeId: string, options: StagehandActOptions): Promise<V1Invocation>;
112
+ observe(runtimeId: string, options: StagehandObserveOptions): Promise<V1Invocation>;
113
+ extract<TSchema extends JsonSchemaLike | undefined = undefined>(runtimeId: string, options: StagehandExtractOptions<TSchema>): Promise<V1Invocation>;
114
+ agent(runtimeId: string, options: StagehandAgentOptions): Promise<V1Invocation>;
80
115
  }
81
- export declare class V1RuntimeBrowserUseInvocationsClient {
116
+ export declare class V1RuntimeBrowserUseInvocationsNamespaceClient {
82
117
  private readonly invocations;
83
- constructor(invocations: V1RuntimeInvocationsClient);
84
- agent(options: BrowserUseAgentOptions): Promise<V1InvocationResource>;
118
+ constructor(invocations: V1RuntimeInvocationsNamespaceClient);
119
+ agent(runtimeId: string, options: BrowserUseAgentOptions): Promise<V1Invocation>;
85
120
  }
86
121
  export {};
@@ -1,55 +1,40 @@
1
- export class V1InvocationResource {
2
- http;
3
- data;
4
- constructor(http, data) {
5
- this.http = http;
6
- this.data = data;
7
- }
8
- get id() {
9
- return this.data.id;
10
- }
11
- refresh() {
12
- return this.http
13
- .request(`/invocations/${encodeURIComponent(this.id)}`)
14
- .then((response) => response.data);
15
- }
16
- wait(request) {
17
- return this.http.request(`/invocations/${encodeURIComponent(this.id)}/wait`, {
18
- method: 'POST',
19
- body: request ?? {},
20
- });
21
- }
22
- cancel() {
23
- return this.http
24
- .request(`/invocations/${encodeURIComponent(this.id)}/cancel`, {
25
- method: 'POST',
26
- })
27
- .then((response) => response.data);
28
- }
1
+ import { v1IdempotencyHeaders } from './http.js';
2
+ import { toOutputSchema } from './schemas.js';
3
+ import { abortableSleep } from './utils.js';
4
+ // Live control is runtime-scoped; observability reads are run-scoped.
5
+ function runtimeInvocationActionPath(runtimeId, invocationId, action) {
6
+ return `/runtimes/${encodeURIComponent(runtimeId)}/invocations/${encodeURIComponent(invocationId)}/${action}`;
29
7
  }
30
- export class V1InvocationsClient {
8
+ function createRuntimeInvocation(http, runtimeId, request, options) {
9
+ return http.request(`/runtimes/${encodeURIComponent(runtimeId)}/invocations`, {
10
+ method: 'POST',
11
+ body: prepareInvocationCreateRequest(request),
12
+ headers: v1IdempotencyHeaders(options),
13
+ });
14
+ }
15
+ export class V1RuntimeInvocationsNamespaceClient {
31
16
  http;
17
+ stagehand;
18
+ browserUse;
32
19
  constructor(http) {
33
20
  this.http = http;
21
+ this.stagehand = new V1RuntimeStagehandInvocationsNamespaceClient(this);
22
+ this.browserUse = new V1RuntimeBrowserUseInvocationsNamespaceClient(this);
34
23
  }
35
- async get(id) {
36
- const response = await this.http.request(`/invocations/${encodeURIComponent(id)}`);
37
- return new V1InvocationResource(this.http, response.data);
24
+ create(runtimeId, request, options) {
25
+ return createRuntimeInvocation(this.http, runtimeId, request, options);
38
26
  }
39
- wait(id, request) {
40
- return this.http.request(`/invocations/${encodeURIComponent(id)}/wait`, {
41
- method: 'POST',
42
- body: request ?? {},
43
- });
27
+ wait(runtimeId, invocationId, request = {}) {
28
+ return new V1RuntimeInvocationsClient(this.http, runtimeId).wait(invocationId, request);
44
29
  }
45
- async cancel(id) {
46
- const response = await this.http.request(`/invocations/${encodeURIComponent(id)}/cancel`, {
47
- method: 'POST',
48
- });
49
- return new V1InvocationResource(this.http, response.data);
30
+ cancel(runtimeId, invocationId) {
31
+ return new V1RuntimeInvocationsClient(this.http, runtimeId).cancel(invocationId);
32
+ }
33
+ createAndWait(runtimeId, request, options = {}) {
34
+ return new V1RuntimeInvocationsClient(this.http, runtimeId).createAndWait(request, options);
50
35
  }
51
36
  }
52
- export class V1RuntimeInvocationsClient {
37
+ class V1RuntimeInvocationsClient {
53
38
  http;
54
39
  runtimeId;
55
40
  stagehand;
@@ -60,100 +45,154 @@ export class V1RuntimeInvocationsClient {
60
45
  this.stagehand = new V1RuntimeStagehandInvocationsClient(this);
61
46
  this.browserUse = new V1RuntimeBrowserUseInvocationsClient(this);
62
47
  }
63
- async create(request) {
64
- const response = await this.http.request(`/runtimes/${encodeURIComponent(this.runtimeId)}/invocations`, {
48
+ async create(request, options) {
49
+ return createRuntimeInvocation(this.http, this.runtimeId, request, options);
50
+ }
51
+ wait(invocationId, request = {}) {
52
+ const { signal, ...body } = request;
53
+ return this.http.request(runtimeInvocationActionPath(this.runtimeId, invocationId, 'wait'), {
65
54
  method: 'POST',
66
- body: request,
55
+ body,
56
+ signal,
67
57
  });
68
- return new V1InvocationResource(this.http, response.data);
58
+ }
59
+ cancel(invocationId) {
60
+ return this.http.request(runtimeInvocationActionPath(this.runtimeId, invocationId, 'cancel'), {
61
+ method: 'POST',
62
+ });
63
+ }
64
+ async createAndWait(request, options = {}) {
65
+ const invocation = await this.create(request, options);
66
+ return waitForInvocation(this, invocation.id, options);
69
67
  }
70
68
  }
71
- export class V1RuntimeStagehandInvocationsClient {
69
+ class V1RuntimeStagehandInvocationsClient {
72
70
  invocations;
73
71
  constructor(invocations) {
74
72
  this.invocations = invocations;
75
73
  }
76
74
  act(options) {
77
- const { instruction, timeoutMs, ...common } = options;
78
75
  return this.invocations.create({
79
- provider: 'stagehand',
80
- method: 'act',
81
- ...common,
82
- input: {
83
- instruction,
84
- ...(timeoutMs !== undefined ? { timeoutMs } : {}),
85
- },
76
+ action: 'act',
77
+ ...options,
86
78
  });
87
79
  }
88
80
  observe(options) {
89
- const { instruction, selector, timeoutMs, ...common } = options;
90
81
  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
- },
82
+ action: 'observe',
83
+ ...options,
99
84
  });
100
85
  }
101
86
  extract(options) {
102
- const { instruction, schema, ...common } = options;
87
+ const { schema, ...common } = options;
103
88
  return this.invocations.create({
104
- provider: 'stagehand',
105
- method: 'extract',
89
+ action: 'extract',
106
90
  ...common,
107
- input: { instruction },
108
- ...(schema !== undefined ? { outputSchema: toJsonSchemaObject(schema) } : {}),
91
+ ...(schema !== undefined
92
+ ? { outputSchema: toOutputSchema(schema, 'Stagehand extract schema') }
93
+ : {}),
109
94
  });
110
95
  }
111
96
  agent(options) {
112
- const { instruction, maxSteps, timeoutMs, variables, config, options: agentOptions, ...common } = options;
113
97
  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 } : {}),
98
+ action: 'stagehandAgent',
99
+ ...options,
125
100
  });
126
101
  }
127
102
  }
128
- export class V1RuntimeBrowserUseInvocationsClient {
103
+ class V1RuntimeBrowserUseInvocationsClient {
129
104
  invocations;
130
105
  constructor(invocations) {
131
106
  this.invocations = invocations;
132
107
  }
133
108
  agent(options) {
134
- const { instruction, maxSteps, config, options: agentOptions, ...common } = options;
135
109
  return this.invocations.create({
136
- provider: 'browserUse',
137
- method: 'agent',
110
+ action: 'browserUse',
111
+ ...options,
112
+ });
113
+ }
114
+ }
115
+ export class V1RuntimeStagehandInvocationsNamespaceClient {
116
+ invocations;
117
+ constructor(invocations) {
118
+ this.invocations = invocations;
119
+ }
120
+ act(runtimeId, options) {
121
+ return this.invocations.create(runtimeId, {
122
+ action: 'act',
123
+ ...options,
124
+ });
125
+ }
126
+ observe(runtimeId, options) {
127
+ return this.invocations.create(runtimeId, {
128
+ action: 'observe',
129
+ ...options,
130
+ });
131
+ }
132
+ extract(runtimeId, options) {
133
+ const { schema, ...common } = options;
134
+ return this.invocations.create(runtimeId, {
135
+ action: 'extract',
138
136
  ...common,
139
- input: {
140
- instruction,
141
- ...(maxSteps !== undefined ? { maxSteps } : {}),
142
- },
143
- ...(config !== undefined ? { config } : {}),
144
- ...(agentOptions !== undefined ? { options: agentOptions } : {}),
137
+ ...(schema !== undefined
138
+ ? { outputSchema: toOutputSchema(schema, 'Stagehand extract schema') }
139
+ : {}),
140
+ });
141
+ }
142
+ agent(runtimeId, options) {
143
+ return this.invocations.create(runtimeId, {
144
+ action: 'stagehandAgent',
145
+ ...options,
146
+ });
147
+ }
148
+ }
149
+ export class V1RuntimeBrowserUseInvocationsNamespaceClient {
150
+ invocations;
151
+ constructor(invocations) {
152
+ this.invocations = invocations;
153
+ }
154
+ agent(runtimeId, options) {
155
+ return this.invocations.create(runtimeId, {
156
+ action: 'browserUse',
157
+ ...options,
145
158
  });
146
159
  }
147
160
  }
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;
161
+ function prepareInvocationCreateRequest(request) {
162
+ if (!hasInvocationSchema(request)) {
163
+ return request;
164
+ }
165
+ const { schema, ...body } = request;
166
+ return {
167
+ ...body,
168
+ outputSchema: toOutputSchema(schema, 'Invocation schema'),
169
+ };
156
170
  }
157
- function isJsonObject(value) {
158
- return value !== null && typeof value === 'object' && !Array.isArray(value);
171
+ function hasInvocationSchema(request) {
172
+ return 'schema' in request && request.schema !== undefined;
173
+ }
174
+ async function waitForInvocation(client, invocationId, options) {
175
+ const deadline = options.timeoutMs === undefined ? undefined : Date.now() + options.timeoutMs;
176
+ for (;;) {
177
+ if (deadline !== undefined && Date.now() >= deadline) {
178
+ throw new Error(`Invocation ${invocationId} did not finish before timeout`);
179
+ }
180
+ const remaining = deadline === undefined ? undefined : Math.max(1, deadline - Date.now());
181
+ const timeoutMs = options.pollTimeoutMs === undefined
182
+ ? remaining
183
+ : remaining === undefined
184
+ ? options.pollTimeoutMs
185
+ : Math.min(options.pollTimeoutMs, remaining);
186
+ const result = await client.wait(invocationId, {
187
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
188
+ signal: options.signal,
189
+ });
190
+ if (result.waitStatus === 'completed') {
191
+ return result;
192
+ }
193
+ const sleepMs = deadline === undefined
194
+ ? (result.retryAfterMs ?? 1000)
195
+ : Math.min(result.retryAfterMs ?? 1000, Math.max(0, deadline - Date.now()));
196
+ await abortableSleep(sleepMs, options.signal);
197
+ }
159
198
  }
package/dist/node.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { BctrlV1 } from './bctrl.js';
2
+ import type { V1ToolCreateRequest, V1ToolVersionCreateRequest } from './types.js';
3
+ type V1HostedToolCreateRequest = Extract<V1ToolCreateRequest, {
4
+ type: 'hosted';
5
+ }>;
6
+ export declare function createHostedToolFromFile(client: BctrlV1, request: Omit<V1HostedToolCreateRequest, 'source'> & {
7
+ filePath: string;
8
+ }): Promise<import("./types.js").V1Tool>;
9
+ export declare function createToolVersionFromFile(client: BctrlV1, toolId: string, request: Omit<V1ToolVersionCreateRequest, 'source'> & {
10
+ filePath: string;
11
+ }): Promise<import("./types.js").V1ToolVersion>;
12
+ export {};
package/dist/node.js ADDED
@@ -0,0 +1,11 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ export async function createHostedToolFromFile(client, request) {
3
+ const source = await readFile(request.filePath, 'utf8');
4
+ const { filePath: _filePath, ...rest } = request;
5
+ return client.tools.create({ ...rest, source });
6
+ }
7
+ export async function createToolVersionFromFile(client, toolId, request) {
8
+ const source = await readFile(request.filePath, 'utf8');
9
+ const { filePath: _filePath, ...rest } = request;
10
+ return client.tools.createVersion(toolId, { ...rest, source });
11
+ }
@@ -0,0 +1,21 @@
1
+ import type { V1HttpClient } from './http.js';
2
+ import type { V1ListEnvelope, V1Proxy, V1ProxyCreateRequest, V1ProxyDeleteResponse, V1ProxyListQuery, V1ProxyPool, V1ProxyPoolListQuery, V1ProxyTestResponse, V1ProxyUpdateRequest } from './types.js';
3
+ export declare class V1ProxyPoolsClient {
4
+ private readonly http;
5
+ constructor(http: V1HttpClient);
6
+ list(query?: V1ProxyPoolListQuery): Promise<V1ListEnvelope<V1ProxyPool>>;
7
+ iter(query?: V1ProxyPoolListQuery): AsyncGenerator<V1ProxyPool, void, undefined>;
8
+ get(poolId: string): Promise<V1ProxyPool>;
9
+ }
10
+ export declare class V1ProxiesClient {
11
+ private readonly http;
12
+ readonly pools: V1ProxyPoolsClient;
13
+ constructor(http: V1HttpClient);
14
+ list(query?: V1ProxyListQuery): Promise<V1ListEnvelope<V1Proxy>>;
15
+ iter(query?: V1ProxyListQuery): AsyncGenerator<V1Proxy, void, undefined>;
16
+ create(request: V1ProxyCreateRequest): Promise<V1Proxy>;
17
+ get(proxyId: string): Promise<V1Proxy>;
18
+ update(proxyId: string, request: V1ProxyUpdateRequest): Promise<V1Proxy>;
19
+ test(proxyId: string): Promise<V1ProxyTestResponse>;
20
+ delete(proxyId: string): Promise<V1ProxyDeleteResponse>;
21
+ }
@@ -0,0 +1,55 @@
1
+ import { iterateV1Pages } from './pagination.js';
2
+ export class V1ProxyPoolsClient {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ list(query = {}) {
8
+ return this.http.request('/proxies/pools', { query });
9
+ }
10
+ iter(query = {}) {
11
+ return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
12
+ }
13
+ get(poolId) {
14
+ return this.http.request(`/proxies/pools/${encodeURIComponent(poolId)}`);
15
+ }
16
+ }
17
+ export class V1ProxiesClient {
18
+ http;
19
+ pools;
20
+ constructor(http) {
21
+ this.http = http;
22
+ this.pools = new V1ProxyPoolsClient(http);
23
+ }
24
+ list(query = {}) {
25
+ return this.http.request('/proxies', { query });
26
+ }
27
+ iter(query = {}) {
28
+ return iterateV1Pages(query, (pageQuery) => this.list(pageQuery));
29
+ }
30
+ create(request) {
31
+ return this.http.request('/proxies', {
32
+ method: 'POST',
33
+ body: request,
34
+ });
35
+ }
36
+ get(proxyId) {
37
+ return this.http.request(`/proxies/${encodeURIComponent(proxyId)}`);
38
+ }
39
+ update(proxyId, request) {
40
+ return this.http.request(`/proxies/${encodeURIComponent(proxyId)}`, {
41
+ method: 'PATCH',
42
+ body: request,
43
+ });
44
+ }
45
+ test(proxyId) {
46
+ return this.http.request(`/proxies/${encodeURIComponent(proxyId)}/test`, {
47
+ method: 'POST',
48
+ });
49
+ }
50
+ delete(proxyId) {
51
+ return this.http.request(`/proxies/${encodeURIComponent(proxyId)}`, {
52
+ method: 'DELETE',
53
+ });
54
+ }
55
+ }