UNPKG

@convex-dev/agent

Version:

A agent component for Convex.

57 lines 2.43 kB
import { type ChunkDetector, type StreamTextTransform, type ToolSet } from "ai"; import type { ProviderOptions, TextStreamPart } from "../validators.js"; import type { AgentComponent, MessageDoc } from "./index.js"; import type { RunActionCtx } from "./types.js"; export type StreamingOptions = { /** * The minimum granularity of deltas to save. * Note: this is not a guarantee that every delta will be exactly one line. * E.g. if "line" is specified, it won't save any deltas until it encounters * a newline character. * Defaults to a regex that chunks by punctuation followed by whitespace. */ chunking?: "word" | "line" | RegExp | ChunkDetector; /** * The minimum number of milliseconds to wait between saving deltas. * Defaults to 250. */ throttleMs?: number; }; export declare const DEFAULT_STREAMING_OPTIONS: { chunking: RegExp; throttleMs: number; }; export declare function mergeTransforms<TOOLS extends ToolSet>(options: StreamingOptions | boolean | undefined, existing: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>> | undefined): StreamTextTransform<TOOLS> | StreamTextTransform<TOOLS>[] | undefined; export declare class DeltaStreamer { #private; readonly component: AgentComponent; readonly ctx: RunActionCtx; readonly metadata: { threadId: string; agentName: string | undefined; model: string | undefined; provider: string | undefined; providerOptions: ProviderOptions | undefined; userId: string | undefined; order: number | undefined; stepOrder: number | undefined; abortSignal: AbortSignal | undefined; }; streamId: string | undefined; readonly options: Required<StreamingOptions>; abortController: AbortController; constructor(component: AgentComponent, ctx: RunActionCtx, options: true | StreamingOptions, metadata: { threadId: string; agentName: string | undefined; model: string | undefined; provider: string | undefined; providerOptions: ProviderOptions | undefined; userId: string | undefined; order: number | undefined; stepOrder: number | undefined; abortSignal: AbortSignal | undefined; }); addParts(parts: TextStreamPart[]): Promise<void>; finish(messages: MessageDoc[]): Promise<void>; } //# sourceMappingURL=streaming.d.ts.map