diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index e9c5562f..1f174100 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,12 +1,12 @@ -speakeasyVersion: 1.517.3 +speakeasyVersion: 1.606.10 sources: mistral-azure-source: sourceNamespace: mistral-openapi-azure - sourceRevisionDigest: sha256:670c460702ec74f7077491464a6dc5ee9d873969c80e812c48dbf4deb160e470 - sourceBlobDigest: sha256:5a3ebfa4cb00a015bb7bb03ec7442fc7e0b9c17ca66ab35d3045290b2ad87eac + sourceRevisionDigest: sha256:597774940087aa6fcd0d62d088533e695b2b98c6f1048ceb73712688484e96f4 + sourceBlobDigest: sha256:d7f5753d129b1f4a2a5631130ec30c13dc29c6b763d18e0e1d96ae2fe9e0fc62 tags: - latest - - speakeasy-sdk-regen-1756133560 + - speakeasy-sdk-regen-1756820965 mistral-google-cloud-source: sourceNamespace: mistral-openapi-google-cloud sourceRevisionDigest: sha256:4a5343e63c6a78152e472b00ccc46d7bcb15594496bc94c8040039d3a9d4c5f8 @@ -25,10 +25,10 @@ targets: mistralai-azure-sdk: source: mistral-azure-source sourceNamespace: mistral-openapi-azure - sourceRevisionDigest: sha256:670c460702ec74f7077491464a6dc5ee9d873969c80e812c48dbf4deb160e470 - sourceBlobDigest: sha256:5a3ebfa4cb00a015bb7bb03ec7442fc7e0b9c17ca66ab35d3045290b2ad87eac + sourceRevisionDigest: sha256:597774940087aa6fcd0d62d088533e695b2b98c6f1048ceb73712688484e96f4 + sourceBlobDigest: sha256:d7f5753d129b1f4a2a5631130ec30c13dc29c6b763d18e0e1d96ae2fe9e0fc62 codeSamplesNamespace: mistral-openapi-azure-code-samples - codeSamplesRevisionDigest: sha256:d373ba4abaf784b31d5e84bf6df764cfefc312dc926b6ac1503f95c2a0c5cfee + codeSamplesRevisionDigest: sha256:d911a84daedd405bf470148ad76626dd4e38c21bf0b4b2aaead7aec5efdd760c mistralai-gcp-sdk: source: mistral-google-cloud-source sourceNamespace: mistral-openapi-google-cloud @@ -45,7 +45,7 @@ targets: codeSamplesRevisionDigest: sha256:34e2099c693e2889e7a954dd68353d33403f7b2bdb0eb39e2c69f3c8c1e58b70 workflow: workflowVersion: 1.0.0 - speakeasyVersion: 1.517.3 + speakeasyVersion: v1.606.10 sources: mistral-azure-source: inputs: diff --git a/packages/mistralai-azure/.gitignore b/packages/mistralai-azure/.gitignore index dc2842dc..da5c73af 100644 --- a/packages/mistralai-azure/.gitignore +++ b/packages/mistralai-azure/.gitignore @@ -1,3 +1,11 @@ +/examples/node_modules +.DS_Store +**/.speakeasy/temp/ +**/.speakeasy/logs/ +.DS_Store +.env +.env.local +.env.*.local /mcp-server /bin /.eslintcache diff --git a/packages/mistralai-azure/.speakeasy/gen.lock b/packages/mistralai-azure/.speakeasy/gen.lock index 8671e92d..d69e3cf4 100644 --- a/packages/mistralai-azure/.speakeasy/gen.lock +++ b/packages/mistralai-azure/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 01e8a40b-3df3-4d9a-9501-2eb9e0d26c05 management: - docChecksum: 87653f040f5b36c90e066870f34c478e + docChecksum: 65d0e29b5374a9509e9af311f51a1b21 docVersion: 1.0.0 - speakeasyVersion: 1.517.3 - generationVersion: 2.548.6 - releaseVersion: 1.6.0 - configChecksum: 9a8039f55bb9f5f2ed7dc48f15005ec5 + speakeasyVersion: 1.606.10 + generationVersion: 2.687.13 + releaseVersion: 1.7.0 + configChecksum: 7ac97405dd6668d2395562f99adc191b repoURL: https://github.com/mistralai/client-ts.git repoSubDirectory: packages/mistralai-azure installationURL: https://gitpkg.now.sh/mistralai/client-ts/packages/mistralai-azure @@ -15,26 +15,26 @@ features: typescript: additionalDependencies: 0.1.0 additionalProperties: 0.1.1 - constsAndDefaults: 0.1.11 - core: 3.21.4 + constsAndDefaults: 0.1.12 + core: 3.21.20 defaultEnabledRetries: 0.1.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.1.2 - examples: 2.81.5 + examples: 2.82.3 globalSecurity: 2.82.13 globalSecurityCallbacks: 0.1.0 globalSecurityFlattening: 0.1.0 - globalServerURLs: 2.82.4 + globalServerURLs: 2.82.5 nameOverrides: 2.81.2 nullables: 0.1.1 openEnums: 0.1.1 responseFormat: 0.2.3 retries: 2.83.0 - sdkHooks: 0.2.0 - serverEvents: 0.1.5 + sdkHooks: 0.3.0 + serverEvents: 0.1.8 serverEventsSentinels: 0.1.0 serverIDs: 2.81.2 - unions: 2.85.8 + unions: 2.85.11 generatedFiles: - .gitattributes - .npmignore @@ -92,7 +92,11 @@ generatedFiles: - docs/models/components/stop.md - docs/models/components/systemmessage.md - docs/models/components/systemmessagecontent.md + - docs/models/components/systemmessagecontentchunks.md - docs/models/components/textchunk.md + - docs/models/components/thinkchunk.md + - docs/models/components/thinkchunktype.md + - docs/models/components/thinking.md - docs/models/components/tool.md - docs/models/components/toolcall.md - docs/models/components/toolchoice.md @@ -109,6 +113,9 @@ generatedFiles: - docs/models/components/validationerror.md - docs/models/errors/httpvalidationerror.md - eslint.config.mjs + - examples/.env.template + - examples/chatComplete.example.ts + - examples/package.json - jsr.json - package.json - src/core.ts @@ -168,7 +175,9 @@ generatedFiles: - src/models/components/responseformats.ts - src/models/components/security.ts - src/models/components/systemmessage.ts + - src/models/components/systemmessagecontentchunks.ts - src/models/components/textchunk.ts + - src/models/components/thinkchunk.ts - src/models/components/tool.ts - src/models/components/toolcall.ts - src/models/components/toolchoice.ts @@ -181,6 +190,8 @@ generatedFiles: - src/models/errors/httpclienterrors.ts - src/models/errors/httpvalidationerror.ts - src/models/errors/index.ts + - src/models/errors/mistralazureerror.ts + - src/models/errors/responsevalidationerror.ts - src/models/errors/sdkerror.ts - src/models/errors/sdkvalidationerror.ts - src/sdk/chat.ts @@ -204,24 +215,24 @@ examples: responses: "422": application/json: {} - "200": {} chat_completion_v1_chat_completions_post: speakeasy-default-chat-completion-v1-chat-completions-post: requestBody: application/json: {"model": "azureai", "stream": false, "messages": [{"content": "Who is the best French painter? Answer in one short sentence.", "role": "user"}]} responses: "200": - application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 16, "completion_tokens": 34, "total_tokens": 50}, "created": 1702256327, "choices": [{"index": 0, "message": {"prefix": false, "role": "assistant"}, "finish_reason": "stop"}, {"index": 0, "message": {"prefix": false, "role": "assistant"}, "finish_reason": "stop"}, {"index": 0, "message": {"prefix": false, "role": "assistant"}, "finish_reason": "stop"}]} + application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "mistral-small-latest", "usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0}, "created": 1702256327, "choices": []} "422": application/json: {} ocr_v1_ocr_post: speakeasy-default-ocr-v1-ocr-post: requestBody: - application/json: {"model": "Focus", "document": {"type": "file", "file_id": "d36f3178-f390-4532-8486-0e0b118bbaba"}} + application/json: {"model": "CX-9", "document": {"document_url": "https://upset-labourer.net/", "type": "document_url"}} responses: "200": - application/json: {"pages": [], "model": "Expedition", "usage_info": {"pages_processed": 487025}} + application/json: {"pages": [], "model": "Golf", "usage_info": {"pages_processed": 944919}} "422": application/json: {} -examplesVersion: 1.0.0 +examplesVersion: 1.0.2 generatedTests: {} +releaseNotes: "## SDK Changes Detected:\n* `mistralazure.chat.complete()`: \n * `request.messages.[].[assistant].content.[array]` **Changed** **Breaking** :warning:\n" diff --git a/packages/mistralai-azure/.speakeasy/gen.yaml b/packages/mistralai-azure/.speakeasy/gen.yaml index ca928089..34021977 100644 --- a/packages/mistralai-azure/.speakeasy/gen.yaml +++ b/packages/mistralai-azure/.speakeasy/gen.yaml @@ -4,6 +4,7 @@ generation: maintainOpenAPIOrder: true usageSnippets: optionalPropertyRendering: withExample + sdkInitStyle: constructor useClassNamesForArrayFields: true fixes: nameResolutionDec2023: true @@ -11,18 +12,25 @@ generation: parameterOrderingFeb2024: true requestResponseComponentNamesFeb2024: true securityFeb2025: false + sharedErrorComponentsApr2025: false auth: oAuth2ClientCredentialsEnabled: true oAuth2PasswordEnabled: false + tests: + generateTests: true + generateNewTests: false + skipResponseBodyAssertions: false typescript: - version: 1.6.0 + version: 1.7.0 additionalDependencies: dependencies: {} devDependencies: {} peerDependencies: {} additionalPackageJSON: {} author: Speakeasy + baseErrorName: MistralAzureError clientServerStatusCodesAsErrors: true + constFieldsAlwaysOptional: true defaultErrorName: SDKError enableCustomCodeRegions: false enableMCPServer: false @@ -31,6 +39,7 @@ typescript: envVarPrefix: MISTRAL flattenGlobalSecurity: true flatteningOrder: body-first + generateExamples: true imports: option: openapi paths: @@ -48,4 +57,5 @@ typescript: packageName: '@mistralai/mistralai-azure' responseFormat: flat templateVersion: v2 + usageSDKInitImports: [] useIndexModules: true diff --git a/packages/mistralai-azure/FUNCTIONS.md b/packages/mistralai-azure/FUNCTIONS.md index 572f41e9..9e2ebb04 100644 --- a/packages/mistralai-azure/FUNCTIONS.md +++ b/packages/mistralai-azure/FUNCTIONS.md @@ -21,7 +21,6 @@ specific category of applications. ```typescript import { MistralAzureCore } from "@mistralai/mistralai-azure/core.js"; import { chatComplete } from "@mistralai/mistralai-azure/funcs/chatComplete.js"; -import { SDKValidationError } from "@mistralai/mistralai-azure/models/errors/sdkvalidationerror.js"; // Use `MistralAzureCore` for best tree-shaking performance. // You can create one instance of it to use across an application. @@ -38,28 +37,12 @@ async function run() { }, ], }); - - 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("chatComplete failed:", res.error); } - - - const { value: result } = res; - - // Handle the result - console.log(result); } run(); diff --git a/packages/mistralai-azure/RELEASES.md b/packages/mistralai-azure/RELEASES.md index a23eb800..e4701147 100644 --- a/packages/mistralai-azure/RELEASES.md +++ b/packages/mistralai-azure/RELEASES.md @@ -128,4 +128,14 @@ Based on: ### Generated - [typescript v1.6.0] packages/mistralai-azure ### Releases -- [NPM v1.6.0] https://www.npmjs.com/package/@mistralai/mistralai-azure/v/1.6.0 - packages/mistralai-azure \ No newline at end of file +- [NPM v1.6.0] https://www.npmjs.com/package/@mistralai/mistralai-azure/v/1.6.0 - packages/mistralai-azure + +## 2025-09-02 13:49:09 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.606.10 (2.687.13) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v1.7.0] packages/mistralai-azure +### Releases +- [NPM v1.7.0] https://www.npmjs.com/package/@mistralai/mistralai-azure/v/1.7.0 - packages/mistralai-azure \ No newline at end of file diff --git a/packages/mistralai-azure/docs/models/components/arguments.md b/packages/mistralai-azure/docs/models/components/arguments.md index ef0bdc61..5a99a089 100644 --- a/packages/mistralai-azure/docs/models/components/arguments.md +++ b/packages/mistralai-azure/docs/models/components/arguments.md @@ -8,6 +8,8 @@ ```typescript const value: { [k: string]: any } = { "key": "", + "key1": "", + "key2": "", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/assistantmessagecontent.md b/packages/mistralai-azure/docs/models/components/assistantmessagecontent.md index ffa94cf0..7918f1c9 100644 --- a/packages/mistralai-azure/docs/models/components/assistantmessagecontent.md +++ b/packages/mistralai-azure/docs/models/components/assistantmessagecontent.md @@ -12,13 +12,6 @@ const value: string = ""; ### `components.ContentChunk[]` ```typescript -const value: components.ContentChunk[] = [ - { - imageUrl: { - url: "https://jittery-window.com", - }, - type: "image_url", - }, -]; +const value: components.ContentChunk[] = []; ``` diff --git a/packages/mistralai-azure/docs/models/components/chatcompletionrequestmessages.md b/packages/mistralai-azure/docs/models/components/chatcompletionrequestmessages.md index 0bc19a1b..68272ebf 100644 --- a/packages/mistralai-azure/docs/models/components/chatcompletionrequestmessages.md +++ b/packages/mistralai-azure/docs/models/components/chatcompletionrequestmessages.md @@ -3,12 +3,6 @@ ## Supported Types -### `components.AssistantMessage` - -```typescript -const value: components.AssistantMessage = {}; -``` - ### `components.SystemMessage` ```typescript @@ -21,14 +15,7 @@ const value: components.SystemMessage = { ```typescript const value: components.ToolMessage = { - content: [ - { - imageUrl: { - url: "https://sugary-brace.org/", - }, - type: "image_url", - }, - ], + content: [], }; ``` @@ -40,3 +27,9 @@ const value: components.UserMessage = { }; ``` +### `components.AssistantMessage` + +```typescript +const value: components.AssistantMessage = {}; +``` + diff --git a/packages/mistralai-azure/docs/models/components/chatcompletionrequeststop.md b/packages/mistralai-azure/docs/models/components/chatcompletionrequeststop.md index 5cf805d7..e935025f 100644 --- a/packages/mistralai-azure/docs/models/components/chatcompletionrequeststop.md +++ b/packages/mistralai-azure/docs/models/components/chatcompletionrequeststop.md @@ -15,7 +15,8 @@ const value: string = ""; ```typescript const value: string[] = [ - "", + "", + "", ]; ``` diff --git a/packages/mistralai-azure/docs/models/components/chatcompletionresponse.md b/packages/mistralai-azure/docs/models/components/chatcompletionresponse.md index 8a925b79..a5b5bbc8 100644 --- a/packages/mistralai-azure/docs/models/components/chatcompletionresponse.md +++ b/packages/mistralai-azure/docs/models/components/chatcompletionresponse.md @@ -11,13 +11,7 @@ let value: ChatCompletionResponse = { model: "mistral-small-latest", usage: {}, created: 1702256327, - choices: [ - { - index: 0, - message: {}, - finishReason: "stop", - }, - ], + choices: [], }; ``` diff --git a/packages/mistralai-azure/docs/models/components/chatcompletionstreamrequesttoolchoice.md b/packages/mistralai-azure/docs/models/components/chatcompletionstreamrequesttoolchoice.md index 4d4a29f2..9f19e8c4 100644 --- a/packages/mistralai-azure/docs/models/components/chatcompletionstreamrequesttoolchoice.md +++ b/packages/mistralai-azure/docs/models/components/chatcompletionstreamrequesttoolchoice.md @@ -16,6 +16,6 @@ const value: components.ToolChoice = { ### `components.ToolChoiceEnum` ```typescript -const value: components.ToolChoiceEnum = "none"; +const value: components.ToolChoiceEnum = "required"; ``` diff --git a/packages/mistralai-azure/docs/models/components/completionchunk.md b/packages/mistralai-azure/docs/models/components/completionchunk.md index 209c9984..4ed0b424 100644 --- a/packages/mistralai-azure/docs/models/components/completionchunk.md +++ b/packages/mistralai-azure/docs/models/components/completionchunk.md @@ -7,14 +7,8 @@ import { CompletionChunk } from "@mistralai/mistralai-azure/models/components"; let value: CompletionChunk = { id: "", - model: "Golf", - choices: [ - { - index: 423655, - delta: {}, - finishReason: "error", - }, - ], + model: "Prius", + choices: [], }; ``` diff --git a/packages/mistralai-azure/docs/models/components/completionevent.md b/packages/mistralai-azure/docs/models/components/completionevent.md index 4fbe8aba..53125907 100644 --- a/packages/mistralai-azure/docs/models/components/completionevent.md +++ b/packages/mistralai-azure/docs/models/components/completionevent.md @@ -8,14 +8,8 @@ import { CompletionEvent } from "@mistralai/mistralai-azure/models/components"; let value: CompletionEvent = { data: { id: "", - model: "Golf", - choices: [ - { - index: 715190, - delta: {}, - finishReason: "error", - }, - ], + model: "Model S", + choices: [], }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/completionresponsestreamchoice.md b/packages/mistralai-azure/docs/models/components/completionresponsestreamchoice.md index 6f3cac44..35956d97 100644 --- a/packages/mistralai-azure/docs/models/components/completionresponsestreamchoice.md +++ b/packages/mistralai-azure/docs/models/components/completionresponsestreamchoice.md @@ -6,7 +6,7 @@ import { CompletionResponseStreamChoice } from "@mistralai/mistralai-azure/models/components"; let value: CompletionResponseStreamChoice = { - index: 891773, + index: 264645, delta: {}, finishReason: "tool_calls", }; diff --git a/packages/mistralai-azure/docs/models/components/content.md b/packages/mistralai-azure/docs/models/components/content.md index b05000a3..e31bfa0c 100644 --- a/packages/mistralai-azure/docs/models/components/content.md +++ b/packages/mistralai-azure/docs/models/components/content.md @@ -12,11 +12,6 @@ const value: string = ""; ### `components.ContentChunk[]` ```typescript -const value: components.ContentChunk[] = [ - { - text: "", - type: "text", - }, -]; +const value: components.ContentChunk[] = []; ``` diff --git a/packages/mistralai-azure/docs/models/components/contentchunk.md b/packages/mistralai-azure/docs/models/components/contentchunk.md index b25f2ef2..51f7f26a 100644 --- a/packages/mistralai-azure/docs/models/components/contentchunk.md +++ b/packages/mistralai-azure/docs/models/components/contentchunk.md @@ -7,7 +7,7 @@ ```typescript const value: components.ImageURLChunk = { - imageUrl: "https://blaring-bog.com", + imageUrl: "https://darling-distinction.org", }; ``` @@ -23,9 +23,7 @@ const value: components.TextChunk = { ```typescript const value: components.ReferenceChunk = { - referenceIds: [ - 832620, - ], + referenceIds: [], }; ``` diff --git a/packages/mistralai-azure/docs/models/components/document.md b/packages/mistralai-azure/docs/models/components/document.md index 503e0389..9b7be3aa 100644 --- a/packages/mistralai-azure/docs/models/components/document.md +++ b/packages/mistralai-azure/docs/models/components/document.md @@ -9,7 +9,7 @@ Document to run OCR on ```typescript const value: components.FileChunk = { - fileId: "0d0a4bf3-9993-4f7d-9b4d-6e9ebb8fa690", + fileId: "9a7a83aa-6211-475c-88de-7116b47d91cd", }; ``` @@ -17,7 +17,7 @@ const value: components.FileChunk = { ```typescript const value: components.DocumentURLChunk = { - documentUrl: "https://fortunate-octave.info", + documentUrl: "https://other-reach.net", }; ``` @@ -25,9 +25,7 @@ const value: components.DocumentURLChunk = { ```typescript const value: components.ImageURLChunk = { - imageUrl: { - url: "https://official-mouser.name/", - }, + imageUrl: "https://darling-distinction.org", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/documenturlchunk.md b/packages/mistralai-azure/docs/models/components/documenturlchunk.md index 8b8c962e..cdf39198 100644 --- a/packages/mistralai-azure/docs/models/components/documenturlchunk.md +++ b/packages/mistralai-azure/docs/models/components/documenturlchunk.md @@ -6,7 +6,7 @@ import { DocumentURLChunk } from "@mistralai/mistralai-azure/models/components"; let value: DocumentURLChunk = { - documentUrl: "https://elliptical-fog.org", + documentUrl: "https://other-reach.net", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/filechunk.md b/packages/mistralai-azure/docs/models/components/filechunk.md index dbcbb5b0..49df1c26 100644 --- a/packages/mistralai-azure/docs/models/components/filechunk.md +++ b/packages/mistralai-azure/docs/models/components/filechunk.md @@ -6,7 +6,7 @@ import { FileChunk } from "@mistralai/mistralai-azure/models/components"; let value: FileChunk = { - fileId: "ecb1ebf2-d291-4dc9-861b-7bdfd05b2803", + fileId: "9a7a83aa-6211-475c-88de-7116b47d91cd", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/finishreason.md b/packages/mistralai-azure/docs/models/components/finishreason.md index fc4e9f1e..d9803f31 100644 --- a/packages/mistralai-azure/docs/models/components/finishreason.md +++ b/packages/mistralai-azure/docs/models/components/finishreason.md @@ -5,7 +5,7 @@ ```typescript import { FinishReason } from "@mistralai/mistralai-azure/models/components"; -let value: FinishReason = "length"; +let value: FinishReason = "error"; ``` ## Values diff --git a/packages/mistralai-azure/docs/models/components/imageurl.md b/packages/mistralai-azure/docs/models/components/imageurl.md index afcc58c8..415b8d31 100644 --- a/packages/mistralai-azure/docs/models/components/imageurl.md +++ b/packages/mistralai-azure/docs/models/components/imageurl.md @@ -6,7 +6,7 @@ import { ImageURL } from "@mistralai/mistralai-azure/models/components"; let value: ImageURL = { - url: "https://misguided-hawk.biz", + url: "https://grim-farm.name/", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/imageurlchunk.md b/packages/mistralai-azure/docs/models/components/imageurlchunk.md index d7feaa4c..541208a6 100644 --- a/packages/mistralai-azure/docs/models/components/imageurlchunk.md +++ b/packages/mistralai-azure/docs/models/components/imageurlchunk.md @@ -8,9 +8,7 @@ import { ImageURLChunk } from "@mistralai/mistralai-azure/models/components"; let value: ImageURLChunk = { - imageUrl: { - url: "https://close-paintwork.com", - }, + imageUrl: "https://darling-distinction.org", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/imageurlchunkimageurl.md b/packages/mistralai-azure/docs/models/components/imageurlchunkimageurl.md index 486a5ef7..6b0520c0 100644 --- a/packages/mistralai-azure/docs/models/components/imageurlchunkimageurl.md +++ b/packages/mistralai-azure/docs/models/components/imageurlchunkimageurl.md @@ -7,7 +7,7 @@ ```typescript const value: components.ImageURL = { - url: "https://true-wasabi.net", + url: "https://grim-farm.name/", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/jsonschema.md b/packages/mistralai-azure/docs/models/components/jsonschema.md index e0527855..10ac2182 100644 --- a/packages/mistralai-azure/docs/models/components/jsonschema.md +++ b/packages/mistralai-azure/docs/models/components/jsonschema.md @@ -9,6 +9,7 @@ let value: JsonSchema = { name: "", schemaDefinition: { "key": "", + "key1": "", }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/loc.md b/packages/mistralai-azure/docs/models/components/loc.md index 93706ec7..74021dec 100644 --- a/packages/mistralai-azure/docs/models/components/loc.md +++ b/packages/mistralai-azure/docs/models/components/loc.md @@ -12,6 +12,6 @@ const value: string = ""; ### `number` ```typescript -const value: number = 456150; +const value: number = 128403; ``` diff --git a/packages/mistralai-azure/docs/models/components/messages.md b/packages/mistralai-azure/docs/models/components/messages.md index 22b2a13a..9d69632e 100644 --- a/packages/mistralai-azure/docs/models/components/messages.md +++ b/packages/mistralai-azure/docs/models/components/messages.md @@ -3,22 +3,11 @@ ## Supported Types -### `components.AssistantMessage` - -```typescript -const value: components.AssistantMessage = {}; -``` - ### `components.SystemMessage` ```typescript const value: components.SystemMessage = { - content: [ - { - text: "", - type: "text", - }, - ], + content: "", }; ``` @@ -26,12 +15,7 @@ const value: components.SystemMessage = { ```typescript const value: components.ToolMessage = { - content: [ - { - text: "", - type: "text", - }, - ], + content: [], }; ``` @@ -39,14 +23,13 @@ const value: components.ToolMessage = { ```typescript const value: components.UserMessage = { - content: [ - { - referenceIds: [ - 359508, - ], - type: "reference", - }, - ], + content: "", }; ``` +### `components.AssistantMessage` + +```typescript +const value: components.AssistantMessage = {}; +``` + diff --git a/packages/mistralai-azure/docs/models/components/ocrimageobject.md b/packages/mistralai-azure/docs/models/components/ocrimageobject.md index 1e7b356d..0cbbad25 100644 --- a/packages/mistralai-azure/docs/models/components/ocrimageobject.md +++ b/packages/mistralai-azure/docs/models/components/ocrimageobject.md @@ -7,10 +7,10 @@ import { OCRImageObject } from "@mistralai/mistralai-azure/models/components"; let value: OCRImageObject = { id: "", - topLeftX: 716327, - topLeftY: 289406, - bottomRightX: 183191, - bottomRightY: 586513, + topLeftX: 147638, + topLeftY: null, + bottomRightX: 907287, + bottomRightY: null, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/ocrpagedimensions.md b/packages/mistralai-azure/docs/models/components/ocrpagedimensions.md index 96f38779..525e434f 100644 --- a/packages/mistralai-azure/docs/models/components/ocrpagedimensions.md +++ b/packages/mistralai-azure/docs/models/components/ocrpagedimensions.md @@ -6,9 +6,9 @@ import { OCRPageDimensions } from "@mistralai/mistralai-azure/models/components"; let value: OCRPageDimensions = { - dpi: 318569, - height: 667411, - width: 131797, + dpi: 613038, + height: 235980, + width: 539169, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/ocrpageobject.md b/packages/mistralai-azure/docs/models/components/ocrpageobject.md index 6037b41c..925f23f1 100644 --- a/packages/mistralai-azure/docs/models/components/ocrpageobject.md +++ b/packages/mistralai-azure/docs/models/components/ocrpageobject.md @@ -6,21 +6,13 @@ import { OCRPageObject } from "@mistralai/mistralai-azure/models/components"; let value: OCRPageObject = { - index: 64147, + index: 355599, markdown: "", - images: [ - { - id: "", - topLeftX: 692472, - topLeftY: 566602, - bottomRightX: 265389, - bottomRightY: 523248, - }, - ], + images: [], dimensions: { - dpi: 93940, - height: 575947, - width: 929297, + dpi: 225573, + height: 229870, + width: 469391, }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/ocrrequest.md b/packages/mistralai-azure/docs/models/components/ocrrequest.md index c6e10587..a36f1fb3 100644 --- a/packages/mistralai-azure/docs/models/components/ocrrequest.md +++ b/packages/mistralai-azure/docs/models/components/ocrrequest.md @@ -6,10 +6,9 @@ import { OCRRequest } from "@mistralai/mistralai-azure/models/components"; let value: OCRRequest = { - model: "Malibu", + model: "Aventador", document: { - documentUrl: "https://unlucky-fund.info/", - type: "document_url", + fileId: "ea6400b9-bfdc-4769-82dc-df5d318855aa", }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/ocrresponse.md b/packages/mistralai-azure/docs/models/components/ocrresponse.md index 7ffb7d17..87ab615f 100644 --- a/packages/mistralai-azure/docs/models/components/ocrresponse.md +++ b/packages/mistralai-azure/docs/models/components/ocrresponse.md @@ -6,29 +6,10 @@ import { OCRResponse } from "@mistralai/mistralai-azure/models/components"; let value: OCRResponse = { - pages: [ - { - index: 468651, - markdown: "", - images: [ - { - id: "", - topLeftX: 976762, - topLeftY: 604846, - bottomRightX: 739264, - bottomRightY: 39187, - }, - ], - dimensions: { - dpi: 282807, - height: 120196, - width: 296140, - }, - }, - ], - model: "Alpine", + pages: [], + model: "Mustang", usageInfo: { - pagesProcessed: 317983, + pagesProcessed: 819030, }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/ocrusageinfo.md b/packages/mistralai-azure/docs/models/components/ocrusageinfo.md index 0584b95f..d70ea045 100644 --- a/packages/mistralai-azure/docs/models/components/ocrusageinfo.md +++ b/packages/mistralai-azure/docs/models/components/ocrusageinfo.md @@ -6,7 +6,7 @@ import { OCRUsageInfo } from "@mistralai/mistralai-azure/models/components"; let value: OCRUsageInfo = { - pagesProcessed: 414263, + pagesProcessed: 329301, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/referencechunk.md b/packages/mistralai-azure/docs/models/components/referencechunk.md index f31ab3a8..47cbfcb8 100644 --- a/packages/mistralai-azure/docs/models/components/referencechunk.md +++ b/packages/mistralai-azure/docs/models/components/referencechunk.md @@ -6,9 +6,7 @@ import { ReferenceChunk } from "@mistralai/mistralai-azure/models/components"; let value: ReferenceChunk = { - referenceIds: [ - 774234, - ], + referenceIds: [], }; ``` diff --git a/packages/mistralai-azure/docs/models/components/responseformats.md b/packages/mistralai-azure/docs/models/components/responseformats.md index 1e0618dc..c74c419f 100644 --- a/packages/mistralai-azure/docs/models/components/responseformats.md +++ b/packages/mistralai-azure/docs/models/components/responseformats.md @@ -7,7 +7,7 @@ An object specifying the format that the model must output. Setting to `{ "type" ```typescript import { ResponseFormats } from "@mistralai/mistralai-azure/models/components"; -let value: ResponseFormats = "text"; +let value: ResponseFormats = "json_object"; ``` ## Values diff --git a/packages/mistralai-azure/docs/models/components/stop.md b/packages/mistralai-azure/docs/models/components/stop.md index f26b1bf3..bc9d30e0 100644 --- a/packages/mistralai-azure/docs/models/components/stop.md +++ b/packages/mistralai-azure/docs/models/components/stop.md @@ -15,7 +15,8 @@ const value: string = ""; ```typescript const value: string[] = [ - "", + "", + "", ]; ``` diff --git a/packages/mistralai-azure/docs/models/components/systemmessage.md b/packages/mistralai-azure/docs/models/components/systemmessage.md index 8a819fe2..a8f28d7c 100644 --- a/packages/mistralai-azure/docs/models/components/systemmessage.md +++ b/packages/mistralai-azure/docs/models/components/systemmessage.md @@ -6,12 +6,7 @@ import { SystemMessage } from "@mistralai/mistralai-azure/models/components"; let value: SystemMessage = { - content: [ - { - text: "", - type: "text", - }, - ], + content: "", }; ``` diff --git a/packages/mistralai-azure/docs/models/components/systemmessagecontent.md b/packages/mistralai-azure/docs/models/components/systemmessagecontent.md index cda9bedd..7bfdb5b7 100644 --- a/packages/mistralai-azure/docs/models/components/systemmessagecontent.md +++ b/packages/mistralai-azure/docs/models/components/systemmessagecontent.md @@ -9,12 +9,13 @@ const value: string = ""; ``` -### `components.TextChunk[]` +### `components.SystemMessageContentChunks[]` ```typescript -const value: components.TextChunk[] = [ +const value: components.SystemMessageContentChunks[] = [ { - text: "", + thinking: [], + type: "thinking", }, ]; ``` diff --git a/packages/mistralai-azure/docs/models/components/systemmessagecontentchunks.md b/packages/mistralai-azure/docs/models/components/systemmessagecontentchunks.md new file mode 100644 index 00000000..a6f0642f --- /dev/null +++ b/packages/mistralai-azure/docs/models/components/systemmessagecontentchunks.md @@ -0,0 +1,21 @@ +# SystemMessageContentChunks + + +## Supported Types + +### `components.TextChunk` + +```typescript +const value: components.TextChunk = { + text: "", +}; +``` + +### `components.ThinkChunk` + +```typescript +const value: components.ThinkChunk = { + thinking: [], +}; +``` + diff --git a/packages/mistralai-azure/docs/models/components/thinkchunk.md b/packages/mistralai-azure/docs/models/components/thinkchunk.md new file mode 100644 index 00000000..dd528e1f --- /dev/null +++ b/packages/mistralai-azure/docs/models/components/thinkchunk.md @@ -0,0 +1,19 @@ +# ThinkChunk + +## Example Usage + +```typescript +import { ThinkChunk } from "@mistralai/mistralai-azure/models/components"; + +let value: ThinkChunk = { + thinking: [], +}; +``` + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | +| `thinking` | *components.Thinking*[] | :heavy_check_mark: | N/A | +| `closed` | *boolean* | :heavy_minus_sign: | Whether the thinking chunk is closed or not. Currently only used for prefixing. | +| `type` | [components.ThinkChunkType](../../models/components/thinkchunktype.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/packages/mistralai-azure/docs/models/components/thinkchunktype.md b/packages/mistralai-azure/docs/models/components/thinkchunktype.md new file mode 100644 index 00000000..6ed7597c --- /dev/null +++ b/packages/mistralai-azure/docs/models/components/thinkchunktype.md @@ -0,0 +1,15 @@ +# ThinkChunkType + +## Example Usage + +```typescript +import { ThinkChunkType } from "@mistralai/mistralai-azure/models/components"; + +let value: ThinkChunkType = "thinking"; +``` + +## Values + +```typescript +"thinking" +``` \ No newline at end of file diff --git a/packages/mistralai-azure/docs/models/components/thinking.md b/packages/mistralai-azure/docs/models/components/thinking.md new file mode 100644 index 00000000..0e23944c --- /dev/null +++ b/packages/mistralai-azure/docs/models/components/thinking.md @@ -0,0 +1,21 @@ +# Thinking + + +## Supported Types + +### `components.ReferenceChunk` + +```typescript +const value: components.ReferenceChunk = { + referenceIds: [], +}; +``` + +### `components.TextChunk` + +```typescript +const value: components.TextChunk = { + text: "", +}; +``` + diff --git a/packages/mistralai-azure/docs/models/components/tool.md b/packages/mistralai-azure/docs/models/components/tool.md index 17d4268c..54520ed4 100644 --- a/packages/mistralai-azure/docs/models/components/tool.md +++ b/packages/mistralai-azure/docs/models/components/tool.md @@ -8,9 +8,7 @@ import { Tool } from "@mistralai/mistralai-azure/models/components"; let value: Tool = { function: { name: "", - parameters: { - "key": "", - }, + parameters: {}, }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/toolcall.md b/packages/mistralai-azure/docs/models/components/toolcall.md index 0565e63f..68ba744f 100644 --- a/packages/mistralai-azure/docs/models/components/toolcall.md +++ b/packages/mistralai-azure/docs/models/components/toolcall.md @@ -8,7 +8,7 @@ import { ToolCall } from "@mistralai/mistralai-azure/models/components"; let value: ToolCall = { function: { name: "", - arguments: "", + arguments: {}, }, }; ``` diff --git a/packages/mistralai-azure/docs/models/components/toolchoiceenum.md b/packages/mistralai-azure/docs/models/components/toolchoiceenum.md index 66cfb8c4..a9f24a44 100644 --- a/packages/mistralai-azure/docs/models/components/toolchoiceenum.md +++ b/packages/mistralai-azure/docs/models/components/toolchoiceenum.md @@ -5,7 +5,7 @@ ```typescript import { ToolChoiceEnum } from "@mistralai/mistralai-azure/models/components"; -let value: ToolChoiceEnum = "any"; +let value: ToolChoiceEnum = "required"; ``` ## Values diff --git a/packages/mistralai-azure/docs/models/components/toolmessage.md b/packages/mistralai-azure/docs/models/components/toolmessage.md index a724c141..86ca13a2 100644 --- a/packages/mistralai-azure/docs/models/components/toolmessage.md +++ b/packages/mistralai-azure/docs/models/components/toolmessage.md @@ -6,7 +6,7 @@ import { ToolMessage } from "@mistralai/mistralai-azure/models/components"; let value: ToolMessage = { - content: "", + content: [], }; ``` diff --git a/packages/mistralai-azure/docs/models/components/toolmessagecontent.md b/packages/mistralai-azure/docs/models/components/toolmessagecontent.md index 1b59bf96..3acfc705 100644 --- a/packages/mistralai-azure/docs/models/components/toolmessagecontent.md +++ b/packages/mistralai-azure/docs/models/components/toolmessagecontent.md @@ -12,13 +12,6 @@ const value: string = ""; ### `components.ContentChunk[]` ```typescript -const value: components.ContentChunk[] = [ - { - imageUrl: { - url: "https://fair-insolence.biz", - }, - type: "image_url", - }, -]; +const value: components.ContentChunk[] = []; ``` diff --git a/packages/mistralai-azure/docs/models/components/usermessagecontent.md b/packages/mistralai-azure/docs/models/components/usermessagecontent.md index a8be0fda..22c7d880 100644 --- a/packages/mistralai-azure/docs/models/components/usermessagecontent.md +++ b/packages/mistralai-azure/docs/models/components/usermessagecontent.md @@ -12,13 +12,6 @@ const value: string = ""; ### `components.ContentChunk[]` ```typescript -const value: components.ContentChunk[] = [ - { - referenceIds: [ - 210382, - ], - type: "reference", - }, -]; +const value: components.ContentChunk[] = []; ``` diff --git a/packages/mistralai-azure/docs/models/components/validationerror.md b/packages/mistralai-azure/docs/models/components/validationerror.md index 0c8438ff..e2a893a8 100644 --- a/packages/mistralai-azure/docs/models/components/validationerror.md +++ b/packages/mistralai-azure/docs/models/components/validationerror.md @@ -7,7 +7,7 @@ import { ValidationError } from "@mistralai/mistralai-azure/models/components"; let value: ValidationError = { loc: [ - 18789, + 929957, ], msg: "", type: "", diff --git a/packages/mistralai-azure/eslint.config.mjs b/packages/mistralai-azure/eslint.config.mjs index 3483f71b..67bccfec 100644 --- a/packages/mistralai-azure/eslint.config.mjs +++ b/packages/mistralai-azure/eslint.config.mjs @@ -11,6 +11,7 @@ export default [ { rules: { "no-constant-condition": "off", + "no-useless-escape": "off", // Handled by typescript compiler "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/packages/mistralai-azure/examples/.env.template b/packages/mistralai-azure/examples/.env.template new file mode 100644 index 00000000..90641f14 --- /dev/null +++ b/packages/mistralai-azure/examples/.env.template @@ -0,0 +1,14 @@ +# @mistralai/mistralai-azure SDK Environment Variables +# Copy this file to .env and fill in your actual values +# DO NOT commit the .env file to version control + +# Security Configuration +# The SDK supports loading security credentials from environment variables +# with the prefix: MISTRAL_ +# +# Security environment variables: +MISTRAL_API_KEY=your_api_key_here + +# Debug Configuration +# Enable HTTP request/response logging for debugging +MISTRAL_DEBUG=false diff --git a/packages/mistralai-azure/examples/chatComplete.example.ts b/packages/mistralai-azure/examples/chatComplete.example.ts new file mode 100644 index 00000000..97526b5f --- /dev/null +++ b/packages/mistralai-azure/examples/chatComplete.example.ts @@ -0,0 +1,34 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import dotenv from "dotenv"; +dotenv.config(); +/** + * Example usage of the @mistralai/mistralai-azure SDK + * + * To run this example from the examples directory: + * npm run build && npx tsx chatComplete.example.ts + */ + +import { MistralAzure } from "@mistralai/mistralai-azure"; + +const mistralAzure = new MistralAzure({ + apiKey: process.env["MISTRAL_API_KEY"] ?? "", +}); + +async function main() { + const result = await mistralAzure.complete({ + messages: [ + { + content: + "Who is the best French painter? Answer in one short sentence.", + role: "user", + }, + ], + }); + + console.log(result); +} + +main().catch(console.error); diff --git a/packages/mistralai-azure/examples/package-lock.json b/packages/mistralai-azure/examples/package-lock.json new file mode 100644 index 00000000..bb532133 --- /dev/null +++ b/packages/mistralai-azure/examples/package-lock.json @@ -0,0 +1,610 @@ +{ + "name": "@mistralai/mistralai-azure-examples", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@mistralai/mistralai-azure-examples", + "version": "1.0.0", + "dependencies": { + "@mistralai/mistralai-azure": "file:.." + }, + "devDependencies": { + "@types/node": "^20.0.0", + "dotenv": "^16.4.5", + "tsx": "^4.19.2" + } + }, + "..": { + "name": "@mistralai/mistralai-azure", + "version": "1.7.0", + "dependencies": { + "zod": "^3.20.0" + }, + "devDependencies": { + "@eslint/js": "^9.19.0", + "eslint": "^9.19.0", + "globals": "^15.14.0", + "typescript": "~5.8.3", + "typescript-eslint": "^8.26.0" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.9.tgz", + "integrity": "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.9.tgz", + "integrity": "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.9.tgz", + "integrity": "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.9.tgz", + "integrity": "sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.9.tgz", + "integrity": "sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.9.tgz", + "integrity": "sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.9.tgz", + "integrity": "sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.9.tgz", + "integrity": "sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.9.tgz", + "integrity": "sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.9.tgz", + "integrity": "sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.9.tgz", + "integrity": "sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.9.tgz", + "integrity": "sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.9.tgz", + "integrity": "sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.9.tgz", + "integrity": "sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.9.tgz", + "integrity": "sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.9.tgz", + "integrity": "sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.9.tgz", + "integrity": "sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.9.tgz", + "integrity": "sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.9.tgz", + "integrity": "sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.9.tgz", + "integrity": "sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.9.tgz", + "integrity": "sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.9.tgz", + "integrity": "sha512-4Xd0xNiMVXKh6Fa7HEJQbrpP3m3DDn43jKxMjxLLRjWnRsfxjORYJlXPO4JNcXtOyfajXorRKY9NkOpTHptErg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.9.tgz", + "integrity": "sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.9.tgz", + "integrity": "sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.9.tgz", + "integrity": "sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.9.tgz", + "integrity": "sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@mistralai/mistralai-azure": { + "resolved": "..", + "link": true + }, + "node_modules/@types/node": { + "version": "20.19.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.11.tgz", + "integrity": "sha512-uug3FEEGv0r+jrecvUUpbY8lLisvIjg6AAic6a2bSP5OEOLeJsDSnvhCDov7ipFFMXS3orMpzlmi0ZcuGkBbow==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/dotenv": { + "version": "16.6.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", + "integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/esbuild": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz", + "integrity": "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.9", + "@esbuild/android-arm": "0.25.9", + "@esbuild/android-arm64": "0.25.9", + "@esbuild/android-x64": "0.25.9", + "@esbuild/darwin-arm64": "0.25.9", + "@esbuild/darwin-x64": "0.25.9", + "@esbuild/freebsd-arm64": "0.25.9", + "@esbuild/freebsd-x64": "0.25.9", + "@esbuild/linux-arm": "0.25.9", + "@esbuild/linux-arm64": "0.25.9", + "@esbuild/linux-ia32": "0.25.9", + "@esbuild/linux-loong64": "0.25.9", + "@esbuild/linux-mips64el": "0.25.9", + "@esbuild/linux-ppc64": "0.25.9", + "@esbuild/linux-riscv64": "0.25.9", + "@esbuild/linux-s390x": "0.25.9", + "@esbuild/linux-x64": "0.25.9", + "@esbuild/netbsd-arm64": "0.25.9", + "@esbuild/netbsd-x64": "0.25.9", + "@esbuild/openbsd-arm64": "0.25.9", + "@esbuild/openbsd-x64": "0.25.9", + "@esbuild/openharmony-arm64": "0.25.9", + "@esbuild/sunos-x64": "0.25.9", + "@esbuild/win32-arm64": "0.25.9", + "@esbuild/win32-ia32": "0.25.9", + "@esbuild/win32-x64": "0.25.9" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-tsconfig": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.1.tgz", + "integrity": "sha512-auHyJ4AgMz7vgS8Hp3N6HXSmlMdUyhSUrfBF16w153rxtLIEOE+HGqaBppczZvnHLqQJfiHotCYpNhl0lUROFQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/tsx": { + "version": "4.20.5", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.20.5.tgz", + "integrity": "sha512-+wKjMNU9w/EaQayHXb7WA7ZaHY6hN8WgfvHNQ3t1PnU91/7O8TcTnIhCDYTZwnt8JsO9IBqZ30Ln1r7pPF52Aw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.25.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/packages/mistralai-azure/examples/package.json b/packages/mistralai-azure/examples/package.json new file mode 100644 index 00000000..4f051032 --- /dev/null +++ b/packages/mistralai-azure/examples/package.json @@ -0,0 +1,18 @@ +{ + "name": "@mistralai/mistralai-azure-examples", + "version": "1.0.0", + "private": true, + "scripts": { + "build:parent": "cd .. && npm i && npm run build && cd -", + "build:examples": "npm i", + "build": "npm run build:parent && npm run build:examples" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "dotenv": "^16.4.5", + "tsx": "^4.19.2" + }, + "dependencies": { + "@mistralai/mistralai-azure": "file:.." + } +} \ No newline at end of file diff --git a/packages/mistralai-azure/jsr.json b/packages/mistralai-azure/jsr.json index b52b20ad..186dd0cd 100644 --- a/packages/mistralai-azure/jsr.json +++ b/packages/mistralai-azure/jsr.json @@ -2,7 +2,7 @@ { "name": "@mistralai/mistralai-azure", - "version": "1.6.0", + "version": "1.7.0", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/packages/mistralai-azure/package-lock.json b/packages/mistralai-azure/package-lock.json index 32f74a29..bd9e50f2 100644 --- a/packages/mistralai-azure/package-lock.json +++ b/packages/mistralai-azure/package-lock.json @@ -1,22 +1,21 @@ { "name": "@mistralai/mistralai-azure", - "version": "1.6.0", + "version": "1.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mistralai/mistralai-azure", - "version": "1.6.0", + "version": "1.7.0", + "dependencies": { + "zod": "^3.20.0" + }, "devDependencies": { "@eslint/js": "^9.19.0", "eslint": "^9.19.0", "globals": "^15.14.0", - "typescript": "^5.4.5", - "typescript-eslint": "^8.22.0", - "zod": "^3.23.4" - }, - "peerDependencies": { - "zod": ">= 3" + "typescript": "~5.8.3", + "typescript-eslint": "^8.26.0" } }, "node_modules/@eslint-community/eslint-utils": { @@ -1612,9 +1611,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", "dev": true, "license": "Apache-2.0", "bin": { @@ -1859,7 +1858,6 @@ "version": "3.23.8", "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/colinhacks" diff --git a/packages/mistralai-azure/package.json b/packages/mistralai-azure/package.json index 85a249d3..79894b80 100644 --- a/packages/mistralai-azure/package.json +++ b/packages/mistralai-azure/package.json @@ -1,6 +1,6 @@ { "name": "@mistralai/mistralai-azure", - "version": "1.6.0", + "version": "1.7.0", "author": "Speakeasy", "main": "./index.js", "sideEffects": false, @@ -15,17 +15,16 @@ "prepublishOnly": "npm run build" }, "peerDependencies": { - "zod": ">= 3" + }, "devDependencies": { "@eslint/js": "^9.19.0", "eslint": "^9.19.0", "globals": "^15.14.0", - "typescript": "^5.4.5", - "typescript-eslint": "^8.22.0", - "zod": "^3.23.4" + "typescript": "~5.8.3", + "typescript-eslint": "^8.26.0" }, "dependencies": { - + "zod": "^3.20.0" } } diff --git a/packages/mistralai-azure/src/funcs/chatComplete.ts b/packages/mistralai-azure/src/funcs/chatComplete.ts index b73752ec..e09546b1 100644 --- a/packages/mistralai-azure/src/funcs/chatComplete.ts +++ b/packages/mistralai-azure/src/funcs/chatComplete.ts @@ -19,7 +19,8 @@ import { UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import * as errors from "../models/errors/index.js"; -import { SDKError } from "../models/errors/sdkerror.js"; +import { MistralAzureError } from "../models/errors/mistralazureerror.js"; +import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; @@ -35,13 +36,14 @@ export function chatComplete( Result< components.ChatCompletionResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError > > { return new APIPromise($do( @@ -60,13 +62,14 @@ async function $do( Result< components.ChatCompletionResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >, APICall, ] @@ -94,6 +97,7 @@ async function $do( const requestSecurity = resolveGlobalSecurity(securityInput); const context = { + options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "chat_completion_v1_chat_completions_post", oAuth2Scopes: [], @@ -114,6 +118,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) { @@ -139,19 +144,20 @@ async function $do( const [result] = await M.match< components.ChatCompletionResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >( M.json(200, components.ChatCompletionResponse$inboundSchema), M.jsonErr(422, errors.HTTPValidationError$inboundSchema), M.fail("4XX"), M.fail("5XX"), - )(response, { extraFields: responseFields }); + )(response, req, { extraFields: responseFields }); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } diff --git a/packages/mistralai-azure/src/funcs/chatStream.ts b/packages/mistralai-azure/src/funcs/chatStream.ts index e5987793..f0922180 100644 --- a/packages/mistralai-azure/src/funcs/chatStream.ts +++ b/packages/mistralai-azure/src/funcs/chatStream.ts @@ -21,7 +21,8 @@ import { UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import * as errors from "../models/errors/index.js"; -import { SDKError } from "../models/errors/sdkerror.js"; +import { MistralAzureError } from "../models/errors/mistralazureerror.js"; +import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; @@ -40,13 +41,14 @@ export function chatStream( Result< EventStream, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError > > { return new APIPromise($do( @@ -65,13 +67,14 @@ async function $do( Result< EventStream, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >, APICall, ] @@ -100,6 +103,7 @@ async function $do( const requestSecurity = resolveGlobalSecurity(securityInput); const context = { + options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "stream_chat", oAuth2Scopes: [], @@ -120,6 +124,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) { @@ -145,31 +150,30 @@ async function $do( const [result] = await M.match< EventStream, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >( M.sse( 200, z.instanceof(ReadableStream).transform(stream => { - return new EventStream({ - stream, - decoder(rawEvent) { - const schema = components.CompletionEvent$inboundSchema; - return schema.parse(rawEvent); - }, + return new EventStream(stream, rawEvent => { + if (rawEvent.data === "[DONE]") return { done: true }; + return { + value: components.CompletionEvent$inboundSchema.parse(rawEvent), + }; }); }), - { sseSentinel: "[DONE]" }, ), M.jsonErr(422, errors.HTTPValidationError$inboundSchema), M.fail("4XX"), M.fail("5XX"), - )(response, { extraFields: responseFields }); + )(response, req, { extraFields: responseFields }); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } diff --git a/packages/mistralai-azure/src/funcs/ocrProcess.ts b/packages/mistralai-azure/src/funcs/ocrProcess.ts index c6a96a6f..7adf9305 100644 --- a/packages/mistralai-azure/src/funcs/ocrProcess.ts +++ b/packages/mistralai-azure/src/funcs/ocrProcess.ts @@ -19,7 +19,8 @@ import { UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import * as errors from "../models/errors/index.js"; -import { SDKError } from "../models/errors/sdkerror.js"; +import { MistralAzureError } from "../models/errors/mistralazureerror.js"; +import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; @@ -35,13 +36,14 @@ export function ocrProcess( Result< components.OCRResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError > > { return new APIPromise($do( @@ -60,13 +62,14 @@ async function $do( Result< components.OCRResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >, APICall, ] @@ -94,6 +97,7 @@ async function $do( const requestSecurity = resolveGlobalSecurity(securityInput); const context = { + options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "ocr_v1_ocr_post", oAuth2Scopes: [], @@ -114,6 +118,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) { @@ -139,19 +144,20 @@ async function $do( const [result] = await M.match< components.OCRResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralAzureError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >( M.json(200, components.OCRResponse$inboundSchema), M.jsonErr(422, errors.HTTPValidationError$inboundSchema), M.fail("4XX"), M.fail("5XX"), - )(response, { extraFields: responseFields }); + )(response, req, { extraFields: responseFields }); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } diff --git a/packages/mistralai-azure/src/hooks/types.ts b/packages/mistralai-azure/src/hooks/types.ts index f34898c0..8bfe4fe8 100644 --- a/packages/mistralai-azure/src/hooks/types.ts +++ b/packages/mistralai-azure/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"; @@ -9,10 +10,11 @@ import { SecurityState } from "../lib/security.js"; export type HookContext = { baseURL: string | URL; operationID: string; - oAuth2Scopes?: string[]; + oAuth2Scopes: string[] | null; securitySource?: any | (() => Promise); retryConfig: RetryConfig; resolvedSecurity: SecurityState | null; + options: SDKOptions; }; export type Awaitable = T | Promise; diff --git a/packages/mistralai-azure/src/index.ts b/packages/mistralai-azure/src/index.ts index 5ddc765e..dbcba164 100644 --- a/packages/mistralai-azure/src/index.ts +++ b/packages/mistralai-azure/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/packages/mistralai-azure/src/lib/config.ts b/packages/mistralai-azure/src/lib/config.ts index a2f43d9f..2ec69f2d 100644 --- a/packages/mistralai-azure/src/lib/config.ts +++ b/packages/mistralai-azure/src/lib/config.ts @@ -30,6 +30,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 */ @@ -55,8 +59,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "1.0.0", - sdkVersion: "1.6.0", - genVersion: "2.548.6", + sdkVersion: "1.7.0", + genVersion: "2.687.13", userAgent: - "speakeasy-sdk/typescript 1.6.0 2.548.6 1.0.0 @mistralai/mistralai-azure", + "speakeasy-sdk/typescript 1.7.0 2.687.13 1.0.0 @mistralai/mistralai-azure", } as const; diff --git a/packages/mistralai-azure/src/lib/event-streams.ts b/packages/mistralai-azure/src/lib/event-streams.ts index 2ab114f2..d14c6e7d 100644 --- a/packages/mistralai-azure/src/lib/event-streams.ts +++ b/packages/mistralai-azure/src/lib/event-streams.ts @@ -5,260 +5,133 @@ export type ServerEvent = { data?: T | undefined; event?: string | undefined; - retry?: number | undefined; id?: string | undefined; + retry?: number | undefined; }; -const LF = 0x0a; -const CR = 0x0d; -const NEWLINE_CHARS = new Set([LF, CR]); -const MESSAGE_BOUNDARIES = [ - new Uint8Array([CR, LF, CR, LF]), - new Uint8Array([CR, CR]), - new Uint8Array([LF, LF]), -]; - -export class EventStream> { - private readonly stream: ReadableStream; - private readonly decoder: (rawEvent: ServerEvent) => Event; - - constructor(init: { - stream: ReadableStream; - decoder: (rawEvent: ServerEvent) => Event; - }) { - this.stream = init.stream; - this.decoder = init.decoder; - } - - async *[Symbol.asyncIterator](): AsyncGenerator { - const reader = this.stream.getReader(); - let buffer = new Uint8Array([]); - let position = 0; - - try { - while (true) { - const { done, value } = await reader.read(); - if (done) { - break; - } - const newBuffer = new Uint8Array(buffer.length + value.length); - newBuffer.set(buffer); - newBuffer.set(value, buffer.length); - buffer = newBuffer; - - for (let i = position; i < buffer.length; i++) { - const boundary = findBoundary(buffer, i); - if (boundary == null) { - continue; - } - - const chunk = buffer.slice(position, i); - position = i + boundary.length; - const event = parseEvent(chunk, this.decoder); - if (event != null) { - yield event; +export class EventStream> + extends ReadableStream +{ + constructor( + responseBody: ReadableStream, + parse: (x: ServerEvent) => IteratorResult, + ) { + const upstream = responseBody.getReader(); + let buffer: Uint8Array = new Uint8Array(); + super({ + async pull(downstream) { + try { + while (true) { + const match = findBoundary(buffer); + if (!match) { + const chunk = await upstream.read(); + if (chunk.done) return downstream.close(); + buffer = concatBuffer(buffer, chunk.value); + continue; + } + const message = buffer.slice(0, match.index); + buffer = buffer.slice(match.index + match.length); + const item = parseMessage(message, parse); + if (item?.value) return downstream.enqueue(item.value); + if (item?.done) { + await upstream.cancel("done"); + return downstream.close(); + } } + } catch (e) { + downstream.error(e); + await upstream.cancel(e); } + }, + cancel: reason => upstream.cancel(reason), + }); + } - if (position > 0) { - buffer = buffer.slice(position); - position = 0; - } - } - - if (buffer.length > 0) { - const event = parseEvent(buffer, this.decoder); - if (event != null) { - yield event; + // Polyfill for older browsers + [Symbol.asyncIterator](): AsyncIterableIterator { + const fn = (ReadableStream.prototype as any)[Symbol.asyncIterator]; + if (typeof fn === "function") return fn.call(this); + const reader = this.getReader(); + return { + next: async () => { + const r = await reader.read(); + if (r.done) { + reader.releaseLock(); + return { done: true, value: undefined }; } - } - } catch (e: unknown) { - if (e instanceof Error && e.name === "AbortError") { - return; - } - - throw e; - } finally { - reader.releaseLock(); - } + return { done: false, value: r.value }; + }, + throw: async (e) => { + await reader.cancel(e); + reader.releaseLock(); + return { done: true, value: undefined }; + }, + return: async () => { + await reader.cancel("done"); + reader.releaseLock(); + return { done: true, value: undefined }; + }, + [Symbol.asyncIterator]() { + return this; + }, + }; } } -function findBoundary(buffer: Uint8Array, start: number): Uint8Array | null { - const char1 = buffer[start]; - const char2 = buffer[start + 1]; - - // Don't bother checking if the first two characters are not new line - // characters. - if ( - char1 == null - || char2 == null - || !NEWLINE_CHARS.has(char1) - || !NEWLINE_CHARS.has(char2) - ) { - return null; - } - - for (const s of MESSAGE_BOUNDARIES) { - const seq = peekSequence(start, buffer, s); - if (seq != null) { - return seq; - } - } - - return null; +function concatBuffer(a: Uint8Array, b: Uint8Array): Uint8Array { + const c = new Uint8Array(a.length + b.length); + c.set(a, 0); + c.set(b, a.length); + return c; } -function peekSequence( - position: number, - buffer: Uint8Array, - sequence: Uint8Array, -): Uint8Array | null { - if (sequence.length > buffer.length - position) { - return null; - } - - for (let i = 0; i < sequence.length; i++) { - if (buffer[position + i] !== sequence[i]) { - return null; +/** Finds the first (CR,LF,CR,LF) or (CR,CR) or (LF,LF) */ +function findBoundary( + buf: Uint8Array, +): { index: number; length: number } | null { + const len = buf.length; + for (let i = 0; i < len; i++) { + if ( + i <= len - 4 + && buf[i] === 13 && buf[i + 1] === 10 && buf[i + 2] === 13 + && buf[i + 3] === 10 + ) { + return { index: i, length: 4 }; + } + if (i <= len - 2 && buf[i] === 13 && buf[i + 1] === 13) { + return { index: i, length: 2 }; + } + if (i <= len - 2 && buf[i] === 10 && buf[i + 1] === 10) { + return { index: i, length: 2 }; } } - - return sequence; + return null; } -function parseEvent>( +function parseMessage>( chunk: Uint8Array, - decoder: (rawEvent: ServerEvent) => Event, + parse: (x: ServerEvent) => IteratorResult, ) { - if (!chunk.length) { - return null; - } - - const td = new TextDecoder(); - const raw = td.decode(chunk); - const lines = raw.split(/\r?\n|\r/g); - let publish = false; - const rawEvent: ServerEvent = {}; - + const text = new TextDecoder().decode(chunk); + const lines = text.split(/\r\n|\r|\n/); + const dataLines: string[] = []; + const ret: ServerEvent = {}; + let ignore = true; for (const line of lines) { - if (!line) { - continue; - } - - const delim = line.indexOf(":"); - // Lines starting with a colon are ignored. - if (delim === 0) { - continue; - } - - const field = delim > 0 ? line.substring(0, delim) : ""; - let value = delim > 0 ? line.substring(delim + 1) : ""; - if (value.charAt(0) === " ") { - value = value.substring(1); - } - - switch (field) { - case "event": { - publish = true; - rawEvent.event = value; - break; - } - case "data": { - publish = true; - rawEvent.data ??= ""; - rawEvent.data += value + "\n"; - break; - } - case "id": { - publish = true; - rawEvent.id = value; - break; - } - case "retry": { - const r = parseInt(value, 10); - if (!Number.isNaN(r)) { - publish = true; - rawEvent.retry = r; - } - break; - } + if (!line || line.startsWith(":")) continue; + ignore = false; + const i = line.indexOf(":"); + const field = line.slice(0, i); + const value = line[i + 1] === " " ? line.slice(i + 2) : line.slice(i + 1); + if (field === "data") dataLines.push(value); + else if (field === "event") ret.event = value; + else if (field === "id") ret.id = value; + else if (field === "retry") { + const n = Number(value); + if (!isNaN(n)) ret.retry = n; } } - - if (!publish) { - return null; - } - - if (rawEvent.data != null) { - rawEvent.data = rawEvent.data.slice(0, -1); - } - - return decoder(rawEvent); -} - -export function discardSentinel( - stream: ReadableStream, - sentinel: string, -): ReadableStream { - return new ReadableStream({ - async start(controller) { - let buffer = new Uint8Array([]); - let position = 0; - let done = false; - let discard = false; - const rdr = stream.getReader(); - try { - while (!done) { - const result = await rdr.read(); - const value = result.value; - done = done || result.done; - // We keep consuming from the source to its completion so it can - // flush all its contents and release resources. - if (discard) { - continue; - } - if (typeof value === "undefined") { - continue; - } - - const newBuffer = new Uint8Array(buffer.length + value.length); - newBuffer.set(buffer); - newBuffer.set(value, buffer.length); - buffer = newBuffer; - - for (let i = position; i < buffer.length; i++) { - const boundary = findBoundary(buffer, i); - if (boundary == null) { - continue; - } - - const start = position; - const chunk = buffer.slice(start, i); - position = i + boundary.length; - const event = parseEvent(chunk, id); - if (event?.data === sentinel) { - controller.enqueue(buffer.slice(0, start)); - discard = true; - } else { - controller.enqueue(buffer.slice(0, position)); - buffer = buffer.slice(position); - position = 0; - } - } - } - } catch (e) { - controller.error(e); - } finally { - // If the source stream terminates, flush its contents and terminate. - // If the sentinel event was found, flush everything up to its start. - controller.close(); - rdr.releaseLock(); - } - }, - }); -} - -function id(v: T): T { - return v; + if (ignore) return; + if (dataLines.length) ret.data = dataLines.join("\n"); + return parse(ret); } diff --git a/packages/mistralai-azure/src/lib/files.ts b/packages/mistralai-azure/src/lib/files.ts index 59d15f09..0344cd04 100644 --- a/packages/mistralai-azure/src/lib/files.ts +++ b/packages/mistralai-azure/src/lib/files.ts @@ -38,3 +38,45 @@ export async function readableStreamToArrayBuffer( return concatenatedChunks.buffer as ArrayBuffer; } + +/** + * Determines the MIME content type based on a file's extension. + * Returns null if the extension is not recognized. + */ +export function getContentTypeFromFileName(fileName: string): string | null { + if (!fileName) return null; + + const ext = fileName.toLowerCase().split(".").pop(); + if (!ext) return null; + + const mimeTypes: Record = { + json: "application/json", + xml: "application/xml", + html: "text/html", + htm: "text/html", + txt: "text/plain", + csv: "text/csv", + pdf: "application/pdf", + png: "image/png", + jpg: "image/jpeg", + jpeg: "image/jpeg", + gif: "image/gif", + svg: "image/svg+xml", + js: "application/javascript", + css: "text/css", + zip: "application/zip", + tar: "application/x-tar", + gz: "application/gzip", + mp4: "video/mp4", + mp3: "audio/mpeg", + wav: "audio/wav", + webp: "image/webp", + ico: "image/x-icon", + woff: "font/woff", + woff2: "font/woff2", + ttf: "font/ttf", + otf: "font/otf", + }; + + return mimeTypes[ext] || null; +} diff --git a/packages/mistralai-azure/src/lib/matchers.ts b/packages/mistralai-azure/src/lib/matchers.ts index f8ec5c3c..5e2e60be 100644 --- a/packages/mistralai-azure/src/lib/matchers.ts +++ b/packages/mistralai-azure/src/lib/matchers.ts @@ -2,15 +2,14 @@ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ +import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKError } from "../models/errors/sdkerror.js"; -import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; -import { Result } from "../types/fp.js"; -import { discardSentinel } from "./event-streams.js"; +import { ERR, OK, Result } from "../types/fp.js"; import { matchResponse, matchStatusCode, StatusCodePredicate } from "./http.js"; import { isPlainObject } from "./is-plain-object.js"; -import { safeParse } from "./schemas.js"; export type Encoding = + | "jsonl" | "json" | "text" | "bytes" @@ -20,6 +19,7 @@ export type Encoding = | "fail"; const DEFAULT_CONTENT_TYPES: Record = { + jsonl: "application/jsonl", json: "application/json", text: "text/plain", bytes: "application/octet-stream", @@ -73,6 +73,21 @@ export function json( return { ...options, enc: "json", codes, schema }; } +export function jsonl( + codes: StatusCodePredicate, + schema: Schema, + options?: MatchOptions, +): ValueMatcher { + return { ...options, enc: "jsonl", codes, schema }; +} + +export function jsonlErr( + codes: StatusCodePredicate, + schema: Schema, + options?: MatchOptions, +): ErrorMatcher { + return { ...options, err: true, enc: "jsonl", codes, schema }; +} export function textErr( codes: StatusCodePredicate, schema: Schema, @@ -160,17 +175,19 @@ export type MatchedError = Matchers extends Matcher[] : never; export type MatchFunc = ( response: Response, + request: Request, options?: { resultKey?: string; extraFields?: Record }, ) => Promise<[result: Result, raw: unknown]>; export function match( ...matchers: Array> -): MatchFunc { +): MatchFunc { return async function matchFunc( response: Response, + request: Request, options?: { resultKey?: string; extraFields?: Record }, ): Promise< - [result: Result, raw: unknown] + [result: Result, raw: unknown] > { let raw: unknown; let matcher: Matcher | undefined; @@ -189,21 +206,25 @@ export function match( } if (!matcher) { - const responseBody = await response.text(); return [{ ok: false, - error: new SDKError( - "Unexpected API response status or content-type", + error: new SDKError("Unexpected Status or Content-Type", { response, - responseBody, - ), - }, responseBody]; + request, + body: await response.text().catch(() => ""), + }), + }, raw]; } const encoding = matcher.enc; + let body = ""; switch (encoding) { case "json": - raw = await response.json(); + body = await response.text(); + raw = JSON.parse(body); + break; + case "jsonl": + raw = response.body; break; case "bytes": raw = new Uint8Array(await response.arrayBuffer()); @@ -212,18 +233,19 @@ export function match( raw = response.body; break; case "text": - raw = await response.text(); + body = await response.text(); + raw = body; break; case "sse": - raw = response.body && matcher.sseSentinel - ? discardSentinel(response.body, matcher.sseSentinel) - : response.body; + raw = response.body; break; case "nil": - raw = await discardResponseBody(response); + body = await response.text(); + raw = undefined; break; case "fail": - raw = await response.text(); + body = await response.text(); + raw = body; break; default: encoding satisfies never; @@ -233,11 +255,7 @@ export function match( if (matcher.enc === "fail") { return [{ ok: false, - error: new SDKError( - "API error occurred", - response, - typeof raw === "string" ? raw : "", - ), + error: new SDKError("API error occurred", { request, response, body }), }, raw]; } @@ -249,6 +267,9 @@ export function match( ...options?.extraFields, ...(matcher.hdrs ? { Headers: unpackHeaders(response.headers) } : null), ...(isPlainObject(raw) ? raw : null), + request$: request, + response$: response, + body$: body, }; } else if (resultKey) { data = { @@ -267,18 +288,20 @@ export function match( } if ("err" in matcher) { - const result = safeParse( + const result = safeParseResponse( data, (v: unknown) => matcher.schema.parse(v), "Response validation failed", + { request, response, body }, ); return [result.ok ? { ok: false, error: result.value } : result, raw]; } else { return [ - safeParse( + safeParseResponse( data, (v: unknown) => matcher.schema.parse(v), "Response validation failed", + { request, response, body }, ), raw, ]; @@ -301,25 +324,22 @@ export function unpackHeaders(headers: Headers): Record { return out; } -/** - * Discards the response body to free up resources. - * - * To learn why this is need, see the undici docs: - * https://undici.nodejs.org/#/?id=garbage-collection - */ -export async function discardResponseBody(res: Response) { - const reader = res.body?.getReader(); - if (reader == null) { - return; - } - +function safeParseResponse( + rawValue: Inp, + fn: (value: Inp) => Out, + errorMessage: string, + httpMeta: { response: Response; request: Request; body: string }, +): Result { try { - let done = false; - while (!done) { - const res = await reader.read(); - done = res.done; - } - } finally { - reader.releaseLock(); + return OK(fn(rawValue)); + } catch (err) { + return ERR( + new ResponseValidationError(errorMessage, { + cause: err, + rawValue, + rawMessage: errorMessage, + ...httpMeta, + }), + ); } } diff --git a/packages/mistralai-azure/src/lib/sdks.ts b/packages/mistralai-azure/src/lib/sdks.ts index 19e6358e..a5c602ee 100644 --- a/packages/mistralai-azure/src/lib/sdks.ts +++ b/packages/mistralai-azure/src/lib/sdks.ts @@ -47,12 +47,14 @@ export type RequestOptions = { */ serverURL?: string | URL; /** + * @deprecated `fetchOptions` has been flattened into `RequestOptions`. + * * Sets various request options on the `fetch` call made by an SDK method. * * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options|Request} */ fetchOptions?: Omit; -}; +} & Omit; type RequestConfig = { method: string; @@ -63,6 +65,7 @@ type RequestConfig = { headers?: HeadersInit; security?: SecurityState | null; uaHeader?: string; + userAgent?: string | undefined; timeoutMs?: number; }; @@ -94,19 +97,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; if (!this.#logger && env().MISTRAL_DEBUG) { this.#logger = console; } @@ -172,7 +177,9 @@ export class ClientSDK { cookie = cookie.startsWith("; ") ? cookie.slice(2) : cookie; headers.set("cookie", cookie); - const userHeaders = new Headers(options?.fetchOptions?.headers); + const userHeaders = new Headers( + options?.headers ?? options?.fetchOptions?.headers, + ); for (const [k, v] of userHeaders) { headers.set(k, v); } @@ -180,23 +187,22 @@ 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, + ); } - let fetchOptions = options?.fetchOptions; + const fetchOptions: Omit = { + ...options?.fetchOptions, + ...options, + }; if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) { const timeoutSignal = AbortSignal.timeout(conf.timeoutMs); - if (!fetchOptions) { - fetchOptions = { signal: timeoutSignal }; - } else { - fetchOptions.signal = timeoutSignal; - } + fetchOptions.signal = timeoutSignal; } if (conf.body instanceof ReadableStream) { - if (!fetchOptions) { - fetchOptions = {}; - } Object.assign(fetchOptions, { duplex: "half" }); } @@ -302,7 +308,9 @@ export class ClientSDK { } } -const jsonLikeContentTypeRE = /^application\/(?:.{0,100}\+)?json/; +const jsonLikeContentTypeRE = /(application|text)\/.*?\+*json.*/; +const jsonlLikeContentTypeRE = + /(application|text)\/(.*?\+*\bjsonl\b.*|.*?\+*\bx-ndjson\b.*)/; async function logRequest(logger: Logger | undefined, req: Request) { if (!logger) { return; @@ -368,9 +376,13 @@ async function logResponse( logger.group("Body:"); switch (true) { case matchContentType(res, "application/json") - || jsonLikeContentTypeRE.test(ct): + || jsonLikeContentTypeRE.test(ct) && !jsonlLikeContentTypeRE.test(ct): logger.log(await res.clone().json()); break; + case matchContentType(res, "application/jsonl") + || jsonlLikeContentTypeRE.test(ct): + logger.log(await res.clone().text()); + break; case matchContentType(res, "text/event-stream"): logger.log(`<${contentType}>`); break; diff --git a/packages/mistralai-azure/src/lib/security.ts b/packages/mistralai-azure/src/lib/security.ts index 4bc0dd91..209f790b 100644 --- a/packages/mistralai-azure/src/lib/security.ts +++ b/packages/mistralai-azure/src/lib/security.ts @@ -4,10 +4,11 @@ import * as components from "../models/components/index.js"; import { env } from "./env.js"; + type OAuth2PasswordFlow = { username: string; - password?: string | undefined; - clientID: string; + password: string; + clientID?: string | undefined; clientSecret?: string | undefined; tokenURL: string; }; @@ -83,9 +84,14 @@ type SecurityInputOAuth2 = { type SecurityInputOAuth2ClientCredentials = { type: "oauth2:client_credentials"; value: - | { clientID?: string | undefined; clientSecret?: string | undefined } + | { + clientID?: string | undefined; + clientSecret?: string | undefined; + } | null + | string | undefined; + fieldName?: string; }; type SecurityInputOAuth2PasswordCredentials = { @@ -94,13 +100,13 @@ type SecurityInputOAuth2PasswordCredentials = { | string | null | undefined; - fieldName: string; + fieldName?: string; }; type SecurityInputCustom = { type: "http:custom"; value: any | null | undefined; - fieldName: string; + fieldName?: string; }; export type SecurityInput = @@ -137,6 +143,9 @@ export function resolveSecurity( typeof o.value === "string" && !!o.value ); } else if (o.type === "oauth2:client_credentials") { + if (typeof o.value == "string") { + return !!o.value; + } return o.value.clientID != null || o.value.clientSecret != null; } else if (typeof o.value === "string") { return !!o.value; @@ -225,7 +234,9 @@ function applyBearer( value = `Bearer ${value}`; } - state.headers[spec.fieldName] = value; + if (spec.fieldName !== undefined) { + state.headers[spec.fieldName] = value; + } } export function resolveGlobalSecurity( diff --git a/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts b/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts index 1a2ed66d..b4cffaff 100644 --- a/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts +++ b/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts @@ -73,9 +73,9 @@ export type ChatCompletionRequestStop = string | Array; export type ChatCompletionRequestMessages = | (SystemMessage & { role: "system" }) + | (ToolMessage & { role: "tool" }) | (UserMessage & { role: "user" }) - | (AssistantMessage & { role: "assistant" }) - | (ToolMessage & { role: "tool" }); + | (AssistantMessage & { role: "assistant" }); export type ChatCompletionRequestToolChoice = ToolChoice | ToolChoiceEnum; @@ -113,9 +113,9 @@ export type ChatCompletionRequest = { */ messages: Array< | (SystemMessage & { role: "system" }) + | (ToolMessage & { role: "tool" }) | (UserMessage & { role: "user" }) | (AssistantMessage & { role: "assistant" }) - | (ToolMessage & { role: "tool" }) >; responseFormat?: ResponseFormat | undefined; tools?: Array | null | undefined; @@ -203,6 +203,9 @@ export const ChatCompletionRequestMessages$inboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$inboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), + ), UserMessage$inboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role })), ), @@ -211,17 +214,14 @@ export const ChatCompletionRequestMessages$inboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$inboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), - ), ]); /** @internal */ export type ChatCompletionRequestMessages$Outbound = | (SystemMessage$Outbound & { role: "system" }) + | (ToolMessage$Outbound & { role: "tool" }) | (UserMessage$Outbound & { role: "user" }) - | (AssistantMessage$Outbound & { role: "assistant" }) - | (ToolMessage$Outbound & { role: "tool" }); + | (AssistantMessage$Outbound & { role: "assistant" }); /** @internal */ export const ChatCompletionRequestMessages$outboundSchema: z.ZodType< @@ -234,6 +234,9 @@ export const ChatCompletionRequestMessages$outboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$outboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), + ), UserMessage$outboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role })), ), @@ -242,9 +245,6 @@ export const ChatCompletionRequestMessages$outboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$outboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), - ), ]); /** @@ -352,6 +352,11 @@ export const ChatCompletionRequest$inboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$inboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ + role: v.role, + })), + ), UserMessage$inboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role, @@ -362,11 +367,6 @@ export const ChatCompletionRequest$inboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$inboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ - role: v.role, - })), - ), ]), ), response_format: ResponseFormat$inboundSchema.optional(), @@ -406,9 +406,9 @@ export type ChatCompletionRequest$Outbound = { random_seed?: number | null | undefined; messages: Array< | (SystemMessage$Outbound & { role: "system" }) + | (ToolMessage$Outbound & { role: "tool" }) | (UserMessage$Outbound & { role: "user" }) | (AssistantMessage$Outbound & { role: "assistant" }) - | (ToolMessage$Outbound & { role: "tool" }) >; response_format?: ResponseFormat$Outbound | undefined; tools?: Array | null | undefined; @@ -442,6 +442,11 @@ export const ChatCompletionRequest$outboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$outboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ + role: v.role, + })), + ), UserMessage$outboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role, @@ -452,11 +457,6 @@ export const ChatCompletionRequest$outboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$outboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ - role: v.role, - })), - ), ]), ), responseFormat: ResponseFormat$outboundSchema.optional(), diff --git a/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts b/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts index 5447db5b..3a734709 100644 --- a/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts +++ b/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts @@ -73,9 +73,9 @@ export type Stop = string | Array; export type Messages = | (SystemMessage & { role: "system" }) + | (ToolMessage & { role: "tool" }) | (UserMessage & { role: "user" }) - | (AssistantMessage & { role: "assistant" }) - | (ToolMessage & { role: "tool" }); + | (AssistantMessage & { role: "assistant" }); export type ChatCompletionStreamRequestToolChoice = ToolChoice | ToolChoiceEnum; @@ -110,9 +110,9 @@ export type ChatCompletionStreamRequest = { */ messages: Array< | (SystemMessage & { role: "system" }) + | (ToolMessage & { role: "tool" }) | (UserMessage & { role: "user" }) | (AssistantMessage & { role: "assistant" }) - | (ToolMessage & { role: "tool" }) >; responseFormat?: ResponseFormat | undefined; tools?: Array | null | undefined; @@ -190,6 +190,9 @@ export const Messages$inboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$inboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), + ), UserMessage$inboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role })), ), @@ -198,17 +201,14 @@ export const Messages$inboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$inboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), - ), ]); /** @internal */ export type Messages$Outbound = | (SystemMessage$Outbound & { role: "system" }) + | (ToolMessage$Outbound & { role: "tool" }) | (UserMessage$Outbound & { role: "user" }) - | (AssistantMessage$Outbound & { role: "assistant" }) - | (ToolMessage$Outbound & { role: "tool" }); + | (AssistantMessage$Outbound & { role: "assistant" }); /** @internal */ export const Messages$outboundSchema: z.ZodType< @@ -221,6 +221,9 @@ export const Messages$outboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$outboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), + ), UserMessage$outboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role })), ), @@ -229,9 +232,6 @@ export const Messages$outboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$outboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), - ), ]); /** @@ -336,6 +336,11 @@ export const ChatCompletionStreamRequest$inboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$inboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ + role: v.role, + })), + ), UserMessage$inboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role, @@ -346,11 +351,6 @@ export const ChatCompletionStreamRequest$inboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$inboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ - role: v.role, - })), - ), ]), ), response_format: ResponseFormat$inboundSchema.optional(), @@ -390,9 +390,9 @@ export type ChatCompletionStreamRequest$Outbound = { random_seed?: number | null | undefined; messages: Array< | (SystemMessage$Outbound & { role: "system" }) + | (ToolMessage$Outbound & { role: "tool" }) | (UserMessage$Outbound & { role: "user" }) | (AssistantMessage$Outbound & { role: "assistant" }) - | (ToolMessage$Outbound & { role: "tool" }) >; response_format?: ResponseFormat$Outbound | undefined; tools?: Array | null | undefined; @@ -426,6 +426,11 @@ export const ChatCompletionStreamRequest$outboundSchema: z.ZodType< role: v.role, })), ), + ToolMessage$outboundSchema.and( + z.object({ role: z.literal("tool") }).transform((v) => ({ + role: v.role, + })), + ), UserMessage$outboundSchema.and( z.object({ role: z.literal("user") }).transform((v) => ({ role: v.role, @@ -436,11 +441,6 @@ export const ChatCompletionStreamRequest$outboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$outboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ - role: v.role, - })), - ), ]), ), responseFormat: ResponseFormat$outboundSchema.optional(), diff --git a/packages/mistralai-azure/src/models/components/index.ts b/packages/mistralai-azure/src/models/components/index.ts index 10a280b6..d747e865 100644 --- a/packages/mistralai-azure/src/models/components/index.ts +++ b/packages/mistralai-azure/src/models/components/index.ts @@ -33,7 +33,9 @@ export * from "./responseformat.js"; export * from "./responseformats.js"; export * from "./security.js"; export * from "./systemmessage.js"; +export * from "./systemmessagecontentchunks.js"; export * from "./textchunk.js"; +export * from "./thinkchunk.js"; export * from "./tool.js"; export * from "./toolcall.js"; export * from "./toolchoice.js"; diff --git a/packages/mistralai-azure/src/models/components/ocrrequest.ts b/packages/mistralai-azure/src/models/components/ocrrequest.ts index 9c5087e7..77a5998b 100644 --- a/packages/mistralai-azure/src/models/components/ocrrequest.ts +++ b/packages/mistralai-azure/src/models/components/ocrrequest.ts @@ -35,7 +35,7 @@ import { /** * Document to run OCR on */ -export type Document = FileChunk | ImageURLChunk | DocumentURLChunk; +export type Document = FileChunk | DocumentURLChunk | ImageURLChunk; export type OCRRequest = { model: string | null; @@ -43,7 +43,7 @@ export type OCRRequest = { /** * Document to run OCR on */ - document: FileChunk | ImageURLChunk | DocumentURLChunk; + document: FileChunk | DocumentURLChunk | ImageURLChunk; /** * Specific pages user wants to process in various formats: single number, range, or list of both. Starts from 0 */ @@ -77,15 +77,15 @@ export const Document$inboundSchema: z.ZodType< unknown > = z.union([ FileChunk$inboundSchema, - ImageURLChunk$inboundSchema, DocumentURLChunk$inboundSchema, + ImageURLChunk$inboundSchema, ]); /** @internal */ export type Document$Outbound = | FileChunk$Outbound - | ImageURLChunk$Outbound - | DocumentURLChunk$Outbound; + | DocumentURLChunk$Outbound + | ImageURLChunk$Outbound; /** @internal */ export const Document$outboundSchema: z.ZodType< @@ -94,8 +94,8 @@ export const Document$outboundSchema: z.ZodType< Document > = z.union([ FileChunk$outboundSchema, - ImageURLChunk$outboundSchema, DocumentURLChunk$outboundSchema, + ImageURLChunk$outboundSchema, ]); /** @@ -135,8 +135,8 @@ export const OCRRequest$inboundSchema: z.ZodType< id: z.string().optional(), document: z.union([ FileChunk$inboundSchema, - ImageURLChunk$inboundSchema, DocumentURLChunk$inboundSchema, + ImageURLChunk$inboundSchema, ]), pages: z.nullable(z.array(z.number().int())).optional(), include_image_base64: z.nullable(z.boolean()).optional(), @@ -161,8 +161,8 @@ export type OCRRequest$Outbound = { id?: string | undefined; document: | FileChunk$Outbound - | ImageURLChunk$Outbound - | DocumentURLChunk$Outbound; + | DocumentURLChunk$Outbound + | ImageURLChunk$Outbound; pages?: Array | null | undefined; include_image_base64?: boolean | null | undefined; image_limit?: number | null | undefined; @@ -181,8 +181,8 @@ export const OCRRequest$outboundSchema: z.ZodType< id: z.string().optional(), document: z.union([ FileChunk$outboundSchema, - ImageURLChunk$outboundSchema, DocumentURLChunk$outboundSchema, + ImageURLChunk$outboundSchema, ]), pages: z.nullable(z.array(z.number().int())).optional(), includeImageBase64: z.nullable(z.boolean()).optional(), diff --git a/packages/mistralai-azure/src/models/components/systemmessage.ts b/packages/mistralai-azure/src/models/components/systemmessage.ts index a911a012..838daf4a 100644 --- a/packages/mistralai-azure/src/models/components/systemmessage.ts +++ b/packages/mistralai-azure/src/models/components/systemmessage.ts @@ -8,13 +8,13 @@ import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { - TextChunk, - TextChunk$inboundSchema, - TextChunk$Outbound, - TextChunk$outboundSchema, -} from "./textchunk.js"; + SystemMessageContentChunks, + SystemMessageContentChunks$inboundSchema, + SystemMessageContentChunks$Outbound, + SystemMessageContentChunks$outboundSchema, +} from "./systemmessagecontentchunks.js"; -export type SystemMessageContent = string | Array; +export type SystemMessageContent = string | Array; export const Role = { System: "system", @@ -22,7 +22,7 @@ export const Role = { export type Role = ClosedEnum; export type SystemMessage = { - content: string | Array; + content: string | Array; role?: Role | undefined; }; @@ -31,17 +31,19 @@ export const SystemMessageContent$inboundSchema: z.ZodType< SystemMessageContent, z.ZodTypeDef, unknown -> = z.union([z.string(), z.array(TextChunk$inboundSchema)]); +> = z.union([z.string(), z.array(SystemMessageContentChunks$inboundSchema)]); /** @internal */ -export type SystemMessageContent$Outbound = string | Array; +export type SystemMessageContent$Outbound = + | string + | Array; /** @internal */ export const SystemMessageContent$outboundSchema: z.ZodType< SystemMessageContent$Outbound, z.ZodTypeDef, SystemMessageContent -> = z.union([z.string(), z.array(TextChunk$outboundSchema)]); +> = z.union([z.string(), z.array(SystemMessageContentChunks$outboundSchema)]); /** * @internal @@ -100,13 +102,16 @@ export const SystemMessage$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.object({ - content: z.union([z.string(), z.array(TextChunk$inboundSchema)]), + content: z.union([ + z.string(), + z.array(SystemMessageContentChunks$inboundSchema), + ]), role: Role$inboundSchema.default("system"), }); /** @internal */ export type SystemMessage$Outbound = { - content: string | Array; + content: string | Array; role: string; }; @@ -116,7 +121,10 @@ export const SystemMessage$outboundSchema: z.ZodType< z.ZodTypeDef, SystemMessage > = z.object({ - content: z.union([z.string(), z.array(TextChunk$outboundSchema)]), + content: z.union([ + z.string(), + z.array(SystemMessageContentChunks$outboundSchema), + ]), role: Role$outboundSchema.default("system"), }); diff --git a/packages/mistralai-azure/src/models/components/systemmessagecontentchunks.ts b/packages/mistralai-azure/src/models/components/systemmessagecontentchunks.ts new file mode 100644 index 00000000..c02ec0bc --- /dev/null +++ b/packages/mistralai-azure/src/models/components/systemmessagecontentchunks.ts @@ -0,0 +1,92 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; +import { + TextChunk, + TextChunk$inboundSchema, + TextChunk$Outbound, + TextChunk$outboundSchema, +} from "./textchunk.js"; +import { + ThinkChunk, + ThinkChunk$inboundSchema, + ThinkChunk$Outbound, + ThinkChunk$outboundSchema, +} from "./thinkchunk.js"; + +export type SystemMessageContentChunks = + | (TextChunk & { type: "text" }) + | (ThinkChunk & { type: "thinking" }); + +/** @internal */ +export const SystemMessageContentChunks$inboundSchema: z.ZodType< + SystemMessageContentChunks, + z.ZodTypeDef, + unknown +> = z.union([ + TextChunk$inboundSchema.and( + z.object({ type: z.literal("text") }).transform((v) => ({ type: v.type })), + ), + ThinkChunk$inboundSchema.and( + z.object({ type: z.literal("thinking") }).transform((v) => ({ + type: v.type, + })), + ), +]); + +/** @internal */ +export type SystemMessageContentChunks$Outbound = + | (TextChunk$Outbound & { type: "text" }) + | (ThinkChunk$Outbound & { type: "thinking" }); + +/** @internal */ +export const SystemMessageContentChunks$outboundSchema: z.ZodType< + SystemMessageContentChunks$Outbound, + z.ZodTypeDef, + SystemMessageContentChunks +> = z.union([ + TextChunk$outboundSchema.and( + z.object({ type: z.literal("text") }).transform((v) => ({ type: v.type })), + ), + ThinkChunk$outboundSchema.and( + z.object({ type: z.literal("thinking") }).transform((v) => ({ + type: v.type, + })), + ), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace SystemMessageContentChunks$ { + /** @deprecated use `SystemMessageContentChunks$inboundSchema` instead. */ + export const inboundSchema = SystemMessageContentChunks$inboundSchema; + /** @deprecated use `SystemMessageContentChunks$outboundSchema` instead. */ + export const outboundSchema = SystemMessageContentChunks$outboundSchema; + /** @deprecated use `SystemMessageContentChunks$Outbound` instead. */ + export type Outbound = SystemMessageContentChunks$Outbound; +} + +export function systemMessageContentChunksToJSON( + systemMessageContentChunks: SystemMessageContentChunks, +): string { + return JSON.stringify( + SystemMessageContentChunks$outboundSchema.parse(systemMessageContentChunks), + ); +} + +export function systemMessageContentChunksFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => SystemMessageContentChunks$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'SystemMessageContentChunks' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/thinkchunk.ts b/packages/mistralai-azure/src/models/components/thinkchunk.ts new file mode 100644 index 00000000..2e09c78d --- /dev/null +++ b/packages/mistralai-azure/src/models/components/thinkchunk.ts @@ -0,0 +1,162 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { safeParse } from "../../lib/schemas.js"; +import { ClosedEnum } from "../../types/enums.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; +import { + ReferenceChunk, + ReferenceChunk$inboundSchema, + ReferenceChunk$Outbound, + ReferenceChunk$outboundSchema, +} from "./referencechunk.js"; +import { + TextChunk, + TextChunk$inboundSchema, + TextChunk$Outbound, + TextChunk$outboundSchema, +} from "./textchunk.js"; + +export type Thinking = ReferenceChunk | TextChunk; + +export const ThinkChunkType = { + Thinking: "thinking", +} as const; +export type ThinkChunkType = ClosedEnum; + +export type ThinkChunk = { + thinking: Array; + /** + * Whether the thinking chunk is closed or not. Currently only used for prefixing. + */ + closed?: boolean | undefined; + type?: ThinkChunkType | undefined; +}; + +/** @internal */ +export const Thinking$inboundSchema: z.ZodType< + Thinking, + z.ZodTypeDef, + unknown +> = z.union([ReferenceChunk$inboundSchema, TextChunk$inboundSchema]); + +/** @internal */ +export type Thinking$Outbound = ReferenceChunk$Outbound | TextChunk$Outbound; + +/** @internal */ +export const Thinking$outboundSchema: z.ZodType< + Thinking$Outbound, + z.ZodTypeDef, + Thinking +> = z.union([ReferenceChunk$outboundSchema, TextChunk$outboundSchema]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace Thinking$ { + /** @deprecated use `Thinking$inboundSchema` instead. */ + export const inboundSchema = Thinking$inboundSchema; + /** @deprecated use `Thinking$outboundSchema` instead. */ + export const outboundSchema = Thinking$outboundSchema; + /** @deprecated use `Thinking$Outbound` instead. */ + export type Outbound = Thinking$Outbound; +} + +export function thinkingToJSON(thinking: Thinking): string { + return JSON.stringify(Thinking$outboundSchema.parse(thinking)); +} + +export function thinkingFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Thinking$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Thinking' from JSON`, + ); +} + +/** @internal */ +export const ThinkChunkType$inboundSchema: z.ZodNativeEnum< + typeof ThinkChunkType +> = z.nativeEnum(ThinkChunkType); + +/** @internal */ +export const ThinkChunkType$outboundSchema: z.ZodNativeEnum< + typeof ThinkChunkType +> = ThinkChunkType$inboundSchema; + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ThinkChunkType$ { + /** @deprecated use `ThinkChunkType$inboundSchema` instead. */ + export const inboundSchema = ThinkChunkType$inboundSchema; + /** @deprecated use `ThinkChunkType$outboundSchema` instead. */ + export const outboundSchema = ThinkChunkType$outboundSchema; +} + +/** @internal */ +export const ThinkChunk$inboundSchema: z.ZodType< + ThinkChunk, + z.ZodTypeDef, + unknown +> = z.object({ + thinking: z.array( + z.union([ReferenceChunk$inboundSchema, TextChunk$inboundSchema]), + ), + closed: z.boolean().optional(), + type: ThinkChunkType$inboundSchema.default("thinking"), +}); + +/** @internal */ +export type ThinkChunk$Outbound = { + thinking: Array; + closed?: boolean | undefined; + type: string; +}; + +/** @internal */ +export const ThinkChunk$outboundSchema: z.ZodType< + ThinkChunk$Outbound, + z.ZodTypeDef, + ThinkChunk +> = z.object({ + thinking: z.array( + z.union([ReferenceChunk$outboundSchema, TextChunk$outboundSchema]), + ), + closed: z.boolean().optional(), + type: ThinkChunkType$outboundSchema.default("thinking"), +}); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace ThinkChunk$ { + /** @deprecated use `ThinkChunk$inboundSchema` instead. */ + export const inboundSchema = ThinkChunk$inboundSchema; + /** @deprecated use `ThinkChunk$outboundSchema` instead. */ + export const outboundSchema = ThinkChunk$outboundSchema; + /** @deprecated use `ThinkChunk$Outbound` instead. */ + export type Outbound = ThinkChunk$Outbound; +} + +export function thinkChunkToJSON(thinkChunk: ThinkChunk): string { + return JSON.stringify(ThinkChunk$outboundSchema.parse(thinkChunk)); +} + +export function thinkChunkFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ThinkChunk$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ThinkChunk' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/errors/httpvalidationerror.ts b/packages/mistralai-azure/src/models/errors/httpvalidationerror.ts index d9a58dc8..a59c540b 100644 --- a/packages/mistralai-azure/src/models/errors/httpvalidationerror.ts +++ b/packages/mistralai-azure/src/models/errors/httpvalidationerror.ts @@ -4,24 +4,27 @@ import * as z from "zod"; import * as components from "../components/index.js"; +import { MistralAzureError } from "./mistralazureerror.js"; export type HTTPValidationErrorData = { detail?: Array | undefined; }; -export class HTTPValidationError extends Error { +export class HTTPValidationError extends MistralAzureError { detail?: Array | undefined; /** The original data that was passed to this error instance. */ data$: HTTPValidationErrorData; - constructor(err: HTTPValidationErrorData) { + constructor( + err: HTTPValidationErrorData, + httpMeta: { response: Response; request: Request; body: string }, + ) { const message = "message" in err && typeof err.message === "string" ? err.message : `API error occurred: ${JSON.stringify(err)}`; - super(message); + super(message, httpMeta); this.data$ = err; - if (err.detail != null) this.detail = err.detail; this.name = "HTTPValidationError"; @@ -35,9 +38,16 @@ export const HTTPValidationError$inboundSchema: z.ZodType< unknown > = z.object({ detail: z.array(components.ValidationError$inboundSchema).optional(), + request$: z.instanceof(Request), + response$: z.instanceof(Response), + body$: z.string(), }) .transform((v) => { - return new HTTPValidationError(v); + return new HTTPValidationError(v, { + request: v.request$, + response: v.response$, + body: v.body$, + }); }); /** @internal */ diff --git a/packages/mistralai-azure/src/models/errors/index.ts b/packages/mistralai-azure/src/models/errors/index.ts index 8a5df29e..8692ad30 100644 --- a/packages/mistralai-azure/src/models/errors/index.ts +++ b/packages/mistralai-azure/src/models/errors/index.ts @@ -4,5 +4,6 @@ export * from "./httpclienterrors.js"; export * from "./httpvalidationerror.js"; +export * from "./responsevalidationerror.js"; export * from "./sdkerror.js"; export * from "./sdkvalidationerror.js"; diff --git a/packages/mistralai-azure/src/models/errors/mistralazureerror.ts b/packages/mistralai-azure/src/models/errors/mistralazureerror.ts new file mode 100644 index 00000000..1bdb6f2b --- /dev/null +++ b/packages/mistralai-azure/src/models/errors/mistralazureerror.ts @@ -0,0 +1,35 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +/** The base class for all HTTP error responses */ +export class MistralAzureError extends Error { + /** HTTP status code */ + public readonly statusCode: number; + /** HTTP body */ + public readonly body: string; + /** HTTP headers */ + public readonly headers: Headers; + /** HTTP content type */ + public readonly contentType: string; + /** Raw response */ + public readonly rawResponse: Response; + + constructor( + message: string, + httpMeta: { + response: Response; + request: Request; + body: string; + }, + ) { + super(message); + this.statusCode = httpMeta.response.status; + this.body = httpMeta.body; + this.headers = httpMeta.response.headers; + this.contentType = httpMeta.response.headers.get("content-type") || ""; + this.rawResponse = httpMeta.response; + + this.name = "MistralAzureError"; + } +} diff --git a/packages/mistralai-azure/src/models/errors/responsevalidationerror.ts b/packages/mistralai-azure/src/models/errors/responsevalidationerror.ts new file mode 100644 index 00000000..1d339fdd --- /dev/null +++ b/packages/mistralai-azure/src/models/errors/responsevalidationerror.ts @@ -0,0 +1,50 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { MistralAzureError } from "./mistralazureerror.js"; +import { formatZodError } from "./sdkvalidationerror.js"; + +export class ResponseValidationError extends MistralAzureError { + /** + * The raw value that failed validation. + */ + public readonly rawValue: unknown; + + /** + * The raw message that failed validation. + */ + public readonly rawMessage: unknown; + + constructor( + message: string, + extra: { + response: Response; + request: Request; + body: string; + cause: unknown; + rawValue: unknown; + rawMessage: unknown; + }, + ) { + super(message, extra); + this.name = "ResponseValidationError"; + this.cause = extra.cause; + this.rawValue = extra.rawValue; + this.rawMessage = extra.rawMessage; + } + + /** + * Return a pretty-formatted error message if the underlying validation error + * is a ZodError or some other recognized error type, otherwise return the + * default error message. + */ + public pretty(): string { + if (this.cause instanceof z.ZodError) { + return `${this.rawMessage}\n${formatZodError(this.cause)}`; + } else { + return this.toString(); + } + } +} diff --git a/packages/mistralai-azure/src/models/errors/sdkerror.ts b/packages/mistralai-azure/src/models/errors/sdkerror.ts index 001f4659..086a5c3a 100644 --- a/packages/mistralai-azure/src/models/errors/sdkerror.ts +++ b/packages/mistralai-azure/src/models/errors/sdkerror.ts @@ -2,26 +2,39 @@ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ -export class SDKError extends Error { - public readonly statusCode: number; - public readonly contentType: string; +import { MistralAzureError } from "./mistralazureerror.js"; +/** The fallback error class if no more specific error class is matched */ +export class SDKError extends MistralAzureError { constructor( message: string, - public readonly rawResponse: Response, - public readonly body: string = "", + httpMeta: { + response: Response; + request: Request; + 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.statusCode = statusCode; - this.contentType = contentType; - + if (message) { + message += `: `; + } + message += `Status ${httpMeta.response.status}`; + const contentType = httpMeta.response.headers.get("content-type") || `""`; + if (contentType !== "application/json") { + message += ` Content-Type ${ + contentType.includes(" ") ? `"${contentType}"` : contentType + }`; + } + const body = httpMeta.body || `""`; + message += body.length > 100 ? "\n" : ". "; + let bodyDisplay = body; + if (body.length > 10000) { + const truncated = body.substring(0, 10000); + const remaining = body.length - 10000; + bodyDisplay = `${truncated}...and ${remaining} more chars`; + } + message += `Body: ${bodyDisplay}`; + message = message.trim(); + super(message, httpMeta); this.name = "SDKError"; } } diff --git a/packages/mistralai-azure/src/models/errors/sdkvalidationerror.ts b/packages/mistralai-azure/src/models/errors/sdkvalidationerror.ts index 16929b9e..37face8a 100644 --- a/packages/mistralai-azure/src/models/errors/sdkvalidationerror.ts +++ b/packages/mistralai-azure/src/models/errors/sdkvalidationerror.ts @@ -15,6 +15,18 @@ export class SDKValidationError extends Error { */ public readonly rawMessage: unknown; + // Allows for backwards compatibility for `instanceof` checks of `ResponseValidationError` + static override [Symbol.hasInstance]( + instance: unknown, + ): instance is SDKValidationError { + if (!(instance instanceof Error)) return false; + if (!("rawValue" in instance)) return false; + if (!("rawMessage" in instance)) return false; + if (!("pretty" in instance)) return false; + if (typeof instance.pretty !== "function") return false; + return true; + } + constructor(message: string, cause: unknown, rawValue: unknown) { super(`${message}: ${cause}`); this.name = "SDKValidationError"; diff --git a/packages/mistralai-azure/src/types/constdatetime.ts b/packages/mistralai-azure/src/types/constdatetime.ts index c0a4409c..eeff4dde 100644 --- a/packages/mistralai-azure/src/types/constdatetime.ts +++ b/packages/mistralai-azure/src/types/constdatetime.ts @@ -11,5 +11,5 @@ export function constDateTime( return ( typeof v === "string" && new Date(v).getTime() === new Date(val).getTime() ); - }, `Value must be equivelant to ${val}`); + }, `Value must be equivalent to ${val}`); }