@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
package/README.md
CHANGED
|
@@ -2,151 +2,92 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@beeos-ai/bma-sdk)
|
|
4
4
|
|
|
5
|
-
TypeScript client for
|
|
6
|
-
[
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
TypeScript client for BMA, version 2.0 (ADR 0025): **the official
|
|
6
|
+
[`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk) 1.6.0
|
|
7
|
+
plus the BMA extensions**. `BmaClient` extends the official `Anthropic` client,
|
|
8
|
+
so every Claude Managed Agents resource under `client.beta` (agents,
|
|
9
|
+
environments, sessions, events, files, skills, vaults, memory stores, …) is the
|
|
10
|
+
official one with its signatures; the BMA extensions (`machines`,
|
|
11
|
+
`machinePools` and `.grants`, `desktopSessions` and `.tickets`,
|
|
12
|
+
`terminalSessions` and `.tickets`, `organization.projects`) are generated from
|
|
13
|
+
[`contracts/bma/v2/extensions.openapi.yaml`](../contracts/bma/v2/extensions.openapi.yaml)
|
|
14
|
+
and use the same client: base URL, authentication, retries, timeouts, `fetch`,
|
|
15
|
+
middleware and error classes. Server side only: the API key is a tenant
|
|
16
|
+
credential (hand end users a ticket, never the key).
|
|
9
17
|
|
|
10
18
|
| | |
|
|
11
19
|
| --- | --- |
|
|
12
|
-
| Version | 1.0
|
|
13
|
-
|
|
|
20
|
+
| Version | 2.1.0, see [CHANGELOG](../CHANGELOG.md); from 1.x: [MIGRATION](../MIGRATION.md#typescript-1x--20) |
|
|
21
|
+
| Official core | `@anthropic-ai/sdk` 1.6.0 (exact pin) |
|
|
14
22
|
| Node.js | 20 or newer; ESM |
|
|
15
23
|
|
|
16
24
|
```ts
|
|
17
|
-
import { BmaClient } from "@beeos-ai/bma-sdk";
|
|
25
|
+
import { BmaClient, errorCode, sessionExtensions } from "@beeos-ai/bma-sdk";
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
orgId: "org_...", // defaults: also read from BMA_ORG_ID / BMA_PROJECT_ID
|
|
23
|
-
projectId: "prj_...",
|
|
24
|
-
});
|
|
27
|
+
// apiKey: BMA_API_KEY, baseURL: BMA_BASE_URL (default https://api.bma.beeos.ai),
|
|
28
|
+
// project: BMA_PROJECT_ID. ANTHROPIC_* is never read.
|
|
29
|
+
const client = new BmaClient({ apiKey: process.env.BMA_API_KEY, baseURL: process.env.BMA_BASE_URL });
|
|
25
30
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
31
|
+
const session = await client.beta.sessions.create({
|
|
32
|
+
agent: agentId,
|
|
33
|
+
environment_id: environmentId,
|
|
34
|
+
bma_model_override: { model: "deepseek-flash" }, // typed BMA field
|
|
35
|
+
});
|
|
36
|
+
console.log(sessionExtensions(session).modelOverride);
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
// Open the stream first, then send. A dropped stream resumes with Last-Event-ID
|
|
39
|
+
// and returns every event once.
|
|
40
|
+
const stream = await client.beta.sessions.events.stream(session.id);
|
|
41
|
+
await client.beta.sessions.events.send(session.id, {
|
|
42
|
+
events: [{ type: "user.message", content: [{ type: "text", text: "Start the task." }] }],
|
|
43
|
+
});
|
|
44
|
+
for await (const event of stream) {
|
|
45
|
+
if (event.type === "session.status_idle") break;
|
|
39
46
|
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Set `baseUrl` to the origin of your BMA deployment (for example
|
|
43
|
-
`https://api.staging.bma.beeos.ai`; the default `https://api.bma.beeos.ai` does
|
|
44
|
-
not resolve yet). The client adds `/api/v1`; a value already ending in
|
|
45
|
-
`/api/v1` is accepted. `token` and `baseUrl` default to
|
|
46
|
-
`BMA_TOKEN` and `BMA_BASE_URL`, `orgId` and `projectId` to `BMA_ORG_ID` and
|
|
47
|
-
`BMA_PROJECT_ID`.
|
|
48
|
-
|
|
49
|
-
## Methods
|
|
50
|
-
|
|
51
|
-
Every contract operation is a method on a resource: path IDs are positional
|
|
52
|
-
arguments, `params` is the operation's query, header and body fields in one
|
|
53
|
-
object (wire names, snake_case), and `options` is the per-request
|
|
54
|
-
`{ timeout, maxRetries, signal, idempotencyKey, headers }`. Params and results
|
|
55
|
-
are the contract types; every schema is exported by name (`AgentSession`,
|
|
56
|
-
`ToolCall`, ...).
|
|
57
|
-
|
|
58
|
-
- **Scope.** `orgId` / `projectId` fill the organization and project of every
|
|
59
|
-
method; pass `org_id` / `project_id` in params to override one call.
|
|
60
|
-
- **Lists.** Every list whose response is `{ data, next_<param> }` returns a
|
|
61
|
-
`PagePromise`: `await` gives the first page (`page.data`,
|
|
62
|
-
`page.hasNextPage()`, `page.getNextPage()`), and
|
|
63
|
-
`for await (const agent of bma.agents.list())` walks every item. Besides
|
|
64
|
-
`cursor` lists this covers `agents.events.list` (forward by
|
|
65
|
-
`after_sequence`, backward when you pass `before_sequence`),
|
|
66
|
-
`agents.sessions.list` (`before_id`), `agentSessions.list` (`after_id`),
|
|
67
|
-
`agents.turns.list`, `agents.turns.events.list` and `files.list` (`page`).
|
|
68
|
-
- **Event stream.** `agents.events.stream()` yields frames discriminated by
|
|
69
|
-
`event`; durable frames carry `id` and `sequence`. Like EventSource, it
|
|
70
|
-
reconnects with `Last-Event-ID` set to the last durable frame when the
|
|
71
|
-
connection drops, when the server ends the response (a deployment), or on
|
|
72
|
-
an `error` frame with code `service_unavailable`; a frame cut off at the end
|
|
73
|
-
is discarded. It never ends on its own: it throws once `maxRetries`
|
|
74
|
-
reconnects in a row received no data (a heartbeat counts as data), and any
|
|
75
|
-
other error frame throws `EventStreamError`.
|
|
76
|
-
- **Files.** Uploads take the bytes as `body` (`Blob`, `ArrayBuffer`, typed
|
|
77
|
-
array or string); downloads (`files.download`, `agents.artifacts.download`,
|
|
78
|
-
...) return the `Response`. `agents.artifacts.downloadVerified(artifact, { maxBytes })`
|
|
79
|
-
verifies the size and sha256 digest.
|
|
80
|
-
|
|
81
|
-
## Errors, retries, timeouts
|
|
82
|
-
|
|
83
|
-
Errors are `BmaApiError` subclasses named after the status, as in the
|
|
84
|
-
Anthropic SDK: `BadRequestError` (400), `AuthenticationError` (401),
|
|
85
|
-
`PermissionDeniedError` (403), `NotFoundError` (404), `ConflictError` (409),
|
|
86
|
-
`ContentTooLargeError` (413), `UnprocessableEntityError` (422),
|
|
87
|
-
`RateLimitError` (429), `InternalServerError` (5xx), `ServiceUnavailableError`
|
|
88
|
-
(503), plus `APIConnectionError`, `APIConnectionTimeoutError` and
|
|
89
|
-
`APIUserAbortError`. `error.code` is the contract's `ErrorCode`.
|
|
90
|
-
|
|
91
|
-
Each call retries twice by default (`maxRetries`) with exponential backoff,
|
|
92
|
-
honouring `retry-after-ms` / `retry-after`. Reads and operations that accept
|
|
93
|
-
an `Idempotency-Key` retry 408, 429, 5xx and connection errors; the SDK sends
|
|
94
|
-
a generated key (`bma-sdk-retry-<uuid>`) unless you pass `idempotencyKey`, and
|
|
95
|
-
reuses it across the retries. Other writes retry only 429, 503 and requests
|
|
96
|
-
that never reached the server. 409 is never retried. The timeout is 60 s per
|
|
97
|
-
attempt (`timeout`), measured until the response headers arrive; `0`
|
|
98
|
-
disables it. Uploads (binary and multipart bodies) get only a per-call
|
|
99
|
-
`timeout`, so a large file is never cut off by the client default (Node's
|
|
100
|
-
fetch still bounds connecting and waiting for headers). The `signal` also
|
|
101
|
-
aborts reading the response body. Every error the SDK throws is a
|
|
102
|
-
`BmaError`.
|
|
103
47
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
import { z } from "zod";
|
|
113
|
-
import { ToolError, defineTool } from "@beeos-ai/bma-sdk";
|
|
114
|
-
|
|
115
|
-
const weather = defineTool({
|
|
116
|
-
name: "get_weather",
|
|
117
|
-
description: "Current weather",
|
|
118
|
-
inputSchema: z.object({ city: z.string() }),
|
|
119
|
-
run: async ({ city }) => {
|
|
120
|
-
if (!city) throw new ToolError("city is empty"); // submitted as a failed result
|
|
121
|
-
return `Sunny in ${city}`; // string or result content blocks
|
|
122
|
-
},
|
|
48
|
+
// Or send first: sendAndStream opens the stream at the cursor read before the
|
|
49
|
+
// send (bma_resume_cursor), so frames an executor wrote before the stream
|
|
50
|
+
// opened are not lost. `replayed` is true when the server gave no cursor and
|
|
51
|
+
// the stream starts at Last-Event-ID 0 (pick your turn by bma_input_id).
|
|
52
|
+
const { sent, stream: turn } = await client.beta.sessions.events.sendAndStream(session.id, {
|
|
53
|
+
events: [{ type: "user.message", content: [{ type: "text", text: "Next step." }] }],
|
|
123
54
|
});
|
|
124
|
-
// weather.definition is the agent config entry for tools.get_weather.
|
|
125
|
-
|
|
126
|
-
const runner = bma.agents.toolCalls.runner(agentId, { session_id: session.id, tools: [weather] });
|
|
127
|
-
// ... later
|
|
128
|
-
await runner.stop();
|
|
129
|
-
```
|
|
130
55
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
silently.
|
|
56
|
+
// Extensions
|
|
57
|
+
for await (const machine of client.beta.machines.list({ limit: 20 })) console.log(machine.id);
|
|
58
|
+
const term = await client.beta.terminalSessions.create({ machine_id: machineId }); // sends an Idempotency-Key
|
|
59
|
+
const ticket = await client.beta.terminalSessions.tickets.create(term.id, {}); // single use; give it to the end user
|
|
136
60
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
import { FacadeExtensionsClient, bmaSequence } from "@beeos-ai/bma-sdk/facade-extensions";
|
|
61
|
+
try {
|
|
62
|
+
await client.beta.machines.retrieve("mch_x");
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.log(errorCode(err)); // BMA's error.code, e.g. "machine_not_found"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
144
67
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
68
|
+
- **Extension fields.** `sessionExtensions`, `agentExtensions`,
|
|
69
|
+
`environmentExtensions` and `eventExtensions` read `bma_*` response fields as
|
|
70
|
+
typed values; `sessions.create/update`, `agents.create/update` and
|
|
71
|
+
`environments.create/update` accept `bma_model_override`, `bma_harness` and
|
|
72
|
+
`bma_desktop` as typed params (`bma_model_override: null` revokes).
|
|
73
|
+
- **Project.** `new BmaClient({ project })` sets `x-bma-project-id`;
|
|
74
|
+
`client.withOptions({ project })` copies the client into another project.
|
|
75
|
+
- **Idempotency.** Extension creates send a random `Idempotency-Key` once per
|
|
76
|
+
call, so automatic retries resend it; pass `{ headers: { "Idempotency-Key": key } }`
|
|
77
|
+
to choose it. CMA creates get none unless you pass one.
|
|
78
|
+
- **Types.** The extension request and response types are exported by name
|
|
79
|
+
(`Machine`, `MachineCreateParams`, …); the whole schema set is
|
|
80
|
+
`components["schemas"]`.
|
|
81
|
+
- Credential features of the official client (profiles, `authToken`,
|
|
82
|
+
federation) are disabled: authentication is the BMA API key.
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm ci
|
|
88
|
+
npm run build # tsc
|
|
89
|
+
npm test # unit tests against a local server; BMA_INTEGRATION=1 adds the staging test
|
|
149
90
|
```
|
|
150
91
|
|
|
151
|
-
|
|
152
|
-
|
|
92
|
+
`src/generated/` is written by `tools/generate.sh` (openapi-typescript for the
|
|
93
|
+
types, `tools/sdkgen/ts2gen.py` for the services); never edit it by hand.
|
package/dist/beta.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { APIPromise } from '@anthropic-ai/sdk/core/api-promise';
|
|
2
|
+
import { type RequestOptions } from './internal.js';
|
|
3
|
+
import { Stream } from '@anthropic-ai/sdk/core/streaming';
|
|
4
|
+
import { Beta } from '@anthropic-ai/sdk/resources/beta/beta';
|
|
5
|
+
import { Agents, type AgentCreateParams, type AgentUpdateParams } from '@anthropic-ai/sdk/resources/beta/agents/agents';
|
|
6
|
+
import { Environments, type EnvironmentCreateParams, type EnvironmentUpdateParams } from '@anthropic-ai/sdk/resources/beta/environments/environments';
|
|
7
|
+
import { Events, type EventSendParams, type EventStreamParams } from '@anthropic-ai/sdk/resources/beta/sessions/events';
|
|
8
|
+
import { Sessions, type SessionCreateParams, type SessionUpdateParams } from '@anthropic-ai/sdk/resources/beta/sessions/sessions';
|
|
9
|
+
import { Organization } from '@anthropic-ai/sdk/resources/beta/organization/organization';
|
|
10
|
+
import type { AgentExtParams, EnvironmentExtParams, SessionCreateExt, SessionUpdateExt } from './extensions.js';
|
|
11
|
+
import { OrganizationProjects, type ExtensionServices } from './generated/extensions-resources.js';
|
|
12
|
+
type StreamEvent = Awaited<ReturnType<Events['stream']>> extends Stream<infer T> ? T : never;
|
|
13
|
+
/** The result of `sendAndStream`. */
|
|
14
|
+
export interface SentStream {
|
|
15
|
+
/** The send response. */
|
|
16
|
+
sent: Awaited<ReturnType<Events['send']>>;
|
|
17
|
+
/** Starts at the cursor read before the send: its first frames are the sent `user.message` and its turn. */
|
|
18
|
+
stream: Stream<StreamEvent>;
|
|
19
|
+
/** True when the server gave no `bma_resume_cursor` for a `user.message`: the stream replays from `Last-Event-ID: 0`. */
|
|
20
|
+
replayed: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** client.beta.sessions.events: the official resource whose `stream` resumes a dropped connection. */
|
|
23
|
+
export declare class BmaEvents extends Events {
|
|
24
|
+
/**
|
|
25
|
+
* Stream Events. Same signature and frames as the official method. When the
|
|
26
|
+
* connection drops or the server ends the stream, it reconnects with
|
|
27
|
+
* `Last-Event-ID` set to the `bma_sequence` before the one of the last frame
|
|
28
|
+
* and returns every event once. The official, non-resuming stream is
|
|
29
|
+
* `Events.prototype.stream.call(client.beta.sessions.events, ...)`.
|
|
30
|
+
*/
|
|
31
|
+
stream(sessionID: string, params?: EventStreamParams | undefined, options?: RequestOptions): APIPromise<Stream<StreamEvent>>;
|
|
32
|
+
/**
|
|
33
|
+
* Send events, then open the resuming stream at the cursor the send
|
|
34
|
+
* returned (`bma_resume_cursor`: the session's last sequence before the
|
|
35
|
+
* send), so a frame an executor wrote before the stream opened is not lost.
|
|
36
|
+
* The official pattern, a stream opened before the send, needs no cursor;
|
|
37
|
+
* this one is for a caller that sends first. Without a cursor for a
|
|
38
|
+
* `user.message` the stream starts at `Last-Event-ID: 0` and `replayed` is
|
|
39
|
+
* true: it replays the session from its first event, so it can carry events
|
|
40
|
+
* that precede the send; pick this one's turn by `bma_input_id`. A send
|
|
41
|
+
* with no `user.message` streams from the server's default position (new
|
|
42
|
+
* events only). A send error rejects with no stream; an error opening the
|
|
43
|
+
* stream rejects too, after the message was accepted.
|
|
44
|
+
*/
|
|
45
|
+
sendAndStream(sessionID: string, body: EventSendParams, params?: EventStreamParams | undefined, options?: RequestOptions): Promise<SentStream>;
|
|
46
|
+
private openStream;
|
|
47
|
+
}
|
|
48
|
+
/** client.beta.sessions: the official resource with the typed bma_* request fields and the resuming events stream. */
|
|
49
|
+
export declare class BmaSessions extends Sessions {
|
|
50
|
+
events: BmaEvents;
|
|
51
|
+
create(params: SessionCreateParams & SessionCreateExt, options?: RequestOptions): APIPromise<Beta.Sessions.BetaManagedAgentsSession>;
|
|
52
|
+
update(sessionID: string, params: SessionUpdateParams & SessionUpdateExt, options?: RequestOptions): APIPromise<Beta.Sessions.BetaManagedAgentsSession>;
|
|
53
|
+
}
|
|
54
|
+
/** client.beta.agents: the official resource with the typed bma_harness request field. */
|
|
55
|
+
export declare class BmaAgents extends Agents {
|
|
56
|
+
create(params: AgentCreateParams & AgentExtParams, options?: RequestOptions): APIPromise<Beta.Agents.BetaManagedAgentsAgent>;
|
|
57
|
+
update(agentID: string, params: AgentUpdateParams & AgentExtParams, options?: RequestOptions): APIPromise<Beta.Agents.BetaManagedAgentsAgent>;
|
|
58
|
+
}
|
|
59
|
+
/** client.beta.environments: the official resource with the typed bma_desktop request field. */
|
|
60
|
+
export declare class BmaEnvironments extends Environments {
|
|
61
|
+
create(params: EnvironmentCreateParams & EnvironmentExtParams, options?: RequestOptions): APIPromise<Beta.Environments.BetaEnvironment>;
|
|
62
|
+
update(environmentID: string, params: EnvironmentUpdateParams & EnvironmentExtParams, options?: RequestOptions): APIPromise<Beta.Environments.BetaEnvironment>;
|
|
63
|
+
}
|
|
64
|
+
/** client.beta.organization: the official resource plus `projects`. */
|
|
65
|
+
export declare class BmaOrganization extends Organization {
|
|
66
|
+
projects: OrganizationProjects;
|
|
67
|
+
}
|
|
68
|
+
/** client.beta: the official Beta resources plus the BMA extensions. */
|
|
69
|
+
export declare class BmaBeta extends Beta implements ExtensionServices {
|
|
70
|
+
agents: BmaAgents;
|
|
71
|
+
environments: BmaEnvironments;
|
|
72
|
+
sessions: BmaSessions;
|
|
73
|
+
organization: BmaOrganization;
|
|
74
|
+
machines: import("./generated/extensions-resources.js").Machines;
|
|
75
|
+
machinePools: import("./generated/extensions-resources.js").MachinePools;
|
|
76
|
+
desktopSessions: import("./generated/extensions-resources.js").DesktopSessions;
|
|
77
|
+
terminalSessions: import("./generated/extensions-resources.js").TerminalSessions;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
package/dist/beta.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { mergeHeaders } from './internal.js';
|
|
2
|
+
import { Beta } from '@anthropic-ai/sdk/resources/beta/beta';
|
|
3
|
+
import { Agents } from '@anthropic-ai/sdk/resources/beta/agents/agents';
|
|
4
|
+
import { Environments, } from '@anthropic-ai/sdk/resources/beta/environments/environments';
|
|
5
|
+
import { Events } from '@anthropic-ai/sdk/resources/beta/sessions/events';
|
|
6
|
+
import { Sessions, } from '@anthropic-ai/sdk/resources/beta/sessions/sessions';
|
|
7
|
+
import { Organization } from '@anthropic-ai/sdk/resources/beta/organization/organization';
|
|
8
|
+
import { OrganizationProjects, newExtensionServices } from './generated/extensions-resources.js';
|
|
9
|
+
import { resumable } from './resume.js';
|
|
10
|
+
function withLastEventID(options, lastEventID) {
|
|
11
|
+
return lastEventID === undefined ? options : ({ ...options, headers: mergeHeaders([options?.headers, { 'Last-Event-ID': lastEventID }]) });
|
|
12
|
+
}
|
|
13
|
+
/** The Last-Event-ID for a stream opened after a send: the smallest `bma_resume_cursor` of the response's
|
|
14
|
+
* `user.message` events; 0 and `replayed` when one has none; undefined without a `user.message`. */
|
|
15
|
+
function resumeCursor(sent) {
|
|
16
|
+
let after;
|
|
17
|
+
for (const event of (sent.data ?? [])) {
|
|
18
|
+
if (event.type !== 'user.message')
|
|
19
|
+
continue;
|
|
20
|
+
if (typeof event.bma_resume_cursor !== 'number')
|
|
21
|
+
return { after: 0, replayed: true };
|
|
22
|
+
after = after === undefined ? event.bma_resume_cursor : Math.min(after, event.bma_resume_cursor);
|
|
23
|
+
}
|
|
24
|
+
return { after, replayed: false };
|
|
25
|
+
}
|
|
26
|
+
/** client.beta.sessions.events: the official resource whose `stream` resumes a dropped connection. */
|
|
27
|
+
export class BmaEvents extends Events {
|
|
28
|
+
/**
|
|
29
|
+
* Stream Events. Same signature and frames as the official method. When the
|
|
30
|
+
* connection drops or the server ends the stream, it reconnects with
|
|
31
|
+
* `Last-Event-ID` set to the `bma_sequence` before the one of the last frame
|
|
32
|
+
* and returns every event once. The official, non-resuming stream is
|
|
33
|
+
* `Events.prototype.stream.call(client.beta.sessions.events, ...)`.
|
|
34
|
+
*/
|
|
35
|
+
stream(sessionID, params = {}, options) {
|
|
36
|
+
return this.openStream(sessionID, params, options);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Send events, then open the resuming stream at the cursor the send
|
|
40
|
+
* returned (`bma_resume_cursor`: the session's last sequence before the
|
|
41
|
+
* send), so a frame an executor wrote before the stream opened is not lost.
|
|
42
|
+
* The official pattern, a stream opened before the send, needs no cursor;
|
|
43
|
+
* this one is for a caller that sends first. Without a cursor for a
|
|
44
|
+
* `user.message` the stream starts at `Last-Event-ID: 0` and `replayed` is
|
|
45
|
+
* true: it replays the session from its first event, so it can carry events
|
|
46
|
+
* that precede the send; pick this one's turn by `bma_input_id`. A send
|
|
47
|
+
* with no `user.message` streams from the server's default position (new
|
|
48
|
+
* events only). A send error rejects with no stream; an error opening the
|
|
49
|
+
* stream rejects too, after the message was accepted.
|
|
50
|
+
*/
|
|
51
|
+
async sendAndStream(sessionID, body, params = {}, options) {
|
|
52
|
+
const sent = await this.send(sessionID, body, options);
|
|
53
|
+
const { after, replayed } = resumeCursor(sent);
|
|
54
|
+
const stream = await this.openStream(sessionID, params, options, after);
|
|
55
|
+
return { sent, stream, replayed };
|
|
56
|
+
}
|
|
57
|
+
openStream(sessionID, params, options, after) {
|
|
58
|
+
const open = (lastEventID) => super.stream(sessionID, params, withLastEventID(options, lastEventID));
|
|
59
|
+
return super
|
|
60
|
+
.stream(sessionID, params, withLastEventID(options, after === undefined ? undefined : String(after)))
|
|
61
|
+
._thenUnwrap((first) => resumable(first, open, this._client, options?.signal, after));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** client.beta.sessions: the official resource with the typed bma_* request fields and the resuming events stream. */
|
|
65
|
+
export class BmaSessions extends Sessions {
|
|
66
|
+
events = new BmaEvents(this._client);
|
|
67
|
+
create(params, options) {
|
|
68
|
+
return super.create(params, options);
|
|
69
|
+
}
|
|
70
|
+
update(sessionID, params, options) {
|
|
71
|
+
return super.update(sessionID, params, options);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** client.beta.agents: the official resource with the typed bma_harness request field. */
|
|
75
|
+
export class BmaAgents extends Agents {
|
|
76
|
+
create(params, options) {
|
|
77
|
+
return super.create(params, options);
|
|
78
|
+
}
|
|
79
|
+
update(agentID, params, options) {
|
|
80
|
+
return super.update(agentID, params, options);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** client.beta.environments: the official resource with the typed bma_desktop request field. */
|
|
84
|
+
export class BmaEnvironments extends Environments {
|
|
85
|
+
create(params, options) {
|
|
86
|
+
return super.create(params, options);
|
|
87
|
+
}
|
|
88
|
+
update(environmentID, params, options) {
|
|
89
|
+
return super.update(environmentID, params, options);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** client.beta.organization: the official resource plus `projects`. */
|
|
93
|
+
export class BmaOrganization extends Organization {
|
|
94
|
+
projects = new OrganizationProjects(this._client);
|
|
95
|
+
}
|
|
96
|
+
/** client.beta: the official Beta resources plus the BMA extensions. */
|
|
97
|
+
export class BmaBeta extends Beta {
|
|
98
|
+
agents = new BmaAgents(this._client);
|
|
99
|
+
environments = new BmaEnvironments(this._client);
|
|
100
|
+
sessions = new BmaSessions(this._client);
|
|
101
|
+
organization = new BmaOrganization(this._client);
|
|
102
|
+
machines = newExtensionServices(this._client).machines;
|
|
103
|
+
machinePools = newExtensionServices(this._client).machinePools;
|
|
104
|
+
desktopSessions = newExtensionServices(this._client).desktopSessions;
|
|
105
|
+
terminalSessions = newExtensionServices(this._client).terminalSessions;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=beta.js.map
|
package/dist/beta.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beta.js","sourceRoot":"","sources":["../src/beta.ts"],"names":[],"mappings":"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"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Anthropic, type ClientOptions } from '@anthropic-ai/sdk';
|
|
2
|
+
import { BmaBeta } from './beta.js';
|
|
3
|
+
/** The hosted BMA origin (the paths carry /v1). */
|
|
4
|
+
export declare const DEFAULT_BASE_URL = "https://api.bma.beeos.ai";
|
|
5
|
+
export interface BmaClientOptions extends Omit<ClientOptions, 'apiKey' | 'authToken' | 'credentials' | 'config' | 'profile' | 'baseURL' | 'webhookKey'> {
|
|
6
|
+
/** The BMA API key (a tenant credential, server side only). Defaults to process.env.BMA_API_KEY. */
|
|
7
|
+
apiKey?: string | null | undefined;
|
|
8
|
+
/** The deployment origin, e.g. https://api.staging.bma.beeos.ai. Defaults to process.env.BMA_BASE_URL, else DEFAULT_BASE_URL. */
|
|
9
|
+
baseURL?: string | null | undefined;
|
|
10
|
+
/** The project scope, sent as x-bma-project-id; required when the key can see more than one project. Defaults to process.env.BMA_PROJECT_ID. */
|
|
11
|
+
project?: string | null | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The BMA client: the official Anthropic client with the BMA defaults, whose
|
|
15
|
+
* `beta` adds the BMA extensions. It never reads the ANTHROPIC_API_KEY,
|
|
16
|
+
* ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL or credential-profile configuration
|
|
17
|
+
* of the official client: the key defaults to BMA_API_KEY, the origin to
|
|
18
|
+
* BMA_BASE_URL and the project to BMA_PROJECT_ID.
|
|
19
|
+
*
|
|
20
|
+
* Only use it on a server: the API key is a tenant credential. End-user
|
|
21
|
+
* clients get single-use tickets instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare class BmaClient extends Anthropic {
|
|
24
|
+
beta: BmaBeta;
|
|
25
|
+
constructor({ apiKey, baseURL, project, defaultHeaders, ...rest }?: BmaClientOptions);
|
|
26
|
+
/** A copy with other options; `project` replaces the project scope. */
|
|
27
|
+
withOptions(options: Partial<ClientOptions> & {
|
|
28
|
+
project?: string | null;
|
|
29
|
+
}): this;
|
|
30
|
+
/** Never resolve the official credential chain (profiles, federation, files). */
|
|
31
|
+
protected _shouldResolveDefaultCredentials(): boolean;
|
|
32
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
+
import { BmaBeta } from './beta.js';
|
|
3
|
+
import { SDK_VERSION } from './version.js';
|
|
4
|
+
/** The hosted BMA origin (the paths carry /v1). */
|
|
5
|
+
export const DEFAULT_BASE_URL = 'https://api.bma.beeos.ai';
|
|
6
|
+
function env(name) {
|
|
7
|
+
const value = typeof process !== 'undefined' ? process.env?.[name]?.trim() : undefined;
|
|
8
|
+
return value || undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The BMA client: the official Anthropic client with the BMA defaults, whose
|
|
12
|
+
* `beta` adds the BMA extensions. It never reads the ANTHROPIC_API_KEY,
|
|
13
|
+
* ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL or credential-profile configuration
|
|
14
|
+
* of the official client: the key defaults to BMA_API_KEY, the origin to
|
|
15
|
+
* BMA_BASE_URL and the project to BMA_PROJECT_ID.
|
|
16
|
+
*
|
|
17
|
+
* Only use it on a server: the API key is a tenant credential. End-user
|
|
18
|
+
* clients get single-use tickets instead.
|
|
19
|
+
*/
|
|
20
|
+
export class BmaClient extends Anthropic {
|
|
21
|
+
beta = new BmaBeta(this);
|
|
22
|
+
constructor({ apiKey, baseURL, project, defaultHeaders, ...rest } = {}) {
|
|
23
|
+
const key = apiKey || env('BMA_API_KEY');
|
|
24
|
+
if (!key) {
|
|
25
|
+
throw new TypeError('BmaClient: set the apiKey option or the BMA_API_KEY environment variable');
|
|
26
|
+
}
|
|
27
|
+
const scope = project || undefined;
|
|
28
|
+
super({
|
|
29
|
+
...rest,
|
|
30
|
+
apiKey: key,
|
|
31
|
+
authToken: null,
|
|
32
|
+
baseURL: baseURL || env('BMA_BASE_URL') || DEFAULT_BASE_URL,
|
|
33
|
+
defaultHeaders: {
|
|
34
|
+
'X-BMA-SDK': `bma-sdk-ts/${SDK_VERSION}`,
|
|
35
|
+
...(env('BMA_PROJECT_ID') ? { 'x-bma-project-id': env('BMA_PROJECT_ID') } : {}),
|
|
36
|
+
...defaultHeaders,
|
|
37
|
+
...(scope ? { 'x-bma-project-id': scope } : {}),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** A copy with other options; `project` replaces the project scope. */
|
|
42
|
+
withOptions(options) {
|
|
43
|
+
return super.withOptions(options);
|
|
44
|
+
}
|
|
45
|
+
/** Never resolve the official credential chain (profiles, federation, files). */
|
|
46
|
+
_shouldResolveDefaultCredentials() {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,mDAAmD;AACnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAY3D,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,OAAO,KAAK,IAAI,SAAS,CAAC;AAC5B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAU,SAAQ,SAAS;IAC7B,IAAI,GAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3C,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,KAAuB,EAAE;QACtF,MAAM,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,SAAS,CAAC,0EAA0E,CAAC,CAAC;QAClG,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,IAAI,SAAS,CAAC;QACnC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,MAAM,EAAE,GAAG;YACX,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,OAAO,IAAI,GAAG,CAAC,cAAc,CAAC,IAAI,gBAAgB;YAC3D,cAAc,EAAE;gBACd,WAAW,EAAE,cAAc,WAAW,EAAE;gBACxC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,GAAG,CAAC,gBAAgB,CAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChF,GAAG,cAAc;gBACjB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChD;SACF,CAAC,CAAC;IACL,CAAC;IAED,uEAAuE;IAC9D,WAAW,CAAC,OAA6D;QAChF,OAAO,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,iFAAiF;IAC9D,gCAAgC;QACjD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,77 +1,8 @@
|
|
|
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
1
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
2
|
+
* BMA's reason for an API error (`error.code` of the Anthropic error envelope,
|
|
3
|
+
* e.g. "idempotency_key_reused"), or undefined when `error` is not an API
|
|
4
|
+
* error or has no code. Branch on it rather than on the message. (The
|
|
5
|
+
* official `errorCode` property is `error.details.error_code`, which BMA does
|
|
6
|
+
* not set.)
|
|
51
7
|
*/
|
|
52
|
-
export declare
|
|
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 {};
|
|
8
|
+
export declare function errorCode(error: unknown): string | undefined;
|