{"version":3,"file":"chat_memory.cjs","names":["BaseMemory","ChatMessageHistory"],"sources":["../../src/memory/chat_memory.ts"],"sourcesContent":["import {\n  BaseChatMessageHistory,\n  InMemoryChatMessageHistory as ChatMessageHistory,\n} from \"@langchain/core/chat_history\";\nimport {\n  BaseMemory,\n  InputValues,\n  OutputValues,\n  getInputValue,\n  getOutputValue,\n} from \"@langchain/core/memory\";\n\n/**\n * Interface for the input parameters of the BaseChatMemory class.\n */\nexport interface BaseChatMemoryInput {\n  chatHistory?: BaseChatMessageHistory;\n  returnMessages?: boolean;\n  inputKey?: string;\n  outputKey?: string;\n}\n\n/**\n * Abstract class that provides a base for implementing different types of\n * memory systems. It is designed to maintain the state of an application,\n * specifically the history of a conversation. This class is typically\n * extended by other classes to create specific types of memory systems.\n */\nexport abstract class BaseChatMemory extends BaseMemory {\n  chatHistory: BaseChatMessageHistory;\n\n  returnMessages = false;\n\n  inputKey?: string;\n\n  outputKey?: string;\n\n  constructor(fields?: BaseChatMemoryInput) {\n    super();\n    this.chatHistory = fields?.chatHistory ?? new ChatMessageHistory();\n    this.returnMessages = fields?.returnMessages ?? this.returnMessages;\n    this.inputKey = fields?.inputKey ?? this.inputKey;\n    this.outputKey = fields?.outputKey ?? this.outputKey;\n  }\n\n  /**\n   * Method to add user and AI messages to the chat history in sequence.\n   * @param inputValues The input values from the user.\n   * @param outputValues The output values from the AI.\n   * @returns Promise that resolves when the context has been saved.\n   */\n  async saveContext(\n    inputValues: InputValues,\n    outputValues: OutputValues\n  ): Promise<void> {\n    // this is purposefully done in sequence so they're saved in order\n    await this.chatHistory.addUserMessage(\n      getInputValue(inputValues, this.inputKey)\n    );\n    await this.chatHistory.addAIMessage(\n      getOutputValue(outputValues, this.outputKey)\n    );\n  }\n\n  /**\n   * Method to clear the chat history.\n   * @returns Promise that resolves when the chat history has been cleared.\n   */\n  async clear(): Promise<void> {\n    await this.chatHistory.clear();\n  }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,IAAsB,iBAAtB,cAA6CA,uBAAAA,WAAW;CACtD;CAEA,iBAAiB;CAEjB;CAEA;CAEA,YAAY,QAA8B;AACxC,SAAO;AACP,OAAK,cAAc,QAAQ,eAAe,IAAIC,6BAAAA,4BAAoB;AAClE,OAAK,iBAAiB,QAAQ,kBAAkB,KAAK;AACrD,OAAK,WAAW,QAAQ,YAAY,KAAK;AACzC,OAAK,YAAY,QAAQ,aAAa,KAAK;;;;;;;;CAS7C,MAAM,YACJ,aACA,cACe;AAEf,QAAM,KAAK,YAAY,gBAAA,GAAA,uBAAA,eACP,aAAa,KAAK,SAAS,CAC1C;AACD,QAAM,KAAK,YAAY,cAAA,GAAA,uBAAA,gBACN,cAAc,KAAK,UAAU,CAC7C;;;;;;CAOH,MAAM,QAAuB;AAC3B,QAAM,KAAK,YAAY,OAAO"}