diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 9fbc3544..f361f090 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: 3e42d77bf491e4e7a999ec6d27d41fd1 - docVersion: 1.1.17 - speakeasyVersion: 1.552.0 - generationVersion: 2.610.0 - releaseVersion: 0.24.4 - configChecksum: c0e0d6524bed361c1a8ebeda0e6333df + docChecksum: 251a87fb7643cd585e4ddf956bb1ae1f + docVersion: 1.1.23 + speakeasyVersion: 1.555.3 + generationVersion: 2.620.2 + releaseVersion: 0.25.0 + configChecksum: 3cf3f043a49108bf9cbc7c2f2476b151 repoURL: https://github.com/Unstructured-IO/unstructured-js-client.git repoSubDirectory: . installationURL: https://github.com/Unstructured-IO/unstructured-js-client @@ -16,7 +16,7 @@ features: acceptHeaders: 2.81.2 additionalDependencies: 0.1.0 constsAndDefaults: 0.1.11 - core: 3.21.9 + core: 3.21.10 defaultEnabledRetries: 0.1.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.1.2 @@ -30,7 +30,7 @@ features: openEnums: 0.1.1 responseFormat: 0.2.3 retries: 2.83.0 - sdkHooks: 0.2.0 + sdkHooks: 0.3.0 serverIDs: 2.81.2 unions: 2.85.8 uploadStreams: 0.1.0 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 7ad7cc29..a314bfdc 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,21 +1,21 @@ -speakeasyVersion: 1.552.0 +speakeasyVersion: 1.555.3 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:11dc672fb20011d88c36c9e88092258b76ffe07dbf7d4d9493a4a8a63de97e0b - sourceBlobDigest: sha256:d70162f1aa06e4b75fdb38608d8ca25948651246e8da161f0947af385732aff3 + sourceRevisionDigest: sha256:8eb1828e2c067201a3e864721b453543815bbbb71fb160723bb331bb01e4d9aa + sourceBlobDigest: sha256:614c15b826e255f33812df0a7bb989a7bfb194167fa111162594664c04c2c5f4 tags: - latest - - speakeasy-sdk-regen-1748046653 - - 1.1.17 + - speakeasy-sdk-regen-1749083555 + - 1.1.23 targets: unstructed-typescript: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:11dc672fb20011d88c36c9e88092258b76ffe07dbf7d4d9493a4a8a63de97e0b - sourceBlobDigest: sha256:d70162f1aa06e4b75fdb38608d8ca25948651246e8da161f0947af385732aff3 + sourceRevisionDigest: sha256:8eb1828e2c067201a3e864721b453543815bbbb71fb160723bb331bb01e4d9aa + sourceBlobDigest: sha256:614c15b826e255f33812df0a7bb989a7bfb194167fa111162594664c04c2c5f4 codeSamplesNamespace: my-source-typescript-code-samples - codeSamplesRevisionDigest: sha256:116507a44839dec1f86e45a1a782df522e4ff29c592635c14f2f5e8196ec91d7 + codeSamplesRevisionDigest: sha256:145ca0fb688e7d825c8f66ba00ecfee5a960ce4ad2c9a07c0e7683306d0b92e2 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/FUNCTIONS.md b/FUNCTIONS.md index 0dd1ddc2..03906a13 100644 --- a/FUNCTIONS.md +++ b/FUNCTIONS.md @@ -22,8 +22,7 @@ specific category of applications. import { openAsBlob } from "node:fs"; import { UnstructuredClientCore } from "unstructured-client/core.js"; import { generalPartition } from "unstructured-client/funcs/generalPartition.js"; -import { SDKValidationError } from "unstructured-client/sdk/models/errors/sdkvalidationerror.js"; -import { VLMModel, VLMModelProvider } from "unstructured-client/sdk/models/shared"; +import { Strategy, VLMModel, VLMModelProvider } from "unstructured-client/sdk/models/shared"; // Use `UnstructuredClientCore` for best tree-shaking performance. // You can create one instance of it to use across an application. @@ -38,32 +37,17 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, }); - - switch (true) { - case res.ok: - // The success case will be handled outside of the switch block - break; - case res.error instanceof SDKValidationError: - // Pretty-print validation errors. - return console.log(res.error.pretty()); - case res.error instanceof Error: - return console.log(res.error); - default: - // TypeScript's type checking will fail on the following line if the above - // cases were not exhaustive. - res.error satisfies never; - throw new Error("Assertion failed: expected error checks to be exhaustive: " + res.error); + if (res.ok) { + const { value: result } = res; + console.log(result); + } else { + console.log("generalPartition failed:", res.error); } - - - const { value: result } = res; - - // Handle the result - console.log(result); } run(); diff --git a/README.md b/README.md index c59dae3a..8af7e390 100755 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ To change the default retry strategy for a single API call, simply provide a ret import { openAsBlob } from "node:fs"; import { UnstructuredClient } from "unstructured-client"; import { + Strategy, VLMModel, VLMModelProvider, } from "unstructured-client/sdk/models/shared"; @@ -221,6 +222,7 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, @@ -237,7 +239,6 @@ async function run() { }, }); - // Handle the result console.log(result); } @@ -250,6 +251,7 @@ If you'd like to override the default retry strategy for all operations that sup import { openAsBlob } from "node:fs"; import { UnstructuredClient } from "unstructured-client"; import { + Strategy, VLMModel, VLMModelProvider, } from "unstructured-client/sdk/models/shared"; @@ -276,12 +278,12 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, }); - // Handle the result console.log(result); } @@ -378,6 +380,7 @@ Certain SDK methods accept files as part of a multi-part request. It is possible import { openAsBlob } from "node:fs"; import { UnstructuredClient } from "unstructured-client"; import { + Strategy, VLMModel, VLMModelProvider, } from "unstructured-client/sdk/models/shared"; @@ -393,12 +396,12 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, }); - // Handle the result console.log(result); } diff --git a/RELEASES.md b/RELEASES.md index 76d70c50..194b4b56 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -604,4 +604,14 @@ Based on: ### Generated - [typescript v0.24.4] . ### Releases -- [NPM v0.24.4] https://www.npmjs.com/package/unstructured-client/v/0.24.4 - . \ No newline at end of file +- [NPM v0.24.4] https://www.npmjs.com/package/unstructured-client/v/0.24.4 - . + +## 2025-06-05 00:32:18 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.555.3 (2.620.2) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v0.25.0] . +### Releases +- [NPM v0.25.0] https://www.npmjs.com/package/unstructured-client/v/0.25.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 8612aec5..9ea4c10b 100644 --- a/USAGE.md +++ b/USAGE.md @@ -3,6 +3,7 @@ import { openAsBlob } from "node:fs"; import { UnstructuredClient } from "unstructured-client"; import { + Strategy, VLMModel, VLMModelProvider, } from "unstructured-client/sdk/models/shared"; @@ -18,12 +19,12 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, }); - // Handle the result console.log(result); } diff --git a/codeSamples.yaml b/codeSamples.yaml index 29daf366..2e99eb00 100644 --- a/codeSamples.yaml +++ b/codeSamples.yaml @@ -8,4 +8,4 @@ actions: "x-codeSamples": - "lang": "typescript" "label": "partition" - "source": "import { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport { VLMModel, VLMModelProvider } 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 vlmModelProvider: VLMModelProvider.Openai,\n vlmModel: VLMModel.Gpt4o,\n chunkingStrategy: \"by_title\",\n splitPdfPageRange: [\n 1,\n 10,\n ],\n },\n });\n\n // Handle the result\n console.log(result);\n}\n\nrun();" + "source": "import { openAsBlob } from \"node:fs\";\nimport { UnstructuredClient } from \"unstructured-client\";\nimport { Strategy, VLMModel, VLMModelProvider } 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 vlmModelProvider: VLMModelProvider.Openai,\n vlmModel: VLMModel.Gpt4o,\n chunkingStrategy: \"by_title\",\n splitPdfPageRange: [\n 1,\n 10,\n ],\n },\n });\n\n console.log(result);\n}\n\nrun();" diff --git a/docs/sdk/models/errors/detail.md b/docs/sdk/models/errors/detail.md index 37dc30e9..f7e48032 100644 --- a/docs/sdk/models/errors/detail.md +++ b/docs/sdk/models/errors/detail.md @@ -9,7 +9,7 @@ const value: shared.ValidationError[] = [ { loc: [ - 569227, + "", ], msg: "", type: "", diff --git a/docs/sdk/models/shared/strategy.md b/docs/sdk/models/shared/strategy.md index 57b5ff3b..1da5d448 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.Vlm; +let value: Strategy = Strategy.Auto; ``` ## Values diff --git a/docs/sdk/models/shared/validationerror.md b/docs/sdk/models/shared/validationerror.md index 5e83e718..d2f88c59 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: [ - 598752, + 929957, ], msg: "", type: "", diff --git a/docs/sdks/general/README.md b/docs/sdks/general/README.md index 2b6cf332..45e15c73 100644 --- a/docs/sdks/general/README.md +++ b/docs/sdks/general/README.md @@ -16,7 +16,7 @@ Description ```typescript import { openAsBlob } from "node:fs"; import { UnstructuredClient } from "unstructured-client"; -import { VLMModel, VLMModelProvider } from "unstructured-client/sdk/models/shared"; +import { Strategy, VLMModel, VLMModelProvider } from "unstructured-client/sdk/models/shared"; const unstructuredClient = new UnstructuredClient(); @@ -29,12 +29,12 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, }); - // Handle the result console.log(result); } @@ -49,7 +49,7 @@ The standalone function version of this method: import { openAsBlob } from "node:fs"; import { UnstructuredClientCore } from "unstructured-client/core.js"; import { generalPartition } from "unstructured-client/funcs/generalPartition.js"; -import { VLMModel, VLMModelProvider } from "unstructured-client/sdk/models/shared"; +import { Strategy, VLMModel, VLMModelProvider } from "unstructured-client/sdk/models/shared"; // Use `UnstructuredClientCore` for best tree-shaking performance. // You can create one instance of it to use across an application. @@ -64,19 +64,17 @@ async function run() { 1, 10, ], + strategy: Strategy.Auto, vlmModel: VLMModel.Gpt4o, vlmModelProvider: VLMModelProvider.Openai, }, }); - - if (!res.ok) { - throw res.error; + if (res.ok) { + const { value: result } = res; + console.log(result); + } else { + console.log("generalPartition failed:", res.error); } - - const { value: result } = res; - - // Handle the result - console.log(result); } run(); diff --git a/gen.yaml b/gen.yaml index e51917dc..ad5ca0af 100644 --- a/gen.yaml +++ b/gen.yaml @@ -3,6 +3,7 @@ generation: sdkClassName: unstructured_client usageSnippets: optionalPropertyRendering: withExample + sdkInitStyle: constructor fixes: nameResolutionFeb2025: false parameterOrderingFeb2024: false @@ -13,7 +14,7 @@ generation: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false typescript: - version: 0.24.4 + version: 0.25.0 additionalDependencies: dependencies: async: ^3.2.5 diff --git a/jsr.json b/jsr.json index e57b63f3..d9bb297e 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "unstructured-client", - "version": "0.24.4", + "version": "0.25.0", "exports": { ".": "./src/index.ts", "./sdk/models/errors": "./src/sdk/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index 8256759e..f5bbd3b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "unstructured-client", - "version": "0.24.4", + "version": "0.25.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "unstructured-client", - "version": "0.24.4", + "version": "0.25.0", "dependencies": { "async": "^3.2.5", "pdf-lib": "^1.17.1" diff --git a/package.json b/package.json index 2f59a3bf..7acf62a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unstructured-client", - "version": "0.24.4", + "version": "0.25.0", "author": "Unstructured", "type": "module", "bin": { diff --git a/src/funcs/generalPartition.ts b/src/funcs/generalPartition.ts index 75961644..47898d0c 100644 --- a/src/funcs/generalPartition.ts +++ b/src/funcs/generalPartition.ts @@ -357,6 +357,7 @@ async function $do( const requestSecurity = resolveGlobalSecurity(securityInput); const context = { + options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "partition", oAuth2Scopes: [], @@ -387,6 +388,7 @@ async function $do( path: path, headers: headers, body: body, + userAgent: client._options.userAgent, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { diff --git a/src/hooks/types.ts b/src/hooks/types.ts index 1d56c6f2..8bfe4fe8 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -2,6 +2,7 @@ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ +import { SDKOptions } from "../lib/config.js"; import { HTTPClient, RequestInput } from "../lib/http.js"; import { RetryConfig } from "../lib/retries.js"; import { SecurityState } from "../lib/security.js"; @@ -13,6 +14,7 @@ export type HookContext = { securitySource?: any | (() => Promise); retryConfig: RetryConfig; resolvedSecurity: SecurityState | null; + options: SDKOptions; }; export type Awaitable = T | Promise; diff --git a/src/index.ts b/src/index.ts index 5ddc765e..dbcba164 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,4 +4,6 @@ export * from "./lib/config.js"; export * as files from "./lib/files.js"; +export { HTTPClient } from "./lib/http.js"; +export type { Fetcher, HTTPClientOptions } from "./lib/http.js"; export * from "./sdk/sdk.js"; diff --git a/src/lib/config.ts b/src/lib/config.ts index fb37706e..e3b81918 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -39,6 +39,10 @@ export type SDKOptions = { * Allows overriding the default server URL used by the SDK */ serverURL?: string | undefined; + /** + * Allows overriding the default user agent used by the SDK + */ + userAgent?: string | undefined; /** * Allows overriding the default retry config used by the SDK */ @@ -63,9 +67,9 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", - openapiDocVersion: "1.1.17", - sdkVersion: "0.24.4", - genVersion: "2.610.0", + openapiDocVersion: "1.1.23", + sdkVersion: "0.25.0", + genVersion: "2.620.2", userAgent: - "speakeasy-sdk/typescript 0.24.4 2.610.0 1.1.17 unstructured-client", + "speakeasy-sdk/typescript 0.25.0 2.620.2 1.1.23 unstructured-client", } as const; diff --git a/src/lib/sdks.ts b/src/lib/sdks.ts index 7864f67c..9979e5f5 100644 --- a/src/lib/sdks.ts +++ b/src/lib/sdks.ts @@ -64,6 +64,7 @@ type RequestConfig = { headers?: HeadersInit; security?: SecurityState | null; uaHeader?: string; + userAgent?: string | undefined; timeoutMs?: number; }; @@ -95,19 +96,21 @@ export class ClientSDK { } else { this.#hooks = new SDKHooks(); } - this._options = { ...options, hooks: this.#hooks }; - const url = serverURLFromOptions(options); if (url) { url.pathname = url.pathname.replace(/\/+$/, "") + "/"; } + const { baseURL, client } = this.#hooks.sdkInit({ baseURL: url, client: options.httpClient || new HTTPClient(), }); this._baseURL = baseURL; this.#httpClient = client; - this.#logger = options.debugLogger; + + this._options = { ...options, hooks: this.#hooks }; + + this.#logger = this._options.debugLogger; } public _createRequest( @@ -180,7 +183,10 @@ export class ClientSDK { // Only set user agent header in non-browser-like environments since CORS // policy disallows setting it in browsers e.g. Chrome throws an error. if (!isBrowserLike) { - headers.set(conf.uaHeader ?? "user-agent", SDK_METADATA.userAgent); + headers.set( + conf.uaHeader ?? "user-agent", + conf.userAgent ?? SDK_METADATA.userAgent, + ); } const fetchOptions: Omit = { diff --git a/src/mcp-server/mcp-server.ts b/src/mcp-server/mcp-server.ts index 2044c7a3..ee3ca4e9 100644 --- a/src/mcp-server/mcp-server.ts +++ b/src/mcp-server/mcp-server.ts @@ -19,7 +19,7 @@ const routes = buildRouteMap({ export const app = buildApplication(routes, { name: "mcp", versionInfo: { - currentVersion: "0.24.4", + currentVersion: "0.25.0", }, }); diff --git a/src/mcp-server/server.ts b/src/mcp-server/server.ts index 7d44fd63..2d798435 100644 --- a/src/mcp-server/server.ts +++ b/src/mcp-server/server.ts @@ -27,7 +27,7 @@ export function createMCPServer(deps: { }) { const server = new McpServer({ name: "UnstructuredClient", - version: "0.24.4", + version: "0.25.0", }); const client = new UnstructuredClientCore({ diff --git a/src/sdk/models/errors/sdkerror.ts b/src/sdk/models/errors/sdkerror.ts index 001f4659..ba47f662 100644 --- a/src/sdk/models/errors/sdkerror.ts +++ b/src/sdk/models/errors/sdkerror.ts @@ -3,22 +3,37 @@ */ export class SDKError extends Error { + /** + * HTTP status code + */ public readonly statusCode: number; + /** + * HTTP content type + */ public readonly contentType: string; + /** + * HTTP body + */ + public readonly body: string; + /** + * Raw response + */ + public readonly rawResponse: Response; constructor( message: string, - public readonly rawResponse: Response, - public readonly body: string = "", + rawResponse: Response, + body: string = "", ) { const statusCode = rawResponse.status; const contentType = rawResponse.headers.get("content-type") || ""; const bodyString = body.length > 0 ? `\n${body}` : ""; - super( `${message}: Status ${statusCode} Content-Type ${contentType} Body ${bodyString}`, ); + this.body = body; + this.rawResponse = rawResponse; this.statusCode = statusCode; this.contentType = contentType;