import { CancelablePromise, LogEventRequest as ApiLogEventRequest, CompletionResponse as ApiCompletionResponse, } from "./generated"; import { AgentConfig } from "./AgentConfig"; export type AgentInitOptions = { config: Partial; client: string; }; export type CompletionRequest = { filepath: string; language: string; text: string; position: number; maxPrefixLines: number; maxSuffixLines: number; }; export type CompletionResponse = ApiCompletionResponse; export type LogEventRequest = ApiLogEventRequest; export type AgentStatus = "notInitialized" | "ready" | "disconnected" | "unauthorized"; export interface AgentFunction { initialize(options: Partial): Promise; updateConfig(config: Partial): Promise; getConfig(): AgentConfig; getStatus(): AgentStatus; /** * @returns string auth url if AgentStatus is `unauthorized`, null otherwise * @throws Error if agent is not initialized */ startAuth(): CancelablePromise; /** * @param request * @returns * @throws Error if agent is not initialized */ getCompletions(request: CompletionRequest): CancelablePromise; /** * @param event * @returns * @throws Error if agent is not initialized */ postEvent(event: LogEventRequest): CancelablePromise; } export type StatusChangedEvent = { event: "statusChanged"; status: AgentStatus; }; export type ConfigUpdatedEvent = { event: "configUpdated"; config: AgentConfig; }; export type AgentEvent = StatusChangedEvent | ConfigUpdatedEvent; export const agentEventNames: AgentEvent["event"][] = ["statusChanged", "configUpdated"]; export interface AgentEventEmitter { on(eventName: T["event"], callback: (event: T) => void): this; } export type Agent = AgentFunction & AgentEventEmitter;