@convex-dev/agent 0.5.0-alpha.1 → 0.6.0-alpha.0
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/README.md +32 -27
- package/dist/UIMessages.d.ts +46 -0
- package/dist/UIMessages.d.ts.map +1 -0
- package/dist/UIMessages.js +546 -0
- package/dist/UIMessages.js.map +1 -0
- package/dist/client/createTool.d.ts +129 -27
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +66 -12
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/defaultComponent.d.ts +11 -0
- package/dist/client/defaultComponent.d.ts.map +1 -0
- package/dist/client/defaultComponent.js +7 -0
- package/dist/client/defaultComponent.js.map +1 -0
- package/dist/client/definePlaygroundAPI.d.ts +1323 -192
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +52 -28
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/files.d.ts +20 -7
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +68 -11
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +1056 -965
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +242 -748
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +461 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +106 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/client/mockModel.d.ts +42 -0
- package/dist/client/mockModel.d.ts.map +1 -0
- package/dist/client/mockModel.js +175 -0
- package/dist/client/mockModel.js.map +1 -0
- package/dist/client/saveInputMessages.d.ts +20 -0
- package/dist/client/saveInputMessages.d.ts.map +1 -0
- package/dist/client/saveInputMessages.js +58 -0
- package/dist/client/saveInputMessages.js.map +1 -0
- package/dist/client/search.d.ts +346 -35
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +350 -39
- package/dist/client/search.js.map +1 -1
- package/dist/client/start.d.ts +84 -0
- package/dist/client/start.d.ts.map +1 -0
- package/dist/client/start.js +171 -0
- package/dist/client/start.js.map +1 -0
- package/dist/client/streamText.d.ts +46 -0
- package/dist/client/streamText.d.ts.map +1 -0
- package/dist/client/streamText.js +93 -0
- package/dist/client/streamText.js.map +1 -0
- package/dist/client/streaming.d.ts +3705 -32
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js +141 -59
- package/dist/client/streaming.js.map +1 -1
- package/dist/client/threads.d.ts +46 -0
- package/dist/client/threads.d.ts.map +1 -0
- package/dist/client/threads.js +49 -0
- package/dist/client/threads.js.map +1 -0
- package/dist/client/types.d.ts +265 -128
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/utils.d.ts +4 -0
- package/dist/client/utils.d.ts.map +1 -0
- package/dist/client/utils.js +21 -0
- package/dist/client/utils.js.map +1 -0
- package/dist/component/_generated/api.d.ts +24 -2178
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js +10 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +3119 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +4 -18
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +10 -38
- package/dist/component/_generated/server.d.ts.map +1 -1
- package/dist/component/_generated/server.js +9 -5
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/files.d.ts +16 -10
- package/dist/component/files.d.ts.map +1 -1
- package/dist/component/files.js +10 -2
- package/dist/component/files.js.map +1 -1
- package/dist/component/messages.d.ts +2553 -342
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +387 -154
- package/dist/component/messages.js.map +1 -1
- package/dist/component/schema.d.ts +5697 -3584
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +18 -41
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.d.ts +35 -335
- package/dist/component/streams.d.ts.map +1 -1
- package/dist/component/streams.js +114 -73
- package/dist/component/streams.js.map +1 -1
- package/dist/component/threads.d.ts +16 -16
- package/dist/component/users.d.ts +4 -4
- package/dist/component/vector/index.d.ts +1 -1
- package/dist/component/vector/index.d.ts.map +1 -1
- package/dist/component/vector/index.js +1 -3
- package/dist/component/vector/index.js.map +1 -1
- package/dist/deltas.d.ts +43 -0
- package/dist/deltas.d.ts.map +1 -0
- package/dist/deltas.js +447 -0
- package/dist/deltas.js.map +1 -0
- package/dist/mapping.d.ts +20 -20
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +313 -96
- package/dist/mapping.js.map +1 -1
- package/dist/react/SmoothText.d.ts +5 -0
- package/dist/react/SmoothText.d.ts.map +1 -0
- package/dist/react/SmoothText.js +6 -0
- package/dist/react/SmoothText.js.map +1 -0
- package/dist/react/index.d.ts +5 -77
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +6 -160
- package/dist/react/index.js.map +1 -1
- package/dist/react/optimisticallySendMessage.d.ts +36 -3
- package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
- package/dist/react/optimisticallySendMessage.js +35 -9
- package/dist/react/optimisticallySendMessage.js.map +1 -1
- package/dist/react/types.d.ts +4 -18
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/useDeltaStreams.d.ts +10 -0
- package/dist/react/useDeltaStreams.d.ts.map +1 -0
- package/dist/react/useDeltaStreams.js +101 -0
- package/dist/react/useDeltaStreams.js.map +1 -0
- package/dist/react/useSmoothText.d.ts +13 -12
- package/dist/react/useSmoothText.d.ts.map +1 -1
- package/dist/react/useSmoothText.js +32 -15
- package/dist/react/useSmoothText.js.map +1 -1
- package/dist/react/useStreamingUIMessages.d.ts +22 -0
- package/dist/react/useStreamingUIMessages.d.ts.map +1 -0
- package/dist/react/useStreamingUIMessages.js +92 -0
- package/dist/react/useStreamingUIMessages.js.map +1 -0
- package/dist/react/useThreadMessages.d.ts +104 -0
- package/dist/react/useThreadMessages.d.ts.map +1 -0
- package/dist/react/useThreadMessages.js +148 -0
- package/dist/react/useThreadMessages.js.map +1 -0
- package/dist/react/useUIMessages.d.ts +96 -0
- package/dist/react/useUIMessages.d.ts.map +1 -0
- package/dist/react/useUIMessages.js +108 -0
- package/dist/react/useUIMessages.js.map +1 -0
- package/dist/shared.d.ts +20 -4
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +45 -8
- package/dist/shared.js.map +1 -1
- package/dist/validators.d.ts +22981 -5666
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +245 -137
- package/dist/validators.js.map +1 -1
- package/package.json +98 -50
- package/src/UIMessages.combineUIMessages.test.ts +239 -0
- package/src/UIMessages.test.ts +273 -0
- package/src/UIMessages.ts +739 -0
- package/src/client/createTool.ts +293 -76
- package/src/client/defaultComponent.ts +17 -0
- package/src/client/definePlaygroundAPI.ts +67 -31
- package/src/client/files.ts +100 -20
- package/src/client/index.test.ts +40 -85
- package/src/client/index.ts +520 -1290
- package/src/client/messages.ts +237 -0
- package/src/client/mockModel.ts +245 -0
- package/src/client/saveInputMessages.test.ts +583 -0
- package/src/client/saveInputMessages.ts +101 -0
- package/src/client/search.test.ts +1207 -0
- package/src/client/search.ts +577 -70
- package/src/client/start.ts +310 -0
- package/src/client/streamText.ts +163 -0
- package/src/client/streaming.test.ts +186 -0
- package/src/client/streaming.ts +219 -97
- package/src/client/threads.ts +83 -0
- package/src/client/types.ts +368 -219
- package/src/client/utils.ts +27 -0
- package/src/component/_generated/api.ts +64 -0
- package/src/component/_generated/component.ts +4913 -0
- package/src/component/_generated/{server.d.ts → server.ts} +33 -21
- package/src/component/files.ts +11 -2
- package/src/component/messages.test.ts +195 -51
- package/src/component/messages.ts +490 -201
- package/src/component/schema.ts +20 -46
- package/src/component/setup.test.ts +7 -0
- package/src/component/streams.ts +184 -83
- package/src/component/users.test.ts +0 -1
- package/src/component/vector/index.ts +1 -3
- package/src/deltas.test.ts +626 -0
- package/src/deltas.ts +570 -0
- package/src/fromUIMessages.test.ts +497 -0
- package/src/mapping.test.ts +103 -6
- package/src/mapping.ts +422 -161
- package/src/react/SmoothText.tsx +9 -0
- package/src/react/index.ts +10 -230
- package/src/react/optimisticallySendMessage.ts +55 -12
- package/src/react/types.ts +6 -39
- package/src/react/useDeltaStreams.ts +154 -0
- package/src/react/useSmoothText.ts +56 -36
- package/src/react/useStreamingUIMessages.ts +143 -0
- package/src/react/useThreadMessages.ts +262 -0
- package/src/react/useUIMessages.test.ts +255 -0
- package/src/react/useUIMessages.ts +195 -0
- package/src/shared.ts +88 -12
- package/src/test.ts +18 -0
- package/src/toUIMessages.test.ts +1269 -0
- package/src/validators.test.ts +18 -19
- package/src/validators.ts +325 -185
- package/dist/client/_generated/_ignore.d.ts +0 -1
- package/dist/client/_generated/_ignore.d.ts.map +0 -1
- package/dist/client/_generated/_ignore.js +0 -3
- package/dist/client/_generated/_ignore.js.map +0 -1
- package/dist/client/listMessages.d.ts +0 -22
- package/dist/client/listMessages.d.ts.map +0 -1
- package/dist/client/listMessages.js +0 -25
- package/dist/client/listMessages.js.map +0 -1
- package/dist/package.json +0 -3
- package/dist/react/deltas.d.ts +0 -26
- package/dist/react/deltas.d.ts.map +0 -1
- package/dist/react/deltas.js +0 -384
- package/dist/react/deltas.js.map +0 -1
- package/dist/react/toUIMessages.d.ts +0 -15
- package/dist/react/toUIMessages.d.ts.map +0 -1
- package/dist/react/toUIMessages.js +0 -211
- package/dist/react/toUIMessages.js.map +0 -1
- package/src/client/listMessages.ts +0 -38
- package/src/component/_generated/api.d.ts +0 -2202
- package/src/component/_generated/api.js +0 -23
- package/src/component/_generated/server.js +0 -90
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
- package/src/react/deltas.test.ts +0 -315
- package/src/react/deltas.ts +0 -478
- package/src/react/toUIMessages.test.ts +0 -420
- package/src/react/toUIMessages.ts +0 -253
- package/src/vitest.config.ts +0 -7
- /package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +0 -0
package/dist/client/index.d.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import type { JSONValue } from "@ai-sdk/provider";
|
|
2
|
+
import type { FlexibleSchema, IdGenerator, InferSchema } from "@ai-sdk/provider-utils";
|
|
3
|
+
import type { CallSettings, GenerateObjectResult, GenerateTextResult, LanguageModel, ModelMessage, StepResult, StopCondition, StreamTextResult, ToolSet } from "ai";
|
|
4
|
+
import { streamObject } from "ai";
|
|
5
|
+
import { type GenericDataModel, type PaginationOptions, type PaginationResult } from "convex/server";
|
|
5
6
|
import type { threadFieldsSupportingPatch } from "../component/threads.js";
|
|
6
7
|
import { type VectorDimension } from "../component/vector/tables.js";
|
|
7
|
-
import {
|
|
8
|
-
import { type
|
|
9
|
-
import { createTool } from "./createTool.js";
|
|
10
|
-
import { listMessages } from "./listMessages.js";
|
|
8
|
+
import { type Message, type MessageDoc, type MessageStatus, type MessageWithMetadata, type ProviderMetadata, type StreamArgs, type ThreadDoc } from "../validators.js";
|
|
9
|
+
import { type SaveMessageArgs, type SaveMessagesArgs } from "./messages.js";
|
|
11
10
|
import { type StreamingOptions } from "./streaming.js";
|
|
12
|
-
import type { ActionCtx, AgentComponent,
|
|
13
|
-
import type z from "zod";
|
|
11
|
+
import type { ActionCtx, AgentComponent, Config, ContextOptions, GenerateObjectArgs, GenerationOutputMetadata, MaybeCustomCtx, ObjectMode, Options, RawRequestResponseHandler, MutationCtx, StorageOptions, StreamingTextArgs, StreamObjectArgs, SyncStreamsReturnValue, TextArgs, Thread, UsageHandler, QueryCtx, AgentPrompt, Output } from "./types.js";
|
|
14
12
|
export { stepCountIs } from "ai";
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export { vAssistantMessage, vContextOptions, vMessage, vPaginationResult, vProviderMetadata, vStorageOptions, vStreamArgs, vSystemMessage, vToolMessage, vUsage, vUserMessage, } from "../validators.js";
|
|
18
|
-
export type
|
|
13
|
+
export { docsToModelMessages, toModelMessage, toModelMessage as deserializeMessage, guessMimeType, serializeDataOrUrl, serializeMessage, toUIFilePart, } from "../mapping.js";
|
|
14
|
+
export { extractText, isTool, sorted } from "../shared.js";
|
|
15
|
+
export { vAssistantMessage, vContent, vContextOptions, vMessage, vMessageDoc, vPaginationResult, vProviderMetadata, vSource, vStorageOptions, vStreamArgs, vSystemMessage, vThreadDoc, vToolMessage, vUsage, vUserMessage, type Message, type MessageDoc, type SourcePart, type ThreadDoc, type Usage, } from "../validators.js";
|
|
16
|
+
export { createTool, type ToolCtx } from "./createTool.js";
|
|
17
|
+
export { definePlaygroundAPI, type AgentsFn, type PlaygroundAPI, } from "./definePlaygroundAPI.js";
|
|
19
18
|
export { getFile, storeFile } from "./files.js";
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export
|
|
19
|
+
export { listMessages, listUIMessages, saveMessage, saveMessages, type SaveMessageArgs, type SaveMessagesArgs, } from "./messages.js";
|
|
20
|
+
export { mockModel } from "./mockModel.js";
|
|
21
|
+
export { fetchContextMessages, filterOutOrphanedToolMessages, fetchContextWithPrompt, generateAndSaveEmbeddings, embedMessages, embedMany, } from "./search.js";
|
|
22
|
+
export { startGeneration } from "./start.js";
|
|
23
|
+
export { DEFAULT_STREAMING_OPTIONS, DeltaStreamer, abortStream, compressUIMessageChunks, listStreams, syncStreams, vStreamMessagesReturnValue, } from "./streaming.js";
|
|
24
|
+
export { createThread, getThreadMetadata, searchThreadTitles, updateThreadMetadata, } from "./threads.js";
|
|
25
|
+
export type { ContextHandler } from "./types.js";
|
|
26
|
+
export { toUIMessages, fromUIMessages, type UIMessage } from "../UIMessages.js";
|
|
27
|
+
export type { AgentComponent, Config, ContextOptions, ProviderMetadata, RawRequestResponseHandler, StorageOptions, StreamArgs, SyncStreamsReturnValue, Thread, UsageHandler, };
|
|
25
28
|
export declare class Agent<
|
|
26
29
|
/**
|
|
27
30
|
* You can require that all `ctx` args to generateText & streamText
|
|
@@ -44,31 +47,20 @@ export declare class Agent<
|
|
|
44
47
|
*/
|
|
45
48
|
CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
46
49
|
component: AgentComponent;
|
|
47
|
-
options: {
|
|
50
|
+
options: Config & {
|
|
48
51
|
/**
|
|
49
52
|
* The name for the agent. This will be attributed on each message
|
|
50
53
|
* created by this agent.
|
|
51
54
|
*/
|
|
52
|
-
name
|
|
55
|
+
name: string;
|
|
53
56
|
/**
|
|
54
57
|
* The LLM model to use for generating / streaming text and objects.
|
|
55
58
|
* e.g.
|
|
56
59
|
* import { openai } from "@ai-sdk/openai"
|
|
57
60
|
* const myAgent = new Agent(components.agent, {
|
|
58
|
-
*
|
|
61
|
+
* languageModel: openai.chat("gpt-4o-mini"),
|
|
59
62
|
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The model to use for text embeddings. Optional.
|
|
63
|
-
* If specified, it will use this for generating vector embeddings
|
|
64
|
-
* of chats, and can opt-in to doing vector search for automatic context
|
|
65
|
-
* on generateText, etc.
|
|
66
|
-
* e.g.
|
|
67
|
-
* import { openai } from "@ai-sdk/openai"
|
|
68
|
-
* const myAgent = new Agent(components.agent, {
|
|
69
|
-
* textEmbedding: openai.embedding("text-embedding-3-small")
|
|
70
|
-
*/
|
|
71
|
-
textEmbedding?: EmbeddingModelV2<string>;
|
|
63
|
+
languageModel: LanguageModel;
|
|
72
64
|
/**
|
|
73
65
|
* The default system prompt to put in each request.
|
|
74
66
|
* Override per-prompt by passing the "system" parameter.
|
|
@@ -81,62 +73,26 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
81
73
|
* (import { createTool } from "@convex-dev/agent")
|
|
82
74
|
*/
|
|
83
75
|
tools?: AgentTools;
|
|
84
|
-
/**
|
|
85
|
-
* Options to determine what messages are included as context in message
|
|
86
|
-
* generation. To disable any messages automatically being added, pass:
|
|
87
|
-
* { recentMessages: 0 }
|
|
88
|
-
*/
|
|
89
|
-
contextOptions?: ContextOptions;
|
|
90
|
-
/**
|
|
91
|
-
* Determines whether messages are automatically stored when passed as
|
|
92
|
-
* arguments or generated.
|
|
93
|
-
*/
|
|
94
|
-
storageOptions?: StorageOptions;
|
|
95
76
|
/**
|
|
96
77
|
* When generating or streaming text with tools available, this
|
|
97
|
-
* determines when to stop. Defaults to
|
|
98
|
-
*/
|
|
99
|
-
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
100
|
-
/**
|
|
101
|
-
* The maximum number of calls to make to an LLM in case it fails.
|
|
102
|
-
* This can be overridden at each generate/stream callsite.
|
|
103
|
-
*/
|
|
104
|
-
maxRetries?: number;
|
|
105
|
-
/**
|
|
106
|
-
* The usage handler to use for this agent.
|
|
107
|
-
*/
|
|
108
|
-
usageHandler?: UsageHandler;
|
|
109
|
-
/**
|
|
110
|
-
* Called for each LLM request/response, so you can do things like
|
|
111
|
-
* log the raw request body or response headers to a table, or logs.
|
|
78
|
+
* determines when to stop. Defaults to the AI SDK default.
|
|
112
79
|
*/
|
|
113
|
-
|
|
80
|
+
stopWhen?: StopCondition<NoInfer<AgentTools>> | Array<StopCondition<NoInfer<AgentTools>>>;
|
|
114
81
|
};
|
|
115
|
-
constructor(component: AgentComponent, options: {
|
|
82
|
+
constructor(component: AgentComponent, options: Config & {
|
|
116
83
|
/**
|
|
117
84
|
* The name for the agent. This will be attributed on each message
|
|
118
85
|
* created by this agent.
|
|
119
86
|
*/
|
|
120
|
-
name
|
|
87
|
+
name: string;
|
|
121
88
|
/**
|
|
122
89
|
* The LLM model to use for generating / streaming text and objects.
|
|
123
90
|
* e.g.
|
|
124
91
|
* import { openai } from "@ai-sdk/openai"
|
|
125
92
|
* const myAgent = new Agent(components.agent, {
|
|
126
|
-
*
|
|
93
|
+
* languageModel: openai.chat("gpt-4o-mini"),
|
|
127
94
|
*/
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* The model to use for text embeddings. Optional.
|
|
131
|
-
* If specified, it will use this for generating vector embeddings
|
|
132
|
-
* of chats, and can opt-in to doing vector search for automatic context
|
|
133
|
-
* on generateText, etc.
|
|
134
|
-
* e.g.
|
|
135
|
-
* import { openai } from "@ai-sdk/openai"
|
|
136
|
-
* const myAgent = new Agent(components.agent, {
|
|
137
|
-
* textEmbedding: openai.embedding("text-embedding-3-small")
|
|
138
|
-
*/
|
|
139
|
-
textEmbedding?: EmbeddingModelV2<string>;
|
|
95
|
+
languageModel: LanguageModel;
|
|
140
96
|
/**
|
|
141
97
|
* The default system prompt to put in each request.
|
|
142
98
|
* Override per-prompt by passing the "system" parameter.
|
|
@@ -149,37 +105,17 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
149
105
|
* (import { createTool } from "@convex-dev/agent")
|
|
150
106
|
*/
|
|
151
107
|
tools?: AgentTools;
|
|
152
|
-
/**
|
|
153
|
-
* Options to determine what messages are included as context in message
|
|
154
|
-
* generation. To disable any messages automatically being added, pass:
|
|
155
|
-
* { recentMessages: 0 }
|
|
156
|
-
*/
|
|
157
|
-
contextOptions?: ContextOptions;
|
|
158
|
-
/**
|
|
159
|
-
* Determines whether messages are automatically stored when passed as
|
|
160
|
-
* arguments or generated.
|
|
161
|
-
*/
|
|
162
|
-
storageOptions?: StorageOptions;
|
|
163
108
|
/**
|
|
164
109
|
* When generating or streaming text with tools available, this
|
|
165
|
-
* determines when to stop. Defaults to
|
|
166
|
-
*/
|
|
167
|
-
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
168
|
-
/**
|
|
169
|
-
* The maximum number of calls to make to an LLM in case it fails.
|
|
170
|
-
* This can be overridden at each generate/stream callsite.
|
|
171
|
-
*/
|
|
172
|
-
maxRetries?: number;
|
|
173
|
-
/**
|
|
174
|
-
* The usage handler to use for this agent.
|
|
175
|
-
*/
|
|
176
|
-
usageHandler?: UsageHandler;
|
|
177
|
-
/**
|
|
178
|
-
* Called for each LLM request/response, so you can do things like
|
|
179
|
-
* log the raw request body or response headers to a table, or logs.
|
|
110
|
+
* determines when to stop. Defaults to the AI SDK default.
|
|
180
111
|
*/
|
|
181
|
-
|
|
112
|
+
stopWhen?: StopCondition<NoInfer<AgentTools>> | Array<StopCondition<NoInfer<AgentTools>>>;
|
|
182
113
|
});
|
|
114
|
+
/**
|
|
115
|
+
* Get the embedding model, prioritizing embeddingModel over textEmbeddingModel.
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
private getEmbeddingModel;
|
|
183
119
|
/**
|
|
184
120
|
* Start a new thread with the agent. This will have a fresh history, though if
|
|
185
121
|
* you pass in a userId you can have it search across other threads for relevant
|
|
@@ -190,7 +126,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
190
126
|
* @param args The thread metadata.
|
|
191
127
|
* @returns The threadId of the new thread and the thread object.
|
|
192
128
|
*/
|
|
193
|
-
createThread
|
|
129
|
+
createThread(ctx: ActionCtx & CustomCtx, args?: {
|
|
194
130
|
/**
|
|
195
131
|
* The userId to associate with the thread. If not provided, the thread will be
|
|
196
132
|
* anonymous.
|
|
@@ -204,19 +140,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
204
140
|
* The summary of the thread. Not currently used for anything.
|
|
205
141
|
*/
|
|
206
142
|
summary?: string;
|
|
207
|
-
/**
|
|
208
|
-
* The usage handler to use for this thread. Overrides any handler
|
|
209
|
-
* set in the agent constructor.
|
|
210
|
-
*/
|
|
211
|
-
usageHandler?: UsageHandler;
|
|
212
|
-
/**
|
|
213
|
-
* The tools to use for this thread.
|
|
214
|
-
* Overrides any tools passed in the agent constructor.
|
|
215
|
-
*/
|
|
216
|
-
tools?: ThreadTools;
|
|
217
143
|
}): Promise<{
|
|
218
144
|
threadId: string;
|
|
219
|
-
thread: Thread<
|
|
145
|
+
thread: Thread<AgentTools>;
|
|
220
146
|
}>;
|
|
221
147
|
/**
|
|
222
148
|
* Start a new thread with the agent. This will have a fresh history, though if
|
|
@@ -227,7 +153,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
227
153
|
* @param args The thread metadata.
|
|
228
154
|
* @returns The threadId of the new thread.
|
|
229
155
|
*/
|
|
230
|
-
createThread
|
|
156
|
+
createThread(ctx: MutationCtx, args?: {
|
|
231
157
|
/**
|
|
232
158
|
* The userId to associate with the thread. If not provided, the thread will be
|
|
233
159
|
* anonymous.
|
|
@@ -241,16 +167,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
241
167
|
* The summary of the thread. Not currently used for anything.
|
|
242
168
|
*/
|
|
243
169
|
summary?: string;
|
|
244
|
-
/**
|
|
245
|
-
* The usage handler to use for this thread. Overrides any handler
|
|
246
|
-
* set in the agent constructor.
|
|
247
|
-
*/
|
|
248
|
-
usageHandler?: UsageHandler;
|
|
249
|
-
/**
|
|
250
|
-
* The tools to use for this thread.
|
|
251
|
-
* Overrides any tools passed in the agent constructor.
|
|
252
|
-
*/
|
|
253
|
-
tools?: ThreadTools;
|
|
254
170
|
}): Promise<{
|
|
255
171
|
threadId: string;
|
|
256
172
|
}>;
|
|
@@ -262,7 +178,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
262
178
|
* @param { threadId, userId }: the thread and user to associate the messages with.
|
|
263
179
|
* @returns Functions bound to the userId and threadId on a `{thread}` object.
|
|
264
180
|
*/
|
|
265
|
-
continueThread
|
|
181
|
+
continueThread(ctx: ActionCtx & CustomCtx, args: {
|
|
266
182
|
/**
|
|
267
183
|
* The associated thread created by {@link createThread}
|
|
268
184
|
*/
|
|
@@ -272,29 +188,58 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
272
188
|
* relevant messages from the same user as context for the LLM calls.
|
|
273
189
|
*/
|
|
274
190
|
userId?: string | null;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
thread: Thread<AgentTools>;
|
|
193
|
+
}>;
|
|
194
|
+
start<TOOLS extends ToolSet | undefined, T extends {
|
|
195
|
+
_internal?: {
|
|
196
|
+
generateId?: IdGenerator;
|
|
197
|
+
};
|
|
198
|
+
}>(ctx: ActionCtx & CustomCtx,
|
|
199
|
+
/**
|
|
200
|
+
* These are the arguments you'll pass to the LLM call such as
|
|
201
|
+
* `generateText` or `streamText`. This function will look up the context
|
|
202
|
+
* and provide functions to save the steps, abort the generation, and more.
|
|
203
|
+
* The type of the arguments returned infers from the type of the arguments
|
|
204
|
+
* you pass here.
|
|
205
|
+
*/
|
|
206
|
+
args: T & AgentPrompt & {
|
|
275
207
|
/**
|
|
276
|
-
* The
|
|
277
|
-
*
|
|
208
|
+
* The tools to use for the tool calls. This will override tools specified
|
|
209
|
+
* in the Agent constructor or createThread / continueThread.
|
|
278
210
|
*/
|
|
279
|
-
|
|
211
|
+
tools?: TOOLS;
|
|
280
212
|
/**
|
|
281
|
-
* The
|
|
282
|
-
*
|
|
213
|
+
* The abort signal to be passed to the LLM call. If triggered, it will
|
|
214
|
+
* mark the pending message as failed. If the generation is asynchronously
|
|
215
|
+
* aborted, it will trigger this signal when detected.
|
|
283
216
|
*/
|
|
284
|
-
|
|
217
|
+
abortSignal?: AbortSignal;
|
|
218
|
+
stopWhen?: StopCondition<TOOLS extends undefined ? AgentTools : TOOLS> | Array<StopCondition<TOOLS extends undefined ? AgentTools : TOOLS>>;
|
|
219
|
+
}, options?: Options & {
|
|
220
|
+
userId?: string | null;
|
|
221
|
+
threadId?: string;
|
|
285
222
|
}): Promise<{
|
|
286
|
-
|
|
223
|
+
args: T & {
|
|
224
|
+
system?: string;
|
|
225
|
+
model: LanguageModel;
|
|
226
|
+
prompt?: never;
|
|
227
|
+
messages: ModelMessage[];
|
|
228
|
+
tools?: TOOLS extends undefined ? AgentTools : TOOLS;
|
|
229
|
+
} & CallSettings;
|
|
230
|
+
order: number;
|
|
231
|
+
stepOrder: number;
|
|
232
|
+
userId: string | undefined;
|
|
233
|
+
promptMessageId: string | undefined;
|
|
234
|
+
updateModel: (model: LanguageModel | undefined) => void;
|
|
235
|
+
save: <TOOLS extends ToolSet>(toSave: {
|
|
236
|
+
step: StepResult<TOOLS>;
|
|
237
|
+
} | {
|
|
238
|
+
object: GenerateObjectResult<unknown>;
|
|
239
|
+
}, createPendingMessage?: boolean) => Promise<void>;
|
|
240
|
+
fail: (reason: string) => Promise<void>;
|
|
241
|
+
getSavedMessages: () => MessageDoc[];
|
|
287
242
|
}>;
|
|
288
|
-
/**
|
|
289
|
-
* Search for threads by title, paginated.
|
|
290
|
-
* @param ctx The context passed from the query/mutation/action.
|
|
291
|
-
* @returns The threads matching the search, paginated.
|
|
292
|
-
*/
|
|
293
|
-
searchThreadTitles(ctx: RunQueryCtx, { userId, query, limit, }: {
|
|
294
|
-
userId?: string | undefined;
|
|
295
|
-
query: string;
|
|
296
|
-
limit?: number;
|
|
297
|
-
}): Promise<ThreadDoc[]>;
|
|
298
243
|
/**
|
|
299
244
|
* This behaves like {@link generateText} from the "ai" package except that
|
|
300
245
|
* it add context based on the userId and threadId and saves the input and
|
|
@@ -302,22 +247,21 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
302
247
|
* Use {@link continueThread} to get a version of this function already scoped
|
|
303
248
|
* to a thread (and optionally userId).
|
|
304
249
|
* @param ctx The context passed from the action function calling this.
|
|
305
|
-
* @param
|
|
306
|
-
* @param
|
|
307
|
-
*
|
|
250
|
+
* @param scope: The user and thread to associate the message with
|
|
251
|
+
* @param generateTextArgs The arguments to the generateText function, along
|
|
252
|
+
* with {@link AgentPrompt} options, such as promptMessageId.
|
|
253
|
+
* @param options Extra controls for the {@link ContextOptions} and {@link StorageOptions}.
|
|
308
254
|
* @returns The result of the generateText function.
|
|
309
255
|
*/
|
|
310
|
-
generateText<TOOLS extends ToolSet | undefined = undefined, OUTPUT
|
|
256
|
+
generateText<TOOLS extends ToolSet | undefined = undefined, OUTPUT extends Output<any, any, any> = never>(ctx: ActionCtx & CustomCtx, threadOpts: {
|
|
311
257
|
userId?: string | null;
|
|
312
258
|
threadId?: string;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
tools?: ToolSet;
|
|
320
|
-
}, args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>, options?: Options): Promise<GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* The arguments to the generateText function, similar to the ai sdk's
|
|
262
|
+
* {@link generateText} function, along with Agent prompt options.
|
|
263
|
+
*/
|
|
264
|
+
generateTextArgs: AgentPrompt & TextArgs<AgentTools, TOOLS, OUTPUT>, options?: Options): Promise<GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
|
|
321
265
|
/**
|
|
322
266
|
* This behaves like {@link streamText} from the "ai" package except that
|
|
323
267
|
* it add context based on the userId and threadId and saves the input and
|
|
@@ -325,18 +269,15 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
325
269
|
* Use {@link continueThread} to get a version of this function already scoped
|
|
326
270
|
* to a thread (and optionally userId).
|
|
327
271
|
*/
|
|
328
|
-
streamText<TOOLS extends ToolSet | undefined = undefined, OUTPUT
|
|
329
|
-
/** Note: to get better type inference, pass tools in the next arg */
|
|
330
|
-
tools: threadTools, }: {
|
|
272
|
+
streamText<TOOLS extends ToolSet | undefined = undefined, OUTPUT extends Output<any, any, any> = never>(ctx: ActionCtx & CustomCtx, threadOpts: {
|
|
331
273
|
userId?: string | null;
|
|
332
274
|
threadId?: string;
|
|
333
|
-
usageHandler?: UsageHandler;
|
|
334
|
-
tools?: ToolSet;
|
|
335
275
|
},
|
|
336
276
|
/**
|
|
337
|
-
* The arguments to the streamText function, similar to the ai
|
|
277
|
+
* The arguments to the streamText function, similar to the ai sdk's
|
|
278
|
+
* {@link streamText} function, along with Agent prompt options.
|
|
338
279
|
*/
|
|
339
|
-
|
|
280
|
+
streamTextArgs: AgentPrompt & StreamingTextArgs<AgentTools, TOOLS, OUTPUT>,
|
|
340
281
|
/**
|
|
341
282
|
* The {@link ContextOptions} and {@link StorageOptions}
|
|
342
283
|
* options to use for fetching contextual messages and saving input/output messages.
|
|
@@ -353,7 +294,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
353
294
|
* iterating over the text, streaming it over HTTP, etc.
|
|
354
295
|
*/
|
|
355
296
|
saveStreamDeltas?: boolean | StreamingOptions;
|
|
356
|
-
}): Promise<StreamTextResult<TOOLS extends undefined ? AgentTools : TOOLS,
|
|
297
|
+
}): Promise<StreamTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
|
|
357
298
|
/**
|
|
358
299
|
* This behaves like {@link generateObject} from the "ai" package except that
|
|
359
300
|
* it add context based on the userId and threadId and saves the input and
|
|
@@ -361,20 +302,20 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
361
302
|
* Use {@link continueThread} to get a version of this function already scoped
|
|
362
303
|
* to a thread (and optionally userId).
|
|
363
304
|
*/
|
|
364
|
-
generateObject<
|
|
305
|
+
generateObject<SCHEMA extends FlexibleSchema<unknown> = FlexibleSchema<JSONValue>, OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string ? "enum" : "object", RESULT = OUTPUT extends "array" ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(ctx: ActionCtx & CustomCtx, threadOpts: {
|
|
365
306
|
userId?: string | null;
|
|
366
307
|
threadId?: string;
|
|
367
|
-
usageHandler?: UsageHandler;
|
|
368
308
|
},
|
|
369
309
|
/**
|
|
370
|
-
* The arguments to the generateObject function, similar to the ai
|
|
310
|
+
* The arguments to the generateObject function, similar to the ai sdk's
|
|
311
|
+
* {@link generateObject} function, along with Agent prompt options.
|
|
371
312
|
*/
|
|
372
|
-
|
|
313
|
+
generateObjectArgs: AgentPrompt & GenerateObjectArgs<SCHEMA, OUTPUT, RESULT>,
|
|
373
314
|
/**
|
|
374
315
|
* The {@link ContextOptions} and {@link StorageOptions}
|
|
375
316
|
* options to use for fetching contextual messages and saving input/output messages.
|
|
376
317
|
*/
|
|
377
|
-
options?: Options): Promise<GenerateObjectResult<
|
|
318
|
+
options?: Options): Promise<GenerateObjectResult<RESULT> & GenerationOutputMetadata>;
|
|
378
319
|
/**
|
|
379
320
|
* This behaves like `streamObject` from the "ai" package except that
|
|
380
321
|
* it add context based on the userId and threadId and saves the input and
|
|
@@ -382,20 +323,20 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
382
323
|
* Use {@link continueThread} to get a version of this function already scoped
|
|
383
324
|
* to a thread (and optionally userId).
|
|
384
325
|
*/
|
|
385
|
-
streamObject<
|
|
326
|
+
streamObject<SCHEMA extends FlexibleSchema<unknown> = FlexibleSchema<JSONValue>, OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string ? "enum" : "object", RESULT = OUTPUT extends "array" ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(ctx: ActionCtx & CustomCtx, threadOpts: {
|
|
386
327
|
userId?: string | null;
|
|
387
328
|
threadId?: string;
|
|
388
|
-
usageHandler?: UsageHandler;
|
|
389
329
|
},
|
|
390
330
|
/**
|
|
391
|
-
* The arguments to the streamObject function, similar to the ai
|
|
331
|
+
* The arguments to the streamObject function, similar to the ai sdk's
|
|
332
|
+
* {@link streamObject} function, along with Agent prompt options.
|
|
392
333
|
*/
|
|
393
|
-
|
|
334
|
+
streamObjectArgs: AgentPrompt & StreamObjectArgs<SCHEMA, OUTPUT, RESULT>,
|
|
394
335
|
/**
|
|
395
336
|
* The {@link ContextOptions} and {@link StorageOptions}
|
|
396
337
|
* options to use for fetching contextual messages and saving input/output messages.
|
|
397
338
|
*/
|
|
398
|
-
options?: Options): Promise<
|
|
339
|
+
options?: Options): Promise<ReturnType<typeof streamObject<SCHEMA, OUTPUT, RESULT>> & GenerationOutputMetadata>;
|
|
399
340
|
/**
|
|
400
341
|
* Save a message to the thread.
|
|
401
342
|
* @param ctx A ctx object from a mutation or action.
|
|
@@ -403,7 +344,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
403
344
|
* You can pass extra metadata alongside the message, e.g. associated fileIds.
|
|
404
345
|
* @returns The messageId of the saved message.
|
|
405
346
|
*/
|
|
406
|
-
saveMessage(ctx:
|
|
347
|
+
saveMessage(ctx: MutationCtx | ActionCtx, args: SaveMessageArgs & {
|
|
407
348
|
/**
|
|
408
349
|
* If true, it will not generate embeddings for the message.
|
|
409
350
|
* Useful if you're saving messages in a mutation where you can't run `fetch`.
|
|
@@ -428,18 +369,22 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
428
369
|
role: "user";
|
|
429
370
|
content: string | ({
|
|
430
371
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
372
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
431
373
|
type: "text";
|
|
432
374
|
text: string;
|
|
433
375
|
} | {
|
|
434
376
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
377
|
+
mediaType?: string | undefined;
|
|
435
378
|
mimeType?: string | undefined;
|
|
436
379
|
type: "image";
|
|
437
380
|
image: string | ArrayBuffer;
|
|
438
381
|
} | {
|
|
439
382
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
383
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
384
|
+
mediaType?: string | undefined;
|
|
385
|
+
mimeType?: string | undefined;
|
|
440
386
|
filename?: string | undefined;
|
|
441
387
|
type: "file";
|
|
442
|
-
mimeType: string;
|
|
443
388
|
data: string | ArrayBuffer;
|
|
444
389
|
})[];
|
|
445
390
|
} | {
|
|
@@ -447,39 +392,221 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
447
392
|
role: "assistant";
|
|
448
393
|
content: string | ({
|
|
449
394
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
395
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
450
396
|
type: "text";
|
|
451
397
|
text: string;
|
|
452
398
|
} | {
|
|
453
399
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
400
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
401
|
+
mediaType?: string | undefined;
|
|
402
|
+
mimeType?: string | undefined;
|
|
454
403
|
filename?: string | undefined;
|
|
455
404
|
type: "file";
|
|
456
|
-
mimeType: string;
|
|
457
405
|
data: string | ArrayBuffer;
|
|
458
406
|
} | {
|
|
459
407
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
408
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
460
409
|
signature?: string | undefined;
|
|
461
|
-
state?: "streaming" | "done" | undefined;
|
|
462
410
|
type: "reasoning";
|
|
463
411
|
text: string;
|
|
464
412
|
} | {
|
|
465
413
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
414
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
466
415
|
type: "redacted-reasoning";
|
|
467
416
|
data: string;
|
|
468
417
|
} | {
|
|
469
418
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
419
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
420
|
+
args?: any;
|
|
421
|
+
providerExecuted?: boolean | undefined;
|
|
422
|
+
type: "tool-call";
|
|
423
|
+
toolCallId: string;
|
|
424
|
+
toolName: string;
|
|
425
|
+
input: any;
|
|
426
|
+
} | {
|
|
427
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
428
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
429
|
+
input?: any;
|
|
470
430
|
providerExecuted?: boolean | undefined;
|
|
471
431
|
type: "tool-call";
|
|
472
432
|
toolCallId: string;
|
|
473
433
|
toolName: string;
|
|
474
434
|
args: any;
|
|
435
|
+
} | {
|
|
436
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
437
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
438
|
+
args?: any;
|
|
439
|
+
providerExecuted?: boolean | undefined;
|
|
440
|
+
output?: {
|
|
441
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
442
|
+
type: "text";
|
|
443
|
+
value: string;
|
|
444
|
+
} | {
|
|
445
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
446
|
+
type: "json";
|
|
447
|
+
value: any;
|
|
448
|
+
} | {
|
|
449
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
450
|
+
type: "error-text";
|
|
451
|
+
value: string;
|
|
452
|
+
} | {
|
|
453
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
454
|
+
type: "error-json";
|
|
455
|
+
value: any;
|
|
456
|
+
} | {
|
|
457
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
458
|
+
reason?: string | undefined;
|
|
459
|
+
type: "execution-denied";
|
|
460
|
+
} | {
|
|
461
|
+
type: "content";
|
|
462
|
+
value: ({
|
|
463
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
464
|
+
type: "text";
|
|
465
|
+
text: string;
|
|
466
|
+
} | {
|
|
467
|
+
type: "media";
|
|
468
|
+
mediaType: string;
|
|
469
|
+
data: string;
|
|
470
|
+
} | {
|
|
471
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
472
|
+
filename?: string | undefined;
|
|
473
|
+
type: "file-data";
|
|
474
|
+
mediaType: string;
|
|
475
|
+
data: string;
|
|
476
|
+
} | {
|
|
477
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
478
|
+
type: "file-url";
|
|
479
|
+
url: string;
|
|
480
|
+
} | {
|
|
481
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
482
|
+
type: "file-id";
|
|
483
|
+
fileId: string | Record<string, string>;
|
|
484
|
+
} | {
|
|
485
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
486
|
+
type: "image-data";
|
|
487
|
+
mediaType: string;
|
|
488
|
+
data: string;
|
|
489
|
+
} | {
|
|
490
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
491
|
+
type: "image-url";
|
|
492
|
+
url: string;
|
|
493
|
+
} | {
|
|
494
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
495
|
+
type: "image-file-id";
|
|
496
|
+
fileId: string | Record<string, string>;
|
|
497
|
+
} | {
|
|
498
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
499
|
+
type: "custom";
|
|
500
|
+
})[];
|
|
501
|
+
} | undefined;
|
|
502
|
+
result?: any;
|
|
503
|
+
isError?: boolean | undefined;
|
|
504
|
+
experimental_content?: ({
|
|
505
|
+
type: "text";
|
|
506
|
+
text: string;
|
|
507
|
+
} | {
|
|
508
|
+
mimeType?: string | undefined;
|
|
509
|
+
type: "image";
|
|
510
|
+
data: string;
|
|
511
|
+
})[] | undefined;
|
|
512
|
+
type: "tool-result";
|
|
513
|
+
toolCallId: string;
|
|
514
|
+
toolName: string;
|
|
515
|
+
} | {
|
|
516
|
+
title?: string | undefined;
|
|
517
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
518
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
519
|
+
id: string;
|
|
520
|
+
type: "source";
|
|
521
|
+
url: string;
|
|
522
|
+
sourceType: "url";
|
|
523
|
+
} | {
|
|
524
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
525
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
526
|
+
filename?: string | undefined;
|
|
527
|
+
id: string;
|
|
528
|
+
title: string;
|
|
529
|
+
type: "source";
|
|
530
|
+
mediaType: string;
|
|
531
|
+
sourceType: "document";
|
|
532
|
+
} | {
|
|
533
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
534
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
535
|
+
type: "tool-approval-request";
|
|
536
|
+
toolCallId: string;
|
|
537
|
+
approvalId: string;
|
|
475
538
|
})[];
|
|
476
539
|
} | {
|
|
477
540
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
478
541
|
role: "tool";
|
|
479
|
-
content: {
|
|
542
|
+
content: ({
|
|
480
543
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
544
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
481
545
|
args?: any;
|
|
482
546
|
providerExecuted?: boolean | undefined;
|
|
547
|
+
output?: {
|
|
548
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
549
|
+
type: "text";
|
|
550
|
+
value: string;
|
|
551
|
+
} | {
|
|
552
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
553
|
+
type: "json";
|
|
554
|
+
value: any;
|
|
555
|
+
} | {
|
|
556
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
557
|
+
type: "error-text";
|
|
558
|
+
value: string;
|
|
559
|
+
} | {
|
|
560
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
561
|
+
type: "error-json";
|
|
562
|
+
value: any;
|
|
563
|
+
} | {
|
|
564
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
565
|
+
reason?: string | undefined;
|
|
566
|
+
type: "execution-denied";
|
|
567
|
+
} | {
|
|
568
|
+
type: "content";
|
|
569
|
+
value: ({
|
|
570
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
571
|
+
type: "text";
|
|
572
|
+
text: string;
|
|
573
|
+
} | {
|
|
574
|
+
type: "media";
|
|
575
|
+
mediaType: string;
|
|
576
|
+
data: string;
|
|
577
|
+
} | {
|
|
578
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
579
|
+
filename?: string | undefined;
|
|
580
|
+
type: "file-data";
|
|
581
|
+
mediaType: string;
|
|
582
|
+
data: string;
|
|
583
|
+
} | {
|
|
584
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
585
|
+
type: "file-url";
|
|
586
|
+
url: string;
|
|
587
|
+
} | {
|
|
588
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
589
|
+
type: "file-id";
|
|
590
|
+
fileId: string | Record<string, string>;
|
|
591
|
+
} | {
|
|
592
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
593
|
+
type: "image-data";
|
|
594
|
+
mediaType: string;
|
|
595
|
+
data: string;
|
|
596
|
+
} | {
|
|
597
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
598
|
+
type: "image-url";
|
|
599
|
+
url: string;
|
|
600
|
+
} | {
|
|
601
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
602
|
+
type: "image-file-id";
|
|
603
|
+
fileId: string | Record<string, string>;
|
|
604
|
+
} | {
|
|
605
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
606
|
+
type: "custom";
|
|
607
|
+
})[];
|
|
608
|
+
} | undefined;
|
|
609
|
+
result?: any;
|
|
483
610
|
isError?: boolean | undefined;
|
|
484
611
|
experimental_content?: ({
|
|
485
612
|
type: "text";
|
|
@@ -492,14 +619,22 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
492
619
|
type: "tool-result";
|
|
493
620
|
toolCallId: string;
|
|
494
621
|
toolName: string;
|
|
495
|
-
|
|
496
|
-
|
|
622
|
+
} | {
|
|
623
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
624
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
625
|
+
providerExecuted?: boolean | undefined;
|
|
626
|
+
reason?: string | undefined;
|
|
627
|
+
type: "tool-approval-response";
|
|
628
|
+
approvalId: string;
|
|
629
|
+
approved: boolean;
|
|
630
|
+
})[];
|
|
497
631
|
} | {
|
|
498
632
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
499
633
|
role: "system";
|
|
500
634
|
content: string;
|
|
501
635
|
} | undefined;
|
|
502
636
|
text?: string | undefined;
|
|
637
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
503
638
|
reasoning?: string | undefined;
|
|
504
639
|
usage?: {
|
|
505
640
|
reasoningTokens?: number | undefined;
|
|
@@ -508,27 +643,41 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
508
643
|
completionTokens: number;
|
|
509
644
|
totalTokens: number;
|
|
510
645
|
} | undefined;
|
|
511
|
-
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
512
646
|
sources?: ({
|
|
513
647
|
title?: string | undefined;
|
|
514
648
|
type?: "source" | undefined;
|
|
515
649
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
516
|
-
|
|
650
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
517
651
|
id: string;
|
|
652
|
+
url: string;
|
|
518
653
|
sourceType: "url";
|
|
519
654
|
} | {
|
|
520
|
-
|
|
655
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
521
656
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
657
|
+
filename?: string | undefined;
|
|
522
658
|
id: string;
|
|
523
659
|
title: string;
|
|
524
660
|
type: "source";
|
|
525
|
-
sourceType: "document";
|
|
526
661
|
mediaType: string;
|
|
662
|
+
sourceType: "document";
|
|
663
|
+
})[] | undefined;
|
|
664
|
+
warnings?: ({
|
|
665
|
+
details?: string | undefined;
|
|
666
|
+
type: "unsupported-setting";
|
|
667
|
+
setting: string;
|
|
668
|
+
} | {
|
|
669
|
+
details?: string | undefined;
|
|
670
|
+
type: "unsupported-tool";
|
|
671
|
+
tool: any;
|
|
672
|
+
} | {
|
|
673
|
+
type: "other";
|
|
674
|
+
message: string;
|
|
527
675
|
})[] | undefined;
|
|
676
|
+
finishReason?: "error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
528
677
|
reasoningDetails?: ({
|
|
529
678
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
679
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
530
680
|
signature?: string | undefined;
|
|
531
|
-
state?: "streaming" | "done" | undefined;
|
|
532
681
|
type: "reasoning";
|
|
533
682
|
text: string;
|
|
534
683
|
} | {
|
|
@@ -539,26 +688,13 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
539
688
|
type: "redacted";
|
|
540
689
|
data: string;
|
|
541
690
|
})[] | undefined;
|
|
542
|
-
warnings?: ({
|
|
543
|
-
details?: string | undefined;
|
|
544
|
-
type: "unsupported-setting";
|
|
545
|
-
setting: string;
|
|
546
|
-
} | {
|
|
547
|
-
details?: string | undefined;
|
|
548
|
-
type: "unsupported-tool";
|
|
549
|
-
tool: any;
|
|
550
|
-
} | {
|
|
551
|
-
type: "other";
|
|
552
|
-
message: string;
|
|
553
|
-
})[] | undefined;
|
|
554
|
-
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
555
|
-
_id: string;
|
|
556
|
-
_creationTime: number;
|
|
557
691
|
status: "pending" | "success" | "failed";
|
|
558
692
|
order: number;
|
|
693
|
+
_creationTime: number;
|
|
559
694
|
threadId: string;
|
|
560
695
|
stepOrder: number;
|
|
561
696
|
tool: boolean;
|
|
697
|
+
_id: string;
|
|
562
698
|
};
|
|
563
699
|
}>;
|
|
564
700
|
/**
|
|
@@ -569,7 +705,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
569
705
|
* @param args The messages and context to save
|
|
570
706
|
* @returns
|
|
571
707
|
*/
|
|
572
|
-
saveMessages(ctx:
|
|
708
|
+
saveMessages(ctx: MutationCtx | ActionCtx, args: SaveMessagesArgs & {
|
|
573
709
|
/**
|
|
574
710
|
* Skip generating embeddings for the messages. Useful if you're
|
|
575
711
|
* saving messages in a mutation where you can't run `fetch`.
|
|
@@ -578,7 +714,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
578
714
|
*/
|
|
579
715
|
skipEmbeddings?: boolean;
|
|
580
716
|
}): Promise<{
|
|
581
|
-
lastMessageId: string;
|
|
582
717
|
messages: MessageDoc[];
|
|
583
718
|
}>;
|
|
584
719
|
/**
|
|
@@ -591,7 +726,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
591
726
|
* @param args.statuses What statuses to include. All by default.
|
|
592
727
|
* @returns The MessageDoc's in a format compatible with usePaginatedQuery.
|
|
593
728
|
*/
|
|
594
|
-
listMessages(ctx:
|
|
729
|
+
listMessages(ctx: QueryCtx | MutationCtx | ActionCtx, args: {
|
|
595
730
|
threadId: string;
|
|
596
731
|
paginationOpts: PaginationOptions;
|
|
597
732
|
excludeToolMessages?: boolean;
|
|
@@ -605,7 +740,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
605
740
|
* @param args.streamArgs The stream arguments with per-stream cursors.
|
|
606
741
|
* @returns The deltas for each stream from their existing cursor.
|
|
607
742
|
*/
|
|
608
|
-
syncStreams(ctx:
|
|
743
|
+
syncStreams(ctx: QueryCtx | MutationCtx | ActionCtx, args: {
|
|
609
744
|
threadId: string;
|
|
610
745
|
streamArgs: StreamArgs | undefined;
|
|
611
746
|
includeStatuses?: ("streaming" | "finished" | "aborted")[];
|
|
@@ -618,14 +753,25 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
618
753
|
* @param args The associated thread, user, message
|
|
619
754
|
* @returns
|
|
620
755
|
*/
|
|
621
|
-
fetchContextMessages(ctx:
|
|
756
|
+
fetchContextMessages(ctx: QueryCtx | MutationCtx | ActionCtx, args: {
|
|
622
757
|
userId: string | undefined;
|
|
623
758
|
threadId: string | undefined;
|
|
624
|
-
messages: (ModelMessage | Message)[];
|
|
625
759
|
/**
|
|
626
|
-
* If
|
|
627
|
-
*
|
|
628
|
-
|
|
760
|
+
* If targetMessageId is not provided, this text will be used
|
|
761
|
+
* for text and vector search
|
|
762
|
+
*/
|
|
763
|
+
searchText?: string;
|
|
764
|
+
/**
|
|
765
|
+
* If provided, it will use this message for text/vector search (if enabled)
|
|
766
|
+
* and will only fetch messages up to (and including) this message's "order"
|
|
767
|
+
*/
|
|
768
|
+
targetMessageId?: string;
|
|
769
|
+
/**
|
|
770
|
+
* @deprecated use searchText and targetMessageId instead
|
|
771
|
+
*/
|
|
772
|
+
messages?: (ModelMessage | Message)[];
|
|
773
|
+
/**
|
|
774
|
+
* @deprecated use targetMessageId instead
|
|
629
775
|
*/
|
|
630
776
|
upToAndIncludingMessageId?: string;
|
|
631
777
|
contextOptions: ContextOptions | undefined;
|
|
@@ -636,7 +782,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
636
782
|
* @param args.threadId The thread to get the metadata for.
|
|
637
783
|
* @returns The metadata for the thread.
|
|
638
784
|
*/
|
|
639
|
-
getThreadMetadata(ctx:
|
|
785
|
+
getThreadMetadata(ctx: QueryCtx | MutationCtx | ActionCtx, args: {
|
|
640
786
|
threadId: string;
|
|
641
787
|
}): Promise<ThreadDoc>;
|
|
642
788
|
/**
|
|
@@ -646,7 +792,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
646
792
|
* @param args.patch The patch to apply to the thread.
|
|
647
793
|
* @returns The updated thread metadata.
|
|
648
794
|
*/
|
|
649
|
-
updateThreadMetadata(ctx:
|
|
795
|
+
updateThreadMetadata(ctx: MutationCtx | ActionCtx, args: {
|
|
650
796
|
threadId: string;
|
|
651
797
|
patch: Partial<Pick<ThreadDoc, (typeof threadFieldsSupportingPatch)[number]>>;
|
|
652
798
|
}): Promise<ThreadDoc>;
|
|
@@ -655,7 +801,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
655
801
|
* @param messages The messages to get the embeddings for.
|
|
656
802
|
* @returns The embeddings for the messages.
|
|
657
803
|
*/
|
|
658
|
-
generateEmbeddings(ctx:
|
|
804
|
+
generateEmbeddings(ctx: ActionCtx, args: {
|
|
659
805
|
userId: string | undefined;
|
|
660
806
|
threadId: string | undefined;
|
|
661
807
|
}, messages: (ModelMessage | Message)[]): Promise<{
|
|
@@ -670,10 +816,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
670
816
|
* @param ctx The ctx parameter to an action.
|
|
671
817
|
* @param args The messageIds to generate embeddings for.
|
|
672
818
|
*/
|
|
673
|
-
generateAndSaveEmbeddings(ctx:
|
|
819
|
+
generateAndSaveEmbeddings(ctx: ActionCtx, args: {
|
|
674
820
|
messageIds: string[];
|
|
675
821
|
}): Promise<void>;
|
|
676
|
-
_generateAndSaveEmbeddings(ctx: RunActionCtx, messages: MessageDoc[]): Promise<void>;
|
|
677
822
|
/**
|
|
678
823
|
* Explicitly save a "step" created by the AI SDK.
|
|
679
824
|
* @param ctx The ctx argument to a mutation or action.
|
|
@@ -702,7 +847,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
702
847
|
provider?: string;
|
|
703
848
|
}): Promise<{
|
|
704
849
|
messages: MessageDoc[];
|
|
705
|
-
pending?: MessageDoc;
|
|
706
850
|
}>;
|
|
707
851
|
/**
|
|
708
852
|
* Manually save the result of a generateObject call to the thread.
|
|
@@ -719,7 +863,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
719
863
|
provider: string | undefined;
|
|
720
864
|
result: GenerateObjectResult<unknown>;
|
|
721
865
|
metadata?: Omit<MessageWithMetadata, "message">;
|
|
722
|
-
}): Promise<
|
|
866
|
+
}): Promise<{
|
|
867
|
+
messages: MessageDoc[];
|
|
868
|
+
}>;
|
|
723
869
|
/**
|
|
724
870
|
* Commit or rollback a message that was pending.
|
|
725
871
|
* This is done automatically when saving messages by default.
|
|
@@ -728,14 +874,13 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
728
874
|
* @param args What message to save. Generally the parent message sent into
|
|
729
875
|
* the generateText call.
|
|
730
876
|
*/
|
|
731
|
-
|
|
732
|
-
threadId: string;
|
|
877
|
+
finalizeMessage(ctx: MutationCtx | ActionCtx, args: {
|
|
733
878
|
messageId: string;
|
|
734
879
|
result: {
|
|
735
|
-
|
|
880
|
+
status: "failed";
|
|
736
881
|
error: string;
|
|
737
882
|
} | {
|
|
738
|
-
|
|
883
|
+
status: "success";
|
|
739
884
|
};
|
|
740
885
|
}): Promise<void>;
|
|
741
886
|
/**
|
|
@@ -743,14 +888,12 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
743
888
|
* @param ctx The ctx argument to your mutation or action.
|
|
744
889
|
* @param args The message fields to update.
|
|
745
890
|
*/
|
|
746
|
-
updateMessage(ctx:
|
|
891
|
+
updateMessage(ctx: MutationCtx | ActionCtx, args: {
|
|
747
892
|
/** The id of the message to update. */
|
|
748
893
|
messageId: string;
|
|
749
894
|
patch: {
|
|
750
895
|
/** The message to replace the existing message. */
|
|
751
|
-
message:
|
|
752
|
-
id?: string;
|
|
753
|
-
}) | Message;
|
|
896
|
+
message: ModelMessage | Message;
|
|
754
897
|
/** The status to set on the message. */
|
|
755
898
|
status: "success" | "error";
|
|
756
899
|
/** The error message to set on the message. */
|
|
@@ -774,7 +917,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
774
917
|
* @param ctx The ctx argument to your mutation or action.
|
|
775
918
|
* @param args The ids of the messages to delete.
|
|
776
919
|
*/
|
|
777
|
-
deleteMessages(ctx:
|
|
920
|
+
deleteMessages(ctx: MutationCtx | ActionCtx, args: {
|
|
778
921
|
messageIds: string[];
|
|
779
922
|
}): Promise<void>;
|
|
780
923
|
/**
|
|
@@ -783,7 +926,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
783
926
|
* @param ctx The ctx argument to your mutation or action.
|
|
784
927
|
* @param args The id of the message to delete.
|
|
785
928
|
*/
|
|
786
|
-
deleteMessage(ctx:
|
|
929
|
+
deleteMessage(ctx: MutationCtx | ActionCtx, args: {
|
|
787
930
|
messageId: string;
|
|
788
931
|
}): Promise<void>;
|
|
789
932
|
/**
|
|
@@ -823,7 +966,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
823
966
|
* @param ctx The ctx argument to your mutation or action.
|
|
824
967
|
* @param args The range of messages to delete.
|
|
825
968
|
*/
|
|
826
|
-
deleteMessageRange(ctx:
|
|
969
|
+
deleteMessageRange(ctx: MutationCtx | ActionCtx, args: {
|
|
827
970
|
threadId: string;
|
|
828
971
|
startOrder: number;
|
|
829
972
|
startStepOrder?: number;
|
|
@@ -841,7 +984,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
841
984
|
* @param ctx The ctx argument to your mutation or action.
|
|
842
985
|
* @param args The id of the thread to delete and optionally the page size to use for the delete.
|
|
843
986
|
*/
|
|
844
|
-
deleteThreadAsync(ctx:
|
|
987
|
+
deleteThreadAsync(ctx: MutationCtx | ActionCtx, args: {
|
|
845
988
|
threadId: string;
|
|
846
989
|
pageSize?: number;
|
|
847
990
|
}): Promise<void>;
|
|
@@ -852,53 +995,10 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
852
995
|
* @param ctx The ctx argument to your action.
|
|
853
996
|
* @param args The id of the thread to delete and optionally the page size to use for the delete.
|
|
854
997
|
*/
|
|
855
|
-
deleteThreadSync(ctx:
|
|
998
|
+
deleteThreadSync(ctx: ActionCtx, args: {
|
|
856
999
|
threadId: string;
|
|
857
1000
|
pageSize?: number;
|
|
858
1001
|
}): Promise<void>;
|
|
859
|
-
_saveMessagesAndFetchContext<T extends {
|
|
860
|
-
id?: string;
|
|
861
|
-
prompt?: string | (ModelMessage | Message)[];
|
|
862
|
-
messages?: (ModelMessage | Message)[];
|
|
863
|
-
system?: string;
|
|
864
|
-
promptMessageId?: string;
|
|
865
|
-
model?: LanguageModelV2;
|
|
866
|
-
maxRetries?: number;
|
|
867
|
-
}>(ctx: RunActionCtx, args: T, { userId: argsUserId, threadId, contextOptions, storageOptions, }: {
|
|
868
|
-
userId: string | undefined;
|
|
869
|
-
threadId: string | undefined;
|
|
870
|
-
} & Options): Promise<{
|
|
871
|
-
args: T & {
|
|
872
|
-
model: LanguageModelV2;
|
|
873
|
-
};
|
|
874
|
-
userId: string | undefined;
|
|
875
|
-
messageId: string | undefined;
|
|
876
|
-
order: number | undefined;
|
|
877
|
-
stepOrder: number | undefined;
|
|
878
|
-
}>;
|
|
879
|
-
doEmbed(ctx: RunActionCtx, options: {
|
|
880
|
-
userId: string | undefined;
|
|
881
|
-
threadId: string | undefined;
|
|
882
|
-
values: string[];
|
|
883
|
-
abortSignal?: AbortSignal;
|
|
884
|
-
headers?: Record<string, string>;
|
|
885
|
-
}): Promise<{
|
|
886
|
-
embeddings: number[][];
|
|
887
|
-
}>;
|
|
888
|
-
/**
|
|
889
|
-
* Process messages to inline file and image URLs that point to localhost
|
|
890
|
-
* by converting them to base64. This solves the problem of LLMs not being
|
|
891
|
-
* able to access localhost URLs.
|
|
892
|
-
*/
|
|
893
|
-
private _inlineMessagesFiles;
|
|
894
|
-
/**
|
|
895
|
-
* Check if a URL points to localhost
|
|
896
|
-
*/
|
|
897
|
-
private _isLocalhostUrl;
|
|
898
|
-
/**
|
|
899
|
-
* Download a file from a URL
|
|
900
|
-
*/
|
|
901
|
-
private _downloadFile;
|
|
902
1002
|
/**
|
|
903
1003
|
* WORKFLOW UTILITIES
|
|
904
1004
|
*/
|
|
@@ -933,23 +1033,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
933
1033
|
* @param spec Configuration for the agent acting as an action, including
|
|
934
1034
|
* {@link ContextOptions}, {@link StorageOptions}, and {@link stopWhen}.
|
|
935
1035
|
*/
|
|
936
|
-
asTextAction<DataModel extends GenericDataModel>(spec
|
|
937
|
-
/**
|
|
938
|
-
* When to stop generating text.
|
|
939
|
-
* Defaults to the {@link Agent["options"].stopWhen} option.
|
|
940
|
-
*/
|
|
941
|
-
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
942
|
-
/**
|
|
943
|
-
* The {@link ContextOptions} to use for fetching contextual messages and
|
|
944
|
-
* saving input/output messages.
|
|
945
|
-
* Defaults to the {@link Agent.contextOptions} option.
|
|
946
|
-
*/
|
|
947
|
-
contextOptions?: ContextOptions;
|
|
948
|
-
/**
|
|
949
|
-
* The {@link StorageOptions} to use for saving input/output messages.
|
|
950
|
-
* Defaults to the {@link Agent.storageOptions} option.
|
|
951
|
-
*/
|
|
952
|
-
storageOptions?: StorageOptions;
|
|
1036
|
+
asTextAction<DataModel extends GenericDataModel>(spec: MaybeCustomCtx<CustomCtx, DataModel, AgentTools> & {
|
|
953
1037
|
/**
|
|
954
1038
|
* Whether to stream the text.
|
|
955
1039
|
* If false, it will generate the text in a single call. (default)
|
|
@@ -958,30 +1042,12 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
958
1042
|
* defaults if you pass true.
|
|
959
1043
|
*/
|
|
960
1044
|
stream?: boolean | StreamingOptions;
|
|
961
|
-
} & (CustomCtx extends Record<string, unknown> ? {
|
|
962
1045
|
/**
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
* you need to provide this function to add any extra fields.
|
|
966
|
-
* e.g.
|
|
967
|
-
* ```ts
|
|
968
|
-
* const myAgent = new Agent<{ orgId: string }>(...);
|
|
969
|
-
* const myAction = myAgent.asTextAction({
|
|
970
|
-
* customCtx: (ctx: ActionCtx, target, llmArgs) => {
|
|
971
|
-
* const orgId = await lookupOrgId(ctx, target.threadId);
|
|
972
|
-
* return { orgId };
|
|
973
|
-
* },
|
|
974
|
-
* });
|
|
975
|
-
* ```
|
|
976
|
-
* Then, in your tools, you can
|
|
1046
|
+
* When to stop generating text.
|
|
1047
|
+
* Defaults to the {@link Agent["options"].stopWhen} option.
|
|
977
1048
|
*/
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
threadId?: string | undefined;
|
|
981
|
-
}, llmArgs: TextArgs<AgentTools>) => CustomCtx;
|
|
982
|
-
} : {
|
|
983
|
-
customCtx?: never;
|
|
984
|
-
})): import("convex/server").RegisteredAction<"internal", {
|
|
1049
|
+
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
1050
|
+
} & Options, overrides?: CallSettings): import("convex/server").RegisteredAction<"internal", {
|
|
985
1051
|
userId?: string | undefined;
|
|
986
1052
|
threadId?: string | undefined;
|
|
987
1053
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
@@ -991,18 +1057,22 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
991
1057
|
role: "user";
|
|
992
1058
|
content: string | ({
|
|
993
1059
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1060
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
994
1061
|
type: "text";
|
|
995
1062
|
text: string;
|
|
996
1063
|
} | {
|
|
997
1064
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1065
|
+
mediaType?: string | undefined;
|
|
998
1066
|
mimeType?: string | undefined;
|
|
999
1067
|
type: "image";
|
|
1000
1068
|
image: string | ArrayBuffer;
|
|
1001
1069
|
} | {
|
|
1002
1070
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1071
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1072
|
+
mediaType?: string | undefined;
|
|
1073
|
+
mimeType?: string | undefined;
|
|
1003
1074
|
filename?: string | undefined;
|
|
1004
1075
|
type: "file";
|
|
1005
|
-
mimeType: string;
|
|
1006
1076
|
data: string | ArrayBuffer;
|
|
1007
1077
|
})[];
|
|
1008
1078
|
} | {
|
|
@@ -1010,39 +1080,114 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1010
1080
|
role: "assistant";
|
|
1011
1081
|
content: string | ({
|
|
1012
1082
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1083
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1013
1084
|
type: "text";
|
|
1014
1085
|
text: string;
|
|
1015
1086
|
} | {
|
|
1016
1087
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1088
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1089
|
+
mediaType?: string | undefined;
|
|
1090
|
+
mimeType?: string | undefined;
|
|
1017
1091
|
filename?: string | undefined;
|
|
1018
1092
|
type: "file";
|
|
1019
|
-
mimeType: string;
|
|
1020
1093
|
data: string | ArrayBuffer;
|
|
1021
1094
|
} | {
|
|
1022
1095
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1096
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1023
1097
|
signature?: string | undefined;
|
|
1024
|
-
state?: "streaming" | "done" | undefined;
|
|
1025
1098
|
type: "reasoning";
|
|
1026
1099
|
text: string;
|
|
1027
1100
|
} | {
|
|
1028
1101
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1102
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1029
1103
|
type: "redacted-reasoning";
|
|
1030
1104
|
data: string;
|
|
1031
1105
|
} | {
|
|
1032
1106
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1107
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1108
|
+
args?: any;
|
|
1109
|
+
providerExecuted?: boolean | undefined;
|
|
1110
|
+
type: "tool-call";
|
|
1111
|
+
toolCallId: string;
|
|
1112
|
+
toolName: string;
|
|
1113
|
+
input: any;
|
|
1114
|
+
} | {
|
|
1115
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1116
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1117
|
+
input?: any;
|
|
1033
1118
|
providerExecuted?: boolean | undefined;
|
|
1034
1119
|
type: "tool-call";
|
|
1035
1120
|
toolCallId: string;
|
|
1036
1121
|
toolName: string;
|
|
1037
1122
|
args: any;
|
|
1038
|
-
}
|
|
1039
|
-
} | {
|
|
1040
|
-
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1041
|
-
role: "tool";
|
|
1042
|
-
content: {
|
|
1123
|
+
} | {
|
|
1043
1124
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1125
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1044
1126
|
args?: any;
|
|
1045
1127
|
providerExecuted?: boolean | undefined;
|
|
1128
|
+
output?: {
|
|
1129
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1130
|
+
type: "text";
|
|
1131
|
+
value: string;
|
|
1132
|
+
} | {
|
|
1133
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1134
|
+
type: "json";
|
|
1135
|
+
value: any;
|
|
1136
|
+
} | {
|
|
1137
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1138
|
+
type: "error-text";
|
|
1139
|
+
value: string;
|
|
1140
|
+
} | {
|
|
1141
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1142
|
+
type: "error-json";
|
|
1143
|
+
value: any;
|
|
1144
|
+
} | {
|
|
1145
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1146
|
+
reason?: string | undefined;
|
|
1147
|
+
type: "execution-denied";
|
|
1148
|
+
} | {
|
|
1149
|
+
type: "content";
|
|
1150
|
+
value: ({
|
|
1151
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1152
|
+
type: "text";
|
|
1153
|
+
text: string;
|
|
1154
|
+
} | {
|
|
1155
|
+
type: "media";
|
|
1156
|
+
mediaType: string;
|
|
1157
|
+
data: string;
|
|
1158
|
+
} | {
|
|
1159
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1160
|
+
filename?: string | undefined;
|
|
1161
|
+
type: "file-data";
|
|
1162
|
+
mediaType: string;
|
|
1163
|
+
data: string;
|
|
1164
|
+
} | {
|
|
1165
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1166
|
+
type: "file-url";
|
|
1167
|
+
url: string;
|
|
1168
|
+
} | {
|
|
1169
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1170
|
+
type: "file-id";
|
|
1171
|
+
fileId: string | Record<string, string>;
|
|
1172
|
+
} | {
|
|
1173
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1174
|
+
type: "image-data";
|
|
1175
|
+
mediaType: string;
|
|
1176
|
+
data: string;
|
|
1177
|
+
} | {
|
|
1178
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1179
|
+
type: "image-url";
|
|
1180
|
+
url: string;
|
|
1181
|
+
} | {
|
|
1182
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1183
|
+
type: "image-file-id";
|
|
1184
|
+
fileId: string | Record<string, string>;
|
|
1185
|
+
} | {
|
|
1186
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1187
|
+
type: "custom";
|
|
1188
|
+
})[];
|
|
1189
|
+
} | undefined;
|
|
1190
|
+
result?: any;
|
|
1046
1191
|
isError?: boolean | undefined;
|
|
1047
1192
|
experimental_content?: ({
|
|
1048
1193
|
type: "text";
|
|
@@ -1055,30 +1200,135 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1055
1200
|
type: "tool-result";
|
|
1056
1201
|
toolCallId: string;
|
|
1057
1202
|
toolName: string;
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1203
|
+
} | {
|
|
1204
|
+
title?: string | undefined;
|
|
1205
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1206
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1207
|
+
id: string;
|
|
1208
|
+
type: "source";
|
|
1209
|
+
url: string;
|
|
1210
|
+
sourceType: "url";
|
|
1211
|
+
} | {
|
|
1212
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1213
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1214
|
+
filename?: string | undefined;
|
|
1215
|
+
id: string;
|
|
1216
|
+
title: string;
|
|
1217
|
+
type: "source";
|
|
1218
|
+
mediaType: string;
|
|
1219
|
+
sourceType: "document";
|
|
1220
|
+
} | {
|
|
1221
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1222
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1223
|
+
type: "tool-approval-request";
|
|
1224
|
+
toolCallId: string;
|
|
1225
|
+
approvalId: string;
|
|
1226
|
+
})[];
|
|
1227
|
+
} | {
|
|
1228
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1229
|
+
role: "tool";
|
|
1230
|
+
content: ({
|
|
1231
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1232
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1233
|
+
args?: any;
|
|
1234
|
+
providerExecuted?: boolean | undefined;
|
|
1235
|
+
output?: {
|
|
1236
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1237
|
+
type: "text";
|
|
1238
|
+
value: string;
|
|
1239
|
+
} | {
|
|
1240
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1241
|
+
type: "json";
|
|
1242
|
+
value: any;
|
|
1243
|
+
} | {
|
|
1244
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1245
|
+
type: "error-text";
|
|
1246
|
+
value: string;
|
|
1247
|
+
} | {
|
|
1248
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1249
|
+
type: "error-json";
|
|
1250
|
+
value: any;
|
|
1251
|
+
} | {
|
|
1252
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1253
|
+
reason?: string | undefined;
|
|
1254
|
+
type: "execution-denied";
|
|
1255
|
+
} | {
|
|
1256
|
+
type: "content";
|
|
1257
|
+
value: ({
|
|
1258
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1259
|
+
type: "text";
|
|
1260
|
+
text: string;
|
|
1261
|
+
} | {
|
|
1262
|
+
type: "media";
|
|
1263
|
+
mediaType: string;
|
|
1264
|
+
data: string;
|
|
1265
|
+
} | {
|
|
1266
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1267
|
+
filename?: string | undefined;
|
|
1268
|
+
type: "file-data";
|
|
1269
|
+
mediaType: string;
|
|
1270
|
+
data: string;
|
|
1271
|
+
} | {
|
|
1272
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1273
|
+
type: "file-url";
|
|
1274
|
+
url: string;
|
|
1275
|
+
} | {
|
|
1276
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1277
|
+
type: "file-id";
|
|
1278
|
+
fileId: string | Record<string, string>;
|
|
1279
|
+
} | {
|
|
1280
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1281
|
+
type: "image-data";
|
|
1282
|
+
mediaType: string;
|
|
1283
|
+
data: string;
|
|
1284
|
+
} | {
|
|
1285
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1286
|
+
type: "image-url";
|
|
1287
|
+
url: string;
|
|
1288
|
+
} | {
|
|
1289
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1290
|
+
type: "image-file-id";
|
|
1291
|
+
fileId: string | Record<string, string>;
|
|
1292
|
+
} | {
|
|
1293
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1294
|
+
type: "custom";
|
|
1295
|
+
})[];
|
|
1296
|
+
} | undefined;
|
|
1297
|
+
result?: any;
|
|
1298
|
+
isError?: boolean | undefined;
|
|
1299
|
+
experimental_content?: ({
|
|
1300
|
+
type: "text";
|
|
1301
|
+
text: string;
|
|
1302
|
+
} | {
|
|
1303
|
+
mimeType?: string | undefined;
|
|
1304
|
+
type: "image";
|
|
1305
|
+
data: string;
|
|
1306
|
+
})[] | undefined;
|
|
1307
|
+
type: "tool-result";
|
|
1308
|
+
toolCallId: string;
|
|
1309
|
+
toolName: string;
|
|
1310
|
+
} | {
|
|
1311
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1312
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1313
|
+
providerExecuted?: boolean | undefined;
|
|
1314
|
+
reason?: string | undefined;
|
|
1315
|
+
type: "tool-approval-response";
|
|
1316
|
+
approvalId: string;
|
|
1317
|
+
approved: boolean;
|
|
1318
|
+
})[];
|
|
1319
|
+
} | {
|
|
1320
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1321
|
+
role: "system";
|
|
1322
|
+
content: string;
|
|
1323
|
+
})[] | undefined;
|
|
1324
|
+
stream?: boolean | undefined;
|
|
1325
|
+
toolChoice?: "required" | "none" | "auto" | {
|
|
1326
|
+
type: "tool";
|
|
1327
|
+
toolName: string;
|
|
1328
|
+
} | undefined;
|
|
1329
|
+
maxSteps?: number | undefined;
|
|
1330
|
+
experimental_continueSteps?: boolean | undefined;
|
|
1331
|
+
prompt?: string | undefined;
|
|
1082
1332
|
promptMessageId?: string | undefined;
|
|
1083
1333
|
contextOptions?: {
|
|
1084
1334
|
excludeToolMessages?: boolean | undefined;
|
|
@@ -1098,18 +1348,25 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1098
1348
|
storageOptions?: {
|
|
1099
1349
|
saveMessages?: "all" | "none" | "promptAndOutput" | undefined;
|
|
1100
1350
|
} | undefined;
|
|
1351
|
+
callSettings?: {
|
|
1352
|
+
headers?: Record<string, string> | undefined;
|
|
1353
|
+
maxOutputTokens?: number | undefined;
|
|
1354
|
+
temperature?: number | undefined;
|
|
1355
|
+
topP?: number | undefined;
|
|
1356
|
+
topK?: number | undefined;
|
|
1357
|
+
presencePenalty?: number | undefined;
|
|
1358
|
+
frequencyPenalty?: number | undefined;
|
|
1359
|
+
stopSequences?: string[] | undefined;
|
|
1360
|
+
seed?: number | undefined;
|
|
1361
|
+
maxRetries?: number | undefined;
|
|
1362
|
+
} | undefined;
|
|
1101
1363
|
}, Promise<{
|
|
1102
1364
|
text: string;
|
|
1103
|
-
|
|
1104
|
-
order: number | undefined;
|
|
1105
|
-
finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
|
|
1106
|
-
warnings: Promise<import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined>;
|
|
1107
|
-
} | {
|
|
1108
|
-
text: string;
|
|
1109
|
-
messageId: string | undefined;
|
|
1365
|
+
promptMessageId: string | undefined;
|
|
1110
1366
|
order: number | undefined;
|
|
1111
|
-
finishReason: import("
|
|
1112
|
-
warnings: import("@ai-sdk/provider").
|
|
1367
|
+
finishReason: import("ai").FinishReason;
|
|
1368
|
+
warnings: import("@ai-sdk/provider").SharedV3Warning[] | undefined;
|
|
1369
|
+
savedMessageIds: string[];
|
|
1113
1370
|
}>>;
|
|
1114
1371
|
/**
|
|
1115
1372
|
* Create an action that generates an object out of this agent so you can call
|
|
@@ -1118,10 +1375,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1118
1375
|
* the normal parameters to {@link generateObject}, plus {@link ContextOptions}
|
|
1119
1376
|
* and stopWhen.
|
|
1120
1377
|
*/
|
|
1121
|
-
asObjectAction<T>(
|
|
1122
|
-
contextOptions?: ContextOptions;
|
|
1123
|
-
storageOptions?: StorageOptions;
|
|
1124
|
-
}): import("convex/server").RegisteredAction<"internal", {
|
|
1378
|
+
asObjectAction<T, DataModel extends GenericDataModel>(objectArgs: GenerateObjectArgs<FlexibleSchema<T>> & Partial<AgentPrompt>, options?: Options & MaybeCustomCtx<CustomCtx, DataModel, AgentTools>): import("convex/server").RegisteredAction<"internal", {
|
|
1125
1379
|
userId?: string | undefined;
|
|
1126
1380
|
threadId?: string | undefined;
|
|
1127
1381
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
@@ -1131,18 +1385,22 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1131
1385
|
role: "user";
|
|
1132
1386
|
content: string | ({
|
|
1133
1387
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1388
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1134
1389
|
type: "text";
|
|
1135
1390
|
text: string;
|
|
1136
1391
|
} | {
|
|
1137
1392
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1393
|
+
mediaType?: string | undefined;
|
|
1138
1394
|
mimeType?: string | undefined;
|
|
1139
1395
|
type: "image";
|
|
1140
1396
|
image: string | ArrayBuffer;
|
|
1141
1397
|
} | {
|
|
1142
1398
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1399
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1400
|
+
mediaType?: string | undefined;
|
|
1401
|
+
mimeType?: string | undefined;
|
|
1143
1402
|
filename?: string | undefined;
|
|
1144
1403
|
type: "file";
|
|
1145
|
-
mimeType: string;
|
|
1146
1404
|
data: string | ArrayBuffer;
|
|
1147
1405
|
})[];
|
|
1148
1406
|
} | {
|
|
@@ -1150,39 +1408,221 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1150
1408
|
role: "assistant";
|
|
1151
1409
|
content: string | ({
|
|
1152
1410
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1411
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1153
1412
|
type: "text";
|
|
1154
1413
|
text: string;
|
|
1155
1414
|
} | {
|
|
1156
1415
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1416
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1417
|
+
mediaType?: string | undefined;
|
|
1418
|
+
mimeType?: string | undefined;
|
|
1157
1419
|
filename?: string | undefined;
|
|
1158
1420
|
type: "file";
|
|
1159
|
-
mimeType: string;
|
|
1160
1421
|
data: string | ArrayBuffer;
|
|
1161
1422
|
} | {
|
|
1162
1423
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1424
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1163
1425
|
signature?: string | undefined;
|
|
1164
|
-
state?: "streaming" | "done" | undefined;
|
|
1165
1426
|
type: "reasoning";
|
|
1166
1427
|
text: string;
|
|
1167
1428
|
} | {
|
|
1168
1429
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1430
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1169
1431
|
type: "redacted-reasoning";
|
|
1170
1432
|
data: string;
|
|
1171
1433
|
} | {
|
|
1172
1434
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1435
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1436
|
+
args?: any;
|
|
1437
|
+
providerExecuted?: boolean | undefined;
|
|
1438
|
+
type: "tool-call";
|
|
1439
|
+
toolCallId: string;
|
|
1440
|
+
toolName: string;
|
|
1441
|
+
input: any;
|
|
1442
|
+
} | {
|
|
1443
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1444
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1445
|
+
input?: any;
|
|
1173
1446
|
providerExecuted?: boolean | undefined;
|
|
1174
1447
|
type: "tool-call";
|
|
1175
1448
|
toolCallId: string;
|
|
1176
1449
|
toolName: string;
|
|
1177
1450
|
args: any;
|
|
1451
|
+
} | {
|
|
1452
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1453
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1454
|
+
args?: any;
|
|
1455
|
+
providerExecuted?: boolean | undefined;
|
|
1456
|
+
output?: {
|
|
1457
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1458
|
+
type: "text";
|
|
1459
|
+
value: string;
|
|
1460
|
+
} | {
|
|
1461
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1462
|
+
type: "json";
|
|
1463
|
+
value: any;
|
|
1464
|
+
} | {
|
|
1465
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1466
|
+
type: "error-text";
|
|
1467
|
+
value: string;
|
|
1468
|
+
} | {
|
|
1469
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1470
|
+
type: "error-json";
|
|
1471
|
+
value: any;
|
|
1472
|
+
} | {
|
|
1473
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1474
|
+
reason?: string | undefined;
|
|
1475
|
+
type: "execution-denied";
|
|
1476
|
+
} | {
|
|
1477
|
+
type: "content";
|
|
1478
|
+
value: ({
|
|
1479
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1480
|
+
type: "text";
|
|
1481
|
+
text: string;
|
|
1482
|
+
} | {
|
|
1483
|
+
type: "media";
|
|
1484
|
+
mediaType: string;
|
|
1485
|
+
data: string;
|
|
1486
|
+
} | {
|
|
1487
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1488
|
+
filename?: string | undefined;
|
|
1489
|
+
type: "file-data";
|
|
1490
|
+
mediaType: string;
|
|
1491
|
+
data: string;
|
|
1492
|
+
} | {
|
|
1493
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1494
|
+
type: "file-url";
|
|
1495
|
+
url: string;
|
|
1496
|
+
} | {
|
|
1497
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1498
|
+
type: "file-id";
|
|
1499
|
+
fileId: string | Record<string, string>;
|
|
1500
|
+
} | {
|
|
1501
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1502
|
+
type: "image-data";
|
|
1503
|
+
mediaType: string;
|
|
1504
|
+
data: string;
|
|
1505
|
+
} | {
|
|
1506
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1507
|
+
type: "image-url";
|
|
1508
|
+
url: string;
|
|
1509
|
+
} | {
|
|
1510
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1511
|
+
type: "image-file-id";
|
|
1512
|
+
fileId: string | Record<string, string>;
|
|
1513
|
+
} | {
|
|
1514
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1515
|
+
type: "custom";
|
|
1516
|
+
})[];
|
|
1517
|
+
} | undefined;
|
|
1518
|
+
result?: any;
|
|
1519
|
+
isError?: boolean | undefined;
|
|
1520
|
+
experimental_content?: ({
|
|
1521
|
+
type: "text";
|
|
1522
|
+
text: string;
|
|
1523
|
+
} | {
|
|
1524
|
+
mimeType?: string | undefined;
|
|
1525
|
+
type: "image";
|
|
1526
|
+
data: string;
|
|
1527
|
+
})[] | undefined;
|
|
1528
|
+
type: "tool-result";
|
|
1529
|
+
toolCallId: string;
|
|
1530
|
+
toolName: string;
|
|
1531
|
+
} | {
|
|
1532
|
+
title?: string | undefined;
|
|
1533
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1534
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1535
|
+
id: string;
|
|
1536
|
+
type: "source";
|
|
1537
|
+
url: string;
|
|
1538
|
+
sourceType: "url";
|
|
1539
|
+
} | {
|
|
1540
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1541
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1542
|
+
filename?: string | undefined;
|
|
1543
|
+
id: string;
|
|
1544
|
+
title: string;
|
|
1545
|
+
type: "source";
|
|
1546
|
+
mediaType: string;
|
|
1547
|
+
sourceType: "document";
|
|
1548
|
+
} | {
|
|
1549
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1550
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1551
|
+
type: "tool-approval-request";
|
|
1552
|
+
toolCallId: string;
|
|
1553
|
+
approvalId: string;
|
|
1178
1554
|
})[];
|
|
1179
1555
|
} | {
|
|
1180
1556
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1181
1557
|
role: "tool";
|
|
1182
|
-
content: {
|
|
1558
|
+
content: ({
|
|
1183
1559
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1560
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1184
1561
|
args?: any;
|
|
1185
1562
|
providerExecuted?: boolean | undefined;
|
|
1563
|
+
output?: {
|
|
1564
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1565
|
+
type: "text";
|
|
1566
|
+
value: string;
|
|
1567
|
+
} | {
|
|
1568
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1569
|
+
type: "json";
|
|
1570
|
+
value: any;
|
|
1571
|
+
} | {
|
|
1572
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1573
|
+
type: "error-text";
|
|
1574
|
+
value: string;
|
|
1575
|
+
} | {
|
|
1576
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1577
|
+
type: "error-json";
|
|
1578
|
+
value: any;
|
|
1579
|
+
} | {
|
|
1580
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1581
|
+
reason?: string | undefined;
|
|
1582
|
+
type: "execution-denied";
|
|
1583
|
+
} | {
|
|
1584
|
+
type: "content";
|
|
1585
|
+
value: ({
|
|
1586
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1587
|
+
type: "text";
|
|
1588
|
+
text: string;
|
|
1589
|
+
} | {
|
|
1590
|
+
type: "media";
|
|
1591
|
+
mediaType: string;
|
|
1592
|
+
data: string;
|
|
1593
|
+
} | {
|
|
1594
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1595
|
+
filename?: string | undefined;
|
|
1596
|
+
type: "file-data";
|
|
1597
|
+
mediaType: string;
|
|
1598
|
+
data: string;
|
|
1599
|
+
} | {
|
|
1600
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1601
|
+
type: "file-url";
|
|
1602
|
+
url: string;
|
|
1603
|
+
} | {
|
|
1604
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1605
|
+
type: "file-id";
|
|
1606
|
+
fileId: string | Record<string, string>;
|
|
1607
|
+
} | {
|
|
1608
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1609
|
+
type: "image-data";
|
|
1610
|
+
mediaType: string;
|
|
1611
|
+
data: string;
|
|
1612
|
+
} | {
|
|
1613
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1614
|
+
type: "image-url";
|
|
1615
|
+
url: string;
|
|
1616
|
+
} | {
|
|
1617
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1618
|
+
type: "image-file-id";
|
|
1619
|
+
fileId: string | Record<string, string>;
|
|
1620
|
+
} | {
|
|
1621
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1622
|
+
type: "custom";
|
|
1623
|
+
})[];
|
|
1624
|
+
} | undefined;
|
|
1625
|
+
result?: any;
|
|
1186
1626
|
isError?: boolean | undefined;
|
|
1187
1627
|
experimental_content?: ({
|
|
1188
1628
|
type: "text";
|
|
@@ -1195,22 +1635,20 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1195
1635
|
type: "tool-result";
|
|
1196
1636
|
toolCallId: string;
|
|
1197
1637
|
toolName: string;
|
|
1198
|
-
|
|
1199
|
-
|
|
1638
|
+
} | {
|
|
1639
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1640
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1641
|
+
providerExecuted?: boolean | undefined;
|
|
1642
|
+
reason?: string | undefined;
|
|
1643
|
+
type: "tool-approval-response";
|
|
1644
|
+
approvalId: string;
|
|
1645
|
+
approved: boolean;
|
|
1646
|
+
})[];
|
|
1200
1647
|
} | {
|
|
1201
1648
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1202
1649
|
role: "system";
|
|
1203
1650
|
content: string;
|
|
1204
1651
|
})[] | undefined;
|
|
1205
|
-
headers?: Record<string, string> | undefined;
|
|
1206
|
-
maxTokens?: number | undefined;
|
|
1207
|
-
temperature?: number | undefined;
|
|
1208
|
-
topP?: number | undefined;
|
|
1209
|
-
topK?: number | undefined;
|
|
1210
|
-
presencePenalty?: number | undefined;
|
|
1211
|
-
frequencyPenalty?: number | undefined;
|
|
1212
|
-
seed?: number | undefined;
|
|
1213
|
-
maxRetries?: number | undefined;
|
|
1214
1652
|
prompt?: string | undefined;
|
|
1215
1653
|
promptMessageId?: string | undefined;
|
|
1216
1654
|
contextOptions?: {
|
|
@@ -1231,46 +1669,46 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1231
1669
|
storageOptions?: {
|
|
1232
1670
|
saveMessages?: "all" | "none" | "promptAndOutput" | undefined;
|
|
1233
1671
|
} | undefined;
|
|
1672
|
+
callSettings?: {
|
|
1673
|
+
headers?: Record<string, string> | undefined;
|
|
1674
|
+
maxOutputTokens?: number | undefined;
|
|
1675
|
+
temperature?: number | undefined;
|
|
1676
|
+
topP?: number | undefined;
|
|
1677
|
+
topK?: number | undefined;
|
|
1678
|
+
presencePenalty?: number | undefined;
|
|
1679
|
+
frequencyPenalty?: number | undefined;
|
|
1680
|
+
stopSequences?: string[] | undefined;
|
|
1681
|
+
seed?: number | undefined;
|
|
1682
|
+
maxRetries?: number | undefined;
|
|
1683
|
+
} | undefined;
|
|
1234
1684
|
}, Promise<{
|
|
1235
1685
|
object: T;
|
|
1236
|
-
|
|
1686
|
+
promptMessageId: string | undefined;
|
|
1237
1687
|
order: number | undefined;
|
|
1238
|
-
finishReason: import("
|
|
1239
|
-
warnings: import("@ai-sdk/provider").
|
|
1688
|
+
finishReason: import("ai").FinishReason;
|
|
1689
|
+
warnings: import("@ai-sdk/provider").SharedV3Warning[] | undefined;
|
|
1690
|
+
savedMessageIds: string[];
|
|
1240
1691
|
}>>;
|
|
1241
1692
|
/**
|
|
1242
|
-
*
|
|
1243
|
-
* Useful as a step in Workflows, e.g.
|
|
1244
|
-
* ```ts
|
|
1245
|
-
* const saveMessages = agent.asSaveMessagesMutation();
|
|
1246
|
-
*
|
|
1247
|
-
* const myWorkflow = workflow.define({
|
|
1248
|
-
* args: {...},
|
|
1249
|
-
* handler: async (step, args) => {
|
|
1250
|
-
* // do things to create (but not save)messages
|
|
1251
|
-
* const { messageIds } = await step.runMutation(internal.foo.saveMessages, {
|
|
1252
|
-
* threadId: args.threadId,
|
|
1253
|
-
* messages: args.messages,
|
|
1254
|
-
* });
|
|
1255
|
-
* // ...
|
|
1256
|
-
* },
|
|
1257
|
-
* })
|
|
1258
|
-
* ```
|
|
1259
|
-
* @returns A mutation that can be used to save messages to the thread.
|
|
1693
|
+
* @deprecated Use {@link saveMessages} directly instead.
|
|
1260
1694
|
*/
|
|
1261
1695
|
asSaveMessagesMutation(): import("convex/server").RegisteredMutation<"internal", {
|
|
1262
1696
|
userId?: string | undefined;
|
|
1263
|
-
pending?: boolean | undefined;
|
|
1264
1697
|
promptMessageId?: string | undefined;
|
|
1698
|
+
embeddings?: {
|
|
1699
|
+
model: string;
|
|
1700
|
+
vectors: (number[] | null)[];
|
|
1701
|
+
} | undefined;
|
|
1265
1702
|
failPendingSteps?: boolean | undefined;
|
|
1266
1703
|
threadId: string;
|
|
1267
1704
|
messages: {
|
|
1268
|
-
|
|
1705
|
+
status?: "pending" | "success" | "failed" | undefined;
|
|
1269
1706
|
fileIds?: string[] | undefined;
|
|
1270
1707
|
error?: string | undefined;
|
|
1271
1708
|
model?: string | undefined;
|
|
1272
1709
|
provider?: string | undefined;
|
|
1273
1710
|
text?: string | undefined;
|
|
1711
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1274
1712
|
reasoning?: string | undefined;
|
|
1275
1713
|
usage?: {
|
|
1276
1714
|
reasoningTokens?: number | undefined;
|
|
@@ -1279,27 +1717,41 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1279
1717
|
completionTokens: number;
|
|
1280
1718
|
totalTokens: number;
|
|
1281
1719
|
} | undefined;
|
|
1282
|
-
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1283
1720
|
sources?: ({
|
|
1284
1721
|
title?: string | undefined;
|
|
1285
1722
|
type?: "source" | undefined;
|
|
1286
1723
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1287
|
-
|
|
1724
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1288
1725
|
id: string;
|
|
1726
|
+
url: string;
|
|
1289
1727
|
sourceType: "url";
|
|
1290
1728
|
} | {
|
|
1291
|
-
|
|
1729
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1292
1730
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1731
|
+
filename?: string | undefined;
|
|
1293
1732
|
id: string;
|
|
1294
1733
|
title: string;
|
|
1295
1734
|
type: "source";
|
|
1296
|
-
sourceType: "document";
|
|
1297
1735
|
mediaType: string;
|
|
1736
|
+
sourceType: "document";
|
|
1298
1737
|
})[] | undefined;
|
|
1738
|
+
warnings?: ({
|
|
1739
|
+
details?: string | undefined;
|
|
1740
|
+
type: "unsupported-setting";
|
|
1741
|
+
setting: string;
|
|
1742
|
+
} | {
|
|
1743
|
+
details?: string | undefined;
|
|
1744
|
+
type: "unsupported-tool";
|
|
1745
|
+
tool: any;
|
|
1746
|
+
} | {
|
|
1747
|
+
type: "other";
|
|
1748
|
+
message: string;
|
|
1749
|
+
})[] | undefined;
|
|
1750
|
+
finishReason?: "error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
1299
1751
|
reasoningDetails?: ({
|
|
1300
1752
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1753
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1301
1754
|
signature?: string | undefined;
|
|
1302
|
-
state?: "streaming" | "done" | undefined;
|
|
1303
1755
|
type: "reasoning";
|
|
1304
1756
|
text: string;
|
|
1305
1757
|
} | {
|
|
@@ -1310,36 +1762,27 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1310
1762
|
type: "redacted";
|
|
1311
1763
|
data: string;
|
|
1312
1764
|
})[] | undefined;
|
|
1313
|
-
warnings?: ({
|
|
1314
|
-
details?: string | undefined;
|
|
1315
|
-
type: "unsupported-setting";
|
|
1316
|
-
setting: string;
|
|
1317
|
-
} | {
|
|
1318
|
-
details?: string | undefined;
|
|
1319
|
-
type: "unsupported-tool";
|
|
1320
|
-
tool: any;
|
|
1321
|
-
} | {
|
|
1322
|
-
type: "other";
|
|
1323
|
-
message: string;
|
|
1324
|
-
})[] | undefined;
|
|
1325
|
-
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
1326
1765
|
message: {
|
|
1327
1766
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1328
1767
|
role: "user";
|
|
1329
1768
|
content: string | ({
|
|
1330
1769
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1770
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1331
1771
|
type: "text";
|
|
1332
1772
|
text: string;
|
|
1333
1773
|
} | {
|
|
1334
1774
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1775
|
+
mediaType?: string | undefined;
|
|
1335
1776
|
mimeType?: string | undefined;
|
|
1336
1777
|
type: "image";
|
|
1337
1778
|
image: string | ArrayBuffer;
|
|
1338
1779
|
} | {
|
|
1339
1780
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1781
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1782
|
+
mediaType?: string | undefined;
|
|
1783
|
+
mimeType?: string | undefined;
|
|
1340
1784
|
filename?: string | undefined;
|
|
1341
1785
|
type: "file";
|
|
1342
|
-
mimeType: string;
|
|
1343
1786
|
data: string | ArrayBuffer;
|
|
1344
1787
|
})[];
|
|
1345
1788
|
} | {
|
|
@@ -1347,39 +1790,221 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1347
1790
|
role: "assistant";
|
|
1348
1791
|
content: string | ({
|
|
1349
1792
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1793
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1350
1794
|
type: "text";
|
|
1351
1795
|
text: string;
|
|
1352
1796
|
} | {
|
|
1353
1797
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1798
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1799
|
+
mediaType?: string | undefined;
|
|
1800
|
+
mimeType?: string | undefined;
|
|
1354
1801
|
filename?: string | undefined;
|
|
1355
1802
|
type: "file";
|
|
1356
|
-
mimeType: string;
|
|
1357
1803
|
data: string | ArrayBuffer;
|
|
1358
1804
|
} | {
|
|
1359
1805
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1806
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1360
1807
|
signature?: string | undefined;
|
|
1361
|
-
state?: "streaming" | "done" | undefined;
|
|
1362
1808
|
type: "reasoning";
|
|
1363
1809
|
text: string;
|
|
1364
1810
|
} | {
|
|
1365
1811
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1812
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1366
1813
|
type: "redacted-reasoning";
|
|
1367
1814
|
data: string;
|
|
1368
1815
|
} | {
|
|
1369
1816
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1817
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1818
|
+
args?: any;
|
|
1819
|
+
providerExecuted?: boolean | undefined;
|
|
1820
|
+
type: "tool-call";
|
|
1821
|
+
toolCallId: string;
|
|
1822
|
+
toolName: string;
|
|
1823
|
+
input: any;
|
|
1824
|
+
} | {
|
|
1825
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1826
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1827
|
+
input?: any;
|
|
1370
1828
|
providerExecuted?: boolean | undefined;
|
|
1371
1829
|
type: "tool-call";
|
|
1372
1830
|
toolCallId: string;
|
|
1373
1831
|
toolName: string;
|
|
1374
1832
|
args: any;
|
|
1833
|
+
} | {
|
|
1834
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1835
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1836
|
+
args?: any;
|
|
1837
|
+
providerExecuted?: boolean | undefined;
|
|
1838
|
+
output?: {
|
|
1839
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1840
|
+
type: "text";
|
|
1841
|
+
value: string;
|
|
1842
|
+
} | {
|
|
1843
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1844
|
+
type: "json";
|
|
1845
|
+
value: any;
|
|
1846
|
+
} | {
|
|
1847
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1848
|
+
type: "error-text";
|
|
1849
|
+
value: string;
|
|
1850
|
+
} | {
|
|
1851
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1852
|
+
type: "error-json";
|
|
1853
|
+
value: any;
|
|
1854
|
+
} | {
|
|
1855
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1856
|
+
reason?: string | undefined;
|
|
1857
|
+
type: "execution-denied";
|
|
1858
|
+
} | {
|
|
1859
|
+
type: "content";
|
|
1860
|
+
value: ({
|
|
1861
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1862
|
+
type: "text";
|
|
1863
|
+
text: string;
|
|
1864
|
+
} | {
|
|
1865
|
+
type: "media";
|
|
1866
|
+
mediaType: string;
|
|
1867
|
+
data: string;
|
|
1868
|
+
} | {
|
|
1869
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1870
|
+
filename?: string | undefined;
|
|
1871
|
+
type: "file-data";
|
|
1872
|
+
mediaType: string;
|
|
1873
|
+
data: string;
|
|
1874
|
+
} | {
|
|
1875
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1876
|
+
type: "file-url";
|
|
1877
|
+
url: string;
|
|
1878
|
+
} | {
|
|
1879
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1880
|
+
type: "file-id";
|
|
1881
|
+
fileId: string | Record<string, string>;
|
|
1882
|
+
} | {
|
|
1883
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1884
|
+
type: "image-data";
|
|
1885
|
+
mediaType: string;
|
|
1886
|
+
data: string;
|
|
1887
|
+
} | {
|
|
1888
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1889
|
+
type: "image-url";
|
|
1890
|
+
url: string;
|
|
1891
|
+
} | {
|
|
1892
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1893
|
+
type: "image-file-id";
|
|
1894
|
+
fileId: string | Record<string, string>;
|
|
1895
|
+
} | {
|
|
1896
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1897
|
+
type: "custom";
|
|
1898
|
+
})[];
|
|
1899
|
+
} | undefined;
|
|
1900
|
+
result?: any;
|
|
1901
|
+
isError?: boolean | undefined;
|
|
1902
|
+
experimental_content?: ({
|
|
1903
|
+
type: "text";
|
|
1904
|
+
text: string;
|
|
1905
|
+
} | {
|
|
1906
|
+
mimeType?: string | undefined;
|
|
1907
|
+
type: "image";
|
|
1908
|
+
data: string;
|
|
1909
|
+
})[] | undefined;
|
|
1910
|
+
type: "tool-result";
|
|
1911
|
+
toolCallId: string;
|
|
1912
|
+
toolName: string;
|
|
1913
|
+
} | {
|
|
1914
|
+
title?: string | undefined;
|
|
1915
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1916
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1917
|
+
id: string;
|
|
1918
|
+
type: "source";
|
|
1919
|
+
url: string;
|
|
1920
|
+
sourceType: "url";
|
|
1921
|
+
} | {
|
|
1922
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1923
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1924
|
+
filename?: string | undefined;
|
|
1925
|
+
id: string;
|
|
1926
|
+
title: string;
|
|
1927
|
+
type: "source";
|
|
1928
|
+
mediaType: string;
|
|
1929
|
+
sourceType: "document";
|
|
1930
|
+
} | {
|
|
1931
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1932
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1933
|
+
type: "tool-approval-request";
|
|
1934
|
+
toolCallId: string;
|
|
1935
|
+
approvalId: string;
|
|
1375
1936
|
})[];
|
|
1376
1937
|
} | {
|
|
1377
1938
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1378
1939
|
role: "tool";
|
|
1379
|
-
content: {
|
|
1940
|
+
content: ({
|
|
1380
1941
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1942
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1381
1943
|
args?: any;
|
|
1382
1944
|
providerExecuted?: boolean | undefined;
|
|
1945
|
+
output?: {
|
|
1946
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1947
|
+
type: "text";
|
|
1948
|
+
value: string;
|
|
1949
|
+
} | {
|
|
1950
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1951
|
+
type: "json";
|
|
1952
|
+
value: any;
|
|
1953
|
+
} | {
|
|
1954
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1955
|
+
type: "error-text";
|
|
1956
|
+
value: string;
|
|
1957
|
+
} | {
|
|
1958
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1959
|
+
type: "error-json";
|
|
1960
|
+
value: any;
|
|
1961
|
+
} | {
|
|
1962
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1963
|
+
reason?: string | undefined;
|
|
1964
|
+
type: "execution-denied";
|
|
1965
|
+
} | {
|
|
1966
|
+
type: "content";
|
|
1967
|
+
value: ({
|
|
1968
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1969
|
+
type: "text";
|
|
1970
|
+
text: string;
|
|
1971
|
+
} | {
|
|
1972
|
+
type: "media";
|
|
1973
|
+
mediaType: string;
|
|
1974
|
+
data: string;
|
|
1975
|
+
} | {
|
|
1976
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1977
|
+
filename?: string | undefined;
|
|
1978
|
+
type: "file-data";
|
|
1979
|
+
mediaType: string;
|
|
1980
|
+
data: string;
|
|
1981
|
+
} | {
|
|
1982
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1983
|
+
type: "file-url";
|
|
1984
|
+
url: string;
|
|
1985
|
+
} | {
|
|
1986
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1987
|
+
type: "file-id";
|
|
1988
|
+
fileId: string | Record<string, string>;
|
|
1989
|
+
} | {
|
|
1990
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1991
|
+
type: "image-data";
|
|
1992
|
+
mediaType: string;
|
|
1993
|
+
data: string;
|
|
1994
|
+
} | {
|
|
1995
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1996
|
+
type: "image-url";
|
|
1997
|
+
url: string;
|
|
1998
|
+
} | {
|
|
1999
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2000
|
+
type: "image-file-id";
|
|
2001
|
+
fileId: string | Record<string, string>;
|
|
2002
|
+
} | {
|
|
2003
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2004
|
+
type: "custom";
|
|
2005
|
+
})[];
|
|
2006
|
+
} | undefined;
|
|
2007
|
+
result?: any;
|
|
1383
2008
|
isError?: boolean | undefined;
|
|
1384
2009
|
experimental_content?: ({
|
|
1385
2010
|
type: "text";
|
|
@@ -1392,8 +2017,15 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1392
2017
|
type: "tool-result";
|
|
1393
2018
|
toolCallId: string;
|
|
1394
2019
|
toolName: string;
|
|
1395
|
-
|
|
1396
|
-
|
|
2020
|
+
} | {
|
|
2021
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2022
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
2023
|
+
providerExecuted?: boolean | undefined;
|
|
2024
|
+
reason?: string | undefined;
|
|
2025
|
+
type: "tool-approval-response";
|
|
2026
|
+
approvalId: string;
|
|
2027
|
+
approved: boolean;
|
|
2028
|
+
})[];
|
|
1397
2029
|
} | {
|
|
1398
2030
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1399
2031
|
role: "system";
|
|
@@ -1402,552 +2034,11 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1402
2034
|
}[];
|
|
1403
2035
|
}, Promise<{
|
|
1404
2036
|
lastMessageId: string;
|
|
1405
|
-
|
|
2037
|
+
messages: {
|
|
2038
|
+
order: number;
|
|
2039
|
+
stepOrder: number;
|
|
2040
|
+
_id: string;
|
|
2041
|
+
}[];
|
|
1406
2042
|
}>>;
|
|
1407
2043
|
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Create a thread to store messages with an Agent.
|
|
1410
|
-
* @param ctx The context from a mutation or action.
|
|
1411
|
-
* @param component The Agent component, usually `components.agent`.
|
|
1412
|
-
* @param args The associated thread metadata.
|
|
1413
|
-
* @returns The id of the created thread.
|
|
1414
|
-
*/
|
|
1415
|
-
export declare function createThread(ctx: RunMutationCtx, component: AgentComponent, args?: {
|
|
1416
|
-
userId?: string | null;
|
|
1417
|
-
title?: string;
|
|
1418
|
-
summary?: string;
|
|
1419
|
-
}): Promise<string>;
|
|
1420
|
-
/**
|
|
1421
|
-
* Get the metadata for a thread.
|
|
1422
|
-
* @param ctx A ctx object from a query, mutation, or action.
|
|
1423
|
-
* @param args.threadId The thread to get the metadata for.
|
|
1424
|
-
* @returns The metadata for the thread.
|
|
1425
|
-
*/
|
|
1426
|
-
export declare function getThreadMetadata(ctx: RunQueryCtx, component: AgentComponent, args: {
|
|
1427
|
-
threadId: string;
|
|
1428
|
-
}): Promise<ThreadDoc>;
|
|
1429
|
-
type SaveMessagesArgs = {
|
|
1430
|
-
threadId: string;
|
|
1431
|
-
userId?: string | null;
|
|
1432
|
-
/**
|
|
1433
|
-
* The message that these messages are in response to. They will be
|
|
1434
|
-
* the same "order" as this message, at increasing stepOrder(s).
|
|
1435
|
-
*/
|
|
1436
|
-
promptMessageId?: string;
|
|
1437
|
-
/**
|
|
1438
|
-
* The messages to save.
|
|
1439
|
-
*/
|
|
1440
|
-
messages: ((ModelMessage & {
|
|
1441
|
-
id?: string | undefined;
|
|
1442
|
-
}) | Message)[];
|
|
1443
|
-
/**
|
|
1444
|
-
* Metadata to save with the messages. Each element corresponds to the
|
|
1445
|
-
* message at the same index.
|
|
1446
|
-
*/
|
|
1447
|
-
metadata?: Omit<MessageWithMetadata, "message">[];
|
|
1448
|
-
/**
|
|
1449
|
-
* If false, it will "commit" the messages immediately.
|
|
1450
|
-
* If true, it will mark them as pending until the final step has finished.
|
|
1451
|
-
* Defaults to false.
|
|
1452
|
-
*/
|
|
1453
|
-
pending?: boolean;
|
|
1454
|
-
/**
|
|
1455
|
-
* If true, it will fail any pending steps.
|
|
1456
|
-
* Defaults to false.
|
|
1457
|
-
*/
|
|
1458
|
-
failPendingSteps?: boolean;
|
|
1459
|
-
/**
|
|
1460
|
-
* The embeddings to save with the messages.
|
|
1461
|
-
*/
|
|
1462
|
-
embeddings?: Omit<MessageEmbeddings, "dimension">;
|
|
1463
|
-
};
|
|
1464
|
-
/**
|
|
1465
|
-
* Explicitly save messages associated with the thread (& user if provided)
|
|
1466
|
-
*/
|
|
1467
|
-
export declare function saveMessages(ctx: RunMutationCtx, component: AgentComponent, args: SaveMessagesArgs & {
|
|
1468
|
-
/**
|
|
1469
|
-
* The agent name to associate with the messages.
|
|
1470
|
-
*/
|
|
1471
|
-
agentName?: string;
|
|
1472
|
-
}): Promise<{
|
|
1473
|
-
lastMessageId: string;
|
|
1474
|
-
messages: {
|
|
1475
|
-
_creationTime: number;
|
|
1476
|
-
_id: string;
|
|
1477
|
-
agentName?: string | undefined;
|
|
1478
|
-
embeddingId?: string | undefined;
|
|
1479
|
-
error?: string | undefined;
|
|
1480
|
-
fileIds?: string[] | undefined;
|
|
1481
|
-
finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
|
|
1482
|
-
id?: string | undefined;
|
|
1483
|
-
message?: {
|
|
1484
|
-
content: string | ({
|
|
1485
|
-
providerOptions?: {
|
|
1486
|
-
[x: string]: {
|
|
1487
|
-
[x: string]: any;
|
|
1488
|
-
};
|
|
1489
|
-
} | undefined;
|
|
1490
|
-
text: string;
|
|
1491
|
-
type: "text";
|
|
1492
|
-
} | {
|
|
1493
|
-
image: string | ArrayBuffer;
|
|
1494
|
-
mimeType?: string | undefined;
|
|
1495
|
-
providerOptions?: {
|
|
1496
|
-
[x: string]: {
|
|
1497
|
-
[x: string]: any;
|
|
1498
|
-
};
|
|
1499
|
-
} | undefined;
|
|
1500
|
-
type: "image";
|
|
1501
|
-
} | {
|
|
1502
|
-
data: string | ArrayBuffer;
|
|
1503
|
-
filename?: string | undefined;
|
|
1504
|
-
mimeType: string;
|
|
1505
|
-
providerOptions?: {
|
|
1506
|
-
[x: string]: {
|
|
1507
|
-
[x: string]: any;
|
|
1508
|
-
};
|
|
1509
|
-
} | undefined;
|
|
1510
|
-
type: "file";
|
|
1511
|
-
})[];
|
|
1512
|
-
providerOptions?: {
|
|
1513
|
-
[x: string]: {
|
|
1514
|
-
[x: string]: any;
|
|
1515
|
-
};
|
|
1516
|
-
} | undefined;
|
|
1517
|
-
role: "user";
|
|
1518
|
-
} | {
|
|
1519
|
-
content: string | ({
|
|
1520
|
-
providerOptions?: {
|
|
1521
|
-
[x: string]: {
|
|
1522
|
-
[x: string]: any;
|
|
1523
|
-
};
|
|
1524
|
-
} | undefined;
|
|
1525
|
-
text: string;
|
|
1526
|
-
type: "text";
|
|
1527
|
-
} | {
|
|
1528
|
-
data: string | ArrayBuffer;
|
|
1529
|
-
filename?: string | undefined;
|
|
1530
|
-
mimeType: string;
|
|
1531
|
-
providerOptions?: {
|
|
1532
|
-
[x: string]: {
|
|
1533
|
-
[x: string]: any;
|
|
1534
|
-
};
|
|
1535
|
-
} | undefined;
|
|
1536
|
-
type: "file";
|
|
1537
|
-
} | {
|
|
1538
|
-
providerOptions?: {
|
|
1539
|
-
[x: string]: {
|
|
1540
|
-
[x: string]: any;
|
|
1541
|
-
};
|
|
1542
|
-
} | undefined;
|
|
1543
|
-
signature?: string | undefined;
|
|
1544
|
-
state?: "streaming" | "done" | undefined;
|
|
1545
|
-
text: string;
|
|
1546
|
-
type: "reasoning";
|
|
1547
|
-
} | {
|
|
1548
|
-
data: string;
|
|
1549
|
-
providerOptions?: {
|
|
1550
|
-
[x: string]: {
|
|
1551
|
-
[x: string]: any;
|
|
1552
|
-
};
|
|
1553
|
-
} | undefined;
|
|
1554
|
-
type: "redacted-reasoning";
|
|
1555
|
-
} | {
|
|
1556
|
-
args: any;
|
|
1557
|
-
providerExecuted?: boolean | undefined;
|
|
1558
|
-
providerOptions?: {
|
|
1559
|
-
[x: string]: {
|
|
1560
|
-
[x: string]: any;
|
|
1561
|
-
};
|
|
1562
|
-
} | undefined;
|
|
1563
|
-
toolCallId: string;
|
|
1564
|
-
toolName: string;
|
|
1565
|
-
type: "tool-call";
|
|
1566
|
-
})[];
|
|
1567
|
-
providerOptions?: {
|
|
1568
|
-
[x: string]: {
|
|
1569
|
-
[x: string]: any;
|
|
1570
|
-
};
|
|
1571
|
-
} | undefined;
|
|
1572
|
-
role: "assistant";
|
|
1573
|
-
} | {
|
|
1574
|
-
content: {
|
|
1575
|
-
args?: any;
|
|
1576
|
-
experimental_content?: ({
|
|
1577
|
-
text: string;
|
|
1578
|
-
type: "text";
|
|
1579
|
-
} | {
|
|
1580
|
-
data: string;
|
|
1581
|
-
mimeType?: string | undefined;
|
|
1582
|
-
type: "image";
|
|
1583
|
-
})[] | undefined;
|
|
1584
|
-
isError?: boolean | undefined;
|
|
1585
|
-
providerExecuted?: boolean | undefined;
|
|
1586
|
-
providerOptions?: {
|
|
1587
|
-
[x: string]: {
|
|
1588
|
-
[x: string]: any;
|
|
1589
|
-
};
|
|
1590
|
-
} | undefined;
|
|
1591
|
-
result: any;
|
|
1592
|
-
toolCallId: string;
|
|
1593
|
-
toolName: string;
|
|
1594
|
-
type: "tool-result";
|
|
1595
|
-
}[];
|
|
1596
|
-
providerOptions?: {
|
|
1597
|
-
[x: string]: {
|
|
1598
|
-
[x: string]: any;
|
|
1599
|
-
};
|
|
1600
|
-
} | undefined;
|
|
1601
|
-
role: "tool";
|
|
1602
|
-
} | {
|
|
1603
|
-
content: string;
|
|
1604
|
-
providerOptions?: {
|
|
1605
|
-
[x: string]: {
|
|
1606
|
-
[x: string]: any;
|
|
1607
|
-
};
|
|
1608
|
-
} | undefined;
|
|
1609
|
-
role: "system";
|
|
1610
|
-
} | undefined;
|
|
1611
|
-
model?: string | undefined;
|
|
1612
|
-
order: number;
|
|
1613
|
-
provider?: string | undefined;
|
|
1614
|
-
providerMetadata?: {
|
|
1615
|
-
[x: string]: {
|
|
1616
|
-
[x: string]: any;
|
|
1617
|
-
};
|
|
1618
|
-
} | undefined;
|
|
1619
|
-
providerOptions?: {
|
|
1620
|
-
[x: string]: {
|
|
1621
|
-
[x: string]: any;
|
|
1622
|
-
};
|
|
1623
|
-
} | undefined;
|
|
1624
|
-
reasoning?: string | undefined;
|
|
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
|
-
} | {
|
|
1636
|
-
signature?: string | undefined;
|
|
1637
|
-
text: string;
|
|
1638
|
-
type: "text";
|
|
1639
|
-
} | {
|
|
1640
|
-
data: string;
|
|
1641
|
-
type: "redacted";
|
|
1642
|
-
})[] | undefined;
|
|
1643
|
-
sources?: ({
|
|
1644
|
-
id: string;
|
|
1645
|
-
providerOptions?: {
|
|
1646
|
-
[x: string]: {
|
|
1647
|
-
[x: string]: any;
|
|
1648
|
-
};
|
|
1649
|
-
} | undefined;
|
|
1650
|
-
sourceType: "url";
|
|
1651
|
-
title?: string | undefined;
|
|
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;
|
|
1667
|
-
status: "pending" | "success" | "failed";
|
|
1668
|
-
stepOrder: number;
|
|
1669
|
-
text?: string | undefined;
|
|
1670
|
-
threadId: string;
|
|
1671
|
-
tool: boolean;
|
|
1672
|
-
usage?: {
|
|
1673
|
-
cachedInputTokens?: number | undefined;
|
|
1674
|
-
completionTokens: number;
|
|
1675
|
-
promptTokens: number;
|
|
1676
|
-
reasoningTokens?: number | undefined;
|
|
1677
|
-
totalTokens: number;
|
|
1678
|
-
} | undefined;
|
|
1679
|
-
userId?: string | undefined;
|
|
1680
|
-
warnings?: ({
|
|
1681
|
-
details?: string | undefined;
|
|
1682
|
-
setting: string;
|
|
1683
|
-
type: "unsupported-setting";
|
|
1684
|
-
} | {
|
|
1685
|
-
details?: string | undefined;
|
|
1686
|
-
tool: any;
|
|
1687
|
-
type: "unsupported-tool";
|
|
1688
|
-
} | {
|
|
1689
|
-
message: string;
|
|
1690
|
-
type: "other";
|
|
1691
|
-
})[] | undefined;
|
|
1692
|
-
}[];
|
|
1693
|
-
}>;
|
|
1694
|
-
type SaveMessageArgs = {
|
|
1695
|
-
threadId: string;
|
|
1696
|
-
userId?: string | null;
|
|
1697
|
-
/**
|
|
1698
|
-
* Metadata to save with the messages. Each element corresponds to the
|
|
1699
|
-
* message at the same index.
|
|
1700
|
-
*/
|
|
1701
|
-
metadata?: Omit<MessageWithMetadata, "message">;
|
|
1702
|
-
/**
|
|
1703
|
-
* The embedding to save with the message.
|
|
1704
|
-
*/
|
|
1705
|
-
embedding?: {
|
|
1706
|
-
vector: number[];
|
|
1707
|
-
model: string;
|
|
1708
|
-
};
|
|
1709
|
-
} & ({
|
|
1710
|
-
prompt?: undefined;
|
|
1711
|
-
/**
|
|
1712
|
-
* The message to save.
|
|
1713
|
-
*/
|
|
1714
|
-
message: ModelMessage | Message;
|
|
1715
|
-
} | {
|
|
1716
|
-
prompt: string;
|
|
1717
|
-
message?: undefined;
|
|
1718
|
-
});
|
|
1719
|
-
/**
|
|
1720
|
-
* Save a message to the thread.
|
|
1721
|
-
* @param ctx A ctx object from a mutation or action.
|
|
1722
|
-
* @param args The message and what to associate it with (user / thread)
|
|
1723
|
-
* You can pass extra metadata alongside the message, e.g. associated fileIds.
|
|
1724
|
-
* @returns The messageId of the saved message.
|
|
1725
|
-
*/
|
|
1726
|
-
export declare function saveMessage(ctx: RunMutationCtx, component: AgentComponent, args: SaveMessageArgs & {
|
|
1727
|
-
/**
|
|
1728
|
-
* The agent name to associate with the message.
|
|
1729
|
-
*/
|
|
1730
|
-
agentName?: string;
|
|
1731
|
-
}): Promise<{
|
|
1732
|
-
messageId: string;
|
|
1733
|
-
message: {
|
|
1734
|
-
_creationTime: number;
|
|
1735
|
-
_id: string;
|
|
1736
|
-
agentName?: string | undefined;
|
|
1737
|
-
embeddingId?: string | undefined;
|
|
1738
|
-
error?: string | undefined;
|
|
1739
|
-
fileIds?: string[] | undefined;
|
|
1740
|
-
finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
|
|
1741
|
-
id?: string | undefined;
|
|
1742
|
-
message?: {
|
|
1743
|
-
content: string | ({
|
|
1744
|
-
providerOptions?: {
|
|
1745
|
-
[x: string]: {
|
|
1746
|
-
[x: string]: any;
|
|
1747
|
-
};
|
|
1748
|
-
} | undefined;
|
|
1749
|
-
text: string;
|
|
1750
|
-
type: "text";
|
|
1751
|
-
} | {
|
|
1752
|
-
image: string | ArrayBuffer;
|
|
1753
|
-
mimeType?: string | undefined;
|
|
1754
|
-
providerOptions?: {
|
|
1755
|
-
[x: string]: {
|
|
1756
|
-
[x: string]: any;
|
|
1757
|
-
};
|
|
1758
|
-
} | undefined;
|
|
1759
|
-
type: "image";
|
|
1760
|
-
} | {
|
|
1761
|
-
data: string | ArrayBuffer;
|
|
1762
|
-
filename?: string | undefined;
|
|
1763
|
-
mimeType: string;
|
|
1764
|
-
providerOptions?: {
|
|
1765
|
-
[x: string]: {
|
|
1766
|
-
[x: string]: any;
|
|
1767
|
-
};
|
|
1768
|
-
} | undefined;
|
|
1769
|
-
type: "file";
|
|
1770
|
-
})[];
|
|
1771
|
-
providerOptions?: {
|
|
1772
|
-
[x: string]: {
|
|
1773
|
-
[x: string]: any;
|
|
1774
|
-
};
|
|
1775
|
-
} | undefined;
|
|
1776
|
-
role: "user";
|
|
1777
|
-
} | {
|
|
1778
|
-
content: string | ({
|
|
1779
|
-
providerOptions?: {
|
|
1780
|
-
[x: string]: {
|
|
1781
|
-
[x: string]: any;
|
|
1782
|
-
};
|
|
1783
|
-
} | undefined;
|
|
1784
|
-
text: string;
|
|
1785
|
-
type: "text";
|
|
1786
|
-
} | {
|
|
1787
|
-
data: string | ArrayBuffer;
|
|
1788
|
-
filename?: string | undefined;
|
|
1789
|
-
mimeType: string;
|
|
1790
|
-
providerOptions?: {
|
|
1791
|
-
[x: string]: {
|
|
1792
|
-
[x: string]: any;
|
|
1793
|
-
};
|
|
1794
|
-
} | undefined;
|
|
1795
|
-
type: "file";
|
|
1796
|
-
} | {
|
|
1797
|
-
providerOptions?: {
|
|
1798
|
-
[x: string]: {
|
|
1799
|
-
[x: string]: any;
|
|
1800
|
-
};
|
|
1801
|
-
} | undefined;
|
|
1802
|
-
signature?: string | undefined;
|
|
1803
|
-
state?: "streaming" | "done" | undefined;
|
|
1804
|
-
text: string;
|
|
1805
|
-
type: "reasoning";
|
|
1806
|
-
} | {
|
|
1807
|
-
data: string;
|
|
1808
|
-
providerOptions?: {
|
|
1809
|
-
[x: string]: {
|
|
1810
|
-
[x: string]: any;
|
|
1811
|
-
};
|
|
1812
|
-
} | undefined;
|
|
1813
|
-
type: "redacted-reasoning";
|
|
1814
|
-
} | {
|
|
1815
|
-
args: any;
|
|
1816
|
-
providerExecuted?: boolean | undefined;
|
|
1817
|
-
providerOptions?: {
|
|
1818
|
-
[x: string]: {
|
|
1819
|
-
[x: string]: any;
|
|
1820
|
-
};
|
|
1821
|
-
} | undefined;
|
|
1822
|
-
toolCallId: string;
|
|
1823
|
-
toolName: string;
|
|
1824
|
-
type: "tool-call";
|
|
1825
|
-
})[];
|
|
1826
|
-
providerOptions?: {
|
|
1827
|
-
[x: string]: {
|
|
1828
|
-
[x: string]: any;
|
|
1829
|
-
};
|
|
1830
|
-
} | undefined;
|
|
1831
|
-
role: "assistant";
|
|
1832
|
-
} | {
|
|
1833
|
-
content: {
|
|
1834
|
-
args?: any;
|
|
1835
|
-
experimental_content?: ({
|
|
1836
|
-
text: string;
|
|
1837
|
-
type: "text";
|
|
1838
|
-
} | {
|
|
1839
|
-
data: string;
|
|
1840
|
-
mimeType?: string | undefined;
|
|
1841
|
-
type: "image";
|
|
1842
|
-
})[] | undefined;
|
|
1843
|
-
isError?: boolean | undefined;
|
|
1844
|
-
providerExecuted?: boolean | undefined;
|
|
1845
|
-
providerOptions?: {
|
|
1846
|
-
[x: string]: {
|
|
1847
|
-
[x: string]: any;
|
|
1848
|
-
};
|
|
1849
|
-
} | undefined;
|
|
1850
|
-
result: any;
|
|
1851
|
-
toolCallId: string;
|
|
1852
|
-
toolName: string;
|
|
1853
|
-
type: "tool-result";
|
|
1854
|
-
}[];
|
|
1855
|
-
providerOptions?: {
|
|
1856
|
-
[x: string]: {
|
|
1857
|
-
[x: string]: any;
|
|
1858
|
-
};
|
|
1859
|
-
} | undefined;
|
|
1860
|
-
role: "tool";
|
|
1861
|
-
} | {
|
|
1862
|
-
content: string;
|
|
1863
|
-
providerOptions?: {
|
|
1864
|
-
[x: string]: {
|
|
1865
|
-
[x: string]: any;
|
|
1866
|
-
};
|
|
1867
|
-
} | undefined;
|
|
1868
|
-
role: "system";
|
|
1869
|
-
} | undefined;
|
|
1870
|
-
model?: string | undefined;
|
|
1871
|
-
order: number;
|
|
1872
|
-
provider?: string | undefined;
|
|
1873
|
-
providerMetadata?: {
|
|
1874
|
-
[x: string]: {
|
|
1875
|
-
[x: string]: any;
|
|
1876
|
-
};
|
|
1877
|
-
} | undefined;
|
|
1878
|
-
providerOptions?: {
|
|
1879
|
-
[x: string]: {
|
|
1880
|
-
[x: string]: any;
|
|
1881
|
-
};
|
|
1882
|
-
} | undefined;
|
|
1883
|
-
reasoning?: string | undefined;
|
|
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
|
-
} | {
|
|
1895
|
-
signature?: string | undefined;
|
|
1896
|
-
text: string;
|
|
1897
|
-
type: "text";
|
|
1898
|
-
} | {
|
|
1899
|
-
data: string;
|
|
1900
|
-
type: "redacted";
|
|
1901
|
-
})[] | undefined;
|
|
1902
|
-
sources?: ({
|
|
1903
|
-
id: string;
|
|
1904
|
-
providerOptions?: {
|
|
1905
|
-
[x: string]: {
|
|
1906
|
-
[x: string]: any;
|
|
1907
|
-
};
|
|
1908
|
-
} | undefined;
|
|
1909
|
-
sourceType: "url";
|
|
1910
|
-
title?: string | undefined;
|
|
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;
|
|
1926
|
-
status: "pending" | "success" | "failed";
|
|
1927
|
-
stepOrder: number;
|
|
1928
|
-
text?: string | undefined;
|
|
1929
|
-
threadId: string;
|
|
1930
|
-
tool: boolean;
|
|
1931
|
-
usage?: {
|
|
1932
|
-
cachedInputTokens?: number | undefined;
|
|
1933
|
-
completionTokens: number;
|
|
1934
|
-
promptTokens: number;
|
|
1935
|
-
reasoningTokens?: number | undefined;
|
|
1936
|
-
totalTokens: number;
|
|
1937
|
-
} | undefined;
|
|
1938
|
-
userId?: string | undefined;
|
|
1939
|
-
warnings?: ({
|
|
1940
|
-
details?: string | undefined;
|
|
1941
|
-
setting: string;
|
|
1942
|
-
type: "unsupported-setting";
|
|
1943
|
-
} | {
|
|
1944
|
-
details?: string | undefined;
|
|
1945
|
-
tool: any;
|
|
1946
|
-
type: "unsupported-tool";
|
|
1947
|
-
} | {
|
|
1948
|
-
message: string;
|
|
1949
|
-
type: "other";
|
|
1950
|
-
})[] | undefined;
|
|
1951
|
-
};
|
|
1952
|
-
}>;
|
|
1953
2044
|
//# sourceMappingURL=index.d.ts.map
|