diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index f60c4ef3..c9a425e1 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: f42cb8e6-e2ce-4565-b975-5a9f38b94d5a management: - docChecksum: 07648fa4a81409d493b04f9a0210053a + docChecksum: e1ddcc2cf71c4056b8ea02935f420820 docVersion: 1.0.48 - speakeasyVersion: 1.398.0 - generationVersion: 2.415.8 - releaseVersion: 0.17.0 - configChecksum: 2c276110c3d851f4c60673861a0ec379 + speakeasyVersion: 1.401.2 + generationVersion: 2.421.3 + releaseVersion: 0.17.1 + configChecksum: 1055fe9a71bdb4cdbbe397b0bc8f8d65 repoURL: https://github.com/Unstructured-IO/unstructured-js-client.git repoSubDirectory: . installationURL: https://github.com/Unstructured-IO/unstructured-js-client @@ -15,7 +15,7 @@ features: typescript: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.11 - core: 3.17.3 + core: 3.17.6 defaultEnabledRetries: 0.1.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.1.1 @@ -109,6 +109,6 @@ examples: "200": application/json: [{"type": "Title", "element_id": "6aa0ff22f91bbe7e26e8e25ca8052acd", "text": "LayoutParser: A Unified Toolkit for Deep Learning Based Document Image Analysis", "metadata": {"languages": ["eng"], "page_number": 1, "filename": "layout-parser-paper.pdf", "filetype": "application/pdf"}}] "422": - application/json: {"detail": ""} + application/json: {"detail": []} 5XX: application/json: {"detail": "An error occurred"} diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 0ba2d74b..5d381a9a 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,9 +1,9 @@ -speakeasyVersion: 1.398.0 +speakeasyVersion: 1.401.2 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:c94b4493c1e49e6f6a922e16c6ba45f067f862adb66542e7bd3355b195a3477e - sourceBlobDigest: sha256:108f49adb0607b20fc4d54949d36599c08c87c2d19e0a40e4bd5a2b91d9ac3e3 + sourceRevisionDigest: sha256:a1cab617ff2e6f54400d7a1558b3a9dd86ec53c7db8e716cef2f90926c74798e + sourceBlobDigest: sha256:6b8cb9c93f74eb8c94e57469c73722791d51e77052bd0c4cf168aee14cd05ff3 tags: - latest - main @@ -11,8 +11,8 @@ targets: unstructed-typescript: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:c94b4493c1e49e6f6a922e16c6ba45f067f862adb66542e7bd3355b195a3477e - sourceBlobDigest: sha256:108f49adb0607b20fc4d54949d36599c08c87c2d19e0a40e4bd5a2b91d9ac3e3 + sourceRevisionDigest: sha256:a1cab617ff2e6f54400d7a1558b3a9dd86ec53c7db8e716cef2f90926c74798e + sourceBlobDigest: sha256:6b8cb9c93f74eb8c94e57469c73722791d51e77052bd0c4cf168aee14cd05ff3 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/RELEASES.md b/RELEASES.md index 3f873089..53d6623e 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -454,4 +454,14 @@ Based on: ### Generated - [typescript v0.17.0] . ### Releases -- [NPM v0.17.0] https://www.npmjs.com/package/unstructured-client/v/0.17.0 - . \ No newline at end of file +- [NPM v0.17.0] https://www.npmjs.com/package/unstructured-client/v/0.17.0 - . + +## 2024-09-23 00:27:28 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.401.2 (2.421.3) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v0.17.1] . +### Releases +- [NPM v0.17.1] https://www.npmjs.com/package/unstructured-client/v/0.17.1 - . \ No newline at end of file diff --git a/codeSamples.yaml b/codeSamples.yaml index 2dda4a4d..573d1060 100644 --- a/codeSamples.yaml +++ b/codeSamples.yaml @@ -5,7 +5,7 @@ info: actions: - target: $["paths"]["/general/v0/general"]["post"] update: - x-codeSamples: - - lang: typescript - label: partition - source: "import { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport { ChunkingStrategy, Strategy } from \"unstructured-client/sdk/models/shared\";\n\nconst unstructuredClient = new UnstructuredClient();\n\nasync function run() {\n const result = await unstructuredClient.general.partition({\n partitionParameters: {\n files: await openAsBlob(\"example.file\"),\n strategy: Strategy.Auto,\n chunkingStrategy: ChunkingStrategy.Basic,\n splitPdfPageRange: [\n 1,\n 10,\n ],\n },\n });\n \n // Handle the result\n console.log(result)\n}\n\nrun();" + "x-codeSamples": + - "lang": "typescript" + "label": "partition" + "source": "import { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport { ChunkingStrategy, Strategy } from \"unstructured-client/sdk/models/shared\";\n\nconst unstructuredClient = new UnstructuredClient();\n\nasync function run() {\n const result = await unstructuredClient.general.partition({\n partitionParameters: {\n files: await openAsBlob(\"example.file\"),\n strategy: Strategy.Auto,\n chunkingStrategy: ChunkingStrategy.Basic,\n splitPdfPageRange: [\n 1,\n 10,\n ],\n },\n });\n \n // Handle the result\n console.log(result)\n}\n\nrun();" diff --git a/docs/sdk/models/shared/chunkingstrategy.md b/docs/sdk/models/shared/chunkingstrategy.md index fa7a1f41..82ebe5ca 100644 --- a/docs/sdk/models/shared/chunkingstrategy.md +++ b/docs/sdk/models/shared/chunkingstrategy.md @@ -5,7 +5,7 @@ ```typescript import { ChunkingStrategy } from "unstructured-client/sdk/models/shared"; -let value: ChunkingStrategy = ChunkingStrategy.Basic; +let value: ChunkingStrategy = ChunkingStrategy.ByTitle; ``` ## Values diff --git a/docs/sdk/models/shared/loc.md b/docs/sdk/models/shared/loc.md index 1005af3a..b37ac78a 100644 --- a/docs/sdk/models/shared/loc.md +++ b/docs/sdk/models/shared/loc.md @@ -5,7 +5,7 @@ ```typescript import { Loc } from "unstructured-client/sdk/models/shared"; -let value: Loc = 844266; +let value: Loc = 544883; ``` ## Supported Types diff --git a/docs/sdk/models/shared/outputformat.md b/docs/sdk/models/shared/outputformat.md index bc156a08..1b80f898 100644 --- a/docs/sdk/models/shared/outputformat.md +++ b/docs/sdk/models/shared/outputformat.md @@ -7,7 +7,7 @@ The format of the response. Supported formats are application/json and text/csv. ```typescript import { OutputFormat } from "unstructured-client/sdk/models/shared"; -let value: OutputFormat = OutputFormat.ApplicationJson; +let value: OutputFormat = OutputFormat.TextCsv; ``` ## Values diff --git a/docs/sdk/models/shared/strategy.md b/docs/sdk/models/shared/strategy.md index 7209428b..43b1ff6e 100644 --- a/docs/sdk/models/shared/strategy.md +++ b/docs/sdk/models/shared/strategy.md @@ -7,7 +7,7 @@ The strategy to use for partitioning PDF/image. Options are fast, hi_res, auto. ```typescript import { Strategy } from "unstructured-client/sdk/models/shared"; -let value: Strategy = Strategy.HiRes; +let value: Strategy = Strategy.Auto; ``` ## Values diff --git a/docs/sdk/models/shared/validationerror.md b/docs/sdk/models/shared/validationerror.md index 6ffc44e3..5eb730db 100644 --- a/docs/sdk/models/shared/validationerror.md +++ b/docs/sdk/models/shared/validationerror.md @@ -7,7 +7,7 @@ import { ValidationError } from "unstructured-client/sdk/models/shared"; let value: ValidationError = { loc: [ - 857946, + "", ], msg: "", type: "", diff --git a/gen.yaml b/gen.yaml index 2e759500..9451ea0a 100644 --- a/gen.yaml +++ b/gen.yaml @@ -10,7 +10,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false typescript: - version: 0.17.0 + version: 0.17.1 additionalDependencies: dependencies: async: ^3.2.5 diff --git a/jsr.json b/jsr.json index ffd2cd3b..289c2058 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "unstructured-client", - "version": "0.17.0", + "version": "0.17.1", "exports": { ".": "./src/index.ts", "./sdk/models/errors": "./src/sdk/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index c1529040..d4703b0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "unstructured-client", - "version": "0.17.0", + "version": "0.17.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "unstructured-client", - "version": "0.17.0", + "version": "0.17.1", "dependencies": { "async": "^3.2.5", "pdf-lib": "^1.17.1" diff --git a/package.json b/package.json index 512c1666..b42baf53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unstructured-client", - "version": "0.17.0", + "version": "0.17.1", "author": "Unstructured", "main": "./index.js", "sideEffects": false, diff --git a/src/funcs/generalPartition.ts b/src/funcs/generalPartition.ts index 9e28e474..cb7f4ab6 100644 --- a/src/funcs/generalPartition.ts +++ b/src/funcs/generalPartition.ts @@ -3,10 +3,10 @@ */ import { UnstructuredClientCore } from "../core.js"; -import { encodeSimple as encodeSimple$ } from "../lib/encodings.js"; +import { encodeSimple } from "../lib/encodings.js"; import { readableStreamToArrayBuffer } from "../lib/files.js"; -import * as m$ from "../lib/matchers.js"; -import * as schemas$ from "../lib/schemas.js"; +import * as M from "../lib/matchers.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"; @@ -32,7 +32,7 @@ import { isReadableStream } from "../sdk/types/streams.js"; * Description */ export async function generalPartition( - client$: UnstructuredClientCore, + client: UnstructuredClientCore, request: operations.PartitionRequest, options?: RequestOptions, ): Promise< @@ -49,241 +49,239 @@ export async function generalPartition( | ConnectionError > > { - const input$ = request; + const input = request; - const parsed$ = schemas$.safeParse( - input$, - (value$) => operations.PartitionRequest$outboundSchema.parse(value$), + const parsed = safeParse( + input, + (value) => operations.PartitionRequest$outboundSchema.parse(value), "Input validation failed", ); - if (!parsed$.ok) { - return parsed$; + if (!parsed.ok) { + return parsed; } - const payload$ = parsed$.value; - const body$ = new FormData(); + const payload = parsed.value; + const body = new FormData(); - if (isBlobLike(payload$.partition_parameters.files)) { - body$.append("files", payload$.partition_parameters.files); - } else if (isReadableStream(payload$.partition_parameters.files.content)) { + if (isBlobLike(payload.partition_parameters.files)) { + body.append("files", payload.partition_parameters.files); + } else if (isReadableStream(payload.partition_parameters.files.content)) { const buffer = await readableStreamToArrayBuffer( - payload$.partition_parameters.files.content, + payload.partition_parameters.files.content, ); const blob = new Blob([buffer], { type: "application/octet-stream" }); - body$.append("files", blob); + body.append("files", blob); } else { - body$.append( + body.append( "files", - new Blob([payload$.partition_parameters.files.content], { + new Blob([payload.partition_parameters.files.content], { type: "application/octet-stream", }), - payload$.partition_parameters.files.fileName, + payload.partition_parameters.files.fileName, ); } - if (payload$.partition_parameters.chunking_strategy !== undefined) { - body$.append( + if (payload.partition_parameters.chunking_strategy !== undefined) { + body.append( "chunking_strategy", - String(payload$.partition_parameters.chunking_strategy), + String(payload.partition_parameters.chunking_strategy), ); } - if (payload$.partition_parameters.combine_under_n_chars !== undefined) { - body$.append( + if (payload.partition_parameters.combine_under_n_chars !== undefined) { + body.append( "combine_under_n_chars", - String(payload$.partition_parameters.combine_under_n_chars), + String(payload.partition_parameters.combine_under_n_chars), ); } - if (payload$.partition_parameters.content_type !== undefined) { - body$.append( + if (payload.partition_parameters.content_type !== undefined) { + body.append( "content_type", - String(payload$.partition_parameters.content_type), + String(payload.partition_parameters.content_type), ); } - if (payload$.partition_parameters.coordinates !== undefined) { - body$.append( + if (payload.partition_parameters.coordinates !== undefined) { + body.append( "coordinates", - String(payload$.partition_parameters.coordinates), + String(payload.partition_parameters.coordinates), ); } - if (payload$.partition_parameters.encoding !== undefined) { - body$.append("encoding", String(payload$.partition_parameters.encoding)); + if (payload.partition_parameters.encoding !== undefined) { + body.append("encoding", String(payload.partition_parameters.encoding)); } - if (payload$.partition_parameters.extract_image_block_types !== undefined) { - body$.append( + if (payload.partition_parameters.extract_image_block_types !== undefined) { + body.append( "extract_image_block_types", - String(payload$.partition_parameters.extract_image_block_types), + String(payload.partition_parameters.extract_image_block_types), ); } - if ( - payload$.partition_parameters.gz_uncompressed_content_type !== undefined - ) { - body$.append( + if (payload.partition_parameters.gz_uncompressed_content_type !== undefined) { + body.append( "gz_uncompressed_content_type", - String(payload$.partition_parameters.gz_uncompressed_content_type), + String(payload.partition_parameters.gz_uncompressed_content_type), ); } - if (payload$.partition_parameters.hi_res_model_name !== undefined) { - body$.append( + if (payload.partition_parameters.hi_res_model_name !== undefined) { + body.append( "hi_res_model_name", - String(payload$.partition_parameters.hi_res_model_name), + String(payload.partition_parameters.hi_res_model_name), ); } - if (payload$.partition_parameters.include_orig_elements !== undefined) { - body$.append( + if (payload.partition_parameters.include_orig_elements !== undefined) { + body.append( "include_orig_elements", - String(payload$.partition_parameters.include_orig_elements), + String(payload.partition_parameters.include_orig_elements), ); } - if (payload$.partition_parameters.include_page_breaks !== undefined) { - body$.append( + if (payload.partition_parameters.include_page_breaks !== undefined) { + body.append( "include_page_breaks", - String(payload$.partition_parameters.include_page_breaks), + String(payload.partition_parameters.include_page_breaks), ); } - if (payload$.partition_parameters.include_slide_notes !== undefined) { - body$.append( + if (payload.partition_parameters.include_slide_notes !== undefined) { + body.append( "include_slide_notes", - String(payload$.partition_parameters.include_slide_notes), + String(payload.partition_parameters.include_slide_notes), ); } - if (payload$.partition_parameters.languages !== undefined) { - body$.append("languages", String(payload$.partition_parameters.languages)); + if (payload.partition_parameters.languages !== undefined) { + body.append("languages", String(payload.partition_parameters.languages)); } - if (payload$.partition_parameters.max_characters !== undefined) { - body$.append( + if (payload.partition_parameters.max_characters !== undefined) { + body.append( "max_characters", - String(payload$.partition_parameters.max_characters), + String(payload.partition_parameters.max_characters), ); } - if (payload$.partition_parameters.multipage_sections !== undefined) { - body$.append( + if (payload.partition_parameters.multipage_sections !== undefined) { + body.append( "multipage_sections", - String(payload$.partition_parameters.multipage_sections), + String(payload.partition_parameters.multipage_sections), ); } - if (payload$.partition_parameters.new_after_n_chars !== undefined) { - body$.append( + if (payload.partition_parameters.new_after_n_chars !== undefined) { + body.append( "new_after_n_chars", - String(payload$.partition_parameters.new_after_n_chars), + String(payload.partition_parameters.new_after_n_chars), ); } - if (payload$.partition_parameters.ocr_languages !== undefined) { - body$.append( + if (payload.partition_parameters.ocr_languages !== undefined) { + body.append( "ocr_languages", - String(payload$.partition_parameters.ocr_languages), + String(payload.partition_parameters.ocr_languages), ); } - if (payload$.partition_parameters.output_format !== undefined) { - body$.append("output_format", payload$.partition_parameters.output_format); + if (payload.partition_parameters.output_format !== undefined) { + body.append("output_format", payload.partition_parameters.output_format); } - if (payload$.partition_parameters.overlap !== undefined) { - body$.append("overlap", String(payload$.partition_parameters.overlap)); + if (payload.partition_parameters.overlap !== undefined) { + body.append("overlap", String(payload.partition_parameters.overlap)); } - if (payload$.partition_parameters.overlap_all !== undefined) { - body$.append( + if (payload.partition_parameters.overlap_all !== undefined) { + body.append( "overlap_all", - String(payload$.partition_parameters.overlap_all), + String(payload.partition_parameters.overlap_all), ); } - if (payload$.partition_parameters.pdf_infer_table_structure !== undefined) { - body$.append( + if (payload.partition_parameters.pdf_infer_table_structure !== undefined) { + body.append( "pdf_infer_table_structure", - String(payload$.partition_parameters.pdf_infer_table_structure), + String(payload.partition_parameters.pdf_infer_table_structure), ); } - if (payload$.partition_parameters.similarity_threshold !== undefined) { - body$.append( + if (payload.partition_parameters.similarity_threshold !== undefined) { + body.append( "similarity_threshold", - String(payload$.partition_parameters.similarity_threshold), + String(payload.partition_parameters.similarity_threshold), ); } - if (payload$.partition_parameters.skip_infer_table_types !== undefined) { - body$.append( + if (payload.partition_parameters.skip_infer_table_types !== undefined) { + body.append( "skip_infer_table_types", - String(payload$.partition_parameters.skip_infer_table_types), + String(payload.partition_parameters.skip_infer_table_types), ); } - if (payload$.partition_parameters.split_pdf_allow_failed !== undefined) { - body$.append( + if (payload.partition_parameters.split_pdf_allow_failed !== undefined) { + body.append( "split_pdf_allow_failed", - String(payload$.partition_parameters.split_pdf_allow_failed), + String(payload.partition_parameters.split_pdf_allow_failed), ); } - if (payload$.partition_parameters.split_pdf_concurrency_level !== undefined) { - body$.append( + if (payload.partition_parameters.split_pdf_concurrency_level !== undefined) { + body.append( "split_pdf_concurrency_level", - String(payload$.partition_parameters.split_pdf_concurrency_level), + String(payload.partition_parameters.split_pdf_concurrency_level), ); } - if (payload$.partition_parameters.split_pdf_page !== undefined) { - body$.append( + if (payload.partition_parameters.split_pdf_page !== undefined) { + body.append( "split_pdf_page", - String(payload$.partition_parameters.split_pdf_page), + String(payload.partition_parameters.split_pdf_page), ); } - if (payload$.partition_parameters.split_pdf_page_range !== undefined) { - body$.append( + if (payload.partition_parameters.split_pdf_page_range !== undefined) { + body.append( "split_pdf_page_range", - String(payload$.partition_parameters.split_pdf_page_range), + String(payload.partition_parameters.split_pdf_page_range), ); } - if (payload$.partition_parameters.starting_page_number !== undefined) { - body$.append( + if (payload.partition_parameters.starting_page_number !== undefined) { + body.append( "starting_page_number", - String(payload$.partition_parameters.starting_page_number), + String(payload.partition_parameters.starting_page_number), ); } - if (payload$.partition_parameters.strategy !== undefined) { - body$.append("strategy", payload$.partition_parameters.strategy); + if (payload.partition_parameters.strategy !== undefined) { + body.append("strategy", payload.partition_parameters.strategy); } - if (payload$.partition_parameters.unique_element_ids !== undefined) { - body$.append( + if (payload.partition_parameters.unique_element_ids !== undefined) { + body.append( "unique_element_ids", - String(payload$.partition_parameters.unique_element_ids), + String(payload.partition_parameters.unique_element_ids), ); } - if (payload$.partition_parameters.xml_keep_tags !== undefined) { - body$.append( + if (payload.partition_parameters.xml_keep_tags !== undefined) { + body.append( "xml_keep_tags", - String(payload$.partition_parameters.xml_keep_tags), + String(payload.partition_parameters.xml_keep_tags), ); } - const path$ = pathToFunc("/general/v0/general")(); + const path = pathToFunc("/general/v0/general")(); - const headers$ = new Headers({ + const headers = new Headers({ Accept: "application/json", - "unstructured-api-key": encodeSimple$( + "unstructured-api-key": encodeSimple( "unstructured-api-key", - payload$["unstructured-api-key"], + payload["unstructured-api-key"], { explode: false, charEncoding: "none" }, ), }); - const security$ = await extractSecurity(client$.options$.security); + const securityInput = await extractSecurity(client._options.security); const context = { operationID: "partition", oAuth2Scopes: [], - securitySource: client$.options$.security, + securitySource: client._options.security, }; - const securitySettings$ = resolveGlobalSecurity(security$); + const requestSecurity = resolveGlobalSecurity(securityInput); - const requestRes = client$.createRequest$(context, { - security: securitySettings$, + const requestRes = client._createRequest(context, { + security: requestSecurity, method: "POST", - path: path$, - headers: headers$, - body: body$, - timeoutMs: options?.timeoutMs || client$.options$.timeoutMs || -1, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return requestRes; } - const request$ = requestRes.value; + const req = requestRes.value; - const doResult = await client$.do$(request$, { + const doResult = await client._do(req, { context, errorCodes: ["422", "4XX", "5XX"], retryConfig: options?.retries - || client$.options$.retryConfig + || client._options.retryConfig || { strategy: "backoff", backoff: { @@ -301,7 +299,7 @@ export async function generalPartition( } const response = doResult.value; - const responseFields$ = { + const responseFields = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, @@ -309,7 +307,7 @@ export async function generalPartition( Headers: {}, }; - const [result$] = await m$.match< + const [result] = await M.match< operations.PartitionResponse, | errors.HTTPValidationError | errors.ServerError @@ -321,16 +319,16 @@ export async function generalPartition( | RequestTimeoutError | ConnectionError >( - m$.json(200, operations.PartitionResponse$inboundSchema, { + M.json(200, operations.PartitionResponse$inboundSchema, { key: "Elements", }), - m$.jsonErr(422, errors.HTTPValidationError$inboundSchema), - m$.fail("4XX"), - m$.jsonErr("5XX", errors.ServerError$inboundSchema), - )(response, { extraFields: responseFields$ }); - if (!result$.ok) { - return result$; + M.jsonErr(422, errors.HTTPValidationError$inboundSchema), + M.fail("4XX"), + M.jsonErr("5XX", errors.ServerError$inboundSchema), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; } - return result$; + return result; } diff --git a/src/lib/config.ts b/src/lib/config.ts index 0f7cc619..a3b2f494 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -69,8 +69,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "1.0.48", - sdkVersion: "0.17.0", - genVersion: "2.415.8", + sdkVersion: "0.17.1", + genVersion: "2.421.3", userAgent: - "speakeasy-sdk/typescript 0.17.0 2.415.8 1.0.48 unstructured-client", + "speakeasy-sdk/typescript 0.17.1 2.421.3 1.0.48 unstructured-client", } as const; diff --git a/src/lib/sdks.ts b/src/lib/sdks.ts index dc42cb99..bfbe7a5b 100644 --- a/src/lib/sdks.ts +++ b/src/lib/sdks.ts @@ -71,11 +71,11 @@ const isBrowserLike = webWorkerLike || (typeof window === "object" && typeof window.document !== "undefined"); export class ClientSDK { - private readonly httpClient: HTTPClient; - protected readonly baseURL: URL | null; - protected readonly hooks$: SDKHooks; - protected readonly logger?: Logger | undefined; - public readonly options$: SDKOptions & { hooks?: SDKHooks }; + readonly #httpClient: HTTPClient; + readonly #hooks: SDKHooks; + readonly #logger?: Logger | undefined; + protected readonly _baseURL: URL | null; + public readonly _options: SDKOptions & { hooks?: SDKHooks }; constructor(options: SDKOptions = {}) { const opt = options as unknown; @@ -85,33 +85,33 @@ export class ClientSDK { && "hooks" in opt && opt.hooks instanceof SDKHooks ) { - this.hooks$ = opt.hooks; + this.#hooks = opt.hooks; } else { - this.hooks$ = new SDKHooks(); + this.#hooks = new SDKHooks(); } - this.options$ = { ...options, hooks: this.hooks$ }; + this._options = { ...options, hooks: this.#hooks }; const url = serverURLFromOptions(options); if (url) { url.pathname = url.pathname.replace(/\/+$/, "") + "/"; } - const { baseURL, client } = this.hooks$.sdkInit({ + const { baseURL, client } = this.#hooks.sdkInit({ baseURL: url, client: options.httpClient || new HTTPClient(), }); - this.baseURL = baseURL; - this.httpClient = client; - this.logger = options.debugLogger; + this._baseURL = baseURL; + this.#httpClient = client; + this.#logger = options.debugLogger; } - public createRequest$( + public _createRequest( context: HookContext, conf: RequestConfig, options?: RequestOptions, ): Result { const { method, path, query, headers: opHeaders, security } = conf; - const base = conf.baseURL ?? this.baseURL; + const base = conf.baseURL ?? this._baseURL; if (!base) { return ERR(new InvalidRequestError("No base URL provided for operation")); } @@ -195,7 +195,7 @@ export class ClientSDK { let input; try { - input = this.hooks$.beforeCreateRequest(context, { + input = this.#hooks.beforeCreateRequest(context, { url: reqURL, options: { ...fetchOptions, @@ -215,7 +215,7 @@ export class ClientSDK { return OK(new Request(input.url, input.options)); } - public async do$( + public async _do( request: Request, options: { context: HookContext; @@ -238,25 +238,25 @@ export class ClientSDK { return retry( async () => { - const req = await this.hooks$.beforeRequest(context, request.clone()); - await logRequest(this.logger, req).catch((e) => - this.logger?.log("Failed to log request:", e) + const req = await this.#hooks.beforeRequest(context, request.clone()); + await logRequest(this.#logger, req).catch((e) => + this.#logger?.log("Failed to log request:", e) ); - let response = await this.httpClient.request(req); + let response = await this.#httpClient.request(req); if (matchStatusCode(response, errorCodes)) { - const result = await this.hooks$.afterError(context, response, null); + const result = await this.#hooks.afterError(context, response, null); if (result.error) { throw result.error; } response = result.response || response; } else { - response = await this.hooks$.afterSuccess(context, response); + response = await this.#hooks.afterSuccess(context, response); } - await logResponse(this.logger, response, req) - .catch(e => this.logger?.log("Failed to log response:", e)); + await logResponse(this.#logger, response, req) + .catch(e => this.#logger?.log("Failed to log response:", e)); return response; }, diff --git a/src/sdk/models/shared/partitionparameters.ts b/src/sdk/models/shared/partitionparameters.ts index abb74b54..2163d780 100644 --- a/src/sdk/models/shared/partitionparameters.ts +++ b/src/sdk/models/shared/partitionparameters.ts @@ -2,30 +2,34 @@ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ +import * as z from "zod"; import { remap as remap$ } from "../../../lib/primitives.js"; import { blobLikeSchema } from "../../types/blobs.js"; -import { catchUnrecognizedEnum, OpenEnum, Unrecognized } from "../../types/enums.js"; -import * as z from "zod"; +import { + catchUnrecognizedEnum, + OpenEnum, + Unrecognized, +} from "../../types/enums.js"; export enum ChunkingStrategy { - Basic = "basic", - ByPage = "by_page", - BySimilarity = "by_similarity", - ByTitle = "by_title", + Basic = "basic", + ByPage = "by_page", + BySimilarity = "by_similarity", + ByTitle = "by_title", } export type ChunkingStrategyOpen = OpenEnum; export type Files = { - content: ReadableStream | Blob | ArrayBuffer | Buffer; - fileName: string; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; + fileName: string; }; /** * The format of the response. Supported formats are application/json and text/csv. Default: application/json. */ export enum OutputFormat { - ApplicationJson = "application/json", - TextCsv = "text/csv", + ApplicationJson = "application/json", + TextCsv = "text/csv", } /** * The format of the response. Supported formats are application/json and text/csv. Default: application/json. @@ -36,10 +40,10 @@ export type OutputFormatOpen = OpenEnum; * The strategy to use for partitioning PDF/image. Options are fast, hi_res, auto. Default: hi_res */ export enum Strategy { - Fast = "fast", - HiRes = "hi_res", - Auto = "auto", - OcrOnly = "ocr_only", + Fast = "fast", + HiRes = "hi_res", + Auto = "auto", + OcrOnly = "ocr_only", } /** * The strategy to use for partitioning PDF/image. Options are fast, hi_res, auto. Default: hi_res @@ -47,183 +51,195 @@ export enum Strategy { export type StrategyOpen = OpenEnum; export type PartitionParameters = { - /** - * The file to extract - */ - files: Files | Blob; - /** - * Use one of the supported strategies to chunk the returned elements after partitioning. When 'chunking_strategy' is not specified, no chunking is performed and any other chunking parameters provided are ignored. Supported strategies: 'basic', 'by_page', 'by_similarity', or 'by_title' - */ - chunkingStrategy?: ChunkingStrategyOpen | null | undefined; - /** - * If chunking strategy is set, combine elements until a section reaches a length of n chars. Default: 500 - */ - combineUnderNChars?: number | null | undefined; - /** - * A hint about the content type to use (such as text/markdown), when there are problems processing a specific file. This value is a MIME type in the format type/subtype. - */ - contentType?: string | null | undefined; - /** - * If `True`, return coordinates for each element extracted via OCR. Default: `False` - */ - coordinates?: boolean | undefined; - /** - * The encoding method used to decode the text input. Default: utf-8 - */ - encoding?: string | null | undefined; - /** - * The types of elements to extract, for use in extracting image blocks as base64 encoded data stored in metadata fields. - */ - extractImageBlockTypes?: Array | undefined; - /** - * If file is gzipped, use this content type after unzipping. - */ - gzUncompressedContentType?: string | null | undefined; - /** - * The name of the inference model used when strategy is hi_res - */ - hiResModelName?: string | null | undefined; - /** - * When a chunking strategy is specified, each returned chunk will include the elements consolidated to form that chunk as `.metadata.orig_elements`. Default: true. - */ - includeOrigElements?: boolean | null | undefined; - /** - * If true, the output will include page breaks if the filetype supports it. Default: false - */ - includePageBreaks?: boolean | undefined; - /** - * When `True`, slide notes from .ppt and .pptx files will be included in the response. Default: `True` - */ - includeSlideNotes?: boolean | undefined; - /** - * The languages present in the document, for use in partitioning and/or OCR. See the Tesseract documentation for a full list of languages. - */ - languages?: Array | undefined; - /** - * If chunking strategy is set, cut off new sections after reaching a length of n chars (hard max). Default: 500 - */ - maxCharacters?: number | null | undefined; - /** - * If chunking strategy is set, determines if sections can span multiple sections. Default: true - */ - multipageSections?: boolean | undefined; - /** - * If chunking strategy is set, cut off new sections after reaching a length of n chars (soft max). Default: 1500 - */ - newAfterNChars?: number | null | undefined; - /** - * Deprecated! The languages present in the document, for use in partitioning and/or OCR - */ - ocrLanguages?: Array | undefined; - /** - * The format of the response. Supported formats are application/json and text/csv. Default: application/json. - */ - outputFormat?: OutputFormatOpen | undefined; - /** - * Specifies the length of a string ('tail') to be drawn from each chunk and prefixed to the next chunk as a context-preserving mechanism. By default, this only applies to split-chunks where an oversized element is divided into multiple chunks by text-splitting. Default: 0 - */ - overlap?: number | undefined; - /** - * When `True`, apply overlap between 'normal' chunks formed from whole elements and not subject to text-splitting. Use this with caution as it entails a certain level of 'pollution' of otherwise clean semantic chunk boundaries. Default: False - */ - overlapAll?: boolean | undefined; - /** - * Deprecated! Use skip_infer_table_types to opt out of table extraction for any file type. If False and strategy=hi_res, no Table Elements will be extracted from pdf files regardless of skip_infer_table_types contents. - */ - pdfInferTableStructure?: boolean | undefined; - /** - * A value between 0.0 and 1.0 describing the minimum similarity two elements must have to be included in the same chunk. Note that similar elements may be separated to meet chunk-size criteria; this value can only guarantees that two elements with similarity below the threshold will appear in separate chunks. - */ - similarityThreshold?: number | null | undefined; - /** - * The document types that you want to skip table extraction with. Default: [] - */ - skipInferTableTypes?: Array | undefined; - /** - * When `split_pdf_page` is set to `True`, this parameter defines the behavior when some of the parallel requests fail. By default `split_pdf_allow_failed` is set to `False` and any failed request send to the API will make the whole process break and raise an Exception. If `split_pdf_allow_failed` is set to `True`, the errors encountered while sending parallel requests will not break the processing - the resuling list of Elements will miss the data from errored pages. - */ - splitPdfAllowFailed?: boolean | undefined; - /** - * Number of maximum concurrent requests made when splitting PDF. Ignored on backend. - */ - splitPdfConcurrencyLevel?: number | undefined; - /** - * Should the pdf file be split at client. Ignored on backend. - */ - splitPdfPage?: boolean | undefined; - /** - * When `split_pdf_page is set to `True`, this parameter selects a subset of the pdf to send to the API. The parameter is a list of 2 integers within the range [1, length_of_pdf]. An Error is thrown if the given range is invalid. Ignored on backend. - */ - splitPdfPageRange?: Array | undefined; - /** - * When PDF is split into pages before sending it into the API, providing this information will allow the page number to be assigned correctly. Introduced in 1.0.27. - */ - startingPageNumber?: number | null | undefined; - /** - * The strategy to use for partitioning PDF/image. Options are fast, hi_res, auto. Default: hi_res - */ - strategy?: StrategyOpen | undefined; - /** - * When `True`, assign UUIDs to element IDs, which guarantees their uniqueness (useful when using them as primary keys in database). Otherwise a SHA-256 of element text is used. Default: `False` - */ - uniqueElementIds?: boolean | undefined; - /** - * If `True`, will retain the XML tags in the output. Otherwise it will simply extract the text from within the tags. Only applies to XML documents. - */ - xmlKeepTags?: boolean | undefined; + /** + * The file to extract + */ + files: Files | Blob; + /** + * Use one of the supported strategies to chunk the returned elements after partitioning. When 'chunking_strategy' is not specified, no chunking is performed and any other chunking parameters provided are ignored. Supported strategies: 'basic', 'by_page', 'by_similarity', or 'by_title' + */ + chunkingStrategy?: ChunkingStrategyOpen | null | undefined; + /** + * If chunking strategy is set, combine elements until a section reaches a length of n chars. Default: 500 + */ + combineUnderNChars?: number | null | undefined; + /** + * A hint about the content type to use (such as text/markdown), when there are problems processing a specific file. This value is a MIME type in the format type/subtype. + */ + contentType?: string | null | undefined; + /** + * If `True`, return coordinates for each element extracted via OCR. Default: `False` + */ + coordinates?: boolean | undefined; + /** + * The encoding method used to decode the text input. Default: utf-8 + */ + encoding?: string | null | undefined; + /** + * The types of elements to extract, for use in extracting image blocks as base64 encoded data stored in metadata fields. + */ + extractImageBlockTypes?: Array | undefined; + /** + * If file is gzipped, use this content type after unzipping. + */ + gzUncompressedContentType?: string | null | undefined; + /** + * The name of the inference model used when strategy is hi_res + */ + hiResModelName?: string | null | undefined; + /** + * When a chunking strategy is specified, each returned chunk will include the elements consolidated to form that chunk as `.metadata.orig_elements`. Default: true. + */ + includeOrigElements?: boolean | null | undefined; + /** + * If true, the output will include page breaks if the filetype supports it. Default: false + */ + includePageBreaks?: boolean | undefined; + /** + * When `True`, slide notes from .ppt and .pptx files will be included in the response. Default: `True` + */ + includeSlideNotes?: boolean | undefined; + /** + * The languages present in the document, for use in partitioning and/or OCR. See the Tesseract documentation for a full list of languages. + */ + languages?: Array | undefined; + /** + * If chunking strategy is set, cut off new sections after reaching a length of n chars (hard max). Default: 500 + */ + maxCharacters?: number | null | undefined; + /** + * If chunking strategy is set, determines if sections can span multiple sections. Default: true + */ + multipageSections?: boolean | undefined; + /** + * If chunking strategy is set, cut off new sections after reaching a length of n chars (soft max). Default: 1500 + */ + newAfterNChars?: number | null | undefined; + /** + * Deprecated! The languages present in the document, for use in partitioning and/or OCR + */ + ocrLanguages?: Array | undefined; + /** + * The format of the response. Supported formats are application/json and text/csv. Default: application/json. + */ + outputFormat?: OutputFormatOpen | undefined; + /** + * Specifies the length of a string ('tail') to be drawn from each chunk and prefixed to the next chunk as a context-preserving mechanism. By default, this only applies to split-chunks where an oversized element is divided into multiple chunks by text-splitting. Default: 0 + */ + overlap?: number | undefined; + /** + * When `True`, apply overlap between 'normal' chunks formed from whole elements and not subject to text-splitting. Use this with caution as it entails a certain level of 'pollution' of otherwise clean semantic chunk boundaries. Default: False + */ + overlapAll?: boolean | undefined; + /** + * Deprecated! Use skip_infer_table_types to opt out of table extraction for any file type. If False and strategy=hi_res, no Table Elements will be extracted from pdf files regardless of skip_infer_table_types contents. + */ + pdfInferTableStructure?: boolean | undefined; + /** + * A value between 0.0 and 1.0 describing the minimum similarity two elements must have to be included in the same chunk. Note that similar elements may be separated to meet chunk-size criteria; this value can only guarantees that two elements with similarity below the threshold will appear in separate chunks. + */ + similarityThreshold?: number | null | undefined; + /** + * The document types that you want to skip table extraction with. Default: [] + */ + skipInferTableTypes?: Array | undefined; + /** + * When `split_pdf_page` is set to `True`, this parameter defines the behavior when some of the parallel requests fail. By default `split_pdf_allow_failed` is set to `False` and any failed request send to the API will make the whole process break and raise an Exception. If `split_pdf_allow_failed` is set to `True`, the errors encountered while sending parallel requests will not break the processing - the resuling list of Elements will miss the data from errored pages. + */ + splitPdfAllowFailed?: boolean | undefined; + /** + * Number of maximum concurrent requests made when splitting PDF. Ignored on backend. + */ + splitPdfConcurrencyLevel?: number | undefined; + /** + * Should the pdf file be split at client. Ignored on backend. + */ + splitPdfPage?: boolean | undefined; + /** + * When `split_pdf_page is set to `True`, this parameter selects a subset of the pdf to send to the API. The parameter is a list of 2 integers within the range [1, length_of_pdf]. An Error is thrown if the given range is invalid. Ignored on backend. + */ + splitPdfPageRange?: Array | undefined; + /** + * When PDF is split into pages before sending it into the API, providing this information will allow the page number to be assigned correctly. Introduced in 1.0.27. + */ + startingPageNumber?: number | null | undefined; + /** + * The strategy to use for partitioning PDF/image. Options are fast, hi_res, auto. Default: hi_res + */ + strategy?: StrategyOpen | undefined; + /** + * When `True`, assign UUIDs to element IDs, which guarantees their uniqueness (useful when using them as primary keys in database). Otherwise a SHA-256 of element text is used. Default: `False` + */ + uniqueElementIds?: boolean | undefined; + /** + * If `True`, will retain the XML tags in the output. Otherwise it will simply extract the text from within the tags. Only applies to XML documents. + */ + xmlKeepTags?: boolean | undefined; }; /** @internal */ export const ChunkingStrategy$inboundSchema: z.ZodType< - ChunkingStrategyOpen, - z.ZodTypeDef, - unknown -> = z.union([z.nativeEnum(ChunkingStrategy), z.string().transform(catchUnrecognizedEnum)]); + ChunkingStrategyOpen, + z.ZodTypeDef, + unknown +> = z + .union([ + z.nativeEnum(ChunkingStrategy), + z.string().transform(catchUnrecognizedEnum), + ]); /** @internal */ export const ChunkingStrategy$outboundSchema: z.ZodType< - ChunkingStrategyOpen, - z.ZodTypeDef, - ChunkingStrategyOpen -> = z.union([z.nativeEnum(ChunkingStrategy), z.string().and(z.custom>())]); + ChunkingStrategyOpen, + z.ZodTypeDef, + ChunkingStrategyOpen +> = z.union([ + z.nativeEnum(ChunkingStrategy), + z.string().and(z.custom>()), +]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ChunkingStrategy$ { - /** @deprecated use `ChunkingStrategy$inboundSchema` instead. */ - export const inboundSchema = ChunkingStrategy$inboundSchema; - /** @deprecated use `ChunkingStrategy$outboundSchema` instead. */ - export const outboundSchema = ChunkingStrategy$outboundSchema; + /** @deprecated use `ChunkingStrategy$inboundSchema` instead. */ + export const inboundSchema = ChunkingStrategy$inboundSchema; + /** @deprecated use `ChunkingStrategy$outboundSchema` instead. */ + export const outboundSchema = ChunkingStrategy$outboundSchema; } /** @internal */ -export const Files$inboundSchema: z.ZodType = z.object({ +export const Files$inboundSchema: z.ZodType = z + .object({ content: z.union([ - z.instanceof(ReadableStream), - z.instanceof(Blob), - z.instanceof(ArrayBuffer), - z.instanceof(Buffer), + z.instanceof(ReadableStream), + z.instanceof(Blob), + z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), ]), fileName: z.string(), -}); + }); /** @internal */ export type Files$Outbound = { - content: ReadableStream | Blob | ArrayBuffer | Buffer; - fileName: string; + content: ReadableStream | Blob | ArrayBuffer | Uint8Array; + fileName: string; }; /** @internal */ -export const Files$outboundSchema: z.ZodType = z.object({ - content: z.union([ - z.instanceof(ReadableStream), - z.instanceof(Blob), - z.instanceof(ArrayBuffer), - z.instanceof(Buffer), - ]), - fileName: z.string(), +export const Files$outboundSchema: z.ZodType< + Files$Outbound, + z.ZodTypeDef, + Files +> = z.object({ + content: z.union([ + z.instanceof(ReadableStream), + z.instanceof(Blob), + z.instanceof(ArrayBuffer), + z.instanceof(Uint8Array), + ]), + fileName: z.string(), }); /** diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 728247be..e3aafe5e 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -8,6 +8,6 @@ import { General } from "./general.js"; export class UnstructuredClient extends ClientSDK { private _general?: General; get general(): General { - return (this._general ??= new General(this.options$)); + return (this._general ??= new General(this._options)); } }