diff options
| author | sharkiecodes <lanyi_stroud@brown.edu> | 2025-07-10 10:22:43 -0400 |
|---|---|---|
| committer | sharkiecodes <lanyi_stroud@brown.edu> | 2025-07-10 10:22:43 -0400 |
| commit | 5ad889e555a02ae63e59ee6c9766d57f829ff687 (patch) | |
| tree | 13352c4a4d1dba30e85fbeed16debf333baee464 /src/client/views/nodes/chatbot/tools/ViewManipulator.ts | |
| parent | b5d53fc2dda0c2adcf0ccd388872faaca7606fa0 (diff) | |
expanding
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/ViewManipulator.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/tools/ViewManipulator.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/ViewManipulator.ts b/src/client/views/nodes/chatbot/tools/ViewManipulator.ts new file mode 100644 index 000000000..67f183412 --- /dev/null +++ b/src/client/views/nodes/chatbot/tools/ViewManipulator.ts @@ -0,0 +1,33 @@ + + + + processGptResponse = (docView: DocumentView, textToDocMap: Map<string, Doc>, gptOutput: string, questionType: GPTDocCommand) => + undoable(() => { + switch (questionType) { // reset collection based on question typefc + case GPTDocCommand.Sort: + docView.Document[docView.ComponentView?.fieldKey + '_sort'] = docSortings.Chat; + break; + case GPTDocCommand.Filter: + docView.ComponentView?.hasChildDocs?.().forEach(d => TagItem.removeTagFromDoc(d, GPTPopup.ChatTag)); + break; + } // prettier-ignore + + gptOutput.split(DescriptionSeperator).filter(item => item.trim() !== '') // Split output into individual document contents + .map(docContentRaw => docContentRaw.replace(/\n/g, ' ').trim()) + .map(docContentRaw => ({doc: textToDocMap.get(docContentRaw.split(DataSeperator)[0]), data: docContentRaw.split(DataSeperator)[1] })) // the find the corresponding Doc using textToDoc map + .filter(({doc}) => doc).map(({doc, data}) => ({doc:doc!, data})) // filter out undefined values + .forEach(({doc, data}, index) => { + switch (questionType) { + case GPTDocCommand.Sort: + doc[ChatSortField] = index; + break; + case GPTDocCommand.AssignTags: + data && TagItem.addTagToDoc(doc, data.startsWith('#') ? data : '#'+data[0].toLowerCase()+data.slice(1) ); + break; + case GPTDocCommand.Filter: + TagItem.addTagToDoc(doc, GPTPopup.ChatTag); + Doc.setDocFilter(docView.Document, 'tags', GPTPopup.ChatTag, 'check'); + break; + } + }); // prettier-ignore + }, '')(); |
