@@ -5,7 +5,11 @@ import { allSupportedExtensions, MEMORYSETS } from './constants';
55import { getDocumentContent } from './get-document-content' ;
66import { formatDocSize } from './lib' ;
77import loadMemoryConfig from './load-memory-config' ;
8- import { memoryConfigSchema , type MemoryConfigI } from 'types/memory' ;
8+ import {
9+ memoryConfigSchema ,
10+ type DocumentConfigI ,
11+ type MemoryConfigI
12+ } from 'types/memory' ;
913import { execSync } from 'child_process' ;
1014import fg from 'fast-glob' ;
1115
@@ -14,6 +18,8 @@ export interface MemoryDocumentI {
1418 size : string ;
1519 content : string ;
1620 blob : Blob ;
21+ path : string ;
22+ meta : Record < string , string > ;
1723}
1824
1925export const loadMemoryFiles = async (
@@ -24,10 +30,11 @@ export const loadMemoryFiles = async (
2430
2531 // useDocumentsDir
2632 const useDocumentsDir = ! memoryConfig || ! memoryConfig . git . enabled ;
33+ const documentConfig = memoryConfig ?. documents ;
2734
2835 // Load files from documents directory.
2936 if ( useDocumentsDir ) {
30- return await loadMemoryFilesFromDocsDir ( memoryName ) ;
37+ return await loadMemoryFilesFromDocsDir ( { memoryName, documentConfig } ) ;
3138 }
3239
3340 // Load files from the repo.
@@ -121,12 +128,21 @@ export const loadMemoryFilesFromCustomDir = async ({
121128 return null ;
122129 }
123130
124- return {
131+ const memoryFile = {
132+ path : filePath ,
125133 name : path . basename ( filePath . replace ( / \/ / g, '-' ) ) ,
126134 size : formatDocSize ( fileContentBlob . size ) ,
127135 content : await getDocumentContent ( fileContentBlob ) ,
128136 blob : fileContentBlob
129137 } ;
138+
139+ let meta = { } ;
140+
141+ if ( memoryConfig ?. documents ?. meta ) {
142+ meta = memoryConfig . documents . meta ( memoryFile ) || { } ;
143+ }
144+
145+ return { ...memoryFile , meta } ;
130146 } )
131147 ) ;
132148
@@ -159,9 +175,13 @@ export const loadMemoryFilesFromCustomDir = async ({
159175 * - Have unsupported file extensions.
160176 * 5. Returns an array of `MemoryDocumentI` objects representing the valid memory files.
161177 */
162- export const loadMemoryFilesFromDocsDir = async (
163- memoryName : string
164- ) : Promise < MemoryDocumentI [ ] > => {
178+ export const loadMemoryFilesFromDocsDir = async ( {
179+ memoryName,
180+ documentConfig
181+ } : {
182+ memoryName : string ;
183+ documentConfig ?: DocumentConfigI ;
184+ } ) : Promise < MemoryDocumentI [ ] > => {
165185 const memoryDir = path . join ( process . cwd ( ) , 'baseai' , 'memory' , memoryName ) ;
166186 const memoryFilesPath = path . join ( memoryDir , 'documents' ) ;
167187
@@ -214,12 +234,21 @@ export const loadMemoryFilesFromDocsDir = async (
214234 return null ;
215235 }
216236
217- return {
237+ const memoryFile = {
218238 name : file ,
239+ path : filePath ,
219240 size : formatDocSize ( fileContentBlob . size ) ,
220241 content : await getDocumentContent ( fileContentBlob ) ,
221242 blob : fileContentBlob
222243 } ;
244+
245+ let meta = { } ;
246+
247+ if ( documentConfig ?. meta ) {
248+ meta = documentConfig . meta ( memoryFile ) || { } ;
249+ }
250+
251+ return { ...memoryFile , meta } ;
223252 } )
224253 ) ;
225254
0 commit comments