diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 64b42c3..7264403 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -2,11 +2,11 @@ speakeasyVersion: 1.451.1 sources: mistral-azure-source: sourceNamespace: mistral-azure-source - sourceRevisionDigest: sha256:c441f2d21e7879f5fb9d8d99e2ae242d1e5a84c0c06db971911eb578173e7f62 - sourceBlobDigest: sha256:de4af0f100f15fef89e093a6b5393302b2218fb154230594ec811aacdd4f2ec7 + sourceRevisionDigest: sha256:9c35eed0174f2d8165807bcd7c8e7b7111fa97c059a77ae7eeaa352ca7e83b4d + sourceBlobDigest: sha256:07283bfde08363f9f69b133888b482472c4bf12d2e5b59cb33c8993c517278e3 tags: - latest - - main + - speakeasy-sdk-regen-1733304480 mistral-google-cloud-source: sourceNamespace: mistral-google-cloud-source sourceRevisionDigest: sha256:e0fd58ce2dbba068f375d3a23d758b8678c2a68cf4fc7bc46ea7e1b37abe0647 @@ -25,10 +25,10 @@ targets: mistralai-azure-sdk: source: mistral-azure-source sourceNamespace: mistral-azure-source - sourceRevisionDigest: sha256:c441f2d21e7879f5fb9d8d99e2ae242d1e5a84c0c06db971911eb578173e7f62 - sourceBlobDigest: sha256:de4af0f100f15fef89e093a6b5393302b2218fb154230594ec811aacdd4f2ec7 + sourceRevisionDigest: sha256:9c35eed0174f2d8165807bcd7c8e7b7111fa97c059a77ae7eeaa352ca7e83b4d + sourceBlobDigest: sha256:07283bfde08363f9f69b133888b482472c4bf12d2e5b59cb33c8993c517278e3 codeSamplesNamespace: mistral-openapi-azure-code-samples - codeSamplesRevisionDigest: sha256:e986a6f674fde2807db8383cdfefc9229cc4df98276918d60a5f4189ce07fb98 + codeSamplesRevisionDigest: sha256:1918c360fdb31c721fbc4e47a1b54530ba8deb526e638c9e61f039027343696f mistralai-gcp-sdk: source: mistral-google-cloud-source sourceNamespace: mistral-google-cloud-source diff --git a/packages/mistralai-azure/.speakeasy/gen.lock b/packages/mistralai-azure/.speakeasy/gen.lock index 48d8974..71f4a86 100644 --- a/packages/mistralai-azure/.speakeasy/gen.lock +++ b/packages/mistralai-azure/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 01e8a40b-3df3-4d9a-9501-2eb9e0d26c05 management: - docChecksum: d0000cbe03848bfe843794965cba332f + docChecksum: 26271aa279a7a7182f7af19df8b67038 docVersion: 0.0.2 - speakeasyVersion: 1.438.1 - generationVersion: 2.457.2 - releaseVersion: 1.3.4 - configChecksum: c701bbf71f3977510ce625c672b31284 + speakeasyVersion: 1.451.1 + generationVersion: 2.470.1 + releaseVersion: 1.3.5 + configChecksum: e32b498a394ce6079f7bced9cced33b5 repoURL: https://github.com/mistralai/client-ts.git repoSubDirectory: packages/mistralai-azure installationURL: https://gitpkg.now.sh/mistralai/client-ts/packages/mistralai-azure @@ -15,7 +15,7 @@ features: typescript: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.11 - core: 3.18.3 + core: 3.18.8 defaultEnabledRetries: 0.1.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.1.2 @@ -33,7 +33,6 @@ features: serverEvents: 0.1.5 serverEventsSentinels: 0.1.0 serverIDs: 2.81.2 - tests: 0.7.0 unions: 2.85.8 generatedFiles: - .eslintrc.cjs @@ -176,3 +175,4 @@ examples: "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, "finish_reason": "stop"}, {"index": 0, "finish_reason": "stop"}, {"index": 0, "finish_reason": "stop"}]} "422": {} +generatedTests: {} diff --git a/packages/mistralai-azure/.speakeasy/gen.yaml b/packages/mistralai-azure/.speakeasy/gen.yaml index da0a24d..36fa901 100644 --- a/packages/mistralai-azure/.speakeasy/gen.yaml +++ b/packages/mistralai-azure/.speakeasy/gen.yaml @@ -22,6 +22,7 @@ typescript: author: Speakeasy clientServerStatusCodesAsErrors: true defaultErrorName: SDKError + enableReactQuery: false enumFormat: union envVarPrefix: MISTRAL flattenGlobalSecurity: true diff --git a/packages/mistralai-azure/RELEASES.md b/packages/mistralai-azure/RELEASES.md index bf65bb5..6bc95bc 100644 --- a/packages/mistralai-azure/RELEASES.md +++ b/packages/mistralai-azure/RELEASES.md @@ -78,4 +78,14 @@ Based on: ### Generated - [typescript v1.3.4] packages/mistralai-azure ### Releases -- [NPM v1.3.4] https://www.npmjs.com/package/@mistralai/mistralai-azure/v/1.3.4 - packages/mistralai-azure \ No newline at end of file +- [NPM v1.3.4] https://www.npmjs.com/package/@mistralai/mistralai-azure/v/1.3.4 - packages/mistralai-azure + +## 2024-12-04 09:27:57 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.451.1 (2.470.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v1.3.5] packages/mistralai-azure +### Releases +- [NPM v1.3.5] https://www.npmjs.com/package/@mistralai/mistralai-azure/v/1.3.5 - packages/mistralai-azure \ No newline at end of file diff --git a/packages/mistralai-azure/docs/models/components/referencechunk.md b/packages/mistralai-azure/docs/models/components/referencechunk.md index a0e9c95..ef4a1f2 100644 --- a/packages/mistralai-azure/docs/models/components/referencechunk.md +++ b/packages/mistralai-azure/docs/models/components/referencechunk.md @@ -16,5 +16,5 @@ let value: ReferenceChunk = { | Field | Type | Required | Description | | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | -| `type` | [components.ReferenceChunkType](../../models/components/referencechunktype.md) | :heavy_minus_sign: | N/A | -| `referenceIds` | *number*[] | :heavy_check_mark: | N/A | \ No newline at end of file +| `referenceIds` | *number*[] | :heavy_check_mark: | N/A | +| `type` | [components.ReferenceChunkType](../../models/components/referencechunktype.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/packages/mistralai-azure/docs/models/components/textchunk.md b/packages/mistralai-azure/docs/models/components/textchunk.md index 26770f7..326a175 100644 --- a/packages/mistralai-azure/docs/models/components/textchunk.md +++ b/packages/mistralai-azure/docs/models/components/textchunk.md @@ -14,5 +14,5 @@ let value: TextChunk = { | Field | Type | Required | Description | | -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- | -------------------------------------------------- | -| `type` | [components.Type](../../models/components/type.md) | :heavy_minus_sign: | N/A | -| `text` | *string* | :heavy_check_mark: | N/A | \ No newline at end of file +| `text` | *string* | :heavy_check_mark: | N/A | +| `type` | [components.Type](../../models/components/type.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/packages/mistralai-azure/jsr.json b/packages/mistralai-azure/jsr.json index dd327c8..438a47f 100644 --- a/packages/mistralai-azure/jsr.json +++ b/packages/mistralai-azure/jsr.json @@ -2,7 +2,7 @@ { "name": "@mistralai/mistralai-azure", - "version": "1.3.4", + "version": "1.3.5", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/packages/mistralai-azure/package-lock.json b/packages/mistralai-azure/package-lock.json index 4a53c75..9ce537c 100644 --- a/packages/mistralai-azure/package-lock.json +++ b/packages/mistralai-azure/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mistralai/mistralai-azure", - "version": "1.3.4", + "version": "1.3.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mistralai/mistralai-azure", - "version": "1.3.4", + "version": "1.3.5", "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", @@ -17,6 +17,8 @@ "zod": "^3.23.4" }, "peerDependencies": { + "react": "^18 || ^19", + "react-dom": "^18 || ^19", "zod": ">= 3" } }, @@ -2216,6 +2218,13 @@ "dev": true, "license": "ISC" }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "license": "MIT", + "peer": true + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -2310,6 +2319,19 @@ "dev": true, "license": "MIT" }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2652,6 +2674,33 @@ ], "license": "MIT" }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-dom": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "license": "MIT", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" + }, + "peerDependencies": { + "react": "^18.3.1" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -2798,6 +2847,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/scheduler": { + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", diff --git a/packages/mistralai-azure/package.json b/packages/mistralai-azure/package.json index 47b434b..80cff18 100644 --- a/packages/mistralai-azure/package.json +++ b/packages/mistralai-azure/package.json @@ -1,6 +1,6 @@ { "name": "@mistralai/mistralai-azure", - "version": "1.3.4", + "version": "1.3.5", "author": "Speakeasy", "main": "./index.js", "sideEffects": false, @@ -15,6 +15,8 @@ "prepublishOnly": "npm run build" }, "peerDependencies": { + "react": "^18 || ^19", + "react-dom": "^18 || ^19", "zod": ">= 3" }, "devDependencies": { diff --git a/packages/mistralai-azure/src/lib/config.ts b/packages/mistralai-azure/src/lib/config.ts index ae356b9..95b7aff 100644 --- a/packages/mistralai-azure/src/lib/config.ts +++ b/packages/mistralai-azure/src/lib/config.ts @@ -55,8 +55,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "0.0.2", - sdkVersion: "1.3.4", - genVersion: "2.457.2", + sdkVersion: "1.3.5", + genVersion: "2.470.1", userAgent: - "speakeasy-sdk/typescript 1.3.4 2.457.2 0.0.2 @mistralai/mistralai-azure", + "speakeasy-sdk/typescript 1.3.5 2.470.1 0.0.2 @mistralai/mistralai-azure", } as const; diff --git a/packages/mistralai-azure/src/lib/matchers.ts b/packages/mistralai-azure/src/lib/matchers.ts index 2258907..f8ec5c3 100644 --- a/packages/mistralai-azure/src/lib/matchers.ts +++ b/packages/mistralai-azure/src/lib/matchers.ts @@ -206,7 +206,7 @@ export function match( raw = await response.json(); break; case "bytes": - raw = await response.arrayBuffer(); + raw = new Uint8Array(await response.arrayBuffer()); break; case "stream": raw = response.body; diff --git a/packages/mistralai-azure/src/lib/primitives.ts b/packages/mistralai-azure/src/lib/primitives.ts index 48b2867..1dc4ee4 100644 --- a/packages/mistralai-azure/src/lib/primitives.ts +++ b/packages/mistralai-azure/src/lib/primitives.ts @@ -58,3 +58,65 @@ export function remap< return out; } + +export function combineSignals( + ...signals: Array +): AbortSignal | null { + const filtered: AbortSignal[] = []; + for (const signal of signals) { + if (signal) { + filtered.push(signal); + } + } + + switch (filtered.length) { + case 0: + case 1: + return filtered[0] || null; + default: + if ("any" in AbortSignal && typeof AbortSignal.any === "function") { + return AbortSignal.any(filtered); + } + return abortSignalAny(filtered); + } +} + +export function abortSignalAny(signals: AbortSignal[]): AbortSignal { + const controller = new AbortController(); + const result = controller.signal; + if (!signals.length) { + return controller.signal; + } + + if (signals.length === 1) { + return signals[0] || controller.signal; + } + + for (const signal of signals) { + if (signal.aborted) { + return signal; + } + } + + function abort(this: AbortSignal) { + controller.abort(this.reason); + clean(); + } + + const signalRefs: WeakRef[] = []; + function clean() { + for (const signalRef of signalRefs) { + const signal = signalRef.deref(); + if (signal) { + signal.removeEventListener("abort", abort); + } + } + } + + for (const signal of signals) { + signalRefs.push(new WeakRef(signal)); + signal.addEventListener("abort", abort); + } + + return result; +} diff --git a/packages/mistralai-azure/src/models/components/assistantmessage.ts b/packages/mistralai-azure/src/models/components/assistantmessage.ts index c0b7260..5a136c6 100644 --- a/packages/mistralai-azure/src/models/components/assistantmessage.ts +++ b/packages/mistralai-azure/src/models/components/assistantmessage.ts @@ -4,7 +4,10 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +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 { ContentChunk, ContentChunk$inboundSchema, @@ -64,6 +67,24 @@ export namespace AssistantMessageContent$ { export type Outbound = AssistantMessageContent$Outbound; } +export function assistantMessageContentToJSON( + assistantMessageContent: AssistantMessageContent, +): string { + return JSON.stringify( + AssistantMessageContent$outboundSchema.parse(assistantMessageContent), + ); +} + +export function assistantMessageContentFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => AssistantMessageContent$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'AssistantMessageContent' from JSON`, + ); +} + /** @internal */ export const AssistantMessageRole$inboundSchema: z.ZodNativeEnum< typeof AssistantMessageRole @@ -141,3 +162,21 @@ export namespace AssistantMessage$ { /** @deprecated use `AssistantMessage$Outbound` instead. */ export type Outbound = AssistantMessage$Outbound; } + +export function assistantMessageToJSON( + assistantMessage: AssistantMessage, +): string { + return JSON.stringify( + AssistantMessage$outboundSchema.parse(assistantMessage), + ); +} + +export function assistantMessageFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => AssistantMessage$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'AssistantMessage' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/chatcompletionchoice.ts b/packages/mistralai-azure/src/models/components/chatcompletionchoice.ts index 074f8e1..899d720 100644 --- a/packages/mistralai-azure/src/models/components/chatcompletionchoice.ts +++ b/packages/mistralai-azure/src/models/components/chatcompletionchoice.ts @@ -4,11 +4,14 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; import { catchUnrecognizedEnum, OpenEnum, Unrecognized, } from "../../types/enums.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { AssistantMessage, AssistantMessage$inboundSchema, @@ -114,3 +117,21 @@ export namespace ChatCompletionChoice$ { /** @deprecated use `ChatCompletionChoice$Outbound` instead. */ export type Outbound = ChatCompletionChoice$Outbound; } + +export function chatCompletionChoiceToJSON( + chatCompletionChoice: ChatCompletionChoice, +): string { + return JSON.stringify( + ChatCompletionChoice$outboundSchema.parse(chatCompletionChoice), + ); +} + +export function chatCompletionChoiceFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionChoice$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionChoice' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts b/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts index 7cf9033..7032582 100644 --- a/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts +++ b/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts @@ -4,6 +4,9 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { AssistantMessage, AssistantMessage$inboundSchema, @@ -154,6 +157,24 @@ export namespace ChatCompletionRequestStop$ { export type Outbound = ChatCompletionRequestStop$Outbound; } +export function chatCompletionRequestStopToJSON( + chatCompletionRequestStop: ChatCompletionRequestStop, +): string { + return JSON.stringify( + ChatCompletionRequestStop$outboundSchema.parse(chatCompletionRequestStop), + ); +} + +export function chatCompletionRequestStopFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionRequestStop$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionRequestStop' from JSON`, + ); +} + /** @internal */ export const ChatCompletionRequestMessages$inboundSchema: z.ZodType< ChatCompletionRequestMessages, @@ -222,6 +243,26 @@ export namespace ChatCompletionRequestMessages$ { export type Outbound = ChatCompletionRequestMessages$Outbound; } +export function chatCompletionRequestMessagesToJSON( + chatCompletionRequestMessages: ChatCompletionRequestMessages, +): string { + return JSON.stringify( + ChatCompletionRequestMessages$outboundSchema.parse( + chatCompletionRequestMessages, + ), + ); +} + +export function chatCompletionRequestMessagesFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionRequestMessages$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionRequestMessages' from JSON`, + ); +} + /** @internal */ export const ChatCompletionRequestToolChoice$inboundSchema: z.ZodType< ChatCompletionRequestToolChoice, @@ -254,6 +295,26 @@ export namespace ChatCompletionRequestToolChoice$ { export type Outbound = ChatCompletionRequestToolChoice$Outbound; } +export function chatCompletionRequestToolChoiceToJSON( + chatCompletionRequestToolChoice: ChatCompletionRequestToolChoice, +): string { + return JSON.stringify( + ChatCompletionRequestToolChoice$outboundSchema.parse( + chatCompletionRequestToolChoice, + ), + ); +} + +export function chatCompletionRequestToolChoiceFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionRequestToolChoice$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionRequestToolChoice' from JSON`, + ); +} + /** @internal */ export const ChatCompletionRequest$inboundSchema: z.ZodType< ChatCompletionRequest, @@ -408,3 +469,21 @@ export namespace ChatCompletionRequest$ { /** @deprecated use `ChatCompletionRequest$Outbound` instead. */ export type Outbound = ChatCompletionRequest$Outbound; } + +export function chatCompletionRequestToJSON( + chatCompletionRequest: ChatCompletionRequest, +): string { + return JSON.stringify( + ChatCompletionRequest$outboundSchema.parse(chatCompletionRequest), + ); +} + +export function chatCompletionRequestFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionRequest$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionRequest' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/chatcompletionresponse.ts b/packages/mistralai-azure/src/models/components/chatcompletionresponse.ts index 44c9daa..68e7073 100644 --- a/packages/mistralai-azure/src/models/components/chatcompletionresponse.ts +++ b/packages/mistralai-azure/src/models/components/chatcompletionresponse.ts @@ -3,6 +3,9 @@ */ 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 { ChatCompletionChoice, ChatCompletionChoice$inboundSchema, @@ -75,3 +78,21 @@ export namespace ChatCompletionResponse$ { /** @deprecated use `ChatCompletionResponse$Outbound` instead. */ export type Outbound = ChatCompletionResponse$Outbound; } + +export function chatCompletionResponseToJSON( + chatCompletionResponse: ChatCompletionResponse, +): string { + return JSON.stringify( + ChatCompletionResponse$outboundSchema.parse(chatCompletionResponse), + ); +} + +export function chatCompletionResponseFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionResponse$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionResponse' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts b/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts index 5e9f6bf..9ee52f2 100644 --- a/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts +++ b/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts @@ -4,6 +4,9 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { AssistantMessage, AssistantMessage$inboundSchema, @@ -145,6 +148,20 @@ export namespace Stop$ { export type Outbound = Stop$Outbound; } +export function stopToJSON(stop: Stop): string { + return JSON.stringify(Stop$outboundSchema.parse(stop)); +} + +export function stopFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Stop$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Stop' from JSON`, + ); +} + /** @internal */ export const Messages$inboundSchema: z.ZodType< Messages, @@ -213,6 +230,20 @@ export namespace Messages$ { export type Outbound = Messages$Outbound; } +export function messagesToJSON(messages: Messages): string { + return JSON.stringify(Messages$outboundSchema.parse(messages)); +} + +export function messagesFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Messages$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Messages' from JSON`, + ); +} + /** @internal */ export const ChatCompletionStreamRequestToolChoice$inboundSchema: z.ZodType< ChatCompletionStreamRequestToolChoice, @@ -247,6 +278,27 @@ export namespace ChatCompletionStreamRequestToolChoice$ { export type Outbound = ChatCompletionStreamRequestToolChoice$Outbound; } +export function chatCompletionStreamRequestToolChoiceToJSON( + chatCompletionStreamRequestToolChoice: ChatCompletionStreamRequestToolChoice, +): string { + return JSON.stringify( + ChatCompletionStreamRequestToolChoice$outboundSchema.parse( + chatCompletionStreamRequestToolChoice, + ), + ); +} + +export function chatCompletionStreamRequestToolChoiceFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => + ChatCompletionStreamRequestToolChoice$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionStreamRequestToolChoice' from JSON`, + ); +} + /** @internal */ export const ChatCompletionStreamRequest$inboundSchema: z.ZodType< ChatCompletionStreamRequest, @@ -401,3 +453,23 @@ export namespace ChatCompletionStreamRequest$ { /** @deprecated use `ChatCompletionStreamRequest$Outbound` instead. */ export type Outbound = ChatCompletionStreamRequest$Outbound; } + +export function chatCompletionStreamRequestToJSON( + chatCompletionStreamRequest: ChatCompletionStreamRequest, +): string { + return JSON.stringify( + ChatCompletionStreamRequest$outboundSchema.parse( + chatCompletionStreamRequest, + ), + ); +} + +export function chatCompletionStreamRequestFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ChatCompletionStreamRequest$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ChatCompletionStreamRequest' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/completionchunk.ts b/packages/mistralai-azure/src/models/components/completionchunk.ts index 796d5e2..31e0089 100644 --- a/packages/mistralai-azure/src/models/components/completionchunk.ts +++ b/packages/mistralai-azure/src/models/components/completionchunk.ts @@ -3,6 +3,9 @@ */ 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 { CompletionResponseStreamChoice, CompletionResponseStreamChoice$inboundSchema, @@ -75,3 +78,19 @@ export namespace CompletionChunk$ { /** @deprecated use `CompletionChunk$Outbound` instead. */ export type Outbound = CompletionChunk$Outbound; } + +export function completionChunkToJSON( + completionChunk: CompletionChunk, +): string { + return JSON.stringify(CompletionChunk$outboundSchema.parse(completionChunk)); +} + +export function completionChunkFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CompletionChunk$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CompletionChunk' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/completionevent.ts b/packages/mistralai-azure/src/models/components/completionevent.ts index 9662e4c..b377901 100644 --- a/packages/mistralai-azure/src/models/components/completionevent.ts +++ b/packages/mistralai-azure/src/models/components/completionevent.ts @@ -3,6 +3,9 @@ */ 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 { CompletionChunk, CompletionChunk$inboundSchema, @@ -59,3 +62,19 @@ export namespace CompletionEvent$ { /** @deprecated use `CompletionEvent$Outbound` instead. */ export type Outbound = CompletionEvent$Outbound; } + +export function completionEventToJSON( + completionEvent: CompletionEvent, +): string { + return JSON.stringify(CompletionEvent$outboundSchema.parse(completionEvent)); +} + +export function completionEventFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CompletionEvent$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CompletionEvent' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/completionresponsestreamchoice.ts b/packages/mistralai-azure/src/models/components/completionresponsestreamchoice.ts index ac61d7b..323645c 100644 --- a/packages/mistralai-azure/src/models/components/completionresponsestreamchoice.ts +++ b/packages/mistralai-azure/src/models/components/completionresponsestreamchoice.ts @@ -4,11 +4,14 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; import { catchUnrecognizedEnum, OpenEnum, Unrecognized, } from "../../types/enums.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { DeltaMessage, DeltaMessage$inboundSchema, @@ -111,3 +114,23 @@ export namespace CompletionResponseStreamChoice$ { /** @deprecated use `CompletionResponseStreamChoice$Outbound` instead. */ export type Outbound = CompletionResponseStreamChoice$Outbound; } + +export function completionResponseStreamChoiceToJSON( + completionResponseStreamChoice: CompletionResponseStreamChoice, +): string { + return JSON.stringify( + CompletionResponseStreamChoice$outboundSchema.parse( + completionResponseStreamChoice, + ), + ); +} + +export function completionResponseStreamChoiceFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => CompletionResponseStreamChoice$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'CompletionResponseStreamChoice' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/contentchunk.ts b/packages/mistralai-azure/src/models/components/contentchunk.ts index ba2c8ab..ebf2c76 100644 --- a/packages/mistralai-azure/src/models/components/contentchunk.ts +++ b/packages/mistralai-azure/src/models/components/contentchunk.ts @@ -3,6 +3,9 @@ */ 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 { ReferenceChunk, ReferenceChunk$inboundSchema, @@ -69,3 +72,17 @@ export namespace ContentChunk$ { /** @deprecated use `ContentChunk$Outbound` instead. */ export type Outbound = ContentChunk$Outbound; } + +export function contentChunkToJSON(contentChunk: ContentChunk): string { + return JSON.stringify(ContentChunk$outboundSchema.parse(contentChunk)); +} + +export function contentChunkFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ContentChunk$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ContentChunk' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/deltamessage.ts b/packages/mistralai-azure/src/models/components/deltamessage.ts index e9b3c0f..f01a3bf 100644 --- a/packages/mistralai-azure/src/models/components/deltamessage.ts +++ b/packages/mistralai-azure/src/models/components/deltamessage.ts @@ -4,6 +4,9 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { ContentChunk, ContentChunk$inboundSchema, @@ -52,6 +55,20 @@ export namespace Content$ { export type Outbound = Content$Outbound; } +export function contentToJSON(content: Content): string { + return JSON.stringify(Content$outboundSchema.parse(content)); +} + +export function contentFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Content$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Content' from JSON`, + ); +} + /** @internal */ export const DeltaMessage$inboundSchema: z.ZodType< DeltaMessage, @@ -105,3 +122,17 @@ export namespace DeltaMessage$ { /** @deprecated use `DeltaMessage$Outbound` instead. */ export type Outbound = DeltaMessage$Outbound; } + +export function deltaMessageToJSON(deltaMessage: DeltaMessage): string { + return JSON.stringify(DeltaMessage$outboundSchema.parse(deltaMessage)); +} + +export function deltaMessageFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => DeltaMessage$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'DeltaMessage' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/function.ts b/packages/mistralai-azure/src/models/components/function.ts index d40b990..aa1f93c 100644 --- a/packages/mistralai-azure/src/models/components/function.ts +++ b/packages/mistralai-azure/src/models/components/function.ts @@ -3,6 +3,9 @@ */ 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"; export type FunctionT = { name: string; @@ -51,3 +54,17 @@ export namespace FunctionT$ { /** @deprecated use `FunctionT$Outbound` instead. */ export type Outbound = FunctionT$Outbound; } + +export function functionToJSON(functionT: FunctionT): string { + return JSON.stringify(FunctionT$outboundSchema.parse(functionT)); +} + +export function functionFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => FunctionT$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'FunctionT' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/functioncall.ts b/packages/mistralai-azure/src/models/components/functioncall.ts index e7d9653..ffaa036 100644 --- a/packages/mistralai-azure/src/models/components/functioncall.ts +++ b/packages/mistralai-azure/src/models/components/functioncall.ts @@ -3,6 +3,9 @@ */ 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"; export type Arguments = { [k: string]: any } | string; @@ -41,6 +44,20 @@ export namespace Arguments$ { export type Outbound = Arguments$Outbound; } +export function argumentsToJSON(value: Arguments): string { + return JSON.stringify(Arguments$outboundSchema.parse(value)); +} + +export function argumentsFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Arguments$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Arguments' from JSON`, + ); +} + /** @internal */ export const FunctionCall$inboundSchema: z.ZodType< FunctionCall, @@ -79,3 +96,17 @@ export namespace FunctionCall$ { /** @deprecated use `FunctionCall$Outbound` instead. */ export type Outbound = FunctionCall$Outbound; } + +export function functionCallToJSON(functionCall: FunctionCall): string { + return JSON.stringify(FunctionCall$outboundSchema.parse(functionCall)); +} + +export function functionCallFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => FunctionCall$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'FunctionCall' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/functionname.ts b/packages/mistralai-azure/src/models/components/functionname.ts index 59e3962..e262790 100644 --- a/packages/mistralai-azure/src/models/components/functionname.ts +++ b/packages/mistralai-azure/src/models/components/functionname.ts @@ -3,6 +3,9 @@ */ 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"; /** * this restriction of `Function` is used to select a specific function to call @@ -46,3 +49,17 @@ export namespace FunctionName$ { /** @deprecated use `FunctionName$Outbound` instead. */ export type Outbound = FunctionName$Outbound; } + +export function functionNameToJSON(functionName: FunctionName): string { + return JSON.stringify(FunctionName$outboundSchema.parse(functionName)); +} + +export function functionNameFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => FunctionName$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'FunctionName' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/referencechunk.ts b/packages/mistralai-azure/src/models/components/referencechunk.ts index d245ce3..9085d7b 100644 --- a/packages/mistralai-azure/src/models/components/referencechunk.ts +++ b/packages/mistralai-azure/src/models/components/referencechunk.ts @@ -4,7 +4,10 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +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"; export const ReferenceChunkType = { Reference: "reference", @@ -12,8 +15,8 @@ export const ReferenceChunkType = { export type ReferenceChunkType = ClosedEnum; export type ReferenceChunk = { - type?: "reference" | undefined; referenceIds: Array; + type?: ReferenceChunkType | undefined; }; /** @internal */ @@ -43,8 +46,8 @@ export const ReferenceChunk$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.object({ - type: z.literal("reference").default("reference"), reference_ids: z.array(z.number().int()), + type: ReferenceChunkType$inboundSchema.default("reference"), }).transform((v) => { return remap$(v, { "reference_ids": "referenceIds", @@ -53,8 +56,8 @@ export const ReferenceChunk$inboundSchema: z.ZodType< /** @internal */ export type ReferenceChunk$Outbound = { - type: "reference"; reference_ids: Array; + type: string; }; /** @internal */ @@ -63,8 +66,8 @@ export const ReferenceChunk$outboundSchema: z.ZodType< z.ZodTypeDef, ReferenceChunk > = z.object({ - type: z.literal("reference").default("reference"), referenceIds: z.array(z.number().int()), + type: ReferenceChunkType$outboundSchema.default("reference"), }).transform((v) => { return remap$(v, { referenceIds: "reference_ids", @@ -83,3 +86,17 @@ export namespace ReferenceChunk$ { /** @deprecated use `ReferenceChunk$Outbound` instead. */ export type Outbound = ReferenceChunk$Outbound; } + +export function referenceChunkToJSON(referenceChunk: ReferenceChunk): string { + return JSON.stringify(ReferenceChunk$outboundSchema.parse(referenceChunk)); +} + +export function referenceChunkFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ReferenceChunk$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ReferenceChunk' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/responseformat.ts b/packages/mistralai-azure/src/models/components/responseformat.ts index b836bf7..c541776 100644 --- a/packages/mistralai-azure/src/models/components/responseformat.ts +++ b/packages/mistralai-azure/src/models/components/responseformat.ts @@ -3,6 +3,9 @@ */ 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 { ResponseFormats, ResponseFormats$inboundSchema, @@ -51,3 +54,17 @@ export namespace ResponseFormat$ { /** @deprecated use `ResponseFormat$Outbound` instead. */ export type Outbound = ResponseFormat$Outbound; } + +export function responseFormatToJSON(responseFormat: ResponseFormat): string { + return JSON.stringify(ResponseFormat$outboundSchema.parse(responseFormat)); +} + +export function responseFormatFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ResponseFormat$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ResponseFormat' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/security.ts b/packages/mistralai-azure/src/models/components/security.ts index caf4fcf..494b49a 100644 --- a/packages/mistralai-azure/src/models/components/security.ts +++ b/packages/mistralai-azure/src/models/components/security.ts @@ -4,6 +4,9 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type Security = { apiKey?: string | undefined; @@ -52,3 +55,17 @@ export namespace Security$ { /** @deprecated use `Security$Outbound` instead. */ export type Outbound = Security$Outbound; } + +export function securityToJSON(security: Security): string { + return JSON.stringify(Security$outboundSchema.parse(security)); +} + +export function securityFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Security$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Security' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/systemmessage.ts b/packages/mistralai-azure/src/models/components/systemmessage.ts index b9f94b1..a911a01 100644 --- a/packages/mistralai-azure/src/models/components/systemmessage.ts +++ b/packages/mistralai-azure/src/models/components/systemmessage.ts @@ -3,7 +3,10 @@ */ 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 { TextChunk, TextChunk$inboundSchema, @@ -53,6 +56,24 @@ export namespace SystemMessageContent$ { export type Outbound = SystemMessageContent$Outbound; } +export function systemMessageContentToJSON( + systemMessageContent: SystemMessageContent, +): string { + return JSON.stringify( + SystemMessageContent$outboundSchema.parse(systemMessageContent), + ); +} + +export function systemMessageContentFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => SystemMessageContent$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'SystemMessageContent' from JSON`, + ); +} + /** @internal */ export const Role$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Role, @@ -111,3 +132,17 @@ export namespace SystemMessage$ { /** @deprecated use `SystemMessage$Outbound` instead. */ export type Outbound = SystemMessage$Outbound; } + +export function systemMessageToJSON(systemMessage: SystemMessage): string { + return JSON.stringify(SystemMessage$outboundSchema.parse(systemMessage)); +} + +export function systemMessageFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => SystemMessage$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'SystemMessage' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/textchunk.ts b/packages/mistralai-azure/src/models/components/textchunk.ts index 456e0fd..aa0afb6 100644 --- a/packages/mistralai-azure/src/models/components/textchunk.ts +++ b/packages/mistralai-azure/src/models/components/textchunk.ts @@ -3,7 +3,10 @@ */ 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"; export const Type = { Text: "text", @@ -11,8 +14,8 @@ export const Type = { export type Type = ClosedEnum; export type TextChunk = { - type?: "text" | undefined; text: string; + type?: Type | undefined; }; /** @internal */ @@ -41,14 +44,14 @@ export const TextChunk$inboundSchema: z.ZodType< z.ZodTypeDef, unknown > = z.object({ - type: z.literal("text").default("text"), text: z.string(), + type: Type$inboundSchema.default("text"), }); /** @internal */ export type TextChunk$Outbound = { - type: "text"; text: string; + type: string; }; /** @internal */ @@ -57,8 +60,8 @@ export const TextChunk$outboundSchema: z.ZodType< z.ZodTypeDef, TextChunk > = z.object({ - type: z.literal("text").default("text"), text: z.string(), + type: Type$outboundSchema.default("text"), }); /** @@ -73,3 +76,17 @@ export namespace TextChunk$ { /** @deprecated use `TextChunk$Outbound` instead. */ export type Outbound = TextChunk$Outbound; } + +export function textChunkToJSON(textChunk: TextChunk): string { + return JSON.stringify(TextChunk$outboundSchema.parse(textChunk)); +} + +export function textChunkFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => TextChunk$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'TextChunk' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/tool.ts b/packages/mistralai-azure/src/models/components/tool.ts index e0c5d31..0e1a73c 100644 --- a/packages/mistralai-azure/src/models/components/tool.ts +++ b/packages/mistralai-azure/src/models/components/tool.ts @@ -3,6 +3,9 @@ */ 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 { FunctionT, FunctionT$inboundSchema, @@ -52,3 +55,17 @@ export namespace Tool$ { /** @deprecated use `Tool$Outbound` instead. */ export type Outbound = Tool$Outbound; } + +export function toolToJSON(tool: Tool): string { + return JSON.stringify(Tool$outboundSchema.parse(tool)); +} + +export function toolFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Tool$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Tool' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/toolcall.ts b/packages/mistralai-azure/src/models/components/toolcall.ts index 75d8f2b..4f4f22a 100644 --- a/packages/mistralai-azure/src/models/components/toolcall.ts +++ b/packages/mistralai-azure/src/models/components/toolcall.ts @@ -3,6 +3,9 @@ */ 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 { FunctionCall, FunctionCall$inboundSchema, @@ -62,3 +65,17 @@ export namespace ToolCall$ { /** @deprecated use `ToolCall$Outbound` instead. */ export type Outbound = ToolCall$Outbound; } + +export function toolCallToJSON(toolCall: ToolCall): string { + return JSON.stringify(ToolCall$outboundSchema.parse(toolCall)); +} + +export function toolCallFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ToolCall$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ToolCall' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/toolchoice.ts b/packages/mistralai-azure/src/models/components/toolchoice.ts index c96e4e0..6813816 100644 --- a/packages/mistralai-azure/src/models/components/toolchoice.ts +++ b/packages/mistralai-azure/src/models/components/toolchoice.ts @@ -3,6 +3,9 @@ */ 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 { FunctionName, FunctionName$inboundSchema, @@ -64,3 +67,17 @@ export namespace ToolChoice$ { /** @deprecated use `ToolChoice$Outbound` instead. */ export type Outbound = ToolChoice$Outbound; } + +export function toolChoiceToJSON(toolChoice: ToolChoice): string { + return JSON.stringify(ToolChoice$outboundSchema.parse(toolChoice)); +} + +export function toolChoiceFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ToolChoice$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ToolChoice' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/toolmessage.ts b/packages/mistralai-azure/src/models/components/toolmessage.ts index fd923fe..a343e40 100644 --- a/packages/mistralai-azure/src/models/components/toolmessage.ts +++ b/packages/mistralai-azure/src/models/components/toolmessage.ts @@ -4,7 +4,10 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +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 { ContentChunk, ContentChunk$inboundSchema, @@ -56,6 +59,24 @@ export namespace ToolMessageContent$ { export type Outbound = ToolMessageContent$Outbound; } +export function toolMessageContentToJSON( + toolMessageContent: ToolMessageContent, +): string { + return JSON.stringify( + ToolMessageContent$outboundSchema.parse(toolMessageContent), + ); +} + +export function toolMessageContentFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ToolMessageContent$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ToolMessageContent' from JSON`, + ); +} + /** @internal */ export const ToolMessageRole$inboundSchema: z.ZodNativeEnum< typeof ToolMessageRole @@ -133,3 +154,17 @@ export namespace ToolMessage$ { /** @deprecated use `ToolMessage$Outbound` instead. */ export type Outbound = ToolMessage$Outbound; } + +export function toolMessageToJSON(toolMessage: ToolMessage): string { + return JSON.stringify(ToolMessage$outboundSchema.parse(toolMessage)); +} + +export function toolMessageFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ToolMessage$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ToolMessage' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/usageinfo.ts b/packages/mistralai-azure/src/models/components/usageinfo.ts index 2480339..f6e8f62 100644 --- a/packages/mistralai-azure/src/models/components/usageinfo.ts +++ b/packages/mistralai-azure/src/models/components/usageinfo.ts @@ -4,6 +4,9 @@ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; export type UsageInfo = { promptTokens: number; @@ -64,3 +67,17 @@ export namespace UsageInfo$ { /** @deprecated use `UsageInfo$Outbound` instead. */ export type Outbound = UsageInfo$Outbound; } + +export function usageInfoToJSON(usageInfo: UsageInfo): string { + return JSON.stringify(UsageInfo$outboundSchema.parse(usageInfo)); +} + +export function usageInfoFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => UsageInfo$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'UsageInfo' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/usermessage.ts b/packages/mistralai-azure/src/models/components/usermessage.ts index 6f0a2cc..e74a20d 100644 --- a/packages/mistralai-azure/src/models/components/usermessage.ts +++ b/packages/mistralai-azure/src/models/components/usermessage.ts @@ -3,7 +3,10 @@ */ 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 { ContentChunk, ContentChunk$inboundSchema, @@ -53,6 +56,24 @@ export namespace UserMessageContent$ { export type Outbound = UserMessageContent$Outbound; } +export function userMessageContentToJSON( + userMessageContent: UserMessageContent, +): string { + return JSON.stringify( + UserMessageContent$outboundSchema.parse(userMessageContent), + ); +} + +export function userMessageContentFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => UserMessageContent$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'UserMessageContent' from JSON`, + ); +} + /** @internal */ export const UserMessageRole$inboundSchema: z.ZodNativeEnum< typeof UserMessageRole @@ -116,3 +137,17 @@ export namespace UserMessage$ { /** @deprecated use `UserMessage$Outbound` instead. */ export type Outbound = UserMessage$Outbound; } + +export function userMessageToJSON(userMessage: UserMessage): string { + return JSON.stringify(UserMessage$outboundSchema.parse(userMessage)); +} + +export function userMessageFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => UserMessage$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'UserMessage' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/models/components/validationerror.ts b/packages/mistralai-azure/src/models/components/validationerror.ts index bfe2a68..9072a89 100644 --- a/packages/mistralai-azure/src/models/components/validationerror.ts +++ b/packages/mistralai-azure/src/models/components/validationerror.ts @@ -3,6 +3,9 @@ */ 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"; export type Loc = string | number; @@ -37,6 +40,20 @@ export namespace Loc$ { export type Outbound = Loc$Outbound; } +export function locToJSON(loc: Loc): string { + return JSON.stringify(Loc$outboundSchema.parse(loc)); +} + +export function locFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => Loc$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'Loc' from JSON`, + ); +} + /** @internal */ export const ValidationError$inboundSchema: z.ZodType< ValidationError, @@ -78,3 +95,19 @@ export namespace ValidationError$ { /** @deprecated use `ValidationError$Outbound` instead. */ export type Outbound = ValidationError$Outbound; } + +export function validationErrorToJSON( + validationError: ValidationError, +): string { + return JSON.stringify(ValidationError$outboundSchema.parse(validationError)); +} + +export function validationErrorFromJSON( + jsonString: string, +): SafeParseResult { + return safeParse( + jsonString, + (x) => ValidationError$inboundSchema.parse(JSON.parse(x)), + `Failed to parse 'ValidationError' from JSON`, + ); +} diff --git a/packages/mistralai-azure/src/types/operations.ts b/packages/mistralai-azure/src/types/operations.ts index 0952f6f..beb81e1 100644 --- a/packages/mistralai-azure/src/types/operations.ts +++ b/packages/mistralai-azure/src/types/operations.ts @@ -6,9 +6,10 @@ import { Result } from "./fp.js"; export type Paginator = () => Promise }> | null; -export type PageIterator = V & { +export type PageIterator = V & { next: Paginator; [Symbol.asyncIterator]: () => AsyncIterableIterator; + "~next"?: PageState | undefined; }; export function createPageIterator( @@ -40,7 +41,9 @@ export function createPageIterator( * terminates. It is useful in paginated SDK functions that have early return * paths when things go wrong. */ -export function haltIterator(v: V): PageIterator { +export function haltIterator( + v: V, +): PageIterator { return { ...v, next: () => null, @@ -54,9 +57,9 @@ export function haltIterator(v: V): PageIterator { * Converts an async iterator of `Result` into an async iterator of `V`. * When error results occur, the underlying error value is thrown. */ -export async function unwrapResultIterator( - iteratorPromise: Promise>>, -): Promise> { +export async function unwrapResultIterator( + iteratorPromise: Promise, PageState>>, +): Promise> { const resultIter = await iteratorPromise; if (!resultIter.ok) { @@ -66,6 +69,7 @@ export async function unwrapResultIterator( return { ...resultIter.value, next: unwrapPaginator(resultIter.next), + "~next": resultIter["~next"], [Symbol.asyncIterator]: async function* paginator() { for await (const page of resultIter) { if (!page.ok) { @@ -97,3 +101,5 @@ function unwrapPaginator( }); }; } + +export const URL_OVERRIDE = Symbol("URL_OVERRIDE"); diff --git a/packages/mistralai-azure/tsconfig.json b/packages/mistralai-azure/tsconfig.json index 7a86d2d..f9d286a 100644 --- a/packages/mistralai-azure/tsconfig.json +++ b/packages/mistralai-azure/tsconfig.json @@ -4,6 +4,7 @@ "tsBuildInfoFile": ".tsbuildinfo", "target": "ES2018", "lib": ["ES2022", "DOM", "DOM.Iterable"], + "jsx": "react-jsx", "module": "Node16", "moduleResolution": "Node16",