@songtonyli/dsh-cli 0.1.76 → 0.1.77

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 (677) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh/README.i18n.yaml +2 -2
  4. package/node_modules/@deepseek-ai/dsh/README.md +1 -1
  5. package/node_modules/@deepseek-ai/dsh/README.zh.md +1 -1
  6. package/node_modules/@deepseek-ai/dsh/package.json +117 -116
  7. package/node_modules/@deepseek-ai/dsh-acp/package.json +23 -23
  8. package/node_modules/@deepseek-ai/dsh-acp-app/package.json +3 -3
  9. package/node_modules/@deepseek-ai/dsh-agent/package.json +18 -18
  10. package/node_modules/@deepseek-ai/dsh-agent-default-model/package.json +7 -7
  11. package/node_modules/@deepseek-ai/dsh-agent-instructions/package.json +24 -24
  12. package/node_modules/@deepseek-ai/dsh-agent-loop/package.json +22 -22
  13. package/node_modules/@deepseek-ai/dsh-agent-preset/package.json +6 -6
  14. package/node_modules/@deepseek-ai/dsh-agent-preset/skills/cordis-composition-reference/references/packages.md +3 -1
  15. package/node_modules/@deepseek-ai/dsh-agent-preset-registry/package.json +26 -26
  16. package/node_modules/@deepseek-ai/dsh-agent-tool-presentation/package.json +8 -8
  17. package/node_modules/@deepseek-ai/dsh-anonymous-user-id/package.json +5 -5
  18. package/node_modules/@deepseek-ai/dsh-api-account-controller/lib/typert.host.js +7 -6
  19. package/node_modules/@deepseek-ai/dsh-api-account-controller/lib/typert.remote-client.js +7 -6
  20. package/node_modules/@deepseek-ai/dsh-api-account-controller/package.json +7 -7
  21. package/node_modules/@deepseek-ai/dsh-api-authorization-controller/package.json +9 -9
  22. package/node_modules/@deepseek-ai/dsh-api-gateway/package.json +11 -11
  23. package/node_modules/@deepseek-ai/dsh-api-job-controller/package.json +9 -10
  24. package/node_modules/@deepseek-ai/dsh-api-remote-access/package.json +7 -8
  25. package/node_modules/@deepseek-ai/dsh-api-remotes/lib/client.js +490 -62
  26. package/node_modules/@deepseek-ai/dsh-api-remotes/lib/index.js +4 -0
  27. package/node_modules/@deepseek-ai/dsh-api-remotes/lib/types/client/index.js +3 -1
  28. package/node_modules/@deepseek-ai/dsh-api-remotes/lib/types/remote-events.js +1 -0
  29. package/node_modules/@deepseek-ai/dsh-api-remotes/package.json +42 -41
  30. package/node_modules/@deepseek-ai/dsh-api-session-controller/lib/typert.host.js +1 -1
  31. package/node_modules/@deepseek-ai/dsh-api-session-controller/package.json +72 -73
  32. package/node_modules/@deepseek-ai/dsh-api-settings-controller/package.json +13 -13
  33. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/README.i18n.yaml +2 -2
  34. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/README.md +2 -0
  35. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/README.zh.md +2 -0
  36. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/lib/client.js +166 -21
  37. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/lib/types/client/index.js +36 -9
  38. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/lib/types/client/inventory.js +101 -0
  39. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/lib/types/client/model.js +23 -7
  40. package/node_modules/@deepseek-ai/dsh-api-terminal-controller/package.json +19 -19
  41. package/node_modules/@deepseek-ai/dsh-api-workspace-controller/package.json +18 -19
  42. package/node_modules/@deepseek-ai/dsh-api-workspace-files/package.json +12 -13
  43. package/node_modules/@deepseek-ai/dsh-app-boot/README.i18n.yaml +2 -2
  44. package/node_modules/@deepseek-ai/dsh-app-boot/README.md +2 -2
  45. package/node_modules/@deepseek-ai/dsh-app-boot/README.zh.md +2 -2
  46. package/node_modules/@deepseek-ai/dsh-app-boot/lib/index.js +40 -26
  47. package/node_modules/@deepseek-ai/dsh-app-boot/package.json +8 -8
  48. package/node_modules/@deepseek-ai/dsh-atomic-write/package.json +1 -1
  49. package/node_modules/@deepseek-ai/dsh-attachment/package.json +3 -3
  50. package/node_modules/@deepseek-ai/dsh-attachment-local/package.json +6 -6
  51. package/node_modules/@deepseek-ai/dsh-authorization/package.json +5 -5
  52. package/node_modules/@deepseek-ai/dsh-base/package.json +94 -94
  53. package/node_modules/@deepseek-ai/dsh-bash-local/package.json +8 -8
  54. package/node_modules/@deepseek-ai/dsh-bash-sandbox/package.json +12 -12
  55. package/node_modules/@deepseek-ai/dsh-brand/package.json +1 -1
  56. package/node_modules/@deepseek-ai/dsh-chunked-list/package.json +1 -1
  57. package/node_modules/@deepseek-ai/dsh-client-connection/package.json +10 -10
  58. package/node_modules/@deepseek-ai/dsh-client-file-upload/package.json +10 -10
  59. package/node_modules/@deepseek-ai/dsh-client-hmr/README.i18n.yaml +2 -2
  60. package/node_modules/@deepseek-ai/dsh-client-hmr/README.md +1 -1
  61. package/node_modules/@deepseek-ai/dsh-client-hmr/README.zh.md +1 -1
  62. package/node_modules/@deepseek-ai/dsh-client-hmr/lib/client.js +237 -11
  63. package/node_modules/@deepseek-ai/dsh-client-hmr/package.json +5 -4
  64. package/node_modules/@deepseek-ai/dsh-client-locale/package.json +7 -10
  65. package/node_modules/@deepseek-ai/dsh-client-modules/README.i18n.yaml +10 -7
  66. package/node_modules/@deepseek-ai/dsh-client-modules/README.md +8 -2
  67. package/node_modules/@deepseek-ai/dsh-client-modules/README.zh.md +9 -2
  68. package/node_modules/@deepseek-ai/dsh-client-modules/lib/client.js +136 -6
  69. package/node_modules/@deepseek-ai/dsh-client-modules/lib/index.js +25 -6
  70. package/node_modules/@deepseek-ai/dsh-client-modules/package.json +3 -4
  71. package/node_modules/@deepseek-ai/dsh-client-product-analytics/README.i18n.yaml +6 -6
  72. package/node_modules/@deepseek-ai/dsh-client-product-analytics/README.md +22 -4
  73. package/node_modules/@deepseek-ai/dsh-client-product-analytics/README.zh.md +22 -4
  74. package/node_modules/@deepseek-ai/dsh-client-product-analytics/lib/index.js +238 -6
  75. package/node_modules/@deepseek-ai/dsh-client-product-analytics/lib/typert.host.js +6 -6
  76. package/node_modules/@deepseek-ai/dsh-client-product-analytics/lib/typert.remote-client.js +4 -4
  77. package/node_modules/@deepseek-ai/dsh-client-product-analytics/package.json +12 -11
  78. package/node_modules/@deepseek-ai/dsh-client-resources/package.json +3 -5
  79. package/node_modules/@deepseek-ai/dsh-client-shortcuts/package.json +6 -8
  80. package/node_modules/@deepseek-ai/dsh-client-ui-agent-preset/package.json +14 -17
  81. package/node_modules/@deepseek-ai/dsh-client-ui-approval/package.json +11 -13
  82. package/node_modules/@deepseek-ai/dsh-client-ui-attachment/package.json +8 -10
  83. package/node_modules/@deepseek-ai/dsh-client-ui-brand-official/package.json +3 -4
  84. package/node_modules/@deepseek-ai/dsh-client-ui-chat/package.json +34 -37
  85. package/node_modules/@deepseek-ai/dsh-client-ui-commands/README.i18n.yaml +2 -2
  86. package/node_modules/@deepseek-ai/dsh-client-ui-commands/README.md +1 -1
  87. package/node_modules/@deepseek-ai/dsh-client-ui-commands/README.zh.md +1 -1
  88. package/node_modules/@deepseek-ai/dsh-client-ui-commands/lib/client.js +16 -1
  89. package/node_modules/@deepseek-ai/dsh-client-ui-commands/package.json +12 -15
  90. package/node_modules/@deepseek-ai/dsh-client-ui-conversation/README.i18n.yaml +2 -2
  91. package/node_modules/@deepseek-ai/dsh-client-ui-conversation/README.md +2 -2
  92. package/node_modules/@deepseek-ai/dsh-client-ui-conversation/README.zh.md +2 -2
  93. package/node_modules/@deepseek-ai/dsh-client-ui-conversation/lib/client.js +356 -124
  94. package/node_modules/@deepseek-ai/dsh-client-ui-conversation/package.json +30 -33
  95. package/node_modules/@deepseek-ai/dsh-client-ui-cordis/package.json +11 -13
  96. package/node_modules/@deepseek-ai/dsh-client-ui-deliverables/package.json +25 -28
  97. package/node_modules/@deepseek-ai/dsh-client-ui-directory-picker-browse/package.json +5 -7
  98. package/node_modules/@deepseek-ai/dsh-client-ui-directory-picker-native/package.json +3 -3
  99. package/node_modules/@deepseek-ai/dsh-client-ui-goal/package.json +12 -14
  100. package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/README.i18n.yaml +2 -2
  101. package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/README.md +1 -1
  102. package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/README.zh.md +1 -1
  103. package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/lib/client.js +18 -0
  104. package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/package.json +9 -12
  105. package/node_modules/@deepseek-ai/dsh-client-ui-jobs/package.json +8 -10
  106. package/node_modules/@deepseek-ai/dsh-client-ui-layout/package.json +7 -9
  107. package/node_modules/@deepseek-ai/dsh-client-ui-message-feedback/package.json +13 -16
  108. package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/README.i18n.yaml +3 -0
  109. package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/README.md +8 -0
  110. package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/README.zh.md +8 -0
  111. package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/lib/client.js +34 -8
  112. package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/package.json +13 -16
  113. package/node_modules/@deepseek-ai/dsh-client-ui-open-in-app/package.json +16 -19
  114. package/node_modules/@deepseek-ai/dsh-client-ui-permission-presets/package.json +12 -15
  115. package/node_modules/@deepseek-ai/dsh-client-ui-plan/package.json +17 -20
  116. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-manager/README.i18n.yaml +5 -2
  117. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-manager/README.md +4 -0
  118. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-manager/README.zh.md +4 -0
  119. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-manager/lib/client.js +314 -85
  120. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-manager/package.json +13 -16
  121. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-market/README.i18n.yaml +34 -0
  122. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-market/README.md +72 -0
  123. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-market/README.zh.md +72 -0
  124. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-market/lib/client.js +1637 -0
  125. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-market/lib/index.js +6 -0
  126. package/node_modules/@deepseek-ai/dsh-client-ui-plugin-market/package.json +62 -0
  127. package/node_modules/@deepseek-ai/dsh-client-ui-reference/package.json +13 -15
  128. package/node_modules/@deepseek-ai/dsh-client-ui-renderer/package.json +1 -2
  129. package/node_modules/@deepseek-ai/dsh-client-ui-schedule/package.json +17 -19
  130. package/node_modules/@deepseek-ai/dsh-client-ui-secret-mask/package.json +4 -5
  131. package/node_modules/@deepseek-ai/dsh-client-ui-session/package.json +7 -9
  132. package/node_modules/@deepseek-ai/dsh-client-ui-settings/package.json +4 -6
  133. package/node_modules/@deepseek-ai/dsh-client-ui-settings-account/README.i18n.yaml +2 -2
  134. package/node_modules/@deepseek-ai/dsh-client-ui-settings-account/README.md +1 -1
  135. package/node_modules/@deepseek-ai/dsh-client-ui-settings-account/README.zh.md +1 -1
  136. package/node_modules/@deepseek-ai/dsh-client-ui-settings-account/lib/client.js +117 -66
  137. package/node_modules/@deepseek-ai/dsh-client-ui-settings-account/package.json +13 -16
  138. package/node_modules/@deepseek-ai/dsh-client-ui-settings-agent-loop/package.json +6 -9
  139. package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/README.i18n.yaml +5 -2
  140. package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/README.md +6 -0
  141. package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/README.zh.md +6 -0
  142. package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/lib/client.js +176 -39
  143. package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/package.json +15 -14
  144. package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/README.i18n.yaml +2 -2
  145. package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/README.md +3 -1
  146. package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/README.zh.md +3 -1
  147. package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/lib/client.js +324 -36
  148. package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/package.json +8 -11
  149. package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugin-inventory/package.json +9 -12
  150. package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugins/package.json +5 -6
  151. package/node_modules/@deepseek-ai/dsh-client-ui-settings-session-log/package.json +6 -9
  152. package/node_modules/@deepseek-ai/dsh-client-ui-settings-shell/package.json +6 -9
  153. package/node_modules/@deepseek-ai/dsh-client-ui-settings-signin/package.json +4 -7
  154. package/node_modules/@deepseek-ai/dsh-client-ui-settings-subagent/package.json +6 -9
  155. package/node_modules/@deepseek-ai/dsh-client-ui-settings-web-search/package.json +6 -9
  156. package/node_modules/@deepseek-ai/dsh-client-ui-shortcuts/package.json +7 -10
  157. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  158. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/package.json +9 -12
  159. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-browser/package.json +8 -11
  160. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-documentpreview/package.json +15 -18
  161. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-files/package.json +11 -14
  162. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-right/lib/client.js +1 -1
  163. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-right/package.json +12 -15
  164. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-terminal/package.json +12 -15
  165. package/node_modules/@deepseek-ai/dsh-client-ui-skill/README.i18n.yaml +6 -6
  166. package/node_modules/@deepseek-ai/dsh-client-ui-skill/README.md +5 -3
  167. package/node_modules/@deepseek-ai/dsh-client-ui-skill/README.zh.md +5 -3
  168. package/node_modules/@deepseek-ai/dsh-client-ui-skill/lib/client.js +1 -0
  169. package/node_modules/@deepseek-ai/dsh-client-ui-skill/package.json +14 -15
  170. package/node_modules/@deepseek-ai/dsh-client-ui-subagent/package.json +15 -17
  171. package/node_modules/@deepseek-ai/dsh-client-ui-theme/package.json +9 -12
  172. package/node_modules/@deepseek-ai/dsh-client-ui-tool/README.i18n.yaml +2 -2
  173. package/node_modules/@deepseek-ai/dsh-client-ui-tool/README.md +1 -1
  174. package/node_modules/@deepseek-ai/dsh-client-ui-tool/README.zh.md +1 -1
  175. package/node_modules/@deepseek-ai/dsh-client-ui-tool/lib/client.js +75 -25
  176. package/node_modules/@deepseek-ai/dsh-client-ui-tool/package.json +25 -27
  177. package/node_modules/@deepseek-ai/dsh-client-ui-trajectory/package.json +14 -17
  178. package/node_modules/@deepseek-ai/dsh-client-ui-user-questions/package.json +18 -21
  179. package/node_modules/@deepseek-ai/dsh-client-ui-workflow-run/package.json +11 -14
  180. package/node_modules/@deepseek-ai/dsh-client-ui-workspace/package.json +23 -26
  181. package/node_modules/@deepseek-ai/dsh-cmdline/package.json +1 -1
  182. package/node_modules/@deepseek-ai/dsh-command-compact/package.json +8 -8
  183. package/node_modules/@deepseek-ai/dsh-command-feedback/package.json +11 -11
  184. package/node_modules/@deepseek-ai/dsh-command-goal/package.json +11 -11
  185. package/node_modules/@deepseek-ai/dsh-commands/package.json +16 -16
  186. package/node_modules/@deepseek-ai/dsh-compaction/package.json +9 -9
  187. package/node_modules/@deepseek-ai/dsh-compaction-basic/package.json +21 -21
  188. package/node_modules/@deepseek-ai/dsh-compaction-image-offload/package.json +16 -16
  189. package/node_modules/@deepseek-ai/dsh-compaction-tool-result-pruner/package.json +12 -12
  190. package/node_modules/@deepseek-ai/dsh-config-editor/package.json +6 -6
  191. package/node_modules/@deepseek-ai/dsh-cordis-client-runner/lib/client.js +95 -8
  192. package/node_modules/@deepseek-ai/dsh-cordis-client-runner/package.json +6 -6
  193. package/node_modules/@deepseek-ai/dsh-cordis-host-runner/package.json +18 -18
  194. package/node_modules/@deepseek-ai/dsh-credentials/package.json +2 -2
  195. package/node_modules/@deepseek-ai/dsh-credentials-local/package.json +9 -9
  196. package/node_modules/@deepseek-ai/dsh-deepseek-account/package.json +9 -7
  197. package/node_modules/@deepseek-ai/dsh-deepseek-account-platform/README.i18n.yaml +2 -2
  198. package/node_modules/@deepseek-ai/dsh-deepseek-account-platform/README.md +1 -1
  199. package/node_modules/@deepseek-ai/dsh-deepseek-account-platform/README.zh.md +1 -1
  200. package/node_modules/@deepseek-ai/dsh-deepseek-account-platform/lib/index.js +15 -13
  201. package/node_modules/@deepseek-ai/dsh-deepseek-account-platform/lib/types/details.js +10 -4
  202. package/node_modules/@deepseek-ai/dsh-deepseek-account-platform/package.json +9 -9
  203. package/node_modules/@deepseek-ai/dsh-deepseek-llm-api-extensions/package.json +1 -1
  204. package/node_modules/@deepseek-ai/dsh-deque/package.json +1 -1
  205. package/node_modules/@deepseek-ai/dsh-experimental-agent-team/package.json +19 -19
  206. package/node_modules/@deepseek-ai/dsh-experimental-agent-team-profile/package.json +4 -4
  207. package/node_modules/@deepseek-ai/dsh-experimental-api-speech-to-text/package.json +5 -5
  208. package/node_modules/@deepseek-ai/dsh-experimental-auto-review/package.json +38 -38
  209. package/node_modules/@deepseek-ai/dsh-experimental-badge-skill-bundle/package.json +2 -2
  210. package/node_modules/@deepseek-ai/dsh-experimental-client-ui-agent-team/package.json +9 -22
  211. package/node_modules/@deepseek-ai/dsh-experimental-client-ui-cot-translation/package.json +18 -26
  212. package/node_modules/@deepseek-ai/dsh-experimental-client-ui-voice-input/package.json +14 -32
  213. package/node_modules/@deepseek-ai/dsh-experimental-cot-translation-bundle/package.json +3 -3
  214. package/node_modules/@deepseek-ai/dsh-experimental-inspector/README.i18n.yaml +2 -2
  215. package/node_modules/@deepseek-ai/dsh-experimental-inspector/README.md +1 -1
  216. package/node_modules/@deepseek-ai/dsh-experimental-inspector/README.zh.md +1 -1
  217. package/node_modules/@deepseek-ai/dsh-experimental-inspector/lib/index.js +70 -17
  218. package/node_modules/@deepseek-ai/dsh-experimental-inspector/lib/worker.js +16 -12
  219. package/node_modules/@deepseek-ai/dsh-experimental-inspector/package.json +14 -20
  220. package/node_modules/@deepseek-ai/dsh-experimental-inspector-profile/package.json +3 -3
  221. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/README.i18n.yaml +34 -0
  222. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/README.md +68 -0
  223. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/README.zh.md +68 -0
  224. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/cordis.patch.yml +10 -0
  225. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/icon.svg +9 -0
  226. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/lib/index.js +1 -0
  227. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/locale/en.json +6 -0
  228. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/locale/zh.json +6 -0
  229. package/node_modules/@deepseek-ai/dsh-experimental-plugin-market-bundle/package.json +50 -0
  230. package/node_modules/@deepseek-ai/dsh-experimental-ralph-bundle/package.json +3 -3
  231. package/node_modules/@deepseek-ai/dsh-experimental-session-inspector/package.json +10 -13
  232. package/node_modules/@deepseek-ai/dsh-experimental-session-search/package.json +3 -3
  233. package/node_modules/@deepseek-ai/dsh-experimental-session-titles-bundle/package.json +2 -2
  234. package/node_modules/@deepseek-ai/dsh-experimental-speech-to-text/package.json +6 -6
  235. package/node_modules/@deepseek-ai/dsh-experimental-speech-to-text-sensevoice/lib/worker.js +26 -12
  236. package/node_modules/@deepseek-ai/dsh-experimental-speech-to-text-sensevoice/package.json +7 -7
  237. package/node_modules/@deepseek-ai/dsh-experimental-terminal-bundle/package.json +4 -4
  238. package/node_modules/@deepseek-ai/dsh-experimental-tool-agent-team/package.json +22 -22
  239. package/node_modules/@deepseek-ai/dsh-experimental-tool-worktree/package.json +18 -18
  240. package/node_modules/@deepseek-ai/dsh-experimental-translator/package.json +24 -24
  241. package/node_modules/@deepseek-ai/dsh-experimental-voice-input-bundle/package.json +5 -5
  242. package/node_modules/@deepseek-ai/dsh-experimental-worktree/package.json +21 -21
  243. package/node_modules/@deepseek-ai/dsh-file-reference/package.json +3 -3
  244. package/node_modules/@deepseek-ai/dsh-file-reference-local/package.json +13 -13
  245. package/node_modules/@deepseek-ai/dsh-fs/package.json +7 -7
  246. package/node_modules/@deepseek-ai/dsh-fs-local/package.json +4 -4
  247. package/node_modules/@deepseek-ai/dsh-fs-observation-policy/package.json +4 -4
  248. package/node_modules/@deepseek-ai/dsh-fs-sandbox/package.json +10 -10
  249. package/node_modules/@deepseek-ai/dsh-goal/package.json +20 -20
  250. package/node_modules/@deepseek-ai/dsh-goal-round-driver/package.json +15 -15
  251. package/node_modules/@deepseek-ai/dsh-harness-dev-context/package.json +11 -11
  252. package/node_modules/@deepseek-ai/dsh-headless/package.json +19 -19
  253. package/node_modules/@deepseek-ai/dsh-hmr/package.json +6 -6
  254. package/node_modules/@deepseek-ai/dsh-home-paths/package.json +1 -1
  255. package/node_modules/@deepseek-ai/dsh-host-directory-picker/package.json +1 -1
  256. package/node_modules/@deepseek-ai/dsh-host-directory-picker-auto/package.json +15 -15
  257. package/node_modules/@deepseek-ai/dsh-host-directory-picker-browse/package.json +2 -2
  258. package/node_modules/@deepseek-ai/dsh-host-directory-picker-native/package.json +3 -3
  259. package/node_modules/@deepseek-ai/dsh-host-frontend-static/package.json +6 -6
  260. package/node_modules/@deepseek-ai/dsh-host-open-in-app/package.json +5 -5
  261. package/node_modules/@deepseek-ai/dsh-host-plugin-inventory/package.json +9 -9
  262. package/node_modules/@deepseek-ai/dsh-host-product-telemetry-otel/package.json +4 -4
  263. package/node_modules/@deepseek-ai/dsh-host-webserver/package.json +1 -1
  264. package/node_modules/@deepseek-ai/dsh-http-proxy/package.json +1 -1
  265. package/node_modules/@deepseek-ai/dsh-jobs/package.json +9 -9
  266. package/node_modules/@deepseek-ai/dsh-jobs-local/package.json +11 -11
  267. package/node_modules/@deepseek-ai/dsh-launch-environment/package.json +1 -1
  268. package/node_modules/@deepseek-ai/dsh-lazy-require/package.json +1 -1
  269. package/node_modules/@deepseek-ai/dsh-llm/package.json +7 -7
  270. package/node_modules/@deepseek-ai/dsh-llm-cursor/package.json +20 -20
  271. package/node_modules/@deepseek-ai/dsh-llm-deepseek/package.json +37 -37
  272. package/node_modules/@deepseek-ai/dsh-llm-deepseek-account/package.json +13 -13
  273. package/node_modules/@deepseek-ai/dsh-llm-deepseek-api-key/package.json +9 -9
  274. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/package.json +21 -21
  275. package/node_modules/@deepseek-ai/dsh-llm-retry/package.json +19 -19
  276. package/node_modules/@deepseek-ai/dsh-mcp-client/package.json +20 -20
  277. package/node_modules/@deepseek-ai/dsh-mcp-resources/package.json +12 -12
  278. package/node_modules/@deepseek-ai/dsh-message-feedback/package.json +14 -14
  279. package/node_modules/@deepseek-ai/dsh-native-command/package.json +2 -2
  280. package/node_modules/@deepseek-ai/dsh-no-progress-reminder/package.json +10 -10
  281. package/node_modules/@deepseek-ai/dsh-office-to-pdf/package.json +6 -6
  282. package/node_modules/@deepseek-ai/dsh-otel/package.json +3 -3
  283. package/node_modules/@deepseek-ai/dsh-output-retention/package.json +1 -1
  284. package/node_modules/@deepseek-ai/dsh-package-manifest/package.json +1 -1
  285. package/node_modules/@deepseek-ai/dsh-permission-presets/package.json +18 -18
  286. package/node_modules/@deepseek-ai/dsh-persona/package.json +4 -4
  287. package/node_modules/@deepseek-ai/dsh-plan-mode/package.json +20 -20
  288. package/node_modules/@deepseek-ai/dsh-plugin-manager/README.i18n.yaml +2 -2
  289. package/node_modules/@deepseek-ai/dsh-plugin-manager/README.md +2 -2
  290. package/node_modules/@deepseek-ai/dsh-plugin-manager/README.zh.md +2 -2
  291. package/node_modules/@deepseek-ai/dsh-plugin-manager/lib/index.js +4 -3
  292. package/node_modules/@deepseek-ai/dsh-plugin-manager/lib/typert.host.js +14 -14
  293. package/node_modules/@deepseek-ai/dsh-plugin-manager/lib/typert.remote-client.js +13 -13
  294. package/node_modules/@deepseek-ai/dsh-plugin-manager/lib/types/failure.js +2 -2
  295. package/node_modules/@deepseek-ai/dsh-plugin-manager/lib/types/operations.js +3 -3
  296. package/node_modules/@deepseek-ai/dsh-plugin-manager/lib/types/tools.js +1 -1
  297. package/node_modules/@deepseek-ai/dsh-plugin-manager/package.json +27 -27
  298. package/node_modules/@deepseek-ai/dsh-plugin-market/README.i18n.yaml +43 -0
  299. package/node_modules/@deepseek-ai/dsh-plugin-market/README.md +117 -0
  300. package/node_modules/@deepseek-ai/dsh-plugin-market/README.zh.md +117 -0
  301. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/index.js +661 -0
  302. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/typert.host.js +407 -0
  303. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/typert.remote-client.js +259 -0
  304. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/index-url.js +27 -0
  305. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/index.js +351 -0
  306. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/parse-thread.js +61 -0
  307. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/parse.js +36 -0
  308. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/search.js +135 -0
  309. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/tools.js +128 -0
  310. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/types.js +2 -0
  311. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/types/worker.js +8 -0
  312. package/node_modules/@deepseek-ai/dsh-plugin-market/lib/worker.cjs +1759 -0
  313. package/node_modules/@deepseek-ai/dsh-plugin-market/package.json +89 -0
  314. package/node_modules/@deepseek-ai/dsh-plugin-market-index/README.i18n.yaml +34 -0
  315. package/node_modules/@deepseek-ai/dsh-plugin-market-index/README.md +74 -0
  316. package/node_modules/@deepseek-ai/dsh-plugin-market-index/README.zh.md +74 -0
  317. package/node_modules/@deepseek-ai/dsh-plugin-market-index/lib/index.js +320 -0
  318. package/node_modules/@deepseek-ai/{dsh-client-ui-slots → dsh-plugin-market-index}/package.json +15 -12
  319. package/node_modules/@deepseek-ai/dsh-plugin-package-inventory-deepseek/package.json +13 -13
  320. package/node_modules/@deepseek-ai/dsh-ptc-runtime/package.json +3 -3
  321. package/node_modules/@deepseek-ai/dsh-ptc-runtime-node/package.json +20 -20
  322. package/node_modules/@deepseek-ai/dsh-pwsh-local/package.json +8 -8
  323. package/node_modules/@deepseek-ai/dsh-pwsh-sandbox/package.json +12 -12
  324. package/node_modules/@deepseek-ai/dsh-repeat-tool-reminder/package.json +9 -9
  325. package/node_modules/@deepseek-ai/dsh-sandbox/package.json +6 -6
  326. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/package.json +22 -22
  327. package/node_modules/@deepseek-ai/dsh-sandbox-local/package.json +9 -9
  328. package/node_modules/@deepseek-ai/dsh-sandbox-policy/package.json +11 -11
  329. package/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/package.json +10 -10
  330. package/node_modules/@deepseek-ai/dsh-schedule/package.json +30 -30
  331. package/node_modules/@deepseek-ai/dsh-scope/package.json +1 -1
  332. package/node_modules/@deepseek-ai/dsh-sdk-app/README.i18n.yaml +4 -4
  333. package/node_modules/@deepseek-ai/dsh-sdk-app/README.md +2 -2
  334. package/node_modules/@deepseek-ai/dsh-sdk-app/README.zh.md +2 -2
  335. package/node_modules/@deepseek-ai/dsh-sdk-app/cordis.patch.yml +5 -0
  336. package/node_modules/@deepseek-ai/dsh-sdk-app/package.json +5 -5
  337. package/node_modules/@deepseek-ai/dsh-sdk-jsonrpc-server/package.json +23 -23
  338. package/node_modules/@deepseek-ai/dsh-sdk-minimal/package.json +34 -34
  339. package/node_modules/@deepseek-ai/dsh-sdk-protocol/package.json +7 -7
  340. package/node_modules/@deepseek-ai/dsh-session/package.json +8 -8
  341. package/node_modules/@deepseek-ai/dsh-session-checkpoint-policy/package.json +15 -15
  342. package/node_modules/@deepseek-ai/dsh-session-format/package.json +2 -2
  343. package/node_modules/@deepseek-ai/dsh-session-format-catalog/package.json +9 -9
  344. package/node_modules/@deepseek-ai/dsh-session-format-v0-to-v1/package.json +4 -4
  345. package/node_modules/@deepseek-ai/dsh-session-format-v1-to-v2/package.json +6 -6
  346. package/node_modules/@deepseek-ai/dsh-session-format-v2-to-v3/package.json +4 -4
  347. package/node_modules/@deepseek-ai/dsh-session-format-v3-to-v4/package.json +3 -3
  348. package/node_modules/@deepseek-ai/dsh-session-log-deepseek/package.json +13 -13
  349. package/node_modules/@deepseek-ai/dsh-session-log-export/package.json +18 -21
  350. package/node_modules/@deepseek-ai/dsh-session-persistence/package.json +9 -9
  351. package/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/package.json +10 -10
  352. package/node_modules/@deepseek-ai/dsh-session-projection/package.json +3 -3
  353. package/node_modules/@deepseek-ai/dsh-session-projection-cache/package.json +10 -10
  354. package/node_modules/@deepseek-ai/dsh-session-query/package.json +18 -18
  355. package/node_modules/@deepseek-ai/dsh-session-query-sqlite/package.json +9 -9
  356. package/node_modules/@deepseek-ai/dsh-session-reference/package.json +35 -35
  357. package/node_modules/@deepseek-ai/dsh-session-stats/package.json +7 -7
  358. package/node_modules/@deepseek-ai/dsh-session-telemetry/package.json +5 -5
  359. package/node_modules/@deepseek-ai/dsh-session-telemetry-otel/package.json +21 -21
  360. package/node_modules/@deepseek-ai/dsh-session-title/package.json +14 -14
  361. package/node_modules/@deepseek-ai/dsh-session-title-all-prompts-llm/package.json +12 -12
  362. package/node_modules/@deepseek-ai/dsh-session-title-first-prompt-llm/package.json +15 -15
  363. package/node_modules/@deepseek-ai/dsh-session-title-llm/package.json +10 -10
  364. package/node_modules/@deepseek-ai/dsh-session-turn-outline/package.json +7 -7
  365. package/node_modules/@deepseek-ai/dsh-settings/package.json +10 -10
  366. package/node_modules/@deepseek-ai/dsh-shell/package.json +5 -5
  367. package/node_modules/@deepseek-ai/dsh-shell-env/package.json +11 -11
  368. package/node_modules/@deepseek-ai/dsh-skill/package.json +6 -6
  369. package/node_modules/@deepseek-ai/dsh-skill-badge/package.json +3 -3
  370. package/node_modules/@deepseek-ai/dsh-skill-filesystem/package.json +7 -7
  371. package/node_modules/@deepseek-ai/dsh-skill-office/README.i18n.yaml +2 -2
  372. package/node_modules/@deepseek-ai/dsh-skill-office/README.md +1 -1
  373. package/node_modules/@deepseek-ai/dsh-skill-office/README.zh.md +1 -1
  374. package/node_modules/@deepseek-ai/dsh-skill-office/assets/office-export-pdf/SKILL.md +1 -1
  375. package/node_modules/@deepseek-ai/dsh-skill-office/assets/office-render/SKILL.md +1 -1
  376. package/node_modules/@deepseek-ai/dsh-skill-office/package.json +4 -4
  377. package/node_modules/@deepseek-ai/dsh-spill/package.json +7 -7
  378. package/node_modules/@deepseek-ai/dsh-spill-local/package.json +6 -6
  379. package/node_modules/@deepseek-ai/dsh-spill-policy/package.json +30 -30
  380. package/node_modules/@deepseek-ai/dsh-storage/package.json +1 -1
  381. package/node_modules/@deepseek-ai/dsh-storage-domain/package.json +3 -3
  382. package/node_modules/@deepseek-ai/dsh-storage-json/package.json +3 -3
  383. package/node_modules/@deepseek-ai/dsh-subagent/package.json +46 -46
  384. package/node_modules/@deepseek-ai/dsh-subagent-acp/package.json +20 -20
  385. package/node_modules/@deepseek-ai/dsh-subagent-fork-in-process/package.json +11 -11
  386. package/node_modules/@deepseek-ai/dsh-subagent-spawn-in-process/package.json +15 -15
  387. package/node_modules/@deepseek-ai/dsh-subprocess/package.json +4 -4
  388. package/node_modules/@deepseek-ai/dsh-subprocess-local/README.i18n.yaml +4 -4
  389. package/node_modules/@deepseek-ai/dsh-subprocess-local/README.md +3 -3
  390. package/node_modules/@deepseek-ai/dsh-subprocess-local/README.zh.md +3 -3
  391. package/node_modules/@deepseek-ai/dsh-subprocess-local/lib/index.js +252 -47
  392. package/node_modules/@deepseek-ai/dsh-subprocess-local/package.json +7 -7
  393. package/node_modules/@deepseek-ai/dsh-system-prompt/package.json +5 -5
  394. package/node_modules/@deepseek-ai/dsh-terminal/package.json +6 -6
  395. package/node_modules/@deepseek-ai/dsh-terminal-bash/package.json +19 -19
  396. package/node_modules/@deepseek-ai/dsh-time-context/package.json +18 -18
  397. package/node_modules/@deepseek-ai/dsh-timeout/package.json +1 -1
  398. package/node_modules/@deepseek-ai/dsh-tmux-context/package.json +11 -11
  399. package/node_modules/@deepseek-ai/dsh-token-meter/package.json +14 -14
  400. package/node_modules/@deepseek-ai/dsh-tool-ask-user/package.json +9 -9
  401. package/node_modules/@deepseek-ai/dsh-tool-bash/package.json +32 -32
  402. package/node_modules/@deepseek-ai/dsh-tool-bash-persistent/package.json +21 -21
  403. package/node_modules/@deepseek-ai/dsh-tool-call-timeout-policy/package.json +7 -7
  404. package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +125 -4
  405. package/node_modules/@deepseek-ai/dsh-tool-cordis/package.json +10 -10
  406. package/node_modules/@deepseek-ai/dsh-tool-fs/README.md +1 -1
  407. package/node_modules/@deepseek-ai/dsh-tool-fs/README.zh.md +1 -1
  408. package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +1 -1
  409. package/node_modules/@deepseek-ai/dsh-tool-fs/package.json +31 -31
  410. package/node_modules/@deepseek-ai/dsh-tool-fs-search/package.json +27 -27
  411. package/node_modules/@deepseek-ai/dsh-tool-goal/package.json +16 -16
  412. package/node_modules/@deepseek-ai/dsh-tool-jobs/package.json +15 -15
  413. package/node_modules/@deepseek-ai/dsh-tool-present/package.json +19 -19
  414. package/node_modules/@deepseek-ai/dsh-tool-pwsh/package.json +31 -31
  415. package/node_modules/@deepseek-ai/dsh-tool-pwsh-persistent/package.json +22 -22
  416. package/node_modules/@deepseek-ai/dsh-tool-ralph/package.json +19 -19
  417. package/node_modules/@deepseek-ai/dsh-tool-schedule/package.json +12 -12
  418. package/node_modules/@deepseek-ai/dsh-tool-session-query/package.json +24 -24
  419. package/node_modules/@deepseek-ai/dsh-tool-skill/package.json +14 -14
  420. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/package.json +19 -19
  421. package/node_modules/@deepseek-ai/dsh-tool-subagent/README.md +1 -1
  422. package/node_modules/@deepseek-ai/dsh-tool-subagent/README.zh.md +1 -1
  423. package/node_modules/@deepseek-ai/dsh-tool-subagent/lib/index.js +1 -1
  424. package/node_modules/@deepseek-ai/dsh-tool-subagent/package.json +22 -22
  425. package/node_modules/@deepseek-ai/dsh-tool-subagent-control/package.json +19 -19
  426. package/node_modules/@deepseek-ai/dsh-tool-terminal/package.json +25 -25
  427. package/node_modules/@deepseek-ai/dsh-tool-todo/package.json +13 -13
  428. package/node_modules/@deepseek-ai/dsh-tool-web/package.json +19 -19
  429. package/node_modules/@deepseek-ai/dsh-tool-workflow/package.json +20 -20
  430. package/node_modules/@deepseek-ai/dsh-tool-working-directory/package.json +11 -11
  431. package/node_modules/@deepseek-ai/dsh-tool-workspace-dependencies/package.json +6 -6
  432. package/node_modules/@deepseek-ai/dsh-tools/README.i18n.yaml +2 -2
  433. package/node_modules/@deepseek-ai/dsh-tools/README.md +3 -3
  434. package/node_modules/@deepseek-ai/dsh-tools/README.zh.md +3 -3
  435. package/node_modules/@deepseek-ai/dsh-tools/lib/index.js +45 -26
  436. package/node_modules/@deepseek-ai/dsh-tools/lib/types/index.js +1 -1
  437. package/node_modules/@deepseek-ai/dsh-tools/lib/types/ptc.js +20 -10
  438. package/node_modules/@deepseek-ai/dsh-tools/lib/types/py-types.js +1 -1
  439. package/node_modules/@deepseek-ai/dsh-tools/lib/types/ts-types.js +26 -9
  440. package/node_modules/@deepseek-ai/dsh-tools/package.json +24 -24
  441. package/node_modules/@deepseek-ai/dsh-tui-app/package.json +78 -78
  442. package/node_modules/@deepseek-ai/dsh-typert-loader/package.json +5 -5
  443. package/node_modules/@deepseek-ai/dsh-typert-protocol/package.json +2 -2
  444. package/node_modules/@deepseek-ai/dsh-typert-registry/package.json +2 -2
  445. package/node_modules/@deepseek-ai/dsh-user-approval/package.json +13 -13
  446. package/node_modules/@deepseek-ai/dsh-user-questions/package.json +15 -15
  447. package/node_modules/@deepseek-ai/dsh-util-code-language/package.json +1 -1
  448. package/node_modules/@deepseek-ai/dsh-util-crypto/package.json +1 -1
  449. package/node_modules/@deepseek-ai/dsh-util-time/package.json +1 -1
  450. package/node_modules/@deepseek-ai/dsh-util-values/package.json +1 -1
  451. package/node_modules/@deepseek-ai/dsh-util-workspace-path/package.json +1 -1
  452. package/node_modules/@deepseek-ai/dsh-web/package.json +3 -3
  453. package/node_modules/@deepseek-ai/dsh-web-app/package.json +140 -139
  454. package/node_modules/@deepseek-ai/dsh-web-app/presets/cordis.patch.yml +3 -0
  455. package/node_modules/@deepseek-ai/dsh-web-app/presets/ptc.patch.yml +3 -0
  456. package/node_modules/@deepseek-ai/dsh-web-app/presets/standard.patch.yml +3 -0
  457. package/node_modules/@deepseek-ai/dsh-web-fetch-http/package.json +7 -7
  458. package/node_modules/@deepseek-ai/dsh-web-frontend/package.json +18 -20
  459. package/node_modules/@deepseek-ai/dsh-web-search-deepseek/package.json +15 -15
  460. package/node_modules/@deepseek-ai/dsh-web-search-exa/package.json +6 -6
  461. package/node_modules/@deepseek-ai/dsh-web-search-perplexity/package.json +6 -6
  462. package/node_modules/@deepseek-ai/dsh-win32-process/package.json +2 -2
  463. package/node_modules/@deepseek-ai/dsh-workflow/package.json +9 -9
  464. package/node_modules/@deepseek-ai/dsh-workflow-ptc/package.json +36 -36
  465. package/node_modules/@deepseek-ai/dsh-working-directory/package.json +18 -18
  466. package/node_modules/@deepseek-ai/dsh-workspace/package.json +12 -12
  467. package/node_modules/@deepseek-ai/dsh-workspace-changes/package.json +18 -18
  468. package/node_modules/@earendil-works/pi-ai/README.md +5 -34
  469. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +59 -54
  470. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +16 -18
  471. package/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +2 -0
  472. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +2 -2
  473. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +29 -27
  474. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +15 -2
  475. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +21 -4
  476. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js +28 -15
  477. package/node_modules/@earendil-works/pi-ai/dist/index.js +0 -1
  478. package/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +8 -0
  479. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  480. package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  481. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  482. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
  483. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  484. package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  485. package/node_modules/@earendil-works/pi-ai/dist/providers/data/meta.json +1 -1
  486. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  487. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  488. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  489. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  490. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  491. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  492. package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  493. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  494. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  495. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  496. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  497. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  498. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +3 -3
  499. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js +2 -0
  500. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.js +26 -1
  501. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +5 -1
  502. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js +3 -0
  503. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  504. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  505. package/node_modules/minisearch/LICENSE.txt +7 -0
  506. package/node_modules/minisearch/README.md +347 -0
  507. package/node_modules/minisearch/dist/cjs/SearchableMap.cjs +549 -0
  508. package/node_modules/minisearch/dist/cjs/index.cjs +2007 -0
  509. package/node_modules/minisearch/dist/es/SearchableMap.js +547 -0
  510. package/node_modules/minisearch/dist/es/index.js +2005 -0
  511. package/node_modules/minisearch/dist/umd/SearchableMap.js +555 -0
  512. package/node_modules/minisearch/dist/umd/index.js +2013 -0
  513. package/node_modules/minisearch/package.json +90 -0
  514. package/node_modules/minisearch/src/MiniSearch.test.js +1997 -0
  515. package/node_modules/minisearch/src/MiniSearch.ts +2261 -0
  516. package/node_modules/minisearch/src/SearchableMap/SearchableMap.test.js +314 -0
  517. package/node_modules/minisearch/src/SearchableMap/SearchableMap.ts +424 -0
  518. package/node_modules/minisearch/src/SearchableMap/TreeIterator.ts +103 -0
  519. package/node_modules/minisearch/src/SearchableMap/fuzzySearch.ts +130 -0
  520. package/node_modules/minisearch/src/SearchableMap/types.ts +18 -0
  521. package/node_modules/minisearch/src/index.ts +4 -0
  522. package/node_modules/minisearch/src/testSetup/jest.js +1 -0
  523. package/package.json +305 -301
  524. package/node_modules/@deepseek-ai/dsh-client-store/LICENSE +0 -21
  525. package/node_modules/@deepseek-ai/dsh-client-store/README.i18n.yaml +0 -28
  526. package/node_modules/@deepseek-ai/dsh-client-store/README.md +0 -46
  527. package/node_modules/@deepseek-ai/dsh-client-store/README.zh.md +0 -46
  528. package/node_modules/@deepseek-ai/dsh-client-store/lib/index.js +0 -180
  529. package/node_modules/@deepseek-ai/dsh-client-store/lib/types/contract.d.ts +0 -121
  530. package/node_modules/@deepseek-ai/dsh-client-store/lib/types/index.d.ts +0 -92
  531. package/node_modules/@deepseek-ai/dsh-client-store/package.json +0 -37
  532. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/LICENSE +0 -21
  533. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/README.i18n.yaml +0 -61
  534. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/README.md +0 -221
  535. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/README.zh.md +0 -221
  536. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Button.module.css +0 -77
  537. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Checkbox.module.css +0 -28
  538. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/CodeCard.module.css +0 -83
  539. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/CommandText.module.css +0 -12
  540. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/ConnectionIndicator.module.css +0 -118
  541. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/DiffBlock.module.css +0 -80
  542. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/DisclosureRow.module.css +0 -111
  543. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/FileTypeIcon.module.css +0 -50
  544. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/HoverCard.module.css +0 -90
  545. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/ImageLightbox.module.css +0 -54
  546. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/ImagePreview.module.css +0 -24
  547. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/InlineEditor.module.css +0 -23
  548. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Input.module.css +0 -38
  549. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/JsonTree.module.css +0 -345
  550. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Menu.module.css +0 -285
  551. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/MenuGroup.module.css +0 -37
  552. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/MenuSurface.module.css +0 -49
  553. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Modal.module.css +0 -129
  554. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/OnboardingSurface.module.css +0 -28
  555. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/PathLabel.module.css +0 -28
  556. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Pill.module.css +0 -28
  557. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/ReadBlock.module.css +0 -43
  558. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/RiskConfirmation.module.css +0 -73
  559. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/SearchBlock.module.css +0 -112
  560. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/SegmentedControl.module.css +0 -76
  561. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/SegmentedTabs.module.css +0 -55
  562. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/ShortcutKeys.module.css +0 -33
  563. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/StateDot.module.css +0 -100
  564. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Switch.module.css +0 -49
  565. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Tag.module.css +0 -57
  566. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/TerminalBlock.module.css +0 -205
  567. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/TextShimmer.module.css +0 -88
  568. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Toast.module.css +0 -101
  569. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/Tooltip.module.css +0 -63
  570. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/WebBlock.module.css +0 -141
  571. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/index.js +0 -12583
  572. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/markdown/CodeBlock.module.css +0 -145
  573. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/markdown/JsonBlock.module.css +0 -32
  574. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/markdown/MarkdownText.module.css +0 -467
  575. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/settings-form/SettingsForm.module.css +0 -53
  576. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/settings-form/fields.module.css +0 -145
  577. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/BrandWordmark.d.ts +0 -15
  578. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Button.d.ts +0 -19
  579. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Checkbox.d.ts +0 -20
  580. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/CodeFileIcon.d.ts +0 -12
  581. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/CodeToolbar.d.ts +0 -30
  582. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/CommandText.d.ts +0 -16
  583. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ConfigField.d.ts +0 -33
  584. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ConnectionIndicator.d.ts +0 -26
  585. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/DiffBlock.d.ts +0 -52
  586. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/DisclosureRow.d.ts +0 -38
  587. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/FileTypeIcon.d.ts +0 -43
  588. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/FishLogo.d.ts +0 -16
  589. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/FoldToggle.d.ts +0 -20
  590. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/HoverCard.d.ts +0 -40
  591. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/HoverCardGroup.d.ts +0 -23
  592. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ImageLightbox.d.ts +0 -27
  593. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ImagePreview.d.ts +0 -12
  594. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/InlineEditor.d.ts +0 -23
  595. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Input.d.ts +0 -12
  596. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/JsonTree.d.ts +0 -59
  597. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/LinkIcon.d.ts +0 -34
  598. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Menu.d.ts +0 -143
  599. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/MenuGroup.d.ts +0 -22
  600. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/MenuSurface.d.ts +0 -16
  601. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Modal.d.ts +0 -44
  602. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/OnboardingSurface.d.ts +0 -11
  603. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/PathLabel.d.ts +0 -13
  604. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/PermissionIcon.d.ts +0 -51
  605. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Pill.d.ts +0 -13
  606. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ReadBlock.d.ts +0 -48
  607. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ReferenceIcon.d.ts +0 -21
  608. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/RiskConfirmation.d.ts +0 -20
  609. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/SearchBlock.d.ts +0 -72
  610. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/SegmentedControl.d.ts +0 -35
  611. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/SegmentedTabs.d.ts +0 -26
  612. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ShortcutKeys.d.ts +0 -11
  613. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/SiteGlyph.d.ts +0 -25
  614. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/StateDot.d.ts +0 -20
  615. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Switch.d.ts +0 -20
  616. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Tag.d.ts +0 -32
  617. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/TerminalBlock.d.ts +0 -86
  618. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/TextShimmer.d.ts +0 -22
  619. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Toast.d.ts +0 -49
  620. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/Tooltip.d.ts +0 -63
  621. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/WebBlock.d.ts +0 -61
  622. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/ansi.d.ts +0 -17
  623. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/clipboard.d.ts +0 -9
  624. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/code-file-icon-artwork.d.ts +0 -54
  625. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/code-file-types.d.ts +0 -30
  626. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/code-highlighting.d.ts +0 -12
  627. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/darwin-desktop.d.ts +0 -9
  628. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/file-size.d.ts +0 -8
  629. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/focus.d.ts +0 -9
  630. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/guide-artwork.d.ts +0 -15
  631. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/head-tail-cap.d.ts +0 -23
  632. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/icons/index.d.ts +0 -385
  633. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/icons/props.d.ts +0 -9
  634. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/icons/shared-artwork.d.ts +0 -43
  635. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/index.d.ts +0 -102
  636. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/input-modality.d.ts +0 -19
  637. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/keyboard-composition.d.ts +0 -11
  638. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/CodeBlock.d.ts +0 -35
  639. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/JsonBlock.d.ts +0 -8
  640. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/MarkdownDelegate.d.ts +0 -46
  641. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/MarkdownText.d.ts +0 -49
  642. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/cjkFriendlyStrong.d.ts +0 -9
  643. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/file-link.d.ts +0 -13
  644. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/highlight.d.ts +0 -148
  645. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/incremental.d.ts +0 -80
  646. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/katex.d.ts +0 -27
  647. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/local-image-syntax.d.ts +0 -10
  648. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/mathCompatibility.d.ts +0 -11
  649. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/parse.d.ts +0 -25
  650. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/plain-text.d.ts +0 -22
  651. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/render.d.ts +0 -141
  652. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/markdown/useViewportHighlighting.d.ts +0 -11
  653. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/overlay-top-margin.d.ts +0 -8
  654. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/plugin-artwork.d.ts +0 -17
  655. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/pointer-grace.d.ts +0 -22
  656. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/rank-by-name.d.ts +0 -22
  657. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/relative-time.d.ts +0 -23
  658. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/settings-form/SettingsForm.d.ts +0 -46
  659. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/settings-form/fields.d.ts +0 -70
  660. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/settings-form/form-model.d.ts +0 -214
  661. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/use-copy-feedback.d.ts +0 -14
  662. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/useAnchoredMaxHeight.d.ts +0 -14
  663. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/useAnchoredPosition.d.ts +0 -36
  664. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/useDismissOnOutsidePointer.d.ts +0 -11
  665. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/useModalLayer.d.ts +0 -27
  666. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/types/user-text.d.ts +0 -29
  667. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/lib/user-text.module.css +0 -46
  668. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +0 -61
  669. package/node_modules/@deepseek-ai/dsh-client-ui-slots/LICENSE +0 -21
  670. package/node_modules/@deepseek-ai/dsh-client-ui-slots/README.i18n.yaml +0 -55
  671. package/node_modules/@deepseek-ai/dsh-client-ui-slots/README.md +0 -111
  672. package/node_modules/@deepseek-ai/dsh-client-ui-slots/README.zh.md +0 -111
  673. package/node_modules/@deepseek-ai/dsh-client-ui-slots/lib/index.js +0 -577
  674. package/node_modules/@deepseek-ai/dsh-client-ui-slots/lib/types/index.d.ts +0 -955
  675. package/node_modules/@deepseek-ai/dsh-client-ui-slots/lib/types/renderer.d.ts +0 -271
  676. package/node_modules/@deepseek-ai/dsh-client-ui-slots/lib/types/store.d.ts +0 -3
  677. package/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.js +0 -425
@@ -0,0 +1,2005 @@
1
+ /** @ignore */
2
+ const ENTRIES = 'ENTRIES';
3
+ /** @ignore */
4
+ const KEYS = 'KEYS';
5
+ /** @ignore */
6
+ const VALUES = 'VALUES';
7
+ /** @ignore */
8
+ const LEAF = '';
9
+ /**
10
+ * @private
11
+ */
12
+ class TreeIterator {
13
+ constructor(set, type) {
14
+ const node = set._tree;
15
+ const keys = Array.from(node.keys());
16
+ this.set = set;
17
+ this._type = type;
18
+ this._path = keys.length > 0 ? [{ node, keys }] : [];
19
+ }
20
+ next() {
21
+ const value = this.dive();
22
+ this.backtrack();
23
+ return value;
24
+ }
25
+ dive() {
26
+ if (this._path.length === 0) {
27
+ return { done: true, value: undefined };
28
+ }
29
+ const { node, keys } = last$1(this._path);
30
+ if (last$1(keys) === LEAF) {
31
+ return { done: false, value: this.result() };
32
+ }
33
+ const child = node.get(last$1(keys));
34
+ this._path.push({ node: child, keys: Array.from(child.keys()) });
35
+ return this.dive();
36
+ }
37
+ backtrack() {
38
+ if (this._path.length === 0) {
39
+ return;
40
+ }
41
+ const keys = last$1(this._path).keys;
42
+ keys.pop();
43
+ if (keys.length > 0) {
44
+ return;
45
+ }
46
+ this._path.pop();
47
+ this.backtrack();
48
+ }
49
+ key() {
50
+ return this.set._prefix + this._path
51
+ .map(({ keys }) => last$1(keys))
52
+ .filter(key => key !== LEAF)
53
+ .join('');
54
+ }
55
+ value() {
56
+ return last$1(this._path).node.get(LEAF);
57
+ }
58
+ result() {
59
+ switch (this._type) {
60
+ case VALUES: return this.value();
61
+ case KEYS: return this.key();
62
+ default: return [this.key(), this.value()];
63
+ }
64
+ }
65
+ [Symbol.iterator]() {
66
+ return this;
67
+ }
68
+ }
69
+ const last$1 = (array) => {
70
+ return array[array.length - 1];
71
+ };
72
+
73
+ /* eslint-disable no-labels */
74
+ /**
75
+ * @ignore
76
+ */
77
+ const fuzzySearch = (node, query, maxDistance) => {
78
+ const results = new Map();
79
+ if (query === undefined)
80
+ return results;
81
+ // Number of columns in the Levenshtein matrix.
82
+ const n = query.length + 1;
83
+ // Matching terms can never be longer than N + maxDistance.
84
+ const m = n + maxDistance;
85
+ // Fill first matrix row and column with numbers: 0 1 2 3 ...
86
+ const matrix = new Uint8Array(m * n).fill(maxDistance + 1);
87
+ for (let j = 0; j < n; ++j)
88
+ matrix[j] = j;
89
+ for (let i = 1; i < m; ++i)
90
+ matrix[i * n] = i;
91
+ recurse(node, query, maxDistance, results, matrix, 1, n, '');
92
+ return results;
93
+ };
94
+ // Modified version of http://stevehanov.ca/blog/?id=114
95
+ // This builds a Levenshtein matrix for a given query and continuously updates
96
+ // it for nodes in the radix tree that fall within the given maximum edit
97
+ // distance. Keeping the same matrix around is beneficial especially for larger
98
+ // edit distances.
99
+ //
100
+ // k a t e <-- query
101
+ // 0 1 2 3 4
102
+ // c 1 1 2 3 4
103
+ // a 2 2 1 2 3
104
+ // t 3 3 2 1 [2] <-- edit distance
105
+ // ^
106
+ // ^ term in radix tree, rows are added and removed as needed
107
+ const recurse = (node, query, maxDistance, results, matrix, m, n, prefix) => {
108
+ const offset = m * n;
109
+ key: for (const key of node.keys()) {
110
+ if (key === LEAF) {
111
+ // We've reached a leaf node. Check if the edit distance acceptable and
112
+ // store the result if it is.
113
+ const distance = matrix[offset - 1];
114
+ if (distance <= maxDistance) {
115
+ results.set(prefix, [node.get(key), distance]);
116
+ }
117
+ }
118
+ else {
119
+ // Iterate over all characters in the key. Update the Levenshtein matrix
120
+ // and check if the minimum distance in the last row is still within the
121
+ // maximum edit distance. If it is, we can recurse over all child nodes.
122
+ let i = m;
123
+ for (let pos = 0; pos < key.length; ++pos, ++i) {
124
+ const char = key[pos];
125
+ const thisRowOffset = n * i;
126
+ const prevRowOffset = thisRowOffset - n;
127
+ // Set the first column based on the previous row, and initialize the
128
+ // minimum distance in the current row.
129
+ let minDistance = matrix[thisRowOffset];
130
+ const jmin = Math.max(0, i - maxDistance - 1);
131
+ const jmax = Math.min(n - 1, i + maxDistance);
132
+ // Iterate over remaining columns (characters in the query).
133
+ for (let j = jmin; j < jmax; ++j) {
134
+ const different = char !== query[j];
135
+ // It might make sense to only read the matrix positions used for
136
+ // deletion/insertion if the characters are different. But we want to
137
+ // avoid conditional reads for performance reasons.
138
+ const rpl = matrix[prevRowOffset + j] + +different;
139
+ const del = matrix[prevRowOffset + j + 1] + 1;
140
+ const ins = matrix[thisRowOffset + j] + 1;
141
+ const dist = matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins);
142
+ if (dist < minDistance)
143
+ minDistance = dist;
144
+ }
145
+ // Because distance will never decrease, we can stop. There will be no
146
+ // matching child nodes.
147
+ if (minDistance > maxDistance) {
148
+ continue key;
149
+ }
150
+ }
151
+ recurse(node.get(key), query, maxDistance, results, matrix, i, n, prefix + key);
152
+ }
153
+ }
154
+ };
155
+
156
+ /* eslint-disable no-labels */
157
+ /**
158
+ * A class implementing the same interface as a standard JavaScript
159
+ * [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
160
+ * with string keys, but adding support for efficiently searching entries with
161
+ * prefix or fuzzy search. This class is used internally by {@link MiniSearch}
162
+ * as the inverted index data structure. The implementation is a radix tree
163
+ * (compressed prefix tree).
164
+ *
165
+ * Since this class can be of general utility beyond _MiniSearch_, it is
166
+ * exported by the `minisearch` package and can be imported (or required) as
167
+ * `minisearch/SearchableMap`.
168
+ *
169
+ * @typeParam T The type of the values stored in the map.
170
+ */
171
+ class SearchableMap {
172
+ /**
173
+ * The constructor is normally called without arguments, creating an empty
174
+ * map. In order to create a {@link SearchableMap} from an iterable or from an
175
+ * object, check {@link SearchableMap.from} and {@link
176
+ * SearchableMap.fromObject}.
177
+ *
178
+ * The constructor arguments are for internal use, when creating derived
179
+ * mutable views of a map at a prefix.
180
+ */
181
+ constructor(tree = new Map(), prefix = '') {
182
+ this._size = undefined;
183
+ this._tree = tree;
184
+ this._prefix = prefix;
185
+ }
186
+ /**
187
+ * Creates and returns a mutable view of this {@link SearchableMap},
188
+ * containing only entries that share the given prefix.
189
+ *
190
+ * ### Usage:
191
+ *
192
+ * ```javascript
193
+ * let map = new SearchableMap()
194
+ * map.set("unicorn", 1)
195
+ * map.set("universe", 2)
196
+ * map.set("university", 3)
197
+ * map.set("unique", 4)
198
+ * map.set("hello", 5)
199
+ *
200
+ * let uni = map.atPrefix("uni")
201
+ * uni.get("unique") // => 4
202
+ * uni.get("unicorn") // => 1
203
+ * uni.get("hello") // => undefined
204
+ *
205
+ * let univer = map.atPrefix("univer")
206
+ * univer.get("unique") // => undefined
207
+ * univer.get("universe") // => 2
208
+ * univer.get("university") // => 3
209
+ * ```
210
+ *
211
+ * @param prefix The prefix
212
+ * @return A {@link SearchableMap} representing a mutable view of the original
213
+ * Map at the given prefix
214
+ */
215
+ atPrefix(prefix) {
216
+ if (!prefix.startsWith(this._prefix)) {
217
+ throw new Error('Mismatched prefix');
218
+ }
219
+ const [node, path] = trackDown(this._tree, prefix.slice(this._prefix.length));
220
+ if (node === undefined) {
221
+ const [parentNode, key] = last(path);
222
+ for (const k of parentNode.keys()) {
223
+ if (k !== LEAF && k.startsWith(key)) {
224
+ const node = new Map();
225
+ node.set(k.slice(key.length), parentNode.get(k));
226
+ return new SearchableMap(node, prefix);
227
+ }
228
+ }
229
+ }
230
+ return new SearchableMap(node, prefix);
231
+ }
232
+ /**
233
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
234
+ */
235
+ clear() {
236
+ this._size = undefined;
237
+ this._tree.clear();
238
+ }
239
+ /**
240
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete
241
+ * @param key Key to delete
242
+ */
243
+ delete(key) {
244
+ this._size = undefined;
245
+ return remove(this._tree, key);
246
+ }
247
+ /**
248
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries
249
+ * @return An iterator iterating through `[key, value]` entries.
250
+ */
251
+ entries() {
252
+ return new TreeIterator(this, ENTRIES);
253
+ }
254
+ /**
255
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach
256
+ * @param fn Iteration function
257
+ */
258
+ forEach(fn) {
259
+ for (const [key, value] of this) {
260
+ fn(key, value, this);
261
+ }
262
+ }
263
+ /**
264
+ * Returns a Map of all the entries that have a key within the given edit
265
+ * distance from the search key. The keys of the returned Map are the matching
266
+ * keys, while the values are two-element arrays where the first element is
267
+ * the value associated to the key, and the second is the edit distance of the
268
+ * key to the search key.
269
+ *
270
+ * ### Usage:
271
+ *
272
+ * ```javascript
273
+ * let map = new SearchableMap()
274
+ * map.set('hello', 'world')
275
+ * map.set('hell', 'yeah')
276
+ * map.set('ciao', 'mondo')
277
+ *
278
+ * // Get all entries that match the key 'hallo' with a maximum edit distance of 2
279
+ * map.fuzzyGet('hallo', 2)
280
+ * // => Map(2) { 'hello' => ['world', 1], 'hell' => ['yeah', 2] }
281
+ *
282
+ * // In the example, the "hello" key has value "world" and edit distance of 1
283
+ * // (change "e" to "a"), the key "hell" has value "yeah" and edit distance of 2
284
+ * // (change "e" to "a", delete "o")
285
+ * ```
286
+ *
287
+ * @param key The search key
288
+ * @param maxEditDistance The maximum edit distance (Levenshtein)
289
+ * @return A Map of the matching keys to their value and edit distance
290
+ */
291
+ fuzzyGet(key, maxEditDistance) {
292
+ return fuzzySearch(this._tree, key, maxEditDistance);
293
+ }
294
+ /**
295
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
296
+ * @param key Key to get
297
+ * @return Value associated to the key, or `undefined` if the key is not
298
+ * found.
299
+ */
300
+ get(key) {
301
+ const node = lookup(this._tree, key);
302
+ return node !== undefined ? node.get(LEAF) : undefined;
303
+ }
304
+ /**
305
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
306
+ * @param key Key
307
+ * @return True if the key is in the map, false otherwise
308
+ */
309
+ has(key) {
310
+ const node = lookup(this._tree, key);
311
+ return node !== undefined && node.has(LEAF);
312
+ }
313
+ /**
314
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
315
+ * @return An `Iterable` iterating through keys
316
+ */
317
+ keys() {
318
+ return new TreeIterator(this, KEYS);
319
+ }
320
+ /**
321
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set
322
+ * @param key Key to set
323
+ * @param value Value to associate to the key
324
+ * @return The {@link SearchableMap} itself, to allow chaining
325
+ */
326
+ set(key, value) {
327
+ if (typeof key !== 'string') {
328
+ throw new Error('key must be a string');
329
+ }
330
+ this._size = undefined;
331
+ const node = createPath(this._tree, key);
332
+ node.set(LEAF, value);
333
+ return this;
334
+ }
335
+ /**
336
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size
337
+ */
338
+ get size() {
339
+ if (this._size) {
340
+ return this._size;
341
+ }
342
+ /** @ignore */
343
+ this._size = 0;
344
+ const iter = this.entries();
345
+ while (!iter.next().done)
346
+ this._size += 1;
347
+ return this._size;
348
+ }
349
+ /**
350
+ * Updates the value at the given key using the provided function. The function
351
+ * is called with the current value at the key, and its return value is used as
352
+ * the new value to be set.
353
+ *
354
+ * ### Example:
355
+ *
356
+ * ```javascript
357
+ * // Increment the current value by one
358
+ * searchableMap.update('somekey', (currentValue) => currentValue == null ? 0 : currentValue + 1)
359
+ * ```
360
+ *
361
+ * If the value at the given key is or will be an object, it might not require
362
+ * re-assignment. In that case it is better to use `fetch()`, because it is
363
+ * faster.
364
+ *
365
+ * @param key The key to update
366
+ * @param fn The function used to compute the new value from the current one
367
+ * @return The {@link SearchableMap} itself, to allow chaining
368
+ */
369
+ update(key, fn) {
370
+ if (typeof key !== 'string') {
371
+ throw new Error('key must be a string');
372
+ }
373
+ this._size = undefined;
374
+ const node = createPath(this._tree, key);
375
+ node.set(LEAF, fn(node.get(LEAF)));
376
+ return this;
377
+ }
378
+ /**
379
+ * Fetches the value of the given key. If the value does not exist, calls the
380
+ * given function to create a new value, which is inserted at the given key
381
+ * and subsequently returned.
382
+ *
383
+ * ### Example:
384
+ *
385
+ * ```javascript
386
+ * const map = searchableMap.fetch('somekey', () => new Map())
387
+ * map.set('foo', 'bar')
388
+ * ```
389
+ *
390
+ * @param key The key to update
391
+ * @param initial A function that creates a new value if the key does not exist
392
+ * @return The existing or new value at the given key
393
+ */
394
+ fetch(key, initial) {
395
+ if (typeof key !== 'string') {
396
+ throw new Error('key must be a string');
397
+ }
398
+ this._size = undefined;
399
+ const node = createPath(this._tree, key);
400
+ let value = node.get(LEAF);
401
+ if (value === undefined) {
402
+ node.set(LEAF, value = initial());
403
+ }
404
+ return value;
405
+ }
406
+ /**
407
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values
408
+ * @return An `Iterable` iterating through values.
409
+ */
410
+ values() {
411
+ return new TreeIterator(this, VALUES);
412
+ }
413
+ /**
414
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/@@iterator
415
+ */
416
+ [Symbol.iterator]() {
417
+ return this.entries();
418
+ }
419
+ /**
420
+ * Creates a {@link SearchableMap} from an `Iterable` of entries
421
+ *
422
+ * @param entries Entries to be inserted in the {@link SearchableMap}
423
+ * @return A new {@link SearchableMap} with the given entries
424
+ */
425
+ static from(entries) {
426
+ const tree = new SearchableMap();
427
+ for (const [key, value] of entries) {
428
+ tree.set(key, value);
429
+ }
430
+ return tree;
431
+ }
432
+ /**
433
+ * Creates a {@link SearchableMap} from the iterable properties of a JavaScript object
434
+ *
435
+ * @param object Object of entries for the {@link SearchableMap}
436
+ * @return A new {@link SearchableMap} with the given entries
437
+ */
438
+ static fromObject(object) {
439
+ return SearchableMap.from(Object.entries(object));
440
+ }
441
+ }
442
+ const trackDown = (tree, key, path = []) => {
443
+ if (key.length === 0 || tree == null) {
444
+ return [tree, path];
445
+ }
446
+ for (const k of tree.keys()) {
447
+ if (k !== LEAF && key.startsWith(k)) {
448
+ path.push([tree, k]); // performance: update in place
449
+ return trackDown(tree.get(k), key.slice(k.length), path);
450
+ }
451
+ }
452
+ path.push([tree, key]); // performance: update in place
453
+ return trackDown(undefined, '', path);
454
+ };
455
+ const lookup = (tree, key) => {
456
+ if (key.length === 0 || tree == null) {
457
+ return tree;
458
+ }
459
+ for (const k of tree.keys()) {
460
+ if (k !== LEAF && key.startsWith(k)) {
461
+ return lookup(tree.get(k), key.slice(k.length));
462
+ }
463
+ }
464
+ };
465
+ // Create a path in the radix tree for the given key, and returns the deepest
466
+ // node. This function is in the hot path for indexing. It avoids unnecessary
467
+ // string operations and recursion for performance.
468
+ const createPath = (node, key) => {
469
+ const keyLength = key.length;
470
+ outer: for (let pos = 0; node && pos < keyLength;) {
471
+ for (const k of node.keys()) {
472
+ // Check whether this key is a candidate: the first characters must match.
473
+ if (k !== LEAF && key[pos] === k[0]) {
474
+ const len = Math.min(keyLength - pos, k.length);
475
+ // Advance offset to the point where key and k no longer match.
476
+ let offset = 1;
477
+ while (offset < len && key[pos + offset] === k[offset])
478
+ ++offset;
479
+ const child = node.get(k);
480
+ if (offset === k.length) {
481
+ // The existing key is shorter than the key we need to create.
482
+ node = child;
483
+ }
484
+ else {
485
+ // Partial match: we need to insert an intermediate node to contain
486
+ // both the existing subtree and the new node.
487
+ const intermediate = new Map();
488
+ intermediate.set(k.slice(offset), child);
489
+ node.set(key.slice(pos, pos + offset), intermediate);
490
+ node.delete(k);
491
+ node = intermediate;
492
+ }
493
+ pos += offset;
494
+ continue outer;
495
+ }
496
+ }
497
+ // Create a final child node to contain the final suffix of the key.
498
+ const child = new Map();
499
+ node.set(key.slice(pos), child);
500
+ return child;
501
+ }
502
+ return node;
503
+ };
504
+ const remove = (tree, key) => {
505
+ const [node, path] = trackDown(tree, key);
506
+ if (node === undefined) {
507
+ return;
508
+ }
509
+ node.delete(LEAF);
510
+ if (node.size === 0) {
511
+ cleanup(path);
512
+ }
513
+ else if (node.size === 1) {
514
+ const [key, value] = node.entries().next().value;
515
+ merge(path, key, value);
516
+ }
517
+ };
518
+ const cleanup = (path) => {
519
+ if (path.length === 0) {
520
+ return;
521
+ }
522
+ const [node, key] = last(path);
523
+ node.delete(key);
524
+ if (node.size === 0) {
525
+ cleanup(path.slice(0, -1));
526
+ }
527
+ else if (node.size === 1) {
528
+ const [key, value] = node.entries().next().value;
529
+ if (key !== LEAF) {
530
+ merge(path.slice(0, -1), key, value);
531
+ }
532
+ }
533
+ };
534
+ const merge = (path, key, value) => {
535
+ if (path.length === 0) {
536
+ return;
537
+ }
538
+ const [node, nodeKey] = last(path);
539
+ node.set(nodeKey + key, value);
540
+ node.delete(nodeKey);
541
+ };
542
+ const last = (array) => {
543
+ return array[array.length - 1];
544
+ };
545
+
546
+ const OR = 'or';
547
+ const AND = 'and';
548
+ const AND_NOT = 'and_not';
549
+ /**
550
+ * {@link MiniSearch} is the main entrypoint class, implementing a full-text
551
+ * search engine in memory.
552
+ *
553
+ * @typeParam T The type of the documents being indexed.
554
+ *
555
+ * ### Basic example:
556
+ *
557
+ * ```javascript
558
+ * const documents = [
559
+ * {
560
+ * id: 1,
561
+ * title: 'Moby Dick',
562
+ * text: 'Call me Ishmael. Some years ago...',
563
+ * category: 'fiction'
564
+ * },
565
+ * {
566
+ * id: 2,
567
+ * title: 'Zen and the Art of Motorcycle Maintenance',
568
+ * text: 'I can see by my watch...',
569
+ * category: 'fiction'
570
+ * },
571
+ * {
572
+ * id: 3,
573
+ * title: 'Neuromancer',
574
+ * text: 'The sky above the port was...',
575
+ * category: 'fiction'
576
+ * },
577
+ * {
578
+ * id: 4,
579
+ * title: 'Zen and the Art of Archery',
580
+ * text: 'At first sight it must seem...',
581
+ * category: 'non-fiction'
582
+ * },
583
+ * // ...and more
584
+ * ]
585
+ *
586
+ * // Create a search engine that indexes the 'title' and 'text' fields for
587
+ * // full-text search. Search results will include 'title' and 'category' (plus the
588
+ * // id field, that is always stored and returned)
589
+ * const miniSearch = new MiniSearch({
590
+ * fields: ['title', 'text'],
591
+ * storeFields: ['title', 'category']
592
+ * })
593
+ *
594
+ * // Add documents to the index
595
+ * miniSearch.addAll(documents)
596
+ *
597
+ * // Search for documents:
598
+ * let results = miniSearch.search('zen art motorcycle')
599
+ * // => [
600
+ * // { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 },
601
+ * // { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 }
602
+ * // ]
603
+ * ```
604
+ */
605
+ class MiniSearch {
606
+ /**
607
+ * @param options Configuration options
608
+ *
609
+ * ### Examples:
610
+ *
611
+ * ```javascript
612
+ * // Create a search engine that indexes the 'title' and 'text' fields of your
613
+ * // documents:
614
+ * const miniSearch = new MiniSearch({ fields: ['title', 'text'] })
615
+ * ```
616
+ *
617
+ * ### ID Field:
618
+ *
619
+ * ```javascript
620
+ * // Your documents are assumed to include a unique 'id' field, but if you want
621
+ * // to use a different field for document identification, you can set the
622
+ * // 'idField' option:
623
+ * const miniSearch = new MiniSearch({ idField: 'key', fields: ['title', 'text'] })
624
+ * ```
625
+ *
626
+ * ### Options and defaults:
627
+ *
628
+ * ```javascript
629
+ * // The full set of options (here with their default value) is:
630
+ * const miniSearch = new MiniSearch({
631
+ * // idField: field that uniquely identifies a document
632
+ * idField: 'id',
633
+ *
634
+ * // extractField: function used to get the value of a field in a document.
635
+ * // By default, it assumes the document is a flat object with field names as
636
+ * // property keys and field values as string property values, but custom logic
637
+ * // can be implemented by setting this option to a custom extractor function.
638
+ * extractField: (document, fieldName) => document[fieldName],
639
+ *
640
+ * // tokenize: function used to split fields into individual terms. By
641
+ * // default, it is also used to tokenize search queries, unless a specific
642
+ * // `tokenize` search option is supplied. When tokenizing an indexed field,
643
+ * // the field name is passed as the second argument.
644
+ * tokenize: (string, _fieldName) => string.split(SPACE_OR_PUNCTUATION),
645
+ *
646
+ * // processTerm: function used to process each tokenized term before
647
+ * // indexing. It can be used for stemming and normalization. Return a falsy
648
+ * // value in order to discard a term. By default, it is also used to process
649
+ * // search queries, unless a specific `processTerm` option is supplied as a
650
+ * // search option. When processing a term from a indexed field, the field
651
+ * // name is passed as the second argument.
652
+ * processTerm: (term, _fieldName) => term.toLowerCase(),
653
+ *
654
+ * // searchOptions: default search options, see the `search` method for
655
+ * // details
656
+ * searchOptions: undefined,
657
+ *
658
+ * // fields: document fields to be indexed. Mandatory, but not set by default
659
+ * fields: undefined
660
+ *
661
+ * // storeFields: document fields to be stored and returned as part of the
662
+ * // search results.
663
+ * storeFields: []
664
+ * })
665
+ * ```
666
+ */
667
+ constructor(options) {
668
+ if ((options === null || options === void 0 ? void 0 : options.fields) == null) {
669
+ throw new Error('MiniSearch: option "fields" must be provided');
670
+ }
671
+ const autoVacuum = (options.autoVacuum == null || options.autoVacuum === true) ? defaultAutoVacuumOptions : options.autoVacuum;
672
+ this._options = {
673
+ ...defaultOptions,
674
+ ...options,
675
+ autoVacuum,
676
+ searchOptions: { ...defaultSearchOptions, ...(options.searchOptions || {}) },
677
+ autoSuggestOptions: { ...defaultAutoSuggestOptions, ...(options.autoSuggestOptions || {}) }
678
+ };
679
+ this._index = new SearchableMap();
680
+ this._documentCount = 0;
681
+ this._documentIds = new Map();
682
+ this._idToShortId = new Map();
683
+ // Fields are defined during initialization, don't change, are few in
684
+ // number, rarely need iterating over, and have string keys. Therefore in
685
+ // this case an object is a better candidate than a Map to store the mapping
686
+ // from field key to ID.
687
+ this._fieldIds = {};
688
+ this._fieldLength = new Map();
689
+ this._avgFieldLength = [];
690
+ this._nextId = 0;
691
+ this._storedFields = new Map();
692
+ this._dirtCount = 0;
693
+ this._currentVacuum = null;
694
+ this._enqueuedVacuum = null;
695
+ this._enqueuedVacuumConditions = defaultVacuumConditions;
696
+ this.addFields(this._options.fields);
697
+ }
698
+ /**
699
+ * Adds a document to the index
700
+ *
701
+ * @param document The document to be indexed
702
+ */
703
+ add(document) {
704
+ const { extractField, stringifyField, tokenize, processTerm, fields, idField } = this._options;
705
+ const id = extractField(document, idField);
706
+ if (id == null) {
707
+ throw new Error(`MiniSearch: document does not have ID field "${idField}"`);
708
+ }
709
+ if (this._idToShortId.has(id)) {
710
+ throw new Error(`MiniSearch: duplicate ID ${id}`);
711
+ }
712
+ const shortDocumentId = this.addDocumentId(id);
713
+ this.saveStoredFields(shortDocumentId, document);
714
+ for (const field of fields) {
715
+ const fieldValue = extractField(document, field);
716
+ if (fieldValue == null)
717
+ continue;
718
+ const tokens = tokenize(stringifyField(fieldValue, field), field);
719
+ const fieldId = this._fieldIds[field];
720
+ const uniqueTerms = new Set(tokens).size;
721
+ this.addFieldLength(shortDocumentId, fieldId, this._documentCount - 1, uniqueTerms);
722
+ for (const term of tokens) {
723
+ const processedTerm = processTerm(term, field);
724
+ if (Array.isArray(processedTerm)) {
725
+ for (const t of processedTerm) {
726
+ this.addTerm(fieldId, shortDocumentId, t);
727
+ }
728
+ }
729
+ else if (processedTerm) {
730
+ this.addTerm(fieldId, shortDocumentId, processedTerm);
731
+ }
732
+ }
733
+ }
734
+ }
735
+ /**
736
+ * Adds all the given documents to the index
737
+ *
738
+ * @param documents An array of documents to be indexed
739
+ */
740
+ addAll(documents) {
741
+ for (const document of documents)
742
+ this.add(document);
743
+ }
744
+ /**
745
+ * Adds all the given documents to the index asynchronously.
746
+ *
747
+ * Returns a promise that resolves (to `undefined`) when the indexing is done.
748
+ * This method is useful when index many documents, to avoid blocking the main
749
+ * thread. The indexing is performed asynchronously and in chunks.
750
+ *
751
+ * @param documents An array of documents to be indexed
752
+ * @param options Configuration options
753
+ * @return A promise resolving to `undefined` when the indexing is done
754
+ */
755
+ addAllAsync(documents, options = {}) {
756
+ const { chunkSize = 10 } = options;
757
+ const acc = { chunk: [], promise: Promise.resolve() };
758
+ const { chunk, promise } = documents.reduce(({ chunk, promise }, document, i) => {
759
+ chunk.push(document);
760
+ if ((i + 1) % chunkSize === 0) {
761
+ return {
762
+ chunk: [],
763
+ promise: promise
764
+ .then(() => new Promise(resolve => setTimeout(resolve, 0)))
765
+ .then(() => this.addAll(chunk))
766
+ };
767
+ }
768
+ else {
769
+ return { chunk, promise };
770
+ }
771
+ }, acc);
772
+ return promise.then(() => this.addAll(chunk));
773
+ }
774
+ /**
775
+ * Removes the given document from the index.
776
+ *
777
+ * The document to remove must NOT have changed between indexing and removal,
778
+ * otherwise the index will be corrupted.
779
+ *
780
+ * This method requires passing the full document to be removed (not just the
781
+ * ID), and immediately removes the document from the inverted index, allowing
782
+ * memory to be released. A convenient alternative is {@link
783
+ * MiniSearch#discard}, which needs only the document ID, and has the same
784
+ * visible effect, but delays cleaning up the index until the next vacuuming.
785
+ *
786
+ * @param document The document to be removed
787
+ */
788
+ remove(document) {
789
+ const { tokenize, processTerm, extractField, stringifyField, fields, idField } = this._options;
790
+ const id = extractField(document, idField);
791
+ if (id == null) {
792
+ throw new Error(`MiniSearch: document does not have ID field "${idField}"`);
793
+ }
794
+ const shortId = this._idToShortId.get(id);
795
+ if (shortId == null) {
796
+ throw new Error(`MiniSearch: cannot remove document with ID ${id}: it is not in the index`);
797
+ }
798
+ for (const field of fields) {
799
+ const fieldValue = extractField(document, field);
800
+ if (fieldValue == null)
801
+ continue;
802
+ const tokens = tokenize(stringifyField(fieldValue, field), field);
803
+ const fieldId = this._fieldIds[field];
804
+ const uniqueTerms = new Set(tokens).size;
805
+ this.removeFieldLength(shortId, fieldId, this._documentCount, uniqueTerms);
806
+ for (const term of tokens) {
807
+ const processedTerm = processTerm(term, field);
808
+ if (Array.isArray(processedTerm)) {
809
+ for (const t of processedTerm) {
810
+ this.removeTerm(fieldId, shortId, t);
811
+ }
812
+ }
813
+ else if (processedTerm) {
814
+ this.removeTerm(fieldId, shortId, processedTerm);
815
+ }
816
+ }
817
+ }
818
+ this._storedFields.delete(shortId);
819
+ this._documentIds.delete(shortId);
820
+ this._idToShortId.delete(id);
821
+ this._fieldLength.delete(shortId);
822
+ this._documentCount -= 1;
823
+ }
824
+ /**
825
+ * Removes all the given documents from the index. If called with no arguments,
826
+ * it removes _all_ documents from the index.
827
+ *
828
+ * @param documents The documents to be removed. If this argument is omitted,
829
+ * all documents are removed. Note that, for removing all documents, it is
830
+ * more efficient to call this method with no arguments than to pass all
831
+ * documents.
832
+ */
833
+ removeAll(documents) {
834
+ if (documents) {
835
+ for (const document of documents)
836
+ this.remove(document);
837
+ }
838
+ else if (arguments.length > 0) {
839
+ throw new Error('Expected documents to be present. Omit the argument to remove all documents.');
840
+ }
841
+ else {
842
+ this._index = new SearchableMap();
843
+ this._documentCount = 0;
844
+ this._documentIds = new Map();
845
+ this._idToShortId = new Map();
846
+ this._fieldLength = new Map();
847
+ this._avgFieldLength = [];
848
+ this._storedFields = new Map();
849
+ this._nextId = 0;
850
+ }
851
+ }
852
+ /**
853
+ * Discards the document with the given ID, so it won't appear in search results
854
+ *
855
+ * It has the same visible effect of {@link MiniSearch.remove} (both cause the
856
+ * document to stop appearing in searches), but a different effect on the
857
+ * internal data structures:
858
+ *
859
+ * - {@link MiniSearch#remove} requires passing the full document to be
860
+ * removed as argument, and removes it from the inverted index immediately.
861
+ *
862
+ * - {@link MiniSearch#discard} instead only needs the document ID, and
863
+ * works by marking the current version of the document as discarded, so it
864
+ * is immediately ignored by searches. This is faster and more convenient
865
+ * than {@link MiniSearch#remove}, but the index is not immediately
866
+ * modified. To take care of that, vacuuming is performed after a certain
867
+ * number of documents are discarded, cleaning up the index and allowing
868
+ * memory to be released.
869
+ *
870
+ * After discarding a document, it is possible to re-add a new version, and
871
+ * only the new version will appear in searches. In other words, discarding
872
+ * and re-adding a document works exactly like removing and re-adding it. The
873
+ * {@link MiniSearch.replace} method can also be used to replace a document
874
+ * with a new version.
875
+ *
876
+ * #### Details about vacuuming
877
+ *
878
+ * Repetite calls to this method would leave obsolete document references in
879
+ * the index, invisible to searches. Two mechanisms take care of cleaning up:
880
+ * clean up during search, and vacuuming.
881
+ *
882
+ * - Upon search, whenever a discarded ID is found (and ignored for the
883
+ * results), references to the discarded document are removed from the
884
+ * inverted index entries for the search terms. This ensures that subsequent
885
+ * searches for the same terms do not need to skip these obsolete references
886
+ * again.
887
+ *
888
+ * - In addition, vacuuming is performed automatically by default (see the
889
+ * `autoVacuum` field in {@link Options}) after a certain number of
890
+ * documents are discarded. Vacuuming traverses all terms in the index,
891
+ * cleaning up all references to discarded documents. Vacuuming can also be
892
+ * triggered manually by calling {@link MiniSearch#vacuum}.
893
+ *
894
+ * @param id The ID of the document to be discarded
895
+ */
896
+ discard(id) {
897
+ const shortId = this._idToShortId.get(id);
898
+ if (shortId == null) {
899
+ throw new Error(`MiniSearch: cannot discard document with ID ${id}: it is not in the index`);
900
+ }
901
+ this._idToShortId.delete(id);
902
+ this._documentIds.delete(shortId);
903
+ this._storedFields.delete(shortId);
904
+ (this._fieldLength.get(shortId) || []).forEach((fieldLength, fieldId) => {
905
+ this.removeFieldLength(shortId, fieldId, this._documentCount, fieldLength);
906
+ });
907
+ this._fieldLength.delete(shortId);
908
+ this._documentCount -= 1;
909
+ this._dirtCount += 1;
910
+ this.maybeAutoVacuum();
911
+ }
912
+ maybeAutoVacuum() {
913
+ if (this._options.autoVacuum === false) {
914
+ return;
915
+ }
916
+ const { minDirtFactor, minDirtCount, batchSize, batchWait } = this._options.autoVacuum;
917
+ this.conditionalVacuum({ batchSize, batchWait }, { minDirtCount, minDirtFactor });
918
+ }
919
+ /**
920
+ * Discards the documents with the given IDs, so they won't appear in search
921
+ * results
922
+ *
923
+ * It is equivalent to calling {@link MiniSearch#discard} for all the given
924
+ * IDs, but with the optimization of triggering at most one automatic
925
+ * vacuuming at the end.
926
+ *
927
+ * Note: to remove all documents from the index, it is faster and more
928
+ * convenient to call {@link MiniSearch.removeAll} with no argument, instead
929
+ * of passing all IDs to this method.
930
+ */
931
+ discardAll(ids) {
932
+ const autoVacuum = this._options.autoVacuum;
933
+ try {
934
+ this._options.autoVacuum = false;
935
+ for (const id of ids) {
936
+ this.discard(id);
937
+ }
938
+ }
939
+ finally {
940
+ this._options.autoVacuum = autoVacuum;
941
+ }
942
+ this.maybeAutoVacuum();
943
+ }
944
+ /**
945
+ * It replaces an existing document with the given updated version
946
+ *
947
+ * It works by discarding the current version and adding the updated one, so
948
+ * it is functionally equivalent to calling {@link MiniSearch#discard}
949
+ * followed by {@link MiniSearch#add}. The ID of the updated document should
950
+ * be the same as the original one.
951
+ *
952
+ * Since it uses {@link MiniSearch#discard} internally, this method relies on
953
+ * vacuuming to clean up obsolete document references from the index, allowing
954
+ * memory to be released (see {@link MiniSearch#discard}).
955
+ *
956
+ * @param updatedDocument The updated document to replace the old version
957
+ * with
958
+ */
959
+ replace(updatedDocument) {
960
+ const { idField, extractField } = this._options;
961
+ const id = extractField(updatedDocument, idField);
962
+ this.discard(id);
963
+ this.add(updatedDocument);
964
+ }
965
+ /**
966
+ * Triggers a manual vacuuming, cleaning up references to discarded documents
967
+ * from the inverted index
968
+ *
969
+ * Vacuuming is only useful for applications that use the {@link
970
+ * MiniSearch#discard} or {@link MiniSearch#replace} methods.
971
+ *
972
+ * By default, vacuuming is performed automatically when needed (controlled by
973
+ * the `autoVacuum` field in {@link Options}), so there is usually no need to
974
+ * call this method, unless one wants to make sure to perform vacuuming at a
975
+ * specific moment.
976
+ *
977
+ * Vacuuming traverses all terms in the inverted index in batches, and cleans
978
+ * up references to discarded documents from the posting list, allowing memory
979
+ * to be released.
980
+ *
981
+ * The method takes an optional object as argument with the following keys:
982
+ *
983
+ * - `batchSize`: the size of each batch (1000 by default)
984
+ *
985
+ * - `batchWait`: the number of milliseconds to wait between batches (10 by
986
+ * default)
987
+ *
988
+ * On large indexes, vacuuming could have a non-negligible cost: batching
989
+ * avoids blocking the thread for long, diluting this cost so that it is not
990
+ * negatively affecting the application. Nonetheless, this method should only
991
+ * be called when necessary, and relying on automatic vacuuming is usually
992
+ * better.
993
+ *
994
+ * It returns a promise that resolves (to undefined) when the clean up is
995
+ * completed. If vacuuming is already ongoing at the time this method is
996
+ * called, a new one is enqueued immediately after the ongoing one, and a
997
+ * corresponding promise is returned. However, no more than one vacuuming is
998
+ * enqueued on top of the ongoing one, even if this method is called more
999
+ * times (enqueuing multiple ones would be useless).
1000
+ *
1001
+ * @param options Configuration options for the batch size and delay. See
1002
+ * {@link VacuumOptions}.
1003
+ */
1004
+ vacuum(options = {}) {
1005
+ return this.conditionalVacuum(options);
1006
+ }
1007
+ conditionalVacuum(options, conditions) {
1008
+ // If a vacuum is already ongoing, schedule another as soon as it finishes,
1009
+ // unless there's already one enqueued. If one was already enqueued, do not
1010
+ // enqueue another on top, but make sure that the conditions are the
1011
+ // broadest.
1012
+ if (this._currentVacuum) {
1013
+ this._enqueuedVacuumConditions = this._enqueuedVacuumConditions && conditions;
1014
+ if (this._enqueuedVacuum != null) {
1015
+ return this._enqueuedVacuum;
1016
+ }
1017
+ this._enqueuedVacuum = this._currentVacuum.then(() => {
1018
+ const conditions = this._enqueuedVacuumConditions;
1019
+ this._enqueuedVacuumConditions = defaultVacuumConditions;
1020
+ return this.performVacuuming(options, conditions);
1021
+ });
1022
+ return this._enqueuedVacuum;
1023
+ }
1024
+ if (this.vacuumConditionsMet(conditions) === false) {
1025
+ return Promise.resolve();
1026
+ }
1027
+ this._currentVacuum = this.performVacuuming(options);
1028
+ return this._currentVacuum;
1029
+ }
1030
+ async performVacuuming(options, conditions) {
1031
+ const initialDirtCount = this._dirtCount;
1032
+ if (this.vacuumConditionsMet(conditions)) {
1033
+ const batchSize = options.batchSize || defaultVacuumOptions.batchSize;
1034
+ const batchWait = options.batchWait || defaultVacuumOptions.batchWait;
1035
+ let i = 1;
1036
+ for (const [term, fieldsData] of this._index) {
1037
+ for (const [fieldId, fieldIndex] of fieldsData) {
1038
+ for (const [shortId] of fieldIndex) {
1039
+ if (this._documentIds.has(shortId)) {
1040
+ continue;
1041
+ }
1042
+ if (fieldIndex.size <= 1) {
1043
+ fieldsData.delete(fieldId);
1044
+ }
1045
+ else {
1046
+ fieldIndex.delete(shortId);
1047
+ }
1048
+ }
1049
+ }
1050
+ if (this._index.get(term).size === 0) {
1051
+ this._index.delete(term);
1052
+ }
1053
+ if (i % batchSize === 0) {
1054
+ await new Promise((resolve) => setTimeout(resolve, batchWait));
1055
+ }
1056
+ i += 1;
1057
+ }
1058
+ this._dirtCount -= initialDirtCount;
1059
+ }
1060
+ // Make the next lines always async, so they execute after this function returns
1061
+ await null;
1062
+ this._currentVacuum = this._enqueuedVacuum;
1063
+ this._enqueuedVacuum = null;
1064
+ }
1065
+ vacuumConditionsMet(conditions) {
1066
+ if (conditions == null) {
1067
+ return true;
1068
+ }
1069
+ let { minDirtCount, minDirtFactor } = conditions;
1070
+ minDirtCount = minDirtCount || defaultAutoVacuumOptions.minDirtCount;
1071
+ minDirtFactor = minDirtFactor || defaultAutoVacuumOptions.minDirtFactor;
1072
+ return this.dirtCount >= minDirtCount && this.dirtFactor >= minDirtFactor;
1073
+ }
1074
+ /**
1075
+ * Is `true` if a vacuuming operation is ongoing, `false` otherwise
1076
+ */
1077
+ get isVacuuming() {
1078
+ return this._currentVacuum != null;
1079
+ }
1080
+ /**
1081
+ * The number of documents discarded since the most recent vacuuming
1082
+ */
1083
+ get dirtCount() {
1084
+ return this._dirtCount;
1085
+ }
1086
+ /**
1087
+ * A number between 0 and 1 giving an indication about the proportion of
1088
+ * documents that are discarded, and can therefore be cleaned up by vacuuming.
1089
+ * A value close to 0 means that the index is relatively clean, while a higher
1090
+ * value means that the index is relatively dirty, and vacuuming could release
1091
+ * memory.
1092
+ */
1093
+ get dirtFactor() {
1094
+ return this._dirtCount / (1 + this._documentCount + this._dirtCount);
1095
+ }
1096
+ /**
1097
+ * Returns `true` if a document with the given ID is present in the index and
1098
+ * available for search, `false` otherwise
1099
+ *
1100
+ * @param id The document ID
1101
+ */
1102
+ has(id) {
1103
+ return this._idToShortId.has(id);
1104
+ }
1105
+ /**
1106
+ * Returns the stored fields (as configured in the `storeFields` constructor
1107
+ * option) for the given document ID. Returns `undefined` if the document is
1108
+ * not present in the index.
1109
+ *
1110
+ * @param id The document ID
1111
+ */
1112
+ getStoredFields(id) {
1113
+ const shortId = this._idToShortId.get(id);
1114
+ if (shortId == null) {
1115
+ return undefined;
1116
+ }
1117
+ return this._storedFields.get(shortId);
1118
+ }
1119
+ /**
1120
+ * Search for documents matching the given search query.
1121
+ *
1122
+ * The result is a list of scored document IDs matching the query, sorted by
1123
+ * descending score, and each including data about which terms were matched and
1124
+ * in which fields.
1125
+ *
1126
+ * ### Basic usage:
1127
+ *
1128
+ * ```javascript
1129
+ * // Search for "zen art motorcycle" with default options: terms have to match
1130
+ * // exactly, and individual terms are joined with OR
1131
+ * miniSearch.search('zen art motorcycle')
1132
+ * // => [ { id: 2, score: 2.77258, match: { ... } }, { id: 4, score: 1.38629, match: { ... } } ]
1133
+ * ```
1134
+ *
1135
+ * ### Restrict search to specific fields:
1136
+ *
1137
+ * ```javascript
1138
+ * // Search only in the 'title' field
1139
+ * miniSearch.search('zen', { fields: ['title'] })
1140
+ * ```
1141
+ *
1142
+ * ### Field boosting:
1143
+ *
1144
+ * ```javascript
1145
+ * // Boost a field
1146
+ * miniSearch.search('zen', { boost: { title: 2 } })
1147
+ * ```
1148
+ *
1149
+ * ### Prefix search:
1150
+ *
1151
+ * ```javascript
1152
+ * // Search for "moto" with prefix search (it will match documents
1153
+ * // containing terms that start with "moto" or "neuro")
1154
+ * miniSearch.search('moto neuro', { prefix: true })
1155
+ * ```
1156
+ *
1157
+ * ### Fuzzy search:
1158
+ *
1159
+ * ```javascript
1160
+ * // Search for "ismael" with fuzzy search (it will match documents containing
1161
+ * // terms similar to "ismael", with a maximum edit distance of 0.2 term.length
1162
+ * // (rounded to nearest integer)
1163
+ * miniSearch.search('ismael', { fuzzy: 0.2 })
1164
+ * ```
1165
+ *
1166
+ * ### Combining strategies:
1167
+ *
1168
+ * ```javascript
1169
+ * // Mix of exact match, prefix search, and fuzzy search
1170
+ * miniSearch.search('ismael mob', {
1171
+ * prefix: true,
1172
+ * fuzzy: 0.2
1173
+ * })
1174
+ * ```
1175
+ *
1176
+ * ### Advanced prefix and fuzzy search:
1177
+ *
1178
+ * ```javascript
1179
+ * // Perform fuzzy and prefix search depending on the search term. Here
1180
+ * // performing prefix and fuzzy search only on terms longer than 3 characters
1181
+ * miniSearch.search('ismael mob', {
1182
+ * prefix: term => term.length > 3
1183
+ * fuzzy: term => term.length > 3 ? 0.2 : null
1184
+ * })
1185
+ * ```
1186
+ *
1187
+ * ### Combine with AND:
1188
+ *
1189
+ * ```javascript
1190
+ * // Combine search terms with AND (to match only documents that contain both
1191
+ * // "motorcycle" and "art")
1192
+ * miniSearch.search('motorcycle art', { combineWith: 'AND' })
1193
+ * ```
1194
+ *
1195
+ * ### Combine with AND_NOT:
1196
+ *
1197
+ * There is also an AND_NOT combinator, that finds documents that match the
1198
+ * first term, but do not match any of the other terms. This combinator is
1199
+ * rarely useful with simple queries, and is meant to be used with advanced
1200
+ * query combinations (see later for more details).
1201
+ *
1202
+ * ### Filtering results:
1203
+ *
1204
+ * ```javascript
1205
+ * // Filter only results in the 'fiction' category (assuming that 'category'
1206
+ * // is a stored field)
1207
+ * miniSearch.search('motorcycle art', {
1208
+ * filter: (result) => result.category === 'fiction'
1209
+ * })
1210
+ * ```
1211
+ *
1212
+ * ### Wildcard query
1213
+ *
1214
+ * Searching for an empty string (assuming the default tokenizer) returns no
1215
+ * results. Sometimes though, one needs to match all documents, like in a
1216
+ * "wildcard" search. This is possible by passing the special value
1217
+ * {@link MiniSearch.wildcard} as the query:
1218
+ *
1219
+ * ```javascript
1220
+ * // Return search results for all documents
1221
+ * miniSearch.search(MiniSearch.wildcard)
1222
+ * ```
1223
+ *
1224
+ * Note that search options such as `filter` and `boostDocument` are still
1225
+ * applied, influencing which results are returned, and their order:
1226
+ *
1227
+ * ```javascript
1228
+ * // Return search results for all documents in the 'fiction' category
1229
+ * miniSearch.search(MiniSearch.wildcard, {
1230
+ * filter: (result) => result.category === 'fiction'
1231
+ * })
1232
+ * ```
1233
+ *
1234
+ * ### Advanced combination of queries:
1235
+ *
1236
+ * It is possible to combine different subqueries with OR, AND, and AND_NOT,
1237
+ * and even with different search options, by passing a query expression
1238
+ * tree object as the first argument, instead of a string.
1239
+ *
1240
+ * ```javascript
1241
+ * // Search for documents that contain "zen" and ("motorcycle" or "archery")
1242
+ * miniSearch.search({
1243
+ * combineWith: 'AND',
1244
+ * queries: [
1245
+ * 'zen',
1246
+ * {
1247
+ * combineWith: 'OR',
1248
+ * queries: ['motorcycle', 'archery']
1249
+ * }
1250
+ * ]
1251
+ * })
1252
+ *
1253
+ * // Search for documents that contain ("apple" or "pear") but not "juice" and
1254
+ * // not "tree"
1255
+ * miniSearch.search({
1256
+ * combineWith: 'AND_NOT',
1257
+ * queries: [
1258
+ * {
1259
+ * combineWith: 'OR',
1260
+ * queries: ['apple', 'pear']
1261
+ * },
1262
+ * 'juice',
1263
+ * 'tree'
1264
+ * ]
1265
+ * })
1266
+ * ```
1267
+ *
1268
+ * Each node in the expression tree can be either a string, or an object that
1269
+ * supports all {@link SearchOptions} fields, plus a `queries` array field for
1270
+ * subqueries.
1271
+ *
1272
+ * Note that, while this can become complicated to do by hand for complex or
1273
+ * deeply nested queries, it provides a formalized expression tree API for
1274
+ * external libraries that implement a parser for custom query languages.
1275
+ *
1276
+ * @param query Search query
1277
+ * @param searchOptions Search options. Each option, if not given, defaults to the corresponding value of `searchOptions` given to the constructor, or to the library default.
1278
+ */
1279
+ search(query, searchOptions = {}) {
1280
+ const { searchOptions: globalSearchOptions } = this._options;
1281
+ const searchOptionsWithDefaults = { ...globalSearchOptions, ...searchOptions };
1282
+ const rawResults = this.executeQuery(query, searchOptions);
1283
+ const results = [];
1284
+ for (const [docId, { score, terms, match }] of rawResults) {
1285
+ // terms are the matched query terms, which will be returned to the user
1286
+ // as queryTerms. The quality is calculated based on them, as opposed to
1287
+ // the matched terms in the document (which can be different due to
1288
+ // prefix and fuzzy match)
1289
+ const quality = terms.length || 1;
1290
+ const result = {
1291
+ id: this._documentIds.get(docId),
1292
+ score: score * quality,
1293
+ terms: Object.keys(match),
1294
+ queryTerms: terms,
1295
+ match
1296
+ };
1297
+ Object.assign(result, this._storedFields.get(docId));
1298
+ if (searchOptionsWithDefaults.filter == null || searchOptionsWithDefaults.filter(result)) {
1299
+ results.push(result);
1300
+ }
1301
+ }
1302
+ // If it's a wildcard query, and no document boost is applied, skip sorting
1303
+ // the results, as all results have the same score of 1
1304
+ if (query === MiniSearch.wildcard && searchOptionsWithDefaults.boostDocument == null) {
1305
+ return results;
1306
+ }
1307
+ results.sort(byScore);
1308
+ return results;
1309
+ }
1310
+ /**
1311
+ * Provide suggestions for the given search query
1312
+ *
1313
+ * The result is a list of suggested modified search queries, derived from the
1314
+ * given search query, each with a relevance score, sorted by descending score.
1315
+ *
1316
+ * By default, it uses the same options used for search, except that by
1317
+ * default it performs prefix search on the last term of the query, and
1318
+ * combine terms with `'AND'` (requiring all query terms to match). Custom
1319
+ * options can be passed as a second argument. Defaults can be changed upon
1320
+ * calling the {@link MiniSearch} constructor, by passing a
1321
+ * `autoSuggestOptions` option.
1322
+ *
1323
+ * ### Basic usage:
1324
+ *
1325
+ * ```javascript
1326
+ * // Get suggestions for 'neuro':
1327
+ * miniSearch.autoSuggest('neuro')
1328
+ * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 0.46240 } ]
1329
+ * ```
1330
+ *
1331
+ * ### Multiple words:
1332
+ *
1333
+ * ```javascript
1334
+ * // Get suggestions for 'zen ar':
1335
+ * miniSearch.autoSuggest('zen ar')
1336
+ * // => [
1337
+ * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 },
1338
+ * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 }
1339
+ * // ]
1340
+ * ```
1341
+ *
1342
+ * ### Fuzzy suggestions:
1343
+ *
1344
+ * ```javascript
1345
+ * // Correct spelling mistakes using fuzzy search:
1346
+ * miniSearch.autoSuggest('neromancer', { fuzzy: 0.2 })
1347
+ * // => [ { suggestion: 'neuromancer', terms: [ 'neuromancer' ], score: 1.03998 } ]
1348
+ * ```
1349
+ *
1350
+ * ### Filtering:
1351
+ *
1352
+ * ```javascript
1353
+ * // Get suggestions for 'zen ar', but only within the 'fiction' category
1354
+ * // (assuming that 'category' is a stored field):
1355
+ * miniSearch.autoSuggest('zen ar', {
1356
+ * filter: (result) => result.category === 'fiction'
1357
+ * })
1358
+ * // => [
1359
+ * // { suggestion: 'zen archery art', terms: [ 'zen', 'archery', 'art' ], score: 1.73332 },
1360
+ * // { suggestion: 'zen art', terms: [ 'zen', 'art' ], score: 1.21313 }
1361
+ * // ]
1362
+ * ```
1363
+ *
1364
+ * @param queryString Query string to be expanded into suggestions
1365
+ * @param options Search options. The supported options and default values
1366
+ * are the same as for the {@link MiniSearch#search} method, except that by
1367
+ * default prefix search is performed on the last term in the query, and terms
1368
+ * are combined with `'AND'`.
1369
+ * @return A sorted array of suggestions sorted by relevance score.
1370
+ */
1371
+ autoSuggest(queryString, options = {}) {
1372
+ options = { ...this._options.autoSuggestOptions, ...options };
1373
+ const suggestions = new Map();
1374
+ for (const { score, terms } of this.search(queryString, options)) {
1375
+ const phrase = terms.join(' ');
1376
+ const suggestion = suggestions.get(phrase);
1377
+ if (suggestion != null) {
1378
+ suggestion.score += score;
1379
+ suggestion.count += 1;
1380
+ }
1381
+ else {
1382
+ suggestions.set(phrase, { score, terms, count: 1 });
1383
+ }
1384
+ }
1385
+ const results = [];
1386
+ for (const [suggestion, { score, terms, count }] of suggestions) {
1387
+ results.push({ suggestion, terms, score: score / count });
1388
+ }
1389
+ results.sort(byScore);
1390
+ return results;
1391
+ }
1392
+ /**
1393
+ * Total number of documents available to search
1394
+ */
1395
+ get documentCount() {
1396
+ return this._documentCount;
1397
+ }
1398
+ /**
1399
+ * Number of terms in the index
1400
+ */
1401
+ get termCount() {
1402
+ return this._index.size;
1403
+ }
1404
+ /**
1405
+ * Deserializes a JSON index (serialized with `JSON.stringify(miniSearch)`)
1406
+ * and instantiates a MiniSearch instance. It should be given the same options
1407
+ * originally used when serializing the index.
1408
+ *
1409
+ * ### Usage:
1410
+ *
1411
+ * ```javascript
1412
+ * // If the index was serialized with:
1413
+ * let miniSearch = new MiniSearch({ fields: ['title', 'text'] })
1414
+ * miniSearch.addAll(documents)
1415
+ *
1416
+ * const json = JSON.stringify(miniSearch)
1417
+ * // It can later be deserialized like this:
1418
+ * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] })
1419
+ * ```
1420
+ *
1421
+ * @param json JSON-serialized index
1422
+ * @param options configuration options, same as the constructor
1423
+ * @return An instance of MiniSearch deserialized from the given JSON.
1424
+ */
1425
+ static loadJSON(json, options) {
1426
+ if (options == null) {
1427
+ throw new Error('MiniSearch: loadJSON should be given the same options used when serializing the index');
1428
+ }
1429
+ return this.loadJS(JSON.parse(json), options);
1430
+ }
1431
+ /**
1432
+ * Async equivalent of {@link MiniSearch.loadJSON}
1433
+ *
1434
+ * This function is an alternative to {@link MiniSearch.loadJSON} that returns
1435
+ * a promise, and loads the index in batches, leaving pauses between them to avoid
1436
+ * blocking the main thread. It tends to be slower than the synchronous
1437
+ * version, but does not block the main thread, so it can be a better choice
1438
+ * when deserializing very large indexes.
1439
+ *
1440
+ * @param json JSON-serialized index
1441
+ * @param options configuration options, same as the constructor
1442
+ * @return A Promise that will resolve to an instance of MiniSearch deserialized from the given JSON.
1443
+ */
1444
+ static async loadJSONAsync(json, options) {
1445
+ if (options == null) {
1446
+ throw new Error('MiniSearch: loadJSON should be given the same options used when serializing the index');
1447
+ }
1448
+ return this.loadJSAsync(JSON.parse(json), options);
1449
+ }
1450
+ /**
1451
+ * Returns the default value of an option. It will throw an error if no option
1452
+ * with the given name exists.
1453
+ *
1454
+ * @param optionName Name of the option
1455
+ * @return The default value of the given option
1456
+ *
1457
+ * ### Usage:
1458
+ *
1459
+ * ```javascript
1460
+ * // Get default tokenizer
1461
+ * MiniSearch.getDefault('tokenize')
1462
+ *
1463
+ * // Get default term processor
1464
+ * MiniSearch.getDefault('processTerm')
1465
+ *
1466
+ * // Unknown options will throw an error
1467
+ * MiniSearch.getDefault('notExisting')
1468
+ * // => throws 'MiniSearch: unknown option "notExisting"'
1469
+ * ```
1470
+ */
1471
+ static getDefault(optionName) {
1472
+ if (defaultOptions.hasOwnProperty(optionName)) {
1473
+ return getOwnProperty(defaultOptions, optionName);
1474
+ }
1475
+ else {
1476
+ throw new Error(`MiniSearch: unknown option "${optionName}"`);
1477
+ }
1478
+ }
1479
+ /**
1480
+ * @ignore
1481
+ */
1482
+ static loadJS(js, options) {
1483
+ const { index, documentIds, fieldLength, storedFields, serializationVersion } = js;
1484
+ const miniSearch = this.instantiateMiniSearch(js, options);
1485
+ miniSearch._documentIds = objectToNumericMap(documentIds);
1486
+ miniSearch._fieldLength = objectToNumericMap(fieldLength);
1487
+ miniSearch._storedFields = objectToNumericMap(storedFields);
1488
+ for (const [shortId, id] of miniSearch._documentIds) {
1489
+ miniSearch._idToShortId.set(id, shortId);
1490
+ }
1491
+ for (const [term, data] of index) {
1492
+ const dataMap = new Map();
1493
+ for (const fieldId of Object.keys(data)) {
1494
+ let indexEntry = data[fieldId];
1495
+ // Version 1 used to nest the index entry inside a field called ds
1496
+ if (serializationVersion === 1) {
1497
+ indexEntry = indexEntry.ds;
1498
+ }
1499
+ dataMap.set(parseInt(fieldId, 10), objectToNumericMap(indexEntry));
1500
+ }
1501
+ miniSearch._index.set(term, dataMap);
1502
+ }
1503
+ return miniSearch;
1504
+ }
1505
+ /**
1506
+ * @ignore
1507
+ */
1508
+ static async loadJSAsync(js, options) {
1509
+ const { index, documentIds, fieldLength, storedFields, serializationVersion } = js;
1510
+ const miniSearch = this.instantiateMiniSearch(js, options);
1511
+ miniSearch._documentIds = await objectToNumericMapAsync(documentIds);
1512
+ miniSearch._fieldLength = await objectToNumericMapAsync(fieldLength);
1513
+ miniSearch._storedFields = await objectToNumericMapAsync(storedFields);
1514
+ for (const [shortId, id] of miniSearch._documentIds) {
1515
+ miniSearch._idToShortId.set(id, shortId);
1516
+ }
1517
+ let count = 0;
1518
+ for (const [term, data] of index) {
1519
+ const dataMap = new Map();
1520
+ for (const fieldId of Object.keys(data)) {
1521
+ let indexEntry = data[fieldId];
1522
+ // Version 1 used to nest the index entry inside a field called ds
1523
+ if (serializationVersion === 1) {
1524
+ indexEntry = indexEntry.ds;
1525
+ }
1526
+ dataMap.set(parseInt(fieldId, 10), await objectToNumericMapAsync(indexEntry));
1527
+ }
1528
+ if (++count % 1000 === 0)
1529
+ await wait(0);
1530
+ miniSearch._index.set(term, dataMap);
1531
+ }
1532
+ return miniSearch;
1533
+ }
1534
+ /**
1535
+ * @ignore
1536
+ */
1537
+ static instantiateMiniSearch(js, options) {
1538
+ const { documentCount, nextId, fieldIds, averageFieldLength, dirtCount, serializationVersion } = js;
1539
+ if (serializationVersion !== 1 && serializationVersion !== 2) {
1540
+ throw new Error('MiniSearch: cannot deserialize an index created with an incompatible version');
1541
+ }
1542
+ const miniSearch = new MiniSearch(options);
1543
+ miniSearch._documentCount = documentCount;
1544
+ miniSearch._nextId = nextId;
1545
+ miniSearch._idToShortId = new Map();
1546
+ miniSearch._fieldIds = fieldIds;
1547
+ miniSearch._avgFieldLength = averageFieldLength;
1548
+ miniSearch._dirtCount = dirtCount || 0;
1549
+ miniSearch._index = new SearchableMap();
1550
+ return miniSearch;
1551
+ }
1552
+ /**
1553
+ * @ignore
1554
+ */
1555
+ executeQuery(query, searchOptions = {}) {
1556
+ if (query === MiniSearch.wildcard) {
1557
+ return this.executeWildcardQuery(searchOptions);
1558
+ }
1559
+ if (typeof query !== 'string') {
1560
+ const options = { ...searchOptions, ...query, queries: undefined };
1561
+ const results = query.queries.map((subquery) => this.executeQuery(subquery, options));
1562
+ return this.combineResults(results, options.combineWith);
1563
+ }
1564
+ const { tokenize, processTerm, searchOptions: globalSearchOptions } = this._options;
1565
+ const options = { tokenize, processTerm, ...globalSearchOptions, ...searchOptions };
1566
+ const { tokenize: searchTokenize, processTerm: searchProcessTerm } = options;
1567
+ const terms = searchTokenize(query)
1568
+ .flatMap((term) => searchProcessTerm(term))
1569
+ .filter((term) => !!term);
1570
+ const queries = terms.map(termToQuerySpec(options));
1571
+ const results = queries.map(query => this.executeQuerySpec(query, options));
1572
+ return this.combineResults(results, options.combineWith);
1573
+ }
1574
+ /**
1575
+ * @ignore
1576
+ */
1577
+ executeQuerySpec(query, searchOptions) {
1578
+ const options = { ...this._options.searchOptions, ...searchOptions };
1579
+ const boosts = (options.fields || this._options.fields).reduce((boosts, field) => ({ ...boosts, [field]: getOwnProperty(options.boost, field) || 1 }), {});
1580
+ const { boostDocument, weights, maxFuzzy, bm25: bm25params } = options;
1581
+ const { fuzzy: fuzzyWeight, prefix: prefixWeight } = { ...defaultSearchOptions.weights, ...weights };
1582
+ const data = this._index.get(query.term);
1583
+ const results = this.termResults(query.term, query.term, 1, query.termBoost, data, boosts, boostDocument, bm25params);
1584
+ let prefixMatches;
1585
+ let fuzzyMatches;
1586
+ if (query.prefix) {
1587
+ prefixMatches = this._index.atPrefix(query.term);
1588
+ }
1589
+ if (query.fuzzy) {
1590
+ const fuzzy = (query.fuzzy === true) ? 0.2 : query.fuzzy;
1591
+ const maxDistance = fuzzy < 1 ? Math.min(maxFuzzy, Math.round(query.term.length * fuzzy)) : fuzzy;
1592
+ if (maxDistance)
1593
+ fuzzyMatches = this._index.fuzzyGet(query.term, maxDistance);
1594
+ }
1595
+ if (prefixMatches) {
1596
+ for (const [term, data] of prefixMatches) {
1597
+ const distance = term.length - query.term.length;
1598
+ if (!distance) {
1599
+ continue;
1600
+ } // Skip exact match.
1601
+ // Delete the term from fuzzy results (if present) if it is also a
1602
+ // prefix result. This entry will always be scored as a prefix result.
1603
+ fuzzyMatches === null || fuzzyMatches === void 0 ? void 0 : fuzzyMatches.delete(term);
1604
+ // Weight gradually approaches 0 as distance goes to infinity, with the
1605
+ // weight for the hypothetical distance 0 being equal to prefixWeight.
1606
+ // The rate of change is much lower than that of fuzzy matches to
1607
+ // account for the fact that prefix matches stay more relevant than
1608
+ // fuzzy matches for longer distances.
1609
+ const weight = prefixWeight * term.length / (term.length + 0.3 * distance);
1610
+ this.termResults(query.term, term, weight, query.termBoost, data, boosts, boostDocument, bm25params, results);
1611
+ }
1612
+ }
1613
+ if (fuzzyMatches) {
1614
+ for (const term of fuzzyMatches.keys()) {
1615
+ const [data, distance] = fuzzyMatches.get(term);
1616
+ if (!distance) {
1617
+ continue;
1618
+ } // Skip exact match.
1619
+ // Weight gradually approaches 0 as distance goes to infinity, with the
1620
+ // weight for the hypothetical distance 0 being equal to fuzzyWeight.
1621
+ const weight = fuzzyWeight * term.length / (term.length + distance);
1622
+ this.termResults(query.term, term, weight, query.termBoost, data, boosts, boostDocument, bm25params, results);
1623
+ }
1624
+ }
1625
+ return results;
1626
+ }
1627
+ /**
1628
+ * @ignore
1629
+ */
1630
+ executeWildcardQuery(searchOptions) {
1631
+ const results = new Map();
1632
+ const options = { ...this._options.searchOptions, ...searchOptions };
1633
+ for (const [shortId, id] of this._documentIds) {
1634
+ const score = options.boostDocument ? options.boostDocument(id, '', this._storedFields.get(shortId)) : 1;
1635
+ results.set(shortId, {
1636
+ score,
1637
+ terms: [],
1638
+ match: {}
1639
+ });
1640
+ }
1641
+ return results;
1642
+ }
1643
+ /**
1644
+ * @ignore
1645
+ */
1646
+ combineResults(results, combineWith = OR) {
1647
+ if (results.length === 0) {
1648
+ return new Map();
1649
+ }
1650
+ const operator = combineWith.toLowerCase();
1651
+ const combinator = combinators[operator];
1652
+ if (!combinator) {
1653
+ throw new Error(`Invalid combination operator: ${combineWith}`);
1654
+ }
1655
+ return results.reduce(combinator) || new Map();
1656
+ }
1657
+ /**
1658
+ * Allows serialization of the index to JSON, to possibly store it and later
1659
+ * deserialize it with {@link MiniSearch.loadJSON}.
1660
+ *
1661
+ * Normally one does not directly call this method, but rather call the
1662
+ * standard JavaScript `JSON.stringify()` passing the {@link MiniSearch}
1663
+ * instance, and JavaScript will internally call this method. Upon
1664
+ * deserialization, one must pass to {@link MiniSearch.loadJSON} the same
1665
+ * options used to create the original instance that was serialized.
1666
+ *
1667
+ * ### Usage:
1668
+ *
1669
+ * ```javascript
1670
+ * // Serialize the index:
1671
+ * let miniSearch = new MiniSearch({ fields: ['title', 'text'] })
1672
+ * miniSearch.addAll(documents)
1673
+ * const json = JSON.stringify(miniSearch)
1674
+ *
1675
+ * // Later, to deserialize it:
1676
+ * miniSearch = MiniSearch.loadJSON(json, { fields: ['title', 'text'] })
1677
+ * ```
1678
+ *
1679
+ * @return A plain-object serializable representation of the search index.
1680
+ */
1681
+ toJSON() {
1682
+ const index = [];
1683
+ for (const [term, fieldIndex] of this._index) {
1684
+ const data = {};
1685
+ for (const [fieldId, freqs] of fieldIndex) {
1686
+ data[fieldId] = Object.fromEntries(freqs);
1687
+ }
1688
+ index.push([term, data]);
1689
+ }
1690
+ return {
1691
+ documentCount: this._documentCount,
1692
+ nextId: this._nextId,
1693
+ documentIds: Object.fromEntries(this._documentIds),
1694
+ fieldIds: this._fieldIds,
1695
+ fieldLength: Object.fromEntries(this._fieldLength),
1696
+ averageFieldLength: this._avgFieldLength,
1697
+ storedFields: Object.fromEntries(this._storedFields),
1698
+ dirtCount: this._dirtCount,
1699
+ index,
1700
+ serializationVersion: 2
1701
+ };
1702
+ }
1703
+ /**
1704
+ * @ignore
1705
+ */
1706
+ termResults(sourceTerm, derivedTerm, termWeight, termBoost, fieldTermData, fieldBoosts, boostDocumentFn, bm25params, results = new Map()) {
1707
+ if (fieldTermData == null)
1708
+ return results;
1709
+ for (const field of Object.keys(fieldBoosts)) {
1710
+ const fieldBoost = fieldBoosts[field];
1711
+ const fieldId = this._fieldIds[field];
1712
+ const fieldTermFreqs = fieldTermData.get(fieldId);
1713
+ if (fieldTermFreqs == null)
1714
+ continue;
1715
+ let matchingFields = fieldTermFreqs.size;
1716
+ const avgFieldLength = this._avgFieldLength[fieldId];
1717
+ for (const docId of fieldTermFreqs.keys()) {
1718
+ if (!this._documentIds.has(docId)) {
1719
+ this.removeTerm(fieldId, docId, derivedTerm);
1720
+ matchingFields -= 1;
1721
+ continue;
1722
+ }
1723
+ const docBoost = boostDocumentFn ? boostDocumentFn(this._documentIds.get(docId), derivedTerm, this._storedFields.get(docId)) : 1;
1724
+ if (!docBoost)
1725
+ continue;
1726
+ const termFreq = fieldTermFreqs.get(docId);
1727
+ const fieldLength = this._fieldLength.get(docId)[fieldId];
1728
+ // NOTE: The total number of fields is set to the number of documents
1729
+ // `this._documentCount`. It could also make sense to use the number of
1730
+ // documents where the current field is non-blank as a normalization
1731
+ // factor. This will make a difference in scoring if the field is rarely
1732
+ // present. This is currently not supported, and may require further
1733
+ // analysis to see if it is a valid use case.
1734
+ const rawScore = calcBM25Score(termFreq, matchingFields, this._documentCount, fieldLength, avgFieldLength, bm25params);
1735
+ const weightedScore = termWeight * termBoost * fieldBoost * docBoost * rawScore;
1736
+ const result = results.get(docId);
1737
+ if (result) {
1738
+ result.score += weightedScore;
1739
+ assignUniqueTerm(result.terms, sourceTerm);
1740
+ const match = getOwnProperty(result.match, derivedTerm);
1741
+ if (match) {
1742
+ match.push(field);
1743
+ }
1744
+ else {
1745
+ result.match[derivedTerm] = [field];
1746
+ }
1747
+ }
1748
+ else {
1749
+ results.set(docId, {
1750
+ score: weightedScore,
1751
+ terms: [sourceTerm],
1752
+ match: { [derivedTerm]: [field] }
1753
+ });
1754
+ }
1755
+ }
1756
+ }
1757
+ return results;
1758
+ }
1759
+ /**
1760
+ * @ignore
1761
+ */
1762
+ addTerm(fieldId, documentId, term) {
1763
+ const indexData = this._index.fetch(term, createMap);
1764
+ let fieldIndex = indexData.get(fieldId);
1765
+ if (fieldIndex == null) {
1766
+ fieldIndex = new Map();
1767
+ fieldIndex.set(documentId, 1);
1768
+ indexData.set(fieldId, fieldIndex);
1769
+ }
1770
+ else {
1771
+ const docs = fieldIndex.get(documentId);
1772
+ fieldIndex.set(documentId, (docs || 0) + 1);
1773
+ }
1774
+ }
1775
+ /**
1776
+ * @ignore
1777
+ */
1778
+ removeTerm(fieldId, documentId, term) {
1779
+ if (!this._index.has(term)) {
1780
+ this.warnDocumentChanged(documentId, fieldId, term);
1781
+ return;
1782
+ }
1783
+ const indexData = this._index.fetch(term, createMap);
1784
+ const fieldIndex = indexData.get(fieldId);
1785
+ if (fieldIndex == null || fieldIndex.get(documentId) == null) {
1786
+ this.warnDocumentChanged(documentId, fieldId, term);
1787
+ }
1788
+ else if (fieldIndex.get(documentId) <= 1) {
1789
+ if (fieldIndex.size <= 1) {
1790
+ indexData.delete(fieldId);
1791
+ }
1792
+ else {
1793
+ fieldIndex.delete(documentId);
1794
+ }
1795
+ }
1796
+ else {
1797
+ fieldIndex.set(documentId, fieldIndex.get(documentId) - 1);
1798
+ }
1799
+ if (this._index.get(term).size === 0) {
1800
+ this._index.delete(term);
1801
+ }
1802
+ }
1803
+ /**
1804
+ * @ignore
1805
+ */
1806
+ warnDocumentChanged(shortDocumentId, fieldId, term) {
1807
+ for (const fieldName of Object.keys(this._fieldIds)) {
1808
+ if (this._fieldIds[fieldName] === fieldId) {
1809
+ this._options.logger('warn', `MiniSearch: document with ID ${this._documentIds.get(shortDocumentId)} has changed before removal: term "${term}" was not present in field "${fieldName}". Removing a document after it has changed can corrupt the index!`, 'version_conflict');
1810
+ return;
1811
+ }
1812
+ }
1813
+ }
1814
+ /**
1815
+ * @ignore
1816
+ */
1817
+ addDocumentId(documentId) {
1818
+ const shortDocumentId = this._nextId;
1819
+ this._idToShortId.set(documentId, shortDocumentId);
1820
+ this._documentIds.set(shortDocumentId, documentId);
1821
+ this._documentCount += 1;
1822
+ this._nextId += 1;
1823
+ return shortDocumentId;
1824
+ }
1825
+ /**
1826
+ * @ignore
1827
+ */
1828
+ addFields(fields) {
1829
+ for (let i = 0; i < fields.length; i++) {
1830
+ this._fieldIds[fields[i]] = i;
1831
+ }
1832
+ }
1833
+ /**
1834
+ * @ignore
1835
+ */
1836
+ addFieldLength(documentId, fieldId, count, length) {
1837
+ let fieldLengths = this._fieldLength.get(documentId);
1838
+ if (fieldLengths == null)
1839
+ this._fieldLength.set(documentId, fieldLengths = []);
1840
+ fieldLengths[fieldId] = length;
1841
+ const averageFieldLength = this._avgFieldLength[fieldId] || 0;
1842
+ const totalFieldLength = (averageFieldLength * count) + length;
1843
+ this._avgFieldLength[fieldId] = totalFieldLength / (count + 1);
1844
+ }
1845
+ /**
1846
+ * @ignore
1847
+ */
1848
+ removeFieldLength(documentId, fieldId, count, length) {
1849
+ if (count === 1) {
1850
+ this._avgFieldLength[fieldId] = 0;
1851
+ return;
1852
+ }
1853
+ const totalFieldLength = (this._avgFieldLength[fieldId] * count) - length;
1854
+ this._avgFieldLength[fieldId] = totalFieldLength / (count - 1);
1855
+ }
1856
+ /**
1857
+ * @ignore
1858
+ */
1859
+ saveStoredFields(documentId, doc) {
1860
+ const { storeFields, extractField } = this._options;
1861
+ if (storeFields == null || storeFields.length === 0) {
1862
+ return;
1863
+ }
1864
+ let documentFields = this._storedFields.get(documentId);
1865
+ if (documentFields == null)
1866
+ this._storedFields.set(documentId, documentFields = {});
1867
+ for (const fieldName of storeFields) {
1868
+ const fieldValue = extractField(doc, fieldName);
1869
+ if (fieldValue !== undefined)
1870
+ documentFields[fieldName] = fieldValue;
1871
+ }
1872
+ }
1873
+ }
1874
+ /**
1875
+ * The special wildcard symbol that can be passed to {@link MiniSearch#search}
1876
+ * to match all documents
1877
+ */
1878
+ MiniSearch.wildcard = Symbol('*');
1879
+ const getOwnProperty = (object, property) => Object.prototype.hasOwnProperty.call(object, property) ? object[property] : undefined;
1880
+ const combinators = {
1881
+ [OR]: (a, b) => {
1882
+ for (const docId of b.keys()) {
1883
+ const existing = a.get(docId);
1884
+ if (existing == null) {
1885
+ a.set(docId, b.get(docId));
1886
+ }
1887
+ else {
1888
+ const { score, terms, match } = b.get(docId);
1889
+ existing.score = existing.score + score;
1890
+ existing.match = Object.assign(existing.match, match);
1891
+ assignUniqueTerms(existing.terms, terms);
1892
+ }
1893
+ }
1894
+ return a;
1895
+ },
1896
+ [AND]: (a, b) => {
1897
+ const combined = new Map();
1898
+ for (const docId of b.keys()) {
1899
+ const existing = a.get(docId);
1900
+ if (existing == null)
1901
+ continue;
1902
+ const { score, terms, match } = b.get(docId);
1903
+ assignUniqueTerms(existing.terms, terms);
1904
+ combined.set(docId, {
1905
+ score: existing.score + score,
1906
+ terms: existing.terms,
1907
+ match: Object.assign(existing.match, match)
1908
+ });
1909
+ }
1910
+ return combined;
1911
+ },
1912
+ [AND_NOT]: (a, b) => {
1913
+ for (const docId of b.keys())
1914
+ a.delete(docId);
1915
+ return a;
1916
+ }
1917
+ };
1918
+ const defaultBM25params = { k: 1.2, b: 0.7, d: 0.5 };
1919
+ const calcBM25Score = (termFreq, matchingCount, totalCount, fieldLength, avgFieldLength, bm25params) => {
1920
+ const { k, b, d } = bm25params;
1921
+ const invDocFreq = Math.log(1 + (totalCount - matchingCount + 0.5) / (matchingCount + 0.5));
1922
+ return invDocFreq * (d + termFreq * (k + 1) / (termFreq + k * (1 - b + b * fieldLength / avgFieldLength)));
1923
+ };
1924
+ const termToQuerySpec = (options) => (term, i, terms) => {
1925
+ const fuzzy = (typeof options.fuzzy === 'function')
1926
+ ? options.fuzzy(term, i, terms)
1927
+ : (options.fuzzy || false);
1928
+ const prefix = (typeof options.prefix === 'function')
1929
+ ? options.prefix(term, i, terms)
1930
+ : (options.prefix === true);
1931
+ const termBoost = (typeof options.boostTerm === 'function')
1932
+ ? options.boostTerm(term, i, terms)
1933
+ : 1;
1934
+ return { term, fuzzy, prefix, termBoost };
1935
+ };
1936
+ const defaultOptions = {
1937
+ idField: 'id',
1938
+ extractField: (document, fieldName) => document[fieldName],
1939
+ stringifyField: (fieldValue, fieldName) => fieldValue.toString(),
1940
+ tokenize: (text) => text.split(SPACE_OR_PUNCTUATION),
1941
+ processTerm: (term) => term.toLowerCase(),
1942
+ fields: undefined,
1943
+ searchOptions: undefined,
1944
+ storeFields: [],
1945
+ logger: (level, message) => {
1946
+ if (typeof (console === null || console === void 0 ? void 0 : console[level]) === 'function')
1947
+ console[level](message);
1948
+ },
1949
+ autoVacuum: true
1950
+ };
1951
+ const defaultSearchOptions = {
1952
+ combineWith: OR,
1953
+ prefix: false,
1954
+ fuzzy: false,
1955
+ maxFuzzy: 6,
1956
+ boost: {},
1957
+ weights: { fuzzy: 0.45, prefix: 0.375 },
1958
+ bm25: defaultBM25params
1959
+ };
1960
+ const defaultAutoSuggestOptions = {
1961
+ combineWith: AND,
1962
+ prefix: (term, i, terms) => i === terms.length - 1
1963
+ };
1964
+ const defaultVacuumOptions = { batchSize: 1000, batchWait: 10 };
1965
+ const defaultVacuumConditions = { minDirtFactor: 0.1, minDirtCount: 20 };
1966
+ const defaultAutoVacuumOptions = { ...defaultVacuumOptions, ...defaultVacuumConditions };
1967
+ const assignUniqueTerm = (target, term) => {
1968
+ // Avoid adding duplicate terms.
1969
+ if (!target.includes(term))
1970
+ target.push(term);
1971
+ };
1972
+ const assignUniqueTerms = (target, source) => {
1973
+ for (const term of source) {
1974
+ // Avoid adding duplicate terms.
1975
+ if (!target.includes(term))
1976
+ target.push(term);
1977
+ }
1978
+ };
1979
+ const byScore = ({ score: a }, { score: b }) => b - a;
1980
+ const createMap = () => new Map();
1981
+ const objectToNumericMap = (object) => {
1982
+ const map = new Map();
1983
+ for (const key of Object.keys(object)) {
1984
+ map.set(parseInt(key, 10), object[key]);
1985
+ }
1986
+ return map;
1987
+ };
1988
+ const objectToNumericMapAsync = async (object) => {
1989
+ const map = new Map();
1990
+ let count = 0;
1991
+ for (const key of Object.keys(object)) {
1992
+ map.set(parseInt(key, 10), object[key]);
1993
+ if (++count % 1000 === 0) {
1994
+ await wait(0);
1995
+ }
1996
+ }
1997
+ return map;
1998
+ };
1999
+ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2000
+ // This regular expression matches any Unicode space, newline, or punctuation
2001
+ // character
2002
+ const SPACE_OR_PUNCTUATION = /[\n\r\p{Z}\p{P}]+/u;
2003
+
2004
+ export { MiniSearch as default };
2005
+ //# sourceMappingURL=index.js.map