ai 4.3.2 → 5.0.0-canary.1
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 +21 -19
- package/dist/index.d.mts +33 -135
- package/dist/index.d.ts +33 -135
- package/dist/index.js +14 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -135
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -14
- package/rsc/dist/index.d.ts +7 -7
- package/rsc/dist/rsc-server.d.mts +7 -7
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +18 -18
- package/test/dist/index.d.ts +18 -18
- package/test/dist/index.js +4 -4
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +3 -3
- package/test/dist/index.mjs.map +1 -1
- package/react/dist/index.d.mts +0 -22
- package/react/dist/index.d.ts +0 -22
- package/react/dist/index.js +0 -42
- package/react/dist/index.js.map +0 -1
- package/react/dist/index.mjs +0 -20
- package/react/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { IDGenerator } from '@ai-sdk/provider-utils';
|
2
2
|
export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
|
3
|
-
import { DataStreamString, Message, Schema, DeepPartial, JSONValue as JSONValue$1
|
4
|
-
export {
|
5
|
-
import {
|
6
|
-
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError,
|
3
|
+
import { DataStreamString, Message, Schema, DeepPartial, JSONValue as JSONValue$1 } from '@ai-sdk/ui-utils';
|
4
|
+
export { Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UIMessage, formatDataStreamPart, jsonSchema, parseDataStreamPart, processDataStream, processTextStream, zodSchema } from '@ai-sdk/ui-utils';
|
5
|
+
import { LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2LogProbs, LanguageModelV2CallWarning, LanguageModelV2Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV2ProviderMetadata, LanguageModelV2CallOptions, AISDKError, LanguageModelV2FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
6
|
+
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Prompt, LanguageModelV2StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
7
7
|
import { ServerResponse } from 'node:http';
|
8
8
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
9
9
|
import { z } from 'zod';
|
@@ -12,7 +12,7 @@ import { ServerResponse as ServerResponse$1 } from 'http';
|
|
12
12
|
/**
|
13
13
|
Language model that is used by the AI SDK Core functions.
|
14
14
|
*/
|
15
|
-
type LanguageModel =
|
15
|
+
type LanguageModel = LanguageModelV2;
|
16
16
|
/**
|
17
17
|
Reason why a language model finished generating a response.
|
18
18
|
|
@@ -24,22 +24,22 @@ Can be one of the following:
|
|
24
24
|
- `error`: model stopped because of an error
|
25
25
|
- `other`: model stopped for other reasons
|
26
26
|
*/
|
27
|
-
type FinishReason =
|
27
|
+
type FinishReason = LanguageModelV2FinishReason;
|
28
28
|
/**
|
29
29
|
Log probabilities for each token and its top log probabilities.
|
30
30
|
|
31
31
|
@deprecated Will become a provider extension in the future.
|
32
32
|
*/
|
33
|
-
type LogProbs =
|
33
|
+
type LogProbs = LanguageModelV2LogProbs;
|
34
34
|
/**
|
35
35
|
Warning from the model provider for this call. The call will proceed, but e.g.
|
36
36
|
some settings might not be supported, which can lead to suboptimal results.
|
37
37
|
*/
|
38
|
-
type CallWarning =
|
38
|
+
type CallWarning = LanguageModelV2CallWarning;
|
39
39
|
/**
|
40
40
|
A source that has been used as input to generate the response.
|
41
41
|
*/
|
42
|
-
type Source =
|
42
|
+
type Source = LanguageModelV2Source;
|
43
43
|
/**
|
44
44
|
Tool choice for the generation. It supports the following settings:
|
45
45
|
|
@@ -240,14 +240,14 @@ Additional provider-specific metadata that is returned from the provider.
|
|
240
240
|
This is needed to enable provider-specific functionality that can be
|
241
241
|
fully encapsulated in the provider.
|
242
242
|
*/
|
243
|
-
type ProviderMetadata =
|
243
|
+
type ProviderMetadata = LanguageModelV2ProviderMetadata;
|
244
244
|
/**
|
245
245
|
Additional provider-specific options.
|
246
246
|
|
247
247
|
They are passed through to the provider from the AI SDK and enable
|
248
248
|
provider-specific functionality that can be fully encapsulated in the provider.
|
249
249
|
*/
|
250
|
-
type ProviderOptions =
|
250
|
+
type ProviderOptions = LanguageModelV2ProviderMetadata;
|
251
251
|
|
252
252
|
/**
|
253
253
|
Represents the number of tokens used in a prompt and completion.
|
@@ -2243,7 +2243,7 @@ interface Output<OUTPUT, PARTIAL> {
|
|
2243
2243
|
}): string | undefined;
|
2244
2244
|
responseFormat: (options: {
|
2245
2245
|
model: LanguageModel;
|
2246
|
-
}) =>
|
2246
|
+
}) => LanguageModelV2CallOptions['responseFormat'];
|
2247
2247
|
parsePartial(options: {
|
2248
2248
|
text: string;
|
2249
2249
|
}): {
|
@@ -2352,13 +2352,13 @@ declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages:
|
|
2352
2352
|
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
2353
2353
|
system: string | undefined;
|
2354
2354
|
messages: CoreMessage[];
|
2355
|
-
toolCall:
|
2355
|
+
toolCall: LanguageModelV2FunctionToolCall;
|
2356
2356
|
tools: TOOLS;
|
2357
2357
|
parameterSchema: (options: {
|
2358
2358
|
toolName: string;
|
2359
2359
|
}) => JSONSchema7;
|
2360
2360
|
error: NoSuchToolError | InvalidToolArgumentsError;
|
2361
|
-
}) => Promise<
|
2361
|
+
}) => Promise<LanguageModelV2FunctionToolCall | null>;
|
2362
2362
|
|
2363
2363
|
/**
|
2364
2364
|
Callback that is set using the `onStepFinish` option.
|
@@ -2539,9 +2539,6 @@ type DataStreamOptions = {
|
|
2539
2539
|
*/
|
2540
2540
|
experimental_sendStart?: boolean;
|
2541
2541
|
};
|
2542
|
-
type ConsumeStreamOptions = {
|
2543
|
-
onError?: (error: unknown) => void;
|
2544
|
-
};
|
2545
2542
|
/**
|
2546
2543
|
A result object for accessing different stream types and additional information.
|
2547
2544
|
*/
|
@@ -2662,10 +2659,8 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
2662
2659
|
This is useful to force the stream to finish.
|
2663
2660
|
It effectively removes the backpressure and allows the stream to finish,
|
2664
2661
|
triggering the `onFinish` callback and the promise resolution.
|
2665
|
-
|
2666
|
-
If an error occurs, it is passed to the optional `onError` callback.
|
2667
2662
|
*/
|
2668
|
-
consumeStream(
|
2663
|
+
consumeStream(): Promise<void>;
|
2669
2664
|
/**
|
2670
2665
|
Converts the result to a data stream.
|
2671
2666
|
|
@@ -3792,74 +3787,14 @@ Callback that is called when the LLM response and the final object validation ar
|
|
3792
3787
|
};
|
3793
3788
|
}): StreamObjectResult<JSONValue, JSONValue, never>;
|
3794
3789
|
|
3795
|
-
/**
|
3796
|
-
* Experimental middleware for LanguageModelV1.
|
3797
|
-
* This type defines the structure for middleware that can be used to modify
|
3798
|
-
* the behavior of LanguageModelV1 operations.
|
3799
|
-
*/
|
3800
|
-
type LanguageModelV1Middleware = {
|
3801
|
-
/**
|
3802
|
-
* Middleware specification version. Use `v1` for the current version.
|
3803
|
-
*/
|
3804
|
-
middlewareVersion?: 'v1' | undefined;
|
3805
|
-
/**
|
3806
|
-
* Transforms the parameters before they are passed to the language model.
|
3807
|
-
* @param options - Object containing the type of operation and the parameters.
|
3808
|
-
* @param options.type - The type of operation ('generate' or 'stream').
|
3809
|
-
* @param options.params - The original parameters for the language model call.
|
3810
|
-
* @returns A promise that resolves to the transformed parameters.
|
3811
|
-
*/
|
3812
|
-
transformParams?: (options: {
|
3813
|
-
type: 'generate' | 'stream';
|
3814
|
-
params: LanguageModelV1CallOptions;
|
3815
|
-
}) => PromiseLike<LanguageModelV1CallOptions>;
|
3816
|
-
/**
|
3817
|
-
* Wraps the generate operation of the language model.
|
3818
|
-
* @param options - Object containing the generate function, parameters, and model.
|
3819
|
-
* @param options.doGenerate - The original generate function.
|
3820
|
-
* @param options.doStream - The original stream function.
|
3821
|
-
* @param options.params - The parameters for the generate call. If the
|
3822
|
-
* `transformParams` middleware is used, this will be the transformed parameters.
|
3823
|
-
* @param options.model - The language model instance.
|
3824
|
-
* @returns A promise that resolves to the result of the generate operation.
|
3825
|
-
*/
|
3826
|
-
wrapGenerate?: (options: {
|
3827
|
-
doGenerate: () => ReturnType<LanguageModelV1['doGenerate']>;
|
3828
|
-
doStream: () => ReturnType<LanguageModelV1['doStream']>;
|
3829
|
-
params: LanguageModelV1CallOptions;
|
3830
|
-
model: LanguageModelV1;
|
3831
|
-
}) => Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
3832
|
-
/**
|
3833
|
-
* Wraps the stream operation of the language model.
|
3834
|
-
*
|
3835
|
-
* @param options - Object containing the stream function, parameters, and model.
|
3836
|
-
* @param options.doGenerate - The original generate function.
|
3837
|
-
* @param options.doStream - The original stream function.
|
3838
|
-
* @param options.params - The parameters for the stream call. If the
|
3839
|
-
* `transformParams` middleware is used, this will be the transformed parameters.
|
3840
|
-
* @param options.model - The language model instance.
|
3841
|
-
* @returns A promise that resolves to the result of the stream operation.
|
3842
|
-
*/
|
3843
|
-
wrapStream?: (options: {
|
3844
|
-
doGenerate: () => ReturnType<LanguageModelV1['doGenerate']>;
|
3845
|
-
doStream: () => ReturnType<LanguageModelV1['doStream']>;
|
3846
|
-
params: LanguageModelV1CallOptions;
|
3847
|
-
model: LanguageModelV1;
|
3848
|
-
}) => PromiseLike<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
3849
|
-
};
|
3850
|
-
/**
|
3851
|
-
* @deprecated Use `LanguageModelV1Middleware` instead.
|
3852
|
-
*/
|
3853
|
-
type Experimental_LanguageModelV1Middleware = LanguageModelV1Middleware;
|
3854
|
-
|
3855
3790
|
/**
|
3856
3791
|
* Applies default settings for a language model.
|
3857
3792
|
*/
|
3858
3793
|
declare function defaultSettingsMiddleware({ settings, }: {
|
3859
|
-
settings: Partial<
|
3860
|
-
providerMetadata?:
|
3794
|
+
settings: Partial<LanguageModelV2CallOptions & {
|
3795
|
+
providerMetadata?: LanguageModelV2ProviderMetadata;
|
3861
3796
|
}>;
|
3862
|
-
}):
|
3797
|
+
}): LanguageModelV2Middleware;
|
3863
3798
|
|
3864
3799
|
/**
|
3865
3800
|
* Extract an XML-tagged reasoning section from the generated text and exposes it
|
@@ -3873,40 +3808,40 @@ declare function extractReasoningMiddleware({ tagName, separator, startWithReaso
|
|
3873
3808
|
tagName: string;
|
3874
3809
|
separator?: string;
|
3875
3810
|
startWithReasoning?: boolean;
|
3876
|
-
}):
|
3811
|
+
}): LanguageModelV2Middleware;
|
3877
3812
|
|
3878
3813
|
/**
|
3879
3814
|
* Simulates streaming chunks with the response from a generate call.
|
3880
3815
|
*/
|
3881
|
-
declare function simulateStreamingMiddleware():
|
3816
|
+
declare function simulateStreamingMiddleware(): LanguageModelV2Middleware;
|
3882
3817
|
|
3883
3818
|
/**
|
3884
|
-
* Wraps a
|
3819
|
+
* Wraps a LanguageModelV2 instance with middleware functionality.
|
3885
3820
|
* This function allows you to apply middleware to transform parameters,
|
3886
3821
|
* wrap generate operations, and wrap stream operations of a language model.
|
3887
3822
|
*
|
3888
3823
|
* @param options - Configuration options for wrapping the language model.
|
3889
|
-
* @param options.model - The original
|
3824
|
+
* @param options.model - The original LanguageModelV2 instance to be wrapped.
|
3890
3825
|
* @param options.middleware - The middleware to be applied to the language model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
|
3891
3826
|
* @param options.modelId - Optional custom model ID to override the original model's ID.
|
3892
3827
|
* @param options.providerId - Optional custom provider ID to override the original model's provider.
|
3893
|
-
* @returns A new
|
3828
|
+
* @returns A new LanguageModelV2 instance with middleware applied.
|
3894
3829
|
*/
|
3895
3830
|
declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
3896
|
-
model:
|
3897
|
-
middleware:
|
3831
|
+
model: LanguageModelV2;
|
3832
|
+
middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3898
3833
|
modelId?: string;
|
3899
3834
|
providerId?: string;
|
3900
|
-
}) =>
|
3835
|
+
}) => LanguageModelV2;
|
3901
3836
|
/**
|
3902
3837
|
* @deprecated Use `wrapLanguageModel` instead.
|
3903
3838
|
*/
|
3904
3839
|
declare const experimental_wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
3905
|
-
model:
|
3906
|
-
middleware:
|
3840
|
+
model: LanguageModelV2;
|
3841
|
+
middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3907
3842
|
modelId?: string;
|
3908
3843
|
providerId?: string;
|
3909
|
-
}) =>
|
3844
|
+
}) => LanguageModelV2;
|
3910
3845
|
|
3911
3846
|
/**
|
3912
3847
|
* Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
|
@@ -3924,7 +3859,7 @@ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageM
|
|
3924
3859
|
languageModels?: LANGUAGE_MODELS;
|
3925
3860
|
textEmbeddingModels?: EMBEDDING_MODELS;
|
3926
3861
|
imageModels?: IMAGE_MODELS;
|
3927
|
-
fallbackProvider?:
|
3862
|
+
fallbackProvider?: ProviderV2;
|
3928
3863
|
}): Provider & {
|
3929
3864
|
languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModel;
|
3930
3865
|
textEmbeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModel<string>;
|
@@ -3952,7 +3887,7 @@ declare class NoSuchProviderError extends NoSuchModelError {
|
|
3952
3887
|
}
|
3953
3888
|
|
3954
3889
|
type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
|
3955
|
-
interface ProviderRegistryProvider<PROVIDERS extends Record<string,
|
3890
|
+
interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
|
3956
3891
|
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModel;
|
3957
3892
|
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModel;
|
3958
3893
|
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModel<string>;
|
@@ -3963,7 +3898,7 @@ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV1>
|
|
3963
3898
|
/**
|
3964
3899
|
* Creates a registry for the given providers.
|
3965
3900
|
*/
|
3966
|
-
declare function createProviderRegistry<PROVIDERS extends Record<string,
|
3901
|
+
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
|
3967
3902
|
separator?: SEPARATOR;
|
3968
3903
|
}): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
|
3969
3904
|
/**
|
@@ -4262,43 +4197,6 @@ declare class RetryError extends AISDKError {
|
|
4262
4197
|
static isInstance(error: unknown): error is RetryError;
|
4263
4198
|
}
|
4264
4199
|
|
4265
|
-
/**
|
4266
|
-
You can pass the thread and the latest message into the `AssistantResponse`. This establishes the context for the response.
|
4267
|
-
*/
|
4268
|
-
type AssistantResponseSettings = {
|
4269
|
-
/**
|
4270
|
-
The thread ID that the response is associated with.
|
4271
|
-
*/
|
4272
|
-
threadId: string;
|
4273
|
-
/**
|
4274
|
-
The ID of the latest message that the response is associated with.
|
4275
|
-
*/
|
4276
|
-
messageId: string;
|
4277
|
-
};
|
4278
|
-
/**
|
4279
|
-
The process parameter is a callback in which you can run the assistant on threads, and send messages and data messages to the client.
|
4280
|
-
*/
|
4281
|
-
type AssistantResponseCallback = (options: {
|
4282
|
-
/**
|
4283
|
-
Forwards an assistant message (non-streaming) to the client.
|
4284
|
-
*/
|
4285
|
-
sendMessage: (message: AssistantMessage) => void;
|
4286
|
-
/**
|
4287
|
-
Send a data message to the client. You can use this to provide information for rendering custom UIs while the assistant is processing the thread.
|
4288
|
-
*/
|
4289
|
-
sendDataMessage: (message: DataMessage) => void;
|
4290
|
-
/**
|
4291
|
-
Forwards the assistant response stream to the client. Returns the `Run` object after it completes, or when it requires an action.
|
4292
|
-
*/
|
4293
|
-
forwardStream: (stream: any) => Promise<any | undefined>;
|
4294
|
-
}) => Promise<void>;
|
4295
|
-
/**
|
4296
|
-
The `AssistantResponse` allows you to send a stream of assistant update to `useAssistant`.
|
4297
|
-
It is designed to facilitate streaming assistant responses to the `useAssistant` hook.
|
4298
|
-
It receives an assistant thread and a current message, and can send messages and data messages to the client.
|
4299
|
-
*/
|
4300
|
-
declare function AssistantResponse({ threadId, messageId }: AssistantResponseSettings, process: AssistantResponseCallback): Response;
|
4301
|
-
|
4302
4200
|
/**
|
4303
4201
|
* Configuration options and helper callback methods for stream lifecycle events.
|
4304
4202
|
*/
|
@@ -4395,4 +4293,4 @@ declare namespace llamaindexAdapter {
|
|
4395
4293
|
};
|
4396
4294
|
}
|
4397
4295
|
|
4398
|
-
export { AssistantContent,
|
4296
|
+
export { AssistantContent, CallWarning, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolCallUnion, CoreToolChoice, CoreToolMessage, CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamOptions, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, FilePart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Provider, ProviderMetadata, ProviderRegistryProvider, RepairTextFunction, RetryError, StepResult, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolResultPart, ToolResultUnion, ToolSet, UserContent, appendClientMessage, appendResponseMessages, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, experimental_wrapLanguageModel, extractReasoningMiddleware, generateObject, generateText, pipeDataStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, tool, wrapLanguageModel };
|
package/dist/index.js
CHANGED
@@ -22,7 +22,6 @@ var streams_exports = {};
|
|
22
22
|
__export(streams_exports, {
|
23
23
|
AISDKError: () => import_provider20.AISDKError,
|
24
24
|
APICallError: () => import_provider20.APICallError,
|
25
|
-
AssistantResponse: () => AssistantResponse,
|
26
25
|
DownloadError: () => DownloadError,
|
27
26
|
EmptyResponseBodyError: () => import_provider20.EmptyResponseBodyError,
|
28
27
|
InvalidArgumentError: () => InvalidArgumentError,
|
@@ -75,13 +74,11 @@ __export(streams_exports, {
|
|
75
74
|
experimental_generateImage: () => generateImage,
|
76
75
|
experimental_wrapLanguageModel: () => experimental_wrapLanguageModel,
|
77
76
|
extractReasoningMiddleware: () => extractReasoningMiddleware,
|
78
|
-
formatAssistantStreamPart: () => import_ui_utils11.formatAssistantStreamPart,
|
79
77
|
formatDataStreamPart: () => import_ui_utils11.formatDataStreamPart,
|
80
78
|
generateId: () => import_provider_utils15.generateId,
|
81
79
|
generateObject: () => generateObject,
|
82
80
|
generateText: () => generateText,
|
83
81
|
jsonSchema: () => import_ui_utils11.jsonSchema,
|
84
|
-
parseAssistantStreamPart: () => import_ui_utils11.parseAssistantStreamPart,
|
85
82
|
parseDataStreamPart: () => import_ui_utils11.parseDataStreamPart,
|
86
83
|
pipeDataStreamToResponse: () => pipeDataStreamToResponse,
|
87
84
|
processDataStream: () => import_ui_utils11.processDataStream,
|
@@ -4754,25 +4751,6 @@ function asArray(value) {
|
|
4754
4751
|
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
4755
4752
|
}
|
4756
4753
|
|
4757
|
-
// util/consume-stream.ts
|
4758
|
-
async function consumeStream({
|
4759
|
-
stream,
|
4760
|
-
onError
|
4761
|
-
}) {
|
4762
|
-
const reader = stream.getReader();
|
4763
|
-
try {
|
4764
|
-
while (true) {
|
4765
|
-
const { done } = await reader.read();
|
4766
|
-
if (done)
|
4767
|
-
break;
|
4768
|
-
}
|
4769
|
-
} catch (error) {
|
4770
|
-
onError == null ? void 0 : onError(error);
|
4771
|
-
} finally {
|
4772
|
-
reader.releaseLock();
|
4773
|
-
}
|
4774
|
-
}
|
4775
|
-
|
4776
4754
|
// core/util/merge-streams.ts
|
4777
4755
|
function mergeStreams(stream1, stream2) {
|
4778
4756
|
const reader1 = stream1.getReader();
|
@@ -6014,15 +5992,9 @@ var DefaultStreamTextResult = class {
|
|
6014
5992
|
)
|
6015
5993
|
);
|
6016
5994
|
}
|
6017
|
-
async consumeStream(
|
6018
|
-
|
6019
|
-
|
6020
|
-
await consumeStream({
|
6021
|
-
stream: this.fullStream,
|
6022
|
-
onError: options == null ? void 0 : options.onError
|
6023
|
-
});
|
6024
|
-
} catch (error) {
|
6025
|
-
(_a17 = options == null ? void 0 : options.onError) == null ? void 0 : _a17.call(options, error);
|
5995
|
+
async consumeStream() {
|
5996
|
+
const stream = this.fullStream;
|
5997
|
+
for await (const part of stream) {
|
6026
5998
|
}
|
6027
5999
|
}
|
6028
6000
|
get experimental_partialOutputStream() {
|
@@ -6331,7 +6303,7 @@ function defaultSettingsMiddleware({
|
|
6331
6303
|
settings
|
6332
6304
|
}) {
|
6333
6305
|
return {
|
6334
|
-
middlewareVersion: "
|
6306
|
+
middlewareVersion: "v2",
|
6335
6307
|
transformParams: async ({ params }) => {
|
6336
6308
|
var _a17;
|
6337
6309
|
return {
|
@@ -6376,7 +6348,7 @@ function extractReasoningMiddleware({
|
|
6376
6348
|
const openingTag = `<${tagName}>`;
|
6377
6349
|
const closingTag = `</${tagName}>`;
|
6378
6350
|
return {
|
6379
|
-
middlewareVersion: "
|
6351
|
+
middlewareVersion: "v2",
|
6380
6352
|
wrapGenerate: async ({ doGenerate }) => {
|
6381
6353
|
const { text: rawText, ...rest } = await doGenerate();
|
6382
6354
|
if (rawText == null) {
|
@@ -6462,7 +6434,7 @@ function extractReasoningMiddleware({
|
|
6462
6434
|
// core/middleware/simulate-streaming-middleware.ts
|
6463
6435
|
function simulateStreamingMiddleware() {
|
6464
6436
|
return {
|
6465
|
-
middlewareVersion: "
|
6437
|
+
middlewareVersion: "v2",
|
6466
6438
|
wrapStream: async ({ doGenerate }) => {
|
6467
6439
|
const result = await doGenerate();
|
6468
6440
|
const simulatedStream = new ReadableStream({
|
@@ -6567,7 +6539,7 @@ var doWrap = ({
|
|
6567
6539
|
return transformParams ? await transformParams({ params, type }) : params;
|
6568
6540
|
}
|
6569
6541
|
return {
|
6570
|
-
specificationVersion: "
|
6542
|
+
specificationVersion: "v2",
|
6571
6543
|
provider: providerId != null ? providerId : model.provider,
|
6572
6544
|
modelId: modelId != null ? modelId : model.modelId,
|
6573
6545
|
defaultObjectGenerationMode: model.defaultObjectGenerationMode,
|
@@ -7540,102 +7512,6 @@ function simulateReadableStream({
|
|
7540
7512
|
});
|
7541
7513
|
}
|
7542
7514
|
|
7543
|
-
// streams/assistant-response.ts
|
7544
|
-
var import_ui_utils12 = require("@ai-sdk/ui-utils");
|
7545
|
-
function AssistantResponse({ threadId, messageId }, process2) {
|
7546
|
-
const stream = new ReadableStream({
|
7547
|
-
async start(controller) {
|
7548
|
-
var _a17;
|
7549
|
-
const textEncoder = new TextEncoder();
|
7550
|
-
const sendMessage = (message) => {
|
7551
|
-
controller.enqueue(
|
7552
|
-
textEncoder.encode(
|
7553
|
-
(0, import_ui_utils12.formatAssistantStreamPart)("assistant_message", message)
|
7554
|
-
)
|
7555
|
-
);
|
7556
|
-
};
|
7557
|
-
const sendDataMessage = (message) => {
|
7558
|
-
controller.enqueue(
|
7559
|
-
textEncoder.encode(
|
7560
|
-
(0, import_ui_utils12.formatAssistantStreamPart)("data_message", message)
|
7561
|
-
)
|
7562
|
-
);
|
7563
|
-
};
|
7564
|
-
const sendError = (errorMessage) => {
|
7565
|
-
controller.enqueue(
|
7566
|
-
textEncoder.encode((0, import_ui_utils12.formatAssistantStreamPart)("error", errorMessage))
|
7567
|
-
);
|
7568
|
-
};
|
7569
|
-
const forwardStream = async (stream2) => {
|
7570
|
-
var _a18, _b;
|
7571
|
-
let result = void 0;
|
7572
|
-
for await (const value of stream2) {
|
7573
|
-
switch (value.event) {
|
7574
|
-
case "thread.message.created": {
|
7575
|
-
controller.enqueue(
|
7576
|
-
textEncoder.encode(
|
7577
|
-
(0, import_ui_utils12.formatAssistantStreamPart)("assistant_message", {
|
7578
|
-
id: value.data.id,
|
7579
|
-
role: "assistant",
|
7580
|
-
content: [{ type: "text", text: { value: "" } }]
|
7581
|
-
})
|
7582
|
-
)
|
7583
|
-
);
|
7584
|
-
break;
|
7585
|
-
}
|
7586
|
-
case "thread.message.delta": {
|
7587
|
-
const content = (_a18 = value.data.delta.content) == null ? void 0 : _a18[0];
|
7588
|
-
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
7589
|
-
controller.enqueue(
|
7590
|
-
textEncoder.encode(
|
7591
|
-
(0, import_ui_utils12.formatAssistantStreamPart)("text", content.text.value)
|
7592
|
-
)
|
7593
|
-
);
|
7594
|
-
}
|
7595
|
-
break;
|
7596
|
-
}
|
7597
|
-
case "thread.run.completed":
|
7598
|
-
case "thread.run.requires_action": {
|
7599
|
-
result = value.data;
|
7600
|
-
break;
|
7601
|
-
}
|
7602
|
-
}
|
7603
|
-
}
|
7604
|
-
return result;
|
7605
|
-
};
|
7606
|
-
controller.enqueue(
|
7607
|
-
textEncoder.encode(
|
7608
|
-
(0, import_ui_utils12.formatAssistantStreamPart)("assistant_control_data", {
|
7609
|
-
threadId,
|
7610
|
-
messageId
|
7611
|
-
})
|
7612
|
-
)
|
7613
|
-
);
|
7614
|
-
try {
|
7615
|
-
await process2({
|
7616
|
-
sendMessage,
|
7617
|
-
sendDataMessage,
|
7618
|
-
forwardStream
|
7619
|
-
});
|
7620
|
-
} catch (error) {
|
7621
|
-
sendError((_a17 = error.message) != null ? _a17 : `${error}`);
|
7622
|
-
} finally {
|
7623
|
-
controller.close();
|
7624
|
-
}
|
7625
|
-
},
|
7626
|
-
pull(controller) {
|
7627
|
-
},
|
7628
|
-
cancel() {
|
7629
|
-
}
|
7630
|
-
});
|
7631
|
-
return new Response(stream, {
|
7632
|
-
status: 200,
|
7633
|
-
headers: {
|
7634
|
-
"Content-Type": "text/plain; charset=utf-8"
|
7635
|
-
}
|
7636
|
-
});
|
7637
|
-
}
|
7638
|
-
|
7639
7515
|
// streams/langchain-adapter.ts
|
7640
7516
|
var langchain_adapter_exports = {};
|
7641
7517
|
__export(langchain_adapter_exports, {
|
@@ -7643,7 +7519,7 @@ __export(langchain_adapter_exports, {
|
|
7643
7519
|
toDataStream: () => toDataStream,
|
7644
7520
|
toDataStreamResponse: () => toDataStreamResponse
|
7645
7521
|
});
|
7646
|
-
var
|
7522
|
+
var import_ui_utils12 = require("@ai-sdk/ui-utils");
|
7647
7523
|
|
7648
7524
|
// streams/stream-callbacks.ts
|
7649
7525
|
function createCallbacksTransformer(callbacks = {}) {
|
@@ -7699,7 +7575,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
7699
7575
|
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
|
7700
7576
|
new TransformStream({
|
7701
7577
|
transform: async (chunk, controller) => {
|
7702
|
-
controller.enqueue((0,
|
7578
|
+
controller.enqueue((0, import_ui_utils12.formatDataStreamPart)("text", chunk));
|
7703
7579
|
}
|
7704
7580
|
})
|
7705
7581
|
);
|
@@ -7751,7 +7627,7 @@ __export(llamaindex_adapter_exports, {
|
|
7751
7627
|
toDataStreamResponse: () => toDataStreamResponse2
|
7752
7628
|
});
|
7753
7629
|
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
7754
|
-
var
|
7630
|
+
var import_ui_utils13 = require("@ai-sdk/ui-utils");
|
7755
7631
|
function toDataStreamInternal2(stream, callbacks) {
|
7756
7632
|
const trimStart = trimStartOfStream();
|
7757
7633
|
return (0, import_provider_utils16.convertAsyncIteratorToReadableStream)(stream[Symbol.asyncIterator]()).pipeThrough(
|
@@ -7763,7 +7639,7 @@ function toDataStreamInternal2(stream, callbacks) {
|
|
7763
7639
|
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
|
7764
7640
|
new TransformStream({
|
7765
7641
|
transform: async (chunk, controller) => {
|
7766
|
-
controller.enqueue((0,
|
7642
|
+
controller.enqueue((0, import_ui_utils13.formatDataStreamPart)("text", chunk));
|
7767
7643
|
}
|
7768
7644
|
})
|
7769
7645
|
);
|
@@ -7805,7 +7681,7 @@ function trimStartOfStream() {
|
|
7805
7681
|
}
|
7806
7682
|
|
7807
7683
|
// streams/stream-data.ts
|
7808
|
-
var
|
7684
|
+
var import_ui_utils14 = require("@ai-sdk/ui-utils");
|
7809
7685
|
|
7810
7686
|
// util/constants.ts
|
7811
7687
|
var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
@@ -7857,7 +7733,7 @@ var StreamData = class {
|
|
7857
7733
|
throw new Error("Stream controller is not initialized.");
|
7858
7734
|
}
|
7859
7735
|
this.controller.enqueue(
|
7860
|
-
this.encoder.encode((0,
|
7736
|
+
this.encoder.encode((0, import_ui_utils14.formatDataStreamPart)("data", [value]))
|
7861
7737
|
);
|
7862
7738
|
}
|
7863
7739
|
appendMessageAnnotation(value) {
|
@@ -7868,7 +7744,7 @@ var StreamData = class {
|
|
7868
7744
|
throw new Error("Stream controller is not initialized.");
|
7869
7745
|
}
|
7870
7746
|
this.controller.enqueue(
|
7871
|
-
this.encoder.encode((0,
|
7747
|
+
this.encoder.encode((0, import_ui_utils14.formatDataStreamPart)("message_annotations", [value]))
|
7872
7748
|
);
|
7873
7749
|
}
|
7874
7750
|
};
|
@@ -7876,7 +7752,6 @@ var StreamData = class {
|
|
7876
7752
|
0 && (module.exports = {
|
7877
7753
|
AISDKError,
|
7878
7754
|
APICallError,
|
7879
|
-
AssistantResponse,
|
7880
7755
|
DownloadError,
|
7881
7756
|
EmptyResponseBodyError,
|
7882
7757
|
InvalidArgumentError,
|
@@ -7929,13 +7804,11 @@ var StreamData = class {
|
|
7929
7804
|
experimental_generateImage,
|
7930
7805
|
experimental_wrapLanguageModel,
|
7931
7806
|
extractReasoningMiddleware,
|
7932
|
-
formatAssistantStreamPart,
|
7933
7807
|
formatDataStreamPart,
|
7934
7808
|
generateId,
|
7935
7809
|
generateObject,
|
7936
7810
|
generateText,
|
7937
7811
|
jsonSchema,
|
7938
|
-
parseAssistantStreamPart,
|
7939
7812
|
parseDataStreamPart,
|
7940
7813
|
pipeDataStreamToResponse,
|
7941
7814
|
processDataStream,
|