index.ts 843 B

123456789101112131415161718192021222324252627
  1. import type { ThoughtItem } from '@/app/components/base/chat/chat/type'
  2. import type { FileEntity } from '@/app/components/base/file-uploader/types'
  3. import type { VisionFile } from '@/types/app'
  4. export const sortAgentSorts = (list: ThoughtItem[]) => {
  5. if (!list)
  6. return list
  7. if (list.some(item => item.position === undefined))
  8. return list
  9. const temp = [...list]
  10. temp.sort((a, b) => a.position - b.position)
  11. return temp
  12. }
  13. export const addFileInfos = (list: ThoughtItem[], messageFiles: (FileEntity | VisionFile)[]) => {
  14. if (!list || !messageFiles)
  15. return list
  16. return list.map((item) => {
  17. if (item.files && item.files?.length > 0) {
  18. return {
  19. ...item,
  20. message_files: item.files.map(fileId => messageFiles.find(file => file.id === fileId)) as FileEntity[],
  21. }
  22. }
  23. return item
  24. })
  25. }