ai 5.0.0-alpha.7 → 5.0.0-alpha.9
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 +49 -0
- package/dist/index.d.mts +122 -276
- package/dist/index.d.ts +122 -276
- package/dist/index.js +866 -916
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +836 -883
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +3 -2
- package/dist/internal/index.d.ts +3 -2
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import { ToolResultContent, Schema, ToolCall, ToolResult,
|
1
|
+
import { ToolResultContent, Schema, ToolCall, ToolResult, Validator, StandardSchemaV1, IdGenerator, InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
2
2
|
export { IdGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
|
3
3
|
import { AISDKError, SharedV2ProviderMetadata, SharedV2ProviderOptions, EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2ToolCall, JSONSchema7, LanguageModelV2CallOptions, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
4
4
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
5
|
-
import
|
5
|
+
import * as z3 from 'zod/v3';
|
6
|
+
import * as z4 from 'zod/v4/core';
|
6
7
|
import { z } from 'zod';
|
7
8
|
import { ServerResponse } from 'node:http';
|
8
9
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
@@ -383,7 +384,7 @@ type JSONValue = JSONValue$1;
|
|
383
384
|
/**
|
384
385
|
Language model that is used by the AI SDK Core functions.
|
385
386
|
*/
|
386
|
-
type LanguageModel =
|
387
|
+
type LanguageModel = string | LanguageModelV2;
|
387
388
|
/**
|
388
389
|
Reason why a language model finished generating a response.
|
389
390
|
|
@@ -879,7 +880,7 @@ type MCPTransportConfig = {
|
|
879
880
|
headers?: Record<string, string>;
|
880
881
|
};
|
881
882
|
|
882
|
-
type ToolParameters<T = JSONObject> =
|
883
|
+
type ToolParameters<T = JSONObject> = z4.$ZodType<T> | z3.Schema<T> | Schema<T>;
|
883
884
|
interface ToolExecutionOptions {
|
884
885
|
/**
|
885
886
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
@@ -961,7 +962,7 @@ type ToolSchemas = Record<string, {
|
|
961
962
|
parameters: ToolParameters<JSONObject | unknown>;
|
962
963
|
}> | 'automatic' | undefined;
|
963
964
|
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
964
|
-
parameters: ToolParameters<
|
965
|
+
parameters: ToolParameters<unknown>;
|
965
966
|
}> ? {
|
966
967
|
[K in keyof TOOL_SCHEMAS]: MappedTool<TOOL_SCHEMAS[K], CallToolResult> & Required<Pick<MappedTool<TOOL_SCHEMAS[K], CallToolResult>, 'execute'>>;
|
967
968
|
} : McpToolSet<Record<string, {
|
@@ -1901,6 +1902,8 @@ type Prompt = {
|
|
1901
1902
|
messages?: Array<ModelMessage>;
|
1902
1903
|
};
|
1903
1904
|
|
1905
|
+
declare const GLOBAL_DEFAULT_PROVIDER: unique symbol;
|
1906
|
+
|
1904
1907
|
/**
|
1905
1908
|
* A function that attempts to repair a tool call that failed to parse.
|
1906
1909
|
*
|
@@ -2160,6 +2163,10 @@ type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
|
2160
2163
|
data: DATA_TYPES[NAME];
|
2161
2164
|
};
|
2162
2165
|
}>;
|
2166
|
+
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
2167
|
+
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
2168
|
+
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
2169
|
+
};
|
2163
2170
|
/**
|
2164
2171
|
* A text part of a message.
|
2165
2172
|
*/
|
@@ -2303,15 +2310,6 @@ declare function callCompletionApi({ api, prompt, credentials, headers, body, st
|
|
2303
2310
|
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
2304
2311
|
}): Promise<string | null | undefined>;
|
2305
2312
|
|
2306
|
-
type Job = () => Promise<void>;
|
2307
|
-
|
2308
|
-
declare class SerialJobExecutor {
|
2309
|
-
private queue;
|
2310
|
-
private isProcessing;
|
2311
|
-
private processQueue;
|
2312
|
-
run(job: Job): Promise<void>;
|
2313
|
-
}
|
2314
|
-
|
2315
2313
|
/**
|
2316
2314
|
The result of an `embed` call.
|
2317
2315
|
It contains the embedding, the value, and additional information.
|
@@ -2666,7 +2664,7 @@ It always recurses into arrays.
|
|
2666
2664
|
|
2667
2665
|
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
2668
2666
|
*/
|
2669
|
-
type DeepPartial<T> = T extends
|
2667
|
+
type DeepPartial<T> = T extends z3.ZodTypeAny ? DeepPartialInternal<z3.infer<T>> : T extends z4.$ZodType ? DeepPartialInternal<z4.infer<T>> : DeepPartialInternal<T>;
|
2670
2668
|
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
2671
2669
|
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
2672
2670
|
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
@@ -2676,7 +2674,7 @@ type PartialObject<ObjectType extends object> = {
|
|
2676
2674
|
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
2677
2675
|
};
|
2678
2676
|
|
2679
|
-
interface Output
|
2677
|
+
interface Output<OUTPUT, PARTIAL> {
|
2680
2678
|
readonly type: 'object' | 'text';
|
2681
2679
|
responseFormat: LanguageModelV2CallOptions['responseFormat'];
|
2682
2680
|
parsePartial(options: {
|
@@ -2692,16 +2690,17 @@ interface Output$1<OUTPUT, PARTIAL> {
|
|
2692
2690
|
finishReason: FinishReason;
|
2693
2691
|
}): Promise<OUTPUT>;
|
2694
2692
|
}
|
2695
|
-
declare const text: () => Output
|
2693
|
+
declare const text: () => Output<string, string>;
|
2696
2694
|
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
2697
|
-
schema:
|
2698
|
-
}) => Output
|
2695
|
+
schema: z4.$ZodType<OUTPUT, any> | z3.Schema<OUTPUT, z3.ZodTypeDef, any> | Schema<OUTPUT>;
|
2696
|
+
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
2699
2697
|
|
2698
|
+
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
2700
2699
|
declare const output_object: typeof object;
|
2701
2700
|
declare const output_text: typeof text;
|
2702
2701
|
declare namespace output {
|
2703
2702
|
export {
|
2704
|
-
|
2703
|
+
output_Output as Output,
|
2705
2704
|
output_object as object,
|
2706
2705
|
output_text as text,
|
2707
2706
|
};
|
@@ -2830,7 +2829,7 @@ changing the tool call and result types in the result.
|
|
2830
2829
|
/**
|
2831
2830
|
Optional specification for parsing structured outputs from the LLM response.
|
2832
2831
|
*/
|
2833
|
-
experimental_output?: Output
|
2832
|
+
experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
|
2834
2833
|
/**
|
2835
2834
|
* @deprecated Use `prepareStep` instead.
|
2836
2835
|
*/
|
@@ -3318,7 +3317,7 @@ functionality that can be fully encapsulated in the provider.
|
|
3318
3317
|
/**
|
3319
3318
|
Optional specification for parsing structured outputs from the LLM response.
|
3320
3319
|
*/
|
3321
|
-
experimental_output?: Output
|
3320
|
+
experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
|
3322
3321
|
/**
|
3323
3322
|
Optional function that you can use to provide different settings for a step.
|
3324
3323
|
|
@@ -3607,14 +3606,14 @@ functionality that can be fully encapsulated in the provider.
|
|
3607
3606
|
@returns
|
3608
3607
|
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
3609
3608
|
*/
|
3610
|
-
declare function generateObject<
|
3609
|
+
declare function generateObject<SCHEMA extends z3.Schema | z4.$ZodType | Schema = z4.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
3611
3610
|
/**
|
3612
3611
|
The enum values that the model should use.
|
3613
3612
|
*/
|
3614
3613
|
enum: Array<RESULT>;
|
3615
3614
|
mode?: 'json';
|
3616
3615
|
output: 'enum';
|
3617
|
-
} :
|
3616
|
+
} : OUTPUT extends 'no-schema' ? {} : {
|
3618
3617
|
/**
|
3619
3618
|
The schema of the object that the model should generate.
|
3620
3619
|
*/
|
@@ -3646,7 +3645,7 @@ Default and recommended: 'auto' (best mode for the model).
|
|
3646
3645
|
*/
|
3647
3646
|
mode?: 'auto' | 'json' | 'tool';
|
3648
3647
|
}) & {
|
3649
|
-
output?:
|
3648
|
+
output?: OUTPUT;
|
3650
3649
|
/**
|
3651
3650
|
The language model to use.
|
3652
3651
|
*/
|
@@ -3708,6 +3707,15 @@ declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
|
3708
3707
|
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
3709
3708
|
}>;
|
3710
3709
|
|
3710
|
+
type Job = () => Promise<void>;
|
3711
|
+
|
3712
|
+
declare class SerialJobExecutor {
|
3713
|
+
private queue;
|
3714
|
+
private isProcessing;
|
3715
|
+
private processQueue;
|
3716
|
+
run(job: Job): Promise<void>;
|
3717
|
+
}
|
3718
|
+
|
3711
3719
|
/**
|
3712
3720
|
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
3713
3721
|
*
|
@@ -3915,14 +3923,14 @@ functionality that can be fully encapsulated in the provider.
|
|
3915
3923
|
@returns
|
3916
3924
|
A result object for accessing the partial object stream and additional information.
|
3917
3925
|
*/
|
3918
|
-
declare function streamObject<
|
3926
|
+
declare function streamObject<SCHEMA extends z3.Schema | z4.$ZodType | Schema = z4.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
3919
3927
|
/**
|
3920
3928
|
The enum values that the model should use.
|
3921
3929
|
*/
|
3922
3930
|
enum: Array<RESULT>;
|
3923
3931
|
mode?: 'json';
|
3924
3932
|
output: 'enum';
|
3925
|
-
} :
|
3933
|
+
} : OUTPUT extends 'no-schema' ? {} : {
|
3926
3934
|
/**
|
3927
3935
|
The schema of the object that the model should generate.
|
3928
3936
|
*/
|
@@ -3954,7 +3962,7 @@ Default and recommended: 'auto' (best mode for the model).
|
|
3954
3962
|
*/
|
3955
3963
|
mode?: 'auto' | 'json' | 'tool';
|
3956
3964
|
}) & {
|
3957
|
-
output?:
|
3965
|
+
output?: OUTPUT;
|
3958
3966
|
/**
|
3959
3967
|
The language model to use.
|
3960
3968
|
*/
|
@@ -3987,7 +3995,7 @@ Callback that is called when the LLM response and the final object validation ar
|
|
3987
3995
|
currentDate?: () => Date;
|
3988
3996
|
now?: () => number;
|
3989
3997
|
};
|
3990
|
-
}): StreamObjectResult<
|
3998
|
+
}): StreamObjectResult<OUTPUT extends 'enum' ? string : OUTPUT extends 'array' ? RESULT : DeepPartial<RESULT>, OUTPUT extends 'array' ? RESULT : RESULT, OUTPUT extends 'array' ? RESULT extends Array<infer U> ? AsyncIterableStream<U> : never : never>;
|
3991
3999
|
|
3992
4000
|
/**
|
3993
4001
|
* A generated audio file.
|
@@ -4463,95 +4471,50 @@ type ChatRequestOptions = {
|
|
4463
4471
|
*/
|
4464
4472
|
body?: object;
|
4465
4473
|
};
|
4466
|
-
|
4474
|
+
|
4475
|
+
interface ChatSubscriber {
|
4476
|
+
onChange: (event: ChatEvent) => void;
|
4477
|
+
}
|
4478
|
+
interface ChatEvent {
|
4479
|
+
type: 'messages-changed' | 'status-changed';
|
4480
|
+
}
|
4481
|
+
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
4482
|
+
interface ChatState<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
|
4483
|
+
status: ChatStatus;
|
4484
|
+
error: Error | undefined;
|
4485
|
+
messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
|
4486
|
+
pushMessage: (message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
|
4487
|
+
popMessage: () => void;
|
4488
|
+
replaceMessage: (index: number, message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
|
4489
|
+
snapshot: <T>(thing: T) => T;
|
4490
|
+
}
|
4491
|
+
interface BaseChatInit<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
|
4467
4492
|
/**
|
4468
4493
|
* A unique identifier for the chat. If not provided, a random one will be
|
4469
|
-
* generated.
|
4470
|
-
* have shared states across components.
|
4471
|
-
*/
|
4472
|
-
chatId?: string;
|
4473
|
-
/**
|
4474
|
-
* Initial input of the chat.
|
4494
|
+
* generated.
|
4475
4495
|
*/
|
4476
|
-
|
4477
|
-
|
4478
|
-
Optional callback function that is invoked when a tool call is received.
|
4479
|
-
Intended for automatic client-side tool execution.
|
4480
|
-
|
4481
|
-
You can optionally return a result for the tool call,
|
4482
|
-
either synchronously or asynchronously.
|
4483
|
-
*/
|
4484
|
-
onToolCall?: ({ toolCall, }: {
|
4485
|
-
toolCall: ToolCall<string, unknown>;
|
4486
|
-
}) => void | Promise<unknown> | unknown;
|
4487
|
-
/**
|
4488
|
-
* Optional callback function that is called when the assistant message is finished streaming.
|
4489
|
-
*
|
4490
|
-
* @param message The message that was streamed.
|
4491
|
-
*/
|
4492
|
-
onFinish?: (options: {
|
4493
|
-
message: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_TYPE_SCHEMAS>>;
|
4494
|
-
}) => void;
|
4495
|
-
/**
|
4496
|
-
* Callback function to be called when an error is encountered.
|
4497
|
-
*/
|
4498
|
-
onError?: (error: Error) => void;
|
4496
|
+
id?: string;
|
4497
|
+
messages?: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4499
4498
|
/**
|
4500
4499
|
* A way to provide a function that is going to be used for ids for messages and the chat.
|
4501
4500
|
* If not provided the default AI SDK `generateId` is used.
|
4502
4501
|
*/
|
4503
4502
|
generateId?: IdGenerator;
|
4503
|
+
transport?: ChatTransport<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4504
|
+
maxSteps?: number;
|
4505
|
+
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4506
|
+
dataPartSchemas?: UI_DATA_PART_SCHEMAS;
|
4504
4507
|
/**
|
4505
|
-
*
|
4506
|
-
* It must not change during the component lifecycle.
|
4507
|
-
*
|
4508
|
-
* When a ChatStore is provided, it will be used as is.
|
4509
|
-
* It should be stable and the stability is guaranteed by the user.
|
4510
|
-
*
|
4511
|
-
* When a function is provided, it will be called to create a new chat store.
|
4512
|
-
* The function will be called when the hook is mounted and the chat store will be
|
4513
|
-
* created.
|
4514
|
-
* The function will be called with the same arguments as the hook is called with.
|
4515
|
-
* The function should return a ChatStoreOptions object.
|
4516
|
-
*
|
4517
|
-
* When no value is provided, a default chat store will be created.
|
4508
|
+
* Callback function to be called when an error is encountered.
|
4518
4509
|
*/
|
4519
|
-
chatStore?: ChatStore<MESSAGE_METADATA, DATA_TYPE_SCHEMAS> | (() => ChatStoreOptions<MESSAGE_METADATA, DATA_TYPE_SCHEMAS>);
|
4520
|
-
};
|
4521
|
-
|
4522
|
-
type StreamingUIMessageState<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> = {
|
4523
|
-
message: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4524
|
-
activeTextPart: TextUIPart | undefined;
|
4525
|
-
activeReasoningPart: ReasoningUIPart | undefined;
|
4526
|
-
partialToolCalls: Record<string, {
|
4527
|
-
text: string;
|
4528
|
-
index: number;
|
4529
|
-
toolName: string;
|
4530
|
-
}>;
|
4531
|
-
};
|
4532
|
-
|
4533
|
-
interface ChatStoreSubscriber {
|
4534
|
-
onChatChanged: (event: ChatStoreEvent) => void;
|
4535
|
-
}
|
4536
|
-
interface ChatStoreEvent {
|
4537
|
-
type: 'chat-messages-changed' | 'chat-status-changed';
|
4538
|
-
chatId: number | string;
|
4539
|
-
error?: Error;
|
4540
|
-
}
|
4541
|
-
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
4542
|
-
type ActiveResponse<MESSAGE_METADATA> = {
|
4543
|
-
state: StreamingUIMessageState<MESSAGE_METADATA>;
|
4544
|
-
abortController: AbortController | undefined;
|
4545
|
-
};
|
4546
|
-
type ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = ChatRequestOptions & {
|
4547
4510
|
onError?: (error: Error) => void;
|
4548
4511
|
/**
|
4549
|
-
|
4550
|
-
|
4512
|
+
Optional callback function that is invoked when a tool call is received.
|
4513
|
+
Intended for automatic client-side tool execution.
|
4551
4514
|
|
4552
|
-
|
4553
|
-
|
4554
|
-
|
4515
|
+
You can optionally return a result for the tool call,
|
4516
|
+
either synchronously or asynchronously.
|
4517
|
+
*/
|
4555
4518
|
onToolCall?: ({ toolCall, }: {
|
4556
4519
|
toolCall: ToolCall<string, unknown>;
|
4557
4520
|
}) => void | Promise<unknown> | unknown;
|
@@ -4561,105 +4524,69 @@ type ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = Cha
|
|
4561
4524
|
* @param message The message that was streamed.
|
4562
4525
|
*/
|
4563
4526
|
onFinish?: (options: {
|
4564
|
-
message: UIMessage<MESSAGE_METADATA,
|
4527
|
+
message: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4565
4528
|
}) => void;
|
4566
|
-
};
|
4567
|
-
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
4568
|
-
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
4569
|
-
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
4570
|
-
};
|
4571
|
-
type ChatFactory<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = (options: {
|
4572
|
-
messages?: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
|
4573
|
-
}) => Chat<MESSAGE_METADATA, DATA_TYPES>;
|
4574
|
-
type ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS extends UIDataPartSchemas> = {
|
4575
|
-
chats?: {
|
4576
|
-
[id: string]: {
|
4577
|
-
messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[];
|
4578
|
-
};
|
4579
|
-
};
|
4580
|
-
generateId?: UseChatOptions['generateId'];
|
4581
|
-
transport: ChatTransport<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>;
|
4582
|
-
maxSteps?: number;
|
4583
|
-
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4584
|
-
dataPartSchemas?: DATA_PART_SCHEMAS;
|
4585
|
-
};
|
4586
|
-
type ChatStoreFactory<MESSAGE_METADATA, DATA_PART_SCHEMAS extends UIDataPartSchemas> = (options: ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS>) => ChatStore<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
|
4587
|
-
interface Chat<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
|
4588
|
-
readonly status: ChatStatus;
|
4589
|
-
readonly messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
|
4590
|
-
readonly error: Error | undefined;
|
4591
|
-
readonly activeResponse: ActiveResponse<MESSAGE_METADATA> | undefined;
|
4592
|
-
readonly jobExecutor: SerialJobExecutor;
|
4593
|
-
setStatus: (status: ChatStatus) => void;
|
4594
|
-
setError: (error: Error | undefined) => void;
|
4595
|
-
setActiveResponse: (activeResponse: ActiveResponse<MESSAGE_METADATA> | undefined) => void;
|
4596
|
-
pushMessage: (message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
|
4597
|
-
popMessage: () => void;
|
4598
|
-
replaceMessage: (index: number, message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
|
4599
|
-
setMessages: (messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[]) => void;
|
4600
|
-
snapshot?: <T>(thing: T) => T;
|
4601
4529
|
}
|
4602
|
-
declare class
|
4603
|
-
|
4604
|
-
|
4605
|
-
|
4606
|
-
private
|
4530
|
+
declare abstract class AbstractChat<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
|
4531
|
+
readonly id: string;
|
4532
|
+
readonly generateId: IdGenerator;
|
4533
|
+
protected state: ChatState<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4534
|
+
private readonly subscribers;
|
4607
4535
|
private messageMetadataSchema;
|
4608
4536
|
private dataPartSchemas;
|
4609
|
-
private transport;
|
4537
|
+
private readonly transport;
|
4610
4538
|
private maxSteps;
|
4611
|
-
|
4612
|
-
|
4613
|
-
|
4614
|
-
|
4615
|
-
|
4616
|
-
|
4617
|
-
|
4618
|
-
transport: ChatTransport<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4619
|
-
maxSteps?: number;
|
4620
|
-
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4621
|
-
dataPartSchemas?: UI_DATA_PART_SCHEMAS;
|
4622
|
-
createChat: ChatFactory<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4539
|
+
private onError?;
|
4540
|
+
private onToolCall?;
|
4541
|
+
private onFinish?;
|
4542
|
+
private activeResponse;
|
4543
|
+
private jobExecutor;
|
4544
|
+
constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, }: Omit<BaseChatInit<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>, 'messages'> & {
|
4545
|
+
state: ChatState<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4623
4546
|
});
|
4624
|
-
|
4625
|
-
|
4626
|
-
|
4627
|
-
|
4628
|
-
|
4629
|
-
|
4630
|
-
|
4547
|
+
/**
|
4548
|
+
* Hook status:
|
4549
|
+
*
|
4550
|
+
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
4551
|
+
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
4552
|
+
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
4553
|
+
* - `error`: An error occurred during the API request, preventing successful completion.
|
4554
|
+
*/
|
4555
|
+
get status(): ChatStatus;
|
4556
|
+
protected setStatus({ status, error, }: {
|
4631
4557
|
status: ChatStatus;
|
4632
4558
|
error?: Error;
|
4633
4559
|
}): void;
|
4634
|
-
|
4635
|
-
|
4636
|
-
|
4637
|
-
subscribe(subscriber:
|
4638
|
-
|
4639
|
-
|
4640
|
-
|
4641
|
-
|
4642
|
-
|
4643
|
-
|
4644
|
-
|
4645
|
-
|
4646
|
-
|
4647
|
-
|
4648
|
-
|
4649
|
-
|
4650
|
-
|
4651
|
-
|
4652
|
-
|
4653
|
-
|
4654
|
-
|
4560
|
+
get error(): Error | undefined;
|
4561
|
+
get messages(): UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4562
|
+
get lastMessage(): UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>> | undefined;
|
4563
|
+
subscribe(subscriber: ChatSubscriber): () => void;
|
4564
|
+
set messages(messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[]);
|
4565
|
+
removeAssistantResponse: () => void;
|
4566
|
+
/**
|
4567
|
+
* Append a user message to the chat list. This triggers the API call to fetch
|
4568
|
+
* the assistant's response.
|
4569
|
+
*/
|
4570
|
+
append: (message: CreateUIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>, { headers, body }?: ChatRequestOptions) => Promise<void>;
|
4571
|
+
/**
|
4572
|
+
* Reload the last AI chat response for the given chat history. If the last
|
4573
|
+
* message isn't from the assistant, it will request the API to generate a
|
4574
|
+
* new response.
|
4575
|
+
*/
|
4576
|
+
reload: ({ headers, body, }?: ChatRequestOptions) => Promise<void>;
|
4577
|
+
/**
|
4578
|
+
* Resume an ongoing chat generation stream. This does not resume an aborted generation.
|
4579
|
+
*/
|
4580
|
+
experimental_resume: ({ headers, body, }?: ChatRequestOptions) => Promise<void>;
|
4581
|
+
addToolResult: ({ toolCallId, result, }: {
|
4655
4582
|
toolCallId: string;
|
4656
4583
|
result: unknown;
|
4657
|
-
})
|
4658
|
-
|
4659
|
-
|
4660
|
-
|
4584
|
+
}) => Promise<void>;
|
4585
|
+
/**
|
4586
|
+
* Abort the current request immediately, keep the generated tokens if any.
|
4587
|
+
*/
|
4588
|
+
stop: () => Promise<void>;
|
4661
4589
|
private emit;
|
4662
|
-
private getChatState;
|
4663
4590
|
private triggerRequest;
|
4664
4591
|
}
|
4665
4592
|
|
@@ -4677,87 +4604,6 @@ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages:
|
|
4677
4604
|
*/
|
4678
4605
|
declare const convertToCoreMessages: typeof convertToModelMessages;
|
4679
4606
|
|
4680
|
-
interface DefaultChatStoreOptions<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
|
4681
|
-
/**
|
4682
|
-
* Schema for the message metadata. Validates the message metadata.
|
4683
|
-
* Message metadata can be undefined or must match the schema.
|
4684
|
-
*/
|
4685
|
-
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4686
|
-
/**
|
4687
|
-
* Schema for the data types. Validates the data types.
|
4688
|
-
*/
|
4689
|
-
dataPartSchemas?: UI_DATA_PART_SCHEMAS;
|
4690
|
-
/**
|
4691
|
-
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
4692
|
-
* a stream of tokens of the AI chat response.
|
4693
|
-
*
|
4694
|
-
* Defaults to `/api/chat`
|
4695
|
-
*/
|
4696
|
-
api?: string;
|
4697
|
-
/**
|
4698
|
-
* A way to provide a function that is going to be used for ids for messages and the chat.
|
4699
|
-
* If not provided the default AI SDK `generateId` is used.
|
4700
|
-
*/
|
4701
|
-
generateId?: IdGenerator;
|
4702
|
-
/**
|
4703
|
-
* The credentials mode to be used for the fetch request.
|
4704
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
4705
|
-
* Defaults to 'same-origin'.
|
4706
|
-
*/
|
4707
|
-
credentials?: RequestCredentials;
|
4708
|
-
/**
|
4709
|
-
* HTTP headers to be sent with the API request.
|
4710
|
-
*/
|
4711
|
-
headers?: Record<string, string> | Headers;
|
4712
|
-
/**
|
4713
|
-
* Extra body object to be sent with the API request.
|
4714
|
-
* @example
|
4715
|
-
* Send a `sessionId` to the API along with the messages.
|
4716
|
-
* ```js
|
4717
|
-
* useChat({
|
4718
|
-
* body: {
|
4719
|
-
* sessionId: '123',
|
4720
|
-
* }
|
4721
|
-
* })
|
4722
|
-
* ```
|
4723
|
-
*/
|
4724
|
-
body?: object;
|
4725
|
-
/**
|
4726
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
4727
|
-
or to provide a custom fetch implementation for e.g. testing.
|
4728
|
-
*/
|
4729
|
-
fetch?: FetchFunction;
|
4730
|
-
/**
|
4731
|
-
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
4732
|
-
Must be at least 1.
|
4733
|
-
|
4734
|
-
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
4735
|
-
|
4736
|
-
By default, it's set to 1, which means that only a single LLM call is made.
|
4737
|
-
*/
|
4738
|
-
maxSteps?: number;
|
4739
|
-
/**
|
4740
|
-
* When a function is provided, it will be used
|
4741
|
-
* to prepare the request body for the chat API. This can be useful for
|
4742
|
-
* customizing the request body based on the messages and data in the chat.
|
4743
|
-
*
|
4744
|
-
* @param chatId The id of the chat.
|
4745
|
-
* @param messages The current messages in the chat.
|
4746
|
-
* @param requestBody The request body object passed in the chat request.
|
4747
|
-
*/
|
4748
|
-
prepareRequestBody?: (options: {
|
4749
|
-
chatId: string;
|
4750
|
-
messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4751
|
-
requestBody?: object;
|
4752
|
-
}) => unknown;
|
4753
|
-
chats?: {
|
4754
|
-
[id: string]: {
|
4755
|
-
messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4756
|
-
};
|
4757
|
-
};
|
4758
|
-
}
|
4759
|
-
declare function defaultChatStoreOptions<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas>({ api, fetch, credentials, headers, body, prepareRequestBody, generateId, messageMetadataSchema, maxSteps, dataPartSchemas, chats, }: DefaultChatStoreOptions<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>): () => ChatStoreOptions<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>;
|
4760
|
-
|
4761
4607
|
declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
|
4762
4608
|
private api;
|
4763
4609
|
private credentials?;
|
@@ -4765,8 +4611,8 @@ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTy
|
|
4765
4611
|
private body?;
|
4766
4612
|
private fetch?;
|
4767
4613
|
private prepareRequestBody?;
|
4768
|
-
constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }
|
4769
|
-
api
|
4614
|
+
constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }?: {
|
4615
|
+
api?: string;
|
4770
4616
|
/**
|
4771
4617
|
* The credentials mode to be used for the fetch request.
|
4772
4618
|
* Possible values are: 'omit', 'same-origin', 'include'.
|
@@ -4942,4 +4788,4 @@ type UseCompletionOptions = {
|
|
4942
4788
|
fetch?: FetchFunction;
|
4943
4789
|
};
|
4944
4790
|
|
4945
|
-
export {
|
4791
|
+
export { AbstractChat, AssistantContent, AssistantModelMessage, BaseChatInit, CallSettings, CallWarning, ChatEvent, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GLOBAL_DEFAULT_PROVIDER, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamChatTransport, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseCompletionOptions, UserContent, UserModelMessage, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
|