diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index e9c5562f..0d4a7587 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,4 +1,4 @@ -speakeasyVersion: 1.517.3 +speakeasyVersion: 1.606.10 sources: mistral-azure-source: sourceNamespace: mistral-openapi-azure @@ -9,11 +9,11 @@ sources: - speakeasy-sdk-regen-1756133560 mistral-google-cloud-source: sourceNamespace: mistral-openapi-google-cloud - sourceRevisionDigest: sha256:4a5343e63c6a78152e472b00ccc46d7bcb15594496bc94c8040039d3a9d4c5f8 - sourceBlobDigest: sha256:3327f078a11596abdcbc21cd8a1adcf0b2aa474975cd9ab1feb745a2e50d555f + sourceRevisionDigest: sha256:6ebd7313536f2ff9a221e7cf8b9423cc740266e89f28c1103141f231562d6c7f + sourceBlobDigest: sha256:3fc6da55bf015d2fe6e14ae1a1098046e4730966be9b21f73cc2db4811e5dcc5 tags: - latest - - speakeasy-sdk-regen-1742480568 + - speakeasy-sdk-regen-1756820974 mistral-openapi: sourceNamespace: mistral-openapi sourceRevisionDigest: sha256:eefc1f0b6a5e9ec673d317d61cad766290710b5fc369412491b75f732cccfedd @@ -32,10 +32,10 @@ targets: mistralai-gcp-sdk: source: mistral-google-cloud-source sourceNamespace: mistral-openapi-google-cloud - sourceRevisionDigest: sha256:4a5343e63c6a78152e472b00ccc46d7bcb15594496bc94c8040039d3a9d4c5f8 - sourceBlobDigest: sha256:3327f078a11596abdcbc21cd8a1adcf0b2aa474975cd9ab1feb745a2e50d555f + sourceRevisionDigest: sha256:6ebd7313536f2ff9a221e7cf8b9423cc740266e89f28c1103141f231562d6c7f + sourceBlobDigest: sha256:3fc6da55bf015d2fe6e14ae1a1098046e4730966be9b21f73cc2db4811e5dcc5 codeSamplesNamespace: mistral-openapi-google-cloud-code-samples - codeSamplesRevisionDigest: sha256:4b6150daaeabee64521e9cbfb209d2aaf84746dabd6e359a9728e18b5f25380a + codeSamplesRevisionDigest: sha256:900700ca7d24d86b456a8249c47d8e3d6b018b6b9df4a763f6cbaaa82e8b5d95 mistralai-sdk: source: mistral-openapi sourceNamespace: mistral-openapi @@ -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-gcp/.gitignore b/packages/mistralai-gcp/.gitignore index dc2842dc..da5c73af 100644 --- a/packages/mistralai-gcp/.gitignore +++ b/packages/mistralai-gcp/.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-gcp/.speakeasy/gen.lock b/packages/mistralai-gcp/.speakeasy/gen.lock index b610d8cd..c63d617b 100644 --- a/packages/mistralai-gcp/.speakeasy/gen.lock +++ b/packages/mistralai-gcp/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: c6044247-eaf9-46da-b078-0e1334e93be2 management: - docChecksum: 28fe1ab59b4dee005217f2dbbd836060 - docVersion: 0.0.2 - speakeasyVersion: 1.517.3 - generationVersion: 2.548.6 - releaseVersion: 1.5.0 - configChecksum: 1c5e28cded8c5d3a7d735e20f6f09b99 + docChecksum: 14c4b1b2397cbfd401cc9e73d4f3236f + docVersion: 1.0.0 + speakeasyVersion: 1.606.10 + generationVersion: 2.687.13 + releaseVersion: 1.6.0 + configChecksum: 36a28c11b7aeab0315d39474accbc4d6 repoURL: https://github.com/mistralai/client-ts.git repoSubDirectory: packages/mistralai-gcp installationURL: https://gitpkg.now.sh/mistralai/client-ts/packages/mistralai-gcp @@ -14,26 +14,27 @@ management: features: typescript: additionalDependencies: 0.1.0 - constsAndDefaults: 0.1.11 - core: 3.21.4 + additionalProperties: 0.1.1 + 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 @@ -75,6 +76,7 @@ generatedFiles: - docs/models/components/jsonschema.md - docs/models/components/loc.md - docs/models/components/messages.md + - docs/models/components/mistralpromptmode.md - docs/models/components/prediction.md - docs/models/components/referencechunk.md - docs/models/components/referencechunktype.md @@ -85,7 +87,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 @@ -102,6 +108,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 @@ -149,13 +158,16 @@ generatedFiles: - src/models/components/imageurlchunk.ts - src/models/components/index.ts - src/models/components/jsonschema.ts + - src/models/components/mistralpromptmode.ts - src/models/components/prediction.ts - src/models/components/referencechunk.ts - src/models/components/responseformat.ts - 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 @@ -168,6 +180,8 @@ generatedFiles: - src/models/errors/httpclienterrors.ts - src/models/errors/httpvalidationerror.ts - src/models/errors/index.ts + - src/models/errors/mistralgoogleclouderror.ts + - src/models/errors/responsevalidationerror.ts - src/models/errors/sdkerror.ts - src/models/errors/sdkvalidationerror.ts - src/sdk/chat.ts @@ -191,14 +205,13 @@ examples: responses: "422": application/json: {} - "200": {} chat_completion_v1_chat_completions_post: speakeasy-default-chat-completion-v1-chat-completions-post: requestBody: application/json: {"model": "mistral-small-latest", "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: {} stream_fim: @@ -208,15 +221,15 @@ examples: responses: "422": application/json: {} - "200": {} fim_completion_v1_fim_completions_post: speakeasy-default-fim-completion-v1-fim-completions-post: requestBody: application/json: {"model": "codestral-2405", "top_p": 1, "stream": false, "prompt": "def", "suffix": "return a+b"} responses: "200": - application/json: {"id": "cmpl-e5cc70bb28c444948073e77776eb30ef", "object": "chat.completion", "model": "codestral-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": "codestral-latest", "usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0}, "created": 1702256327, "choices": []} "422": application/json: {} -examplesVersion: 1.0.0 +examplesVersion: 1.0.2 generatedTests: {} +releaseNotes: "## SDK Changes Detected:\n* `mistralgooglecloud.chat.complete()`: \n * `request` **Changed** **Breaking** :warning:\n * `response` **Changed**\n* `mistralgooglecloud.fim.complete()`: `response` **Changed**\n" diff --git a/packages/mistralai-gcp/.speakeasy/gen.yaml b/packages/mistralai-gcp/.speakeasy/gen.yaml index fb22816d..1683849f 100644 --- a/packages/mistralai-gcp/.speakeasy/gen.yaml +++ b/packages/mistralai-gcp/.speakeasy/gen.yaml @@ -4,6 +4,7 @@ generation: maintainOpenAPIOrder: true usageSnippets: optionalPropertyRendering: withExample + sdkInitStyle: constructor useClassNamesForArrayFields: true fixes: nameResolutionDec2023: true @@ -11,11 +12,16 @@ generation: parameterOrderingFeb2024: true requestResponseComponentNamesFeb2024: true securityFeb2025: false + sharedErrorComponentsApr2025: false auth: oAuth2ClientCredentialsEnabled: true oAuth2PasswordEnabled: false + tests: + generateTests: true + generateNewTests: false + skipResponseBodyAssertions: false typescript: - version: 1.5.0 + version: 1.6.0 additionalDependencies: dependencies: google-auth-library: ^9.11.0 @@ -23,7 +29,9 @@ typescript: peerDependencies: {} additionalPackageJSON: {} author: Speakeasy + baseErrorName: MistralGoogleCloudError clientServerStatusCodesAsErrors: true + constFieldsAlwaysOptional: true defaultErrorName: SDKError enableCustomCodeRegions: false enableMCPServer: false @@ -31,6 +39,7 @@ typescript: enumFormat: union flattenGlobalSecurity: true flatteningOrder: body-first + generateExamples: true imports: option: openapi paths: @@ -48,4 +57,5 @@ typescript: packageName: '@mistralai/mistralai-gcp' responseFormat: flat templateVersion: v2 + usageSDKInitImports: [] useIndexModules: true diff --git a/packages/mistralai-gcp/FUNCTIONS.md b/packages/mistralai-gcp/FUNCTIONS.md index 3a89845a..ef73276e 100644 --- a/packages/mistralai-gcp/FUNCTIONS.md +++ b/packages/mistralai-gcp/FUNCTIONS.md @@ -21,7 +21,6 @@ specific category of applications. ```typescript import { MistralGoogleCloudCore } from "@mistralai/mistralai-gcp/core.js"; import { chatComplete } from "@mistralai/mistralai-gcp/funcs/chatComplete.js"; -import { SDKValidationError } from "@mistralai/mistralai-gcp/models/errors/sdkvalidationerror.js"; // Use `MistralGoogleCloudCore` for best tree-shaking performance. // You can create one instance of it to use across an application. @@ -39,28 +38,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-gcp/RELEASES.md b/packages/mistralai-gcp/RELEASES.md index 1cd7fda9..1d61eeb0 100644 --- a/packages/mistralai-gcp/RELEASES.md +++ b/packages/mistralai-gcp/RELEASES.md @@ -118,4 +118,14 @@ Based on: ### Generated - [typescript v1.5.0] packages/mistralai-gcp ### Releases -- [NPM v1.5.0] https://www.npmjs.com/package/@mistralai/mistralai-gcp/v/1.5.0 - packages/mistralai-gcp \ No newline at end of file +- [NPM v1.5.0] https://www.npmjs.com/package/@mistralai/mistralai-gcp/v/1.5.0 - packages/mistralai-gcp + +## 2025-09-02 13:49:18 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.606.10 (2.687.13) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v1.6.0] packages/mistralai-gcp +### Releases +- [NPM v1.6.0] https://www.npmjs.com/package/@mistralai/mistralai-gcp/v/1.6.0 - packages/mistralai-gcp \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/arguments.md b/packages/mistralai-gcp/docs/models/components/arguments.md index ef0bdc61..5a99a089 100644 --- a/packages/mistralai-gcp/docs/models/components/arguments.md +++ b/packages/mistralai-gcp/docs/models/components/arguments.md @@ -8,6 +8,8 @@ ```typescript const value: { [k: string]: any } = { "key": "", + "key1": "", + "key2": "", }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/assistantmessagecontent.md b/packages/mistralai-gcp/docs/models/components/assistantmessagecontent.md index ffa94cf0..7918f1c9 100644 --- a/packages/mistralai-gcp/docs/models/components/assistantmessagecontent.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/chatcompletionrequest.md b/packages/mistralai-gcp/docs/models/components/chatcompletionrequest.md index 986344be..32c21005 100644 --- a/packages/mistralai-gcp/docs/models/components/chatcompletionrequest.md +++ b/packages/mistralai-gcp/docs/models/components/chatcompletionrequest.md @@ -35,4 +35,5 @@ let value: ChatCompletionRequest = { | `frequencyPenalty` | *number* | :heavy_minus_sign: | frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition. | | | `n` | *number* | :heavy_minus_sign: | Number of completions to return for each request, input tokens are only billed once. | | | `prediction` | [components.Prediction](../../models/components/prediction.md) | :heavy_minus_sign: | N/A | | -| `parallelToolCalls` | *boolean* | :heavy_minus_sign: | N/A | | \ No newline at end of file +| `parallelToolCalls` | *boolean* | :heavy_minus_sign: | N/A | | +| `promptMode` | [components.MistralPromptMode](../../models/components/mistralpromptmode.md) | :heavy_minus_sign: | Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used. | | \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/chatcompletionrequestmessages.md b/packages/mistralai-gcp/docs/models/components/chatcompletionrequestmessages.md index 0bc19a1b..68272ebf 100644 --- a/packages/mistralai-gcp/docs/models/components/chatcompletionrequestmessages.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/chatcompletionrequeststop.md b/packages/mistralai-gcp/docs/models/components/chatcompletionrequeststop.md index 5cf805d7..e935025f 100644 --- a/packages/mistralai-gcp/docs/models/components/chatcompletionrequeststop.md +++ b/packages/mistralai-gcp/docs/models/components/chatcompletionrequeststop.md @@ -15,7 +15,8 @@ const value: string = ""; ```typescript const value: string[] = [ - "", + "", + "", ]; ``` diff --git a/packages/mistralai-gcp/docs/models/components/chatcompletionresponse.md b/packages/mistralai-gcp/docs/models/components/chatcompletionresponse.md index 406db865..f0a6f5ba 100644 --- a/packages/mistralai-gcp/docs/models/components/chatcompletionresponse.md +++ b/packages/mistralai-gcp/docs/models/components/chatcompletionresponse.md @@ -9,19 +9,9 @@ let value: ChatCompletionResponse = { id: "cmpl-e5cc70bb28c444948073e77776eb30ef", object: "chat.completion", model: "mistral-small-latest", - usage: { - promptTokens: 16, - completionTokens: 34, - totalTokens: 50, - }, + usage: {}, created: 1702256327, - choices: [ - { - index: 0, - message: {}, - finishReason: "stop", - }, - ], + choices: [], }; ``` @@ -33,5 +23,5 @@ let value: ChatCompletionResponse = { | `object` | *string* | :heavy_check_mark: | N/A | chat.completion | | `model` | *string* | :heavy_check_mark: | N/A | mistral-small-latest | | `usage` | [components.UsageInfo](../../models/components/usageinfo.md) | :heavy_check_mark: | N/A | | -| `created` | *number* | :heavy_minus_sign: | N/A | 1702256327 | -| `choices` | [components.ChatCompletionChoice](../../models/components/chatcompletionchoice.md)[] | :heavy_minus_sign: | N/A | | \ No newline at end of file +| `created` | *number* | :heavy_check_mark: | N/A | 1702256327 | +| `choices` | [components.ChatCompletionChoice](../../models/components/chatcompletionchoice.md)[] | :heavy_check_mark: | N/A | | \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequest.md b/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequest.md index 62744998..d538b79c 100644 --- a/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequest.md +++ b/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequest.md @@ -35,4 +35,5 @@ let value: ChatCompletionStreamRequest = { | `frequencyPenalty` | *number* | :heavy_minus_sign: | frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition. | | | `n` | *number* | :heavy_minus_sign: | Number of completions to return for each request, input tokens are only billed once. | | | `prediction` | [components.Prediction](../../models/components/prediction.md) | :heavy_minus_sign: | N/A | | -| `parallelToolCalls` | *boolean* | :heavy_minus_sign: | N/A | | \ No newline at end of file +| `parallelToolCalls` | *boolean* | :heavy_minus_sign: | N/A | | +| `promptMode` | [components.MistralPromptMode](../../models/components/mistralpromptmode.md) | :heavy_minus_sign: | Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used. | | \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequesttoolchoice.md b/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequesttoolchoice.md index 4d4a29f2..9f19e8c4 100644 --- a/packages/mistralai-gcp/docs/models/components/chatcompletionstreamrequesttoolchoice.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/completionchunk.md b/packages/mistralai-gcp/docs/models/components/completionchunk.md index feac1c03..8f013c59 100644 --- a/packages/mistralai-gcp/docs/models/components/completionchunk.md +++ b/packages/mistralai-gcp/docs/models/components/completionchunk.md @@ -7,19 +7,8 @@ import { CompletionChunk } from "@mistralai/mistralai-gcp/models/components"; let value: CompletionChunk = { id: "", - model: "Golf", - usage: { - promptTokens: 16, - completionTokens: 34, - totalTokens: 50, - }, - choices: [ - { - index: 423655, - delta: {}, - finishReason: "error", - }, - ], + model: "Prius", + choices: [], }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/completionevent.md b/packages/mistralai-gcp/docs/models/components/completionevent.md index 1e30d6e0..2a1aaf55 100644 --- a/packages/mistralai-gcp/docs/models/components/completionevent.md +++ b/packages/mistralai-gcp/docs/models/components/completionevent.md @@ -8,19 +8,8 @@ import { CompletionEvent } from "@mistralai/mistralai-gcp/models/components"; let value: CompletionEvent = { data: { id: "", - model: "Golf", - usage: { - promptTokens: 16, - completionTokens: 34, - totalTokens: 50, - }, - choices: [ - { - index: 715190, - delta: {}, - finishReason: "error", - }, - ], + model: "Model S", + choices: [], }, }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/completionresponsestreamchoice.md b/packages/mistralai-gcp/docs/models/components/completionresponsestreamchoice.md index 823eecdb..64ce8460 100644 --- a/packages/mistralai-gcp/docs/models/components/completionresponsestreamchoice.md +++ b/packages/mistralai-gcp/docs/models/components/completionresponsestreamchoice.md @@ -6,7 +6,7 @@ import { CompletionResponseStreamChoice } from "@mistralai/mistralai-gcp/models/components"; let value: CompletionResponseStreamChoice = { - index: 891773, + index: 264645, delta: {}, finishReason: "tool_calls", }; diff --git a/packages/mistralai-gcp/docs/models/components/content.md b/packages/mistralai-gcp/docs/models/components/content.md index b05000a3..e31bfa0c 100644 --- a/packages/mistralai-gcp/docs/models/components/content.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/contentchunk.md b/packages/mistralai-gcp/docs/models/components/contentchunk.md index b25f2ef2..51f7f26a 100644 --- a/packages/mistralai-gcp/docs/models/components/contentchunk.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/fimcompletionrequeststop.md b/packages/mistralai-gcp/docs/models/components/fimcompletionrequeststop.md index 84c5828f..564250b1 100644 --- a/packages/mistralai-gcp/docs/models/components/fimcompletionrequeststop.md +++ b/packages/mistralai-gcp/docs/models/components/fimcompletionrequeststop.md @@ -15,7 +15,8 @@ const value: string = ""; ```typescript const value: string[] = [ - "", + "", + "", ]; ``` diff --git a/packages/mistralai-gcp/docs/models/components/fimcompletionresponse.md b/packages/mistralai-gcp/docs/models/components/fimcompletionresponse.md index cf052b2d..7cf85278 100644 --- a/packages/mistralai-gcp/docs/models/components/fimcompletionresponse.md +++ b/packages/mistralai-gcp/docs/models/components/fimcompletionresponse.md @@ -9,11 +9,7 @@ let value: FIMCompletionResponse = { id: "cmpl-e5cc70bb28c444948073e77776eb30ef", object: "chat.completion", model: "codestral-latest", - usage: { - promptTokens: 16, - completionTokens: 34, - totalTokens: 50, - }, + usage: {}, created: 1702256327, choices: [ { @@ -33,5 +29,5 @@ let value: FIMCompletionResponse = { | `object` | *string* | :heavy_check_mark: | N/A | chat.completion | | `model` | *string* | :heavy_check_mark: | N/A | codestral-latest | | `usage` | [components.UsageInfo](../../models/components/usageinfo.md) | :heavy_check_mark: | N/A | | -| `created` | *number* | :heavy_minus_sign: | N/A | 1702256327 | -| `choices` | [components.ChatCompletionChoice](../../models/components/chatcompletionchoice.md)[] | :heavy_minus_sign: | N/A | | \ No newline at end of file +| `created` | *number* | :heavy_check_mark: | N/A | 1702256327 | +| `choices` | [components.ChatCompletionChoice](../../models/components/chatcompletionchoice.md)[] | :heavy_check_mark: | N/A | | \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/fimcompletionstreamrequeststop.md b/packages/mistralai-gcp/docs/models/components/fimcompletionstreamrequeststop.md index 376ae828..12021bc4 100644 --- a/packages/mistralai-gcp/docs/models/components/fimcompletionstreamrequeststop.md +++ b/packages/mistralai-gcp/docs/models/components/fimcompletionstreamrequeststop.md @@ -15,7 +15,8 @@ const value: string = ""; ```typescript const value: string[] = [ - "", + "", + "", ]; ``` diff --git a/packages/mistralai-gcp/docs/models/components/finishreason.md b/packages/mistralai-gcp/docs/models/components/finishreason.md index f284ebe0..a0e47a10 100644 --- a/packages/mistralai-gcp/docs/models/components/finishreason.md +++ b/packages/mistralai-gcp/docs/models/components/finishreason.md @@ -5,7 +5,7 @@ ```typescript import { FinishReason } from "@mistralai/mistralai-gcp/models/components"; -let value: FinishReason = "length"; +let value: FinishReason = "error"; ``` ## Values diff --git a/packages/mistralai-gcp/docs/models/components/imageurl.md b/packages/mistralai-gcp/docs/models/components/imageurl.md index 66bd18b3..bf31d084 100644 --- a/packages/mistralai-gcp/docs/models/components/imageurl.md +++ b/packages/mistralai-gcp/docs/models/components/imageurl.md @@ -6,7 +6,7 @@ import { ImageURL } from "@mistralai/mistralai-gcp/models/components"; let value: ImageURL = { - url: "https://misguided-hawk.biz", + url: "https://grim-farm.name/", }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/imageurlchunk.md b/packages/mistralai-gcp/docs/models/components/imageurlchunk.md index 49b4f934..23e6300a 100644 --- a/packages/mistralai-gcp/docs/models/components/imageurlchunk.md +++ b/packages/mistralai-gcp/docs/models/components/imageurlchunk.md @@ -8,9 +8,7 @@ import { ImageURLChunk } from "@mistralai/mistralai-gcp/models/components"; let value: ImageURLChunk = { - imageUrl: { - url: "https://close-paintwork.com", - }, + imageUrl: "https://darling-distinction.org", }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/imageurlchunkimageurl.md b/packages/mistralai-gcp/docs/models/components/imageurlchunkimageurl.md index 486a5ef7..6b0520c0 100644 --- a/packages/mistralai-gcp/docs/models/components/imageurlchunkimageurl.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/jsonschema.md b/packages/mistralai-gcp/docs/models/components/jsonschema.md index cd57dfb9..7ffcd46d 100644 --- a/packages/mistralai-gcp/docs/models/components/jsonschema.md +++ b/packages/mistralai-gcp/docs/models/components/jsonschema.md @@ -9,6 +9,7 @@ let value: JsonSchema = { name: "", schemaDefinition: { "key": "", + "key1": "", }, }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/loc.md b/packages/mistralai-gcp/docs/models/components/loc.md index 93706ec7..74021dec 100644 --- a/packages/mistralai-gcp/docs/models/components/loc.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/messages.md b/packages/mistralai-gcp/docs/models/components/messages.md index 22b2a13a..44e7a796 100644 --- a/packages/mistralai-gcp/docs/models/components/messages.md +++ b/packages/mistralai-gcp/docs/models/components/messages.md @@ -13,12 +13,7 @@ const value: components.AssistantMessage = {}; ```typescript const value: components.SystemMessage = { - content: [ - { - text: "", - type: "text", - }, - ], + content: "", }; ``` @@ -26,12 +21,7 @@ const value: components.SystemMessage = { ```typescript const value: components.ToolMessage = { - content: [ - { - text: "", - type: "text", - }, - ], + content: [], }; ``` @@ -39,14 +29,7 @@ const value: components.ToolMessage = { ```typescript const value: components.UserMessage = { - content: [ - { - referenceIds: [ - 359508, - ], - type: "reference", - }, - ], + content: "", }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/mistralpromptmode.md b/packages/mistralai-gcp/docs/models/components/mistralpromptmode.md new file mode 100644 index 00000000..e52dfa19 --- /dev/null +++ b/packages/mistralai-gcp/docs/models/components/mistralpromptmode.md @@ -0,0 +1,17 @@ +# MistralPromptMode + +## Example Usage + +```typescript +import { MistralPromptMode } from "@mistralai/mistralai-gcp/models/components"; + +let value: MistralPromptMode = "reasoning"; +``` + +## Values + +This is an open enum. Unrecognized values will be captured as the `Unrecognized` branded type. + +```typescript +"reasoning" | Unrecognized +``` \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/referencechunk.md b/packages/mistralai-gcp/docs/models/components/referencechunk.md index b342cc99..7c0e459e 100644 --- a/packages/mistralai-gcp/docs/models/components/referencechunk.md +++ b/packages/mistralai-gcp/docs/models/components/referencechunk.md @@ -6,9 +6,7 @@ import { ReferenceChunk } from "@mistralai/mistralai-gcp/models/components"; let value: ReferenceChunk = { - referenceIds: [ - 774234, - ], + referenceIds: [], }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/responseformats.md b/packages/mistralai-gcp/docs/models/components/responseformats.md index 351d4580..e9d22c2d 100644 --- a/packages/mistralai-gcp/docs/models/components/responseformats.md +++ b/packages/mistralai-gcp/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-gcp/models/components"; -let value: ResponseFormats = "text"; +let value: ResponseFormats = "json_object"; ``` ## Values diff --git a/packages/mistralai-gcp/docs/models/components/stop.md b/packages/mistralai-gcp/docs/models/components/stop.md index f26b1bf3..bc9d30e0 100644 --- a/packages/mistralai-gcp/docs/models/components/stop.md +++ b/packages/mistralai-gcp/docs/models/components/stop.md @@ -15,7 +15,8 @@ const value: string = ""; ```typescript const value: string[] = [ - "", + "", + "", ]; ``` diff --git a/packages/mistralai-gcp/docs/models/components/systemmessage.md b/packages/mistralai-gcp/docs/models/components/systemmessage.md index b02ca226..d82489c8 100644 --- a/packages/mistralai-gcp/docs/models/components/systemmessage.md +++ b/packages/mistralai-gcp/docs/models/components/systemmessage.md @@ -6,12 +6,7 @@ import { SystemMessage } from "@mistralai/mistralai-gcp/models/components"; let value: SystemMessage = { - content: [ - { - text: "", - type: "text", - }, - ], + content: "", }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/systemmessagecontent.md b/packages/mistralai-gcp/docs/models/components/systemmessagecontent.md index cda9bedd..7bfdb5b7 100644 --- a/packages/mistralai-gcp/docs/models/components/systemmessagecontent.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/systemmessagecontentchunks.md b/packages/mistralai-gcp/docs/models/components/systemmessagecontentchunks.md new file mode 100644 index 00000000..a6f0642f --- /dev/null +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/thinkchunk.md b/packages/mistralai-gcp/docs/models/components/thinkchunk.md new file mode 100644 index 00000000..13551dcc --- /dev/null +++ b/packages/mistralai-gcp/docs/models/components/thinkchunk.md @@ -0,0 +1,19 @@ +# ThinkChunk + +## Example Usage + +```typescript +import { ThinkChunk } from "@mistralai/mistralai-gcp/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-gcp/docs/models/components/thinkchunktype.md b/packages/mistralai-gcp/docs/models/components/thinkchunktype.md new file mode 100644 index 00000000..0cc1ebc6 --- /dev/null +++ b/packages/mistralai-gcp/docs/models/components/thinkchunktype.md @@ -0,0 +1,15 @@ +# ThinkChunkType + +## Example Usage + +```typescript +import { ThinkChunkType } from "@mistralai/mistralai-gcp/models/components"; + +let value: ThinkChunkType = "thinking"; +``` + +## Values + +```typescript +"thinking" +``` \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/thinking.md b/packages/mistralai-gcp/docs/models/components/thinking.md new file mode 100644 index 00000000..0e23944c --- /dev/null +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/tool.md b/packages/mistralai-gcp/docs/models/components/tool.md index 6b4f5438..a8cc6dec 100644 --- a/packages/mistralai-gcp/docs/models/components/tool.md +++ b/packages/mistralai-gcp/docs/models/components/tool.md @@ -8,9 +8,7 @@ import { Tool } from "@mistralai/mistralai-gcp/models/components"; let value: Tool = { function: { name: "", - parameters: { - "key": "", - }, + parameters: {}, }, }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/toolcall.md b/packages/mistralai-gcp/docs/models/components/toolcall.md index c4edd169..64786317 100644 --- a/packages/mistralai-gcp/docs/models/components/toolcall.md +++ b/packages/mistralai-gcp/docs/models/components/toolcall.md @@ -8,7 +8,7 @@ import { ToolCall } from "@mistralai/mistralai-gcp/models/components"; let value: ToolCall = { function: { name: "", - arguments: "", + arguments: {}, }, }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/toolchoiceenum.md b/packages/mistralai-gcp/docs/models/components/toolchoiceenum.md index 11580ae4..6283aa36 100644 --- a/packages/mistralai-gcp/docs/models/components/toolchoiceenum.md +++ b/packages/mistralai-gcp/docs/models/components/toolchoiceenum.md @@ -5,7 +5,7 @@ ```typescript import { ToolChoiceEnum } from "@mistralai/mistralai-gcp/models/components"; -let value: ToolChoiceEnum = "any"; +let value: ToolChoiceEnum = "required"; ``` ## Values diff --git a/packages/mistralai-gcp/docs/models/components/toolmessage.md b/packages/mistralai-gcp/docs/models/components/toolmessage.md index 142851c9..15808bb1 100644 --- a/packages/mistralai-gcp/docs/models/components/toolmessage.md +++ b/packages/mistralai-gcp/docs/models/components/toolmessage.md @@ -6,7 +6,7 @@ import { ToolMessage } from "@mistralai/mistralai-gcp/models/components"; let value: ToolMessage = { - content: "", + content: [], }; ``` diff --git a/packages/mistralai-gcp/docs/models/components/toolmessagecontent.md b/packages/mistralai-gcp/docs/models/components/toolmessagecontent.md index 1b59bf96..3acfc705 100644 --- a/packages/mistralai-gcp/docs/models/components/toolmessagecontent.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/usageinfo.md b/packages/mistralai-gcp/docs/models/components/usageinfo.md index a27db9cb..b482d5dc 100644 --- a/packages/mistralai-gcp/docs/models/components/usageinfo.md +++ b/packages/mistralai-gcp/docs/models/components/usageinfo.md @@ -5,17 +5,15 @@ ```typescript import { UsageInfo } from "@mistralai/mistralai-gcp/models/components"; -let value: UsageInfo = { - promptTokens: 16, - completionTokens: 34, - totalTokens: 50, -}; +let value: UsageInfo = {}; ``` ## Fields -| Field | Type | Required | Description | Example | -| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | -| `promptTokens` | *number* | :heavy_check_mark: | N/A | 16 | -| `completionTokens` | *number* | :heavy_check_mark: | N/A | 34 | -| `totalTokens` | *number* | :heavy_check_mark: | N/A | 50 | \ No newline at end of file +| Field | Type | Required | Description | +| ---------------------- | ---------------------- | ---------------------- | ---------------------- | +| `promptTokens` | *number* | :heavy_minus_sign: | N/A | +| `completionTokens` | *number* | :heavy_minus_sign: | N/A | +| `totalTokens` | *number* | :heavy_minus_sign: | N/A | +| `promptAudioSeconds` | *number* | :heavy_minus_sign: | N/A | +| `additionalProperties` | Record | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/packages/mistralai-gcp/docs/models/components/usermessagecontent.md b/packages/mistralai-gcp/docs/models/components/usermessagecontent.md index a8be0fda..22c7d880 100644 --- a/packages/mistralai-gcp/docs/models/components/usermessagecontent.md +++ b/packages/mistralai-gcp/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-gcp/docs/models/components/validationerror.md b/packages/mistralai-gcp/docs/models/components/validationerror.md index b5cae6b1..85e9c965 100644 --- a/packages/mistralai-gcp/docs/models/components/validationerror.md +++ b/packages/mistralai-gcp/docs/models/components/validationerror.md @@ -7,7 +7,7 @@ import { ValidationError } from "@mistralai/mistralai-gcp/models/components"; let value: ValidationError = { loc: [ - 18789, + 929957, ], msg: "", type: "", diff --git a/packages/mistralai-gcp/eslint.config.mjs b/packages/mistralai-gcp/eslint.config.mjs index 3483f71b..67bccfec 100644 --- a/packages/mistralai-gcp/eslint.config.mjs +++ b/packages/mistralai-gcp/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-gcp/examples/.env.template b/packages/mistralai-gcp/examples/.env.template new file mode 100644 index 00000000..40fcbedf --- /dev/null +++ b/packages/mistralai-gcp/examples/.env.template @@ -0,0 +1,3 @@ +# @mistralai/mistralai-gcp SDK Environment Variables +# Copy this file to .env and fill in your actual values +# DO NOT commit the .env file to version control diff --git a/packages/mistralai-gcp/examples/chatComplete.example.ts b/packages/mistralai-gcp/examples/chatComplete.example.ts new file mode 100644 index 00000000..631a3efb --- /dev/null +++ b/packages/mistralai-gcp/examples/chatComplete.example.ts @@ -0,0 +1,35 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import dotenv from "dotenv"; +dotenv.config(); +/** + * Example usage of the @mistralai/mistralai-gcp SDK + * + * To run this example from the examples directory: + * npm run build && npx tsx chatComplete.example.ts + */ + +import { MistralGoogleCloud } from "@mistralai/mistralai-gcp"; + +const mistralGoogleCloud = new MistralGoogleCloud({ + apiKey: "", +}); + +async function main() { + const result = await mistralGoogleCloud.complete({ + model: "mistral-small-latest", + 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-gcp/examples/package-lock.json b/packages/mistralai-gcp/examples/package-lock.json new file mode 100644 index 00000000..67e35cd9 --- /dev/null +++ b/packages/mistralai-gcp/examples/package-lock.json @@ -0,0 +1,611 @@ +{ + "name": "@mistralai/mistralai-gcp-examples", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@mistralai/mistralai-gcp-examples", + "version": "1.0.0", + "dependencies": { + "@mistralai/mistralai-gcp": "file:.." + }, + "devDependencies": { + "@types/node": "^20.0.0", + "dotenv": "^16.4.5", + "tsx": "^4.19.2" + } + }, + "..": { + "name": "@mistralai/mistralai-gcp", + "version": "1.6.0", + "dependencies": { + "google-auth-library": "^9.11.0", + "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-gcp": { + "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-gcp/examples/package.json b/packages/mistralai-gcp/examples/package.json new file mode 100644 index 00000000..b980d03b --- /dev/null +++ b/packages/mistralai-gcp/examples/package.json @@ -0,0 +1,18 @@ +{ + "name": "@mistralai/mistralai-gcp-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-gcp": "file:.." + } +} \ No newline at end of file diff --git a/packages/mistralai-gcp/jsr.json b/packages/mistralai-gcp/jsr.json index 688a39b0..32b55540 100644 --- a/packages/mistralai-gcp/jsr.json +++ b/packages/mistralai-gcp/jsr.json @@ -2,7 +2,7 @@ { "name": "@mistralai/mistralai-gcp", - "version": "1.5.0", + "version": "1.6.0", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/packages/mistralai-gcp/package-lock.json b/packages/mistralai-gcp/package-lock.json index ff6c97d9..1c2d0942 100644 --- a/packages/mistralai-gcp/package-lock.json +++ b/packages/mistralai-gcp/package-lock.json @@ -1,25 +1,22 @@ { "name": "@mistralai/mistralai-gcp", - "version": "1.5.0", + "version": "1.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mistralai/mistralai-gcp", - "version": "1.5.0", + "version": "1.6.0", "dependencies": { - "google-auth-library": "^9.11.0" + "google-auth-library": "^9.11.0", + "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": { @@ -1835,9 +1832,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": { @@ -2111,7 +2108,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-gcp/package.json b/packages/mistralai-gcp/package.json index 61cc55ec..b314b125 100644 --- a/packages/mistralai-gcp/package.json +++ b/packages/mistralai-gcp/package.json @@ -1,6 +1,6 @@ { "name": "@mistralai/mistralai-gcp", - "version": "1.5.0", + "version": "1.6.0", "author": "Speakeasy", "main": "./index.js", "sideEffects": false, @@ -15,17 +15,17 @@ "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": { - "google-auth-library": "^9.11.0" + "google-auth-library": "^9.11.0", + "zod": "^3.20.0" } } diff --git a/packages/mistralai-gcp/src/funcs/chatComplete.ts b/packages/mistralai-gcp/src/funcs/chatComplete.ts index 6f565e80..9af42d36 100644 --- a/packages/mistralai-gcp/src/funcs/chatComplete.ts +++ b/packages/mistralai-gcp/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 { MistralGoogleCloudError } from "../models/errors/mistralgoogleclouderror.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 + | MistralGoogleCloudError + | 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 + | MistralGoogleCloudError + | 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 + | MistralGoogleCloudError + | 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-gcp/src/funcs/chatStream.ts b/packages/mistralai-gcp/src/funcs/chatStream.ts index 4af0db73..3db29167 100644 --- a/packages/mistralai-gcp/src/funcs/chatStream.ts +++ b/packages/mistralai-gcp/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 { MistralGoogleCloudError } from "../models/errors/mistralgoogleclouderror.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 + | MistralGoogleCloudError + | 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 + | MistralGoogleCloudError + | 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 + | MistralGoogleCloudError + | 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-gcp/src/funcs/fimComplete.ts b/packages/mistralai-gcp/src/funcs/fimComplete.ts index 97ba6173..9884401c 100644 --- a/packages/mistralai-gcp/src/funcs/fimComplete.ts +++ b/packages/mistralai-gcp/src/funcs/fimComplete.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 { MistralGoogleCloudError } from "../models/errors/mistralgoogleclouderror.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"; @@ -38,13 +39,14 @@ export function fimComplete( Result< components.FIMCompletionResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralGoogleCloudError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError > > { return new APIPromise($do( @@ -63,13 +65,14 @@ async function $do( Result< components.FIMCompletionResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralGoogleCloudError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >, APICall, ] @@ -97,6 +100,7 @@ async function $do( const requestSecurity = resolveGlobalSecurity(securityInput); const context = { + options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "fim_completion_v1_fim_completions_post", oAuth2Scopes: [], @@ -117,6 +121,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) { @@ -142,19 +147,20 @@ async function $do( const [result] = await M.match< components.FIMCompletionResponse, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralGoogleCloudError + | ResponseValidationError + | ConnectionError | RequestAbortedError | RequestTimeoutError - | ConnectionError + | InvalidRequestError + | UnexpectedClientError + | SDKValidationError >( M.json(200, components.FIMCompletionResponse$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-gcp/src/funcs/fimStream.ts b/packages/mistralai-gcp/src/funcs/fimStream.ts index 435fc95a..753ce012 100644 --- a/packages/mistralai-gcp/src/funcs/fimStream.ts +++ b/packages/mistralai-gcp/src/funcs/fimStream.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 { MistralGoogleCloudError } from "../models/errors/mistralgoogleclouderror.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 fimStream( Result< EventStream, | errors.HTTPValidationError - | SDKError - | SDKValidationError - | UnexpectedClientError - | InvalidRequestError + | MistralGoogleCloudError + | 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 + | MistralGoogleCloudError + | 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_fim", 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 + | MistralGoogleCloudError + | 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-gcp/src/hooks/types.ts b/packages/mistralai-gcp/src/hooks/types.ts index f34898c0..8bfe4fe8 100644 --- a/packages/mistralai-gcp/src/hooks/types.ts +++ b/packages/mistralai-gcp/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-gcp/src/index.ts b/packages/mistralai-gcp/src/index.ts index 5ddc765e..dbcba164 100644 --- a/packages/mistralai-gcp/src/index.ts +++ b/packages/mistralai-gcp/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-gcp/src/lib/config.ts b/packages/mistralai-gcp/src/lib/config.ts index 78896fda..76896c43 100644 --- a/packages/mistralai-gcp/src/lib/config.ts +++ b/packages/mistralai-gcp/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 */ @@ -54,9 +58,9 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", - openapiDocVersion: "0.0.2", - sdkVersion: "1.5.0", - genVersion: "2.548.6", + openapiDocVersion: "1.0.0", + sdkVersion: "1.6.0", + genVersion: "2.687.13", userAgent: - "speakeasy-sdk/typescript 1.5.0 2.548.6 0.0.2 @mistralai/mistralai-gcp", + "speakeasy-sdk/typescript 1.6.0 2.687.13 1.0.0 @mistralai/mistralai-gcp", } as const; diff --git a/packages/mistralai-gcp/src/lib/event-streams.ts b/packages/mistralai-gcp/src/lib/event-streams.ts index 2ab114f2..d14c6e7d 100644 --- a/packages/mistralai-gcp/src/lib/event-streams.ts +++ b/packages/mistralai-gcp/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-gcp/src/lib/files.ts b/packages/mistralai-gcp/src/lib/files.ts index 59d15f09..0344cd04 100644 --- a/packages/mistralai-gcp/src/lib/files.ts +++ b/packages/mistralai-gcp/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-gcp/src/lib/matchers.ts b/packages/mistralai-gcp/src/lib/matchers.ts index f8ec5c3c..5e2e60be 100644 --- a/packages/mistralai-gcp/src/lib/matchers.ts +++ b/packages/mistralai-gcp/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-gcp/src/lib/sdks.ts b/packages/mistralai-gcp/src/lib/sdks.ts index 0b0f2d63..bdb1f37c 100644 --- a/packages/mistralai-gcp/src/lib/sdks.ts +++ b/packages/mistralai-gcp/src/lib/sdks.ts @@ -46,12 +46,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; @@ -62,6 +64,7 @@ type RequestConfig = { headers?: HeadersInit; security?: SecurityState | null; uaHeader?: string; + userAgent?: string | undefined; timeoutMs?: number; }; @@ -93,19 +96,21 @@ export class ClientSDK { } else { this.#hooks = new SDKHooks(); } - this._options = { ...options, hooks: this.#hooks }; - const url = serverURLFromOptions(options); if (url) { url.pathname = url.pathname.replace(/\/+$/, "") + "/"; } + const { baseURL, client } = this.#hooks.sdkInit({ baseURL: url, client: options.httpClient || new HTTPClient(), }); this._baseURL = baseURL; this.#httpClient = client; - this.#logger = options.debugLogger; + + this._options = { ...options, hooks: this.#hooks }; + + this.#logger = this._options.debugLogger; } public _createRequest( @@ -168,7 +173,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); } @@ -176,23 +183,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" }); } @@ -298,7 +304,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; @@ -364,9 +372,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-gcp/src/lib/security.ts b/packages/mistralai-gcp/src/lib/security.ts index 4879498d..af334ba8 100644 --- a/packages/mistralai-gcp/src/lib/security.ts +++ b/packages/mistralai-gcp/src/lib/security.ts @@ -3,10 +3,11 @@ */ import * as components from "../models/components/index.js"; + type OAuth2PasswordFlow = { username: string; - password?: string | undefined; - clientID: string; + password: string; + clientID?: string | undefined; clientSecret?: string | undefined; tokenURL: string; }; @@ -82,9 +83,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 = { @@ -93,13 +99,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 = @@ -136,6 +142,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; @@ -224,7 +233,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-gcp/src/models/components/chatcompletionrequest.ts b/packages/mistralai-gcp/src/models/components/chatcompletionrequest.ts index fec42342..ec86f4c9 100644 --- a/packages/mistralai-gcp/src/models/components/chatcompletionrequest.ts +++ b/packages/mistralai-gcp/src/models/components/chatcompletionrequest.ts @@ -13,6 +13,11 @@ import { AssistantMessage$Outbound, AssistantMessage$outboundSchema, } from "./assistantmessage.js"; +import { + MistralPromptMode, + MistralPromptMode$inboundSchema, + MistralPromptMode$outboundSchema, +} from "./mistralpromptmode.js"; import { Prediction, Prediction$inboundSchema, @@ -68,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; @@ -108,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; @@ -129,6 +134,10 @@ export type ChatCompletionRequest = { n?: number | null | undefined; prediction?: Prediction | undefined; parallelToolCalls?: boolean | undefined; + /** + * Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used. + */ + promptMode?: MistralPromptMode | null | undefined; }; /** @internal */ @@ -190,6 +199,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 })), ), @@ -198,17 +210,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< @@ -221,6 +230,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 })), ), @@ -229,9 +241,6 @@ export const ChatCompletionRequestMessages$outboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$outboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), - ), ]); /** @@ -339,6 +348,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, @@ -349,11 +363,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(), @@ -365,6 +374,7 @@ export const ChatCompletionRequest$inboundSchema: z.ZodType< n: z.nullable(z.number().int()).optional(), prediction: Prediction$inboundSchema.optional(), parallel_tool_calls: z.boolean().optional(), + prompt_mode: z.nullable(MistralPromptMode$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "top_p": "topP", @@ -375,6 +385,7 @@ export const ChatCompletionRequest$inboundSchema: z.ZodType< "presence_penalty": "presencePenalty", "frequency_penalty": "frequencyPenalty", "parallel_tool_calls": "parallelToolCalls", + "prompt_mode": "promptMode", }); }); @@ -389,9 +400,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; @@ -401,6 +412,7 @@ export type ChatCompletionRequest$Outbound = { n?: number | null | undefined; prediction?: Prediction$Outbound | undefined; parallel_tool_calls?: boolean | undefined; + prompt_mode?: string | null | undefined; }; /** @internal */ @@ -423,6 +435,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, @@ -433,11 +450,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(), @@ -451,6 +463,7 @@ export const ChatCompletionRequest$outboundSchema: z.ZodType< n: z.nullable(z.number().int()).optional(), prediction: Prediction$outboundSchema.optional(), parallelToolCalls: z.boolean().optional(), + promptMode: z.nullable(MistralPromptMode$outboundSchema).optional(), }).transform((v) => { return remap$(v, { topP: "top_p", @@ -461,6 +474,7 @@ export const ChatCompletionRequest$outboundSchema: z.ZodType< presencePenalty: "presence_penalty", frequencyPenalty: "frequency_penalty", parallelToolCalls: "parallel_tool_calls", + promptMode: "prompt_mode", }); }); diff --git a/packages/mistralai-gcp/src/models/components/chatcompletionresponse.ts b/packages/mistralai-gcp/src/models/components/chatcompletionresponse.ts index 68e70738..941fcf6c 100644 --- a/packages/mistralai-gcp/src/models/components/chatcompletionresponse.ts +++ b/packages/mistralai-gcp/src/models/components/chatcompletionresponse.ts @@ -24,8 +24,8 @@ export type ChatCompletionResponse = { object: string; model: string; usage: UsageInfo; - created?: number | undefined; - choices?: Array | undefined; + created: number; + choices: Array; }; /** @internal */ @@ -38,8 +38,8 @@ export const ChatCompletionResponse$inboundSchema: z.ZodType< object: z.string(), model: z.string(), usage: UsageInfo$inboundSchema, - created: z.number().int().optional(), - choices: z.array(ChatCompletionChoice$inboundSchema).optional(), + created: z.number().int(), + choices: z.array(ChatCompletionChoice$inboundSchema), }); /** @internal */ @@ -48,8 +48,8 @@ export type ChatCompletionResponse$Outbound = { object: string; model: string; usage: UsageInfo$Outbound; - created?: number | undefined; - choices?: Array | undefined; + created: number; + choices: Array; }; /** @internal */ @@ -62,8 +62,8 @@ export const ChatCompletionResponse$outboundSchema: z.ZodType< object: z.string(), model: z.string(), usage: UsageInfo$outboundSchema, - created: z.number().int().optional(), - choices: z.array(ChatCompletionChoice$outboundSchema).optional(), + created: z.number().int(), + choices: z.array(ChatCompletionChoice$outboundSchema), }); /** diff --git a/packages/mistralai-gcp/src/models/components/chatcompletionstreamrequest.ts b/packages/mistralai-gcp/src/models/components/chatcompletionstreamrequest.ts index 8dff0388..ce59bea5 100644 --- a/packages/mistralai-gcp/src/models/components/chatcompletionstreamrequest.ts +++ b/packages/mistralai-gcp/src/models/components/chatcompletionstreamrequest.ts @@ -13,6 +13,11 @@ import { AssistantMessage$Outbound, AssistantMessage$outboundSchema, } from "./assistantmessage.js"; +import { + MistralPromptMode, + MistralPromptMode$inboundSchema, + MistralPromptMode$outboundSchema, +} from "./mistralpromptmode.js"; import { Prediction, Prediction$inboundSchema, @@ -68,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; @@ -105,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; @@ -126,6 +131,10 @@ export type ChatCompletionStreamRequest = { n?: number | null | undefined; prediction?: Prediction | undefined; parallelToolCalls?: boolean | undefined; + /** + * Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used. + */ + promptMode?: MistralPromptMode | null | undefined; }; /** @internal */ @@ -177,6 +186,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 })), ), @@ -185,17 +197,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< @@ -208,6 +217,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 })), ), @@ -216,9 +228,6 @@ export const Messages$outboundSchema: z.ZodType< role: v.role, })), ), - ToolMessage$outboundSchema.and( - z.object({ role: z.literal("tool") }).transform((v) => ({ role: v.role })), - ), ]); /** @@ -323,6 +332,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, @@ -333,11 +347,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(), @@ -349,6 +358,7 @@ export const ChatCompletionStreamRequest$inboundSchema: z.ZodType< n: z.nullable(z.number().int()).optional(), prediction: Prediction$inboundSchema.optional(), parallel_tool_calls: z.boolean().optional(), + prompt_mode: z.nullable(MistralPromptMode$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "top_p": "topP", @@ -359,6 +369,7 @@ export const ChatCompletionStreamRequest$inboundSchema: z.ZodType< "presence_penalty": "presencePenalty", "frequency_penalty": "frequencyPenalty", "parallel_tool_calls": "parallelToolCalls", + "prompt_mode": "promptMode", }); }); @@ -373,9 +384,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; @@ -385,6 +396,7 @@ export type ChatCompletionStreamRequest$Outbound = { n?: number | null | undefined; prediction?: Prediction$Outbound | undefined; parallel_tool_calls?: boolean | undefined; + prompt_mode?: string | null | undefined; }; /** @internal */ @@ -407,6 +419,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, @@ -417,11 +434,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(), @@ -435,6 +447,7 @@ export const ChatCompletionStreamRequest$outboundSchema: z.ZodType< n: z.nullable(z.number().int()).optional(), prediction: Prediction$outboundSchema.optional(), parallelToolCalls: z.boolean().optional(), + promptMode: z.nullable(MistralPromptMode$outboundSchema).optional(), }).transform((v) => { return remap$(v, { topP: "top_p", @@ -445,6 +458,7 @@ export const ChatCompletionStreamRequest$outboundSchema: z.ZodType< presencePenalty: "presence_penalty", frequencyPenalty: "frequency_penalty", parallelToolCalls: "parallel_tool_calls", + promptMode: "prompt_mode", }); }); diff --git a/packages/mistralai-gcp/src/models/components/fimcompletionresponse.ts b/packages/mistralai-gcp/src/models/components/fimcompletionresponse.ts index 9f3e3095..3877623e 100644 --- a/packages/mistralai-gcp/src/models/components/fimcompletionresponse.ts +++ b/packages/mistralai-gcp/src/models/components/fimcompletionresponse.ts @@ -24,8 +24,8 @@ export type FIMCompletionResponse = { object: string; model: string; usage: UsageInfo; - created?: number | undefined; - choices?: Array | undefined; + created: number; + choices: Array; }; /** @internal */ @@ -38,8 +38,8 @@ export const FIMCompletionResponse$inboundSchema: z.ZodType< object: z.string(), model: z.string(), usage: UsageInfo$inboundSchema, - created: z.number().int().optional(), - choices: z.array(ChatCompletionChoice$inboundSchema).optional(), + created: z.number().int(), + choices: z.array(ChatCompletionChoice$inboundSchema), }); /** @internal */ @@ -48,8 +48,8 @@ export type FIMCompletionResponse$Outbound = { object: string; model: string; usage: UsageInfo$Outbound; - created?: number | undefined; - choices?: Array | undefined; + created: number; + choices: Array; }; /** @internal */ @@ -62,8 +62,8 @@ export const FIMCompletionResponse$outboundSchema: z.ZodType< object: z.string(), model: z.string(), usage: UsageInfo$outboundSchema, - created: z.number().int().optional(), - choices: z.array(ChatCompletionChoice$outboundSchema).optional(), + created: z.number().int(), + choices: z.array(ChatCompletionChoice$outboundSchema), }); /** diff --git a/packages/mistralai-gcp/src/models/components/index.ts b/packages/mistralai-gcp/src/models/components/index.ts index 54155d4c..552bf528 100644 --- a/packages/mistralai-gcp/src/models/components/index.ts +++ b/packages/mistralai-gcp/src/models/components/index.ts @@ -21,13 +21,16 @@ export * from "./functionname.js"; export * from "./imageurl.js"; export * from "./imageurlchunk.js"; export * from "./jsonschema.js"; +export * from "./mistralpromptmode.js"; export * from "./prediction.js"; export * from "./referencechunk.js"; 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-gcp/src/models/components/mistralpromptmode.ts b/packages/mistralai-gcp/src/models/components/mistralpromptmode.ts new file mode 100644 index 00000000..b17c1e2e --- /dev/null +++ b/packages/mistralai-gcp/src/models/components/mistralpromptmode.ts @@ -0,0 +1,47 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { + catchUnrecognizedEnum, + OpenEnum, + Unrecognized, +} from "../../types/enums.js"; + +export const MistralPromptMode = { + Reasoning: "reasoning", +} as const; +export type MistralPromptMode = OpenEnum; + +/** @internal */ +export const MistralPromptMode$inboundSchema: z.ZodType< + MistralPromptMode, + z.ZodTypeDef, + unknown +> = z + .union([ + z.nativeEnum(MistralPromptMode), + z.string().transform(catchUnrecognizedEnum), + ]); + +/** @internal */ +export const MistralPromptMode$outboundSchema: z.ZodType< + MistralPromptMode, + z.ZodTypeDef, + MistralPromptMode +> = z.union([ + z.nativeEnum(MistralPromptMode), + z.string().and(z.custom>()), +]); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace MistralPromptMode$ { + /** @deprecated use `MistralPromptMode$inboundSchema` instead. */ + export const inboundSchema = MistralPromptMode$inboundSchema; + /** @deprecated use `MistralPromptMode$outboundSchema` instead. */ + export const outboundSchema = MistralPromptMode$outboundSchema; +} diff --git a/packages/mistralai-gcp/src/models/components/systemmessage.ts b/packages/mistralai-gcp/src/models/components/systemmessage.ts index a911a012..838daf4a 100644 --- a/packages/mistralai-gcp/src/models/components/systemmessage.ts +++ b/packages/mistralai-gcp/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-gcp/src/models/components/systemmessagecontentchunks.ts b/packages/mistralai-gcp/src/models/components/systemmessagecontentchunks.ts new file mode 100644 index 00000000..c02ec0bc --- /dev/null +++ b/packages/mistralai-gcp/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-gcp/src/models/components/thinkchunk.ts b/packages/mistralai-gcp/src/models/components/thinkchunk.ts new file mode 100644 index 00000000..2e09c78d --- /dev/null +++ b/packages/mistralai-gcp/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-gcp/src/models/components/usageinfo.ts b/packages/mistralai-gcp/src/models/components/usageinfo.ts index f6e8f62c..021789d1 100644 --- a/packages/mistralai-gcp/src/models/components/usageinfo.ts +++ b/packages/mistralai-gcp/src/models/components/usageinfo.ts @@ -4,14 +4,19 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; -import { safeParse } from "../../lib/schemas.js"; +import { + collectExtraKeys as collectExtraKeys$, + safeParse, +} from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type UsageInfo = { - promptTokens: number; - completionTokens: number; - totalTokens: number; + promptTokens?: number | undefined; + completionTokens?: number | undefined; + totalTokens?: number | undefined; + promptAudioSeconds?: number | null | undefined; + additionalProperties?: { [k: string]: any }; }; /** @internal */ @@ -19,15 +24,21 @@ export const UsageInfo$inboundSchema: z.ZodType< UsageInfo, z.ZodTypeDef, unknown -> = z.object({ - prompt_tokens: z.number().int(), - completion_tokens: z.number().int(), - total_tokens: z.number().int(), -}).transform((v) => { +> = collectExtraKeys$( + z.object({ + prompt_tokens: z.number().int().default(0), + completion_tokens: z.number().int().default(0), + total_tokens: z.number().int().default(0), + prompt_audio_seconds: z.nullable(z.number().int()).optional(), + }).catchall(z.any()), + "additionalProperties", + true, +).transform((v) => { return remap$(v, { "prompt_tokens": "promptTokens", "completion_tokens": "completionTokens", "total_tokens": "totalTokens", + "prompt_audio_seconds": "promptAudioSeconds", }); }); @@ -36,6 +47,8 @@ export type UsageInfo$Outbound = { prompt_tokens: number; completion_tokens: number; total_tokens: number; + prompt_audio_seconds?: number | null | undefined; + [additionalProperties: string]: unknown; }; /** @internal */ @@ -44,15 +57,22 @@ export const UsageInfo$outboundSchema: z.ZodType< z.ZodTypeDef, UsageInfo > = z.object({ - promptTokens: z.number().int(), - completionTokens: z.number().int(), - totalTokens: z.number().int(), + promptTokens: z.number().int().default(0), + completionTokens: z.number().int().default(0), + totalTokens: z.number().int().default(0), + promptAudioSeconds: z.nullable(z.number().int()).optional(), + additionalProperties: z.record(z.any()), }).transform((v) => { - return remap$(v, { - promptTokens: "prompt_tokens", - completionTokens: "completion_tokens", - totalTokens: "total_tokens", - }); + return { + ...v.additionalProperties, + ...remap$(v, { + promptTokens: "prompt_tokens", + completionTokens: "completion_tokens", + totalTokens: "total_tokens", + promptAudioSeconds: "prompt_audio_seconds", + additionalProperties: null, + }), + }; }); /** diff --git a/packages/mistralai-gcp/src/models/errors/httpvalidationerror.ts b/packages/mistralai-gcp/src/models/errors/httpvalidationerror.ts index d9a58dc8..ea8da2fc 100644 --- a/packages/mistralai-gcp/src/models/errors/httpvalidationerror.ts +++ b/packages/mistralai-gcp/src/models/errors/httpvalidationerror.ts @@ -4,24 +4,27 @@ import * as z from "zod"; import * as components from "../components/index.js"; +import { MistralGoogleCloudError } from "./mistralgoogleclouderror.js"; export type HTTPValidationErrorData = { detail?: Array | undefined; }; -export class HTTPValidationError extends Error { +export class HTTPValidationError extends MistralGoogleCloudError { 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-gcp/src/models/errors/index.ts b/packages/mistralai-gcp/src/models/errors/index.ts index 8a5df29e..8692ad30 100644 --- a/packages/mistralai-gcp/src/models/errors/index.ts +++ b/packages/mistralai-gcp/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-gcp/src/models/errors/mistralgoogleclouderror.ts b/packages/mistralai-gcp/src/models/errors/mistralgoogleclouderror.ts new file mode 100644 index 00000000..2b9e3e7f --- /dev/null +++ b/packages/mistralai-gcp/src/models/errors/mistralgoogleclouderror.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 MistralGoogleCloudError 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 = "MistralGoogleCloudError"; + } +} diff --git a/packages/mistralai-gcp/src/models/errors/responsevalidationerror.ts b/packages/mistralai-gcp/src/models/errors/responsevalidationerror.ts new file mode 100644 index 00000000..d082250a --- /dev/null +++ b/packages/mistralai-gcp/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 { MistralGoogleCloudError } from "./mistralgoogleclouderror.js"; +import { formatZodError } from "./sdkvalidationerror.js"; + +export class ResponseValidationError extends MistralGoogleCloudError { + /** + * 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-gcp/src/models/errors/sdkerror.ts b/packages/mistralai-gcp/src/models/errors/sdkerror.ts index 001f4659..e2969792 100644 --- a/packages/mistralai-gcp/src/models/errors/sdkerror.ts +++ b/packages/mistralai-gcp/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 { MistralGoogleCloudError } from "./mistralgoogleclouderror.js"; +/** The fallback error class if no more specific error class is matched */ +export class SDKError extends MistralGoogleCloudError { 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-gcp/src/models/errors/sdkvalidationerror.ts b/packages/mistralai-gcp/src/models/errors/sdkvalidationerror.ts index 16929b9e..37face8a 100644 --- a/packages/mistralai-gcp/src/models/errors/sdkvalidationerror.ts +++ b/packages/mistralai-gcp/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-gcp/src/types/constdatetime.ts b/packages/mistralai-gcp/src/types/constdatetime.ts index c0a4409c..eeff4dde 100644 --- a/packages/mistralai-gcp/src/types/constdatetime.ts +++ b/packages/mistralai-gcp/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}`); }