import { z } from "zod"; import { ChatMessageRoleEnum, FunctionCall, LanguageModelProgramExecutor, RequestOptions, ChatMessageContent, ChatMessage } from "./languageModels"; export interface NextOptions { model?: string; requestOptions?: RequestOptions; tags?: Record; stream?: boolean; } interface NextOptionsNonStreaming extends NextOptions { stream?: false; } interface NextOptionsStreaming extends NextOptions { stream: true; } export type NextFunction = (step: CortexStep) => Promise> | BrainFunction; export interface Memory> { role: ChatMessageRoleEnum; content: ChatMessageContent; name?: string; function_call?: FunctionCall; metadata?: MetaDataType; } export declare const memoryToChatMessage: (memory: Memory) => ChatMessage; interface BrainStepInit> { id?: string; parents?: string[]; tags?: Record; memories?: Memory[]; lastValue?: LastValue; processor?: LanguageModelProgramExecutor; } interface FunctionOutput { value: ProcessFunctionReturnType; memories?: Memory[]; } export type StepCommandFunction = (step: CortexStep) => Promise | string; export type StepCommand = string | StepCommandFunction; export type StreamProcessor = (step: CortexStep, stream: AsyncIterable) => AsyncIterable | Promise>; interface BrainFunctionAsCommand { name?: string; description?: string; parameters?: z.ZodSchema; process?: (step: CortexStep, response: ParsedArgumentType) => Promise> | FunctionOutput; command: StepCommand; commandRole?: ChatMessageRoleEnum; streamProcessor?: StreamProcessor; } interface BrainFunctionWithFunction { name: string; description: string; parameters: z.ZodSchema; process?: (step: CortexStep, response: ParsedArgumentType) => Promise> | FunctionOutput; command?: StepCommand; commandRole?: ChatMessageRoleEnum; streamProcessor?: StreamProcessor; } export type BrainFunction = BrainFunctionAsCommand | BrainFunctionWithFunction; export declare const memoryWithDefaultMetadata: (...memories: Memory[]) => { metadata: { timestamp: number; }; role: ChatMessageRoleEnum; content: ChatMessageContent; name?: string; function_call?: FunctionCall; }[]; export declare class CortexStep { id: string; parents: string[]; tags: Record; nextOptions?: NextOptions; readonly entityName: string; readonly memories: Memory[]; private lastValue; private processor; constructor(entityName: string, { memories, lastValue, processor, id, parents, tags }?: BrainStepInit); get value(): LastValueType; /** * Adds the given memories to the step and returns a new step (does not modify existing step) * @param memory An array of Memory instances to add. * @returns A new CortexStep instance with the added memories. */ withMemory(memory: Memory[], skipMetadata?: boolean): CortexStep; /** * Returns a new step with the memories provided by the updateFn * @param updateFn A function that takes the existing memories and returns the new memories (or a promise of the new memories) * @returns A new CortexStep instance with the new memories. */ withUpdatedMemory(updateFn: (existingMemories: Memory[]) => Memory[] | Promise): Promise>; /** * Adds the given thought to the step as a new memory and returns a new step (does not modify existing step) * @param narrative a narrative phrase like "Samantha thought: This is getting out of control, I need to leave." * @returns A new CortexStep instance with the added memories. */ withMonologue(narrative: string): CortexStep; toString(): string; private stepCommandToString; private memoriesWithCommandString; private executeNextCommand; private executeStreamingNext; private streamingNext; /** * compute is very similar to #next, but returns only a value, and NOT a new CortexStep with new memories. * Nothing is modified on this CortexStep. */ compute(functionFactory: NextFunction, opts?: NextOptions): Promise; /** * next is used to execute CognitiveFunctions on this CortexStep. * @param functionFactory - A factory function that returns a cognitive function. * @param opts - An optional parameter that can be used to pass per request options and tags * @returns - Returns a Promise that resolves to a CortexStep object. */ next(functionFactory: NextFunction, opts?: NextOptionsNonStreaming): Promise : CortexStep>; next(functionFactory: NextFunction, opts?: NextOptionsStreaming): Promise<{ nextStep: Promise : CortexStep>; stream: AsyncIterable; }>; private nonStreamingNext; } export {};