({
memory,
account,
documents,
overwrite
}: {
memory: MemoryI;
account: Account;
documents: MemoryDocumentI[];
overwrite: boolean;
})
| 697 | } |
| 698 | |
| 699 | export async function handleExistingMemoryDeploy({ |
| 700 | memory, |
| 701 | account, |
| 702 | documents, |
| 703 | overwrite |
| 704 | }: { |
| 705 | memory: MemoryI; |
| 706 | account: Account; |
| 707 | documents: MemoryDocumentI[]; |
| 708 | overwrite: boolean; |
| 709 | }) { |
| 710 | p.log.info(`Fetching "${memory.name}" memory documents.`); |
| 711 | |
| 712 | // Fetch the existing documents and compare with the local documents |
| 713 | const prodDocs = await listMemoryDocuments({ |
| 714 | account, |
| 715 | memoryName: memory.name |
| 716 | }); |
| 717 | |
| 718 | // Get the list of local document names |
| 719 | const localDocs = await getMemoryFileNames(memory.name); |
| 720 | |
| 721 | // Compare the documents |
| 722 | const { |
| 723 | areListsSame, |
| 724 | isProdSubsetOfLocal, |
| 725 | isProdSupersetOfLocal, |
| 726 | areMutuallyExclusive, |
| 727 | areOverlapping |
| 728 | } = compareDocumentLists({ |
| 729 | localDocs, |
| 730 | prodDocs |
| 731 | }); |
| 732 | |
| 733 | // If the user wants to overwrite, overwrite the memory. |
| 734 | if (overwrite) { |
| 735 | await overwriteMemory({ memory, documents, account }); |
| 736 | return true; |
| 737 | } |
| 738 | |
| 739 | // If the lists are the same, do nothing and skip deployment. |
| 740 | if (areListsSame) { |
| 741 | p.log.info( |
| 742 | `Documents in local and prod are the same. Skipping deployment for memory: "${memory.name}".` |
| 743 | ); |
| 744 | |
| 745 | return true; |
| 746 | } |
| 747 | |
| 748 | // If prod is a subset of local, upload the missing documents. |
| 749 | if (isProdSubsetOfLocal) { |
| 750 | await uploadMissingDocumentsToMemory({ |
| 751 | memory, |
| 752 | prodDocs, |
| 753 | documents, |
| 754 | account |
| 755 | }); |
| 756 | return true; |
no test coverage detected