@convex-dev/agent 0.5.0-alpha.1 → 0.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +153 -0
- 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 +126 -27
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +67 -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 +1335 -204
- 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 +1116 -978
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +332 -747
- 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 +182 -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 +350 -39
- 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 +185 -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 +117 -0
- package/dist/client/streamText.js.map +1 -0
- package/dist/client/streaming.d.ts +3716 -32
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js +161 -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 +266 -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 +3120 -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 +2578 -366
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +397 -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 +39 -339
- 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 +13 -13
- package/dist/component/users.d.ts +7 -7
- 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 +446 -0
- package/dist/deltas.js.map +1 -0
- package/dist/mapping.d.ts +38 -20
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +365 -97
- 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 +106 -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 +101 -51
- package/src/UIMessages.combineUIMessages.test.ts +239 -0
- package/src/UIMessages.test.ts +273 -0
- package/src/UIMessages.ts +739 -0
- package/src/client/approval.test.ts +350 -0
- package/src/client/createTool.ts +291 -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 +638 -1289
- package/src/client/messages.ts +237 -0
- package/src/client/mockModel.ts +252 -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 +581 -70
- package/src/client/start.ts +327 -0
- package/src/client/streamText.ts +187 -0
- package/src/client/streaming.test.ts +186 -0
- package/src/client/streaming.ts +241 -97
- package/src/client/threads.ts +83 -0
- package/src/client/types.ts +370 -219
- package/src/client/utils.ts +27 -0
- package/src/component/_generated/api.ts +64 -0
- package/src/component/_generated/component.ts +4902 -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 +500 -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 +569 -0
- package/src/fromUIMessages.test.ts +497 -0
- package/src/mapping.test.ts +180 -6
- package/src/mapping.ts +479 -162
- 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 +160 -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`.
|
|
@@ -414,8 +355,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
414
355
|
}): Promise<{
|
|
415
356
|
messageId: string;
|
|
416
357
|
message: {
|
|
417
|
-
id?: string | undefined;
|
|
418
358
|
userId?: string | undefined;
|
|
359
|
+
id?: string | undefined;
|
|
419
360
|
embeddingId?: string | undefined;
|
|
420
361
|
fileIds?: string[] | undefined;
|
|
421
362
|
error?: string | undefined;
|
|
@@ -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
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
517
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
518
|
+
title?: string | undefined;
|
|
519
|
+
type: "source";
|
|
520
|
+
id: string;
|
|
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
|
+
type: "source";
|
|
528
|
+
id: string;
|
|
529
|
+
mediaType: string;
|
|
530
|
+
sourceType: "document";
|
|
531
|
+
title: string;
|
|
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,36 +643,23 @@ 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
|
-
title?: string | undefined;
|
|
514
647
|
type?: "source" | undefined;
|
|
515
648
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
516
|
-
|
|
649
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
650
|
+
title?: string | 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;
|
|
522
|
-
|
|
523
|
-
title: string;
|
|
657
|
+
filename?: string | undefined;
|
|
524
658
|
type: "source";
|
|
525
|
-
|
|
659
|
+
id: string;
|
|
526
660
|
mediaType: string;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
530
|
-
signature?: string | undefined;
|
|
531
|
-
state?: "streaming" | "done" | undefined;
|
|
532
|
-
type: "reasoning";
|
|
533
|
-
text: string;
|
|
534
|
-
} | {
|
|
535
|
-
signature?: string | undefined;
|
|
536
|
-
type: "text";
|
|
537
|
-
text: string;
|
|
538
|
-
} | {
|
|
539
|
-
type: "redacted";
|
|
540
|
-
data: string;
|
|
661
|
+
sourceType: "document";
|
|
662
|
+
title: string;
|
|
541
663
|
})[] | undefined;
|
|
542
664
|
warnings?: ({
|
|
543
665
|
details?: string | undefined;
|
|
@@ -552,12 +674,26 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
552
674
|
message: string;
|
|
553
675
|
})[] | undefined;
|
|
554
676
|
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
677
|
+
reasoningDetails?: ({
|
|
678
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
679
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
680
|
+
signature?: string | undefined;
|
|
681
|
+
type: "reasoning";
|
|
682
|
+
text: string;
|
|
683
|
+
} | {
|
|
684
|
+
signature?: string | undefined;
|
|
685
|
+
type: "text";
|
|
686
|
+
text: string;
|
|
687
|
+
} | {
|
|
688
|
+
type: "redacted";
|
|
689
|
+
data: string;
|
|
690
|
+
})[] | undefined;
|
|
555
691
|
_id: string;
|
|
556
692
|
_creationTime: number;
|
|
557
|
-
status: "pending" | "success" | "failed";
|
|
558
|
-
order: number;
|
|
559
693
|
threadId: string;
|
|
694
|
+
order: number;
|
|
560
695
|
stepOrder: number;
|
|
696
|
+
status: "pending" | "success" | "failed";
|
|
561
697
|
tool: boolean;
|
|
562
698
|
};
|
|
563
699
|
}>;
|
|
@@ -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,56 @@ 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
|
-
|
|
822
|
+
/**
|
|
823
|
+
* Approve a tool call that requires human approval.
|
|
824
|
+
* Saves a `tool-approval-response` message to the thread.
|
|
825
|
+
* After calling this, call `agent.streamText` or `agent.generateText`
|
|
826
|
+
* with `promptMessageId` set to the returned `messageId` to continue
|
|
827
|
+
* generation — the AI SDK will automatically execute the approved tool.
|
|
828
|
+
*
|
|
829
|
+
* The approval response is attached to the same generation order as the
|
|
830
|
+
* original approval request, preserving tool_call/tool_result adjacency in
|
|
831
|
+
* the continuation context even if newer thread messages exist.
|
|
832
|
+
*
|
|
833
|
+
* @param ctx A ctx object from a mutation.
|
|
834
|
+
* @param args.threadId The thread containing the tool call.
|
|
835
|
+
* @param args.approvalId The approval ID from the tool-approval-request part.
|
|
836
|
+
* @param args.reason Optional reason for approval.
|
|
837
|
+
* @returns The messageId of the saved approval response message.
|
|
838
|
+
*/
|
|
839
|
+
approveToolCall(ctx: MutationCtx, args: {
|
|
840
|
+
threadId: string;
|
|
841
|
+
approvalId: string;
|
|
842
|
+
reason?: string;
|
|
843
|
+
}): Promise<{
|
|
844
|
+
messageId: string;
|
|
845
|
+
}>;
|
|
846
|
+
/**
|
|
847
|
+
* Deny a tool call that requires human approval.
|
|
848
|
+
* Saves a `tool-approval-response` message to the thread.
|
|
849
|
+
* After calling this, call `agent.streamText` or `agent.generateText`
|
|
850
|
+
* with `promptMessageId` set to the returned `messageId` to continue
|
|
851
|
+
* generation — the AI SDK will automatically create an `execution-denied`
|
|
852
|
+
* result and let the model respond accordingly.
|
|
853
|
+
*
|
|
854
|
+
* @param ctx A ctx object from a mutation.
|
|
855
|
+
* @param args.threadId The thread containing the tool call.
|
|
856
|
+
* @param args.approvalId The approval ID from the tool-approval-request part.
|
|
857
|
+
* @param args.reason Optional reason for denial.
|
|
858
|
+
* @returns The messageId of the saved denial response message.
|
|
859
|
+
*/
|
|
860
|
+
denyToolCall(ctx: MutationCtx, args: {
|
|
861
|
+
threadId: string;
|
|
862
|
+
approvalId: string;
|
|
863
|
+
reason?: string;
|
|
864
|
+
}): Promise<{
|
|
865
|
+
messageId: string;
|
|
866
|
+
}>;
|
|
867
|
+
private respondToToolCallApproval;
|
|
868
|
+
private getApprovalRequestMessageId;
|
|
677
869
|
/**
|
|
678
870
|
* Explicitly save a "step" created by the AI SDK.
|
|
679
871
|
* @param ctx The ctx argument to a mutation or action.
|
|
@@ -702,7 +894,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
702
894
|
provider?: string;
|
|
703
895
|
}): Promise<{
|
|
704
896
|
messages: MessageDoc[];
|
|
705
|
-
pending?: MessageDoc;
|
|
706
897
|
}>;
|
|
707
898
|
/**
|
|
708
899
|
* Manually save the result of a generateObject call to the thread.
|
|
@@ -719,7 +910,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
719
910
|
provider: string | undefined;
|
|
720
911
|
result: GenerateObjectResult<unknown>;
|
|
721
912
|
metadata?: Omit<MessageWithMetadata, "message">;
|
|
722
|
-
}): Promise<
|
|
913
|
+
}): Promise<{
|
|
914
|
+
messages: MessageDoc[];
|
|
915
|
+
}>;
|
|
723
916
|
/**
|
|
724
917
|
* Commit or rollback a message that was pending.
|
|
725
918
|
* This is done automatically when saving messages by default.
|
|
@@ -728,14 +921,13 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
728
921
|
* @param args What message to save. Generally the parent message sent into
|
|
729
922
|
* the generateText call.
|
|
730
923
|
*/
|
|
731
|
-
|
|
732
|
-
threadId: string;
|
|
924
|
+
finalizeMessage(ctx: MutationCtx | ActionCtx, args: {
|
|
733
925
|
messageId: string;
|
|
734
926
|
result: {
|
|
735
|
-
|
|
927
|
+
status: "failed";
|
|
736
928
|
error: string;
|
|
737
929
|
} | {
|
|
738
|
-
|
|
930
|
+
status: "success";
|
|
739
931
|
};
|
|
740
932
|
}): Promise<void>;
|
|
741
933
|
/**
|
|
@@ -743,14 +935,12 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
743
935
|
* @param ctx The ctx argument to your mutation or action.
|
|
744
936
|
* @param args The message fields to update.
|
|
745
937
|
*/
|
|
746
|
-
updateMessage(ctx:
|
|
938
|
+
updateMessage(ctx: MutationCtx | ActionCtx, args: {
|
|
747
939
|
/** The id of the message to update. */
|
|
748
940
|
messageId: string;
|
|
749
941
|
patch: {
|
|
750
942
|
/** The message to replace the existing message. */
|
|
751
|
-
message:
|
|
752
|
-
id?: string;
|
|
753
|
-
}) | Message;
|
|
943
|
+
message: ModelMessage | Message;
|
|
754
944
|
/** The status to set on the message. */
|
|
755
945
|
status: "success" | "error";
|
|
756
946
|
/** The error message to set on the message. */
|
|
@@ -774,7 +964,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
774
964
|
* @param ctx The ctx argument to your mutation or action.
|
|
775
965
|
* @param args The ids of the messages to delete.
|
|
776
966
|
*/
|
|
777
|
-
deleteMessages(ctx:
|
|
967
|
+
deleteMessages(ctx: MutationCtx | ActionCtx, args: {
|
|
778
968
|
messageIds: string[];
|
|
779
969
|
}): Promise<void>;
|
|
780
970
|
/**
|
|
@@ -783,7 +973,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
783
973
|
* @param ctx The ctx argument to your mutation or action.
|
|
784
974
|
* @param args The id of the message to delete.
|
|
785
975
|
*/
|
|
786
|
-
deleteMessage(ctx:
|
|
976
|
+
deleteMessage(ctx: MutationCtx | ActionCtx, args: {
|
|
787
977
|
messageId: string;
|
|
788
978
|
}): Promise<void>;
|
|
789
979
|
/**
|
|
@@ -823,7 +1013,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
823
1013
|
* @param ctx The ctx argument to your mutation or action.
|
|
824
1014
|
* @param args The range of messages to delete.
|
|
825
1015
|
*/
|
|
826
|
-
deleteMessageRange(ctx:
|
|
1016
|
+
deleteMessageRange(ctx: MutationCtx | ActionCtx, args: {
|
|
827
1017
|
threadId: string;
|
|
828
1018
|
startOrder: number;
|
|
829
1019
|
startStepOrder?: number;
|
|
@@ -841,7 +1031,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
841
1031
|
* @param ctx The ctx argument to your mutation or action.
|
|
842
1032
|
* @param args The id of the thread to delete and optionally the page size to use for the delete.
|
|
843
1033
|
*/
|
|
844
|
-
deleteThreadAsync(ctx:
|
|
1034
|
+
deleteThreadAsync(ctx: MutationCtx | ActionCtx, args: {
|
|
845
1035
|
threadId: string;
|
|
846
1036
|
pageSize?: number;
|
|
847
1037
|
}): Promise<void>;
|
|
@@ -852,53 +1042,10 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
852
1042
|
* @param ctx The ctx argument to your action.
|
|
853
1043
|
* @param args The id of the thread to delete and optionally the page size to use for the delete.
|
|
854
1044
|
*/
|
|
855
|
-
deleteThreadSync(ctx:
|
|
1045
|
+
deleteThreadSync(ctx: ActionCtx, args: {
|
|
856
1046
|
threadId: string;
|
|
857
1047
|
pageSize?: number;
|
|
858
1048
|
}): 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
1049
|
/**
|
|
903
1050
|
* WORKFLOW UTILITIES
|
|
904
1051
|
*/
|
|
@@ -933,23 +1080,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
933
1080
|
* @param spec Configuration for the agent acting as an action, including
|
|
934
1081
|
* {@link ContextOptions}, {@link StorageOptions}, and {@link stopWhen}.
|
|
935
1082
|
*/
|
|
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;
|
|
1083
|
+
asTextAction<DataModel extends GenericDataModel>(spec: MaybeCustomCtx<CustomCtx, DataModel, AgentTools> & {
|
|
953
1084
|
/**
|
|
954
1085
|
* Whether to stream the text.
|
|
955
1086
|
* If false, it will generate the text in a single call. (default)
|
|
@@ -958,51 +1089,38 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
958
1089
|
* defaults if you pass true.
|
|
959
1090
|
*/
|
|
960
1091
|
stream?: boolean | StreamingOptions;
|
|
961
|
-
} & (CustomCtx extends Record<string, unknown> ? {
|
|
962
1092
|
/**
|
|
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
|
|
1093
|
+
* When to stop generating text.
|
|
1094
|
+
* Defaults to the {@link Agent["options"].stopWhen} option.
|
|
977
1095
|
*/
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
threadId?: string | undefined;
|
|
981
|
-
}, llmArgs: TextArgs<AgentTools>) => CustomCtx;
|
|
982
|
-
} : {
|
|
983
|
-
customCtx?: never;
|
|
984
|
-
})): import("convex/server").RegisteredAction<"internal", {
|
|
1096
|
+
stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
|
|
1097
|
+
} & Options, overrides?: CallSettings): import("convex/server").RegisteredAction<"internal", {
|
|
985
1098
|
userId?: string | undefined;
|
|
986
1099
|
threadId?: string | undefined;
|
|
987
1100
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
988
1101
|
system?: string | undefined;
|
|
1102
|
+
prompt?: string | undefined;
|
|
989
1103
|
messages?: ({
|
|
990
1104
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
991
1105
|
role: "user";
|
|
992
1106
|
content: string | ({
|
|
993
1107
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1108
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
994
1109
|
type: "text";
|
|
995
1110
|
text: string;
|
|
996
1111
|
} | {
|
|
997
1112
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1113
|
+
mediaType?: string | undefined;
|
|
998
1114
|
mimeType?: string | undefined;
|
|
999
1115
|
type: "image";
|
|
1000
1116
|
image: string | ArrayBuffer;
|
|
1001
1117
|
} | {
|
|
1002
1118
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1119
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1120
|
+
mediaType?: string | undefined;
|
|
1121
|
+
mimeType?: string | undefined;
|
|
1003
1122
|
filename?: string | undefined;
|
|
1004
1123
|
type: "file";
|
|
1005
|
-
mimeType: string;
|
|
1006
1124
|
data: string | ArrayBuffer;
|
|
1007
1125
|
})[];
|
|
1008
1126
|
} | {
|
|
@@ -1010,82 +1128,270 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1010
1128
|
role: "assistant";
|
|
1011
1129
|
content: string | ({
|
|
1012
1130
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1131
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1013
1132
|
type: "text";
|
|
1014
1133
|
text: string;
|
|
1015
1134
|
} | {
|
|
1016
1135
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1136
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1137
|
+
mediaType?: string | undefined;
|
|
1138
|
+
mimeType?: string | undefined;
|
|
1017
1139
|
filename?: string | undefined;
|
|
1018
1140
|
type: "file";
|
|
1019
|
-
mimeType: string;
|
|
1020
1141
|
data: string | ArrayBuffer;
|
|
1021
1142
|
} | {
|
|
1022
1143
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1144
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1023
1145
|
signature?: string | undefined;
|
|
1024
|
-
state?: "streaming" | "done" | undefined;
|
|
1025
1146
|
type: "reasoning";
|
|
1026
1147
|
text: string;
|
|
1027
1148
|
} | {
|
|
1028
1149
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1150
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1029
1151
|
type: "redacted-reasoning";
|
|
1030
1152
|
data: string;
|
|
1031
1153
|
} | {
|
|
1032
1154
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1155
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1156
|
+
args?: any;
|
|
1157
|
+
providerExecuted?: boolean | undefined;
|
|
1158
|
+
type: "tool-call";
|
|
1159
|
+
toolCallId: string;
|
|
1160
|
+
toolName: string;
|
|
1161
|
+
input: any;
|
|
1162
|
+
} | {
|
|
1163
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1164
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1165
|
+
input?: any;
|
|
1033
1166
|
providerExecuted?: boolean | undefined;
|
|
1034
1167
|
type: "tool-call";
|
|
1035
1168
|
toolCallId: string;
|
|
1036
1169
|
toolName: string;
|
|
1037
1170
|
args: any;
|
|
1038
|
-
}
|
|
1039
|
-
} | {
|
|
1040
|
-
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1041
|
-
role: "tool";
|
|
1042
|
-
content: {
|
|
1171
|
+
} | {
|
|
1043
1172
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1173
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1044
1174
|
args?: any;
|
|
1045
1175
|
providerExecuted?: boolean | undefined;
|
|
1046
|
-
|
|
1047
|
-
|
|
1176
|
+
output?: {
|
|
1177
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1048
1178
|
type: "text";
|
|
1049
|
-
|
|
1179
|
+
value: string;
|
|
1050
1180
|
} | {
|
|
1051
|
-
|
|
1052
|
-
type: "
|
|
1053
|
-
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1181
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1182
|
+
type: "json";
|
|
1183
|
+
value: any;
|
|
1184
|
+
} | {
|
|
1185
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1186
|
+
type: "error-text";
|
|
1187
|
+
value: string;
|
|
1188
|
+
} | {
|
|
1189
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1190
|
+
type: "error-json";
|
|
1191
|
+
value: any;
|
|
1192
|
+
} | {
|
|
1193
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1194
|
+
reason?: string | undefined;
|
|
1195
|
+
type: "execution-denied";
|
|
1196
|
+
} | {
|
|
1197
|
+
type: "content";
|
|
1198
|
+
value: ({
|
|
1199
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1200
|
+
type: "text";
|
|
1201
|
+
text: string;
|
|
1202
|
+
} | {
|
|
1203
|
+
type: "media";
|
|
1204
|
+
mediaType: string;
|
|
1205
|
+
data: string;
|
|
1206
|
+
} | {
|
|
1207
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1208
|
+
filename?: string | undefined;
|
|
1209
|
+
type: "file-data";
|
|
1210
|
+
mediaType: string;
|
|
1211
|
+
data: string;
|
|
1212
|
+
} | {
|
|
1213
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1214
|
+
type: "file-url";
|
|
1215
|
+
url: string;
|
|
1216
|
+
} | {
|
|
1217
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1218
|
+
type: "file-id";
|
|
1219
|
+
fileId: string | Record<string, string>;
|
|
1220
|
+
} | {
|
|
1221
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1222
|
+
type: "image-data";
|
|
1223
|
+
mediaType: string;
|
|
1224
|
+
data: string;
|
|
1225
|
+
} | {
|
|
1226
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1227
|
+
type: "image-url";
|
|
1228
|
+
url: string;
|
|
1229
|
+
} | {
|
|
1230
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1231
|
+
type: "image-file-id";
|
|
1232
|
+
fileId: string | Record<string, string>;
|
|
1233
|
+
} | {
|
|
1234
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1235
|
+
type: "custom";
|
|
1236
|
+
})[];
|
|
1237
|
+
} | undefined;
|
|
1238
|
+
result?: any;
|
|
1239
|
+
isError?: boolean | undefined;
|
|
1240
|
+
experimental_content?: ({
|
|
1241
|
+
type: "text";
|
|
1242
|
+
text: string;
|
|
1243
|
+
} | {
|
|
1244
|
+
mimeType?: string | undefined;
|
|
1245
|
+
type: "image";
|
|
1246
|
+
data: string;
|
|
1247
|
+
})[] | undefined;
|
|
1248
|
+
type: "tool-result";
|
|
1249
|
+
toolCallId: string;
|
|
1250
|
+
toolName: string;
|
|
1251
|
+
} | {
|
|
1252
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1253
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1254
|
+
title?: string | undefined;
|
|
1255
|
+
type: "source";
|
|
1256
|
+
id: string;
|
|
1257
|
+
url: string;
|
|
1258
|
+
sourceType: "url";
|
|
1259
|
+
} | {
|
|
1260
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1261
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1262
|
+
filename?: string | undefined;
|
|
1263
|
+
type: "source";
|
|
1264
|
+
id: string;
|
|
1265
|
+
mediaType: string;
|
|
1266
|
+
sourceType: "document";
|
|
1267
|
+
title: string;
|
|
1268
|
+
} | {
|
|
1269
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1270
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1271
|
+
type: "tool-approval-request";
|
|
1272
|
+
toolCallId: string;
|
|
1273
|
+
approvalId: string;
|
|
1274
|
+
})[];
|
|
1275
|
+
} | {
|
|
1276
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1277
|
+
role: "tool";
|
|
1278
|
+
content: ({
|
|
1279
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1280
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1281
|
+
args?: any;
|
|
1282
|
+
providerExecuted?: boolean | undefined;
|
|
1283
|
+
output?: {
|
|
1284
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1285
|
+
type: "text";
|
|
1286
|
+
value: string;
|
|
1287
|
+
} | {
|
|
1288
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1289
|
+
type: "json";
|
|
1290
|
+
value: any;
|
|
1291
|
+
} | {
|
|
1292
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1293
|
+
type: "error-text";
|
|
1294
|
+
value: string;
|
|
1295
|
+
} | {
|
|
1296
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1297
|
+
type: "error-json";
|
|
1298
|
+
value: any;
|
|
1299
|
+
} | {
|
|
1300
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1301
|
+
reason?: string | undefined;
|
|
1302
|
+
type: "execution-denied";
|
|
1303
|
+
} | {
|
|
1304
|
+
type: "content";
|
|
1305
|
+
value: ({
|
|
1306
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1307
|
+
type: "text";
|
|
1308
|
+
text: string;
|
|
1309
|
+
} | {
|
|
1310
|
+
type: "media";
|
|
1311
|
+
mediaType: string;
|
|
1312
|
+
data: string;
|
|
1313
|
+
} | {
|
|
1314
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1315
|
+
filename?: string | undefined;
|
|
1316
|
+
type: "file-data";
|
|
1317
|
+
mediaType: string;
|
|
1318
|
+
data: string;
|
|
1319
|
+
} | {
|
|
1320
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1321
|
+
type: "file-url";
|
|
1322
|
+
url: string;
|
|
1323
|
+
} | {
|
|
1324
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1325
|
+
type: "file-id";
|
|
1326
|
+
fileId: string | Record<string, string>;
|
|
1327
|
+
} | {
|
|
1328
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1329
|
+
type: "image-data";
|
|
1330
|
+
mediaType: string;
|
|
1331
|
+
data: string;
|
|
1332
|
+
} | {
|
|
1333
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1334
|
+
type: "image-url";
|
|
1335
|
+
url: string;
|
|
1336
|
+
} | {
|
|
1337
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1338
|
+
type: "image-file-id";
|
|
1339
|
+
fileId: string | Record<string, string>;
|
|
1340
|
+
} | {
|
|
1341
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1342
|
+
type: "custom";
|
|
1343
|
+
})[];
|
|
1344
|
+
} | undefined;
|
|
1345
|
+
result?: any;
|
|
1346
|
+
isError?: boolean | undefined;
|
|
1347
|
+
experimental_content?: ({
|
|
1348
|
+
type: "text";
|
|
1349
|
+
text: string;
|
|
1350
|
+
} | {
|
|
1351
|
+
mimeType?: string | undefined;
|
|
1352
|
+
type: "image";
|
|
1353
|
+
data: string;
|
|
1354
|
+
})[] | undefined;
|
|
1355
|
+
type: "tool-result";
|
|
1356
|
+
toolCallId: string;
|
|
1357
|
+
toolName: string;
|
|
1358
|
+
} | {
|
|
1359
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1360
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1361
|
+
providerExecuted?: boolean | undefined;
|
|
1362
|
+
reason?: string | undefined;
|
|
1363
|
+
type: "tool-approval-response";
|
|
1364
|
+
approvalId: string;
|
|
1365
|
+
approved: boolean;
|
|
1366
|
+
})[];
|
|
1367
|
+
} | {
|
|
1061
1368
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1062
1369
|
role: "system";
|
|
1063
1370
|
content: string;
|
|
1064
1371
|
})[] | undefined;
|
|
1065
|
-
|
|
1066
|
-
maxTokens?: number | undefined;
|
|
1067
|
-
temperature?: number | undefined;
|
|
1068
|
-
topP?: number | undefined;
|
|
1069
|
-
topK?: number | undefined;
|
|
1070
|
-
presencePenalty?: number | undefined;
|
|
1071
|
-
frequencyPenalty?: number | undefined;
|
|
1072
|
-
seed?: number | undefined;
|
|
1073
|
-
maxRetries?: number | undefined;
|
|
1074
|
-
stream?: boolean | undefined;
|
|
1075
|
-
toolChoice?: "required" | "none" | "auto" | {
|
|
1372
|
+
toolChoice?: "none" | "required" | "auto" | {
|
|
1076
1373
|
type: "tool";
|
|
1077
1374
|
toolName: string;
|
|
1078
1375
|
} | undefined;
|
|
1079
|
-
maxSteps?: number | undefined;
|
|
1080
|
-
experimental_continueSteps?: boolean | undefined;
|
|
1081
|
-
prompt?: string | undefined;
|
|
1082
1376
|
promptMessageId?: string | undefined;
|
|
1377
|
+
callSettings?: {
|
|
1378
|
+
maxOutputTokens?: number | undefined;
|
|
1379
|
+
temperature?: number | undefined;
|
|
1380
|
+
topP?: number | undefined;
|
|
1381
|
+
topK?: number | undefined;
|
|
1382
|
+
presencePenalty?: number | undefined;
|
|
1383
|
+
frequencyPenalty?: number | undefined;
|
|
1384
|
+
stopSequences?: string[] | undefined;
|
|
1385
|
+
seed?: number | undefined;
|
|
1386
|
+
maxRetries?: number | undefined;
|
|
1387
|
+
headers?: Record<string, string> | undefined;
|
|
1388
|
+
} | undefined;
|
|
1083
1389
|
contextOptions?: {
|
|
1084
1390
|
excludeToolMessages?: boolean | undefined;
|
|
1085
1391
|
recentMessages?: number | undefined;
|
|
1086
1392
|
searchOptions?: {
|
|
1087
|
-
textSearch?: boolean | undefined;
|
|
1088
1393
|
vectorSearch?: boolean | undefined;
|
|
1394
|
+
textSearch?: boolean | undefined;
|
|
1089
1395
|
vectorScoreThreshold?: number | undefined;
|
|
1090
1396
|
messageRange?: {
|
|
1091
1397
|
before: number;
|
|
@@ -1098,18 +1404,16 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1098
1404
|
storageOptions?: {
|
|
1099
1405
|
saveMessages?: "all" | "none" | "promptAndOutput" | undefined;
|
|
1100
1406
|
} | undefined;
|
|
1407
|
+
maxSteps?: number | undefined;
|
|
1408
|
+
stream?: boolean | undefined;
|
|
1409
|
+
experimental_continueSteps?: boolean | undefined;
|
|
1101
1410
|
}, Promise<{
|
|
1102
1411
|
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;
|
|
1412
|
+
promptMessageId: string | undefined;
|
|
1110
1413
|
order: number | undefined;
|
|
1111
|
-
finishReason: import("
|
|
1112
|
-
warnings: import("@ai-sdk/provider").
|
|
1414
|
+
finishReason: import("ai").FinishReason;
|
|
1415
|
+
warnings: import("@ai-sdk/provider").SharedV3Warning[] | undefined;
|
|
1416
|
+
savedMessageIds: string[];
|
|
1113
1417
|
}>>;
|
|
1114
1418
|
/**
|
|
1115
1419
|
* Create an action that generates an object out of this agent so you can call
|
|
@@ -1118,31 +1422,33 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1118
1422
|
* the normal parameters to {@link generateObject}, plus {@link ContextOptions}
|
|
1119
1423
|
* and stopWhen.
|
|
1120
1424
|
*/
|
|
1121
|
-
asObjectAction<T>(
|
|
1122
|
-
contextOptions?: ContextOptions;
|
|
1123
|
-
storageOptions?: StorageOptions;
|
|
1124
|
-
}): import("convex/server").RegisteredAction<"internal", {
|
|
1425
|
+
asObjectAction<T, DataModel extends GenericDataModel>(objectArgs: GenerateObjectArgs<FlexibleSchema<T>> & Partial<AgentPrompt>, options?: Options & MaybeCustomCtx<CustomCtx, DataModel, AgentTools>): import("convex/server").RegisteredAction<"internal", {
|
|
1125
1426
|
userId?: string | undefined;
|
|
1126
1427
|
threadId?: string | undefined;
|
|
1127
1428
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1128
1429
|
system?: string | undefined;
|
|
1430
|
+
prompt?: string | undefined;
|
|
1129
1431
|
messages?: ({
|
|
1130
1432
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1131
1433
|
role: "user";
|
|
1132
1434
|
content: string | ({
|
|
1133
1435
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1436
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1134
1437
|
type: "text";
|
|
1135
1438
|
text: string;
|
|
1136
1439
|
} | {
|
|
1137
1440
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1441
|
+
mediaType?: string | undefined;
|
|
1138
1442
|
mimeType?: string | undefined;
|
|
1139
1443
|
type: "image";
|
|
1140
1444
|
image: string | ArrayBuffer;
|
|
1141
1445
|
} | {
|
|
1142
1446
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1447
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1448
|
+
mediaType?: string | undefined;
|
|
1449
|
+
mimeType?: string | undefined;
|
|
1143
1450
|
filename?: string | undefined;
|
|
1144
1451
|
type: "file";
|
|
1145
|
-
mimeType: string;
|
|
1146
1452
|
data: string | ArrayBuffer;
|
|
1147
1453
|
})[];
|
|
1148
1454
|
} | {
|
|
@@ -1150,39 +1456,221 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1150
1456
|
role: "assistant";
|
|
1151
1457
|
content: string | ({
|
|
1152
1458
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1459
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1153
1460
|
type: "text";
|
|
1154
1461
|
text: string;
|
|
1155
1462
|
} | {
|
|
1156
1463
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1464
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1465
|
+
mediaType?: string | undefined;
|
|
1466
|
+
mimeType?: string | undefined;
|
|
1157
1467
|
filename?: string | undefined;
|
|
1158
1468
|
type: "file";
|
|
1159
|
-
mimeType: string;
|
|
1160
1469
|
data: string | ArrayBuffer;
|
|
1161
1470
|
} | {
|
|
1162
1471
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1472
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1163
1473
|
signature?: string | undefined;
|
|
1164
|
-
state?: "streaming" | "done" | undefined;
|
|
1165
1474
|
type: "reasoning";
|
|
1166
1475
|
text: string;
|
|
1167
1476
|
} | {
|
|
1168
1477
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1478
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1169
1479
|
type: "redacted-reasoning";
|
|
1170
1480
|
data: string;
|
|
1171
1481
|
} | {
|
|
1172
1482
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1483
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1484
|
+
args?: any;
|
|
1485
|
+
providerExecuted?: boolean | undefined;
|
|
1486
|
+
type: "tool-call";
|
|
1487
|
+
toolCallId: string;
|
|
1488
|
+
toolName: string;
|
|
1489
|
+
input: any;
|
|
1490
|
+
} | {
|
|
1491
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1492
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1493
|
+
input?: any;
|
|
1173
1494
|
providerExecuted?: boolean | undefined;
|
|
1174
1495
|
type: "tool-call";
|
|
1175
1496
|
toolCallId: string;
|
|
1176
1497
|
toolName: string;
|
|
1177
1498
|
args: any;
|
|
1499
|
+
} | {
|
|
1500
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1501
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1502
|
+
args?: any;
|
|
1503
|
+
providerExecuted?: boolean | undefined;
|
|
1504
|
+
output?: {
|
|
1505
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1506
|
+
type: "text";
|
|
1507
|
+
value: string;
|
|
1508
|
+
} | {
|
|
1509
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1510
|
+
type: "json";
|
|
1511
|
+
value: any;
|
|
1512
|
+
} | {
|
|
1513
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1514
|
+
type: "error-text";
|
|
1515
|
+
value: string;
|
|
1516
|
+
} | {
|
|
1517
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1518
|
+
type: "error-json";
|
|
1519
|
+
value: any;
|
|
1520
|
+
} | {
|
|
1521
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1522
|
+
reason?: string | undefined;
|
|
1523
|
+
type: "execution-denied";
|
|
1524
|
+
} | {
|
|
1525
|
+
type: "content";
|
|
1526
|
+
value: ({
|
|
1527
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1528
|
+
type: "text";
|
|
1529
|
+
text: string;
|
|
1530
|
+
} | {
|
|
1531
|
+
type: "media";
|
|
1532
|
+
mediaType: string;
|
|
1533
|
+
data: string;
|
|
1534
|
+
} | {
|
|
1535
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1536
|
+
filename?: string | undefined;
|
|
1537
|
+
type: "file-data";
|
|
1538
|
+
mediaType: string;
|
|
1539
|
+
data: string;
|
|
1540
|
+
} | {
|
|
1541
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1542
|
+
type: "file-url";
|
|
1543
|
+
url: string;
|
|
1544
|
+
} | {
|
|
1545
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1546
|
+
type: "file-id";
|
|
1547
|
+
fileId: string | Record<string, string>;
|
|
1548
|
+
} | {
|
|
1549
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1550
|
+
type: "image-data";
|
|
1551
|
+
mediaType: string;
|
|
1552
|
+
data: string;
|
|
1553
|
+
} | {
|
|
1554
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1555
|
+
type: "image-url";
|
|
1556
|
+
url: string;
|
|
1557
|
+
} | {
|
|
1558
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1559
|
+
type: "image-file-id";
|
|
1560
|
+
fileId: string | Record<string, string>;
|
|
1561
|
+
} | {
|
|
1562
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1563
|
+
type: "custom";
|
|
1564
|
+
})[];
|
|
1565
|
+
} | undefined;
|
|
1566
|
+
result?: any;
|
|
1567
|
+
isError?: boolean | undefined;
|
|
1568
|
+
experimental_content?: ({
|
|
1569
|
+
type: "text";
|
|
1570
|
+
text: string;
|
|
1571
|
+
} | {
|
|
1572
|
+
mimeType?: string | undefined;
|
|
1573
|
+
type: "image";
|
|
1574
|
+
data: string;
|
|
1575
|
+
})[] | undefined;
|
|
1576
|
+
type: "tool-result";
|
|
1577
|
+
toolCallId: string;
|
|
1578
|
+
toolName: string;
|
|
1579
|
+
} | {
|
|
1580
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1581
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1582
|
+
title?: string | undefined;
|
|
1583
|
+
type: "source";
|
|
1584
|
+
id: string;
|
|
1585
|
+
url: string;
|
|
1586
|
+
sourceType: "url";
|
|
1587
|
+
} | {
|
|
1588
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1589
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1590
|
+
filename?: string | undefined;
|
|
1591
|
+
type: "source";
|
|
1592
|
+
id: string;
|
|
1593
|
+
mediaType: string;
|
|
1594
|
+
sourceType: "document";
|
|
1595
|
+
title: string;
|
|
1596
|
+
} | {
|
|
1597
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1598
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1599
|
+
type: "tool-approval-request";
|
|
1600
|
+
toolCallId: string;
|
|
1601
|
+
approvalId: string;
|
|
1178
1602
|
})[];
|
|
1179
1603
|
} | {
|
|
1180
1604
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1181
1605
|
role: "tool";
|
|
1182
|
-
content: {
|
|
1606
|
+
content: ({
|
|
1183
1607
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1608
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1184
1609
|
args?: any;
|
|
1185
1610
|
providerExecuted?: boolean | undefined;
|
|
1611
|
+
output?: {
|
|
1612
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1613
|
+
type: "text";
|
|
1614
|
+
value: string;
|
|
1615
|
+
} | {
|
|
1616
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1617
|
+
type: "json";
|
|
1618
|
+
value: any;
|
|
1619
|
+
} | {
|
|
1620
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1621
|
+
type: "error-text";
|
|
1622
|
+
value: string;
|
|
1623
|
+
} | {
|
|
1624
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1625
|
+
type: "error-json";
|
|
1626
|
+
value: any;
|
|
1627
|
+
} | {
|
|
1628
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1629
|
+
reason?: string | undefined;
|
|
1630
|
+
type: "execution-denied";
|
|
1631
|
+
} | {
|
|
1632
|
+
type: "content";
|
|
1633
|
+
value: ({
|
|
1634
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1635
|
+
type: "text";
|
|
1636
|
+
text: string;
|
|
1637
|
+
} | {
|
|
1638
|
+
type: "media";
|
|
1639
|
+
mediaType: string;
|
|
1640
|
+
data: string;
|
|
1641
|
+
} | {
|
|
1642
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1643
|
+
filename?: string | undefined;
|
|
1644
|
+
type: "file-data";
|
|
1645
|
+
mediaType: string;
|
|
1646
|
+
data: string;
|
|
1647
|
+
} | {
|
|
1648
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1649
|
+
type: "file-url";
|
|
1650
|
+
url: string;
|
|
1651
|
+
} | {
|
|
1652
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1653
|
+
type: "file-id";
|
|
1654
|
+
fileId: string | Record<string, string>;
|
|
1655
|
+
} | {
|
|
1656
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1657
|
+
type: "image-data";
|
|
1658
|
+
mediaType: string;
|
|
1659
|
+
data: string;
|
|
1660
|
+
} | {
|
|
1661
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1662
|
+
type: "image-url";
|
|
1663
|
+
url: string;
|
|
1664
|
+
} | {
|
|
1665
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1666
|
+
type: "image-file-id";
|
|
1667
|
+
fileId: string | Record<string, string>;
|
|
1668
|
+
} | {
|
|
1669
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1670
|
+
type: "custom";
|
|
1671
|
+
})[];
|
|
1672
|
+
} | undefined;
|
|
1673
|
+
result?: any;
|
|
1186
1674
|
isError?: boolean | undefined;
|
|
1187
1675
|
experimental_content?: ({
|
|
1188
1676
|
type: "text";
|
|
@@ -1195,30 +1683,39 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1195
1683
|
type: "tool-result";
|
|
1196
1684
|
toolCallId: string;
|
|
1197
1685
|
toolName: string;
|
|
1198
|
-
|
|
1199
|
-
|
|
1686
|
+
} | {
|
|
1687
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1688
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1689
|
+
providerExecuted?: boolean | undefined;
|
|
1690
|
+
reason?: string | undefined;
|
|
1691
|
+
type: "tool-approval-response";
|
|
1692
|
+
approvalId: string;
|
|
1693
|
+
approved: boolean;
|
|
1694
|
+
})[];
|
|
1200
1695
|
} | {
|
|
1201
1696
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1202
1697
|
role: "system";
|
|
1203
1698
|
content: string;
|
|
1204
1699
|
})[] | 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
|
-
prompt?: string | undefined;
|
|
1215
1700
|
promptMessageId?: string | undefined;
|
|
1701
|
+
callSettings?: {
|
|
1702
|
+
maxOutputTokens?: number | undefined;
|
|
1703
|
+
temperature?: number | undefined;
|
|
1704
|
+
topP?: number | undefined;
|
|
1705
|
+
topK?: number | undefined;
|
|
1706
|
+
presencePenalty?: number | undefined;
|
|
1707
|
+
frequencyPenalty?: number | undefined;
|
|
1708
|
+
stopSequences?: string[] | undefined;
|
|
1709
|
+
seed?: number | undefined;
|
|
1710
|
+
maxRetries?: number | undefined;
|
|
1711
|
+
headers?: Record<string, string> | undefined;
|
|
1712
|
+
} | undefined;
|
|
1216
1713
|
contextOptions?: {
|
|
1217
1714
|
excludeToolMessages?: boolean | undefined;
|
|
1218
1715
|
recentMessages?: number | undefined;
|
|
1219
1716
|
searchOptions?: {
|
|
1220
|
-
textSearch?: boolean | undefined;
|
|
1221
1717
|
vectorSearch?: boolean | undefined;
|
|
1718
|
+
textSearch?: boolean | undefined;
|
|
1222
1719
|
vectorScoreThreshold?: number | undefined;
|
|
1223
1720
|
messageRange?: {
|
|
1224
1721
|
before: number;
|
|
@@ -1233,44 +1730,32 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1233
1730
|
} | undefined;
|
|
1234
1731
|
}, Promise<{
|
|
1235
1732
|
object: T;
|
|
1236
|
-
|
|
1733
|
+
promptMessageId: string | undefined;
|
|
1237
1734
|
order: number | undefined;
|
|
1238
|
-
finishReason: import("
|
|
1239
|
-
warnings: import("@ai-sdk/provider").
|
|
1735
|
+
finishReason: import("ai").FinishReason;
|
|
1736
|
+
warnings: import("@ai-sdk/provider").SharedV3Warning[] | undefined;
|
|
1737
|
+
savedMessageIds: string[];
|
|
1240
1738
|
}>>;
|
|
1241
1739
|
/**
|
|
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.
|
|
1740
|
+
* @deprecated Use {@link saveMessages} directly instead.
|
|
1260
1741
|
*/
|
|
1261
1742
|
asSaveMessagesMutation(): import("convex/server").RegisteredMutation<"internal", {
|
|
1262
1743
|
userId?: string | undefined;
|
|
1263
|
-
pending?: boolean | undefined;
|
|
1264
1744
|
promptMessageId?: string | undefined;
|
|
1745
|
+
embeddings?: {
|
|
1746
|
+
model: string;
|
|
1747
|
+
vectors: (number[] | null)[];
|
|
1748
|
+
} | undefined;
|
|
1265
1749
|
failPendingSteps?: boolean | undefined;
|
|
1266
1750
|
threadId: string;
|
|
1267
1751
|
messages: {
|
|
1268
|
-
id?: string | undefined;
|
|
1269
1752
|
fileIds?: string[] | undefined;
|
|
1270
1753
|
error?: string | undefined;
|
|
1754
|
+
status?: "pending" | "success" | "failed" | undefined;
|
|
1271
1755
|
model?: string | undefined;
|
|
1272
1756
|
provider?: string | undefined;
|
|
1273
1757
|
text?: string | undefined;
|
|
1758
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1274
1759
|
reasoning?: string | undefined;
|
|
1275
1760
|
usage?: {
|
|
1276
1761
|
reasoningTokens?: number | undefined;
|
|
@@ -1279,36 +1764,23 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1279
1764
|
completionTokens: number;
|
|
1280
1765
|
totalTokens: number;
|
|
1281
1766
|
} | undefined;
|
|
1282
|
-
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1283
1767
|
sources?: ({
|
|
1284
|
-
title?: string | undefined;
|
|
1285
1768
|
type?: "source" | undefined;
|
|
1286
1769
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1287
|
-
|
|
1770
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1771
|
+
title?: string | undefined;
|
|
1288
1772
|
id: string;
|
|
1773
|
+
url: string;
|
|
1289
1774
|
sourceType: "url";
|
|
1290
1775
|
} | {
|
|
1291
|
-
|
|
1776
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1292
1777
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1293
|
-
|
|
1294
|
-
title: string;
|
|
1778
|
+
filename?: string | undefined;
|
|
1295
1779
|
type: "source";
|
|
1296
|
-
|
|
1780
|
+
id: string;
|
|
1297
1781
|
mediaType: string;
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1301
|
-
signature?: string | undefined;
|
|
1302
|
-
state?: "streaming" | "done" | undefined;
|
|
1303
|
-
type: "reasoning";
|
|
1304
|
-
text: string;
|
|
1305
|
-
} | {
|
|
1306
|
-
signature?: string | undefined;
|
|
1307
|
-
type: "text";
|
|
1308
|
-
text: string;
|
|
1309
|
-
} | {
|
|
1310
|
-
type: "redacted";
|
|
1311
|
-
data: string;
|
|
1782
|
+
sourceType: "document";
|
|
1783
|
+
title: string;
|
|
1312
1784
|
})[] | undefined;
|
|
1313
1785
|
warnings?: ({
|
|
1314
1786
|
details?: string | undefined;
|
|
@@ -1323,23 +1795,41 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1323
1795
|
message: string;
|
|
1324
1796
|
})[] | undefined;
|
|
1325
1797
|
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
1798
|
+
reasoningDetails?: ({
|
|
1799
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1800
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1801
|
+
signature?: string | undefined;
|
|
1802
|
+
type: "reasoning";
|
|
1803
|
+
text: string;
|
|
1804
|
+
} | {
|
|
1805
|
+
signature?: string | undefined;
|
|
1806
|
+
type: "text";
|
|
1807
|
+
text: string;
|
|
1808
|
+
} | {
|
|
1809
|
+
type: "redacted";
|
|
1810
|
+
data: string;
|
|
1811
|
+
})[] | undefined;
|
|
1326
1812
|
message: {
|
|
1327
1813
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1328
1814
|
role: "user";
|
|
1329
1815
|
content: string | ({
|
|
1330
1816
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1817
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1331
1818
|
type: "text";
|
|
1332
1819
|
text: string;
|
|
1333
1820
|
} | {
|
|
1334
1821
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1822
|
+
mediaType?: string | undefined;
|
|
1335
1823
|
mimeType?: string | undefined;
|
|
1336
1824
|
type: "image";
|
|
1337
1825
|
image: string | ArrayBuffer;
|
|
1338
1826
|
} | {
|
|
1339
1827
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1828
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1829
|
+
mediaType?: string | undefined;
|
|
1830
|
+
mimeType?: string | undefined;
|
|
1340
1831
|
filename?: string | undefined;
|
|
1341
1832
|
type: "file";
|
|
1342
|
-
mimeType: string;
|
|
1343
1833
|
data: string | ArrayBuffer;
|
|
1344
1834
|
})[];
|
|
1345
1835
|
} | {
|
|
@@ -1347,39 +1837,221 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1347
1837
|
role: "assistant";
|
|
1348
1838
|
content: string | ({
|
|
1349
1839
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1840
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1350
1841
|
type: "text";
|
|
1351
1842
|
text: string;
|
|
1352
1843
|
} | {
|
|
1353
1844
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1845
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1846
|
+
mediaType?: string | undefined;
|
|
1847
|
+
mimeType?: string | undefined;
|
|
1354
1848
|
filename?: string | undefined;
|
|
1355
1849
|
type: "file";
|
|
1356
|
-
mimeType: string;
|
|
1357
1850
|
data: string | ArrayBuffer;
|
|
1358
1851
|
} | {
|
|
1359
1852
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1853
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1360
1854
|
signature?: string | undefined;
|
|
1361
|
-
state?: "streaming" | "done" | undefined;
|
|
1362
1855
|
type: "reasoning";
|
|
1363
1856
|
text: string;
|
|
1364
1857
|
} | {
|
|
1365
1858
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1859
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1366
1860
|
type: "redacted-reasoning";
|
|
1367
1861
|
data: string;
|
|
1368
1862
|
} | {
|
|
1369
1863
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1864
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1865
|
+
args?: any;
|
|
1866
|
+
providerExecuted?: boolean | undefined;
|
|
1867
|
+
type: "tool-call";
|
|
1868
|
+
toolCallId: string;
|
|
1869
|
+
toolName: string;
|
|
1870
|
+
input: any;
|
|
1871
|
+
} | {
|
|
1872
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1873
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1874
|
+
input?: any;
|
|
1370
1875
|
providerExecuted?: boolean | undefined;
|
|
1371
1876
|
type: "tool-call";
|
|
1372
1877
|
toolCallId: string;
|
|
1373
1878
|
toolName: string;
|
|
1374
1879
|
args: any;
|
|
1880
|
+
} | {
|
|
1881
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1882
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1883
|
+
args?: any;
|
|
1884
|
+
providerExecuted?: boolean | undefined;
|
|
1885
|
+
output?: {
|
|
1886
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1887
|
+
type: "text";
|
|
1888
|
+
value: string;
|
|
1889
|
+
} | {
|
|
1890
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1891
|
+
type: "json";
|
|
1892
|
+
value: any;
|
|
1893
|
+
} | {
|
|
1894
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1895
|
+
type: "error-text";
|
|
1896
|
+
value: string;
|
|
1897
|
+
} | {
|
|
1898
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1899
|
+
type: "error-json";
|
|
1900
|
+
value: any;
|
|
1901
|
+
} | {
|
|
1902
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1903
|
+
reason?: string | undefined;
|
|
1904
|
+
type: "execution-denied";
|
|
1905
|
+
} | {
|
|
1906
|
+
type: "content";
|
|
1907
|
+
value: ({
|
|
1908
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1909
|
+
type: "text";
|
|
1910
|
+
text: string;
|
|
1911
|
+
} | {
|
|
1912
|
+
type: "media";
|
|
1913
|
+
mediaType: string;
|
|
1914
|
+
data: string;
|
|
1915
|
+
} | {
|
|
1916
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1917
|
+
filename?: string | undefined;
|
|
1918
|
+
type: "file-data";
|
|
1919
|
+
mediaType: string;
|
|
1920
|
+
data: string;
|
|
1921
|
+
} | {
|
|
1922
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1923
|
+
type: "file-url";
|
|
1924
|
+
url: string;
|
|
1925
|
+
} | {
|
|
1926
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1927
|
+
type: "file-id";
|
|
1928
|
+
fileId: string | Record<string, string>;
|
|
1929
|
+
} | {
|
|
1930
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1931
|
+
type: "image-data";
|
|
1932
|
+
mediaType: string;
|
|
1933
|
+
data: string;
|
|
1934
|
+
} | {
|
|
1935
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1936
|
+
type: "image-url";
|
|
1937
|
+
url: string;
|
|
1938
|
+
} | {
|
|
1939
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1940
|
+
type: "image-file-id";
|
|
1941
|
+
fileId: string | Record<string, string>;
|
|
1942
|
+
} | {
|
|
1943
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1944
|
+
type: "custom";
|
|
1945
|
+
})[];
|
|
1946
|
+
} | undefined;
|
|
1947
|
+
result?: any;
|
|
1948
|
+
isError?: boolean | undefined;
|
|
1949
|
+
experimental_content?: ({
|
|
1950
|
+
type: "text";
|
|
1951
|
+
text: string;
|
|
1952
|
+
} | {
|
|
1953
|
+
mimeType?: string | undefined;
|
|
1954
|
+
type: "image";
|
|
1955
|
+
data: string;
|
|
1956
|
+
})[] | undefined;
|
|
1957
|
+
type: "tool-result";
|
|
1958
|
+
toolCallId: string;
|
|
1959
|
+
toolName: string;
|
|
1960
|
+
} | {
|
|
1961
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1962
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1963
|
+
title?: string | undefined;
|
|
1964
|
+
type: "source";
|
|
1965
|
+
id: string;
|
|
1966
|
+
url: string;
|
|
1967
|
+
sourceType: "url";
|
|
1968
|
+
} | {
|
|
1969
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1970
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1971
|
+
filename?: string | undefined;
|
|
1972
|
+
type: "source";
|
|
1973
|
+
id: string;
|
|
1974
|
+
mediaType: string;
|
|
1975
|
+
sourceType: "document";
|
|
1976
|
+
title: string;
|
|
1977
|
+
} | {
|
|
1978
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1979
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1980
|
+
type: "tool-approval-request";
|
|
1981
|
+
toolCallId: string;
|
|
1982
|
+
approvalId: string;
|
|
1375
1983
|
})[];
|
|
1376
1984
|
} | {
|
|
1377
1985
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1378
1986
|
role: "tool";
|
|
1379
|
-
content: {
|
|
1987
|
+
content: ({
|
|
1380
1988
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1989
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
1381
1990
|
args?: any;
|
|
1382
1991
|
providerExecuted?: boolean | undefined;
|
|
1992
|
+
output?: {
|
|
1993
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1994
|
+
type: "text";
|
|
1995
|
+
value: string;
|
|
1996
|
+
} | {
|
|
1997
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1998
|
+
type: "json";
|
|
1999
|
+
value: any;
|
|
2000
|
+
} | {
|
|
2001
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2002
|
+
type: "error-text";
|
|
2003
|
+
value: string;
|
|
2004
|
+
} | {
|
|
2005
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2006
|
+
type: "error-json";
|
|
2007
|
+
value: any;
|
|
2008
|
+
} | {
|
|
2009
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2010
|
+
reason?: string | undefined;
|
|
2011
|
+
type: "execution-denied";
|
|
2012
|
+
} | {
|
|
2013
|
+
type: "content";
|
|
2014
|
+
value: ({
|
|
2015
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2016
|
+
type: "text";
|
|
2017
|
+
text: string;
|
|
2018
|
+
} | {
|
|
2019
|
+
type: "media";
|
|
2020
|
+
mediaType: string;
|
|
2021
|
+
data: string;
|
|
2022
|
+
} | {
|
|
2023
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2024
|
+
filename?: string | undefined;
|
|
2025
|
+
type: "file-data";
|
|
2026
|
+
mediaType: string;
|
|
2027
|
+
data: string;
|
|
2028
|
+
} | {
|
|
2029
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2030
|
+
type: "file-url";
|
|
2031
|
+
url: string;
|
|
2032
|
+
} | {
|
|
2033
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2034
|
+
type: "file-id";
|
|
2035
|
+
fileId: string | Record<string, string>;
|
|
2036
|
+
} | {
|
|
2037
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2038
|
+
type: "image-data";
|
|
2039
|
+
mediaType: string;
|
|
2040
|
+
data: string;
|
|
2041
|
+
} | {
|
|
2042
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2043
|
+
type: "image-url";
|
|
2044
|
+
url: string;
|
|
2045
|
+
} | {
|
|
2046
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2047
|
+
type: "image-file-id";
|
|
2048
|
+
fileId: string | Record<string, string>;
|
|
2049
|
+
} | {
|
|
2050
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2051
|
+
type: "custom";
|
|
2052
|
+
})[];
|
|
2053
|
+
} | undefined;
|
|
2054
|
+
result?: any;
|
|
1383
2055
|
isError?: boolean | undefined;
|
|
1384
2056
|
experimental_content?: ({
|
|
1385
2057
|
type: "text";
|
|
@@ -1392,8 +2064,15 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1392
2064
|
type: "tool-result";
|
|
1393
2065
|
toolCallId: string;
|
|
1394
2066
|
toolName: string;
|
|
1395
|
-
|
|
1396
|
-
|
|
2067
|
+
} | {
|
|
2068
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
2069
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
2070
|
+
providerExecuted?: boolean | undefined;
|
|
2071
|
+
reason?: string | undefined;
|
|
2072
|
+
type: "tool-approval-response";
|
|
2073
|
+
approvalId: string;
|
|
2074
|
+
approved: boolean;
|
|
2075
|
+
})[];
|
|
1397
2076
|
} | {
|
|
1398
2077
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
1399
2078
|
role: "system";
|
|
@@ -1402,552 +2081,11 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
|
|
|
1402
2081
|
}[];
|
|
1403
2082
|
}, Promise<{
|
|
1404
2083
|
lastMessageId: string;
|
|
1405
|
-
|
|
2084
|
+
messages: {
|
|
2085
|
+
_id: string;
|
|
2086
|
+
order: number;
|
|
2087
|
+
stepOrder: number;
|
|
2088
|
+
}[];
|
|
1406
2089
|
}>>;
|
|
1407
2090
|
}
|
|
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
2091
|
//# sourceMappingURL=index.d.ts.map
|