@boxline/sdk 1.1.0
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/CHANGELOG.md +187 -0
- package/LICENSE +21 -0
- package/README.md +495 -0
- package/dist/client.d.ts +529 -0
- package/dist/client.js +874 -0
- package/dist/client.js.map +1 -0
- package/dist/core.d.ts +77 -0
- package/dist/core.js +223 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.d.ts +300 -0
- package/dist/errors.js +403 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination.d.ts +34 -0
- package/dist/pagination.js +67 -0
- package/dist/pagination.js.map +1 -0
- package/dist/session.d.ts +252 -0
- package/dist/session.js +345 -0
- package/dist/session.js.map +1 -0
- package/dist/streaming.d.ts +7 -0
- package/dist/streaming.js +71 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.d.ts +2147 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/webhooks.d.ts +27 -0
- package/dist/webhooks.js +184 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +59 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors. Every failed call throws a BoxlineError (or a subclass) with the HTTP status, the API's stable
|
|
3
|
+
* snake_case `code`, a message for people, the API's `requestId` to quote when asking for support, and your own
|
|
4
|
+
* `clientRequestId` if you sent one.
|
|
5
|
+
*/
|
|
6
|
+
/** Stable error codes the SDK gives its own class to (docs/CONTRACT.md "Errors"). */
|
|
7
|
+
export const ErrorCode = {
|
|
8
|
+
rateLimited: "rate_limited",
|
|
9
|
+
concurrencyLimit: "concurrency_limit",
|
|
10
|
+
featureNotInPlan: "feature_not_in_plan",
|
|
11
|
+
projectSuspended: "project_suspended",
|
|
12
|
+
idempotencyMismatch: "idempotency_mismatch",
|
|
13
|
+
idempotencyInProgress: "idempotency_in_progress",
|
|
14
|
+
invalidCursor: "invalid_cursor",
|
|
15
|
+
captchaTimeout: "captcha_timeout",
|
|
16
|
+
pageUnreachable: "page_unreachable",
|
|
17
|
+
pageTimeout: "page_timeout",
|
|
18
|
+
notAWebPage: "not_a_web_page",
|
|
19
|
+
modelRefused: "model_refused",
|
|
20
|
+
searchUnavailable: "search_unavailable",
|
|
21
|
+
outOfViewport: "out_of_viewport",
|
|
22
|
+
webhookUrlNotAllowed: "webhook_url_not_allowed",
|
|
23
|
+
webhooksUnavailable: "webhooks_unavailable",
|
|
24
|
+
webhookDisabled: "webhook_disabled",
|
|
25
|
+
payloadExpired: "payload_expired",
|
|
26
|
+
/** A delivery's errorCode (never an HTTP error): the project already had 10,000 deliveries waiting. */
|
|
27
|
+
queueFull: "queue_full",
|
|
28
|
+
invalidSignature: "invalid_signature",
|
|
29
|
+
variablesWithExtensions: "variables_with_extensions",
|
|
30
|
+
extensionDenied: "extension_denied",
|
|
31
|
+
crossSiteRequest: "cross_site_request",
|
|
32
|
+
invalidExtension: "invalid_extension",
|
|
33
|
+
payloadTooLarge: "payload_too_large",
|
|
34
|
+
limitReached: "limit_reached",
|
|
35
|
+
missingVariables: "missing_variables",
|
|
36
|
+
planLimit: "plan_limit",
|
|
37
|
+
tooManySecretValues: "too_many_secret_values",
|
|
38
|
+
secretExists: "secret_exists",
|
|
39
|
+
secretNotForAi: "secret_not_for_ai",
|
|
40
|
+
secretNotForShell: "secret_not_for_shell",
|
|
41
|
+
machineTooOld: "machine_too_old",
|
|
42
|
+
/**
|
|
43
|
+
* An agent or task run's errorCode (never an HTTP error): the answer did not match the run's output schema after the
|
|
44
|
+
* repair try (the run's `error` lists the problems).
|
|
45
|
+
*/
|
|
46
|
+
outputInvalid: "output_invalid",
|
|
47
|
+
/**
|
|
48
|
+
* Agent-run errorCodes (never HTTP errors) for a run that stopped at one of its limits and can be continued
|
|
49
|
+
* (agent.continueRun) while its `continuable` is set: its maxSteps, its maxCostUsd, maxConsecutiveErrors tool errors in
|
|
50
|
+
* a row, or the same call with the same result 5 times in a row.
|
|
51
|
+
*/
|
|
52
|
+
maxSteps: "max_steps",
|
|
53
|
+
maxCost: "max_cost",
|
|
54
|
+
tooManyErrors: "too_many_errors",
|
|
55
|
+
noProgress: "no_progress",
|
|
56
|
+
/**
|
|
57
|
+
* Agent-run errorCode (continuable like the limits): the API server running the loop stopped (a restart, a deploy)
|
|
58
|
+
* while its session went on; agent.continueRun picks it up in the same browser.
|
|
59
|
+
*/
|
|
60
|
+
serverRestarted: "server_restarted",
|
|
61
|
+
/** Agent-run errorCodes: its session reached its time limit, or ended another way, while it worked (not continuable). */
|
|
62
|
+
sessionTimeout: "session_timeout",
|
|
63
|
+
sessionEnded: "session_ended",
|
|
64
|
+
/** 409: agent.continueRun on a run that did not stop at a limit, was continued already, or whose window passed. */
|
|
65
|
+
notContinuable: "not_continuable",
|
|
66
|
+
/** 409: agent.sendMessage after 50 messages to one run. */
|
|
67
|
+
tooManyMessages: "too_many_messages",
|
|
68
|
+
/** 409: takeover, handBack or sendMessage on a run whose server stopped (continue it instead). */
|
|
69
|
+
runNotLive: "run_not_live",
|
|
70
|
+
/** 400: project.setModelKey when the provider does not accept the key (nothing is saved). */
|
|
71
|
+
invalidModelKey: "invalid_model_key",
|
|
72
|
+
/** 400: a call on the project's own model key was refused by the provider (a run ends with this errorCode); never falls back to Boxline's key. */
|
|
73
|
+
modelKeyRejected: "model_key_rejected",
|
|
74
|
+
/** 502: another failure of a call on the project's own model key (the provider's text, key scrubbed). */
|
|
75
|
+
modelError: "model_error",
|
|
76
|
+
/** 413: contexts.create({fromSession}) when the session's cookies and site storage exceed 16 MB. */
|
|
77
|
+
contextTooLarge: "context_too_large",
|
|
78
|
+
/** 409: the session has ended (e.g. an agent run or continueRun in it). */
|
|
79
|
+
sessionNotRunning: "session_not_running",
|
|
80
|
+
unauthorized: "unauthorized",
|
|
81
|
+
notFound: "not_found",
|
|
82
|
+
connectionError: "connection_error",
|
|
83
|
+
timeout: "timeout",
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* 5xx answers that are not the platform's own trouble, so they are not retried by themselves: configuration (a model
|
|
87
|
+
* provider, proxies or webhook delivery not set up), and a page that could not be loaded (fix the address; a page_timeout may be worth
|
|
88
|
+
* one more try of your own, with a longer timeoutMs).
|
|
89
|
+
*/
|
|
90
|
+
const NOT_RETRYABLE = new Set(["provider_unavailable", "proxy_unavailable", "webhooks_unavailable", "page_unreachable", "page_timeout", "not_a_web_page"]);
|
|
91
|
+
export class BoxlineError extends Error {
|
|
92
|
+
status;
|
|
93
|
+
code;
|
|
94
|
+
/** The API's id for the request: quote it when asking for support. */
|
|
95
|
+
requestId;
|
|
96
|
+
/** Your own id for the request, if you sent one (RequestOptions.clientRequestId). */
|
|
97
|
+
clientRequestId;
|
|
98
|
+
/** Response headers (RateLimit-*, Retry-After, …); undefined when no response came back. */
|
|
99
|
+
headers;
|
|
100
|
+
body;
|
|
101
|
+
constructor(status, code, message, details = {}) {
|
|
102
|
+
super(message, details.cause === undefined ? undefined : { cause: details.cause });
|
|
103
|
+
this.name = "BoxlineError";
|
|
104
|
+
this.status = status;
|
|
105
|
+
this.code = code;
|
|
106
|
+
this.requestId = details.requestId ?? null;
|
|
107
|
+
this.clientRequestId = details.clientRequestId ?? null;
|
|
108
|
+
this.headers = details.headers;
|
|
109
|
+
this.body = details.body;
|
|
110
|
+
}
|
|
111
|
+
/** Whether trying the same call again later can succeed (rate limits, server errors, network trouble). */
|
|
112
|
+
get retryable() {
|
|
113
|
+
if (this.code === ErrorCode.idempotencyInProgress)
|
|
114
|
+
return true;
|
|
115
|
+
// Search not set up is for good; the provider rate limiting the platform says when to come back.
|
|
116
|
+
if (this.code === ErrorCode.searchUnavailable)
|
|
117
|
+
return retryAfterSeconds(this.headers) !== null;
|
|
118
|
+
if (NOT_RETRYABLE.has(this.code))
|
|
119
|
+
return false;
|
|
120
|
+
return this.status === 429 || (this.status >= 500 && this.status !== 501);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** 429: too many requests (`rate_limited`) or all of the plan's concurrent sessions in use (`concurrency_limit`). */
|
|
124
|
+
export class RateLimitError extends BoxlineError {
|
|
125
|
+
/** Seconds the server asked to wait (Retry-After), when it said. */
|
|
126
|
+
retryAfter;
|
|
127
|
+
constructor(status, code, message, details = {}) {
|
|
128
|
+
super(status, code, message, details);
|
|
129
|
+
this.name = "RateLimitError";
|
|
130
|
+
this.retryAfter = retryAfterSeconds(details.headers);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** 402 `feature_not_in_plan`: the project's plan does not include this. */
|
|
134
|
+
export class FeatureNotInPlanError extends BoxlineError {
|
|
135
|
+
name = "FeatureNotInPlanError";
|
|
136
|
+
}
|
|
137
|
+
/** 403 `project_suspended`: an admin suspended the project; the message says why. */
|
|
138
|
+
export class ProjectSuspendedError extends BoxlineError {
|
|
139
|
+
name = "ProjectSuspendedError";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 422 `idempotency_mismatch`: this Idempotency-Key was already used for a different request (another body or route),
|
|
143
|
+
* or, for a new API key, by another caller (another API key or console login).
|
|
144
|
+
*/
|
|
145
|
+
export class IdempotencyMismatchError extends BoxlineError {
|
|
146
|
+
name = "IdempotencyMismatchError";
|
|
147
|
+
}
|
|
148
|
+
/** 409 `idempotency_in_progress`: the first request with this key is still being answered (retried automatically). */
|
|
149
|
+
export class IdempotencyInProgressError extends BoxlineError {
|
|
150
|
+
name = "IdempotencyInProgressError";
|
|
151
|
+
}
|
|
152
|
+
/** 400 `invalid_cursor`: `after` is not a `next` value of that list. */
|
|
153
|
+
export class InvalidCursorError extends BoxlineError {
|
|
154
|
+
name = "InvalidCursorError";
|
|
155
|
+
}
|
|
156
|
+
/** `captcha_timeout`: a CAPTCHA kept waiting for a person (a plain-English step, or waitForHuman). */
|
|
157
|
+
export class CaptchaTimeoutError extends BoxlineError {
|
|
158
|
+
name = "CaptchaTimeoutError";
|
|
159
|
+
}
|
|
160
|
+
/** 502 `page_unreachable` (fetch, screenshot, pdf, extract): the page could not be loaded; the message says why. */
|
|
161
|
+
export class PageUnreachableError extends BoxlineError {
|
|
162
|
+
name = "PageUnreachableError";
|
|
163
|
+
}
|
|
164
|
+
/** 504 `page_timeout` (fetch, screenshot, pdf, extract): the page did not finish loading within `timeoutMs`. */
|
|
165
|
+
export class PageTimeoutError extends BoxlineError {
|
|
166
|
+
name = "PageTimeoutError";
|
|
167
|
+
}
|
|
168
|
+
/** 422 `not_a_web_page` (fetch, extract, search, crawl): the address is a file Chrome only displays (a PDF), with no page text. */
|
|
169
|
+
export class NotAWebPageError extends BoxlineError {
|
|
170
|
+
name = "NotAWebPageError";
|
|
171
|
+
}
|
|
172
|
+
/** 422 `model_refused` (extract): the model declined to extract from these pages. */
|
|
173
|
+
export class ModelRefusedError extends BoxlineError {
|
|
174
|
+
name = "ModelRefusedError";
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 503 `search_unavailable`: web search is not set up on this server, or its provider did not answer or is limiting
|
|
178
|
+
* the platform (then `retryable`, with Retry-After).
|
|
179
|
+
*/
|
|
180
|
+
export class SearchUnavailableError extends BoxlineError {
|
|
181
|
+
name = "SearchUnavailableError";
|
|
182
|
+
}
|
|
183
|
+
/** 400 `out_of_viewport`: a mouse action's point is outside the page (or the computer-use screenshot). */
|
|
184
|
+
export class OutOfViewportError extends BoxlineError {
|
|
185
|
+
name = "OutOfViewportError";
|
|
186
|
+
}
|
|
187
|
+
/** 400 `webhook_url_not_allowed`: webhook endpoints must be public HTTPS addresses (the message says what is wrong). */
|
|
188
|
+
export class WebhookUrlNotAllowedError extends BoxlineError {
|
|
189
|
+
name = "WebhookUrlNotAllowedError";
|
|
190
|
+
}
|
|
191
|
+
/** 503 `webhooks_unavailable`: webhook delivery is not set up on this server. */
|
|
192
|
+
export class WebhooksUnavailableError extends BoxlineError {
|
|
193
|
+
name = "WebhooksUnavailableError";
|
|
194
|
+
}
|
|
195
|
+
/** 409 `webhook_disabled`: the endpoint is switched off; turn it on (update enabled: true) first. */
|
|
196
|
+
export class WebhookDisabledError extends BoxlineError {
|
|
197
|
+
name = "WebhookDisabledError";
|
|
198
|
+
}
|
|
199
|
+
/** 409 `payload_expired`: the event's body is kept 7 days; that delivery can no longer be sent again. */
|
|
200
|
+
export class PayloadExpiredError extends BoxlineError {
|
|
201
|
+
name = "PayloadExpiredError";
|
|
202
|
+
}
|
|
203
|
+
/** 400 `variables_with_extensions`: an agent run with variables in a session with extensions (see allowWithExtensions). */
|
|
204
|
+
export class VariablesWithExtensionsError extends BoxlineError {
|
|
205
|
+
name = "VariablesWithExtensionsError";
|
|
206
|
+
}
|
|
207
|
+
/** 403 `extension_denied`: the operator does not allow this extension. */
|
|
208
|
+
export class ExtensionDeniedError extends BoxlineError {
|
|
209
|
+
name = "ExtensionDeniedError";
|
|
210
|
+
}
|
|
211
|
+
/** 403 `cross_site_request`: a console-login upload that did not come from the platform's own sites. */
|
|
212
|
+
export class CrossSiteRequestError extends BoxlineError {
|
|
213
|
+
name = "CrossSiteRequestError";
|
|
214
|
+
}
|
|
215
|
+
/** 400 `invalid_extension`: the zip is not an acceptable Manifest V3 extension (the message says why). */
|
|
216
|
+
export class InvalidExtensionError extends BoxlineError {
|
|
217
|
+
name = "InvalidExtensionError";
|
|
218
|
+
}
|
|
219
|
+
/** 413 `payload_too_large`: the body is larger than the route allows (an extension zip: 10 MB). */
|
|
220
|
+
export class PayloadTooLargeError extends BoxlineError {
|
|
221
|
+
name = "PayloadTooLargeError";
|
|
222
|
+
}
|
|
223
|
+
/** 409 `limit_reached`: the project has as many as it may (e.g. 100 extensions). */
|
|
224
|
+
export class LimitReachedError extends BoxlineError {
|
|
225
|
+
name = "LimitReachedError";
|
|
226
|
+
}
|
|
227
|
+
/** 400 `missing_variables`: a task run (or its schedule) has no value for a variable without a default; the message names them. */
|
|
228
|
+
export class MissingVariablesError extends BoxlineError {
|
|
229
|
+
name = "MissingVariablesError";
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* `plan_limit`: the plan allows no more of this (402: tasks, schedules switched on, searches on Free, project
|
|
233
|
+
* secrets beyond `maxSecrets`, a session longer than the plan allows); the message says the limit.
|
|
234
|
+
*/
|
|
235
|
+
export class PlanLimitError extends BoxlineError {
|
|
236
|
+
name = "PlanLimitError";
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* 409 `too_many_secret_values`: the session already hides as many earlier secret values in its output as it can (256
|
|
240
|
+
* values or 256 KB); a session create, exec, agent run or step adding more is refused. Start a new session.
|
|
241
|
+
*/
|
|
242
|
+
export class TooManySecretValuesError extends BoxlineError {
|
|
243
|
+
name = "TooManySecretValuesError";
|
|
244
|
+
}
|
|
245
|
+
/** 409 `secret_exists`: the project has a secret with that name; change it with secrets.update. */
|
|
246
|
+
export class SecretExistsError extends BoxlineError {
|
|
247
|
+
name = "SecretExistsError";
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 400 `secret_not_for_ai` / `secret_not_for_shell`: the secret's scope does not allow this use (scope "shell" is not for
|
|
251
|
+
* the AI; a secret goes into a shell only with scope "shell" or "all", or shell: true).
|
|
252
|
+
*/
|
|
253
|
+
export class SecretNotAllowedError extends BoxlineError {
|
|
254
|
+
name = "SecretNotAllowedError";
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 409 `machine_too_old`: the session's machine comes from an image older than the API (during a deploy) and cannot take
|
|
258
|
+
* `env` or `secrets`; start a new session.
|
|
259
|
+
*/
|
|
260
|
+
export class MachineTooOldError extends BoxlineError {
|
|
261
|
+
name = "MachineTooOldError";
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 409 `not_continuable`: agent.continueRun on a run that did not stop at one of its limits, was already continued (the
|
|
265
|
+
* message names the run that did), or whose continue window has passed.
|
|
266
|
+
*/
|
|
267
|
+
export class NotContinuableError extends BoxlineError {
|
|
268
|
+
name = "NotContinuableError";
|
|
269
|
+
}
|
|
270
|
+
/** 409 `too_many_messages`: a run takes at most 50 messages (agent.sendMessage). */
|
|
271
|
+
export class TooManyMessagesError extends BoxlineError {
|
|
272
|
+
name = "TooManyMessagesError";
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* 409 `run_not_live`: agent.takeover, handBack or sendMessage on a run whose API server stopped (a restart, a deploy):
|
|
276
|
+
* no loop is left to act on it. Continue it (agent.continueRun) once it shows as failed with `server_restarted`.
|
|
277
|
+
*/
|
|
278
|
+
export class RunNotLiveError extends BoxlineError {
|
|
279
|
+
name = "RunNotLiveError";
|
|
280
|
+
}
|
|
281
|
+
/** 409 `session_not_running`: the session has ended (an agent run started or continued in it, a command, …). */
|
|
282
|
+
export class SessionNotRunningError extends BoxlineError {
|
|
283
|
+
name = "SessionNotRunningError";
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* verifyWebhook refused a delivery (not an API error: answer the sender 400). `reason`: the Boxline-Signature header
|
|
287
|
+
* is missing or malformed, its timestamp is too far from now (a replay), or no signature matches the secret(s).
|
|
288
|
+
*/
|
|
289
|
+
export class WebhookSignatureError extends BoxlineError {
|
|
290
|
+
reason;
|
|
291
|
+
constructor(reason, message) {
|
|
292
|
+
super(400, ErrorCode.invalidSignature, message);
|
|
293
|
+
this.name = "WebhookSignatureError";
|
|
294
|
+
this.reason = reason;
|
|
295
|
+
}
|
|
296
|
+
get retryable() {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/** 401: missing or invalid API key. */
|
|
301
|
+
export class AuthenticationError extends BoxlineError {
|
|
302
|
+
name = "AuthenticationError";
|
|
303
|
+
}
|
|
304
|
+
/** 404: no such thing in this project. */
|
|
305
|
+
export class NotFoundError extends BoxlineError {
|
|
306
|
+
name = "NotFoundError";
|
|
307
|
+
}
|
|
308
|
+
/** No response: the network failed or the server went away (retried automatically where safe). */
|
|
309
|
+
export class BoxlineConnectionError extends BoxlineError {
|
|
310
|
+
constructor(message, details = {}) {
|
|
311
|
+
super(0, ErrorCode.connectionError, message, details);
|
|
312
|
+
this.name = "BoxlineConnectionError";
|
|
313
|
+
}
|
|
314
|
+
get retryable() {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/** The request took longer than its time limit (`timeoutMs`). */
|
|
319
|
+
export class BoxlineTimeoutError extends BoxlineConnectionError {
|
|
320
|
+
constructor(message, details = {}) {
|
|
321
|
+
super(message, details);
|
|
322
|
+
this.code = ErrorCode.timeout;
|
|
323
|
+
this.name = "BoxlineTimeoutError";
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const BY_CODE = {
|
|
327
|
+
[ErrorCode.rateLimited]: RateLimitError,
|
|
328
|
+
[ErrorCode.concurrencyLimit]: RateLimitError,
|
|
329
|
+
[ErrorCode.featureNotInPlan]: FeatureNotInPlanError,
|
|
330
|
+
[ErrorCode.projectSuspended]: ProjectSuspendedError,
|
|
331
|
+
[ErrorCode.idempotencyMismatch]: IdempotencyMismatchError,
|
|
332
|
+
[ErrorCode.idempotencyInProgress]: IdempotencyInProgressError,
|
|
333
|
+
[ErrorCode.invalidCursor]: InvalidCursorError,
|
|
334
|
+
[ErrorCode.captchaTimeout]: CaptchaTimeoutError,
|
|
335
|
+
[ErrorCode.pageUnreachable]: PageUnreachableError,
|
|
336
|
+
[ErrorCode.pageTimeout]: PageTimeoutError,
|
|
337
|
+
[ErrorCode.notAWebPage]: NotAWebPageError,
|
|
338
|
+
[ErrorCode.modelRefused]: ModelRefusedError,
|
|
339
|
+
[ErrorCode.searchUnavailable]: SearchUnavailableError,
|
|
340
|
+
[ErrorCode.outOfViewport]: OutOfViewportError,
|
|
341
|
+
[ErrorCode.webhookUrlNotAllowed]: WebhookUrlNotAllowedError,
|
|
342
|
+
[ErrorCode.webhooksUnavailable]: WebhooksUnavailableError,
|
|
343
|
+
[ErrorCode.webhookDisabled]: WebhookDisabledError,
|
|
344
|
+
[ErrorCode.payloadExpired]: PayloadExpiredError,
|
|
345
|
+
[ErrorCode.variablesWithExtensions]: VariablesWithExtensionsError,
|
|
346
|
+
[ErrorCode.extensionDenied]: ExtensionDeniedError,
|
|
347
|
+
[ErrorCode.crossSiteRequest]: CrossSiteRequestError,
|
|
348
|
+
[ErrorCode.invalidExtension]: InvalidExtensionError,
|
|
349
|
+
[ErrorCode.payloadTooLarge]: PayloadTooLargeError,
|
|
350
|
+
[ErrorCode.limitReached]: LimitReachedError,
|
|
351
|
+
[ErrorCode.missingVariables]: MissingVariablesError,
|
|
352
|
+
[ErrorCode.planLimit]: PlanLimitError,
|
|
353
|
+
[ErrorCode.tooManySecretValues]: TooManySecretValuesError,
|
|
354
|
+
[ErrorCode.secretExists]: SecretExistsError,
|
|
355
|
+
[ErrorCode.secretNotForAi]: SecretNotAllowedError,
|
|
356
|
+
[ErrorCode.secretNotForShell]: SecretNotAllowedError,
|
|
357
|
+
[ErrorCode.machineTooOld]: MachineTooOldError,
|
|
358
|
+
[ErrorCode.notContinuable]: NotContinuableError,
|
|
359
|
+
[ErrorCode.tooManyMessages]: TooManyMessagesError,
|
|
360
|
+
[ErrorCode.runNotLive]: RunNotLiveError,
|
|
361
|
+
[ErrorCode.sessionNotRunning]: SessionNotRunningError,
|
|
362
|
+
};
|
|
363
|
+
const BY_STATUS = { 401: AuthenticationError, 404: NotFoundError, 429: RateLimitError };
|
|
364
|
+
/** The error class for an API error: by its code first, then by its status. */
|
|
365
|
+
export function makeError(status, code, message, details = {}) {
|
|
366
|
+
const Cls = BY_CODE[code] ?? BY_STATUS[status] ?? BoxlineError;
|
|
367
|
+
return new Cls(status, code, message, details);
|
|
368
|
+
}
|
|
369
|
+
/** Retry-After in seconds (a number of seconds or an HTTP date); null when absent or unreadable. */
|
|
370
|
+
export function retryAfterSeconds(headers) {
|
|
371
|
+
const v = headers?.get("retry-after");
|
|
372
|
+
if (v === null || v === undefined || v.trim() === "")
|
|
373
|
+
return null;
|
|
374
|
+
const n = Number(v);
|
|
375
|
+
if (Number.isFinite(n))
|
|
376
|
+
return Math.max(0, n);
|
|
377
|
+
const at = Date.parse(v);
|
|
378
|
+
return Number.isNaN(at) ? null : Math.max(0, (at - Date.now()) / 1000);
|
|
379
|
+
}
|
|
380
|
+
/** Turns an error response into a typed error. The body is read here (it is small JSON); this never throws. */
|
|
381
|
+
export async function errorFromResponse(res, method, path, sentClientId) {
|
|
382
|
+
let body;
|
|
383
|
+
let code = "http_error";
|
|
384
|
+
let message = `${method} ${path.split("?")[0]} failed with ${res.status}`;
|
|
385
|
+
let requestId = res.headers.get("x-request-id");
|
|
386
|
+
try {
|
|
387
|
+
const text = await res.text();
|
|
388
|
+
body = text ? JSON.parse(text) : undefined;
|
|
389
|
+
const err = body?.error;
|
|
390
|
+
if (typeof err?.code === "string")
|
|
391
|
+
code = err.code;
|
|
392
|
+
if (typeof err?.message === "string")
|
|
393
|
+
message = err.message;
|
|
394
|
+
if (typeof err?.requestId === "string")
|
|
395
|
+
requestId = err.requestId;
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
/* not JSON (a proxy's error page), or the body could not be read: keep the generic message */
|
|
399
|
+
}
|
|
400
|
+
const clientRequestId = res.headers.get("x-client-request-id") ?? sentClientId ?? null;
|
|
401
|
+
return makeError(res.status, code, message, { requestId, clientRequestId, headers: res.headers, body });
|
|
402
|
+
}
|
|
403
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qFAAqF;AACrF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,WAAW,EAAE,cAAc;IAC3B,gBAAgB,EAAE,mBAAmB;IACrC,gBAAgB,EAAE,qBAAqB;IACvC,gBAAgB,EAAE,mBAAmB;IACrC,mBAAmB,EAAE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AAQ;YAAE,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,8FAA8F;IAChG,CAAC;IACD,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,YAAY,IAAI,IAAI,CAAC;IACvF,OAAO,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1G,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript SDK for Boxline: isolated cloud sessions with a Chrome browser, a bash shell and a shared disk, plus
|
|
3
|
+
* web APIs (fetch, screenshot, pdf, extract, crawl, search), computer use, an AI agent and saved tasks. Works in Node 18+ and modern browsers (it
|
|
4
|
+
* uses the global fetch). The wire format is docs/CONTRACT.md and docs/openapi.yaml.
|
|
5
|
+
*/
|
|
6
|
+
export { Boxline, Auth, ProjectSettings, ApiKeys, Sessions, SessionFiles, Contexts, Crawl, Agent, Tasks, Secrets, Webhooks, Extensions, DEFAULT_BASE_URL, type BoxlineOptions, type SessionPage, type WaitOptions, } from "./client.js";
|
|
7
|
+
export { Session, type ClickOptions, type DragOptions } from "./session.js";
|
|
8
|
+
export { Page, PagePromise } from "./pagination.js";
|
|
9
|
+
export { IDEMPOTENT_POSTS, isIdempotentPost, RETRY, retryDelayMs, type RequestOptions } from "./core.js";
|
|
10
|
+
export { BoxlineError, RateLimitError, FeatureNotInPlanError, ProjectSuspendedError, IdempotencyMismatchError, IdempotencyInProgressError, InvalidCursorError, CaptchaTimeoutError, PageUnreachableError, PageTimeoutError, NotAWebPageError, ModelRefusedError, SearchUnavailableError, OutOfViewportError, WebhookUrlNotAllowedError, WebhooksUnavailableError, WebhookDisabledError, PayloadExpiredError, WebhookSignatureError, VariablesWithExtensionsError, ExtensionDeniedError, CrossSiteRequestError, InvalidExtensionError, PayloadTooLargeError, LimitReachedError, MissingVariablesError, PlanLimitError, TooManySecretValuesError, SecretExistsError, SecretNotAllowedError, MachineTooOldError, NotContinuableError, TooManyMessagesError, RunNotLiveError, SessionNotRunningError, type WebhookSignatureFailure, AuthenticationError, NotFoundError, BoxlineConnectionError, BoxlineTimeoutError, ErrorCode, makeError, } from "./errors.js";
|
|
11
|
+
export { verifyWebhook, webhookSignatureHeader, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS, type VerifyWebhookOptions } from "./webhooks.js";
|
|
12
|
+
export { VERSION } from "./version.js";
|
|
13
|
+
export type * from "./types.js";
|
|
14
|
+
export { Boxline as default } from "./client.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript SDK for Boxline: isolated cloud sessions with a Chrome browser, a bash shell and a shared disk, plus
|
|
3
|
+
* web APIs (fetch, screenshot, pdf, extract, crawl, search), computer use, an AI agent and saved tasks. Works in Node 18+ and modern browsers (it
|
|
4
|
+
* uses the global fetch). The wire format is docs/CONTRACT.md and docs/openapi.yaml.
|
|
5
|
+
*/
|
|
6
|
+
export { Boxline, Auth, ProjectSettings, ApiKeys, Sessions, SessionFiles, Contexts, Crawl, Agent, Tasks, Secrets, Webhooks, Extensions, DEFAULT_BASE_URL, } from "./client.js";
|
|
7
|
+
export { Session } from "./session.js";
|
|
8
|
+
export { Page, PagePromise } from "./pagination.js";
|
|
9
|
+
export { IDEMPOTENT_POSTS, isIdempotentPost, RETRY, retryDelayMs } from "./core.js";
|
|
10
|
+
export { BoxlineError, RateLimitError, FeatureNotInPlanError, ProjectSuspendedError, IdempotencyMismatchError, IdempotencyInProgressError, InvalidCursorError, CaptchaTimeoutError, PageUnreachableError, PageTimeoutError, NotAWebPageError, ModelRefusedError, SearchUnavailableError, OutOfViewportError, WebhookUrlNotAllowedError, WebhooksUnavailableError, WebhookDisabledError, PayloadExpiredError, WebhookSignatureError, VariablesWithExtensionsError, ExtensionDeniedError, CrossSiteRequestError, InvalidExtensionError, PayloadTooLargeError, LimitReachedError, MissingVariablesError, PlanLimitError, TooManySecretValuesError, SecretExistsError, SecretNotAllowedError, MachineTooOldError, NotContinuableError, TooManyMessagesError, RunNotLiveError, SessionNotRunningError, AuthenticationError, NotFoundError, BoxlineConnectionError, BoxlineTimeoutError, ErrorCode, makeError, } from "./errors.js";
|
|
11
|
+
export { verifyWebhook, webhookSignatureHeader, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TOLERANCE_SECONDS } from "./webhooks.js";
|
|
12
|
+
export { VERSION } from "./version.js";
|
|
13
|
+
export { Boxline as default } from "./client.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,OAAO,EACP,IAAI,EACJ,eAAe,EACf,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,gBAAgB,GAIjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAuC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAuB,MAAM,WAAW,CAAC;AACzG,OAAO,EACL,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,4BAA4B,EAC5B,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EAEtB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EACnB,SAAS,EACT,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,yBAAyB,EAA6B,MAAM,eAAe,CAAC;AACtJ,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor pages (docs/CONTRACT.md "Pagination"): every list returns `{data, next}`, and `next` goes back as `after`
|
|
3
|
+
* until it is null.
|
|
4
|
+
*
|
|
5
|
+
* const page = await bx.sessions.list({ limit: 50 }); // one page: page.data, page.next
|
|
6
|
+
* for await (const s of bx.sessions.list()) { … } // every session, page after page
|
|
7
|
+
*/
|
|
8
|
+
export declare class Page<T> implements AsyncIterable<T> {
|
|
9
|
+
#private;
|
|
10
|
+
/** The items on this page. */
|
|
11
|
+
readonly data: T[];
|
|
12
|
+
/** The cursor of the following page (pass it as `after`), or null on the last page. */
|
|
13
|
+
readonly next: string | null;
|
|
14
|
+
constructor(body: {
|
|
15
|
+
data: T[];
|
|
16
|
+
next?: string | null;
|
|
17
|
+
} & Record<string, unknown>, load: (after: string) => Promise<Page<T>>);
|
|
18
|
+
hasNextPage(): boolean;
|
|
19
|
+
/** The following page (same filters). Throws on the last page: check hasNextPage() first. */
|
|
20
|
+
getNextPage(): Promise<this>;
|
|
21
|
+
/** This page and every page after it. */
|
|
22
|
+
iterPages(): AsyncGenerator<this>;
|
|
23
|
+
/** Every item from this page on, fetching the following pages as needed. */
|
|
24
|
+
[Symbol.asyncIterator](): AsyncGenerator<T>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What list methods return: await it for the first page, or iterate it with `for await` for every item.
|
|
28
|
+
* The first page is requested right away.
|
|
29
|
+
*/
|
|
30
|
+
export declare class PagePromise<T, P extends Page<T> = Page<T>> extends Promise<P> implements AsyncIterable<T> {
|
|
31
|
+
static get [Symbol.species](): PromiseConstructor;
|
|
32
|
+
constructor(load: () => Promise<P>);
|
|
33
|
+
[Symbol.asyncIterator](): AsyncGenerator<T>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor pages (docs/CONTRACT.md "Pagination"): every list returns `{data, next}`, and `next` goes back as `after`
|
|
3
|
+
* until it is null.
|
|
4
|
+
*
|
|
5
|
+
* const page = await bx.sessions.list({ limit: 50 }); // one page: page.data, page.next
|
|
6
|
+
* for await (const s of bx.sessions.list()) { … } // every session, page after page
|
|
7
|
+
*/
|
|
8
|
+
export class Page {
|
|
9
|
+
/** The items on this page. */
|
|
10
|
+
data;
|
|
11
|
+
/** The cursor of the following page (pass it as `after`), or null on the last page. */
|
|
12
|
+
next;
|
|
13
|
+
#load;
|
|
14
|
+
constructor(body, load) {
|
|
15
|
+
// Other fields of the list (total, limit, offset, nextAfter) are kept as they are.
|
|
16
|
+
Object.assign(this, body);
|
|
17
|
+
this.data = body.data;
|
|
18
|
+
this.next = typeof body.next === "string" && body.next !== "" ? body.next : null;
|
|
19
|
+
this.#load = load;
|
|
20
|
+
}
|
|
21
|
+
hasNextPage() {
|
|
22
|
+
return this.next !== null;
|
|
23
|
+
}
|
|
24
|
+
/** The following page (same filters). Throws on the last page: check hasNextPage() first. */
|
|
25
|
+
async getNextPage() {
|
|
26
|
+
if (this.next === null)
|
|
27
|
+
throw new Error("this is the last page (next is null)");
|
|
28
|
+
return (await this.#load(this.next));
|
|
29
|
+
}
|
|
30
|
+
/** This page and every page after it. */
|
|
31
|
+
async *iterPages() {
|
|
32
|
+
let page = this;
|
|
33
|
+
yield page;
|
|
34
|
+
while (page.hasNextPage()) {
|
|
35
|
+
page = await page.getNextPage();
|
|
36
|
+
yield page;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Every item from this page on, fetching the following pages as needed. */
|
|
40
|
+
async *[Symbol.asyncIterator]() {
|
|
41
|
+
for await (const page of this.iterPages())
|
|
42
|
+
yield* page.data;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* What list methods return: await it for the first page, or iterate it with `for await` for every item.
|
|
47
|
+
* The first page is requested right away.
|
|
48
|
+
*/
|
|
49
|
+
export class PagePromise extends Promise {
|
|
50
|
+
// then/catch/finally make plain promises, not PagePromises (whose constructor takes a loader).
|
|
51
|
+
static get [Symbol.species]() {
|
|
52
|
+
return Promise;
|
|
53
|
+
}
|
|
54
|
+
constructor(load) {
|
|
55
|
+
let resolve;
|
|
56
|
+
let reject;
|
|
57
|
+
super((res, rej) => {
|
|
58
|
+
resolve = res;
|
|
59
|
+
reject = rej;
|
|
60
|
+
});
|
|
61
|
+
load().then(resolve, reject);
|
|
62
|
+
}
|
|
63
|
+
async *[Symbol.asyncIterator]() {
|
|
64
|
+
yield* await this;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,IAAI;IACf,8BAA8B;IACrB,IAAI,CAAM;IACnB,uFAAuF;IAC9E,IAAI,CAAgB;IACpB,KAAK,CAAsC;IAEpD,YAAY,IAAmE,EAAE,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