@lobehub/chat 1.17.7 → 1.18.1
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.
Potentially problematic release.
This version of @lobehub/chat might be problematic. Click here for more details.
- package/.dockerignore +0 -1
- package/CHANGELOG.md +42 -0
- package/locales/ar/common.json +1 -1
- package/locales/ar/discover.json +204 -0
- package/locales/ar/metadata.json +20 -3
- package/locales/ar/models.json +845 -0
- package/locales/ar/providers.json +80 -0
- package/locales/bg-BG/common.json +1 -1
- package/locales/bg-BG/discover.json +204 -0
- package/locales/bg-BG/metadata.json +20 -3
- package/locales/bg-BG/models.json +845 -0
- package/locales/bg-BG/providers.json +80 -0
- package/locales/de-DE/common.json +1 -1
- package/locales/de-DE/discover.json +204 -0
- package/locales/de-DE/metadata.json +20 -3
- package/locales/de-DE/models.json +845 -0
- package/locales/de-DE/providers.json +80 -0
- package/locales/en-US/common.json +1 -1
- package/locales/en-US/discover.json +204 -0
- package/locales/en-US/metadata.json +20 -3
- package/locales/en-US/models.json +845 -0
- package/locales/en-US/providers.json +80 -0
- package/locales/es-ES/common.json +1 -1
- package/locales/es-ES/discover.json +204 -0
- package/locales/es-ES/metadata.json +20 -3
- package/locales/es-ES/models.json +845 -0
- package/locales/es-ES/providers.json +80 -0
- package/locales/fr-FR/common.json +1 -1
- package/locales/fr-FR/discover.json +204 -0
- package/locales/fr-FR/metadata.json +20 -3
- package/locales/fr-FR/models.json +845 -0
- package/locales/fr-FR/providers.json +80 -0
- package/locales/it-IT/common.json +1 -1
- package/locales/it-IT/discover.json +204 -0
- package/locales/it-IT/metadata.json +20 -3
- package/locales/it-IT/models.json +845 -0
- package/locales/it-IT/providers.json +80 -0
- package/locales/ja-JP/common.json +1 -1
- package/locales/ja-JP/discover.json +204 -0
- package/locales/ja-JP/metadata.json +20 -3
- package/locales/ja-JP/models.json +845 -0
- package/locales/ja-JP/providers.json +80 -0
- package/locales/ko-KR/common.json +1 -1
- package/locales/ko-KR/discover.json +204 -0
- package/locales/ko-KR/metadata.json +20 -3
- package/locales/ko-KR/models.json +845 -0
- package/locales/ko-KR/providers.json +80 -0
- package/locales/nl-NL/common.json +1 -1
- package/locales/nl-NL/discover.json +204 -0
- package/locales/nl-NL/metadata.json +20 -3
- package/locales/nl-NL/models.json +845 -0
- package/locales/nl-NL/providers.json +80 -0
- package/locales/pl-PL/common.json +1 -1
- package/locales/pl-PL/discover.json +204 -0
- package/locales/pl-PL/metadata.json +20 -3
- package/locales/pl-PL/models.json +845 -0
- package/locales/pl-PL/providers.json +80 -0
- package/locales/pt-BR/common.json +1 -1
- package/locales/pt-BR/discover.json +204 -0
- package/locales/pt-BR/metadata.json +20 -3
- package/locales/pt-BR/models.json +845 -0
- package/locales/pt-BR/providers.json +80 -0
- package/locales/ru-RU/common.json +1 -1
- package/locales/ru-RU/discover.json +204 -0
- package/locales/ru-RU/metadata.json +20 -3
- package/locales/ru-RU/models.json +845 -0
- package/locales/ru-RU/providers.json +80 -0
- package/locales/tr-TR/common.json +1 -1
- package/locales/tr-TR/discover.json +204 -0
- package/locales/tr-TR/metadata.json +20 -3
- package/locales/tr-TR/models.json +845 -0
- package/locales/tr-TR/providers.json +80 -0
- package/locales/vi-VN/common.json +1 -1
- package/locales/vi-VN/discover.json +204 -0
- package/locales/vi-VN/metadata.json +20 -3
- package/locales/vi-VN/models.json +845 -0
- package/locales/vi-VN/providers.json +80 -0
- package/locales/zh-CN/common.json +1 -1
- package/locales/zh-CN/discover.json +204 -0
- package/locales/zh-CN/metadata.json +20 -3
- package/locales/zh-CN/models.json +845 -0
- package/locales/zh-CN/providers.json +80 -0
- package/locales/zh-CN/welcome.json +1 -1
- package/locales/zh-TW/common.json +1 -1
- package/locales/zh-TW/discover.json +204 -0
- package/locales/zh-TW/metadata.json +20 -3
- package/locales/zh-TW/models.json +845 -0
- package/locales/zh-TW/providers.json +80 -0
- package/package.json +3 -2
- package/src/app/(main)/@nav/_layout/Desktop/TopActions.test.tsx +3 -3
- package/src/app/(main)/@nav/_layout/Desktop/TopActions.tsx +3 -3
- package/src/app/(main)/@nav/_layout/Mobile.tsx +3 -3
- package/src/app/(main)/_layout/Mobile.tsx +9 -1
- package/src/app/(main)/discover/(detail)/_layout/Desktop.tsx +24 -0
- package/src/app/(main)/discover/(detail)/_layout/Mobile/Header.tsx +25 -0
- package/src/app/(main)/discover/(detail)/_layout/Mobile/index.tsx +17 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/Actions.tsx +35 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/AddAgent.tsx +86 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/ConversationExample/TopicList.tsx +74 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/ConversationExample/index.tsx +100 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/Header.tsx +118 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/InfoSidebar/SuggestionItem.tsx +62 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/InfoSidebar/ToolItem.tsx +19 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/InfoSidebar/index.tsx +64 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/SystemRole.tsx +35 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/features/Temp.tsx +44 -0
- package/src/app/(main)/discover/(detail)/assistant/[slug]/page.tsx +121 -0
- package/src/app/(main)/discover/(detail)/error.tsx +5 -0
- package/src/app/(main)/discover/(detail)/features/Back.tsx +42 -0
- package/src/app/(main)/discover/(detail)/features/Block.tsx +50 -0
- package/src/app/(main)/discover/(detail)/features/DetailLayout.tsx +91 -0
- package/src/app/(main)/discover/(detail)/features/HighlightBlock.tsx +82 -0
- package/src/app/(main)/discover/(detail)/features/ShareButton.tsx +160 -0
- package/src/app/(main)/discover/(detail)/features/SidebarContainer.tsx +19 -0
- package/src/app/(main)/discover/(detail)/layout.tsx +12 -0
- package/src/app/(main)/discover/(detail)/loading.tsx +38 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/Actions.tsx +46 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/ChatWithModel.tsx +93 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/Header.tsx +85 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/InfoSidebar/SuggestionItem.tsx +75 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/InfoSidebar/index.tsx +49 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/ParameterList/ParameterItem.tsx +71 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/ParameterList/index.tsx +110 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/ProviderList/ProviderItem.tsx +152 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/features/ProviderList/index.tsx +45 -0
- package/src/app/(main)/discover/(detail)/model/[...slugs]/page.tsx +114 -0
- package/src/app/(main)/discover/(detail)/not-found.tsx +3 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/Actions.tsx +35 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/Header.tsx +114 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/InfoSidebar/SuggestionItem.tsx +62 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/InfoSidebar/index.tsx +49 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/InstallPlugin.tsx +87 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/ParameterList.tsx +95 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/features/Schema.tsx +23 -0
- package/src/app/(main)/discover/(detail)/plugin/[slug]/page.tsx +103 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/Actions.tsx +49 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/Header.tsx +73 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/InfoSidebar/SuggestionItem.tsx +75 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/InfoSidebar/index.tsx +49 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/ModelList/ModelItem.tsx +148 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/ModelList/index.tsx +60 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/features/ProviderConfig.tsx +80 -0
- package/src/app/(main)/discover/(detail)/provider/[slug]/page.tsx +116 -0
- package/src/app/(main)/discover/(list)/(home)/Client.tsx +42 -0
- package/src/app/(main)/discover/(list)/(home)/features/AssistantList.tsx +33 -0
- package/src/app/(main)/discover/(list)/(home)/features/ModelList.tsx +22 -0
- package/src/app/(main)/discover/(list)/(home)/features/PluginList.tsx +25 -0
- package/src/app/(main)/discover/(list)/(home)/loading.tsx +1 -0
- package/src/app/(main)/discover/(list)/(home)/page.tsx +54 -0
- package/src/app/(main)/discover/(list)/_layout/Desktop/Nav.tsx +118 -0
- package/src/app/(main)/discover/(list)/_layout/Desktop/index.tsx +37 -0
- package/src/app/(main)/discover/(list)/_layout/Desktop/useScroll.ts +33 -0
- package/src/app/(main)/discover/(list)/_layout/Mobile/Header.tsx +62 -0
- package/src/app/(main)/discover/(list)/_layout/Mobile/Nav.tsx +94 -0
- package/src/app/(main)/discover/(list)/_layout/Mobile/index.tsx +27 -0
- package/src/app/(main)/discover/(list)/assistants/[slug]/page.tsx +64 -0
- package/src/app/(main)/discover/(list)/assistants/_layout/Desktop.tsx +22 -0
- package/src/app/(main)/discover/(list)/assistants/_layout/Mobile.tsx +9 -0
- package/src/app/(main)/discover/(list)/assistants/features/Card.tsx +176 -0
- package/src/app/(main)/discover/(list)/assistants/features/Category.tsx +48 -0
- package/src/app/(main)/discover/(list)/assistants/features/List.tsx +97 -0
- package/src/app/(main)/discover/(list)/assistants/features/useCategory.tsx +116 -0
- package/src/app/(main)/discover/(list)/assistants/layout.tsx +12 -0
- package/src/app/(main)/discover/(list)/assistants/loading.tsx +1 -0
- package/src/app/(main)/discover/(list)/assistants/page.tsx +51 -0
- package/src/app/(main)/discover/(list)/error.tsx +5 -0
- package/src/app/(main)/{market → discover/(list)}/layout.tsx +4 -3
- package/src/app/(main)/discover/(list)/loading.tsx +39 -0
- package/src/app/(main)/discover/(list)/models/[slug]/page.tsx +70 -0
- package/src/app/(main)/discover/(list)/models/_layout/Desktop.tsx +28 -0
- package/src/app/(main)/discover/(list)/models/_layout/Mobile.tsx +9 -0
- package/src/app/(main)/discover/(list)/models/features/Card.tsx +116 -0
- package/src/app/(main)/discover/(list)/models/features/Category.tsx +67 -0
- package/src/app/(main)/discover/(list)/models/features/List.tsx +72 -0
- package/src/app/(main)/discover/(list)/models/features/const.ts +9 -0
- package/src/app/(main)/discover/(list)/models/layout.tsx +12 -0
- package/src/app/(main)/discover/(list)/models/loading.tsx +1 -0
- package/src/app/(main)/discover/(list)/models/page.tsx +61 -0
- package/src/app/(main)/discover/(list)/not-found.tsx +3 -0
- package/src/app/(main)/discover/(list)/plugins/[slug]/page.tsx +64 -0
- package/src/app/(main)/discover/(list)/plugins/_layout/Desktop.tsx +22 -0
- package/src/app/(main)/discover/(list)/plugins/_layout/Mobile.tsx +9 -0
- package/src/app/(main)/discover/(list)/plugins/features/Card.tsx +154 -0
- package/src/app/(main)/discover/(list)/plugins/features/Category.tsx +45 -0
- package/src/app/(main)/discover/(list)/plugins/features/List.tsx +96 -0
- package/src/app/(main)/discover/(list)/plugins/features/useCategory.tsx +80 -0
- package/src/app/(main)/discover/(list)/plugins/layout.tsx +12 -0
- package/src/app/(main)/discover/(list)/plugins/loading.tsx +1 -0
- package/src/app/(main)/discover/(list)/plugins/page.tsx +52 -0
- package/src/app/(main)/discover/(list)/providers/features/Card.tsx +117 -0
- package/src/app/(main)/discover/(list)/providers/features/List.tsx +71 -0
- package/src/app/(main)/discover/(list)/providers/loading.tsx +1 -0
- package/src/app/(main)/discover/(list)/providers/page.tsx +52 -0
- package/src/app/(main)/discover/_layout/Desktop/Header.tsx +36 -0
- package/src/app/(main)/discover/_layout/Desktop/index.tsx +21 -0
- package/src/app/(main)/discover/_layout/Mobile/index.tsx +9 -0
- package/src/app/(main)/{market/features/AgentCard/AgentCardBanner.tsx → discover/components/CardBanner.tsx} +5 -5
- package/src/app/(main)/discover/components/CategoryContainer.tsx +18 -0
- package/src/app/(main)/discover/components/CategoryMenu.tsx +39 -0
- package/src/app/(main)/discover/components/GitHubAvatar.tsx +19 -0
- package/src/app/(main)/discover/components/GridLoadingCard.tsx +69 -0
- package/src/app/(main)/discover/components/ListLoading.tsx +66 -0
- package/src/app/(main)/discover/components/Loading.tsx +17 -0
- package/src/app/(main)/discover/components/SearchResultCount.tsx +37 -0
- package/src/app/(main)/discover/components/Statistic.tsx +92 -0
- package/src/app/(main)/discover/components/Title.tsx +76 -0
- package/src/app/(main)/discover/components/VirtuosoGridList/index.tsx +52 -0
- package/src/app/(main)/discover/components/VirtuosoGridList/useScrollParent.ts +19 -0
- package/src/app/(main)/discover/error.tsx +5 -0
- package/src/app/(main)/{market/features/ShareAgentButton → discover/features/CreateButton}/Inner.tsx +9 -10
- package/src/app/(main)/{market/features/ShareAgentButton → discover/features/CreateButton}/index.tsx +9 -9
- package/src/app/(main)/discover/features/LikeButton.tsx +73 -0
- package/src/app/(main)/discover/features/ModelFeatureTags.tsx +77 -0
- package/src/app/(main)/discover/features/StoreSearchBar.tsx +84 -0
- package/src/app/(main)/discover/features/const.ts +2 -0
- package/src/app/(main)/discover/features/useNav.tsx +71 -0
- package/src/app/(main)/discover/layout.tsx +12 -0
- package/src/app/(main)/discover/loading.tsx +9 -0
- package/src/app/(main)/discover/not-found.tsx +3 -0
- package/src/app/(main)/discover/search/_layout/Desktop.tsx +42 -0
- package/src/app/(main)/discover/search/_layout/Mobile/Header.tsx +31 -0
- package/src/app/(main)/discover/search/_layout/Mobile/Nav.tsx +56 -0
- package/src/app/(main)/discover/search/_layout/Mobile/index.tsx +32 -0
- package/src/app/(main)/discover/search/features/AssistantsResult.tsx +27 -0
- package/src/app/(main)/discover/search/features/Category.tsx +41 -0
- package/src/app/(main)/discover/search/features/ModelsResult.tsx +27 -0
- package/src/app/(main)/discover/search/features/PluginsResult.tsx +27 -0
- package/src/app/(main)/discover/search/features/ProvidersResult.tsx +26 -0
- package/src/app/(main)/discover/search/layout.tsx +12 -0
- package/src/app/(main)/discover/search/loading.tsx +1 -0
- package/src/app/(main)/discover/search/page.tsx +78 -0
- package/src/app/(main)/settings/llm/components/ProviderConfig/index.tsx +0 -6
- package/src/app/(main)/welcome/features/Actions.tsx +1 -1
- package/src/app/@modal/(.)discover/assistant/[slug]/page.tsx +1 -0
- package/src/app/@modal/(.)discover/layout.tsx +29 -0
- package/src/app/@modal/(.)discover/loading.tsx +3 -0
- package/src/app/@modal/(.)discover/model/[...slugs]/page.tsx +1 -0
- package/src/app/@modal/(.)discover/plugin/[slug]/page.tsx +1 -0
- package/src/app/@modal/(.)discover/provider/[slug]/page.tsx +1 -0
- package/src/app/@modal/features/InterceptingContext.tsx +9 -0
- package/src/app/@modal/layout.tsx +58 -21
- package/src/app/api/{market → assistant}/[id]/route.ts +2 -3
- package/src/app/api/{market → assistant/store}/route.ts +2 -5
- package/src/app/api/plugin/store/route.ts +1 -4
- package/src/app/metadata.ts +3 -0
- package/src/app/redirect/page.tsx +15 -0
- package/src/components/FetchErrorNotification/Description.tsx +2 -0
- package/src/components/InterceptingLink/index.tsx +27 -0
- package/src/components/mdx/CodeBlock.tsx +46 -0
- package/src/components/mdx/Link.tsx +21 -0
- package/src/components/mdx/index.tsx +51 -0
- package/src/const/discover.ts +63 -1
- package/src/features/Conversation/Error/PluginSettings.tsx +1 -1
- package/src/features/Conversation/Messages/Tool/Inspector/Settings.tsx +1 -1
- package/src/features/Conversation/components/InboxWelcome/AgentsSuggest.tsx +41 -24
- package/src/features/MobileTabBar/index.tsx +3 -3
- package/src/features/PluginDetailModal/APIs.tsx +1 -1
- package/src/features/PluginDevModal/UrlManifestForm.tsx +1 -1
- package/src/features/PluginStore/PluginItem/Action.tsx +1 -1
- package/src/features/PluginsUI/Render/DefaultType/index.tsx +1 -1
- package/src/features/PluginsUI/Render/StandaloneType/index.tsx +1 -1
- package/src/hooks/useInterceptingRoutes.ts +21 -1
- package/src/hooks/useShare.tsx +191 -0
- package/src/locales/create.ts +1 -1
- package/src/locales/default/common.ts +1 -1
- package/src/locales/default/discover.ts +205 -0
- package/src/locales/default/index.ts +6 -2
- package/src/locales/default/metadata.ts +23 -3
- package/src/locales/default/models.ts +15 -0
- package/src/locales/default/providers.ts +15 -0
- package/src/locales/default/welcome.ts +1 -1
- package/src/locales/resources.ts +2 -0
- package/src/server/ld.ts +85 -11
- package/src/server/metadata.ts +41 -3
- package/src/{app/api/market/AgentMarket.test.ts → server/modules/AssistantStore/index.test.ts} +15 -15
- package/src/{app/api/market/AgentMarket.ts → server/modules/AssistantStore/index.ts} +7 -3
- package/src/{app/api/plugin/store/Store.test.ts → server/modules/PluginStore/index.test.ts} +1 -1
- package/src/server/services/discover/index.ts +352 -0
- package/src/server/services/doc/index.tsx +40 -0
- package/src/server/translation.ts +11 -5
- package/src/services/__tests__/__snapshots__/tool.test.ts.snap +1 -1
- package/src/services/{_auth.test.ts → __tests__/_auth.test.ts} +1 -1
- package/src/services/__tests__/assistant.test.ts +82 -0
- package/src/services/__tests__/tool.test.ts +13 -13
- package/src/services/_url.ts +2 -2
- package/src/services/assistant.ts +30 -0
- package/src/services/chat.ts +1 -1
- package/src/services/tool.ts +7 -129
- package/src/store/chat/slices/plugin/action.test.ts +112 -0
- package/src/store/chat/slices/plugin/action.ts +1 -3
- package/src/store/global/initialState.ts +1 -1
- package/src/store/tool/selectors/tool.test.ts +1 -1
- package/src/store/tool/slices/customPlugin/action.test.ts +1 -1
- package/src/store/tool/slices/customPlugin/action.ts +1 -1
- package/src/store/tool/slices/plugin/action.ts +1 -1
- package/src/store/tool/slices/plugin/selectors.test.ts +3 -3
- package/src/store/tool/slices/plugin/selectors.ts +3 -3
- package/src/store/tool/slices/store/action.test.ts +16 -22
- package/src/store/tool/slices/store/action.ts +8 -8
- package/src/types/discover.ts +152 -0
- package/src/types/llm.ts +4 -2
- package/src/types/meta.ts +1 -0
- package/src/utils/format.test.ts +191 -112
- package/src/utils/format.ts +36 -0
- package/src/utils/toolManifest.ts +124 -0
- package/src/app/(main)/market/@detail/default.tsx +0 -12
- package/src/app/(main)/market/@detail/features/AgentDetailContent.tsx +0 -73
- package/src/app/(main)/market/@detail/features/Banner.tsx +0 -46
- package/src/app/(main)/market/@detail/features/Comment.tsx +0 -16
- package/src/app/(main)/market/@detail/features/Header.tsx +0 -81
- package/src/app/(main)/market/@detail/features/Loading.tsx +0 -63
- package/src/app/(main)/market/@detail/features/TokenTag.tsx +0 -27
- package/src/app/(main)/market/@detail/features/style.ts +0 -32
- package/src/app/(main)/market/_layout/Desktop/DetailSidebar.tsx +0 -84
- package/src/app/(main)/market/_layout/Desktop/Header.tsx +0 -29
- package/src/app/(main)/market/_layout/Desktop/Hero.tsx +0 -40
- package/src/app/(main)/market/_layout/Desktop/index.tsx +0 -46
- package/src/app/(main)/market/_layout/Mobile/DetailModal.tsx +0 -32
- package/src/app/(main)/market/_layout/Mobile/Header.tsx +0 -20
- package/src/app/(main)/market/_layout/Mobile/index.tsx +0 -25
- package/src/app/(main)/market/_layout/type.ts +0 -6
- package/src/app/(main)/market/features/AgentCard/index.tsx +0 -139
- package/src/app/(main)/market/features/AgentList.tsx +0 -103
- package/src/app/(main)/market/features/AgentSearchBar.tsx +0 -42
- package/src/app/(main)/market/features/TagList.tsx +0 -69
- package/src/app/(main)/market/loading.tsx +0 -15
- package/src/app/(main)/market/page.tsx +0 -44
- package/src/const/market.ts +0 -15
- package/src/locales/default/market.ts +0 -32
- package/src/services/market.ts +0 -22
- package/src/store/market/action.ts +0 -82
- package/src/store/market/index.ts +0 -3
- package/src/store/market/initialState.ts +0 -19
- package/src/store/market/selectors.ts +0 -38
- package/src/store/market/store.ts +0 -48
- package/src/types/market.ts +0 -20
- /package/src/{app/api/plugin/store/Store.ts → server/modules/PluginStore/index.ts} +0 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
2
|
+
import { LobeChatPluginMeta, Meta } from '@lobehub/chat-plugin-sdk/lib/types/market';
|
3
|
+
|
4
|
+
import { ChatModelCard, ModelProviderCard } from '@/types/llm';
|
5
|
+
import { MetaData } from '@/types/meta';
|
6
|
+
import { LobeAgentSettings } from '@/types/session';
|
7
|
+
|
8
|
+
export enum AssistantCategory {
|
9
|
+
Academic = 'academic',
|
10
|
+
All = 'all',
|
11
|
+
Career = 'career',
|
12
|
+
CopyWriting = 'copywriting',
|
13
|
+
Design = 'design',
|
14
|
+
Education = 'education',
|
15
|
+
Emotions = 'emotions',
|
16
|
+
Entertainment = 'entertainment',
|
17
|
+
Games = 'games',
|
18
|
+
General = 'general',
|
19
|
+
Life = 'life',
|
20
|
+
Marketing = 'marketing',
|
21
|
+
Office = 'office',
|
22
|
+
Programming = 'programming',
|
23
|
+
Translation = 'translation',
|
24
|
+
}
|
25
|
+
|
26
|
+
export enum PluginCategory {
|
27
|
+
All = 'all',
|
28
|
+
GamingEntertainment = 'gaming-entertainment',
|
29
|
+
LifeStyle = 'lifestyle',
|
30
|
+
MediaGenerate = 'media-generate',
|
31
|
+
ScienceEducation = 'science-education',
|
32
|
+
Social = 'social',
|
33
|
+
StocksFinance = 'stocks-finance',
|
34
|
+
Tools = 'tools',
|
35
|
+
WebSearch = 'web-search',
|
36
|
+
}
|
37
|
+
|
38
|
+
export enum DiscoverTab {
|
39
|
+
Assistants = 'assistants',
|
40
|
+
Home = 'home',
|
41
|
+
Models = 'models',
|
42
|
+
Plugins = 'plugins',
|
43
|
+
Providers = 'providers',
|
44
|
+
}
|
45
|
+
|
46
|
+
// TODO 可能需要修改
|
47
|
+
export interface ExampleTopic {
|
48
|
+
description: string;
|
49
|
+
id: string;
|
50
|
+
title: string;
|
51
|
+
}
|
52
|
+
|
53
|
+
// TODO 服务端接口待补充
|
54
|
+
export interface DiscoverAssistantItem extends LobeAgentSettings {
|
55
|
+
author: string;
|
56
|
+
createdAt: string;
|
57
|
+
examples?: ExampleTopic[];
|
58
|
+
homepage: string;
|
59
|
+
identifier: string;
|
60
|
+
meta: MetaData & {
|
61
|
+
category?: AssistantCategory;
|
62
|
+
};
|
63
|
+
schemaVersion: 1;
|
64
|
+
socialData: {
|
65
|
+
conversations: number;
|
66
|
+
likes: number;
|
67
|
+
users: number;
|
68
|
+
};
|
69
|
+
suggestions: Omit<DiscoverAssistantItem, 'suggestions' | 'socialData' | 'config'>[];
|
70
|
+
}
|
71
|
+
|
72
|
+
export interface DiscoverModelItem {
|
73
|
+
createdAt: string;
|
74
|
+
identifier: string;
|
75
|
+
meta: Omit<ChatModelCard, 'displayName' | 'deploymentName'> & {
|
76
|
+
category?: string;
|
77
|
+
title: string;
|
78
|
+
};
|
79
|
+
providers?: string[];
|
80
|
+
socialData: {
|
81
|
+
conversations: number;
|
82
|
+
likes: number;
|
83
|
+
tokens: number;
|
84
|
+
};
|
85
|
+
suggestions: Omit<DiscoverModelItem, 'suggestions' | 'socialData' | 'providers'>[];
|
86
|
+
}
|
87
|
+
|
88
|
+
export interface DiscoverProviderItem {
|
89
|
+
createdAt: string;
|
90
|
+
identifier: string;
|
91
|
+
meta: Omit<ModelProviderCard, 'chatModels' | 'name'> & {
|
92
|
+
description?: string;
|
93
|
+
title: string;
|
94
|
+
};
|
95
|
+
models: string[];
|
96
|
+
socialData: {
|
97
|
+
conversations: number;
|
98
|
+
likes: number;
|
99
|
+
users: number;
|
100
|
+
};
|
101
|
+
suggestions: Omit<DiscoverProviderItem, 'suggestions' | 'socialData'>[];
|
102
|
+
}
|
103
|
+
|
104
|
+
// TODO 服务端接口待补充
|
105
|
+
export type DiscoverPlugintem = LobeChatPluginMeta & {
|
106
|
+
manifest: LobeChatPluginManifest;
|
107
|
+
meta: Meta & {
|
108
|
+
category?: PluginCategory;
|
109
|
+
};
|
110
|
+
socialData: {
|
111
|
+
called: number;
|
112
|
+
executionTime: number;
|
113
|
+
likes: number;
|
114
|
+
relatedAssistants: number;
|
115
|
+
successRate: number;
|
116
|
+
users: number;
|
117
|
+
};
|
118
|
+
suggestions: Omit<DiscoverPlugintem, 'suggestions' | 'socialData' | 'manifest'>[];
|
119
|
+
};
|
120
|
+
|
121
|
+
export enum SortBy {
|
122
|
+
MostLiked = 'liked',
|
123
|
+
MostUsed = 'used',
|
124
|
+
Newest = 'newest',
|
125
|
+
Oldest = 'oldest',
|
126
|
+
Recommended = 'recommended',
|
127
|
+
}
|
128
|
+
|
129
|
+
export enum TimePeriod {
|
130
|
+
All = 'all',
|
131
|
+
Day = 'day',
|
132
|
+
Month = 'month',
|
133
|
+
Week = 'week',
|
134
|
+
Year = 'year',
|
135
|
+
}
|
136
|
+
|
137
|
+
export enum AuthorRange {
|
138
|
+
Everyone = 'everyone',
|
139
|
+
Followed = 'followed',
|
140
|
+
}
|
141
|
+
|
142
|
+
export interface FilterBy {
|
143
|
+
author?: AuthorRange;
|
144
|
+
content?: number;
|
145
|
+
fc?: boolean;
|
146
|
+
knowledge?: boolean;
|
147
|
+
plugin?: boolean;
|
148
|
+
price?: number;
|
149
|
+
time?: TimePeriod;
|
150
|
+
token?: number;
|
151
|
+
vision?: boolean;
|
152
|
+
}
|
package/src/types/llm.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { ReactNode } from 'react';
|
2
2
|
|
3
|
+
export type ModelPriceCurrency = 'CNY' | 'USD';
|
4
|
+
|
3
5
|
export interface ChatModelCard {
|
4
6
|
/**
|
5
7
|
* only used in azure
|
@@ -39,7 +41,7 @@ export interface ChatModelCard {
|
|
39
41
|
* the currency of the pricing
|
40
42
|
* @default USD
|
41
43
|
*/
|
42
|
-
currency?:
|
44
|
+
currency?: ModelPriceCurrency;
|
43
45
|
/**
|
44
46
|
* the input pricing, e.g. $1 / 1M tokens
|
45
47
|
*/
|
@@ -128,7 +130,7 @@ export interface ModelProviderCard {
|
|
128
130
|
/**
|
129
131
|
* provider's website url
|
130
132
|
*/
|
131
|
-
url
|
133
|
+
url: string;
|
132
134
|
}
|
133
135
|
|
134
136
|
// 语言模型的设置参数
|
package/src/types/meta.ts
CHANGED
package/src/utils/format.test.ts
CHANGED
@@ -1,116 +1,195 @@
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
2
2
|
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
});
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
});
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
});
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
3
|
+
import {
|
4
|
+
formatNumber,
|
5
|
+
formatPrice,
|
6
|
+
formatPriceByCurrency,
|
7
|
+
formatShortenNumber,
|
8
|
+
formatSize,
|
9
|
+
formatSpeed,
|
10
|
+
formatTime,
|
11
|
+
formatTokenNumber,
|
12
|
+
} from './format';
|
13
|
+
|
14
|
+
// 保留你已经编写的测试用例
|
15
|
+
describe('format', () => {
|
16
|
+
describe('formatSize', () => {
|
17
|
+
it('should format bytes to KB correctly', () => {
|
18
|
+
expect(formatSize(1024)).toBe('1.0 KB');
|
19
|
+
expect(formatSize(2048)).toBe('2.0 KB');
|
20
|
+
expect(formatSize(1536)).toBe('1.5 KB');
|
21
|
+
});
|
22
|
+
|
23
|
+
it('should format bytes to MB correctly', () => {
|
24
|
+
expect(formatSize(1048576)).toBe('1.0 MB');
|
25
|
+
expect(formatSize(2097152)).toBe('2.0 MB');
|
26
|
+
expect(formatSize(1572864)).toBe('1.5 MB');
|
27
|
+
});
|
28
|
+
|
29
|
+
it('should format bytes to GB correctly', () => {
|
30
|
+
expect(formatSize(1073741824)).toBe('1.0 GB');
|
31
|
+
expect(formatSize(2147483648)).toBe('2.0 GB');
|
32
|
+
expect(formatSize(1610612736)).toBe('1.5 GB');
|
33
|
+
});
|
34
|
+
|
35
|
+
it('should handle edge cases', () => {
|
36
|
+
expect(formatSize(0)).toBe('0.0 KB');
|
37
|
+
expect(formatSize(1023)).toBe('1.0 KB');
|
38
|
+
expect(formatSize(1073741823)).toBe('1024.0 MB');
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
42
|
+
describe('formatSpeed', () => {
|
43
|
+
it('should format speed in KB/s correctly', () => {
|
44
|
+
expect(formatSpeed(10 * 1024)).toBe('10.00 KB/s');
|
45
|
+
expect(formatSpeed(999.99 * 1024)).toBe('999.99 KB/s');
|
46
|
+
});
|
47
|
+
|
48
|
+
it('should format speed in MB/s correctly', () => {
|
49
|
+
expect(formatSpeed(1024 * 1024)).toBe('1.00 MB/s');
|
50
|
+
expect(formatSpeed(10240 * 1024)).toBe('10.00 MB/s');
|
51
|
+
});
|
52
|
+
|
53
|
+
it('should format speed in GB/s correctly', () => {
|
54
|
+
expect(formatSpeed(1048576 * 1024)).toBe('1.00 GB/s');
|
55
|
+
expect(formatSpeed(10485760 * 1024)).toBe('10.00 GB/s');
|
56
|
+
});
|
57
|
+
|
58
|
+
it('should handle edge cases', () => {
|
59
|
+
expect(formatSpeed(0)).toBe('0.00 Byte/s');
|
60
|
+
expect(formatSpeed(1000 * 1024)).toBe('1000.00 KB/s');
|
61
|
+
expect(formatSpeed(1000.01 * 1024)).toBe('0.98 MB/s');
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
describe('formatTime', () => {
|
66
|
+
it('should format time in seconds correctly', () => {
|
67
|
+
expect(formatTime(30)).toBe('30.0 s');
|
68
|
+
expect(formatTime(59.9)).toBe('59.9 s');
|
69
|
+
});
|
70
|
+
|
71
|
+
it('should format time in minutes correctly', () => {
|
72
|
+
expect(formatTime(60)).toBe('1.0 min');
|
73
|
+
expect(formatTime(3599)).toBe('60.0 min');
|
74
|
+
});
|
75
|
+
|
76
|
+
it('should format time in hours correctly', () => {
|
77
|
+
expect(formatTime(3600)).toBe('1.00 h');
|
78
|
+
expect(formatTime(7200)).toBe('2.00 h');
|
79
|
+
});
|
80
|
+
|
81
|
+
it('should handle edge cases', () => {
|
82
|
+
expect(formatTime(0)).toBe('0.0 s');
|
83
|
+
expect(formatTime(59.99)).toBe('60.0 s');
|
84
|
+
expect(formatTime(3599.99)).toBe('60.0 min');
|
85
|
+
});
|
86
|
+
it('should handle edge cases', () => {
|
87
|
+
expect(formatTime(0)).toBe('0.0 s');
|
88
|
+
expect(formatTime(59.99)).toBe('60.0 s');
|
89
|
+
expect(formatTime(3599.99)).toBe('60.0 min');
|
90
|
+
});
|
91
|
+
});
|
92
|
+
|
93
|
+
describe('formatShortenNumber', () => {
|
94
|
+
it('should return the input if it is not a number', () => {
|
95
|
+
expect(formatShortenNumber('not a number')).toBe('not a number');
|
96
|
+
expect(formatShortenNumber(null)).toBe(null);
|
97
|
+
});
|
98
|
+
|
99
|
+
it('should format numbers less than 10,000 correctly', () => {
|
100
|
+
expect(formatShortenNumber(0)).toBe(0);
|
101
|
+
expect(formatShortenNumber(1234)).toBe('1,234');
|
102
|
+
expect(formatShortenNumber(9999)).toBe('9,999');
|
103
|
+
});
|
104
|
+
|
105
|
+
it('should format numbers between 10,000 and 9,999,999 correctly', () => {
|
106
|
+
expect(formatShortenNumber(10000)).toBe('10.0K');
|
107
|
+
expect(formatShortenNumber(123456)).toBe('123.5K');
|
108
|
+
expect(formatShortenNumber(9999999)).toBe('10000.0K');
|
109
|
+
});
|
110
|
+
|
111
|
+
it('should format numbers 10,000,000 and above correctly', () => {
|
112
|
+
expect(formatShortenNumber(10000000)).toBe('10.0M');
|
113
|
+
expect(formatShortenNumber(123456789)).toBe('123.5M');
|
114
|
+
expect(formatShortenNumber(9876543210)).toBe('9876.5M');
|
115
|
+
});
|
116
|
+
});
|
117
|
+
|
118
|
+
describe('formatNumber', () => {
|
119
|
+
it('should format numbers with commas correctly', () => {
|
120
|
+
expect(formatNumber(1000)).toBe('1,000');
|
121
|
+
expect(formatNumber(1000000)).toBe('1,000,000');
|
122
|
+
expect(formatNumber(1234567.89)).toBe('1,234,567.89');
|
123
|
+
});
|
124
|
+
|
125
|
+
it('should handle non-number inputs', () => {
|
126
|
+
expect(formatNumber('1000')).toBe('1,000');
|
127
|
+
expect(formatNumber('not a number')).toBe(Number.NaN.toString());
|
128
|
+
expect(formatNumber(null)).toBe(undefined);
|
129
|
+
});
|
130
|
+
});
|
131
|
+
|
132
|
+
describe('formatPrice', () => {
|
133
|
+
it('should format prices correctly', () => {
|
134
|
+
expect(formatPrice(1000)).toBe('1,000.00');
|
135
|
+
expect(formatPrice(1234.56)).toBe('1,234.56');
|
136
|
+
expect(formatPrice(0.99)).toBe('0.99');
|
137
|
+
expect(formatPrice(1000000.01)).toBe('1,000,000.01');
|
138
|
+
});
|
139
|
+
});
|
140
|
+
|
141
|
+
describe('formatPriceByCurrency', () => {
|
142
|
+
it('should format USD prices correctly', () => {
|
143
|
+
expect(formatPriceByCurrency(1000)).toBe('1,000.00');
|
144
|
+
expect(formatPriceByCurrency(1234.56, 'USD')).toBe('1,234.56');
|
145
|
+
});
|
146
|
+
|
147
|
+
it('should format CNY prices correctly', () => {
|
148
|
+
// Assuming CNY_TO_USD is 6.5
|
149
|
+
const CNY_TO_USD = 6.5;
|
150
|
+
expect(formatPriceByCurrency(1000, 'CNY')).toBe('140.06');
|
151
|
+
expect(formatPriceByCurrency(6500, 'CNY')).toBe('910.36');
|
152
|
+
});
|
153
|
+
});
|
154
|
+
|
155
|
+
describe('formatTokenNumber', () => {
|
156
|
+
it('should return "1K" for numbers between 1 and 1023', () => {
|
157
|
+
expect(formatTokenNumber(500)).toBe('1K');
|
158
|
+
expect(formatTokenNumber(1000)).toBe('1K');
|
159
|
+
});
|
160
|
+
|
161
|
+
it('should format numbers between 1024 and 41,983 correctly', () => {
|
162
|
+
expect(formatTokenNumber(1024)).toBe('1K');
|
163
|
+
expect(formatTokenNumber(2000)).toBe('2K');
|
164
|
+
expect(formatTokenNumber(2048)).toBe('2K');
|
165
|
+
expect(formatTokenNumber(4000)).toBe('4K');
|
166
|
+
expect(formatTokenNumber(4096)).toBe('4K');
|
167
|
+
expect(formatTokenNumber(32000)).toBe('32K');
|
168
|
+
expect(formatTokenNumber(65536)).toBe('64K');
|
169
|
+
});
|
170
|
+
|
171
|
+
it('should format numbers between 41,984 and 127,999 correctly', () => {
|
172
|
+
expect(formatTokenNumber(41984)).toBe('41K');
|
173
|
+
expect(formatTokenNumber(100000)).toBe('97K');
|
174
|
+
expect(formatTokenNumber(127999)).toBe('124K');
|
175
|
+
});
|
176
|
+
|
177
|
+
it('should return "128K" for 131,072', () => {
|
178
|
+
expect(formatTokenNumber(131072)).toBe('128K'); // Qwen
|
179
|
+
});
|
180
|
+
|
181
|
+
it('should format numbers between 128,000 and 999,999 correctly', () => {
|
182
|
+
expect(formatTokenNumber(128000)).toBe('128K');
|
183
|
+
expect(formatTokenNumber(200000)).toBe('200K'); // Claude
|
184
|
+
expect(formatTokenNumber(999999)).toBe('999K');
|
185
|
+
});
|
186
|
+
|
187
|
+
it('should format numbers 1,000,000 and above correctly', () => {
|
188
|
+
expect(formatTokenNumber(1000000)).toBe('1M');
|
189
|
+
expect(formatTokenNumber(1024000)).toBe('1M');
|
190
|
+
expect(formatTokenNumber(1048576)).toBe('1M'); // Gemini Flash
|
191
|
+
expect(formatTokenNumber(2000000)).toBe('2M');
|
192
|
+
expect(formatTokenNumber(2097152)).toBe('2M'); // Gemini Pro
|
193
|
+
});
|
115
194
|
});
|
116
195
|
});
|
package/src/utils/format.ts
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
import { isNumber } from 'lodash-es';
|
2
|
+
import numeral from 'numeral';
|
3
|
+
|
4
|
+
import { CNY_TO_USD } from '@/const/discover';
|
5
|
+
import { ModelPriceCurrency } from '@/types/llm';
|
6
|
+
|
1
7
|
export const formatSize = (bytes: number, fractionDigits = 1): string => {
|
2
8
|
const kbSize = bytes / 1024;
|
3
9
|
if (kbSize < 1024) {
|
@@ -47,11 +53,29 @@ export const formatTime = (timeInSeconds: number): string => {
|
|
47
53
|
}
|
48
54
|
};
|
49
55
|
|
56
|
+
export const formatShortenNumber = (num: any) => {
|
57
|
+
if (!isNumber(num)) return num;
|
58
|
+
// 使用Intl.NumberFormat来添加千分号
|
59
|
+
const formattedWithComma = new Intl.NumberFormat('en-US').format(num);
|
60
|
+
|
61
|
+
// 格式化为 K 或 M
|
62
|
+
if (num >= 10_000_000) {
|
63
|
+
return (num / 1_000_000).toFixed(1) + 'M';
|
64
|
+
} else if (num >= 10_000) {
|
65
|
+
return (num / 1000).toFixed(1) + 'K';
|
66
|
+
} else if (num === 0) {
|
67
|
+
return 0;
|
68
|
+
} else {
|
69
|
+
return formattedWithComma;
|
70
|
+
}
|
71
|
+
};
|
72
|
+
|
50
73
|
/**
|
51
74
|
* format number with comma
|
52
75
|
* @param num
|
53
76
|
*/
|
54
77
|
export const formatNumber = (num: any) => {
|
78
|
+
if (!num) return;
|
55
79
|
return new Intl.NumberFormat('en-US').format(num);
|
56
80
|
};
|
57
81
|
|
@@ -65,3 +89,15 @@ export const formatTokenNumber = (num: number): string => {
|
|
65
89
|
if (num === 131_072) return '128K';
|
66
90
|
return kiloToken < 1000 ? `${kiloToken}K` : `${Math.floor(kiloToken / 1000)}M`;
|
67
91
|
};
|
92
|
+
|
93
|
+
export const formatPrice = (price: number) => {
|
94
|
+
const [a, b] = price.toFixed(2).split('.');
|
95
|
+
return `${numeral(a).format('0,0')}.${b}`;
|
96
|
+
};
|
97
|
+
|
98
|
+
export const formatPriceByCurrency = (price: number, currency?: ModelPriceCurrency) => {
|
99
|
+
if (currency === 'CNY') {
|
100
|
+
return formatPrice(price / CNY_TO_USD);
|
101
|
+
}
|
102
|
+
return formatPrice(price);
|
103
|
+
};
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import { LobeChatPluginManifest, pluginManifestSchema } from '@lobehub/chat-plugin-sdk';
|
2
|
+
|
3
|
+
import { API_ENDPOINTS } from '@/services/_url';
|
4
|
+
import { OpenAIPluginManifest } from '@/types/openai/plugin';
|
5
|
+
|
6
|
+
const fetchJSON = async <T = any>(url: string, proxy = false): Promise<T> => {
|
7
|
+
// 2. 发送请求
|
8
|
+
let res: Response;
|
9
|
+
try {
|
10
|
+
res = await (proxy ? fetch(API_ENDPOINTS.proxy, { body: url, method: 'POST' }) : fetch(url));
|
11
|
+
} catch {
|
12
|
+
throw new TypeError('fetchError');
|
13
|
+
}
|
14
|
+
|
15
|
+
if (!res.ok) {
|
16
|
+
throw new TypeError('fetchError');
|
17
|
+
}
|
18
|
+
|
19
|
+
let data;
|
20
|
+
const contentType = res.headers.get('Content-Type');
|
21
|
+
|
22
|
+
try {
|
23
|
+
if (contentType === 'application/json') {
|
24
|
+
data = await res.json();
|
25
|
+
} else {
|
26
|
+
const { default: YAML } = await import('yaml');
|
27
|
+
|
28
|
+
const yaml = await res.text();
|
29
|
+
data = YAML.parse(yaml);
|
30
|
+
}
|
31
|
+
} catch {
|
32
|
+
throw new TypeError('urlError');
|
33
|
+
}
|
34
|
+
|
35
|
+
return data;
|
36
|
+
};
|
37
|
+
|
38
|
+
export const convertOpenAIManifestToLobeManifest = (
|
39
|
+
data: OpenAIPluginManifest,
|
40
|
+
): LobeChatPluginManifest => {
|
41
|
+
const manifest: LobeChatPluginManifest = {
|
42
|
+
api: [],
|
43
|
+
homepage: data.legal_info_url,
|
44
|
+
identifier: data.name_for_model,
|
45
|
+
meta: {
|
46
|
+
avatar: data.logo_url,
|
47
|
+
description: data.description_for_human,
|
48
|
+
title: data.name_for_human,
|
49
|
+
},
|
50
|
+
openapi: data.api.url,
|
51
|
+
systemRole: data.description_for_model,
|
52
|
+
type: 'default',
|
53
|
+
version: '1',
|
54
|
+
};
|
55
|
+
switch (data.auth.type) {
|
56
|
+
case 'none': {
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
case 'service_http': {
|
60
|
+
manifest.settings = {
|
61
|
+
properties: {
|
62
|
+
apiAuthKey: {
|
63
|
+
default: data.auth.verification_tokens['openai'],
|
64
|
+
description: 'API Key',
|
65
|
+
format: 'password',
|
66
|
+
title: 'API Key',
|
67
|
+
type: 'string',
|
68
|
+
},
|
69
|
+
},
|
70
|
+
type: 'object',
|
71
|
+
};
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
return manifest;
|
77
|
+
};
|
78
|
+
|
79
|
+
export const getToolManifest = async (
|
80
|
+
url?: string,
|
81
|
+
useProxy: boolean = false,
|
82
|
+
): Promise<LobeChatPluginManifest> => {
|
83
|
+
// 1. valid plugin
|
84
|
+
if (!url) {
|
85
|
+
throw new TypeError('noManifest');
|
86
|
+
}
|
87
|
+
|
88
|
+
// 2. 发送请求
|
89
|
+
|
90
|
+
let data = await fetchJSON<LobeChatPluginManifest>(url, useProxy);
|
91
|
+
|
92
|
+
// @ts-ignore
|
93
|
+
// if there is a description_for_model, it is an OpenAI plugin
|
94
|
+
// we need convert to lobe plugin
|
95
|
+
if (data['description_for_model']) {
|
96
|
+
data = convertOpenAIManifestToLobeManifest(data as any);
|
97
|
+
}
|
98
|
+
|
99
|
+
// 3. 校验插件文件格式规范
|
100
|
+
const parser = pluginManifestSchema.safeParse(data);
|
101
|
+
|
102
|
+
if (!parser.success) {
|
103
|
+
throw new TypeError('manifestInvalid', { cause: parser.error });
|
104
|
+
}
|
105
|
+
|
106
|
+
// 4. if exist OpenAPI api, merge the OpenAPIs to api
|
107
|
+
if (parser.data.openapi) {
|
108
|
+
const openapiJson = await fetchJSON(parser.data.openapi, useProxy);
|
109
|
+
|
110
|
+
try {
|
111
|
+
const { OpenAPIConvertor } = await import('@lobehub/chat-plugin-sdk/openapi');
|
112
|
+
|
113
|
+
const convertor = new OpenAPIConvertor(openapiJson);
|
114
|
+
const openAPIs = await convertor.convertOpenAPIToPluginSchema();
|
115
|
+
data.api = [...data.api, ...openAPIs];
|
116
|
+
|
117
|
+
data.settings = await convertor.convertAuthToSettingsSchema(data.settings);
|
118
|
+
} catch (error) {
|
119
|
+
throw new TypeError('openAPIInvalid', { cause: error });
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
return data;
|
124
|
+
};
|