@ai-sdk/azure 4.0.86 → 4.0.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @ai-sdk/azure
2
2
 
3
+ ## 4.0.89
4
+
5
+ ### Patch Changes
6
+
7
+ - d08102b: Add test coverage for `resourceName` validation edge cases: labels at the 63-character limit, underscores, non-ASCII characters, and invalid `AZURE_RESOURCE_NAME` values for non-language models.
8
+
9
+ ## 4.0.88
10
+
11
+ ### Patch Changes
12
+
13
+ - 560ac0b: Route `mai-transcribe-1.5` to the Azure Speech API by default, like `mai-transcribe-2`. MAI-Transcribe-1.5 requests no longer send the `segment` timestamps default, which the model rejects.
14
+ - 00f2a59: Add MAI-Voice-2-Flash and MAI-Voice-2 speech generation through `azure.speech()` using Azure Speech text to speech (SSML), with voice, output format, speed, and `style`/`styleDegree` provider options. `language` picks a default voice when no voice is set. Select the API with `providerOptions.azure.api` to override model-based routing, and add `azure.speechModel()` as an alias of `azure.speech()`.
15
+
16
+ ## 4.0.87
17
+
18
+ ### Patch Changes
19
+
20
+ - 527a163: fix: validate hostname parts using `isValidHostnamePart`
21
+ - Updated dependencies [8c65988]
22
+ - Updated dependencies [527a163]
23
+ - @ai-sdk/provider@4.0.21
24
+ - @ai-sdk/provider-utils@5.0.53
25
+ - @ai-sdk/openai@4.0.83
26
+ - @ai-sdk/deepseek@3.0.58
27
+
3
28
  ## 4.0.86
4
29
 
5
30
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -60,8 +60,8 @@ interface AzureOpenAIProvider extends ProviderV4 {
60
60
  */
61
61
  imageModel(deploymentId: string): ImageModelV4;
62
62
  /**
63
- * Creates an Azure transcription model. MAI-Transcribe-2 uses the Speech API
64
- * by default; other IDs use OpenAI. Override with providerOptions.azure.api.
63
+ * Creates an Azure transcription model. MAI-Transcribe models use the Speech
64
+ * API by default; other IDs use OpenAI. Override with providerOptions.azure.api.
65
65
  */
66
66
  transcription(deploymentId: string): TranscriptionModelV4;
67
67
  /**
@@ -69,9 +69,14 @@ interface AzureOpenAIProvider extends ProviderV4 {
69
69
  */
70
70
  transcriptionModel(deploymentId: string): TranscriptionModelV4;
71
71
  /**
72
- * Creates an Azure OpenAI model for speech generation.
72
+ * Creates an Azure speech generation model. MAI-Voice models use the Speech
73
+ * API by default; other IDs use OpenAI. Override with providerOptions.azure.api.
73
74
  */
74
75
  speech(deploymentId: string): SpeechModelV4;
76
+ /**
77
+ * Creates an Azure speech generation model. Alias of `speech`.
78
+ */
79
+ speechModel(deploymentId: string): SpeechModelV4;
75
80
  /**
76
81
  * AzureOpenAI-specific tools.
77
82
  */
@@ -125,8 +130,9 @@ interface AzureOpenAIProviderSettings {
125
130
  */
126
131
  useDeploymentBasedUrls?: boolean;
127
132
  /**
128
- * URL prefix for Azure Speech transcription (MAI-Transcribe-2), e.g. a
129
- * regional endpoint like `https://eastus.api.cognitive.microsoft.com`.
133
+ * URL prefix for Azure Speech (MAI-Transcribe transcription and MAI-Voice
134
+ * speech), e.g. a regional endpoint like
135
+ * `https://eastus.api.cognitive.microsoft.com`.
130
136
  * Defaults to `https://{resourceName}.cognitiveservices.azure.com`.
131
137
  * Speech requests do not use `baseURL` or `apiVersion`.
132
138
  */
@@ -158,6 +164,14 @@ type AzureResponsesSourceDocumentProviderMetadata = {
158
164
  //#region src/version.d.ts
159
165
  export declare const VERSION: string;
160
166
  //#endregion
167
+ //#region src/azure-speech-model-options.d.ts
168
+ declare const azureSpeechModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
169
+ style?: string | undefined;
170
+ styleDegree?: number | undefined;
171
+ api?: "openai" | "speech" | undefined;
172
+ }>;
173
+ type AzureSpeechModelOptions = InferSchema<typeof azureSpeechModelOptions>;
174
+ //#endregion
161
175
  //#region src/azure-transcription-model-options.d.ts
162
176
  declare const azureTranscriptionModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
163
177
  timestamps?: "word" | "segment" | "none" | undefined;
@@ -197,5 +211,5 @@ export type AzureDeepSeekLanguageModelOptions = Omit<DeepSeekLanguageModelChatOp
197
211
  /** @deprecated Use `AzureDeepSeekLanguageModelOptions` instead. */
198
212
  export type AzureDeepSeekChatOptions = AzureDeepSeekLanguageModelOptions;
199
213
  //#endregion
200
- export type { AzureOpenAIProvider, AzureOpenAIProviderSettings, AzureResponsesProviderMetadata, AzureResponsesReasoningProviderMetadata, AzureResponsesSourceDocumentProviderMetadata, AzureResponsesTextProviderMetadata, AzureTranscriptionModelOptions, AzureTranscriptionProviderMetadata, OpenAIChatLanguageModelOptions, OpenAILanguageModelChatOptions, OpenAILanguageModelResponsesOptions, OpenAIResponsesProviderOptions, OpenAIResponsesSystemMessageOptions };
214
+ export type { AzureOpenAIProvider, AzureOpenAIProviderSettings, AzureResponsesProviderMetadata, AzureResponsesReasoningProviderMetadata, AzureResponsesSourceDocumentProviderMetadata, AzureResponsesTextProviderMetadata, AzureSpeechModelOptions, AzureTranscriptionModelOptions, AzureTranscriptionProviderMetadata, OpenAIChatLanguageModelOptions, OpenAILanguageModelChatOptions, OpenAILanguageModelResponsesOptions, OpenAIResponsesProviderOptions, OpenAIResponsesSystemMessageOptions };
201
215
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/azure-openai-tools.ts","../src/azure-openai-provider.ts","../src/azure-openai-provider-metadata.ts","../src/version.ts","../src/azure-transcription-model-options.ts","../src/azure-transcription-provider-metadata.ts","../src/index.ts"],"mappings":";;;;;;cAQa;EACX,wBAAwB;EACxB,mBAAmB;EACnB,wBAAwB;EACxB,kBAAkB;EAClB,yBAAyB;;;;UC2BV,4BAA4B;GAC1C,uBAAuB;;;;EAKxB,cAAc,uBAAuB;;;;EAKrC,KAAK,uBAAuB;;;;EAK5B,SAAS,uBAAuB;;;;EAKhC,UAAU,uBAAuB;;;;EAKjC,WAAW,uBAAuB;;;;EAKlC,UAAU,uBAAuB;;;;EAKjC,eAAe,uBAAuB;;;;EAKtC,cAAc,uBAAuB;;;;EAKrC,mBAAmB,uBAAuB;;;;EAK1C,MAAM,uBAAuB;;;;EAK7B,WAAW,uBAAuB;;;;;EAMlC,cAAc,uBAAuB;;;;EAKrC,mBAAmB,uBAAuB;;;;EAK1C,OAAO,uBAAuB;;;;EAK9B,cAAc;;UAGC;;;;;;;EAOf;;;;;;;;;EAUA;;;;EAKA;;;;;;EAOA,uBAAuB;;;;EAKvB,UAAU;;;;;EAMV,QAAQ;;;;;EAMR;;;;;;EAOA;;;;;;;EAQA;;;;;wBAgCc,YACd,UAAS,8BACR;;;;qBAiOU,OAAK;;;KCjbN;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;;;qBClBI;;;cCMA,iEAA8B;;;;;;;;;;;;KAY/B,iCAAiC,mBACpC;;;KCrBG;EACV;IACE,SAAS;MACP;MACA;MACA;MACA;MACA;MACA;MACA,QAAQ;QACN;QACA;QACA;;;;;;;YCVI,oCAAoC,KAC9C;;YAIU,2BAA2B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/azure-openai-tools.ts","../src/azure-openai-provider.ts","../src/azure-openai-provider-metadata.ts","../src/version.ts","../src/azure-speech-model-options.ts","../src/azure-transcription-model-options.ts","../src/azure-transcription-provider-metadata.ts","../src/index.ts"],"mappings":";;;;;;cAQa;EACX,wBAAwB;EACxB,mBAAmB;EACnB,wBAAwB;EACxB,kBAAkB;EAClB,yBAAyB;;;;UCkCV,4BAA4B;GAC1C,uBAAuB;;;;EAKxB,cAAc,uBAAuB;;;;EAKrC,KAAK,uBAAuB;;;;EAK5B,SAAS,uBAAuB;;;;EAKhC,UAAU,uBAAuB;;;;EAKjC,WAAW,uBAAuB;;;;EAKlC,UAAU,uBAAuB;;;;EAKjC,eAAe,uBAAuB;;;;EAKtC,cAAc,uBAAuB;;;;EAKrC,mBAAmB,uBAAuB;;;;EAK1C,MAAM,uBAAuB;;;;EAK7B,WAAW,uBAAuB;;;;;EAMlC,cAAc,uBAAuB;;;;EAKrC,mBAAmB,uBAAuB;;;;;EAM1C,OAAO,uBAAuB;;;;EAK9B,YAAY,uBAAuB;;;;EAKnC,cAAc;;UAGC;;;;;;;EAOf;;;;;;;;;EAUA;;;;EAKA;;;;;;EAOA,uBAAuB;;;;EAKvB,UAAU;;;;;EAMV,QAAQ;;;;;EAMR;;;;;;EAOA;;;;;;;;EASA;;;;;wBAgCc,YACd,UAAS,8BACR;;;;qBA4OU,OAAK;;;KC1cN;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;;;qBClBI;;;cCMA,0DAAuB;;;;;KAYxB,0BAA0B,mBAC7B;;;cCbI,iEAA8B;;;;;;;;;;;;KAY/B,iCAAiC,mBACpC;;;KCrBG;EACV;IACE,SAAS;MACP;MACA;MACA;MACA;MACA;MACA;MACA,QAAQ;QACN;QACA;QACA;;;;;;;YCVI,oCAAoC,KAC9C;;YAIU,2BAA2B"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, codeInterpreter, fileSearch, imageGeneration, webSearch, webSearchPreview } from "@ai-sdk/openai/internal";
2
2
  import { DeepSeekChatLanguageModel } from "@ai-sdk/deepseek/internal";
3
- import { InvalidArgumentError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
4
- import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, createJsonErrorResponseHandler, createJsonResponseHandler, lazySchema, loadApiKey, loadSetting, mediaTypeToExtension, normalizeHeaders, parseProviderOptions, postFormDataToApi, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
3
+ import { APICallError, InvalidArgumentError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
4
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, createBinaryResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, extractResponseHeaders, isValidHostnamePart, lazySchema, loadApiKey, loadSetting, mediaTypeToExtension, normalizeHeaders, parseProviderOptions, postFormDataToApi, postToApi, safeParseJSON, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
5
5
  import { z } from "zod/v4";
6
6
  //#region src/azure-openai-tools.ts
7
7
  const azureOpenaiTools = {
@@ -12,6 +12,200 @@ const azureOpenaiTools = {
12
12
  webSearchPreview
13
13
  };
14
14
  //#endregion
15
+ //#region src/azure-speech-speech-model-options.ts
16
+ const azureSpeechSpeechModelOptionsShape = () => ({
17
+ /**
18
+ * Speaking style applied with `mstts:express-as`, e.g. `excited` or
19
+ * `whispering`. Supported styles vary by voice.
20
+ */
21
+ style: z.string().min(1).optional(),
22
+ /**
23
+ * Intensity of `style`, from 0.01 to 2. Azure defaults to 1.
24
+ */
25
+ styleDegree: z.number().min(.01).max(2).optional()
26
+ });
27
+ lazySchema(() => zodSchema(z.strictObject(azureSpeechSpeechModelOptionsShape())));
28
+ //#endregion
29
+ //#region src/azure-speech-model-options.ts
30
+ const azureSpeechModelOptions = lazySchema(() => zodSchema(z.strictObject({
31
+ /**
32
+ * API to use. Defaults to Speech for MAI-Voice models, OpenAI otherwise.
33
+ */
34
+ api: z.enum(["openai", "speech"]).optional(),
35
+ ...azureSpeechSpeechModelOptionsShape()
36
+ })));
37
+ const maiVoiceModels = /* @__PURE__ */ new Map([["mai-voice-2-flash", "MAI-Voice-2-Flash"], ["mai-voice-2", "MAI-Voice-2"]]);
38
+ function getMAIVoiceModel(modelId) {
39
+ return maiVoiceModels.get(modelId.toLowerCase());
40
+ }
41
+ //#endregion
42
+ //#region src/azure-speech-speech-model.ts
43
+ const DEFAULT_VOICE = "en-US-Harper";
44
+ const DEFAULT_VOICES = /* @__PURE__ */ new Map([
45
+ ["de", "de-DE-Mia"],
46
+ ["en", DEFAULT_VOICE],
47
+ ["es", "es-MX-Valeria"],
48
+ ["fr", "fr-FR-Soleil"],
49
+ ["hi", "hi-IN-Kavya"],
50
+ ["hu", "hu-HU-Lilla"],
51
+ ["it", "it-IT-Rosa"],
52
+ ["ko", "ko-KR-Haena"],
53
+ ["nl", "nl-NL-Fleur"],
54
+ ["pt", "pt-BR-Luana"],
55
+ ["ro", "ro-RO-Elena"],
56
+ ["ru", "ru-RU-Masha"],
57
+ ["th", "th-TH-Krit"],
58
+ ["tr", "tr-TR-Elif"],
59
+ ["zh", "zh-CN-Mei"]
60
+ ]);
61
+ const DEFAULT_OUTPUT_FORMAT = "audio-24khz-160kbitrate-mono-mp3";
62
+ const OUTPUT_FORMATS = /* @__PURE__ */ new Map([
63
+ ["mp3", DEFAULT_OUTPUT_FORMAT],
64
+ ["opus", "ogg-24khz-16bit-mono-opus"],
65
+ ["pcm", "raw-24khz-16bit-mono-pcm"],
66
+ ["wav", "riff-24khz-16bit-mono-pcm"]
67
+ ]);
68
+ const NATIVE_OUTPUT_FORMAT = /^(?:amr|audio|g722|ogg|raw|riff|webm)-[a-z0-9-]+$/;
69
+ /**
70
+ * Azure Speech text to speech with SSML. The model is appended to the voice
71
+ * name, e.g. `en-US-Harper:MAI-Voice-2`.
72
+ */
73
+ var AzureSpeechSpeechModel = class {
74
+ constructor(modelId, config) {
75
+ this.modelId = modelId;
76
+ this.config = config;
77
+ this.specificationVersion = "v4";
78
+ this.provider = "azure.speech";
79
+ }
80
+ async doGenerate(options, azureOptions = {}) {
81
+ const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
82
+ const warnings = [];
83
+ const { style, styleDegree } = azureOptions;
84
+ if (options.instructions != null) warnings.push({
85
+ type: "unsupported",
86
+ feature: "instructions",
87
+ details: "Use providerOptions.azure.style to control speaking style."
88
+ });
89
+ const { voice, languageWarning } = resolveVoice(options.voice, options.language);
90
+ if (languageWarning != null) warnings.push({
91
+ type: "unsupported",
92
+ feature: "language",
93
+ details: languageWarning
94
+ });
95
+ if (styleDegree != null && style == null) warnings.push({
96
+ type: "unsupported",
97
+ feature: "providerOptions.azure.styleDegree",
98
+ details: "styleDegree requires style."
99
+ });
100
+ let outputFormat = DEFAULT_OUTPUT_FORMAT;
101
+ if (options.outputFormat != null) {
102
+ const format = options.outputFormat.toLowerCase();
103
+ const shorthand = OUTPUT_FORMATS.get(format);
104
+ if (shorthand != null) outputFormat = shorthand;
105
+ else if (NATIVE_OUTPUT_FORMAT.test(format)) outputFormat = format;
106
+ else warnings.push({
107
+ type: "unsupported",
108
+ feature: "outputFormat",
109
+ details: `Unsupported output format: ${options.outputFormat}. Using mp3 instead.`
110
+ });
111
+ }
112
+ const ssml = buildSsml({
113
+ text: options.text,
114
+ voiceName: voice.includes(":") ? voice : `${voice}:${getMAIVoiceModel(this.modelId) ?? this.modelId}`,
115
+ locale: /^([a-z]{2,3}-[a-z]{2,4})-/i.exec(voice)?.[1],
116
+ speed: options.speed,
117
+ style,
118
+ styleDegree: style != null ? styleDegree : void 0
119
+ });
120
+ const { value: audio, responseHeaders, rawValue } = await postToApi({
121
+ url: this.config.url(),
122
+ headers: combineHeaders(this.config.headers(), {
123
+ "Content-Type": "application/ssml+xml",
124
+ "X-Microsoft-OutputFormat": outputFormat
125
+ }, options.headers),
126
+ body: {
127
+ content: ssml,
128
+ values: ssml
129
+ },
130
+ failedResponseHandler,
131
+ successfulResponseHandler: createBinaryResponseHandler(),
132
+ abortSignal: options.abortSignal,
133
+ fetch: this.config.fetch
134
+ });
135
+ return {
136
+ audio,
137
+ warnings,
138
+ request: { body: ssml },
139
+ response: {
140
+ timestamp: currentDate,
141
+ modelId: this.modelId,
142
+ headers: responseHeaders,
143
+ body: rawValue
144
+ }
145
+ };
146
+ }
147
+ };
148
+ function buildSsml({ text, voiceName, locale = "en-US", speed, style, styleDegree }) {
149
+ let content = escapeXml(text);
150
+ if (speed != null) content = `<prosody rate="${speed}">${content}</prosody>`;
151
+ if (style != null) {
152
+ const degree = styleDegree != null ? ` styledegree="${styleDegree}"` : "";
153
+ content = `<mstts:express-as style="${escapeXml(style)}"${degree}>${content}</mstts:express-as>`;
154
+ }
155
+ return `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xml:lang="${escapeXml(locale)}"><voice name="${escapeXml(voiceName)}">${content}</voice></speak>`;
156
+ }
157
+ const XML_ESCAPES = {
158
+ "&": "&amp;",
159
+ "<": "&lt;",
160
+ ">": "&gt;",
161
+ "\"": "&quot;",
162
+ "'": "&apos;"
163
+ };
164
+ function escapeXml(value) {
165
+ return value.replace(/[&<>"']/g, (char) => XML_ESCAPES[char]);
166
+ }
167
+ function resolveVoice(voice, language) {
168
+ const code = language ? language.split("-")[0].toLowerCase() : void 0;
169
+ if (voice == null) {
170
+ if (code == null) return { voice: DEFAULT_VOICE };
171
+ if (code === "auto") return {
172
+ voice: DEFAULT_VOICE,
173
+ languageWarning: `Automatic language detection is not supported. ${DEFAULT_VOICE} was used.`
174
+ };
175
+ const defaultVoice = DEFAULT_VOICES.get(code);
176
+ return defaultVoice != null ? { voice: defaultVoice } : {
177
+ voice: DEFAULT_VOICE,
178
+ languageWarning: `No default MAI voice for language "${language}". ${DEFAULT_VOICE} was used.`
179
+ };
180
+ }
181
+ const voiceLanguage = /^([a-z]{2,3})-[a-z]{2,4}-/i.exec(voice)?.[1]?.toLowerCase();
182
+ return code != null && code !== "auto" && voiceLanguage != null && code !== voiceLanguage ? {
183
+ voice,
184
+ languageWarning: `The voice ${voice} selects the language. Language "${language}" was ignored.`
185
+ } : { voice };
186
+ }
187
+ const errorSchema = z.object({ error: z.object({ message: z.string() }) });
188
+ const failedResponseHandler = async ({ response, url, requestBodyValues }) => {
189
+ const responseHeaders = extractResponseHeaders(response);
190
+ const responseBody = await response.text();
191
+ const parsed = await safeParseJSON({
192
+ text: responseBody,
193
+ schema: errorSchema
194
+ });
195
+ const message = parsed.success ? parsed.value.error.message : response.status === 400 ? "Azure Speech request failed with status 400. Check the voice name, style, and output format." : `Azure Speech request failed with status ${response.status}.`;
196
+ return {
197
+ responseHeaders,
198
+ value: new APICallError({
199
+ message,
200
+ url,
201
+ requestBodyValues,
202
+ statusCode: response.status,
203
+ responseHeaders,
204
+ responseBody
205
+ })
206
+ };
207
+ };
208
+ //#endregion
15
209
  //#region src/azure-speech-transcription-model-options.ts
16
210
  const azureSpeechTranscriptionModelOptionsShape = () => ({
17
211
  /**
@@ -47,13 +241,20 @@ lazySchema(() => zodSchema(z.strictObject(azureSpeechTranscriptionModelOptionsSh
47
241
  //#region src/azure-transcription-model-options.ts
48
242
  const azureTranscriptionModelOptions = lazySchema(() => zodSchema(z.strictObject({
49
243
  /**
50
- * API to use. Defaults to Speech for MAI-Transcribe-2, OpenAI otherwise.
244
+ * API to use. Defaults to Speech for MAI-Transcribe models, OpenAI otherwise.
51
245
  */
52
246
  api: z.enum(["openai", "speech"]).optional(),
53
247
  ...azureSpeechTranscriptionModelOptionsShape()
54
248
  })));
55
- function isMAITranscribe2(modelId) {
56
- return modelId.toLowerCase() === "mai-transcribe-2";
249
+ const maiTranscribeModels = /* @__PURE__ */ new Map([["mai-transcribe-2", {
250
+ name: "MAI-Transcribe-2",
251
+ supportsTimestamps: true
252
+ }], ["mai-transcribe-1.5", {
253
+ name: "MAI-Transcribe-1.5",
254
+ supportsTimestamps: false
255
+ }]]);
256
+ function getMAITranscribeModel(modelId) {
257
+ return maiTranscribeModels.get(modelId.toLowerCase());
57
258
  }
58
259
  //#endregion
59
260
  //#region src/azure-speech-transcription-model.ts
@@ -66,14 +267,15 @@ var AzureSpeechTranscriptionModel = class {
66
267
  }
67
268
  async doGenerate(options, azureOptions = {}) {
68
269
  const timestamp = /* @__PURE__ */ new Date();
270
+ const maiModel = getMAITranscribeModel(this.modelId);
69
271
  const formData = new FormData();
70
272
  formData.append("audio", new Blob([typeof options.audio === "string" ? convertBase64ToUint8Array(options.audio) : options.audio], { type: options.mediaType }), `audio.${mediaTypeToExtension(options.mediaType)}`);
71
273
  formData.append("definition", JSON.stringify({
72
274
  enhancedMode: {
73
275
  enabled: true,
74
- model: isMAITranscribe2(this.modelId) ? "MAI-Transcribe-2" : this.modelId,
276
+ model: maiModel?.name ?? this.modelId,
75
277
  modelOptions: {
76
- timestamps: azureOptions.timestamps ?? "segment",
278
+ timestamps: azureOptions.timestamps ?? (maiModel?.supportsTimestamps === false ? void 0 : "segment"),
77
279
  transcribeStyle: azureOptions.transcribeStyle
78
280
  }
79
281
  },
@@ -136,7 +338,7 @@ const responseSchema = z.object({
136
338
  });
137
339
  //#endregion
138
340
  //#region src/version.ts
139
- const VERSION = "4.0.86";
341
+ const VERSION = "4.0.89";
140
342
  //#endregion
141
343
  //#region src/azure-openai-provider.ts
142
344
  function getAzureOpenAIBaseURLInfo(baseURL) {
@@ -190,7 +392,7 @@ function createAzure(options = {}) {
190
392
  environmentVariableName: "AZURE_RESOURCE_NAME",
191
393
  description: "Azure OpenAI resource name"
192
394
  });
193
- if (!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(resourceName)) throw new InvalidArgumentError({
395
+ if (!isValidHostnamePart(resourceName)) throw new InvalidArgumentError({
194
396
  argument: "resourceName",
195
397
  message: "Invalid Azure resource name. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints."
196
398
  });
@@ -252,22 +454,27 @@ function createAzure(options = {}) {
252
454
  supportsMaskInputs: void 0
253
455
  }
254
456
  });
457
+ const speechBaseURL = () => withoutTrailingSlash(options.speechBaseURL) ?? `https://${getResourceName()}.cognitiveservices.azure.com`;
255
458
  const createTranscriptionModel = (modelId) => new AzureTranscriptionModel(modelId, options, new OpenAITranscriptionModel(modelId, {
256
459
  provider: "azure.transcription",
257
460
  url,
258
461
  headers: getHeaders,
259
462
  fetch
260
463
  }), new AzureSpeechTranscriptionModel(modelId, {
261
- url: () => `${withoutTrailingSlash(options.speechBaseURL) ?? `https://${getResourceName()}.cognitiveservices.azure.com`}/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
464
+ url: () => `${speechBaseURL()}/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
262
465
  headers: () => getHeaders("speech"),
263
466
  fetch
264
467
  }));
265
- const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
468
+ const createSpeechModel = (modelId) => new AzureSpeechModel(modelId, options, new OpenAISpeechModel(modelId, {
266
469
  provider: "azure.speech",
267
470
  url,
268
471
  headers: getHeaders,
269
472
  fetch
270
- });
473
+ }), new AzureSpeechSpeechModel(modelId, {
474
+ url: () => `${speechBaseURL()}/tts/cognitiveservices/v1`,
475
+ headers: () => getHeaders("speech"),
476
+ fetch
477
+ }));
271
478
  const provider = function(deploymentId) {
272
479
  if (new.target) throw new Error("The Azure OpenAI model function cannot be called with the new keyword.");
273
480
  return createResponsesModel(deploymentId);
@@ -287,6 +494,7 @@ function createAzure(options = {}) {
287
494
  provider.transcription = createTranscriptionModel;
288
495
  provider.transcriptionModel = createTranscriptionModel;
289
496
  provider.speech = createSpeechModel;
497
+ provider.speechModel = createSpeechModel;
290
498
  provider.tools = azureOpenaiTools;
291
499
  return provider;
292
500
  }
@@ -338,7 +546,43 @@ var AzureTranscriptionModel = class {
338
546
  });
339
547
  return {
340
548
  ...options,
341
- api: options?.api ?? (isMAITranscribe2(this.modelId) ? "speech" : "openai")
549
+ api: options?.api ?? (getMAITranscribeModel(this.modelId) ? "speech" : "openai")
550
+ };
551
+ }
552
+ };
553
+ var AzureSpeechModel = class {
554
+ constructor(modelId, config, openai, speech) {
555
+ this.modelId = modelId;
556
+ this.config = config;
557
+ this.openai = openai;
558
+ this.speech = speech;
559
+ this.specificationVersion = "v4";
560
+ this.provider = "azure.speech";
561
+ }
562
+ static [WORKFLOW_SERIALIZE](model) {
563
+ return serializeModelOptions({
564
+ modelId: model.modelId,
565
+ config: model.config
566
+ });
567
+ }
568
+ static [WORKFLOW_DESERIALIZE](options) {
569
+ return createAzure(options.config).speech(options.modelId);
570
+ }
571
+ async doGenerate(options) {
572
+ const { api, ...speechOptions } = await parseProviderOptions({
573
+ provider: "azure",
574
+ providerOptions: options.providerOptions,
575
+ schema: azureSpeechModelOptions
576
+ }) ?? {};
577
+ if ((api ?? (getMAIVoiceModel(this.modelId) ? "speech" : "openai")) === "speech") return this.speech.doGenerate(options, speechOptions);
578
+ const result = await this.openai.doGenerate(options);
579
+ return {
580
+ ...result,
581
+ warnings: [...result.warnings, ...Object.entries(speechOptions).filter(([, value]) => value !== void 0).map(([key]) => ({
582
+ type: "unsupported",
583
+ feature: `providerOptions.azure.${key}`,
584
+ details: "This option requires the Azure Speech API."
585
+ }))]
342
586
  };
343
587
  }
344
588
  };