import { AbortSignal } from "abort-controller"; import { CortexStep } from "./cortexStep"; import { ChatMessage } from "./languageModels"; export interface Job { process: MentalProcess; newMemory: ChatMessage; abortController: AbortController; jobCompletion: { resolve: () => void; promise: Promise; }; } type ManagerOptions = { queuingStrategy: QueuingStrategy; }; /** * `MentalProcess` is a type that represents a function performing cognitive * operations. These operations could be anything from data retrieval, * processing, or AI computations. It requires an AbortSignal for handling * abort scenarios, a newMemory object for context, and lastStep which is the * last performed CortexStep. It returns a promise that resolves with a new * CortexStep. * * @typedef {(signal: AbortSignal, newMemory: ChatMessage, lastStep: CortexStep) => Promise} MentalProcess */ export type MentalProcess = (signal: AbortSignal, newMemory: ChatMessage, lastStep: CortexStep) => Promise; /** * `ProcessConfig` interface represents the configuration for a mental process. * It contains the name of the process and the process function itself. * * @interface ProcessConfig */ export interface ProcessConfig { name: string; process: MentalProcess; } /** * `QueuingStrategy` is a function type that defines how jobs are queued in the * CortexScheduler. It takes the current job, the existing queue, and the new job * and returns a modified queue. * * @typedef {(currentJob: Job | null, queue: Job[], newJob: Job) => Job[]} QueuingStrategy */ export type QueuingStrategy = (currentJob: Job | null, queue: Job[], newJob: Job) => Job[]; export declare const defaultQueuingStrategy: QueuingStrategy; /** * `CortexScheduler` is a class that manages the execution of mental processes * in a queue. It ensures that only one process runs at a time, and provides * mechanisms for process registration, dispatching, and cancellation. * * @class CortexScheduler * * @method register: Used to register a new process in the CortexScheduler. * @method dispatch: Adds a process to the queue and starts the process if * the CortexScheduler is not currently running any process. * @method run: Starts the execution of jobs in the queue. It dequeues the next * job and runs the mental process. If an error occurs, it is logged and the * next job is dequeued. */ export declare class CortexScheduler { private processQueue; private currentJob; private processes; private lastStep; private readonly queuingStrategy; private isRunning; private mutex; constructor(firstStep: CortexStep, options?: ManagerOptions); register({ name, process }: ProcessConfig): void; dispatch(name: string, newMemory: ChatMessage): Promise; private run; } export {};