{"version":3,"file":"transformers.cjs","names":["Runnable"],"sources":["../../src/documents/transformers.ts"],"sourcesContent":["import { Runnable } from \"../runnables/base.js\";\nimport type { BaseCallbackConfig } from \"../callbacks/manager.js\";\nimport type { DocumentInterface } from \"./document.js\";\n\n/**\n * Abstract base class for document transformation systems.\n *\n * A document transformation system takes an array of Documents and returns an\n * array of transformed Documents. These arrays do not necessarily have to have\n * the same length.\n *\n * One example of this is a text splitter that splits a large document into\n * many smaller documents.\n */\nexport abstract class BaseDocumentTransformer<\n  RunInput extends DocumentInterface[] = DocumentInterface[],\n  RunOutput extends DocumentInterface[] = DocumentInterface[],\n> extends Runnable<RunInput, RunOutput> {\n  lc_namespace = [\"langchain_core\", \"documents\", \"transformers\"];\n\n  /**\n   * Transform a list of documents.\n   * @param documents A sequence of documents to be transformed.\n   * @returns A list of transformed documents.\n   */\n  abstract transformDocuments(documents: RunInput): Promise<RunOutput>;\n\n  /**\n   * Method to invoke the document transformation. This method calls the\n   * transformDocuments method with the provided input.\n   * @param input The input documents to be transformed.\n   * @param _options Optional configuration object to customize the behavior of callbacks.\n   * @returns A Promise that resolves to the transformed documents.\n   */\n  invoke(input: RunInput, _options?: BaseCallbackConfig): Promise<RunOutput> {\n    return this.transformDocuments(input);\n  }\n}\n\n/**\n * Class for document transformers that return exactly one transformed document\n * for each input document.\n */\nexport abstract class MappingDocumentTransformer extends BaseDocumentTransformer {\n  async transformDocuments(\n    documents: DocumentInterface[]\n  ): Promise<DocumentInterface[]> {\n    const newDocuments = [];\n    for (const document of documents) {\n      const transformedDocument = await this._transformDocument(document);\n      newDocuments.push(transformedDocument);\n    }\n    return newDocuments;\n  }\n\n  abstract _transformDocument(\n    document: DocumentInterface\n  ): Promise<DocumentInterface>;\n}\n"],"mappings":";;;;;;;;;;;;AAcA,IAAsB,0BAAtB,cAGUA,aAAAA,SAA8B;CACtC,eAAe;EAAC;EAAkB;EAAa;EAAe;;;;;;;;CAgB9D,OAAO,OAAiB,UAAmD;AACzE,SAAO,KAAK,mBAAmB,MAAM;;;;;;;AAQzC,IAAsB,6BAAtB,cAAyD,wBAAwB;CAC/E,MAAM,mBACJ,WAC8B;EAC9B,MAAM,eAAe,EAAE;AACvB,OAAK,MAAM,YAAY,WAAW;GAChC,MAAM,sBAAsB,MAAM,KAAK,mBAAmB,SAAS;AACnE,gBAAa,KAAK,oBAAoB;;AAExC,SAAO"}