@convex-dev/agent 0.1.18-alpha.1 → 0.5.0-alpha.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/dist/client/createTool.d.ts +30 -9
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +24 -9
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/definePlaygroundAPI.d.ts +174 -199
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +12 -19
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/files.js +4 -4
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +166 -63
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +75 -45
- package/dist/client/index.js.map +1 -1
- package/dist/client/search.d.ts +27 -6
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js.map +1 -1
- package/dist/client/streaming.d.ts +3 -2
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js.map +1 -1
- package/dist/client/types.d.ts +27 -41
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +436 -73
- package/dist/component/messages.d.ts +246 -43
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +2 -2
- package/dist/component/messages.js.map +1 -1
- package/dist/component/schema.d.ts +1453 -152
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +2 -2
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.d.ts +180 -6
- package/dist/component/streams.d.ts.map +1 -1
- package/dist/mapping.d.ts +12 -14
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +187 -47
- package/dist/mapping.js.map +1 -1
- package/dist/react/deltas.d.ts +0 -3
- package/dist/react/deltas.d.ts.map +1 -1
- package/dist/react/deltas.js +140 -44
- package/dist/react/deltas.js.map +1 -1
- package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
- package/dist/react/optimisticallySendMessage.js +2 -1
- package/dist/react/optimisticallySendMessage.js.map +1 -1
- package/dist/react/toUIMessages.d.ts +5 -4
- package/dist/react/toUIMessages.d.ts.map +1 -1
- package/dist/react/toUIMessages.js +103 -40
- package/dist/react/toUIMessages.js.map +1 -1
- package/dist/validators.d.ts +1798 -259
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +79 -15
- package/dist/validators.js.map +1 -1
- package/package.json +2 -2
- package/src/client/createTool.ts +68 -37
- package/src/client/definePlaygroundAPI.ts +24 -25
- package/src/client/files.ts +4 -4
- package/src/client/index.test.ts +14 -12
- package/src/client/index.ts +134 -94
- package/src/client/search.ts +3 -2
- package/src/client/streaming.ts +4 -3
- package/src/client/types.ts +34 -70
- package/src/component/_generated/api.d.ts +436 -73
- package/src/component/messages.ts +2 -2
- package/src/component/schema.ts +2 -2
- package/src/mapping.ts +228 -75
- package/src/react/deltas.ts +165 -52
- package/src/react/optimisticallySendMessage.ts +4 -1
- package/src/react/toUIMessages.test.ts +154 -36
- package/src/react/toUIMessages.ts +136 -57
- package/src/validators.test.ts +2 -99
- package/src/validators.ts +95 -17
package/dist/client/index.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { LanguageModelV2, EmbeddingModelV2 } from "@ai-sdk/provider";
|
|
2
|
+
import type { ModelMessage, DeepPartial, GenerateObjectResult, GenerateTextResult, StepResult, StreamObjectResult, StreamTextResult, ToolSet, StopCondition, Schema } from "ai";
|
|
3
3
|
import { type GenericActionCtx, type GenericDataModel, type PaginationOptions, type PaginationResult } from "convex/server";
|
|
4
4
|
import type { MessageDoc, ThreadDoc } from "../component/schema.js";
|
|
5
5
|
import type { threadFieldsSupportingPatch } from "../component/threads.js";
|
|
6
6
|
import { type VectorDimension } from "../component/vector/tables.js";
|
|
7
|
-
import { type AIMessageWithoutId } from "../mapping.js";
|
|
8
7
|
import { extractText, isTool } from "../shared.js";
|
|
9
|
-
import { type MessageEmbeddings, type MessageStatus, type MessageWithMetadata, type ProviderMetadata, type StreamArgs, type Usage } from "../validators.js";
|
|
8
|
+
import { type Message, type MessageEmbeddings, type MessageStatus, type MessageWithMetadata, type ProviderMetadata, type StreamArgs, type Usage } from "../validators.js";
|
|
10
9
|
import { createTool } from "./createTool.js";
|
|
11
10
|
import { listMessages } from "./listMessages.js";
|
|
12
|
-
import {
|
|
13
|
-
import { type StreamingOptions, syncStreams } from "./streaming.js";
|
|
11
|
+
import { type StreamingOptions } from "./streaming.js";
|
|
14
12
|
import type { ActionCtx, AgentComponent, ContextOptions, GenerationOutputMetadata, Options, OurObjectArgs, OurStreamObjectArgs, RawRequestResponseHandler, RunActionCtx, RunMutationCtx, RunQueryCtx, StorageOptions, StreamingTextArgs, SyncStreamsReturnValue, TextArgs, Thread, UsageHandler } from "./types.js";
|
|
13
|
+
import type z from "zod";
|
|
14
|
+
export { stepCountIs } from "ai";
|
|
15
15
|
export { vMessageDoc, vThreadDoc } from "../component/schema.js";
|
|
16
|
-
export { serializeDataOrUrl } from "../mapping.js";
|
|
16
|
+
export { serializeDataOrUrl, deserializeMessage, serializeMessage, } from "../mapping.js";
|
|
17
17
|
export { vAssistantMessage, vContextOptions, vMessage, vPaginationResult, vProviderMetadata, vStorageOptions, vStreamArgs, vSystemMessage, vToolMessage, vUsage, vUserMessage, } from "../validators.js";
|
|
18
18
|
export type { ToolCtx } from "./createTool.js";
|
|
19
19
|
export { getFile, storeFile } from "./files.js";
|
|
20
|
-
export { filterOutOrphanedToolMessages } from "./search.js";
|
|
21
|
-
export { abortStream, listStreams } from "./streaming.js";
|
|
22
|
-
export { createTool, extractText,
|
|
20
|
+
export { filterOutOrphanedToolMessages, fetchContextMessages, } from "./search.js";
|
|
21
|
+
export { abortStream, listStreams, syncStreams } from "./streaming.js";
|
|
22
|
+
export { createTool, extractText, isTool, listMessages };
|
|
23
23
|
export { definePlaygroundAPI, type PlaygroundAPI, type AgentsFn, } from "./definePlaygroundAPI.js";
|
|
24
24
|
export type { AgentComponent, ContextOptions, MessageDoc, ProviderMetadata, RawRequestResponseHandler, StorageOptions, StreamArgs, SyncStreamsReturnValue, Thread, ThreadDoc, Usage, UsageHandler, };
|
|
25
25
|
export declare class Agent<
|
|
@@ -57,7 +57,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
57
57
|
* const myAgent = new Agent(components.agent, {
|
|
58
58
|
* chat: openai.chat("gpt-4o-mini"),
|
|
59
59
|
*/
|
|
60
|
-
chat:
|
|
60
|
+
chat: LanguageModelV2;
|
|
61
61
|
/**
|
|
62
62
|
* The model to use for text embeddings. Optional.
|
|
63
63
|
* If specified, it will use this for generating vector embeddings
|
|
@@ -68,7 +68,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
68
68
|
* const myAgent = new Agent(components.agent, {
|
|
69
69
|
* textEmbedding: openai.embedding("text-embedding-3-small")
|
|
70
70
|
*/
|
|
71
|
-
textEmbedding?:
|
|
71
|
+
textEmbedding?: EmbeddingModelV2<string>;
|
|
72
72
|
/**
|
|
73
73
|
* The default system prompt to put in each request.
|
|
74
74
|
* Override per-prompt by passing the "system" parameter.
|
|
@@ -94,9 +94,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
94
94
|
storageOptions?: StorageOptions;
|
|
95
95
|
/**
|
|
96
96
|
* When generating or streaming text with tools available, this
|
|
97
|
-
* determines
|
|
97
|
+
* determines when to stop. Defaults to stepCountIs(1).
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
100
100
|
/**
|
|
101
101
|
* The maximum number of calls to make to an LLM in case it fails.
|
|
102
102
|
* This can be overridden at each generate/stream callsite.
|
|
@@ -125,7 +125,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
125
125
|
* const myAgent = new Agent(components.agent, {
|
|
126
126
|
* chat: openai.chat("gpt-4o-mini"),
|
|
127
127
|
*/
|
|
128
|
-
chat:
|
|
128
|
+
chat: LanguageModelV2;
|
|
129
129
|
/**
|
|
130
130
|
* The model to use for text embeddings. Optional.
|
|
131
131
|
* If specified, it will use this for generating vector embeddings
|
|
@@ -136,7 +136,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
136
136
|
* const myAgent = new Agent(components.agent, {
|
|
137
137
|
* textEmbedding: openai.embedding("text-embedding-3-small")
|
|
138
138
|
*/
|
|
139
|
-
textEmbedding?:
|
|
139
|
+
textEmbedding?: EmbeddingModelV2<string>;
|
|
140
140
|
/**
|
|
141
141
|
* The default system prompt to put in each request.
|
|
142
142
|
* Override per-prompt by passing the "system" parameter.
|
|
@@ -162,9 +162,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
162
162
|
storageOptions?: StorageOptions;
|
|
163
163
|
/**
|
|
164
164
|
* When generating or streaming text with tools available, this
|
|
165
|
-
* determines
|
|
165
|
+
* determines when to stop. Defaults to stepCountIs(1).
|
|
166
166
|
*/
|
|
167
|
-
|
|
167
|
+
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
168
168
|
/**
|
|
169
169
|
* The maximum number of calls to make to an LLM in case it fails.
|
|
170
170
|
* This can be overridden at each generate/stream callsite.
|
|
@@ -382,7 +382,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
382
382
|
* Use {@link continueThread} to get a version of this function already scoped
|
|
383
383
|
* to a thread (and optionally userId).
|
|
384
384
|
*/
|
|
385
|
-
streamObject<T>(ctx: ActionCtx, { userId: argsUserId, threadId, usageHandler, }: {
|
|
385
|
+
streamObject<T extends z.Schema | Schema>(ctx: ActionCtx, { userId: argsUserId, threadId, usageHandler, }: {
|
|
386
386
|
userId?: string | null;
|
|
387
387
|
threadId?: string;
|
|
388
388
|
usageHandler?: UsageHandler;
|
|
@@ -458,6 +458,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
458
458
|
} | {
|
|
459
459
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
460
460
|
signature?: string | undefined;
|
|
461
|
+
state?: "streaming" | "done" | undefined;
|
|
461
462
|
type: "reasoning";
|
|
462
463
|
text: string;
|
|
463
464
|
} | {
|
|
@@ -466,6 +467,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
466
467
|
data: string;
|
|
467
468
|
} | {
|
|
468
469
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
470
|
+
providerExecuted?: boolean | undefined;
|
|
469
471
|
type: "tool-call";
|
|
470
472
|
toolCallId: string;
|
|
471
473
|
toolName: string;
|
|
@@ -477,6 +479,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
477
479
|
content: {
|
|
478
480
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
479
481
|
args?: any;
|
|
482
|
+
providerExecuted?: boolean | undefined;
|
|
483
|
+
isError?: boolean | undefined;
|
|
480
484
|
experimental_content?: ({
|
|
481
485
|
type: "text";
|
|
482
486
|
text: string;
|
|
@@ -485,7 +489,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
485
489
|
type: "image";
|
|
486
490
|
data: string;
|
|
487
491
|
})[] | undefined;
|
|
488
|
-
isError?: boolean | undefined;
|
|
489
492
|
type: "tool-result";
|
|
490
493
|
toolCallId: string;
|
|
491
494
|
toolName: string;
|
|
@@ -499,19 +502,36 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
499
502
|
text?: string | undefined;
|
|
500
503
|
reasoning?: string | undefined;
|
|
501
504
|
usage?: {
|
|
505
|
+
reasoningTokens?: number | undefined;
|
|
506
|
+
cachedInputTokens?: number | undefined;
|
|
502
507
|
promptTokens: number;
|
|
503
508
|
completionTokens: number;
|
|
504
509
|
totalTokens: number;
|
|
505
510
|
} | undefined;
|
|
506
511
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
507
|
-
sources?: {
|
|
512
|
+
sources?: ({
|
|
508
513
|
title?: string | undefined;
|
|
514
|
+
type?: "source" | undefined;
|
|
509
515
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
516
|
+
url?: string | undefined;
|
|
510
517
|
id: string;
|
|
511
518
|
sourceType: "url";
|
|
512
|
-
|
|
513
|
-
|
|
519
|
+
} | {
|
|
520
|
+
filename?: string | undefined;
|
|
521
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
522
|
+
id: string;
|
|
523
|
+
title: string;
|
|
524
|
+
type: "source";
|
|
525
|
+
sourceType: "document";
|
|
526
|
+
mediaType: string;
|
|
527
|
+
})[] | undefined;
|
|
514
528
|
reasoningDetails?: ({
|
|
529
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
530
|
+
signature?: string | undefined;
|
|
531
|
+
state?: "streaming" | "done" | undefined;
|
|
532
|
+
type: "reasoning";
|
|
533
|
+
text: string;
|
|
534
|
+
} | {
|
|
515
535
|
signature?: string | undefined;
|
|
516
536
|
type: "text";
|
|
517
537
|
text: string;
|
|
@@ -601,7 +621,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
601
621
|
fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, args: {
|
|
602
622
|
userId: string | undefined;
|
|
603
623
|
threadId: string | undefined;
|
|
604
|
-
messages:
|
|
624
|
+
messages: (ModelMessage | Message)[];
|
|
605
625
|
/**
|
|
606
626
|
* If provided, it will search for messages up to and including this message.
|
|
607
627
|
* Note: if this is far in the past, text and vector search results may be more
|
|
@@ -638,7 +658,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
638
658
|
generateEmbeddings(ctx: RunActionCtx, { userId, threadId, }: {
|
|
639
659
|
userId: string | undefined;
|
|
640
660
|
threadId: string | undefined;
|
|
641
|
-
}, messages:
|
|
661
|
+
}, messages: (ModelMessage | Message)[]): Promise<{
|
|
642
662
|
vectors: (number[] | null)[];
|
|
643
663
|
dimension: VectorDimension;
|
|
644
664
|
model: string;
|
|
@@ -728,9 +748,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
728
748
|
messageId: string;
|
|
729
749
|
patch: {
|
|
730
750
|
/** The message to replace the existing message. */
|
|
731
|
-
message:
|
|
751
|
+
message: (ModelMessage & {
|
|
732
752
|
id?: string;
|
|
733
|
-
};
|
|
753
|
+
}) | Message;
|
|
734
754
|
/** The status to set on the message. */
|
|
735
755
|
status: "success" | "error";
|
|
736
756
|
/** The error message to set on the message. */
|
|
@@ -809,7 +829,11 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
809
829
|
startStepOrder?: number;
|
|
810
830
|
endOrder: number;
|
|
811
831
|
endStepOrder?: number;
|
|
812
|
-
}): Promise<
|
|
832
|
+
}): Promise<{
|
|
833
|
+
isDone: boolean;
|
|
834
|
+
lastOrder?: number;
|
|
835
|
+
lastStepOrder?: number;
|
|
836
|
+
}>;
|
|
813
837
|
/**
|
|
814
838
|
* Delete a thread and all its messages and streams asynchronously (in batches)
|
|
815
839
|
* This uses a mutation to that processes one page and recursively queues the
|
|
@@ -834,18 +858,18 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
834
858
|
}): Promise<void>;
|
|
835
859
|
_saveMessagesAndFetchContext<T extends {
|
|
836
860
|
id?: string;
|
|
837
|
-
prompt?: string;
|
|
838
|
-
messages?:
|
|
861
|
+
prompt?: string | (ModelMessage | Message)[];
|
|
862
|
+
messages?: (ModelMessage | Message)[];
|
|
839
863
|
system?: string;
|
|
840
864
|
promptMessageId?: string;
|
|
841
|
-
model?:
|
|
865
|
+
model?: LanguageModelV2;
|
|
842
866
|
maxRetries?: number;
|
|
843
867
|
}>(ctx: RunActionCtx, args: T, { userId: argsUserId, threadId, contextOptions, storageOptions, }: {
|
|
844
868
|
userId: string | undefined;
|
|
845
869
|
threadId: string | undefined;
|
|
846
870
|
} & Options): Promise<{
|
|
847
871
|
args: T & {
|
|
848
|
-
model:
|
|
872
|
+
model: LanguageModelV2;
|
|
849
873
|
};
|
|
850
874
|
userId: string | undefined;
|
|
851
875
|
messageId: string | undefined;
|
|
@@ -907,14 +931,14 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
907
931
|
* Create an action out of this agent so you can call it from workflows or other actions
|
|
908
932
|
* without a wrapping function.
|
|
909
933
|
* @param spec Configuration for the agent acting as an action, including
|
|
910
|
-
* {@link ContextOptions}, {@link StorageOptions}, and
|
|
934
|
+
* {@link ContextOptions}, {@link StorageOptions}, and {@link stopWhen}.
|
|
911
935
|
*/
|
|
912
936
|
asTextAction<DataModel extends GenericDataModel>(spec?: {
|
|
913
937
|
/**
|
|
914
|
-
*
|
|
915
|
-
* Defaults to the {@link Agent.
|
|
938
|
+
* When to stop generating text.
|
|
939
|
+
* Defaults to the {@link Agent["options"].stopWhen} option.
|
|
916
940
|
*/
|
|
917
|
-
|
|
941
|
+
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
918
942
|
/**
|
|
919
943
|
* The {@link ContextOptions} to use for fetching contextual messages and
|
|
920
944
|
* saving input/output messages.
|
|
@@ -997,6 +1021,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
997
1021
|
} | {
|
|
998
1022
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
999
1023
|
signature?: string | undefined;
|
|
1024
|
+
state?: "streaming" | "done" | undefined;
|
|
1000
1025
|
type: "reasoning";
|
|
1001
1026
|
text: string;
|
|
1002
1027
|
} | {
|
|
@@ -1005,6 +1030,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1005
1030
|
data: string;
|
|
1006
1031
|
} | {
|
|
1007
1032
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1033
|
+
providerExecuted?: boolean | undefined;
|
|
1008
1034
|
type: "tool-call";
|
|
1009
1035
|
toolCallId: string;
|
|
1010
1036
|
toolName: string;
|
|
@@ -1016,6 +1042,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1016
1042
|
content: {
|
|
1017
1043
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1018
1044
|
args?: any;
|
|
1045
|
+
providerExecuted?: boolean | undefined;
|
|
1046
|
+
isError?: boolean | undefined;
|
|
1019
1047
|
experimental_content?: ({
|
|
1020
1048
|
type: "text";
|
|
1021
1049
|
text: string;
|
|
@@ -1024,7 +1052,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1024
1052
|
type: "image";
|
|
1025
1053
|
data: string;
|
|
1026
1054
|
})[] | undefined;
|
|
1027
|
-
isError?: boolean | undefined;
|
|
1028
1055
|
type: "tool-result";
|
|
1029
1056
|
toolCallId: string;
|
|
1030
1057
|
toolName: string;
|
|
@@ -1075,25 +1102,23 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1075
1102
|
text: string;
|
|
1076
1103
|
messageId: string | undefined;
|
|
1077
1104
|
order: number | undefined;
|
|
1078
|
-
finishReason: import("@ai-sdk/provider").
|
|
1079
|
-
warnings: Promise<import("@ai-sdk/provider").
|
|
1105
|
+
finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
|
|
1106
|
+
warnings: Promise<import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined>;
|
|
1080
1107
|
} | {
|
|
1081
1108
|
text: string;
|
|
1082
1109
|
messageId: string | undefined;
|
|
1083
1110
|
order: number | undefined;
|
|
1084
|
-
finishReason: import("@ai-sdk/provider").
|
|
1085
|
-
warnings: import("@ai-sdk/provider").
|
|
1111
|
+
finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
|
|
1112
|
+
warnings: import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined;
|
|
1086
1113
|
}>>;
|
|
1087
1114
|
/**
|
|
1088
1115
|
* Create an action that generates an object out of this agent so you can call
|
|
1089
1116
|
* it from workflows or other actions without a wrapping function.
|
|
1090
1117
|
* @param spec Configuration for the agent acting as an action, including
|
|
1091
1118
|
* the normal parameters to {@link generateObject}, plus {@link ContextOptions}
|
|
1092
|
-
* and
|
|
1119
|
+
* and stopWhen.
|
|
1093
1120
|
*/
|
|
1094
|
-
asObjectAction<T>(spec: OurObjectArgs<T
|
|
1095
|
-
maxSteps?: number;
|
|
1096
|
-
}, options?: {
|
|
1121
|
+
asObjectAction<T>(spec: OurObjectArgs<T>, options?: {
|
|
1097
1122
|
contextOptions?: ContextOptions;
|
|
1098
1123
|
storageOptions?: StorageOptions;
|
|
1099
1124
|
}): import("convex/server").RegisteredAction<"internal", {
|
|
@@ -1136,6 +1161,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1136
1161
|
} | {
|
|
1137
1162
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1138
1163
|
signature?: string | undefined;
|
|
1164
|
+
state?: "streaming" | "done" | undefined;
|
|
1139
1165
|
type: "reasoning";
|
|
1140
1166
|
text: string;
|
|
1141
1167
|
} | {
|
|
@@ -1144,6 +1170,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1144
1170
|
data: string;
|
|
1145
1171
|
} | {
|
|
1146
1172
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1173
|
+
providerExecuted?: boolean | undefined;
|
|
1147
1174
|
type: "tool-call";
|
|
1148
1175
|
toolCallId: string;
|
|
1149
1176
|
toolName: string;
|
|
@@ -1155,6 +1182,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1155
1182
|
content: {
|
|
1156
1183
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1157
1184
|
args?: any;
|
|
1185
|
+
providerExecuted?: boolean | undefined;
|
|
1186
|
+
isError?: boolean | undefined;
|
|
1158
1187
|
experimental_content?: ({
|
|
1159
1188
|
type: "text";
|
|
1160
1189
|
text: string;
|
|
@@ -1163,7 +1192,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1163
1192
|
type: "image";
|
|
1164
1193
|
data: string;
|
|
1165
1194
|
})[] | undefined;
|
|
1166
|
-
isError?: boolean | undefined;
|
|
1167
1195
|
type: "tool-result";
|
|
1168
1196
|
toolCallId: string;
|
|
1169
1197
|
toolName: string;
|
|
@@ -1207,8 +1235,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1207
1235
|
object: T;
|
|
1208
1236
|
messageId: string | undefined;
|
|
1209
1237
|
order: number | undefined;
|
|
1210
|
-
finishReason: import("@ai-sdk/provider").
|
|
1211
|
-
warnings: import("@ai-sdk/provider").
|
|
1238
|
+
finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
|
|
1239
|
+
warnings: import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined;
|
|
1212
1240
|
}>>;
|
|
1213
1241
|
/**
|
|
1214
1242
|
* Save messages to the thread.
|
|
@@ -1245,19 +1273,36 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1245
1273
|
text?: string | undefined;
|
|
1246
1274
|
reasoning?: string | undefined;
|
|
1247
1275
|
usage?: {
|
|
1276
|
+
reasoningTokens?: number | undefined;
|
|
1277
|
+
cachedInputTokens?: number | undefined;
|
|
1248
1278
|
promptTokens: number;
|
|
1249
1279
|
completionTokens: number;
|
|
1250
1280
|
totalTokens: number;
|
|
1251
1281
|
} | undefined;
|
|
1252
1282
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1253
|
-
sources?: {
|
|
1283
|
+
sources?: ({
|
|
1254
1284
|
title?: string | undefined;
|
|
1285
|
+
type?: "source" | undefined;
|
|
1255
1286
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1287
|
+
url?: string | undefined;
|
|
1256
1288
|
id: string;
|
|
1257
1289
|
sourceType: "url";
|
|
1258
|
-
|
|
1259
|
-
|
|
1290
|
+
} | {
|
|
1291
|
+
filename?: string | undefined;
|
|
1292
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1293
|
+
id: string;
|
|
1294
|
+
title: string;
|
|
1295
|
+
type: "source";
|
|
1296
|
+
sourceType: "document";
|
|
1297
|
+
mediaType: string;
|
|
1298
|
+
})[] | undefined;
|
|
1260
1299
|
reasoningDetails?: ({
|
|
1300
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1301
|
+
signature?: string | undefined;
|
|
1302
|
+
state?: "streaming" | "done" | undefined;
|
|
1303
|
+
type: "reasoning";
|
|
1304
|
+
text: string;
|
|
1305
|
+
} | {
|
|
1261
1306
|
signature?: string | undefined;
|
|
1262
1307
|
type: "text";
|
|
1263
1308
|
text: string;
|
|
@@ -1313,6 +1358,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1313
1358
|
} | {
|
|
1314
1359
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1315
1360
|
signature?: string | undefined;
|
|
1361
|
+
state?: "streaming" | "done" | undefined;
|
|
1316
1362
|
type: "reasoning";
|
|
1317
1363
|
text: string;
|
|
1318
1364
|
} | {
|
|
@@ -1321,6 +1367,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1321
1367
|
data: string;
|
|
1322
1368
|
} | {
|
|
1323
1369
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1370
|
+
providerExecuted?: boolean | undefined;
|
|
1324
1371
|
type: "tool-call";
|
|
1325
1372
|
toolCallId: string;
|
|
1326
1373
|
toolName: string;
|
|
@@ -1332,6 +1379,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1332
1379
|
content: {
|
|
1333
1380
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1334
1381
|
args?: any;
|
|
1382
|
+
providerExecuted?: boolean | undefined;
|
|
1383
|
+
isError?: boolean | undefined;
|
|
1335
1384
|
experimental_content?: ({
|
|
1336
1385
|
type: "text";
|
|
1337
1386
|
text: string;
|
|
@@ -1340,7 +1389,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1340
1389
|
type: "image";
|
|
1341
1390
|
data: string;
|
|
1342
1391
|
})[] | undefined;
|
|
1343
|
-
isError?: boolean | undefined;
|
|
1344
1392
|
type: "tool-result";
|
|
1345
1393
|
toolCallId: string;
|
|
1346
1394
|
toolName: string;
|
|
@@ -1357,9 +1405,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1357
1405
|
messageIds: string[];
|
|
1358
1406
|
}>>;
|
|
1359
1407
|
}
|
|
1360
|
-
type CoreMessageMaybeWithId = CoreMessage & {
|
|
1361
|
-
id?: string | undefined;
|
|
1362
|
-
};
|
|
1363
1408
|
/**
|
|
1364
1409
|
* Create a thread to store messages with an Agent.
|
|
1365
1410
|
* @param ctx The context from a mutation or action.
|
|
@@ -1392,7 +1437,9 @@ type SaveMessagesArgs = {
|
|
|
1392
1437
|
/**
|
|
1393
1438
|
* The messages to save.
|
|
1394
1439
|
*/
|
|
1395
|
-
messages:
|
|
1440
|
+
messages: ((ModelMessage & {
|
|
1441
|
+
id?: string | undefined;
|
|
1442
|
+
}) | Message)[];
|
|
1396
1443
|
/**
|
|
1397
1444
|
* Metadata to save with the messages. Each element corresponds to the
|
|
1398
1445
|
* message at the same index.
|
|
@@ -1494,6 +1541,7 @@ export declare function saveMessages(ctx: RunMutationCtx, component: AgentCompon
|
|
|
1494
1541
|
};
|
|
1495
1542
|
} | undefined;
|
|
1496
1543
|
signature?: string | undefined;
|
|
1544
|
+
state?: "streaming" | "done" | undefined;
|
|
1497
1545
|
text: string;
|
|
1498
1546
|
type: "reasoning";
|
|
1499
1547
|
} | {
|
|
@@ -1506,6 +1554,7 @@ export declare function saveMessages(ctx: RunMutationCtx, component: AgentCompon
|
|
|
1506
1554
|
type: "redacted-reasoning";
|
|
1507
1555
|
} | {
|
|
1508
1556
|
args: any;
|
|
1557
|
+
providerExecuted?: boolean | undefined;
|
|
1509
1558
|
providerOptions?: {
|
|
1510
1559
|
[x: string]: {
|
|
1511
1560
|
[x: string]: any;
|
|
@@ -1533,6 +1582,7 @@ export declare function saveMessages(ctx: RunMutationCtx, component: AgentCompon
|
|
|
1533
1582
|
type: "image";
|
|
1534
1583
|
})[] | undefined;
|
|
1535
1584
|
isError?: boolean | undefined;
|
|
1585
|
+
providerExecuted?: boolean | undefined;
|
|
1536
1586
|
providerOptions?: {
|
|
1537
1587
|
[x: string]: {
|
|
1538
1588
|
[x: string]: any;
|
|
@@ -1573,6 +1623,16 @@ export declare function saveMessages(ctx: RunMutationCtx, component: AgentCompon
|
|
|
1573
1623
|
} | undefined;
|
|
1574
1624
|
reasoning?: string | undefined;
|
|
1575
1625
|
reasoningDetails?: ({
|
|
1626
|
+
providerOptions?: {
|
|
1627
|
+
[x: string]: {
|
|
1628
|
+
[x: string]: any;
|
|
1629
|
+
};
|
|
1630
|
+
} | undefined;
|
|
1631
|
+
signature?: string | undefined;
|
|
1632
|
+
state?: "streaming" | "done" | undefined;
|
|
1633
|
+
text: string;
|
|
1634
|
+
type: "reasoning";
|
|
1635
|
+
} | {
|
|
1576
1636
|
signature?: string | undefined;
|
|
1577
1637
|
text: string;
|
|
1578
1638
|
type: "text";
|
|
@@ -1580,7 +1640,7 @@ export declare function saveMessages(ctx: RunMutationCtx, component: AgentCompon
|
|
|
1580
1640
|
data: string;
|
|
1581
1641
|
type: "redacted";
|
|
1582
1642
|
})[] | undefined;
|
|
1583
|
-
sources?: {
|
|
1643
|
+
sources?: ({
|
|
1584
1644
|
id: string;
|
|
1585
1645
|
providerOptions?: {
|
|
1586
1646
|
[x: string]: {
|
|
@@ -1589,16 +1649,31 @@ export declare function saveMessages(ctx: RunMutationCtx, component: AgentCompon
|
|
|
1589
1649
|
} | undefined;
|
|
1590
1650
|
sourceType: "url";
|
|
1591
1651
|
title?: string | undefined;
|
|
1592
|
-
|
|
1593
|
-
|
|
1652
|
+
type?: "source" | undefined;
|
|
1653
|
+
url?: string | undefined;
|
|
1654
|
+
} | {
|
|
1655
|
+
filename?: string | undefined;
|
|
1656
|
+
id: string;
|
|
1657
|
+
mediaType: string;
|
|
1658
|
+
providerMetadata?: {
|
|
1659
|
+
[x: string]: {
|
|
1660
|
+
[x: string]: any;
|
|
1661
|
+
};
|
|
1662
|
+
} | undefined;
|
|
1663
|
+
sourceType: "document";
|
|
1664
|
+
title: string;
|
|
1665
|
+
type: "source";
|
|
1666
|
+
})[] | undefined;
|
|
1594
1667
|
status: "pending" | "success" | "failed";
|
|
1595
1668
|
stepOrder: number;
|
|
1596
1669
|
text?: string | undefined;
|
|
1597
1670
|
threadId: string;
|
|
1598
1671
|
tool: boolean;
|
|
1599
1672
|
usage?: {
|
|
1673
|
+
cachedInputTokens?: number | undefined;
|
|
1600
1674
|
completionTokens: number;
|
|
1601
1675
|
promptTokens: number;
|
|
1676
|
+
reasoningTokens?: number | undefined;
|
|
1602
1677
|
totalTokens: number;
|
|
1603
1678
|
} | undefined;
|
|
1604
1679
|
userId?: string | undefined;
|
|
@@ -1636,7 +1711,7 @@ type SaveMessageArgs = {
|
|
|
1636
1711
|
/**
|
|
1637
1712
|
* The message to save.
|
|
1638
1713
|
*/
|
|
1639
|
-
message:
|
|
1714
|
+
message: ModelMessage | Message;
|
|
1640
1715
|
} | {
|
|
1641
1716
|
prompt: string;
|
|
1642
1717
|
message?: undefined;
|
|
@@ -1725,6 +1800,7 @@ export declare function saveMessage(ctx: RunMutationCtx, component: AgentCompone
|
|
|
1725
1800
|
};
|
|
1726
1801
|
} | undefined;
|
|
1727
1802
|
signature?: string | undefined;
|
|
1803
|
+
state?: "streaming" | "done" | undefined;
|
|
1728
1804
|
text: string;
|
|
1729
1805
|
type: "reasoning";
|
|
1730
1806
|
} | {
|
|
@@ -1737,6 +1813,7 @@ export declare function saveMessage(ctx: RunMutationCtx, component: AgentCompone
|
|
|
1737
1813
|
type: "redacted-reasoning";
|
|
1738
1814
|
} | {
|
|
1739
1815
|
args: any;
|
|
1816
|
+
providerExecuted?: boolean | undefined;
|
|
1740
1817
|
providerOptions?: {
|
|
1741
1818
|
[x: string]: {
|
|
1742
1819
|
[x: string]: any;
|
|
@@ -1764,6 +1841,7 @@ export declare function saveMessage(ctx: RunMutationCtx, component: AgentCompone
|
|
|
1764
1841
|
type: "image";
|
|
1765
1842
|
})[] | undefined;
|
|
1766
1843
|
isError?: boolean | undefined;
|
|
1844
|
+
providerExecuted?: boolean | undefined;
|
|
1767
1845
|
providerOptions?: {
|
|
1768
1846
|
[x: string]: {
|
|
1769
1847
|
[x: string]: any;
|
|
@@ -1804,6 +1882,16 @@ export declare function saveMessage(ctx: RunMutationCtx, component: AgentCompone
|
|
|
1804
1882
|
} | undefined;
|
|
1805
1883
|
reasoning?: string | undefined;
|
|
1806
1884
|
reasoningDetails?: ({
|
|
1885
|
+
providerOptions?: {
|
|
1886
|
+
[x: string]: {
|
|
1887
|
+
[x: string]: any;
|
|
1888
|
+
};
|
|
1889
|
+
} | undefined;
|
|
1890
|
+
signature?: string | undefined;
|
|
1891
|
+
state?: "streaming" | "done" | undefined;
|
|
1892
|
+
text: string;
|
|
1893
|
+
type: "reasoning";
|
|
1894
|
+
} | {
|
|
1807
1895
|
signature?: string | undefined;
|
|
1808
1896
|
text: string;
|
|
1809
1897
|
type: "text";
|
|
@@ -1811,7 +1899,7 @@ export declare function saveMessage(ctx: RunMutationCtx, component: AgentCompone
|
|
|
1811
1899
|
data: string;
|
|
1812
1900
|
type: "redacted";
|
|
1813
1901
|
})[] | undefined;
|
|
1814
|
-
sources?: {
|
|
1902
|
+
sources?: ({
|
|
1815
1903
|
id: string;
|
|
1816
1904
|
providerOptions?: {
|
|
1817
1905
|
[x: string]: {
|
|
@@ -1820,16 +1908,31 @@ export declare function saveMessage(ctx: RunMutationCtx, component: AgentCompone
|
|
|
1820
1908
|
} | undefined;
|
|
1821
1909
|
sourceType: "url";
|
|
1822
1910
|
title?: string | undefined;
|
|
1823
|
-
|
|
1824
|
-
|
|
1911
|
+
type?: "source" | undefined;
|
|
1912
|
+
url?: string | undefined;
|
|
1913
|
+
} | {
|
|
1914
|
+
filename?: string | undefined;
|
|
1915
|
+
id: string;
|
|
1916
|
+
mediaType: string;
|
|
1917
|
+
providerMetadata?: {
|
|
1918
|
+
[x: string]: {
|
|
1919
|
+
[x: string]: any;
|
|
1920
|
+
};
|
|
1921
|
+
} | undefined;
|
|
1922
|
+
sourceType: "document";
|
|
1923
|
+
title: string;
|
|
1924
|
+
type: "source";
|
|
1925
|
+
})[] | undefined;
|
|
1825
1926
|
status: "pending" | "success" | "failed";
|
|
1826
1927
|
stepOrder: number;
|
|
1827
1928
|
text?: string | undefined;
|
|
1828
1929
|
threadId: string;
|
|
1829
1930
|
tool: boolean;
|
|
1830
1931
|
usage?: {
|
|
1932
|
+
cachedInputTokens?: number | undefined;
|
|
1831
1933
|
completionTokens: number;
|
|
1832
1934
|
promptTokens: number;
|
|
1935
|
+
reasoningTokens?: number | undefined;
|
|
1833
1936
|
totalTokens: number;
|
|
1834
1937
|
} | undefined;
|
|
1835
1938
|
userId?: string | undefined;
|