@lobehub/chat 1.96.19 → 1.97.0

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 (509) hide show
  1. package/.env.example +7 -0
  2. package/CHANGELOG.md +50 -0
  3. package/apps/desktop/package.json +1 -1
  4. package/apps/desktop/src/main/core/Browser.ts +2 -1
  5. package/apps/desktop/src/main/utils/next-electron-rsc.ts +15 -8
  6. package/changelog/v1.json +18 -0
  7. package/locales/ar/discover.json +452 -12
  8. package/locales/ar/metadata.json +4 -0
  9. package/locales/ar/plugin.json +89 -2
  10. package/locales/ar/setting.json +1 -0
  11. package/locales/bg-BG/discover.json +452 -12
  12. package/locales/bg-BG/metadata.json +4 -0
  13. package/locales/bg-BG/plugin.json +89 -2
  14. package/locales/bg-BG/setting.json +1 -0
  15. package/locales/de-DE/discover.json +452 -12
  16. package/locales/de-DE/metadata.json +4 -0
  17. package/locales/de-DE/plugin.json +89 -2
  18. package/locales/de-DE/setting.json +1 -0
  19. package/locales/en-US/discover.json +452 -12
  20. package/locales/en-US/metadata.json +4 -0
  21. package/locales/en-US/plugin.json +89 -2
  22. package/locales/en-US/setting.json +1 -0
  23. package/locales/es-ES/discover.json +452 -12
  24. package/locales/es-ES/metadata.json +4 -0
  25. package/locales/es-ES/plugin.json +89 -2
  26. package/locales/es-ES/setting.json +1 -0
  27. package/locales/fa-IR/discover.json +452 -12
  28. package/locales/fa-IR/metadata.json +4 -0
  29. package/locales/fa-IR/plugin.json +89 -2
  30. package/locales/fa-IR/setting.json +1 -0
  31. package/locales/fr-FR/discover.json +452 -12
  32. package/locales/fr-FR/metadata.json +4 -0
  33. package/locales/fr-FR/plugin.json +89 -2
  34. package/locales/fr-FR/setting.json +1 -0
  35. package/locales/it-IT/discover.json +452 -12
  36. package/locales/it-IT/metadata.json +4 -0
  37. package/locales/it-IT/plugin.json +89 -2
  38. package/locales/it-IT/setting.json +1 -0
  39. package/locales/ja-JP/discover.json +452 -12
  40. package/locales/ja-JP/metadata.json +4 -0
  41. package/locales/ja-JP/plugin.json +89 -2
  42. package/locales/ja-JP/setting.json +1 -0
  43. package/locales/ko-KR/discover.json +452 -12
  44. package/locales/ko-KR/metadata.json +4 -0
  45. package/locales/ko-KR/plugin.json +89 -2
  46. package/locales/ko-KR/setting.json +1 -0
  47. package/locales/nl-NL/discover.json +452 -12
  48. package/locales/nl-NL/metadata.json +4 -0
  49. package/locales/nl-NL/plugin.json +89 -2
  50. package/locales/nl-NL/setting.json +1 -0
  51. package/locales/pl-PL/discover.json +452 -12
  52. package/locales/pl-PL/metadata.json +4 -0
  53. package/locales/pl-PL/plugin.json +89 -2
  54. package/locales/pl-PL/setting.json +1 -0
  55. package/locales/pt-BR/discover.json +452 -12
  56. package/locales/pt-BR/metadata.json +4 -0
  57. package/locales/pt-BR/plugin.json +89 -2
  58. package/locales/pt-BR/setting.json +1 -0
  59. package/locales/ru-RU/discover.json +452 -12
  60. package/locales/ru-RU/metadata.json +4 -0
  61. package/locales/ru-RU/plugin.json +89 -2
  62. package/locales/ru-RU/setting.json +1 -0
  63. package/locales/tr-TR/discover.json +452 -12
  64. package/locales/tr-TR/metadata.json +4 -0
  65. package/locales/tr-TR/plugin.json +89 -2
  66. package/locales/tr-TR/setting.json +1 -0
  67. package/locales/vi-VN/discover.json +452 -12
  68. package/locales/vi-VN/metadata.json +4 -0
  69. package/locales/vi-VN/plugin.json +89 -2
  70. package/locales/vi-VN/setting.json +1 -0
  71. package/locales/zh-CN/discover.json +452 -12
  72. package/locales/zh-CN/metadata.json +8 -4
  73. package/locales/zh-CN/plugin.json +89 -2
  74. package/locales/zh-CN/setting.json +1 -0
  75. package/locales/zh-TW/discover.json +452 -12
  76. package/locales/zh-TW/metadata.json +4 -0
  77. package/locales/zh-TW/plugin.json +89 -2
  78. package/locales/zh-TW/setting.json +1 -0
  79. package/next.config.ts +70 -19
  80. package/package.json +6 -2
  81. package/scripts/buildSitemapIndex/index.ts +9 -4
  82. package/src/app/(backend)/trpc/lambda/[trpc]/route.ts +5 -0
  83. package/src/app/[variants]/(main)/_layout/Mobile/index.tsx +5 -4
  84. package/src/app/[variants]/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/InboxWelcome/AgentsSuggest.tsx +31 -45
  85. package/src/app/[variants]/(main)/discover/(detail)/_layout/Desktop.tsx +8 -6
  86. package/src/app/[variants]/(main)/discover/(detail)/_layout/Mobile/Header.tsx +3 -2
  87. package/src/app/[variants]/(main)/discover/(detail)/_layout/Mobile/index.tsx +5 -1
  88. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/Client.tsx +40 -0
  89. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/DetailProvider.tsx +19 -0
  90. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Capabilities/Block.tsx +27 -0
  91. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Capabilities/Knowledge.tsx +33 -0
  92. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Capabilities/KnowledgeItem.tsx +58 -0
  93. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Capabilities/PluginItem.tsx +68 -0
  94. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Capabilities/Plugins.tsx +32 -0
  95. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Capabilities/index.tsx +37 -0
  96. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Nav.tsx +121 -0
  97. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Overview/TagList.tsx +47 -0
  98. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Overview/index.tsx +96 -0
  99. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Related/index.tsx +31 -0
  100. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/SystemRole/TagList.tsx +47 -0
  101. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/SystemRole/index.tsx +54 -0
  102. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/index.tsx +49 -0
  103. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Header.tsx +176 -0
  104. package/src/app/[variants]/(main)/discover/(detail)/assistant/{[slug]/features → [...slugs]/features/Sidebar/ActionButton}/AddAgent.tsx +22 -21
  105. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/ActionButton/index.tsx +31 -0
  106. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/Related/Item.tsx +57 -0
  107. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/Related/index.tsx +43 -0
  108. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/Summary/index.tsx +38 -0
  109. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/TocList/index.tsx +77 -0
  110. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/index.tsx +46 -0
  111. package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/loading.tsx +48 -0
  112. package/src/app/[variants]/(main)/discover/(detail)/{plugin/[slug] → assistant/[...slugs]}/page.tsx +39 -42
  113. package/src/app/[variants]/(main)/discover/(detail)/features/Breadcrumb.tsx +56 -0
  114. package/src/app/[variants]/(main)/discover/(detail)/features/DetailLayout.tsx +0 -1
  115. package/src/app/[variants]/(main)/discover/(detail)/features/MakedownRender.tsx +44 -0
  116. package/src/app/[variants]/(main)/discover/(detail)/features/ShareButton.tsx +4 -3
  117. package/src/app/[variants]/(main)/discover/(detail)/features/Toc/Heading.tsx +108 -0
  118. package/src/app/[variants]/(main)/discover/(detail)/features/Toc/index.tsx +92 -0
  119. package/src/app/[variants]/(main)/discover/(detail)/features/Toc/useToc.tsx +66 -0
  120. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/Client.tsx +43 -0
  121. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Details/Related/index.tsx +32 -0
  122. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Details/Versions/index.tsx +76 -0
  123. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Details/index.tsx +59 -0
  124. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/ActionButton/index.tsx +84 -0
  125. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/ConnectionTypeAlert.tsx +35 -0
  126. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/Related/Item.tsx +57 -0
  127. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/Related/index.tsx +44 -0
  128. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/ServerConfig.tsx +36 -0
  129. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/TocList/index.tsx +98 -0
  130. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/features/Sidebar/index.tsx +58 -0
  131. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/loading.tsx +1 -0
  132. package/src/app/[variants]/(main)/discover/(detail)/mcp/[slug]/page.tsx +103 -0
  133. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/Client.tsx +40 -0
  134. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/DetailProvider.tsx +19 -0
  135. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Details/Nav.tsx +90 -0
  136. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Details/Overview/ProviderList/index.tsx +179 -0
  137. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Details/Overview/index.tsx +22 -0
  138. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/{ParameterList → Details/Parameter}/ParameterItem.tsx +1 -1
  139. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/{ParameterList → Details/Parameter}/index.tsx +11 -11
  140. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Details/Related/index.tsx +31 -0
  141. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Details/index.tsx +47 -0
  142. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Header.tsx +84 -59
  143. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/ActionButton/ChatWithModel.tsx +92 -0
  144. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/ActionButton/index.tsx +32 -0
  145. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/Related/Item.tsx +60 -0
  146. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/Related/index.tsx +43 -0
  147. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/RelatedProviders/Item.tsx +60 -0
  148. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/RelatedProviders/index.tsx +34 -0
  149. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Sidebar/index.tsx +44 -0
  150. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/loading.tsx +1 -0
  151. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/page.tsx +22 -45
  152. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/Client.tsx +40 -0
  153. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/DetailProvider.tsx +19 -0
  154. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Details/Guide/index.tsx +25 -0
  155. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Details/Nav.tsx +99 -0
  156. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Details/Overview/ModelList/index.tsx +142 -0
  157. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Details/Overview/index.tsx +23 -0
  158. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Details/Related/index.tsx +22 -0
  159. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Details/index.tsx +47 -0
  160. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Header.tsx +99 -0
  161. package/src/app/[variants]/(main)/discover/(detail)/provider/{[slug]/features → [...slugs]/features/Sidebar/ActionButton}/ProviderConfig.tsx +9 -14
  162. package/src/app/[variants]/(main)/discover/(detail)/provider/{[slug]/features/Actions.tsx → [...slugs]/features/Sidebar/ActionButton/index.tsx} +14 -18
  163. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Sidebar/Related/Item.tsx +60 -0
  164. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Sidebar/Related/index.tsx +34 -0
  165. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Sidebar/RelatedModels/Item.tsx +60 -0
  166. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Sidebar/RelatedModels/index.tsx +43 -0
  167. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/features/Sidebar/index.tsx +44 -0
  168. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/loading.tsx +1 -0
  169. package/src/app/[variants]/(main)/discover/(detail)/provider/[...slugs]/page.tsx +103 -0
  170. package/src/app/[variants]/(main)/discover/(list)/(home)/Client.tsx +24 -21
  171. package/src/app/[variants]/(main)/discover/(list)/(home)/loading.tsx +1 -1
  172. package/src/app/[variants]/(main)/discover/(list)/(home)/page.tsx +13 -38
  173. package/src/app/[variants]/(main)/discover/(list)/_layout/Desktop/Nav.tsx +15 -8
  174. package/src/app/[variants]/(main)/discover/(list)/_layout/Mobile/Header.tsx +1 -1
  175. package/src/app/[variants]/(main)/discover/(list)/_layout/Mobile/Nav.tsx +2 -1
  176. package/src/app/[variants]/(main)/discover/(list)/assistant/Client.tsx +44 -0
  177. package/src/app/[variants]/(main)/discover/(list)/assistant/features/Category/index.tsx +84 -0
  178. package/src/app/[variants]/(main)/discover/(list)/assistant/features/Category/useCategory.tsx +112 -0
  179. package/src/app/[variants]/(main)/discover/(list)/assistant/features/List/Item.tsx +189 -0
  180. package/src/app/[variants]/(main)/discover/(list)/assistant/features/List/TokenTag.tsx +70 -0
  181. package/src/app/[variants]/(main)/discover/(list)/assistant/features/List/index.tsx +33 -0
  182. package/src/app/[variants]/(main)/discover/(list)/assistant/page.tsx +46 -0
  183. package/src/app/[variants]/(main)/discover/(list)/features/Pagination.tsx +67 -0
  184. package/src/app/[variants]/(main)/discover/(list)/features/SortButton/index.tsx +184 -0
  185. package/src/app/[variants]/(main)/discover/(list)/mcp/Client.tsx +44 -0
  186. package/src/app/[variants]/(main)/discover/(list)/mcp/features/Category/index.tsx +83 -0
  187. package/src/app/[variants]/(main)/discover/(list)/mcp/features/List/ConnectionTypeTag.tsx +51 -0
  188. package/src/app/[variants]/(main)/discover/(list)/mcp/features/List/Item.tsx +225 -0
  189. package/src/app/[variants]/(main)/discover/(list)/mcp/features/List/MetaInfo.tsx +33 -0
  190. package/src/app/[variants]/(main)/discover/(list)/mcp/features/List/index.tsx +33 -0
  191. package/src/app/[variants]/(main)/discover/(list)/mcp/page.tsx +46 -0
  192. package/src/app/[variants]/(main)/discover/(list)/model/Client.tsx +44 -0
  193. package/src/app/[variants]/(main)/discover/(list)/{models → model}/_layout/Desktop.tsx +1 -7
  194. package/src/app/[variants]/(main)/discover/(list)/model/features/Category/index.tsx +82 -0
  195. package/src/app/[variants]/(main)/discover/(list)/model/features/Category/useCategory.tsx +41 -0
  196. package/src/app/[variants]/(main)/discover/(list)/model/features/List/Item.tsx +190 -0
  197. package/src/app/[variants]/(main)/discover/(list)/model/features/List/ModelTypeIcon.tsx +39 -0
  198. package/src/app/[variants]/(main)/discover/(list)/model/features/List/index.tsx +33 -0
  199. package/src/app/[variants]/(main)/discover/(list)/model/loading.tsx +1 -0
  200. package/src/app/[variants]/(main)/discover/(list)/model/page.tsx +44 -0
  201. package/src/app/[variants]/(main)/discover/(list)/provider/Client.tsx +43 -0
  202. package/src/app/[variants]/(main)/discover/(list)/provider/features/List/Item.tsx +136 -0
  203. package/src/app/[variants]/(main)/discover/(list)/provider/features/List/index.tsx +33 -0
  204. package/src/app/[variants]/(main)/discover/(list)/provider/loading.tsx +1 -0
  205. package/src/app/[variants]/(main)/discover/(list)/provider/page.tsx +44 -0
  206. package/src/app/[variants]/(main)/discover/_layout/Desktop/Header.tsx +1 -1
  207. package/src/app/[variants]/(main)/discover/components/CategoryContainer.tsx +7 -5
  208. package/src/app/[variants]/(main)/discover/components/CategoryMenu.tsx +28 -30
  209. package/src/app/[variants]/(main)/discover/components/ListLoading.tsx +56 -46
  210. package/src/app/[variants]/(main)/discover/components/Statistic.tsx +5 -6
  211. package/src/app/[variants]/(main)/discover/features/Search.tsx +62 -0
  212. package/src/app/[variants]/(main)/discover/features/Title.tsx +83 -0
  213. package/src/app/[variants]/(main)/discover/features/__tests__/calculateScore.test.ts +185 -0
  214. package/src/app/[variants]/(main)/discover/features/useNav.tsx +32 -12
  215. package/src/app/robots.tsx +7 -5
  216. package/src/app/sitemap.tsx +81 -13
  217. package/src/components/CopyableLabel/index.tsx +37 -0
  218. package/src/components/Descriptions/index.tsx +119 -0
  219. package/src/components/InlineTable/index.tsx +69 -0
  220. package/src/{features/PluginSettings/PluginSettingRender.tsx → components/JSONSchemaConfig/ItemRender.tsx} +3 -3
  221. package/src/components/MCPDepsIcon/Java.tsx +23 -0
  222. package/src/components/MCPDepsIcon/PowerShell.tsx +23 -0
  223. package/src/components/MCPDepsIcon/Terminal.tsx +23 -0
  224. package/src/components/MCPDepsIcon/UV.tsx +23 -0
  225. package/src/components/MCPDepsIcon/index.tsx +72 -0
  226. package/src/components/MCPStdioCommandInput/index.tsx +47 -0
  227. package/src/components/OfficialIcon.tsx +23 -0
  228. package/src/components/Plugins/MCPTag.tsx +18 -0
  229. package/src/components/Plugins/PluginTag.tsx +50 -0
  230. package/src/components/PublishedTime.tsx +71 -0
  231. package/src/config/__tests__/app.test.ts +6 -2
  232. package/src/const/discover.ts +8 -34
  233. package/src/database/models/message.ts +1 -0
  234. package/src/database/models/plugin.ts +13 -3
  235. package/src/envs/app.ts +1 -1
  236. package/src/features/AgentSetting/AgentPlugin/index.tsx +2 -2
  237. package/src/features/ChatInput/ActionBar/Tools/ToolItem.tsx +1 -1
  238. package/src/features/ChatInput/ActionBar/Tools/useControls.tsx +5 -5
  239. package/src/features/Conversation/Messages/Assistant/Tool/Inspector/index.tsx +25 -11
  240. package/src/features/MCP/MCPInstallProgress/InstallError/ErrorDetails.tsx +110 -0
  241. package/src/features/MCP/MCPInstallProgress/InstallError/index.tsx +51 -0
  242. package/src/features/MCP/MCPInstallProgress/MCPConfigForm.tsx +151 -0
  243. package/src/features/MCP/MCPInstallProgress/MCPDependenciesGuide.tsx +217 -0
  244. package/src/features/MCP/MCPInstallProgress/index.tsx +118 -0
  245. package/src/features/MCP/Scores.tsx +268 -0
  246. package/src/features/MCP/calculateScore.ts +324 -0
  247. package/src/features/MCP/useScoreList.ts +126 -0
  248. package/src/features/MCP/utils.ts +225 -0
  249. package/src/features/MCPPluginDetail/CollapseDesc.tsx +44 -0
  250. package/src/features/MCPPluginDetail/CollapseLayout.tsx +34 -0
  251. package/src/features/MCPPluginDetail/Deployment/Platform/index.tsx +47 -0
  252. package/src/features/MCPPluginDetail/Deployment/index.tsx +322 -0
  253. package/src/features/MCPPluginDetail/DetailProvider.tsx +19 -0
  254. package/src/features/MCPPluginDetail/Header.tsx +218 -0
  255. package/src/features/MCPPluginDetail/Nav.tsx +196 -0
  256. package/src/features/MCPPluginDetail/Overview/TagList.tsx +47 -0
  257. package/src/features/MCPPluginDetail/Overview/index.tsx +57 -0
  258. package/src/features/MCPPluginDetail/Schema/Block.tsx +50 -0
  259. package/src/features/MCPPluginDetail/Schema/Prompts.tsx +125 -0
  260. package/src/features/MCPPluginDetail/Schema/Resources.tsx +70 -0
  261. package/src/features/MCPPluginDetail/Schema/Tools.tsx +146 -0
  262. package/src/features/MCPPluginDetail/Schema/index.tsx +63 -0
  263. package/src/features/MCPPluginDetail/Schema/style.ts +9 -0
  264. package/src/features/MCPPluginDetail/Schema/types.ts +4 -0
  265. package/src/features/MCPPluginDetail/Score/GithubBadge/index.tsx +82 -0
  266. package/src/features/MCPPluginDetail/Score/ScoreItem.tsx +34 -0
  267. package/src/features/MCPPluginDetail/Score/ScoreList.tsx +24 -0
  268. package/src/features/MCPPluginDetail/Score/TotalScore.tsx +289 -0
  269. package/src/features/MCPPluginDetail/Score/index.tsx +88 -0
  270. package/src/features/PluginAvatar/index.tsx +1 -1
  271. package/src/features/PluginDetailModal/Meta.tsx +3 -4
  272. package/src/features/PluginDevModal/MCPManifestForm/MCPTypeSelect.tsx +3 -4
  273. package/src/features/PluginDevModal/MCPManifestForm/index.tsx +4 -41
  274. package/src/features/PluginDevModal/PluginPreview/EmptyState.tsx +5 -7
  275. package/src/features/PluginDevModal/PluginPreview/index.tsx +6 -6
  276. package/src/features/PluginSettings/index.tsx +2 -2
  277. package/src/features/PluginStore/AddPluginButton.tsx +1 -1
  278. package/src/features/PluginStore/Content.tsx +59 -0
  279. package/src/features/PluginStore/InstalledList/Detail/CustomPluginEmptyState.tsx +81 -0
  280. package/src/features/PluginStore/InstalledList/Detail/index.tsx +21 -0
  281. package/src/features/PluginStore/InstalledList/EditCustomPlugin.tsx +52 -0
  282. package/src/features/PluginStore/{PluginItem → InstalledList/List/Item}/Action.tsx +33 -13
  283. package/src/features/PluginStore/InstalledList/List/Item/index.tsx +62 -0
  284. package/src/features/PluginStore/InstalledList/List/index.tsx +77 -0
  285. package/src/features/PluginStore/InstalledList/index.tsx +85 -0
  286. package/src/features/PluginStore/Loading.tsx +2 -2
  287. package/src/features/PluginStore/McpList/Detail/Loading.tsx +44 -0
  288. package/src/features/PluginStore/McpList/Detail/Settings/index.tsx +381 -0
  289. package/src/features/PluginStore/McpList/Detail/index.tsx +71 -0
  290. package/src/features/PluginStore/McpList/List/Action.tsx +94 -0
  291. package/src/features/PluginStore/McpList/List/Item.tsx +84 -0
  292. package/src/features/PluginStore/McpList/List/index.tsx +97 -0
  293. package/src/features/PluginStore/McpList/index.tsx +54 -0
  294. package/src/features/PluginStore/PluginList/Detail/DetailProvider.tsx +19 -0
  295. package/src/features/PluginStore/PluginList/Detail/EmptyState.tsx +58 -0
  296. package/src/features/PluginStore/PluginList/Detail/Header.tsx +132 -0
  297. package/src/features/PluginStore/PluginList/Detail/InstallDetail/Nav.tsx +75 -0
  298. package/src/features/PluginStore/PluginList/Detail/InstallDetail/Settings.tsx +19 -0
  299. package/src/features/PluginStore/PluginList/Detail/InstallDetail/Tools.tsx +109 -0
  300. package/src/features/PluginStore/PluginList/Detail/InstallDetail/index.tsx +24 -0
  301. package/src/features/PluginStore/PluginList/Detail/Loading.tsx +44 -0
  302. package/src/features/PluginStore/PluginList/Detail/TagList.tsx +37 -0
  303. package/src/features/PluginStore/PluginList/Detail/index.tsx +39 -0
  304. package/src/features/PluginStore/PluginList/Detail/useCategory.tsx +76 -0
  305. package/src/features/PluginStore/PluginList/List/Action.tsx +72 -0
  306. package/src/features/PluginStore/PluginList/List/Item.tsx +94 -0
  307. package/src/features/PluginStore/PluginList/List/index.tsx +91 -0
  308. package/src/features/PluginStore/PluginList/index.tsx +47 -0
  309. package/src/features/PluginStore/Search/index.tsx +29 -0
  310. package/src/features/PluginStore/VirtuosoLoading.tsx +16 -0
  311. package/src/features/PluginStore/index.tsx +7 -31
  312. package/src/features/PluginTag/index.tsx +6 -4
  313. package/src/hooks/useInterceptingRoutes.test.ts +6 -0
  314. package/src/hooks/useMCPCategory.tsx +133 -0
  315. package/src/hooks/useQuery.ts +8 -0
  316. package/src/hooks/useQueryRoute.test.ts +7 -0
  317. package/src/hooks/useQueryRoute.ts +5 -3
  318. package/src/libs/mcp/client.ts +265 -13
  319. package/src/libs/mcp/types.ts +99 -0
  320. package/src/libs/trpc/client/desktop.ts +2 -3
  321. package/src/libs/trpc/lambda/context.ts +36 -5
  322. package/src/libs/trpc/lambda/index.ts +1 -1
  323. package/src/libs/trpc/lambda/init.ts +8 -1
  324. package/src/locales/default/discover.ts +457 -12
  325. package/src/locales/default/metadata.ts +9 -4
  326. package/src/locales/default/plugin.ts +89 -1
  327. package/src/locales/default/setting.ts +1 -0
  328. package/src/locales/resources.ts +1 -1
  329. package/src/middleware.ts +13 -3
  330. package/src/server/ld.ts +4 -3
  331. package/src/server/modules/AssistantStore/index.test.ts +10 -8
  332. package/src/server/modules/AssistantStore/index.ts +37 -17
  333. package/src/server/modules/PluginStore/index.test.ts +1 -1
  334. package/src/server/modules/PluginStore/index.ts +24 -1
  335. package/src/server/routers/desktop/mcp.ts +36 -2
  336. package/src/server/routers/edge/index.ts +0 -6
  337. package/src/server/routers/{edge → lambda}/config/index.ts +1 -1
  338. package/src/server/routers/lambda/index.ts +4 -0
  339. package/src/server/routers/lambda/market/index.ts +621 -0
  340. package/src/server/routers/lambda/plugin.ts +2 -0
  341. package/src/server/routers/tools/mcp.ts +22 -0
  342. package/src/server/services/discover/index.test.ts +573 -250
  343. package/src/server/services/discover/index.ts +1096 -241
  344. package/src/server/services/mcp/deps/MCPSystemDepsCheckService.ts +238 -0
  345. package/src/server/services/mcp/deps/checkers/ManualInstallationChecker.ts +20 -0
  346. package/src/server/services/mcp/deps/checkers/NpmInstallationChecker.ts +51 -0
  347. package/src/server/services/mcp/deps/checkers/PythonInstallationChecker.ts +69 -0
  348. package/src/server/services/mcp/deps/index.ts +14 -0
  349. package/src/server/services/mcp/deps/types.ts +49 -0
  350. package/src/server/services/mcp/index.ts +251 -33
  351. package/src/server/sitemap.test.ts +203 -46
  352. package/src/server/sitemap.ts +159 -52
  353. package/src/services/__tests__/global.test.ts +4 -7
  354. package/src/services/__tests__/tool.test.ts +1 -29
  355. package/src/services/discover.ts +365 -0
  356. package/src/services/global.ts +3 -3
  357. package/src/services/mcp.ts +131 -10
  358. package/src/services/plugin/_deprecated.ts +1 -1
  359. package/src/services/plugin/type.ts +3 -1
  360. package/src/services/tool.ts +9 -6
  361. package/src/store/chat/slices/plugin/action.test.ts +2 -3
  362. package/src/store/chat/slices/plugin/action.ts +22 -4
  363. package/src/store/discover/index.ts +1 -0
  364. package/src/store/discover/slices/assistant/action.ts +73 -0
  365. package/src/store/discover/slices/assistant/index.ts +1 -0
  366. package/src/store/discover/slices/mcp/action.ts +70 -0
  367. package/src/store/discover/slices/mcp/index.ts +1 -0
  368. package/src/store/discover/slices/model/action.ts +70 -0
  369. package/src/store/discover/slices/model/index.ts +1 -0
  370. package/src/store/discover/slices/plugin/action.ts +76 -0
  371. package/src/store/discover/slices/plugin/index.ts +1 -0
  372. package/src/store/discover/slices/provider/action.ts +61 -0
  373. package/src/store/discover/slices/provider/index.ts +1 -0
  374. package/src/store/discover/store.ts +39 -0
  375. package/src/store/tool/initialState.ts +8 -2
  376. package/src/store/tool/selectors/index.ts +2 -1
  377. package/src/store/tool/selectors/tool.test.ts +3 -1
  378. package/src/store/tool/selectors/tool.ts +14 -2
  379. package/src/store/tool/slices/mcpStore/action.ts +496 -0
  380. package/src/store/tool/slices/mcpStore/initialState.ts +40 -0
  381. package/src/store/tool/slices/mcpStore/selectors.ts +62 -0
  382. package/src/store/tool/slices/{store → oldStore}/action.test.ts +24 -19
  383. package/src/store/tool/slices/oldStore/action.ts +269 -0
  384. package/src/store/tool/slices/oldStore/index.ts +3 -0
  385. package/src/store/tool/slices/oldStore/initialState.ts +54 -0
  386. package/src/store/tool/slices/{store → oldStore}/selectors.test.ts +6 -3
  387. package/src/store/tool/slices/{store → oldStore}/selectors.ts +18 -5
  388. package/src/store/tool/slices/plugin/action.test.ts +2 -1
  389. package/src/store/tool/slices/plugin/action.ts +22 -4
  390. package/src/store/tool/slices/plugin/selectors.test.ts +12 -4
  391. package/src/store/tool/slices/plugin/selectors.ts +20 -9
  392. package/src/store/tool/store.ts +5 -2
  393. package/src/types/discover/assistants.ts +72 -0
  394. package/src/types/discover/index.ts +41 -0
  395. package/src/types/discover/mcp.ts +59 -0
  396. package/src/types/discover/models.ts +51 -0
  397. package/src/types/discover/plugins.ts +52 -0
  398. package/src/types/discover/providers.ts +47 -0
  399. package/src/types/message/tools.ts +3 -0
  400. package/src/types/plugins/index.ts +53 -0
  401. package/src/types/plugins/mcp.ts +188 -0
  402. package/src/types/plugins/mcpDeps.ts +30 -0
  403. package/src/types/tool/index.ts +10 -0
  404. package/src/types/tool/plugin.ts +3 -2
  405. package/src/types/tool/tool.ts +4 -1
  406. package/src/utils/client/cookie.ts +5 -2
  407. package/src/utils/locale.ts +2 -17
  408. package/src/utils/object.ts +10 -0
  409. package/src/utils/server/pageProps.ts +9 -0
  410. package/src/utils/toolCall.ts +5 -1
  411. package/src/utils/toolManifest.ts +1 -2
  412. package/vercel.json +1 -1
  413. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/Actions.tsx +0 -35
  414. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/ConversationExample/TopicList.tsx +0 -75
  415. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/ConversationExample/index.tsx +0 -105
  416. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/Header.tsx +0 -115
  417. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/InfoSidebar/SuggestionItem.tsx +0 -62
  418. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/InfoSidebar/ToolItem.tsx +0 -19
  419. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/InfoSidebar/index.tsx +0 -60
  420. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/SystemRole.tsx +0 -35
  421. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/features/Temp.tsx +0 -44
  422. package/src/app/[variants]/(main)/discover/(detail)/assistant/[slug]/page.tsx +0 -124
  423. package/src/app/[variants]/(main)/discover/(detail)/loading.tsx +0 -38
  424. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/Actions.tsx +0 -40
  425. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/ChatWithModel.tsx +0 -93
  426. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/InfoSidebar/SuggestionItem.tsx +0 -74
  427. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/InfoSidebar/index.tsx +0 -45
  428. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/ProviderList/ProviderItem.tsx +0 -139
  429. package/src/app/[variants]/(main)/discover/(detail)/model/[...slugs]/features/ProviderList/index.tsx +0 -45
  430. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/Actions.tsx +0 -35
  431. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/Header.tsx +0 -119
  432. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/InfoSidebar/SuggestionItem.tsx +0 -64
  433. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/InfoSidebar/index.tsx +0 -45
  434. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/InstallPlugin.tsx +0 -83
  435. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/ParameterList.tsx +0 -95
  436. package/src/app/[variants]/(main)/discover/(detail)/plugin/[slug]/features/Schema.tsx +0 -23
  437. package/src/app/[variants]/(main)/discover/(detail)/provider/[slug]/features/Header.tsx +0 -73
  438. package/src/app/[variants]/(main)/discover/(detail)/provider/[slug]/features/InfoSidebar/SuggestionItem.tsx +0 -77
  439. package/src/app/[variants]/(main)/discover/(detail)/provider/[slug]/features/InfoSidebar/index.tsx +0 -45
  440. package/src/app/[variants]/(main)/discover/(detail)/provider/[slug]/features/ModelList/ModelItem.tsx +0 -152
  441. package/src/app/[variants]/(main)/discover/(detail)/provider/[slug]/features/ModelList/index.tsx +0 -60
  442. package/src/app/[variants]/(main)/discover/(detail)/provider/[slug]/page.tsx +0 -126
  443. package/src/app/[variants]/(main)/discover/(list)/(home)/features/AssistantList.tsx +0 -33
  444. package/src/app/[variants]/(main)/discover/(list)/(home)/features/ModelList.tsx +0 -19
  445. package/src/app/[variants]/(main)/discover/(list)/(home)/features/PluginList.tsx +0 -25
  446. package/src/app/[variants]/(main)/discover/(list)/assistants/[slug]/page.tsx +0 -75
  447. package/src/app/[variants]/(main)/discover/(list)/assistants/features/Card.tsx +0 -195
  448. package/src/app/[variants]/(main)/discover/(list)/assistants/features/Category.tsx +0 -48
  449. package/src/app/[variants]/(main)/discover/(list)/assistants/features/List.tsx +0 -98
  450. package/src/app/[variants]/(main)/discover/(list)/assistants/features/useCategory.tsx +0 -116
  451. package/src/app/[variants]/(main)/discover/(list)/assistants/page.tsx +0 -64
  452. package/src/app/[variants]/(main)/discover/(list)/loading.tsx +0 -39
  453. package/src/app/[variants]/(main)/discover/(list)/models/[slug]/page.tsx +0 -78
  454. package/src/app/[variants]/(main)/discover/(list)/models/features/Card.tsx +0 -118
  455. package/src/app/[variants]/(main)/discover/(list)/models/features/Category.tsx +0 -67
  456. package/src/app/[variants]/(main)/discover/(list)/models/features/List.tsx +0 -71
  457. package/src/app/[variants]/(main)/discover/(list)/models/loading.tsx +0 -1
  458. package/src/app/[variants]/(main)/discover/(list)/models/page.tsx +0 -73
  459. package/src/app/[variants]/(main)/discover/(list)/plugins/[slug]/page.tsx +0 -75
  460. package/src/app/[variants]/(main)/discover/(list)/plugins/features/Card.tsx +0 -161
  461. package/src/app/[variants]/(main)/discover/(list)/plugins/features/Category.tsx +0 -45
  462. package/src/app/[variants]/(main)/discover/(list)/plugins/features/List.tsx +0 -97
  463. package/src/app/[variants]/(main)/discover/(list)/plugins/features/useCategory.tsx +0 -80
  464. package/src/app/[variants]/(main)/discover/(list)/plugins/page.tsx +0 -64
  465. package/src/app/[variants]/(main)/discover/(list)/providers/features/Card.tsx +0 -119
  466. package/src/app/[variants]/(main)/discover/(list)/providers/features/List.tsx +0 -67
  467. package/src/app/[variants]/(main)/discover/(list)/providers/loading.tsx +0 -1
  468. package/src/app/[variants]/(main)/discover/(list)/providers/page.tsx +0 -64
  469. package/src/app/[variants]/(main)/discover/features/StoreSearchBar.tsx +0 -87
  470. package/src/app/[variants]/(main)/discover/loading.tsx +0 -3
  471. package/src/app/[variants]/(main)/discover/search/_layout/Desktop.tsx +0 -42
  472. package/src/app/[variants]/(main)/discover/search/_layout/Mobile/Header.tsx +0 -31
  473. package/src/app/[variants]/(main)/discover/search/_layout/Mobile/Nav.tsx +0 -56
  474. package/src/app/[variants]/(main)/discover/search/_layout/Mobile/index.tsx +0 -32
  475. package/src/app/[variants]/(main)/discover/search/features/AssistantsResult.tsx +0 -27
  476. package/src/app/[variants]/(main)/discover/search/features/Category.tsx +0 -41
  477. package/src/app/[variants]/(main)/discover/search/features/ModelsResult.tsx +0 -27
  478. package/src/app/[variants]/(main)/discover/search/features/PluginsResult.tsx +0 -27
  479. package/src/app/[variants]/(main)/discover/search/features/ProvidersResult.tsx +0 -26
  480. package/src/app/[variants]/(main)/discover/search/layout.tsx +0 -12
  481. package/src/app/[variants]/(main)/discover/search/loading.tsx +0 -1
  482. package/src/app/[variants]/(main)/discover/search/page.tsx +0 -82
  483. package/src/features/PluginStore/InstalledPluginList.tsx +0 -59
  484. package/src/features/PluginStore/OnlineList.tsx +0 -87
  485. package/src/features/PluginStore/PluginItem/EditCustomPlugin.tsx +0 -55
  486. package/src/features/PluginStore/PluginItem/PluginTag.tsx +0 -29
  487. package/src/features/PluginStore/PluginItem/index.tsx +0 -83
  488. package/src/server/routers/edge/market/index.ts +0 -108
  489. package/src/services/__tests__/assistant.test.ts +0 -87
  490. package/src/services/assistant.ts +0 -25
  491. package/src/store/tool/slices/store/action.ts +0 -113
  492. package/src/store/tool/slices/store/initialState.ts +0 -17
  493. package/src/types/discover.ts +0 -179
  494. package/src/types/requestCache.ts +0 -3
  495. /package/src/app/[variants]/(main)/discover/(list)/{assistants → assistant}/_layout/Desktop.tsx +0 -0
  496. /package/src/app/[variants]/(main)/discover/(list)/{assistants → assistant}/_layout/Mobile.tsx +0 -0
  497. /package/src/app/[variants]/(main)/discover/(list)/{assistants → assistant}/layout.tsx +0 -0
  498. /package/src/app/[variants]/(main)/discover/(list)/{assistants → assistant}/loading.tsx +0 -0
  499. /package/src/app/[variants]/(main)/discover/(list)/{plugins → mcp}/_layout/Desktop.tsx +0 -0
  500. /package/src/app/[variants]/(main)/discover/(list)/{plugins → mcp}/_layout/Mobile.tsx +0 -0
  501. /package/src/app/[variants]/(main)/discover/(list)/{plugins → mcp}/layout.tsx +0 -0
  502. /package/src/app/[variants]/(main)/discover/(list)/{plugins → mcp}/loading.tsx +0 -0
  503. /package/src/app/[variants]/(main)/discover/(list)/{models → model}/_layout/Mobile.tsx +0 -0
  504. /package/src/app/[variants]/(main)/discover/(list)/{models → model}/features/const.ts +0 -0
  505. /package/src/app/[variants]/(main)/discover/(list)/{models → model}/layout.tsx +0 -0
  506. /package/src/{features/PluginStore/PluginItem → components/Plugins}/PluginAvatar.tsx +0 -0
  507. /package/src/server/routers/{edge → lambda}/config/__snapshots__/index.test.ts.snap +0 -0
  508. /package/src/server/routers/{edge → lambda}/config/index.test.ts +0 -0
  509. /package/src/store/tool/slices/{store → mcpStore}/index.ts +0 -0
@@ -1,305 +1,628 @@
1
1
  // @vitest-environment node
2
2
  import { beforeEach, describe, expect, it, vi } from 'vitest';
3
3
 
4
- import { AssistantCategory, PluginCategory } from '@/types/discover';
4
+ import { AssistantStore } from '@/server/modules/AssistantStore';
5
+ import { PluginStore } from '@/server/modules/PluginStore';
6
+ import { AssistantSorts, ModelSorts, PluginSorts, ProviderSorts } from '@/types/discover';
5
7
 
6
8
  import { DiscoverService } from './index';
7
9
 
8
- // 模拟 fetch 函数
9
- global.fetch = vi.fn();
10
+ // Mock external dependencies
11
+ vi.mock('@/server/modules/AssistantStore');
12
+ vi.mock('@/server/modules/PluginStore');
13
+ vi.mock('@lobehub/market-sdk');
14
+ vi.mock('@/utils/toolManifest');
15
+ vi.mock('@/locales/resources', () => ({
16
+ normalizeLocale: vi.fn((locale) => {
17
+ if (locale === 'en-US') return 'en';
18
+ return locale || 'en';
19
+ }),
20
+ }));
21
+
22
+ // Set environment variable for tests
23
+ process.env.MARKET_BASE_URL = 'http://localhost:8787/api';
24
+
25
+ // Mock constants with inline data
26
+ vi.mock('@/config/aiModels', () => ({
27
+ LOBE_DEFAULT_MODEL_LIST: [
28
+ {
29
+ id: 'gpt-4',
30
+ displayName: 'GPT-4',
31
+ description: 'OpenAI GPT-4 model',
32
+ providerId: 'openai',
33
+ contextWindowTokens: 8192,
34
+ abilities: {
35
+ vision: true,
36
+ functionCall: true,
37
+ files: true,
38
+ },
39
+ pricing: {
40
+ input: 0.03,
41
+ output: 0.06,
42
+ },
43
+ releasedAt: '2023-03-01T00:00:00Z',
44
+ },
45
+ {
46
+ id: 'claude-3-opus',
47
+ displayName: 'Claude 3 Opus',
48
+ description: 'Anthropic Claude 3 Opus model',
49
+ providerId: 'anthropic',
50
+ contextWindowTokens: 200000,
51
+ abilities: {
52
+ vision: true,
53
+ reasoning: true,
54
+ },
55
+ pricing: {
56
+ input: 0.015,
57
+ output: 0.075,
58
+ },
59
+ releasedAt: '2024-02-01T00:00:00Z',
60
+ },
61
+ ],
62
+ }));
63
+
64
+ vi.mock('@/config/modelProviders', () => ({
65
+ DEFAULT_MODEL_PROVIDER_LIST: [
66
+ {
67
+ id: 'openai',
68
+ name: 'OpenAI',
69
+ description: 'OpenAI provider',
70
+ },
71
+ {
72
+ id: 'anthropic',
73
+ name: 'Anthropic',
74
+ description: 'Anthropic provider',
75
+ },
76
+ ],
77
+ }));
78
+
79
+ vi.mock('@/const/discover', () => ({
80
+ DEFAULT_DISCOVER_ASSISTANT_ITEM: {},
81
+ DEFAULT_DISCOVER_PLUGIN_ITEM: {},
82
+ DEFAULT_DISCOVER_PROVIDER_ITEM: {},
83
+ }));
84
+
85
+ // Mock data - moved after mocks to avoid hoisting issues
86
+ const mockAssistantList = [
87
+ {
88
+ identifier: 'assistant-1',
89
+ title: 'Test Assistant 1',
90
+ description: 'A test assistant',
91
+ author: 'Test Author',
92
+ category: 'productivity',
93
+ createdAt: '2024-01-01T00:00:00Z',
94
+ knowledgeCount: 5,
95
+ pluginCount: 2,
96
+ tokenUsage: 1000,
97
+ tags: ['test', 'assistant'],
98
+ },
99
+ {
100
+ identifier: 'assistant-2',
101
+ title: 'Test Assistant 2',
102
+ description: 'Another test assistant',
103
+ author: 'Test Author 2',
104
+ category: 'productivity', // Changed to same category for related items test
105
+ createdAt: '2024-01-02T00:00:00Z',
106
+ knowledgeCount: 3,
107
+ pluginCount: 1,
108
+ tokenUsage: 500,
109
+ tags: ['test', 'creative'],
110
+ },
111
+ {
112
+ identifier: 'assistant-3',
113
+ title: 'Test Assistant 3',
114
+ description: 'A creative assistant',
115
+ author: 'Test Author 3',
116
+ category: 'creativity', // Keep this for category filtering tests
117
+ createdAt: '2024-01-03T00:00:00Z',
118
+ knowledgeCount: 2,
119
+ pluginCount: 0,
120
+ tokenUsage: 300,
121
+ tags: ['test', 'creative'],
122
+ },
123
+ ];
124
+
125
+ const mockPluginList = [
126
+ {
127
+ identifier: 'plugin-1',
128
+ title: 'Test Plugin 1',
129
+ description: 'A test plugin',
130
+ author: 'Plugin Author',
131
+ category: 'tools',
132
+ createdAt: '2024-01-01T00:00:00Z',
133
+ tags: ['test', 'plugin'],
134
+ manifest: 'https://example.com/plugin1/manifest.json',
135
+ },
136
+ {
137
+ identifier: 'plugin-2',
138
+ title: 'Test Plugin 2',
139
+ description: 'Another test plugin',
140
+ author: 'Plugin Author 2',
141
+ category: 'utilities',
142
+ createdAt: '2024-01-02T00:00:00Z',
143
+ tags: ['test', 'utility'],
144
+ manifest: 'https://example.com/plugin2/manifest.json',
145
+ },
146
+ ];
10
147
 
11
148
  describe('DiscoverService', () => {
12
149
  let service: DiscoverService;
150
+ let mockAssistantStore: any;
151
+ let mockPluginStore: any;
152
+ let mockMarket: any;
13
153
 
14
154
  beforeEach(() => {
155
+ vi.clearAllMocks();
156
+
157
+ // Setup AssistantStore mock
158
+ mockAssistantStore = {
159
+ getAgentIndex: vi
160
+ .fn()
161
+ .mockResolvedValue(mockAssistantList.map((item) => ({ ...item, meta: {} }))),
162
+ getAgent: vi.fn().mockImplementation((identifier) => {
163
+ const agent = mockAssistantList.find((a) => a.identifier === identifier);
164
+ return Promise.resolve(agent ? { ...agent, meta: {} } : null);
165
+ }),
166
+ };
167
+
168
+ // Setup PluginStore mock
169
+ mockPluginStore = {
170
+ getPluginList: vi
171
+ .fn()
172
+ .mockResolvedValue(mockPluginList.map((item) => ({ ...item, meta: {} }))),
173
+ };
174
+
175
+ // Setup MarketSDK mock
176
+ mockMarket = {
177
+ plugins: {
178
+ getCategories: vi.fn().mockResolvedValue([
179
+ { category: 'tools', count: 5 },
180
+ { category: 'utilities', count: 3 },
181
+ ]),
182
+ getPluginDetail: vi.fn().mockImplementation((params) => {
183
+ const plugin = mockPluginList.find((p) => p.identifier === params.identifier);
184
+ return Promise.resolve(plugin || null);
185
+ }),
186
+ getPluginList: vi.fn().mockResolvedValue({
187
+ items: mockPluginList,
188
+ totalCount: mockPluginList.length,
189
+ currentPage: 1,
190
+ pageSize: 20,
191
+ totalPages: 1,
192
+ }),
193
+ getPublishedIdentifiers: vi
194
+ .fn()
195
+ .mockResolvedValue(
196
+ mockPluginList.map((p) => ({ identifier: p.identifier, lastModified: p.createdAt })),
197
+ ),
198
+ getPluginManifest: vi.fn().mockResolvedValue({}),
199
+ },
200
+ };
201
+
202
+ (AssistantStore as any).mockImplementation(() => mockAssistantStore);
203
+ (PluginStore as any).mockImplementation(() => mockPluginStore);
204
+
15
205
  service = new DiscoverService();
16
- vi.resetAllMocks();
206
+ service.market = mockMarket;
17
207
  });
18
208
 
19
- describe('Assistants', () => {
20
- it('should search assistants', async () => {
21
- const mockAssistants = [
22
- {
23
- author: 'John',
24
- meta: { title: 'Test Assistant', description: 'A test assistant', tags: ['test'] },
25
- },
26
- {
27
- author: 'Jane',
28
- meta: {
29
- title: 'Another Assistant',
30
- description: 'Another test assistant',
31
- tags: ['demo'],
32
- },
33
- },
34
- ];
35
-
36
- vi.spyOn(service, 'getAssistantList').mockResolvedValue(mockAssistants as any);
37
-
38
- const result = await service.searchAssistant('en-US', 'A test assistant');
39
- expect(result).toHaveLength(1);
40
- expect(result[0].author).toBe('John');
41
- });
42
-
43
- it('should get assistant category', async () => {
44
- const mockAssistants = [
45
- { meta: { category: AssistantCategory.General } },
46
- { meta: { category: AssistantCategory.Academic } },
47
- ];
48
-
49
- vi.spyOn(service, 'getAssistantList').mockResolvedValue(mockAssistants as any);
50
-
51
- const result = await service.getAssistantCategory('en-US', AssistantCategory.General);
52
- expect(result).toHaveLength(1);
53
- expect(result[0].meta.category).toBe(AssistantCategory.General);
54
- });
55
-
56
- it('should get assistant list', async () => {
57
- const mockResponse = { agents: [{ id: 'test-assistant' }] };
58
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({
59
- ok: true,
60
- json: vi.fn().mockResolvedValue(mockResponse),
61
- } as any);
62
-
63
- const result = await service.getAssistantList('en-US');
64
- expect(result).toEqual(mockResponse.agents);
65
- });
66
-
67
- it('should get assistant by id', async () => {
68
- const mockAssistant = {
69
- identifier: 'test-assistant',
70
- meta: { category: AssistantCategory.General },
71
- };
72
-
73
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({
74
- ok: true,
75
- json: vi.fn().mockResolvedValue(mockAssistant),
76
- } as any);
77
-
78
- vi.spyOn(service, 'getAssistantCategory').mockResolvedValue([]);
79
-
80
- const result = await service.getAssistantById('en-US', 'test-assistant');
81
-
82
- expect(result).toBeDefined();
83
- expect(result?.identifier).toBe('test-assistant');
209
+ describe('Assistant Market', () => {
210
+ describe('getAssistantList', () => {
211
+ it('should return formatted assistant list with default parameters', async () => {
212
+ const result = await service.getAssistantList();
213
+
214
+ expect(result).toEqual({
215
+ currentPage: 1,
216
+ pageSize: 20,
217
+ totalCount: 3,
218
+ totalPages: 1,
219
+ items: expect.arrayContaining([
220
+ expect.objectContaining({
221
+ identifier: 'assistant-1',
222
+ title: 'Test Assistant 1',
223
+ }),
224
+ expect.objectContaining({
225
+ identifier: 'assistant-2',
226
+ title: 'Test Assistant 2',
227
+ }),
228
+ expect.objectContaining({
229
+ identifier: 'assistant-3',
230
+ title: 'Test Assistant 3',
231
+ }),
232
+ ]),
233
+ });
234
+ });
235
+
236
+ it('should filter by category', async () => {
237
+ const result = await service.getAssistantList({ category: 'productivity' });
238
+
239
+ expect(result.items).toHaveLength(2);
240
+ expect(result.items.map((item) => item.identifier)).toContain('assistant-1');
241
+ expect(result.items.map((item) => item.identifier)).toContain('assistant-2');
242
+ });
243
+
244
+ it('should filter by search query', async () => {
245
+ const result = await service.getAssistantList({ q: 'creative' });
246
+
247
+ expect(result.items).toHaveLength(2);
248
+ expect(result.items.map((item) => item.identifier)).toContain('assistant-2');
249
+ expect(result.items.map((item) => item.identifier)).toContain('assistant-3');
250
+ });
251
+
252
+ it('should sort by creation date descending', async () => {
253
+ const result = await service.getAssistantList({
254
+ sort: AssistantSorts.CreatedAt,
255
+ order: 'desc',
256
+ });
257
+
258
+ expect(result.items[0].identifier).toBe('assistant-3');
259
+ expect(result.items[1].identifier).toBe('assistant-2');
260
+ expect(result.items[2].identifier).toBe('assistant-1');
261
+ });
262
+
263
+ it('should sort by title ascending', async () => {
264
+ const result = await service.getAssistantList({
265
+ sort: AssistantSorts.Title,
266
+ order: 'asc',
267
+ });
268
+
269
+ // Note: The service has reversed logic for title sorting
270
+ expect(result.items[0].title).toBe('Test Assistant 3');
271
+ expect(result.items[1].title).toBe('Test Assistant 2');
272
+ });
273
+
274
+ it('should paginate results', async () => {
275
+ const result = await service.getAssistantList({ page: 1, pageSize: 1 });
276
+
277
+ expect(result.items).toHaveLength(1);
278
+ expect(result.currentPage).toBe(1);
279
+ expect(result.pageSize).toBe(1);
280
+ expect(result.totalPages).toBe(3);
281
+ });
84
282
  });
85
283
 
86
- it('should get assistants by ids', async () => {
87
- const mockAssistants = [{ identifier: 'assistant1' }, { identifier: 'assistant2' }];
88
-
89
- vi.spyOn(service, 'getAssistantById').mockImplementation(
90
- async (_, id) => mockAssistants.find((a) => a.identifier === id) as any,
91
- );
92
-
93
- const result = await service.getAssistantByIds('en-US', [
94
- 'assistant1',
95
- 'assistant2',
96
- 'nonexistent',
97
- ]);
98
- expect(result).toHaveLength(2);
99
- expect(result[0].identifier).toBe('assistant1');
100
- expect(result[1].identifier).toBe('assistant2');
284
+ describe('getAssistantDetail', () => {
285
+ it('should return assistant detail with related items', async () => {
286
+ const result = await service.getAssistantDetail({
287
+ identifier: 'assistant-1',
288
+ });
289
+
290
+ expect(result).toEqual(
291
+ expect.objectContaining({
292
+ identifier: 'assistant-1',
293
+ title: 'Test Assistant 1',
294
+ related: expect.any(Array),
295
+ }),
296
+ );
297
+ expect(result?.related).toHaveLength(1);
298
+ expect(result?.related[0].identifier).toBe('assistant-2');
299
+ });
300
+
301
+ it('should return undefined for non-existent assistant', async () => {
302
+ mockAssistantStore.getAgent.mockResolvedValue(null);
303
+
304
+ const result = await service.getAssistantDetail({
305
+ identifier: 'non-existent',
306
+ });
307
+
308
+ expect(result).toBeUndefined();
309
+ });
101
310
  });
102
- });
103
311
 
104
- describe('Plugins', () => {
105
- it('should search plugins', async () => {
106
- const mockPlugins = [
107
- {
108
- author: 'John',
109
- meta: { title: 'Test Plugin', description: 'A test plugin', tags: ['test'] },
110
- },
111
- {
112
- author: 'Jane',
113
- meta: { title: 'Another Plugin', description: 'Another test plugin', tags: ['demo'] },
114
- },
115
- ];
116
-
117
- vi.spyOn(service, 'getPluginList').mockResolvedValue(mockPlugins as any);
118
-
119
- const result = await service.searchPlugin('en-US', 'A test plugin');
120
- expect(result).toHaveLength(1);
121
- expect(result[0].author).toBe('John');
122
- });
312
+ describe('getAssistantCategories', () => {
313
+ it('should return category counts', async () => {
314
+ const result = await service.getAssistantCategories();
123
315
 
124
- it('should get plugin category', async () => {
125
- const mockPlugins = [
126
- { meta: { category: PluginCategory.Tools } },
127
- { meta: { category: PluginCategory.Social } },
128
- ];
316
+ expect(result).toEqual([
317
+ { category: 'productivity', count: 2 },
318
+ { category: 'creativity', count: 1 },
319
+ ]);
320
+ });
129
321
 
130
- vi.spyOn(service, 'getPluginList').mockResolvedValue(mockPlugins as any);
322
+ it('should filter categories by search query', async () => {
323
+ const result = await service.getAssistantCategories({ q: 'creative' });
131
324
 
132
- const result = await service.getPluginCategory('en-US', PluginCategory.Tools);
133
- expect(result).toHaveLength(1);
134
- expect(result[0].meta.category).toBe(PluginCategory.Tools);
325
+ expect(result).toEqual([
326
+ {
327
+ category: 'productivity',
328
+ count: 1,
329
+ },
330
+ {
331
+ category: 'creativity',
332
+ count: 1,
333
+ },
334
+ ]);
335
+ });
135
336
  });
136
337
 
137
- it('should get plugin list', async () => {
138
- const mockResponse = { plugins: [{ id: 'test-plugin' }] };
139
- vi.spyOn(global, 'fetch').mockResolvedValueOnce({
140
- ok: true,
141
- json: vi.fn().mockResolvedValue(mockResponse),
142
- } as any);
338
+ describe('getAssistantIdentifiers', () => {
339
+ it('should return list of identifiers with lastModified dates', async () => {
340
+ const result = await service.getAssistantIdentifiers();
143
341
 
144
- const result = await service.getPluginList('en-US');
145
- expect(result).toEqual(mockResponse.plugins);
342
+ expect(result).toEqual([
343
+ { identifier: 'assistant-1', lastModified: '2024-01-01T00:00:00Z' },
344
+ { identifier: 'assistant-2', lastModified: '2024-01-02T00:00:00Z' },
345
+ { identifier: 'assistant-3', lastModified: '2024-01-03T00:00:00Z' },
346
+ ]);
347
+ });
146
348
  });
349
+ });
147
350
 
148
- it('should get plugin by id', async () => {
149
- const mockPlugin = {
150
- identifier: 'test-plugin',
151
- meta: { category: PluginCategory.Tools },
152
- };
153
-
154
- vi.spyOn(service, 'getPluginList').mockResolvedValue([mockPlugin] as any);
155
- vi.spyOn(service, 'getPluginCategory').mockResolvedValue([]);
156
-
157
- const result = await service.getPluginById('en-US', 'test-plugin');
158
-
159
- expect(result).toBeDefined();
160
- expect(result?.identifier).toBe('test-plugin');
351
+ describe('Plugin Market', () => {
352
+ describe('getPluginList', () => {
353
+ it('should return formatted plugin list with default parameters', async () => {
354
+ const result = await service.getPluginList();
355
+
356
+ expect(result).toEqual({
357
+ currentPage: 1,
358
+ pageSize: 20,
359
+ totalCount: 2,
360
+ totalPages: 1,
361
+ items: expect.arrayContaining([
362
+ expect.objectContaining({
363
+ identifier: 'plugin-1',
364
+ title: 'Test Plugin 1',
365
+ }),
366
+ expect.objectContaining({
367
+ identifier: 'plugin-2',
368
+ title: 'Test Plugin 2',
369
+ }),
370
+ ]),
371
+ });
372
+ });
373
+
374
+ it('should filter by category', async () => {
375
+ const result = await service.getPluginList({ category: 'tools' });
376
+
377
+ expect(result.items).toHaveLength(1);
378
+ expect(result.items[0].identifier).toBe('plugin-1');
379
+ });
380
+
381
+ it('should sort by identifier', async () => {
382
+ const result = await service.getPluginList({
383
+ sort: PluginSorts.Identifier,
384
+ order: 'asc',
385
+ });
386
+
387
+ // Note: The service has reversed logic for identifier sorting
388
+ expect(result.items[0].identifier).toBe('plugin-2');
389
+ expect(result.items[1].identifier).toBe('plugin-1');
390
+ });
161
391
  });
162
392
 
163
- it('should get plugins by ids', async () => {
164
- const mockPlugins = [{ identifier: 'plugin1' }, { identifier: 'plugin2' }];
165
-
166
- vi.spyOn(service, 'getPluginById').mockImplementation(
167
- async (_, id) => mockPlugins.find((p) => p.identifier === id) as any,
168
- );
169
-
170
- const result = await service.getPluginByIds('en-US', ['plugin1', 'plugin2', 'nonexistent']);
171
- expect(result).toHaveLength(2);
172
- expect(result[0].identifier).toBe('plugin1');
173
- expect(result[1].identifier).toBe('plugin2');
393
+ describe('getPluginDetail', () => {
394
+ it('should return plugin detail with related items', async () => {
395
+ const result = await service.getPluginDetail({
396
+ identifier: 'plugin-1',
397
+ });
398
+
399
+ expect(result).toEqual(
400
+ expect.objectContaining({
401
+ identifier: 'plugin-1',
402
+ title: 'Test Plugin 1',
403
+ related: expect.any(Array),
404
+ }),
405
+ );
406
+ });
407
+
408
+ it('should return undefined for non-existent plugin', async () => {
409
+ const result = await service.getPluginDetail({
410
+ identifier: 'non-existent',
411
+ });
412
+
413
+ expect(result).toBeUndefined();
414
+ });
174
415
  });
175
416
  });
176
417
 
177
- describe('Providers', () => {
178
- it('should get provider list', async () => {
179
- const result = await service.getProviderList('en-US');
180
- expect(result).toBeDefined();
181
- expect(Array.isArray(result)).toBe(true);
182
- expect(result.length).toBeGreaterThan(0);
183
- expect(result[0]).toHaveProperty('identifier');
184
- expect(result[0]).toHaveProperty('meta');
185
- expect(result[0]).toHaveProperty('models');
418
+ describe('MCP Market', () => {
419
+ describe('getMcpList', () => {
420
+ it('should call market SDK with normalized locale', async () => {
421
+ await service.getMcpList({ locale: 'en-US' });
422
+
423
+ expect(mockMarket.plugins.getPluginList).toHaveBeenCalledWith(
424
+ expect.objectContaining({
425
+ locale: 'en',
426
+ }),
427
+ expect.any(Object),
428
+ );
429
+ });
186
430
  });
187
431
 
188
- it('should search providers', async () => {
189
- const mockProviders = [
190
- { identifier: 'provider1', meta: { title: 'Test Provider' } },
191
- { identifier: 'provider2', meta: { title: 'Another Provider' } },
192
- ];
193
-
194
- vi.spyOn(service, 'getProviderList').mockResolvedValue(mockProviders as any);
195
-
196
- const result = await service.searchProvider('en-US', 'test');
197
- expect(result).toHaveLength(1);
198
- expect(result[0].identifier).toBe('provider1');
432
+ describe('getMcpDetail', () => {
433
+ it('should return MCP detail with related items', async () => {
434
+ const mockMcp = { identifier: 'mcp-1', category: 'tools' };
435
+ mockMarket.plugins.getPluginDetail.mockResolvedValue(mockMcp);
436
+
437
+ const result = await service.getMcpDetail({
438
+ identifier: 'mcp-1',
439
+ });
440
+
441
+ expect(result).toEqual(
442
+ expect.objectContaining({
443
+ identifier: 'mcp-1',
444
+ related: expect.any(Array),
445
+ }),
446
+ );
447
+ });
199
448
  });
449
+ });
200
450
 
201
- it('should get provider by id', async () => {
202
- const mockProvider = {
203
- identifier: 'test-provider',
204
- meta: { title: 'Test Provider' },
205
- models: ['model1', 'model2'],
206
- };
207
-
208
- vi.spyOn(service, 'getProviderList').mockResolvedValue([mockProvider] as any);
209
-
210
- const result = await service.getProviderById('en-US', 'test-provider');
211
-
212
- expect(result).toBeDefined();
213
- expect(result?.identifier).toBe('test-provider');
451
+ describe('Provider Market', () => {
452
+ describe('getProviderList', () => {
453
+ it('should return formatted provider list', async () => {
454
+ const result = await service.getProviderList();
455
+
456
+ expect(result.items).toEqual(
457
+ expect.arrayContaining([
458
+ expect.objectContaining({
459
+ identifier: 'openai',
460
+ name: 'OpenAI',
461
+ modelCount: expect.any(Number),
462
+ }),
463
+ expect.objectContaining({
464
+ identifier: 'anthropic',
465
+ name: 'Anthropic',
466
+ modelCount: expect.any(Number),
467
+ }),
468
+ ]),
469
+ );
470
+ });
471
+
472
+ it('should filter by search query', async () => {
473
+ const result = await service.getProviderList({ q: 'openai' });
474
+
475
+ expect(result.items).toHaveLength(1);
476
+ expect(result.items[0].identifier).toBe('openai');
477
+ });
478
+
479
+ it('should sort by model count', async () => {
480
+ const result = await service.getProviderList({
481
+ sort: ProviderSorts.ModelCount,
482
+ order: 'desc',
483
+ });
484
+
485
+ expect(result.items).toHaveLength(2);
486
+ });
214
487
  });
215
488
 
216
- it('should get providers by ids', async () => {
217
- const mockProviders = [{ identifier: 'provider1' }, { identifier: 'provider2' }];
218
-
219
- vi.spyOn(service, 'getProviderById').mockImplementation(
220
- async (_, id) => mockProviders.find((p) => p.identifier === id) as any,
221
- );
222
-
223
- const result = await service.getProviderByIds('en-US', [
224
- 'provider1',
225
- 'provider2',
226
- 'nonexistent',
227
- ]);
228
- expect(result).toHaveLength(2);
229
- expect(result[0].identifier).toBe('provider1');
230
- expect(result[1].identifier).toBe('provider2');
489
+ describe('getProviderDetail', () => {
490
+ it('should return provider detail', async () => {
491
+ const result = await service.getProviderDetail({
492
+ identifier: 'openai',
493
+ });
494
+
495
+ expect(result).toEqual(
496
+ expect.objectContaining({
497
+ identifier: 'openai',
498
+ name: 'OpenAI',
499
+ models: expect.any(Array),
500
+ related: expect.any(Array),
501
+ }),
502
+ );
503
+ });
231
504
  });
232
505
  });
233
506
 
234
- describe('Models', () => {
235
- it('should get model list', async () => {
236
- const result = await service.getModelList('en-US');
237
- expect(result).toBeDefined();
238
- expect(Array.isArray(result)).toBe(true);
239
- expect(result.length).toBeGreaterThan(0);
240
- expect(result[0]).toHaveProperty('identifier');
241
- expect(result[0]).toHaveProperty('meta');
242
- expect(result[0]).toHaveProperty('providers');
507
+ describe('Model Market', () => {
508
+ describe('getModelList', () => {
509
+ it('should return deduplicated model list', async () => {
510
+ const result = await service.getModelList();
511
+
512
+ expect(result.items).toEqual(
513
+ expect.arrayContaining([
514
+ expect.objectContaining({
515
+ identifier: expect.any(String),
516
+ displayName: expect.any(String),
517
+ providers: expect.any(Array),
518
+ }),
519
+ ]),
520
+ );
521
+ });
522
+
523
+ it('should filter by category', async () => {
524
+ const result = await service.getModelList({ category: 'openai' });
525
+
526
+ expect(result.items.length).toBeGreaterThan(0);
527
+ });
528
+
529
+ it('should sort by context window tokens', async () => {
530
+ const result = await service.getModelList({
531
+ sort: ModelSorts.ContextWindowTokens,
532
+ order: 'desc',
533
+ });
534
+
535
+ expect(result.items).toHaveLength(2);
536
+ });
537
+
538
+ it('should filter by search query', async () => {
539
+ const result = await service.getModelList({ q: 'gpt' });
540
+
541
+ expect(result.items.length).toBeGreaterThan(0);
542
+ });
243
543
  });
244
544
 
245
- it('should search models', async () => {
246
- const mockModels = [
247
- {
248
- identifier: 'model1',
249
- meta: { title: 'Test Model', description: 'A test model' },
250
- providers: ['provider1'],
251
- },
252
- {
253
- identifier: 'model2',
254
- meta: { title: 'Another Model', description: 'Another test model' },
255
- providers: ['provider2'],
256
- },
257
- ];
258
-
259
- vi.spyOn(service as any, '_getModelList').mockResolvedValue(mockModels);
260
-
261
- const result = await service.searchModel('en-US', 'A test model');
262
- expect(result).toHaveLength(1);
263
- expect(result[0].identifier).toBe('model1');
545
+ describe('getModelDetail', () => {
546
+ it('should return model detail with providers', async () => {
547
+ const result = await service.getModelDetail({
548
+ identifier: 'gpt-4',
549
+ });
550
+
551
+ expect(result).toEqual(
552
+ expect.objectContaining({
553
+ identifier: 'gpt-4',
554
+ displayName: 'GPT-4',
555
+ providers: expect.any(Array),
556
+ related: expect.any(Array),
557
+ }),
558
+ );
559
+ });
264
560
  });
265
561
 
266
- it('should get model category', async () => {
267
- const mockModels = [{ meta: { category: 'category1' } }, { meta: { category: 'category2' } }];
268
-
269
- vi.spyOn(service as any, '_getModelList').mockResolvedValue(mockModels);
270
-
271
- const result = await service.getModelCategory('en-US', 'category1');
272
- expect(result).toHaveLength(1);
273
- expect(result[0].meta.category).toBe('category1');
562
+ describe('getModelCategories', () => {
563
+ it('should return model categories by provider', async () => {
564
+ const result = await service.getModelCategories();
565
+
566
+ expect(result).toEqual(
567
+ expect.arrayContaining([
568
+ expect.objectContaining({
569
+ category: expect.any(String),
570
+ count: expect.any(Number),
571
+ }),
572
+ ]),
573
+ );
574
+ });
274
575
  });
576
+ });
275
577
 
276
- it('should get model by id', async () => {
277
- const mockModel = {
278
- identifier: 'test-model',
279
- meta: { category: 'test-category' },
280
- providers: ['provider1'],
281
- };
578
+ describe('Helper Methods', () => {
579
+ describe('calculateAbilitiesScore', () => {
580
+ it('should calculate abilities score correctly', () => {
581
+ const abilities = {
582
+ vision: true,
583
+ functionCall: true,
584
+ files: false,
585
+ };
586
+
587
+ // Access private method for testing
588
+ const score = (service as any).calculateAbilitiesScore(abilities);
589
+ expect(score).toBe(2); // vision + functionCall
590
+ });
591
+
592
+ it('should return 0 for empty abilities', () => {
593
+ const score = (service as any).calculateAbilitiesScore(null);
594
+ expect(score).toBe(0);
595
+ });
596
+ });
282
597
 
283
- vi.spyOn(service, 'getModelList').mockResolvedValue([mockModel] as any);
284
- vi.spyOn(service, 'getModelCategory').mockResolvedValue([]);
598
+ describe('selectModelWithBestAbilities', () => {
599
+ it('should select model with best abilities', () => {
600
+ const models = [
601
+ {
602
+ identifier: 'model-1',
603
+ abilities: { vision: true },
604
+ contextWindowTokens: 4000,
605
+ },
606
+ {
607
+ identifier: 'model-1',
608
+ abilities: { vision: true, functionCall: true },
609
+ contextWindowTokens: 8000,
610
+ },
611
+ ];
285
612
 
286
- const result = await service.getModelById('en-US', 'test-model');
613
+ const result = (service as any).selectModelWithBestAbilities(models);
287
614
 
288
- expect(result).toBeDefined();
289
- expect(result?.identifier).toBe('test-model');
290
- });
615
+ expect(result.abilities).toEqual({ vision: true, functionCall: true });
616
+ expect(result.contextWindowTokens).toBe(8000);
617
+ });
291
618
 
292
- it('should get models by ids', async () => {
293
- const mockModels = [{ identifier: 'model1' }, { identifier: 'model2' }];
619
+ it('should return single model if only one provided', () => {
620
+ const models = [{ identifier: 'model-1', abilities: {} }];
294
621
 
295
- vi.spyOn(service, 'getModelById').mockImplementation(
296
- async (_, id) => mockModels.find((m) => m.identifier === id) as any,
297
- );
622
+ const result = (service as any).selectModelWithBestAbilities(models);
298
623
 
299
- const result = await service.getModelByIds('en-US', ['model1', 'model2', 'nonexistent']);
300
- expect(result).toHaveLength(2);
301
- expect(result[0].identifier).toBe('model1');
302
- expect(result[1].identifier).toBe('model2');
624
+ expect(result).toEqual(models[0]);
625
+ });
303
626
  });
304
627
  });
305
628
  });