/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { SDKCore } from "../core.js"; import { encodeSimple } from "../lib/encodings.js"; import { matchStatusCode } from "../lib/http.js"; import * as M from "../lib/matchers.js"; import { compactMap } from "../lib/primitives.js"; import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import * as errors from "../models/errors/index.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKError } from "../models/errors/sdkerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import * as operations from "../models/operations/index.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; export enum ContentAcceptEnum { applicationJson = "application/json", textCsv = "text/csv", textPlain = "text/plain", applicationJavascript = "application/javascript", applicationJsonl = "application/jsonl", applicationMsword = "application/msword", applicationPdf = "application/pdf", applicationRtf = "application/rtf", applicationVndMsExcel = "application/vnd.ms-excel", applicationVndMsPowerpoint = "application/vnd.ms-powerpoint", applicationVndOpenxmlformatsOfficedocumentPresentationmlPresentation = "application/vnd.openxmlformats-officedocument.presentationml.presentation", applicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", applicationVndOpenxmlformatsOfficedocumentWordprocessingmlDocument = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", applicationXNdjson = "application/x-ndjson", applicationXml = "application/xml", imageGif = "image/gif", imageJpeg = "image/jpeg", imageJpg = "image/jpg", imagePng = "image/png", imageSvgPlusXml = "image/svg+xml", imageTiff = "image/tiff", imageWebp = "image/webp", textCss = "text/css", textHtml = "text/html", textJavascript = "text/javascript", textMarkdown = "text/markdown", textXPython = "text/x-python", textXml = "text/xml", } /** * Retrieve file content * * @remarks * Returns the raw binary contents of the specified file with appropriate Content-Type header. */ export function llmFilesContent( client: SDKCore, request: operations.GetFileContentRequest, options?: RequestOptions & { acceptHeaderOverride?: ContentAcceptEnum }, ): APIPromise< Result< operations.GetFileContentResponse, | errors.GetFileContentResponseBody | errors.GetFileContentLlmFilesResponseBody | errors.GetFileContentLlmFilesResponseResponseBody | errors.GetFileContentLlmFilesResponse500ResponseBody | SDKError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: SDKCore, request: operations.GetFileContentRequest, options?: RequestOptions & { acceptHeaderOverride?: ContentAcceptEnum }, ): Promise< [ Result< operations.GetFileContentResponse, | errors.GetFileContentResponseBody | errors.GetFileContentLlmFilesResponseBody | errors.GetFileContentLlmFilesResponseResponseBody | errors.GetFileContentLlmFilesResponse500ResponseBody | SDKError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => operations.GetFileContentRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = null; const pathParams = { file_id: encodeSimple("file_id", payload.file_id, { explode: false, charEncoding: "percent", }), }; const path = pathToFunc("/api/v1/llm/files/{file_id}/content")(pathParams); const headers = new Headers(compactMap({ Accept: options?.acceptHeaderOverride || "application/json;q=1, text/csv;q=0.96, text/plain;q=0.93, application/javascript;q=0.89, application/jsonl;q=0.86, application/msword;q=0.82, application/pdf;q=0.79, application/rtf;q=0.75, application/vnd.ms-excel;q=0.71, application/vnd.ms-powerpoint;q=0.68, application/vnd.openxmlformats-officedocument.presentationml.presentation;q=0.64, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;q=0.61, application/vnd.openxmlformats-officedocument.wordprocessingml.document;q=0.57, application/x-ndjson;q=0.54, application/xml;q=0.50, image/gif;q=0.46, image/jpeg;q=0.43, image/jpg;q=0.39, image/png;q=0.36, image/svg+xml;q=0.32, image/tiff;q=0.29, image/webp;q=0.25, text/css;q=0.21, text/html;q=0.18, text/javascript;q=0.14, text/markdown;q=0.11, text/x-python;q=0.07, text/xml;q=0", "X-On-Behalf-Of": encodeSimple( "X-On-Behalf-Of", payload["X-On-Behalf-Of"], { explode: false, charEncoding: "none" }, ), })); const secConfig = await extractSecurity(client._options.bearerAuth); const securityInput = secConfig == null ? {} : { bearerAuth: secConfig }; const requestSecurity = resolveGlobalSecurity(securityInput); const context = { options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "getFileContent", oAuth2Scopes: null, resolvedSecurity: requestSecurity, securitySource: client._options.bearerAuth, retryConfig: options?.retries || client._options.retryConfig || { strategy: "backoff", backoff: { initialInterval: 500, maxInterval: 5000, exponent: 1.5, maxElapsedTime: 15000, }, retryConnectionErrors: true, } || { strategy: "none" }, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; const requestRes = client._createRequest(context, { security: requestSecurity, method: "GET", baseURL: options?.serverURL, path: path, headers: headers, body: body, userAgent: client._options.userAgent, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return [requestRes, { status: "invalid" }]; } const req = requestRes.value; const doResult = await client._do(req, { context, isErrorStatusCode: (statusCode: number) => matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]), retryConfig: context.retryConfig, retryCodes: context.retryCodes, }); if (!doResult.ok) { return [doResult, { status: "request-error", request: req }]; } const response = doResult.value; const responseFields = { HttpMeta: { Response: response, Request: req }, }; const [result] = await M.match< operations.GetFileContentResponse, | errors.GetFileContentResponseBody | errors.GetFileContentLlmFilesResponseBody | errors.GetFileContentLlmFilesResponseResponseBody | errors.GetFileContentLlmFilesResponse500ResponseBody | SDKError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/plain", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/csv", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/html", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/css", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/javascript", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/markdown", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/xml", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "text/x-python", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/json", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/x-ndjson", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/jsonl", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/xml", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/javascript", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/pdf", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/png", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/jpeg", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/jpg", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/gif", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/webp", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/tiff", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/msword", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/vnd.ms-excel", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/vnd.ms-powerpoint", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/vnd.openxmlformats-officedocument.presentationml.presentation", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "application/rtf", }), M.stream(200, operations.GetFileContentResponse$inboundSchema, { ctype: "image/svg+xml", }), M.jsonErr(400, errors.GetFileContentResponseBody$inboundSchema), M.jsonErr(401, errors.GetFileContentLlmFilesResponseBody$inboundSchema), M.jsonErr( 404, errors.GetFileContentLlmFilesResponseResponseBody$inboundSchema, ), M.jsonErr( 500, errors.GetFileContentLlmFilesResponse500ResponseBody$inboundSchema, ), M.fail("4XX"), M.fail("5XX"), )(response, req, { extraFields: responseFields }); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } return [result, { status: "complete", request: req, response }]; }