ai 7.0.0-beta.113 → 7.0.0-beta.115
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 +32 -0
- package/dist/index.d.ts +1506 -1468
- package/dist/index.js +889 -979
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +273 -273
- package/dist/internal/index.js +367 -405
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +18 -18
- package/dist/test/index.js +22 -22
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/03-prompts.mdx +13 -11
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +2 -1
- package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +1 -1
- package/docs/03-ai-sdk-core/60-telemetry.mdx +87 -13
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +9 -1
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +104 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +56 -10
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +1 -1
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +42 -0
- package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
- package/package.json +5 -5
- package/src/agent/agent.ts +13 -9
- package/src/agent/create-agent-ui-stream-response.ts +8 -8
- package/src/agent/create-agent-ui-stream.ts +9 -9
- package/src/agent/infer-agent-tools.ts +1 -1
- package/src/agent/infer-agent-ui-message.ts +2 -2
- package/src/agent/pipe-agent-ui-stream-to-response.ts +9 -9
- package/src/agent/tool-loop-agent-settings.ts +17 -19
- package/src/agent/tool-loop-agent.ts +16 -8
- package/src/embed/embed-many-result.ts +3 -4
- package/src/embed/embed-many.ts +5 -5
- package/src/embed/embed-result.ts +3 -4
- package/src/embed/embed.ts +4 -4
- package/src/error/invalid-stream-part-error.ts +1 -1
- package/src/error/no-image-generated-error.ts +1 -1
- package/src/error/no-object-generated-error.ts +3 -3
- package/src/error/no-speech-generated-error.ts +1 -1
- package/src/error/no-transcript-generated-error.ts +1 -1
- package/src/error/no-video-generated-error.ts +1 -1
- package/src/error/tool-call-repair-error.ts +2 -2
- package/src/error/verify-no-object-generated-error.ts +1 -1
- package/src/generate-image/generate-image-result.ts +5 -5
- package/src/generate-image/generate-image.ts +12 -15
- package/src/generate-image/index.ts +3 -2
- package/src/generate-object/generate-object-result.ts +2 -2
- package/src/generate-object/generate-object.ts +14 -14
- package/src/generate-object/inject-json-instruction.ts +1 -1
- package/src/generate-object/output-strategy.ts +10 -10
- package/src/generate-object/parse-and-validate-object-result.ts +1 -1
- package/src/generate-object/repair-text.ts +1 -1
- package/src/generate-object/stream-object-result.ts +4 -4
- package/src/generate-object/stream-object.ts +22 -19
- package/src/generate-object/validate-object-generation-input.ts +1 -1
- package/src/generate-speech/generate-speech-result.ts +4 -4
- package/src/generate-speech/generate-speech.ts +12 -13
- package/src/generate-speech/generated-audio-file.ts +1 -2
- package/src/generate-text/collect-tool-approvals.ts +4 -4
- package/src/generate-text/content-part.ts +9 -9
- package/src/generate-text/create-execute-tools-transformation.ts +9 -7
- package/src/generate-text/execute-tool-call.ts +11 -13
- package/src/generate-text/extract-reasoning-content.ts +1 -1
- package/src/generate-text/extract-text-content.ts +4 -1
- package/src/generate-text/generate-text-events.ts +2 -2
- package/src/generate-text/generate-text-result.ts +18 -14
- package/src/generate-text/generate-text.ts +42 -38
- package/src/generate-text/invoke-tool-callbacks-from-stream.ts +2 -3
- package/src/generate-text/output-utils.ts +1 -1
- package/src/generate-text/output.ts +8 -8
- package/src/generate-text/parse-tool-call.ts +36 -9
- package/src/generate-text/prepare-step.ts +3 -5
- package/src/generate-text/prune-messages.ts +1 -1
- package/src/generate-text/reasoning-output.ts +26 -9
- package/src/generate-text/reasoning.ts +1 -1
- package/src/generate-text/resolve-tool-approval.ts +3 -3
- package/src/generate-text/response-message.ts +1 -1
- package/src/generate-text/restricted-telemetry-dispatcher.ts +1 -1
- package/src/generate-text/smooth-stream.ts +6 -5
- package/src/generate-text/step-result.ts +16 -11
- package/src/generate-text/stop-condition.ts +1 -1
- package/src/generate-text/stream-language-model-call.ts +26 -21
- package/src/generate-text/stream-text-result.ts +29 -26
- package/src/generate-text/stream-text.ts +48 -46
- package/src/generate-text/to-response-messages.ts +2 -2
- package/src/generate-text/tool-approval-configuration.ts +2 -2
- package/src/generate-text/tool-approval-request-output.ts +1 -1
- package/src/generate-text/tool-approval-response-output.ts +1 -1
- package/src/generate-text/tool-call-repair-function.ts +4 -4
- package/src/generate-text/tool-call.ts +3 -4
- package/src/generate-text/tool-error.ts +3 -4
- package/src/generate-text/tool-execution-events.ts +2 -2
- package/src/generate-text/tool-output-denied.ts +1 -1
- package/src/generate-text/tool-output.ts +2 -2
- package/src/generate-text/tool-result.ts +7 -4
- package/src/generate-text/tools-context-parameter.ts +1 -1
- package/src/generate-text/validate-tool-context.ts +1 -2
- package/src/generate-video/generate-video-result.ts +4 -4
- package/src/generate-video/generate-video.ts +6 -10
- package/src/global.ts +2 -2
- package/src/index.ts +3 -3
- package/src/logger/log-warnings.ts +1 -1
- package/src/middleware/add-tool-input-examples-middleware.ts +2 -2
- package/src/middleware/default-embedding-settings-middleware.ts +2 -2
- package/src/middleware/default-settings-middleware.ts +2 -2
- package/src/middleware/extract-json-middleware.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +1 -1
- package/src/middleware/simulate-streaming-middleware.ts +1 -1
- package/src/middleware/wrap-embedding-model.ts +2 -2
- package/src/middleware/wrap-image-model.ts +2 -2
- package/src/middleware/wrap-language-model.ts +2 -2
- package/src/middleware/wrap-provider.ts +2 -2
- package/src/model/as-embedding-model-v3.ts +1 -1
- package/src/model/as-embedding-model-v4.ts +1 -1
- package/src/model/as-image-model-v3.ts +1 -1
- package/src/model/as-image-model-v4.ts +5 -1
- package/src/model/as-language-model-v3.ts +1 -1
- package/src/model/as-language-model-v4.ts +1 -1
- package/src/model/as-provider-v3.ts +1 -1
- package/src/model/as-provider-v4.ts +1 -1
- package/src/model/as-reranking-model-v4.ts +1 -1
- package/src/model/as-speech-model-v3.ts +1 -1
- package/src/model/as-speech-model-v4.ts +5 -1
- package/src/model/as-transcription-model-v3.ts +4 -1
- package/src/model/as-transcription-model-v4.ts +1 -1
- package/src/model/as-video-model-v4.ts +1 -1
- package/src/model/resolve-model.ts +8 -8
- package/src/prompt/content-part.ts +45 -15
- package/src/prompt/convert-to-language-model-prompt.ts +108 -122
- package/src/prompt/create-tool-model-output.ts +2 -2
- package/src/prompt/data-content.ts +1 -78
- package/src/prompt/file-part-data.ts +125 -0
- package/src/prompt/index.ts +3 -2
- package/src/prompt/language-model-call-options.ts +1 -1
- package/src/prompt/message-conversion-error.ts +1 -1
- package/src/prompt/message.ts +1 -1
- package/src/prompt/prepare-language-model-call-options.ts +1 -1
- package/src/prompt/prepare-tool-choice.ts +2 -2
- package/src/prompt/prepare-tools.ts +2 -2
- package/src/prompt/prompt.ts +1 -1
- package/src/prompt/standardize-prompt.ts +3 -3
- package/src/registry/custom-provider.ts +127 -92
- package/src/registry/index.ts +1 -1
- package/src/registry/provider-registry.ts +91 -87
- package/src/rerank/rerank-result.ts +1 -1
- package/src/rerank/rerank.ts +8 -5
- package/src/telemetry/create-telemetry-dispatcher.ts +11 -1
- package/src/telemetry/diagnostic-channel-publisher.ts +50 -0
- package/src/telemetry/diagnostic-channel.ts +24 -0
- package/src/telemetry/index.ts +5 -0
- package/src/telemetry/telemetry.ts +1 -1
- package/src/test/mock-embedding-model-v2.ts +1 -1
- package/src/test/mock-embedding-model-v3.ts +1 -1
- package/src/test/mock-embedding-model-v4.ts +1 -1
- package/src/test/mock-image-model-v2.ts +1 -1
- package/src/test/mock-image-model-v3.ts +1 -1
- package/src/test/mock-image-model-v4.ts +1 -1
- package/src/test/mock-language-model-v2.ts +1 -1
- package/src/test/mock-language-model-v3.ts +1 -1
- package/src/test/mock-language-model-v4.ts +1 -1
- package/src/test/mock-provider-v2.ts +6 -7
- package/src/test/mock-provider-v3.ts +7 -8
- package/src/test/mock-provider-v4.ts +7 -8
- package/src/test/mock-reranking-model-v3.ts +1 -1
- package/src/test/mock-reranking-model-v4.ts +1 -1
- package/src/test/mock-server-response.ts +1 -1
- package/src/test/mock-speech-model-v2.ts +1 -1
- package/src/test/mock-speech-model-v3.ts +1 -1
- package/src/test/mock-speech-model-v4.ts +1 -1
- package/src/test/mock-transcription-model-v2.ts +1 -1
- package/src/test/mock-transcription-model-v3.ts +1 -1
- package/src/test/mock-transcription-model-v4.ts +1 -1
- package/src/test/mock-video-model-v3.ts +1 -1
- package/src/test/mock-video-model-v4.ts +1 -1
- package/src/text-stream/pipe-text-stream-to-response.ts +1 -1
- package/src/transcribe/transcribe-result.ts +3 -3
- package/src/transcribe/transcribe.ts +12 -12
- package/src/types/embedding-model-middleware.ts +1 -1
- package/src/types/embedding-model.ts +1 -1
- package/src/types/image-model-middleware.ts +1 -1
- package/src/types/image-model.ts +1 -1
- package/src/types/json-value.ts +1 -1
- package/src/types/language-model-middleware.ts +1 -1
- package/src/types/language-model.ts +2 -2
- package/src/types/provider-metadata.ts +1 -1
- package/src/types/provider-reference.ts +1 -1
- package/src/types/provider.ts +4 -4
- package/src/types/reranking-model.ts +1 -1
- package/src/types/speech-model.ts +5 -1
- package/src/types/transcription-model.ts +1 -1
- package/src/types/usage.ts +1 -1
- package/src/types/video-model.ts +1 -1
- package/src/types/warning.ts +1 -1
- package/src/ui/call-completion-api.ts +2 -2
- package/src/ui/chat-transport.ts +3 -3
- package/src/ui/chat.ts +10 -11
- package/src/ui/convert-file-list-to-file-ui-parts.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +34 -23
- package/src/ui/default-chat-transport.ts +4 -4
- package/src/ui/direct-chat-transport.ts +6 -6
- package/src/ui/http-chat-transport.ts +5 -5
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +0 -1
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +0 -1
- package/src/ui/process-ui-message-stream.ts +20 -21
- package/src/ui/text-stream-chat-transport.ts +3 -3
- package/src/ui/transform-text-to-ui-message-stream.ts +1 -1
- package/src/ui/ui-messages.ts +13 -6
- package/src/ui/use-completion.ts +1 -1
- package/src/ui/validate-ui-messages.ts +3 -3
- package/src/ui-message-stream/create-ui-message-stream-response.ts +2 -2
- package/src/ui-message-stream/create-ui-message-stream.ts +6 -6
- package/src/ui-message-stream/get-response-ui-message-id.ts +2 -2
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +6 -6
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -3
- package/src/ui-message-stream/read-ui-message-stream.ts +4 -4
- package/src/ui-message-stream/ui-message-chunks.ts +4 -4
- package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +2 -2
- package/src/ui-message-stream/ui-message-stream-on-step-finish-callback.ts +1 -1
- package/src/ui-message-stream/ui-message-stream-writer.ts +3 -3
- package/src/upload-file/upload-file-result.ts +3 -3
- package/src/upload-file/upload-file.ts +34 -56
- package/src/upload-skill/upload-skill-result.ts +3 -3
- package/src/upload-skill/upload-skill.ts +27 -8
- package/src/util/create-resolvable-promise.ts +1 -1
- package/src/util/deep-partial.ts +1 -1
- package/src/util/download/download.ts +0 -2
- package/src/util/extract-literal-union.ts +18 -0
- package/src/util/is-node-runtime.ts +3 -0
- package/src/util/notify.ts +1 -1
- package/src/util/parse-partial-json.ts +1 -1
- package/src/util/prepare-retries.ts +1 -2
- package/src/util/serial-job-executor.ts +1 -1
- package/src/util/write-to-server-response.ts +1 -1
- package/src/util/detect-media-type.ts +0 -235
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JSONObject } from '@ai-sdk/provider';
|
|
2
|
-
import { TranscriptionModelResponseMetadata } from '../types/transcription-model-response-metadata';
|
|
3
|
-
import { Warning } from '../types/warning';
|
|
1
|
+
import type { JSONObject } from '@ai-sdk/provider';
|
|
2
|
+
import type { TranscriptionModelResponseMetadata } from '../types/transcription-model-response-metadata';
|
|
3
|
+
import type { Warning } from '../types/warning';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The result of a `transcribe` call.
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { JSONObject } from '@ai-sdk/provider';
|
|
2
|
-
import {
|
|
1
|
+
import type { JSONObject } from '@ai-sdk/provider';
|
|
2
|
+
import {
|
|
3
|
+
detectMediaType,
|
|
4
|
+
withUserAgentSuffix,
|
|
5
|
+
type ProviderOptions,
|
|
6
|
+
} from '@ai-sdk/provider-utils';
|
|
3
7
|
import { NoTranscriptGeneratedError } from '../error/no-transcript-generated-error';
|
|
4
8
|
import { logWarnings } from '../logger/log-warnings';
|
|
5
|
-
import { DataContent } from '../prompt';
|
|
9
|
+
import type { DataContent } from '../prompt';
|
|
6
10
|
import { convertDataContentToUint8Array } from '../prompt/data-content';
|
|
7
|
-
import { TranscriptionModel } from '../types/transcription-model';
|
|
8
|
-
import { TranscriptionModelResponseMetadata } from '../types/transcription-model-response-metadata';
|
|
9
|
-
import {
|
|
10
|
-
audioMediaTypeSignatures,
|
|
11
|
-
detectMediaType,
|
|
12
|
-
} from '../util/detect-media-type';
|
|
11
|
+
import type { TranscriptionModel } from '../types/transcription-model';
|
|
12
|
+
import type { TranscriptionModelResponseMetadata } from '../types/transcription-model-response-metadata';
|
|
13
13
|
import { createDownload } from '../util/download/create-download';
|
|
14
14
|
import { prepareRetries } from '../util/prepare-retries';
|
|
15
|
-
import { TranscriptionResult } from './transcribe-result';
|
|
15
|
+
import type { TranscriptionResult } from './transcribe-result';
|
|
16
16
|
import { VERSION } from '../version';
|
|
17
17
|
import { resolveTranscriptionModel } from '../model/resolve-model';
|
|
18
|
-
import { Warning } from '../types';
|
|
18
|
+
import type { Warning } from '../types';
|
|
19
19
|
/**
|
|
20
20
|
* Generates transcripts using a transcription model.
|
|
21
21
|
*
|
|
@@ -124,7 +124,7 @@ export async function transcribe({
|
|
|
124
124
|
mediaType:
|
|
125
125
|
detectMediaType({
|
|
126
126
|
data: audioData,
|
|
127
|
-
|
|
127
|
+
topLevelType: 'audio',
|
|
128
128
|
}) ?? 'audio/wav',
|
|
129
129
|
}),
|
|
130
130
|
);
|
package/src/types/image-model.ts
CHANGED
package/src/types/json-value.ts
CHANGED
package/src/types/provider.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EmbeddingModel } from './embedding-model';
|
|
2
|
-
import { LanguageModel } from './language-model';
|
|
3
|
-
import { ImageModel } from './image-model';
|
|
4
|
-
import { RerankingModel } from './reranking-model';
|
|
1
|
+
import type { EmbeddingModel } from './embedding-model';
|
|
2
|
+
import type { LanguageModel } from './language-model';
|
|
3
|
+
import type { ImageModel } from './image-model';
|
|
4
|
+
import type { RerankingModel } from './reranking-model';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Provider for language, text embedding, and image models.
|
package/src/types/usage.ts
CHANGED
package/src/types/video-model.ts
CHANGED
package/src/types/warning.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseJsonEventStream,
|
|
3
|
-
ParseResult,
|
|
4
3
|
withUserAgentSuffix,
|
|
5
4
|
getRuntimeEnvironmentUserAgent,
|
|
5
|
+
type ParseResult,
|
|
6
6
|
} from '@ai-sdk/provider-utils';
|
|
7
7
|
import {
|
|
8
|
-
UIMessageChunk,
|
|
9
8
|
uiMessageChunkSchema,
|
|
9
|
+
type UIMessageChunk,
|
|
10
10
|
} from '../ui-message-stream/ui-message-chunks';
|
|
11
11
|
import { consumeStream } from '../util/consume-stream';
|
|
12
12
|
import { processTextStream } from './process-text-stream';
|
package/src/ui/chat-transport.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UIMessageChunk } from '../ui-message-stream';
|
|
2
|
-
import { ChatRequestOptions } from './chat';
|
|
3
|
-
import { UIMessage } from './ui-messages';
|
|
1
|
+
import type { UIMessageChunk } from '../ui-message-stream';
|
|
2
|
+
import type { ChatRequestOptions } from './chat';
|
|
3
|
+
import type { UIMessage } from './ui-messages';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Transport interface for handling chat message communication and streaming.
|
package/src/ui/chat.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FlexibleSchema,
|
|
3
2
|
generateId as generateIdFunc,
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type FlexibleSchema,
|
|
4
|
+
type IdGenerator,
|
|
5
|
+
type InferSchema,
|
|
6
6
|
} from '@ai-sdk/provider-utils';
|
|
7
|
-
import { FinishReason } from '../types/language-model';
|
|
8
|
-
import { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
7
|
+
import type { FinishReason } from '../types/language-model';
|
|
8
|
+
import type { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
9
9
|
import { consumeStream } from '../util/consume-stream';
|
|
10
10
|
import { SerialJobExecutor } from '../util/serial-job-executor';
|
|
11
|
-
import { ChatTransport } from './chat-transport';
|
|
11
|
+
import type { ChatTransport } from './chat-transport';
|
|
12
12
|
import { convertFileListToFileUIParts } from './convert-file-list-to-file-ui-parts';
|
|
13
13
|
import { DefaultChatTransport } from './default-chat-transport';
|
|
14
14
|
import {
|
|
15
15
|
createStreamingUIMessageState,
|
|
16
16
|
processUIMessageStream,
|
|
17
|
-
StreamingUIMessageState,
|
|
17
|
+
type StreamingUIMessageState,
|
|
18
18
|
} from './process-ui-message-stream';
|
|
19
19
|
import {
|
|
20
|
-
InferUIMessageToolCall,
|
|
21
20
|
isToolUIPart,
|
|
22
|
-
UIMessagePart,
|
|
23
|
-
UITools,
|
|
24
21
|
type DataUIPart,
|
|
25
22
|
type FileUIPart,
|
|
26
23
|
type InferUIMessageData,
|
|
@@ -28,8 +25,10 @@ import {
|
|
|
28
25
|
type InferUIMessageTools,
|
|
29
26
|
type UIDataTypes,
|
|
30
27
|
type UIMessage,
|
|
28
|
+
type InferUIMessageToolCall,
|
|
29
|
+
type UIMessagePart,
|
|
30
|
+
type UITools,
|
|
31
31
|
} from './ui-messages';
|
|
32
|
-
|
|
33
32
|
export type CreateUIMessage<UI_MESSAGE extends UIMessage> = Omit<
|
|
34
33
|
UI_MESSAGE,
|
|
35
34
|
'id' | 'role'
|
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AssistantContent,
|
|
3
|
-
CustomPart,
|
|
4
|
-
FilePart,
|
|
5
2
|
isNonNullable,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
type ToolSet,
|
|
4
|
+
type AssistantContent,
|
|
5
|
+
type CustomPart,
|
|
6
|
+
type FilePart,
|
|
7
|
+
type ModelMessage,
|
|
8
|
+
type TextPart,
|
|
9
|
+
type ToolApprovalResponse,
|
|
10
|
+
type ToolResultPart,
|
|
10
11
|
} from '@ai-sdk/provider-utils';
|
|
11
|
-
import type { ToolSet } from '@ai-sdk/provider-utils';
|
|
12
12
|
import { createToolModelOutput } from '../prompt/create-tool-model-output';
|
|
13
13
|
import { MessageConversionError } from '../prompt/message-conversion-error';
|
|
14
14
|
import {
|
|
15
|
-
CustomContentUIPart,
|
|
16
|
-
DataUIPart,
|
|
17
|
-
DynamicToolUIPart,
|
|
18
|
-
FileUIPart,
|
|
19
15
|
getToolName,
|
|
20
|
-
InferUIMessageData,
|
|
21
|
-
InferUIMessageTools,
|
|
22
16
|
isCustomContentUIPart,
|
|
23
17
|
isDataUIPart,
|
|
24
18
|
isFileUIPart,
|
|
25
19
|
isReasoningFileUIPart,
|
|
26
20
|
isReasoningUIPart,
|
|
27
|
-
ReasoningFileUIPart,
|
|
28
21
|
isTextUIPart,
|
|
29
22
|
isToolUIPart,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
type CustomContentUIPart,
|
|
24
|
+
type DataUIPart,
|
|
25
|
+
type DynamicToolUIPart,
|
|
26
|
+
type FileUIPart,
|
|
27
|
+
type InferUIMessageData,
|
|
28
|
+
type InferUIMessageTools,
|
|
29
|
+
type ReasoningFileUIPart,
|
|
30
|
+
type ReasoningUIPart,
|
|
31
|
+
type TextUIPart,
|
|
32
|
+
type ToolUIPart,
|
|
33
|
+
type UIMessage,
|
|
34
34
|
} from './ui-messages';
|
|
35
|
-
|
|
36
35
|
/**
|
|
37
36
|
* Converts an array of UI messages from useChat into an array of ModelMessages that can be used
|
|
38
37
|
* with the AI functions (e.g. `streamText`, `generateText`).
|
|
@@ -114,7 +113,13 @@ export async function convertToModelMessages<UI_MESSAGE extends UIMessage>(
|
|
|
114
113
|
type: 'file' as const,
|
|
115
114
|
mediaType: part.mediaType,
|
|
116
115
|
filename: part.filename,
|
|
117
|
-
data:
|
|
116
|
+
data:
|
|
117
|
+
part.providerReference != null
|
|
118
|
+
? {
|
|
119
|
+
type: 'reference' as const,
|
|
120
|
+
reference: part.providerReference,
|
|
121
|
+
}
|
|
122
|
+
: { type: 'url' as const, url: new URL(part.url) },
|
|
118
123
|
...(part.providerMetadata != null
|
|
119
124
|
? { providerOptions: part.providerMetadata }
|
|
120
125
|
: {}),
|
|
@@ -176,7 +181,13 @@ export async function convertToModelMessages<UI_MESSAGE extends UIMessage>(
|
|
|
176
181
|
type: 'file' as const,
|
|
177
182
|
mediaType: part.mediaType,
|
|
178
183
|
filename: part.filename,
|
|
179
|
-
data:
|
|
184
|
+
data:
|
|
185
|
+
part.providerReference != null
|
|
186
|
+
? {
|
|
187
|
+
type: 'reference' as const,
|
|
188
|
+
reference: part.providerReference,
|
|
189
|
+
}
|
|
190
|
+
: { type: 'url' as const, url: new URL(part.url) },
|
|
180
191
|
...(part.providerMetadata != null
|
|
181
192
|
? { providerOptions: part.providerMetadata }
|
|
182
193
|
: {}),
|
|
@@ -184,7 +195,7 @@ export async function convertToModelMessages<UI_MESSAGE extends UIMessage>(
|
|
|
184
195
|
} else if (isReasoningFileUIPart(part)) {
|
|
185
196
|
content.push({
|
|
186
197
|
type: 'reasoning-file' as const,
|
|
187
|
-
data: part.url,
|
|
198
|
+
data: { type: 'url' as const, url: new URL(part.url) },
|
|
188
199
|
mediaType: part.mediaType,
|
|
189
200
|
providerOptions: part.providerMetadata,
|
|
190
201
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { parseJsonEventStream, ParseResult } from '@ai-sdk/provider-utils';
|
|
1
|
+
import { parseJsonEventStream, type ParseResult } from '@ai-sdk/provider-utils';
|
|
2
2
|
import {
|
|
3
|
-
UIMessageChunk,
|
|
4
3
|
uiMessageChunkSchema,
|
|
4
|
+
type UIMessageChunk,
|
|
5
5
|
} from '../ui-message-stream/ui-message-chunks';
|
|
6
6
|
import {
|
|
7
7
|
HttpChatTransport,
|
|
8
|
-
HttpChatTransportInitOptions,
|
|
8
|
+
type HttpChatTransportInitOptions,
|
|
9
9
|
} from './http-chat-transport';
|
|
10
|
-
import { UIMessage } from './ui-messages';
|
|
10
|
+
import type { UIMessage } from './ui-messages';
|
|
11
11
|
|
|
12
12
|
export class DefaultChatTransport<
|
|
13
13
|
UI_MESSAGE extends UIMessage,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Agent } from '../agent/agent';
|
|
2
|
-
import { Output } from '../generate-text/output';
|
|
3
|
-
import { UIMessageStreamOptions } from '../generate-text/stream-text-result';
|
|
1
|
+
import type { Agent } from '../agent/agent';
|
|
2
|
+
import type { Output } from '../generate-text/output';
|
|
3
|
+
import type { UIMessageStreamOptions } from '../generate-text/stream-text-result';
|
|
4
4
|
import type { Context, ToolSet } from '@ai-sdk/provider-utils';
|
|
5
|
-
import { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
6
|
-
import { ChatTransport } from './chat-transport';
|
|
5
|
+
import type { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
6
|
+
import type { ChatTransport } from './chat-transport';
|
|
7
7
|
import { convertToModelMessages } from './convert-to-model-messages';
|
|
8
|
-
import { InferUITools, UIMessage } from './ui-messages';
|
|
8
|
+
import type { InferUITools, UIMessage } from './ui-messages';
|
|
9
9
|
import { validateUIMessages } from './validate-ui-messages';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FetchFunction,
|
|
3
|
-
Resolvable,
|
|
4
2
|
normalizeHeaders,
|
|
5
3
|
resolve,
|
|
4
|
+
type FetchFunction,
|
|
5
|
+
type Resolvable,
|
|
6
6
|
} from '@ai-sdk/provider-utils';
|
|
7
|
-
import { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
8
|
-
import { ChatTransport } from './chat-transport';
|
|
9
|
-
import { UIMessage } from './ui-messages';
|
|
7
|
+
import type { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
8
|
+
import type { ChatTransport } from './chat-transport';
|
|
9
|
+
import type { UIMessage } from './ui-messages';
|
|
10
10
|
|
|
11
11
|
export type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (
|
|
12
12
|
options: {
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { validateTypes, type FlexibleSchema } from '@ai-sdk/provider-utils';
|
|
2
2
|
import { UIMessageStreamError } from '../error/ui-message-stream-error';
|
|
3
|
-
import { ProviderMetadata } from '../types';
|
|
4
|
-
import { FinishReason } from '../types/language-model';
|
|
3
|
+
import type { ProviderMetadata } from '../types';
|
|
4
|
+
import type { FinishReason } from '../types/language-model';
|
|
5
5
|
import {
|
|
6
|
-
DataUIMessageChunk,
|
|
7
|
-
InferUIMessageChunk,
|
|
8
6
|
isDataUIMessageChunk,
|
|
9
|
-
|
|
7
|
+
type DataUIMessageChunk,
|
|
8
|
+
type InferUIMessageChunk,
|
|
9
|
+
type UIMessageChunk,
|
|
10
10
|
} from '../ui-message-stream/ui-message-chunks';
|
|
11
|
-
import { ErrorHandler } from '../util/error-handler';
|
|
11
|
+
import type { ErrorHandler } from '../util/error-handler';
|
|
12
12
|
import { mergeObjects } from '../util/merge-objects';
|
|
13
13
|
import { parsePartialJson } from '../util/parse-partial-json';
|
|
14
|
-
import { UIDataTypesToSchemas } from './chat';
|
|
14
|
+
import type { UIDataTypesToSchemas } from './chat';
|
|
15
15
|
import {
|
|
16
|
-
CustomContentUIPart,
|
|
17
|
-
DataUIPart,
|
|
18
|
-
DynamicToolUIPart,
|
|
19
16
|
getStaticToolName,
|
|
20
|
-
InferUIMessageData,
|
|
21
|
-
InferUIMessageMetadata,
|
|
22
|
-
InferUIMessageToolCall,
|
|
23
|
-
InferUIMessageTools,
|
|
24
17
|
isStaticToolUIPart,
|
|
25
18
|
isToolUIPart,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
type CustomContentUIPart,
|
|
20
|
+
type DataUIPart,
|
|
21
|
+
type DynamicToolUIPart,
|
|
22
|
+
type InferUIMessageData,
|
|
23
|
+
type InferUIMessageMetadata,
|
|
24
|
+
type InferUIMessageToolCall,
|
|
25
|
+
type InferUIMessageTools,
|
|
26
|
+
type ReasoningUIPart,
|
|
27
|
+
type TextUIPart,
|
|
28
|
+
type ToolUIPart,
|
|
29
|
+
type UIMessage,
|
|
30
|
+
type UIMessagePart,
|
|
31
31
|
} from './ui-messages';
|
|
32
|
-
|
|
33
32
|
export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
|
|
34
33
|
message: UI_MESSAGE;
|
|
35
34
|
activeTextParts: Record<string, TextUIPart>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
1
|
+
import type { UIMessageChunk } from '../ui-message-stream/ui-message-chunks';
|
|
2
2
|
import {
|
|
3
3
|
HttpChatTransport,
|
|
4
|
-
HttpChatTransportInitOptions,
|
|
4
|
+
type HttpChatTransportInitOptions,
|
|
5
5
|
} from './http-chat-transport';
|
|
6
6
|
import { transformTextToUiMessageStream } from './transform-text-to-ui-message-stream';
|
|
7
|
-
import { UIMessage } from './ui-messages';
|
|
7
|
+
import type { UIMessage } from './ui-messages';
|
|
8
8
|
|
|
9
9
|
export class TextStreamChatTransport<
|
|
10
10
|
UI_MESSAGE extends UIMessage,
|
package/src/ui/ui-messages.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
InferToolInput,
|
|
3
3
|
InferToolOutput,
|
|
4
4
|
Tool,
|
|
5
5
|
ToolCall,
|
|
6
6
|
ToolSet,
|
|
7
7
|
} from '@ai-sdk/provider-utils';
|
|
8
|
-
import { ProviderMetadata } from '../types/provider-metadata';
|
|
9
|
-
import { ProviderReference } from '../types/provider-reference';
|
|
10
|
-
import { DeepPartial } from '../util/deep-partial';
|
|
11
|
-
import { ValueOf } from '../util/value-of';
|
|
8
|
+
import type { ProviderMetadata } from '../types/provider-metadata';
|
|
9
|
+
import type { ProviderReference } from '../types/provider-reference';
|
|
10
|
+
import type { DeepPartial } from '../util/deep-partial';
|
|
11
|
+
import type { ValueOf } from '../util/value-of';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The data types that can be used in the UI message for the UI message data parts.
|
|
@@ -180,7 +180,14 @@ export type FileUIPart = {
|
|
|
180
180
|
type: 'file';
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* IANA media type
|
|
183
|
+
* Either a full IANA media type (`type/subtype`, e.g. `image/png`) or just
|
|
184
|
+
* the top-level IANA segment (e.g. `image`, `audio`, `video`, `text`).
|
|
185
|
+
*
|
|
186
|
+
* `*`-subtype wildcards (e.g. `image/*`) are normalized as equivalent to the
|
|
187
|
+
* top-level segment alone (e.g. `image`). Providers can use the helpers in
|
|
188
|
+
* `@ai-sdk/provider-utils` (`isFullMediaType`, `getTopLevelMediaType`,
|
|
189
|
+
* `detectMediaType`) to resolve the field according to their API
|
|
190
|
+
* requirements.
|
|
184
191
|
*
|
|
185
192
|
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
186
193
|
*/
|
package/src/ui/use-completion.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { TypeValidationError } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
|
-
FlexibleSchema,
|
|
4
3
|
lazySchema,
|
|
5
|
-
Tool,
|
|
6
4
|
validateTypes,
|
|
7
5
|
zodSchema,
|
|
6
|
+
type FlexibleSchema,
|
|
7
|
+
type Tool,
|
|
8
8
|
} from '@ai-sdk/provider-utils';
|
|
9
9
|
import { z } from 'zod/v4';
|
|
10
10
|
import { InvalidArgumentError } from '../error';
|
|
11
11
|
import { providerMetadataSchema } from '../types/provider-metadata';
|
|
12
|
-
import {
|
|
12
|
+
import type {
|
|
13
13
|
DataUIPart,
|
|
14
14
|
InferUIMessageData,
|
|
15
15
|
InferUIMessageTools,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { prepareHeaders } from '../util/prepare-headers';
|
|
2
2
|
import { JsonToSseTransformStream } from './json-to-sse-transform-stream';
|
|
3
3
|
import { UI_MESSAGE_STREAM_HEADERS } from './ui-message-stream-headers';
|
|
4
|
-
import { UIMessageChunk } from './ui-message-chunks';
|
|
5
|
-
import { UIMessageStreamResponseInit } from './ui-message-stream-response-init';
|
|
4
|
+
import type { UIMessageChunk } from './ui-message-chunks';
|
|
5
|
+
import type { UIMessageStreamResponseInit } from './ui-message-stream-response-init';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a Response object from a UI message stream.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generateId as generateIdFunc,
|
|
3
3
|
getErrorMessage,
|
|
4
|
-
IdGenerator,
|
|
4
|
+
type IdGenerator,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
|
-
import { UIMessage } from '../ui/ui-messages';
|
|
6
|
+
import type { UIMessage } from '../ui/ui-messages';
|
|
7
7
|
import { handleUIMessageStreamFinish } from './handle-ui-message-stream-finish';
|
|
8
|
-
import { InferUIMessageChunk } from './ui-message-chunks';
|
|
9
|
-
import { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';
|
|
10
|
-
import { UIMessageStreamOnStepFinishCallback } from './ui-message-stream-on-step-finish-callback';
|
|
11
|
-
import { UIMessageStreamWriter } from './ui-message-stream-writer';
|
|
8
|
+
import type { InferUIMessageChunk } from './ui-message-chunks';
|
|
9
|
+
import type { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';
|
|
10
|
+
import type { UIMessageStreamOnStepFinishCallback } from './ui-message-stream-on-step-finish-callback';
|
|
11
|
+
import type { UIMessageStreamWriter } from './ui-message-stream-writer';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a UI message stream that can be used to send messages to the client.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IdGenerator } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { UIMessage } from '../ui/ui-messages';
|
|
1
|
+
import type { IdGenerator } from '@ai-sdk/provider-utils';
|
|
2
|
+
import type { UIMessage } from '../ui/ui-messages';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Determines the message ID to use for a response message.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createStreamingUIMessageState,
|
|
3
3
|
processUIMessageStream,
|
|
4
|
-
StreamingUIMessageState,
|
|
4
|
+
type StreamingUIMessageState,
|
|
5
5
|
} from '../ui/process-ui-message-stream';
|
|
6
|
-
import { UIMessage } from '../ui/ui-messages';
|
|
7
|
-
import { ErrorHandler } from '../util/error-handler';
|
|
8
|
-
import { InferUIMessageChunk, UIMessageChunk } from './ui-message-chunks';
|
|
9
|
-
import { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';
|
|
10
|
-
import { UIMessageStreamOnStepFinishCallback } from './ui-message-stream-on-step-finish-callback';
|
|
6
|
+
import type { UIMessage } from '../ui/ui-messages';
|
|
7
|
+
import type { ErrorHandler } from '../util/error-handler';
|
|
8
|
+
import type { InferUIMessageChunk, UIMessageChunk } from './ui-message-chunks';
|
|
9
|
+
import type { UIMessageStreamOnFinishCallback } from './ui-message-stream-on-finish-callback';
|
|
10
|
+
import type { UIMessageStreamOnStepFinishCallback } from './ui-message-stream-on-step-finish-callback';
|
|
11
11
|
|
|
12
12
|
export function handleUIMessageStreamFinish<UI_MESSAGE extends UIMessage>({
|
|
13
13
|
messageId,
|