UNPKG

@convex-dev/agent

Version:

A agent component for Convex.

46 lines 2.16 kB
import type { StreamTextResult, ToolSet } from "ai"; import { streamText as streamTextAi } from "ai"; import { type StreamingOptions } from "./streaming.js"; import type { ActionCtx, AgentComponent, AgentPrompt, GenerationOutputMetadata, Options } from "./types.js"; import type { Agent } from "./index.js"; /** * This behaves like {@link streamText} from the "ai" package except that * it add context based on the userId and threadId and saves the input and * resulting messages to the thread, if specified. * Use {@link continueThread} to get a version of this function already scoped * to a thread (and optionally userId). */ export declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: ActionCtx, component: AgentComponent, /** * The arguments to the streamText function, similar to the ai sdk's * {@link streamText} function, along with Agent prompt options. */ streamTextArgs: AgentPrompt & Omit<Parameters<typeof streamTextAi<TOOLS, OUTPUT, PARTIAL_OUTPUT>>[0], "model" | "prompt" | "messages"> & { /** * The tools to use for the tool calls. This will override tools specified * in the Agent constructor or createThread / continueThread. */ tools?: TOOLS; }, /** * The {@link ContextOptions} and {@link StorageOptions} * options to use for fetching contextual messages and saving input/output messages. */ options: Options & { agentName: string; userId?: string | null; threadId?: string; /** * Whether to save incremental data (deltas) from streaming responses. * Defaults to false. * If false, it will not save any deltas to the database. * If true, it will save deltas with {@link DEFAULT_STREAMING_OPTIONS}. * * Regardless of this option, when streaming you are able to use this * `streamText` function as you would with the "ai" package's version: * iterating over the text, streaming it over HTTP, etc. */ saveStreamDeltas?: boolean | StreamingOptions; agentForToolCtx?: Agent; }): Promise<StreamTextResult<TOOLS, PARTIAL_OUTPUT> & GenerationOutputMetadata>; //# sourceMappingURL=streamText.d.ts.map