ai 7.0.186 → 7.0.187
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 +15 -0
- package/dist/{default-stop-condition-CVw9jxWu.js → default-stop-condition-CeJWqvOg.js} +19 -13
- package/dist/default-stop-condition-CeJWqvOg.js.map +1 -0
- package/dist/{index-D1zb0Eh5.d.ts → index-Dg74caoY.d.ts} +39 -11
- package/dist/index-Dg74caoY.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +66 -14
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +22 -5
- package/docs/03-ai-sdk-core/18-tools.mdx +10 -8
- package/docs/03-ai-sdk-core/32-decisions.mdx +4 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +12 -13
- package/docs/03-ai-sdk-core/36-translation.mdx +18 -23
- package/docs/03-ai-sdk-core/50-error-handling.mdx +6 -0
- package/docs/03-ai-sdk-core/60-telemetry.mdx +14 -12
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +11 -9
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/{11-stream-translate.mdx → 11-stream-speech-translation.mdx} +9 -16
- package/docs/07-reference/01-ai-sdk-core/{11-stream-transcribe.mdx → 11-stream-transcription.mdx} +7 -14
- package/docs/07-reference/01-ai-sdk-core/index.mdx +4 -4
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +14 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-transcript-generated-error.mdx +1 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-translation-generated-error.mdx +1 -0
- package/package.json +17 -13
- package/src/error/no-transcript-generated-error.ts +11 -2
- package/src/error/no-translation-generated-error.ts +13 -2
- package/src/generate-text/stream-text.ts +27 -0
- package/src/logger/deprecations.ts +2 -0
- package/src/model/resolve-model.ts +3 -3
- package/src/transcribe/index.ts +19 -1
- package/src/transcribe/stream-transcribe.ts +21 -11
- package/src/translate/index.ts +41 -3
- package/src/translate/stream-translate-result.ts +4 -4
- package/src/translate/stream-translate.ts +23 -13
- package/src/util/retry-with-exponential-backoff.ts +14 -9
- package/dist/default-stop-condition-CVw9jxWu.js.map +0 -1
- package/dist/index-D1zb0Eh5.d.ts.map +0 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $l as ToolChoice, $s as ContentPart, Ao as ResolvedToolCallers, Cc as standardizePrompt, Cl as createDefaultDownloadFunction, Da as TelemetryDispatcher, Eo as ToolCallRepairFunction, Fl as addLanguageModelUsage, Gl as LanguageModelResponseMetadata, Go as ToolOrder, Il as asLanguageModelUsage, Ja as GenerateTextOnStepErrorCallback, Ka as GenerateTextOnStartCallback, Kl as ResponseMessage, Ll as createNullLanguageModelUsage, No as ToolApprovalConfiguration, Ol as LogWarningsFunction, Oo as InvalidToolInputError, Pl as LanguageModelUsage, Po as ToolApprovalStatus, Ql as LanguageModel, Qo as InferCompleteOutput, Sc as StandardizedPrompt, Sl as DownloadFunction, So as OnToolExecutionStartCallback, To as ToolOutput, Ua as GenerateTextOnAbortCallback, Wa as GenerateTextOnEndCallback, Wc as Instructions, Xa as GenerateTextOnStepStartCallback, Xo as StaticToolOutputDenied, Ya as GenerateTextOnStepFinishCallback, Yo as StoppedBy, Ys as DefaultStepResult, Zl as FinishReason, Zs as StepResult, _c as IncludedToolsContext, _o as ToolsContextSettings, ao as Output, ba as GenerateTextResult, cc as DynamicToolCall, dc as ReasoningFileOutput, ec as DynamicToolResult, fc as ReasoningOutput, gc as IncludedContext, hc as GeneratedFile, il as LanguageModelCallOptions, jl as Warning, kc as AssistantModelMessage$1, kl as logWarnings, lc as StaticToolCall, nc as TypedToolResult, ns as createAsyncIterableStream, oc as ToolApprovalResponseOutput, qa as GenerateTextOnStepEndCallback, ql as LanguageModelRequestMetadata, sc as ToolApprovalRequestOutput, tc as StaticToolResult, uc as TypedToolCall, vc as TelemetryOptions, vo as ToolInputRefinement, xa as LanguageModelStreamPart, xc as Callback, xo as OnToolExecutionEndCallback, zc as ToolModelMessage$1 } from "../index-Dg74caoY.js";
|
|
2
2
|
import { Arrayable, Context, Experimental_SandboxSession, FlexibleSchema, IdGenerator, InferToolSetContext, ModelMessage, RetryFunction, ShouldRetryFunction, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolResultOutput, ToolResultPart, ToolSet, convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { EmbeddingModelV4, Experimental_DecisionModelV4, Experimental_ExtractionModelV4, Experimental_SpeechTranslationModelV4, Experimental_VideoModelV4, ImageModelV4, LanguageModelV4, LanguageModelV4Content, LanguageModelV4FunctionTool, LanguageModelV4Prompt, LanguageModelV4ProviderTool, LanguageModelV4ToolCall, LanguageModelV4ToolChoice, LanguageModelV4ToolResultOutput, RerankingModelV4, SharedV4Warning, SpeechModelV4, TranscriptionModelV4 } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/prompt/convert-to-language-model-prompt.d.ts
|
package/dist/internal/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as createToolModelOutput, B as setAbortTimeout, C as resolveToolApproval, E as DefaultGenerateTextResult, J as createNullLanguageModelUsage, K as addLanguageModelUsage, O as validateToolContext, Ot as logWarnings, P as convertLanguageModelContent, Q as prepareLanguageModelCallOptions, R as collectToolApprovals, S as filterIncludedContext, U as mergeAbortSignals, V as prepareRetries, X as prepareTools, Y as standardizePrompt, Z as prepareToolChoice, _ as createTelemetryDispatcher, a as createAsyncIterableStream, c as validateApprovedToolApprovals, ct as createDefaultDownloadFunction, d as verifyToolApprovalSignature, et as convertToLanguageModelPrompt, g as DefaultStepResult, gt as resolveLanguageModel, h as createRestrictedTelemetryDispatcher, k as createToolSearchState, n as logDefaultStopConditionWarning, nt as mapToolResultOutput, o as mapWithConcurrency, p as toResponseMessages, q as asLanguageModelUsage, r as isOutputChunk, s as prepareToolCallConcurrency, st as mergeObjects, tt as downloadAssets, u as signToolApproval, w as parseToolCall, x as mergeCallbacks, z as calculateTokensPerSecond } from "../default-stop-condition-CeJWqvOg.js";
|
|
2
2
|
import { convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
3
3
|
export { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertAsyncIteratorToReadableStream, convertLanguageModelContent, convertToLanguageModelPrompt, createAsyncIterableStream, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, filterIncludedContext, isOutputChunk, logDefaultStopConditionWarning, logWarnings, mapToolResultOutput, mapWithConcurrency, mergeAbortSignals, mergeCallbacks, mergeObjects, parseToolCall, prepareLanguageModelCallOptions as prepareCallSettings, prepareLanguageModelCallOptions, prepareRetries, prepareToolCallConcurrency, prepareToolChoice, prepareTools, resolveLanguageModel, resolveToolApproval, setAbortTimeout, signToolApproval, standardizePrompt, toResponseMessages, validateApprovedToolApprovals, validateToolContext, verifyToolApprovalSignature };
|
|
@@ -187,10 +187,11 @@ return createUIMessageStreamResponse({
|
|
|
187
187
|
});
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
-
The
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
the
|
|
190
|
+
A model-call step can run more than once. The workflow runtime runs it again when an execution did not report its outcome, for example because the function instance was terminated during the model call, and two executions can overlap.
|
|
191
|
+
Every execution writes a `reset-step` event before its output and tags its stream parts with an `attemptId`.
|
|
192
|
+
The transform forwards `reset-step`, so clients remove the partial parts of the earlier execution, and it forwards the parts of one execution only: the latest one, or the one named by the `commitAttemptId` that `WorkflowAgent` writes on its next stream part once the model step has returned.
|
|
193
|
+
Tool results, step boundaries and the `finish` chunk are written by the next step that runs, usually the following model step, and carry a `writeId`. A step that writes them can run more than once, and the transform forwards each `writeId` once.
|
|
194
|
+
If you read the raw `ModelCallStreamPart` stream without the transform, apply the same rules.
|
|
194
195
|
|
|
195
196
|
## Resumable Streaming with WorkflowChatTransport
|
|
196
197
|
|
|
@@ -320,6 +321,22 @@ async function bookFlightStep(input: {
|
|
|
320
321
|
|
|
321
322
|
Tools without `'use step'` still work but run as regular in-memory functions without durability guarantees.
|
|
322
323
|
|
|
324
|
+
### Conversation Messages in Tool Steps
|
|
325
|
+
|
|
326
|
+
Every tool receives the conversation as `messages` in the second argument of its `execute` function. When `execute` is a workflow step, its arguments are stored as the step input, so the whole conversation is stored again for every tool call. With long conversations or large attachments, this is most of what a run stores.
|
|
327
|
+
|
|
328
|
+
If your tools do not read `messages`, set `includeMessagesInToolExecution` to `false`. Tools then receive an empty `messages` array:
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
const agent = new WorkflowAgent({
|
|
332
|
+
model,
|
|
333
|
+
tools,
|
|
334
|
+
includeMessagesInToolExecution: false,
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
You can also pass the setting to `generate()` or `stream()`, where it overrides the constructor value. The default is `true`. Callbacks such as `onToolExecutionStart` run in the workflow and always receive the conversation.
|
|
339
|
+
|
|
323
340
|
## Tool Approval
|
|
324
341
|
|
|
325
342
|
Human approval is configured on the tool definition with `needsApproval` or on
|
|
@@ -996,7 +1013,7 @@ const result = await agent.stream({
|
|
|
996
1013
|
});
|
|
997
1014
|
```
|
|
998
1015
|
|
|
999
|
-
A number has the same meaning as `totalMs`. Inside a workflow, it sets an absolute deadline for model calls. Each model step checks it before dispatch, before SDK retry attempts, and after the provider returns. The same deadline remains in effect after a tool suspends and resumes. SDK `maxRetries` governs model retries; the durable model step does not add another retry layer. Expiration before dispatch rejects with `TimeoutError`; expiration during SDK retry backoff rejects with `AbortError`. Neither starts a new retry.
|
|
1016
|
+
A number has the same meaning as `totalMs`. Inside a workflow, it sets an absolute deadline for model calls. Each model step checks it before dispatch, before SDK retry attempts, and after the provider returns. The same deadline remains in effect after a tool suspends and resumes. SDK `maxRetries` governs model retries; the durable model step does not add another retry layer for failed model calls. The workflow runtime runs the model step again only when an execution did not report its outcome, which calls the model again. Expiration before dispatch rejects with `TimeoutError`; expiration during SDK retry backoff rejects with `AbortError`. Neither starts a new retry.
|
|
1000
1017
|
|
|
1001
1018
|
The other values apply to one model call and start again for the next one:
|
|
1002
1019
|
|
|
@@ -231,7 +231,7 @@ const result = await generateText({
|
|
|
231
231
|
type: 'boolean',
|
|
232
232
|
isOptional: true,
|
|
233
233
|
description:
|
|
234
|
-
'Only
|
|
234
|
+
'Only allow the model to request URLs that appear in user messages. URLs in instructions, system messages, assistant messages, and tool results are not included. HTTP redirects from an allowed URL are still followed, subject to domain filters and address validation. Defaults to `false`.',
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
237
|
name: 'maxLength',
|
|
@@ -338,10 +338,12 @@ See [Secure URL Fetching](/docs/advanced/secure-url-fetching).
|
|
|
338
338
|
Fetched content is untrusted and can contain prompt injections. When an agent
|
|
339
339
|
has access to private data, a model could also be instructed to send that data
|
|
340
340
|
to another site, for example in a URL query string. Restrict fetching with
|
|
341
|
-
`allowedDomains`, enable `requireUrlInUserMessage` so
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
`requireUrlInUserMessage`
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
341
|
+
`allowedDomains`, enable `requireUrlInUserMessage` so the model can only request
|
|
342
|
+
URLs from user messages, or require [tool approval](/docs/ai-sdk-core/tools-and-tool-calling#tool-execution-approval).
|
|
343
|
+
|
|
344
|
+
`requireUrlInUserMessage` checks the initial URL requested by the model and
|
|
345
|
+
ignores URLs from tool results, so the model cannot follow links from search
|
|
346
|
+
results or fetched pages in this mode. HTTP redirects from a user-provided URL
|
|
347
|
+
are still followed (subject to `allowedDomains`, `blockedDomains`, and address
|
|
348
|
+
validation). Combine `requireUrlInUserMessage` with `allowedDomains` (and
|
|
349
|
+
`guarded-fetch` on Node.js) if you also want to restrict redirect destinations.
|
|
@@ -111,6 +111,7 @@ Use a provider's `decisionModel` factory:
|
|
|
111
111
|
| Google | `google.decisionModel('gemini-decision-1')` |
|
|
112
112
|
| HeyGen | `heygen.decisionModel('heygen-decision-1')` |
|
|
113
113
|
| Liquid | `liquid.decisionModel('d1.2')` |
|
|
114
|
+
| SubQ | `subquadratic.decisionModel('subq-snap-1.2')` |
|
|
114
115
|
|
|
115
116
|
TypeSafe AI's [Jev](https://vercel.com/i/what-is-jev), OpenAI's
|
|
116
117
|
[Decisions API](https://developers.openai.com/api/docs/guides/decisions),
|
|
@@ -304,6 +305,9 @@ HeyGen exposes Choice/Score confidence at
|
|
|
304
305
|
Liquid exposes Choice/Score/Box confidence at
|
|
305
306
|
`result.providerMetadata?.liquid?.confidence` and Score legends at
|
|
306
307
|
`result.providerMetadata?.liquid?.legend`, also keyed by question ID.
|
|
308
|
+
SubQ exposes Choice/Score confidence at
|
|
309
|
+
`result.providerMetadata?.subquadratic?.confidence` and Score legends at
|
|
310
|
+
`result.providerMetadata?.subquadratic?.legend`, also keyed by question ID.
|
|
307
311
|
|
|
308
312
|
Check for optional distributions before using them. For example, an application
|
|
309
313
|
can route only when a provider supplies a sufficiently high selected-option
|
|
@@ -75,14 +75,15 @@ normalized word timings.
|
|
|
75
75
|
|
|
76
76
|
## Telemetry
|
|
77
77
|
|
|
78
|
-
`transcribe` and `
|
|
78
|
+
`transcribe` and `streamTranscription` accept the standard
|
|
79
79
|
`telemetry` option. Registered integrations receive start, end, and error
|
|
80
80
|
events with the provider and model, audio byte length and media type, final
|
|
81
81
|
transcript, warnings, response metadata, provider metadata, and usage when the
|
|
82
|
-
provider reports it.
|
|
83
|
-
|
|
82
|
+
provider reports it. Custom integrations receive streaming transcription's
|
|
83
|
+
lifecycle through the still experimental
|
|
84
84
|
`experimental_onStreamTranscriptionStart` and
|
|
85
|
-
`experimental_onStreamTranscriptionEnd
|
|
85
|
+
`experimental_onStreamTranscriptionEnd` callbacks; errors continue to use
|
|
86
|
+
`onError`.
|
|
86
87
|
Integrations that wrap or delegate to another telemetry integration must
|
|
87
88
|
forward these experimental callbacks explicitly for streaming transcription
|
|
88
89
|
to be observed.
|
|
@@ -111,15 +112,13 @@ complete.
|
|
|
111
112
|
|
|
112
113
|
## Streaming Transcription
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Use `experimental_streamTranscribe` when you have live raw audio and need transcript updates before the full audio stream is complete. The function uses transcription models with streaming support; provider options configure provider-specific behavior, but the streaming operation is selected by the function itself.
|
|
115
|
+
Use `streamTranscription` when you have live raw audio and need transcript updates before the full audio stream is complete. The function uses transcription models with streaming support; provider options configure provider-specific behavior, but the streaming operation is selected by the function itself.
|
|
117
116
|
|
|
118
117
|
```ts
|
|
119
118
|
import { openai } from '@ai-sdk/openai';
|
|
120
|
-
import {
|
|
119
|
+
import { streamTranscription } from 'ai';
|
|
121
120
|
|
|
122
|
-
const result =
|
|
121
|
+
const result = streamTranscription({
|
|
123
122
|
model: openai.transcription('gpt-realtime-whisper'),
|
|
124
123
|
audio: audioStream, // ReadableStream<Uint8Array | string>
|
|
125
124
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
@@ -172,7 +171,7 @@ The `audio` stream must contain raw audio chunks. `Uint8Array` chunks are raw by
|
|
|
172
171
|
default). AI Gateway supports streaming transcription for supported models
|
|
173
172
|
(e.g. `openai/gpt-realtime-whisper`, `elevenlabs/eleven-scribe-2-realtime`,
|
|
174
173
|
`xai/grok-stt`), so string IDs work:
|
|
175
|
-
`
|
|
174
|
+
`streamTranscription({ model: 'openai/gpt-realtime-whisper', ...
|
|
176
175
|
})`. You can also pass a provider model instance (e.g.
|
|
177
176
|
`openai.transcription('gpt-realtime-whisper')`) to stream directly against
|
|
178
177
|
the provider.
|
|
@@ -191,14 +190,14 @@ transcription. ElevenLabs uses
|
|
|
191
190
|
uses `azure.transcription('mai-transcribe-2-streaming')` for streaming-only
|
|
192
191
|
MAI-Transcribe-2-Streaming. xAI
|
|
193
192
|
uses the same `xai.transcription()` model for request/response and streaming
|
|
194
|
-
transcription; `
|
|
193
|
+
transcription; `streamTranscription` selects the provider's
|
|
195
194
|
WebSocket STT transport.
|
|
196
195
|
|
|
197
196
|
```ts
|
|
198
197
|
import { xai } from '@ai-sdk/xai';
|
|
199
|
-
import {
|
|
198
|
+
import { streamTranscription } from 'ai';
|
|
200
199
|
|
|
201
|
-
const result =
|
|
200
|
+
const result = streamTranscription({
|
|
202
201
|
model: xai.transcription(),
|
|
203
202
|
audio: audioStream,
|
|
204
203
|
inputAudioFormat: { type: 'audio/pcm', rate: 16000 },
|
|
@@ -5,15 +5,13 @@ description: Learn how to translate speech with the AI SDK.
|
|
|
5
5
|
|
|
6
6
|
# Translation
|
|
7
7
|
|
|
8
|
-
<Note type="warning">Speech translation is an experimental feature.</Note>
|
|
9
|
-
|
|
10
8
|
The AI SDK provides the
|
|
11
|
-
[`
|
|
9
|
+
[`streamSpeechTranslation`](/docs/reference/ai-sdk-core/stream-speech-translation)
|
|
12
10
|
function to translate live speech into another language. Translation is a
|
|
13
11
|
streaming-only modality: models translate live source audio into
|
|
14
12
|
target-language audio and text.
|
|
15
13
|
|
|
16
|
-
`
|
|
14
|
+
`streamSpeechTranslation` is built on the speech translation model
|
|
17
15
|
specification (`Experimental_SpeechTranslationModelV4`).
|
|
18
16
|
|
|
19
17
|
<Note>
|
|
@@ -25,10 +23,10 @@ specification (`Experimental_SpeechTranslationModelV4`).
|
|
|
25
23
|
|
|
26
24
|
```ts
|
|
27
25
|
import { openai } from '@ai-sdk/openai';
|
|
28
|
-
import {
|
|
26
|
+
import { streamSpeechTranslation } from 'ai';
|
|
29
27
|
|
|
30
|
-
const result =
|
|
31
|
-
model: openai.
|
|
28
|
+
const result = streamSpeechTranslation({
|
|
29
|
+
model: openai.speechTranslation('gpt-realtime-translate'),
|
|
32
30
|
audio: audioStream, // ReadableStream<Uint8Array | string>
|
|
33
31
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
34
32
|
targetLanguage: 'es',
|
|
@@ -109,10 +107,10 @@ audio chunks. When absent, the provider default output format is used.
|
|
|
109
107
|
|
|
110
108
|
```ts highlight="8"
|
|
111
109
|
import { openai } from '@ai-sdk/openai';
|
|
112
|
-
import {
|
|
110
|
+
import { streamSpeechTranslation } from 'ai';
|
|
113
111
|
|
|
114
|
-
const result =
|
|
115
|
-
model: openai.
|
|
112
|
+
const result = streamSpeechTranslation({
|
|
113
|
+
model: openai.speechTranslation('gpt-realtime-translate'),
|
|
116
114
|
audio: audioStream,
|
|
117
115
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
118
116
|
outputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
@@ -127,10 +125,10 @@ set using the `providerOptions` parameter.
|
|
|
127
125
|
|
|
128
126
|
```ts highlight="9-13"
|
|
129
127
|
import { openai } from '@ai-sdk/openai';
|
|
130
|
-
import {
|
|
128
|
+
import { streamSpeechTranslation } from 'ai';
|
|
131
129
|
|
|
132
|
-
const result =
|
|
133
|
-
model: openai.
|
|
130
|
+
const result = streamSpeechTranslation({
|
|
131
|
+
model: openai.speechTranslation('gpt-realtime-translate'),
|
|
134
132
|
audio: audioStream,
|
|
135
133
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
136
134
|
targetLanguage: 'es',
|
|
@@ -148,10 +146,10 @@ Pass an `abortSignal` to cancel the translation:
|
|
|
148
146
|
|
|
149
147
|
```ts highlight="9"
|
|
150
148
|
import { openai } from '@ai-sdk/openai';
|
|
151
|
-
import {
|
|
149
|
+
import { streamSpeechTranslation } from 'ai';
|
|
152
150
|
|
|
153
|
-
const result =
|
|
154
|
-
model: openai.
|
|
151
|
+
const result = streamSpeechTranslation({
|
|
152
|
+
model: openai.speechTranslation('gpt-realtime-translate'),
|
|
155
153
|
audio: audioStream,
|
|
156
154
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
157
155
|
targetLanguage: 'es',
|
|
@@ -161,7 +159,7 @@ const result = streamTranslate({
|
|
|
161
159
|
|
|
162
160
|
### Error Handling
|
|
163
161
|
|
|
164
|
-
When `
|
|
162
|
+
When `streamSpeechTranslation` cannot produce a translation — no `audio`
|
|
165
163
|
part was emitted and the final output text is empty, or the stream ends
|
|
166
164
|
without a finish event — it errors with a
|
|
167
165
|
[`AI_NoTranslationGeneratedError`](/docs/reference/ai-sdk-errors/ai-no-translation-generated-error).
|
|
@@ -175,14 +173,11 @@ The error preserves the following information to help you log the issue:
|
|
|
175
173
|
|
|
176
174
|
```ts
|
|
177
175
|
import { openai } from '@ai-sdk/openai';
|
|
178
|
-
import {
|
|
179
|
-
experimental_streamTranslate as streamTranslate,
|
|
180
|
-
NoTranslationGeneratedError,
|
|
181
|
-
} from 'ai';
|
|
176
|
+
import { NoTranslationGeneratedError, streamSpeechTranslation } from 'ai';
|
|
182
177
|
|
|
183
178
|
try {
|
|
184
|
-
const result =
|
|
185
|
-
model: openai.
|
|
179
|
+
const result = streamSpeechTranslation({
|
|
180
|
+
model: openai.speechTranslation('gpt-realtime-translate'),
|
|
186
181
|
audio: audioStream,
|
|
187
182
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
188
183
|
targetLanguage: 'es',
|
|
@@ -139,6 +139,12 @@ A retry remains part of the same logical step. `onStepStart` runs once for that
|
|
|
139
139
|
step. `onLanguageModelCallStart` runs for each provider call attempt, while
|
|
140
140
|
`onLanguageModelCallEnd` runs only for attempts that reach a model-call finish.
|
|
141
141
|
|
|
142
|
+
Before each automatic or callback-directed stream retry, `streamText` waits
|
|
143
|
+
with exponential backoff (2 seconds, then 4 seconds, and so on). When the
|
|
144
|
+
provider sends a reasonable `retry-after-ms` or `retry-after` header (less than
|
|
145
|
+
60 seconds), that delay is used instead. Aborting the call or cancelling the
|
|
146
|
+
stream ends the wait without calling the provider again.
|
|
147
|
+
|
|
142
148
|
You can also decide dynamically in `onError`. Set `streamRetries` explicitly to
|
|
143
149
|
enable stream recovery; use `0` when a single retry should only be
|
|
144
150
|
callback-directed:
|
|
@@ -94,23 +94,23 @@ telemetry views.
|
|
|
94
94
|
|
|
95
95
|
For `generateSpeech`, input telemetry contains the source text and output
|
|
96
96
|
telemetry contains the generated audio byte length, media type, and format.
|
|
97
|
-
For `transcribe` and `
|
|
97
|
+
For `transcribe` and `streamTranscription`, telemetry contains the
|
|
98
98
|
input audio byte length and media type plus the output transcript. Raw audio is
|
|
99
99
|
never included in telemetry events. Streaming transcription reports its final
|
|
100
100
|
byte length when the audio stream has been consumed and the transcription
|
|
101
101
|
finishes.
|
|
102
102
|
|
|
103
103
|
Custom integrations receive stable `generateSpeech` and `transcribe`
|
|
104
|
-
operations through `onStart` and `onEnd`.
|
|
105
|
-
|
|
104
|
+
operations through `onStart` and `onEnd`. Streaming transcription reports its
|
|
105
|
+
lifecycle through the still experimental
|
|
106
106
|
`experimental_onStreamTranscriptionStart` and
|
|
107
|
-
`experimental_onStreamTranscriptionEnd
|
|
108
|
-
through `onError`.
|
|
107
|
+
`experimental_onStreamTranscriptionEnd` callbacks; all three operations report
|
|
108
|
+
failures through `onError`.
|
|
109
109
|
|
|
110
110
|
An integration that wraps or delegates to another integration must explicitly
|
|
111
111
|
forward the experimental streaming transcription callbacks. Forwarding only
|
|
112
112
|
the stable `onStart` and `onEnd` callbacks does not observe
|
|
113
|
-
`
|
|
113
|
+
`streamTranscription`.
|
|
114
114
|
|
|
115
115
|
The built-in OpenTelemetry integrations record numeric provider usage by
|
|
116
116
|
default, preserving each reported unit. The modern integration uses attributes
|
|
@@ -312,9 +312,9 @@ example on a tool approval), using the original event timestamps. The root
|
|
|
312
312
|
includes the run's prompt and final output, subject to `recordInputs` and
|
|
313
313
|
`recordOutputs`.
|
|
314
314
|
|
|
315
|
-
|
|
316
|
-
decision once. That context is carried to subsequent steps, preserving
|
|
317
|
-
ID, sampling decision, and trace state. By default, the bridge uses parent-based
|
|
315
|
+
The run's first model step captures the active parent trace and makes the run's
|
|
316
|
+
sampling decision once. That context is carried to subsequent steps, preserving
|
|
317
|
+
the trace ID, sampling decision, and trace state. By default, the bridge uses parent-based
|
|
318
318
|
sampling with roots enabled. To use another sampler, pass it through
|
|
319
319
|
`new OpenTelemetryIdGenerator({ sampler: yourSampler })` and keep the bridge as
|
|
320
320
|
the provider's sampler. Unrelated spans use random IDs and the configured sampler.
|
|
@@ -470,8 +470,10 @@ For durable workflows, integrations normally receive recorded events after the
|
|
|
470
470
|
run ends. Events can include `timestamp` (Unix milliseconds); use it for span
|
|
471
471
|
start and end times instead of the current time. Integrations that can reconstruct
|
|
472
472
|
traces across processes can implement the experimental
|
|
473
|
-
`experimental_durable.captureContext(event)` hook. It runs in
|
|
474
|
-
|
|
473
|
+
`experimental_durable.captureContext(event)` hook. It runs in the
|
|
474
|
+
run's first model step, before any model call (or in the reporting step when the
|
|
475
|
+
run ends before its first model step), and returns a serializable
|
|
476
|
+
`DurableTelemetryContext`. Live model-start events
|
|
475
477
|
then carry that context in `event.durableContext` with `phase: 'live'`; the
|
|
476
478
|
recorded operation-start event carries it with `phase: 'replay'`. Such integrations
|
|
477
479
|
should skip replayed model events to avoid duplicate spans. Returning `undefined`
|
|
@@ -772,7 +774,7 @@ For `rerank`, the integration records spans with `CLIENT` kind:
|
|
|
772
774
|
- `gen_ai.provider.name`: the provider
|
|
773
775
|
- `gen_ai.request.model`: the model ID
|
|
774
776
|
|
|
775
|
-
#### generateSpeech / transcribe /
|
|
777
|
+
#### generateSpeech / transcribe / streamTranscription
|
|
776
778
|
|
|
777
779
|
Each call records a single `CLIENT` span named `{operationId} {modelId}`, where
|
|
778
780
|
`operationId` is `ai.generateSpeech`, `ai.transcribe`, or `ai.streamTranscribe`.
|
|
@@ -114,15 +114,17 @@ In Node.js, these warnings have the type `DeprecationWarning` and a stable
|
|
|
114
114
|
`AISDK_DEP_*` code, available as `warning.code` on `process.on('warning', handler)`.
|
|
115
115
|
Browser/edge console messages include the code in brackets.
|
|
116
116
|
|
|
117
|
-
| Code
|
|
118
|
-
|
|
|
119
|
-
| `AISDK_DEP_GENERATE_OBJECT`
|
|
120
|
-
| `AISDK_DEP_STREAM_OBJECT`
|
|
121
|
-
| `AISDK_DEP_EXPERIMENTAL_GENERATE_SPEECH`
|
|
122
|
-
| `AISDK_DEP_EXPERIMENTAL_TRANSCRIBE`
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
117
|
+
| Code | Deprecated usage / replacement |
|
|
118
|
+
| ------------------------------------------ | -------------------------------------------------------------------------- |
|
|
119
|
+
| `AISDK_DEP_GENERATE_OBJECT` | Use `generateText` with `output` instead of `generateObject`. |
|
|
120
|
+
| `AISDK_DEP_STREAM_OBJECT` | Use `streamText` with `output` instead of `streamObject`. |
|
|
121
|
+
| `AISDK_DEP_EXPERIMENTAL_GENERATE_SPEECH` | Use `generateSpeech` instead of `experimental_generateSpeech`. |
|
|
122
|
+
| `AISDK_DEP_EXPERIMENTAL_TRANSCRIBE` | Use `transcribe` instead of `experimental_transcribe`. |
|
|
123
|
+
| `AISDK_DEP_EXPERIMENTAL_STREAM_TRANSCRIBE` | Use `streamTranscription` instead of `experimental_streamTranscribe`. |
|
|
124
|
+
| `AISDK_DEP_EXPERIMENTAL_STREAM_TRANSLATE` | Use `streamSpeechTranslation` instead of `experimental_streamTranslate`. |
|
|
125
|
+
| `AISDK_DEP_TOOL_RESULT_*` | Use `file` with tagged `data` instead of legacy tool-result content types. |
|
|
126
|
+
| `AISDK_DEP_UI_MESSAGE_RAW_INPUT` | Use `input` instead of `rawInput` in UI tool parts. |
|
|
127
|
+
| `AISDK_DEP_IMAGE_CONTENT_PART` | Use `file` with an image `mediaType` instead of `image` message parts. |
|
|
126
128
|
|
|
127
129
|
Run Node.js with `--throw-deprecation` to fail on deprecated usage,
|
|
128
130
|
`--no-deprecation` to suppress deprecations, or `--trace-deprecation` for stack
|
|
@@ -479,7 +479,7 @@ retain the content their contracts require.
|
|
|
479
479
|
type: 'number',
|
|
480
480
|
isOptional: true,
|
|
481
481
|
description:
|
|
482
|
-
'Maximum number of automatic retries for provider error events received after response streaming begins. Retries rerun only the current model step and preserve completed earlier steps and their tool results. Tool-related output and client-side tool work from failed attempts are discarded; other output already emitted cannot be retracted, but is excluded from the recovered step result, structured output parsing, response messages, and subsequent model steps. Final request and response metadata come from the recovered attempt. Open text and reasoning parts are ended before recovered output begins. onStepStart runs once for the logical step, onLanguageModelCallStart runs for each attempt, and onLanguageModelCallEnd runs for attempts that reach a model-call finish. Provider-executed tool work cannot be undone and may repeat. Set to 0 to disable automatic retries while allowing onError to request one callback-directed retry. With automatic retries configured, onError can request at most one additional retry after they are exhausted, bounding total recovery calls to streamRetries + 1. Omit to disable all stream retry behavior and preserve incremental tool streaming for existing onError observers. Default: 0.',
|
|
482
|
+
'Maximum number of automatic retries for provider error events received after response streaming begins. Retries rerun only the current model step and preserve completed earlier steps and their tool results. Tool-related output and client-side tool work from failed attempts are discarded; other output already emitted cannot be retracted, but is excluded from the recovered step result, structured output parsing, response messages, and subsequent model steps. Final request and response metadata come from the recovered attempt. Open text and reasoning parts are ended before recovered output begins. Each retry waits with exponential backoff starting at 2 seconds, or for the delay from a reasonable retry-after-ms or retry-after response header. onStepStart runs once for the logical step, onLanguageModelCallStart runs for each attempt, and onLanguageModelCallEnd runs for attempts that reach a model-call finish. Provider-executed tool work cannot be undone and may repeat. Set to 0 to disable automatic retries while allowing onError to request one callback-directed retry. With automatic retries configured, onError can request at most one additional retry after they are exhausted, bounding total recovery calls to streamRetries + 1. Omit to disable all stream retry behavior and preserve incremental tool streaming for existing onError observers. Default: 0.',
|
|
483
483
|
},
|
|
484
484
|
{
|
|
485
485
|
name: 'abortSignal',
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
3
|
-
description: API Reference for
|
|
2
|
+
title: streamSpeechTranslation
|
|
3
|
+
description: API Reference for streamSpeechTranslation.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# `
|
|
7
|
-
|
|
8
|
-
<Note type="warning">
|
|
9
|
-
`experimental_streamTranslate` is an experimental feature.
|
|
10
|
-
</Note>
|
|
6
|
+
# `streamSpeechTranslation()`
|
|
11
7
|
|
|
12
8
|
Streams a speech-to-speech translation from live raw audio. Models translate
|
|
13
9
|
live source audio into target-language audio and text.
|
|
14
10
|
|
|
15
|
-
`
|
|
11
|
+
`streamSpeechTranslation` is built on the speech translation model
|
|
16
12
|
specification (`Experimental_SpeechTranslationModelV4`). Provider
|
|
17
13
|
implementations of the specification ship separately — see your provider's
|
|
18
14
|
documentation for available translation models.
|
|
19
15
|
|
|
20
16
|
```ts
|
|
21
|
-
import {
|
|
17
|
+
import { streamSpeechTranslation } from 'ai';
|
|
22
18
|
|
|
23
|
-
const result =
|
|
19
|
+
const result = streamSpeechTranslation({
|
|
24
20
|
// any provider model instance that implements the experimental
|
|
25
21
|
// speech translation model specification (Experimental_SpeechTranslationModelV4):
|
|
26
22
|
model: translationModel,
|
|
@@ -40,10 +36,7 @@ console.log(await result.translationText);
|
|
|
40
36
|
|
|
41
37
|
## Import
|
|
42
38
|
|
|
43
|
-
<Snippet
|
|
44
|
-
text={`import { experimental_streamTranslate as streamTranslate } from "ai"`}
|
|
45
|
-
prompt={false}
|
|
46
|
-
/>
|
|
39
|
+
<Snippet text={`import { streamSpeechTranslation } from "ai"`} prompt={false} />
|
|
47
40
|
|
|
48
41
|
## API Signature
|
|
49
42
|
|
|
@@ -55,7 +48,7 @@ console.log(await result.translationText);
|
|
|
55
48
|
name: 'model',
|
|
56
49
|
type: 'Experimental_SpeechTranslationModelV4',
|
|
57
50
|
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
|
|
51
|
+
'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, e.g. `openai.speechTranslation("gpt-realtime-translate")`. String model IDs resolve through the global default provider (`AI_SDK_DEFAULT_PROVIDER`) only when that provider implements `speechTranslationModel`. AI Gateway does not support speech translation models.',
|
|
59
52
|
},
|
|
60
53
|
{
|
|
61
54
|
name: 'audio',
|
|
@@ -124,7 +117,7 @@ console.log(await result.translationText);
|
|
|
124
117
|
content={[
|
|
125
118
|
{
|
|
126
119
|
name: 'fullStream',
|
|
127
|
-
type: 'AsyncIterableStream<
|
|
120
|
+
type: 'AsyncIterableStream<SpeechTranslationStreamPart>',
|
|
128
121
|
description:
|
|
129
122
|
'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
123
|
},
|
package/docs/07-reference/01-ai-sdk-core/{11-stream-transcribe.mdx → 11-stream-transcription.mdx}
RENAMED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
3
|
-
description: API Reference for
|
|
2
|
+
title: streamTranscription
|
|
3
|
+
description: API Reference for streamTranscription.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# `
|
|
7
|
-
|
|
8
|
-
<Note type="warning">
|
|
9
|
-
`experimental_streamTranscribe` is an experimental feature.
|
|
10
|
-
</Note>
|
|
6
|
+
# `streamTranscription()`
|
|
11
7
|
|
|
12
8
|
Streams a transcript from live raw audio using a transcription model with
|
|
13
9
|
streaming support.
|
|
14
10
|
|
|
15
11
|
```ts
|
|
16
|
-
import {
|
|
12
|
+
import { streamTranscription } from 'ai';
|
|
17
13
|
import { openai } from '@ai-sdk/openai';
|
|
18
14
|
|
|
19
|
-
const result =
|
|
15
|
+
const result = streamTranscription({
|
|
20
16
|
model: openai.transcription('gpt-realtime-whisper'),
|
|
21
17
|
audio: audioStream, // ReadableStream<Uint8Array | string>
|
|
22
18
|
inputAudioFormat: { type: 'audio/pcm', rate: 24000 },
|
|
@@ -33,10 +29,7 @@ console.log(await result.text);
|
|
|
33
29
|
|
|
34
30
|
## Import
|
|
35
31
|
|
|
36
|
-
<Snippet
|
|
37
|
-
text={`import { experimental_streamTranscribe as streamTranscribe } from "ai"`}
|
|
38
|
-
prompt={false}
|
|
39
|
-
/>
|
|
32
|
+
<Snippet text={`import { streamTranscription } from "ai"`} prompt={false} />
|
|
40
33
|
|
|
41
34
|
## API Signature
|
|
42
35
|
|
|
@@ -48,7 +41,7 @@ console.log(await result.text);
|
|
|
48
41
|
name: 'model',
|
|
49
42
|
type: 'TranscriptionModelV4',
|
|
50
43
|
description:
|
|
51
|
-
"The transcription model to use. The model must support streaming (`doStream`). String model IDs resolve through the global provider (AI Gateway by default), which supports streaming transcription for supported models (e.g. `openai/gpt-realtime-whisper`, `xai/grok-stt`): `
|
|
44
|
+
"The transcription model to use. The model must support streaming (`doStream`). String model IDs resolve through the global provider (AI Gateway by default), which supports streaming transcription for supported models (e.g. `openai/gpt-realtime-whisper`, `xai/grok-stt`): `streamTranscription({ model: 'openai/gpt-realtime-whisper', ... })`.",
|
|
52
45
|
},
|
|
53
46
|
{
|
|
54
47
|
name: 'audio',
|
|
@@ -84,14 +84,14 @@ AI SDK Core contains the following main functions:
|
|
|
84
84
|
href: '/docs/reference/ai-sdk-core/transcribe',
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
title: '
|
|
87
|
+
title: 'streamTranscription()',
|
|
88
88
|
description: 'Stream a transcript from live raw audio.',
|
|
89
|
-
href: '/docs/reference/ai-sdk-core/stream-
|
|
89
|
+
href: '/docs/reference/ai-sdk-core/stream-transcription',
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
|
-
title: '
|
|
92
|
+
title: 'streamSpeechTranslation()',
|
|
93
93
|
description: 'Stream a speech-to-speech translation from live raw audio.',
|
|
94
|
-
href: '/docs/reference/ai-sdk-core/stream-
|
|
94
|
+
href: '/docs/reference/ai-sdk-core/stream-speech-translation',
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
97
|
title: 'generateSpeech()',
|
|
@@ -110,6 +110,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
110
110
|
description:
|
|
111
111
|
'Maximum number of local tool calls executing concurrently within a step, including approved calls. Must be a positive integer. Set to 1 for sequential execution in model order. Defaults to unlimited concurrency. Can be changed by prepareCall; explicit generate/stream call options take precedence. Provider-executed tools are unaffected.',
|
|
112
112
|
},
|
|
113
|
+
{
|
|
114
|
+
name: 'includeMessagesInToolExecution',
|
|
115
|
+
type: 'boolean',
|
|
116
|
+
isOptional: true,
|
|
117
|
+
description:
|
|
118
|
+
"Whether tools receive the conversation as `messages` in their execution options. Defaults to true. When a tool's execute function is a workflow step, its arguments are stored as the step input, so the conversation is stored again for every tool call. Set to false when your tools do not read `messages`; they then receive an empty array. Per-call values override this default.",
|
|
119
|
+
},
|
|
113
120
|
{
|
|
114
121
|
name: 'activeTools',
|
|
115
122
|
type: 'ActiveTools<TTools>',
|
|
@@ -643,6 +650,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
|
|
|
643
650
|
description:
|
|
644
651
|
'Override the local tool call concurrency limit for this call. Must be a positive integer. Set to 1 for sequential execution in model order, including approved calls. Takes precedence over the constructor and prepareCall.',
|
|
645
652
|
},
|
|
653
|
+
{
|
|
654
|
+
name: 'includeMessagesInToolExecution',
|
|
655
|
+
type: 'boolean',
|
|
656
|
+
isOptional: true,
|
|
657
|
+
description:
|
|
658
|
+
'Whether tools receive the conversation as `messages` in their execution options for this call. Set to false to pass an empty array instead. Overrides the constructor value.',
|
|
659
|
+
},
|
|
646
660
|
{
|
|
647
661
|
name: 'activeTools',
|
|
648
662
|
type: 'ActiveTools<TTools>',
|
|
@@ -10,6 +10,7 @@ This error occurs when no transcript could be generated from the input.
|
|
|
10
10
|
## Properties
|
|
11
11
|
|
|
12
12
|
- `responses`: Array of transcription model response metadata (required in constructor)
|
|
13
|
+
- `cause`: The provider error reported in the stream before a streaming transcription ended without a transcript, if any (optional)
|
|
13
14
|
|
|
14
15
|
## Checking for this Error
|
|
15
16
|
|
|
@@ -12,6 +12,7 @@ ended without a finish event.
|
|
|
12
12
|
## Properties
|
|
13
13
|
|
|
14
14
|
- `response`: Speech translation model response metadata (required in constructor)
|
|
15
|
+
- `cause`: The provider error reported in the stream before a streaming translation ended without a translation, if any (optional)
|
|
15
16
|
|
|
16
17
|
## Checking for this Error
|
|
17
18
|
|