UNPKG

aiwrapper

Version:

A Universal AI Wrapper for JavaScript & TypeScript

39 lines (38 loc) 1.33 kB
export type AgentState = "idle" | "running"; export interface AgentFinishedEvent<TOutput> { type: "finished"; output: TOutput; } export interface AgentErrorEvent { type: "error"; error: Error; } export interface AgentAbortedEvent<TOutput> { type: "aborted"; error: Error; partial?: TOutput; } export interface AgentStateEvent { type: "state"; state: AgentState; } export interface AgentCustomEvent<TType extends string, TData = any> { type: TType; data: TData; } export type AgentEvent<TOutput, TCustomEvents = never> = AgentFinishedEvent<TOutput> | AgentErrorEvent | AgentAbortedEvent<TOutput> | AgentStateEvent | TCustomEvents; export type AgentEventListener<TOutput, TCustomEvents = never> = (event: AgentEvent<TOutput, TCustomEvents>) => void; export declare abstract class Agent<TInput, TOutput, TCustomEvents = never> { private listeners; private _state; get state(): AgentState; subscribe(listener: AgentEventListener<TOutput, TCustomEvents>): () => void; run(input?: TInput, options?: { signal?: AbortSignal; }): Promise<TOutput>; private setState; protected emit(event: AgentEvent<TOutput, TCustomEvents>): void; protected abstract runInternal(input?: TInput, options?: { signal?: AbortSignal; }): Promise<TOutput>; }