| 24 | }; |
| 25 | |
| 26 | export async function createMemory() { |
| 27 | p.intro(heading({ text: 'MEMORY', sub: 'Create a new memory' })); |
| 28 | |
| 29 | const memoryInfo = await p.group( |
| 30 | { |
| 31 | name: () => |
| 32 | p.text({ |
| 33 | message: 'Name of the memory', |
| 34 | placeholder: defaultConfig.name, |
| 35 | validate: value => { |
| 36 | const validatedName = memoryNameSchema.safeParse(value); |
| 37 | if (!validatedName.success) { |
| 38 | const validationError = fromZodError( |
| 39 | validatedName.error |
| 40 | ).toString(); |
| 41 | return validationError; |
| 42 | } |
| 43 | return; |
| 44 | } |
| 45 | }), |
| 46 | description: () => |
| 47 | p.text({ |
| 48 | message: 'Description of the memory', |
| 49 | placeholder: defaultConfig.description |
| 50 | }), |
| 51 | useGit: () => |
| 52 | p.confirm({ |
| 53 | message: |
| 54 | 'Do you want to create memory from current project git repository?', |
| 55 | initialValue: false |
| 56 | }) |
| 57 | }, |
| 58 | { |
| 59 | onCancel: () => { |
| 60 | p.cancel('Operation cancelled.'); |
| 61 | process.exit(0); |
| 62 | } |
| 63 | } |
| 64 | ); |
| 65 | |
| 66 | const memoryNameSlugified = slugify(memoryInfo.name); |
| 67 | const memoryNameCamelCase = camelCase('memory-' + memoryNameSlugified); |
| 68 | const baseDir = path.join(process.cwd(), 'baseai', 'memory'); |
| 69 | const memoryDir = path.join(baseDir, memoryNameSlugified); |
| 70 | const filePath = path.join(memoryDir, 'index.ts'); |
| 71 | const dbDir = path.join(process.cwd(), '.baseai', 'db'); |
| 72 | |
| 73 | if (memoryInfo.useGit) { |
| 74 | try { |
| 75 | await execAsync('git rev-parse --is-inside-work-tree'); |
| 76 | } catch (error) { |
| 77 | p.cancel('The current directory is not a Git repository.'); |
| 78 | process.exit(1); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | const memoryContent = `import {MemoryI} from '@baseai/core'; |
| 83 | |