ai 6.0.0-beta.42 → 6.0.0-beta.44
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 +12 -0
- package/dist/index.d.mts +61 -12
- package/dist/index.d.ts +61 -12
- package/dist/index.js +90 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.0-beta.44
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b1bf9d: feat(ai): add pruneMessages helper function
|
|
8
|
+
|
|
9
|
+
## 6.0.0-beta.43
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 27e8c3a: chore(ai): rename Agent to BasicAgent, introduce Agent interface
|
|
14
|
+
|
|
3
15
|
## 6.0.0-beta.42
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1137,6 +1137,26 @@ A function that attempts to repair a tool call that failed to parse.
|
|
|
1137
1137
|
};
|
|
1138
1138
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
1139
1139
|
|
|
1140
|
+
/**
|
|
1141
|
+
* Prunes model messages from a list of model messages.
|
|
1142
|
+
*
|
|
1143
|
+
* @param messages - The list of model messages to prune.
|
|
1144
|
+
* @param reasoning - How to remove reasoning content from assistant messages. Default is `'none'`.
|
|
1145
|
+
* @param toolCalls - How to prune tool call/results/approval content. Default is `[]`.
|
|
1146
|
+
* @param emptyMessages - Whether to keep or remove messages whose content is empty after pruning. Default is `'remove'`.
|
|
1147
|
+
*
|
|
1148
|
+
* @returns The pruned list of model messages.
|
|
1149
|
+
*/
|
|
1150
|
+
declare function pruneMessages({ messages, reasoning, toolCalls, emptyMessages, }: {
|
|
1151
|
+
messages: ModelMessage[];
|
|
1152
|
+
reasoning?: 'all' | 'before-last-message' | 'none';
|
|
1153
|
+
toolCalls?: 'all' | 'before-last-message' | `before-last-${number}-messages` | 'none' | Array<{
|
|
1154
|
+
type: 'all' | 'before-last-message' | `before-last-${number}-messages`;
|
|
1155
|
+
tools?: string[];
|
|
1156
|
+
}>;
|
|
1157
|
+
emptyMessages?: 'keep' | 'remove';
|
|
1158
|
+
}): ModelMessage[];
|
|
1159
|
+
|
|
1140
1160
|
/**
|
|
1141
1161
|
* Detects the first chunk in a buffer.
|
|
1142
1162
|
*
|
|
@@ -2295,12 +2315,41 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
|
2295
2315
|
rawValue: unknown;
|
|
2296
2316
|
};
|
|
2297
2317
|
|
|
2318
|
+
/**
|
|
2319
|
+
* An agent is a reusable component that that has tools and that
|
|
2320
|
+
* can generate or stream content.
|
|
2321
|
+
*/
|
|
2322
|
+
interface Agent<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> {
|
|
2323
|
+
/**
|
|
2324
|
+
* The id of the agent.
|
|
2325
|
+
*/
|
|
2326
|
+
id: string | undefined;
|
|
2327
|
+
/**
|
|
2328
|
+
* The tools that the agent can use.
|
|
2329
|
+
*/
|
|
2330
|
+
tools: TOOLS;
|
|
2331
|
+
/**
|
|
2332
|
+
* Generates an output from the agent (non-streaming).
|
|
2333
|
+
*/
|
|
2334
|
+
generate(options: Prompt): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
2335
|
+
/**
|
|
2336
|
+
* Streams an output from the agent (streaming).
|
|
2337
|
+
*/
|
|
2338
|
+
stream(options: Prompt): StreamTextResult<TOOLS, OUTPUT_PARTIAL>;
|
|
2339
|
+
/**
|
|
2340
|
+
* Creates a response object that streams UI messages to the client.
|
|
2341
|
+
*/
|
|
2342
|
+
respond(options: {
|
|
2343
|
+
messages: UIMessage<never, never, InferUITools<TOOLS>>[];
|
|
2344
|
+
}): Response;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2298
2347
|
/**
|
|
2299
2348
|
Callback that is set using the `onFinish` option.
|
|
2300
2349
|
|
|
2301
2350
|
@param event - The event that is passed to the callback.
|
|
2302
2351
|
*/
|
|
2303
|
-
type
|
|
2352
|
+
type BasicAgentOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
|
2304
2353
|
/**
|
|
2305
2354
|
Details for all steps.
|
|
2306
2355
|
*/
|
|
@@ -2316,16 +2365,16 @@ Callback that is set using the `onStepFinish` option.
|
|
|
2316
2365
|
|
|
2317
2366
|
@param stepResult - The result of the step.
|
|
2318
2367
|
*/
|
|
2319
|
-
type
|
|
2368
|
+
type BasicAgentOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
|
2320
2369
|
|
|
2321
2370
|
/**
|
|
2322
2371
|
* Configuration options for an agent.
|
|
2323
2372
|
*/
|
|
2324
|
-
type
|
|
2373
|
+
type BasicAgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> = CallSettings & {
|
|
2325
2374
|
/**
|
|
2326
|
-
* The
|
|
2375
|
+
* The id of the agent.
|
|
2327
2376
|
*/
|
|
2328
|
-
|
|
2377
|
+
id?: string;
|
|
2329
2378
|
/**
|
|
2330
2379
|
* The system prompt to use.
|
|
2331
2380
|
*/
|
|
@@ -2377,11 +2426,11 @@ type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never
|
|
|
2377
2426
|
/**
|
|
2378
2427
|
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
2379
2428
|
*/
|
|
2380
|
-
onStepFinish?:
|
|
2429
|
+
onStepFinish?: BasicAgentOnStepFinishCallback<NoInfer<TOOLS>>;
|
|
2381
2430
|
/**
|
|
2382
2431
|
* Callback that is called when all steps are finished and the response is complete.
|
|
2383
2432
|
*/
|
|
2384
|
-
onFinish?:
|
|
2433
|
+
onFinish?: BasicAgentOnFinishCallback<NoInfer<TOOLS>>;
|
|
2385
2434
|
/**
|
|
2386
2435
|
Additional provider-specific options. They are passed through
|
|
2387
2436
|
to the provider from the AI SDK and enable provider-specific
|
|
@@ -2407,13 +2456,13 @@ type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never
|
|
|
2407
2456
|
*
|
|
2408
2457
|
* Define agents once and use them across your application.
|
|
2409
2458
|
*/
|
|
2410
|
-
declare class
|
|
2459
|
+
declare class BasicAgent<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> implements Agent<TOOLS, OUTPUT, OUTPUT_PARTIAL> {
|
|
2411
2460
|
private readonly settings;
|
|
2412
|
-
constructor(settings:
|
|
2461
|
+
constructor(settings: BasicAgentSettings<TOOLS, OUTPUT, OUTPUT_PARTIAL>);
|
|
2413
2462
|
/**
|
|
2414
|
-
* The
|
|
2463
|
+
* The id of the agent.
|
|
2415
2464
|
*/
|
|
2416
|
-
get
|
|
2465
|
+
get id(): string | undefined;
|
|
2417
2466
|
/**
|
|
2418
2467
|
* The tools that the agent can use.
|
|
2419
2468
|
*/
|
|
@@ -4795,4 +4844,4 @@ declare global {
|
|
|
4795
4844
|
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
4796
4845
|
}
|
|
4797
4846
|
|
|
4798
|
-
export { AbstractChat, Agent,
|
|
4847
|
+
export { AbstractChat, Agent, AsyncIterableStream, BasicAgent, BasicAgentOnFinishCallback, BasicAgentOnStepFinishCallback, BasicAgentSettings, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, BasicAgent as Experimental_Agent, BasicAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, Warning as Experimental_Warning, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferAgentUIMessage, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoOutputSpecifiedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolApprovalRequestOutput, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, MCPClient as experimental_MCPClient, MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDeepEqualData, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapLanguageModel, wrapProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1137,6 +1137,26 @@ A function that attempts to repair a tool call that failed to parse.
|
|
|
1137
1137
|
};
|
|
1138
1138
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
1139
1139
|
|
|
1140
|
+
/**
|
|
1141
|
+
* Prunes model messages from a list of model messages.
|
|
1142
|
+
*
|
|
1143
|
+
* @param messages - The list of model messages to prune.
|
|
1144
|
+
* @param reasoning - How to remove reasoning content from assistant messages. Default is `'none'`.
|
|
1145
|
+
* @param toolCalls - How to prune tool call/results/approval content. Default is `[]`.
|
|
1146
|
+
* @param emptyMessages - Whether to keep or remove messages whose content is empty after pruning. Default is `'remove'`.
|
|
1147
|
+
*
|
|
1148
|
+
* @returns The pruned list of model messages.
|
|
1149
|
+
*/
|
|
1150
|
+
declare function pruneMessages({ messages, reasoning, toolCalls, emptyMessages, }: {
|
|
1151
|
+
messages: ModelMessage[];
|
|
1152
|
+
reasoning?: 'all' | 'before-last-message' | 'none';
|
|
1153
|
+
toolCalls?: 'all' | 'before-last-message' | `before-last-${number}-messages` | 'none' | Array<{
|
|
1154
|
+
type: 'all' | 'before-last-message' | `before-last-${number}-messages`;
|
|
1155
|
+
tools?: string[];
|
|
1156
|
+
}>;
|
|
1157
|
+
emptyMessages?: 'keep' | 'remove';
|
|
1158
|
+
}): ModelMessage[];
|
|
1159
|
+
|
|
1140
1160
|
/**
|
|
1141
1161
|
* Detects the first chunk in a buffer.
|
|
1142
1162
|
*
|
|
@@ -2295,12 +2315,41 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
|
2295
2315
|
rawValue: unknown;
|
|
2296
2316
|
};
|
|
2297
2317
|
|
|
2318
|
+
/**
|
|
2319
|
+
* An agent is a reusable component that that has tools and that
|
|
2320
|
+
* can generate or stream content.
|
|
2321
|
+
*/
|
|
2322
|
+
interface Agent<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> {
|
|
2323
|
+
/**
|
|
2324
|
+
* The id of the agent.
|
|
2325
|
+
*/
|
|
2326
|
+
id: string | undefined;
|
|
2327
|
+
/**
|
|
2328
|
+
* The tools that the agent can use.
|
|
2329
|
+
*/
|
|
2330
|
+
tools: TOOLS;
|
|
2331
|
+
/**
|
|
2332
|
+
* Generates an output from the agent (non-streaming).
|
|
2333
|
+
*/
|
|
2334
|
+
generate(options: Prompt): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
2335
|
+
/**
|
|
2336
|
+
* Streams an output from the agent (streaming).
|
|
2337
|
+
*/
|
|
2338
|
+
stream(options: Prompt): StreamTextResult<TOOLS, OUTPUT_PARTIAL>;
|
|
2339
|
+
/**
|
|
2340
|
+
* Creates a response object that streams UI messages to the client.
|
|
2341
|
+
*/
|
|
2342
|
+
respond(options: {
|
|
2343
|
+
messages: UIMessage<never, never, InferUITools<TOOLS>>[];
|
|
2344
|
+
}): Response;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2298
2347
|
/**
|
|
2299
2348
|
Callback that is set using the `onFinish` option.
|
|
2300
2349
|
|
|
2301
2350
|
@param event - The event that is passed to the callback.
|
|
2302
2351
|
*/
|
|
2303
|
-
type
|
|
2352
|
+
type BasicAgentOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
|
2304
2353
|
/**
|
|
2305
2354
|
Details for all steps.
|
|
2306
2355
|
*/
|
|
@@ -2316,16 +2365,16 @@ Callback that is set using the `onStepFinish` option.
|
|
|
2316
2365
|
|
|
2317
2366
|
@param stepResult - The result of the step.
|
|
2318
2367
|
*/
|
|
2319
|
-
type
|
|
2368
|
+
type BasicAgentOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
|
2320
2369
|
|
|
2321
2370
|
/**
|
|
2322
2371
|
* Configuration options for an agent.
|
|
2323
2372
|
*/
|
|
2324
|
-
type
|
|
2373
|
+
type BasicAgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> = CallSettings & {
|
|
2325
2374
|
/**
|
|
2326
|
-
* The
|
|
2375
|
+
* The id of the agent.
|
|
2327
2376
|
*/
|
|
2328
|
-
|
|
2377
|
+
id?: string;
|
|
2329
2378
|
/**
|
|
2330
2379
|
* The system prompt to use.
|
|
2331
2380
|
*/
|
|
@@ -2377,11 +2426,11 @@ type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never
|
|
|
2377
2426
|
/**
|
|
2378
2427
|
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
2379
2428
|
*/
|
|
2380
|
-
onStepFinish?:
|
|
2429
|
+
onStepFinish?: BasicAgentOnStepFinishCallback<NoInfer<TOOLS>>;
|
|
2381
2430
|
/**
|
|
2382
2431
|
* Callback that is called when all steps are finished and the response is complete.
|
|
2383
2432
|
*/
|
|
2384
|
-
onFinish?:
|
|
2433
|
+
onFinish?: BasicAgentOnFinishCallback<NoInfer<TOOLS>>;
|
|
2385
2434
|
/**
|
|
2386
2435
|
Additional provider-specific options. They are passed through
|
|
2387
2436
|
to the provider from the AI SDK and enable provider-specific
|
|
@@ -2407,13 +2456,13 @@ type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never
|
|
|
2407
2456
|
*
|
|
2408
2457
|
* Define agents once and use them across your application.
|
|
2409
2458
|
*/
|
|
2410
|
-
declare class
|
|
2459
|
+
declare class BasicAgent<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never> implements Agent<TOOLS, OUTPUT, OUTPUT_PARTIAL> {
|
|
2411
2460
|
private readonly settings;
|
|
2412
|
-
constructor(settings:
|
|
2461
|
+
constructor(settings: BasicAgentSettings<TOOLS, OUTPUT, OUTPUT_PARTIAL>);
|
|
2413
2462
|
/**
|
|
2414
|
-
* The
|
|
2463
|
+
* The id of the agent.
|
|
2415
2464
|
*/
|
|
2416
|
-
get
|
|
2465
|
+
get id(): string | undefined;
|
|
2417
2466
|
/**
|
|
2418
2467
|
* The tools that the agent can use.
|
|
2419
2468
|
*/
|
|
@@ -4795,4 +4844,4 @@ declare global {
|
|
|
4795
4844
|
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
4796
4845
|
}
|
|
4797
4846
|
|
|
4798
|
-
export { AbstractChat, Agent,
|
|
4847
|
+
export { AbstractChat, Agent, AsyncIterableStream, BasicAgent, BasicAgentOnFinishCallback, BasicAgentOnStepFinishCallback, BasicAgentSettings, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, BasicAgent as Experimental_Agent, BasicAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, Warning as Experimental_Warning, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferAgentUIMessage, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoOutputSpecifiedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolApprovalRequestOutput, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, MCPClient as experimental_MCPClient, MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDeepEqualData, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapLanguageModel, wrapProvider };
|
package/dist/index.js
CHANGED
|
@@ -23,11 +23,11 @@ __export(src_exports, {
|
|
|
23
23
|
AISDKError: () => import_provider18.AISDKError,
|
|
24
24
|
APICallError: () => import_provider18.APICallError,
|
|
25
25
|
AbstractChat: () => AbstractChat,
|
|
26
|
-
|
|
26
|
+
BasicAgent: () => BasicAgent,
|
|
27
27
|
DefaultChatTransport: () => DefaultChatTransport,
|
|
28
28
|
DownloadError: () => DownloadError,
|
|
29
29
|
EmptyResponseBodyError: () => import_provider18.EmptyResponseBodyError,
|
|
30
|
-
Experimental_Agent: () =>
|
|
30
|
+
Experimental_Agent: () => BasicAgent,
|
|
31
31
|
HttpChatTransport: () => HttpChatTransport,
|
|
32
32
|
InvalidArgumentError: () => InvalidArgumentError,
|
|
33
33
|
InvalidDataContentError: () => InvalidDataContentError,
|
|
@@ -110,6 +110,7 @@ __export(src_exports, {
|
|
|
110
110
|
parsePartialJson: () => parsePartialJson,
|
|
111
111
|
pipeTextStreamToResponse: () => pipeTextStreamToResponse,
|
|
112
112
|
pipeUIMessageStreamToResponse: () => pipeUIMessageStreamToResponse,
|
|
113
|
+
pruneMessages: () => pruneMessages,
|
|
113
114
|
readUIMessageStream: () => readUIMessageStream,
|
|
114
115
|
safeValidateUIMessages: () => safeValidateUIMessages,
|
|
115
116
|
simulateReadableStream: () => simulateReadableStream,
|
|
@@ -813,7 +814,7 @@ function detectMediaType({
|
|
|
813
814
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
814
815
|
|
|
815
816
|
// src/version.ts
|
|
816
|
-
var VERSION = true ? "6.0.0-beta.
|
|
817
|
+
var VERSION = true ? "6.0.0-beta.44" : "0.0.0-test";
|
|
817
818
|
|
|
818
819
|
// src/util/download/download.ts
|
|
819
820
|
var download = async ({ url }) => {
|
|
@@ -6376,16 +6377,16 @@ function convertToModelMessages(messages, options) {
|
|
|
6376
6377
|
}
|
|
6377
6378
|
var convertToCoreMessages = convertToModelMessages;
|
|
6378
6379
|
|
|
6379
|
-
// src/agent/agent.ts
|
|
6380
|
-
var
|
|
6380
|
+
// src/agent/basic-agent.ts
|
|
6381
|
+
var BasicAgent = class {
|
|
6381
6382
|
constructor(settings) {
|
|
6382
6383
|
this.settings = settings;
|
|
6383
6384
|
}
|
|
6384
6385
|
/**
|
|
6385
|
-
* The
|
|
6386
|
+
* The id of the agent.
|
|
6386
6387
|
*/
|
|
6387
|
-
get
|
|
6388
|
-
return this.settings.
|
|
6388
|
+
get id() {
|
|
6389
|
+
return this.settings.id;
|
|
6389
6390
|
}
|
|
6390
6391
|
/**
|
|
6391
6392
|
* The tools that the agent can use.
|
|
@@ -8452,6 +8453,85 @@ var object = ({
|
|
|
8452
8453
|
};
|
|
8453
8454
|
};
|
|
8454
8455
|
|
|
8456
|
+
// src/generate-text/prune-messages.ts
|
|
8457
|
+
function pruneMessages({
|
|
8458
|
+
messages,
|
|
8459
|
+
reasoning = "none",
|
|
8460
|
+
toolCalls = [],
|
|
8461
|
+
emptyMessages = "remove"
|
|
8462
|
+
}) {
|
|
8463
|
+
if (reasoning === "all" || reasoning === "before-last-message") {
|
|
8464
|
+
messages = messages.map((message, messageIndex) => {
|
|
8465
|
+
if (message.role !== "assistant" || typeof message.content === "string" || reasoning === "before-last-message" && messageIndex === messages.length - 1) {
|
|
8466
|
+
return message;
|
|
8467
|
+
}
|
|
8468
|
+
return {
|
|
8469
|
+
...message,
|
|
8470
|
+
content: message.content.filter((part) => part.type !== "reasoning")
|
|
8471
|
+
};
|
|
8472
|
+
});
|
|
8473
|
+
}
|
|
8474
|
+
if (toolCalls === "none") {
|
|
8475
|
+
toolCalls = [];
|
|
8476
|
+
} else if (toolCalls === "all") {
|
|
8477
|
+
toolCalls = [{ type: "all" }];
|
|
8478
|
+
} else if (toolCalls === "before-last-message") {
|
|
8479
|
+
toolCalls = [{ type: "before-last-message" }];
|
|
8480
|
+
} else if (typeof toolCalls === "string") {
|
|
8481
|
+
toolCalls = [{ type: toolCalls }];
|
|
8482
|
+
}
|
|
8483
|
+
for (const toolCall of toolCalls) {
|
|
8484
|
+
const keepLastMessagesCount = toolCall.type === "all" ? void 0 : toolCall.type === "before-last-message" ? 1 : Number(
|
|
8485
|
+
toolCall.type.slice("before-last-".length).slice(0, -"-messages".length)
|
|
8486
|
+
);
|
|
8487
|
+
const keptToolCallIds = /* @__PURE__ */ new Set();
|
|
8488
|
+
const keptApprovalIds = /* @__PURE__ */ new Set();
|
|
8489
|
+
if (keepLastMessagesCount != null) {
|
|
8490
|
+
for (const message of messages.slice(0, -keepLastMessagesCount)) {
|
|
8491
|
+
if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
|
|
8492
|
+
for (const part of message.content) {
|
|
8493
|
+
if (part.type === "tool-call" || part.type === "tool-result") {
|
|
8494
|
+
keptToolCallIds.add(part.toolCallId);
|
|
8495
|
+
} else if (part.type === "tool-approval-request" || part.type === "tool-approval-response") {
|
|
8496
|
+
keptApprovalIds.add(part.approvalId);
|
|
8497
|
+
}
|
|
8498
|
+
}
|
|
8499
|
+
}
|
|
8500
|
+
}
|
|
8501
|
+
}
|
|
8502
|
+
messages = messages.map((message, messageIndex) => {
|
|
8503
|
+
if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
|
|
8504
|
+
return message;
|
|
8505
|
+
}
|
|
8506
|
+
const toolCallIdToToolName = {};
|
|
8507
|
+
const approvalIdToToolName = {};
|
|
8508
|
+
return {
|
|
8509
|
+
...message,
|
|
8510
|
+
content: message.content.filter((part) => {
|
|
8511
|
+
if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
|
|
8512
|
+
return true;
|
|
8513
|
+
}
|
|
8514
|
+
if (part.type === "tool-call") {
|
|
8515
|
+
toolCallIdToToolName[part.toolCallId] = part.toolName;
|
|
8516
|
+
} else if (part.type === "tool-approval-request") {
|
|
8517
|
+
approvalIdToToolName[part.approvalId] = toolCallIdToToolName[part.toolCallId];
|
|
8518
|
+
}
|
|
8519
|
+
if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId) || (part.type === "tool-approval-request" || part.type === "tool-approval-response") && keptApprovalIds.has(part.approvalId)) {
|
|
8520
|
+
return true;
|
|
8521
|
+
}
|
|
8522
|
+
return toolCall.tools != null && !toolCall.tools.includes(
|
|
8523
|
+
part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName[part.approvalId]
|
|
8524
|
+
);
|
|
8525
|
+
})
|
|
8526
|
+
};
|
|
8527
|
+
});
|
|
8528
|
+
}
|
|
8529
|
+
if (emptyMessages === "remove") {
|
|
8530
|
+
messages = messages.filter((message) => message.content.length > 0);
|
|
8531
|
+
}
|
|
8532
|
+
return messages;
|
|
8533
|
+
}
|
|
8534
|
+
|
|
8455
8535
|
// src/generate-text/smooth-stream.ts
|
|
8456
8536
|
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
8457
8537
|
var import_provider27 = require("@ai-sdk/provider");
|
|
@@ -10907,7 +10987,7 @@ function readUIMessageStream({
|
|
|
10907
10987
|
AISDKError,
|
|
10908
10988
|
APICallError,
|
|
10909
10989
|
AbstractChat,
|
|
10910
|
-
|
|
10990
|
+
BasicAgent,
|
|
10911
10991
|
DefaultChatTransport,
|
|
10912
10992
|
DownloadError,
|
|
10913
10993
|
EmptyResponseBodyError,
|
|
@@ -10994,6 +11074,7 @@ function readUIMessageStream({
|
|
|
10994
11074
|
parsePartialJson,
|
|
10995
11075
|
pipeTextStreamToResponse,
|
|
10996
11076
|
pipeUIMessageStreamToResponse,
|
|
11077
|
+
pruneMessages,
|
|
10997
11078
|
readUIMessageStream,
|
|
10998
11079
|
safeValidateUIMessages,
|
|
10999
11080
|
simulateReadableStream,
|