@convex-dev/agent
Version:
A agent component for Convex.
184 lines • 6.73 kB
TypeScript
import type { AgentComponent, ContextOptions, RunActionCtx, RunQueryCtx } from "./types.js";
import type { MessageDoc } from "../component/schema.js";
import type { EmbeddingModel, LanguageModel, ModelMessage } from "ai";
import type { Message } from "../validators.js";
export type GetEmbedding = (text: string) => Promise<{
embedding: number[];
textEmbeddingModel: string | EmbeddingModel<string>;
}>;
/**
* Fetch the context messages for a thread.
* @param ctx Either a query, mutation, or action ctx.
* If it is not an action context, you can't do text or
* vector search.
* @param args The associated thread, user, message
* @returns
*/
export declare function fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, component: AgentComponent, args: {
userId: string | undefined;
threadId: string | undefined;
messages: (ModelMessage | Message)[];
/**
* If provided, it will search for messages up to and including this message.
* Note: if this is far in the past, text and vector search results may be more
* limited, as it's post-filtering the results.
*/
upToAndIncludingMessageId?: string;
contextOptions: ContextOptions;
getEmbedding?: GetEmbedding;
}): Promise<MessageDoc[]>;
/**
* Filter out tool messages that don't have both a tool call and response.
* @param docs The messages to filter.
* @returns The filtered messages.
*/
export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
id?: string | undefined;
userId?: string | undefined;
embeddingId?: string | undefined;
fileIds?: string[] | undefined;
error?: string | undefined;
agentName?: string | undefined;
model?: string | undefined;
provider?: string | undefined;
providerOptions?: Record<string, Record<string, any>> | undefined;
message?: {
providerOptions?: Record<string, Record<string, any>> | undefined;
role: "user";
content: string | ({
providerOptions?: Record<string, Record<string, any>> | undefined;
type: "text";
text: string;
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
mimeType?: string | undefined;
type: "image";
image: string | ArrayBuffer;
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
filename?: string | undefined;
type: "file";
mimeType: string;
data: string | ArrayBuffer;
})[];
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
role: "assistant";
content: string | ({
providerOptions?: Record<string, Record<string, any>> | undefined;
type: "text";
text: string;
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
filename?: string | undefined;
type: "file";
mimeType: string;
data: string | ArrayBuffer;
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
signature?: string | undefined;
state?: "streaming" | "done" | undefined;
type: "reasoning";
text: string;
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
type: "redacted-reasoning";
data: string;
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
providerExecuted?: boolean | undefined;
type: "tool-call";
toolCallId: string;
toolName: string;
args: any;
})[];
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
role: "tool";
content: {
providerOptions?: Record<string, Record<string, any>> | undefined;
args?: any;
providerExecuted?: boolean | undefined;
isError?: boolean | undefined;
experimental_content?: ({
type: "text";
text: string;
} | {
mimeType?: string | undefined;
type: "image";
data: string;
})[] | undefined;
type: "tool-result";
toolCallId: string;
toolName: string;
result: any;
}[];
} | {
providerOptions?: Record<string, Record<string, any>> | undefined;
role: "system";
content: string;
} | undefined;
text?: string | undefined;
reasoning?: string | undefined;
usage?: {
reasoningTokens?: number | undefined;
cachedInputTokens?: number | undefined;
promptTokens: number;
completionTokens: number;
totalTokens: number;
} | undefined;
providerMetadata?: Record<string, Record<string, any>> | undefined;
sources?: ({
title?: string | undefined;
type?: "source" | undefined;
providerOptions?: Record<string, Record<string, any>> | undefined;
id: string;
sourceType: "url";
url: string;
} | {
filename?: string | undefined;
providerMetadata?: Record<string, Record<string, any>> | undefined;
id: string;
title: string;
type: "source";
sourceType: "document";
mediaType: string;
})[] | undefined;
warnings?: ({
details?: string | undefined;
type: "unsupported-setting";
setting: string;
} | {
details?: string | undefined;
type: "unsupported-tool";
tool: any;
} | {
type: "other";
message: string;
})[] | undefined;
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
reasoningDetails?: ({
providerOptions?: Record<string, Record<string, any>> | undefined;
signature?: string | undefined;
state?: "streaming" | "done" | undefined;
type: "reasoning";
text: string;
} | {
signature?: string | undefined;
type: "text";
text: string;
} | {
type: "redacted";
data: string;
})[] | undefined;
_id: string;
_creationTime: number;
status: "pending" | "success" | "failed";
order: number;
threadId: string;
stepOrder: number;
tool: boolean;
}[];
export declare function getModelName(embeddingModel: string | EmbeddingModel<string> | LanguageModel): string;
export declare function getProviderName(embeddingModel: string | EmbeddingModel<string> | LanguageModel): string;
//# sourceMappingURL=search.d.ts.map