node-llama-cpp 3.0.0-beta.3 → 3.0.0-beta.30

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 (690) hide show
  1. package/README.md +14 -11
  2. package/bins/linux-arm64/_nlcBuildMetadata.json +1 -0
  3. package/bins/linux-arm64/llama-addon.node +0 -0
  4. package/bins/linux-armv7l/_nlcBuildMetadata.json +1 -0
  5. package/bins/linux-armv7l/llama-addon.node +0 -0
  6. package/bins/linux-x64/_nlcBuildMetadata.json +1 -0
  7. package/bins/linux-x64/llama-addon.node +0 -0
  8. package/bins/linux-x64-cuda/_nlcBuildMetadata.json +1 -0
  9. package/bins/linux-x64-cuda/llama-addon.node +0 -0
  10. package/bins/linux-x64-vulkan/_nlcBuildMetadata.json +1 -0
  11. package/bins/linux-x64-vulkan/llama-addon.node +0 -0
  12. package/bins/mac-arm64-metal/_nlcBuildMetadata.json +1 -0
  13. package/bins/mac-arm64-metal/default.metallib +0 -0
  14. package/bins/mac-arm64-metal/llama-addon.node +0 -0
  15. package/bins/mac-x64/_nlcBuildMetadata.json +1 -0
  16. package/bins/mac-x64/llama-addon.node +0 -0
  17. package/bins/win-arm64/_nlcBuildMetadata.json +1 -0
  18. package/bins/win-arm64/llama-addon.exp +0 -0
  19. package/bins/win-arm64/llama-addon.lib +0 -0
  20. package/bins/win-arm64/llama-addon.node +0 -0
  21. package/bins/win-x64/_nlcBuildMetadata.json +1 -0
  22. package/bins/win-x64/llama-addon.exp +0 -0
  23. package/bins/win-x64/llama-addon.lib +0 -0
  24. package/bins/win-x64/llama-addon.node +0 -0
  25. package/bins/win-x64-cuda/_nlcBuildMetadata.json +1 -0
  26. package/bins/win-x64-cuda/llama-addon.exp +0 -0
  27. package/bins/win-x64-cuda/llama-addon.lib +0 -0
  28. package/bins/win-x64-cuda/llama-addon.node +0 -0
  29. package/bins/win-x64-vulkan/_nlcBuildMetadata.json +1 -0
  30. package/bins/win-x64-vulkan/llama-addon.exp +0 -0
  31. package/bins/win-x64-vulkan/llama-addon.lib +0 -0
  32. package/bins/win-x64-vulkan/llama-addon.node +0 -0
  33. package/dist/ChatWrapper.d.ts +8 -39
  34. package/dist/ChatWrapper.js +115 -72
  35. package/dist/ChatWrapper.js.map +1 -1
  36. package/dist/apiDocsIndex.d.ts +1 -0
  37. package/dist/apiDocsIndex.js +7 -0
  38. package/dist/apiDocsIndex.js.map +1 -0
  39. package/dist/{utils/getBin.d.ts → bindings/AddonTypes.d.ts} +54 -8
  40. package/dist/bindings/AddonTypes.js +2 -0
  41. package/dist/bindings/AddonTypes.js.map +1 -0
  42. package/dist/bindings/Llama.d.ts +47 -0
  43. package/dist/bindings/Llama.js +353 -0
  44. package/dist/bindings/Llama.js.map +1 -0
  45. package/dist/bindings/consts.d.ts +2 -0
  46. package/dist/bindings/consts.js +11 -0
  47. package/dist/bindings/consts.js.map +1 -0
  48. package/dist/bindings/getLlama.d.ts +148 -0
  49. package/dist/bindings/getLlama.js +401 -0
  50. package/dist/bindings/getLlama.js.map +1 -0
  51. package/dist/bindings/types.d.ts +56 -0
  52. package/dist/bindings/types.js +77 -0
  53. package/dist/bindings/types.js.map +1 -0
  54. package/dist/bindings/utils/MemoryOrchestrator.d.ts +21 -0
  55. package/dist/bindings/utils/MemoryOrchestrator.js +49 -0
  56. package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
  57. package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
  58. package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
  59. package/dist/bindings/utils/NoBinaryFoundError.js.map +1 -0
  60. package/dist/bindings/utils/asyncEvery.d.ts +5 -0
  61. package/dist/bindings/utils/asyncEvery.js +15 -0
  62. package/dist/bindings/utils/asyncEvery.js.map +1 -0
  63. package/dist/bindings/utils/asyncSome.d.ts +5 -0
  64. package/dist/bindings/utils/asyncSome.js +27 -0
  65. package/dist/bindings/utils/asyncSome.js.map +1 -0
  66. package/dist/{utils → bindings/utils}/binariesGithubRelease.js +1 -1
  67. package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
  68. package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
  69. package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
  70. package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
  71. package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
  72. package/dist/bindings/utils/cloneLlamaCppRepo.js +166 -0
  73. package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
  74. package/dist/bindings/utils/compileLLamaCpp.d.ts +17 -0
  75. package/dist/bindings/utils/compileLLamaCpp.js +226 -0
  76. package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
  77. package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +14 -0
  78. package/dist/bindings/utils/detectAvailableComputeLayers.js +305 -0
  79. package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
  80. package/dist/bindings/utils/detectGlibc.d.ts +4 -0
  81. package/dist/bindings/utils/detectGlibc.js +46 -0
  82. package/dist/bindings/utils/detectGlibc.js.map +1 -0
  83. package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +10 -0
  84. package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
  85. package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
  86. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.d.ts +5 -0
  87. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +93 -0
  88. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
  89. package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
  90. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
  91. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
  92. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
  93. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
  94. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
  95. package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
  96. package/dist/bindings/utils/getGpuTypesToUseForOption.js +30 -0
  97. package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
  98. package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
  99. package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
  100. package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
  101. package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
  102. package/dist/bindings/utils/getLlamaWithoutBackend.js +27 -0
  103. package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
  104. package/dist/bindings/utils/getPlatform.d.ts +2 -0
  105. package/dist/bindings/utils/getPlatform.js +15 -0
  106. package/dist/bindings/utils/getPlatform.js.map +1 -0
  107. package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
  108. package/dist/bindings/utils/getPlatformInfo.js +28 -0
  109. package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
  110. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
  111. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
  112. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
  113. package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
  114. package/dist/bindings/utils/hasFileInPath.js +34 -0
  115. package/dist/bindings/utils/hasFileInPath.js.map +1 -0
  116. package/dist/bindings/utils/lastBuildInfo.d.ts +6 -0
  117. package/dist/bindings/utils/lastBuildInfo.js +17 -0
  118. package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
  119. package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
  120. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +22 -0
  121. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
  122. package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
  123. package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
  124. package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
  125. package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
  126. package/dist/bindings/utils/resolveCustomCmakeOptions.js +47 -0
  127. package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
  128. package/dist/bindings/utils/testBindingBinary.d.ts +1 -0
  129. package/dist/bindings/utils/testBindingBinary.js +100 -0
  130. package/dist/bindings/utils/testBindingBinary.js.map +1 -0
  131. package/dist/bindings/utils/testCmakeBinary.d.ts +6 -0
  132. package/dist/bindings/utils/testCmakeBinary.js +32 -0
  133. package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
  134. package/dist/chatWrappers/AlpacaChatWrapper.d.ts +2 -1
  135. package/dist/chatWrappers/AlpacaChatWrapper.js +9 -2
  136. package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -1
  137. package/dist/chatWrappers/ChatMLChatWrapper.d.ts +2 -9
  138. package/dist/chatWrappers/ChatMLChatWrapper.js +23 -21
  139. package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -1
  140. package/dist/chatWrappers/FalconChatWrapper.d.ts +4 -10
  141. package/dist/chatWrappers/FalconChatWrapper.js +38 -21
  142. package/dist/chatWrappers/FalconChatWrapper.js.map +1 -1
  143. package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +8 -32
  144. package/dist/chatWrappers/FunctionaryChatWrapper.js +323 -118
  145. package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
  146. package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
  147. package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
  148. package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
  149. package/dist/chatWrappers/GeneralChatWrapper.d.ts +4 -10
  150. package/dist/chatWrappers/GeneralChatWrapper.js +45 -22
  151. package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -1
  152. package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
  153. package/dist/chatWrappers/{LlamaChatWrapper.js → Llama2ChatWrapper.js} +38 -20
  154. package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
  155. package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
  156. package/dist/chatWrappers/Llama3ChatWrapper.js +174 -0
  157. package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
  158. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +67 -0
  159. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +371 -0
  160. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
  161. package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +54 -0
  162. package/dist/chatWrappers/generic/TemplateChatWrapper.js +200 -0
  163. package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
  164. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +23 -0
  165. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
  166. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
  167. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +42 -0
  168. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +82 -0
  169. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
  170. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
  171. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +210 -0
  172. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
  173. package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +69 -0
  174. package/dist/chatWrappers/utils/resolveChatWrapper.js +243 -0
  175. package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
  176. package/dist/cli/cli.js +21 -7
  177. package/dist/cli/cli.js.map +1 -1
  178. package/dist/cli/commands/BuildCommand.d.ts +11 -4
  179. package/dist/cli/commands/BuildCommand.js +114 -41
  180. package/dist/cli/commands/BuildCommand.js.map +1 -1
  181. package/dist/cli/commands/ChatCommand.d.ts +18 -6
  182. package/dist/cli/commands/ChatCommand.js +299 -143
  183. package/dist/cli/commands/ChatCommand.js.map +1 -1
  184. package/dist/cli/commands/ClearCommand.d.ts +1 -1
  185. package/dist/cli/commands/ClearCommand.js +11 -12
  186. package/dist/cli/commands/ClearCommand.js.map +1 -1
  187. package/dist/cli/commands/CompleteCommand.d.ts +29 -0
  188. package/dist/cli/commands/CompleteCommand.js +365 -0
  189. package/dist/cli/commands/CompleteCommand.js.map +1 -0
  190. package/dist/cli/commands/DebugCommand.d.ts +7 -0
  191. package/dist/cli/commands/DebugCommand.js +54 -0
  192. package/dist/cli/commands/DebugCommand.js.map +1 -0
  193. package/dist/cli/commands/DownloadCommand.d.ts +7 -4
  194. package/dist/cli/commands/DownloadCommand.js +121 -70
  195. package/dist/cli/commands/DownloadCommand.js.map +1 -1
  196. package/dist/cli/commands/InfillCommand.d.ts +31 -0
  197. package/dist/cli/commands/InfillCommand.js +401 -0
  198. package/dist/cli/commands/InfillCommand.js.map +1 -0
  199. package/dist/cli/commands/InitCommand.d.ts +11 -0
  200. package/dist/cli/commands/InitCommand.js +195 -0
  201. package/dist/cli/commands/InitCommand.js.map +1 -0
  202. package/dist/cli/commands/OnPostInstallCommand.js +9 -10
  203. package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
  204. package/dist/cli/commands/PullCommand.d.ts +12 -0
  205. package/dist/cli/commands/PullCommand.js +117 -0
  206. package/dist/cli/commands/PullCommand.js.map +1 -0
  207. package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
  208. package/dist/cli/commands/inspect/InspectCommand.js +19 -0
  209. package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
  210. package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +12 -0
  211. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +136 -0
  212. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
  213. package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
  214. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +164 -0
  215. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
  216. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +17 -0
  217. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +613 -0
  218. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
  219. package/dist/cli/projectTemplates.d.ts +7 -0
  220. package/dist/cli/projectTemplates.js +10 -0
  221. package/dist/cli/projectTemplates.js.map +1 -0
  222. package/dist/cli/recommendedModels.d.ts +2 -0
  223. package/dist/cli/recommendedModels.js +363 -0
  224. package/dist/cli/recommendedModels.js.map +1 -0
  225. package/dist/cli/startCreateCli.d.ts +2 -0
  226. package/dist/cli/startCreateCli.js +26 -0
  227. package/dist/cli/startCreateCli.js.map +1 -0
  228. package/dist/cli/utils/ConsoleInteraction.d.ts +23 -0
  229. package/dist/cli/utils/ConsoleInteraction.js +122 -0
  230. package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
  231. package/dist/cli/utils/ConsoleTable.d.ts +23 -0
  232. package/dist/cli/utils/ConsoleTable.js +86 -0
  233. package/dist/cli/utils/ConsoleTable.js.map +1 -0
  234. package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
  235. package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
  236. package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
  237. package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
  238. package/dist/cli/utils/consolePromptQuestion.js +82 -0
  239. package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
  240. package/dist/cli/utils/getReadablePath.d.ts +1 -0
  241. package/dist/cli/utils/getReadablePath.js +14 -0
  242. package/dist/cli/utils/getReadablePath.js.map +1 -0
  243. package/dist/cli/utils/interactivelyAskForModel.d.ts +7 -0
  244. package/dist/cli/utils/interactivelyAskForModel.js +451 -0
  245. package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
  246. package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
  247. package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
  248. package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
  249. package/dist/cli/utils/printCommonInfoLines.d.ts +9 -0
  250. package/dist/cli/utils/printCommonInfoLines.js +75 -0
  251. package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
  252. package/dist/cli/utils/printInfoLine.d.ts +12 -0
  253. package/dist/cli/utils/printInfoLine.js +54 -0
  254. package/dist/cli/utils/printInfoLine.js.map +1 -0
  255. package/dist/cli/utils/projectTemplates.d.ts +19 -0
  256. package/dist/cli/utils/projectTemplates.js +47 -0
  257. package/dist/cli/utils/projectTemplates.js.map +1 -0
  258. package/dist/cli/utils/resolveCommandGgufPath.d.ts +4 -0
  259. package/dist/cli/utils/resolveCommandGgufPath.js +71 -0
  260. package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
  261. package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
  262. package/dist/cli/utils/resolveHeaderFlag.js +21 -0
  263. package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
  264. package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +19 -0
  265. package/dist/cli/utils/resolveModelRecommendationFileOptions.js +7 -0
  266. package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
  267. package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
  268. package/dist/cli/utils/splitAnsiToLines.js +32 -0
  269. package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
  270. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
  271. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
  272. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
  273. package/dist/commands.d.ts +1 -0
  274. package/dist/commands.js +3 -0
  275. package/dist/commands.js.map +1 -1
  276. package/dist/config.d.ts +38 -5
  277. package/dist/config.js +61 -16
  278. package/dist/config.js.map +1 -1
  279. package/dist/consts.d.ts +3 -0
  280. package/dist/consts.js +10 -0
  281. package/dist/consts.js.map +1 -0
  282. package/dist/{llamaEvaluator → evaluator}/LlamaChat/LlamaChat.d.ts +112 -39
  283. package/dist/evaluator/LlamaChat/LlamaChat.js +1512 -0
  284. package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
  285. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
  286. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
  287. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
  288. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
  289. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
  290. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
  291. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
  292. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
  293. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
  294. package/dist/{llamaEvaluator → evaluator}/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +42 -16
  295. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
  296. package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +288 -0
  297. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +419 -0
  298. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
  299. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +39 -0
  300. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +186 -0
  301. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
  302. package/dist/{llamaEvaluator → evaluator}/LlamaChatSession/utils/defineChatSessionFunction.d.ts +3 -0
  303. package/dist/{llamaEvaluator → evaluator}/LlamaChatSession/utils/defineChatSessionFunction.js +3 -0
  304. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
  305. package/dist/evaluator/LlamaCompletion.d.ts +143 -0
  306. package/dist/evaluator/LlamaCompletion.js +418 -0
  307. package/dist/evaluator/LlamaCompletion.js.map +1 -0
  308. package/dist/{llamaEvaluator → evaluator}/LlamaContext/LlamaContext.d.ts +41 -21
  309. package/dist/{llamaEvaluator → evaluator}/LlamaContext/LlamaContext.js +270 -81
  310. package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
  311. package/dist/evaluator/LlamaContext/types.d.ts +140 -0
  312. package/dist/evaluator/LlamaContext/types.js.map +1 -0
  313. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
  314. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
  315. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
  316. package/dist/{llamaEvaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js → evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js} +4 -4
  317. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
  318. package/dist/evaluator/LlamaEmbeddingContext.d.ts +51 -0
  319. package/dist/evaluator/LlamaEmbeddingContext.js +73 -0
  320. package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
  321. package/dist/{llamaEvaluator → evaluator}/LlamaGrammar.d.ts +10 -7
  322. package/dist/{llamaEvaluator → evaluator}/LlamaGrammar.js +14 -11
  323. package/dist/evaluator/LlamaGrammar.js.map +1 -0
  324. package/dist/{llamaEvaluator → evaluator}/LlamaGrammarEvaluationState.js +4 -4
  325. package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
  326. package/dist/{llamaEvaluator → evaluator}/LlamaJsonSchemaGrammar.d.ts +2 -1
  327. package/dist/{llamaEvaluator → evaluator}/LlamaJsonSchemaGrammar.js +3 -3
  328. package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
  329. package/dist/evaluator/LlamaModel/LlamaModel.d.ts +236 -0
  330. package/dist/evaluator/LlamaModel/LlamaModel.js +679 -0
  331. package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
  332. package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
  333. package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
  334. package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
  335. package/dist/evaluator/TokenBias.d.ts +22 -0
  336. package/dist/evaluator/TokenBias.js +33 -0
  337. package/dist/evaluator/TokenBias.js.map +1 -0
  338. package/dist/evaluator/TokenMeter.d.ts +54 -0
  339. package/dist/evaluator/TokenMeter.js +86 -0
  340. package/dist/evaluator/TokenMeter.js.map +1 -0
  341. package/dist/gguf/consts.d.ts +3 -0
  342. package/dist/gguf/consts.js +8 -0
  343. package/dist/gguf/consts.js.map +1 -0
  344. package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
  345. package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
  346. package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
  347. package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
  348. package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
  349. package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
  350. package/dist/gguf/fileReaders/GgufFileReader.d.ts +33 -0
  351. package/dist/gguf/fileReaders/GgufFileReader.js +76 -0
  352. package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
  353. package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +17 -0
  354. package/dist/gguf/fileReaders/GgufFsFileReader.js +46 -0
  355. package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
  356. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +22 -0
  357. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +63 -0
  358. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
  359. package/dist/gguf/insights/GgufInsights.d.ts +48 -0
  360. package/dist/gguf/insights/GgufInsights.js +381 -0
  361. package/dist/gguf/insights/GgufInsights.js.map +1 -0
  362. package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +87 -0
  363. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +141 -0
  364. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
  365. package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +18 -0
  366. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +76 -0
  367. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
  368. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +14 -0
  369. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +177 -0
  370. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
  371. package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
  372. package/dist/gguf/insights/utils/scoreLevels.js +16 -0
  373. package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
  374. package/dist/gguf/parser/GgufV2Parser.d.ts +19 -0
  375. package/dist/gguf/parser/GgufV2Parser.js +115 -0
  376. package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
  377. package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
  378. package/dist/gguf/parser/GgufV3Parser.js +4 -0
  379. package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
  380. package/dist/gguf/parser/parseGguf.d.ts +8 -0
  381. package/dist/gguf/parser/parseGguf.js +63 -0
  382. package/dist/gguf/parser/parseGguf.js.map +1 -0
  383. package/dist/gguf/readGgufFileInfo.d.ts +33 -0
  384. package/dist/gguf/readGgufFileInfo.js +66 -0
  385. package/dist/gguf/readGgufFileInfo.js.map +1 -0
  386. package/dist/gguf/types/GgufFileInfoTypes.d.ts +84 -0
  387. package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
  388. package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
  389. package/dist/gguf/types/GgufMetadataTypes.d.ts +335 -0
  390. package/dist/gguf/types/GgufMetadataTypes.js +86 -0
  391. package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
  392. package/dist/gguf/types/GgufTensorInfoTypes.d.ts +37 -0
  393. package/dist/gguf/types/GgufTensorInfoTypes.js +33 -0
  394. package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
  395. package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
  396. package/dist/gguf/utils/GgufReadOffset.js +18 -0
  397. package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
  398. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +5 -0
  399. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +38 -0
  400. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
  401. package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
  402. package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
  403. package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
  404. package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
  405. package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
  406. package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
  407. package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +1 -0
  408. package/dist/gguf/utils/normalizeGgufDownloadUrl.js +16 -0
  409. package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
  410. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
  411. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +39 -0
  412. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
  413. package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
  414. package/dist/gguf/utils/resolveSplitGgufParts.js +55 -0
  415. package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
  416. package/dist/index.d.ts +41 -18
  417. package/dist/index.js +36 -15
  418. package/dist/index.js.map +1 -1
  419. package/dist/state.d.ts +4 -0
  420. package/dist/state.js +14 -0
  421. package/dist/state.js.map +1 -1
  422. package/dist/types.d.ts +116 -5
  423. package/dist/types.js.map +1 -1
  424. package/dist/utils/DisposeGuard.d.ts +13 -0
  425. package/dist/utils/DisposeGuard.js +120 -0
  426. package/dist/utils/DisposeGuard.js.map +1 -0
  427. package/dist/utils/InsufficientMemoryError.d.ts +3 -0
  428. package/dist/utils/InsufficientMemoryError.js +6 -0
  429. package/dist/utils/InsufficientMemoryError.js.map +1 -0
  430. package/dist/utils/LlamaText.d.ts +70 -26
  431. package/dist/utils/LlamaText.js +469 -157
  432. package/dist/utils/LlamaText.js.map +1 -1
  433. package/dist/utils/LruCache.d.ts +12 -0
  434. package/dist/utils/LruCache.js +44 -0
  435. package/dist/utils/LruCache.js.map +1 -0
  436. package/dist/utils/ReplHistory.js.map +1 -1
  437. package/dist/utils/StopGenerationDetector.d.ts +25 -9
  438. package/dist/utils/StopGenerationDetector.js +93 -22
  439. package/dist/utils/StopGenerationDetector.js.map +1 -1
  440. package/dist/utils/TokenStreamRegulator.d.ts +9 -4
  441. package/dist/utils/TokenStreamRegulator.js +81 -8
  442. package/dist/utils/TokenStreamRegulator.js.map +1 -1
  443. package/dist/utils/UnsupportedError.d.ts +2 -0
  444. package/dist/utils/UnsupportedError.js +7 -0
  445. package/dist/utils/UnsupportedError.js.map +1 -0
  446. package/dist/utils/appendUserMessageToChatHistory.js.map +1 -1
  447. package/dist/utils/clearTempFolder.js.map +1 -1
  448. package/dist/utils/cmake.js +38 -20
  449. package/dist/utils/cmake.js.map +1 -1
  450. package/dist/utils/createModelDownloader.d.ts +108 -0
  451. package/dist/utils/createModelDownloader.js +231 -0
  452. package/dist/utils/createModelDownloader.js.map +1 -0
  453. package/dist/utils/findBestOption.d.ts +4 -0
  454. package/dist/utils/findBestOption.js +15 -0
  455. package/dist/utils/findBestOption.js.map +1 -0
  456. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +1 -0
  457. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +23 -12
  458. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
  459. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
  460. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
  461. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
  462. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
  463. package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +3 -1
  464. package/dist/utils/gbnfJson/terminals/GbnfArray.js +10 -5
  465. package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
  466. package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +1 -1
  467. package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -1
  468. package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -1
  469. package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -1
  470. package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +1 -1
  471. package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -1
  472. package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +1 -1
  473. package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -1
  474. package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -1
  475. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +3 -1
  476. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +9 -4
  477. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
  478. package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -1
  479. package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +9 -0
  480. package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +37 -0
  481. package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
  482. package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +1 -1
  483. package/dist/utils/gbnfJson/terminals/GbnfString.js +23 -5
  484. package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
  485. package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -1
  486. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -1
  487. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +7 -4
  488. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +37 -9
  489. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
  490. package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +5 -4
  491. package/dist/utils/gbnfJson/terminals/gbnfConsts.js +14 -3
  492. package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
  493. package/dist/utils/gbnfJson/types.d.ts +3 -0
  494. package/dist/utils/gbnfJson/types.js.map +1 -1
  495. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
  496. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
  497. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
  498. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +2 -1
  499. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +6 -5
  500. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
  501. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +2 -2
  502. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
  503. package/dist/utils/getBuildDefaults.d.ts +1 -2
  504. package/dist/utils/getBuildDefaults.js +2 -3
  505. package/dist/utils/getBuildDefaults.js.map +1 -1
  506. package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
  507. package/dist/utils/getConsoleLogPrefix.js +10 -0
  508. package/dist/utils/getConsoleLogPrefix.js.map +1 -0
  509. package/dist/utils/getGrammarsFolder.d.ts +2 -1
  510. package/dist/utils/getGrammarsFolder.js +8 -7
  511. package/dist/utils/getGrammarsFolder.js.map +1 -1
  512. package/dist/utils/getModuleVersion.d.ts +1 -0
  513. package/dist/utils/getModuleVersion.js +13 -0
  514. package/dist/utils/getModuleVersion.js.map +1 -0
  515. package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
  516. package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
  517. package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
  518. package/dist/utils/getReadableContextSize.d.ts +1 -0
  519. package/dist/utils/getReadableContextSize.js +7 -0
  520. package/dist/utils/getReadableContextSize.js.map +1 -0
  521. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +15 -11
  522. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -1
  523. package/dist/utils/gitReleaseBundles.js +73 -5
  524. package/dist/utils/gitReleaseBundles.js.map +1 -1
  525. package/dist/utils/hashString.d.ts +1 -0
  526. package/dist/utils/hashString.js +8 -0
  527. package/dist/utils/hashString.js.map +1 -0
  528. package/dist/utils/isLockfileActive.d.ts +4 -0
  529. package/dist/utils/isLockfileActive.js +12 -0
  530. package/dist/utils/isLockfileActive.js.map +1 -0
  531. package/dist/utils/isToken.d.ts +2 -0
  532. package/dist/utils/isToken.js +4 -0
  533. package/dist/utils/isToken.js.map +1 -0
  534. package/dist/utils/isUrl.d.ts +1 -0
  535. package/dist/utils/isUrl.js +15 -0
  536. package/dist/utils/isUrl.js.map +1 -0
  537. package/dist/utils/mergeUnionTypes.d.ts +10 -0
  538. package/dist/utils/mergeUnionTypes.js +2 -0
  539. package/dist/utils/mergeUnionTypes.js.map +1 -0
  540. package/dist/utils/parseModelFileName.d.ts +1 -0
  541. package/dist/utils/parseModelFileName.js +6 -1
  542. package/dist/utils/parseModelFileName.js.map +1 -1
  543. package/dist/utils/parseTextTemplate.d.ts +66 -0
  544. package/dist/utils/parseTextTemplate.js +116 -0
  545. package/dist/utils/parseTextTemplate.js.map +1 -0
  546. package/dist/utils/prettyPrintObject.d.ts +10 -0
  547. package/dist/utils/prettyPrintObject.js +84 -0
  548. package/dist/utils/prettyPrintObject.js.map +1 -0
  549. package/dist/utils/removeNullFields.d.ts +2 -1
  550. package/dist/utils/removeNullFields.js +8 -0
  551. package/dist/utils/removeNullFields.js.map +1 -1
  552. package/dist/utils/resolveGithubRelease.d.ts +2 -0
  553. package/dist/utils/resolveGithubRelease.js +36 -0
  554. package/dist/utils/resolveGithubRelease.js.map +1 -0
  555. package/dist/utils/runtime.d.ts +4 -0
  556. package/dist/utils/runtime.js +8 -0
  557. package/dist/utils/runtime.js.map +1 -0
  558. package/dist/utils/safeEventCallback.d.ts +6 -0
  559. package/dist/utils/safeEventCallback.js +29 -0
  560. package/dist/utils/safeEventCallback.js.map +1 -0
  561. package/dist/utils/spawnCommand.d.ts +11 -1
  562. package/dist/utils/spawnCommand.js +56 -6
  563. package/dist/utils/spawnCommand.js.map +1 -1
  564. package/dist/utils/tokenizeInput.d.ts +3 -0
  565. package/dist/utils/tokenizeInput.js +12 -0
  566. package/dist/utils/tokenizeInput.js.map +1 -0
  567. package/dist/utils/truncateTextAndRoundToWords.d.ts +2 -0
  568. package/dist/utils/truncateTextAndRoundToWords.js +30 -0
  569. package/dist/utils/truncateTextAndRoundToWords.js.map +1 -1
  570. package/dist/utils/utilTypes.d.ts +3 -0
  571. package/dist/utils/utilTypes.js +2 -0
  572. package/dist/utils/utilTypes.js.map +1 -0
  573. package/dist/utils/waitForLockfileRelease.d.ts +5 -0
  574. package/dist/utils/waitForLockfileRelease.js +20 -0
  575. package/dist/utils/waitForLockfileRelease.js.map +1 -0
  576. package/dist/utils/withLockfile.d.ts +7 -0
  577. package/dist/utils/withLockfile.js +44 -0
  578. package/dist/utils/withLockfile.js.map +1 -0
  579. package/dist/utils/withOra.d.ts +2 -0
  580. package/dist/utils/withOra.js +22 -6
  581. package/dist/utils/withOra.js.map +1 -1
  582. package/dist/utils/withProgressLog.d.ts +23 -0
  583. package/dist/utils/withProgressLog.js +211 -0
  584. package/dist/utils/withProgressLog.js.map +1 -0
  585. package/dist/utils/withStatusLogs.d.ts +2 -1
  586. package/dist/utils/withStatusLogs.js +12 -9
  587. package/dist/utils/withStatusLogs.js.map +1 -1
  588. package/dist/utils/wrapAbortSignal.d.ts +2 -0
  589. package/dist/utils/wrapAbortSignal.js +9 -0
  590. package/dist/utils/wrapAbortSignal.js.map +1 -0
  591. package/llama/.clang-format +1 -2
  592. package/llama/CMakeLists.txt +115 -4
  593. package/llama/addon.cpp +1300 -97
  594. package/llama/binariesGithubRelease.json +1 -1
  595. package/llama/gitRelease.bundle +0 -0
  596. package/llama/gpuInfo/cuda-gpu-info.cu +120 -0
  597. package/llama/gpuInfo/cuda-gpu-info.h +10 -0
  598. package/llama/gpuInfo/metal-gpu-info.h +8 -0
  599. package/llama/gpuInfo/metal-gpu-info.mm +30 -0
  600. package/llama/gpuInfo/vulkan-gpu-info.cpp +83 -0
  601. package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
  602. package/llama/grammars/README.md +58 -5
  603. package/llama/grammars/json.gbnf +4 -4
  604. package/llama/grammars/json_arr.gbnf +4 -4
  605. package/llama/llama.cpp.info.json +4 -0
  606. package/llama/toolchains/win32.host-x64.target-arm64.cmake +41 -0
  607. package/package.json +78 -53
  608. package/templates/packed/electron-typescript-react.json +1 -0
  609. package/templates/packed/node-typescript.json +1 -0
  610. package/dist/AbortError.d.ts +0 -2
  611. package/dist/AbortError.js +0 -7
  612. package/dist/AbortError.js.map +0 -1
  613. package/dist/chatWrappers/LlamaChatWrapper.d.ts +0 -13
  614. package/dist/chatWrappers/LlamaChatWrapper.js.map +0 -1
  615. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +0 -13
  616. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +0 -57
  617. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +0 -1
  618. package/dist/llamaEvaluator/LlamaBins.d.ts +0 -18
  619. package/dist/llamaEvaluator/LlamaBins.js +0 -5
  620. package/dist/llamaEvaluator/LlamaBins.js.map +0 -1
  621. package/dist/llamaEvaluator/LlamaChat/LlamaChat.js +0 -704
  622. package/dist/llamaEvaluator/LlamaChat/LlamaChat.js.map +0 -1
  623. package/dist/llamaEvaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +0 -21
  624. package/dist/llamaEvaluator/LlamaChat/utils/FunctionCallGrammar.js +0 -120
  625. package/dist/llamaEvaluator/LlamaChat/utils/FunctionCallGrammar.js.map +0 -1
  626. package/dist/llamaEvaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +0 -1
  627. package/dist/llamaEvaluator/LlamaChatSession/LlamaChatSession.d.ts +0 -146
  628. package/dist/llamaEvaluator/LlamaChatSession/LlamaChatSession.js +0 -211
  629. package/dist/llamaEvaluator/LlamaChatSession/LlamaChatSession.js.map +0 -1
  630. package/dist/llamaEvaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +0 -1
  631. package/dist/llamaEvaluator/LlamaContext/LlamaContext.js.map +0 -1
  632. package/dist/llamaEvaluator/LlamaContext/types.d.ts +0 -82
  633. package/dist/llamaEvaluator/LlamaContext/types.js.map +0 -1
  634. package/dist/llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +0 -1
  635. package/dist/llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +0 -1
  636. package/dist/llamaEvaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +0 -2
  637. package/dist/llamaEvaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +0 -1
  638. package/dist/llamaEvaluator/LlamaEmbeddingContext.d.ts +0 -35
  639. package/dist/llamaEvaluator/LlamaEmbeddingContext.js +0 -73
  640. package/dist/llamaEvaluator/LlamaEmbeddingContext.js.map +0 -1
  641. package/dist/llamaEvaluator/LlamaGrammar.js.map +0 -1
  642. package/dist/llamaEvaluator/LlamaGrammarEvaluationState.js.map +0 -1
  643. package/dist/llamaEvaluator/LlamaJsonSchemaGrammar.js.map +0 -1
  644. package/dist/llamaEvaluator/LlamaModel.d.ts +0 -119
  645. package/dist/llamaEvaluator/LlamaModel.js +0 -322
  646. package/dist/llamaEvaluator/LlamaModel.js.map +0 -1
  647. package/dist/utils/binariesGithubRelease.js.map +0 -1
  648. package/dist/utils/clearLlamaBuild.d.ts +0 -1
  649. package/dist/utils/clearLlamaBuild.js +0 -12
  650. package/dist/utils/clearLlamaBuild.js.map +0 -1
  651. package/dist/utils/cloneLlamaCppRepo.d.ts +0 -2
  652. package/dist/utils/cloneLlamaCppRepo.js +0 -102
  653. package/dist/utils/cloneLlamaCppRepo.js.map +0 -1
  654. package/dist/utils/compileLLamaCpp.d.ts +0 -8
  655. package/dist/utils/compileLLamaCpp.js +0 -132
  656. package/dist/utils/compileLLamaCpp.js.map +0 -1
  657. package/dist/utils/getBin.js +0 -78
  658. package/dist/utils/getBin.js.map +0 -1
  659. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.d.ts +0 -2
  660. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +0 -9
  661. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +0 -1
  662. package/dist/utils/getReleaseInfo.d.ts +0 -7
  663. package/dist/utils/getReleaseInfo.js +0 -30
  664. package/dist/utils/getReleaseInfo.js.map +0 -1
  665. package/dist/utils/parseModelTypeDescription.d.ts +0 -6
  666. package/dist/utils/parseModelTypeDescription.js +0 -9
  667. package/dist/utils/parseModelTypeDescription.js.map +0 -1
  668. package/dist/utils/resolveChatWrapper.d.ts +0 -4
  669. package/dist/utils/resolveChatWrapper.js +0 -16
  670. package/dist/utils/resolveChatWrapper.js.map +0 -1
  671. package/dist/utils/usedBinFlag.d.ts +0 -6
  672. package/dist/utils/usedBinFlag.js +0 -15
  673. package/dist/utils/usedBinFlag.js.map +0 -1
  674. package/llama/usedBin.json +0 -3
  675. package/llamaBins/linux-arm64/llama-addon.node +0 -0
  676. package/llamaBins/linux-armv7l/llama-addon.node +0 -0
  677. package/llamaBins/linux-x64/llama-addon.node +0 -0
  678. package/llamaBins/mac-arm64/llama-addon.node +0 -0
  679. package/llamaBins/mac-x64/llama-addon.node +0 -0
  680. package/llamaBins/win-x64/llama-addon.exp +0 -0
  681. package/llamaBins/win-x64/llama-addon.lib +0 -0
  682. package/llamaBins/win-x64/llama-addon.node +0 -0
  683. /package/dist/{utils → bindings/utils}/binariesGithubRelease.d.ts +0 -0
  684. /package/dist/{llamaEvaluator → evaluator}/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.d.ts +0 -0
  685. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/types.js +0 -0
  686. /package/dist/{llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies → evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.d.ts +0 -0
  687. /package/dist/{llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies → evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.js +0 -0
  688. /package/dist/{llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies → evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies}/maximumParallelismStrategy.d.ts +0 -0
  689. /package/dist/{llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies → evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies}/maximumParallelismStrategy.js +0 -0
  690. /package/dist/{llamaEvaluator → evaluator}/LlamaGrammarEvaluationState.d.ts +0 -0
@@ -0,0 +1,7 @@
1
+ export class UnsupportedError extends Error {
2
+ /** @internal */
3
+ constructor(message = "UnsupportedError") {
4
+ super(message);
5
+ }
6
+ }
7
+ //# sourceMappingURL=UnsupportedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnsupportedError.js","sourceRoot":"","sources":["../../src/utils/UnsupportedError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvC,gBAAgB;IAChB,YAAmB,UAAkB,kBAAkB;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"appendUserMessageToChatHistory.js","sourceRoot":"","sources":["../../src/utils/appendUserMessageToChatHistory.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,8BAA8B,CAAC,WAAuC,EAAE,OAAe;IACnG,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC;IAE3C,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE;QACxF,MAAM,eAAe,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAoB,CAAC;QAErF,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG;YACxC,GAAG,eAAe;YAClB,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;SACrD,CAAC;KACL;SAAM;QACH,cAAc,CAAC,IAAI,CAAC;YAChB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,OAAO;SAChB,CAAC,CAAC;KACN;IAED,OAAO,cAAc,CAAC;AAC1B,CAAC"}
1
+ {"version":3,"file":"appendUserMessageToChatHistory.js","sourceRoot":"","sources":["../../src/utils/appendUserMessageToChatHistory.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,8BAA8B,CAAC,WAAuC,EAAE,OAAe;IACnG,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC;IAE3C,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzF,MAAM,eAAe,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAoB,CAAC;QAErF,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG;YACxC,GAAG,eAAe;YAClB,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;SACrD,CAAC;IACN,CAAC;SAAM,CAAC;QACJ,cAAc,CAAC,IAAI,CAAC;YAChB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,OAAO;SAChB,CAAC,CAAC;IACP,CAAC;IAED,OAAO,cAAc,CAAC;AAC1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"clearTempFolder.js","sourceRoot":"","sources":["../../src/utils/clearTempFolder.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,eAAe;IACjC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QAC9B,IAAI;YACA,MAAM,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;SAC1C;QAAC,OAAO,GAAG,EAAE;YACV,gGAAgG;SACnG;QAED,OAAO;KACV;IAED,MAAM,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC"}
1
+ {"version":3,"file":"clearTempFolder.js","sourceRoot":"","sources":["../../src/utils/clearTempFolder.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,eAAe;IACjC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC;YACD,MAAM,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,gGAAgG;QACpG,CAAC;QAED,OAAO;IACX,CAAC;IAED,MAAM,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC"}
@@ -4,8 +4,10 @@ import which from "which";
4
4
  import chalk from "chalk";
5
5
  import { chmodr } from "chmodrp";
6
6
  import { defaultXpacksCacheDirectory, defaultXpacksStoreDirectory, llamaDirectory, localXpacksCacheDirectory, localXpacksStoreDirectory, xpackDirectory, xpmVersion } from "../config.js";
7
+ import { logDistroInstallInstruction } from "../bindings/utils/logDistroInstallInstruction.js";
7
8
  import { spawnCommand } from "./spawnCommand.js";
8
9
  import withStatusLogs from "./withStatusLogs.js";
10
+ import { withLockfile } from "./withLockfile.js";
9
11
  export async function hasBuiltinCmake() {
10
12
  try {
11
13
  const resolvedPath = await which("cmake");
@@ -17,8 +19,10 @@ export async function hasBuiltinCmake() {
17
19
  }
18
20
  export async function getCmakePath() {
19
21
  try {
20
- const resolvedPath = await which("cmake");
21
- if (resolvedPath !== "")
22
+ const resolvedPath = await which("cmake", {
23
+ nothrow: true
24
+ });
25
+ if (resolvedPath !== "" && resolvedPath != null)
22
26
  return resolvedPath;
23
27
  }
24
28
  catch (err) { }
@@ -46,15 +50,25 @@ export async function downloadCmakeIfNeeded(wrapWithStatusLogs = false) {
46
50
  }
47
51
  catch (err) { }
48
52
  if (!wrapWithStatusLogs)
49
- await downloadCmake();
50
- else
51
- await withStatusLogs({
52
- loading: chalk.blue("Downloading cmake"),
53
- success: chalk.blue("Downloaded cmake"),
54
- fail: chalk.blue("Failed to download cmake")
55
- }, async () => {
56
- await downloadCmake();
57
- });
53
+ await downloadCmake({ progressLogs: wrapWithStatusLogs });
54
+ else {
55
+ try {
56
+ await withStatusLogs({
57
+ loading: chalk.blue("Downloading cmake"),
58
+ success: chalk.blue("Downloaded cmake"),
59
+ fail: chalk.blue("Failed to download cmake")
60
+ }, async () => {
61
+ await downloadCmake({ progressLogs: wrapWithStatusLogs });
62
+ });
63
+ }
64
+ catch (err) {
65
+ await logDistroInstallInstruction('To install "cmake", ', {
66
+ linuxPackages: { apt: ["cmake"], apk: ["cmake"] },
67
+ macOsPackages: { brew: ["cmake"] }
68
+ });
69
+ throw err;
70
+ }
71
+ }
58
72
  }
59
73
  export async function clearLocalCmake() {
60
74
  await fs.remove(localXpacksStoreDirectory);
@@ -74,15 +88,19 @@ export async function fixXpackPermissions() {
74
88
  }
75
89
  catch (err) { }
76
90
  }
77
- async function downloadCmake() {
78
- const xpmEnv = {
79
- ...process.env,
80
- XPACKS_STORE_FOLDER: defaultXpacksStoreDirectory,
81
- XPACKS_CACHE_FOLDER: defaultXpacksCacheDirectory
82
- };
83
- await spawnCommand("npm", ["exec", "--yes", "--", `xpm@${xpmVersion}`, "install", "@xpack-dev-tools/cmake@latest", "--no-save"], xpackDirectory, xpmEnv);
84
- await fs.remove(localXpacksCacheDirectory);
85
- await fixXpackPermissions();
91
+ async function downloadCmake({ progressLogs = true } = {}) {
92
+ await withLockfile({
93
+ resourcePath: path.join(xpackDirectory, "cmakeInstall")
94
+ }, async () => {
95
+ const xpmEnv = {
96
+ ...process.env,
97
+ XPACKS_STORE_FOLDER: defaultXpacksStoreDirectory,
98
+ XPACKS_CACHE_FOLDER: defaultXpacksCacheDirectory
99
+ };
100
+ await spawnCommand("npm", ["exec", "--yes", "--", `xpm@${xpmVersion}`, "install", "@xpack-dev-tools/cmake@latest", "--no-save"], xpackDirectory, xpmEnv, progressLogs);
101
+ await fs.remove(localXpacksCacheDirectory);
102
+ await fixXpackPermissions();
103
+ });
86
104
  }
87
105
  async function getBinFromWindowCmd(cmdFilePath, binName) {
88
106
  const fileContent = await fs.readFile(cmdFilePath, "utf8");
@@ -1 +1 @@
1
- {"version":3,"file":"cmake.js","sourceRoot":"","sources":["../../src/utils/cmake.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAC/B,OAAO,EACH,2BAA2B,EAAE,2BAA2B,EAAE,cAAc,EAAE,yBAAyB,EAAE,yBAAyB,EAC9H,cAAc,EAAE,UAAU,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAGjD,MAAM,CAAC,KAAK,UAAU,eAAe;IACjC,IAAI;QACA,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,YAAY,KAAK,EAAE,CAAC;KAC9B;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,KAAK,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AAE,cAAc,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;QAEvK,MAAM,EAAE,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC;QAC3C,MAAM,mBAAmB,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,mBAAmB,CAAC,WAAmB,EAAE,OAAe;IACnE,MAAM,WAAW,GAAW,MAAM,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACnE,MAAM,oBAAoB,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;IAEvD,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvC,OAAO,IAAI,CAAC;IAEhB,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrE,MAAM,qBAAqB,GAAG,WAAW,CAAC,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/E,IAAI,qBAAqB,KAAK,GAAG,IAAI,qBAAqB,KAAK,GAAG;QAC9D,OAAO,IAAI,CAAC;IAEhB,MAAM,oBAAoB,GAAG,WAAW,CAAC,WAAW,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;IAEhG,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjG,IAAI,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAC7B,OAAO,IAAI,CAAC;IAEhB,OAAO,OAAO,CAAC;AACnB,CAAC"}
@@ -0,0 +1,108 @@
1
+ /// <reference types="node" />
2
+ export type ModelDownloaderOptions = {
3
+ modelUrl: string;
4
+ /**
5
+ * The directory to save the model file to.
6
+ * Default to `node-llama-cpp`'s default global models directory (`~/.node-llama-cpp/models`).
7
+ */
8
+ dirPath?: string;
9
+ fileName?: string;
10
+ headers?: Record<string, string>;
11
+ /**
12
+ * Defaults to `false`.
13
+ */
14
+ showCliProgress?: boolean;
15
+ onProgress?: (status: {
16
+ totalSize: number;
17
+ downloadedSize: number;
18
+ }) => void;
19
+ /**
20
+ * If true, the downloader will skip the download if the file already exists, and its size matches the size of the remote file.
21
+ *
22
+ * Defaults to `true`.
23
+ */
24
+ skipExisting?: boolean;
25
+ /**
26
+ * If true, the temporary file will be deleted when the download is canceled.
27
+ *
28
+ * Defaults to `true`.
29
+ */
30
+ deleteTempFileOnCancel?: boolean;
31
+ /**
32
+ * The number of parallel downloads to use when downloading split files.
33
+ *
34
+ * Defaults to `4`.
35
+ */
36
+ parallelDownloads?: number;
37
+ };
38
+ /**
39
+ * Create a model downloader to download a model from a URL.
40
+ * Uses [`ipull`](https://github.com/ido-pluto/ipull) to download a model file as fast as possible with parallel connections
41
+ * and other optimizations.
42
+ *
43
+ * If the url points to a `.gguf` file that is split into multiple parts (for example, `model-00001-of-00009.gguf`),
44
+ * all the parts will be downloaded to the specified directory.
45
+ *
46
+ * If the url points to a `.gguf` file that is binary spliced into multiple parts (for example, `model.gguf.part1of9`),
47
+ * all the parts will be spliced into a single file and be downloaded to the specified directory.
48
+ *
49
+ * If the url points to a `.gguf` file that is not split or binary spliced (for example, `model.gguf`),
50
+ * the file will be downloaded to the specified directory.
51
+ * @example
52
+ * ```typescript
53
+ * import {fileURLToPath} from "url";
54
+ * import path from "path";
55
+ * import {createModelDownloader, getLlama} from "node-llama-cpp";
56
+ *
57
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url));
58
+ *
59
+ * const downloader = await createModelDownloader({
60
+ * modelUrl: "https://example.com/model.gguf",
61
+ * dirPath: path.join(__dirname, "models")
62
+ * });
63
+ * const modelPath = await downloader.download();
64
+ *
65
+ * const llama = await getLlama();
66
+ * const model = llama.loadModel({
67
+ * modelPath
68
+ * });
69
+ * ```
70
+ */
71
+ export declare function createModelDownloader(options: ModelDownloaderOptions): Promise<ModelDownloader>;
72
+ export declare class ModelDownloader {
73
+ private constructor();
74
+ /**
75
+ * The filename of the entrypoint file that should be used to load the model.
76
+ */
77
+ get entrypointFilename(): string;
78
+ /**
79
+ * The full path to the entrypoint file that should be used to load the model.
80
+ */
81
+ get entrypointFilePath(): string;
82
+ /**
83
+ * If the model is binary spliced from multiple parts, this will return the number of those binary parts.
84
+ */
85
+ get splitBinaryParts(): number | undefined;
86
+ /**
87
+ * The total number of files that will be saved to the directory.
88
+ * For split files, this will be the number of split parts, as multiple files will be saved.
89
+ * For binary-split files, this will be 1, as the parts will be spliced into a single file.
90
+ */
91
+ get totalFiles(): number;
92
+ get totalSize(): number;
93
+ get downloadedSize(): number;
94
+ /**
95
+ * @returns The path to the entrypoint file that should be used to load the model
96
+ */
97
+ download({ signal }?: {
98
+ signal?: AbortSignal;
99
+ }): Promise<string>;
100
+ cancel({ deleteTempFile }?: {
101
+ /**
102
+ * Delete the temporary file that was created during the download.
103
+ *
104
+ * Defaults to the value of `deleteTempFileOnCancel` in the constructor.
105
+ */
106
+ deleteTempFile?: boolean;
107
+ }): Promise<void>;
108
+ }
@@ -0,0 +1,231 @@
1
+ import process from "process";
2
+ import path from "path";
3
+ import { downloadFile, downloadSequence } from "ipull";
4
+ import fs from "fs-extra";
5
+ import { normalizeGgufDownloadUrl } from "../gguf/utils/normalizeGgufDownloadUrl.js";
6
+ import { createSplitPartFilename, resolveSplitGgufParts } from "../gguf/utils/resolveSplitGgufParts.js";
7
+ import { getFilenameForBinarySplitGgufPartUrls, resolveBinarySplitGgufPartUrls } from "../gguf/utils/resolveBinarySplitGgufPartUrls.js";
8
+ import { cliModelsDirectory } from "../config.js";
9
+ import { safeEventCallback } from "./safeEventCallback.js";
10
+ /**
11
+ * Create a model downloader to download a model from a URL.
12
+ * Uses [`ipull`](https://github.com/ido-pluto/ipull) to download a model file as fast as possible with parallel connections
13
+ * and other optimizations.
14
+ *
15
+ * If the url points to a `.gguf` file that is split into multiple parts (for example, `model-00001-of-00009.gguf`),
16
+ * all the parts will be downloaded to the specified directory.
17
+ *
18
+ * If the url points to a `.gguf` file that is binary spliced into multiple parts (for example, `model.gguf.part1of9`),
19
+ * all the parts will be spliced into a single file and be downloaded to the specified directory.
20
+ *
21
+ * If the url points to a `.gguf` file that is not split or binary spliced (for example, `model.gguf`),
22
+ * the file will be downloaded to the specified directory.
23
+ * @example
24
+ * ```typescript
25
+ * import {fileURLToPath} from "url";
26
+ * import path from "path";
27
+ * import {createModelDownloader, getLlama} from "node-llama-cpp";
28
+ *
29
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url));
30
+ *
31
+ * const downloader = await createModelDownloader({
32
+ * modelUrl: "https://example.com/model.gguf",
33
+ * dirPath: path.join(__dirname, "models")
34
+ * });
35
+ * const modelPath = await downloader.download();
36
+ *
37
+ * const llama = await getLlama();
38
+ * const model = llama.loadModel({
39
+ * modelPath
40
+ * });
41
+ * ```
42
+ */
43
+ export async function createModelDownloader(options) {
44
+ const downloader = ModelDownloader._create(options);
45
+ await downloader._init();
46
+ return downloader;
47
+ }
48
+ export class ModelDownloader {
49
+ /** @internal */ _modelUrl;
50
+ /** @internal */ _dirPath;
51
+ /** @internal */ _fileName;
52
+ /** @internal */ _headers;
53
+ /** @internal */ _showCliProgress;
54
+ /** @internal */ _onProgress;
55
+ /** @internal */ _deleteTempFileOnCancel;
56
+ /** @internal */ _skipExisting;
57
+ /** @internal */ _parallelDownloads;
58
+ /** @internal */ _downloader;
59
+ /** @internal */ _specificFileDownloaders = [];
60
+ /** @internal */ _entrypointFilename;
61
+ /** @internal */ _splitBinaryParts;
62
+ /** @internal */ _totalFiles;
63
+ constructor({ modelUrl, dirPath = cliModelsDirectory, fileName, headers, showCliProgress = false, onProgress, deleteTempFileOnCancel = true, skipExisting = true, parallelDownloads = 4 }) {
64
+ if (modelUrl == null || dirPath == null)
65
+ throw new Error("modelUrl and dirPath cannot be null");
66
+ this._modelUrl = normalizeGgufDownloadUrl(modelUrl);
67
+ this._dirPath = path.resolve(process.cwd(), dirPath);
68
+ this._fileName = fileName;
69
+ this._headers = headers;
70
+ this._showCliProgress = showCliProgress;
71
+ this._onProgress = safeEventCallback(onProgress);
72
+ this._deleteTempFileOnCancel = deleteTempFileOnCancel;
73
+ this._skipExisting = skipExisting;
74
+ this._parallelDownloads = parallelDownloads;
75
+ this._onDownloadProgress = this._onDownloadProgress.bind(this);
76
+ }
77
+ /**
78
+ * The filename of the entrypoint file that should be used to load the model.
79
+ */
80
+ get entrypointFilename() {
81
+ return this._entrypointFilename;
82
+ }
83
+ /**
84
+ * The full path to the entrypoint file that should be used to load the model.
85
+ */
86
+ get entrypointFilePath() {
87
+ return path.join(this._dirPath, this.entrypointFilename);
88
+ }
89
+ /**
90
+ * If the model is binary spliced from multiple parts, this will return the number of those binary parts.
91
+ */
92
+ get splitBinaryParts() {
93
+ return this._splitBinaryParts;
94
+ }
95
+ /**
96
+ * The total number of files that will be saved to the directory.
97
+ * For split files, this will be the number of split parts, as multiple files will be saved.
98
+ * For binary-split files, this will be 1, as the parts will be spliced into a single file.
99
+ */
100
+ get totalFiles() {
101
+ return this._totalFiles;
102
+ }
103
+ get totalSize() {
104
+ return this._downloader.downloadStatues
105
+ .map(status => status.totalBytes)
106
+ .reduce((acc, totalBytes) => acc + totalBytes, 0);
107
+ }
108
+ get downloadedSize() {
109
+ return this._downloader.downloadStatues
110
+ .map(status => status.transferredBytes)
111
+ .reduce((acc, transferredBytes) => acc + transferredBytes, 0);
112
+ }
113
+ /**
114
+ * @returns The path to the entrypoint file that should be used to load the model
115
+ */
116
+ async download({ signal } = {}) {
117
+ if (signal?.aborted)
118
+ throw signal.reason;
119
+ if (this._skipExisting) {
120
+ if (this._specificFileDownloaders.length === 1 && await fs.pathExists(this.entrypointFilePath)) {
121
+ const fileStat = await fs.stat(this.entrypointFilePath);
122
+ if (this._specificFileDownloaders[0].status.totalBytes === fileStat.size)
123
+ return this.entrypointFilePath;
124
+ }
125
+ else {
126
+ // TODO: skip existing split files
127
+ }
128
+ }
129
+ const onAbort = () => {
130
+ signal?.removeEventListener("abort", onAbort);
131
+ this.cancel();
132
+ };
133
+ if (signal != null)
134
+ signal.addEventListener("abort", onAbort);
135
+ try {
136
+ if (this._onProgress)
137
+ this._downloader.on("progress", this._onDownloadProgress);
138
+ await this._downloader.download();
139
+ }
140
+ catch (err) {
141
+ if (signal?.aborted)
142
+ throw signal.reason;
143
+ throw err;
144
+ }
145
+ finally {
146
+ if (this._onProgress)
147
+ this._downloader.off("progress", this._onDownloadProgress);
148
+ if (signal != null)
149
+ signal.removeEventListener("abort", onAbort);
150
+ }
151
+ return this.entrypointFilePath;
152
+ }
153
+ async cancel({ deleteTempFile = this._deleteTempFileOnCancel } = {}) {
154
+ for (const downloader of this._specificFileDownloaders) {
155
+ if (deleteTempFile)
156
+ await downloader.closeAndDeleteFile();
157
+ else
158
+ await downloader.close();
159
+ }
160
+ if (this._downloader !== this._specificFileDownloaders[0])
161
+ await this._downloader?.close();
162
+ }
163
+ /** @internal */
164
+ _onDownloadProgress() {
165
+ this._onProgress?.({
166
+ totalSize: this.totalSize,
167
+ downloadedSize: this.downloadedSize
168
+ });
169
+ }
170
+ /** @internal */
171
+ async _init() {
172
+ const binarySplitPartUrls = resolveBinarySplitGgufPartUrls(this._modelUrl);
173
+ await fs.ensureDir(this._dirPath);
174
+ if (binarySplitPartUrls instanceof Array) {
175
+ this._downloader = await downloadFile({
176
+ partURLs: binarySplitPartUrls,
177
+ directory: this._dirPath,
178
+ fileName: this._fileName ?? getFilenameForBinarySplitGgufPartUrls(binarySplitPartUrls),
179
+ cliProgress: this._showCliProgress,
180
+ headers: this._headers ?? {}
181
+ });
182
+ this._specificFileDownloaders.push(this._downloader);
183
+ this._entrypointFilename = this._downloader.fileName;
184
+ this._splitBinaryParts = binarySplitPartUrls.length;
185
+ this._totalFiles = 1;
186
+ if (this._downloader.fileName == null || this._downloader.fileName === "")
187
+ throw new Error("Failed to get the file name from the given URL");
188
+ return;
189
+ }
190
+ const splitGgufPartUrls = resolveSplitGgufParts(this._modelUrl);
191
+ if (splitGgufPartUrls.length === 1) {
192
+ this._downloader = await downloadFile({
193
+ url: splitGgufPartUrls[0],
194
+ directory: this._dirPath,
195
+ fileName: this._fileName ?? undefined,
196
+ cliProgress: this._showCliProgress,
197
+ headers: this._headers ?? {}
198
+ });
199
+ this._specificFileDownloaders.push(this._downloader);
200
+ this._entrypointFilename = this._downloader.fileName;
201
+ this._totalFiles = 1;
202
+ if (this._downloader.fileName == null || this._downloader.fileName === "")
203
+ throw new Error("Failed to get the file name from the given URL");
204
+ return;
205
+ }
206
+ const partDownloads = splitGgufPartUrls.map((url, index) => downloadFile({
207
+ url,
208
+ directory: this._dirPath,
209
+ fileName: this._fileName != null
210
+ ? createSplitPartFilename(this._fileName, index + 1, splitGgufPartUrls.length)
211
+ : undefined,
212
+ headers: this._headers ?? {}
213
+ }));
214
+ this._downloader = await downloadSequence({
215
+ cliProgress: this._showCliProgress,
216
+ parallelDownloads: this._parallelDownloads
217
+ }, ...partDownloads);
218
+ const firstDownload = await partDownloads[0];
219
+ this._specificFileDownloaders = await Promise.all(partDownloads);
220
+ this._entrypointFilename = firstDownload.fileName;
221
+ this._totalFiles = partDownloads.length;
222
+ if (this._entrypointFilename == null || this._entrypointFilename === "")
223
+ throw new Error("Failed to get the file name from the given URL");
224
+ return;
225
+ }
226
+ /** @internal */
227
+ static _create(options) {
228
+ return new ModelDownloader(options);
229
+ }
230
+ }
231
+ //# sourceMappingURL=createModelDownloader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModelDownloader.js","sourceRoot":"","sources":["../../src/utils/createModelDownloader.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAoD,YAAY,EAAE,gBAAgB,EAAC,MAAM,OAAO,CAAC;AACxG,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,wBAAwB,EAAC,MAAM,2CAA2C,CAA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AAI,CAAC,mBAAmB,IAAI,IAAI,IAAI,IAAI,CAAC,mBAAmB,KAAK,EAAE;YACnE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAEtE,OAAO;IACX,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,OAAO,CAAC,OAA+B;QACjD,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACJ"}
@@ -0,0 +1,4 @@
1
+ export declare function findBestOption<const O>({ generator, score }: {
2
+ generator: () => Generator<O>;
3
+ score: (option: O) => number | null;
4
+ }): O | null;
@@ -0,0 +1,15 @@
1
+ export function findBestOption({ generator, score }) {
2
+ let bestOption = null;
3
+ let bestScore = null;
4
+ for (const option of generator()) {
5
+ const currentScore = score(option);
6
+ if (currentScore === Infinity)
7
+ return option;
8
+ if (currentScore != null && (bestScore == null || currentScore > bestScore)) {
9
+ bestOption = option;
10
+ bestScore = currentScore;
11
+ }
12
+ }
13
+ return bestOption;
14
+ }
15
+ //# sourceMappingURL=findBestOption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findBestOption.js","sourceRoot":"","sources":["../../src/utils/findBestOption.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAU,EAAC,SAAS,EAAE,KAAK,EAGxD;IACG,IAAI,UAAU,GAAa,IAAI,CAAC;IAChC,IAAI,SAAS,GAAkB,IAAI,CAAC;IAEpC,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,YAAY,KAAK,QAAQ;YACzB,OAAO,MAAM,CAAC;QAElB,IAAI,YAAY,IAAI,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,IAAI,YAAY,GAAG,SAAS,CAAC,EAAE,CAAC;YAC1E,UAAU,GAAG,MAAM,CAAC;YACpB,SAAS,GAAG,YAAY,CAAC;QAC7B,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -4,6 +4,7 @@ export declare function findCharacterRemovalCountToFitChatHistoryInContext({ com
4
4
  compressChatHistory(options: {
5
5
  chatHistory: readonly ChatHistoryItem[];
6
6
  charactersToRemove: number;
7
+ estimatedCharactersPerToken: number;
7
8
  }): ChatHistoryItem[] | Promise<ChatHistoryItem[]>;
8
9
  chatHistory: ChatHistoryItem[];
9
10
  tokensCountToFit: number;
@@ -1,7 +1,8 @@
1
1
  export async function findCharacterRemovalCountToFitChatHistoryInContext({ compressChatHistory, chatHistory, tokensCountToFit, tokenizer, chatWrapper, initialCharactersRemovalCount = 0, estimatedCharactersPerToken = 5, maxDecompressionAttempts = 2 }) {
2
+ let currentEstimatedCharactersPerToken = estimatedCharactersPerToken;
2
3
  function getTokensCountForChatHistory(chatHistory) {
3
- const { contextText } = chatWrapper.generateContextText(chatHistory);
4
- return contextText.tokenize(tokenizer).length;
4
+ const { contextText } = chatWrapper.generateContextState({ chatHistory });
5
+ return contextText.tokenize(tokenizer, "trimLeadingSpace").length;
5
6
  }
6
7
  async function getResultForCharacterRemovalCount(characterRemovalCount) {
7
8
  if (characterRemovalCount === 0)
@@ -12,7 +13,8 @@ export async function findCharacterRemovalCountToFitChatHistoryInContext({ compr
12
13
  };
13
14
  const compressedHistory = await compressChatHistory({
14
15
  chatHistory,
15
- charactersToRemove: characterRemovalCount
16
+ charactersToRemove: characterRemovalCount,
17
+ estimatedCharactersPerToken: currentEstimatedCharactersPerToken
16
18
  });
17
19
  return {
18
20
  compressedHistory,
@@ -22,22 +24,24 @@ export async function findCharacterRemovalCountToFitChatHistoryInContext({ compr
22
24
  }
23
25
  let latestCompressionAttempt = await getResultForCharacterRemovalCount(initialCharactersRemovalCount);
24
26
  const firstCompressionAttempt = latestCompressionAttempt;
25
- let currentEstimatedCharactersPerToken = estimatedCharactersPerToken;
26
27
  if (latestCompressionAttempt.tokensCount === tokensCountToFit ||
27
28
  (latestCompressionAttempt.tokensCount < tokensCountToFit && latestCompressionAttempt.characterRemovalCount === 0))
28
29
  return {
29
30
  removedCharactersCount: initialCharactersRemovalCount,
30
31
  compressedChatHistory: latestCompressionAttempt.compressedHistory
31
32
  };
32
- for (let compressionAttempts = 0, decompressionAttempts = 0; latestCompressionAttempt.tokensCount !== tokensCountToFit;) {
33
+ let bestCompressionAttempt = latestCompressionAttempt;
34
+ for (let compressionAttempts = 0, decompressionAttempts = 0; bestCompressionAttempt.tokensCount !== tokensCountToFit;) {
33
35
  if (compressionAttempts > 0) {
34
- currentEstimatedCharactersPerToken =
35
- Math.abs(latestCompressionAttempt.characterRemovalCount - firstCompressionAttempt.characterRemovalCount) /
36
- Math.abs(latestCompressionAttempt.tokensCount - firstCompressionAttempt.tokensCount);
37
- if (!Number.isFinite(currentEstimatedCharactersPerToken))
36
+ if (latestCompressionAttempt.tokensCount != firstCompressionAttempt.tokensCount &&
37
+ latestCompressionAttempt.characterRemovalCount != firstCompressionAttempt.characterRemovalCount)
38
+ currentEstimatedCharactersPerToken =
39
+ Math.abs(latestCompressionAttempt.characterRemovalCount - firstCompressionAttempt.characterRemovalCount) /
40
+ Math.abs(latestCompressionAttempt.tokensCount - firstCompressionAttempt.tokensCount);
41
+ if (!Number.isFinite(currentEstimatedCharactersPerToken) || currentEstimatedCharactersPerToken === 0)
38
42
  currentEstimatedCharactersPerToken = estimatedCharactersPerToken;
39
43
  }
40
- const tokensLeftToRemove = tokensCountToFit - latestCompressionAttempt.tokensCount;
44
+ const tokensLeftToRemove = latestCompressionAttempt.tokensCount - tokensCountToFit;
41
45
  let additionalCharactersToRemove = Math.round(tokensLeftToRemove * currentEstimatedCharactersPerToken);
42
46
  if (additionalCharactersToRemove === 0) {
43
47
  if (tokensLeftToRemove > 0)
@@ -52,10 +56,17 @@ export async function findCharacterRemovalCountToFitChatHistoryInContext({ compr
52
56
  if (decompressionAttempts >= maxDecompressionAttempts)
53
57
  break;
54
58
  latestCompressionAttempt = await getResultForCharacterRemovalCount(latestCompressionAttempt.characterRemovalCount + additionalCharactersToRemove);
59
+ if ((bestCompressionAttempt.tokensCount > tokensCountToFit &&
60
+ latestCompressionAttempt.tokensCount <= bestCompressionAttempt.tokensCount) || (bestCompressionAttempt.tokensCount < tokensCountToFit &&
61
+ latestCompressionAttempt.tokensCount < tokensCountToFit &&
62
+ latestCompressionAttempt.tokensCount > bestCompressionAttempt.tokensCount) || (bestCompressionAttempt.tokensCount <= tokensCountToFit &&
63
+ latestCompressionAttempt.tokensCount <= tokensCountToFit &&
64
+ latestCompressionAttempt.characterRemovalCount < bestCompressionAttempt.characterRemovalCount))
65
+ bestCompressionAttempt = latestCompressionAttempt;
55
66
  }
56
67
  return {
57
- removedCharactersCount: latestCompressionAttempt.characterRemovalCount,
58
- compressedChatHistory: latestCompressionAttempt.compressedHistory
68
+ removedCharactersCount: bestCompressionAttempt.characterRemovalCount,
69
+ compressedChatHistory: bestCompressionAttempt.compressedHistory
59
70
  };
60
71
  }
61
72
  //# sourceMappingURL=findCharacterRemovalCountToFitChatHistoryInContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"findCharacterRemovalCountToFitChatHistoryInContext.js","sourceRoot":"","sources":["../../src/utils/findCharacterRemovalCountToFitChatHistoryInContext.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,kDAAkD,CAAC,EACrE,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,6BAA6B,GAAG,CAAC,EACjC,2BAA2B,GAAG,CAAC,EAC/B,wBAAwB,GAAG,CAAC,EAY/B;IAIG,SAAS,4BAA4B,CAAC,WAAuC;QACzE,MAAM,EAAC,WAAW,EAAC,GAAG,WAAW,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACnE,OAAO,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;IAClD,CAAC;IAED,KAAK,UAAU,iCAAiC,CAAC,qBAA6B;QAC1E,IAAI,qBAAqB,KAAK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C;QACnF,IAAI,4BAA4B,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,kCAAkC,CAAC,CAAC;QAEvG,IAAI,4BAA4B,KAAK,CAAC,EAAE;YACpC,IAAI,kBAAkB,GAAG,CAAC;gBACtB,4BAA4B,GAAG,CAAC,CAAC;iBAChC,IAAI,kBAAkB,GAAG,CAAC;gBAC3B,4BAA4B,GAAG,CAAC,CAAC,CAAC;SACzC;QAED,IAAI,kBAAkB,GAAG,CAAC;YACtB,mBAAmB,EAAE,CAAC;aACrB,IAAI,kBAAkB,GAAG,CAAC;YAC3B,qBAAqB,EAAE,CAAC;QAE5B,IAAI,qBAAqB,IAAI,wBAAwB;YACjD,MAAM;QAEV,wBAAwB,GAAG,MAAM,iCAAiC,CAC9D,wBAAwB,CAAC,qBAAqB,GAAG,4BAA4B,CAChF,CAAC;KACL;IAED,OAAO;QACH,sBAAsB,EAAE,wBAAwB,CAAC,qBAAqB;QACtE,qBAAqB,EAAE,wBAAwB,CAAC,iBAAiB;KACpE,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"findCharacterRemovalCountToFitChatHistoryInContext.js","sourceRoot":"","sources":["../../src/utils/findCharacterRemovalCountToFitChatHistoryInContext.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,kDAAkD,CAAC,EACrE,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,6BAA6B,GAAG,CAAC,EACjC,2BAA2B,GAAG,CAAC,EAC/B,wBAAwB,GAAG,CAAC,EAY/B;IAIG,IAAI,kCAAkC,GAAG,2BAA2B,CAAC;IAErE,SAAS,4BAA4B,CAAC,WAAuC;QACzE,MAAM,EAAC,WAAW,EAAC,GAAG,WAAW,CAAC,oBAAoB,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC;QACtE,OAAO,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,MAAM,CAAC;IACtE,CAAC;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G,wBAAwB,CAAC;IAC1D,CAAC;IAED,OAAO;QACH,sBAAsB,EAAE,sBAAsB,CAAC,qBAAqB;QACpE,qBAAqB,EAAE,sBAAsB,CAAC,iBAAiB;KAClE,CAAC;AACN,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"GbnfGrammarGenerator.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/GbnfGrammarGenerator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAoB;IACtB,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACxC,MAAM,GAAW,CAAC,CAAC;IAEpB,gBAAgB;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,OAAO,OAAO,MAAM,EAAE,CAAC;IAC3B,CAAC;IAEM,gBAAgB,CAAC,WAAmB;QACvC,MAAM,KAAK,GAAsC,CAAC;gBAC9C,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,WAAW;aACvB,CAAC,CAAC;QAEH,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE;YACpD,IAAI,OAAO,IAAI,IAAI;gBACf,SAAS;YAEb,KAAK,CAAC,IAAI,CAAC;gBACP,IAAI,EAAE,QAAQ;gBACd,OAAO;aACV,CAAC,CAAC;SACN;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5E,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
1
+ {"version":3,"file":"GbnfGrammarGenerator.js","sourceRoot":"","sources":["../../../src/utils/gbnfJson/GbnfGrammarGenerator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAoB;IACtB,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACxC,MAAM,GAAW,CAAC,CAAC;IAEpB,gBAAgB;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,OAAO,OAAO,MAAM,EAAE,CAAC;IAC3B,CAAC;IAEM,gBAAgB,CAAC,WAAmB;QACvC,MAAM,KAAK,GAAsC,CAAC;gBAC9C,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,WAAW;aACvB,CAAC,CAAC;QAEH,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACrD,IAAI,OAAO,IAAI,IAAI;gBACf,SAAS;YAEb,KAAK,CAAC,IAAI,CAAC;gBACP,IAAI,EAAE,QAAQ;gBACd,OAAO;aACV,CAAC,CAAC;QACP,CAAC;QAED,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5E,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
@@ -0,0 +1,5 @@
1
+ import { GbnfJsonSchema } from "./types.js";
2
+ export declare function getGbnfGrammarForGbnfJsonSchema(schema: GbnfJsonSchema, { allowNewLines, scopePadSpaces }?: {
3
+ allowNewLines?: boolean;
4
+ scopePadSpaces?: number;
5
+ }): string;
@@ -0,0 +1,11 @@
1
+ import { getGbnfJsonTerminalForGbnfJsonSchema } from "./utils/getGbnfJsonTerminalForGbnfJsonSchema.js";
2
+ import { GbnfGrammarGenerator } from "./GbnfGrammarGenerator.js";
3
+ import { GbnfJsonScopeState } from "./utils/GbnfJsonScopeState.js";
4
+ export function getGbnfGrammarForGbnfJsonSchema(schema, { allowNewLines = true, scopePadSpaces = 4 } = {}) {
5
+ const grammarGenerator = new GbnfGrammarGenerator();
6
+ const scopeState = new GbnfJsonScopeState({ allowNewLines, scopePadSpaces });
7
+ const rootTerminal = getGbnfJsonTerminalForGbnfJsonSchema(schema, grammarGenerator, scopeState);
8
+ const rootGrammar = rootTerminal.getGrammar(grammarGenerator);
9
+ return grammarGenerator.generateGbnfFile(rootGrammar + ` "${"\\n".repeat(4)}"` + " [\\n]*");
10
+ }
11
+ //# sourceMappingURL=getGbnfGrammarForGbnfJsonSchema.js.map