@beeos-ai/bma-sdk 1.0.1 → 2.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/README.md +72 -131
- package/dist/beta.d.ts +79 -0
- package/dist/beta.js +107 -0
- package/dist/beta.js.map +1 -0
- package/dist/client.d.ts +32 -0
- package/dist/client.js +50 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +6 -75
- package/dist/errors.js +11 -105
- package/dist/errors.js.map +1 -1
- package/dist/extensions.d.ts +80 -0
- package/dist/extensions.js +24 -0
- package/dist/extensions.js.map +1 -0
- package/dist/generated/extensions-resources.d.ts +271 -0
- package/dist/generated/extensions-resources.js +255 -0
- package/dist/generated/extensions-resources.js.map +1 -0
- package/dist/generated/extensions.d.ts +3727 -0
- package/dist/generated/{rest.js → extensions.js} +1 -1
- package/dist/generated/extensions.js.map +1 -0
- package/dist/idempotency.d.ts +4 -0
- package/dist/idempotency.js +7 -0
- package/dist/idempotency.js.map +1 -0
- package/dist/index.d.ts +9 -55
- package/dist/index.js +9 -57
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +9 -0
- package/dist/internal.js +32 -0
- package/dist/internal.js.map +1 -0
- package/dist/resume.d.ts +24 -0
- package/dist/resume.js +127 -0
- package/dist/resume.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +3 -3
- package/dist/version.js.map +1 -1
- package/package.json +6 -12
- package/dist/core.d.ts +0 -105
- package/dist/core.js +0 -406
- package/dist/core.js.map +0 -1
- package/dist/facade-extensions.d.ts +0 -27
- package/dist/facade-extensions.js +0 -47
- package/dist/facade-extensions.js.map +0 -1
- package/dist/generated/facade-extensions-operations.d.ts +0 -133
- package/dist/generated/facade-extensions-operations.js +0 -11
- package/dist/generated/facade-extensions-operations.js.map +0 -1
- package/dist/generated/facade-extensions-resources.d.ts +0 -34
- package/dist/generated/facade-extensions-resources.js +0 -47
- package/dist/generated/facade-extensions-resources.js.map +0 -1
- package/dist/generated/facade-extensions-types.d.ts +0 -14
- package/dist/generated/facade-extensions-types.js +0 -2
- package/dist/generated/facade-extensions-types.js.map +0 -1
- package/dist/generated/facade-extensions.d.ts +0 -507
- package/dist/generated/facade-extensions.js +0 -6
- package/dist/generated/facade-extensions.js.map +0 -1
- package/dist/generated/rest-operations.d.ts +0 -4079
- package/dist/generated/rest-operations.js +0 -234
- package/dist/generated/rest-operations.js.map +0 -1
- package/dist/generated/rest-resources.d.ts +0 -666
- package/dist/generated/rest-resources.js +0 -1124
- package/dist/generated/rest-resources.js.map +0 -1
- package/dist/generated/rest-types.d.ts +0 -572
- package/dist/generated/rest-types.js +0 -2
- package/dist/generated/rest-types.js.map +0 -1
- package/dist/generated/rest.d.ts +0 -18519
- package/dist/generated/rest.js.map +0 -1
- package/dist/lib/artifacts.d.ts +0 -14
- package/dist/lib/artifacts.js +0 -56
- package/dist/lib/artifacts.js.map +0 -1
- package/dist/lib/tool-runner.d.ts +0 -99
- package/dist/lib/tool-runner.js +0 -140
- package/dist/lib/tool-runner.js.map +0 -1
- package/dist/pagination.d.ts +0 -31
- package/dist/pagination.js +0 -66
- package/dist/pagination.js.map +0 -1
- package/dist/resource.d.ts +0 -8
- package/dist/resource.js +0 -9
- package/dist/resource.js.map +0 -1
- package/dist/streaming.d.ts +0 -27
- package/dist/streaming.js +0 -89
- package/dist/streaming.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../src/generated/extensions.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A random Idempotency-Key for one extension create. It is computed once per
|
|
2
|
+
* call, so the official client's automatic retries resend the same key and the
|
|
3
|
+
* server replays the first result. */
|
|
4
|
+
export function newIdempotencyKey() {
|
|
5
|
+
return globalThis.crypto.randomUUID();
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=idempotency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA;;sCAEsC;AACtC,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;AACxC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,55 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
7
|
-
export type
|
|
8
|
-
export type
|
|
9
|
-
export
|
|
10
|
-
export { APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, BmaApiError, BmaError, ConflictError, ContentTooLargeError, EventStreamError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, RequestTimeoutError, ServiceUnavailableError, UnprocessableEntityError, type ErrorCode, } from "./errors.js";
|
|
11
|
-
export { DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, type RequestOptions, type Uploadable } from "./core.js";
|
|
12
|
-
export { PagePromise, type CursorPageBody, type Page, type PageItem } from "./pagination.js";
|
|
13
|
-
export { Stream } from "./streaming.js";
|
|
14
|
-
export { defineTool, ToolError, type RunnableTool, type ToolOutput, type ToolRunContext, type ToolRunner, type ToolRunnerParams } from "./lib/tool-runner.js";
|
|
15
|
-
export type { DownloadArtifactOptions } from "./lib/artifacts.js";
|
|
16
|
-
export type { StreamEventsEvent as AgentStreamEvent } from "./generated/rest-operations.js";
|
|
17
|
-
/** Hosted BMA origin; the client adds the /api/v1 prefix. */
|
|
18
|
-
export declare const DEFAULT_BASE_URL = "https://api.bma.beeos.ai";
|
|
19
|
-
export interface BmaClientOptions {
|
|
20
|
-
/** BMA personal or organization bearer token; env BMA_TOKEN. */
|
|
21
|
-
token?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Deployment origin, for example https://api.bma.beeos.ai; env BMA_BASE_URL.
|
|
24
|
-
* The client adds /api/v1; a value that already ends with /api/v1 is accepted.
|
|
25
|
-
*/
|
|
26
|
-
baseUrl?: string;
|
|
27
|
-
/** Default organization (org_...) for org- and project-scoped methods; env BMA_ORG_ID. */
|
|
28
|
-
orgId?: string;
|
|
29
|
-
/** Default project (prj_...) for project-scoped methods; env BMA_PROJECT_ID. */
|
|
30
|
-
projectId?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Per-attempt timeout in milliseconds until the response headers arrive
|
|
33
|
-
* (default 60 000; 0 disables it). Uploads have no default timeout.
|
|
34
|
-
*/
|
|
35
|
-
timeout?: number;
|
|
36
|
-
/** Retries after the first attempt (default 2). */
|
|
37
|
-
maxRetries?: number;
|
|
38
|
-
/** Optional fetch implementation; defaults to globalThis.fetch. */
|
|
39
|
-
fetch?: typeof globalThis.fetch;
|
|
40
|
-
}
|
|
41
|
-
/** Authenticated BMA REST client. */
|
|
42
|
-
export declare class BmaClient extends RestClientBase {
|
|
43
|
-
/**
|
|
44
|
-
* Escape hatch: the openapi-fetch client typed by contract path, for
|
|
45
|
-
* operations without a resource method (Machine Daemon). Pair with unwrap().
|
|
46
|
-
*/
|
|
47
|
-
readonly rest: Client<paths>;
|
|
48
|
-
constructor(options?: BmaClientOptions);
|
|
49
|
-
}
|
|
50
|
-
/** Escape hatch companion of `bma.rest`: returns `data` or throws the typed error. */
|
|
51
|
-
export declare function unwrap<T>(result: {
|
|
52
|
-
data?: T;
|
|
53
|
-
error?: unknown;
|
|
54
|
-
response: Response;
|
|
55
|
-
}): T;
|
|
1
|
+
export { BmaClient, DEFAULT_BASE_URL, type BmaClientOptions } from './client.js';
|
|
2
|
+
export { BmaClient as default } from './client.js';
|
|
3
|
+
export { SDK_VERSION } from './version.js';
|
|
4
|
+
export { errorCode } from './errors.js';
|
|
5
|
+
export { agentExtensions, environmentExtensions, eventExtensions, sessionExtensions, type AgentExt, type AgentExtParams, type AgentModelOverride, type AgentModelOverrideInput, type AgentModelOverridePatch, type EnvironmentDesktop, type EnvironmentExt, type EnvironmentExtParams, type EnvironmentMachine, type EventExt, type Harness, type SessionCreateExt, type SessionExt, type SessionUpdateExt, } from './extensions.js';
|
|
6
|
+
export * from './generated/extensions-resources.js';
|
|
7
|
+
export type { components } from './generated/extensions.js';
|
|
8
|
+
export { BmaBeta, BmaEvents, BmaSessions, type SentStream } from './beta.js';
|
|
9
|
+
export { AnthropicError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, ConflictError, ContentTooLargeError, GatewayTimeoutError, InternalServerError, NotFoundError, OverloadedError, PermissionDeniedError, PreconditionFailedError, RateLimitError, RequestTimeoutError, ServiceUnavailableError, UnprocessableEntityError, } from '@anthropic-ai/sdk';
|
package/dist/index.js
CHANGED
|
@@ -1,58 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
import { BmaApiError, BmaError } from "./errors.js";
|
|
11
|
-
import { bmaOrigin } from "./core.js";
|
|
12
|
-
import { RestClientBase } from "./generated/rest-resources.js";
|
|
13
|
-
import { SDK_VERSION } from "./version.js";
|
|
14
|
-
export { SDK_VERSION };
|
|
15
|
-
export * as Resources from "./generated/rest-resources.js";
|
|
16
|
-
export { APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, BmaApiError, BmaError, ConflictError, ContentTooLargeError, EventStreamError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, RequestTimeoutError, ServiceUnavailableError, UnprocessableEntityError, } from "./errors.js";
|
|
17
|
-
export { DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS } from "./core.js";
|
|
18
|
-
export { PagePromise } from "./pagination.js";
|
|
19
|
-
export { Stream } from "./streaming.js";
|
|
20
|
-
export { defineTool, ToolError } from "./lib/tool-runner.js";
|
|
21
|
-
/** Hosted BMA origin; the client adds the /api/v1 prefix. */
|
|
22
|
-
export const DEFAULT_BASE_URL = "https://api.bma.beeos.ai";
|
|
23
|
-
function env(name) {
|
|
24
|
-
const value = typeof process === "undefined" ? undefined : process.env?.[name]?.trim();
|
|
25
|
-
return value || undefined;
|
|
26
|
-
}
|
|
27
|
-
/** Authenticated BMA REST client. */
|
|
28
|
-
export class BmaClient extends RestClientBase {
|
|
29
|
-
/**
|
|
30
|
-
* Escape hatch: the openapi-fetch client typed by contract path, for
|
|
31
|
-
* operations without a resource method (Machine Daemon). Pair with unwrap().
|
|
32
|
-
*/
|
|
33
|
-
rest;
|
|
34
|
-
constructor(options = {}) {
|
|
35
|
-
const token = options.token?.trim() || env("BMA_TOKEN");
|
|
36
|
-
if (!token)
|
|
37
|
-
throw new BmaError("bma: token is required; pass token or set BMA_TOKEN");
|
|
38
|
-
const baseUrl = `${bmaOrigin(options.baseUrl?.trim() || env("BMA_BASE_URL") || DEFAULT_BASE_URL)}/api/v1`;
|
|
39
|
-
const headers = { Authorization: `Bearer ${token}`, "User-Agent": `bma-sdk-typescript/${SDK_VERSION}` };
|
|
40
|
-
super({
|
|
41
|
-
baseUrl,
|
|
42
|
-
fetch: options.fetch,
|
|
43
|
-
timeout: options.timeout,
|
|
44
|
-
maxRetries: options.maxRetries,
|
|
45
|
-
headers,
|
|
46
|
-
scope: { org_id: options.orgId ?? env("BMA_ORG_ID"), project_id: options.projectId ?? env("BMA_PROJECT_ID") },
|
|
47
|
-
scopeOption: { org_id: "orgId", project_id: "projectId" },
|
|
48
|
-
});
|
|
49
|
-
this.rest = createClient({ baseUrl: this.baseUrl, fetch: options.fetch ?? globalThis.fetch, headers });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/** Escape hatch companion of `bma.rest`: returns `data` or throws the typed error. */
|
|
53
|
-
export function unwrap(result) {
|
|
54
|
-
if (result.response.ok)
|
|
55
|
-
return result.data;
|
|
56
|
-
throw BmaApiError.generate(result.response.status, result.error, result.response.headers);
|
|
57
|
-
}
|
|
1
|
+
export { BmaClient, DEFAULT_BASE_URL } from './client.js';
|
|
2
|
+
export { BmaClient as default } from './client.js';
|
|
3
|
+
export { SDK_VERSION } from './version.js';
|
|
4
|
+
export { errorCode } from './errors.js';
|
|
5
|
+
export { agentExtensions, environmentExtensions, eventExtensions, sessionExtensions, } from './extensions.js';
|
|
6
|
+
export * from './generated/extensions-resources.js';
|
|
7
|
+
export { BmaBeta, BmaEvents, BmaSessions } from './beta.js';
|
|
8
|
+
// The official error classes, so one import serves error handling.
|
|
9
|
+
export { AnthropicError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, ConflictError, ContentTooLargeError, GatewayTimeoutError, InternalServerError, NotFoundError, OverloadedError, PermissionDeniedError, PreconditionFailedError, RateLimitError, RequestTimeoutError, ServiceUnavailableError, UnprocessableEntityError, } from '@anthropic-ai/sdk';
|
|
58
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAyB,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,iBAAiB,GAelB,MAAM,iBAAiB,CAAC;AACzB,cAAc,qCAAqC,CAAC;AAEpD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAmB,MAAM,WAAW,CAAC;AAC7E,mEAAmE;AACnE,OAAO,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
+
/** The per-request options of the official client (its type is not exported). */
|
|
3
|
+
export type RequestOptions = NonNullable<Parameters<Anthropic['beta']['sessions']['events']['stream']>[2]>;
|
|
4
|
+
type HeadersLike = RequestOptions['headers'];
|
|
5
|
+
/** Merges header sets; a later one wins. Explicit nulls (unset a default) are kept. */
|
|
6
|
+
export declare function mergeHeaders(sets: HeadersLike[]): Headers;
|
|
7
|
+
/** Tagged template for a URL path: every interpolated segment is checked and percent-encoded. */
|
|
8
|
+
export declare function path(strings: TemplateStringsArray, ...segments: string[]): string;
|
|
9
|
+
export {};
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Merges header sets; a later one wins. Explicit nulls (unset a default) are kept. */
|
|
2
|
+
export function mergeHeaders(sets) {
|
|
3
|
+
const out = new Headers();
|
|
4
|
+
for (const set of sets) {
|
|
5
|
+
if (!set)
|
|
6
|
+
continue;
|
|
7
|
+
const entries = set instanceof Headers ? set.entries()
|
|
8
|
+
: Array.isArray(set) ? set
|
|
9
|
+
: 'values' in set && set.values instanceof Headers ? set.values.entries()
|
|
10
|
+
: Object.entries(set);
|
|
11
|
+
for (const [name, value] of entries) {
|
|
12
|
+
if (value === undefined || value === null)
|
|
13
|
+
out.delete(name);
|
|
14
|
+
else
|
|
15
|
+
out.set(name, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/** Tagged template for a URL path: every interpolated segment is checked and percent-encoded. */
|
|
21
|
+
export function path(strings, ...segments) {
|
|
22
|
+
return strings.reduce((url, text, i) => {
|
|
23
|
+
if (i === 0)
|
|
24
|
+
return text;
|
|
25
|
+
const segment = segments[i - 1];
|
|
26
|
+
if (segment === '' || segment === '.' || segment === '..') {
|
|
27
|
+
throw new TypeError(`Expected a valid path segment but received ${JSON.stringify(segment)}`);
|
|
28
|
+
}
|
|
29
|
+
return url + encodeURIComponent(segment) + text;
|
|
30
|
+
}, '');
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAOA,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC9C,MAAM,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;IAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG;YAAE,SAAS;QACnB,MAAM,OAAO,GACX,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE;YACtC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAA0B;gBAClD,CAAC,CAAC,QAAQ,IAAI,GAAG,IAAK,GAA2B,CAAC,MAAM,YAAY,OAAO,CAAC,CAAC,CAAE,GAA2B,CAAC,MAAM,CAAC,OAAO,EAAE;oBAC3H,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAgD,CAAC,CAAC;QACrE,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;YACpC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;gBAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;gBACvD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,IAAI,CAAC,OAA6B,EAAE,GAAG,QAAkB;IACvE,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE;QACrC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACzB,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC;QACjC,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC1D,MAAM,IAAI,SAAS,CAAC,8CAA8C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/F,CAAC;QACD,OAAO,GAAG,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAClD,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
package/dist/resume.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Stream } from '@anthropic-ai/sdk/core/streaming';
|
|
2
|
+
import type { BaseAnthropic } from '@anthropic-ai/sdk/client';
|
|
3
|
+
/** Stream resumption: a dropped stream reconnects with Last-Event-ID, up to
|
|
4
|
+
* `maxReconnects` attempts in a row with exponential backoff from `backoffMs`
|
|
5
|
+
* to `maxBackoffMs`. Exported for the tests; not part of the public API. */
|
|
6
|
+
export declare const streamResume: {
|
|
7
|
+
maxReconnects: number;
|
|
8
|
+
backoffMs: number;
|
|
9
|
+
maxBackoffMs: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* resumable wraps the official, non-resuming event stream `first`. When the
|
|
13
|
+
* connection drops or the server ends the stream, it calls `connect` with the
|
|
14
|
+
* Last-Event-ID to send and carries on with the new stream, so no event is lost
|
|
15
|
+
* or repeated. One durable BMA event (a `bma_sequence`) projects into several
|
|
16
|
+
* frames that share its sequence and the server resumes after a whole
|
|
17
|
+
* sequence: it resumes after the previous sequence and skips the frames it
|
|
18
|
+
* already returned. It stops when the stream is aborted, after `maxReconnects`
|
|
19
|
+
* failed attempts in a row, or on an API error other than 408, 409, 429 and
|
|
20
|
+
* 5xx (which the official client retries first). `after` is the Last-Event-ID
|
|
21
|
+
* `first` was opened with (none: the server's default position); a reconnect
|
|
22
|
+
* before any durable frame arrives reuses it, so the anchor survives a drop.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resumable<Item extends object>(first: Stream<Item>, connect: (lastEventID: string | undefined) => Promise<Stream<Item>>, client: BaseAnthropic, signal?: AbortSignal | null, after?: number): Stream<Item>;
|
package/dist/resume.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { APIConnectionError, APIError } from '@anthropic-ai/sdk/core/error';
|
|
2
|
+
import { Stream } from '@anthropic-ai/sdk/core/streaming';
|
|
3
|
+
/** Stream resumption: a dropped stream reconnects with Last-Event-ID, up to
|
|
4
|
+
* `maxReconnects` attempts in a row with exponential backoff from `backoffMs`
|
|
5
|
+
* to `maxBackoffMs`. Exported for the tests; not part of the public API. */
|
|
6
|
+
export const streamResume = { maxReconnects: 5, backoffMs: 500, maxBackoffMs: 8000 };
|
|
7
|
+
function retryableStatus(status) {
|
|
8
|
+
return status === 408 || status === 409 || status === 429 || (status !== undefined && status >= 500);
|
|
9
|
+
}
|
|
10
|
+
function isAbort(error) {
|
|
11
|
+
return error instanceof Error && (error.name === 'AbortError' || error.name === 'APIUserAbortError');
|
|
12
|
+
}
|
|
13
|
+
function sleep(ms, signal) {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
const timer = setTimeout(done, ms);
|
|
16
|
+
signal.addEventListener('abort', done, { once: true });
|
|
17
|
+
function done() {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
signal.removeEventListener('abort', done);
|
|
20
|
+
resolve();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* resumable wraps the official, non-resuming event stream `first`. When the
|
|
26
|
+
* connection drops or the server ends the stream, it calls `connect` with the
|
|
27
|
+
* Last-Event-ID to send and carries on with the new stream, so no event is lost
|
|
28
|
+
* or repeated. One durable BMA event (a `bma_sequence`) projects into several
|
|
29
|
+
* frames that share its sequence and the server resumes after a whole
|
|
30
|
+
* sequence: it resumes after the previous sequence and skips the frames it
|
|
31
|
+
* already returned. It stops when the stream is aborted, after `maxReconnects`
|
|
32
|
+
* failed attempts in a row, or on an API error other than 408, 409, 429 and
|
|
33
|
+
* 5xx (which the official client retries first). `after` is the Last-Event-ID
|
|
34
|
+
* `first` was opened with (none: the server's default position); a reconnect
|
|
35
|
+
* before any durable frame arrives reuses it, so the anchor survives a drop.
|
|
36
|
+
*/
|
|
37
|
+
export function resumable(first, connect, client, signal, after) {
|
|
38
|
+
const master = new AbortController();
|
|
39
|
+
let current = first;
|
|
40
|
+
master.signal.addEventListener('abort', () => current?.controller.abort());
|
|
41
|
+
signal?.addEventListener('abort', () => master.abort(), { once: true });
|
|
42
|
+
let consumed = false;
|
|
43
|
+
async function* iterate() {
|
|
44
|
+
if (consumed) {
|
|
45
|
+
throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
46
|
+
}
|
|
47
|
+
consumed = true;
|
|
48
|
+
let sequence = 0; // bma_sequence of the last durable frame
|
|
49
|
+
let resumeAfter = after; // Last-Event-ID a reconnect sends
|
|
50
|
+
const seen = new Set(); // frame ids returned at `sequence`
|
|
51
|
+
let failures = 0;
|
|
52
|
+
try {
|
|
53
|
+
for (;;) {
|
|
54
|
+
let cause = new Error('stream ended');
|
|
55
|
+
try {
|
|
56
|
+
for await (const frame of current) {
|
|
57
|
+
const { id = '', bma_sequence: seq = 0 } = frame;
|
|
58
|
+
if (seq > 0) {
|
|
59
|
+
if (seq < sequence)
|
|
60
|
+
continue; // replayed after a reconnect
|
|
61
|
+
if (seq === sequence) {
|
|
62
|
+
if (seen.has(id))
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
sequence = seq;
|
|
67
|
+
resumeAfter = seq - 1;
|
|
68
|
+
seen.clear();
|
|
69
|
+
}
|
|
70
|
+
seen.add(id);
|
|
71
|
+
}
|
|
72
|
+
else if (id !== '') {
|
|
73
|
+
// An announcement ahead of its durable copy (such as the
|
|
74
|
+
// session.status_idle of requires_action): a replay of the
|
|
75
|
+
// current sequence must not return it twice.
|
|
76
|
+
if (seen.has(id))
|
|
77
|
+
continue;
|
|
78
|
+
seen.add(id);
|
|
79
|
+
}
|
|
80
|
+
failures = 0;
|
|
81
|
+
yield frame;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (master.signal.aborted || isAbort(error))
|
|
86
|
+
return;
|
|
87
|
+
if (error instanceof APIError && !(error instanceof APIConnectionError))
|
|
88
|
+
throw error;
|
|
89
|
+
cause = error;
|
|
90
|
+
}
|
|
91
|
+
current?.controller.abort();
|
|
92
|
+
for (;;) {
|
|
93
|
+
if (master.signal.aborted)
|
|
94
|
+
return;
|
|
95
|
+
if (failures >= streamResume.maxReconnects) {
|
|
96
|
+
throw new Error(`bma-sdk: event stream not resumed after ${failures} attempts`, { cause });
|
|
97
|
+
}
|
|
98
|
+
const delay = Math.min(streamResume.backoffMs * 2 ** failures, streamResume.maxBackoffMs);
|
|
99
|
+
failures++;
|
|
100
|
+
await sleep(delay, master.signal);
|
|
101
|
+
if (master.signal.aborted)
|
|
102
|
+
return;
|
|
103
|
+
try {
|
|
104
|
+
// Resume after the previous sequence; none yet means the anchor
|
|
105
|
+
// the stream was opened with, or the server's default position
|
|
106
|
+
// (new events only) without one.
|
|
107
|
+
current = await connect(resumeAfter === undefined ? undefined : String(resumeAfter));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (master.signal.aborted || isAbort(error))
|
|
112
|
+
return;
|
|
113
|
+
if (error instanceof APIError && !(error instanceof APIConnectionError) && !retryableStatus(error.status)) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
cause = error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
master.abort();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return new Stream(iterate, master, client);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=resume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.js","sourceRoot":"","sources":["../src/resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAG1D;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,aAAa,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAOrF,SAAS,eAAe,CAAC,MAA0B;IACjD,OAAO,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC;AACvG,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,CAAC,CAAC;AACvG,CAAC;AAED,SAAS,KAAK,CAAC,EAAU,EAAE,MAAmB;IAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,CAAC,gBAAgB,CAAC,OA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.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0
|
|
1
|
+
export declare const SDK_VERSION = "2.1.0";
|
package/dist/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The package
|
|
2
|
-
// equal to package.json
|
|
3
|
-
export const SDK_VERSION = "1.0
|
|
1
|
+
// The version of this package, sent as X-BMA-SDK; tools/check_versions.sh keeps
|
|
2
|
+
// it equal to package.json.
|
|
3
|
+
export const SDK_VERSION = "2.1.0";
|
|
4
4
|
//# sourceMappingURL=version.js.map
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,4BAA4B;AAC5B,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beeos-ai/bma-sdk",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "TypeScript client for the
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "TypeScript client for BMA: the official Anthropic SDK with the BMA extensions (machines, machine pools, desktop and terminal sessions) under client.beta.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,10 +13,6 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"import": "./dist/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./facade-extensions": {
|
|
18
|
-
"types": "./dist/facade-extensions.d.ts",
|
|
19
|
-
"import": "./dist/facade-extensions.js"
|
|
20
16
|
}
|
|
21
17
|
},
|
|
22
18
|
"files": [
|
|
@@ -27,18 +23,16 @@
|
|
|
27
23
|
"node": ">=20"
|
|
28
24
|
},
|
|
29
25
|
"scripts": {
|
|
30
|
-
"generate": "openapi-typescript ../.build/
|
|
26
|
+
"generate": "openapi-typescript ../.build/extensions.openapi.ts.yaml --default-non-nullable=false -o src/generated/extensions.ts",
|
|
31
27
|
"build": "tsc -p tsconfig.json",
|
|
32
28
|
"test": "tsc -p tsconfig.test.json && node --test build-test/test/*.test.js"
|
|
33
29
|
},
|
|
34
30
|
"dependencies": {
|
|
35
|
-
"
|
|
31
|
+
"@anthropic-ai/sdk": "1.6.0"
|
|
36
32
|
},
|
|
37
33
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^
|
|
39
|
-
"expect-type": "1.4.0",
|
|
34
|
+
"@types/node": "^26.6.6",
|
|
40
35
|
"openapi-typescript": "7.13.0",
|
|
41
|
-
"typescript": "5.9.3"
|
|
42
|
-
"zod": "4.6.7"
|
|
36
|
+
"typescript": "5.9.3"
|
|
43
37
|
}
|
|
44
38
|
}
|
package/dist/core.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { PagePromise, type CursorPageBody } from "./pagination.js";
|
|
2
|
-
import { Stream } from "./streaming.js";
|
|
3
|
-
/**
|
|
4
|
-
* Default per-attempt timeout (D3), measured until the response headers
|
|
5
|
-
* arrive. Uploads (binary and multipart bodies) have no default timeout;
|
|
6
|
-
* event streams and downloads are bounded only until the headers arrive.
|
|
7
|
-
*/
|
|
8
|
-
export declare const DEFAULT_TIMEOUT_MS = 60000;
|
|
9
|
-
/** Default retries after the first attempt (D3; @anthropic-ai/sdk uses 2). */
|
|
10
|
-
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
11
|
-
/** Generated description of one contract operation. */
|
|
12
|
-
export interface OperationDescriptor {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
15
|
-
readonly path: string;
|
|
16
|
-
/** Path template name -> params key (scope params) or positional name. */
|
|
17
|
-
readonly pathParams?: Readonly<Record<string, string>>;
|
|
18
|
-
/** Query name -> serialization style. */
|
|
19
|
-
readonly query?: Readonly<Record<string, string>>;
|
|
20
|
-
/** Header name -> params key. */
|
|
21
|
-
readonly headers?: Readonly<Record<string, string>>;
|
|
22
|
-
readonly body?: "json" | "binary" | "multipart";
|
|
23
|
-
readonly bodyRequired?: boolean;
|
|
24
|
-
readonly multipartJSON?: readonly string[];
|
|
25
|
-
readonly response: "json" | "void" | "binary" | "sse";
|
|
26
|
-
/** The operation accepts an Idempotency-Key header. */
|
|
27
|
-
readonly idempotency?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Paginated list: [query parameter, response field] pairs, the default
|
|
30
|
-
* direction first, e.g. [["cursor", "next_cursor"]].
|
|
31
|
-
*/
|
|
32
|
-
readonly page?: readonly (readonly [string, string])[];
|
|
33
|
-
}
|
|
34
|
-
/** Per-request options; every resource method takes them last. */
|
|
35
|
-
export interface RequestOptions {
|
|
36
|
-
/**
|
|
37
|
-
* Per-attempt timeout in milliseconds, until the response headers arrive;
|
|
38
|
-
* 0 means none. Uploads use only this per-call value (no client default).
|
|
39
|
-
*/
|
|
40
|
-
timeout?: number;
|
|
41
|
-
/** Retries after the first attempt; for event streams, reconnects in a row without receiving data. */
|
|
42
|
-
maxRetries?: number;
|
|
43
|
-
signal?: AbortSignal;
|
|
44
|
-
/**
|
|
45
|
-
* Idempotency-Key for operations that declare it. When omitted the SDK
|
|
46
|
-
* generates one and reuses it across the retries of this call.
|
|
47
|
-
*/
|
|
48
|
-
idempotencyKey?: string;
|
|
49
|
-
headers?: Record<string, string>;
|
|
50
|
-
}
|
|
51
|
-
/** A raw request body: file contents or bytes. */
|
|
52
|
-
export type Uploadable = Blob | ArrayBuffer | ArrayBufferView | string;
|
|
53
|
-
/** @internal A body that may be omitted entirely. */
|
|
54
|
-
export type OptionalBody<B> = B | {
|
|
55
|
-
[K in keyof B]?: never;
|
|
56
|
-
};
|
|
57
|
-
/** @internal A multipart body whose binary fields take a Blob or File. */
|
|
58
|
-
export type MultipartBody<B, Files extends PropertyKey> = B extends unknown ? {
|
|
59
|
-
[K in keyof B]: K extends Files ? Blob : B[K];
|
|
60
|
-
} : never;
|
|
61
|
-
/** @internal */
|
|
62
|
-
export interface ClientCoreOptions {
|
|
63
|
-
baseUrl: string;
|
|
64
|
-
fetch?: typeof globalThis.fetch;
|
|
65
|
-
timeout?: number;
|
|
66
|
-
maxRetries?: number;
|
|
67
|
-
/** Authentication and other headers sent on every request. */
|
|
68
|
-
headers: Record<string, string>;
|
|
69
|
-
/** Scope defaults keyed by params name (org_id, project_id). */
|
|
70
|
-
scope: Record<string, string | undefined>;
|
|
71
|
-
/** Client option that sets each scope default, for error messages. */
|
|
72
|
-
scopeOption: Record<string, string>;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* The deployment origin of a BMA base URL (BMA_BASE_URL): trailing slashes and
|
|
76
|
-
* a trailing /api/v1 (the pre-1.0 API-root form) are removed, so the SDK adds
|
|
77
|
-
* each API prefix exactly once.
|
|
78
|
-
*/
|
|
79
|
-
export declare function bmaOrigin(baseUrl: string): string;
|
|
80
|
-
/** @internal The transport every resource calls. */
|
|
81
|
-
export declare class ClientCore {
|
|
82
|
-
#private;
|
|
83
|
-
readonly baseUrl: string;
|
|
84
|
-
constructor(options: ClientCoreOptions);
|
|
85
|
-
/** @internal */
|
|
86
|
-
_request<T>(op: OperationDescriptor, path: Record<string, string>, params: object, options?: RequestOptions): Promise<T>;
|
|
87
|
-
/**
|
|
88
|
-
* @internal A paginated list. The cursor parameter is the one of
|
|
89
|
-
* `op.page` the caller passed (e.g. before_sequence), else the default.
|
|
90
|
-
*/
|
|
91
|
-
_page<R extends CursorPageBody>(op: OperationDescriptor, path: Record<string, string>, params: object, options?: RequestOptions): PagePromise<R>;
|
|
92
|
-
/**
|
|
93
|
-
* @internal Event stream with EventSource reconnection: when the
|
|
94
|
-
* connection drops or the server ends the response (a rolling restart), or
|
|
95
|
-
* sends an `error` frame with code `service_unavailable`, the stream
|
|
96
|
-
* reconnects with Last-Event-ID set to the last durable frame. A frame not
|
|
97
|
-
* terminated before the end is discarded. Reconnects are bounded by
|
|
98
|
-
* `maxReconnects` (default `maxRetries`) attempts in a row that receive no
|
|
99
|
-
* data; any other error frame ends the stream with EventStreamError.
|
|
100
|
-
*/
|
|
101
|
-
_stream<T>(op: OperationDescriptor, path: Record<string, string>, params: object, options?: RequestOptions, hooks?: {
|
|
102
|
-
onOpen?: () => void;
|
|
103
|
-
maxReconnects?: number;
|
|
104
|
-
}): Stream<T>;
|
|
105
|
-
}
|