@beeos-ai/bma-sdk 0.4.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -34
- package/dist/core.d.ts +105 -0
- package/dist/core.js +406 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.js +109 -0
- package/dist/errors.js.map +1 -0
- package/dist/facade-extensions.d.ts +17 -61
- package/dist/facade-extensions.js +25 -112
- package/dist/facade-extensions.js.map +1 -1
- package/dist/generated/facade-extensions-operations.d.ts +133 -0
- package/dist/generated/facade-extensions-operations.js +11 -0
- package/dist/generated/facade-extensions-operations.js.map +1 -0
- package/dist/generated/facade-extensions-resources.d.ts +34 -0
- package/dist/generated/facade-extensions-resources.js +47 -0
- package/dist/generated/facade-extensions-resources.js.map +1 -0
- package/dist/generated/facade-extensions-types.d.ts +14 -0
- package/dist/generated/facade-extensions-types.js +2 -0
- package/dist/generated/facade-extensions-types.js.map +1 -0
- package/dist/generated/rest-operations.d.ts +4079 -0
- package/dist/generated/rest-operations.js +234 -0
- package/dist/generated/rest-operations.js.map +1 -0
- package/dist/generated/rest-resources.d.ts +666 -0
- package/dist/generated/rest-resources.js +1124 -0
- package/dist/generated/rest-resources.js.map +1 -0
- package/dist/generated/rest-types.d.ts +572 -0
- package/dist/generated/rest-types.js +2 -0
- package/dist/generated/rest-types.js.map +1 -0
- package/dist/generated/rest.d.ts +244 -21
- package/dist/index.d.ts +41 -76
- package/dist/index.js +49 -239
- package/dist/index.js.map +1 -1
- package/dist/lib/artifacts.d.ts +14 -0
- package/dist/lib/artifacts.js +56 -0
- package/dist/lib/artifacts.js.map +1 -0
- package/dist/lib/tool-runner.d.ts +99 -0
- package/dist/lib/tool-runner.js +140 -0
- package/dist/lib/tool-runner.js.map +1 -0
- package/dist/pagination.d.ts +31 -0
- package/dist/pagination.js +66 -0
- package/dist/pagination.js.map +1 -0
- package/dist/resource.d.ts +8 -0
- package/dist/resource.js +9 -0
- package/dist/resource.js.map +1 -0
- package/dist/streaming.d.ts +27 -0
- package/dist/streaming.js +89 -0
- package/dist/streaming.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +5 -3
package/dist/core.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
// Request runtime shared by every generated resource method: scope defaults,
|
|
2
|
+
// request encoding, retries with idempotency keys, timeouts, error decoding,
|
|
3
|
+
// pagination and event streams. Defaults are ADR 0012 decision D3.
|
|
4
|
+
import { APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, BmaApiError, BmaError, EventStreamError, } from "./errors.js";
|
|
5
|
+
import { PagePromise } from "./pagination.js";
|
|
6
|
+
import { Stream, parseSSE } from "./streaming.js";
|
|
7
|
+
/**
|
|
8
|
+
* Default per-attempt timeout (D3), measured until the response headers
|
|
9
|
+
* arrive. Uploads (binary and multipart bodies) have no default timeout;
|
|
10
|
+
* event streams and downloads are bounded only until the headers arrive.
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_TIMEOUT_MS = 60_000;
|
|
13
|
+
/** Default retries after the first attempt (D3; @anthropic-ai/sdk uses 2). */
|
|
14
|
+
export const DEFAULT_MAX_RETRIES = 2;
|
|
15
|
+
// Connection failures where the request provably never reached the server
|
|
16
|
+
// (resolution, refusal, connect timeout). Undici reports them in `cause.code`.
|
|
17
|
+
const UNDELIVERED = new Set(["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH", "UND_ERR_CONNECT_TIMEOUT"]);
|
|
18
|
+
function undelivered(error) {
|
|
19
|
+
for (let e = error, depth = 0; e && depth < 5; e = e.cause, depth++) {
|
|
20
|
+
const code = e.code;
|
|
21
|
+
if (typeof code === "string" && UNDELIVERED.has(code))
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function sleep(ms, signal) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
if (signal?.aborted)
|
|
29
|
+
return reject(new APIUserAbortError());
|
|
30
|
+
const timer = setTimeout(() => {
|
|
31
|
+
signal?.removeEventListener("abort", onAbort);
|
|
32
|
+
resolve();
|
|
33
|
+
}, ms);
|
|
34
|
+
const onAbort = () => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
reject(new APIUserAbortError());
|
|
37
|
+
};
|
|
38
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Exponential backoff with up to 25% jitter: 0.5s, 1s, 2s ... capped at 8s
|
|
42
|
+
// (@anthropic-ai/sdk client.js calculateDefaultRetryTimeoutMillis).
|
|
43
|
+
function backoff(retry) {
|
|
44
|
+
return Math.min(0.5 * 2 ** retry, 8) * (1 - Math.random() * 0.25) * 1000;
|
|
45
|
+
}
|
|
46
|
+
// retry-after-ms, then retry-after (seconds or HTTP date), honoured when
|
|
47
|
+
// between 0 and 60 seconds, as in @anthropic-ai/sdk.
|
|
48
|
+
function retryAfter(headers) {
|
|
49
|
+
const ms = Number.parseFloat(headers?.get("retry-after-ms") ?? "");
|
|
50
|
+
if (Number.isFinite(ms) && ms >= 0 && ms < 60_000)
|
|
51
|
+
return ms;
|
|
52
|
+
const raw = headers?.get("retry-after");
|
|
53
|
+
if (raw) {
|
|
54
|
+
const seconds = Number.parseFloat(raw);
|
|
55
|
+
const delay = Number.isFinite(seconds) ? seconds * 1000 : Date.parse(raw) - Date.now();
|
|
56
|
+
if (Number.isFinite(delay) && delay >= 0 && delay < 60_000)
|
|
57
|
+
return delay;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The deployment origin of a BMA base URL (BMA_BASE_URL): trailing slashes and
|
|
63
|
+
* a trailing /api/v1 (the pre-1.0 API-root form) are removed, so the SDK adds
|
|
64
|
+
* each API prefix exactly once.
|
|
65
|
+
*/
|
|
66
|
+
export function bmaOrigin(baseUrl) {
|
|
67
|
+
return baseUrl.trim().replace(/\/+$/, "").replace(/\/api\/v1$/, "");
|
|
68
|
+
}
|
|
69
|
+
/** @internal The transport every resource calls. */
|
|
70
|
+
export class ClientCore {
|
|
71
|
+
baseUrl;
|
|
72
|
+
#fetch;
|
|
73
|
+
#timeout;
|
|
74
|
+
#maxRetries;
|
|
75
|
+
#headers;
|
|
76
|
+
#scope;
|
|
77
|
+
#scopeOption;
|
|
78
|
+
constructor(options) {
|
|
79
|
+
const baseUrl = options.baseUrl.trim().replace(/\/+$/, "");
|
|
80
|
+
const scheme = new URL(baseUrl).protocol;
|
|
81
|
+
if (scheme !== "http:" && scheme !== "https:")
|
|
82
|
+
throw new BmaError("bma: baseUrl must use http or https");
|
|
83
|
+
this.baseUrl = baseUrl;
|
|
84
|
+
this.#fetch = options.fetch ?? globalThis.fetch;
|
|
85
|
+
this.#timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
86
|
+
this.#maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
87
|
+
this.#headers = options.headers;
|
|
88
|
+
this.#scope = options.scope;
|
|
89
|
+
this.#scopeOption = options.scopeOption;
|
|
90
|
+
}
|
|
91
|
+
/** @internal */
|
|
92
|
+
_request(op, path, params, options) {
|
|
93
|
+
return (async () => {
|
|
94
|
+
const built = this.#build(op, path, params, options);
|
|
95
|
+
const { response, release } = await this.#send(op, built, options);
|
|
96
|
+
try {
|
|
97
|
+
return await this.#decode(op, response, options?.signal);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
if (op.response !== "binary")
|
|
101
|
+
release();
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @internal A paginated list. The cursor parameter is the one of
|
|
107
|
+
* `op.page` the caller passed (e.g. before_sequence), else the default.
|
|
108
|
+
*/
|
|
109
|
+
_page(op, path, params, options) {
|
|
110
|
+
const pairs = op.page ?? [["cursor", "next_cursor"]];
|
|
111
|
+
const given = params;
|
|
112
|
+
const [param, field] = pairs.find(([p]) => given[p] !== undefined && given[p] !== null) ?? pairs[0];
|
|
113
|
+
return new PagePromise((cursor) => this._request(op, path, cursor === undefined ? params : { ...params, [param]: cursor }, options), (body) => {
|
|
114
|
+
const next = body[field];
|
|
115
|
+
if (body.data.length === 0 || body.has_more === false)
|
|
116
|
+
return undefined;
|
|
117
|
+
return typeof next === "string" ? next || undefined : typeof next === "number" ? next : undefined;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @internal Event stream with EventSource reconnection: when the
|
|
122
|
+
* connection drops or the server ends the response (a rolling restart), or
|
|
123
|
+
* sends an `error` frame with code `service_unavailable`, the stream
|
|
124
|
+
* reconnects with Last-Event-ID set to the last durable frame. A frame not
|
|
125
|
+
* terminated before the end is discarded. Reconnects are bounded by
|
|
126
|
+
* `maxReconnects` (default `maxRetries`) attempts in a row that receive no
|
|
127
|
+
* data; any other error frame ends the stream with EventStreamError.
|
|
128
|
+
*/
|
|
129
|
+
_stream(op, path, params, options, hooks) {
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
if (options?.signal) {
|
|
132
|
+
if (options.signal.aborted)
|
|
133
|
+
controller.abort();
|
|
134
|
+
else
|
|
135
|
+
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
136
|
+
}
|
|
137
|
+
const resumeKey = Object.entries(op.headers ?? {}).find(([name]) => name.toLowerCase() === "last-event-id")?.[1];
|
|
138
|
+
const budget = hooks?.maxReconnects ?? options?.maxRetries ?? this.#maxRetries;
|
|
139
|
+
const self = this;
|
|
140
|
+
async function* iterate(signal) {
|
|
141
|
+
let current = { ...params };
|
|
142
|
+
let lastId;
|
|
143
|
+
let failures = 0;
|
|
144
|
+
for (;;) {
|
|
145
|
+
let lastError;
|
|
146
|
+
try {
|
|
147
|
+
const built = self.#build(op, path, current, options);
|
|
148
|
+
built.headers.set("Accept", "text/event-stream");
|
|
149
|
+
const { response } = await self.#send(op, built, { ...options, signal, maxRetries: 0 }, true);
|
|
150
|
+
if (!response.body)
|
|
151
|
+
throw new BmaError("bma: event stream response has no body");
|
|
152
|
+
hooks?.onOpen?.();
|
|
153
|
+
for await (const raw of parseSSE(response.body, () => (failures = 0))) {
|
|
154
|
+
const data = parseFrame(raw.event, raw.data);
|
|
155
|
+
if (raw.event === "error") {
|
|
156
|
+
const error = new EventStreamError(data);
|
|
157
|
+
if (error.code !== "service_unavailable")
|
|
158
|
+
throw error;
|
|
159
|
+
throw new ReconnectSignal(error);
|
|
160
|
+
}
|
|
161
|
+
if (raw.id !== undefined) {
|
|
162
|
+
const sequence = Number(raw.id);
|
|
163
|
+
if (!Number.isSafeInteger(sequence))
|
|
164
|
+
throw new BmaError(`bma: invalid event id ${JSON.stringify(raw.id)}`);
|
|
165
|
+
lastId = raw.id;
|
|
166
|
+
yield { event: raw.event, id: raw.id, sequence, data };
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
yield { event: raw.event, data };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
lastError = new APIConnectionError({ message: "bma: event stream ended by the server" });
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (signal.aborted)
|
|
176
|
+
throw new APIUserAbortError();
|
|
177
|
+
if (error instanceof ReconnectSignal)
|
|
178
|
+
lastError = error.error;
|
|
179
|
+
else if (error instanceof APIConnectionError)
|
|
180
|
+
lastError = error;
|
|
181
|
+
else if (error instanceof BmaApiError && error.status !== undefined && retryableStatus(error.status))
|
|
182
|
+
lastError = error;
|
|
183
|
+
else if (error instanceof BmaError)
|
|
184
|
+
throw error;
|
|
185
|
+
else
|
|
186
|
+
lastError = new APIConnectionError({ cause: error });
|
|
187
|
+
}
|
|
188
|
+
if (failures >= budget)
|
|
189
|
+
throw lastError;
|
|
190
|
+
await sleep(backoff(failures), signal);
|
|
191
|
+
failures++;
|
|
192
|
+
if (lastId !== undefined && resumeKey) {
|
|
193
|
+
current = { ...params, [resumeKey]: Number(lastId) };
|
|
194
|
+
// Last-Event-ID is the resume point; after_sequence would replay older events.
|
|
195
|
+
delete current.after_sequence;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return new Stream(iterate, controller);
|
|
200
|
+
}
|
|
201
|
+
#build(op, path, params, options) {
|
|
202
|
+
const rest = { ...params };
|
|
203
|
+
const headers = new Headers(this.#headers);
|
|
204
|
+
let url = op.path;
|
|
205
|
+
for (const [name, key] of Object.entries(op.pathParams ?? {})) {
|
|
206
|
+
let value = path[name];
|
|
207
|
+
if (value === undefined) {
|
|
208
|
+
value = rest[key] ?? this.#scope[key];
|
|
209
|
+
delete rest[key];
|
|
210
|
+
if (typeof value !== "string" || value === "") {
|
|
211
|
+
const option = this.#scopeOption[key] ?? key;
|
|
212
|
+
throw new BmaError(`bma: ${op.id} needs ${key}; set the client option ${option} or pass ${key} in params`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
url = url.replace(`{${name}}`, encodeURIComponent(String(value)));
|
|
216
|
+
}
|
|
217
|
+
const search = new URLSearchParams();
|
|
218
|
+
for (const [name, style] of Object.entries(op.query ?? {})) {
|
|
219
|
+
const value = rest[name];
|
|
220
|
+
delete rest[name];
|
|
221
|
+
if (value === undefined || value === null)
|
|
222
|
+
continue;
|
|
223
|
+
if (style === "deepObject" && typeof value === "object" && !Array.isArray(value)) {
|
|
224
|
+
for (const [k, v] of Object.entries(value))
|
|
225
|
+
search.append(`${name}[${k}]`, String(v));
|
|
226
|
+
}
|
|
227
|
+
else if (Array.isArray(value)) {
|
|
228
|
+
for (const v of value)
|
|
229
|
+
search.append(name, String(v));
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
search.append(name, String(value));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const [name, key] of Object.entries(op.headers ?? {})) {
|
|
236
|
+
const value = rest[key] ?? (key in this.#scope ? this.#scope[key] : undefined);
|
|
237
|
+
delete rest[key];
|
|
238
|
+
if (value !== undefined && value !== null)
|
|
239
|
+
headers.set(name, String(value));
|
|
240
|
+
}
|
|
241
|
+
if (op.idempotency) {
|
|
242
|
+
headers.set("Idempotency-Key", options?.idempotencyKey ?? `bma-sdk-retry-${crypto.randomUUID()}`);
|
|
243
|
+
}
|
|
244
|
+
else if (options?.idempotencyKey !== undefined) {
|
|
245
|
+
throw new BmaError(`bma: ${op.id} does not accept an Idempotency-Key`);
|
|
246
|
+
}
|
|
247
|
+
let body;
|
|
248
|
+
if (op.body === "json") {
|
|
249
|
+
if (op.bodyRequired || Object.keys(rest).length > 0) {
|
|
250
|
+
body = JSON.stringify(rest);
|
|
251
|
+
headers.set("Content-Type", "application/json");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else if (op.body === "binary") {
|
|
255
|
+
const raw = rest.body;
|
|
256
|
+
if (raw !== undefined) {
|
|
257
|
+
body = raw;
|
|
258
|
+
headers.set("Content-Type", "application/octet-stream");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (op.body === "multipart") {
|
|
262
|
+
// JSON fields (op.multipartJSON, the contract's encoding contentType
|
|
263
|
+
// application/json) are sent as text parts: FormData can only give a
|
|
264
|
+
// part a Content-Type through a Blob, which also adds filename="blob"
|
|
265
|
+
// and turns the field into a file part. The server reads them by name.
|
|
266
|
+
const form = new FormData();
|
|
267
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
268
|
+
if (value === undefined)
|
|
269
|
+
continue;
|
|
270
|
+
if (value instanceof Blob)
|
|
271
|
+
form.append(key, value, value instanceof File ? value.name : key);
|
|
272
|
+
else if (op.multipartJSON?.includes(key) || typeof value === "object")
|
|
273
|
+
form.append(key, JSON.stringify(value));
|
|
274
|
+
else
|
|
275
|
+
form.append(key, String(value));
|
|
276
|
+
}
|
|
277
|
+
body = form;
|
|
278
|
+
}
|
|
279
|
+
for (const [k, v] of Object.entries(options?.headers ?? {}))
|
|
280
|
+
headers.set(k, v);
|
|
281
|
+
const query = search.toString();
|
|
282
|
+
return { url: this.baseUrl + url + (query ? `?${query}` : ""), headers, body };
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Sends with retries. GET and operations with an Idempotency-Key retry
|
|
286
|
+
* 408/429/5xx and connection errors; other writes retry only requests that
|
|
287
|
+
* never reached the server, 429 and 503 (D3). 409 is never retried. The
|
|
288
|
+
* timeout runs until the response headers arrive; the caller's signal
|
|
289
|
+
* stays attached until `release()`, so it also aborts reading the body.
|
|
290
|
+
*/
|
|
291
|
+
async #send(op, built, options, stream = false) {
|
|
292
|
+
const attempts = { max: options?.maxRetries ?? this.#maxRetries, used: 0 };
|
|
293
|
+
const safe = op.method === "GET" || op.idempotency === true;
|
|
294
|
+
const upload = op.body === "binary" || op.body === "multipart";
|
|
295
|
+
const timeout = options?.timeout ?? (upload ? 0 : this.#timeout);
|
|
296
|
+
for (;;) {
|
|
297
|
+
const controller = new AbortController();
|
|
298
|
+
const user = options?.signal;
|
|
299
|
+
if (user?.aborted)
|
|
300
|
+
throw new APIUserAbortError();
|
|
301
|
+
const onAbort = () => controller.abort();
|
|
302
|
+
user?.addEventListener("abort", onAbort, { once: true });
|
|
303
|
+
const release = () => user?.removeEventListener("abort", onAbort);
|
|
304
|
+
let timedOut = false;
|
|
305
|
+
const timer = timeout > 0
|
|
306
|
+
? setTimeout(() => {
|
|
307
|
+
timedOut = true;
|
|
308
|
+
controller.abort();
|
|
309
|
+
}, timeout)
|
|
310
|
+
: undefined;
|
|
311
|
+
let response;
|
|
312
|
+
try {
|
|
313
|
+
response = await this.#fetch(built.url, {
|
|
314
|
+
method: op.method,
|
|
315
|
+
headers: built.headers,
|
|
316
|
+
body: built.body,
|
|
317
|
+
signal: controller.signal,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
clearTimeout(timer);
|
|
322
|
+
release();
|
|
323
|
+
if (user?.aborted)
|
|
324
|
+
throw new APIUserAbortError();
|
|
325
|
+
const failure = timedOut ? new APIConnectionTimeoutError() : new APIConnectionError({ cause: error });
|
|
326
|
+
if (attempts.used < attempts.max && (safe || (!timedOut && undelivered(error)))) {
|
|
327
|
+
await sleep(backoff(attempts.used++), user);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
throw failure;
|
|
331
|
+
}
|
|
332
|
+
clearTimeout(timer);
|
|
333
|
+
if (response.ok)
|
|
334
|
+
return { response, release: stream ? () => undefined : release };
|
|
335
|
+
release();
|
|
336
|
+
const text = await response.text().catch(() => "");
|
|
337
|
+
let body;
|
|
338
|
+
try {
|
|
339
|
+
body = text ? JSON.parse(text) : undefined;
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
body = undefined;
|
|
343
|
+
}
|
|
344
|
+
const error = BmaApiError.generate(response.status, body, response.headers);
|
|
345
|
+
if (attempts.used < attempts.max && this.#shouldRetry(response, safe)) {
|
|
346
|
+
await sleep(retryAfter(response.headers) ?? backoff(attempts.used), user);
|
|
347
|
+
attempts.used++;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
#shouldRetry(response, safe) {
|
|
354
|
+
const hint = response.headers.get("x-should-retry");
|
|
355
|
+
if (hint === "false")
|
|
356
|
+
return false;
|
|
357
|
+
const s = response.status;
|
|
358
|
+
if (!safe)
|
|
359
|
+
return s === 429 || s === 503;
|
|
360
|
+
if (hint === "true")
|
|
361
|
+
return true;
|
|
362
|
+
return s === 408 || s === 429 || s >= 500;
|
|
363
|
+
}
|
|
364
|
+
async #decode(op, response, signal) {
|
|
365
|
+
if (op.response === "binary")
|
|
366
|
+
return response;
|
|
367
|
+
try {
|
|
368
|
+
if (response.status === 204 || op.response === "void") {
|
|
369
|
+
await response.body?.cancel();
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
const text = await response.text();
|
|
373
|
+
try {
|
|
374
|
+
return JSON.parse(text);
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
throw new BmaError(`bma: ${op.id}: response is not JSON`, { cause: error });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
if (signal?.aborted)
|
|
382
|
+
throw new APIUserAbortError();
|
|
383
|
+
if (error instanceof BmaError)
|
|
384
|
+
throw error;
|
|
385
|
+
throw new APIConnectionError({ message: `bma: ${op.id}: reading the response failed`, cause: error });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function retryableStatus(status) {
|
|
390
|
+
return status === 408 || status === 429 || status >= 500;
|
|
391
|
+
}
|
|
392
|
+
function parseFrame(event, data) {
|
|
393
|
+
try {
|
|
394
|
+
return JSON.parse(data);
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
throw new BmaError(`bma: invalid JSON in ${event} event frame`, { cause: error });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
class ReconnectSignal {
|
|
401
|
+
error;
|
|
402
|
+
constructor(error) {
|
|
403
|
+
this.error = error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,mEAAmE;AACnE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAuB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAA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C,CAAC;IACpF,CAAC;AACH,CAAC;AAED,MAAM,eAAe;IACE;IAArB,YAAqB,KAAkB;QAAlB,UAAK,GAAL,KAAK,CAAa;IAAG,CAAC;CAC5C"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { components } from "./generated/rest.js";
|
|
2
|
+
/** Contract error codes; unknown future codes still type-check as strings. */
|
|
3
|
+
export type ErrorCode = components["schemas"]["ErrorCode"] | (string & {});
|
|
4
|
+
type AgentConfigErrorIssue = components["schemas"]["AgentConfigErrorIssue"];
|
|
5
|
+
/** Base class of every error thrown by the SDK. */
|
|
6
|
+
export declare class BmaError extends Error {
|
|
7
|
+
constructor(message: string, options?: {
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/** An error response from the API, or a request that never got one. */
|
|
12
|
+
export declare class BmaApiError<TStatus extends number | undefined = number | undefined> extends BmaError {
|
|
13
|
+
/** HTTP status; undefined for connection errors and stream error frames. */
|
|
14
|
+
readonly status: TStatus;
|
|
15
|
+
readonly headers: Headers | undefined;
|
|
16
|
+
/** Stable error code from the response body. */
|
|
17
|
+
readonly code: ErrorCode | undefined;
|
|
18
|
+
/** Parsed response body, if any. */
|
|
19
|
+
readonly error: unknown;
|
|
20
|
+
/** Field-level problems for agent config validation errors. */
|
|
21
|
+
readonly issues: AgentConfigErrorIssue[] | undefined;
|
|
22
|
+
/** Current file digest for file_content_conflict / expected_digest_required. */
|
|
23
|
+
readonly currentDigest: string | undefined;
|
|
24
|
+
/** Facade extensions only: the Anthropic-style `error.type`. */
|
|
25
|
+
readonly type: string | undefined;
|
|
26
|
+
constructor(status: TStatus, body: unknown, message: string | undefined, headers: Headers | undefined, options?: {
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
});
|
|
29
|
+
/** @internal */
|
|
30
|
+
static generate(status: number, body: unknown, headers: Headers): BmaApiError;
|
|
31
|
+
}
|
|
32
|
+
export declare class APIConnectionError extends BmaApiError<undefined> {
|
|
33
|
+
constructor({ message, cause }?: {
|
|
34
|
+
message?: string;
|
|
35
|
+
cause?: unknown;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export declare class APIConnectionTimeoutError extends APIConnectionError {
|
|
39
|
+
constructor({ message }?: {
|
|
40
|
+
message?: string;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export declare class APIUserAbortError extends BmaApiError<undefined> {
|
|
44
|
+
constructor({ message }?: {
|
|
45
|
+
message?: string;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An `error` frame on an event stream. The stream ends after it; frames with
|
|
50
|
+
* code `service_unavailable` are retried by the SDK before this is thrown.
|
|
51
|
+
*/
|
|
52
|
+
export declare class EventStreamError extends BmaApiError<undefined> {
|
|
53
|
+
constructor(body: unknown);
|
|
54
|
+
}
|
|
55
|
+
export declare class BadRequestError extends BmaApiError<400> {
|
|
56
|
+
}
|
|
57
|
+
export declare class AuthenticationError extends BmaApiError<401> {
|
|
58
|
+
}
|
|
59
|
+
export declare class PermissionDeniedError extends BmaApiError<403> {
|
|
60
|
+
}
|
|
61
|
+
export declare class NotFoundError extends BmaApiError<404> {
|
|
62
|
+
}
|
|
63
|
+
export declare class RequestTimeoutError extends BmaApiError<408> {
|
|
64
|
+
}
|
|
65
|
+
export declare class ConflictError extends BmaApiError<409> {
|
|
66
|
+
}
|
|
67
|
+
export declare class ContentTooLargeError extends BmaApiError<413> {
|
|
68
|
+
}
|
|
69
|
+
export declare class UnprocessableEntityError extends BmaApiError<422> {
|
|
70
|
+
}
|
|
71
|
+
export declare class RateLimitError extends BmaApiError<429> {
|
|
72
|
+
}
|
|
73
|
+
export declare class InternalServerError extends BmaApiError<number> {
|
|
74
|
+
}
|
|
75
|
+
export declare class ServiceUnavailableError extends InternalServerError {
|
|
76
|
+
}
|
|
77
|
+
export {};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** Base class of every error thrown by the SDK. */
|
|
2
|
+
export class BmaError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** An error response from the API, or a request that never got one. */
|
|
9
|
+
export class BmaApiError extends BmaError {
|
|
10
|
+
/** HTTP status; undefined for connection errors and stream error frames. */
|
|
11
|
+
status;
|
|
12
|
+
headers;
|
|
13
|
+
/** Stable error code from the response body. */
|
|
14
|
+
code;
|
|
15
|
+
/** Parsed response body, if any. */
|
|
16
|
+
error;
|
|
17
|
+
/** Field-level problems for agent config validation errors. */
|
|
18
|
+
issues;
|
|
19
|
+
/** Current file digest for file_content_conflict / expected_digest_required. */
|
|
20
|
+
currentDigest;
|
|
21
|
+
/** Facade extensions only: the Anthropic-style `error.type`. */
|
|
22
|
+
type;
|
|
23
|
+
constructor(status, body, message, headers, options) {
|
|
24
|
+
const wire = (typeof body === "object" && body !== null ? body : {});
|
|
25
|
+
// Native API: {error: string, code}. Facade: {type: "error", error: {type, message, code}}.
|
|
26
|
+
const nested = typeof wire.error === "object" && wire.error !== null ? wire.error : undefined;
|
|
27
|
+
const code = str(nested ? nested.code : wire.code);
|
|
28
|
+
const type = nested ? str(nested.type) : undefined;
|
|
29
|
+
const detail = str(nested ? nested.message : wire.error) ?? message;
|
|
30
|
+
super(status === undefined
|
|
31
|
+
? (message ?? detail ?? "bma: request failed")
|
|
32
|
+
: `bma: ${status} ${code ?? type ?? "unknown"}: ${detail ?? `HTTP ${status}`}`, options);
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.headers = headers;
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.type = type;
|
|
37
|
+
this.error = body;
|
|
38
|
+
this.issues = Array.isArray(wire.issues) ? wire.issues : undefined;
|
|
39
|
+
this.currentDigest = str(wire.current_digest);
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
static generate(status, body, headers) {
|
|
43
|
+
const cls = STATUS_CLASSES.get(status) ?? (status >= 500 ? InternalServerError : BmaApiError);
|
|
44
|
+
return new cls(status, body, undefined, headers);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function str(value) {
|
|
48
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
49
|
+
}
|
|
50
|
+
export class APIConnectionError extends BmaApiError {
|
|
51
|
+
constructor({ message, cause } = {}) {
|
|
52
|
+
super(undefined, undefined, message ?? "bma: connection error", undefined, { cause });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
56
|
+
constructor({ message } = {}) {
|
|
57
|
+
super({ message: message ?? "bma: request timed out" });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class APIUserAbortError extends BmaApiError {
|
|
61
|
+
constructor({ message } = {}) {
|
|
62
|
+
super(undefined, undefined, message ?? "bma: request was aborted", undefined);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* An `error` frame on an event stream. The stream ends after it; frames with
|
|
67
|
+
* code `service_unavailable` are retried by the SDK before this is thrown.
|
|
68
|
+
*/
|
|
69
|
+
export class EventStreamError extends BmaApiError {
|
|
70
|
+
constructor(body) {
|
|
71
|
+
const wire = (body ?? {});
|
|
72
|
+
super(undefined, body, `bma: event stream error ${String(wire.code ?? "unknown")}: ${String(wire.error ?? "")}`, undefined);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class BadRequestError extends BmaApiError {
|
|
76
|
+
}
|
|
77
|
+
export class AuthenticationError extends BmaApiError {
|
|
78
|
+
}
|
|
79
|
+
export class PermissionDeniedError extends BmaApiError {
|
|
80
|
+
}
|
|
81
|
+
export class NotFoundError extends BmaApiError {
|
|
82
|
+
}
|
|
83
|
+
export class RequestTimeoutError extends BmaApiError {
|
|
84
|
+
}
|
|
85
|
+
export class ConflictError extends BmaApiError {
|
|
86
|
+
}
|
|
87
|
+
export class ContentTooLargeError extends BmaApiError {
|
|
88
|
+
}
|
|
89
|
+
export class UnprocessableEntityError extends BmaApiError {
|
|
90
|
+
}
|
|
91
|
+
export class RateLimitError extends BmaApiError {
|
|
92
|
+
}
|
|
93
|
+
export class InternalServerError extends BmaApiError {
|
|
94
|
+
}
|
|
95
|
+
export class ServiceUnavailableError extends InternalServerError {
|
|
96
|
+
}
|
|
97
|
+
const STATUS_CLASSES = new Map([
|
|
98
|
+
[400, BadRequestError],
|
|
99
|
+
[401, AuthenticationError],
|
|
100
|
+
[403, PermissionDeniedError],
|
|
101
|
+
[404, NotFoundError],
|
|
102
|
+
[408, RequestTimeoutError],
|
|
103
|
+
[409, ConflictError],
|
|
104
|
+
[413, ContentTooLargeError],
|
|
105
|
+
[422, UnprocessableEntityError],
|
|
106
|
+
[429, RateLimitError],
|
|
107
|
+
[503, ServiceUnavailableError],
|
|
108
|
+
]);
|
|
109
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAUA,mDAAmD;AACnD,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,uEAAuE;AACvE,MAAM,OAAO,WAAqE,SAAQ,QAAQ;IAChG,4EAA4E;IACnE,MAAM,CAAU;IAChB,OAAO,CAAsB;IACtC,gDAAgD;IACvC,IAAI,CAAwB;IACrC,oCAAoC;IAC3B,KAAK,CAAU;IACxB,+DAA+D;IACtD,MAAM,CAAsC;IACrD,gFAAgF;IACvE,aAAa,CAAqB;IAC3C,gEAAgE;IACvD,IAAI,CAAqB;IAElC,YACE,MAAe,EACf,IAAa,EACb,OAA2B,EA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