UNPKG

@autobe/agent

Version:

AI backend server code generator

53 lines (52 loc) 2.01 kB
import { MicroAgentica, MicroAgenticaHistory } from "@agentica/core"; import { AutoBeTimeoutError } from "./AutoBeTimeoutError"; /** * Wraps LLM conversation with timeout enforcement and discriminated result * types. * * Prevents hanging indefinitely when LLM APIs become unresponsive or requests * take excessively long. Uses AbortController to cancel in-flight requests when * timeout expires. Returns discriminated union enabling callers to handle * success/timeout/error cases separately. * * @author Samchon */ export declare namespace TimedConversation { /** Configuration for timed conversation execution. */ interface IProps { /** MicroAgentica agent to execute conversation */ agent: MicroAgentica; /** User message to send */ message: string; /** Timeout in milliseconds, or null for no timeout */ timeout: number | null; } /** Discriminated union of possible conversation outcomes. */ type IResult = ISuccessResult | ITimeoutResult | IErrorResult; /** Successful conversation completion. */ interface ISuccessResult { type: "success"; histories: MicroAgenticaHistory[]; } /** Conversation exceeded timeout limit. */ interface ITimeoutResult { type: "timeout"; error: AutoBeTimeoutError; } /** Conversation failed with error other than timeout. */ interface IErrorResult { type: "error"; error: Error; } /** * Executes conversation with optional timeout enforcement. * * If timeout is null, executes without time limit. Otherwise, sets up timeout * handler that aborts the request and returns timeout result. Uses condition * variable for synchronization between conversation and timeout threads. * * @param props Agent, message, and timeout configuration * @returns Discriminated result indicating success, timeout, or error */ const process: (props: IProps) => Promise<IResult>; }