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