import type { Scenario } from "../client.mjs"; import type { APIPromise } from "../core/api-promise.mjs"; import type { RequestOptions } from "../internal/request-options.mjs"; import { Uploads, type UploadCreateParams, type UploadCreateResponse, type UploadRetrieveParams, type UploadRetrieveResponse, type UploadTriggerActionParams, type UploadTriggerActionResponse } from "../resources/uploads.mjs"; import type { AssetRetrieveResponse } from "../resources/assets/assets.mjs"; import type { ModelRetrieveResponse } from "../resources/models/models.mjs"; import { type Scope } from "./scope.mjs"; type UploadKind = NonNullable; /** The resolved entity returned after a successful upload, narrowed by `kind`. */ export type UploadResult = K extends 'model' ? ModelRetrieveResponse : AssetRetrieveResponse; /** * Accepted upload inputs. * - `string` — a local file path, read from disk (Node only; throws in browsers). * - `Uint8Array` — raw bytes. `Buffer` is a `Uint8Array` and works too. * - `Blob` / `File` — browser-native, or Node ≥ 18 via `fs.openAsBlob()` / * constructors. */ export type UploadFileInput = string | Uint8Array | Blob; export interface UploadFileParams { /** * The file to upload. Accepts a local path (Node), a `Uint8Array` / `Buffer`, * or a `Blob` / `File`. */ file: UploadFileInput; /** Original filename (e.g. `"my-model.safetensors"`). */ fileName: string; /** MIME type (e.g. `"application/octet-stream"`, `"image/png"`). */ contentType: string; /** The kind of upload. Determines the returned entity type. */ kind: K; /** * Extra asset options. Ignored when `kind === 'model'` — models don't * produce an asset, so these options are not applicable server-side. */ assetOptions?: UploadCreateParams['assetOptions']; /** * Maximum number of parts uploaded to S3 in parallel. * @default 4 */ partConcurrency?: number; /** * Polling interval for the final "upload imported" check, in ms. * @default 2000 */ pollIntervalMs?: number; /** * Maximum time to wait for the upload to reach a terminal state, in ms. * Throws if exceeded. * @default 300000 */ pollTimeoutMs?: number; } export interface UploadWaitOptions { /** Polling interval in milliseconds. Default: 2000 */ intervalMs?: number; /** Maximum wait time in milliseconds. Default: 300000 */ timeoutMs?: number; /** * Override the project scope used for the polling requests. Defaults to * the scope captured on the upload (per-call override on the originating * call, else the client's default project). */ projectId?: string; } /** Upload methods added on top of the original upload fields. */ export declare class UploadMethods { /** @internal */ readonly _client: Scenario; /** @internal scope captured from the originating call — replayed on every `.wait()` poll. */ readonly _scope?: Scope; /** * Poll until the upload has been processed into an entity (asset or model), * or reaches a terminal state (`imported`, `complete`, `failed`). Resolves * with the latest upload data so you can read `entityId`, `status`, or * `errorMessage` without a follow-up retrieve. * * @example * ```ts * const res = await client.uploads.retrieve(uploadId); * const done = await res.upload.wait(); * if (done.status === 'failed') throw new Error(done.errorMessage); * console.log(done.entityId); * ``` */ wait(this: Upload, options?: UploadWaitOptions): Promise; /** @internal Create an Upload from raw upload data, optionally remembering the originating scope. */ static from(client: Scenario, data: UploadRetrieveResponse['upload'], scope?: Scope): Upload; } /** An upload with all original fields plus `.wait()`. */ export type Upload = UploadRetrieveResponse.Upload & UploadMethods; export declare const Upload: typeof UploadMethods; /** * @internal Helper type: adds `.wait()` to the `upload` field of a response. * Uses intersection so the original response type is preserved — a `WithUpload` is still assignable to `T`. */ export type WithUpload = T & { upload: UploadMethods; }; /** * @internal Wrap `_thenUnwrap` to replace `response.upload` with an enhanced Upload. * Captures the effective scope (per-call override or client default) so * `.wait()` can replay it on every poll — keeping follow-up calls in sync * with the project the upload was originally created in. */ export declare function enhanceUpload(client: Scenario, promise: APIPromise, options?: RequestOptions): APIPromise>; /** * Enhanced Uploads resource. * All original methods (`create`, `retrieve`, `triggerAction`) are inherited, * with each response's `upload` field enriched with a `.wait()` helper. * Adds `uploadFile()` — a one-call wrapper around the 4-step upload flow: * init → PUT parts to S3 → trigger complete → poll until imported. */ export declare class EnhancedUploads extends Uploads { create(body: UploadCreateParams, options?: RequestOptions): APIPromise>; retrieve(uploadID: string, query?: UploadRetrieveParams | null | undefined, options?: RequestOptions): APIPromise>; triggerAction(uploadID: string, body: UploadTriggerActionParams, options?: RequestOptions): APIPromise>; /** * Upload a file end-to-end. Computes an optimal part size (within AWS's * 5 MiB / 5 GiB / 10,000-part bounds), uploads all parts in parallel, * triggers completion, polls until the server has validated and imported * the file, and returns the resolved entity. * * The returned type narrows on `kind`: `'model'` returns a Model, * everything else returns an Asset. * * @example * ```ts * // From a file path (Node) * const { asset } = await client.uploads.uploadFile({ * file: './photo.jpg', * fileName: 'photo.jpg', * contentType: 'image/jpeg', * kind: 'image', * }); * console.log(asset.id, asset.url); * * // Or from bytes / Blob — anything you already have in memory * await client.uploads.uploadFile({ * file: new Blob([pngBytes], { type: 'image/png' }), * fileName: 'generated.png', * contentType: 'image/png', * kind: 'image', * }); * ``` */ uploadFile(params: UploadFileParams, options?: RequestOptions): Promise>; } export {}; //# sourceMappingURL=upload.d.mts.map