@lobehub/chat 1.81.4 → 1.81.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.eslintrc.js +1 -0
  2. package/.github/workflows/release.yml +5 -0
  3. package/.github/workflows/test.yml +5 -0
  4. package/CHANGELOG.md +25 -0
  5. package/changelog/v1.json +9 -0
  6. package/locales/ar/models.json +3 -0
  7. package/locales/bg-BG/models.json +3 -0
  8. package/locales/de-DE/models.json +3 -0
  9. package/locales/en-US/models.json +3 -0
  10. package/locales/es-ES/models.json +3 -0
  11. package/locales/fa-IR/models.json +3 -0
  12. package/locales/fr-FR/models.json +3 -0
  13. package/locales/it-IT/models.json +3 -0
  14. package/locales/ja-JP/models.json +3 -0
  15. package/locales/ko-KR/models.json +3 -0
  16. package/locales/nl-NL/models.json +3 -0
  17. package/locales/pl-PL/models.json +3 -0
  18. package/locales/pt-BR/models.json +3 -0
  19. package/locales/ru-RU/models.json +3 -0
  20. package/locales/tr-TR/models.json +3 -0
  21. package/locales/vi-VN/models.json +3 -0
  22. package/locales/zh-CN/models.json +3 -0
  23. package/locales/zh-TW/models.json +3 -0
  24. package/package.json +2 -2
  25. package/packages/file-loaders/README.md +63 -0
  26. package/packages/file-loaders/package.json +42 -0
  27. package/packages/file-loaders/src/index.ts +2 -0
  28. package/packages/file-loaders/src/loadFile.ts +206 -0
  29. package/packages/file-loaders/src/loaders/docx/__snapshots__/index.test.ts.snap +74 -0
  30. package/packages/file-loaders/src/loaders/docx/fixtures/test.docx +0 -0
  31. package/packages/file-loaders/src/loaders/docx/index.test.ts +41 -0
  32. package/packages/file-loaders/src/loaders/docx/index.ts +73 -0
  33. package/packages/file-loaders/src/loaders/excel/__snapshots__/index.test.ts.snap +58 -0
  34. package/packages/file-loaders/src/loaders/excel/fixtures/test.xlsx +0 -0
  35. package/packages/file-loaders/src/loaders/excel/index.test.ts +47 -0
  36. package/packages/file-loaders/src/loaders/excel/index.ts +121 -0
  37. package/packages/file-loaders/src/loaders/index.ts +19 -0
  38. package/packages/file-loaders/src/loaders/pdf/__snapshots__/index.test.ts.snap +98 -0
  39. package/packages/file-loaders/src/loaders/pdf/index.test.ts +49 -0
  40. package/packages/file-loaders/src/loaders/pdf/index.ts +133 -0
  41. package/packages/file-loaders/src/loaders/pptx/__snapshots__/index.test.ts.snap +40 -0
  42. package/packages/file-loaders/src/loaders/pptx/fixtures/test.pptx +0 -0
  43. package/packages/file-loaders/src/loaders/pptx/index.test.ts +47 -0
  44. package/packages/file-loaders/src/loaders/pptx/index.ts +186 -0
  45. package/packages/file-loaders/src/loaders/text/__snapshots__/index.test.ts.snap +15 -0
  46. package/packages/file-loaders/src/loaders/text/fixtures/test.txt +2 -0
  47. package/packages/file-loaders/src/loaders/text/index.test.ts +38 -0
  48. package/packages/file-loaders/src/loaders/text/index.ts +53 -0
  49. package/packages/file-loaders/src/types.ts +200 -0
  50. package/packages/file-loaders/src/utils/isTextReadableFile.ts +68 -0
  51. package/packages/file-loaders/src/utils/parser-utils.ts +112 -0
  52. package/packages/file-loaders/test/__snapshots__/loaders.test.ts.snap +93 -0
  53. package/packages/file-loaders/test/fixtures/test.csv +4 -0
  54. package/packages/file-loaders/test/fixtures/test.docx +0 -0
  55. package/packages/file-loaders/test/fixtures/test.epub +0 -0
  56. package/packages/file-loaders/test/fixtures/test.md +3 -0
  57. package/packages/file-loaders/test/fixtures/test.pptx +0 -0
  58. package/packages/file-loaders/test/fixtures/test.txt +3 -0
  59. package/packages/file-loaders/test/loaders.test.ts +39 -0
package/.eslintrc.js CHANGED
@@ -17,6 +17,7 @@ config.rules['unicorn/prefer-spread'] = 0;
17
17
  config.rules['unicorn/catch-error-name'] = 0;
18
18
  config.rules['unicorn/no-array-for-each'] = 0;
19
19
  config.rules['unicorn/prefer-number-properties'] = 0;
20
+ config.rules['unicorn/prefer-query-selector'] = 0;
20
21
  config.rules['unicorn/no-array-callback-reference'] = 0;
21
22
 
22
23
  config.overrides = [
@@ -22,6 +22,11 @@ jobs:
22
22
  steps:
23
23
  - uses: actions/checkout@v4
24
24
 
25
+ - name: Setup Node.js
26
+ uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 22
29
+
25
30
  - name: Install bun
26
31
  uses: oven-sh/setup-bun@v1
27
32
  with:
@@ -21,6 +21,11 @@ jobs:
21
21
  steps:
22
22
  - uses: actions/checkout@v4
23
23
 
24
+ - name: Setup Node.js
25
+ uses: actions/setup-node@v4
26
+ with:
27
+ node-version: 22
28
+
24
29
  - name: Install bun
25
30
  uses: oven-sh/setup-bun@v1
26
31
  with:
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.81.5](https://github.com/lobehub/lobe-chat/compare/v1.81.4...v1.81.5)
6
+
7
+ <sup>Released on **2025-04-20**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Lock nextauth to beta.25.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Lock nextauth to beta.25, closes [#7491](https://github.com/lobehub/lobe-chat/issues/7491) ([d1fd40d](https://github.com/lobehub/lobe-chat/commit/d1fd40d))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 1.81.4](https://github.com/lobehub/lobe-chat/compare/v1.81.3...v1.81.4)
6
31
 
7
32
  <sup>Released on **2025-04-19**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,13 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "fixes": [
5
+ "Lock nextauth to beta.25."
6
+ ]
7
+ },
8
+ "date": "2025-04-20",
9
+ "version": "1.81.5"
10
+ },
2
11
  {
3
12
  "children": {
4
13
  "fixes": [
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental هو أحدث نموذج ذكاء اصطناعي متعدد الوسائط التجريبي من Google، مع تحسينات ملحوظة في الجودة مقارنة بالإصدارات السابقة، خاصة في المعرفة العالمية، والبرمجة، والسياقات الطويلة."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "معاينة فلاش جمنّي 2.5 هي النموذج الأكثر كفاءة من جوجل، حيث تقدم مجموعة شاملة من الميزات."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "نموذج Gemini 2.5 Pro التجريبي هو الأكثر تقدمًا من Google، قادر على استنتاج المشكلات المعقدة في البرمجة والرياضيات وعلوم STEM، بالإضافة إلى تحليل مجموعات البيانات الكبيرة ومكتبات الشيفرات والمستندات باستخدام سياقات طويلة."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental е най-новият експериментален многомодален AI модел на Google, който предлага значително подобрение в качеството в сравнение с предишните версии, особено по отношение на световни знания, код и дълги контексти."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview е моделът с най-добро съотношение цена-качество на Google, предлагащ пълна функционалност."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental е най-напредналият модел на мислене на Google, способен да разсъждава по сложни проблеми в код, математика и STEM области, както и да анализира големи набори от данни, кодови библиотеки и документи, използвайки дълъг контекст."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental ist Googles neuestes experimentelles multimodales KI-Modell, das im Vergleich zu früheren Versionen eine gewisse Qualitätsverbesserung aufweist, insbesondere in Bezug auf Weltwissen, Code und lange Kontexte."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview ist das kosteneffizienteste Modell von Google und bietet umfassende Funktionen."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental ist Googles fortschrittlichstes Denkmodell, das in der Lage ist, komplexe Probleme in den Bereichen Code, Mathematik und STEM zu analysieren. Es kann auch lange Kontexte nutzen, um große Datensätze, Codebasen und Dokumente zu analysieren."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental is Google's latest experimental multimodal AI model, showing a quality improvement compared to previous versions, especially in world knowledge, coding, and long context."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview is Google's most cost-effective model, offering a comprehensive set of features."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental is Google's most advanced thinking model, capable of reasoning about complex problems in code, mathematics, and STEM fields, as well as analyzing large datasets, codebases, and documents using long context."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental es el último modelo de IA multimodal experimental de Google, con mejoras de calidad en comparación con versiones anteriores, especialmente en conocimiento del mundo, código y contextos largos."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview es el modelo más rentable de Google, que ofrece una funcionalidad completa."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental es el modelo de pensamiento más avanzado de Google, capaz de razonar sobre problemas complejos en código, matemáticas y campos STEM, además de utilizar contextos largos para analizar grandes conjuntos de datos, bibliotecas de código y documentos."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental جدیدترین مدل AI چندرسانه‌ای آزمایشی گوگل است که نسبت به نسخه‌های قبلی خود بهبود کیفیت قابل توجهی داشته است، به ویژه در زمینه دانش جهانی، کد و متن‌های طولانی."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "پیش‌نمایش فلش Gemini 2.5 مدل با بهترین قیمت و کیفیت گوگل است که امکانات جامع و کاملی را ارائه می‌دهد."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental پیشرفته‌ترین مدل تفکر گوگل است که قادر به استدلال در مورد مسائل پیچیده در زمینه‌های کد، ریاضیات و STEM می‌باشد و همچنین می‌تواند با استفاده از زمینه‌های طولانی، مجموعه‌های داده بزرگ، کتابخانه‌های کد و مستندات را تحلیل کند."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental est le dernier modèle AI multimodal expérimental de Google, offrant une amélioration de la qualité par rapport aux versions précédentes, en particulier pour les connaissances générales, le code et les longs contextes."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview est le modèle le plus rentable de Google, offrant des fonctionnalités complètes."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental est le modèle de pensée le plus avancé de Google, capable de raisonner sur des problèmes complexes en code, mathématiques et dans les domaines STEM, tout en utilisant un long contexte pour analyser de grands ensembles de données, des bibliothèques de code et des documents."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental è il più recente modello AI multimodale sperimentale di Google, con un miglioramento della qualità rispetto alle versioni precedenti, in particolare per quanto riguarda la conoscenza del mondo, il codice e i contesti lunghi."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview è il modello più conveniente di Google, che offre funzionalità complete."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental è il modello di pensiero più avanzato di Google, in grado di ragionare su problemi complessi in codice, matematica e nei campi STEM, e di analizzare grandi set di dati, codebase e documenti utilizzando contesti lunghi."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimentalは、Googleの最新の実験的なマルチモーダルAIモデルで、歴史的なバージョンと比較して品質が向上しています。特に、世界の知識、コード、長いコンテキストにおいて顕著です。"
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Previewは、Googleのコストパフォーマンスに優れたモデルで、包括的な機能を提供します。"
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimentalは、Googleの最先端の思考モデルであり、コード、数学、STEM分野の複雑な問題に対して推論を行うことができ、長いコンテキストを利用して大規模なデータセット、コードベース、文書を分析します。"
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental은 Google의 최신 실험적 다중 모달 AI 모델로, 이전 버전과 비교하여 품질이 향상되었습니다. 특히 세계 지식, 코드 및 긴 문맥에 대해 개선되었습니다."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview는 Google의 가장 가성비 높은 모델로, 포괄적인 기능을 제공합니다."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental은 Google의 최첨단 사고 모델로, 코드, 수학 및 STEM 분야의 복잡한 문제를 추론할 수 있으며, 긴 문맥을 활용하여 대규모 데이터 세트, 코드베이스 및 문서를 분석할 수 있습니다."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental is Google's nieuwste experimentele multimodale AI-model, met aanzienlijke kwaliteitsverbeteringen ten opzichte van eerdere versies, vooral op het gebied van wereldkennis, code en lange context."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview is het meest kosteneffectieve model van Google, dat uitgebreide functionaliteit biedt."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental is Google's meest geavanceerde denkmodel, dat in staat is om te redeneren over complexe problemen in code, wiskunde en STEM-gebieden, en bovendien gebruik maakt van lange contexten om grote datasets, codebases en documenten te analyseren."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental to najnowszy eksperymentalny model AI o wielu modalnościach od Google, który w porównaniu do wcześniejszych wersji oferuje pewne poprawy jakości, szczególnie w zakresie wiedzy o świecie, kodu i długiego kontekstu."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview to najbardziej opłacalny model Google, oferujący wszechstronne funkcje."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental to najnowocześniejszy model myślenia Google, zdolny do wnioskowania w zakresie kodu, matematyki i złożonych problemów w dziedzinie STEM, a także do analizy dużych zbiorów danych, repozytoriów kodu i dokumentów, wykorzystując długi kontekst."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental é o mais recente modelo de IA multimodal experimental do Google, apresentando melhorias de qualidade em comparação com versões anteriores, especialmente em conhecimento mundial, código e contextos longos."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "O Gemini 2.5 Flash Preview é o modelo mais acessível do Google, oferecendo uma gama completa de funcionalidades."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "O Gemini 2.5 Pro Experimental é o modelo de pensamento mais avançado do Google, capaz de raciocinar sobre problemas complexos em código, matemática e áreas STEM, além de analisar grandes conjuntos de dados, repositórios de código e documentos utilizando contextos longos."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental — это последняя экспериментальная многомодальная AI модель от Google, которая демонстрирует определенное улучшение качества по сравнению с предыдущими версиями, особенно в области мировых знаний, кода и длинного контекста."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview — это наиболее выгодная модель от Google, предлагающая широкий спектр возможностей."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental — это самая современная модель мышления от Google, способная рассуждать о сложных задачах в области кода, математики и STEM, а также анализировать большие наборы данных, кодовые базы и документы, используя длинный контекст."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Deneysel, Google'ın en son deneysel çok modlu AI modelidir ve önceki sürümlere göre belirli bir kalite artışı sağlamaktadır, özellikle dünya bilgisi, kod ve uzun bağlam için."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Önizleme, Google'ın en iyi fiyat-performans oranına sahip modelidir ve kapsamlı özellikler sunar."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Deneysel, Google'ın en gelişmiş düşünce modeli olup, kod, matematik ve STEM alanlarındaki karmaşık sorunları akıl yürütebilmektedir. Ayrıca, uzun bağlamları kullanarak büyük veri setlerini, kod havuzlarını ve belgeleri analiz edebilir."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental là mô hình AI đa phương tiện thử nghiệm mới nhất của Google, có sự cải thiện chất lượng nhất định so với các phiên bản trước, đặc biệt là về kiến thức thế giới, mã và ngữ cảnh dài."
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview là mô hình có giá trị tốt nhất của Google, cung cấp đầy đủ các tính năng."
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental là mô hình tư duy tiên tiến nhất của Google, có khả năng suy luận về mã, toán học và các vấn đề phức tạp trong lĩnh vực STEM, đồng thời có thể phân tích các tập dữ liệu lớn, kho mã và tài liệu bằng cách sử dụng ngữ cảnh dài."
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental 是 Google 最新的实验性多模态AI模型,与历史版本相比有一定的质量提升,特别是对于世界知识、代码和长上下文。"
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview 是 Google 性价比最高的模型,提供全面的功能。"
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro Experimental 是 Google 最先进的思维模型,能够对代码、数学和STEM领域的复杂问题进行推理,以及使用长上下文分析大型数据集、代码库和文档。"
988
991
  },
@@ -983,6 +983,9 @@
983
983
  "gemini-2.0-pro-exp-02-05": {
984
984
  "description": "Gemini 2.0 Pro Experimental 是 Google 最新的實驗性多模態AI模型,與歷史版本相比有一定的質量提升,特別是對於世界知識、代碼和長上下文。"
985
985
  },
986
+ "gemini-2.5-flash-preview-04-17": {
987
+ "description": "Gemini 2.5 Flash Preview 是 Google 性價比最高的模型,提供全面的功能。"
988
+ },
986
989
  "gemini-2.5-pro-exp-03-25": {
987
990
  "description": "Gemini 2.5 Pro 實驗版是 Google 最先進的思維模型,能夠對代碼、數學和 STEM 領域的複雜問題進行推理,還能利用長上下文來分析大型數據集、代碼庫和文檔。"
988
991
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.81.4",
3
+ "version": "1.81.5",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -200,7 +200,7 @@
200
200
  "modern-screenshot": "^4.6.0",
201
201
  "nanoid": "^5.1.5",
202
202
  "next": "^15.3.0",
203
- "next-auth": "beta",
203
+ "next-auth": "5.0.0-beta.25",
204
204
  "next-mdx-remote": "^5.0.0",
205
205
  "nextjs-toploader": "^3.8.16",
206
206
  "numeral": "^2.0.6",
@@ -0,0 +1,63 @@
1
+ # @lobehub/file-loaders
2
+
3
+ `@lobehub/file-loaders` 是 LobeChat 项目中的一个工具包,专门用于从本地文件路径加载各种类型的文件,并将其内容转换为标准化的 `Document` 对象数组。
4
+
5
+ 它的主要目的是提供一个统一的接口来读取不同的文件格式,提取其核心文本内容,并为后续处理(例如在 LobeChat 中进行文件预览、内容提取或将其作为知识库数据源)做好准备。
6
+
7
+ ## ✨ 功能特性
8
+
9
+ - **统一接口**: 提供 `loadFile(filePath: string)` 函数作为核心入口点。
10
+ - **自动类型检测**: 根据文件扩展名自动选择合适的加载方式。
11
+ - **广泛的格式支持**:
12
+ - **纯文本类**: `.txt`, `.csv`, `.md`, `.json`, `.xml`, `.yaml`, `.html` 以及多种代码和配置文件格式。
13
+ - **PDF**: `.pdf` 文件。
14
+ - **Word**: `.docx` 文件。
15
+ - **Excel**: `.xlsx`, `.xls` 文件,每个工作表作为一个 `Page`。
16
+ - **PowerPoint**: `.pptx` 文件,每个幻灯片作为一个 `Page`。
17
+ - **标准化输出**: 始终返回 `Promise<Document>`。 `Document` 对象代表一个加载的文件,其内部包含一个 `Page` 数组,代表文件的各个逻辑单元(页、幻灯片、工作表、文本块等)。
18
+ - **层级结构**: 采用 `Document` 包含 `Page[]` 的结构,更好地反映文件原始组织方式。
19
+ - **丰富的元数据**: 在 `Document` 和 `Page` 层面提供详细的元数据,包括文件信息、内容统计和结构信息。
20
+
21
+ ## 核心数据结构
22
+
23
+ `loadFile` 函数返回一个 `FileDocument` 对象,包含文件级信息和其所有逻辑页面 / 块 (`DocumentPage`)。
24
+
25
+ ### `FileDocument` Interface
26
+
27
+ | 字段 | 类型 | 描述 |
28
+ | :---------------- | :---------------- | :------------------------------------------------------------- |
29
+ | `content` | `string` | 文件内容 (聚合后的内容) |
30
+ | `createdTime` | `Date` | 文件创建时间戳。 |
31
+ | `fileType` | `string` | 文件类型或扩展名。 |
32
+ | `filename` | `string` | 原始文件名。 |
33
+ | `metadata` | `object` | 文件级别的元数据。 |
34
+ | `metadata.author` | `string?` | 文档作者 (如果可用)。 |
35
+ | `metadata.error` | `string?` | 如果整个文件加载失败,记录错误信息。 |
36
+ | `metadata.title` | `string?` | 文档标题 (如果可用)。 |
37
+ | `...` | `any` | 其他文件级别的元数据。 |
38
+ | `modifiedTime` | `Date` | 文件最后修改时间戳。 |
39
+ | `pages` | `DocumentPage[]?` | 包含文档中所有逻辑页面 / 块的数组 (可选)。 |
40
+ | `source` | `string` | 原始文件的完整路径。 |
41
+ | `totalCharCount` | `number` | 整个文档的总字符数 (所有 `DocumentPage` 的 `charCount` 之和)。 |
42
+ | `totalLineCount` | `number` | 整个文档的总行数 (所有 `DocumentPage` 的 `lineCount` 之和)。 |
43
+
44
+ ### `DocumentPage` Interface
45
+
46
+ | 字段 | 类型 | 描述 |
47
+ | :------------------------- | :-------- | :--------------------------- |
48
+ | `charCount` | `number` | 此页 / 块内容的字符数。 |
49
+ | `lineCount` | `number` | 此页 / 块内容的行数。 |
50
+ | `metadata` | `object` | 与此页 / 块相关的元数据。 |
51
+ | `metadata.chunkIndex` | `number?` | 如果分割成块,当前块的索引。 |
52
+ | `metadata.error` | `string?` | 处理此页 / 块时发生的错误。 |
53
+ | `metadata.lineNumberEnd` | `number?` | 在原始文件中的结束行号。 |
54
+ | `metadata.lineNumberStart` | `number?` | 在原始文件中的起始行号。 |
55
+ | `metadata.pageNumber` | `number?` | 页码 (适用于 PDF, DOCX)。 |
56
+ | `metadata.sectionTitle` | `string?` | 相关的章节标题。 |
57
+ | `metadata.sheetName` | `string?` | 工作表名称 (适用于 XLSX)。 |
58
+ | `metadata.slideNumber` | `number?` | 幻灯片编号 (适用于 PPTX)。 |
59
+ | `metadata.totalChunks` | `number?` | 如果分割成块,总块数。 |
60
+ | `...` | `any` | 其他特定于页 / 块的元数据。 |
61
+ | `pageContent` | `string` | 此页 / 块的核心文本内容。 |
62
+
63
+ 如果你对我们的项目感兴趣,欢迎在 [GitHub](https://github.com/lobehub/lobe-chat) 上查看、点赞或贡献代码!
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@lobechat/file-loaders",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "description": "Utilities for reading and processing various file types",
6
+ "keywords": [
7
+ "file",
8
+ "loader",
9
+ "parser",
10
+ "lobehub"
11
+ ],
12
+ "homepage": "https://github.com/lobehub/lobe-chat/tree/master/packages/file-loaders",
13
+ "bugs": {
14
+ "url": "https://github.com/lobehub/lobe-chat/issues/new"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/lobehub/lobe-chat.git"
19
+ },
20
+ "author": "LobeHub <i@lobehub.com>",
21
+ "sideEffects": false,
22
+ "main": "./src/index.ts",
23
+ "dependencies": {
24
+ "@langchain/community": "^0.3.41",
25
+ "@langchain/core": "^0.3.45",
26
+ "@xmldom/xmldom": "^0.9.8",
27
+ "concat-stream": "^2.0.0",
28
+ "mammoth": "^1.8.0",
29
+ "officeparser": "^5.1.1",
30
+ "pdfjs-dist": "4.8.69",
31
+ "xlsx": "^0.18.5",
32
+ "yauzl": "^3.2.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/concat-stream": "^2.0.3",
36
+ "@types/yauzl": "^2.10.3",
37
+ "typescript": "^5"
38
+ },
39
+ "peerDependencies": {
40
+ "typescript": ">=5"
41
+ }
42
+ }
@@ -0,0 +1,2 @@
1
+ export * from './loadFile';
2
+ export * from './types';
@@ -0,0 +1,206 @@
1
+ import { stat } from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+
4
+ import { fileLoaders } from './loaders';
5
+ import { TextLoader } from './loaders/text';
6
+ import { FileDocument, FileMetadata, SupportedFileType } from './types';
7
+ import type { DocumentPage, FileLoaderInterface } from './types';
8
+ import { isTextReadableFile } from './utils/isTextReadableFile';
9
+
10
+ /**
11
+ * Determines the file type based on the filename extension.
12
+ * @param filePath The path to the file.
13
+ * @returns The determined file type or 'txt' if text-readable, undefined otherwise.
14
+ */
15
+ const getFileType = (filePath: string): SupportedFileType | undefined => {
16
+ const extension = path.extname(filePath).toLowerCase().replace('.', '');
17
+
18
+ if (!extension) return 'txt'; // Treat files without extension as text?
19
+
20
+ // Prioritize checking if it's a generally text-readable type
21
+ if (isTextReadableFile(extension)) {
22
+ return 'txt';
23
+ }
24
+
25
+ // Handle specific non-text or complex types
26
+ switch (extension) {
27
+ case 'pdf': {
28
+ return 'pdf';
29
+ }
30
+ case 'docx': {
31
+ return 'docx';
32
+ }
33
+ case 'xlsx':
34
+ case 'xls': {
35
+ return 'excel';
36
+ }
37
+ case 'pptx': {
38
+ return 'pptx';
39
+ }
40
+ default: {
41
+ // If not text-readable and not a specific known type, it's unsupported
42
+ return undefined;
43
+ }
44
+ }
45
+ };
46
+
47
+ // Default fallback loader class
48
+ const DefaultLoader = TextLoader;
49
+
50
+ /**
51
+ * Loads a file from the specified path, automatically detecting the file type
52
+ * and using the appropriate loader class.
53
+ *
54
+ * @param filePath The path to the file to load.
55
+ * @param fileMetadata Optional metadata to override information read from the filesystem.
56
+ * @returns A Promise resolving to a FileDocument object.
57
+ */
58
+ export const loadFile = async (
59
+ filePath: string,
60
+ fileMetadata?: FileMetadata,
61
+ ): Promise<FileDocument> => {
62
+ let stats;
63
+ let fsError: string | undefined;
64
+
65
+ try {
66
+ stats = await stat(filePath);
67
+ } catch (e) {
68
+ const error = e as Error;
69
+ console.error(`Error getting file stats for ${filePath}: ${error.message}`);
70
+ fsError = `Failed to access file stats: ${error.message}`;
71
+ }
72
+
73
+ // Determine base file info from path and stats (if available)
74
+ const fileExtension = path.extname(filePath).slice(1).toLowerCase();
75
+ const baseFilename = path.basename(filePath);
76
+
77
+ // Apply overrides from fileMetadata or use defaults
78
+ const source = fileMetadata?.source ?? filePath;
79
+ const filename = fileMetadata?.filename ?? baseFilename;
80
+ const fileType = fileMetadata?.fileType ?? fileExtension;
81
+ const createdTime = fileMetadata?.createdTime ?? stats?.ctime ?? new Date();
82
+ const modifiedTime = fileMetadata?.modifiedTime ?? stats?.mtime ?? new Date();
83
+
84
+ const paserType = getFileType(filePath);
85
+
86
+ // Select the loader CLASS based on the determined fileType, fallback to DefaultLoader
87
+ const LoaderClass: new () => FileLoaderInterface = paserType
88
+ ? fileLoaders[paserType]
89
+ : DefaultLoader;
90
+
91
+ if (!paserType) {
92
+ console.warn(
93
+ `No specific loader found for file type '${fileType}'. Using default loader (${DefaultLoader.name}) as fallback.`,
94
+ );
95
+ }
96
+
97
+ let pages: DocumentPage[] = [];
98
+ let aggregatedContent = '';
99
+ let loaderError: string | undefined;
100
+ let aggregationError: string | undefined;
101
+ let metadataError: string | undefined;
102
+ let loaderSpecificMetadata: any | undefined;
103
+
104
+ // Instantiate the loader
105
+ const loaderInstance = new LoaderClass();
106
+
107
+ // If we couldn't even get stats, skip loader execution
108
+ if (!fsError) {
109
+ try {
110
+ // 1. Load pages using the instance
111
+ pages = await loaderInstance.loadPages(filePath);
112
+
113
+ try {
114
+ // 2. Aggregate content using the instance
115
+ aggregatedContent = await loaderInstance.aggregateContent(pages);
116
+ } catch (aggError) {
117
+ const error = aggError as Error;
118
+ console.error(
119
+ `Error aggregating content for ${filePath} using ${LoaderClass.name}: ${error.message}`,
120
+ );
121
+ aggregationError = `Content aggregation failed: ${error.message}`;
122
+ // Keep the pages loaded, but content might be empty/incomplete
123
+ }
124
+
125
+ // 3. Attach document-specific metadata if loader supports it
126
+ if (typeof loaderInstance.attachDocumentMetadata === 'function') {
127
+ try {
128
+ loaderSpecificMetadata = await loaderInstance.attachDocumentMetadata(filePath);
129
+ } catch (metaErr) {
130
+ const error = metaErr as Error;
131
+ console.error(
132
+ `Error attaching metadata for ${filePath} using ${LoaderClass.name}: ${error.message}`,
133
+ );
134
+ metadataError = `Metadata attachment failed: ${error.message}`;
135
+ }
136
+ }
137
+ } catch (loadErr) {
138
+ const error = loadErr as Error;
139
+ console.error(
140
+ `Error loading pages for ${filePath} using ${LoaderClass.name}: ${error.message}`,
141
+ );
142
+ loaderError = `Loader execution failed: ${error.message}`;
143
+ // Provide a minimal error page if loader failed critically
144
+ pages = [
145
+ {
146
+ charCount: 0,
147
+ lineCount: 0,
148
+ metadata: { error: loaderError },
149
+ pageContent: '',
150
+ },
151
+ ];
152
+ // Aggregated content remains empty
153
+ }
154
+ } else {
155
+ // If stats failed, create a minimal error page
156
+ pages = [
157
+ {
158
+ charCount: 0,
159
+ lineCount: 0,
160
+ metadata: { error: fsError },
161
+ pageContent: '',
162
+ },
163
+ ];
164
+ // Aggregated content remains empty
165
+ }
166
+
167
+ // Calculate totals from the loaded pages
168
+ let totalCharCount = 0;
169
+ let totalLineCount = 0;
170
+ for (const page of pages) {
171
+ totalCharCount += page.charCount;
172
+ totalLineCount += page.lineCount;
173
+ }
174
+
175
+ // Combine all potential errors
176
+ const combinedError =
177
+ [fsError, loaderError, aggregationError, metadataError].filter(Boolean).join('; ') || undefined;
178
+
179
+ // Construct the final FileDocument
180
+ const fileDocument: FileDocument = {
181
+ content: aggregatedContent, // Use content from aggregateContent
182
+ createdTime,
183
+ fileType,
184
+ filename,
185
+ metadata: {
186
+ // Include combined errors
187
+ error: combinedError,
188
+ // Add loader specific metadata under a namespace
189
+ loaderSpecific: loaderSpecificMetadata ?? undefined,
190
+ // Add other file-level metadata
191
+ ...fileMetadata,
192
+ },
193
+ modifiedTime,
194
+ pages, // Use pages from loadPages
195
+ source,
196
+ totalCharCount,
197
+ totalLineCount,
198
+ };
199
+
200
+ // Clean up undefined error field if no error occurred
201
+ if (!fileDocument.metadata.error) {
202
+ delete fileDocument.metadata.error;
203
+ }
204
+
205
+ return fileDocument;
206
+ };