// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; import * as FilesAPI from '../../files'; import * as SavedItemsAPI from '../saved-items'; import * as ShareAPI from './share'; import { LibraryShareResponse, Share, ShareCreateParams, ShareDeleteAllParams } from './share'; import { APIPromise } from '../../../core/api-promise'; import { type Uploadable } from '../../../core/uploads'; import { buildHeaders } from '../../../internal/headers'; import { RequestOptions } from '../../../internal/request-options'; import { multipartFormRequestOptions } from '../../../internal/uploads'; import { path } from '../../../internal/utils/path'; export class Files extends APIResource { share: ShareAPI.Share = new ShareAPI.Share(this._client); /** * Upload a file into the caller's Library for reuse across conversations. The file * is stored only; it is not processed or indexed for knowledge-base search. The * extension, size and per-user file count are checked against * `GET /library/config`, and the file is virus-scanned. Requires X-Tenant-ID * header. */ create(params: FileCreateParams, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post( '/library/files', multipartFormRequestOptions( { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }, this._client, ), ); } /** * Get a Library file the caller owns or that was shared with them, with a * presigned URL valid for 1 hour to preview or download it. Requires X-Tenant-ID * header. */ retrieve( fileID: string, params: FileRetrieveParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.get(path`/library/files/${fileID}`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * List one section of the caller's Library, newest first: `uploaded` (files the * caller uploaded), `saved` (items the caller saved from a conversation, with * where each came from) or `shared` (files other members shared with the caller's * Teams or Organization). Requires X-Tenant-ID header. */ list( params: FileListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...query } = params ?? {}; return this._client.get('/library/files', { query, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Delete a file the caller owns. Recipients lose access immediately; conversations * where the file was already attached keep their own copy. Requires X-Tenant-ID * header. */ delete( fileID: string, params: FileDeleteParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.delete(path`/library/files/${fileID}`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Turn a Library file the caller owns, or that was shared with them, into a * temporary chat upload, exactly as `POST /files/upload` would. Send the returned * `temporary_file_id` in `/message`. The attachment is a copy: revoking or * deleting the Library file later does not affect conversations that already used * it. The chatbot's own rules apply, as in `/files/upload`: its supported file * types (unless `agent_id`, a Digital Employee or Agent Mode applies), its maximum * file size and DocProc. Invalid `chatbot_id`, `model_name`, `agent_id` or * `digital_employee_id` values are rejected as `/files/upload` rejects them. * Requires X-Tenant-ID header. */ attach( fileID: string, params: FileAttachParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post(path`/library/files/${fileID}/attach`, { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * Sensitivity level assigned to a knowledge base and the documents it holds. */ export type InformationClassification = 'confidential' | 'restricted' | 'internal' | 'partner' | 'public'; /** * Coarse file category backing the Library's File / Image / Table filter chips. */ export type LibraryFileCategory = 'file' | 'image' | 'table'; /** * A Library file as listed to the caller. */ export interface LibraryFileItem { /** * Library file ID. */ id: string; /** * Detected MIME type. */ content_type: string; /** * Lowercase file extension with a leading dot, e.g. `.pdf`. */ extension: string; /** * Category backing the File/Image/Table filter. */ file_category: LibraryFileCategory; /** * Original file name. */ filename: string; /** * Whether the caller owns the file (and may share, revoke, or delete it). */ is_owner: boolean; /** * The file owner. */ owner: LibraryOwner; /** * File size in bytes. */ size: number; /** * How the file entered the Library. */ source_type: LibraryFileSourceType; /** * When the file was added to the Library. */ created_at?: string | null; /** * Sensitivity level assigned to a knowledge base and the documents it holds. */ information_classification?: InformationClassification | null; /** * Teams and/or the Organization the file is currently shared with. */ shared_with?: Array; /** * Where a saved item came from. Only the owner of the saved item sees it. */ source?: LibrarySavedSource | null; } /** * How a file entered the Library: uploaded directly, or saved from a conversation. */ export type LibraryFileSourceType = 'uploaded' | 'saved'; /** * The user who owns a Library file. */ export interface LibraryOwner { /** * Owner user ID. */ id: string; /** * Owner display name, or username when no display name is set. */ name?: string | null; } /** * Where a saved item came from. Only the owner of the saved item sees it. */ export interface LibrarySavedSource { /** * False once the conversation was deleted, so `View in Conversation` should be * disabled. */ available: boolean; /** * The conversation the item was saved from. */ conversation_id: string; /** * `attachment`, `image` or `table`. */ kind: SavedItemsAPI.LibrarySavedItemKind; /** * The conversation title. Null once the conversation is no longer available. */ conversation_title?: string | null; /** * The message the item was saved from, if any. */ message_id?: string | null; } /** * A Team or the whole Organization a Library file is shared with. */ export interface LibraryShareTarget { /** * `team` or `organization` (everyone in the Organization). */ type: ShareTargetType; /** * Team ID, or the Organization ID for `organization`. Null for `organization` only * if the Organization could not be resolved. */ id?: string | null; /** * Team name, or the Organization name for `organization`. Null if the name could * not be resolved. */ name?: string | null; } /** * Who a Library file can be shared with. Sharing never crosses the owner's * Organization. */ export type ShareTargetType = 'team' | 'organization'; /** * A Library file with a short-lived URL to preview or download it. */ export interface FileRetrieveResponse { /** * Library file ID. */ id: string; /** * Detected MIME type. */ content_type: string; /** * Lowercase file extension with a leading dot, e.g. `.pdf`. */ extension: string; /** * Category backing the File/Image/Table filter. */ file_category: LibraryFileCategory; /** * Original file name. */ filename: string; /** * Whether the caller owns the file (and may share, revoke, or delete it). */ is_owner: boolean; /** * The file owner. */ owner: LibraryOwner; /** * File size in bytes. */ size: number; /** * How the file entered the Library. */ source_type: LibraryFileSourceType; /** * Presigned URL to preview or download the file. Valid for 1 hour. */ url: string; /** * When the file was added to the Library. */ created_at?: string | null; /** * Sensitivity level assigned to a knowledge base and the documents it holds. */ information_classification?: InformationClassification | null; /** * Teams and/or the Organization the file is currently shared with. */ shared_with?: Array; /** * Where a saved item came from. Only the owner of the saved item sees it. */ source?: LibrarySavedSource | null; } /** * One page of Library files. */ export interface FileListResponse { /** * 1-based page number. */ page: number; /** * Page size. */ size: number; /** * Total number of files matching the filters. */ total: number; /** * Files on this page, newest first. */ items?: Array; } /** * Result of deleting a Library file. */ export interface FileDeleteResponse { /** * The deleted Library file ID. */ id: string; /** * Always true on success. */ deleted?: boolean; } export interface FileCreateParams { /** * Body param: The file to add to the Library. */ file: Uploadable; /** * 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 interface FileRetrieveParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export interface FileListParams { /** * Query param: Filter by file category. */ category?: LibraryFileCategory | null; /** * Query param: 1-based page number. */ page?: number; /** * Query param: Case-insensitive filename search. */ q?: string | null; /** * Query param: Library section to list. */ section?: 'uploaded' | 'shared' | 'saved'; /** * Query param: Page size. */ size?: number; /** * 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 interface FileDeleteParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export interface FileAttachParams { /** * Body param: The chatbot the message will be sent to. */ chatbot_id: string; /** * Body param: Agent the message goes to. Skips the extension check and DocProc. */ agent_id?: string | null; /** * Body param: Digital Employee the message goes to. Same rules as `/files/upload`. */ digital_employee_id?: string | null; /** * Body param: Same rule as `/files/upload`: omitted means the chatbot's first * model, an empty string means no model-based extensions apply, any other value * scopes to that model. */ model_name?: string | null; /** * 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; } Files.Share = Share; export declare namespace Files { export { type InformationClassification as InformationClassification, type LibraryFileCategory as LibraryFileCategory, type LibraryFileItem as LibraryFileItem, type LibraryFileSourceType as LibraryFileSourceType, type LibraryOwner as LibraryOwner, type LibrarySavedSource as LibrarySavedSource, type LibraryShareTarget as LibraryShareTarget, type ShareTargetType as ShareTargetType, type FileRetrieveResponse as FileRetrieveResponse, type FileListResponse as FileListResponse, type FileDeleteResponse as FileDeleteResponse, type FileCreateParams as FileCreateParams, type FileRetrieveParams as FileRetrieveParams, type FileListParams as FileListParams, type FileDeleteParams as FileDeleteParams, type FileAttachParams as FileAttachParams, }; export { Share as Share, type LibraryShareResponse as LibraryShareResponse, type ShareCreateParams as ShareCreateParams, type ShareDeleteAllParams as ShareDeleteAllParams, }; }