@ai-sdk/azure 4.0.116 → 4.0.118

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.
@@ -0,0 +1,166 @@
1
+ import type {
2
+ ModelEntry,
3
+ ProviderOptionDefinition,
4
+ ProviderOptionDefinitions,
5
+ } from '@ai-sdk/provider';
6
+ import type { AzureImageModelOptions } from './azure-image-model-options';
7
+ import type { AzureSpeechModelOptions } from './azure-speech-model-options';
8
+ import type { AzureTranscriptionModelOptions } from './azure-transcription-model-options';
9
+
10
+ /** Azure-specific options; OpenAI-backed operations retain OpenAI's options. */
11
+ export const azureProviderOptions = {
12
+ image: {
13
+ api: { description: 'Select the OpenAI or MAI image API.' },
14
+ autoAspectRatio: { description: 'Choose the aspect ratio automatically.' },
15
+ webGrounding: { description: 'Ground image generation in web search.' },
16
+ } satisfies Record<keyof AzureImageModelOptions, ProviderOptionDefinition>,
17
+ speech: {
18
+ api: { description: 'Select the OpenAI or Azure Speech API.' },
19
+ style: { description: 'Speaking style supported by the selected voice.' },
20
+ styleDegree: { description: 'Intensity of the speaking style.' },
21
+ } satisfies Record<keyof AzureSpeechModelOptions, ProviderOptionDefinition>,
22
+ transcription: {
23
+ api: { description: 'Select the OpenAI, Azure Speech, or MAI API.' },
24
+ language: { description: 'Language hint for MAI streaming transcription.' },
25
+ timestamps: { description: 'Word, segment, or no timestamps.' },
26
+ transcribeStyle: { description: 'Verbatim or cleaned transcription.' },
27
+ locales: { description: 'Language to use for transcription.' },
28
+ diarization: { description: 'Enable speaker diarization.' },
29
+ phraseList: { description: 'Phrases to bias transcription toward.' },
30
+ } satisfies Record<
31
+ keyof AzureTranscriptionModelOptions,
32
+ ProviderOptionDefinition
33
+ >,
34
+ } as const satisfies ProviderOptionDefinitions;
35
+
36
+ type AzureRequestConfig = {
37
+ image?: { api: 'mai' };
38
+ speech?: { api: 'speech'; voiceModel: string };
39
+ transcription?:
40
+ | { api: 'speech'; name: string; supportsTimestamps: boolean }
41
+ | { api: 'mai' };
42
+ };
43
+
44
+ type AzureModelEntry = ModelEntry<AzureRequestConfig>;
45
+
46
+ function imageEntry(webGrounding: boolean): AzureModelEntry {
47
+ return {
48
+ capabilities: {
49
+ image: {
50
+ sizes: {
51
+ description: 'Sides must be multiples of 16 and at least 768 pixels.',
52
+ },
53
+ fileInput: true,
54
+ maskInput: false,
55
+ maxImagesPerCall: 1,
56
+ },
57
+ },
58
+ providerOptions: {
59
+ image: { api: true, autoAspectRatio: webGrounding, webGrounding },
60
+ },
61
+ requestConfig: { image: { api: 'mai' } },
62
+ };
63
+ }
64
+
65
+ function speechEntry(voiceModel: string): AzureModelEntry {
66
+ return {
67
+ capabilities: { speech: { instructions: false } },
68
+ providerOptions: {
69
+ speech: {
70
+ api: true,
71
+ style: {
72
+ condition: 'Supported styles depend on the selected voice and model.',
73
+ },
74
+ styleDegree: { condition: 'Requires a supported speaking style.' },
75
+ },
76
+ },
77
+ requestConfig: { speech: { api: 'speech', voiceModel } },
78
+ };
79
+ }
80
+
81
+ function transcriptionEntry(
82
+ name: string,
83
+ supportsTimestamps: boolean,
84
+ ): AzureModelEntry {
85
+ return {
86
+ capabilities: {
87
+ transcription: {
88
+ transcription: true,
89
+ streaming: false,
90
+ duration: true,
91
+ segments: supportsTimestamps,
92
+ language: true,
93
+ },
94
+ },
95
+ providerOptions: {
96
+ transcription: {
97
+ api: true,
98
+ language: { condition: 'Requires the MAI streaming API override.' },
99
+ timestamps: supportsTimestamps
100
+ ? true
101
+ : { condition: 'Only none is supported.' },
102
+ transcribeStyle: supportsTimestamps
103
+ ? true
104
+ : { condition: 'Only verbatim is supported.' },
105
+ locales: true,
106
+ diarization: supportsTimestamps,
107
+ phraseList: true,
108
+ },
109
+ },
110
+ requestConfig: {
111
+ transcription: { api: 'speech', name, supportsTimestamps },
112
+ },
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Azure-owned models. OpenAI and DeepSeek deployments use their adapters' model
118
+ * catalogs; arbitrary deployment names do not declare model-family support.
119
+ */
120
+ export const azureModelCatalog: Readonly<Record<string, AzureModelEntry>> = {
121
+ 'mai-image-2.5': imageEntry(false),
122
+ 'mai-image-2.5-flash': imageEntry(false),
123
+ 'mai-image-2.5-pro': imageEntry(false),
124
+ 'mai-image-2.6': imageEntry(true),
125
+ 'mai-image-2.6-flash': imageEntry(true),
126
+ 'mai-voice-2.1-flash': speechEntry('MAI-Voice-2.1-Flash'),
127
+ 'mai-voice-2.1': speechEntry('MAI-Voice-2.1'),
128
+ 'mai-voice-2-flash': speechEntry('MAI-Voice-2-Flash'),
129
+ 'mai-voice-2': speechEntry('MAI-Voice-2'),
130
+ 'mai-transcribe-2': transcriptionEntry('MAI-Transcribe-2', true),
131
+ 'mai-transcribe-1.5': transcriptionEntry('MAI-Transcribe-1.5', false),
132
+ 'mai-transcribe-2-streaming': {
133
+ capabilities: {
134
+ transcription: {
135
+ transcription: false,
136
+ streaming: true,
137
+ duration: {
138
+ condition: 'Requires an audio format with a known byte rate.',
139
+ },
140
+ segments: false,
141
+ language: { condition: 'Reports the configured language hint.' },
142
+ },
143
+ },
144
+ providerOptions: {
145
+ transcription: {
146
+ api: true,
147
+ language: true,
148
+ timestamps: false,
149
+ transcribeStyle: false,
150
+ locales: false,
151
+ diarization: false,
152
+ phraseList: false,
153
+ },
154
+ },
155
+ requestConfig: { transcription: { api: 'mai' } },
156
+ },
157
+ };
158
+
159
+ export function getAzureModelEntry(
160
+ modelId: string,
161
+ ): AzureModelEntry | undefined {
162
+ const id = modelId.toLowerCase();
163
+ return Object.prototype.hasOwnProperty.call(azureModelCatalog, id)
164
+ ? azureModelCatalog[id]
165
+ : undefined;
166
+ }
@@ -1,16 +1,22 @@
1
1
  import {
2
+ applyPatch,
2
3
  codeInterpreter,
4
+ customTool,
3
5
  fileSearch,
4
6
  imageGeneration,
7
+ shell,
5
8
  toolSearch,
6
9
  webSearch,
7
10
  webSearchPreview,
8
11
  } from '@ai-sdk/openai/internal';
9
12
 
10
13
  export const azureOpenaiTools: {
14
+ applyPatch: typeof applyPatch;
11
15
  codeInterpreter: typeof codeInterpreter;
16
+ customTool: typeof customTool;
12
17
  fileSearch: typeof fileSearch;
13
18
  imageGeneration: typeof imageGeneration;
19
+ shell: typeof shell;
14
20
  toolSearch: typeof toolSearch;
15
21
  webSearch: typeof webSearch;
16
22
  /**
@@ -18,9 +24,12 @@ export const azureOpenaiTools: {
18
24
  */
19
25
  webSearchPreview: typeof webSearchPreview;
20
26
  } = {
27
+ applyPatch,
21
28
  codeInterpreter,
29
+ customTool,
22
30
  fileSearch,
23
31
  imageGeneration,
32
+ shell,
24
33
  toolSearch,
25
34
  webSearch,
26
35
  webSearchPreview,
@@ -4,6 +4,7 @@ import {
4
4
  type InferSchema,
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from 'zod/v4';
7
+ import { getAzureModelEntry } from './azure-model-catalog';
7
8
  import { azureSpeechSpeechModelOptionsShape } from './azure-speech-speech-model-options';
8
9
 
9
10
  export const azureSpeechModelOptions = lazySchema(() =>
@@ -22,14 +23,6 @@ export type AzureSpeechModelOptions = InferSchema<
22
23
  typeof azureSpeechModelOptions
23
24
  >;
24
25
 
25
- // Azure voice-name suffixes by lowercase model ID.
26
- const maiVoiceModels = new Map([
27
- ['mai-voice-2.1-flash', 'MAI-Voice-2.1-Flash'],
28
- ['mai-voice-2.1', 'MAI-Voice-2.1'],
29
- ['mai-voice-2-flash', 'MAI-Voice-2-Flash'],
30
- ['mai-voice-2', 'MAI-Voice-2'],
31
- ]);
32
-
33
26
  export function getMAIVoiceModel(modelId: string) {
34
- return maiVoiceModels.get(modelId.toLowerCase());
27
+ return getAzureModelEntry(modelId)?.requestConfig?.speech?.voiceModel;
35
28
  }
@@ -1,4 +1,4 @@
1
- import type { TranscriptionModelV4 } from '@ai-sdk/provider';
1
+ import type { SharedV4Warning, TranscriptionModelV4 } from '@ai-sdk/provider';
2
2
  import {
3
3
  lazySchema,
4
4
  zodSchema,
@@ -36,6 +36,37 @@ export class AzureSpeechTranscriptionModel implements TranscriptionModelV4 {
36
36
  ): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
37
37
  const timestamp = new Date();
38
38
  const maiModel = getMAITranscribeModel(this.modelId);
39
+ const warnings: SharedV4Warning[] = [];
40
+ let timestamps = azureOptions.timestamps;
41
+ if (options.timestampGranularities != null) {
42
+ const wantsWord = options.timestampGranularities.includes('word');
43
+ const wantsSegment = options.timestampGranularities.includes('segment');
44
+ if (
45
+ maiModel?.supportsTimestamps === false &&
46
+ (wantsWord || wantsSegment)
47
+ ) {
48
+ warnings.push({
49
+ type: 'unsupported',
50
+ feature: 'timestampGranularities',
51
+ details: `${maiModel.name} cannot return word or segment timings.`,
52
+ });
53
+ } else if (timestamps == null) {
54
+ if (wantsWord) {
55
+ timestamps = 'word';
56
+ } else if (wantsSegment) {
57
+ timestamps = 'segment';
58
+ }
59
+ } else if (
60
+ (wantsWord && timestamps !== 'word') ||
61
+ (wantsSegment && timestamps === 'none')
62
+ ) {
63
+ warnings.push({
64
+ type: 'unsupported',
65
+ feature: 'timestampGranularities',
66
+ details: `providerOptions.azure.timestamps is "${timestamps}" and overrides the requested timestamp granularities.`,
67
+ });
68
+ }
69
+ }
39
70
  const formData = new FormData();
40
71
  formData.append(
41
72
  'audio',
@@ -57,7 +88,7 @@ export class AzureSpeechTranscriptionModel implements TranscriptionModelV4 {
57
88
  model: maiModel?.name ?? this.modelId,
58
89
  modelOptions: {
59
90
  timestamps:
60
- azureOptions.timestamps ??
91
+ timestamps ??
61
92
  (maiModel?.supportsTimestamps === false ? undefined : 'segment'),
62
93
  transcribeStyle: azureOptions.transcribeStyle,
63
94
  },
@@ -102,8 +133,24 @@ export class AzureSpeechTranscriptionModel implements TranscriptionModelV4 {
102
133
  ? language
103
134
  : undefined;
104
135
 
136
+ const words = phrases.flatMap(phrase =>
137
+ (phrase.words ?? []).flatMap(word =>
138
+ word.offsetMilliseconds != null && word.durationMilliseconds != null
139
+ ? [
140
+ {
141
+ text: word.text,
142
+ startSecond: word.offsetMilliseconds / 1000,
143
+ endSecond:
144
+ (word.offsetMilliseconds + word.durationMilliseconds) / 1000,
145
+ },
146
+ ]
147
+ : [],
148
+ ),
149
+ );
150
+
105
151
  return {
106
152
  text: value.combinedPhrases.map(phrase => phrase.text).join(' '),
153
+ ...(words.length > 0 ? { words } : {}),
107
154
  segments: phrases.flatMap(phrase =>
108
155
  phrase.offsetMilliseconds != null && phrase.durationMilliseconds != null
109
156
  ? [
@@ -122,7 +169,7 @@ export class AzureSpeechTranscriptionModel implements TranscriptionModelV4 {
122
169
  value.durationMilliseconds != null
123
170
  ? value.durationMilliseconds / 1000
124
171
  : undefined,
125
- warnings: [],
172
+ warnings,
126
173
  providerMetadata: {
127
174
  azure: { phrases },
128
175
  } satisfies AzureTranscriptionProviderMetadata,
@@ -4,6 +4,7 @@ import {
4
4
  type InferSchema,
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from 'zod/v4';
7
+ import { getAzureModelEntry } from './azure-model-catalog';
7
8
  import { azureMaiTranscriptionModelOptionsShape } from './azure-mai-transcription-model-options';
8
9
  import { azureSpeechTranscriptionModelOptionsShape } from './azure-speech-transcription-model-options';
9
10
 
@@ -25,20 +26,15 @@ export type AzureTranscriptionModelOptions = InferSchema<
25
26
  typeof azureTranscriptionModelOptions
26
27
  >;
27
28
 
28
- // Azure Speech model names by lowercase model ID. MAI-Transcribe-1.5 only
29
- // accepts Azure's default timestamps (`none`).
30
- const maiTranscribeModels = new Map([
31
- ['mai-transcribe-2', { name: 'MAI-Transcribe-2', supportsTimestamps: true }],
32
- [
33
- 'mai-transcribe-1.5',
34
- { name: 'MAI-Transcribe-1.5', supportsTimestamps: false },
35
- ],
36
- ]);
37
-
38
29
  export function getMAITranscribeModel(modelId: string) {
39
- return maiTranscribeModels.get(modelId.toLowerCase());
30
+ const config = getAzureModelEntry(modelId)?.requestConfig?.transcription;
31
+ return config?.api === 'speech'
32
+ ? { name: config.name, supportsTimestamps: config.supportsTimestamps }
33
+ : undefined;
40
34
  }
41
35
 
42
36
  export function isMAITranscribeStreaming(modelId: string): boolean {
43
- return modelId.toLowerCase() === 'mai-transcribe-2-streaming';
37
+ return (
38
+ getAzureModelEntry(modelId)?.requestConfig?.transcription?.api === 'mai'
39
+ );
44
40
  }