diff --git a/packages/hub/src/lib/commit.ts b/packages/hub/src/lib/commit.ts index e36be4965c..f07689c19e 100644 --- a/packages/hub/src/lib/commit.ts +++ b/packages/hub/src/lib/commit.ts @@ -120,8 +120,13 @@ export type CommitParams = { */ fetch?: typeof fetch; abortSignal?: AbortSignal; - // Credentials are optional due to custom fetch functions or cookie auth + /** + * @default true + * + * Use xet protocol: https://huggingface.co/blog/xet-on-the-hub to upload, rather than a basic S3 PUT + */ useXet?: boolean; + // Credentials are optional due to custom fetch functions or cookie auth } & Partial; export interface CommitOutput { @@ -165,24 +170,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator(); @@ -206,10 +194,6 @@ export async function* commitIter(params: CommitParams): AsyncGenerator { - if (operation.operation === "edit" && !useXet) { - throw new Error("Edit operation is not supported when Xet is disabled"); - } - if (operation.operation === "edit") { // Convert EditFile operation to a file operation with SplicedBlob const splicedBlob = SplicedBlob.create( @@ -325,7 +309,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator [shas[i], op])); + if (useXet && json.transfer !== "xet") { + useXet = false; + } + if (useXet) { // First get all the files that are already uploaded out of the way for (const obj of json.objects) { @@ -396,6 +384,7 @@ export async function* commitIter(params: CommitParams): AsyncGenerator; /** * Optional object describing the server ref that the objects belong to. Note: Added in v2.4. * @@ -29,7 +29,7 @@ export interface ApiLfsBatchResponse { objects: ApiLfsResponseObject[]; } -export type ApiLfsResponseTransfer = "basic" | "multipart"; +export type ApiLfsResponseTransfer = "basic" | "multipart" | "xet"; export interface ApiLfsCompleteMultipartRequest { oid: string;