ai 7.0.123 → 7.0.126

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 (35) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/index.d.ts +232 -34
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +415 -100
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +199 -8
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +9 -3
  9. package/dist/internal/index.js.map +1 -1
  10. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +25 -0
  11. package/docs/03-ai-sdk-core/36-transcription.mdx +38 -1
  12. package/docs/03-ai-sdk-core/37-speech.mdx +23 -0
  13. package/docs/03-ai-sdk-core/60-telemetry.mdx +49 -1
  14. package/docs/07-reference/01-ai-sdk-core/11-stream-transcribe.mdx +7 -0
  15. package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +7 -0
  16. package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +7 -0
  17. package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +7 -0
  18. package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +7 -0
  19. package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +7 -0
  20. package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +60 -3
  21. package/package.json +12 -12
  22. package/src/agent/create-agent-ui-stream-response.ts +16 -4
  23. package/src/agent/create-agent-ui-stream.ts +16 -2
  24. package/src/agent/pipe-agent-ui-stream-to-response.ts +16 -4
  25. package/src/generate-speech/generate-speech.ts +163 -38
  26. package/src/generate-speech/index.ts +4 -0
  27. package/src/generate-speech/speech-events.ts +91 -0
  28. package/src/telemetry/create-telemetry-dispatcher.ts +18 -5
  29. package/src/telemetry/telemetry.ts +38 -6
  30. package/src/telemetry/tracing-channel.ts +3 -0
  31. package/src/transcribe/index.ts +6 -0
  32. package/src/transcribe/stream-transcribe.ts +182 -31
  33. package/src/transcribe/transcribe.ts +186 -33
  34. package/src/transcribe/transcription-events.ts +111 -0
  35. package/src/ui/chat.ts +36 -5
@@ -0,0 +1,111 @@
1
+ import type { JSONObject, SharedV4AudioFormat } from '@ai-sdk/provider';
2
+ import type { ProviderOptions } from '@ai-sdk/provider-utils';
3
+ import type { ProviderMetadata } from '../types';
4
+ import type { TranscriptionModelResponseMetadata } from '../types/transcription-model-response-metadata';
5
+ import type { Warning } from '../types/warning';
6
+
7
+ /**
8
+ * Event passed to telemetry integrations when transcription begins.
9
+ */
10
+ type TranscriptionStartEventFor<OPERATION_ID extends string> = {
11
+ /** Unique identifier for this transcription call. */
12
+ readonly callId: string;
13
+
14
+ /** Identifies the operation type (`ai.transcribe` or `ai.streamTranscribe`). */
15
+ readonly operationId: OPERATION_ID;
16
+
17
+ /** The provider identifier. */
18
+ readonly provider: string;
19
+
20
+ /** The specific model identifier. */
21
+ readonly modelId: string;
22
+
23
+ /**
24
+ * Metadata about the input audio. The byte length is known immediately for
25
+ * non-streaming transcription and is reported on the end event for streams.
26
+ */
27
+ readonly audio: {
28
+ readonly byteLength: number | undefined;
29
+ /**
30
+ * The media type, when it is known before input preparation completes.
31
+ * URL downloads and invalid inline inputs can begin without this metadata.
32
+ */
33
+ readonly mediaType: string | undefined;
34
+ };
35
+
36
+ /** The raw input format for streaming transcription. */
37
+ readonly inputAudioFormat: SharedV4AudioFormat | undefined;
38
+
39
+ /** Maximum number of retries for non-streaming transcription. */
40
+ readonly maxRetries: number | undefined;
41
+
42
+ /** Additional HTTP or WebSocket headers sent with the request. */
43
+ readonly headers: Record<string, string> | undefined;
44
+
45
+ /** Additional provider-specific options. */
46
+ readonly providerOptions: ProviderOptions;
47
+ };
48
+
49
+ export type TranscriptionStartEvent =
50
+ TranscriptionStartEventFor<'ai.transcribe'>;
51
+
52
+ export type StreamTranscriptionStartEvent =
53
+ TranscriptionStartEventFor<'ai.streamTranscribe'>;
54
+
55
+ /**
56
+ * Event passed to telemetry integrations when transcription completes.
57
+ *
58
+ * Raw audio is intentionally not included.
59
+ */
60
+ type TranscriptionEndEventFor<OPERATION_ID extends string> = {
61
+ /** Unique identifier for this transcription call. */
62
+ readonly callId: string;
63
+
64
+ /** Identifies the operation type (`ai.transcribe` or `ai.streamTranscribe`). */
65
+ readonly operationId: OPERATION_ID;
66
+
67
+ /** The provider identifier. */
68
+ readonly provider: string;
69
+
70
+ /** The specific model identifier. */
71
+ readonly modelId: string;
72
+
73
+ /** Metadata about the input audio. */
74
+ readonly audio: {
75
+ readonly byteLength: number;
76
+ readonly mediaType: string;
77
+ };
78
+
79
+ /** The complete transcript. */
80
+ readonly text: string;
81
+
82
+ /** Transcript segments with timing information. */
83
+ readonly segments: Array<{
84
+ readonly text: string;
85
+ readonly startSecond: number;
86
+ readonly endSecond: number;
87
+ }>;
88
+
89
+ /** The detected language. */
90
+ readonly language: string | undefined;
91
+
92
+ /** The duration of the input audio, when available. */
93
+ readonly durationInSeconds: number | undefined;
94
+
95
+ /** Usage reported by the provider, when available. */
96
+ readonly usage: JSONObject | undefined;
97
+
98
+ /** Warnings from the transcription model. */
99
+ readonly warnings: Array<Warning>;
100
+
101
+ /** Optional provider-specific metadata. */
102
+ readonly providerMetadata: ProviderMetadata | undefined;
103
+
104
+ /** Response metadata from the provider. */
105
+ readonly response: TranscriptionModelResponseMetadata;
106
+ };
107
+
108
+ export type TranscriptionEndEvent = TranscriptionEndEventFor<'ai.transcribe'>;
109
+
110
+ export type StreamTranscriptionEndEvent =
111
+ TranscriptionEndEventFor<'ai.streamTranscribe'>;
package/src/ui/chat.ts CHANGED
@@ -609,7 +609,7 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
609
609
  });
610
610
 
611
611
  addToolOutput: ChatAddToolOutputFunction<UI_MESSAGE> = async ({
612
- state = 'output-available',
612
+ state,
613
613
  toolCallId,
614
614
  output,
615
615
  errorText,
@@ -621,10 +621,41 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
621
621
 
622
622
  const updatePart = (
623
623
  part: UIMessagePart<UIDataTypes, UITools>,
624
- ): UIMessagePart<UIDataTypes, UITools> =>
625
- isToolUIPart(part) && part.toolCallId === toolCallId
626
- ? ({ ...part, state, output, errorText } as typeof part)
627
- : part;
624
+ ): UIMessagePart<UIDataTypes, UITools> => {
625
+ if (!isToolUIPart(part) || part.toolCallId !== toolCallId) {
626
+ return part;
627
+ }
628
+
629
+ // Output states can only retain approvals that were granted.
630
+ const { approval: existingApproval, ...toolPart } = part;
631
+ const approval =
632
+ existingApproval?.approved === true
633
+ ? {
634
+ approval: {
635
+ ...existingApproval,
636
+ approved: existingApproval.approved,
637
+ },
638
+ }
639
+ : {};
640
+
641
+ return state === 'output-error'
642
+ ? {
643
+ ...toolPart,
644
+ ...approval,
645
+ state,
646
+ input: part.input,
647
+ output: undefined,
648
+ errorText,
649
+ }
650
+ : {
651
+ ...toolPart,
652
+ ...approval,
653
+ state: 'output-available',
654
+ input: part.input,
655
+ output,
656
+ errorText: undefined,
657
+ };
658
+ };
628
659
 
629
660
  // update the message to trigger an immediate UI update
630
661
  this.state.replaceMessage(messages.length - 1, {