@beam-network/sdk 0.8.0 → 0.9.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 CHANGED
@@ -169,7 +169,9 @@ Constraints, all of them the Hub's rather than Beam's — see
169
169
  Hub file, set `allow_source_rehash: true` to let the SDK read the source once to
170
170
  compute it.
171
171
  - **One source per Hugging Face destination**, because the Hub dictates the part
172
- size and a plan carries a single chunk size.
172
+ size and a plan carries a single chunk size. The SDK sends that part size to
173
+ Beam as `provider_part_size`; Beam chooses the chunk size of every other
174
+ transfer.
173
175
  - If you do not call `waitForTransfer`, call `finalizeHuggingFaceUploads(transferId)`
174
176
  yourself once the transfer completes — without it the parts are uploaded but no
175
177
  commit is made and the file does not appear in the repo.
package/dist/client.d.ts CHANGED
@@ -60,7 +60,6 @@ type TransferPrepareInput = {
60
60
  signedUrlFlow?: SignedUrlFlow;
61
61
  idempotencyKey?: string;
62
62
  routeGenerationId?: string;
63
- chunkSize?: number;
64
63
  };
65
64
  export declare class BeamClient {
66
65
  readonly apiKey: string;
@@ -126,7 +125,6 @@ export declare class BeamClient {
126
125
  name?: string;
127
126
  urlsExpiresAt?: string;
128
127
  signedUrlFlow?: SignedUrlFlow;
129
- chunkSize?: number;
130
128
  }): Promise<TransferPlanResponse>;
131
129
  /**
132
130
  * Prepares a transfer from already-signed HTTP sources and destinations (`transfer.prepare`).
@@ -168,7 +166,8 @@ export declare class BeamClient {
168
166
  * Negotiate every Hugging Face destination before the plan exists.
169
167
  *
170
168
  * The Hub will not issue upload URLs without the object's sha256, and it chooses the part
171
- * size itself, so this runs first and the plan is then requested at the Hub's chunk size.
169
+ * size itself, so this runs first and the prepare request then carries the Hub's part size
170
+ * as `provider_part_size`.
172
171
  */
173
172
  private planHuggingFaceUploads;
174
173
  /** Fail before any byte moves if BeamCore did not adopt the Hub's part layout. */
package/dist/client.js CHANGED
@@ -157,7 +157,6 @@ export class BeamClient {
157
157
  sources: input.sources,
158
158
  destinations: input.destinations,
159
159
  total_size: input.totalSize,
160
- chunk_size: input.chunkSize,
161
160
  name: input.name,
162
161
  merkle_root: input.merkleRoot,
163
162
  chunk_hashes: input.chunkHashes,
@@ -244,7 +243,6 @@ export class BeamClient {
244
243
  sources: input.sources,
245
244
  destinations: input.destinations,
246
245
  name: input.name,
247
- chunk_size: input.chunkSize,
248
246
  urls_expires_at: input.urlsExpiresAt,
249
247
  signed_url_flow: input.signedUrlFlow ?? "signed_url"
250
248
  }));
@@ -263,10 +261,10 @@ export class BeamClient {
263
261
  prepareTransfer(input) {
264
262
  return this.prepareTransferWithRequestKey(input);
265
263
  }
266
- async prepareTransferWithRequestKey(input, requestKey) {
264
+ async prepareTransferWithRequestKey(input, options = {}) {
267
265
  const transferId = input.transferId ?? await transferIdForIdempotencyKey(input.idempotencyKey);
268
266
  validateId(transferId, "transferId");
269
- const prepareIdempotencyKey = requestKey ?? `transfer:${transferId}:prepare`;
267
+ const prepareIdempotencyKey = options.requestKey ?? `transfer:${transferId}:prepare`;
270
268
  const routeGenerationId = input.routeGenerationId ?? await routeGenerationIdForPrepareIdempotencyKey(prepareIdempotencyKey);
271
269
  const result = await this.control.request("transfer.prepare", compact({
272
270
  transfer_id: transferId,
@@ -274,7 +272,7 @@ export class BeamClient {
274
272
  sources: input.sources,
275
273
  destinations: input.destinations,
276
274
  name: input.name,
277
- chunk_size: input.chunkSize,
275
+ provider_part_size: options.providerPartSize,
278
276
  urls_expires_at: input.urlsExpiresAt,
279
277
  signed_url_flow: input.signedUrlFlow ?? "signed_url"
280
278
  }), {
@@ -411,13 +409,13 @@ export class BeamClient {
411
409
  sources: preparedSources,
412
410
  destinations: preparedDestinations,
413
411
  name: input.name,
414
- chunkSize: huggingFace.chunkSize ?? input.chunkSize,
415
412
  signedUrlFlow: requestedSignedUrlFlow,
416
413
  ...(resume ? { transferId: resume.transferId } : { idempotencyKey: input.idempotencyKey, routeGenerationId: input.routeGenerationId })
417
414
  };
418
- const prepared = resume
419
- ? await this.prepareTransferWithRequestKey(prepareInput, `transfer:${resume.transferId}:prepare:resume:${randomUuid()}`)
420
- : await this.prepareTransfer(prepareInput);
415
+ const prepared = await this.prepareTransferWithRequestKey(prepareInput, {
416
+ requestKey: resume ? `transfer:${resume.transferId}:prepare:resume:${randomUuid()}` : undefined,
417
+ providerPartSize: huggingFace.providerPartSize
418
+ });
421
419
  if (resume && prepared.transfer_id !== resume.transferId)
422
420
  throw new Error("resumed provider transfer id mismatch");
423
421
  input.signal?.throwIfAborted();
@@ -704,7 +702,8 @@ export class BeamClient {
704
702
  * Negotiate every Hugging Face destination before the plan exists.
705
703
  *
706
704
  * The Hub will not issue upload URLs without the object's sha256, and it chooses the part
707
- * size itself, so this runs first and the plan is then requested at the Hub's chunk size.
705
+ * size itself, so this runs first and the prepare request then carries the Hub's part size
706
+ * as `provider_part_size`.
708
707
  */
709
708
  async planHuggingFaceUploads(input) {
710
709
  const targets = input.destinations
@@ -723,7 +722,7 @@ export class BeamClient {
723
722
  ? typeof preparedSource.metadata?.sha256 === "string" ? preparedSource.metadata.sha256 : undefined
724
723
  : undefined;
725
724
  const states = [];
726
- let chunkSize;
725
+ let providerPartSize;
727
726
  for (const { destination, index } of targets) {
728
727
  const preparedDestination = input.preparedDestinations[index];
729
728
  if ((destination.repo_type ?? "model") === "bucket") {
@@ -761,11 +760,11 @@ export class BeamClient {
761
760
  size: preparedSource.size
762
761
  });
763
762
  if (plan.upload?.chunkSize !== undefined) {
764
- if (chunkSize !== undefined && chunkSize !== plan.upload.chunkSize) {
765
- throw new Error(`huggingface destinations disagree on part size (${chunkSize} vs ${plan.upload.chunkSize}); `
763
+ if (providerPartSize !== undefined && providerPartSize !== plan.upload.chunkSize) {
764
+ throw new Error(`huggingface destinations disagree on part size (${providerPartSize} vs ${plan.upload.chunkSize}); `
766
765
  + "the plan carries a single chunk size");
767
766
  }
768
- chunkSize = plan.upload.chunkSize;
767
+ providerPartSize = plan.upload.chunkSize;
769
768
  }
770
769
  states.push({
771
770
  destination: config,
@@ -786,7 +785,7 @@ export class BeamClient {
786
785
  }).then((hashed) => hashed.partEtags)
787
786
  });
788
787
  }
789
- return { states, chunkSize };
788
+ return { states, providerPartSize };
790
789
  }
791
790
  /** Fail before any byte moves if BeamCore did not adopt the Hub's part layout. */
792
791
  assertHuggingFacePlan(prepared, states) {
package/dist/models.d.ts CHANGED
@@ -84,7 +84,6 @@ export interface TransferCreateRequest {
84
84
  sources: SourceConfig[];
85
85
  destinations: DestConfig[];
86
86
  total_size: number;
87
- chunk_size?: number;
88
87
  name?: string;
89
88
  merkle_root?: string;
90
89
  chunk_hashes?: string[];
@@ -96,7 +95,6 @@ export interface RawTransferCreateInput {
96
95
  sources: SourceConfig[];
97
96
  destinations: DestConfig[];
98
97
  totalSize: number;
99
- chunkSize?: number;
100
98
  name?: string;
101
99
  merkleRoot?: string;
102
100
  chunkHashes?: string[];
@@ -443,8 +441,6 @@ export interface ProviderTransferCreateInput {
443
441
  idempotencyKey?: string;
444
442
  /** Internal recovery generation; callers normally omit this. */
445
443
  routeGenerationId?: string;
446
- /** Requested plan chunk size. BeamCore may raise it; the response carries the effective value. */
447
- chunkSize?: number;
448
444
  }
449
445
  export interface ProviderMultipartGroupIdentity {
450
446
  transferId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beam-network/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "TypeScript SDK for BEAM transfer creation and management.",
5
5
  "type": "module",
6
6
  "license": "MIT",