UNPKG

@convex-dev/agent

Version:

A agent component for Convex.

594 lines 23.1 kB
import { type ApiFromModules, type GenericActionCtx, type GenericDataModel, type GenericQueryCtx } from "convex/server"; import { type Agent, type AgentComponent } from "./index.js"; export type PlaygroundAPI = ApiFromModules<{ playground: ReturnType<typeof definePlaygroundAPI>; }>["playground"]; export type AgentsFn<DataModel extends GenericDataModel> = (ctx: GenericActionCtx<DataModel> | GenericQueryCtx<DataModel>, args: { userId: string | undefined; threadId: string | undefined; }) => Agent[] | Promise<Agent[]>; export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(component: AgentComponent, { agents: agentsOrFn, userNameLookup, }: { agents: Agent[] | AgentsFn<DataModel>; userNameLookup?: (ctx: GenericQueryCtx<DataModel>, userId: string) => string | Promise<string>; }): { isApiKeyValid: import("convex/server").RegisteredQuery<"public", { apiKey: string; }, Promise<boolean>>; listUsers: import("convex/server").RegisteredQuery<"public", { apiKey: string; paginationOpts: { id?: number | undefined; endCursor?: string | null | undefined; maximumRowsRead?: number | undefined; maximumBytesRead?: number | undefined; numItems: number; cursor: string | null; }; }, Promise<{ page: { _id: string; name: string; }[]; continueCursor: string; isDone: boolean; pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined; splitCursor?: string | null | undefined; }>>; listThreads: import("convex/server").RegisteredQuery<"public", { userId?: string | undefined; apiKey: string; paginationOpts: { id?: number | undefined; endCursor?: string | null | undefined; maximumRowsRead?: number | undefined; maximumBytesRead?: number | undefined; numItems: number; cursor: string | null; }; }, Promise<{ page: { lastAgentName: string | undefined; latestMessage: string | undefined; lastMessageAt: number; _creationTime: number; _id: string; status: "active" | "archived"; summary?: string | undefined; title?: string | undefined; userId?: string | undefined; }[]; continueCursor: string; isDone: boolean; pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined; splitCursor?: string | null | undefined; }>>; listMessages: import("convex/server").RegisteredQuery<"public", { threadId: string; apiKey: string; paginationOpts: { id?: number | undefined; endCursor?: string | null | undefined; maximumRowsRead?: number | undefined; maximumBytesRead?: number | undefined; numItems: number; cursor: string | null; }; }, Promise<import("convex/server").PaginationResult<{ 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; }>>>; listAgents: import("convex/server").RegisteredQuery<"public", { userId?: string | undefined; threadId?: string | undefined; apiKey: string; }, Promise<{ name: string; instructions: string | undefined; contextOptions: import("./types.js").ContextOptions | undefined; storageOptions: import("./types.js").StorageOptions | undefined; maxRetries: number | undefined; tools: string[]; }[]>>; createThread: import("convex/server").RegisteredMutation<"public", { title?: string | undefined; summary?: string | undefined; agentName?: string | undefined; userId: string; apiKey: string; }, Promise<{ threadId: string; }>>; generateText: import("convex/server").RegisteredAction<"public", { system?: string | undefined; messages?: ({ 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; prompt?: string | undefined; contextOptions?: { excludeToolMessages?: boolean | undefined; recentMessages?: number | undefined; searchOptions?: { textSearch?: boolean | undefined; vectorSearch?: boolean | undefined; vectorScoreThreshold?: number | undefined; messageRange?: { before: number; after: number; } | undefined; limit: number; } | undefined; searchOtherThreads?: boolean | undefined; } | undefined; storageOptions?: { saveMessages?: "all" | "none" | "promptAndOutput" | undefined; } | undefined; userId: string; threadId: string; agentName: string; apiKey: string; }, Promise<{ messageId: string | undefined; text: string; }>>; fetchPromptContext: import("convex/server").RegisteredAction<"public", { userId?: string | undefined; threadId?: string | undefined; beforeMessageId?: string | undefined; agentName: string; messages: ({ 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; })[]; contextOptions: { excludeToolMessages?: boolean | undefined; recentMessages?: number | undefined; searchOptions?: { textSearch?: boolean | undefined; vectorSearch?: boolean | undefined; vectorScoreThreshold?: number | undefined; messageRange?: { before: number; after: number; } | undefined; limit: number; } | undefined; searchOtherThreads?: boolean | undefined; }; apiKey: string; }, Promise<{ 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; }[]>>; }; //# sourceMappingURL=definePlaygroundAPI.d.ts.map