import { APIResource } from "../../core/resource.js"; import { APIPromise } from "../../core/api-promise.js"; import { Stream } from "../../core/streaming.js"; import { type Uploadable } from "../../core/uploads.js"; import { RequestOptions } from "../../internal/request-options.js"; export declare class Files extends APIResource { /** * Upload multiple files independently as a batch. Files are uploaded and processed * concurrently — none of them wait on another file to finish first. Response is a * Server-Sent Events stream merging every file's progress in whatever order it * actually occurs (not necessarily file order). Each event carries two * percentages: file_percentage (0-100, this file's own progress, independent of * the others) and batch_percentage (cumulative, byte-weighted progress across the * WHOLE BATCH so far). A 'processing' event fires immediately when each file * starts (elapsed_seconds=0, both percentages simulated estimates since DocProc * exposes no real progress signal), further 'processing' heartbeats follow every * 10s while still in flight, then a 'file_completed'/'file_failed' event with * file_percentage=100 (exactly) and the real batch_percentage at that moment — * which can still be far below 100 if this was a small file finishing while a * larger one in the batch is still processing. A final 'done' event closes the * stream with the full per-file result summary. Also accepts an optional * 'model_name' form field (its parsed value below is unused; the actual value is * read from the raw form body to preserve the distinction between an omitted value * and an explicit empty string, see BatchFileUploadRequest.as_form). Tri-state: * omitted unions extensions across every model configured for the chatbot; a * non-empty value scopes to that one model; an explicit empty string means no * model is selected, so no model-based extensions apply. Applied identically to * every file in the batch. Also accepts an optional 'agent_id' form field. Uploads * destined for an agent -- either via Agent Mode on the chatbot or a non-empty * 'agent_id' -- skip file-type validation entirely (no extension whitelist, no * content-type check) for every file in the batch; size, empty-file, and * virus-scan checks still apply. A supplied 'agent_id' must belong to the chatbot, * otherwise the request is rejected with 400. An optional 'digital_employee_id' * form field gets the same treatment for uploads destined for a Digital Employee * (DocProc is skipped too); it must exist in the caller's organization (404 * otherwise), and is rejected with 422 when the feature is disabled or when * combined with 'agent_id'. The optional 'temporary_file_ids' form field is sent * as a repeated field (one part per entry, not a JSON-encoded array) and is * matched to 'files' by position: entry N is the temporary_file_id to give file N. * It is not a list of already-uploaded files, and it is meaningless without * 'files' (at least one file is required). Omit it, send fewer entries than files, * or leave an entry blank to have the backend generate the ID for those files. */ upload(params: FileUploadParams, options?: RequestOptions): APIPromise>; } /** * Schema of one `data:` line in the `POST /v2/files/upload` event stream, keyed by * `status`. * * Documentation only: the stream is produced by `FileUploadProgressEvent`, this * model only publishes its shape in the OpenAPI schema so SDKs can generate typed * events. */ export type FileUploadResponse = FileUploadResponse.BatchFileUploadProcessingEvent | FileUploadResponse.BatchFileUploadFileCompletedEvent | FileUploadResponse.BatchFileUploadFileFailedEvent | FileUploadResponse.BatchFileUploadDoneEvent | FileUploadResponse.BatchFileUploadErrorEvent; export declare namespace FileUploadResponse { /** * Emitted when a file starts, then as a heartbeat while it is still in flight. * * Attributes: status (Literal["processing"]): The event discriminator. * temporary_file_id (str): The file's temporary_file_id, known from the very first * event. elapsed_seconds (float): Seconds spent on this file so far (0 on the * starting event). */ interface BatchFileUploadProcessingEvent { /** * Cumulative, byte-weighted progress across the whole batch */ batch_percentage: number; /** * When the event was created (milliseconds since epoch) */ created_date: number; /** * Seconds spent on this file so far */ elapsed_seconds: number; /** * The zero-based index of the file within the batch */ file_index: number; /** * The name of the file this event is about */ file_name: string; /** * This file's own progress (0-100) */ file_percentage: number; status: 'processing'; /** * The file's temporary_file_id, known from the first event */ temporary_file_id: string; /** * The total number of files in the batch */ total_files: number; } /** * Emitted when a file was uploaded and processed successfully. * * Attributes: status (Literal["file_completed"]): The event discriminator. * temporary_file_id (str): The file's temporary_file_id. size (int): The size of * the file in bytes. expires_at (str): ISO 8601 timestamp when the file expires. * url (str | None): Presigned S3 URL, or None if it could not be generated. * object_storage_type (str | None): The object storage backend the file was stored * in. */ interface BatchFileUploadFileCompletedEvent { /** * Cumulative, byte-weighted progress across the whole batch */ batch_percentage: number; /** * When the event was created (milliseconds since epoch) */ created_date: number; /** * ISO 8601 timestamp when the file expires */ expires_at: string; /** * The zero-based index of the file within the batch */ file_index: number; /** * The name of the file this event is about */ file_name: string; /** * This file's own progress (0-100) */ file_percentage: number; /** * The size of the file in bytes */ size: number; status: 'file_completed'; /** * The file's temporary_file_id */ temporary_file_id: string; /** * The total number of files in the batch */ total_files: number; /** * The object storage backend */ object_storage_type?: string | null; /** * Presigned S3 URL to access the file */ url?: string | null; } /** * Emitted when a file failed. The other files in the batch are unaffected. * * Attributes: status (Literal["file_failed"]): The event discriminator. error * (str): Why the file failed. */ interface BatchFileUploadFileFailedEvent { /** * Cumulative, byte-weighted progress across the whole batch */ batch_percentage: number; /** * When the event was created (milliseconds since epoch) */ created_date: number; /** * Why the file failed */ error: string; /** * The zero-based index of the file within the batch */ file_index: number; /** * The name of the file this event is about */ file_name: string; /** * This file's own progress (0-100) */ file_percentage: number; status: 'file_failed'; /** * The total number of files in the batch */ total_files: number; } /** * Closes the stream with the per-file result summary. * * Attributes: status (Literal["done"]): The event discriminator. batch_percentage * (float): Always 100. total_files (int): The total number of files in the batch. * results (list[BatchFileUploadResultItem]): The outcome of every file, in request * order. created_date (int): When the event was created (milliseconds since * epoch). */ interface BatchFileUploadDoneEvent { /** * Always 100 */ batch_percentage: number; /** * When the event was created (milliseconds since epoch) */ created_date: number; /** * The outcome of every file, in request order */ results: Array; status: 'done'; /** * The total number of files in the batch */ total_files: number; } namespace BatchFileUploadDoneEvent { /** * Per-file outcome listed in the final `done` event of a batch upload. * * Attributes: filename (str): The original filename of the file. status (str): * "uploaded" on success, "failed" otherwise. temporary_file_id (str | None): * Backend-generated identifier. Only present when uploaded. size (int | None): The * size of the file in bytes. Only present when uploaded. expires_at (str | None): * ISO 8601 expiry timestamp. Only present when uploaded. url (str | None): * Presigned S3 URL, when it could be generated. Only present when uploaded. * object_storage_type (str | None): The object storage backend the file was stored * in. Only present when uploaded. error (str | None): Why the file failed. Only * present when failed. */ interface Result { /** * The original filename of the file */ filename: string; /** * 'uploaded' on success, 'failed' otherwise */ status: string; /** * Why the file failed, if it failed */ error?: string | null; /** * ISO 8601 timestamp when the file expires, if uploaded */ expires_at?: string | null; /** * The object storage backend, if uploaded */ object_storage_type?: string | null; /** * The size of the file in bytes, if uploaded */ size?: number | null; /** * Backend-generated identifier, if uploaded */ temporary_file_id?: string | null; /** * Presigned S3 URL to access the file, if uploaded */ url?: string | null; } } /** * Emitted, in place of `done`, when the stream itself broke unexpectedly. * * Attributes: status (Literal["error"]): The event discriminator. batch_percentage * (float): Progress at the time of the failure (0 when unknown). error (str): Why * the stream broke. created_date (int): When the event was created (milliseconds * since epoch). */ interface BatchFileUploadErrorEvent { /** * Progress at the time of the failure */ batch_percentage: number; /** * When the event was created (milliseconds since epoch) */ created_date: number; /** * Why the stream broke */ error: string; status: 'error'; } } export interface FileUploadParams { /** * Body param */ chatbot_id: string; /** * Body param */ files: Array; /** * Body param */ agent_id?: string | null; /** * Body param */ digital_employee_id?: string | null; /** * Body param */ model_name?: string | null; /** * Body param */ temporary_file_ids?: Array; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export declare namespace Files { export { type FileUploadResponse as FileUploadResponse, type FileUploadParams as FileUploadParams }; } //# sourceMappingURL=files.d.ts.map