ai 7.0.37 → 7.0.38

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.d.ts +263 -40
  3. package/dist/index.js +684 -423
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.js +1 -1
  6. package/dist/internal/index.js.map +1 -1
  7. package/dist/test/index.d.ts +14 -2
  8. package/dist/test/index.js +15 -0
  9. package/dist/test/index.js.map +1 -1
  10. package/docs/03-ai-sdk-core/36-transcription.mdx +40 -35
  11. package/docs/03-ai-sdk-core/36-translation.mdx +196 -0
  12. package/docs/03-ai-sdk-core/index.mdx +5 -0
  13. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
  14. package/docs/07-reference/01-ai-sdk-core/11-stream-translate.mdx +176 -0
  15. package/docs/07-reference/01-ai-sdk-core/index.mdx +5 -0
  16. package/docs/07-reference/05-ai-sdk-errors/ai-no-translation-generated-error.mdx +26 -0
  17. package/docs/07-reference/05-ai-sdk-errors/index.mdx +1 -0
  18. package/package.json +4 -4
  19. package/src/error/index.ts +1 -0
  20. package/src/error/no-translation-generated-error.ts +28 -0
  21. package/src/generate-text/generate-text.ts +4 -1
  22. package/src/generate-text/stream-language-model-call.ts +14 -12
  23. package/src/generate-text/stream-text-result.ts +3 -2
  24. package/src/index.ts +1 -0
  25. package/src/model/resolve-model.ts +35 -0
  26. package/src/test/mock-speech-translation-model-v4.ts +24 -0
  27. package/src/transcribe/stream-transcribe.ts +2 -11
  28. package/src/translate/index.ts +5 -0
  29. package/src/translate/stream-translate-result.ts +146 -0
  30. package/src/translate/stream-translate.ts +374 -0
  31. package/src/types/speech-translation-model-response-metadata.ts +22 -0
  32. package/src/types/speech-translation-model.ts +11 -0
@@ -0,0 +1,176 @@
1
+ ---
2
+ title: experimental_streamTranslate
3
+ description: API Reference for experimental_streamTranslate.
4
+ ---
5
+
6
+ # `experimental_streamTranslate()`
7
+
8
+ <Note type="warning">
9
+ `experimental_streamTranslate` is an experimental feature.
10
+ </Note>
11
+
12
+ Streams a speech-to-speech translation from live raw audio. Models translate
13
+ live source audio into target-language audio and text.
14
+
15
+ `experimental_streamTranslate` is built on the speech translation model
16
+ specification (`Experimental_SpeechTranslationModelV4`). Provider
17
+ implementations of the specification ship separately — see your provider's
18
+ documentation for available translation models.
19
+
20
+ ```ts
21
+ import { experimental_streamTranslate as streamTranslate } from 'ai';
22
+
23
+ const result = streamTranslate({
24
+ // any provider model instance that implements the experimental
25
+ // speech translation model specification (Experimental_SpeechTranslationModelV4):
26
+ model: translationModel,
27
+ audio: audioStream, // ReadableStream<Uint8Array | string>
28
+ inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
29
+ targetLanguage: 'es',
30
+ });
31
+
32
+ for await (const part of result.fullStream) {
33
+ if (part.type === 'output-text-delta') {
34
+ process.stdout.write(part.delta);
35
+ }
36
+ }
37
+
38
+ console.log(await result.translationText);
39
+ ```
40
+
41
+ ## Import
42
+
43
+ <Snippet
44
+ text={`import { experimental_streamTranslate as streamTranslate } from "ai"`}
45
+ prompt={false}
46
+ />
47
+
48
+ ## API Signature
49
+
50
+ ### Parameters
51
+
52
+ <PropertiesTable
53
+ content={[
54
+ {
55
+ name: 'model',
56
+ type: 'Experimental_SpeechTranslationModelV4',
57
+ description:
58
+ 'The speech translation model to use. Translation is a streaming-only modality. Pass a provider model instance that implements the experimental speech translation model specification. String model IDs resolve through the global provider (AI Gateway by default) when it supports speech translation models.',
59
+ },
60
+ {
61
+ name: 'audio',
62
+ type: 'ReadableStream<Uint8Array | string>',
63
+ description:
64
+ 'Raw audio chunks to translate. `Uint8Array` chunks contain raw audio bytes; `string` chunks contain base64-encoded raw audio bytes.',
65
+ },
66
+ {
67
+ name: 'inputAudioFormat',
68
+ type: '{ type: string; rate?: number }',
69
+ description:
70
+ 'The input audio format for the raw audio chunks, e.g. `{ type: "audio/pcm", rate: 24000 }`. Supported types are provider-specific (e.g. `audio/pcm`, `audio/pcmu`, `audio/pcma`).',
71
+ },
72
+ {
73
+ name: 'targetLanguage',
74
+ type: 'string',
75
+ description:
76
+ 'The language to translate the audio into, as a BCP-47-style language tag (e.g. `en`, `es`, `fr-CA`). Supported values are provider-specific and validated by the provider.',
77
+ },
78
+ {
79
+ name: 'sourceLanguage',
80
+ type: 'string',
81
+ isOptional: true,
82
+ description:
83
+ 'The language of the source audio, as a BCP-47-style language tag. When absent, providers auto-detect the source language.',
84
+ },
85
+ {
86
+ name: 'outputAudioFormat',
87
+ type: '{ type: string; rate?: number }',
88
+ isOptional: true,
89
+ description:
90
+ 'The desired audio format for translated audio chunks. When absent, the provider default output format is used.',
91
+ },
92
+ {
93
+ name: 'providerOptions',
94
+ type: 'Record<string, JSONObject>',
95
+ isOptional: true,
96
+ description: 'Additional provider-specific options.',
97
+ },
98
+ {
99
+ name: 'abortSignal',
100
+ type: 'AbortSignal',
101
+ isOptional: true,
102
+ description: 'An optional abort signal to cancel the call.',
103
+ },
104
+ {
105
+ name: 'headers',
106
+ type: 'Record<string, string>',
107
+ isOptional: true,
108
+ description:
109
+ 'Additional HTTP/WebSocket headers, if supported by the provider.',
110
+ },
111
+ {
112
+ name: 'includeRawChunks',
113
+ type: 'boolean',
114
+ isOptional: true,
115
+ description:
116
+ 'When true, the provider includes raw provider chunks in the stream as `raw` parts.',
117
+ },
118
+ ]}
119
+ />
120
+
121
+ ### Returns
122
+
123
+ <PropertiesTable
124
+ content={[
125
+ {
126
+ name: 'fullStream',
127
+ type: 'AsyncIterableStream<TranslationStreamPart>',
128
+ description:
129
+ 'A single-consumer live stream of translation parts: `audio`, `output-text-delta`, `output-text-final`, `source-transcript-delta`, `source-transcript-partial`, `source-transcript-final`, `raw`, and `error`. Access it once, before any result promise, when both stream parts and final results are needed. Accessing a result promise first consumes the stream internally and makes `fullStream` unavailable.',
130
+ },
131
+ {
132
+ name: 'sourceText',
133
+ type: 'Promise<string>',
134
+ description: 'The final source-language transcript of the input audio.',
135
+ },
136
+ {
137
+ name: 'translationText',
138
+ type: 'Promise<string>',
139
+ description:
140
+ 'The final translated text in the target language. May resolve to an empty string for providers that produce only audio output.',
141
+ },
142
+ {
143
+ name: 'durationInSeconds',
144
+ type: 'Promise<number | undefined>',
145
+ description: 'The duration of the source audio in seconds, if available.',
146
+ },
147
+ {
148
+ name: 'usage',
149
+ type: 'Promise<Experimental_SpeechTranslationModelV4Usage | undefined>',
150
+ description:
151
+ 'Usage information for the translation call, if reported by the provider: `inputAudioSeconds`, `inputAudioTokens`, `outputAudioTokens`, `inputTextTokens`, `outputTextTokens` (all optional numbers).',
152
+ },
153
+ {
154
+ name: 'warnings',
155
+ type: 'Promise<Warning[]>',
156
+ description:
157
+ 'Warnings for the call, e.g. unsupported settings. Resolves at stream start, or with an empty array at finish if no stream-start was emitted.',
158
+ },
159
+ {
160
+ name: 'response',
161
+ type: 'Promise<SpeechTranslationModelResponseMetadata>',
162
+ description: 'Response metadata (timestamp, model ID, headers).',
163
+ },
164
+ {
165
+ name: 'providerMetadata',
166
+ type: 'Promise<Record<string, JSONObject>>',
167
+ description: 'Additional provider-specific metadata.',
168
+ },
169
+ ]}
170
+ />
171
+
172
+ <Note>
173
+ The result promises settle as the stream is consumed. If you stop consuming
174
+ `fullStream` early (e.g. `break` out of the loop), the underlying provider
175
+ connection is closed and pending result promises reject.
176
+ </Note>
@@ -63,6 +63,11 @@ AI SDK Core contains the following main functions:
63
63
  description: 'Stream a transcript from live raw audio.',
64
64
  href: '/docs/reference/ai-sdk-core/stream-transcribe',
65
65
  },
66
+ {
67
+ title: 'experimental_streamTranslate()',
68
+ description: 'Stream a speech-to-speech translation from live raw audio.',
69
+ href: '/docs/reference/ai-sdk-core/stream-translate',
70
+ },
66
71
  {
67
72
  title: 'generateSpeech()',
68
73
  description: 'Generate speech audio from text.',
@@ -0,0 +1,26 @@
1
+ ---
2
+ title: AI_NoTranslationGeneratedError
3
+ description: Learn how to fix AI_NoTranslationGeneratedError
4
+ ---
5
+
6
+ # AI_NoTranslationGeneratedError
7
+
8
+ This error occurs when no translation could be generated from the input audio:
9
+ no `audio` part was emitted and the final output text is empty, or the stream
10
+ ended without a finish event.
11
+
12
+ ## Properties
13
+
14
+ - `response`: Speech translation model response metadata (required in constructor)
15
+
16
+ ## Checking for this Error
17
+
18
+ You can check if an error is an instance of `AI_NoTranslationGeneratedError` using:
19
+
20
+ ```typescript
21
+ import { NoTranslationGeneratedError } from 'ai';
22
+
23
+ if (NoTranslationGeneratedError.isInstance(error)) {
24
+ // Handle the error
25
+ }
26
+ ```
@@ -24,6 +24,7 @@ collapsed: true
24
24
  - [AI_NoContentGeneratedError](/docs/reference/ai-sdk-errors/ai-no-content-generated-error)
25
25
  - [AI_NoImageGeneratedError](/docs/reference/ai-sdk-errors/ai-no-image-generated-error)
26
26
  - [AI_NoTranscriptGeneratedError](/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error)
27
+ - [AI_NoTranslationGeneratedError](/docs/reference/ai-sdk-errors/ai-no-translation-generated-error)
27
28
  - [AI_NoVideoGeneratedError](/docs/reference/ai-sdk-errors/ai-no-video-generated-error)
28
29
  - [AI_NoObjectGeneratedError](/docs/reference/ai-sdk-errors/ai-no-object-generated-error)
29
30
  - [AI_NoOutputGeneratedError](/docs/reference/ai-sdk-errors/ai-no-output-generated-error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.37",
3
+ "version": "7.0.38",
4
4
  "type": "module",
5
5
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
6
6
  "license": "Apache-2.0",
@@ -42,9 +42,9 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.28",
46
- "@ai-sdk/provider": "4.0.3",
47
- "@ai-sdk/provider-utils": "5.0.12"
45
+ "@ai-sdk/gateway": "4.0.29",
46
+ "@ai-sdk/provider": "4.0.4",
47
+ "@ai-sdk/provider-utils": "5.0.13"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@edge-runtime/vm": "^5.0.0",
@@ -27,6 +27,7 @@ export { NoObjectGeneratedError } from './no-object-generated-error';
27
27
  export { NoOutputGeneratedError } from './no-output-generated-error';
28
28
  export { NoSpeechGeneratedError } from './no-speech-generated-error';
29
29
  export { NoTranscriptGeneratedError } from './no-transcript-generated-error';
30
+ export { NoTranslationGeneratedError } from './no-translation-generated-error';
30
31
  export { NoVideoGeneratedError } from './no-video-generated-error';
31
32
  export { NoSuchToolError } from './no-such-tool-error';
32
33
  export { ToolCallRepairError } from './tool-call-repair-error';
@@ -0,0 +1,28 @@
1
+ import { AISDKError } from '@ai-sdk/provider';
2
+ import type { SpeechTranslationModelResponseMetadata } from '../types/speech-translation-model-response-metadata';
3
+
4
+ const name = 'AI_NoTranslationGeneratedError';
5
+ const marker = `vercel.ai.error.${name}`;
6
+ const symbol = Symbol.for(marker);
7
+
8
+ /**
9
+ * Error that is thrown when no translation was generated.
10
+ */
11
+ export class NoTranslationGeneratedError extends AISDKError {
12
+ private readonly [symbol] = true; // used in isInstance
13
+
14
+ readonly response: SpeechTranslationModelResponseMetadata;
15
+
16
+ constructor(options: { response: SpeechTranslationModelResponseMetadata }) {
17
+ super({
18
+ name,
19
+ message: 'No translation generated.',
20
+ });
21
+
22
+ this.response = options.response;
23
+ }
24
+
25
+ static isInstance(error: unknown): error is NoTranslationGeneratedError {
26
+ return AISDKError.hasMarker(error, marker);
27
+ }
28
+ }
@@ -1164,7 +1164,10 @@ export async function generateText<
1164
1164
  // insert error tool outputs for invalid tool calls:
1165
1165
  // TODO AI SDK 6: invalid inputs should not require output parts
1166
1166
  const invalidToolCalls = stepToolCalls.filter(
1167
- toolCall => toolCall.invalid && toolCall.dynamic,
1167
+ toolCall =>
1168
+ toolCall.invalid &&
1169
+ toolCall.dynamic &&
1170
+ !toolCall.providerExecuted,
1168
1171
  );
1169
1172
 
1170
1173
  clientToolOutputs = [];
@@ -627,18 +627,20 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform<
627
627
  modelCallContent.push(toolCall);
628
628
 
629
629
  if (toolCall.invalid) {
630
- controller.enqueue({
631
- type: 'tool-error',
632
- toolCallId: toolCall.toolCallId,
633
- toolName: toolCall.toolName,
634
- input: toolCall.input,
635
- error: getErrorMessage(toolCall.error!),
636
- dynamic: true,
637
- title: toolCall.title,
638
- ...(toolCall.toolMetadata != null
639
- ? { toolMetadata: toolCall.toolMetadata }
640
- : {}),
641
- });
630
+ if (!toolCall.providerExecuted) {
631
+ controller.enqueue({
632
+ type: 'tool-error',
633
+ toolCallId: toolCall.toolCallId,
634
+ toolName: toolCall.toolName,
635
+ input: toolCall.input,
636
+ error: getErrorMessage(toolCall.error!),
637
+ dynamic: true,
638
+ title: toolCall.title,
639
+ ...(toolCall.toolMetadata != null
640
+ ? { toolMetadata: toolCall.toolMetadata }
641
+ : {}),
642
+ });
643
+ }
642
644
  break;
643
645
  }
644
646
  } catch (error) {
@@ -300,8 +300,9 @@ export interface StreamTextResult<
300
300
 
301
301
  /**
302
302
  * A text stream that returns only the generated text deltas. You can use it
303
- * as either an AsyncIterable or a ReadableStream. When an error occurs, the
304
- * stream will throw the error.
303
+ * as either an AsyncIterable or a ReadableStream. Error parts are not
304
+ * surfaced in this stream. Use the `onError` callback or `stream` to observe
305
+ * them.
305
306
  */
306
307
  readonly textStream: AsyncIterableStream<string>;
307
308
 
package/src/index.ts CHANGED
@@ -46,6 +46,7 @@ export * from './rerank';
46
46
  export * from './telemetry';
47
47
  export * from './text-stream';
48
48
  export * from './transcribe';
49
+ export * from './translate';
49
50
  export * from './types';
50
51
  export * from './ui';
51
52
  export * from './ui-message-stream';
@@ -1,6 +1,7 @@
1
1
  import { gateway } from '@ai-sdk/gateway';
2
2
  import type {
3
3
  EmbeddingModelV4,
4
+ Experimental_SpeechTranslationModelV4,
4
5
  Experimental_VideoModelV4,
5
6
  ImageModelV4,
6
7
  LanguageModelV4,
@@ -13,6 +14,7 @@ import { UnsupportedModelVersionError } from '../error';
13
14
  import type { EmbeddingModel } from '../types/embedding-model';
14
15
  import type { LanguageModel } from '../types/language-model';
15
16
  import type { SpeechModel } from '../types/speech-model';
17
+ import type { SpeechTranslationModel } from '../types/speech-translation-model';
16
18
  import type { TranscriptionModel } from '../types/transcription-model';
17
19
  import { asEmbeddingModelV4 } from './as-embedding-model-v4';
18
20
  import { asImageModelV4 } from './as-image-model-v4';
@@ -79,6 +81,39 @@ export function resolveTranscriptionModel(
79
81
  return asTranscriptionModelV4(model);
80
82
  }
81
83
 
84
+ export function resolveSpeechTranslationModel(
85
+ model: SpeechTranslationModel,
86
+ ): Experimental_SpeechTranslationModelV4 {
87
+ if (typeof model === 'string') {
88
+ // Use raw global provider because speechTranslationModel is experimental
89
+ // and not part of the ProviderV4 interface
90
+ const provider = globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway;
91
+ // TODO AI SDK v7
92
+ // @ts-expect-error - speechTranslationModel support is experimental
93
+ const speechTranslationModel = provider.speechTranslationModel;
94
+
95
+ if (!speechTranslationModel) {
96
+ throw new Error(
97
+ 'The default provider does not support speech translation models. ' +
98
+ 'Please pass a provider model instance that implements the experimental speech translation model specification.',
99
+ );
100
+ }
101
+
102
+ return speechTranslationModel(model);
103
+ }
104
+
105
+ if (model.specificationVersion !== 'v4') {
106
+ const unsupportedModel: any = model;
107
+ throw new UnsupportedModelVersionError({
108
+ version: unsupportedModel.specificationVersion,
109
+ provider: unsupportedModel.provider,
110
+ modelId: unsupportedModel.modelId,
111
+ });
112
+ }
113
+
114
+ return model;
115
+ }
116
+
82
117
  export function resolveSpeechModel(
83
118
  model: SpeechModel,
84
119
  ): SpeechModelV4 | undefined {
@@ -0,0 +1,24 @@
1
+ import type { Experimental_SpeechTranslationModelV4 } from '@ai-sdk/provider';
2
+ import { notImplemented } from './not-implemented';
3
+
4
+ export class MockSpeechTranslationModelV4 implements Experimental_SpeechTranslationModelV4 {
5
+ readonly specificationVersion = 'v4';
6
+ readonly provider: Experimental_SpeechTranslationModelV4['provider'];
7
+ readonly modelId: Experimental_SpeechTranslationModelV4['modelId'];
8
+
9
+ doStream: Experimental_SpeechTranslationModelV4['doStream'];
10
+
11
+ constructor({
12
+ provider = 'mock-provider',
13
+ modelId = 'mock-model-id',
14
+ doStream = notImplemented,
15
+ }: {
16
+ provider?: Experimental_SpeechTranslationModelV4['provider'];
17
+ modelId?: Experimental_SpeechTranslationModelV4['modelId'];
18
+ doStream?: Experimental_SpeechTranslationModelV4['doStream'];
19
+ } = {}) {
20
+ this.provider = provider;
21
+ this.modelId = modelId;
22
+ this.doStream = doStream;
23
+ }
24
+ }
@@ -2,6 +2,7 @@ import {
2
2
  UnsupportedFunctionalityError,
3
3
  type Experimental_TranscriptionModelV4StreamPart,
4
4
  type JSONObject,
5
+ type SharedV4AudioFormat,
5
6
  } from '@ai-sdk/provider';
6
7
  import {
7
8
  DelayedPromise,
@@ -63,17 +64,7 @@ export function streamTranscribe({
63
64
  /**
64
65
  * The input audio format for the raw audio chunks.
65
66
  */
66
- inputAudioFormat: {
67
- /**
68
- * Audio format type, e.g. `audio/pcm`, `audio/pcmu`, or `audio/pcma`.
69
- */
70
- type: string;
71
-
72
- /**
73
- * Sample rate in Hz. Only applicable for formats that require a rate.
74
- */
75
- rate?: number;
76
- };
67
+ inputAudioFormat: SharedV4AudioFormat;
77
68
 
78
69
  /**
79
70
  * Additional provider-specific options.
@@ -0,0 +1,5 @@
1
+ export { streamTranslate as experimental_streamTranslate } from './stream-translate';
2
+ export type {
3
+ StreamTranslationResult as Experimental_StreamTranslationResult,
4
+ TranslationStreamPart as Experimental_TranslationStreamPart,
5
+ } from './stream-translate-result';
@@ -0,0 +1,146 @@
1
+ import type {
2
+ Experimental_SpeechTranslationModelV4Usage,
3
+ JSONObject,
4
+ SharedV4ProviderMetadata,
5
+ } from '@ai-sdk/provider';
6
+ import type { SpeechTranslationModelResponseMetadata } from '../types/speech-translation-model-response-metadata';
7
+ import type { Warning } from '../types/warning';
8
+ import type { AsyncIterableStream } from '../util/async-iterable-stream';
9
+
10
+ /**
11
+ * Stream parts emitted by `experimental_streamTranslate`.
12
+ *
13
+ * Speech translation model stream parts are passed through unchanged, except
14
+ * for `stream-start`, `response-metadata`, and `finish`, which are consumed
15
+ * internally and surfaced via the result promises.
16
+ */
17
+ export type TranslationStreamPart =
18
+ | {
19
+ /**
20
+ * Translated audio chunk in the target language.
21
+ *
22
+ * `Uint8Array` chunks contain raw audio bytes. `string` chunks contain
23
+ * base64-encoded raw audio bytes.
24
+ */
25
+ type: 'audio';
26
+ id?: string;
27
+ audio: Uint8Array | string;
28
+ providerMetadata?: SharedV4ProviderMetadata;
29
+ }
30
+ | {
31
+ /**
32
+ * Append-only translated text delta.
33
+ */
34
+ type: 'output-text-delta';
35
+ id?: string;
36
+ delta: string;
37
+ providerMetadata?: SharedV4ProviderMetadata;
38
+ }
39
+ | {
40
+ /**
41
+ * Final translated text for a provider-defined segment or utterance.
42
+ */
43
+ type: 'output-text-final';
44
+ id?: string;
45
+ text: string;
46
+ providerMetadata?: SharedV4ProviderMetadata;
47
+ }
48
+ | {
49
+ /**
50
+ * Append-only source transcript delta.
51
+ */
52
+ type: 'source-transcript-delta';
53
+ id?: string;
54
+ delta: string;
55
+ providerMetadata?: SharedV4ProviderMetadata;
56
+ }
57
+ | {
58
+ /**
59
+ * Non-final source transcript text. The text may be revised by later parts.
60
+ */
61
+ type: 'source-transcript-partial';
62
+ id?: string;
63
+ text: string;
64
+ startSecond?: number;
65
+ endSecond?: number;
66
+ channelIndex?: number;
67
+ providerMetadata?: SharedV4ProviderMetadata;
68
+ }
69
+ | {
70
+ /**
71
+ * Final source transcript text for a provider-defined segment or utterance.
72
+ */
73
+ type: 'source-transcript-final';
74
+ id?: string;
75
+ text: string;
76
+ startSecond?: number;
77
+ endSecond?: number;
78
+ channelIndex?: number;
79
+ providerMetadata?: SharedV4ProviderMetadata;
80
+ }
81
+ | {
82
+ /**
83
+ * Raw provider chunks if enabled via `includeRawChunks`.
84
+ */
85
+ type: 'raw';
86
+ rawValue: unknown;
87
+ }
88
+ | {
89
+ /**
90
+ * Error parts are streamed, allowing for multiple errors.
91
+ */
92
+ type: 'error';
93
+ error: unknown;
94
+ };
95
+
96
+ export interface StreamTranslationResult {
97
+ /**
98
+ * The final source-language transcript of the input audio.
99
+ */
100
+ readonly sourceText: PromiseLike<string>;
101
+
102
+ /**
103
+ * The final translated text in the target language.
104
+ *
105
+ * May resolve to an empty string for providers that produce only audio
106
+ * output.
107
+ */
108
+ readonly translationText: PromiseLike<string>;
109
+
110
+ /**
111
+ * The duration of the source audio in seconds, if available.
112
+ */
113
+ readonly durationInSeconds: PromiseLike<number | undefined>;
114
+
115
+ /**
116
+ * Usage information for the translation call, if reported by the provider.
117
+ */
118
+ readonly usage: PromiseLike<
119
+ Experimental_SpeechTranslationModelV4Usage | undefined
120
+ >;
121
+
122
+ /**
123
+ * Warnings for the call, e.g. unsupported settings.
124
+ */
125
+ readonly warnings: PromiseLike<Array<Warning>>;
126
+
127
+ /**
128
+ * Response metadata.
129
+ */
130
+ readonly response: PromiseLike<SpeechTranslationModelResponseMetadata>;
131
+
132
+ /**
133
+ * Additional provider-specific metadata.
134
+ */
135
+ readonly providerMetadata: PromiseLike<Record<string, JSONObject>>;
136
+
137
+ /**
138
+ * Full stream of translation parts.
139
+ *
140
+ * This is a single-consumer live stream and can only be accessed once.
141
+ * Access it before any result promise when both stream parts and final
142
+ * results are needed; accessing a result promise first consumes the stream
143
+ * internally and makes `fullStream` unavailable.
144
+ */
145
+ readonly fullStream: AsyncIterableStream<TranslationStreamPart>;
146
+ }