UNPKG

openai

Version:

The official TypeScript library for the OpenAI API

194 lines (170 loc) • 5.63 kB
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details. import { APIResource } from '../../../../core/resource'; import { APIPromise } from '../../../../core/api-promise'; import { PagePromise, TokenPage, type TokenPageParams } from '../../../../core/pagination'; import { buildHeaders } from '../../../../internal/headers'; import { RequestOptions } from '../../../../internal/request-options'; import { path } from '../../../../internal/utils/path'; import { prepareAgentFiles, uploadAgentFile, type PreparedAgentFiles, } from '../../../../lib/beta/agents/files'; import type { Uploadable } from '../../../../internal/uploads'; function resolveResourceRequestOptions( options: RequestOptions | undefined, buildOptions: (options: RequestOptions | undefined) => RequestOptions | Promise<RequestOptions>, ): Promise<RequestOptions> { return Promise.resolve(options).then(buildOptions); } export class Files extends APIResource { /** * Copies inline bytes or a Files API file into a connected execution environment, * replacing an existing regular file at the same path. Upload between turns and * wait for success before starting the next turn. See * [environment files](https://developers.openai.com/api/docs/guides/agents-api/environments/files). * * @example * ```ts * const environmentFile = * await client.beta.agents.environments.files.create( * 'environment_id', * { file_id: 'x', path: 'x', type: 'file_id' }, * ); * ``` */ create( environmentID: string, body: FileCreateParams, options?: RequestOptions, ): APIPromise<EnvironmentFile> { return this._client.post( path`/agents/environments/${environmentID}/files`, resolveResourceRequestOptions(options, (options) => ({ body, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]), __security: { bearerAuth: true }, })), ); } /** * Lists live files on a connected execution environment with optional directory * filtering and opaque cursor pagination. See * [environment files](https://developers.openai.com/api/docs/guides/agents-api/environments/files). * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const environmentFile of client.beta.agents.environments.files.list( * 'environment_id', * )) { * // ... * } * ``` */ list( environmentID: string, query: FileListParams | null | undefined = {}, options?: RequestOptions, ): PagePromise<EnvironmentFilesPage, EnvironmentFile> { return this._client.getAPIList( path`/agents/environments/${environmentID}/files`, TokenPage<EnvironmentFile>, resolveResourceRequestOptions(options, (options) => ({ query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]), __security: { bearerAuth: true }, })), ); } /** Beta: prepare initial hosted file references; uploaded Files API objects remain caller-owned. */ prepare(files: Record<string, Uploadable>, options?: RequestOptions): Promise<PreparedAgentFiles> { return prepareAgentFiles(this._client, files, options); } /** Beta: upload one local file and stage its reference in a live environment. */ upload(environmentID: string, params: { file: Uploadable; path: string }, options?: RequestOptions) { return uploadAgentFile(this._client, this, environmentID, params, options); } } export type EnvironmentFilesPage = TokenPage<EnvironmentFile>; /** * A live file in an execution environment. */ export interface EnvironmentFile { /** * The ID of the environment containing this file. */ environment_id: string; /** * The object type. Always `agent.environment.file`. */ object: 'agent.environment.file'; /** * The absolute file path inside the environment's workspace. */ path: string; /** * The file size in bytes. */ size_bytes: number; } export type FileCreateParams = | FileCreateParams.HostedEnvironmentFileParamFileID | FileCreateParams.HostedEnvironmentFileParamInline; export declare namespace FileCreateParams { export interface HostedEnvironmentFileParamFileID { /** * The ID of the uploaded file. */ file_id: string; /** * The absolute destination path inside `/workspace`. */ path: string; /** * The type of the object. Always `file_id`. */ type: 'file_id'; } export interface HostedEnvironmentFileParamInline { /** * The standard-base64-encoded file contents. */ data: string; /** * The absolute destination path inside `/workspace`. */ path: string; /** * The type of the object. Always `inline`. */ type: 'inline'; } } export interface FileListParams extends Omit<TokenPageParams, 'limit'> { /** * The maximum number of files to return, between 1 and 100. */ limit?: number | null; /** * Sort by case-sensitive path components. Defaults to descending. * * - `asc` - Returns resources in ascending order. * - `desc` - Returns resources in descending order. */ order?: 'asc' | 'desc'; /** * Restrict the listing to this absolute workspace directory. */ path?: string | null; } export declare namespace Files { export { type EnvironmentFile as EnvironmentFile, type EnvironmentFilesPage as EnvironmentFilesPage, type FileCreateParams as FileCreateParams, type FileListParams as FileListParams, }; }