ai 5.0.0-alpha.8 → 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 +20 -0
- package/dist/index.d.mts +99 -257
- package/dist/index.d.ts +99 -257
- package/dist/index.js +363 -448
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +306 -392
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 5.0.0-alpha.9
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- 9ae327d: chore (ui): replace chat store concept with chat instances
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- 8255639: ### Fix use with Google APIs + zod v4's `.literal()` schema
|
12
|
+
|
13
|
+
Before [zod@3.25.49](https://github.com/colinhacks/zod/releases/tag/v3.25.49), requests to Google's APIs failed due to a missing `type` in the provided schema. The problem has been resolved for the `ai` SDK by bumping our `zod` peer dependencies to `^3.25.49`.
|
14
|
+
|
15
|
+
pull request: https://github.com/vercel/ai/pull/6609
|
16
|
+
|
17
|
+
- Updated dependencies [26b6dd0]
|
18
|
+
- Updated dependencies [811dff3]
|
19
|
+
- @ai-sdk/gateway@1.0.0-alpha.9
|
20
|
+
- @ai-sdk/provider@2.0.0-alpha.9
|
21
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.9
|
22
|
+
|
3
23
|
## 5.0.0-alpha.8
|
4
24
|
|
5
25
|
### Major Changes
|
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
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';
|
@@ -2163,6 +2163,10 @@ type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
|
2163
2163
|
data: DATA_TYPES[NAME];
|
2164
2164
|
};
|
2165
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
|
+
};
|
2166
2170
|
/**
|
2167
2171
|
* A text part of a message.
|
2168
2172
|
*/
|
@@ -2306,15 +2310,6 @@ declare function callCompletionApi({ api, prompt, credentials, headers, body, st
|
|
2306
2310
|
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
2307
2311
|
}): Promise<string | null | undefined>;
|
2308
2312
|
|
2309
|
-
type Job = () => Promise<void>;
|
2310
|
-
|
2311
|
-
declare class SerialJobExecutor {
|
2312
|
-
private queue;
|
2313
|
-
private isProcessing;
|
2314
|
-
private processQueue;
|
2315
|
-
run(job: Job): Promise<void>;
|
2316
|
-
}
|
2317
|
-
|
2318
2313
|
/**
|
2319
2314
|
The result of an `embed` call.
|
2320
2315
|
It contains the embedding, the value, and additional information.
|
@@ -3712,6 +3707,15 @@ declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
|
3712
3707
|
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
3713
3708
|
}>;
|
3714
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
|
+
|
3715
3719
|
/**
|
3716
3720
|
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
3717
3721
|
*
|
@@ -4467,95 +4471,50 @@ type ChatRequestOptions = {
|
|
4467
4471
|
*/
|
4468
4472
|
body?: object;
|
4469
4473
|
};
|
4470
|
-
|
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> {
|
4471
4492
|
/**
|
4472
4493
|
* A unique identifier for the chat. If not provided, a random one will be
|
4473
|
-
* generated.
|
4474
|
-
* have shared states across components.
|
4475
|
-
*/
|
4476
|
-
chatId?: string;
|
4477
|
-
/**
|
4478
|
-
* Initial input of the chat.
|
4479
|
-
*/
|
4480
|
-
initialInput?: string;
|
4481
|
-
/**
|
4482
|
-
Optional callback function that is invoked when a tool call is received.
|
4483
|
-
Intended for automatic client-side tool execution.
|
4484
|
-
|
4485
|
-
You can optionally return a result for the tool call,
|
4486
|
-
either synchronously or asynchronously.
|
4487
|
-
*/
|
4488
|
-
onToolCall?: ({ toolCall, }: {
|
4489
|
-
toolCall: ToolCall<string, unknown>;
|
4490
|
-
}) => void | Promise<unknown> | unknown;
|
4491
|
-
/**
|
4492
|
-
* Optional callback function that is called when the assistant message is finished streaming.
|
4493
|
-
*
|
4494
|
-
* @param message The message that was streamed.
|
4495
|
-
*/
|
4496
|
-
onFinish?: (options: {
|
4497
|
-
message: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_TYPE_SCHEMAS>>;
|
4498
|
-
}) => void;
|
4499
|
-
/**
|
4500
|
-
* Callback function to be called when an error is encountered.
|
4494
|
+
* generated.
|
4501
4495
|
*/
|
4502
|
-
|
4496
|
+
id?: string;
|
4497
|
+
messages?: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4503
4498
|
/**
|
4504
4499
|
* A way to provide a function that is going to be used for ids for messages and the chat.
|
4505
4500
|
* If not provided the default AI SDK `generateId` is used.
|
4506
4501
|
*/
|
4507
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;
|
4508
4507
|
/**
|
4509
|
-
*
|
4510
|
-
* It must not change during the component lifecycle.
|
4511
|
-
*
|
4512
|
-
* When a ChatStore is provided, it will be used as is.
|
4513
|
-
* It should be stable and the stability is guaranteed by the user.
|
4514
|
-
*
|
4515
|
-
* When a function is provided, it will be called to create a new chat store.
|
4516
|
-
* The function will be called when the hook is mounted and the chat store will be
|
4517
|
-
* created.
|
4518
|
-
* The function will be called with the same arguments as the hook is called with.
|
4519
|
-
* The function should return a ChatStoreOptions object.
|
4520
|
-
*
|
4521
|
-
* When no value is provided, a default chat store will be created.
|
4508
|
+
* Callback function to be called when an error is encountered.
|
4522
4509
|
*/
|
4523
|
-
chatStore?: ChatStore<MESSAGE_METADATA, DATA_TYPE_SCHEMAS> | (() => ChatStoreOptions<MESSAGE_METADATA, DATA_TYPE_SCHEMAS>);
|
4524
|
-
};
|
4525
|
-
|
4526
|
-
type StreamingUIMessageState<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> = {
|
4527
|
-
message: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4528
|
-
activeTextPart: TextUIPart | undefined;
|
4529
|
-
activeReasoningPart: ReasoningUIPart | undefined;
|
4530
|
-
partialToolCalls: Record<string, {
|
4531
|
-
text: string;
|
4532
|
-
index: number;
|
4533
|
-
toolName: string;
|
4534
|
-
}>;
|
4535
|
-
};
|
4536
|
-
|
4537
|
-
interface ChatStoreSubscriber {
|
4538
|
-
onChatChanged: (event: ChatStoreEvent) => void;
|
4539
|
-
}
|
4540
|
-
interface ChatStoreEvent {
|
4541
|
-
type: 'chat-messages-changed' | 'chat-status-changed';
|
4542
|
-
chatId: number | string;
|
4543
|
-
error?: Error;
|
4544
|
-
}
|
4545
|
-
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
4546
|
-
type ActiveResponse<MESSAGE_METADATA> = {
|
4547
|
-
state: StreamingUIMessageState<MESSAGE_METADATA>;
|
4548
|
-
abortController: AbortController | undefined;
|
4549
|
-
};
|
4550
|
-
type ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = ChatRequestOptions & {
|
4551
4510
|
onError?: (error: Error) => void;
|
4552
4511
|
/**
|
4553
|
-
|
4554
|
-
|
4512
|
+
Optional callback function that is invoked when a tool call is received.
|
4513
|
+
Intended for automatic client-side tool execution.
|
4555
4514
|
|
4556
|
-
|
4557
|
-
|
4558
|
-
|
4515
|
+
You can optionally return a result for the tool call,
|
4516
|
+
either synchronously or asynchronously.
|
4517
|
+
*/
|
4559
4518
|
onToolCall?: ({ toolCall, }: {
|
4560
4519
|
toolCall: ToolCall<string, unknown>;
|
4561
4520
|
}) => void | Promise<unknown> | unknown;
|
@@ -4565,105 +4524,69 @@ type ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = Cha
|
|
4565
4524
|
* @param message The message that was streamed.
|
4566
4525
|
*/
|
4567
4526
|
onFinish?: (options: {
|
4568
|
-
message: UIMessage<MESSAGE_METADATA,
|
4527
|
+
message: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4569
4528
|
}) => void;
|
4570
|
-
};
|
4571
|
-
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
4572
|
-
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
4573
|
-
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
4574
|
-
};
|
4575
|
-
type ChatFactory<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = (options: {
|
4576
|
-
messages?: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
|
4577
|
-
}) => Chat<MESSAGE_METADATA, DATA_TYPES>;
|
4578
|
-
type ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS extends UIDataPartSchemas> = {
|
4579
|
-
chats?: {
|
4580
|
-
[id: string]: {
|
4581
|
-
messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[];
|
4582
|
-
};
|
4583
|
-
};
|
4584
|
-
generateId?: UseChatOptions['generateId'];
|
4585
|
-
transport: ChatTransport<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>;
|
4586
|
-
maxSteps?: number;
|
4587
|
-
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4588
|
-
dataPartSchemas?: DATA_PART_SCHEMAS;
|
4589
|
-
};
|
4590
|
-
type ChatStoreFactory<MESSAGE_METADATA, DATA_PART_SCHEMAS extends UIDataPartSchemas> = (options: ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS>) => ChatStore<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
|
4591
|
-
interface Chat<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
|
4592
|
-
readonly status: ChatStatus;
|
4593
|
-
readonly messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
|
4594
|
-
readonly error: Error | undefined;
|
4595
|
-
readonly activeResponse: ActiveResponse<MESSAGE_METADATA> | undefined;
|
4596
|
-
readonly jobExecutor: SerialJobExecutor;
|
4597
|
-
setStatus: (status: ChatStatus) => void;
|
4598
|
-
setError: (error: Error | undefined) => void;
|
4599
|
-
setActiveResponse: (activeResponse: ActiveResponse<MESSAGE_METADATA> | undefined) => void;
|
4600
|
-
pushMessage: (message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
|
4601
|
-
popMessage: () => void;
|
4602
|
-
replaceMessage: (index: number, message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
|
4603
|
-
setMessages: (messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[]) => void;
|
4604
|
-
snapshot?: <T>(thing: T) => T;
|
4605
4529
|
}
|
4606
|
-
declare class
|
4607
|
-
|
4608
|
-
|
4609
|
-
|
4610
|
-
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;
|
4611
4535
|
private messageMetadataSchema;
|
4612
4536
|
private dataPartSchemas;
|
4613
|
-
private transport;
|
4537
|
+
private readonly transport;
|
4614
4538
|
private maxSteps;
|
4615
|
-
|
4616
|
-
|
4617
|
-
|
4618
|
-
|
4619
|
-
|
4620
|
-
|
4621
|
-
|
4622
|
-
transport: ChatTransport<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
|
4623
|
-
maxSteps?: number;
|
4624
|
-
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4625
|
-
dataPartSchemas?: UI_DATA_PART_SCHEMAS;
|
4626
|
-
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>>;
|
4627
4546
|
});
|
4628
|
-
|
4629
|
-
|
4630
|
-
|
4631
|
-
|
4632
|
-
|
4633
|
-
|
4634
|
-
|
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, }: {
|
4635
4557
|
status: ChatStatus;
|
4636
4558
|
error?: Error;
|
4637
4559
|
}): void;
|
4638
|
-
|
4639
|
-
|
4640
|
-
|
4641
|
-
subscribe(subscriber:
|
4642
|
-
|
4643
|
-
|
4644
|
-
|
4645
|
-
|
4646
|
-
|
4647
|
-
|
4648
|
-
|
4649
|
-
|
4650
|
-
|
4651
|
-
|
4652
|
-
|
4653
|
-
|
4654
|
-
|
4655
|
-
|
4656
|
-
|
4657
|
-
|
4658
|
-
|
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, }: {
|
4659
4582
|
toolCallId: string;
|
4660
4583
|
result: unknown;
|
4661
|
-
})
|
4662
|
-
|
4663
|
-
|
4664
|
-
|
4584
|
+
}) => Promise<void>;
|
4585
|
+
/**
|
4586
|
+
* Abort the current request immediately, keep the generated tokens if any.
|
4587
|
+
*/
|
4588
|
+
stop: () => Promise<void>;
|
4665
4589
|
private emit;
|
4666
|
-
private getChat;
|
4667
4590
|
private triggerRequest;
|
4668
4591
|
}
|
4669
4592
|
|
@@ -4681,87 +4604,6 @@ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages:
|
|
4681
4604
|
*/
|
4682
4605
|
declare const convertToCoreMessages: typeof convertToModelMessages;
|
4683
4606
|
|
4684
|
-
interface DefaultChatStoreOptions<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
|
4685
|
-
/**
|
4686
|
-
* Schema for the message metadata. Validates the message metadata.
|
4687
|
-
* Message metadata can be undefined or must match the schema.
|
4688
|
-
*/
|
4689
|
-
messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
|
4690
|
-
/**
|
4691
|
-
* Schema for the data types. Validates the data types.
|
4692
|
-
*/
|
4693
|
-
dataPartSchemas?: UI_DATA_PART_SCHEMAS;
|
4694
|
-
/**
|
4695
|
-
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
4696
|
-
* a stream of tokens of the AI chat response.
|
4697
|
-
*
|
4698
|
-
* Defaults to `/api/chat`
|
4699
|
-
*/
|
4700
|
-
api?: string;
|
4701
|
-
/**
|
4702
|
-
* A way to provide a function that is going to be used for ids for messages and the chat.
|
4703
|
-
* If not provided the default AI SDK `generateId` is used.
|
4704
|
-
*/
|
4705
|
-
generateId?: IdGenerator;
|
4706
|
-
/**
|
4707
|
-
* The credentials mode to be used for the fetch request.
|
4708
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
4709
|
-
* Defaults to 'same-origin'.
|
4710
|
-
*/
|
4711
|
-
credentials?: RequestCredentials;
|
4712
|
-
/**
|
4713
|
-
* HTTP headers to be sent with the API request.
|
4714
|
-
*/
|
4715
|
-
headers?: Record<string, string> | Headers;
|
4716
|
-
/**
|
4717
|
-
* Extra body object to be sent with the API request.
|
4718
|
-
* @example
|
4719
|
-
* Send a `sessionId` to the API along with the messages.
|
4720
|
-
* ```js
|
4721
|
-
* useChat({
|
4722
|
-
* body: {
|
4723
|
-
* sessionId: '123',
|
4724
|
-
* }
|
4725
|
-
* })
|
4726
|
-
* ```
|
4727
|
-
*/
|
4728
|
-
body?: object;
|
4729
|
-
/**
|
4730
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
4731
|
-
or to provide a custom fetch implementation for e.g. testing.
|
4732
|
-
*/
|
4733
|
-
fetch?: FetchFunction;
|
4734
|
-
/**
|
4735
|
-
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
4736
|
-
Must be at least 1.
|
4737
|
-
|
4738
|
-
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
4739
|
-
|
4740
|
-
By default, it's set to 1, which means that only a single LLM call is made.
|
4741
|
-
*/
|
4742
|
-
maxSteps?: number;
|
4743
|
-
/**
|
4744
|
-
* When a function is provided, it will be used
|
4745
|
-
* to prepare the request body for the chat API. This can be useful for
|
4746
|
-
* customizing the request body based on the messages and data in the chat.
|
4747
|
-
*
|
4748
|
-
* @param chatId The id of the chat.
|
4749
|
-
* @param messages The current messages in the chat.
|
4750
|
-
* @param requestBody The request body object passed in the chat request.
|
4751
|
-
*/
|
4752
|
-
prepareRequestBody?: (options: {
|
4753
|
-
chatId: string;
|
4754
|
-
messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4755
|
-
requestBody?: object;
|
4756
|
-
}) => unknown;
|
4757
|
-
chats?: {
|
4758
|
-
[id: string]: {
|
4759
|
-
messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
|
4760
|
-
};
|
4761
|
-
};
|
4762
|
-
}
|
4763
|
-
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>;
|
4764
|
-
|
4765
4607
|
declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
|
4766
4608
|
private api;
|
4767
4609
|
private credentials?;
|
@@ -4769,8 +4611,8 @@ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTy
|
|
4769
4611
|
private body?;
|
4770
4612
|
private fetch?;
|
4771
4613
|
private prepareRequestBody?;
|
4772
|
-
constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }
|
4773
|
-
api
|
4614
|
+
constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }?: {
|
4615
|
+
api?: string;
|
4774
4616
|
/**
|
4775
4617
|
* The credentials mode to be used for the fetch request.
|
4776
4618
|
* Possible values are: 'omit', 'same-origin', 'include'.
|
@@ -4946,4 +4788,4 @@ type UseCompletionOptions = {
|
|
4946
4788
|
fetch?: FetchFunction;
|
4947
4789
|
};
|
4948
4790
|
|
4949
|
-
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 };
|