@beeos-ai/bma-sdk 2.0.0 → 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 +9 -1
- package/dist/beta.d.ts +25 -1
- package/dist/beta.js +42 -4
- package/dist/beta.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/resume.d.ts +4 -2
- package/dist/resume.js +10 -5
- package/dist/resume.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ credential (hand end users a ticket, never the key).
|
|
|
17
17
|
|
|
18
18
|
| | |
|
|
19
19
|
| --- | --- |
|
|
20
|
-
| Version | 2.
|
|
20
|
+
| Version | 2.1.0, see [CHANGELOG](../CHANGELOG.md); from 1.x: [MIGRATION](../MIGRATION.md#typescript-1x--20) |
|
|
21
21
|
| Official core | `@anthropic-ai/sdk` 1.6.0 (exact pin) |
|
|
22
22
|
| Node.js | 20 or newer; ESM |
|
|
23
23
|
|
|
@@ -45,6 +45,14 @@ for await (const event of stream) {
|
|
|
45
45
|
if (event.type === "session.status_idle") break;
|
|
46
46
|
}
|
|
47
47
|
|
|
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." }] }],
|
|
54
|
+
});
|
|
55
|
+
|
|
48
56
|
// Extensions
|
|
49
57
|
for await (const machine of client.beta.machines.list({ limit: 20 })) console.log(machine.id);
|
|
50
58
|
const term = await client.beta.terminalSessions.create({ machine_id: machineId }); // sends an Idempotency-Key
|
package/dist/beta.d.ts
CHANGED
|
@@ -4,12 +4,21 @@ import { Stream } from '@anthropic-ai/sdk/core/streaming';
|
|
|
4
4
|
import { Beta } from '@anthropic-ai/sdk/resources/beta/beta';
|
|
5
5
|
import { Agents, type AgentCreateParams, type AgentUpdateParams } from '@anthropic-ai/sdk/resources/beta/agents/agents';
|
|
6
6
|
import { Environments, type EnvironmentCreateParams, type EnvironmentUpdateParams } from '@anthropic-ai/sdk/resources/beta/environments/environments';
|
|
7
|
-
import { Events, type EventStreamParams } from '@anthropic-ai/sdk/resources/beta/sessions/events';
|
|
7
|
+
import { Events, type EventSendParams, type EventStreamParams } from '@anthropic-ai/sdk/resources/beta/sessions/events';
|
|
8
8
|
import { Sessions, type SessionCreateParams, type SessionUpdateParams } from '@anthropic-ai/sdk/resources/beta/sessions/sessions';
|
|
9
9
|
import { Organization } from '@anthropic-ai/sdk/resources/beta/organization/organization';
|
|
10
10
|
import type { AgentExtParams, EnvironmentExtParams, SessionCreateExt, SessionUpdateExt } from './extensions.js';
|
|
11
11
|
import { OrganizationProjects, type ExtensionServices } from './generated/extensions-resources.js';
|
|
12
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
|
+
}
|
|
13
22
|
/** client.beta.sessions.events: the official resource whose `stream` resumes a dropped connection. */
|
|
14
23
|
export declare class BmaEvents extends Events {
|
|
15
24
|
/**
|
|
@@ -20,6 +29,21 @@ export declare class BmaEvents extends Events {
|
|
|
20
29
|
* `Events.prototype.stream.call(client.beta.sessions.events, ...)`.
|
|
21
30
|
*/
|
|
22
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;
|
|
23
47
|
}
|
|
24
48
|
/** client.beta.sessions: the official resource with the typed bma_* request fields and the resuming events stream. */
|
|
25
49
|
export declare class BmaSessions extends Sessions {
|
package/dist/beta.js
CHANGED
|
@@ -7,6 +7,22 @@ import { Sessions, } from '@anthropic-ai/sdk/resources/beta/sessions/sessions';
|
|
|
7
7
|
import { Organization } from '@anthropic-ai/sdk/resources/beta/organization/organization';
|
|
8
8
|
import { OrganizationProjects, newExtensionServices } from './generated/extensions-resources.js';
|
|
9
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
|
+
}
|
|
10
26
|
/** client.beta.sessions.events: the official resource whose `stream` resumes a dropped connection. */
|
|
11
27
|
export class BmaEvents extends Events {
|
|
12
28
|
/**
|
|
@@ -17,10 +33,32 @@ export class BmaEvents extends Events {
|
|
|
17
33
|
* `Events.prototype.stream.call(client.beta.sessions.events, ...)`.
|
|
18
34
|
*/
|
|
19
35
|
stream(sessionID, params = {}, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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));
|
|
24
62
|
}
|
|
25
63
|
}
|
|
26
64
|
/** client.beta.sessions: the official resource with the typed bma_* request fields and the resuming events stream. */
|
package/dist/beta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beta.js","sourceRoot":"","sources":["../src/beta.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAuB,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAkD,MAAM,gDAAgD,CAAC;AACxH,OAAO,EACL,YAAY,GAGb,MAAM,4DAA4D,CAAC;AACpE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"beta.js","sourceRoot":"","sources":["../src/beta.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAuB,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAkD,MAAM,gDAAgD,CAAC;AACxH,OAAO,EACL,YAAY,GAGb,MAAM,4DAA4D,CAAC;AACpE,OAAO,EAAE,MAAM,EAAgD,MAAM,kDAAkD,CAAC;AACxH,OAAO,EACL,QAAQ,GAGT,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAO1F,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EA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AC,OAAO,CAAC,CAAC,QAAQ,CAAC;IACvD,YAAY,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;IAC/D,eAAe,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC;IACrE,gBAAgB,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC;CACxE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export { errorCode } from './errors.js';
|
|
|
5
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
6
|
export * from './generated/extensions-resources.js';
|
|
7
7
|
export type { components } from './generated/extensions.js';
|
|
8
|
-
export { BmaBeta, BmaEvents, BmaSessions } from './beta.js';
|
|
8
|
+
export { BmaBeta, BmaEvents, BmaSessions, type SentStream } from './beta.js';
|
|
9
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
package/dist/resume.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export declare const streamResume: {
|
|
|
17
17
|
* sequence: it resumes after the previous sequence and skips the frames it
|
|
18
18
|
* already returned. It stops when the stream is aborted, after `maxReconnects`
|
|
19
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).
|
|
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.
|
|
21
23
|
*/
|
|
22
|
-
export declare function resumable<Item extends object>(first: Stream<Item>, connect: (lastEventID: string | undefined) => Promise<Stream<Item>>, client: BaseAnthropic, signal?: AbortSignal | null): Stream<Item>;
|
|
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
CHANGED
|
@@ -30,9 +30,11 @@ function sleep(ms, signal) {
|
|
|
30
30
|
* sequence: it resumes after the previous sequence and skips the frames it
|
|
31
31
|
* already returned. It stops when the stream is aborted, after `maxReconnects`
|
|
32
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).
|
|
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.
|
|
34
36
|
*/
|
|
35
|
-
export function resumable(first, connect, client, signal) {
|
|
37
|
+
export function resumable(first, connect, client, signal, after) {
|
|
36
38
|
const master = new AbortController();
|
|
37
39
|
let current = first;
|
|
38
40
|
master.signal.addEventListener('abort', () => current?.controller.abort());
|
|
@@ -44,6 +46,7 @@ export function resumable(first, connect, client, signal) {
|
|
|
44
46
|
}
|
|
45
47
|
consumed = true;
|
|
46
48
|
let sequence = 0; // bma_sequence of the last durable frame
|
|
49
|
+
let resumeAfter = after; // Last-Event-ID a reconnect sends
|
|
47
50
|
const seen = new Set(); // frame ids returned at `sequence`
|
|
48
51
|
let failures = 0;
|
|
49
52
|
try {
|
|
@@ -61,6 +64,7 @@ export function resumable(first, connect, client, signal) {
|
|
|
61
64
|
}
|
|
62
65
|
else {
|
|
63
66
|
sequence = seq;
|
|
67
|
+
resumeAfter = seq - 1;
|
|
64
68
|
seen.clear();
|
|
65
69
|
}
|
|
66
70
|
seen.add(id);
|
|
@@ -97,9 +101,10 @@ export function resumable(first, connect, client, signal) {
|
|
|
97
101
|
if (master.signal.aborted)
|
|
98
102
|
return;
|
|
99
103
|
try {
|
|
100
|
-
// Resume after the previous sequence; none yet means the
|
|
101
|
-
//
|
|
102
|
-
|
|
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));
|
|
103
108
|
break;
|
|
104
109
|
}
|
|
105
110
|
catch (error) {
|
package/dist/resume.js.map
CHANGED
|
@@ -1 +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,E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AC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.
|
|
1
|
+
export declare const SDK_VERSION = "2.1.0";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beeos-ai/bma-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
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": {
|