@beam-network/sdk 0.5.3 → 0.5.5
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 +1 -1
- package/dist/nats-control.d.ts +1 -0
- package/dist/nats-control.js +13 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ For low-level raw transfer configs, use `createRawTransfer`; lifecycle transport
|
|
|
98
98
|
|
|
99
99
|
Provider transfers use `transfer-client-control/v5`. Every reply carries Runtime and transport epochs; prepare and every route-stream message carry a UUID route generation. S3, R2, and S3-compatible destinations retain direct multipart UploadPart/ListParts/HEAD handling.
|
|
100
100
|
|
|
101
|
-
The client signs up to 64 routes concurrently by default and emits 2,048-route logical batches
|
|
101
|
+
The client signs up to 64 routes concurrently by default and emits 2,048-route logical batches. Encoded MessagePack requests target 4 MiB physical batches under `maxPayloadBytes` (8 MiB by default; explicit positive overrides remain supported). The splitter reserves control-envelope headroom for the live auth token and stable request identity so the final encoded request remains below the configured guard. A single route above the 4 MiB target but within the configured guard publishes alone; a single route larger than the configured limit fails before publication with both sizes in the error. Multipart create and abort requests use a separate `multipartControlConcurrency` limit of 2 by default, with explicit positive overrides supported, and S3-compatible control requests make up to five attempts for transient provider failures. This keeps URL signing throughput independent from provider control-plane pressure.
|
|
102
102
|
|
|
103
103
|
The stream ID derives from the transfer, selected flow, and immutable plan identity, and each ordered batch ID includes its route-coordinate checksum. Manual multi-destination attachment requires `delivery_index` on every route. Lifecycle mutations retry transient failures up to three times with the same request identity. A non-recoverable provider setup or route failure raises `BeamProviderTransferError`, whose `errors`, `transferCancelled`, and `multipartCleanupComplete` fields retain the original provider, cancellation, and cleanup outcomes. `waitForTransfer` subscribes to the API-key-owned, at-most-once terminal signal before its first status read and reconciles every signal through authoritative status; subscription failure degrades to the same jittered 15-to-30-second status fallback. Call `close()` when the client is no longer needed; it also closes outstanding terminal waiters.
|
|
104
104
|
|
package/dist/nats-control.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION = "transfer-client-c
|
|
|
4
4
|
export declare const BEAM_DEFAULT_NATS_URL = "tls://nats.b1m.ai:4222";
|
|
5
5
|
export declare const BEAM_DEFAULT_NATS_WS_URL = "wss://nats.b1m.ai:443";
|
|
6
6
|
export declare const BEAM_DEFAULT_MAX_PAYLOAD_BYTES: number;
|
|
7
|
+
export declare const BEAM_ROUTE_TARGET_PAYLOAD_BYTES: number;
|
|
7
8
|
export type TransferClientMessageType = "runtime.hello" | "transfer.plan" | "transfer.create" | "transfer.prepare" | "transfer.route_stream.begin" | "transfer.route_stream.manifest" | "transfer.route_stream.batch" | "transfer.route_stream.complete" | "transfer.distribute" | "transfer.status" | "transfer.cancel" | "transfer.resume";
|
|
8
9
|
export interface CompactSignedRouteBatch {
|
|
9
10
|
source_chunks: Array<{
|
package/dist/nats-control.js
CHANGED
|
@@ -6,6 +6,8 @@ export const BEAM_DEFAULT_NATS_WS_URL = "wss://nats.b1m.ai:443";
|
|
|
6
6
|
// NATS enforces max_payload per message. This guard splits signed-route control
|
|
7
7
|
// messages before the broker rejects them; transfer bytes never flow through NATS.
|
|
8
8
|
export const BEAM_DEFAULT_MAX_PAYLOAD_BYTES = 8 * 1024 * 1024;
|
|
9
|
+
export const BEAM_ROUTE_TARGET_PAYLOAD_BYTES = 4 * 1024 * 1024;
|
|
10
|
+
const ROUTE_BATCH_AUTH_TOKEN_ESTIMATE_BYTES = 64 * 1024;
|
|
9
11
|
export function buildConnectionOptions(options) {
|
|
10
12
|
const connectionOptions = {
|
|
11
13
|
servers: options.natsUrl,
|
|
@@ -284,6 +286,8 @@ export class BeamTransferControl {
|
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
288
|
splitRoutesForPayload(messageType, basePayload, routes) {
|
|
289
|
+
const targetPayloadBytes = Math.min(this.maxPayloadBytes, BEAM_ROUTE_TARGET_PAYLOAD_BYTES);
|
|
290
|
+
const authTokenEstimateBytes = Math.min(ROUTE_BATCH_AUTH_TOKEN_ESTIMATE_BYTES, Math.max(512, Math.floor(this.maxPayloadBytes / 128)));
|
|
287
291
|
const encodedBytes = (candidate) => {
|
|
288
292
|
const encoded = encode({
|
|
289
293
|
schema_version: TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION,
|
|
@@ -292,7 +296,10 @@ export class BeamTransferControl {
|
|
|
292
296
|
shard_id: 0,
|
|
293
297
|
message_type: messageType,
|
|
294
298
|
request_id: "00000000-0000-4000-8000-000000000000",
|
|
295
|
-
|
|
299
|
+
// The live JWT is larger than the compact placeholder once claims and
|
|
300
|
+
// signatures are encoded. Reserve enough space for token and envelope
|
|
301
|
+
// growth so a batch accepted by the estimator stays below the guard.
|
|
302
|
+
auth_token: "x".repeat(authTokenEstimateBytes),
|
|
296
303
|
occurred_at: new Date().toISOString(),
|
|
297
304
|
producer: "sdk",
|
|
298
305
|
payload: { ...basePayload, route_batch: compactSignedRoutes(candidate) }
|
|
@@ -307,7 +314,7 @@ export class BeamTransferControl {
|
|
|
307
314
|
let accepted = 0;
|
|
308
315
|
while (low <= high) {
|
|
309
316
|
const count = Math.floor((low + high) / 2);
|
|
310
|
-
if (encodedBytes(routes.slice(offset, offset + count)) <=
|
|
317
|
+
if (encodedBytes(routes.slice(offset, offset + count)) <= targetPayloadBytes) {
|
|
311
318
|
accepted = count;
|
|
312
319
|
low = count + 1;
|
|
313
320
|
}
|
|
@@ -316,7 +323,10 @@ export class BeamTransferControl {
|
|
|
316
323
|
}
|
|
317
324
|
if (accepted === 0) {
|
|
318
325
|
const bytes = encodedBytes(routes.slice(offset, offset + 1));
|
|
319
|
-
|
|
326
|
+
if (bytes > this.maxPayloadBytes) {
|
|
327
|
+
throw new Error(`single signed route is ${bytes} bytes, above maxPayloadBytes=${this.maxPayloadBytes}`);
|
|
328
|
+
}
|
|
329
|
+
accepted = 1;
|
|
320
330
|
}
|
|
321
331
|
chunks.push(routes.slice(offset, offset + accepted));
|
|
322
332
|
offset += accepted;
|